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.4 1996/12/18 10:26:44 bostic Exp $ (Berkeley) $Date: 1996/12/18 10:26:44 $";
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( 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 * PUBLIC: void __vi_set_text_ruler __P((int, int));
111 __vi_set_text_ruler( row
, col
)
116 if ( ! active
) return;
118 set_ruler_text( row
, col
, &h
, &w
, &ruler_asc
);
129 #if defined(SelfTest)
136 static void destroyed()
138 #if defined(SelfTest)
142 /* some window managers destroy us upon popdown */
149 /* Draw and display a dialog the describes nvi options */
151 #if defined(__STDC__)
152 static Widget
create_text_ruler_dialog( Widget parent
, String title
)
154 static Widget
create_text_ruler_dialog( parent
, title
)
164 if ( db_ruler
!= NULL
) return db_ruler
;
166 #if defined(SelfTest)
167 ruler_font
= XLoadQueryFont( XtDisplay(parent
), "9x15" );
169 /* check the resource database for interesting resources */
170 __XutConvertResources( parent
,
177 gc_ruler
= XCreateGC( XtDisplay(parent
), XtWindow(parent
), 0, NULL
);
178 XSetFont( XtDisplay(parent
), gc_ruler
, ruler_font
->fid
);
180 box
= XtVaCreatePopupShell( title
,
181 transientShellWidgetClass
,
183 XmNallowShellResize
, False
,
186 XtAddCallback( box
, XmNpopdownCallback
, cancel_cb
, 0 );
187 XtAddCallback( box
, XmNdestroyCallback
, destroyed
, 0 );
189 /* should be ok to use the font now */
192 /* how big a window? */
193 set_ruler_text( 0, 0, &h
, &w
, &asc
);
195 /* keep this global, we might destroy it later */
196 db_ruler
= XtVaCreateManagedWidget( "Ruler",
197 xmDrawingAreaWidgetClass
,
203 /* this callback is for when the drawing area is exposed */
204 XtAddCallback( db_ruler
,
210 /* what colors are selected for the drawing area? */
211 XtVaGetValues( db_ruler
,
216 XSetForeground( XtDisplay(db_ruler
), gc_ruler
, fg
);
217 XSetBackground( XtDisplay(db_ruler
), gc_ruler
, bg
);
225 /* module entry point
226 * __vi_show_text_ruler_dialog( parent, title )
227 * __vi_clear_text_ruler_dialog( parent, title )
230 #if defined(__STDC__)
231 void __vi_show_text_ruler_dialog( Widget parent
, String title
)
233 void __vi_show_text_ruler_dialog( parent
, title
)
238 Widget db
= create_text_ruler_dialog( parent
, title
),
239 shell
= XtParent(db
);
240 Dimension height
, width
;
242 /* this guy does not resize */
248 XtVaSetValues( shell
,
251 XmNmaxHeight
, height
,
252 XmNminHeight
, height
,
258 /* leave this guy up */
259 XtPopup( shell
, XtGrabNone
);
263 /* ask vi core for the current r,c now */
264 #if ! defined(SelfTest)
265 __vi_set_text_ruler( __vi_screen
->cury
, __vi_screen
->curx
);
267 __vi_set_text_ruler( rand(), rand() );
272 #if defined(__STDC__)
273 void __vi_clear_text_ruler_dialog()
275 void __vi_clear_text_ruler_dialog()
279 XtPopdown( XtParent(db_ruler
) );
283 #if defined(SelfTest)
285 #if XtSpecificationRelease == 4
286 #define ArgcType Cardinal *
288 #define ArgcType int *
291 static void change_pos( Widget w
)
293 __vi_set_text_ruler( rand(), rand() );
296 #if defined(__STDC__)
297 static void show_text_ruler( Widget w
, XtPointer data
, XtPointer cbs
)
299 static void show_text_ruler( w
, data
, cbs
)
305 __vi_show_text_ruler_dialog( data
, "Ruler" );
308 main( int argc
, char *argv
[] )
311 Widget top_level
, rc
, button
;
314 /* create a top-level shell for the window manager */
315 top_level
= XtVaAppInitialize( &ctx
,
317 NULL
, 0, /* options */
319 argv
, /* might get modified */
324 rc
= XtVaCreateManagedWidget( "rc",
325 xmRowColumnWidgetClass
,
330 button
= XtVaCreateManagedWidget( "Pop up text ruler dialog",
331 xmPushButtonGadgetClass
,
335 XtAddCallback( button
, XmNactivateCallback
, show_text_ruler
, rc
);
337 button
= XtVaCreateManagedWidget( "Change Position",
338 xmPushButtonGadgetClass
,
342 XtAddCallback( button
, XmNactivateCallback
, change_pos
, rc
);
344 button
= XtVaCreateManagedWidget( "Quit",
345 xmPushButtonGadgetClass
,
349 XtAddCallback( button
, XmNactivateCallback
, exit
, 0 );
351 XtRealizeWidget(top_level
);