]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGauge class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
19 #include "wx/os2/private.h"
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)
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
46 #define ZYZGS_3D 0x8000L /* control will be 3D */
48 /* public function prototypes */
49 // BOOL _Optlink gaugeInit(HINSTANCE hInstance);
51 #if !USE_SHARED_LIBRARY
52 IMPLEMENT_DYNAMIC_CLASS(wxGauge
, wxControl
)
55 bool wxGauge::Create(wxWindow
*parent
, wxWindowID id
,
61 # if defined(__VISAGECPP__)
62 const wxValidator
* validator
,
64 const wxValidator
& validator
,
69 static bool wxGaugeOS2Initialised
= FALSE
;
71 if ( !wxGaugeOS2Initialised
)
75 if (!gaugeInit((HINSTANCE) wxGetInstance()))
76 wxFatalError("Cannot initalize Gauge library");
78 wxGaugeOS2Initialised
= TRUE
;
83 SetValidator(validator
);
85 if (parent
) parent
->AddChild(this);
89 m_windowStyle
= style
;
92 m_windowId
= (int)NewControlId();
108 long msFlags = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
112 CreateWindowEx(MakeExtendedStyle(m_windowStyle), wxT("zYzGauge"), NULL, msFlags,
113 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
114 wxGetInstance(), NULL);
116 m_hWnd = (WXHWND)wx_button;
118 // Subclass again for purposes of dialog editing mode
119 SubclassWin((WXHWND)wx_button);
123 if (m_windowStyle & wxGA_HORIZONTAL)
124 wOrient = ZYZG_ORIENT_LEFTTORIGHT;
126 wOrient = ZYZG_ORIENT_BOTTOMTOTOP;
128 SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0);
129 SendMessage(wx_button, ZYZG_SETRANGE, range, 0);
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()));
134 SetFont(parent->GetFont());
140 SetSize(x, y, width, height);
142 ShowWindow(GetHwnd(), SW_SHOW);
147 void wxGauge::SetShadowWidth(int w
)
149 // TODO optional ::SendMessage(GetHwnd(), ZYZG_SETWIDTH3D, w, 0);
152 void wxGauge::SetBezelFace(int w
)
154 // TODO optional ::SendMessage(GetHwnd(), ZYZG_SETBEZELFACE, w, 0);
157 void wxGauge::SetRange(int r
)
160 // TODO ::SendMessage(GetHwnd(), ZYZG_SETRANGE, r, 0);
163 void wxGauge::SetValue(int pos
)
166 // TODO ::SendMessage(GetHwnd(), ZYZG_SETPOSITION, pos, 0);
169 int wxGauge::GetShadowWidth() const
171 // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETWIDTH3D, 0, 0);
175 int wxGauge::GetBezelFace() const
177 // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETBEZELFACE, 0, 0);
181 int wxGauge::GetRange() const
183 // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETRANGE, 0, 0);
187 int wxGauge::GetValue() const
189 // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETPOSITION, 0, 0);
193 bool wxGauge::SetForegroundColour(const wxColour
& col
)
195 if ( !wxControl::SetForegroundColour(col
) )
198 // TODO ::SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
203 bool wxGauge::SetBackgroundColour(const wxColour
& col
)
205 if ( !wxControl::SetBackgroundColour(col
) )
208 // TODO ::SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
216 // * This module contains functions for creating nifty 3D borders
217 // * around controls like zYzGauge.
220 // * 3/14/91 cjp put in this comment
221 // * 6/19/92 cjp touched it a bit
226 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
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.
236 ///* get the includes we need */
240 ///* misc. control flag defines */
241 //#define DRAW3D_IN 0x0001
242 //#define DRAW3D_OUT 0x0002
244 //#define DRAW3D_TOPLINE 0x0004
245 //#define DRAW3D_BOTTOMLINE 0x0008
246 //#define DRAW3D_LEFTLINE 0x0010
247 //#define DRAW3D_RIGHTLINE 0x0020
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);
256 ///** void _Optlink Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth)
259 // * This function draws a flat frame with the current button-face
263 // * HDC hdc : The DC to draw into.
265 // * LPRECT rc : The containing rect for the new frame.
267 // * WORD wWidth : The width of the frame to draw.
269 // * RETURN (void _Optlink):
270 // * The frame will have been drawn into the DC.
276 //void _Optlink Draw3DFaceFrame(HDC hdc, RECTL* rc, WORD wWidth)
281 // /* don't go through a bunch of work if we don't have to */
285 // /* set up color to be button-face color--so it may not be gray */
286 // rgbOld = SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
288 // /* perform CopyRect w/o bloody windows style overhead */
292 // rc1.top = rc->top;
293 // rc1.left = rc->left;
294 // rc1.bottom = rc->top + wWidth;
295 // rc1.right = rc->right;
298 // ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL);
301 // rc1.left = rc->right - wWidth;
302 // rc1.bottom = rc->bottom;
304 /* blast this part now */
305 // ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL);
308 // rc1.left = rc->left;
309 // rc1.right = rc->left + wWidth;
311 /* and another part */
312 // ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL);
315 // rc1.right = rc->right;
316 // rc1.top = rc->bottom - wWidth;
319 // ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL);
321 /* restore the old bk color */
322 // SetBkColor(hdc, rgbOld);
323 //} /* Draw3DFaceFrame() */
326 ///** void _Optlink Draw3DRect(HDC, LPRECT, WORD, WORD)
329 // * Draws a 3D rectangle that is shaded. wFlags can be used to
330 // * control how the rectangle looks.
333 // * HDC hdc : Handle to the device context that will be
334 // * used to display the rectangle.
336 // * RECT rect : A rectangle describing the dimensions of
337 // * the rectangle in device coordinates.
339 // * WORD wShadowWidth : Width of the shadow in device coordinates.
341 // * WORD wFlags : The following flags may be passed to describe
342 // * the style of the rectangle:
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.
348 // * DRAW3D_OUT : The shadow is drawn such that
349 // * the box appears to be sticking out of the
352 // * RETURN (void _Optlink):
353 // * The 3D looking rectangle will have been drawn into the DC.
359 //void _Optlink Draw3DRect(HDC hdc, LPRECT lpRect,
360 // WORD wShadowWidth, WORD wFlags)
362 // /* sanity check--don't work if you don't have to! */
363 // if (!wShadowWidth || !RectVisible(hdc, lpRect))
366 /* draw the top line */
367 // Draw3DLine(hdc, lpRect->left, lpRect->top,
368 // lpRect->right - lpRect->left,
369 // wShadowWidth, DRAW3D_TOPLINE | wFlags);
372 // Draw3DLine(hdc, lpRect->right, lpRect->top,
373 // lpRect->bottom - lpRect->top,
374 // wShadowWidth, DRAW3D_RIGHTLINE | wFlags);
377 // Draw3DLine(hdc, lpRect->left, lpRect->bottom,
378 // lpRect->right - lpRect->left,
379 // wShadowWidth, DRAW3D_BOTTOMLINE | wFlags);
382 // Draw3DLine(hdc, lpRect->left, lpRect->top,
383 // lpRect->bottom - lpRect->top,
384 // wShadowWidth, DRAW3D_LEFTLINE | wFlags);
385 //} /* Draw3DRect() */
388 ///** void _Optlink Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen,
391 // * Draws a 3D line that can be used to make a 3D box.
394 // * HDC hdc : Handle to the device context that will be
395 // * used to display the 3D line.
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.
403 // * WORD wShadowWidth : Width of the shadow in device coordinates.
405 // * WORD wFlags : The following flags may be passed to
406 // * describe the style of the 3D line:
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.
412 // * DRAW3D_OUT : The shadow is drawn such that
413 // * the box appears to be sticking out of the
416 // * DRAW3D_TOPLINE, _BOTTOMLINE, _LEFTLINE, and
417 // * _RIGHTLINE : Specifies that a "top",
418 // * "Bottom", "Left", or"Right" line is to be
421 // * RETURN (void _Optlink):
422 // * The line will have been drawn into the DC.
428 //void _Optlink Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen,
429 // WORD wShadowWidth, WORD wFlags)
434 // POINT Point[ 4 ]; /* define a polgon with 4 points */
436 // /* if width is zero, don't do nothin'! */
437 // if (!wShadowWidth)
440 /* define shape of polygon--origin is always the same */
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
448 // if (wFlags & DRAW3D_TOPLINE)
450 // /* across to right */
451 // Point[1].x = x + nLen - (wShadowWidth == 1 ? 1 : 0);
455 // Point[2].x = x + nLen - wShadowWidth;
456 // Point[2].y = y + wShadowWidth;
458 /* accross to left */
459 // Point[3].x = x + wShadowWidth;
460 // Point[3].y = y + wShadowWidth;
462 /* select 'dark' brush if 'in'--'light' for 'out' */
463 // fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE;
466 /* possibly the bottom? */
467 // else if (wFlags & DRAW3D_BOTTOMLINE)
469 /* across to right */
470 // Point[1].x = x + nLen;
474 // Point[2].x = x + nLen - wShadowWidth;
475 // Point[2].y = y - wShadowWidth;
477 /* accross to left */
478 // Point[3].x = x + wShadowWidth;
479 // Point[3].y = y - wShadowWidth;
481 /* select 'light' brush if 'in' */
482 // fDark = (wFlags & DRAW3D_IN) ? FALSE : TRUE;
485 /* ok, it's gotta be left? */
486 // else if (wFlags & DRAW3D_LEFTLINE)
490 // Point[1].y = y + nLen - (wShadowWidth == 1 ? 1 : 0);
493 // Point[2].x = x + wShadowWidth;
494 // Point[2].y = y + nLen - wShadowWidth;
497 // Point[3].x = x + wShadowWidth;
498 // Point[3].y = y + wShadowWidth;
500 /* select 'dark' brush if 'in'--'light' for 'out' */
501 // fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE;
504 /* well maybe it's for the right side? */
505 // else if (wFlags & DRAW3D_RIGHTLINE)
509 // Point[1].y = y + nLen;
512 // Point[2].x = x - wShadowWidth;
513 // Point[2].y = y + nLen - wShadowWidth;
516 // Point[3].x = x - wShadowWidth;
517 // Point[3].y = y + wShadowWidth;
519 /* select 'light' brush if 'in' */
520 // fDark = (wFlags & DRAW3D_IN) ? FALSE : TRUE;
526 /* select NULL_PEN for no borders */
527 // hOldPen = (HPEN) SelectObject(hdc, GetStockObject(NULL_PEN));
529 /* select the appropriate color for the fill */
531 // hOldBrush = (HBRUSH) SelectObject(hdc, GetStockObject(GRAY_BRUSH));
533 // hOldBrush = (HBRUSH) SelectObject(hdc, GetStockObject(WHITE_BRUSH));
535 /* finally, draw the dern thing */
536 // Polygon(hdc, (LPPOINT)&Point, 4);
538 /* restore what we killed */
539 // SelectObject(hdc, hOldBrush);
540 // SelectObject(hdc, hOldPen);
541 //} /* Draw3DLine() */
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.
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):
556 // * EXPORTS gaugeWndProc
558 // * You then need initialize the class before you use it:
560 // * if (!gaugeInit(hInstance))
561 // * die a horrible death
563 // * you are good to go
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).
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.
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*
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.
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.
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
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.
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.
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):
615 // * ZYZG_ORIENT_LEFTTORIGHT (0)
616 // * ZYZG_ORIENT_RIGHTTOLEFT (1)
617 // * ZYZG_ORIENT_BOTTOMTOTOP (2)
618 // * ZYZG_ORIENT_TOPTOBOTTOM (3)
621 // * 3/12/91 cjp put in this comment
622 // * 6/19/92 cjp touched it a bit
627 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
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.
637 /* get the includes we need */
638 //#if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
639 //#include <malloc.h>
642 //#include <string.h>
643 //#include <stdlib.h>
644 // #include "zyz3d.h"
645 // #include "zyzgauge.h"
648 /* static global variables */
649 //static wxChar gszzYzGaugeClass[] = wxT("zYzGauge");
652 /* window word position definitions */
653 //#define ZYZG_WW_PZYZGAUGE 0
654 /* #define ZYZG_WW_EXTRABYTES 2 */
655 //#define ZYZG_WW_EXTRABYTES 4
658 /* control block structure typedef */
659 //typedef struct tZYZGAUGE
663 // WORD wOrientation;
665 // WORD wWidthBezelFace;
667 // DWORD rgbTextColor;
670 //} ZYZGAUGE, *PZYZGAUGE, FAR *LPZYZGAUGE;
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
682 /* the default settings for drawing colors--display dependent */
683 //static DWORD rgbDefTextColor;
684 //static DWORD rgbDefBkColor;
685 //static BOOL fSupport3D;
687 //#if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
688 //#define APIENTRY _Optlink
692 //#define _EXPORT /**/
694 //#define _EXPORT _export
695 //typedef signed short int SHORT ;
698 /* internal function prototypes */
699 //static void PASCAL gaugePaint(HWND, HDC);
700 /* LRESULT _Optlink */
701 //LRESULT APIENTRY _EXPORT gaugeWndProc(HWND, UINT, WPARAM, LPARAM);
705 ///** BOOL _Optlink gaugeInit(HINSTANCE hInstance)
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!
714 // * HINSTANCE hInstance : Instance handle to register class with.
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.
724 //#pragma alloc_text(init, gaugeInit)
726 //BOOL _Optlink gaugeInit(HINSTANCE hInstance)
728 // static BOOL fRegistered = FALSE;
732 /* assume already registered if not first instance */
736 /* fill in the class structure for the zyzgauge control */
737 // wc.hCursor = LoadCursor(NULL, IDC_ARROW);
739 // wc.lpszMenuName = NULL;
740 // wc.lpszClassName = gszzYzGaugeClass;
741 // wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
742 // wc.hInstance = hInstance;
744 //#ifdef ZYZGAUGE_DLL
745 // wc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
747 // wc.style = CS_HREDRAW | CS_VREDRAW;
750 // wc.lpfnWndProc = gaugeWndProc;
751 // wc.cbClsExtra = 0;
752 // wc.cbWndExtra = ZYZG_WW_EXTRABYTES;
754 /* attempt to register it--return FALSE if fail */
755 // if (!RegisterClass(&wc))
758 /* Get a DC to determine whether device is mono or not, and set
759 * default foreground/background colors as appropriate.
761 // hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0L) ;
764 /* check for mono-display */
765 // if ((GetDeviceCaps(hdc, BITSPIXEL) == 1) &&
766 // (GetDeviceCaps(hdc, PLANES) == 1))
768 /* using a mono DC--white foreground, black background */
769 // rgbDefTextColor = RGB(255, 255, 255);
770 // rgbDefBkColor = RGB(0, 0, 0);
773 /* good! we have color: blue foreground, white background */
776 // rgbDefTextColor = RGB(0, 0, 255);
777 // rgbDefBkColor = RGB(255, 255, 255);
780 /* need at _least_ 8 for two shades of gray (>=VGA) */
781 // fSupport3D = (GetDeviceCaps(hdc, NUMCOLORS) >= 8) ? TRUE : FALSE;
783 /* get rid of the DC (IC) */
787 /* uh-oh... can't get DC (IC)... fail */
790 /* unregister the class */
791 // UnregisterClass(gszzYzGaugeClass, hInstance);
796 // return (fRegistered = TRUE);
797 //} /* gaugeInit() */
800 /** static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
803 // * This function is responsible for painting the zYzGauge control.
806 // * HWND hwnd : The window handle for the gauge.
808 // * HDC hdc : The DC for the gauge's window.
811 // * The control will have been painted.
817 //static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
820 // WORD iRange, iPos;
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__)
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);
837 /* set the colors into for the gauge into the control */
838 // SetTextColor(hdc, pgauge->rgbTextColor);
839 // SetBkColor(hdc, pgauge->rgbBkColor);
841 /* draw black rectangle for gauge */
842 // GetClientRect(hwnd, &rc1);
844 /* draw a black border on the _outside_ */
845 // FrameRect(hdc, &rc1, (HBRUSH) GetStockObject(BLACK_BRUSH));
847 /* we want to draw _just inside_ the black border */
848 // InflateRect(&rc1, -1, -1);
850 /* one line thick so far... */
851 // Offset = (WORD) 1;
853 /* for 3D stuff, we need to have at least two shades of gray */
854 // if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D)
856 // Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_OUT);
857 // InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D));
859 // Draw3DFaceFrame(hdc, &rc1, pgauge->wWidthBezelFace);
860 // InflateRect(&rc1, ~(pgauge->wWidthBezelFace), ~(pgauge->wWidthBezelFace));
862 // Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_IN);
863 // InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D));
865 /* draw a black border on the _inside_ */
866 // FrameRect(hdc, &rc1, (HBRUSH) GetStockObject(BLACK_BRUSH));
868 /* we want to draw _just inside_ the black border */
869 // InflateRect(&rc1, -1, -1);
871 /* add all the other pixels into the border width */
872 // Offset += (2 * pgauge->wWidth3D) + pgauge->wWidthBezelFace + 1;
875 /* dup--one rc for 'how much filled', one rc for 'how much empty' */
878 /* get the range--make sure it's a valid range */
879 // if ((iRange = pgauge->wRange) <= 0)
882 /* get the position--greater than 100% would be bad */
883 // if ((iPos = pgauge->wPosition) > iRange)
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);
892 /* get the orientation and munge rects accordingly */
893 // switch (pgauge->wOrientation)
895 // case ZYZG_ORIENT_RIGHTTOLEFT:
896 // rc1.left = rc2.right = rc1.right - wGomerX;
899 // case ZYZG_ORIENT_BOTTOMTOTOP:
900 // rc1.top = rc2.bottom = rc1.bottom - wGomerY;
903 // case ZYZG_ORIENT_TOPTOBOTTOM:
904 // rc1.bottom = rc2.top += wGomerY;
908 // rc1.right = rc2.left += wGomerX;
912 /* select the correct font */
913 // hFont = (HFONT) SelectObject(hdc, pgauge->hFont);
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;
922 // dwExtent = GetTextExtent(hdc, ach, wGomerX = lstrlen(ach));
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.
930 // ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset,
931 // (dy - HIWORD(dwExtent)) / 2 + Offset,
932 // ETO_OPAQUE | ETO_CLIPPED, &rc2, ach, wGomerX, NULL);
934 /* Reverse fore and back colors for drawing the undone (ie the non-
935 * finished) side of the box.
937 // SetBkColor(hdc, pgauge->rgbTextColor);
938 // SetTextColor(hdc, pgauge->rgbBkColor);
940 // ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset,
941 // (dy - HIWORD(dwExtent)) / 2 + Offset,
942 // ETO_OPAQUE | ETO_CLIPPED, &rc1, ach, wGomerX, NULL);
944 /* unselect the font */
945 // SelectObject(hdc, hFont);
946 //} /* gaugePaint() */
949 /** LRESULT _Optlink gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
952 // * This is the control's window procedure. Its purpose is to handle
953 // * special messages for this custom control.
955 // * The special control messages for the gauge control are:
957 // * ZYZG_SETRANGE : Sets the range of the gauge. In other
958 // * words, the number of parts that make a
961 // * ZYZG_GETRANGE : Returns the current range of the gauge.
963 // * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This
964 // * can be one of the ZYZG_ORIENT_?? msgs.
966 // * ZYZG_GETORIENTATION : Gets the current orientation of the
969 // * ZYZG_SETPOSITION : Sets the current position of the gauge.
970 // * In other words, how many pieces of the
971 // * whole have been used.
973 // * ZYZG_GETPOSITION : Gets the current position of the gauge.
975 // * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the
976 // * specified amount.
978 // * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color.
980 // * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color.
982 // * ZYZG_SETBKCOLOR : Sets the background (percent not done)
985 // * ZYZG_GETBKCOLOR : Gets the background (percent not done)
988 // * WM_SETFONT : Sets the font to use for the percentage
989 // * text of the gauge.
991 // * WM_GETFONT : Gets the current font in use by the
998 /* LRESULT _Optlink */
1000 //LRESULT APIENTRY _EXPORT gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1004 // PZYZGAUGE pgauge;
1007 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
1008 // pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE);
1010 /* break to get DefWindowProc() */
1014 /* need to allocate a control block */
1015 // pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE));
1016 // pgauge = (PZYZGAUGE)malloc(sizeof(ZYZGAUGE));
1020 /* hang on to this control block */
1021 // SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge);
1022 // SetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE, (LONG)pgauge);
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;
1033 /* use system font */
1034 // SendMessage(hwnd, WM_SETFONT, (WPARAM)NULL, 0L);
1036 /* go to DefWindowProc() to finish the job */
1040 /* get rid of the control's memory */
1042 // LocalFree((HANDLE)pgauge);
1046 // case ZYZG_GETPOSITION:
1047 // return (pgauge->wPosition);
1049 // case ZYZG_GETRANGE:
1050 // return (pgauge->wRange);
1052 // case ZYZG_GETORIENTATION:
1053 // return (pgauge->wOrientation);
1055 // case ZYZG_GETWIDTH3D:
1056 // return (pgauge->wWidth3D);
1058 // case ZYZG_GETBEZELFACE:
1059 // return (pgauge->wWidthBezelFace);
1061 // case ZYZG_GETBKCOLOR:
1062 // return (pgauge->rgbTextColor);
1064 // case ZYZG_GETFGCOLOR:
1065 // return (pgauge->rgbBkColor);
1067 // case ZYZG_SETBKCOLOR:
1068 // pgauge->rgbBkColor = lParam;
1071 // case ZYZG_SETFGCOLOR:
1072 // pgauge->rgbTextColor = lParam;
1076 // case ZYZG_SETPOSITION:
1077 // pgauge->wPosition = wParam;
1080 // GetClientRect(hwnd, &rc);
1081 // if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D)
1083 // wParam = (2 * pgauge->wWidth3D) +
1084 // pgauge->wWidthBezelFace + 2;
1090 // InflateRect(&rc, ~(wParam), ~(wParam));
1091 // InvalidateRect(hwnd, &rc, FALSE);
1092 // UpdateWindow(hwnd);
1095 // case ZYZG_SETRANGE:
1096 // pgauge->wRange = wParam;
1097 // goto zyzgForceRepaint;
1099 // case ZYZG_SETORIENTATION:
1100 // pgauge->wOrientation = wParam;
1101 // goto zyzgForceRepaint;
1103 // case ZYZG_SETWIDTH3D:
1104 // pgauge->wWidth3D = wParam;
1106 //zyzgForceRepaint3D:
1107 // InvalidateRect(hwnd, NULL, FALSE);
1108 // UpdateWindow(hwnd);
1111 // case ZYZG_SETBEZELFACE:
1112 // pgauge->wWidthBezelFace = wParam;
1113 // goto zyzgForceRepaint3D;
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;
1122 // BeginPaint(hwnd, &ps);
1123 // gaugePaint(hwnd, ps.hdc);
1124 // EndPaint(hwnd, &ps);
1128 // hFont = pgauge->hFont;
1130 // /* if system font, then return NULL handle */
1131 // return (long)((hFont == GetStockObject(SYSTEM_FONT)) ? NULL : hFont);
1134 /* if NULL hFont, use system font */
1135 // hFont = (HFONT)wParam ;
1137 // hFont = (HFONT) GetStockObject(SYSTEM_FONT);
1139 // pgauge->hFont = hFont;
1141 /* redraw if indicated in message */
1142 // if ((BOOL)lParam)
1144 // InvalidateRect(hwnd, NULL, TRUE);
1145 // UpdateWindow(hwnd);
1148 // } /* switch () */
1150 /* let the dialog mangler take care of this message */
1151 // return (DefWindowProc(hwnd, uMsg, wParam, lParam));
1152 //} /* gaugeWndProc() */
1155 /** EOF: zyzgauge.c **/