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