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