tell DB it's DB_UNKNOWN rather than DB_BTREE
[nvi.git] / motif_l / m_ruler.c
blob89c9fa5044b6be55e61da923368af29f5170eca1
1 /*-
2 * Copyright (c) 1996
3 * Rob Zimmermann. All rights reserved.
4 * Copyright (c) 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: m_ruler.c,v 8.5 2001/06/25 15:19:27 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:27 $";
14 #endif /* not lint */
16 /* This module implements a dialog for the text ruler
18 * Interface:
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>
33 #include <X11/X.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>
41 #include <stdio.h>
43 #include "../common/common.h"
44 #include "../ipc/ip.h"
45 #include "m_motif.h"
46 #include "vi_mextern.h"
49 /* globals */
51 static Widget db_ruler = NULL;
53 static Boolean active = False;
55 static int ruler_border = 5,
56 ruler_asc;
58 static GC gc_ruler;
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 },
69 #endif
72 /* change the displayed position */
74 static void
75 set_ruler_text(int row, int col, int *h, int *w, int *asc)
77 int dir, des;
78 XCharStruct over;
80 /* format the data */
81 sprintf( text, "%9.d,%-9.d", row+1, col+1 );
83 /* how big will it be? */
84 XTextExtents( ruler_font, text, strlen(text), &dir, asc, &des, &over );
86 /* how big a window will we need? */
87 *h = 2*ruler_border + over.ascent + over.descent;
88 *w = 2*ruler_border + over.width;
92 static void
93 redraw_text(void)
95 XClearArea( XtDisplay(db_ruler), XtWindow(db_ruler), 0, 0, 0, 0, False );
96 XDrawString( XtDisplay(db_ruler),
97 XtWindow(db_ruler),
98 gc_ruler,
99 ruler_border, ruler_border + ruler_asc,
100 text,
101 strlen(text)
107 * PUBLIC: void __vi_set_text_ruler __P((int, int));
109 void
110 __vi_set_text_ruler(int row, int col)
112 int h, w;
114 if ( ! active ) return;
116 set_ruler_text( row, col, &h, &w, &ruler_asc );
118 redraw_text();
122 /* callbacks */
124 static void
125 cancel_cb(void)
127 #if defined(SelfTest)
128 puts( "cancelled" );
129 #endif
130 active = False;
134 static void destroyed(void)
136 #if defined(SelfTest)
137 puts( "destroyed" );
138 #endif
140 /* some window managers destroy us upon popdown */
141 db_ruler = NULL;
142 active = False;
147 /* Draw and display a dialog the describes nvi options */
149 #if defined(__STDC__)
150 static Widget create_text_ruler_dialog( Widget parent, String title )
151 #else
152 static Widget create_text_ruler_dialog( parent, title )
153 Widget parent;
154 String title;
155 #endif
157 Widget box;
158 int h, w, asc;
159 Pixel fg, bg;
161 /* already built? */
162 if ( db_ruler != NULL ) return db_ruler;
164 #if defined(SelfTest)
165 ruler_font = XLoadQueryFont( XtDisplay(parent), "9x15" );
166 #else
167 /* check the resource database for interesting resources */
168 __XutConvertResources( parent,
169 vi_progname,
170 resource,
171 XtNumber(resource)
173 #endif
175 gc_ruler = XCreateGC( XtDisplay(parent), XtWindow(parent), 0, NULL );
176 XSetFont( XtDisplay(parent), gc_ruler, ruler_font->fid );
178 box = XtVaCreatePopupShell( title,
179 transientShellWidgetClass,
180 parent,
181 XmNallowShellResize, False,
184 XtAddCallback( box, XmNpopdownCallback, cancel_cb, 0 );
185 XtAddCallback( box, XmNdestroyCallback, destroyed, 0 );
187 /* should be ok to use the font now */
188 active = True;
190 /* how big a window? */
191 set_ruler_text( 0, 0, &h, &w, &asc );
193 /* keep this global, we might destroy it later */
194 db_ruler = XtVaCreateManagedWidget( "Ruler",
195 xmDrawingAreaWidgetClass,
196 box,
197 XmNheight, h,
198 XmNwidth, w,
201 /* this callback is for when the drawing area is exposed */
202 XtAddCallback( db_ruler,
203 XmNexposeCallback,
204 redraw_text,
208 /* what colors are selected for the drawing area? */
209 XtVaGetValues( db_ruler,
210 XmNbackground, &bg,
211 XmNforeground, &fg,
214 XSetForeground( XtDisplay(db_ruler), gc_ruler, fg );
215 XSetBackground( XtDisplay(db_ruler), gc_ruler, bg );
217 /* done */
218 return db_ruler;
223 /* module entry point
224 * __vi_show_text_ruler_dialog( parent, title )
225 * __vi_clear_text_ruler_dialog( parent, title )
228 #if defined(__STDC__)
229 void __vi_show_text_ruler_dialog( Widget parent, String title )
230 #else
231 void __vi_show_text_ruler_dialog( parent, title )
232 Widget parent;
233 String title;
234 #endif
236 Widget db = create_text_ruler_dialog( parent, title ),
237 shell = XtParent(db);
238 Dimension height, width;
240 /* this guy does not resize */
241 XtVaGetValues( db,
242 XmNheight, &height,
243 XmNwidth, &width,
246 XtVaSetValues( shell,
247 XmNmaxWidth, width,
248 XmNminWidth, width,
249 XmNmaxHeight, height,
250 XmNminHeight, height,
254 XtManageChild( db );
256 /* leave this guy up */
257 XtPopup( shell, XtGrabNone );
259 active = True;
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 );
264 #else
265 __vi_set_text_ruler( rand(), rand() );
266 #endif
270 #if defined(__STDC__)
271 void __vi_clear_text_ruler_dialog()
272 #else
273 void __vi_clear_text_ruler_dialog(void)
274 #endif
276 if ( active )
277 XtPopdown( XtParent(db_ruler) );
281 #if defined(SelfTest)
283 #if XtSpecificationRelease == 4
284 #define ArgcType Cardinal *
285 #else
286 #define ArgcType int *
287 #endif
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 )
296 #else
297 static void show_text_ruler( w, data, cbs )
298 Widget w;
299 XtPointer data;
300 XtPointer cbs;
301 #endif
303 __vi_show_text_ruler_dialog( data, "Ruler" );
306 main( int argc, char *argv[] )
308 XtAppContext ctx;
309 Widget top_level, rc, button;
310 extern exit();
312 /* create a top-level shell for the window manager */
313 top_level = XtVaAppInitialize( &ctx,
314 argv[0],
315 NULL, 0, /* options */
316 (ArgcType) &argc,
317 argv, /* might get modified */
318 NULL,
319 NULL
322 rc = XtVaCreateManagedWidget( "rc",
323 xmRowColumnWidgetClass,
324 top_level,
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);
350 XtAppMainLoop(ctx);
352 #endif