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