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