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