3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid
[] = "$Id: m_ruler.c,v 8.5 2001/06/25 15:19:27 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:27 $";
16 /* This module implements a dialog for the text ruler
19 * void __vi_show_text_ruler_dialog( Widget parent, String title )
20 * Pops up a text ruler dialog.
21 * We allow one per session. It is not modal.
23 * void __vi_clear_text_ruler_dialog( Widget parent, String title )
24 * Pops down the text ruler dialog.
26 * void __vi_set_text_ruler( int row, int col )
27 * Changes the displayed position
30 #include <sys/types.h>
31 #include <sys/queue.h>
34 #include <X11/Intrinsic.h>
35 #include <X11/Shell.h>
36 #include <Xm/DrawingA.h>
37 #include <Xm/RowColumn.h>
38 #include <Xm/PushBG.h>
40 #include <bitstring.h>
43 #include "../common/common.h"
44 #include "../ipc/ip.h"
46 #include "vi_mextern.h"
51 static Widget db_ruler
= NULL
;
53 static Boolean active
= False
;
55 static int ruler_border
= 5,
60 static XFontStruct
*ruler_font
;
62 static char text
[256];
64 #if ! defined(SelfTest)
65 static XutResource resource
[] = {
66 { "rulerFont", XutRKfont
, &ruler_font
},
67 { "rulerBorder", XutRKinteger
, &ruler_border
},
72 /* change the displayed position */
75 set_ruler_text(int row
, int col
, int *h
, int *w
, int *asc
)
81 sprintf( text
, "%9.d,%-9.d", row
+1, col
+1 );
83 /* how big will it be? */
84 XTextExtents( ruler_font
, text
, strlen(text
), &dir
, asc
, &des
, &over
);
86 /* how big a window will we need? */
87 *h
= 2*ruler_border
+ over
.ascent
+ over
.descent
;
88 *w
= 2*ruler_border
+ over
.width
;
95 XClearArea( XtDisplay(db_ruler
), XtWindow(db_ruler
), 0, 0, 0, 0, False
);
96 XDrawString( XtDisplay(db_ruler
),
99 ruler_border
, ruler_border
+ ruler_asc
,
107 * PUBLIC: void __vi_set_text_ruler __P((int, int));
110 __vi_set_text_ruler(int row
, int col
)
114 if ( ! active
) return;
116 set_ruler_text( row
, col
, &h
, &w
, &ruler_asc
);
127 #if defined(SelfTest)
134 static void destroyed(void)
136 #if defined(SelfTest)
140 /* some window managers destroy us upon popdown */
147 /* Draw and display a dialog the describes nvi options */
149 #if defined(__STDC__)
150 static Widget
create_text_ruler_dialog( Widget parent
, String title
)
152 static Widget
create_text_ruler_dialog( parent
, title
)
162 if ( db_ruler
!= NULL
) return db_ruler
;
164 #if defined(SelfTest)
165 ruler_font
= XLoadQueryFont( XtDisplay(parent
), "9x15" );
167 /* check the resource database for interesting resources */
168 __XutConvertResources( parent
,
175 gc_ruler
= XCreateGC( XtDisplay(parent
), XtWindow(parent
), 0, NULL
);
176 XSetFont( XtDisplay(parent
), gc_ruler
, ruler_font
->fid
);
178 box
= XtVaCreatePopupShell( title
,
179 transientShellWidgetClass
,
181 XmNallowShellResize
, False
,
184 XtAddCallback( box
, XmNpopdownCallback
, cancel_cb
, 0 );
185 XtAddCallback( box
, XmNdestroyCallback
, destroyed
, 0 );
187 /* should be ok to use the font now */
190 /* how big a window? */
191 set_ruler_text( 0, 0, &h
, &w
, &asc
);
193 /* keep this global, we might destroy it later */
194 db_ruler
= XtVaCreateManagedWidget( "Ruler",
195 xmDrawingAreaWidgetClass
,
201 /* this callback is for when the drawing area is exposed */
202 XtAddCallback( db_ruler
,
208 /* what colors are selected for the drawing area? */
209 XtVaGetValues( db_ruler
,
214 XSetForeground( XtDisplay(db_ruler
), gc_ruler
, fg
);
215 XSetBackground( XtDisplay(db_ruler
), gc_ruler
, bg
);
223 /* module entry point
224 * __vi_show_text_ruler_dialog( parent, title )
225 * __vi_clear_text_ruler_dialog( parent, title )
228 #if defined(__STDC__)
229 void __vi_show_text_ruler_dialog( Widget parent
, String title
)
231 void __vi_show_text_ruler_dialog( parent
, title
)
236 Widget db
= create_text_ruler_dialog( parent
, title
),
237 shell
= XtParent(db
);
238 Dimension height
, width
;
240 /* this guy does not resize */
246 XtVaSetValues( shell
,
249 XmNmaxHeight
, height
,
250 XmNminHeight
, height
,
256 /* leave this guy up */
257 XtPopup( shell
, XtGrabNone
);
261 /* ask vi core for the current r,c now */
262 #if ! defined(SelfTest)
263 __vi_set_text_ruler( __vi_screen
->cury
, __vi_screen
->curx
);
265 __vi_set_text_ruler( rand(), rand() );
270 #if defined(__STDC__)
271 void __vi_clear_text_ruler_dialog()
273 void __vi_clear_text_ruler_dialog(void)
277 XtPopdown( XtParent(db_ruler
) );
281 #if defined(SelfTest)
283 #if XtSpecificationRelease == 4
284 #define ArgcType Cardinal *
286 #define ArgcType int *
289 static void change_pos( Widget w
)
291 __vi_set_text_ruler( rand(), rand() );
294 #if defined(__STDC__)
295 static void show_text_ruler( Widget w
, XtPointer data
, XtPointer cbs
)
297 static void show_text_ruler( w
, data
, cbs
)
303 __vi_show_text_ruler_dialog( data
, "Ruler" );
306 main( int argc
, char *argv
[] )
309 Widget top_level
, rc
, button
;
312 /* create a top-level shell for the window manager */
313 top_level
= XtVaAppInitialize( &ctx
,
315 NULL
, 0, /* options */
317 argv
, /* might get modified */
322 rc
= XtVaCreateManagedWidget( "rc",
323 xmRowColumnWidgetClass
,
328 button
= XtVaCreateManagedWidget( "Pop up text ruler dialog",
329 xmPushButtonGadgetClass
,
333 XtAddCallback( button
, XmNactivateCallback
, show_text_ruler
, rc
);
335 button
= XtVaCreateManagedWidget( "Change Position",
336 xmPushButtonGadgetClass
,
340 XtAddCallback( button
, XmNactivateCallback
, change_pos
, rc
);
342 button
= XtVaCreateManagedWidget( "Quit",
343 xmPushButtonGadgetClass
,
347 XtAddCallback( button
, XmNactivateCallback
, exit
, 0 );
349 XtRealizeWidget(top_level
);