]> git.saurik.com Git - wxWidgets.git/blame - src/motif/gauge.cpp
rebaked after timer/socket changes
[wxWidgets.git] / src / motif / gauge.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
355b4d3d 2// Name: src/motif/gauge.cpp
4bb6408c
JS
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
355b4d3d 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
7ec69821 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
23f826bd
WS
25#include "wx/gauge.h"
26
27#ifndef WX_PRECOMP
28 #include "wx/math.h"
29#endif
4bb6408c 30
355b4d3d
WS
31#ifdef __OS2__
32#include <types.h>
33#endif
34
338dd992
JJ
35#ifdef __VMS__
36#pragma message disable nosimpint
37#endif
89c7e962 38#include <Xm/Xm.h>
93e73c74
MB
39#ifdef __WXMOTIF20__
40#include <Xm/Scale.h>
41#endif // __WXMOTIF20__
338dd992
JJ
42#ifdef __VMS__
43#pragma message enable nosimpint
44#endif
3096bd2f 45#include "wx/motif/private.h"
89c7e962 46
4bb6408c 47IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
4bb6408c 48
93e73c74
MB
49#if !wxCHECK_MOTIF_VERSION( 2, 0 ) || wxCHECK_LESSTIF()
50
89c7e962
JS
51// XmGauge copyright notice:
52
53/*
2d120f83
JS
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
31528cd3 72* action, arising out of or in connection with the use
2d120f83
JS
73* or performance of this software.
74*
75*/
89c7e962
JS
76
77//// PUBLIC XMGAUGE DECLARATIONS
355b4d3d
WS
78typedef struct _XmGaugeClassRec* XmGaugeWidgetClass;
79typedef struct _XmGaugeRec* XmGaugeWidget;
89c7e962
JS
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
93e73c74 100#endif // !wxCHECK_MOTIF_VERSION( 2, 0 ) || wxCHECK_LESSTIF()
89c7e962 101
4bb6408c 102bool wxGauge::Create(wxWindow *parent, wxWindowID id,
2d120f83
JS
103 int range,
104 const wxPoint& pos,
105 const wxSize& size,
106 long style,
107 const wxValidator& validator,
108 const wxString& name)
4bb6408c 109{
93e73c74
MB
110 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
111 return false;
105fbe1f 112 PreCreation();
31528cd3 113
89c7e962 114 Widget parentWidget = (Widget) parent->GetClientWidget();
31528cd3 115
93e73c74 116 Arg args[7];
89c7e962 117 int count = 4;
93e73c74 118 if (style & wxGA_HORIZONTAL)
89c7e962
JS
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);
93e73c74
MB
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
89c7e962 142 m_mainWidget = (WXWidget) gaugeWidget ;
31528cd3 143
89c7e962 144 XtManageChild (gaugeWidget);
31528cd3 145
89c7e962 146 int x = pos.x; int y = pos.y;
93e73c74 147 wxSize best = GetBestSize();
7ec69821
WS
148 if( size.x != wxDefaultCoord ) best.x = size.x;
149 if( size.y != wxDefaultCoord ) best.y = size.y;
31528cd3 150
105fbe1f 151 PostCreation();
93e73c74
MB
152 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y,
153 best.x, best.y);
31528cd3 154
96be256b 155 return true;
4bb6408c
JS
156}
157
93e73c74
MB
158wxSize wxGauge::DoGetBestSize() const
159{
160 if( HasFlag(wxGA_HORIZONTAL) )
161 return wxSize( 100, 18 );
162 else
163 return wxSize( 18, 100 );
164}
165
4bb6408c
JS
166void wxGauge::SetShadowWidth(int w)
167{
89c7e962
JS
168 if (w == 0)
169 w = 1;
170 XtVaSetValues((Widget) m_mainWidget, XmNshadowThickness, w, NULL);
4bb6408c
JS
171}
172
4bb6408c
JS
173void wxGauge::SetRange(int r)
174{
89c7e962 175 XtVaSetValues((Widget) m_mainWidget, XmNmaximum, r, NULL);
4bb6408c
JS
176}
177
178void wxGauge::SetValue(int pos)
179{
89c7e962 180 XtVaSetValues((Widget) m_mainWidget, XmNvalue, pos, NULL);
4bb6408c
JS
181}
182
183int wxGauge::GetShadowWidth() const
184{
89c7e962
JS
185 Dimension w;
186 XtVaGetValues((Widget) m_mainWidget, XmNshadowThickness, &w, NULL);
187 return (int)w;
4bb6408c
JS
188}
189
4bb6408c
JS
190int wxGauge::GetRange() const
191{
89c7e962
JS
192 int r;
193 XtVaGetValues((Widget) m_mainWidget, XmNmaximum, &r, NULL);
194 return (int)r;
4bb6408c
JS
195}
196
197int wxGauge::GetValue() const
198{
2d120f83
JS
199 int pos;
200 XtVaGetValues((Widget) m_mainWidget, XmNvalue, &pos, NULL);
201 return pos;
0d57be45
JS
202}
203
93e73c74 204void wxGauge::DoMoveWindow(int x, int y, int width, int height)
0d57be45 205{
93e73c74
MB
206 wxGaugeBase::DoMoveWindow( x, y, width, height );
207#ifdef __WXMOTIF20__
208 XtVaSetValues( (Widget)m_mainWidget,
209 XmNscaleHeight, height,
210 NULL );
211#endif
0d57be45
JS
212}
213
93e73c74 214#if !wxCHECK_MOTIF_VERSION( 2, 0 ) || wxCHECK_LESSTIF()
0d57be45 215
89c7e962
JS
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
31528cd3 225typedef struct _XmGaugeClassRec {
355b4d3d
WS
226 CoreClassPart core_class;
227 XmPrimitiveClassPart primitive_class;
228 XmGaugeClassPart gauge_class;
89c7e962
JS
229} XmGaugeClassRec;
230
231
232typedef struct _XmGaugePart{
233 int value;
234 int minimum;
235 int maximum;
236 unsigned char orientation;
237 unsigned char processingDirection;
31528cd3 238
89c7e962
JS
239 XtCallbackList dragCallback;
240 XtCallbackList valueChangedCallback;
31528cd3 241
89c7e962 242 /* private fields */
355b4d3d 243 Boolean dragging; /* drag in progress ? */
89c7e962
JS
244 int oldx, oldy;
245 GC gc;
246} XmGaugePart;
247
248
249typedef struct _XmGaugeRec {
355b4d3d
WS
250 CorePart core;
251 XmPrimitivePart primitive;
252 XmGaugePart gauge;
89c7e962
JS
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);
31528cd3 263void
89c7e962 264GaugeDrag(Widget w, XEvent *e, String *args, Cardinal *num_args);
31528cd3 265void
89c7e962
JS
266GaugeDrop(Widget w, XEvent *e, String *args, Cardinal *num_args);
267
268
269
270static char translations[] =
271"<Btn1Down>: GaugePick()\n\
2d120f83
JS
272 <Btn1Motion>: GaugeDrag()\n\
273 <Btn1Up>: GaugeDrop()\n\
274 ";
89c7e962
JS
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;
2d120f83 290 /***chubraev
89c7e962
JS
291 char string[20];
292 int len;
293 unsigned long backgr,foregr;
294 XRectangle rects[1];
2d120f83 295 ***/
31528cd3 296
89c7e962 297 sht = gw->primitive.shadow_thickness;
31528cd3 298
89c7e962 299 ratio = (float)THIS.value/
2d120f83
JS
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 ***/
31528cd3 306
89c7e962 307 if(clear) {
2d120f83
JS
308 XClearArea(XtDisplay(gw), XtWindow(gw), sht, sht,
309 gw->core.width - 2 * sht, gw->core.height - 2 * sht, False);
89c7e962
JS
310 }
311 switch(THIS.orientation) {
312 case XmHORIZONTAL:
2d120f83
JS
313 size = (int) ((gw->core.width - 2 * sht)*ratio);
314 /***chubraev
31528cd3 315 XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht+gw->core.width/2,
2d120f83
JS
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);
31528cd3 323
2d120f83
JS
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);
31528cd3 334
2d120f83
JS
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 }
89c7e962
JS
341 /***chubraev
342 XSetClipRectangles(XtDisplay(gw), THIS.gc, 0, 0, rects, 1, Unsorted);
2d120f83 343 XSetForeground(XtDisplay(gw), THIS.gc, backgr);
31528cd3 344 XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht+gw->core.width/2,
2d120f83
JS
345 gw->core.height - 2 * sht, string, len);
346 ***/
31528cd3 347
2d120f83
JS
348 break;
349 case XmVERTICAL:
350 size = (int) ((gw->core.height - 2 * sht)*ratio);
89c7e962 351 /***chubraev
31528cd3 352 XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht,
2d120f83
JS
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);
31528cd3 360
2d120f83
JS
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);
31528cd3 371
2d120f83
JS
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 }
89c7e962 377 /***chubraev
2d120f83
JS
378 XSetClipRectangles(XtDisplay(gw), THIS.gc, 0, 0, rects, 1, Unsorted);
379 XSetForeground(XtDisplay(gw), THIS.gc, backgr);
31528cd3 380 XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht,
2d120f83
JS
381 sht+gw->core.height/2, string,len);
382 ***/
383 break;
89c7e962
JS
384 }
385 /***chubraev
386 XSetClipMask(XtDisplay(gw), THIS.gc, None);
387 XSetForeground(XtDisplay(gw), THIS.gc, foregr);
388 ***/
31528cd3 389#undef THIS
89c7e962
JS
390}
391
392/* Old code
2d120f83 393*/
89c7e962
JS
394#if 0
395static void
396DrawSlider(XmGaugeWidget gw, Boolean clear)
397{
398#define THIS gw->gauge
399 int size, sht;
2d120f83 400 /* float ratio; */
31528cd3 401
89c7e962 402 sht = gw->primitive.shadow_thickness;
2d120f83 403 /* See fix comment below: can cause divide by zero error.
89c7e962 404 ratio = (float)((float)THIS.maximum -
2d120f83
JS
405 (float)THIS.minimum) / (float)THIS.value;
406 */
89c7e962 407 if(clear) {
2d120f83
JS
408 XClearArea(XtDisplay(gw), XtWindow(gw), sht, sht,
409 gw->core.width - 2 * sht, gw->core.height - 2 * sht, False);
89c7e962
JS
410 }
411 switch(THIS.orientation) {
412 case XmHORIZONTAL:
355b4d3d 413 /* size = (gw->core.width - 2 * sht) / ratio; */
2d120f83 414 /* A fix suggested by Dmitri Chubraev */
89c7e962 415 size = (gw->core.width - 2 * sht) /((float)THIS.maximum-(float)THIS.minimum)*(float)THIS.value;
2d120f83
JS
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;
355b4d3d 432 /* size = (gw->core.height - 2 * sht)/ ratio; */
2d120f83
JS
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;
89c7e962 446 }
31528cd3 447#undef THIS
89c7e962
JS
448}
449#endif
450
451static void
af111fc3 452Initialize(Widget WXUNUSED(req), Widget new_w, ArgList WXUNUSED(args), Cardinal *WXUNUSED(num_args ))
89c7e962
JS
453{
454 XmGaugeWidget gw = (XmGaugeWidget)new_w;
455#define THIS gw->gauge
456 XGCValues values;
31528cd3 457
89c7e962
JS
458 values.foreground = gw->primitive.foreground;
459 THIS.gc = XtGetGC(new_w, GCForeground, &values);
31528cd3
VZ
460
461#undef THIS
462
89c7e962
JS
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);
31528cd3 473#undef THIS
89c7e962
JS
474}
475
476
477
2d120f83 478
89c7e962
JS
479static Boolean
480SetValues(
2d120f83 481 Widget cw,
af111fc3 482 Widget WXUNUSED(rw),
2d120f83 483 Widget nw,
af111fc3
JS
484 ArgList WXUNUSED(args),
485 Cardinal *WXUNUSED(num_args) )
89c7e962
JS
486{
487 XmGaugeWidget cgw = (XmGaugeWidget)cw;
488 XmGaugeWidget ngw = (XmGaugeWidget)nw;
31528cd3 489
89c7e962
JS
490 Boolean redraw = False;
491 if(cgw->primitive.foreground != ngw->primitive.foreground) {
2d120f83 492 XGCValues values;
31528cd3 493
2d120f83
JS
494 redraw = True;
495 XtReleaseGC(nw, ngw->gauge.gc);
496 values.foreground = ngw->primitive.foreground;
497 ngw->gauge.gc = XtGetGC(nw, GCForeground, &values);
89c7e962
JS
498 }
499 if(cgw->gauge.value != ngw->gauge.value) {
2d120f83 500 redraw = True;
89c7e962
JS
501 }
502 return redraw;
503}
504
505
506
507
508static void
af111fc3 509ExposeProc(Widget w, XEvent *WXUNUSED(event), Region WXUNUSED(r))
89c7e962
JS
510{
511 XmGaugeWidget gw = (XmGaugeWidget)w;
512#define THIS gw->gauge
513 int sht;
31528cd3 514
89c7e962
JS
515 sht = gw->primitive.shadow_thickness;
516 _XmDrawShadows(XtDisplay(w), XtWindow(w),
2d120f83
JS
517 gw->primitive.top_shadow_GC,
518 gw->primitive.bottom_shadow_GC,
519 0, 0, w->core.width, w->core.height,
355b4d3d 520 (Dimension)sht, XmSHADOW_IN);
89c7e962 521 DrawSlider(gw, False);
31528cd3 522#undef THIS
89c7e962
JS
523}
524
525
526
527
528
31528cd3 529static XtResource
89c7e962
JS
530resources[] = {
531#define offset(field) XtOffset(XmGaugeWidget, gauge.field)
2d120f83
JS
532 {XmNvalue, XmCValue, XtRInt, sizeof(int),
533 offset(value), XtRImmediate, (caddr_t)10},
31528cd3 534
2d120f83
JS
535 {XmNminimum, XmCValue, XtRInt, sizeof(int),
536 offset(minimum), XtRImmediate, (caddr_t)0},
31528cd3 537
2d120f83
JS
538 {XmNmaximum, XmCValue, XtRInt, sizeof(int),
539 offset(maximum), XtRImmediate, (caddr_t)100},
31528cd3 540
2d120f83
JS
541 {XmNorientation, XmCOrientation, XmROrientation, sizeof(unsigned char),
542 offset(orientation), XtRImmediate, (caddr_t)XmVERTICAL},
31528cd3 543
2d120f83
JS
544 {XmNprocessingDirection, XmCProcessingDirection,
545 XmRProcessingDirection, sizeof(unsigned char),
546 offset(processingDirection), XtRImmediate, (caddr_t)XmMAX_ON_RIGHT},
31528cd3 547
2d120f83
JS
548 {XmNdragCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
549 offset(dragCallback), XtRImmediate, (caddr_t)NULL},
31528cd3 550
2d120f83
JS
551 {XmNvalueChangedCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),
552 offset(valueChangedCallback), XtRImmediate, (caddr_t)NULL},
31528cd3
VZ
553
554
89c7e962
JS
555#undef offset
556};
557
558
559XmGaugeClassRec xmGaugeClassRec = {
355b4d3d
WS
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 */
89c7e962 593 },
355b4d3d 594 /* primitive_class fields */
89c7e962 595 {
355b4d3d
WS
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 }
89c7e962
JS
607};
608
609WidgetClass xmGaugeWidgetClass = (WidgetClass)&xmGaugeClassRec;
610
611
612
613
31528cd3 614void
af111fc3 615GaugePick(Widget WXUNUSED(w), XEvent *WXUNUSED(e), String *WXUNUSED(args), Cardinal *WXUNUSED(num_args))
89c7e962 616{
77ffb593 617 /* Commented out for a read-only gauge in wxWidgets */
89c7e962
JS
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;
31528cd3 626
89c7e962
JS
627 x = event->x;
628 y = event->y;
629 sht = gw->primitive.shadow_thickness;
630 _XmDrawShadows(XtDisplay(w), XtWindow(w),
2d120f83
JS
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);
31528cd3
VZ
635
636
89c7e962 637 ratio = (float)((float)THIS.maximum -
31528cd3 638 (float)THIS.minimum) / (float)THIS.value;
89c7e962
JS
639 switch(THIS.orientation) {
640 case XmHORIZONTAL:
2d120f83
JS
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;
89c7e962
JS
670 }
671 THIS.dragging = dragging;
672 THIS.oldx = x;
673 THIS.oldy = y;
31528cd3 674#undef THIS
89c7e962 675#endif
4bb6408c
JS
676}
677
31528cd3 678void
af111fc3 679GaugeDrag(Widget WXUNUSED(w), XEvent *WXUNUSED(e), String *WXUNUSED(args), Cardinal *WXUNUSED(num_args))
89c7e962 680{
77ffb593 681 /* Commented out for a read-only gauge in wxWidgets */
89c7e962
JS
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;
31528cd3 688
89c7e962 689 if( ! THIS.dragging) return;
31528cd3 690
89c7e962
JS
691 x = event->x;
692 y = event->y;
693 sht = gw->primitive.shadow_thickness;
31528cd3 694
89c7e962 695 ratio = (float)THIS.value / (float)((float)THIS.maximum -
2d120f83 696 (float)THIS.minimum);
89c7e962
JS
697 switch(THIS.orientation) {
698 case XmHORIZONTAL:
2d120f83
JS
699 max = (w->core.width - 2 * sht);
700 size = (float)max * ratio;
701 delta = (float)x - (float)THIS.oldx;
702 break;
89c7e962 703 case XmVERTICAL:
2d120f83
JS
704 max = (w->core.height - 2 * sht);
705 size = (float) max * ratio;
706 delta = (float)y - (float)THIS.oldy;
707 break;
89c7e962
JS
708 }
709 switch(THIS.processingDirection) {
710 case XmMAX_ON_RIGHT:
711 case XmMAX_ON_BOTTOM:
2d120f83
JS
712 nsize = size + delta;
713 break;
89c7e962 714 default:
2d120f83 715 nsize = size - delta;
89c7e962
JS
716 }
717 if(nsize > (float)max) nsize = (float)max;
718 if(nsize < (float)0 ) nsize = (float)0;
719 nratio = nsize / (float)max;
31528cd3 720
89c7e962 721 fvalue = (int)((float)THIS.maximum -
2d120f83 722 (float)THIS.minimum) * (float)nsize / (float)max;
23f826bd 723 value = wxRound(fvalue);
31528cd3 724
89c7e962
JS
725 THIS.value = value;
726 THIS.oldx = x;
727 THIS.oldy = y;
31528cd3 728
89c7e962
JS
729 /* clear old slider only if it was larger */
730 DrawSlider(gw, (nsize < size));
31528cd3 731
89c7e962 732 {
2d120f83 733 XmGaugeCallbackStruct call;
31528cd3 734
2d120f83
JS
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 }
89c7e962 741 }
31528cd3 742#undef THIS
89c7e962
JS
743#endif
744}
745
746
31528cd3 747void
af111fc3 748GaugeDrop(Widget WXUNUSED(w), XEvent *WXUNUSED(e), String *WXUNUSED(args), Cardinal *WXUNUSED(num_args))
89c7e962 749{
77ffb593 750 /* Commented out for a read-only gauge in wxWidgets */
89c7e962
JS
751#if 0
752 XmGaugeWidget gw = (XmGaugeWidget)w;
753#define THIS gw->gauge
754 if( ! THIS.dragging) return;
31528cd3 755
89c7e962 756 if(NULL != THIS.valueChangedCallback) {
2d120f83
JS
757 XmGaugeCallbackStruct call;
758 call.reason = XmCR_VALUE_CHANGED;
759 call.event = e;
760 call.value = THIS.value;
761 XtCallCallbacks(w, XmNvalueChangedCallback, &call);
89c7e962
JS
762 }
763 THIS.dragging = False;
31528cd3 764#undef THIS
89c7e962
JS
765#endif
766}
767
768void
769XmGaugeSetValue(Widget w, int value)
770{
771 XmGaugeWidget gw = (XmGaugeWidget)w;
31528cd3 772
89c7e962
JS
773 gw->gauge.value = value;
774 DrawSlider(gw, True);
775 XFlush(XtDisplay(w));
776}
777
778int
779XmGaugeGetValue(Widget w)
31528cd3 780{
89c7e962 781 XmGaugeWidget gw = (XmGaugeWidget)w;
31528cd3 782
89c7e962
JS
783 return gw->gauge.value;
784}
93e73c74
MB
785
786#endif // !wxCHECK_MOTIF_VERSION( 2, 0 ) || wxCHECK_LESSTIF()