]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: gauge.cpp | |
3 | // Purpose: wxGauge class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "gauge.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/gauge.h" | |
17 | ||
89c7e962 JS |
18 | #include <Xm/Xm.h> |
19 | #include <wx/motif/private.h> | |
20 | ||
4bb6408c JS |
21 | #if !USE_SHARED_LIBRARY |
22 | IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) | |
23 | #endif | |
24 | ||
89c7e962 JS |
25 | // XmGauge copyright notice: |
26 | ||
27 | /* | |
2d120f83 JS |
28 | * Copyright 1994 GROUPE BULL |
29 | * | |
30 | * Permission to use, copy, modify, and distribute this software and its | |
31 | * documentation for any purpose and without fee is hereby granted, provided | |
32 | * that the above copyright notice appear in all copies and that both that | |
33 | * copyright notice and this permission notice appear in supporting | |
34 | * documentation, and that the name of GROUPE BULL not be used in advertising | |
35 | * or publicity pertaining to distribution of the software without specific, | |
36 | * written prior permission. GROUPE BULL makes no representations about the | |
37 | * suitability of this software for any purpose. It is provided "as is" | |
38 | * without express or implied warranty. | |
39 | * | |
40 | * GROUPE BULL disclaims all warranties with regard to this software, | |
41 | * including all implied warranties of merchantability and fitness, | |
42 | * in no event shall GROUPE BULL be liable for any special, | |
43 | * indirect or consequential damages or any damages | |
44 | * whatsoever resulting from loss of use, data or profits, | |
45 | * whether in an action of contract, negligence or other tortious | |
46 | * action, arising out of or in connection with the use | |
47 | * or performance of this software. | |
48 | * | |
49 | */ | |
89c7e962 JS |
50 | |
51 | //// PUBLIC XMGAUGE DECLARATIONS | |
52 | typedef struct _XmGaugeClassRec* XmGaugeWidgetClass; | |
53 | typedef struct _XmGaugeRec* XmGaugeWidget; | |
54 | ||
55 | #ifdef __cplusplus | |
56 | extern "C" WidgetClass xmGaugeWidgetClass; | |
57 | #else | |
58 | extern WidgetClass xmGaugeWidgetClass; | |
59 | #endif | |
60 | ||
61 | typedef struct _XmGaugeCallbackStruct{ | |
62 | int reason; | |
63 | XEvent *event; | |
64 | int value; | |
65 | } XmGaugeCallbackStruct; | |
66 | ||
67 | ||
68 | void | |
69 | XmGaugeSetValue(Widget w, int value); | |
70 | ||
71 | int | |
72 | XmGaugeGetValue(Widget w); | |
73 | ||
74 | ||
75 | ||
4bb6408c | 76 | bool wxGauge::Create(wxWindow *parent, wxWindowID id, |
2d120f83 JS |
77 | int range, |
78 | const wxPoint& pos, | |
79 | const wxSize& size, | |
80 | long style, | |
81 | const wxValidator& validator, | |
82 | const wxString& name) | |
4bb6408c JS |
83 | { |
84 | SetName(name); | |
85 | SetValidator(validator); | |
86 | m_rangeMax = range; | |
87 | m_windowStyle = style; | |
0d57be45 JS |
88 | m_backgroundColour = parent->GetBackgroundColour(); |
89 | m_foregroundColour = parent->GetForegroundColour(); | |
2d120f83 | 90 | |
4bb6408c | 91 | if (parent) parent->AddChild(this); |
2d120f83 | 92 | |
4bb6408c | 93 | if ( id == -1 ) |
2d120f83 | 94 | m_windowId = (int)NewControlId(); |
4bb6408c | 95 | else |
2d120f83 JS |
96 | m_windowId = id; |
97 | ||
89c7e962 | 98 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
2d120f83 | 99 | |
89c7e962 JS |
100 | Arg args[4]; |
101 | int count = 4; | |
102 | if (style & wxHORIZONTAL) | |
103 | { | |
104 | XtSetArg (args[0], XmNorientation, XmHORIZONTAL); | |
105 | XtSetArg (args[1], XmNprocessingDirection, XmMAX_ON_RIGHT); | |
106 | } | |
107 | else | |
108 | { | |
109 | XtSetArg (args[0], XmNorientation, XmVERTICAL); | |
110 | XtSetArg (args[1], XmNprocessingDirection, XmMAX_ON_TOP); | |
111 | } | |
112 | XtSetArg(args[2], XmNminimum, 0); | |
113 | XtSetArg(args[3], XmNmaximum, range); | |
114 | Widget gaugeWidget = XtCreateManagedWidget("gauge", xmGaugeWidgetClass, parentWidget, args, count); | |
115 | m_mainWidget = (WXWidget) gaugeWidget ; | |
2d120f83 | 116 | |
89c7e962 | 117 | XtManageChild (gaugeWidget); |
2d120f83 | 118 | |
89c7e962 JS |
119 | int x = pos.x; int y = pos.y; |
120 | int width = size.x; int height = size.y; | |
121 | if (width == -1) | |
122 | width = 150; | |
123 | if (height == -1) | |
124 | height = 80; | |
2d120f83 | 125 | |
4b5f3fe6 JS |
126 | m_windowFont = parent->GetFont(); |
127 | ChangeFont(FALSE); | |
2d120f83 | 128 | |
89c7e962 JS |
129 | SetCanAddEventHandler(TRUE); |
130 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height); | |
2d120f83 | 131 | |
0d57be45 | 132 | ChangeBackgroundColour(); |
2d120f83 | 133 | |
89c7e962 | 134 | return TRUE; |
4bb6408c JS |
135 | } |
136 | ||
137 | void wxGauge::SetSize(int x, int y, int width, int height, int sizeFlags) | |
138 | { | |
89c7e962 | 139 | wxControl::SetSize(x, y, width, height, sizeFlags); |
4bb6408c JS |
140 | } |
141 | ||
142 | void wxGauge::SetShadowWidth(int w) | |
143 | { | |
89c7e962 JS |
144 | if (w == 0) |
145 | w = 1; | |
146 | XtVaSetValues((Widget) m_mainWidget, XmNshadowThickness, w, NULL); | |
4bb6408c JS |
147 | } |
148 | ||
149 | void wxGauge::SetBezelFace(int w) | |
150 | { | |
4bb6408c JS |
151 | } |
152 | ||
153 | void wxGauge::SetRange(int r) | |
154 | { | |
155 | m_rangeMax = r; | |
89c7e962 | 156 | XtVaSetValues((Widget) m_mainWidget, XmNmaximum, r, NULL); |
4bb6408c JS |
157 | } |
158 | ||
159 | void wxGauge::SetValue(int pos) | |
160 | { | |
161 | m_gaugePos = pos; | |
89c7e962 | 162 | XtVaSetValues((Widget) m_mainWidget, XmNvalue, pos, NULL); |
4bb6408c JS |
163 | } |
164 | ||
165 | int wxGauge::GetShadowWidth() const | |
166 | { | |
89c7e962 JS |
167 | Dimension w; |
168 | XtVaGetValues((Widget) m_mainWidget, XmNshadowThickness, &w, NULL); | |
169 | return (int)w; | |
4bb6408c JS |
170 | } |
171 | ||
172 | int wxGauge::GetBezelFace() const | |
173 | { | |
4bb6408c JS |
174 | return 0; |
175 | } | |
176 | ||
177 | int wxGauge::GetRange() const | |
178 | { | |
89c7e962 JS |
179 | int r; |
180 | XtVaGetValues((Widget) m_mainWidget, XmNmaximum, &r, NULL); | |
181 | return (int)r; | |
2d120f83 | 182 | // return m_rangeMax; |
4bb6408c JS |
183 | } |
184 | ||
185 | int wxGauge::GetValue() const | |
186 | { | |
2d120f83 JS |
187 | int pos; |
188 | XtVaGetValues((Widget) m_mainWidget, XmNvalue, &pos, NULL); | |
189 | return pos; | |
190 | // return m_gaugePos; | |
89c7e962 JS |
191 | } |
192 | ||
4b5f3fe6 | 193 | void wxGauge::ChangeFont(bool keepOriginalSize) |
0d57be45 | 194 | { |
4b5f3fe6 | 195 | wxWindow::ChangeFont(keepOriginalSize); |
0d57be45 JS |
196 | } |
197 | ||
198 | void wxGauge::ChangeBackgroundColour() | |
199 | { | |
321db4b6 | 200 | wxWindow::ChangeBackgroundColour(); |
0d57be45 JS |
201 | } |
202 | ||
203 | void wxGauge::ChangeForegroundColour() | |
204 | { | |
321db4b6 | 205 | wxWindow::ChangeForegroundColour(); |
0d57be45 JS |
206 | } |
207 | ||
89c7e962 JS |
208 | //// PRIVATE DECLARATIONS FOR XMGAUGE |
209 | ||
210 | #include <Xm/PrimitiveP.h> | |
211 | #include <Xm/DrawP.h> | |
212 | ||
213 | typedef struct { | |
214 | int empty; | |
215 | } XmGaugeClassPart; | |
216 | ||
217 | typedef struct _XmGaugeClassRec { | |
218 | CoreClassPart core_class; | |
219 | XmPrimitiveClassPart primitive_class; | |
220 | XmGaugeClassPart gauge_class; | |
221 | } XmGaugeClassRec; | |
222 | ||
223 | ||
224 | typedef struct _XmGaugePart{ | |
225 | int value; | |
226 | int minimum; | |
227 | int maximum; | |
228 | unsigned char orientation; | |
229 | unsigned char processingDirection; | |
2d120f83 | 230 | |
89c7e962 JS |
231 | XtCallbackList dragCallback; |
232 | XtCallbackList valueChangedCallback; | |
233 | ||
234 | /* private fields */ | |
235 | Boolean dragging; /* drag in progress ? */ | |
236 | int oldx, oldy; | |
237 | GC gc; | |
238 | } XmGaugePart; | |
239 | ||
240 | ||
241 | typedef struct _XmGaugeRec { | |
242 | CorePart core; | |
243 | XmPrimitivePart primitive; | |
244 | XmGaugePart gauge; | |
245 | } XmGaugeRec; | |
246 | ||
247 | extern XmGaugeClassRec xmGaugeClassRec; | |
248 | ||
249 | /* Copyright 1994 GROUPE BULL -- See license conditions in file COPYRIGHT */ | |
250 | ||
251 | //// XMGAUGE IMPLEMENTATION | |
252 | ||
253 | void | |
254 | GaugePick(Widget w, XEvent *e, String *args, Cardinal *num_args); | |
255 | void | |
256 | GaugeDrag(Widget w, XEvent *e, String *args, Cardinal *num_args); | |
257 | void | |
258 | GaugeDrop(Widget w, XEvent *e, String *args, Cardinal *num_args); | |
259 | ||
260 | ||
261 | ||
262 | static char translations[] = | |
263 | "<Btn1Down>: GaugePick()\n\ | |
2d120f83 JS |
264 | <Btn1Motion>: GaugeDrag()\n\ |
265 | <Btn1Up>: GaugeDrop()\n\ | |
266 | "; | |
89c7e962 JS |
267 | |
268 | ||
269 | ||
270 | static XtActionsRec actions[] = { | |
271 | {"GaugePick", GaugePick}, | |
272 | {"GaugeDrag", GaugeDrag}, | |
273 | {"GaugeDrop", GaugeDrop}, | |
274 | }; | |
275 | ||
276 | static void | |
277 | DrawSlider(XmGaugeWidget gw, Boolean clear) | |
278 | { | |
279 | #define THIS gw->gauge | |
280 | int size, sht; | |
281 | float ratio; | |
2d120f83 | 282 | /***chubraev |
89c7e962 JS |
283 | char string[20]; |
284 | int len; | |
285 | unsigned long backgr,foregr; | |
286 | XRectangle rects[1]; | |
2d120f83 | 287 | ***/ |
89c7e962 JS |
288 | |
289 | sht = gw->primitive.shadow_thickness; | |
2d120f83 | 290 | |
89c7e962 | 291 | ratio = (float)THIS.value/ |
2d120f83 JS |
292 | (float)(THIS.maximum - THIS.minimum); |
293 | /***chubraev | |
294 | sprintf(string,"%-d%%",(int)(ratio*100)); | |
295 | len=strlen(string); | |
296 | XtVaGetValues(gw,XmNbackground,&backgr,XmNforeground,&foregr,NULL); | |
297 | ***/ | |
298 | ||
89c7e962 | 299 | if(clear) { |
2d120f83 JS |
300 | XClearArea(XtDisplay(gw), XtWindow(gw), sht, sht, |
301 | gw->core.width - 2 * sht, gw->core.height - 2 * sht, False); | |
89c7e962 JS |
302 | } |
303 | switch(THIS.orientation) { | |
304 | case XmHORIZONTAL: | |
2d120f83 JS |
305 | size = (int) ((gw->core.width - 2 * sht)*ratio); |
306 | /***chubraev | |
307 | XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht+gw->core.width/2, | |
308 | gw->core.height - 2 * sht, string, len); | |
309 | ***/ | |
310 | switch(THIS.processingDirection) { | |
311 | case XmMAX_ON_RIGHT: | |
312 | case XmMAX_ON_BOTTOM: | |
313 | XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, | |
314 | sht, sht, size, gw->core.height - 2 * sht); | |
89c7e962 | 315 | |
2d120f83 JS |
316 | /***chubraev |
317 | rects[0].x = sht; rects[0].y = sht; | |
318 | rects[0].width = size; rects[0].height = gw->core.height - 2 * sht; | |
319 | ***/ | |
320 | break; | |
321 | case XmMAX_ON_LEFT: | |
322 | case XmMAX_ON_TOP: | |
323 | XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, | |
324 | gw->core.width - size - sht, sht, | |
325 | size, gw->core.height - 2 * sht); | |
326 | ||
327 | /***chubraev | |
328 | rects[0].x = gw->core.width - size - sht; rects[0].y = sht; | |
329 | rects[0].width = size; rects[0].height = gw->core.height - 2 * sht; | |
330 | ***/ | |
331 | break; | |
332 | } | |
89c7e962 JS |
333 | /***chubraev |
334 | XSetClipRectangles(XtDisplay(gw), THIS.gc, 0, 0, rects, 1, Unsorted); | |
2d120f83 JS |
335 | XSetForeground(XtDisplay(gw), THIS.gc, backgr); |
336 | XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht+gw->core.width/2, | |
337 | gw->core.height - 2 * sht, string, len); | |
338 | ***/ | |
339 | ||
340 | break; | |
341 | case XmVERTICAL: | |
342 | size = (int) ((gw->core.height - 2 * sht)*ratio); | |
89c7e962 | 343 | /***chubraev |
2d120f83 JS |
344 | XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht, |
345 | sht+gw->core.height/2, string,len); | |
346 | ***/ | |
347 | switch(THIS.processingDirection) { | |
348 | case XmMAX_ON_RIGHT: | |
349 | case XmMAX_ON_BOTTOM: | |
350 | XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, | |
351 | sht, sht, gw->core.width - 2 * sht, size); | |
352 | ||
353 | /***chubraev | |
354 | rects[0].x = sht; rects[0].y = sht; | |
355 | rects[0].width = gw->core.width - 2 * sht; rects[0].height = size; | |
356 | ***/ | |
357 | break; | |
358 | case XmMAX_ON_LEFT: | |
359 | case XmMAX_ON_TOP: | |
360 | XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, | |
361 | sht, gw->core.height - size - sht, | |
362 | gw->core.width - 2 * sht, size); | |
363 | ||
364 | /***chubraev | |
365 | rects[0].x = sht; rects[0].y = gw->core.height - size - sht; | |
366 | rects[0].width = gw->core.width - 2 * sht; rects[0].height = size; | |
367 | ***/ | |
368 | } | |
89c7e962 | 369 | /***chubraev |
2d120f83 JS |
370 | XSetClipRectangles(XtDisplay(gw), THIS.gc, 0, 0, rects, 1, Unsorted); |
371 | XSetForeground(XtDisplay(gw), THIS.gc, backgr); | |
372 | XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht, | |
373 | sht+gw->core.height/2, string,len); | |
374 | ***/ | |
375 | break; | |
89c7e962 JS |
376 | } |
377 | /***chubraev | |
378 | XSetClipMask(XtDisplay(gw), THIS.gc, None); | |
379 | XSetForeground(XtDisplay(gw), THIS.gc, foregr); | |
380 | ***/ | |
381 | #undef THIS | |
382 | } | |
383 | ||
384 | /* Old code | |
2d120f83 | 385 | */ |
89c7e962 JS |
386 | #if 0 |
387 | static void | |
388 | DrawSlider(XmGaugeWidget gw, Boolean clear) | |
389 | { | |
390 | #define THIS gw->gauge | |
391 | int size, sht; | |
2d120f83 JS |
392 | /* float ratio; */ |
393 | ||
89c7e962 | 394 | sht = gw->primitive.shadow_thickness; |
2d120f83 | 395 | /* See fix comment below: can cause divide by zero error. |
89c7e962 | 396 | ratio = (float)((float)THIS.maximum - |
2d120f83 JS |
397 | (float)THIS.minimum) / (float)THIS.value; |
398 | */ | |
89c7e962 | 399 | if(clear) { |
2d120f83 JS |
400 | XClearArea(XtDisplay(gw), XtWindow(gw), sht, sht, |
401 | gw->core.width - 2 * sht, gw->core.height - 2 * sht, False); | |
89c7e962 JS |
402 | } |
403 | switch(THIS.orientation) { | |
404 | case XmHORIZONTAL: | |
2d120f83 JS |
405 | /* size = (gw->core.width - 2 * sht) / ratio; */ |
406 | /* A fix suggested by Dmitri Chubraev */ | |
89c7e962 | 407 | size = (gw->core.width - 2 * sht) /((float)THIS.maximum-(float)THIS.minimum)*(float)THIS.value; |
2d120f83 JS |
408 | switch(THIS.processingDirection) { |
409 | case XmMAX_ON_RIGHT: | |
410 | case XmMAX_ON_BOTTOM: | |
411 | XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, | |
412 | sht, sht, size, gw->core.height - 2 * sht); | |
413 | break; | |
414 | case XmMAX_ON_LEFT: | |
415 | case XmMAX_ON_TOP: | |
416 | XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, | |
417 | gw->core.width - size - sht, sht, | |
418 | size, gw->core.height - 2 * sht); | |
419 | break; | |
420 | } | |
421 | break; | |
422 | case XmVERTICAL: | |
423 | size = (gw->core.height - 2 * sht) /((float)THIS.maximum-(float)THIS.minimum)*(float)THIS.value; | |
424 | /* size = (gw->core.height - 2 * sht)/ ratio; */ | |
425 | switch(THIS.processingDirection) { | |
426 | case XmMAX_ON_RIGHT: | |
427 | case XmMAX_ON_BOTTOM: | |
428 | XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, | |
429 | sht, sht, gw->core.width - 2 * sht, size); | |
430 | break; | |
431 | case XmMAX_ON_LEFT: | |
432 | case XmMAX_ON_TOP: | |
433 | XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, | |
434 | sht, gw->core.height - size - sht, | |
435 | gw->core.width - 2 * sht, size); | |
436 | } | |
437 | break; | |
89c7e962 JS |
438 | } |
439 | #undef THIS | |
440 | } | |
441 | #endif | |
442 | ||
443 | static void | |
444 | Initialize(Widget req, Widget new_w, ArgList args, Cardinal *num_args ) | |
445 | { | |
446 | XmGaugeWidget gw = (XmGaugeWidget)new_w; | |
447 | #define THIS gw->gauge | |
448 | XGCValues values; | |
2d120f83 | 449 | |
89c7e962 JS |
450 | values.foreground = gw->primitive.foreground; |
451 | THIS.gc = XtGetGC(new_w, GCForeground, &values); | |
452 | ||
453 | #undef THIS | |
454 | ||
455 | } | |
456 | ||
457 | ||
458 | ||
459 | static void | |
460 | Destroy(Widget w) | |
461 | { | |
462 | XmGaugeWidget gw = (XmGaugeWidget)w; | |
463 | #define THIS gw->gauge | |
464 | XtReleaseGC(w, THIS.gc); | |
465 | #undef THIS | |
466 | } | |
467 | ||
468 | ||
469 | ||
2d120f83 | 470 | |
89c7e962 JS |
471 | static Boolean |
472 | SetValues( | |
2d120f83 JS |
473 | Widget cw, |
474 | Widget rw, | |
475 | Widget nw, | |
476 | ArgList args, | |
477 | Cardinal *num_args ) | |
89c7e962 JS |
478 | { |
479 | XmGaugeWidget cgw = (XmGaugeWidget)cw; | |
480 | XmGaugeWidget ngw = (XmGaugeWidget)nw; | |
2d120f83 | 481 | |
89c7e962 JS |
482 | Boolean redraw = False; |
483 | if(cgw->primitive.foreground != ngw->primitive.foreground) { | |
2d120f83 JS |
484 | XGCValues values; |
485 | ||
486 | redraw = True; | |
487 | XtReleaseGC(nw, ngw->gauge.gc); | |
488 | values.foreground = ngw->primitive.foreground; | |
489 | ngw->gauge.gc = XtGetGC(nw, GCForeground, &values); | |
89c7e962 JS |
490 | } |
491 | if(cgw->gauge.value != ngw->gauge.value) { | |
2d120f83 | 492 | redraw = True; |
89c7e962 JS |
493 | } |
494 | return redraw; | |
495 | } | |
496 | ||
497 | ||
498 | ||
499 | ||
500 | static void | |
501 | ExposeProc(Widget w, XEvent *event, Region r) | |
502 | { | |
503 | XmGaugeWidget gw = (XmGaugeWidget)w; | |
504 | #define THIS gw->gauge | |
505 | int sht; | |
2d120f83 | 506 | |
89c7e962 JS |
507 | sht = gw->primitive.shadow_thickness; |
508 | _XmDrawShadows(XtDisplay(w), XtWindow(w), | |
2d120f83 JS |
509 | gw->primitive.top_shadow_GC, |
510 | gw->primitive.bottom_shadow_GC, | |
511 | 0, 0, w->core.width, w->core.height, | |
512 | sht, XmSHADOW_IN); | |
89c7e962 JS |
513 | DrawSlider(gw, False); |
514 | #undef THIS | |
515 | } | |
516 | ||
517 | ||
518 | ||
519 | ||
520 | ||
521 | static XtResource | |
522 | resources[] = { | |
523 | #define offset(field) XtOffset(XmGaugeWidget, gauge.field) | |
2d120f83 JS |
524 | {XmNvalue, XmCValue, XtRInt, sizeof(int), |
525 | offset(value), XtRImmediate, (caddr_t)10}, | |
526 | ||
527 | {XmNminimum, XmCValue, XtRInt, sizeof(int), | |
528 | offset(minimum), XtRImmediate, (caddr_t)0}, | |
529 | ||
530 | {XmNmaximum, XmCValue, XtRInt, sizeof(int), | |
531 | offset(maximum), XtRImmediate, (caddr_t)100}, | |
532 | ||
533 | {XmNorientation, XmCOrientation, XmROrientation, sizeof(unsigned char), | |
534 | offset(orientation), XtRImmediate, (caddr_t)XmVERTICAL}, | |
535 | ||
536 | {XmNprocessingDirection, XmCProcessingDirection, | |
537 | XmRProcessingDirection, sizeof(unsigned char), | |
538 | offset(processingDirection), XtRImmediate, (caddr_t)XmMAX_ON_RIGHT}, | |
539 | ||
540 | {XmNdragCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList), | |
541 | offset(dragCallback), XtRImmediate, (caddr_t)NULL}, | |
542 | ||
543 | {XmNvalueChangedCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList), | |
544 | offset(valueChangedCallback), XtRImmediate, (caddr_t)NULL}, | |
545 | ||
546 | ||
89c7e962 JS |
547 | #undef offset |
548 | }; | |
549 | ||
550 | ||
551 | XmGaugeClassRec xmGaugeClassRec = { | |
552 | { /* core fields */ | |
2d120f83 JS |
553 | (WidgetClass) &xmPrimitiveClassRec, /* superclass */ |
554 | "XmGauge", /* class_name */ | |
555 | sizeof(XmGaugeRec), /* widget_size */ | |
556 | NULL, /* class_initialize */ | |
557 | NULL, /* class_part_initialize */ | |
558 | FALSE, /* class_inited */ | |
559 | Initialize, /* initialize */ | |
560 | NULL, /* initialize_hook */ | |
561 | XtInheritRealize, /* realize */ | |
562 | actions, /* actions */ | |
563 | XtNumber(actions), /* num_actions */ | |
564 | resources, /* resources */ | |
565 | XtNumber(resources), /* num_resources */ | |
566 | NULLQUARK, /* xrm_class */ | |
567 | TRUE, /* compress_motion */ | |
568 | TRUE, /* compress_exposure */ | |
569 | TRUE, /* compress_enterleave */ | |
570 | FALSE, /* visible_interest */ | |
571 | Destroy, /* destroy */ | |
572 | NULL, /* resize */ | |
573 | ExposeProc, /* expose */ | |
574 | SetValues, /* set_values */ | |
575 | NULL, /* set_values_hook */ | |
576 | XtInheritSetValuesAlmost, /* set_values_almost */ | |
577 | NULL, /* get_values_hook */ | |
578 | NULL, /* accept_focus */ | |
579 | XtVersion, /* version */ | |
580 | NULL, /* callback_private */ | |
581 | translations, /* tm_table */ | |
582 | NULL, /* query_geometry */ | |
583 | NULL, /* display_accelerator */ | |
584 | NULL /* extension */ | |
89c7e962 JS |
585 | }, |
586 | /* primitive_class fields */ | |
587 | { | |
2d120f83 JS |
588 | NULL, /* border_highlight */ |
589 | NULL, /* border_unhighlight */ | |
590 | NULL, /* translations */ | |
591 | NULL, /* arm_and_activate */ | |
592 | NULL, /* syn_resources */ | |
593 | 0, /* num_syn_resources */ | |
594 | NULL /* extension */ | |
595 | }, | |
596 | { /* gauge fields */ | |
597 | 0 /* empty */ | |
598 | } | |
89c7e962 JS |
599 | }; |
600 | ||
601 | WidgetClass xmGaugeWidgetClass = (WidgetClass)&xmGaugeClassRec; | |
602 | ||
603 | ||
604 | ||
605 | ||
606 | void | |
607 | GaugePick(Widget w, XEvent *e, String *args, Cardinal *num_args) | |
608 | { | |
2d120f83 | 609 | /* Commented out for a read-only gauge in wxWindows */ |
89c7e962 JS |
610 | #if 0 |
611 | XmGaugeWidget gw = (XmGaugeWidget)w; | |
612 | #define THIS gw->gauge | |
613 | int size, sht; | |
614 | float ratio; | |
615 | Boolean dragging = False; | |
616 | XButtonEvent *event = (XButtonEvent *)e; | |
617 | int x, y; | |
2d120f83 | 618 | |
89c7e962 JS |
619 | x = event->x; |
620 | y = event->y; | |
621 | sht = gw->primitive.shadow_thickness; | |
622 | _XmDrawShadows(XtDisplay(w), XtWindow(w), | |
2d120f83 JS |
623 | gw->primitive.top_shadow_GC, |
624 | gw->primitive.bottom_shadow_GC, | |
625 | 0, 0, w->core.width, w->core.height, | |
626 | sht, XmSHADOW_IN); | |
627 | ||
628 | ||
89c7e962 | 629 | ratio = (float)((float)THIS.maximum - |
2d120f83 | 630 | (float)THIS.minimum) / (float)THIS.value; |
89c7e962 JS |
631 | switch(THIS.orientation) { |
632 | case XmHORIZONTAL: | |
2d120f83 JS |
633 | size = (w->core.width - 2 * sht) / ratio; |
634 | switch(THIS.processingDirection) { | |
635 | case XmMAX_ON_RIGHT: | |
636 | case XmMAX_ON_BOTTOM: | |
637 | dragging = (x > sht) && (y > sht) && | |
638 | (x < sht + size) && (y < w->core.height - sht); | |
639 | break; | |
640 | case XmMAX_ON_LEFT: | |
641 | case XmMAX_ON_TOP: | |
642 | dragging = (x > w->core.width - size - sht) && (y > sht) && | |
643 | (x < w->core.width - sht) && (y < w->core.height + sht); | |
644 | break; | |
645 | } | |
646 | break; | |
647 | case XmVERTICAL: | |
648 | size = (w->core.height - 2 * sht) / ratio; | |
649 | switch(THIS.processingDirection) { | |
650 | case XmMAX_ON_RIGHT: | |
651 | case XmMAX_ON_BOTTOM: | |
652 | dragging = (x > sht) && (y > sht) && | |
653 | (x < w->core.width - sht) && | |
654 | (y < w->core.width - 2 * sht + size); | |
655 | break; | |
656 | case XmMAX_ON_LEFT: | |
657 | case XmMAX_ON_TOP: | |
658 | dragging = (x > sht) && (y > w->core.height - size - sht) && | |
659 | (x < w->core.width - sht) && (y < w->core.height - sht); | |
660 | } | |
661 | break; | |
89c7e962 JS |
662 | } |
663 | THIS.dragging = dragging; | |
664 | THIS.oldx = x; | |
665 | THIS.oldy = y; | |
666 | #undef THIS | |
667 | #endif | |
4bb6408c JS |
668 | } |
669 | ||
89c7e962 JS |
670 | #define round(x) ( (x) > 0 ? ((x) + 0.5) : -(-(x) + 0.5) ) |
671 | ||
672 | void | |
673 | GaugeDrag(Widget w, XEvent *e, String *args, Cardinal *num_args) | |
674 | { | |
2d120f83 | 675 | /* Commented out for a read-only gauge in wxWindows */ |
89c7e962 JS |
676 | #if 0 |
677 | XmGaugeWidget gw = (XmGaugeWidget)w; | |
678 | #define THIS gw->gauge | |
679 | int sht, x, y, max, value; | |
680 | float ratio, nratio, size, nsize, fvalue, delta; | |
681 | XMotionEvent *event = (XMotionEvent *)e; | |
682 | ||
683 | if( ! THIS.dragging) return; | |
2d120f83 | 684 | |
89c7e962 JS |
685 | x = event->x; |
686 | y = event->y; | |
687 | sht = gw->primitive.shadow_thickness; | |
2d120f83 | 688 | |
89c7e962 | 689 | ratio = (float)THIS.value / (float)((float)THIS.maximum - |
2d120f83 | 690 | (float)THIS.minimum); |
89c7e962 JS |
691 | switch(THIS.orientation) { |
692 | case XmHORIZONTAL: | |
2d120f83 JS |
693 | max = (w->core.width - 2 * sht); |
694 | size = (float)max * ratio; | |
695 | delta = (float)x - (float)THIS.oldx; | |
696 | break; | |
89c7e962 | 697 | case XmVERTICAL: |
2d120f83 JS |
698 | max = (w->core.height - 2 * sht); |
699 | size = (float) max * ratio; | |
700 | delta = (float)y - (float)THIS.oldy; | |
701 | break; | |
89c7e962 JS |
702 | } |
703 | switch(THIS.processingDirection) { | |
704 | case XmMAX_ON_RIGHT: | |
705 | case XmMAX_ON_BOTTOM: | |
2d120f83 JS |
706 | nsize = size + delta; |
707 | break; | |
89c7e962 | 708 | default: |
2d120f83 | 709 | nsize = size - delta; |
89c7e962 JS |
710 | } |
711 | if(nsize > (float)max) nsize = (float)max; | |
712 | if(nsize < (float)0 ) nsize = (float)0; | |
713 | nratio = nsize / (float)max; | |
714 | ||
715 | fvalue = (int)((float)THIS.maximum - | |
2d120f83 | 716 | (float)THIS.minimum) * (float)nsize / (float)max; |
89c7e962 | 717 | value = round(fvalue); |
2d120f83 | 718 | |
89c7e962 JS |
719 | THIS.value = value; |
720 | THIS.oldx = x; | |
721 | THIS.oldy = y; | |
2d120f83 | 722 | |
89c7e962 JS |
723 | /* clear old slider only if it was larger */ |
724 | DrawSlider(gw, (nsize < size)); | |
725 | ||
726 | { | |
2d120f83 JS |
727 | XmGaugeCallbackStruct call; |
728 | ||
729 | if(NULL != THIS.dragCallback) { | |
730 | call.reason = XmCR_DRAG; | |
731 | call.event = e; | |
732 | call.value = THIS.value; | |
733 | XtCallCallbacks(w, XmNdragCallback, &call); | |
734 | } | |
89c7e962 JS |
735 | } |
736 | #undef THIS | |
737 | #endif | |
738 | } | |
739 | ||
740 | ||
741 | void | |
742 | GaugeDrop(Widget w, XEvent *e, String *args, Cardinal *num_args) | |
743 | { | |
2d120f83 | 744 | /* Commented out for a read-only gauge in wxWindows */ |
89c7e962 JS |
745 | #if 0 |
746 | XmGaugeWidget gw = (XmGaugeWidget)w; | |
747 | #define THIS gw->gauge | |
748 | if( ! THIS.dragging) return; | |
2d120f83 | 749 | |
89c7e962 | 750 | if(NULL != THIS.valueChangedCallback) { |
2d120f83 JS |
751 | XmGaugeCallbackStruct call; |
752 | call.reason = XmCR_VALUE_CHANGED; | |
753 | call.event = e; | |
754 | call.value = THIS.value; | |
755 | XtCallCallbacks(w, XmNvalueChangedCallback, &call); | |
89c7e962 JS |
756 | } |
757 | THIS.dragging = False; | |
758 | #undef THIS | |
759 | #endif | |
760 | } | |
761 | ||
762 | void | |
763 | XmGaugeSetValue(Widget w, int value) | |
764 | { | |
765 | XmGaugeWidget gw = (XmGaugeWidget)w; | |
2d120f83 | 766 | |
89c7e962 JS |
767 | gw->gauge.value = value; |
768 | DrawSlider(gw, True); | |
769 | XFlush(XtDisplay(w)); | |
770 | } | |
771 | ||
772 | int | |
773 | XmGaugeGetValue(Widget w) | |
774 | { | |
775 | XmGaugeWidget gw = (XmGaugeWidget)w; | |
2d120f83 | 776 | |
89c7e962 JS |
777 | return gw->gauge.value; |
778 | } |