]> git.saurik.com Git - wxWidgets.git/blame - src/motif/gauge.cpp
Implemented wxScreenDC the hard way
[wxWidgets.git] / src / motif / gauge.cpp
CommitLineData
4bb6408c
JS
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#include "wx/gauge.h"
17
89c7e962
JS
18#include <Xm/Xm.h>
19#include <wx/motif/private.h>
20
4bb6408c
JS
21#if !USE_SHARED_LIBRARY
22IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
23#endif
24
89c7e962
JS
25// XmGauge copyright notice:
26
27/*
28 * Copyright 1994 GROUPE BULL
29 *
30 * Permission to use, copy, modify, and distribute this software and its
31 * documentation for any purpose and without fee is hereby granted, provided
32 * that the above copyright notice appear in all copies and that both that
33 * copyright notice and this permission notice appear in supporting
34 * documentation, and that the name of GROUPE BULL not be used in advertising
35 * or publicity pertaining to distribution of the software without specific,
36 * written prior permission. GROUPE BULL makes no representations about the
37 * suitability of this software for any purpose. It is provided "as is"
38 * without express or implied warranty.
39 *
40 * GROUPE BULL disclaims all warranties with regard to this software,
41 * including all implied warranties of merchantability and fitness,
42 * in no event shall GROUPE BULL be liable for any special,
43 * indirect or consequential damages or any damages
44 * whatsoever resulting from loss of use, data or profits,
45 * whether in an action of contract, negligence or other tortious
46 * action, arising out of or in connection with the use
47 * or performance of this software.
48 *
49 */
50
51//// PUBLIC XMGAUGE DECLARATIONS
52typedef struct _XmGaugeClassRec* XmGaugeWidgetClass;
53typedef struct _XmGaugeRec* XmGaugeWidget;
54
55#ifdef __cplusplus
56extern "C" WidgetClass xmGaugeWidgetClass;
57#else
58extern WidgetClass xmGaugeWidgetClass;
59#endif
60
61typedef struct _XmGaugeCallbackStruct{
62 int reason;
63 XEvent *event;
64 int value;
65} XmGaugeCallbackStruct;
66
67
68void
69XmGaugeSetValue(Widget w, int value);
70
71int
72XmGaugeGetValue(Widget w);
73
74
75
4bb6408c
JS
76bool wxGauge::Create(wxWindow *parent, wxWindowID id,
77 int range,
78 const wxPoint& pos,
79 const wxSize& size,
80 long style,
81 const wxValidator& validator,
82 const wxString& name)
83{
84 SetName(name);
85 SetValidator(validator);
86 m_rangeMax = range;
87 m_windowStyle = style;
0d57be45
JS
88 m_backgroundColour = parent->GetBackgroundColour();
89 m_foregroundColour = parent->GetForegroundColour();
4bb6408c
JS
90
91 if (parent) parent->AddChild(this);
92
93 if ( id == -1 )
94 m_windowId = (int)NewControlId();
95 else
96 m_windowId = id;
97
89c7e962
JS
98 Widget parentWidget = (Widget) parent->GetClientWidget();
99
100 Arg args[4];
101 int count = 4;
102 if (style & wxHORIZONTAL)
103 {
104 XtSetArg (args[0], XmNorientation, XmHORIZONTAL);
105 XtSetArg (args[1], XmNprocessingDirection, XmMAX_ON_RIGHT);
106 }
107 else
108 {
109 XtSetArg (args[0], XmNorientation, XmVERTICAL);
110 XtSetArg (args[1], XmNprocessingDirection, XmMAX_ON_TOP);
111 }
112 XtSetArg(args[2], XmNminimum, 0);
113 XtSetArg(args[3], XmNmaximum, range);
114 Widget gaugeWidget = XtCreateManagedWidget("gauge", xmGaugeWidgetClass, parentWidget, args, count);
115 m_mainWidget = (WXWidget) gaugeWidget ;
116
117 XtManageChild (gaugeWidget);
4bb6408c 118
89c7e962
JS
119 int x = pos.x; int y = pos.y;
120 int width = size.x; int height = size.y;
121 if (width == -1)
122 width = 150;
123 if (height == -1)
124 height = 80;
125
126 SetCanAddEventHandler(TRUE);
127 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height);
128
129 SetFont(* parent->GetFont());
0d57be45 130 ChangeBackgroundColour();
89c7e962
JS
131
132 return TRUE;
4bb6408c
JS
133}
134
135void wxGauge::SetSize(int x, int y, int width, int height, int sizeFlags)
136{
89c7e962 137 wxControl::SetSize(x, y, width, height, sizeFlags);
4bb6408c
JS
138}
139
140void wxGauge::SetShadowWidth(int w)
141{
89c7e962
JS
142 if (w == 0)
143 w = 1;
144 XtVaSetValues((Widget) m_mainWidget, XmNshadowThickness, w, NULL);
4bb6408c
JS
145}
146
147void wxGauge::SetBezelFace(int w)
148{
4bb6408c
JS
149}
150
151void wxGauge::SetRange(int r)
152{
153 m_rangeMax = r;
89c7e962 154 XtVaSetValues((Widget) m_mainWidget, XmNmaximum, r, NULL);
4bb6408c
JS
155}
156
157void wxGauge::SetValue(int pos)
158{
159 m_gaugePos = pos;
89c7e962 160 XtVaSetValues((Widget) m_mainWidget, XmNvalue, pos, NULL);
4bb6408c
JS
161}
162
163int wxGauge::GetShadowWidth() const
164{
89c7e962
JS
165 Dimension w;
166 XtVaGetValues((Widget) m_mainWidget, XmNshadowThickness, &w, NULL);
167 return (int)w;
4bb6408c
JS
168}
169
170int wxGauge::GetBezelFace() const
171{
4bb6408c
JS
172 return 0;
173}
174
175int wxGauge::GetRange() const
176{
89c7e962
JS
177 int r;
178 XtVaGetValues((Widget) m_mainWidget, XmNmaximum, &r, NULL);
179 return (int)r;
180// return m_rangeMax;
4bb6408c
JS
181}
182
183int wxGauge::GetValue() const
184{
89c7e962
JS
185 int pos;
186 XtVaGetValues((Widget) m_mainWidget, XmNvalue, &pos, NULL);
187 return pos;
188// return m_gaugePos;
189}
190
0d57be45
JS
191void wxGauge::ChangeFont()
192{
321db4b6 193 wxWindow::ChangeFont();
0d57be45
JS
194}
195
196void wxGauge::ChangeBackgroundColour()
197{
321db4b6 198 wxWindow::ChangeBackgroundColour();
0d57be45
JS
199}
200
201void wxGauge::ChangeForegroundColour()
202{
321db4b6 203 wxWindow::ChangeForegroundColour();
0d57be45
JS
204}
205
89c7e962
JS
206//// PRIVATE DECLARATIONS FOR XMGAUGE
207
208#include <Xm/PrimitiveP.h>
209#include <Xm/DrawP.h>
210
211typedef struct {
212 int empty;
213} XmGaugeClassPart;
214
215typedef struct _XmGaugeClassRec {
216 CoreClassPart core_class;
217 XmPrimitiveClassPart primitive_class;
218 XmGaugeClassPart gauge_class;
219} XmGaugeClassRec;
220
221
222typedef 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
239typedef struct _XmGaugeRec {
240 CorePart core;
241 XmPrimitivePart primitive;
242 XmGaugePart gauge;
243} XmGaugeRec;
244
245extern XmGaugeClassRec xmGaugeClassRec;
246
247/* Copyright 1994 GROUPE BULL -- See license conditions in file COPYRIGHT */
248
249//// XMGAUGE IMPLEMENTATION
250
251void
252GaugePick(Widget w, XEvent *e, String *args, Cardinal *num_args);
253void
254GaugeDrag(Widget w, XEvent *e, String *args, Cardinal *num_args);
255void
256GaugeDrop(Widget w, XEvent *e, String *args, Cardinal *num_args);
257
258
259
260static char translations[] =
261"<Btn1Down>: GaugePick()\n\
262 <Btn1Motion>: GaugeDrag()\n\
263 <Btn1Up>: GaugeDrop()\n\
264";
265
266
267
268static XtActionsRec actions[] = {
269 {"GaugePick", GaugePick},
270 {"GaugeDrag", GaugeDrag},
271 {"GaugeDrop", GaugeDrop},
272};
273
274static void
275DrawSlider(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,
306gw->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,
335gw->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,
343sht+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,
371sht+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
385static void
386DrawSlider(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
441static void
442Initialize(Widget req, Widget new_w, ArgList args, Cardinal *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
457static void
458Destroy(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
469static Boolean
470SetValues(
471 Widget cw,
472 Widget rw,
473 Widget nw,
474 ArgList args,
475 Cardinal *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
498static void
499ExposeProc(Widget w, XEvent *event, Region 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
519static XtResource
520resources[] = {
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
549XmGaugeClassRec 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
599WidgetClass xmGaugeWidgetClass = (WidgetClass)&xmGaugeClassRec;
600
601
602
603
604void
605GaugePick(Widget w, XEvent *e, String *args, Cardinal *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
4bb6408c
JS
666}
667
89c7e962
JS
668#define round(x) ( (x) > 0 ? ((x) + 0.5) : -(-(x) + 0.5) )
669
670void
671GaugeDrag(Widget w, XEvent *e, String *args, Cardinal *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
739void
740GaugeDrop(Widget w, XEvent *e, String *args, Cardinal *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
760void
761XmGaugeSetValue(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
770int
771XmGaugeGetValue(Widget w)
772{
773 XmGaugeWidget gw = (XmGaugeWidget)w;
774
775 return gw->gauge.value;
776}