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