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