]> git.saurik.com Git - wxWidgets.git/blob - src/os2/gauge.cpp
89d6f45340423bd45441c1ac1675190558866e0c
[wxWidgets.git] / src / os2 / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gauge.cpp
3 // Purpose: wxGauge class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/06/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/defs.h"
17 #include "wx/utils.h"
18 #endif
19
20 #include "wx/os2/private.h"
21 #include "wx/gauge.h"
22
23 /* gas gauge graph control messages--class "zYzGauge" */
24 #define ZYZG_SETRANGE (WM_USER + 0)
25 #define ZYZG_GETRANGE (WM_USER + 1)
26 #define ZYZG_SETPOSITION (WM_USER + 2)
27 #define ZYZG_GETPOSITION (WM_USER + 3)
28 #define ZYZG_SETORIENTATION (WM_USER + 4)
29 #define ZYZG_GETORIENTATION (WM_USER + 5)
30 #define ZYZG_SETFGCOLOR (WM_USER + 6)
31 #define ZYZG_GETFGCOLOR (WM_USER + 7)
32 #define ZYZG_SETBKCOLOR (WM_USER + 8)
33 #define ZYZG_GETBKCOLOR (WM_USER + 9)
34 #define ZYZG_SETWIDTH3D (WM_USER + 10)
35 #define ZYZG_GETWIDTH3D (WM_USER + 11)
36 #define ZYZG_SETBEZELFACE (WM_USER + 12)
37 #define ZYZG_GETBEZELFACE (WM_USER + 13)
38 #define ZYZG_SETDELTAPOS (WM_USER + 14)
39
40 /* orientations for ZYZG_WW_ORIENTATION */
41 #define ZYZG_ORIENT_LEFTTORIGHT 0
42 #define ZYZG_ORIENT_RIGHTTOLEFT 1
43 #define ZYZG_ORIENT_BOTTOMTOTOP 2
44 #define ZYZG_ORIENT_TOPTOBOTTOM 3
45
46 /* gauge styles */
47 #define ZYZGS_3D 0x8000L /* control will be 3D */
48
49 /* public function prototypes */
50 BOOL _Optlink gaugeInit(HINSTANCE hInstance);
51
52 #if !USE_SHARED_LIBRARY
53 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
54 #endif
55
56 bool wxGauge::Create(wxWindow *parent, wxWindowID id,
57 int range,
58 const wxPoint& pos,
59 const wxSize& size,
60 long style,
61 const wxValidator& validator,
62 const wxString& name)
63 {
64 static bool wxGaugeOS2Initialised = FALSE;
65
66 if ( !wxGaugeOS2Initialised )
67 {
68 if (!gaugeInit((HINSTANCE) wxGetInstance()))
69 wxFatalError("Cannot initalize Gauge library");
70 wxGaugeOS2Initialised = TRUE;
71 }
72
73 SetName(name);
74 SetValidator(validator);
75 if (parent) parent->AddChild(this);
76 m_rangeMax = range;
77 m_gaugePos = 0;
78
79 m_windowStyle = style;
80
81 if ( id == -1 )
82 m_windowId = (int)NewControlId();
83 else
84 m_windowId = id;
85
86 int x = pos.x;
87 int y = pos.y;
88 int width = size.x;
89 int height = size.y;
90
91 // TODO
92 /*
93 int x = pos.x;
94 int y = pos.y;
95 int width = size.x;
96 int height = size.y;
97
98 long msFlags = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
99 msFlags |= ZYZGS_3D;
100
101 HWND wx_button =
102 CreateWindowEx(MakeExtendedStyle(m_windowStyle), wxT("zYzGauge"), NULL, msFlags,
103 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
104 wxGetInstance(), NULL);
105
106 m_hWnd = (WXHWND)wx_button;
107
108 // Subclass again for purposes of dialog editing mode
109 SubclassWin((WXHWND)wx_button);
110
111 int wOrient = 0;
112
113 if (m_windowStyle & wxGA_HORIZONTAL)
114 wOrient = ZYZG_ORIENT_LEFTTORIGHT;
115 else
116 wOrient = ZYZG_ORIENT_BOTTOMTOTOP;
117
118 SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0);
119 SendMessage(wx_button, ZYZG_SETRANGE, range, 0);
120
121 SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
122 SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
123
124 SetFont(parent->GetFont());
125
126 if (width == -1)
127 width = 50;
128 if (height == -1)
129 height = 50;
130 SetSize(x, y, width, height);
131
132 ShowWindow(GetHwnd(), SW_SHOW);
133 */
134 return TRUE;
135 }
136
137 void wxGauge::SetShadowWidth(int w)
138 {
139 // TODO optional ::SendMessage(GetHwnd(), ZYZG_SETWIDTH3D, w, 0);
140 }
141
142 void wxGauge::SetBezelFace(int w)
143 {
144 // TODO optional ::SendMessage(GetHwnd(), ZYZG_SETBEZELFACE, w, 0);
145 }
146
147 void wxGauge::SetRange(int r)
148 {
149 m_rangeMax = r;
150 // TODO ::SendMessage(GetHwnd(), ZYZG_SETRANGE, r, 0);
151 }
152
153 void wxGauge::SetValue(int pos)
154 {
155 m_gaugePos = pos;
156 // TODO ::SendMessage(GetHwnd(), ZYZG_SETPOSITION, pos, 0);
157 }
158
159 int wxGauge::GetShadowWidth() const
160 {
161 // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETWIDTH3D, 0, 0);
162 return 0;
163 }
164
165 int wxGauge::GetBezelFace() const
166 {
167 // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETBEZELFACE, 0, 0);
168 return 0;
169 }
170
171 int wxGauge::GetRange() const
172 {
173 // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETRANGE, 0, 0);
174 return m_rangeMax;
175 }
176
177 int wxGauge::GetValue() const
178 {
179 // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETPOSITION, 0, 0);
180 return m_gaugePos;
181 }
182
183 bool wxGauge::SetForegroundColour(const wxColour& col)
184 {
185 if ( !wxControl::SetForegroundColour(col) )
186 return FALSE;
187
188 // TODO ::SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
189
190 return TRUE;
191 }
192
193 bool wxGauge::SetBackgroundColour(const wxColour& col)
194 {
195 if ( !wxControl::SetBackgroundColour(col) )
196 return FALSE;
197
198 // TODO ::SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
199
200 return TRUE;
201 }
202
203 ///** zyz3d.c
204 // *
205 // * DESCRIPTION:
206 // * This module contains functions for creating nifty 3D borders
207 // * around controls like zYzGauge.
208 // *
209 // * HISTORY:
210 // * 3/14/91 cjp put in this comment
211 // * 6/19/92 cjp touched it a bit
212 // *
213 // ** cjp */
214 // COPYRIGHT:
215 //
216 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
217 //
218 // You have a royalty-free right to use, modify, reproduce and
219 // distribute the Sample Files (and/or any modified version) in
220 // any way you find useful, provided that you agree that
221 // Microsoft has no warranty obligations or liability for any
222 // Sample Application Files which are modified.
223 //
224
225
226 ///* get the includes we need */
227 //#define INCL_PM
228 //#include <os2.h>
229
230 ///* misc. control flag defines */
231 //#define DRAW3D_IN 0x0001
232 //#define DRAW3D_OUT 0x0002
233
234 //#define DRAW3D_TOPLINE 0x0004
235 //#define DRAW3D_BOTTOMLINE 0x0008
236 //#define DRAW3D_LEFTLINE 0x0010
237 //#define DRAW3D_RIGHTLINE 0x0020
238
239
240 ///* public function prototypes */
241 //void _Optlink Draw3DFaceFrame(HDC, LPRECT, WORD);
242 //void _Optlink Draw3DRect(HDC, LPRECT, WORD, WORD);
243 //void _Optlink Draw3DLine(HDC, WORD, WORD, WORD, WORD, WORD);
244
245
246 ///** void _Optlink Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth)
247 // *
248 // * DESCRIPTION:
249 // * This function draws a flat frame with the current button-face
250 // * color.
251 // *
252 // * ARGUMENTS:
253 // * HDC hdc : The DC to draw into.
254 // *
255 // * LPRECT rc : The containing rect for the new frame.
256 // *
257 // * WORD wWidth : The width of the frame to draw.
258 // *
259 // * RETURN (void _Optlink):
260 // * The frame will have been drawn into the DC.
261 // *
262 // * NOTES:
263 // *
264 // ** cjp */
265
266 //void _Optlink Draw3DFaceFrame(HDC hdc, RECTL* rc, WORD wWidth)
267 //{
268 // RECTL rc1;
269 // DWORD rgbOld;
270
271 // /* don't go through a bunch of work if we don't have to */
272 // if (!wWidth)
273 // return;
274
275 // /* set up color to be button-face color--so it may not be gray */
276 // rgbOld = SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
277
278 // /* perform CopyRect w/o bloody windows style overhead */
279 // rc1 = *rc;
280
281 /* top */
282 // rc1.top = rc->top;
283 // rc1.left = rc->left;
284 // rc1.bottom = rc->top + wWidth;
285 // rc1.right = rc->right;
286
287 /* blast it out */
288 // ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL);
289
290 /* right */
291 // rc1.left = rc->right - wWidth;
292 // rc1.bottom = rc->bottom;
293
294 /* blast this part now */
295 // ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL);
296
297 /* left */
298 // rc1.left = rc->left;
299 // rc1.right = rc->left + wWidth;
300
301 /* and another part */
302 // ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL);
303
304 /* bottom */
305 // rc1.right = rc->right;
306 // rc1.top = rc->bottom - wWidth;
307
308 /* finish it off */
309 // ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL);
310
311 /* restore the old bk color */
312 // SetBkColor(hdc, rgbOld);
313 //} /* Draw3DFaceFrame() */
314
315
316 ///** void _Optlink Draw3DRect(HDC, LPRECT, WORD, WORD)
317 // *
318 // * DESCRIPTION:
319 // * Draws a 3D rectangle that is shaded. wFlags can be used to
320 // * control how the rectangle looks.
321 // *
322 // * ARGUMENTS:
323 // * HDC hdc : Handle to the device context that will be
324 // * used to display the rectangle.
325 // *
326 // * RECT rect : A rectangle describing the dimensions of
327 // * the rectangle in device coordinates.
328 // *
329 // * WORD wShadowWidth : Width of the shadow in device coordinates.
330 // *
331 // * WORD wFlags : The following flags may be passed to describe
332 // * the style of the rectangle:
333 // *
334 // * DRAW3D_IN : The shadow is drawn such that
335 // * the box appears to be sunk in to the screen.
336 // * This is default if 0 is passed.
337 // *
338 // * DRAW3D_OUT : The shadow is drawn such that
339 // * the box appears to be sticking out of the
340 // * screen.
341 // *
342 // * RETURN (void _Optlink):
343 // * The 3D looking rectangle will have been drawn into the DC.
344 // *
345 // * NOTES:
346 // *
347 // ** cjp */
348
349 //void _Optlink Draw3DRect(HDC hdc, LPRECT lpRect,
350 // WORD wShadowWidth, WORD wFlags)
351 //{
352 // /* sanity check--don't work if you don't have to! */
353 // if (!wShadowWidth || !RectVisible(hdc, lpRect))
354 // return;
355
356 /* draw the top line */
357 // Draw3DLine(hdc, lpRect->left, lpRect->top,
358 // lpRect->right - lpRect->left,
359 // wShadowWidth, DRAW3D_TOPLINE | wFlags);
360
361 /* right line */
362 // Draw3DLine(hdc, lpRect->right, lpRect->top,
363 // lpRect->bottom - lpRect->top,
364 // wShadowWidth, DRAW3D_RIGHTLINE | wFlags);
365
366 /* bottom line */
367 // Draw3DLine(hdc, lpRect->left, lpRect->bottom,
368 // lpRect->right - lpRect->left,
369 // wShadowWidth, DRAW3D_BOTTOMLINE | wFlags);
370
371 /* left line */
372 // Draw3DLine(hdc, lpRect->left, lpRect->top,
373 // lpRect->bottom - lpRect->top,
374 // wShadowWidth, DRAW3D_LEFTLINE | wFlags);
375 //} /* Draw3DRect() */
376
377
378 ///** void _Optlink Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen,
379 // *
380 // * DESCRIPTION:
381 // * Draws a 3D line that can be used to make a 3D box.
382 // *
383 // * ARGUMENTS:
384 // * HDC hdc : Handle to the device context that will be
385 // * used to display the 3D line.
386 // *
387 // * WORD x, y : Coordinates of the beginning of the line.
388 // * These coordinates are in device units and
389 // * represent the _outside_ most point. Horiz-
390 // * ontal lines are drawn from left to right and
391 // * vertical lines are drawn from top to bottom.
392 // *
393 // * WORD wShadowWidth : Width of the shadow in device coordinates.
394 // *
395 // * WORD wFlags : The following flags may be passed to
396 // * describe the style of the 3D line:
397 // *
398 // * DRAW3D_IN : The shadow is drawn such that
399 // * the box appears to be sunk in to the screen.
400 // * This is default if 0 is passed.
401 // *
402 // * DRAW3D_OUT : The shadow is drawn such that
403 // * the box appears to be sticking out of the
404 // * screen.
405 // *
406 // * DRAW3D_TOPLINE, _BOTTOMLINE, _LEFTLINE, and
407 // * _RIGHTLINE : Specifies that a "top",
408 // * "Bottom", "Left", or"Right" line is to be
409 // * drawn.
410 // *
411 // * RETURN (void _Optlink):
412 // * The line will have been drawn into the DC.
413 // *
414 // * NOTES:
415 // *
416 // ** cjp */
417
418 //void _Optlink Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen,
419 // WORD wShadowWidth, WORD wFlags)
420 //{
421 // HBRUSH hOldBrush;
422 // HPEN hOldPen;
423 // BOOL fDark;
424 // POINT Point[ 4 ]; /* define a polgon with 4 points */
425
426 // /* if width is zero, don't do nothin'! */
427 // if (!wShadowWidth)
428 // return;
429
430 /* define shape of polygon--origin is always the same */
431 // Point[0].x = x;
432 // Point[0].y = y;
433
434 // /* To do this we'll simply draw a polygon with four sides, using
435 // * the appropriate brush. I dare you to ask me why this isn't a
436 // * switch/case!
437 // */
438 // if (wFlags & DRAW3D_TOPLINE)
439 // {
440 // /* across to right */
441 // Point[1].x = x + nLen - (wShadowWidth == 1 ? 1 : 0);
442 // Point[1].y = y;
443
444 /* down/left */
445 // Point[2].x = x + nLen - wShadowWidth;
446 // Point[2].y = y + wShadowWidth;
447
448 /* accross to left */
449 // Point[3].x = x + wShadowWidth;
450 // Point[3].y = y + wShadowWidth;
451
452 /* select 'dark' brush if 'in'--'light' for 'out' */
453 // fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE;
454 // }
455
456 /* possibly the bottom? */
457 // else if (wFlags & DRAW3D_BOTTOMLINE)
458 // {
459 /* across to right */
460 // Point[1].x = x + nLen;
461 // Point[1].y = y;
462
463 /* up/left */
464 // Point[2].x = x + nLen - wShadowWidth;
465 // Point[2].y = y - wShadowWidth;
466
467 /* accross to left */
468 // Point[3].x = x + wShadowWidth;
469 // Point[3].y = y - wShadowWidth;
470
471 /* select 'light' brush if 'in' */
472 // fDark = (wFlags & DRAW3D_IN) ? FALSE : TRUE;
473 // }
474
475 /* ok, it's gotta be left? */
476 // else if (wFlags & DRAW3D_LEFTLINE)
477 // {
478 /* down */
479 // Point[1].x = x;
480 // Point[1].y = y + nLen - (wShadowWidth == 1 ? 1 : 0);
481
482 /* up/right */
483 // Point[2].x = x + wShadowWidth;
484 // Point[2].y = y + nLen - wShadowWidth;
485
486 /* down */
487 // Point[3].x = x + wShadowWidth;
488 // Point[3].y = y + wShadowWidth;
489
490 /* select 'dark' brush if 'in'--'light' for 'out' */
491 // fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE;
492 // }
493
494 /* well maybe it's for the right side? */
495 // else if (wFlags & DRAW3D_RIGHTLINE)
496 // {
497 /* down */
498 // Point[1].x = x;
499 // Point[1].y = y + nLen;
500
501 /* up/left */
502 // Point[2].x = x - wShadowWidth;
503 // Point[2].y = y + nLen - wShadowWidth;
504
505 /* up */
506 // Point[3].x = x - wShadowWidth;
507 // Point[3].y = y + wShadowWidth;
508
509 /* select 'light' brush if 'in' */
510 // fDark = (wFlags & DRAW3D_IN) ? FALSE : TRUE;
511 // }
512
513 /* bad drugs? */
514 // else return;
515
516 /* select NULL_PEN for no borders */
517 // hOldPen = (HPEN) SelectObject(hdc, GetStockObject(NULL_PEN));
518
519 /* select the appropriate color for the fill */
520 // if (fDark)
521 // hOldBrush = (HBRUSH) SelectObject(hdc, GetStockObject(GRAY_BRUSH));
522 // else
523 // hOldBrush = (HBRUSH) SelectObject(hdc, GetStockObject(WHITE_BRUSH));
524
525 /* finally, draw the dern thing */
526 // Polygon(hdc, (LPPOINT)&Point, 4);
527
528 /* restore what we killed */
529 // SelectObject(hdc, hOldBrush);
530 // SelectObject(hdc, hOldPen);
531 //} /* Draw3DLine() */
532
533 /** EOF: zyz3d.c **/
534
535 ///** zyzgauge.c
536 // *
537 // * DESCRIPTION:
538 // * Yet another 'Gas Gauge Custom Control.' This control gives you
539 // * a 'progress bar' class (named zYzGauge) for use in your applications.
540 // * You can set the range, position, font, color, orientation, and 3d
541 // * effect of the gauge by sending messages to the control.
542 // *
543 // * Before you can use this control, you MUST first export the window
544 // * procedure for the control (or define it with the _export keyword):
545 // *
546 // * EXPORTS gaugeWndProc
547 // *
548 // * You then need initialize the class before you use it:
549 // *
550 // * if (!gaugeInit(hInstance))
551 // * die a horrible death
552 // * else
553 // * you are good to go
554 // *
555 // * The colors used by the control default to black and white if you
556 // * are running on a mono-display. They default to blue and white
557 // * if you are on a color display. You enable the 3D effect by setting
558 // * the ZYZGS_3D style flag in the styles field of the control (like
559 // * any other control).
560 // *
561 // * To select your own colors, you can send the ZYZG_SETFGCOLOR and
562 // * ZYZG_SETBKCOLOR messages to set the foreground (percent done) and
563 // * background (percent not done) colors. The lParam is the RGB()
564 // * value--wParam is ignored.
565 // *
566 // * In all of the following ZYZG_??? messages, the arguments are
567 // * WORDS. If you are setting parameters, the value is sent as
568 // * the wParam (lParam is ignored). If you are getting parameters,
569 // * the value is returned as a LONG and should be cast to a *signed*
570 // * integer.
571 // *
572 // * To set the depth of the 3D effect (if enabled), you can send the
573 // * ZYZG_SETBEZELFACE and ZYZG_SETWIDTH3D messages. The bezel face
574 // * is the flat top on the 3D border--its color will be that of the
575 // * button-face. The 3D width is the width of the bezel itself; inside
576 // * and outside. The light color is white, the dark color is gray.
577 // * Both widths *can* be zero--both default to 2 which looks to me.
578 // *
579 // * The range of the control can be set by sending the ZYZG_SETRANGE
580 // * message to the control. It can be any integer from 1 to 32767.
581 // * What this specifies is the number of pieces that create a whole.
582 // * The default is 100. You can get the current range setting by
583 // * sending the ZYZG_GETRANGE message to the control.
584 // *
585 // * The position (number of pieces out of the whole have been used) is
586 // * set with the ZYZG_SETPOSITION message. It can be any integer from
587 // * 0 to the current range setting of the control--it will be clipped
588 // * if the position is out of bounds. The default position is 0. You
589 // * can get the current position at any time with the ZYZG_GETPOSITION
590 // * message.
591 // *
592 // * You can also set the range using a delta from the current range.
593 // * This is done by sending the ZYZG_SETDELTAPOS message with wParam
594 // * set to a _signed_ integer value within the range of the control.
595 // *
596 // * The font used for the percentage text can be set using the standard
597 // * WM_SETFONT message. You can get the current font at any time with
598 // * the WM_GETFONT message.
599 // *
600 // * The orientation can be left to right, right to left, bottom to top,
601 // * or top to bottom. Whatever suits your needs. You set this by
602 // * sending the ZYZG_ORIENTATION message to the control with one of
603 // * the following values (default is ZYZG_ORIENT_LEFTTORIGHT):
604 // *
605 // * ZYZG_ORIENT_LEFTTORIGHT (0)
606 // * ZYZG_ORIENT_RIGHTTOLEFT (1)
607 // * ZYZG_ORIENT_BOTTOMTOTOP (2)
608 // * ZYZG_ORIENT_TOPTOBOTTOM (3)
609 // *
610 // * HISTORY:
611 // * 3/12/91 cjp put in this comment
612 // * 6/19/92 cjp touched it a bit
613 // *
614 // ** cjp */
615 // COPYRIGHT:
616 //
617 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
618 //
619 // You have a royalty-free right to use, modify, reproduce and
620 // distribute the Sample Files (and/or any modified version) in
621 // any way you find useful, provided that you agree that
622 // Microsoft has no warranty obligations or liability for any
623 // Sample Application Files which are modified.
624 //
625
626
627 /* get the includes we need */
628 //#if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
629 //#include <malloc.h>
630 //#endif
631 //#include <stdio.h>
632 //#include <string.h>
633 //#include <stdlib.h>
634 // #include "zyz3d.h"
635 // #include "zyzgauge.h"
636
637
638 /* static global variables */
639 //static wxChar gszzYzGaugeClass[] = wxT("zYzGauge");
640
641
642 /* window word position definitions */
643 //#define ZYZG_WW_PZYZGAUGE 0
644 /* #define ZYZG_WW_EXTRABYTES 2 */
645 //#define ZYZG_WW_EXTRABYTES 4
646
647
648 /* control block structure typedef */
649 //typedef struct tZYZGAUGE
650 //{
651 // WORD wRange;
652 // WORD wPosition;
653 // WORD wOrientation;
654 // WORD wWidth3D;
655 // WORD wWidthBezelFace;
656 // HFONT hFont;
657 // DWORD rgbTextColor;
658 // DWORD rgbBkColor;
659
660 //} ZYZGAUGE, *PZYZGAUGE, FAR *LPZYZGAUGE;
661
662
663 /* some default values for the control */
664 //#define ZYZG_DEF_RANGE 100
665 //#define ZYZG_DEF_POSITION 0
666 //#define ZYZG_DEF_ORIENTATION ZYZG_ORIENT_LEFTTORIGHT
667 //#define ZYZG_DEF_WIDTH3D 2
668 //#define ZYZG_DEF_BEZELFACE 2
669
670
671
672 /* the default settings for drawing colors--display dependent */
673 //static DWORD rgbDefTextColor;
674 //static DWORD rgbDefBkColor;
675 //static BOOL fSupport3D;
676
677 //#if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
678 //#define APIENTRY _Optlink
679 //#endif
680
681 //#ifdef __WIN32__
682 //#define _EXPORT /**/
683 //#else
684 //#define _EXPORT _export
685 //typedef signed short int SHORT ;
686 //#endif
687
688 /* internal function prototypes */
689 //static void PASCAL gaugePaint(HWND, HDC);
690 /* LRESULT _Optlink */
691 //LRESULT APIENTRY _EXPORT gaugeWndProc(HWND, UINT, WPARAM, LPARAM);
692
693
694
695 ///** BOOL _Optlink gaugeInit(HINSTANCE hInstance)
696 // *
697 // * DESCRIPTION:
698 // * Registers the window class for the zYzGauge control. Performs
699 // * other initialization for the zYzGauge text control. This must
700 // * be done before the zYzGauge control is used--or it will fail
701 // * and your dialog box will not open!
702 // *
703 // * ARGUMENTS:
704 // * HINSTANCE hInstance : Instance handle to register class with.
705 // *
706 // * RETURN (BOOL FAR):
707 // * The return value is TRUE if the zYzGauge class was successfully
708 // * registered. It is FALSE if the initialization fails.
709 // *
710 // * NOTES:
711 // *
712 // ** cjp */
713
714 //#pragma alloc_text(init, gaugeInit)
715
716 //BOOL _Optlink gaugeInit(HINSTANCE hInstance)
717 //{
718 // static BOOL fRegistered = FALSE;
719 // WNDCLASS wc;
720 // HDC hdc;
721
722 /* assume already registered if not first instance */
723 // if (fRegistered)
724 // return (TRUE);
725
726 /* fill in the class structure for the zyzgauge control */
727 // wc.hCursor = LoadCursor(NULL, IDC_ARROW);
728 // wc.hIcon = NULL;
729 // wc.lpszMenuName = NULL;
730 // wc.lpszClassName = gszzYzGaugeClass;
731 // wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
732 // wc.hInstance = hInstance;
733
734 //#ifdef ZYZGAUGE_DLL
735 // wc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
736 //#else
737 // wc.style = CS_HREDRAW | CS_VREDRAW;
738 //#endif
739
740 // wc.lpfnWndProc = gaugeWndProc;
741 // wc.cbClsExtra = 0;
742 // wc.cbWndExtra = ZYZG_WW_EXTRABYTES;
743
744 /* attempt to register it--return FALSE if fail */
745 // if (!RegisterClass(&wc))
746 // return (FALSE);
747
748 /* Get a DC to determine whether device is mono or not, and set
749 * default foreground/background colors as appropriate.
750 */
751 // hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0L) ;
752 // if (hdc)
753 // {
754 /* check for mono-display */
755 // if ((GetDeviceCaps(hdc, BITSPIXEL) == 1) &&
756 // (GetDeviceCaps(hdc, PLANES) == 1))
757 // {
758 /* using a mono DC--white foreground, black background */
759 // rgbDefTextColor = RGB(255, 255, 255);
760 // rgbDefBkColor = RGB(0, 0, 0);
761 // }
762
763 /* good! we have color: blue foreground, white background */
764 // else
765 // {
766 // rgbDefTextColor = RGB(0, 0, 255);
767 // rgbDefBkColor = RGB(255, 255, 255);
768 // }
769
770 /* need at _least_ 8 for two shades of gray (>=VGA) */
771 // fSupport3D = (GetDeviceCaps(hdc, NUMCOLORS) >= 8) ? TRUE : FALSE;
772
773 /* get rid of the DC (IC) */
774 // DeleteDC(hdc);
775 // }
776
777 /* uh-oh... can't get DC (IC)... fail */
778 // else
779 // {
780 /* unregister the class */
781 // UnregisterClass(gszzYzGaugeClass, hInstance);
782 // return (FALSE);
783 // }
784
785 /* return success */
786 // return (fRegistered = TRUE);
787 //} /* gaugeInit() */
788
789
790 /** static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
791 // *
792 // * DESCRIPTION:
793 // * This function is responsible for painting the zYzGauge control.
794 // *
795 // * ARGUMENTS:
796 // * HWND hwnd : The window handle for the gauge.
797 // *
798 // * HDC hdc : The DC for the gauge's window.
799 // *
800 // * RETURN (void):
801 // * The control will have been painted.
802 // *
803 // * NOTES:
804 // *
805 // ** cjp */
806
807 //static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
808 //{
809 // PZYZGAUGE pgauge;
810 // WORD iRange, iPos;
811 // WORD Offset = 1;
812 // DWORD dwExtent;
813 // RECT rc1, rc2;
814 // HFONT hFont;
815 // wxChar ach[ 6 ];
816 // WORD dx, dy, wGomerX, wGomerY;
817 ///* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead,
818 // * which needs a SIZE* parameter */
819 //#if defined(__WIN32__)
820 // SIZE size;
821 //#endif
822
823 // /* get pointer to the control's control block */
824 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
825 // pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE);
826
827 /* set the colors into for the gauge into the control */
828 // SetTextColor(hdc, pgauge->rgbTextColor);
829 // SetBkColor(hdc, pgauge->rgbBkColor);
830
831 /* draw black rectangle for gauge */
832 // GetClientRect(hwnd, &rc1);
833
834 /* draw a black border on the _outside_ */
835 // FrameRect(hdc, &rc1, (HBRUSH) GetStockObject(BLACK_BRUSH));
836
837 /* we want to draw _just inside_ the black border */
838 // InflateRect(&rc1, -1, -1);
839
840 /* one line thick so far... */
841 // Offset = (WORD) 1;
842
843 /* for 3D stuff, we need to have at least two shades of gray */
844 // if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D)
845 // {
846 // Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_OUT);
847 // InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D));
848
849 // Draw3DFaceFrame(hdc, &rc1, pgauge->wWidthBezelFace);
850 // InflateRect(&rc1, ~(pgauge->wWidthBezelFace), ~(pgauge->wWidthBezelFace));
851
852 // Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_IN);
853 // InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D));
854
855 /* draw a black border on the _inside_ */
856 // FrameRect(hdc, &rc1, (HBRUSH) GetStockObject(BLACK_BRUSH));
857
858 /* we want to draw _just inside_ the black border */
859 // InflateRect(&rc1, -1, -1);
860
861 /* add all the other pixels into the border width */
862 // Offset += (2 * pgauge->wWidth3D) + pgauge->wWidthBezelFace + 1;
863 // }
864
865 /* dup--one rc for 'how much filled', one rc for 'how much empty' */
866 // rc2 = rc1;
867
868 /* get the range--make sure it's a valid range */
869 // if ((iRange = pgauge->wRange) <= 0)
870 // iRange = 1;
871
872 /* get the position--greater than 100% would be bad */
873 // if ((iPos = pgauge->wPosition) > iRange)
874 // iPos = iRange;
875
876 /* compute the actual size of the gauge */
877 // dx = rc1.right - rc1.left;
878 // dy = rc1.bottom - rc1.top;
879 // wGomerX = (WORD)((DWORD)iPos * dx / iRange);
880 // wGomerY = (WORD)((DWORD)iPos * dy / iRange);
881
882 /* get the orientation and munge rects accordingly */
883 // switch (pgauge->wOrientation)
884 // {
885 // case ZYZG_ORIENT_RIGHTTOLEFT:
886 // rc1.left = rc2.right = rc1.right - wGomerX;
887 // break;
888
889 // case ZYZG_ORIENT_BOTTOMTOTOP:
890 // rc1.top = rc2.bottom = rc1.bottom - wGomerY;
891 // break;
892
893 // case ZYZG_ORIENT_TOPTOBOTTOM:
894 // rc1.bottom = rc2.top += wGomerY;
895 // break;
896
897 // default:
898 // rc1.right = rc2.left += wGomerX;
899 // break;
900 // } /* switch () */
901
902 /* select the correct font */
903 // hFont = (HFONT) SelectObject(hdc, pgauge->hFont);
904
905 /* build up a string to blit out--ie the meaning of life: "42%" */
906 // wsprintf(ach, wxT("%3d%%"), (WORD)((DWORD)iPos * 100 / iRange));
907 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */
908 //#if defined(__WIN32__)
909 // GetTextExtentPoint(hdc, ach, wGomerX = lstrlen(ach), &size);
910 // dwExtent = size.cx;
911 //#else
912 // dwExtent = GetTextExtent(hdc, ach, wGomerX = lstrlen(ach));
913 //#endif
914
915
916 /* Draw the finished (ie the percent done) side of box. If
917 * ZYZG_WW_POSITION is 42, (in range of 0 to 100) this ExtTextOut
918 * draws the meaning of life (42%) bar.
919 */
920 // ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset,
921 // (dy - HIWORD(dwExtent)) / 2 + Offset,
922 // ETO_OPAQUE | ETO_CLIPPED, &rc2, ach, wGomerX, NULL);
923
924 /* Reverse fore and back colors for drawing the undone (ie the non-
925 * finished) side of the box.
926 */
927 // SetBkColor(hdc, pgauge->rgbTextColor);
928 // SetTextColor(hdc, pgauge->rgbBkColor);
929
930 // ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset,
931 // (dy - HIWORD(dwExtent)) / 2 + Offset,
932 // ETO_OPAQUE | ETO_CLIPPED, &rc1, ach, wGomerX, NULL);
933
934 /* unselect the font */
935 // SelectObject(hdc, hFont);
936 //} /* gaugePaint() */
937
938
939 /** LRESULT _Optlink gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
940 // *
941 // * DESCRIPTION:
942 // * This is the control's window procedure. Its purpose is to handle
943 // * special messages for this custom control.
944 // *
945 // * The special control messages for the gauge control are:
946 // *
947 // * ZYZG_SETRANGE : Sets the range of the gauge. In other
948 // * words, the number of parts that make a
949 // * whole.
950 // *
951 // * ZYZG_GETRANGE : Returns the current range of the gauge.
952 // *
953 // * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This
954 // * can be one of the ZYZG_ORIENT_?? msgs.
955 // *
956 // * ZYZG_GETORIENTATION : Gets the current orientation of the
957 // * gauge.
958 // *
959 // * ZYZG_SETPOSITION : Sets the current position of the gauge.
960 // * In other words, how many pieces of the
961 // * whole have been used.
962 // *
963 // * ZYZG_GETPOSITION : Gets the current position of the gauge.
964 // *
965 // * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the
966 // * specified amount.
967 // *
968 // * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color.
969 // *
970 // * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color.
971 // *
972 // * ZYZG_SETBKCOLOR : Sets the background (percent not done)
973 // * color.
974 // *
975 // * ZYZG_GETBKCOLOR : Gets the background (percent not done)
976 // * color.
977 // *
978 // * WM_SETFONT : Sets the font to use for the percentage
979 // * text of the gauge.
980 // *
981 // * WM_GETFONT : Gets the current font in use by the
982 // * gauge.
983 // *
984 // * NOTES:
985 // *
986 // ** cjp */
987
988 /* LRESULT _Optlink */
989
990 //LRESULT APIENTRY _EXPORT gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
991 //{
992 // HFONT hFont;
993 // PAINTSTRUCT ps;
994 // PZYZGAUGE pgauge;
995 // RECT rc;
996
997 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
998 // pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE);
999
1000 /* break to get DefWindowProc() */
1001 // switch (uMsg)
1002 // {
1003 // case WM_CREATE:
1004 /* need to allocate a control block */
1005 // pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE));
1006 // pgauge = (PZYZGAUGE)malloc(sizeof(ZYZGAUGE));
1007 // if (!pgauge)
1008 // return (0L);
1009
1010 /* hang on to this control block */
1011 // SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge);
1012 // SetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE, (LONG)pgauge);
1013
1014 /* fill control block with defaults */
1015 // pgauge->wRange = ZYZG_DEF_RANGE;
1016 // pgauge->wPosition = ZYZG_DEF_POSITION;
1017 // pgauge->wOrientation = ZYZG_DEF_ORIENTATION;
1018 // pgauge->wWidth3D = ZYZG_DEF_WIDTH3D;
1019 // pgauge->wWidthBezelFace = ZYZG_DEF_BEZELFACE;
1020 // pgauge->rgbTextColor = rgbDefTextColor;
1021 // pgauge->rgbBkColor = rgbDefBkColor;
1022
1023 /* use system font */
1024 // SendMessage(hwnd, WM_SETFONT, (WPARAM)NULL, 0L);
1025
1026 /* go to DefWindowProc() to finish the job */
1027 // break;
1028
1029 // case WM_DESTROY:
1030 /* get rid of the control's memory */
1031 // if (pgauge)
1032 // LocalFree((HANDLE)pgauge);
1033 // free(pgauge);
1034 // break;
1035
1036 // case ZYZG_GETPOSITION:
1037 // return (pgauge->wPosition);
1038
1039 // case ZYZG_GETRANGE:
1040 // return (pgauge->wRange);
1041
1042 // case ZYZG_GETORIENTATION:
1043 // return (pgauge->wOrientation);
1044
1045 // case ZYZG_GETWIDTH3D:
1046 // return (pgauge->wWidth3D);
1047
1048 // case ZYZG_GETBEZELFACE:
1049 // return (pgauge->wWidthBezelFace);
1050
1051 // case ZYZG_GETBKCOLOR:
1052 // return (pgauge->rgbTextColor);
1053
1054 // case ZYZG_GETFGCOLOR:
1055 // return (pgauge->rgbBkColor);
1056
1057 // case ZYZG_SETBKCOLOR:
1058 // pgauge->rgbBkColor = lParam;
1059 // return (0L);
1060
1061 // case ZYZG_SETFGCOLOR:
1062 // pgauge->rgbTextColor = lParam;
1063 // return (0L);
1064
1065
1066 // case ZYZG_SETPOSITION:
1067 // pgauge->wPosition = wParam;
1068
1069 //zyzgForceRepaint:
1070 // GetClientRect(hwnd, &rc);
1071 // if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D)
1072 // {
1073 // wParam = (2 * pgauge->wWidth3D) +
1074 // pgauge->wWidthBezelFace + 2;
1075 // }
1076
1077 // else
1078 // wParam = 1;
1079
1080 // InflateRect(&rc, ~(wParam), ~(wParam));
1081 // InvalidateRect(hwnd, &rc, FALSE);
1082 // UpdateWindow(hwnd);
1083 // return (0L);
1084
1085 // case ZYZG_SETRANGE:
1086 // pgauge->wRange = wParam;
1087 // goto zyzgForceRepaint;
1088
1089 // case ZYZG_SETORIENTATION:
1090 // pgauge->wOrientation = wParam;
1091 // goto zyzgForceRepaint;
1092
1093 // case ZYZG_SETWIDTH3D:
1094 // pgauge->wWidth3D = wParam;
1095
1096 //zyzgForceRepaint3D:
1097 // InvalidateRect(hwnd, NULL, FALSE);
1098 // UpdateWindow(hwnd);
1099 // return (0L);
1100
1101 // case ZYZG_SETBEZELFACE:
1102 // pgauge->wWidthBezelFace = wParam;
1103 // goto zyzgForceRepaint3D;
1104
1105 // case ZYZG_SETDELTAPOS:
1106 ///* Watcom doesn't like the following line so removing typecasts */
1107 ///* (int)pgauge->wPosition += (int)wParam; */
1108 // pgauge->wPosition += wParam;
1109 // goto zyzgForceRepaint;
1110
1111 // case WM_PAINT:
1112 // BeginPaint(hwnd, &ps);
1113 // gaugePaint(hwnd, ps.hdc);
1114 // EndPaint(hwnd, &ps);
1115 // return (0L);
1116
1117 // case WM_GETFONT:
1118 // hFont = pgauge->hFont;
1119
1120 // /* if system font, then return NULL handle */
1121 // return (long)((hFont == GetStockObject(SYSTEM_FONT)) ? NULL : hFont);
1122
1123 // case WM_SETFONT:
1124 /* if NULL hFont, use system font */
1125 // hFont = (HFONT)wParam ;
1126 // if (!hFont)
1127 // hFont = (HFONT) GetStockObject(SYSTEM_FONT);
1128
1129 // pgauge->hFont = hFont;
1130
1131 /* redraw if indicated in message */
1132 // if ((BOOL)lParam)
1133 // {
1134 // InvalidateRect(hwnd, NULL, TRUE);
1135 // UpdateWindow(hwnd);
1136 // }
1137 // return (0L);
1138 // } /* switch () */
1139
1140 /* let the dialog mangler take care of this message */
1141 // return (DefWindowProc(hwnd, uMsg, wParam, lParam));
1142 //} /* gaugeWndProc() */
1143
1144
1145 /** EOF: zyzgauge.c **/
1146
1147