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