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