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.6 2003/11/05 17:10:00 skimo Exp $ (Berkeley) $Date: 2003/11/05 17:10:00 $";
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>
44 #include "../common/common.h"
45 #include "../ipc/ip.h"
47 #include "vi_mextern.h"
52 static Widget db_ruler
= NULL
;
54 static Boolean active
= False
;
56 static int ruler_border
= 5,
61 static XFontStruct
*ruler_font
;
63 static char text
[256];
65 #if ! defined(SelfTest)
66 static XutResource resource
[] = {
67 { "rulerFont", XutRKfont
, &ruler_font
},
68 { "rulerBorder", XutRKinteger
, &ruler_border
},
73 /* change the displayed position */
76 set_ruler_text(int row
, int col
, int *h
, int *w
, int *asc
)
82 sprintf( text
, "%9.d,%-9.d", row
+1, col
+1 );
84 /* how big will it be? */
85 XTextExtents( ruler_font
, text
, strlen(text
), &dir
, asc
, &des
, &over
);
87 /* how big a window will we need? */
88 *h
= 2*ruler_border
+ over
.ascent
+ over
.descent
;
89 *w
= 2*ruler_border
+ over
.width
;
96 XClearArea( XtDisplay(db_ruler
), XtWindow(db_ruler
), 0, 0, 0, 0, False
);
97 XDrawString( XtDisplay(db_ruler
),
100 ruler_border
, ruler_border
+ ruler_asc
,
108 * PUBLIC: void __vi_set_text_ruler __P((int, int));
111 __vi_set_text_ruler(int row
, int col
)
115 if ( ! active
) return;
117 set_ruler_text( row
, col
, &h
, &w
, &ruler_asc
);
128 #if defined(SelfTest)
135 static void destroyed(void)
137 #if defined(SelfTest)
141 /* some window managers destroy us upon popdown */
148 /* Draw and display a dialog the describes nvi options */
150 #if defined(__STDC__)
151 static Widget
create_text_ruler_dialog( Widget parent
, String title
)
153 static Widget
create_text_ruler_dialog( parent
, title
)
163 if ( db_ruler
!= NULL
) return db_ruler
;
165 #if defined(SelfTest)
166 ruler_font
= XLoadQueryFont( XtDisplay(parent
), "9x15" );
168 /* check the resource database for interesting resources */
169 __XutConvertResources( parent
,
176 gc_ruler
= XCreateGC( XtDisplay(parent
), XtWindow(parent
), 0, NULL
);
177 XSetFont( XtDisplay(parent
), gc_ruler
, ruler_font
->fid
);
179 box
= XtVaCreatePopupShell( title
,
180 transientShellWidgetClass
,
182 XmNallowShellResize
, False
,
185 XtAddCallback( box
, XmNpopdownCallback
, cancel_cb
, 0 );
186 XtAddCallback( box
, XmNdestroyCallback
, destroyed
, 0 );
188 /* should be ok to use the font now */
191 /* how big a window? */
192 set_ruler_text( 0, 0, &h
, &w
, &asc
);
194 /* keep this global, we might destroy it later */
195 db_ruler
= XtVaCreateManagedWidget( "Ruler",
196 xmDrawingAreaWidgetClass
,
202 /* this callback is for when the drawing area is exposed */
203 XtAddCallback( db_ruler
,
209 /* what colors are selected for the drawing area? */
210 XtVaGetValues( db_ruler
,
215 XSetForeground( XtDisplay(db_ruler
), gc_ruler
, fg
);
216 XSetBackground( XtDisplay(db_ruler
), gc_ruler
, bg
);
224 /* module entry point
225 * __vi_show_text_ruler_dialog( parent, title )
226 * __vi_clear_text_ruler_dialog( parent, title )
229 #if defined(__STDC__)
230 void __vi_show_text_ruler_dialog( Widget parent
, String title
)
232 void __vi_show_text_ruler_dialog( parent
, title
)
237 Widget db
= create_text_ruler_dialog( parent
, title
),
238 shell
= XtParent(db
);
239 Dimension height
, width
;
241 /* this guy does not resize */
247 XtVaSetValues( shell
,
250 XmNmaxHeight
, height
,
251 XmNminHeight
, height
,
257 /* leave this guy up */
258 XtPopup( shell
, XtGrabNone
);
262 /* ask vi core for the current r,c now */
263 #if ! defined(SelfTest)
264 __vi_set_text_ruler( __vi_screen
->cury
, __vi_screen
->curx
);
266 __vi_set_text_ruler( rand(), rand() );
271 #if defined(__STDC__)
272 void __vi_clear_text_ruler_dialog()
274 void __vi_clear_text_ruler_dialog(void)
278 XtPopdown( XtParent(db_ruler
) );
282 #if defined(SelfTest)
284 #if XtSpecificationRelease == 4
285 #define ArgcType Cardinal *
287 #define ArgcType int *
290 static void change_pos( Widget w
)
292 __vi_set_text_ruler( rand(), rand() );
295 #if defined(__STDC__)
296 static void show_text_ruler( Widget w
, XtPointer data
, XtPointer cbs
)
298 static void show_text_ruler( w
, data
, cbs
)
304 __vi_show_text_ruler_dialog( data
, "Ruler" );
307 main( int argc
, char *argv
[] )
310 Widget top_level
, rc
, button
;
313 /* create a top-level shell for the window manager */
314 top_level
= XtVaAppInitialize( &ctx
,
316 NULL
, 0, /* options */
318 argv
, /* might get modified */
323 rc
= XtVaCreateManagedWidget( "rc",
324 xmRowColumnWidgetClass
,
329 button
= XtVaCreateManagedWidget( "Pop up text ruler dialog",
330 xmPushButtonGadgetClass
,
334 XtAddCallback( button
, XmNactivateCallback
, show_text_ruler
, rc
);
336 button
= XtVaCreateManagedWidget( "Change Position",
337 xmPushButtonGadgetClass
,
341 XtAddCallback( button
, XmNactivateCallback
, change_pos
, rc
);
343 button
= XtVaCreateManagedWidget( "Quit",
344 xmPushButtonGadgetClass
,
348 XtAddCallback( button
, XmNactivateCallback
, exit
, 0 );
350 XtRealizeWidget(top_level
);