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