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