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