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