5 * Rob Zimmermann. All rights reserved.
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 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";
18 /* This module implements a dialog for the text ruler
21 * void __vi_show_text_ruler_dialog( Widget parent, String title )
22 * Pops up a text ruler dialog.
23 * We allow one per session. It is not modal.
25 * void __vi_clear_text_ruler_dialog( Widget parent, String title )
26 * Pops down the text ruler dialog.
28 * void __vi_set_text_ruler( int row, int col )
29 * Changes the displayed position
32 #include <sys/types.h>
33 #include <sys/queue.h>
36 #include <X11/Intrinsic.h>
37 #include <X11/Shell.h>
38 #include <Xm/DrawingA.h>
39 #include <Xm/RowColumn.h>
40 #include <Xm/PushBG.h>
42 #include <bitstring.h>
46 #include "../common/common.h"
47 #include "../ipc/ip.h"
49 #include "vi_mextern.h"
54 static Widget db_ruler
= NULL
;
56 static Boolean active
= False
;
58 static int ruler_border
= 5,
63 static XFontStruct
*ruler_font
;
65 static char text
[256];
67 #if ! defined(SelfTest)
68 static XutResource resource
[] = {
69 { "rulerFont", XutRKfont
, &ruler_font
},
70 { "rulerBorder", XutRKinteger
, &ruler_border
},
75 /* change the displayed position */
78 set_ruler_text(int row
, int col
, int *h
, int *w
, int *asc
)
84 sprintf( text
, "%9.d,%-9.d", row
+1, col
+1 );
86 /* how big will it be? */
87 XTextExtents( ruler_font
, text
, strlen(text
), &dir
, asc
, &des
, &over
);
89 /* how big a window will we need? */
90 *h
= 2*ruler_border
+ over
.ascent
+ over
.descent
;
91 *w
= 2*ruler_border
+ over
.width
;
98 XClearArea( XtDisplay(db_ruler
), XtWindow(db_ruler
), 0, 0, 0, 0, False
);
99 XDrawString( XtDisplay(db_ruler
),
102 ruler_border
, ruler_border
+ ruler_asc
,
110 * PUBLIC: void __vi_set_text_ruler __P((int, int));
113 __vi_set_text_ruler(int row
, int col
)
117 if ( ! active
) return;
119 set_ruler_text( row
, col
, &h
, &w
, &ruler_asc
);
130 #if defined(SelfTest)
137 static void destroyed(void)
139 #if defined(SelfTest)
143 /* some window managers destroy us upon popdown */
150 /* Draw and display a dialog the describes nvi options */
152 #if defined(__STDC__)
153 static Widget
create_text_ruler_dialog( Widget parent
, String title
)
155 static Widget
create_text_ruler_dialog( parent
, title
)
165 if ( db_ruler
!= NULL
) return db_ruler
;
167 #if defined(SelfTest)
168 ruler_font
= XLoadQueryFont( XtDisplay(parent
), "9x15" );
170 /* check the resource database for interesting resources */
171 __XutConvertResources( parent
,
178 gc_ruler
= XCreateGC( XtDisplay(parent
), XtWindow(parent
), 0, NULL
);
179 XSetFont( XtDisplay(parent
), gc_ruler
, ruler_font
->fid
);
181 box
= XtVaCreatePopupShell( title
,
182 transientShellWidgetClass
,
184 XmNallowShellResize
, False
,
187 XtAddCallback( box
, XmNpopdownCallback
, cancel_cb
, 0 );
188 XtAddCallback( box
, XmNdestroyCallback
, destroyed
, 0 );
190 /* should be ok to use the font now */
193 /* how big a window? */
194 set_ruler_text( 0, 0, &h
, &w
, &asc
);
196 /* keep this global, we might destroy it later */
197 db_ruler
= XtVaCreateManagedWidget( "Ruler",
198 xmDrawingAreaWidgetClass
,
204 /* this callback is for when the drawing area is exposed */
205 XtAddCallback( db_ruler
,
211 /* what colors are selected for the drawing area? */
212 XtVaGetValues( db_ruler
,
217 XSetForeground( XtDisplay(db_ruler
), gc_ruler
, fg
);
218 XSetBackground( XtDisplay(db_ruler
), gc_ruler
, bg
);
226 /* module entry point
227 * __vi_show_text_ruler_dialog( parent, title )
228 * __vi_clear_text_ruler_dialog( parent, title )
231 #if defined(__STDC__)
232 void __vi_show_text_ruler_dialog( Widget parent
, String title
)
234 void __vi_show_text_ruler_dialog( parent
, title
)
239 Widget db
= create_text_ruler_dialog( parent
, title
),
240 shell
= XtParent(db
);
241 Dimension height
, width
;
243 /* this guy does not resize */
249 XtVaSetValues( shell
,
252 XmNmaxHeight
, height
,
253 XmNminHeight
, height
,
259 /* leave this guy up */
260 XtPopup( shell
, XtGrabNone
);
264 /* ask vi core for the current r,c now */
265 #if ! defined(SelfTest)
266 __vi_set_text_ruler( __vi_screen
->cury
, __vi_screen
->curx
);
268 __vi_set_text_ruler( rand(), rand() );
273 #if defined(__STDC__)
274 void __vi_clear_text_ruler_dialog()
276 void __vi_clear_text_ruler_dialog(void)
280 XtPopdown( XtParent(db_ruler
) );
284 #if defined(SelfTest)
286 #if XtSpecificationRelease == 4
287 #define ArgcType Cardinal *
289 #define ArgcType int *
292 static void change_pos( Widget w
)
294 __vi_set_text_ruler( rand(), rand() );
297 #if defined(__STDC__)
298 static void show_text_ruler( Widget w
, XtPointer data
, XtPointer cbs
)
300 static void show_text_ruler( w
, data
, cbs
)
306 __vi_show_text_ruler_dialog( data
, "Ruler" );
309 main( int argc
, char *argv
[] )
312 Widget top_level
, rc
, button
;
315 /* create a top-level shell for the window manager */
316 top_level
= XtVaAppInitialize( &ctx
,
318 NULL
, 0, /* options */
320 argv
, /* might get modified */
325 rc
= XtVaCreateManagedWidget( "rc",
326 xmRowColumnWidgetClass
,
331 button
= XtVaCreateManagedWidget( "Pop up text ruler dialog",
332 xmPushButtonGadgetClass
,
336 XtAddCallback( button
, XmNactivateCallback
, show_text_ruler
, rc
);
338 button
= XtVaCreateManagedWidget( "Change Position",
339 xmPushButtonGadgetClass
,
343 XtAddCallback( button
, XmNactivateCallback
, change_pos
, rc
);
345 button
= XtVaCreateManagedWidget( "Quit",
346 xmPushButtonGadgetClass
,
350 XtAddCallback( button
, XmNactivateCallback
, exit
, 0 );
352 XtRealizeWidget(top_level
);