Mercurial > hg > xemacs-beta
annotate lwlib/xlwgauge.c @ 5316:9ac28212c75a
#'cl-safe-expr-p, forms that start with the symbol lambda are also safe.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (cl-safe-expr-p):
Forms that start with the symbol lambda are also safe.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 29 Dec 2010 23:53:48 +0000 |
parents | 8b63e21b0436 |
children | 308d34e9f07d |
rev | line source |
---|---|
442 | 1 /* Gauge Widget for XEmacs. |
424 | 2 Copyright (C) 1999 Edward A. Falk |
3 | |
4 This file is part of XEmacs. | |
5 | |
6 XEmacs is free software; you can redistribute it and/or modify it | |
7 under the terms of the GNU General Public License as published by the | |
8 Free Software Foundation; either version 2, or (at your option) any | |
9 later version. | |
10 | |
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with XEmacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 Boston, MA 02111-1307, USA. */ | |
20 | |
21 /* Synched up with: Gauge.c 1.2 */ | |
22 | |
23 /* | |
24 * Gauge.c - Gauge widget | |
25 * | |
26 * Author: Edward A. Falk | |
27 * falk@falconer.vip.best.com | |
442 | 28 * |
424 | 29 * Date: July 9, 1997 |
30 * | |
31 * Note: for fun and demonstration purposes, I have added selection | |
32 * capabilities to this widget. If you select the widget, you create | |
33 * a primary selection containing the current value of the widget in | |
34 * both integer and string form. If you copy into the widget, the | |
35 * primary selection is converted to an integer value and the gauge is | |
36 * set to that value. | |
37 */ | |
38 | |
39 /* TODO: display time instead of value | |
40 */ | |
41 | |
42 #define DEF_LEN 50 /* default width (or height for vertical gauge) */ | |
43 #define MIN_LEN 10 /* minimum reasonable width (height) */ | |
44 #define TIC_LEN 6 /* length of tic marks */ | |
45 #define GA_WID 3 /* width of gauge */ | |
46 #define MS_PER_SEC 1000 | |
47 | |
48 #include <config.h> | |
49 #include <stdlib.h> | |
50 #include <stdio.h> | |
51 #include <ctype.h> | |
52 #include <X11/IntrinsicP.h> | |
53 #include <X11/Xatom.h> | |
54 #include <X11/StringDefs.h> | |
442 | 55 #include ATHENA_XawInit_h_ |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
56 #include "xt-wrappers.h" |
424 | 57 #include "xlwgaugeP.h" |
58 #include <X11/Xmu/Atoms.h> | |
59 #include <X11/Xmu/Drawing.h> | |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4528
diff
changeset
|
60 #include <X11/Xmu/Misc.h> |
424 | 61 #include <X11/Xmu/StdSel.h> |
62 | |
63 | |
64 /**************************************************************** | |
65 * | |
66 * Gauge resources | |
67 * | |
68 ****************************************************************/ | |
69 | |
70 | |
71 static char defaultTranslations[] = | |
72 "<Btn1Up>: select()\n\ | |
73 <Key>F1: select(CLIPBOARD)\n\ | |
74 <Btn2Up>: paste()\n\ | |
75 <Key>F2: paste(CLIPBOARD)" ; | |
76 | |
77 | |
78 | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
79 #define offset(field) XtOffsetOf(GaugeRec, gauge.field) |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
80 #define res(name,_class,intrepr,type,member,extrepr,value) \ |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
81 Xt_RESOURCE (name, _class, intrepr, type, offset(member), extrepr, value) |
424 | 82 static XtResource resources[] = { |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
83 res (XtNvalue, XtCValue, XtRInt, int, value, XtRImmediate, 0), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
84 res (XtNminValue, XtCMinValue, XtRInt, int, v0, XtRImmediate, 0), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
85 res (XtNmaxValue, XtCMaxValue, XtRInt, int, v1, XtRImmediate, 100), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
86 res (XtNntics, XtCNTics, XtRInt, int, ntics, XtRImmediate, 0), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
87 res (XtNnlabels, XtCNLabels, XtRInt, int, nlabels, XtRImmediate, 0), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
88 res (XtNlabels, XtCLabels, XtRStringArray, String *, labels, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
89 XtRStringArray, NULL), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
90 res (XtNautoScaleUp, XtCAutoScaleUp, XtRBoolean, Boolean, autoScaleUp, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
91 XtRImmediate, FALSE), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
92 res (XtNautoScaleDown, XtCAutoScaleDown, XtRBoolean, Boolean, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
93 autoScaleDown, XtRImmediate, FALSE), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
94 res (XtNorientation, XtCOrientation, XtROrientation, XtOrientation, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
95 orientation, XtRImmediate, XtorientHorizontal), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
96 res (XtNupdate, XtCInterval, XtRInt, int, update, XtRImmediate, 0), |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
97 res (XtNgetValue, XtCCallback, XtRCallback, XtPointer, getValue, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
98 XtRImmediate, NULL), |
424 | 99 }; |
100 #undef offset | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
101 #undef res |
424 | 102 |
103 | |
104 /* member functions */ | |
105 | |
106 static void GaugeClassInit (void); | |
107 static void GaugeInit (Widget, Widget, ArgList, Cardinal *); | |
108 static void GaugeDestroy (Widget); | |
109 static void GaugeResize (Widget); | |
110 static void GaugeExpose (Widget, XEvent *, Region); | |
111 static Boolean GaugeSetValues (Widget, Widget, Widget, ArgList, Cardinal *); | |
112 static XtGeometryResult GaugeQueryGeometry (Widget, XtWidgetGeometry *, | |
113 XtWidgetGeometry *); | |
114 | |
115 /* action procs */ | |
116 | |
117 static void GaugeSelect (Widget, XEvent *, String *, Cardinal *); | |
118 static void GaugePaste (Widget, XEvent *, String *, Cardinal *); | |
119 | |
120 /* internal privates */ | |
121 | |
122 static void GaugeSize (GaugeWidget, Dimension *, Dimension *, Dimension); | |
123 static void MaxLabel (GaugeWidget, Dimension *, Dimension *, | |
124 Dimension *, Dimension *); | |
125 static void AutoScale (GaugeWidget); | |
126 static void EnableUpdate (GaugeWidget); | |
127 static void DisableUpdate (GaugeWidget); | |
128 | |
129 static void GaugeGetValue (XtPointer, XtIntervalId *); | |
3968 | 130 static void GaugeMercury (Display *, Window, GC, GaugeWidget, int, int); |
424 | 131 |
132 static Boolean GaugeConvert (Widget, Atom *, Atom *, Atom *, | |
458 | 133 XtPointer *, unsigned long *, int *); |
424 | 134 static void GaugeLoseSel (Widget, Atom *); |
135 static void GaugeDoneSel (Widget, Atom *, Atom *); | |
136 static void GaugeGetSelCB (Widget, XtPointer, Atom *, Atom *, | |
458 | 137 XtPointer, unsigned long *, int *); |
424 | 138 |
139 static GC Get_GC (GaugeWidget, Pixel); | |
140 | |
141 | |
142 static XtActionsRec actionsList[] = | |
143 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
144 { (String) "select", GaugeSelect }, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
145 { (String) "paste", GaugePaste }, |
424 | 146 } ; |
147 | |
148 | |
149 | |
150 /**************************************************************** | |
151 * | |
152 * Full class record constant | |
153 * | |
154 ****************************************************************/ | |
155 | |
156 GaugeClassRec gaugeClassRec = { | |
157 { | |
442 | 158 /* core_class fields */ |
424 | 159 /* superclass */ (WidgetClass) &labelClassRec, |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
160 /* class_name */ (String) "Gauge", |
424 | 161 /* widget_size */ sizeof(GaugeRec), |
162 /* class_initialize */ GaugeClassInit, | |
163 /* class_part_initialize */ NULL, | |
164 /* class_inited */ FALSE, | |
165 /* initialize */ GaugeInit, | |
166 /* initialize_hook */ NULL, | |
167 /* realize */ XtInheritRealize, /* TODO? */ | |
168 /* actions */ actionsList, | |
169 /* num_actions */ XtNumber(actionsList), | |
170 /* resources */ resources, | |
171 /* num_resources */ XtNumber(resources), | |
172 /* xrm_class */ NULLQUARK, | |
173 /* compress_motion */ TRUE, | |
174 /* compress_exposure */ TRUE, | |
175 /* compress_enterleave */ TRUE, | |
176 /* visible_interest */ FALSE, | |
177 /* destroy */ GaugeDestroy, | |
178 /* resize */ GaugeResize, | |
179 /* expose */ GaugeExpose, | |
180 /* set_values */ GaugeSetValues, | |
181 /* set_values_hook */ NULL, | |
182 /* set_values_almost */ XtInheritSetValuesAlmost, | |
183 /* get_values_hook */ NULL, | |
184 /* accept_focus */ NULL, | |
185 /* version */ XtVersion, | |
186 /* callback_private */ NULL, | |
187 /* tm_table */ defaultTranslations, | |
188 /* query_geometry */ GaugeQueryGeometry, | |
189 /* display_accelerator */ XtInheritDisplayAccelerator, | |
190 /* extension */ NULL | |
191 }, | |
192 /* Simple class fields initialization */ | |
193 { | |
194 /* change_sensitive */ XtInheritChangeSensitive | |
195 }, | |
196 #ifdef _ThreeDP_h | |
197 /* ThreeD class fields initialization */ | |
198 { | |
199 XtInheritXaw3dShadowDraw /* shadowdraw */ | |
200 }, | |
201 #endif | |
202 /* Label class fields initialization */ | |
203 { | |
204 /* ignore */ 0 | |
205 }, | |
206 /* Gauge class fields initialization */ | |
207 { | |
208 /* extension */ NULL | |
209 }, | |
210 }; | |
211 | |
212 WidgetClass gaugeWidgetClass = (WidgetClass)&gaugeClassRec; | |
213 | |
214 | |
215 | |
216 | |
217 /**************************************************************** | |
218 * | |
219 * Member Procedures | |
220 * | |
221 ****************************************************************/ | |
222 | |
223 static void | |
224 GaugeClassInit (void) | |
225 { | |
226 XawInitializeWidgetSet(); | |
227 XtAddConverter(XtRString, XtROrientation, XmuCvtStringToOrientation, | |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4528
diff
changeset
|
228 NULL, 0) ; |
424 | 229 } |
230 | |
231 | |
232 | |
233 /* ARGSUSED */ | |
234 static void | |
235 GaugeInit (Widget request, | |
3055 | 236 Widget new_, |
2286 | 237 ArgList UNUSED (args), |
238 Cardinal *UNUSED (num_args)) | |
424 | 239 { |
3055 | 240 GaugeWidget gw = (GaugeWidget) new_; |
424 | 241 |
242 if( gw->gauge.v0 == 0 && gw->gauge.v1 == 0 ) { | |
243 gw->gauge.autoScaleUp = gw->gauge.autoScaleDown = TRUE ; | |
244 AutoScale(gw) ; | |
245 } | |
246 | |
247 /* If size not explicitly set, set it to our preferred size now. */ | |
248 | |
249 if( request->core.width == 0 || request->core.height == 0 ) | |
250 { | |
251 Dimension w,h ; | |
252 GaugeSize(gw, &w,&h, DEF_LEN) ; | |
253 if( request->core.width == 0 ) | |
3055 | 254 new_->core.width = w ; |
424 | 255 if( request->core.height == 0 ) |
3055 | 256 new_->core.height = h ; |
257 gw->core.widget_class->core_class.resize(new_) ; | |
424 | 258 } |
259 | |
260 gw->gauge.selected = None ; | |
261 gw->gauge.selstr = NULL ; | |
262 | |
263 if( gw->gauge.update > 0 ) | |
264 EnableUpdate(gw) ; | |
265 | |
266 gw->gauge.inverse_GC = Get_GC(gw, gw->core.background_pixel) ; | |
267 } | |
268 | |
269 static void | |
270 GaugeDestroy (Widget w) | |
271 { | |
272 GaugeWidget gw = (GaugeWidget)w; | |
273 | |
274 if( gw->gauge.selstr != NULL ) | |
275 XtFree(gw->gauge.selstr) ; | |
276 | |
277 if( gw->gauge.selected != None ) | |
278 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ; | |
279 | |
280 XtReleaseGC(w, gw->gauge.inverse_GC) ; | |
281 | |
282 if( gw->gauge.update > 0 ) | |
283 DisableUpdate(gw) ; | |
284 } | |
285 | |
286 | |
287 /* React to size change from manager. Label widget will compute some | |
288 * internal stuff, but we need to override. | |
289 */ | |
290 | |
291 static void | |
292 GaugeResize (Widget w) | |
293 { | |
294 GaugeWidget gw = (GaugeWidget)w; | |
295 int size ; /* height (width) of gauge */ | |
296 int vmargin ; /* vertical (horizontal) margin */ | |
297 int hmargin ; /* horizontal (vertical) margin */ | |
298 | |
299 vmargin = gw->gauge.orientation == XtorientHorizontal ? | |
300 gw->label.internal_height : gw->label.internal_width ; | |
301 hmargin = gw->gauge.orientation == XtorientHorizontal ? | |
302 gw->label.internal_width : gw->label.internal_height ; | |
303 | |
304 /* TODO: need to call parent resize proc? I don't think so since | |
305 * we're recomputing everything from scratch anyway. | |
306 */ | |
307 | |
308 /* find total height (width) of contents */ | |
309 | |
310 size = GA_WID+2 ; /* gauge itself + edges */ | |
311 | |
312 if( gw->gauge.ntics > 1 ) /* tic marks */ | |
313 size += vmargin + TIC_LEN ; | |
314 | |
315 if( gw->gauge.nlabels > 1 ) | |
316 { | |
4932 | 317 Dimension lwm, lw0=0, lw1 ;/* width of max, left, right labels */ |
424 | 318 Dimension lh ; |
319 | |
320 MaxLabel(gw,&lwm,&lh, &lw0,&lw1) ; | |
321 | |
322 if( gw->gauge.orientation == XtorientHorizontal ) | |
323 { | |
324 gw->gauge.margin0 = lw0 / 2 ; | |
325 gw->gauge.margin1 = lw1 / 2 ; | |
326 size += lh + vmargin ; | |
327 } | |
328 else | |
329 { | |
442 | 330 gw->gauge.margin0 = |
424 | 331 gw->gauge.margin1 = lh / 2 ; |
332 size += lwm + vmargin ; | |
333 } | |
334 } | |
335 else | |
336 gw->gauge.margin0 = gw->gauge.margin1 = 0 ; | |
337 | |
338 gw->gauge.margin0 += hmargin ; | |
339 gw->gauge.margin1 += hmargin ; | |
340 | |
341 /* Now distribute height (width) over components */ | |
342 | |
343 if( gw->gauge.orientation == XtorientHorizontal ) | |
344 gw->gauge.gmargin = (gw->core.height-size)/2 ; | |
345 else | |
346 gw->gauge.gmargin = (gw->core.width-size)/2 ; | |
347 | |
348 gw->gauge.tmargin = gw->gauge.gmargin + GA_WID+2 + vmargin ; | |
349 if( gw->gauge.ntics > 1 ) | |
350 gw->gauge.lmargin = gw->gauge.tmargin + TIC_LEN + vmargin ; | |
351 else | |
352 gw->gauge.lmargin = gw->gauge.tmargin ; | |
353 } | |
354 | |
355 /* | |
356 * Repaint the widget window | |
357 */ | |
358 | |
359 /* ARGSUSED */ | |
360 static void | |
361 GaugeExpose (Widget w, | |
2286 | 362 XEvent *UNUSED (event), |
363 Region UNUSED (region)) | |
424 | 364 { |
365 GaugeWidget gw = (GaugeWidget) w; | |
366 register Display *dpy = XtDisplay(w) ; | |
367 register Window win = XtWindow(w) ; | |
368 GC gc; /* foreground, background */ | |
369 GC gctop, gcbot ; /* dark, light shadows */ | |
370 | |
371 int len ; /* length (width or height) of widget */ | |
372 int e0,e1 ; /* ends of the gauge */ | |
373 int x ; | |
374 int y ; /* vertical (horizontal) position */ | |
375 int i ; | |
376 int v0 = gw->gauge.v0 ; | |
377 int v1 = gw->gauge.v1 ; | |
378 int value = gw->gauge.value ; | |
379 | |
380 gc = XtIsSensitive(w) ? gw->label.normal_GC : gw->label.gray_GC ; | |
381 | |
382 | |
383 #ifdef _ThreeDP_h | |
384 gctop = gw->threeD.bot_shadow_GC ; | |
385 gcbot = gw->threeD.top_shadow_GC ; | |
386 #else | |
387 gctop = gcbot = gc ; | |
388 #endif | |
389 | |
390 if( gw->gauge.orientation == XtorientHorizontal ) { | |
391 len = gw->core.width ; | |
392 } else { | |
393 len = gw->core.height ; | |
394 } | |
395 | |
396 /* if the gauge is selected, signify by drawing the background | |
442 | 397 * in a contrasting color. |
424 | 398 */ |
399 | |
400 if( gw->gauge.selected ) | |
401 { | |
402 XFillRectangle(dpy,win, gc, 0,0, w->core.width,w->core.height) ; | |
403 gc = gw->gauge.inverse_GC ; | |
404 } | |
405 | |
406 e0 = gw->gauge.margin0 ; /* left (top) end */ | |
407 e1 = len - gw->gauge.margin1 -1 ; /* right (bottom) end */ | |
408 | |
409 /* Draw the Gauge itself */ | |
410 | |
411 y = gw->gauge.gmargin ; | |
412 | |
413 if( gw->gauge.orientation == XtorientHorizontal ) /* horizontal */ | |
414 { | |
415 XDrawLine(dpy,win,gctop, e0+1,y, e1-1,y) ; | |
416 XDrawLine(dpy,win,gctop, e0,y+1, e0,y+GA_WID) ; | |
417 XDrawLine(dpy,win,gcbot, e0+1, y+GA_WID+1, e1-1, y+GA_WID+1) ; | |
418 XDrawLine(dpy,win,gcbot, e1,y+1, e1,y+GA_WID) ; | |
419 } | |
420 else /* vertical */ | |
421 { | |
422 XDrawLine(dpy,win,gctop, y,e0+1, y,e1-1) ; | |
423 XDrawLine(dpy,win,gctop, y+1,e0, y+GA_WID,e0) ; | |
424 XDrawLine(dpy,win,gcbot, y+GA_WID+1,e0+1, y+GA_WID+1, e1-1) ; | |
425 XDrawLine(dpy,win,gcbot, y+1,e1, y+GA_WID,e1) ; | |
426 } | |
427 | |
428 | |
429 /* draw the mercury */ | |
430 | |
431 GaugeMercury(dpy, win, gc, gw, 0,value) ; | |
432 | |
433 | |
434 if( gw->gauge.ntics > 1 ) | |
435 { | |
436 y = gw->gauge.tmargin ; | |
437 for(i=0; i<gw->gauge.ntics; ++i) | |
438 { | |
439 x = e0 + i*(e1-e0-1)/(gw->gauge.ntics-1) ; | |
440 if( gw->gauge.orientation == XtorientHorizontal ) { | |
441 XDrawLine(dpy,win,gcbot, x,y+1, x,y+TIC_LEN-2) ; | |
442 XDrawLine(dpy,win,gcbot, x,y, x+1,y) ; | |
443 XDrawLine(dpy,win,gctop, x+1,y+1, x+1,y+TIC_LEN-2) ; | |
444 XDrawLine(dpy,win,gctop, x,y+TIC_LEN-1, x+1,y+TIC_LEN-1) ; | |
445 } | |
446 else { | |
447 XDrawLine(dpy,win,gcbot, y+1,x, y+TIC_LEN-2,x) ; | |
448 XDrawLine(dpy,win,gcbot, y,x, y,x+1) ; | |
449 XDrawLine(dpy,win,gctop, y+1,x+1, y+TIC_LEN-2,x+1) ; | |
450 XDrawLine(dpy,win,gctop, y+TIC_LEN-1,x, y+TIC_LEN-1,x+1) ; | |
451 } | |
452 } | |
453 } | |
454 | |
455 /* draw labels */ | |
456 if( gw->gauge.nlabels > 1 ) | |
457 { | |
458 char label[20], *s = label ; | |
442 | 459 int xlen, wd,h =0 ; |
424 | 460 |
461 if( gw->gauge.orientation == XtorientHorizontal ) | |
462 y = gw->gauge.lmargin + gw->label.font->max_bounds.ascent - 1 ; | |
463 else { | |
464 y = gw->gauge.lmargin ; | |
465 h = gw->label.font->max_bounds.ascent / 2 ; | |
466 } | |
467 | |
468 for(i=0; i<gw->gauge.nlabels; ++i) | |
469 { | |
470 if( gw->gauge.labels == NULL ) | |
471 sprintf(label, "%d", v0+i*(v1 - v0)/(gw->gauge.nlabels - 1)) ; | |
472 else | |
473 s = gw->gauge.labels[i] ; | |
474 if( s != NULL ) { | |
475 x = e0 + i*(e1-e0-1)/(gw->gauge.nlabels-1) ; | |
442 | 476 xlen = strlen(s) ; |
424 | 477 if( gw->gauge.orientation == XtorientHorizontal ) { |
442 | 478 wd = XTextWidth(gw->label.font, s, xlen) ; |
479 XDrawString(dpy,win,gc, x-wd/2,y, s,xlen) ; | |
424 | 480 } |
481 else { | |
442 | 482 XDrawString(dpy,win,gc, y,x+h, s,xlen) ; |
424 | 483 } |
484 } | |
485 } | |
486 } | |
487 } | |
488 | |
489 | |
490 /* | |
491 * Set specified arguments into widget | |
492 */ | |
493 | |
494 static Boolean | |
495 GaugeSetValues (Widget old, | |
2286 | 496 Widget UNUSED (request), |
3055 | 497 Widget new_, |
2286 | 498 ArgList UNUSED (args), |
499 Cardinal *UNUSED (num_args)) | |
424 | 500 { |
501 GaugeWidget oldgw = (GaugeWidget) old; | |
3055 | 502 GaugeWidget gw = (GaugeWidget) new_; |
424 | 503 Boolean was_resized = False; |
504 | |
505 if( gw->gauge.selected != None ) { | |
3055 | 506 XtDisownSelection(new_, gw->gauge.selected, CurrentTime) ; |
424 | 507 gw->gauge.selected = None ; |
508 } | |
509 | |
510 /* Changes to v0,v1,labels, ntics, nlabels require resize & redraw. */ | |
511 /* Change to value requires redraw and possible resize if autoscale */ | |
512 | |
513 was_resized = | |
514 gw->gauge.v0 != oldgw->gauge.v0 || | |
515 gw->gauge.v1 != oldgw->gauge.v1 || | |
516 gw->gauge.ntics != oldgw->gauge.ntics || | |
517 gw->gauge.nlabels != oldgw->gauge.nlabels || | |
518 gw->gauge.labels != oldgw->gauge.labels ; | |
519 | |
520 if( (gw->gauge.autoScaleUp && gw->gauge.value > gw->gauge.v1) || | |
521 (gw->gauge.autoScaleDown && gw->gauge.value < gw->gauge.v1/3 )) | |
522 { | |
523 AutoScale(gw) ; | |
524 was_resized = TRUE ; | |
525 } | |
526 | |
527 if( was_resized ) { | |
528 if( gw->label.resize ) | |
529 GaugeSize(gw, &gw->core.width, &gw->core.height, DEF_LEN) ; | |
530 else | |
3055 | 531 GaugeResize(new_) ; |
424 | 532 } |
442 | 533 |
424 | 534 if( gw->gauge.update != oldgw->gauge.update ) |
535 { | |
536 if( gw->gauge.update > 0 ) | |
537 EnableUpdate(gw) ; | |
538 else | |
539 DisableUpdate(gw) ; | |
540 } | |
541 | |
542 if( gw->core.background_pixel != oldgw->core.background_pixel ) | |
543 { | |
3055 | 544 XtReleaseGC(new_, gw->gauge.inverse_GC) ; |
424 | 545 gw->gauge.inverse_GC = Get_GC(gw, gw->core.background_pixel) ; |
546 } | |
547 | |
548 return was_resized || gw->gauge.value != oldgw->gauge.value || | |
3055 | 549 XtIsSensitive(old) != XtIsSensitive(new_); |
424 | 550 } |
551 | |
552 | |
553 static XtGeometryResult | |
554 GaugeQueryGeometry (Widget w, | |
555 XtWidgetGeometry *intended, | |
556 XtWidgetGeometry *preferred) | |
557 { | |
558 register GaugeWidget gw = (GaugeWidget)w; | |
559 | |
560 if( intended->width == w->core.width && | |
561 intended->height == w->core.height ) | |
562 return XtGeometryNo ; | |
563 | |
564 preferred->request_mode = CWWidth | CWHeight; | |
565 GaugeSize(gw, &preferred->width, &preferred->height, DEF_LEN) ; | |
566 | |
567 if( (!(intended->request_mode & CWWidth) || | |
568 intended->width >= preferred->width) && | |
569 (!(intended->request_mode & CWHeight) || | |
570 intended->height >= preferred->height) ) | |
571 return XtGeometryYes; | |
572 else | |
573 return XtGeometryAlmost; | |
574 } | |
575 | |
576 | |
577 | |
578 | |
579 /**************************************************************** | |
580 * | |
581 * Action Procedures | |
582 * | |
583 ****************************************************************/ | |
584 | |
585 static void | |
586 GaugeSelect (Widget w, | |
587 XEvent *event, | |
588 String *params, | |
589 Cardinal *num_params) | |
590 { | |
591 GaugeWidget gw = (GaugeWidget)w ; | |
592 Atom seln = XA_PRIMARY ; | |
593 | |
594 if( gw->gauge.selected != None ) { | |
595 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ; | |
596 gw->gauge.selected = None ; | |
597 } | |
598 | |
599 if( *num_params > 0 ) { | |
600 seln = XInternAtom(XtDisplay(w), params[0], False) ; | |
601 printf("atom %s is %ld\n", params[0], seln) ; | |
602 } | |
603 | |
604 if( ! XtOwnSelection(w, seln, event->xbutton.time, GaugeConvert, | |
605 GaugeLoseSel, GaugeDoneSel) ) | |
606 { | |
607 /* in real code, this error message would be replaced by | |
608 * something more elegant, or at least deleted | |
609 */ | |
610 | |
611 fprintf(stderr, "Gauge failed to get selection, try again\n") ; | |
612 } | |
613 else | |
614 { | |
615 gw->gauge.selected = TRUE ; | |
616 gw->gauge.selstr = (String)XtMalloc(4*sizeof(int)) ; | |
617 sprintf(gw->gauge.selstr, "%d", gw->gauge.value) ; | |
618 GaugeExpose(w,0,0) ; | |
619 } | |
620 } | |
621 | |
622 | |
623 static Boolean | |
624 GaugeConvert (Widget w, | |
625 Atom *selection, /* usually XA_PRIMARY */ | |
626 Atom *target, /* requested target */ | |
627 Atom *type, /* returned type */ | |
628 XtPointer *value, /* returned value */ | |
458 | 629 unsigned long *length, /* returned length */ |
424 | 630 int *format) /* returned format */ |
631 { | |
632 GaugeWidget gw = (GaugeWidget)w ; | |
633 XSelectionRequestEvent *req ; | |
634 | |
635 printf( "requesting selection %s:%s\n", | |
636 XGetAtomName(XtDisplay(w),*selection), | |
637 XGetAtomName(XtDisplay(w),*target)); | |
638 | |
639 if( *target == XA_TARGETS(XtDisplay(w)) ) | |
640 { | |
2271 | 641 XPointer stdTargets; |
642 Atom *rval ; | |
458 | 643 unsigned long stdLength ; |
424 | 644 |
645 /* XmuConvertStandardSelection can handle this. This function | |
646 * will return a list of standard targets. We prepend TEXT, | |
647 * STRING and INTEGER to the list and return it. | |
648 */ | |
649 | |
650 req = XtGetSelectionRequest(w, *selection, NULL) ; | |
651 XmuConvertStandardSelection(w, req->time, selection, target, | |
2271 | 652 type, &stdTargets, &stdLength, format) ; |
424 | 653 |
654 *type = XA_ATOM ; /* TODO: needed? */ | |
655 *length = stdLength + 3 ; | |
656 rval = (Atom *) XtMalloc(sizeof(Atom)*(stdLength+3)) ; | |
657 *value = (XtPointer) rval ; | |
658 *rval++ = XA_INTEGER ; | |
659 *rval++ = XA_STRING ; | |
660 *rval++ = XA_TEXT(XtDisplay(w)) ; | |
2271 | 661 memcpy(rval, stdTargets, stdLength*sizeof(Atom)) ; |
424 | 662 XtFree((char*) stdTargets) ; |
663 *format = 8*sizeof(Atom) ; /* TODO: needed? */ | |
664 return True ; | |
665 } | |
666 | |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4528
diff
changeset
|
667 else if( *target == XA_INTEGER ) |
424 | 668 { |
669 *type = XA_INTEGER ; | |
670 *length = 1 ; | |
671 *value = (XtPointer) &gw->gauge.value ; | |
672 *format = 8*sizeof(int) ; | |
673 return True ; | |
674 } | |
675 | |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4528
diff
changeset
|
676 else if( *target == XA_STRING || *target == XA_TEXT(XtDisplay(w)) ) |
424 | 677 { |
678 *type = *target ; | |
679 *length = strlen(gw->gauge.selstr)*sizeof(char) ; | |
680 *value = (XtPointer) gw->gauge.selstr ; | |
681 *format = 8 ; | |
682 return True ; | |
683 } | |
684 | |
685 else | |
686 { | |
687 /* anything else, we just give it to XmuConvertStandardSelection() */ | |
688 req = XtGetSelectionRequest(w, *selection, NULL) ; | |
689 if( XmuConvertStandardSelection(w, req->time, selection, target, | |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4528
diff
changeset
|
690 type, (XPointer *) value, length, format) ) |
424 | 691 return True ; |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4528
diff
changeset
|
692 else { |
424 | 693 printf( |
694 "Gauge: requestor is requesting unsupported selection %s:%s\n", | |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4528
diff
changeset
|
695 XGetAtomName(XtDisplay(w),*selection), |
424 | 696 XGetAtomName(XtDisplay(w),*target)); |
697 return False ; | |
698 } | |
699 } | |
700 } | |
701 | |
702 | |
703 | |
704 static void | |
705 GaugeLoseSel (Widget w, | |
2286 | 706 Atom *UNUSED (selection)) /* usually XA_PRIMARY */ |
424 | 707 { |
708 GaugeWidget gw = (GaugeWidget)w ; | |
709 Display *dpy = XtDisplay(w) ; | |
710 Window win = XtWindow(w) ; | |
711 | |
712 if( gw->gauge.selstr != NULL ) { | |
713 XtFree(gw->gauge.selstr) ; | |
714 gw->gauge.selstr = NULL ; | |
715 } | |
716 | |
717 gw->gauge.selected = False ; | |
718 XClearWindow(dpy,win) ; | |
719 GaugeExpose(w,0,0) ; | |
720 } | |
721 | |
722 | |
723 static void | |
2286 | 724 GaugeDoneSel (Widget UNUSED (w), |
725 Atom *UNUSED (selection), /* usually XA_PRIMARY */ | |
726 Atom *UNUSED (target)) /* requested target */ | |
424 | 727 { |
728 /* selection done, anything to do? */ | |
729 } | |
730 | |
731 | |
732 static void | |
733 GaugePaste (Widget w, | |
734 XEvent *event, | |
735 String *params, | |
736 Cardinal *num_params) | |
737 { | |
738 Atom seln = XA_PRIMARY ; | |
739 | |
740 if( *num_params > 0 ) { | |
741 seln = XInternAtom(XtDisplay(w), params[0], False) ; | |
742 printf("atom %s is %ld\n", params[0], seln) ; | |
743 } | |
744 | |
745 /* try for integer value first */ | |
746 XtGetSelectionValue(w, seln, XA_INTEGER, | |
747 GaugeGetSelCB, (XtPointer)XA_INTEGER, | |
748 event->xbutton.time) ; | |
749 } | |
750 | |
751 static void | |
752 GaugeGetSelCB (Widget w, | |
753 XtPointer client, | |
754 Atom *selection, | |
755 Atom *type, | |
756 XtPointer value, | |
2286 | 757 unsigned long *UNUSED (length), |
758 int *UNUSED (format)) | |
424 | 759 { |
760 Display *dpy = XtDisplay(w) ; | |
761 Atom target = (Atom)client ; | |
762 int *iptr ; | |
763 char *cptr ; | |
764 | |
765 if( *type == XA_INTEGER ) { | |
766 iptr = (int *)value ; | |
767 XawGaugeSetValue(w, *iptr) ; | |
768 } | |
769 | |
4769
5460287a3327
Remove support for pre-X11R5 systems, including systems without Xmu. See
Jerry James <james@xemacs.org>
parents:
4528
diff
changeset
|
770 else if( *type == XA_STRING || *type == XA_TEXT(dpy) ) { |
424 | 771 cptr = (char *)value ; |
772 XawGaugeSetValue(w, atoi(cptr)) ; | |
773 } | |
774 | |
775 /* failed, try string */ | |
776 else if( *type == None && target == XA_INTEGER ) | |
777 XtGetSelectionValue(w, *selection, XA_STRING, | |
778 GaugeGetSelCB, (XtPointer)XA_STRING, | |
779 CurrentTime) ; | |
780 } | |
781 | |
782 | |
783 | |
784 /**************************************************************** | |
785 * | |
786 * Public Procedures | |
787 * | |
788 ****************************************************************/ | |
789 | |
790 | |
791 /* Change gauge value. Only undraw or draw what needs to be | |
792 * changed. | |
793 */ | |
794 | |
795 void | |
3968 | 796 XawGaugeSetValue (Widget w, int value) |
424 | 797 { |
798 GaugeWidget gw = (GaugeWidget)w ; | |
799 int oldvalue ; | |
800 GC gc ; | |
801 | |
802 if( gw->gauge.selected != None ) { | |
803 XtDisownSelection(w, gw->gauge.selected, CurrentTime) ; | |
804 gw->gauge.selected = None ; | |
805 } | |
806 | |
807 if( !XtIsRealized(w) ) { | |
808 gw->gauge.value = value ; | |
809 return ; | |
810 } | |
811 | |
812 /* need to rescale? */ | |
647 | 813 if(( gw->gauge.autoScaleUp && (int) value > gw->gauge.v1) || |
814 (gw->gauge.autoScaleDown && (int) value < gw->gauge.v1/3 )) | |
424 | 815 { |
3374 | 816 XtVaSetValues(w, XtNvalue, value, NULL) ; |
424 | 817 return ; |
818 } | |
819 | |
820 oldvalue = gw->gauge.value ; | |
821 gw->gauge.value = value ; | |
822 | |
823 gc = XtIsSensitive(w) ? gw->label.normal_GC : gw->label.gray_GC ; | |
824 GaugeMercury(XtDisplay(w), XtWindow(w), gc, gw, oldvalue,value) ; | |
825 } | |
826 | |
827 | |
3968 | 828 int |
424 | 829 XawGaugeGetValue (Widget w) |
830 { | |
831 GaugeWidget gw = (GaugeWidget)w ; | |
832 return gw->gauge.value ; | |
833 } | |
834 | |
835 | |
836 | |
837 | |
838 /**************************************************************** | |
839 * | |
840 * Private Procedures | |
841 * | |
842 ****************************************************************/ | |
843 | |
844 /* draw the mercury over a specific region */ | |
845 | |
846 static void | |
847 GaugeMercury (Display *dpy, | |
848 Window win, | |
849 GC gc, | |
850 GaugeWidget gw, | |
3968 | 851 int val0, |
852 int val1) | |
424 | 853 { |
854 int v0 = gw->gauge.v0 ; | |
855 int v1 = gw->gauge.v1 ; | |
856 int vd = v1 - v0 ; | |
857 Dimension len ; /* length (width or height) of gauge */ | |
858 Position e0, e1 ; /* gauge ends */ | |
859 Position p0, p1 ; /* mercury ends */ | |
860 int y ; /* vertical (horizontal) position */ | |
861 Boolean undraw = FALSE ; | |
862 | |
863 len = gw->gauge.orientation == XtorientHorizontal ? | |
864 gw->core.width : gw->core.height ; | |
865 | |
866 e0 = gw->gauge.margin0 ; /* left (top) end */ | |
867 e1 = len - gw->gauge.margin1 -1 ; /* right (bottom) end */ | |
868 | |
869 if( vd <= 0 ) vd = 1 ; | |
870 | |
3968 | 871 if( val0 < v0 ) val0 = v0 ; |
872 else if( val0 > v1 ) val0 = v1 ; | |
873 if( val1 < v0 ) val1 = v0 ; | |
874 else if( val1 > v1 ) val1 = v1 ; | |
424 | 875 |
876 p0 = (val0-v0)*(e1-e0-1)/vd ; | |
877 p1 = (val1-v0)*(e1-e0-1)/vd ; | |
878 | |
879 if( p1 == p0 ) | |
880 return ; | |
881 | |
882 y = gw->gauge.gmargin ; | |
883 | |
884 if( p1 < p0 ) | |
885 { | |
886 Position tmp = p0 ; | |
887 p0 = p1 ; | |
888 p1 = tmp ; | |
889 gc = gw->label.normal_GC ; | |
890 XSetForeground(dpy,gc, gw->core.background_pixel) ; | |
891 undraw = TRUE ; | |
892 } | |
893 | |
894 if( gw->gauge.orientation == XtorientHorizontal ) | |
895 XFillRectangle(dpy,win,gc, e0+p0+1,y+1, p1-p0,GA_WID) ; | |
896 else | |
897 XFillRectangle(dpy,win,gc, y+1,e1-p1, GA_WID,p1-p0) ; | |
898 | |
899 if( undraw ) | |
900 XSetForeground(dpy,gc, gw->label.foreground) ; | |
901 } | |
902 | |
903 | |
904 | |
905 /* Search the labels, find the largest one. */ | |
906 /* TODO: handle vertical fonts? */ | |
907 | |
908 static void | |
909 MaxLabel (GaugeWidget gw, | |
910 Dimension *wid, /* max label width */ | |
911 Dimension *hgt, /* max label height */ | |
912 Dimension *w0, /* width of first label */ | |
913 Dimension *w1) /* width of last label */ | |
914 { | |
915 char lstr[80], *lbl ; | |
916 int w ; | |
917 XFontStruct *font = gw->label.font ; | |
918 int i ; | |
919 int lw = 0; | |
920 int v0 = gw->gauge.v0 ; | |
921 int dv = gw->gauge.v1 - v0 ; | |
922 int n = gw->gauge.nlabels ; | |
923 | |
924 if( n > 0 ) | |
925 { | |
926 if( --n <= 0 ) {n = 1 ; v0 += dv/2 ;} | |
927 | |
928 /* loop through all labels, figure out how much room they | |
929 * need. | |
930 */ | |
931 w = 0 ; | |
932 for(i=0; i<gw->gauge.nlabels; ++i) | |
933 { | |
934 if( gw->gauge.labels == NULL ) /* numeric labels */ | |
935 sprintf(lbl = lstr,"%d", v0 + i*dv/n) ; | |
936 else | |
937 lbl = gw->gauge.labels[i] ; | |
938 | |
939 if( lbl != NULL ) { | |
940 lw = XTextWidth(font, lbl, strlen(lbl)) ; | |
941 w = Max( w, lw ) ; | |
942 } | |
943 else | |
944 lw = 0 ; | |
945 | |
946 if( i == 0 && w0 != NULL ) *w0 = lw ; | |
947 } | |
948 if( w1 != NULL ) *w1 = lw ; | |
949 | |
950 *wid = w ; | |
951 *hgt = font->max_bounds.ascent + font->max_bounds.descent ; | |
952 } | |
953 else | |
954 *wid = *hgt = 0 ; | |
955 } | |
956 | |
957 | |
958 /* Determine the preferred size for this widget. choose 100x100 for | |
959 * debugging. | |
960 */ | |
961 | |
962 static void | |
963 GaugeSize (GaugeWidget gw, | |
964 Dimension *wid, | |
965 Dimension *hgt, | |
966 Dimension min_len) | |
967 { | |
968 int w,h ; /* width, height of gauge */ | |
969 int vmargin ; /* vertical margin */ | |
970 int hmargin ; /* horizontal margin */ | |
971 | |
972 hmargin = gw->label.internal_width ; | |
973 vmargin = gw->label.internal_height ; | |
974 | |
975 /* find total height (width) of contents */ | |
976 | |
977 | |
978 /* find minimum size for undecorated gauge */ | |
979 | |
980 if( gw->gauge.orientation == XtorientHorizontal ) | |
981 { | |
982 w = min_len ; | |
983 h = GA_WID+2 ; /* gauge itself + edges */ | |
984 } | |
985 else | |
986 { | |
987 w = GA_WID+2 ; | |
988 h = min_len ; | |
989 } | |
990 | |
991 if( gw->gauge.ntics > 0 ) | |
992 { | |
993 if( gw->gauge.orientation == XtorientHorizontal ) | |
994 { | |
995 w = Max(w, gw->gauge.ntics*3) ; | |
996 h += vmargin + TIC_LEN ; | |
997 } | |
998 else | |
999 { | |
1000 w += hmargin + TIC_LEN ; | |
1001 h = Max(h, gw->gauge.ntics*3) ; | |
1002 } | |
1003 } | |
1004 | |
1005 | |
1006 /* If labels are requested, this gets a little interesting. | |
1007 * We want the end labels centered on the ends of the gauge and | |
1008 * the centers of the labels evenly spaced. The labels at the ends | |
1009 * will not be the same width, meaning that the gauge itself need | |
1010 * not be centered in the widget. | |
1011 * | |
1012 * First, determine the spacing. This is the width of the widest | |
1013 * label, plus the internal margin. Total length of the gauge is | |
1014 * spacing * (nlabels-1). To this, we add half the width of the | |
1015 * left-most label and half the width of the right-most label | |
1016 * to get the entire desired width of the widget. | |
1017 */ | |
1018 if( gw->gauge.nlabels > 0 ) | |
1019 { | |
4932 | 1020 Dimension lwm, lw0=0, lw1 ;/* width of max, left, right labels */ |
424 | 1021 Dimension lh ; |
1022 | |
1023 MaxLabel(gw,&lwm,&lh, &lw0,&lw1) ; | |
1024 | |
1025 if( gw->gauge.orientation == XtorientHorizontal ) | |
1026 { | |
1027 lwm = (lwm+hmargin) * (gw->gauge.nlabels-1) + (lw0+lw1)/2 ; | |
1028 w = Max(w, lwm) ; | |
1029 h += lh + vmargin ; | |
1030 } | |
1031 else | |
1032 { | |
1033 lh = lh*gw->gauge.nlabels + (gw->gauge.nlabels - 1)*vmargin ; | |
1034 h = Max(h, lh) ; | |
1035 w += lwm + hmargin ; | |
1036 } | |
1037 } | |
1038 | |
1039 w += hmargin*2 ; | |
1040 h += vmargin*2 ; | |
1041 | |
1042 *wid = w ; | |
1043 *hgt = h ; | |
1044 } | |
1045 | |
1046 | |
1047 | |
1048 static void | |
1049 AutoScale (GaugeWidget gw) | |
1050 { | |
1051 static int scales[3] = {1,2,5} ; | |
1052 int sptr = 0, smult=1 ; | |
1053 | |
1054 if( gw->gauge.autoScaleDown ) | |
1055 gw->gauge.v1 = 0 ; | |
1056 while( gw->gauge.value > gw->gauge.v1 ) | |
1057 { | |
1058 if( ++sptr > 2 ) { | |
1059 sptr = 0 ; | |
1060 smult *= 10 ; | |
1061 } | |
1062 gw->gauge.v1 = scales[sptr] * smult ; | |
1063 } | |
1064 } | |
1065 | |
1066 static void | |
1067 EnableUpdate (GaugeWidget gw) | |
1068 { | |
1069 gw->gauge.intervalId = | |
1070 XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)gw), | |
1071 gw->gauge.update * MS_PER_SEC, GaugeGetValue, | |
1072 (XtPointer)gw) ; | |
1073 } | |
1074 | |
1075 static void | |
1076 DisableUpdate (GaugeWidget gw) | |
1077 { | |
1078 XtRemoveTimeOut(gw->gauge.intervalId) ; | |
1079 } | |
1080 | |
1081 static void | |
1082 GaugeGetValue (XtPointer clientData, | |
2286 | 1083 XtIntervalId *UNUSED (intervalId)) |
424 | 1084 { |
1085 GaugeWidget gw = (GaugeWidget)clientData ; | |
3968 | 1086 int value ; |
424 | 1087 |
1088 if( gw->gauge.update > 0 ) | |
1089 EnableUpdate(gw) ; | |
1090 | |
1091 if( gw->gauge.getValue != NULL ) | |
1092 { | |
1093 XtCallCallbackList((Widget)gw, gw->gauge.getValue, (XtPointer)&value); | |
1094 XawGaugeSetValue((Widget)gw, value) ; | |
1095 } | |
1096 } | |
1097 | |
1098 | |
1099 static GC | |
1100 Get_GC (GaugeWidget gw, | |
1101 Pixel fg) | |
1102 { | |
1103 XGCValues values ; | |
1104 #define vmask GCForeground | |
1105 #define umask (GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset\ | |
1106 |GCFont|GCDashList|GCArcMode) | |
1107 | |
1108 values.foreground = fg ; | |
1109 | |
1110 return XtAllocateGC((Widget)gw, 0, vmask, &values, 0L, umask) ; | |
1111 } |