3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
12 #include <sys/cdefs.h>
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 __RCSID("$NetBSD: m_ruler.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
21 /* This module implements a dialog for the text ruler
24 * void __vi_show_text_ruler_dialog( Widget parent, String title )
25 * Pops up a text ruler dialog.
26 * We allow one per session. It is not modal.
28 * void __vi_clear_text_ruler_dialog( Widget parent, String title )
29 * Pops down the text ruler dialog.
31 * void __vi_set_text_ruler( int row, int col )
32 * Changes the displayed position
35 #include <sys/types.h>
36 #include <sys/queue.h>
39 #include <X11/Intrinsic.h>
40 #include <X11/Shell.h>
41 #include <Xm/DrawingA.h>
42 #include <Xm/RowColumn.h>
43 #include <Xm/PushBG.h>
45 #include <bitstring.h>
49 #include "../common/common.h"
50 #include "../ipc/ip.h"
52 #include "vi_mextern.h"
57 static Widget db_ruler
= NULL
;
59 static Boolean active
= False
;
61 static int ruler_border
= 5,
66 static XFontStruct
*ruler_font
;
68 static char text
[256];
70 #if ! defined(SelfTest)
71 static XutResource resource
[] = {
72 { "rulerFont", XutRKfont
, &ruler_font
},
73 { "rulerBorder", XutRKinteger
, &ruler_border
},
78 /* change the displayed position */
81 set_ruler_text(int row
, int col
, int *h
, int *w
, int *asc
)
87 sprintf( text
, "%9.d,%-9.d", row
+1, col
+1 );
89 /* how big will it be? */
90 XTextExtents( ruler_font
, text
, strlen(text
), &dir
, asc
, &des
, &over
);
92 /* how big a window will we need? */
93 *h
= 2*ruler_border
+ over
.ascent
+ over
.descent
;
94 *w
= 2*ruler_border
+ over
.width
;
101 XClearArea( XtDisplay(db_ruler
), XtWindow(db_ruler
), 0, 0, 0, 0, False
);
102 XDrawString( XtDisplay(db_ruler
),
105 ruler_border
, ruler_border
+ ruler_asc
,
113 * PUBLIC: void __vi_set_text_ruler __P((int, int));
116 __vi_set_text_ruler(int row
, int col
)
120 if ( ! active
) return;
122 set_ruler_text( row
, col
, &h
, &w
, &ruler_asc
);
133 #if defined(SelfTest)
140 static void destroyed(void)
142 #if defined(SelfTest)
146 /* some window managers destroy us upon popdown */
153 /* Draw and display a dialog the describes nvi options */
155 #if defined(__STDC__)
156 static Widget
create_text_ruler_dialog( Widget parent
, String title
)
158 static Widget
create_text_ruler_dialog( parent
, title
)
168 if ( db_ruler
!= NULL
) return db_ruler
;
170 #if defined(SelfTest)
171 ruler_font
= XLoadQueryFont( XtDisplay(parent
), "9x15" );
173 /* check the resource database for interesting resources */
174 __XutConvertResources( parent
,
181 gc_ruler
= XCreateGC( XtDisplay(parent
), XtWindow(parent
), 0, NULL
);
182 XSetFont( XtDisplay(parent
), gc_ruler
, ruler_font
->fid
);
184 box
= XtVaCreatePopupShell( title
,
185 transientShellWidgetClass
,
187 XmNallowShellResize
, False
,
190 XtAddCallback( box
, XmNpopdownCallback
, cancel_cb
, 0 );
191 XtAddCallback( box
, XmNdestroyCallback
, destroyed
, 0 );
193 /* should be ok to use the font now */
196 /* how big a window? */
197 set_ruler_text( 0, 0, &h
, &w
, &asc
);
199 /* keep this global, we might destroy it later */
200 db_ruler
= XtVaCreateManagedWidget( "Ruler",
201 xmDrawingAreaWidgetClass
,
207 /* this callback is for when the drawing area is exposed */
208 XtAddCallback( db_ruler
,
214 /* what colors are selected for the drawing area? */
215 XtVaGetValues( db_ruler
,
220 XSetForeground( XtDisplay(db_ruler
), gc_ruler
, fg
);
221 XSetBackground( XtDisplay(db_ruler
), gc_ruler
, bg
);
229 /* module entry point
230 * __vi_show_text_ruler_dialog( parent, title )
231 * __vi_clear_text_ruler_dialog( parent, title )
234 #if defined(__STDC__)
235 void __vi_show_text_ruler_dialog( Widget parent
, String title
)
237 void __vi_show_text_ruler_dialog( parent
, title
)
242 Widget db
= create_text_ruler_dialog( parent
, title
),
243 shell
= XtParent(db
);
244 Dimension height
, width
;
246 /* this guy does not resize */
252 XtVaSetValues( shell
,
255 XmNmaxHeight
, height
,
256 XmNminHeight
, height
,
262 /* leave this guy up */
263 XtPopup( shell
, XtGrabNone
);
267 /* ask vi core for the current r,c now */
268 #if ! defined(SelfTest)
269 __vi_set_text_ruler( __vi_screen
->cury
, __vi_screen
->curx
);
271 __vi_set_text_ruler( rand(), rand() );
276 #if defined(__STDC__)
277 void __vi_clear_text_ruler_dialog()
279 void __vi_clear_text_ruler_dialog(void)
283 XtPopdown( XtParent(db_ruler
) );
287 #if defined(SelfTest)
289 #if XtSpecificationRelease == 4
290 #define ArgcType Cardinal *
292 #define ArgcType int *
295 static void change_pos( Widget w
)
297 __vi_set_text_ruler( rand(), rand() );
300 #if defined(__STDC__)
301 static void show_text_ruler( Widget w
, XtPointer data
, XtPointer cbs
)
303 static void show_text_ruler( w
, data
, cbs
)
309 __vi_show_text_ruler_dialog( data
, "Ruler" );
312 main( int argc
, char *argv
[] )
315 Widget top_level
, rc
, button
;
317 /* create a top-level shell for the window manager */
318 top_level
= XtVaAppInitialize( &ctx
,
320 NULL
, 0, /* options */
322 argv
, /* might get modified */
327 rc
= XtVaCreateManagedWidget( "rc",
328 xmRowColumnWidgetClass
,
333 button
= XtVaCreateManagedWidget( "Pop up text ruler dialog",
334 xmPushButtonGadgetClass
,
338 XtAddCallback( button
, XmNactivateCallback
, show_text_ruler
, rc
);
340 button
= XtVaCreateManagedWidget( "Change Position",
341 xmPushButtonGadgetClass
,
345 XtAddCallback( button
, XmNactivateCallback
, change_pos
, rc
);
347 button
= XtVaCreateManagedWidget( "Quit",
348 xmPushButtonGadgetClass
,
352 XtAddCallback( button
, XmNactivateCallback
, exit
, 0 );
354 XtRealizeWidget(top_level
);