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.2 1996/12/16 17:24:03 bostic Exp $ (Berkeley) $Date: 1996/12/16 17:24:03 $";
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"
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( row
, col
, h
, w
, asc
)
76 int row
, col
, *h
, *w
, *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 __vi_set_text_ruler( row
, col
)
113 if ( ! active
) return;
115 set_ruler_text( row
, col
, &h
, &w
, &ruler_asc
);
126 #if defined(SelfTest)
133 static void destroyed()
135 #if defined(SelfTest)
139 /* some window managers destroy us upon popdown */
146 /* Draw and display a dialog the describes nvi options */
148 #if defined(__STDC__)
149 static Widget
create_text_ruler_dialog( Widget parent
, String title
)
151 static Widget
create_text_ruler_dialog( parent
, title
)
161 if ( db_ruler
!= NULL
) return db_ruler
;
163 #if defined(SelfTest)
164 ruler_font
= XLoadQueryFont( XtDisplay(parent
), "9x15" );
166 /* check the resource database for interesting resources */
167 XutConvertResources( parent
,
174 gc_ruler
= XCreateGC( XtDisplay(parent
), XtWindow(parent
), 0, NULL
);
175 XSetFont( XtDisplay(parent
), gc_ruler
, ruler_font
->fid
);
177 box
= XtVaCreatePopupShell( title
,
178 transientShellWidgetClass
,
180 XmNallowShellResize
, False
,
183 XtAddCallback( box
, XmNpopdownCallback
, cancel_cb
, 0 );
184 XtAddCallback( box
, XmNdestroyCallback
, destroyed
, 0 );
186 /* should be ok to use the font now */
189 /* how big a window? */
190 set_ruler_text( 0, 0, &h
, &w
, &asc
);
192 /* keep this global, we might destroy it later */
193 db_ruler
= XtVaCreateManagedWidget( "Ruler",
194 xmDrawingAreaWidgetClass
,
200 /* this callback is for when the drawing area is exposed */
201 XtAddCallback( db_ruler
,
207 /* what colors are selected for the drawing area? */
208 XtVaGetValues( db_ruler
,
213 XSetForeground( XtDisplay(db_ruler
), gc_ruler
, fg
);
214 XSetBackground( XtDisplay(db_ruler
), gc_ruler
, bg
);
222 /* module entry point
223 * __vi_show_text_ruler_dialog( parent, title )
224 * __vi_clear_text_ruler_dialog( parent, title )
227 #if defined(__STDC__)
228 void __vi_show_text_ruler_dialog( Widget parent
, String title
)
230 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()
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
);