]> git.saurik.com Git - wxWidgets.git/blame - src/motif/gauge.cpp
Fix/hack 1.
[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
4dff3400
JJ
16#ifdef __VMS__
17#include <wx/vms_x_fix.h>
18#endif
19
20# include "wx/gauge.h"
4bb6408c 21
338dd992
JJ
22#ifdef __VMS__
23#pragma message disable nosimpint
24#endif
89c7e962 25#include <Xm/Xm.h>
338dd992
JJ
26#ifdef __VMS__
27#pragma message enable nosimpint
28#endif
3096bd2f 29#include "wx/motif/private.h"
89c7e962 30
4bb6408c 31IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
4bb6408c 32
89c7e962
JS
33// XmGauge copyright notice:
34
35/*
2d120f83
JS
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
31528cd3 54* action, arising out of or in connection with the use
2d120f83
JS
55* or performance of this software.
56*
57*/
89c7e962
JS
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
4bb6408c 84bool wxGauge::Create(wxWindow *parent, wxWindowID id,
2d120f83
JS
85 int range,
86 const wxPoint& pos,
87 const wxSize& size,
88 long style,
89 const wxValidator& validator,
90 const wxString& name)
4bb6408c
JS
91{
92 SetName(name);
93 SetValidator(validator);
94 m_rangeMax = range;
95 m_windowStyle = style;
0d57be45
JS
96 m_backgroundColour = parent->GetBackgroundColour();
97 m_foregroundColour = parent->GetForegroundColour();
31528cd3 98
4bb6408c 99 if (parent) parent->AddChild(this);
31528cd3 100
4bb6408c 101 if ( id == -1 )
2d120f83 102 m_windowId = (int)NewControlId();
4bb6408c 103 else
2d120f83 104 m_windowId = id;
31528cd3 105
89c7e962 106 Widget parentWidget = (Widget) parent->GetClientWidget();
31528cd3 107
89c7e962
JS
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 ;
31528cd3 124
89c7e962 125 XtManageChild (gaugeWidget);
31528cd3 126
89c7e962
JS
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;
31528cd3 133
da175b2c 134 m_font = parent->GetFont();
4b5f3fe6 135 ChangeFont(FALSE);
31528cd3 136
89c7e962
JS
137 SetCanAddEventHandler(TRUE);
138 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height);
31528cd3 139
0d57be45 140 ChangeBackgroundColour();
31528cd3 141
89c7e962 142 return TRUE;
4bb6408c
JS
143}
144
4bb6408c
JS
145void wxGauge::SetShadowWidth(int w)
146{
89c7e962
JS
147 if (w == 0)
148 w = 1;
149 XtVaSetValues((Widget) m_mainWidget, XmNshadowThickness, w, NULL);
4bb6408c
JS
150}
151
af111fc3 152void wxGauge::SetBezelFace(int WXUNUSED(w))
4bb6408c 153{
4bb6408c
JS
154}
155
156void wxGauge::SetRange(int r)
157{
158 m_rangeMax = r;
89c7e962 159 XtVaSetValues((Widget) m_mainWidget, XmNmaximum, r, NULL);
4bb6408c
JS
160}
161
162void wxGauge::SetValue(int pos)
163{
164 m_gaugePos = pos;
89c7e962 165 XtVaSetValues((Widget) m_mainWidget, XmNvalue, pos, NULL);
4bb6408c
JS
166}
167
168int wxGauge::GetShadowWidth() const
169{
89c7e962
JS
170 Dimension w;
171 XtVaGetValues((Widget) m_mainWidget, XmNshadowThickness, &w, NULL);
172 return (int)w;
4bb6408c
JS
173}
174
175int wxGauge::GetBezelFace() const
176{
4bb6408c
JS
177 return 0;
178}
179
180int wxGauge::GetRange() const
181{
89c7e962
JS
182 int r;
183 XtVaGetValues((Widget) m_mainWidget, XmNmaximum, &r, NULL);
184 return (int)r;
2d120f83 185 // return m_rangeMax;
4bb6408c
JS
186}
187
188int wxGauge::GetValue() const
189{
2d120f83
JS
190 int pos;
191 XtVaGetValues((Widget) m_mainWidget, XmNvalue, &pos, NULL);
192 return pos;
193 // return m_gaugePos;
89c7e962
JS
194}
195
4b5f3fe6 196void wxGauge::ChangeFont(bool keepOriginalSize)
0d57be45 197{
4b5f3fe6 198 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
199}
200
201void wxGauge::ChangeBackgroundColour()
202{
321db4b6 203 wxWindow::ChangeBackgroundColour();
0d57be45
JS
204}
205
206void wxGauge::ChangeForegroundColour()
207{
321db4b6 208 wxWindow::ChangeForegroundColour();
0d57be45
JS
209}
210
89c7e962
JS
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
31528cd3 220typedef struct _XmGaugeClassRec {
89c7e962
JS
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;
31528cd3 233
89c7e962
JS
234 XtCallbackList dragCallback;
235 XtCallbackList valueChangedCallback;
31528cd3 236
89c7e962
JS
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);
31528cd3 258void
89c7e962 259GaugeDrag(Widget w, XEvent *e, String *args, Cardinal *num_args);
31528cd3 260void
89c7e962
JS
261GaugeDrop(Widget w, XEvent *e, String *args, Cardinal *num_args);
262
263
264
265static char translations[] =
266"<Btn1Down>: GaugePick()\n\
2d120f83
JS
267 <Btn1Motion>: GaugeDrag()\n\
268 <Btn1Up>: GaugeDrop()\n\
269 ";
89c7e962
JS
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;
2d120f83 285 /***chubraev
89c7e962
JS
286 char string[20];
287 int len;
288 unsigned long backgr,foregr;
289 XRectangle rects[1];
2d120f83 290 ***/
31528cd3 291
89c7e962 292 sht = gw->primitive.shadow_thickness;
31528cd3 293
89c7e962 294 ratio = (float)THIS.value/
2d120f83
JS
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 ***/
31528cd3 301
89c7e962 302 if(clear) {
2d120f83
JS
303 XClearArea(XtDisplay(gw), XtWindow(gw), sht, sht,
304 gw->core.width - 2 * sht, gw->core.height - 2 * sht, False);
89c7e962
JS
305 }
306 switch(THIS.orientation) {
307 case XmHORIZONTAL:
2d120f83
JS
308 size = (int) ((gw->core.width - 2 * sht)*ratio);
309 /***chubraev
31528cd3 310 XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht+gw->core.width/2,
2d120f83
JS
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);
31528cd3 318
2d120f83
JS
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);
31528cd3 329
2d120f83
JS
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 }
89c7e962
JS
336 /***chubraev
337 XSetClipRectangles(XtDisplay(gw), THIS.gc, 0, 0, rects, 1, Unsorted);
2d120f83 338 XSetForeground(XtDisplay(gw), THIS.gc, backgr);
31528cd3 339 XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht+gw->core.width/2,
2d120f83
JS
340 gw->core.height - 2 * sht, string, len);
341 ***/
31528cd3 342
2d120f83
JS
343 break;
344 case XmVERTICAL:
345 size = (int) ((gw->core.height - 2 * sht)*ratio);
89c7e962 346 /***chubraev
31528cd3 347 XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht,
2d120f83
JS
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);
31528cd3 355
2d120f83
JS
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);
31528cd3 366
2d120f83
JS
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 }
89c7e962 372 /***chubraev
2d120f83
JS
373 XSetClipRectangles(XtDisplay(gw), THIS.gc, 0, 0, rects, 1, Unsorted);
374 XSetForeground(XtDisplay(gw), THIS.gc, backgr);
31528cd3 375 XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht,
2d120f83
JS
376 sht+gw->core.height/2, string,len);
377 ***/
378 break;
89c7e962
JS
379 }
380 /***chubraev
381 XSetClipMask(XtDisplay(gw), THIS.gc, None);
382 XSetForeground(XtDisplay(gw), THIS.gc, foregr);
383 ***/
31528cd3 384#undef THIS
89c7e962
JS
385}
386
387/* Old code
2d120f83 388*/
89c7e962
JS
389#if 0
390static void
391DrawSlider(XmGaugeWidget gw, Boolean clear)
392{
393#define THIS gw->gauge
394 int size, sht;
2d120f83 395 /* float ratio; */
31528cd3 396
89c7e962 397 sht = gw->primitive.shadow_thickness;
2d120f83 398 /* See fix comment below: can cause divide by zero error.
89c7e962 399 ratio = (float)((float)THIS.maximum -
2d120f83
JS
400 (float)THIS.minimum) / (float)THIS.value;
401 */
89c7e962 402 if(clear) {
2d120f83
JS
403 XClearArea(XtDisplay(gw), XtWindow(gw), sht, sht,
404 gw->core.width - 2 * sht, gw->core.height - 2 * sht, False);
89c7e962
JS
405 }
406 switch(THIS.orientation) {
407 case XmHORIZONTAL:
2d120f83
JS
408 /* size = (gw->core.width - 2 * sht) / ratio; */
409 /* A fix suggested by Dmitri Chubraev */
89c7e962 410 size = (gw->core.width - 2 * sht) /((float)THIS.maximum-(float)THIS.minimum)*(float)THIS.value;
2d120f83
JS
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;
89c7e962 441 }
31528cd3 442#undef THIS
89c7e962
JS
443}
444#endif
445
446static void
af111fc3 447Initialize(Widget WXUNUSED(req), Widget new_w, ArgList WXUNUSED(args), Cardinal *WXUNUSED(num_args ))
89c7e962
JS
448{
449 XmGaugeWidget gw = (XmGaugeWidget)new_w;
450#define THIS gw->gauge
451 XGCValues values;
31528cd3 452
89c7e962
JS
453 values.foreground = gw->primitive.foreground;
454 THIS.gc = XtGetGC(new_w, GCForeground, &values);
31528cd3
VZ
455
456#undef THIS
457
89c7e962
JS
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);
31528cd3 468#undef THIS
89c7e962
JS
469}
470
471
472
2d120f83 473
89c7e962
JS
474static Boolean
475SetValues(
2d120f83 476 Widget cw,
af111fc3 477 Widget WXUNUSED(rw),
2d120f83 478 Widget nw,
af111fc3
JS
479 ArgList WXUNUSED(args),
480 Cardinal *WXUNUSED(num_args) )
89c7e962
JS
481{
482 XmGaugeWidget cgw = (XmGaugeWidget)cw;
483 XmGaugeWidget ngw = (XmGaugeWidget)nw;
31528cd3 484
89c7e962
JS
485 Boolean redraw = False;
486 if(cgw->primitive.foreground != ngw->primitive.foreground) {
2d120f83 487 XGCValues values;
31528cd3 488
2d120f83
JS
489 redraw = True;
490 XtReleaseGC(nw, ngw->gauge.gc);
491 values.foreground = ngw->primitive.foreground;
492 ngw->gauge.gc = XtGetGC(nw, GCForeground, &values);
89c7e962
JS
493 }
494 if(cgw->gauge.value != ngw->gauge.value) {
2d120f83 495 redraw = True;
89c7e962
JS
496 }
497 return redraw;
498}
499
500
501
502
503static void
af111fc3 504ExposeProc(Widget w, XEvent *WXUNUSED(event), Region WXUNUSED(r))
89c7e962
JS
505{
506 XmGaugeWidget gw = (XmGaugeWidget)w;
507#define THIS gw->gauge
508 int sht;
31528cd3 509
89c7e962
JS
510 sht = gw->primitive.shadow_thickness;
511 _XmDrawShadows(XtDisplay(w), XtWindow(w),
2d120f83
JS
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);
89c7e962 516 DrawSlider(gw, False);
31528cd3 517#undef THIS
89c7e962
JS
518}
519
520
521
522
523
31528cd3 524static XtResource
89c7e962
JS
525resources[] = {
526#define offset(field) XtOffset(XmGaugeWidget, gauge.field)
2d120f83
JS
527 {XmNvalue, XmCValue, XtRInt, sizeof(int),
528 offset(value), XtRImmediate, (caddr_t)10},
31528cd3 529
2d120f83
JS
530 {XmNminimum, XmCValue, XtRInt, sizeof(int),
531 offset(minimum), XtRImmediate, (caddr_t)0},
31528cd3 532
2d120f83
JS
533 {XmNmaximum, XmCValue, XtRInt, sizeof(int),
534 offset(maximum), XtRImmediate, (caddr_t)100},
31528cd3 535
2d120f83
JS
536 {XmNorientation, XmCOrientation, XmROrientation, sizeof(unsigned char),
537 offset(orientation), XtRImmediate, (caddr_t)XmVERTICAL},
31528cd3 538
2d120f83
JS
539 {XmNprocessingDirection, XmCProcessingDirection,
540 XmRProcessingDirection, sizeof(unsigned char),
541 offset(processingDirection), XtRImmediate, (caddr_t)XmMAX_ON_RIGHT},
31528cd3 542
2d120f83
JS
543 {XmNdragCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
544 offset(dragCallback), XtRImmediate, (caddr_t)NULL},
31528cd3 545
2d120f83
JS
546 {XmNvalueChangedCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
547 offset(valueChangedCallback), XtRImmediate, (caddr_t)NULL},
31528cd3
VZ
548
549
89c7e962
JS
550#undef offset
551};
552
553
554XmGaugeClassRec xmGaugeClassRec = {
555 { /* core fields */
2d120f83
JS
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 */
89c7e962
JS
588 },
589 /* primitive_class fields */
590 {
2d120f83
JS
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 }
89c7e962
JS
602};
603
604WidgetClass xmGaugeWidgetClass = (WidgetClass)&xmGaugeClassRec;
605
606
607
608
31528cd3 609void
af111fc3 610GaugePick(Widget WXUNUSED(w), XEvent *WXUNUSED(e), String *WXUNUSED(args), Cardinal *WXUNUSED(num_args))
89c7e962 611{
2d120f83 612 /* Commented out for a read-only gauge in wxWindows */
89c7e962
JS
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;
31528cd3 621
89c7e962
JS
622 x = event->x;
623 y = event->y;
624 sht = gw->primitive.shadow_thickness;
625 _XmDrawShadows(XtDisplay(w), XtWindow(w),
2d120f83
JS
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);
31528cd3
VZ
630
631
89c7e962 632 ratio = (float)((float)THIS.maximum -
31528cd3 633 (float)THIS.minimum) / (float)THIS.value;
89c7e962
JS
634 switch(THIS.orientation) {
635 case XmHORIZONTAL:
2d120f83
JS
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;
89c7e962
JS
665 }
666 THIS.dragging = dragging;
667 THIS.oldx = x;
668 THIS.oldy = y;
31528cd3 669#undef THIS
89c7e962 670#endif
4bb6408c
JS
671}
672
89c7e962
JS
673#define round(x) ( (x) > 0 ? ((x) + 0.5) : -(-(x) + 0.5) )
674
31528cd3 675void
af111fc3 676GaugeDrag(Widget WXUNUSED(w), XEvent *WXUNUSED(e), String *WXUNUSED(args), Cardinal *WXUNUSED(num_args))
89c7e962 677{
2d120f83 678 /* Commented out for a read-only gauge in wxWindows */
89c7e962
JS
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;
31528cd3 685
89c7e962 686 if( ! THIS.dragging) return;
31528cd3 687
89c7e962
JS
688 x = event->x;
689 y = event->y;
690 sht = gw->primitive.shadow_thickness;
31528cd3 691
89c7e962 692 ratio = (float)THIS.value / (float)((float)THIS.maximum -
2d120f83 693 (float)THIS.minimum);
89c7e962
JS
694 switch(THIS.orientation) {
695 case XmHORIZONTAL:
2d120f83
JS
696 max = (w->core.width - 2 * sht);
697 size = (float)max * ratio;
698 delta = (float)x - (float)THIS.oldx;
699 break;
89c7e962 700 case XmVERTICAL:
2d120f83
JS
701 max = (w->core.height - 2 * sht);
702 size = (float) max * ratio;
703 delta = (float)y - (float)THIS.oldy;
704 break;
89c7e962
JS
705 }
706 switch(THIS.processingDirection) {
707 case XmMAX_ON_RIGHT:
708 case XmMAX_ON_BOTTOM:
2d120f83
JS
709 nsize = size + delta;
710 break;
89c7e962 711 default:
2d120f83 712 nsize = size - delta;
89c7e962
JS
713 }
714 if(nsize > (float)max) nsize = (float)max;
715 if(nsize < (float)0 ) nsize = (float)0;
716 nratio = nsize / (float)max;
31528cd3 717
89c7e962 718 fvalue = (int)((float)THIS.maximum -
2d120f83 719 (float)THIS.minimum) * (float)nsize / (float)max;
89c7e962 720 value = round(fvalue);
31528cd3 721
89c7e962
JS
722 THIS.value = value;
723 THIS.oldx = x;
724 THIS.oldy = y;
31528cd3 725
89c7e962
JS
726 /* clear old slider only if it was larger */
727 DrawSlider(gw, (nsize < size));
31528cd3 728
89c7e962 729 {
2d120f83 730 XmGaugeCallbackStruct call;
31528cd3 731
2d120f83
JS
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 }
89c7e962 738 }
31528cd3 739#undef THIS
89c7e962
JS
740#endif
741}
742
743
31528cd3 744void
af111fc3 745GaugeDrop(Widget WXUNUSED(w), XEvent *WXUNUSED(e), String *WXUNUSED(args), Cardinal *WXUNUSED(num_args))
89c7e962 746{
2d120f83 747 /* Commented out for a read-only gauge in wxWindows */
89c7e962
JS
748#if 0
749 XmGaugeWidget gw = (XmGaugeWidget)w;
750#define THIS gw->gauge
751 if( ! THIS.dragging) return;
31528cd3 752
89c7e962 753 if(NULL != THIS.valueChangedCallback) {
2d120f83
JS
754 XmGaugeCallbackStruct call;
755 call.reason = XmCR_VALUE_CHANGED;
756 call.event = e;
757 call.value = THIS.value;
758 XtCallCallbacks(w, XmNvalueChangedCallback, &call);
89c7e962
JS
759 }
760 THIS.dragging = False;
31528cd3 761#undef THIS
89c7e962
JS
762#endif
763}
764
765void
766XmGaugeSetValue(Widget w, int value)
767{
768 XmGaugeWidget gw = (XmGaugeWidget)w;
31528cd3 769
89c7e962
JS
770 gw->gauge.value = value;
771 DrawSlider(gw, True);
772 XFlush(XtDisplay(w));
773}
774
775int
776XmGaugeGetValue(Widget w)
31528cd3 777{
89c7e962 778 XmGaugeWidget gw = (XmGaugeWidget)w;
31528cd3 779
89c7e962
JS
780 return gw->gauge.value;
781}