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