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