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