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