Remove building with NOCRYPTO option
[minix.git] / external / bsd / nvi / dist / motif_l / m_ruler.c
blob76305785da6639759fe8c74e1312049bc3cc85dc
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 #include <sys/cdefs.h>
13 #if 0
14 #ifndef lint
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 ";
16 #endif /* not lint */
17 #else
18 __RCSID("$NetBSD: m_ruler.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
19 #endif
21 /* This module implements a dialog for the text ruler
23 * Interface:
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>
38 #include <X11/X.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>
46 #include <stdio.h>
48 #undef LOCK_SUCCESS
49 #include "../common/common.h"
50 #include "../ipc/ip.h"
51 #include "m_motif.h"
52 #include "vi_mextern.h"
55 /* globals */
57 static Widget db_ruler = NULL;
59 static Boolean active = False;
61 static int ruler_border = 5,
62 ruler_asc;
64 static GC gc_ruler;
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 },
75 #endif
78 /* change the displayed position */
80 static void
81 set_ruler_text(int row, int col, int *h, int *w, int *asc)
83 int dir, des;
84 XCharStruct over;
86 /* format the data */
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;
98 static void
99 redraw_text(void)
101 XClearArea( XtDisplay(db_ruler), XtWindow(db_ruler), 0, 0, 0, 0, False );
102 XDrawString( XtDisplay(db_ruler),
103 XtWindow(db_ruler),
104 gc_ruler,
105 ruler_border, ruler_border + ruler_asc,
106 text,
107 strlen(text)
113 * PUBLIC: void __vi_set_text_ruler __P((int, int));
115 void
116 __vi_set_text_ruler(int row, int col)
118 int h, w;
120 if ( ! active ) return;
122 set_ruler_text( row, col, &h, &w, &ruler_asc );
124 redraw_text();
128 /* callbacks */
130 static void
131 cancel_cb(void)
133 #if defined(SelfTest)
134 puts( "cancelled" );
135 #endif
136 active = False;
140 static void destroyed(void)
142 #if defined(SelfTest)
143 puts( "destroyed" );
144 #endif
146 /* some window managers destroy us upon popdown */
147 db_ruler = NULL;
148 active = False;
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 )
157 #else
158 static Widget create_text_ruler_dialog( parent, title )
159 Widget parent;
160 String title;
161 #endif
163 Widget box;
164 int h, w, asc;
165 Pixel fg, bg;
167 /* already built? */
168 if ( db_ruler != NULL ) return db_ruler;
170 #if defined(SelfTest)
171 ruler_font = XLoadQueryFont( XtDisplay(parent), "9x15" );
172 #else
173 /* check the resource database for interesting resources */
174 __XutConvertResources( parent,
175 vi_progname,
176 resource,
177 XtNumber(resource)
179 #endif
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,
186 parent,
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 */
194 active = True;
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,
202 box,
203 XmNheight, h,
204 XmNwidth, w,
207 /* this callback is for when the drawing area is exposed */
208 XtAddCallback( db_ruler,
209 XmNexposeCallback,
210 redraw_text,
214 /* what colors are selected for the drawing area? */
215 XtVaGetValues( db_ruler,
216 XmNbackground, &bg,
217 XmNforeground, &fg,
220 XSetForeground( XtDisplay(db_ruler), gc_ruler, fg );
221 XSetBackground( XtDisplay(db_ruler), gc_ruler, bg );
223 /* done */
224 return db_ruler;
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 )
236 #else
237 void __vi_show_text_ruler_dialog( parent, title )
238 Widget parent;
239 String title;
240 #endif
242 Widget db = create_text_ruler_dialog( parent, title ),
243 shell = XtParent(db);
244 Dimension height, width;
246 /* this guy does not resize */
247 XtVaGetValues( db,
248 XmNheight, &height,
249 XmNwidth, &width,
252 XtVaSetValues( shell,
253 XmNmaxWidth, width,
254 XmNminWidth, width,
255 XmNmaxHeight, height,
256 XmNminHeight, height,
260 XtManageChild( db );
262 /* leave this guy up */
263 XtPopup( shell, XtGrabNone );
265 active = True;
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 );
270 #else
271 __vi_set_text_ruler( rand(), rand() );
272 #endif
276 #if defined(__STDC__)
277 void __vi_clear_text_ruler_dialog()
278 #else
279 void __vi_clear_text_ruler_dialog(void)
280 #endif
282 if ( active )
283 XtPopdown( XtParent(db_ruler) );
287 #if defined(SelfTest)
289 #if XtSpecificationRelease == 4
290 #define ArgcType Cardinal *
291 #else
292 #define ArgcType int *
293 #endif
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 )
302 #else
303 static void show_text_ruler( w, data, cbs )
304 Widget w;
305 XtPointer data;
306 XtPointer cbs;
307 #endif
309 __vi_show_text_ruler_dialog( data, "Ruler" );
312 main( int argc, char *argv[] )
314 XtAppContext ctx;
315 Widget top_level, rc, button;
317 /* create a top-level shell for the window manager */
318 top_level = XtVaAppInitialize( &ctx,
319 argv[0],
320 NULL, 0, /* options */
321 (ArgcType) &argc,
322 argv, /* might get modified */
323 NULL,
324 NULL
327 rc = XtVaCreateManagedWidget( "rc",
328 xmRowColumnWidgetClass,
329 top_level,
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);
355 XtAppMainLoop(ctx);
357 #endif