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