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