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