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