From: Julian Smart Date: Sun, 28 Jun 1998 11:32:14 +0000 (+0000) Subject: Separated out Win95 versions of gauge, slider; added wxTabCtrl::GetCurFocus X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/da87a1ca42a81c7b7b69cb013eb52d09cd5c1b70 Separated out Win95 versions of gauge, slider; added wxTabCtrl::GetCurFocus git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@153 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/gauge.h b/include/wx/msw/gauge.h index 070d25ca46..e4df50bc8a 100644 --- a/include/wx/msw/gauge.h +++ b/include/wx/msw/gauge.h @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: gauge.h -// Purpose: wxGauge class +// Purpose: wxGauge header, includes gauge class headers as appropriate // Author: Julian Smart // Modified by: // Created: 01/02/97 @@ -16,66 +16,15 @@ #pragma interface "gauge.h" #endif -#include "wx/control.h" - -WXDLLEXPORT_DATA(extern const char*) wxGaugeNameStr; - -// Group box -class WXDLLEXPORT wxGauge: public wxControl -{ - DECLARE_DYNAMIC_CLASS(wxGauge) - public: - inline wxGauge(void) { m_rangeMax = 0; m_gaugePos = 0; m_useProgressBar = FALSE; } - - inline wxGauge(wxWindow *parent, const wxWindowID id, - const int range, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - const long style = wxGA_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxGaugeNameStr) - { - Create(parent, id, range, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, const wxWindowID id, - const int range, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - const long style = wxGA_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxGaugeNameStr); - - void SetShadowWidth(const int w); - void SetBezelFace(const int w); - void SetRange(const int r); - void SetValue(const int pos); - - int GetShadowWidth(void) const ; - int GetBezelFace(void) const ; - int GetRange(void) const ; - int GetValue(void) const ; - - void SetForegroundColour(const wxColour& col); - void SetBackgroundColour(const wxColour& col); - - // Backward compatibility -#if WXWIN_COMPATIBILITY - inline void SetButtonColour(const wxColour& col) { SetForegroundColour(col); } +#ifdef __WIN95__ +#include "wx/msw/gauge95.h" +#define wxGauge wxGauge95 +#define classwxGauge classwxGauge95 +#else +#include "wx/msw/gaugemsw.h +#define wxGauge wxGaugeMSW +#define classwxGauge classwxGaugeMSW #endif - void SetSize(const int x, const int y, const int width, const int height, const int sizeFlags = wxSIZE_AUTO); - - // Are we a Win95 progress bar, or a normal gauge? - inline bool GetProgressBar(void) const { return m_useProgressBar; } - - virtual void Command(wxCommandEvent& WXUNUSED(event)) {} ; - - protected: - int m_rangeMax; - int m_gaugePos; - bool m_useProgressBar; -}; - #endif // __GAUGEH__ diff --git a/include/wx/msw/slider.h b/include/wx/msw/slider.h index 78a5e28fa1..3ac84b5342 100644 --- a/include/wx/msw/slider.h +++ b/include/wx/msw/slider.h @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: slider.h -// Purpose: wxSlider class +// Purpose: wxSlider header, includes slider class headers as appropriate // Author: Julian Smart // Modified by: // Created: 01/02/97 @@ -9,102 +9,22 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#ifndef __SLIDERH__ -#define __SLIDERH__ +#ifndef _SLIDER_H_ +#define _SLIDER_H_ #ifdef __GNUG__ #pragma interface "slider.h" #endif -#include "wx/control.h" - -WXDLLEXPORT_DATA(extern const char*) wxSliderNameStr; - -// Slider -class WXDLLEXPORT wxSlider: public wxControl -{ - DECLARE_DYNAMIC_CLASS(wxSlider) - -public: - wxSlider(void); - - inline wxSlider(wxWindow *parent, const wxWindowID id, - const int value, const int minValue, const int maxValue, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - const long style = wxSL_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxSliderNameStr) - { - Create(parent, id, value, minValue, maxValue, pos, size, style, validator, name); - } - - ~wxSlider(void); - - bool Create(wxWindow *parent, const wxWindowID id, - const int value, const int minValue, const int maxValue, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - const long style = wxSL_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxSliderNameStr); - - virtual int GetValue(void) const ; - virtual void SetValue(const int); - void GetSize(int *x, int *y) const ; - void SetSize(const int x, const int y, const int width, const int height, const int sizeFlags = wxSIZE_AUTO); - void GetPosition(int *x, int *y) const ; - bool Show(const bool show); - - void SetRange(const int minValue, const int maxValue); - - inline int GetMin(void) const { return m_rangeMin; } - inline int GetMax(void) const { return m_rangeMax; } - - // For trackbars only - void SetTickFreq(const int n, const int pos); - inline int GetTickFreq(void) const { return m_tickFreq; } - void SetPageSize(const int pageSize); - int GetPageSize(void) const ; - void ClearSel(void) ; - void ClearTicks(void) ; - void SetLineSize(const int lineSize); - int GetLineSize(void) const ; - int GetSelEnd(void) const ; - int GetSelStart(void) const ; - void SetSelection(const int minPos, const int maxPos); - void SetThumbLength(const int len) ; - int GetThumbLength(void) const ; - void SetTick(const int tickPos) ; - - // IMPLEMENTATION - inline WXHWND GetStaticMin() const { return m_staticMin; } - inline WXHWND GetStaticMax() const { return m_staticMax; } - inline WXHWND GetEditValue() const { return m_staticValue; } - virtual bool ContainsHWND(WXHWND hWnd) const; - - // Backward compatibility: translate to familiar wxEVT_COMMAND_SLIDER_UPDATED -#if WXWIN_COMPATIBILITY - void OnScroll(wxScrollEvent& event); +#ifdef __WIN95__ +#include "wx/msw/slider95.h" +#define wxSlider wxSlider95 +#define classwxSlider classwxSlider95 +#else +#include "wx/msw/slidrmsw.h" +#define wxSlider wxSliderMSW +#define classwxSlider classwxSliderMSW #endif - void Command(wxCommandEvent& event); - virtual WXHBRUSH OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - void MSWOnVScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control); - void MSWOnHScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control); - - protected: - WXHWND m_staticMin; - WXHWND m_staticMax; - WXHWND m_staticValue; - int m_rangeMin; - int m_rangeMax; - int m_pageSize; - int m_lineSize; - int m_tickFreq; -DECLARE_EVENT_TABLE() -}; - #endif - // __SLIDERH__ + // _SLIDER_H_ diff --git a/include/wx/msw/tabctrl.h b/include/wx/msw/tabctrl.h index 51237149a6..6b9dd252b6 100644 --- a/include/wx/msw/tabctrl.h +++ b/include/wx/msw/tabctrl.h @@ -51,6 +51,9 @@ class WXDLLEXPORT wxTabCtrl: public wxControl // Get the selection int GetSelection() const; + // Get the tab with the current keyboard focus + int GetCurFocus() const; + // Get the associated image list wxImageList* GetImageList() const; diff --git a/include/wx/toolbar.h b/include/wx/toolbar.h index 5e329fba0f..b4fe589c17 100644 --- a/include/wx/toolbar.h +++ b/include/wx/toolbar.h @@ -1,11 +1,18 @@ -#ifndef __TOOLBARH_BASE__ -#define __TOOLBARH_BASE__ +#ifndef _TOOLBAR_H_BASE_ +#define _TOOLBAR_H_BASE_ -#if defined(__WINDOWS__) -#include "wx/tbar95.h" +#if defined(__WINDOWS__) && defined(__WIN95__) +# include "wx/tbar95.h" +# define wxToolBar wxToolBar95 +# define classwxToolBar classwxToolBar95 +#elif defined(__WINDOWS__) +# include "wx/tbarmsw.h" +# define wxToolBar wxToolBarMSW +# define classwxToolBar classwxToolBarMSW #elif defined(__GTK__) -#include "wx/gtk/tbargtk.h" +# include "wx/gtk/tbargtk.h" +# define classwxToolBar wxToolBarGTK #endif #endif - // __TOOLBARH_BASE__ + // _TOOLBAR_H_BASE_ diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index ed54807594..df27ba6a65 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -20,10 +20,12 @@ #pragma hdrstop #endif -// #define __GOOD_COMPILER__ - #include "wx/defs.h" +#ifdef __WINDOWS__ +#define __GOOD_COMPILER__ +#endif + #ifndef WX_PRECOMP #include "wx/utils.h" #include "wx/dc.h" diff --git a/src/msw/gauge.cpp b/src/msw/gauge.cpp deleted file mode 100644 index 58281cb3fe..0000000000 --- a/src/msw/gauge.cpp +++ /dev/null @@ -1,1254 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: gauge.cpp -// Purpose: wxGauge class -// Author: Julian Smart -// Modified by: -// Created: 01/02/97 -// RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "gauge.h" -#endif - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#include "wx/defs.h" -#endif - -#if USE_GAUGE - -#include "wx/gauge.h" -#include "wx/msw/private.h" - -/* gas gauge graph control messages--class "zYzGauge" */ -#define ZYZG_SETRANGE (WM_USER + 0) -#define ZYZG_GETRANGE (WM_USER + 1) -#define ZYZG_SETPOSITION (WM_USER + 2) -#define ZYZG_GETPOSITION (WM_USER + 3) -#define ZYZG_SETORIENTATION (WM_USER + 4) -#define ZYZG_GETORIENTATION (WM_USER + 5) -#define ZYZG_SETFGCOLOR (WM_USER + 6) -#define ZYZG_GETFGCOLOR (WM_USER + 7) -#define ZYZG_SETBKCOLOR (WM_USER + 8) -#define ZYZG_GETBKCOLOR (WM_USER + 9) -#define ZYZG_SETWIDTH3D (WM_USER + 10) -#define ZYZG_GETWIDTH3D (WM_USER + 11) -#define ZYZG_SETBEZELFACE (WM_USER + 12) -#define ZYZG_GETBEZELFACE (WM_USER + 13) -#define ZYZG_SETDELTAPOS (WM_USER + 14) - - -/* orientations for ZYZG_WW_ORIENTATION */ -#define ZYZG_ORIENT_LEFTTORIGHT 0 -#define ZYZG_ORIENT_RIGHTTOLEFT 1 -#define ZYZG_ORIENT_BOTTOMTOTOP 2 -#define ZYZG_ORIENT_TOPTOBOTTOM 3 - - -/* gauge styles */ -#define ZYZGS_3D 0x8000L /* control will be 3D */ - -/* public function prototypes */ -BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance); - -#define USE_PROGRESS_BAR 1 - -#if defined(__WIN95__) && !defined(__GNUWIN32__) -#include -#endif - -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) -#endif - -bool wxGauge::Create(wxWindow *parent, const wxWindowID id, - const int range, - const wxPoint& pos, - const wxSize& size, - const long style, - const wxValidator& validator, - const wxString& name) -{ - static bool wxGaugeInitialised = FALSE; - - if ( !wxGaugeInitialised ) - { - if (!gaugeInit((HWND) wxGetInstance())) - wxFatalError("Cannot initalize Gauge library"); - wxGaugeInitialised = TRUE; - } - - SetName(name); - SetValidator(validator); - - if (parent) parent->AddChild(this); - m_rangeMax = range; - - SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; - SetForegroundColour(parent->GetDefaultForegroundColour()) ; - - m_useProgressBar = FALSE; - m_windowStyle = style; - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; - - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; - - // Use the Win95 progress bar if possible, but not if - // we request a vertical gauge. -#if defined(__WIN95__) && USE_PROGRESS_BAR - if ((m_windowStyle & wxGA_PROGRESSBAR) && ((m_windowStyle & wxGA_HORIZONTAL) == wxGA_HORIZONTAL)) - m_useProgressBar = TRUE; -#endif - - if (m_useProgressBar) - { -#if defined(__WIN95__) && USE_PROGRESS_BAR - long msFlags = WS_CHILD | WS_VISIBLE | WS_TABSTOP; - - HWND wx_button = - CreateWindowEx(MakeExtendedStyle(m_windowStyle), PROGRESS_CLASS, NULL, msFlags, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, - wxGetInstance(), NULL); - - m_hWnd = (WXHWND)wx_button; - - // Subclass again for purposes of dialog editing mode - SubclassWin((WXHWND) wx_button); - - SendMessage((HWND) GetHWND(), PBM_SETRANGE, 0, MAKELPARAM(0, range)); -#endif - } - else - { - long msFlags = WS_CHILD | WS_VISIBLE | WS_TABSTOP; -/* if (m_windowStyle & wxTHREED) */ - msFlags |= ZYZGS_3D; - - HWND wx_button = - CreateWindowEx(MakeExtendedStyle(m_windowStyle), "zYzGauge", NULL, msFlags, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, - wxGetInstance(), NULL); - - m_hWnd = (WXHWND)wx_button; - - // Subclass again for purposes of dialog editing mode - SubclassWin((WXHWND)wx_button); - - int wOrient = 0; - - if (m_windowStyle & wxGA_HORIZONTAL) - wOrient = ZYZG_ORIENT_LEFTTORIGHT; - else - wOrient = ZYZG_ORIENT_BOTTOMTOTOP; - - SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0); - SendMessage(wx_button, ZYZG_SETRANGE, range, 0); - - SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); - SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); - } - - SetFont(* parent->GetFont()); - - if (width == -1) - width = 50; - if (height == -1) - height = 50; - SetSize(x, y, width, height); - - ShowWindow((HWND) GetHWND(), SW_SHOW); - - return TRUE; -} - -void wxGauge::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) -{ - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } - - // Deal with default size (using -1 values) - if (w1<=0) - w1 = DEFAULT_ITEM_WIDTH; - - if (h1<=0) - h1 = DEFAULT_ITEM_HEIGHT; - - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); - -#if WXWIN_COMPATIBILITY - GetEventHandler()->OldOnSize(width, height); -#else - wxSizeEvent event(wxSize(width, height), m_windowId); - event.eventObject = this; - GetEventHandler()->ProcessEvent(event); -#endif -} - -void wxGauge::SetShadowWidth(const int w) -{ - if (m_useProgressBar) - { - } - else - SendMessage((HWND) GetHWND(), ZYZG_SETWIDTH3D, w, 0); -} - -void wxGauge::SetBezelFace(const int w) -{ - if (m_useProgressBar) - { - } - else - SendMessage((HWND) GetHWND(), ZYZG_SETBEZELFACE, w, 0); -} - -void wxGauge::SetRange(const int r) -{ - m_rangeMax = r; - -#if defined(__WIN95__) && USE_PROGRESS_BAR - if (m_useProgressBar) - SendMessage((HWND) GetHWND(), PBM_SETRANGE, 0, MAKELPARAM(0, r)); - else -#endif - SendMessage((HWND) GetHWND(), ZYZG_SETRANGE, r, 0); -} - -void wxGauge::SetValue(const int pos) -{ - m_gaugePos = pos; - -#if defined(__WIN95__) && USE_PROGRESS_BAR - if (m_useProgressBar) - SendMessage((HWND) GetHWND(), PBM_SETPOS, pos, 0); - else -#endif - SendMessage((HWND) GetHWND(), ZYZG_SETPOSITION, pos, 0); -} - -int wxGauge::GetShadowWidth(void) const -{ - if (m_useProgressBar) - return 0; - else - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETWIDTH3D, 0, 0); -} - -int wxGauge::GetBezelFace(void) const -{ - if (m_useProgressBar) - return 0; - else - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETBEZELFACE, 0, 0); -} - -int wxGauge::GetRange(void) const -{ - if (m_useProgressBar) - return m_rangeMax; - else - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETRANGE, 0, 0); -} - -int wxGauge::GetValue(void) const -{ - if (m_useProgressBar) - return m_gaugePos; - else - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETPOSITION, 0, 0); -} - -void wxGauge::SetForegroundColour(const wxColour& col) -{ - m_foregroundColour = col ; - if (m_useProgressBar) - { - } - else - SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); -} - -void wxGauge::SetBackgroundColour(const wxColour& col) -{ - m_backgroundColour = col ; - if (m_useProgressBar) - { - } - else - SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); -} - - -/** zyz3d.c - * - * DESCRIPTION: - * This module contains functions for creating nifty 3D borders - * around controls like zYzGauge. - * - * HISTORY: - * 3/14/91 cjp put in this comment - * 6/19/92 cjp touched it a bit - * - ** cjp */ -// COPYRIGHT: -// -// (C) Copyright Microsoft Corp. 1992. All rights reserved. -// -// You have a royalty-free right to use, modify, reproduce and -// distribute the Sample Files (and/or any modified version) in -// any way you find useful, provided that you agree that -// Microsoft has no warranty obligations or liability for any -// Sample Application Files which are modified. -// - - -/* get the includes we need */ -#include - -/* misc. control flag defines */ -#define DRAW3D_IN 0x0001 -#define DRAW3D_OUT 0x0002 - -#define DRAW3D_TOPLINE 0x0004 -#define DRAW3D_BOTTOMLINE 0x0008 -#define DRAW3D_LEFTLINE 0x0010 -#define DRAW3D_RIGHTLINE 0x0020 - - -/* public function prototypes */ -void FAR PASCAL Draw3DFaceFrame(HDC, LPRECT, WORD); -void FAR PASCAL Draw3DRect(HDC, LPRECT, WORD, WORD); -void FAR PASCAL Draw3DLine(HDC, WORD, WORD, WORD, WORD, WORD); - - -/** void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth) - * - * DESCRIPTION: - * This function draws a flat frame with the current button-face - * color. - * - * ARGUMENTS: - * HDC hdc : The DC to draw into. - * - * LPRECT rc : The containing rect for the new frame. - * - * WORD wWidth : The width of the frame to draw. - * - * RETURN (void FAR PASCAL): - * The frame will have been drawn into the DC. - * - * NOTES: - * - ** cjp */ - -void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth) -{ - RECT rc1; - DWORD rgbOld; - - /* don't go through a bunch of work if we don't have to */ - if (!wWidth) - return; - - /* set up color to be button-face color--so it may not be gray */ - rgbOld = SetBkColor(hdc, GetSysColor(COLOR_BTNFACE)); - - /* perform CopyRect w/o bloody windows style overhead */ - rc1 = *rc; - - /* top */ - rc1.top = rc->top; - rc1.left = rc->left; - rc1.bottom = rc->top + wWidth; - rc1.right = rc->right; - - /* blast it out */ - ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL); - - /* right */ - rc1.left = rc->right - wWidth; - rc1.bottom = rc->bottom; - - /* blast this part now */ - ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL); - - /* left */ - rc1.left = rc->left; - rc1.right = rc->left + wWidth; - - /* and another part */ - ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL); - - /* bottom */ - rc1.right = rc->right; - rc1.top = rc->bottom - wWidth; - - /* finish it off */ - ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL); - - /* restore the old bk color */ - SetBkColor(hdc, rgbOld); -} /* Draw3DFaceFrame() */ - - -/** void FAR PASCAL Draw3DRect(HDC, LPRECT, WORD, WORD) - * - * DESCRIPTION: - * Draws a 3D rectangle that is shaded. wFlags can be used to - * control how the rectangle looks. - * - * ARGUMENTS: - * HDC hdc : Handle to the device context that will be - * used to display the rectangle. - * - * RECT rect : A rectangle describing the dimensions of - * the rectangle in device coordinates. - * - * WORD wShadowWidth : Width of the shadow in device coordinates. - * - * WORD wFlags : The following flags may be passed to describe - * the style of the rectangle: - * - * DRAW3D_IN : The shadow is drawn such that - * the box appears to be sunk in to the screen. - * This is default if 0 is passed. - * - * DRAW3D_OUT : The shadow is drawn such that - * the box appears to be sticking out of the - * screen. - * - * RETURN (void FAR PASCAL): - * The 3D looking rectangle will have been drawn into the DC. - * - * NOTES: - * - ** cjp */ - -void FAR PASCAL Draw3DRect(HDC hdc, LPRECT lpRect, - WORD wShadowWidth, WORD wFlags) -{ - /* sanity check--don't work if you don't have to! */ - if (!wShadowWidth || !RectVisible(hdc, lpRect)) - return; - - /* draw the top line */ - Draw3DLine(hdc, lpRect->left, lpRect->top, - lpRect->right - lpRect->left, - wShadowWidth, DRAW3D_TOPLINE | wFlags); - - /* right line */ - Draw3DLine(hdc, lpRect->right, lpRect->top, - lpRect->bottom - lpRect->top, - wShadowWidth, DRAW3D_RIGHTLINE | wFlags); - - /* bottom line */ - Draw3DLine(hdc, lpRect->left, lpRect->bottom, - lpRect->right - lpRect->left, - wShadowWidth, DRAW3D_BOTTOMLINE | wFlags); - - /* left line */ - Draw3DLine(hdc, lpRect->left, lpRect->top, - lpRect->bottom - lpRect->top, - wShadowWidth, DRAW3D_LEFTLINE | wFlags); -} /* Draw3DRect() */ - - -/** void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, - * - * DESCRIPTION: - * Draws a 3D line that can be used to make a 3D box. - * - * ARGUMENTS: - * HDC hdc : Handle to the device context that will be - * used to display the 3D line. - * - * WORD x, y : Coordinates of the beginning of the line. - * These coordinates are in device units and - * represent the _outside_ most point. Horiz- - * ontal lines are drawn from left to right and - * vertical lines are drawn from top to bottom. - * - * WORD wShadowWidth : Width of the shadow in device coordinates. - * - * WORD wFlags : The following flags may be passed to - * describe the style of the 3D line: - * - * DRAW3D_IN : The shadow is drawn such that - * the box appears to be sunk in to the screen. - * This is default if 0 is passed. - * - * DRAW3D_OUT : The shadow is drawn such that - * the box appears to be sticking out of the - * screen. - * - * DRAW3D_TOPLINE, _BOTTOMLINE, _LEFTLINE, and - * _RIGHTLINE : Specifies that a "top", - * "Bottom", "Left", or"Right" line is to be - * drawn. - * - * RETURN (void FAR PASCAL): - * The line will have been drawn into the DC. - * - * NOTES: - * - ** cjp */ - -void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, - WORD wShadowWidth, WORD wFlags) -{ - HBRUSH hOldBrush; - HPEN hOldPen; - BOOL fDark; - POINT Point[ 4 ]; /* define a polgon with 4 points */ - - /* if width is zero, don't do nothin'! */ - if (!wShadowWidth) - return; - - /* define shape of polygon--origin is always the same */ - Point[0].x = x; - Point[0].y = y; - - /* To do this we'll simply draw a polygon with four sides, using - * the appropriate brush. I dare you to ask me why this isn't a - * switch/case! - */ - if (wFlags & DRAW3D_TOPLINE) - { - /* across to right */ - Point[1].x = x + nLen - (wShadowWidth == 1 ? 1 : 0); - Point[1].y = y; - - /* down/left */ - Point[2].x = x + nLen - wShadowWidth; - Point[2].y = y + wShadowWidth; - - /* accross to left */ - Point[3].x = x + wShadowWidth; - Point[3].y = y + wShadowWidth; - - /* select 'dark' brush if 'in'--'light' for 'out' */ - fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE; - } - - /* possibly the bottom? */ - else if (wFlags & DRAW3D_BOTTOMLINE) - { - /* across to right */ - Point[1].x = x + nLen; - Point[1].y = y; - - /* up/left */ - Point[2].x = x + nLen - wShadowWidth; - Point[2].y = y - wShadowWidth; - - /* accross to left */ - Point[3].x = x + wShadowWidth; - Point[3].y = y - wShadowWidth; - - /* select 'light' brush if 'in' */ - fDark = (wFlags & DRAW3D_IN) ? FALSE : TRUE; - } - - /* ok, it's gotta be left? */ - else if (wFlags & DRAW3D_LEFTLINE) - { - /* down */ - Point[1].x = x; - Point[1].y = y + nLen - (wShadowWidth == 1 ? 1 : 0); - - /* up/right */ - Point[2].x = x + wShadowWidth; - Point[2].y = y + nLen - wShadowWidth; - - /* down */ - Point[3].x = x + wShadowWidth; - Point[3].y = y + wShadowWidth; - - /* select 'dark' brush if 'in'--'light' for 'out' */ - fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE; - } - - /* well maybe it's for the right side? */ - else if (wFlags & DRAW3D_RIGHTLINE) - { - /* down */ - Point[1].x = x; - Point[1].y = y + nLen; - - /* up/left */ - Point[2].x = x - wShadowWidth; - Point[2].y = y + nLen - wShadowWidth; - - /* up */ - Point[3].x = x - wShadowWidth; - Point[3].y = y + wShadowWidth; - - /* select 'light' brush if 'in' */ - fDark = (wFlags & DRAW3D_IN) ? FALSE : TRUE; - } - - /* bad drugs? */ - else return; - - /* select NULL_PEN for no borders */ - hOldPen = SelectObject(hdc, GetStockObject(NULL_PEN)); - - /* select the appropriate color for the fill */ - if (fDark) - hOldBrush = SelectObject(hdc, GetStockObject(GRAY_BRUSH)); - else - hOldBrush = SelectObject(hdc, GetStockObject(WHITE_BRUSH)); - - /* finally, draw the dern thing */ - Polygon(hdc, (LPPOINT)&Point, 4); - - /* restore what we killed */ - SelectObject(hdc, hOldBrush); - SelectObject(hdc, hOldPen); -} /* Draw3DLine() */ - -/** EOF: zyz3d.c **/ - -/** zyzgauge.c - * - * DESCRIPTION: - * Yet another 'Gas Gauge Custom Control.' This control gives you - * a 'progress bar' class (named zYzGauge) for use in your applications. - * You can set the range, position, font, color, orientation, and 3d - * effect of the gauge by sending messages to the control. - * - * Before you can use this control, you MUST first export the window - * procedure for the control (or define it with the _export keyword): - * - * EXPORTS gaugeWndProc - * - * You then need initialize the class before you use it: - * - * if (!gaugeInit(hInstance)) - * die a horrible death - * else - * you are good to go - * - * The colors used by the control default to black and white if you - * are running on a mono-display. They default to blue and white - * if you are on a color display. You enable the 3D effect by setting - * the ZYZGS_3D style flag in the styles field of the control (like - * any other control). - * - * To select your own colors, you can send the ZYZG_SETFGCOLOR and - * ZYZG_SETBKCOLOR messages to set the foreground (percent done) and - * background (percent not done) colors. The lParam is the RGB() - * value--wParam is ignored. - * - * In all of the following ZYZG_??? messages, the arguments are - * WORDS. If you are setting parameters, the value is sent as - * the wParam (lParam is ignored). If you are getting parameters, - * the value is returned as a LONG and should be cast to a *signed* - * integer. - * - * To set the depth of the 3D effect (if enabled), you can send the - * ZYZG_SETBEZELFACE and ZYZG_SETWIDTH3D messages. The bezel face - * is the flat top on the 3D border--its color will be that of the - * button-face. The 3D width is the width of the bezel itself; inside - * and outside. The light color is white, the dark color is gray. - * Both widths *can* be zero--both default to 2 which looks to me. - * - * The range of the control can be set by sending the ZYZG_SETRANGE - * message to the control. It can be any integer from 1 to 32767. - * What this specifies is the number of pieces that create a whole. - * The default is 100. You can get the current range setting by - * sending the ZYZG_GETRANGE message to the control. - * - * The position (number of pieces out of the whole have been used) is - * set with the ZYZG_SETPOSITION message. It can be any integer from - * 0 to the current range setting of the control--it will be clipped - * if the position is out of bounds. The default position is 0. You - * can get the current position at any time with the ZYZG_GETPOSITION - * message. - * - * You can also set the range using a delta from the current range. - * This is done by sending the ZYZG_SETDELTAPOS message with wParam - * set to a _signed_ integer value within the range of the control. - * - * The font used for the percentage text can be set using the standard - * WM_SETFONT message. You can get the current font at any time with - * the WM_GETFONT message. - * - * The orientation can be left to right, right to left, bottom to top, - * or top to bottom. Whatever suits your needs. You set this by - * sending the ZYZG_ORIENTATION message to the control with one of - * the following values (default is ZYZG_ORIENT_LEFTTORIGHT): - * - * ZYZG_ORIENT_LEFTTORIGHT (0) - * ZYZG_ORIENT_RIGHTTOLEFT (1) - * ZYZG_ORIENT_BOTTOMTOTOP (2) - * ZYZG_ORIENT_TOPTOBOTTOM (3) - * - * HISTORY: - * 3/12/91 cjp put in this comment - * 6/19/92 cjp touched it a bit - * - ** cjp */ -// COPYRIGHT: -// -// (C) Copyright Microsoft Corp. 1992. All rights reserved. -// -// You have a royalty-free right to use, modify, reproduce and -// distribute the Sample Files (and/or any modified version) in -// any way you find useful, provided that you agree that -// Microsoft has no warranty obligations or liability for any -// Sample Application Files which are modified. -// - - -/* get the includes we need */ -#ifndef __GNUWIN32__ -#include -#endif -#include -#include -#include -// #include "zyz3d.h" -// #include "zyzgauge.h" - - -/* static global variables */ -static char gszzYzGaugeClass[] = "zYzGauge"; - - -/* window word position definitions */ -#define ZYZG_WW_PZYZGAUGE 0 -/* #define ZYZG_WW_EXTRABYTES 2 */ -#define ZYZG_WW_EXTRABYTES 4 - - -/* control block structure typedef */ -typedef struct tZYZGAUGE -{ - WORD wRange; - WORD wPosition; - WORD wOrientation; - WORD wWidth3D; - WORD wWidthBezelFace; - HFONT hFont; - DWORD rgbTextColor; - DWORD rgbBkColor; - -} ZYZGAUGE, *PZYZGAUGE, FAR *LPZYZGAUGE; - - -/* some default values for the control */ -#define ZYZG_DEF_RANGE 100 -#define ZYZG_DEF_POSITION 0 -#define ZYZG_DEF_ORIENTATION ZYZG_ORIENT_LEFTTORIGHT -#define ZYZG_DEF_WIDTH3D 2 -#define ZYZG_DEF_BEZELFACE 2 - - - -/* the default settings for drawing colors--display dependent */ -static DWORD rgbDefTextColor; -static DWORD rgbDefBkColor; -static BOOL fSupport3D; - -#if !defined(APIENTRY) // NT defines APIENTRY, 3.x not -#define APIENTRY FAR PASCAL -#endif - -#ifdef __WIN32__ -#define _EXPORT /**/ -#else -#define _EXPORT _export -typedef signed short int SHORT ; -#endif - -/* internal function prototypes */ -static void PASCAL gaugePaint(HWND, HDC); -/* LRESULT FAR PASCAL */ -LRESULT APIENTRY _EXPORT gaugeWndProc(HWND, UINT, WPARAM, LPARAM); - - - -/** BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) - * - * DESCRIPTION: - * Registers the window class for the zYzGauge control. Performs - * other initialization for the zYzGauge text control. This must - * be done before the zYzGauge control is used--or it will fail - * and your dialog box will not open! - * - * ARGUMENTS: - * HINSTANCE hInstance : Instance handle to register class with. - * - * RETURN (BOOL FAR): - * The return value is TRUE if the zYzGauge class was successfully - * registered. It is FALSE if the initialization fails. - * - * NOTES: - * - ** cjp */ - -//#pragma alloc_text(init, gaugeInit) - -BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) -{ - static BOOL fRegistered = FALSE; - WNDCLASS wc; - HDC hdc; - - /* assume already registered if not first instance */ - if (fRegistered) - return (TRUE); - - /* fill in the class structure for the zyzgauge control */ - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hIcon = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = gszzYzGaugeClass; - wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); - wc.hInstance = hInstance; - -#ifdef ZYZGAUGE_DLL - wc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW; -#else - wc.style = CS_HREDRAW | CS_VREDRAW; -#endif - - wc.lpfnWndProc = gaugeWndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = ZYZG_WW_EXTRABYTES; - - /* attempt to register it--return FALSE if fail */ - if (!RegisterClass(&wc)) - return (FALSE); - - /* Get a DC to determine whether device is mono or not, and set - * default foreground/background colors as appropriate. - */ - if ((hdc = CreateIC("DISPLAY", NULL, NULL, 0L))) - { - /* check for mono-display */ - if ((GetDeviceCaps(hdc, BITSPIXEL) == 1) && - (GetDeviceCaps(hdc, PLANES) == 1)) - { - /* using a mono DC--white foreground, black background */ - rgbDefTextColor = RGB(255, 255, 255); - rgbDefBkColor = RGB(0, 0, 0); - } - - /* good! we have color: blue foreground, white background */ - else - { - rgbDefTextColor = RGB(0, 0, 255); - rgbDefBkColor = RGB(255, 255, 255); - } - - /* need at _least_ 8 for two shades of gray (>=VGA) */ - fSupport3D = (GetDeviceCaps(hdc, NUMCOLORS) >= 8) ? TRUE : FALSE; - - /* get rid of the DC (IC) */ - DeleteDC(hdc); - } - - /* uh-oh... can't get DC (IC)... fail */ - else - { - /* unregister the class */ - UnregisterClass(gszzYzGaugeClass, hInstance); - return (FALSE); - } - - /* return success */ - return (fRegistered = TRUE); -} /* gaugeInit() */ - - -/** static void PASCAL gaugePaint(HWND hwnd, HDC hdc) - * - * DESCRIPTION: - * This function is responsible for painting the zYzGauge control. - * - * ARGUMENTS: - * HWND hwnd : The window handle for the gauge. - * - * HDC hdc : The DC for the gauge's window. - * - * RETURN (void): - * The control will have been painted. - * - * NOTES: - * - ** cjp */ - -static void PASCAL gaugePaint(HWND hwnd, HDC hdc) -{ - PZYZGAUGE pgauge; - WORD iRange, iPos; - WORD Offset = 1; - DWORD dwExtent; - RECT rc1, rc2; - HFONT hFont; - char ach[ 6 ]; - WORD dx, dy, wGomerX, wGomerY; -/* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead, - * which needs a SIZE* parameter */ -#if defined(__WIN32__) - SIZE size; -#endif - - /* get pointer to the control's control block */ -// pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE); - pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE); - - /* set the colors into for the gauge into the control */ - SetTextColor(hdc, pgauge->rgbTextColor); - SetBkColor(hdc, pgauge->rgbBkColor); - - /* draw black rectangle for gauge */ - GetClientRect(hwnd, &rc1); - - /* draw a black border on the _outside_ */ - FrameRect(hdc, &rc1, GetStockObject(BLACK_BRUSH)); - - /* we want to draw _just inside_ the black border */ - InflateRect(&rc1, -1, -1); - - /* one line thick so far... */ -// Offset = (WORD) 1; - - /* for 3D stuff, we need to have at least two shades of gray */ - if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D) - { - Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_OUT); - InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D)); - - Draw3DFaceFrame(hdc, &rc1, pgauge->wWidthBezelFace); - InflateRect(&rc1, ~(pgauge->wWidthBezelFace), ~(pgauge->wWidthBezelFace)); - - Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_IN); - InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D)); - - /* draw a black border on the _inside_ */ - FrameRect(hdc, &rc1, GetStockObject(BLACK_BRUSH)); - - /* we want to draw _just inside_ the black border */ - InflateRect(&rc1, -1, -1); - - /* add all the other pixels into the border width */ - Offset += (2 * pgauge->wWidth3D) + pgauge->wWidthBezelFace + 1; - } - - /* dup--one rc for 'how much filled', one rc for 'how much empty' */ - rc2 = rc1; - - /* get the range--make sure it's a valid range */ - if ((iRange = pgauge->wRange) <= 0) - iRange = 1; - - /* get the position--greater than 100% would be bad */ - if ((iPos = pgauge->wPosition) > iRange) - iPos = iRange; - - /* compute the actual size of the gauge */ - dx = rc1.right - rc1.left; - dy = rc1.bottom - rc1.top; - wGomerX = (WORD)((DWORD)iPos * dx / iRange); - wGomerY = (WORD)((DWORD)iPos * dy / iRange); - - /* get the orientation and munge rects accordingly */ - switch (pgauge->wOrientation) - { - case ZYZG_ORIENT_RIGHTTOLEFT: - rc1.left = rc2.right = rc1.right - wGomerX; - break; - - case ZYZG_ORIENT_BOTTOMTOTOP: - rc1.top = rc2.bottom = rc1.bottom - wGomerY; - break; - - case ZYZG_ORIENT_TOPTOBOTTOM: - rc1.bottom = rc2.top += wGomerY; - break; - - default: - rc1.right = rc2.left += wGomerX; - break; - } /* switch () */ - - /* select the correct font */ - hFont = SelectObject(hdc, pgauge->hFont); - - /* build up a string to blit out--ie the meaning of life: "42%" */ - wsprintf(ach, "%3d%%", (WORD)((DWORD)iPos * 100 / iRange)); -/* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */ -#if defined(__WIN32__) - GetTextExtentPoint(hdc, ach, wGomerX = lstrlen(ach), &size); - dwExtent = size.cx; -#else - dwExtent = GetTextExtent(hdc, ach, wGomerX = lstrlen(ach)); -#endif - - - /* Draw the finished (ie the percent done) side of box. If - * ZYZG_WW_POSITION is 42, (in range of 0 to 100) this ExtTextOut - * draws the meaning of life (42%) bar. - */ - ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset, - (dy - HIWORD(dwExtent)) / 2 + Offset, - ETO_OPAQUE | ETO_CLIPPED, &rc2, ach, wGomerX, NULL); - - /* Reverse fore and back colors for drawing the undone (ie the non- - * finished) side of the box. - */ - SetBkColor(hdc, pgauge->rgbTextColor); - SetTextColor(hdc, pgauge->rgbBkColor); - - ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset, - (dy - HIWORD(dwExtent)) / 2 + Offset, - ETO_OPAQUE | ETO_CLIPPED, &rc1, ach, wGomerX, NULL); - - /* unselect the font */ - SelectObject(hdc, hFont); -} /* gaugePaint() */ - - -/** LRESULT FAR PASCAL gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) - * - * DESCRIPTION: - * This is the control's window procedure. Its purpose is to handle - * special messages for this custom control. - * - * The special control messages for the gauge control are: - * - * ZYZG_SETRANGE : Sets the range of the gauge. In other - * words, the number of parts that make a - * whole. - * - * ZYZG_GETRANGE : Returns the current range of the gauge. - * - * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This - * can be one of the ZYZG_ORIENT_?? msgs. - * - * ZYZG_GETORIENTATION : Gets the current orientation of the - * gauge. - * - * ZYZG_SETPOSITION : Sets the current position of the gauge. - * In other words, how many pieces of the - * whole have been used. - * - * ZYZG_GETPOSITION : Gets the current position of the gauge. - * - * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the - * specified amount. - * - * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color. - * - * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color. - * - * ZYZG_SETBKCOLOR : Sets the background (percent not done) - * color. - * - * ZYZG_GETBKCOLOR : Gets the background (percent not done) - * color. - * - * WM_SETFONT : Sets the font to use for the percentage - * text of the gauge. - * - * WM_GETFONT : Gets the current font in use by the - * gauge. - * - * NOTES: - * - ** cjp */ - -/* LRESULT FAR PASCAL */ - -LRESULT APIENTRY _EXPORT gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - HFONT hFont; - PAINTSTRUCT ps; - PZYZGAUGE pgauge; - RECT rc; - -// pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE); - pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE); - - /* break to get DefWindowProc() */ - switch (uMsg) - { - case WM_CREATE: - /* need to allocate a control block */ -// pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE)); - pgauge = (PZYZGAUGE)malloc(sizeof(ZYZGAUGE)); - if (!pgauge) - return (0L); - - /* hang on to this control block */ -// SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge); - SetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE, (LONG)pgauge); - - /* fill control block with defaults */ - pgauge->wRange = ZYZG_DEF_RANGE; - pgauge->wPosition = ZYZG_DEF_POSITION; - pgauge->wOrientation = ZYZG_DEF_ORIENTATION; - pgauge->wWidth3D = ZYZG_DEF_WIDTH3D; - pgauge->wWidthBezelFace = ZYZG_DEF_BEZELFACE; - pgauge->rgbTextColor = rgbDefTextColor; - pgauge->rgbBkColor = rgbDefBkColor; - - /* use system font */ - SendMessage(hwnd, WM_SETFONT, (WPARAM)NULL, 0L); - - /* go to DefWindowProc() to finish the job */ - break; - - case WM_DESTROY: - /* get rid of the control's memory */ - if (pgauge) -// LocalFree((HANDLE)pgauge); - free(pgauge); - break; - - case ZYZG_GETPOSITION: - return (pgauge->wPosition); - - case ZYZG_GETRANGE: - return (pgauge->wRange); - - case ZYZG_GETORIENTATION: - return (pgauge->wOrientation); - - case ZYZG_GETWIDTH3D: - return (pgauge->wWidth3D); - - case ZYZG_GETBEZELFACE: - return (pgauge->wWidthBezelFace); - - case ZYZG_GETBKCOLOR: - return (pgauge->rgbTextColor); - - case ZYZG_GETFGCOLOR: - return (pgauge->rgbBkColor); - - case ZYZG_SETBKCOLOR: - pgauge->rgbBkColor = lParam; - return (0L); - - case ZYZG_SETFGCOLOR: - pgauge->rgbTextColor = lParam; - return (0L); - - - case ZYZG_SETPOSITION: - pgauge->wPosition = wParam; - -zyzgForceRepaint: - GetClientRect(hwnd, &rc); - if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D) - { - wParam = (2 * pgauge->wWidth3D) + - pgauge->wWidthBezelFace + 2; - } - - else - wParam = 1; - - InflateRect(&rc, ~(wParam), ~(wParam)); - InvalidateRect(hwnd, &rc, FALSE); - UpdateWindow(hwnd); - return (0L); - - case ZYZG_SETRANGE: - pgauge->wRange = wParam; - goto zyzgForceRepaint; - - case ZYZG_SETORIENTATION: - pgauge->wOrientation = wParam; - goto zyzgForceRepaint; - - case ZYZG_SETWIDTH3D: - pgauge->wWidth3D = wParam; - -zyzgForceRepaint3D: - InvalidateRect(hwnd, NULL, FALSE); - UpdateWindow(hwnd); - return (0L); - - case ZYZG_SETBEZELFACE: - pgauge->wWidthBezelFace = wParam; - goto zyzgForceRepaint3D; - - case ZYZG_SETDELTAPOS: -/* Watcom doesn't like the following line so removing typecasts */ -/* (int)pgauge->wPosition += (int)wParam; */ - pgauge->wPosition += wParam; - goto zyzgForceRepaint; - - case WM_PAINT: - BeginPaint(hwnd, &ps); - gaugePaint(hwnd, ps.hdc); - EndPaint(hwnd, &ps); - return (0L); - - case WM_GETFONT: - hFont = pgauge->hFont; - - /* if system font, then return NULL handle */ - return (long)((hFont == GetStockObject(SYSTEM_FONT)) ? NULL : hFont); - - case WM_SETFONT: - /* if NULL hFont, use system font */ - if (!(hFont = (HFONT)wParam)) - hFont = GetStockObject(SYSTEM_FONT); - - pgauge->hFont = hFont; - - /* redraw if indicated in message */ - if ((BOOL)lParam) - { - InvalidateRect(hwnd, NULL, TRUE); - UpdateWindow(hwnd); - } - return (0L); - } /* switch () */ - - /* let the dialog mangler take care of this message */ - return (DefWindowProc(hwnd, uMsg, wParam, lParam)); -} /* gaugeWndProc() */ - - -/** EOF: zyzgauge.c **/ - -#endif // USE_GAUGE diff --git a/src/msw/gauge95.cpp b/src/msw/gauge95.cpp new file mode 100644 index 0000000000..6a2f7c668f --- /dev/null +++ b/src/msw/gauge95.cpp @@ -0,0 +1,186 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: gauge95.cpp +// Purpose: wxGauge95 class +// Author: Julian Smart +// Modified by: +// Created: 01/02/97 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart and Markus Holzem +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "gauge95.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/defs.h" +#endif + +#if USE_GAUGE && defined(__WIN95__) + +#include "wx/msw/gauge95.h" +#include "wx/msw/private.h" + +#if defined(__WIN95__) && !defined(__GNUWIN32__) +#include +#endif + +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxGauge95, wxControl) +#endif + +bool wxGauge95::Create(wxWindow *parent, const wxWindowID id, + const int range, + const wxPoint& pos, + const wxSize& size, + const long style, + const wxValidator& validator, + const wxString& name) +{ + SetName(name); + SetValidator(validator); + + if (parent) parent->AddChild(this); + m_rangeMax = range; + + SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; + SetForegroundColour(parent->GetDefaultForegroundColour()) ; + + m_windowStyle = style; + + if ( id == -1 ) + m_windowId = (int)NewControlId(); + else + m_windowId = id; + + int x = pos.x; + int y = pos.y; + int width = size.x; + int height = size.y; + + long msFlags = WS_CHILD | WS_VISIBLE | WS_TABSTOP; + + HWND wx_button = + CreateWindowEx(MakeExtendedStyle(m_windowStyle), PROGRESS_CLASS, NULL, msFlags, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, + wxGetInstance(), NULL); + + m_hWnd = (WXHWND)wx_button; + + // Subclass again for purposes of dialog editing mode + SubclassWin((WXHWND) wx_button); + + SendMessage((HWND) GetHWND(), PBM_SETRANGE, 0, MAKELPARAM(0, range)); + + SetFont(* parent->GetFont()); + + if (width == -1) + width = 50; + if (height == -1) + height = 50; + SetSize(x, y, width, height); + + ShowWindow((HWND) GetHWND(), SW_SHOW); + + return TRUE; +} + +void wxGauge95::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) +{ + int currentX, currentY; + GetPosition(¤tX, ¤tY); + int x1 = x; + int y1 = y; + int w1 = width; + int h1 = height; + + if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + x1 = currentX; + if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + y1 = currentY; + + // If we're prepared to use the existing size, then... + if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) + { + GetSize(&w1, &h1); + } + + // Deal with default size (using -1 values) + if (w1<=0) + w1 = DEFAULT_ITEM_WIDTH; + + if (h1<=0) + h1 = DEFAULT_ITEM_HEIGHT; + + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + +#if WXWIN_COMPATIBILITY + GetEventHandler()->OldOnSize(width, height); +#else + wxSizeEvent event(wxSize(width, height), m_windowId); + event.eventObject = this; + GetEventHandler()->ProcessEvent(event); +#endif +} + +void wxGauge95::SetShadowWidth(const int w) +{ +} + +void wxGauge95::SetBezelFace(const int w) +{ +} + +void wxGauge95::SetRange(const int r) +{ + m_rangeMax = r; + + SendMessage((HWND) GetHWND(), PBM_SETRANGE, 0, MAKELPARAM(0, r)); +} + +void wxGauge95::SetValue(const int pos) +{ + m_gaugePos = pos; + + SendMessage((HWND) GetHWND(), PBM_SETPOS, pos, 0); +} + +int wxGauge95::GetShadowWidth(void) const +{ + return 0; +} + +int wxGauge95::GetBezelFace(void) const +{ + return 0; +} + +int wxGauge95::GetRange(void) const +{ + return m_rangeMax; +} + +int wxGauge95::GetValue(void) const +{ + return m_gaugePos; +} + +void wxGauge95::SetForegroundColour(const wxColour& col) +{ + m_foregroundColour = col ; +} + +void wxGauge95::SetBackgroundColour(const wxColour& col) +{ + m_backgroundColour = col ; +} + +#endif // USE_GAUGE diff --git a/src/msw/gaugemsw.cpp b/src/msw/gaugemsw.cpp new file mode 100644 index 0000000000..2edc0586e2 --- /dev/null +++ b/src/msw/gaugemsw.cpp @@ -0,0 +1,1179 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: gaugemsw.cpp +// Purpose: wxGaugeMSW class +// Author: Julian Smart +// Modified by: +// Created: 01/02/97 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart and Markus Holzem +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "gauge.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/defs.h" +#endif + +#if USE_GAUGE + +#include "wx/msw/gaugemsw.h" +#include "wx/msw/private.h" + +/* gas gauge graph control messages--class "zYzGauge" */ +#define ZYZG_SETRANGE (WM_USER + 0) +#define ZYZG_GETRANGE (WM_USER + 1) +#define ZYZG_SETPOSITION (WM_USER + 2) +#define ZYZG_GETPOSITION (WM_USER + 3) +#define ZYZG_SETORIENTATION (WM_USER + 4) +#define ZYZG_GETORIENTATION (WM_USER + 5) +#define ZYZG_SETFGCOLOR (WM_USER + 6) +#define ZYZG_GETFGCOLOR (WM_USER + 7) +#define ZYZG_SETBKCOLOR (WM_USER + 8) +#define ZYZG_GETBKCOLOR (WM_USER + 9) +#define ZYZG_SETWIDTH3D (WM_USER + 10) +#define ZYZG_GETWIDTH3D (WM_USER + 11) +#define ZYZG_SETBEZELFACE (WM_USER + 12) +#define ZYZG_GETBEZELFACE (WM_USER + 13) +#define ZYZG_SETDELTAPOS (WM_USER + 14) + + +/* orientations for ZYZG_WW_ORIENTATION */ +#define ZYZG_ORIENT_LEFTTORIGHT 0 +#define ZYZG_ORIENT_RIGHTTOLEFT 1 +#define ZYZG_ORIENT_BOTTOMTOTOP 2 +#define ZYZG_ORIENT_TOPTOBOTTOM 3 + +/* gauge styles */ +#define ZYZGS_3D 0x8000L /* control will be 3D */ + +/* public function prototypes */ +BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance); + +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxGaugeMSW, wxControl) +#endif + +bool wxGaugeMSW::Create(wxWindow *parent, const wxWindowID id, + const int range, + const wxPoint& pos, + const wxSize& size, + const long style, + const wxValidator& validator, + const wxString& name) +{ + static bool wxGaugeMSWInitialised = FALSE; + + if ( !wxGaugeMSWInitialised ) + { + if (!gaugeInit((HWND) wxGetInstance())) + wxFatalError("Cannot initalize Gauge library"); + wxGaugeMSWInitialised = TRUE; + } + + SetName(name); + SetValidator(validator); + + if (parent) parent->AddChild(this); + m_rangeMax = range; + + SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; + SetForegroundColour(parent->GetDefaultForegroundColour()) ; + + m_windowStyle = style; + + if ( id == -1 ) + m_windowId = (int)NewControlId(); + else + m_windowId = id; + + int x = pos.x; + int y = pos.y; + int width = size.x; + int height = size.y; + + long msFlags = WS_CHILD | WS_VISIBLE | WS_TABSTOP; + msFlags |= ZYZGS_3D; + + HWND wx_button = + CreateWindowEx(MakeExtendedStyle(m_windowStyle), "zYzGauge", NULL, msFlags, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, + wxGetInstance(), NULL); + + m_hWnd = (WXHWND)wx_button; + + // Subclass again for purposes of dialog editing mode + SubclassWin((WXHWND)wx_button); + + int wOrient = 0; + + if (m_windowStyle & wxGA_HORIZONTAL) + wOrient = ZYZG_ORIENT_LEFTTORIGHT; + else + wOrient = ZYZG_ORIENT_BOTTOMTOTOP; + + SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0); + SendMessage(wx_button, ZYZG_SETRANGE, range, 0); + + SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); + SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); + + SetFont(* parent->GetFont()); + + if (width == -1) + width = 50; + if (height == -1) + height = 50; + SetSize(x, y, width, height); + + ShowWindow((HWND) GetHWND(), SW_SHOW); + + return TRUE; +} + +void wxGaugeMSW::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) +{ + int currentX, currentY; + GetPosition(¤tX, ¤tY); + int x1 = x; + int y1 = y; + int w1 = width; + int h1 = height; + + if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + x1 = currentX; + if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + y1 = currentY; + + // If we're prepared to use the existing size, then... + if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) + { + GetSize(&w1, &h1); + } + + // Deal with default size (using -1 values) + if (w1<=0) + w1 = DEFAULT_ITEM_WIDTH; + + if (h1<=0) + h1 = DEFAULT_ITEM_HEIGHT; + + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + +#if WXWIN_COMPATIBILITY + GetEventHandler()->OldOnSize(width, height); +#else + wxSizeEvent event(wxSize(width, height), m_windowId); + event.eventObject = this; + GetEventHandler()->ProcessEvent(event); +#endif +} + +void wxGaugeMSW::SetShadowWidth(const int w) +{ + SendMessage((HWND) GetHWND(), ZYZG_SETWIDTH3D, w, 0); +} + +void wxGaugeMSW::SetBezelFace(const int w) +{ + SendMessage((HWND) GetHWND(), ZYZG_SETBEZELFACE, w, 0); +} + +void wxGaugeMSW::SetRange(const int r) +{ + m_rangeMax = r; + + SendMessage((HWND) GetHWND(), ZYZG_SETRANGE, r, 0); +} + +void wxGaugeMSW::SetValue(const int pos) +{ + m_gaugePos = pos; + + SendMessage((HWND) GetHWND(), ZYZG_SETPOSITION, pos, 0); +} + +int wxGaugeMSW::GetShadowWidth(void) const +{ + return (int) SendMessage((HWND) GetHWND(), ZYZG_GETWIDTH3D, 0, 0); +} + +int wxGaugeMSW::GetBezelFace(void) const +{ + return (int) SendMessage((HWND) GetHWND(), ZYZG_GETBEZELFACE, 0, 0); +} + +int wxGaugeMSW::GetRange(void) const +{ + return (int) SendMessage((HWND) GetHWND(), ZYZG_GETRANGE, 0, 0); +} + +int wxGaugeMSW::GetValue(void) const +{ + return (int) SendMessage((HWND) GetHWND(), ZYZG_GETPOSITION, 0, 0); +} + +void wxGaugeMSW::SetForegroundColour(const wxColour& col) +{ + m_foregroundColour = col ; + SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); +} + +void wxGaugeMSW::SetBackgroundColour(const wxColour& col) +{ + m_backgroundColour = col ; + SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); +} + + +/** zyz3d.c + * + * DESCRIPTION: + * This module contains functions for creating nifty 3D borders + * around controls like zYzGauge. + * + * HISTORY: + * 3/14/91 cjp put in this comment + * 6/19/92 cjp touched it a bit + * + ** cjp */ +// COPYRIGHT: +// +// (C) Copyright Microsoft Corp. 1992. All rights reserved. +// +// You have a royalty-free right to use, modify, reproduce and +// distribute the Sample Files (and/or any modified version) in +// any way you find useful, provided that you agree that +// Microsoft has no warranty obligations or liability for any +// Sample Application Files which are modified. +// + + +/* get the includes we need */ +#include + +/* misc. control flag defines */ +#define DRAW3D_IN 0x0001 +#define DRAW3D_OUT 0x0002 + +#define DRAW3D_TOPLINE 0x0004 +#define DRAW3D_BOTTOMLINE 0x0008 +#define DRAW3D_LEFTLINE 0x0010 +#define DRAW3D_RIGHTLINE 0x0020 + + +/* public function prototypes */ +void FAR PASCAL Draw3DFaceFrame(HDC, LPRECT, WORD); +void FAR PASCAL Draw3DRect(HDC, LPRECT, WORD, WORD); +void FAR PASCAL Draw3DLine(HDC, WORD, WORD, WORD, WORD, WORD); + + +/** void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth) + * + * DESCRIPTION: + * This function draws a flat frame with the current button-face + * color. + * + * ARGUMENTS: + * HDC hdc : The DC to draw into. + * + * LPRECT rc : The containing rect for the new frame. + * + * WORD wWidth : The width of the frame to draw. + * + * RETURN (void FAR PASCAL): + * The frame will have been drawn into the DC. + * + * NOTES: + * + ** cjp */ + +void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth) +{ + RECT rc1; + DWORD rgbOld; + + /* don't go through a bunch of work if we don't have to */ + if (!wWidth) + return; + + /* set up color to be button-face color--so it may not be gray */ + rgbOld = SetBkColor(hdc, GetSysColor(COLOR_BTNFACE)); + + /* perform CopyRect w/o bloody windows style overhead */ + rc1 = *rc; + + /* top */ + rc1.top = rc->top; + rc1.left = rc->left; + rc1.bottom = rc->top + wWidth; + rc1.right = rc->right; + + /* blast it out */ + ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL); + + /* right */ + rc1.left = rc->right - wWidth; + rc1.bottom = rc->bottom; + + /* blast this part now */ + ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL); + + /* left */ + rc1.left = rc->left; + rc1.right = rc->left + wWidth; + + /* and another part */ + ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL); + + /* bottom */ + rc1.right = rc->right; + rc1.top = rc->bottom - wWidth; + + /* finish it off */ + ExtTextOut(hdc, rc1.left, rc1.top, ETO_OPAQUE, &rc1, NULL, 0, NULL); + + /* restore the old bk color */ + SetBkColor(hdc, rgbOld); +} /* Draw3DFaceFrame() */ + + +/** void FAR PASCAL Draw3DRect(HDC, LPRECT, WORD, WORD) + * + * DESCRIPTION: + * Draws a 3D rectangle that is shaded. wFlags can be used to + * control how the rectangle looks. + * + * ARGUMENTS: + * HDC hdc : Handle to the device context that will be + * used to display the rectangle. + * + * RECT rect : A rectangle describing the dimensions of + * the rectangle in device coordinates. + * + * WORD wShadowWidth : Width of the shadow in device coordinates. + * + * WORD wFlags : The following flags may be passed to describe + * the style of the rectangle: + * + * DRAW3D_IN : The shadow is drawn such that + * the box appears to be sunk in to the screen. + * This is default if 0 is passed. + * + * DRAW3D_OUT : The shadow is drawn such that + * the box appears to be sticking out of the + * screen. + * + * RETURN (void FAR PASCAL): + * The 3D looking rectangle will have been drawn into the DC. + * + * NOTES: + * + ** cjp */ + +void FAR PASCAL Draw3DRect(HDC hdc, LPRECT lpRect, + WORD wShadowWidth, WORD wFlags) +{ + /* sanity check--don't work if you don't have to! */ + if (!wShadowWidth || !RectVisible(hdc, lpRect)) + return; + + /* draw the top line */ + Draw3DLine(hdc, lpRect->left, lpRect->top, + lpRect->right - lpRect->left, + wShadowWidth, DRAW3D_TOPLINE | wFlags); + + /* right line */ + Draw3DLine(hdc, lpRect->right, lpRect->top, + lpRect->bottom - lpRect->top, + wShadowWidth, DRAW3D_RIGHTLINE | wFlags); + + /* bottom line */ + Draw3DLine(hdc, lpRect->left, lpRect->bottom, + lpRect->right - lpRect->left, + wShadowWidth, DRAW3D_BOTTOMLINE | wFlags); + + /* left line */ + Draw3DLine(hdc, lpRect->left, lpRect->top, + lpRect->bottom - lpRect->top, + wShadowWidth, DRAW3D_LEFTLINE | wFlags); +} /* Draw3DRect() */ + + +/** void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, + * + * DESCRIPTION: + * Draws a 3D line that can be used to make a 3D box. + * + * ARGUMENTS: + * HDC hdc : Handle to the device context that will be + * used to display the 3D line. + * + * WORD x, y : Coordinates of the beginning of the line. + * These coordinates are in device units and + * represent the _outside_ most point. Horiz- + * ontal lines are drawn from left to right and + * vertical lines are drawn from top to bottom. + * + * WORD wShadowWidth : Width of the shadow in device coordinates. + * + * WORD wFlags : The following flags may be passed to + * describe the style of the 3D line: + * + * DRAW3D_IN : The shadow is drawn such that + * the box appears to be sunk in to the screen. + * This is default if 0 is passed. + * + * DRAW3D_OUT : The shadow is drawn such that + * the box appears to be sticking out of the + * screen. + * + * DRAW3D_TOPLINE, _BOTTOMLINE, _LEFTLINE, and + * _RIGHTLINE : Specifies that a "top", + * "Bottom", "Left", or"Right" line is to be + * drawn. + * + * RETURN (void FAR PASCAL): + * The line will have been drawn into the DC. + * + * NOTES: + * + ** cjp */ + +void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, + WORD wShadowWidth, WORD wFlags) +{ + HBRUSH hOldBrush; + HPEN hOldPen; + BOOL fDark; + POINT Point[ 4 ]; /* define a polgon with 4 points */ + + /* if width is zero, don't do nothin'! */ + if (!wShadowWidth) + return; + + /* define shape of polygon--origin is always the same */ + Point[0].x = x; + Point[0].y = y; + + /* To do this we'll simply draw a polygon with four sides, using + * the appropriate brush. I dare you to ask me why this isn't a + * switch/case! + */ + if (wFlags & DRAW3D_TOPLINE) + { + /* across to right */ + Point[1].x = x + nLen - (wShadowWidth == 1 ? 1 : 0); + Point[1].y = y; + + /* down/left */ + Point[2].x = x + nLen - wShadowWidth; + Point[2].y = y + wShadowWidth; + + /* accross to left */ + Point[3].x = x + wShadowWidth; + Point[3].y = y + wShadowWidth; + + /* select 'dark' brush if 'in'--'light' for 'out' */ + fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE; + } + + /* possibly the bottom? */ + else if (wFlags & DRAW3D_BOTTOMLINE) + { + /* across to right */ + Point[1].x = x + nLen; + Point[1].y = y; + + /* up/left */ + Point[2].x = x + nLen - wShadowWidth; + Point[2].y = y - wShadowWidth; + + /* accross to left */ + Point[3].x = x + wShadowWidth; + Point[3].y = y - wShadowWidth; + + /* select 'light' brush if 'in' */ + fDark = (wFlags & DRAW3D_IN) ? FALSE : TRUE; + } + + /* ok, it's gotta be left? */ + else if (wFlags & DRAW3D_LEFTLINE) + { + /* down */ + Point[1].x = x; + Point[1].y = y + nLen - (wShadowWidth == 1 ? 1 : 0); + + /* up/right */ + Point[2].x = x + wShadowWidth; + Point[2].y = y + nLen - wShadowWidth; + + /* down */ + Point[3].x = x + wShadowWidth; + Point[3].y = y + wShadowWidth; + + /* select 'dark' brush if 'in'--'light' for 'out' */ + fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE; + } + + /* well maybe it's for the right side? */ + else if (wFlags & DRAW3D_RIGHTLINE) + { + /* down */ + Point[1].x = x; + Point[1].y = y + nLen; + + /* up/left */ + Point[2].x = x - wShadowWidth; + Point[2].y = y + nLen - wShadowWidth; + + /* up */ + Point[3].x = x - wShadowWidth; + Point[3].y = y + wShadowWidth; + + /* select 'light' brush if 'in' */ + fDark = (wFlags & DRAW3D_IN) ? FALSE : TRUE; + } + + /* bad drugs? */ + else return; + + /* select NULL_PEN for no borders */ + hOldPen = SelectObject(hdc, GetStockObject(NULL_PEN)); + + /* select the appropriate color for the fill */ + if (fDark) + hOldBrush = SelectObject(hdc, GetStockObject(GRAY_BRUSH)); + else + hOldBrush = SelectObject(hdc, GetStockObject(WHITE_BRUSH)); + + /* finally, draw the dern thing */ + Polygon(hdc, (LPPOINT)&Point, 4); + + /* restore what we killed */ + SelectObject(hdc, hOldBrush); + SelectObject(hdc, hOldPen); +} /* Draw3DLine() */ + +/** EOF: zyz3d.c **/ + +/** zyzgauge.c + * + * DESCRIPTION: + * Yet another 'Gas Gauge Custom Control.' This control gives you + * a 'progress bar' class (named zYzGauge) for use in your applications. + * You can set the range, position, font, color, orientation, and 3d + * effect of the gauge by sending messages to the control. + * + * Before you can use this control, you MUST first export the window + * procedure for the control (or define it with the _export keyword): + * + * EXPORTS gaugeWndProc + * + * You then need initialize the class before you use it: + * + * if (!gaugeInit(hInstance)) + * die a horrible death + * else + * you are good to go + * + * The colors used by the control default to black and white if you + * are running on a mono-display. They default to blue and white + * if you are on a color display. You enable the 3D effect by setting + * the ZYZGS_3D style flag in the styles field of the control (like + * any other control). + * + * To select your own colors, you can send the ZYZG_SETFGCOLOR and + * ZYZG_SETBKCOLOR messages to set the foreground (percent done) and + * background (percent not done) colors. The lParam is the RGB() + * value--wParam is ignored. + * + * In all of the following ZYZG_??? messages, the arguments are + * WORDS. If you are setting parameters, the value is sent as + * the wParam (lParam is ignored). If you are getting parameters, + * the value is returned as a LONG and should be cast to a *signed* + * integer. + * + * To set the depth of the 3D effect (if enabled), you can send the + * ZYZG_SETBEZELFACE and ZYZG_SETWIDTH3D messages. The bezel face + * is the flat top on the 3D border--its color will be that of the + * button-face. The 3D width is the width of the bezel itself; inside + * and outside. The light color is white, the dark color is gray. + * Both widths *can* be zero--both default to 2 which looks to me. + * + * The range of the control can be set by sending the ZYZG_SETRANGE + * message to the control. It can be any integer from 1 to 32767. + * What this specifies is the number of pieces that create a whole. + * The default is 100. You can get the current range setting by + * sending the ZYZG_GETRANGE message to the control. + * + * The position (number of pieces out of the whole have been used) is + * set with the ZYZG_SETPOSITION message. It can be any integer from + * 0 to the current range setting of the control--it will be clipped + * if the position is out of bounds. The default position is 0. You + * can get the current position at any time with the ZYZG_GETPOSITION + * message. + * + * You can also set the range using a delta from the current range. + * This is done by sending the ZYZG_SETDELTAPOS message with wParam + * set to a _signed_ integer value within the range of the control. + * + * The font used for the percentage text can be set using the standard + * WM_SETFONT message. You can get the current font at any time with + * the WM_GETFONT message. + * + * The orientation can be left to right, right to left, bottom to top, + * or top to bottom. Whatever suits your needs. You set this by + * sending the ZYZG_ORIENTATION message to the control with one of + * the following values (default is ZYZG_ORIENT_LEFTTORIGHT): + * + * ZYZG_ORIENT_LEFTTORIGHT (0) + * ZYZG_ORIENT_RIGHTTOLEFT (1) + * ZYZG_ORIENT_BOTTOMTOTOP (2) + * ZYZG_ORIENT_TOPTOBOTTOM (3) + * + * HISTORY: + * 3/12/91 cjp put in this comment + * 6/19/92 cjp touched it a bit + * + ** cjp */ +// COPYRIGHT: +// +// (C) Copyright Microsoft Corp. 1992. All rights reserved. +// +// You have a royalty-free right to use, modify, reproduce and +// distribute the Sample Files (and/or any modified version) in +// any way you find useful, provided that you agree that +// Microsoft has no warranty obligations or liability for any +// Sample Application Files which are modified. +// + + +/* get the includes we need */ +#ifndef __GNUWIN32__ +#include +#endif +#include +#include +#include +// #include "zyz3d.h" +// #include "zyzgauge.h" + + +/* static global variables */ +static char gszzYzGaugeClass[] = "zYzGauge"; + + +/* window word position definitions */ +#define ZYZG_WW_PZYZGAUGE 0 +/* #define ZYZG_WW_EXTRABYTES 2 */ +#define ZYZG_WW_EXTRABYTES 4 + + +/* control block structure typedef */ +typedef struct tZYZGAUGE +{ + WORD wRange; + WORD wPosition; + WORD wOrientation; + WORD wWidth3D; + WORD wWidthBezelFace; + HFONT hFont; + DWORD rgbTextColor; + DWORD rgbBkColor; + +} ZYZGAUGE, *PZYZGAUGE, FAR *LPZYZGAUGE; + + +/* some default values for the control */ +#define ZYZG_DEF_RANGE 100 +#define ZYZG_DEF_POSITION 0 +#define ZYZG_DEF_ORIENTATION ZYZG_ORIENT_LEFTTORIGHT +#define ZYZG_DEF_WIDTH3D 2 +#define ZYZG_DEF_BEZELFACE 2 + + + +/* the default settings for drawing colors--display dependent */ +static DWORD rgbDefTextColor; +static DWORD rgbDefBkColor; +static BOOL fSupport3D; + +#if !defined(APIENTRY) // NT defines APIENTRY, 3.x not +#define APIENTRY FAR PASCAL +#endif + +#ifdef __WIN32__ +#define _EXPORT /**/ +#else +#define _EXPORT _export +typedef signed short int SHORT ; +#endif + +/* internal function prototypes */ +static void PASCAL gaugePaint(HWND, HDC); +/* LRESULT FAR PASCAL */ +LRESULT APIENTRY _EXPORT gaugeWndProc(HWND, UINT, WPARAM, LPARAM); + + + +/** BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) + * + * DESCRIPTION: + * Registers the window class for the zYzGauge control. Performs + * other initialization for the zYzGauge text control. This must + * be done before the zYzGauge control is used--or it will fail + * and your dialog box will not open! + * + * ARGUMENTS: + * HINSTANCE hInstance : Instance handle to register class with. + * + * RETURN (BOOL FAR): + * The return value is TRUE if the zYzGauge class was successfully + * registered. It is FALSE if the initialization fails. + * + * NOTES: + * + ** cjp */ + +//#pragma alloc_text(init, gaugeInit) + +BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) +{ + static BOOL fRegistered = FALSE; + WNDCLASS wc; + HDC hdc; + + /* assume already registered if not first instance */ + if (fRegistered) + return (TRUE); + + /* fill in the class structure for the zyzgauge control */ + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = gszzYzGaugeClass; + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wc.hInstance = hInstance; + +#ifdef ZYZGAUGE_DLL + wc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW; +#else + wc.style = CS_HREDRAW | CS_VREDRAW; +#endif + + wc.lpfnWndProc = gaugeWndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = ZYZG_WW_EXTRABYTES; + + /* attempt to register it--return FALSE if fail */ + if (!RegisterClass(&wc)) + return (FALSE); + + /* Get a DC to determine whether device is mono or not, and set + * default foreground/background colors as appropriate. + */ + if ((hdc = CreateIC("DISPLAY", NULL, NULL, 0L))) + { + /* check for mono-display */ + if ((GetDeviceCaps(hdc, BITSPIXEL) == 1) && + (GetDeviceCaps(hdc, PLANES) == 1)) + { + /* using a mono DC--white foreground, black background */ + rgbDefTextColor = RGB(255, 255, 255); + rgbDefBkColor = RGB(0, 0, 0); + } + + /* good! we have color: blue foreground, white background */ + else + { + rgbDefTextColor = RGB(0, 0, 255); + rgbDefBkColor = RGB(255, 255, 255); + } + + /* need at _least_ 8 for two shades of gray (>=VGA) */ + fSupport3D = (GetDeviceCaps(hdc, NUMCOLORS) >= 8) ? TRUE : FALSE; + + /* get rid of the DC (IC) */ + DeleteDC(hdc); + } + + /* uh-oh... can't get DC (IC)... fail */ + else + { + /* unregister the class */ + UnregisterClass(gszzYzGaugeClass, hInstance); + return (FALSE); + } + + /* return success */ + return (fRegistered = TRUE); +} /* gaugeInit() */ + + +/** static void PASCAL gaugePaint(HWND hwnd, HDC hdc) + * + * DESCRIPTION: + * This function is responsible for painting the zYzGauge control. + * + * ARGUMENTS: + * HWND hwnd : The window handle for the gauge. + * + * HDC hdc : The DC for the gauge's window. + * + * RETURN (void): + * The control will have been painted. + * + * NOTES: + * + ** cjp */ + +static void PASCAL gaugePaint(HWND hwnd, HDC hdc) +{ + PZYZGAUGE pgauge; + WORD iRange, iPos; + WORD Offset = 1; + DWORD dwExtent; + RECT rc1, rc2; + HFONT hFont; + char ach[ 6 ]; + WORD dx, dy, wGomerX, wGomerY; +/* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead, + * which needs a SIZE* parameter */ +#if defined(__WIN32__) + SIZE size; +#endif + + /* get pointer to the control's control block */ +// pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE); + pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE); + + /* set the colors into for the gauge into the control */ + SetTextColor(hdc, pgauge->rgbTextColor); + SetBkColor(hdc, pgauge->rgbBkColor); + + /* draw black rectangle for gauge */ + GetClientRect(hwnd, &rc1); + + /* draw a black border on the _outside_ */ + FrameRect(hdc, &rc1, GetStockObject(BLACK_BRUSH)); + + /* we want to draw _just inside_ the black border */ + InflateRect(&rc1, -1, -1); + + /* one line thick so far... */ +// Offset = (WORD) 1; + + /* for 3D stuff, we need to have at least two shades of gray */ + if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D) + { + Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_OUT); + InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D)); + + Draw3DFaceFrame(hdc, &rc1, pgauge->wWidthBezelFace); + InflateRect(&rc1, ~(pgauge->wWidthBezelFace), ~(pgauge->wWidthBezelFace)); + + Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_IN); + InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D)); + + /* draw a black border on the _inside_ */ + FrameRect(hdc, &rc1, GetStockObject(BLACK_BRUSH)); + + /* we want to draw _just inside_ the black border */ + InflateRect(&rc1, -1, -1); + + /* add all the other pixels into the border width */ + Offset += (2 * pgauge->wWidth3D) + pgauge->wWidthBezelFace + 1; + } + + /* dup--one rc for 'how much filled', one rc for 'how much empty' */ + rc2 = rc1; + + /* get the range--make sure it's a valid range */ + if ((iRange = pgauge->wRange) <= 0) + iRange = 1; + + /* get the position--greater than 100% would be bad */ + if ((iPos = pgauge->wPosition) > iRange) + iPos = iRange; + + /* compute the actual size of the gauge */ + dx = rc1.right - rc1.left; + dy = rc1.bottom - rc1.top; + wGomerX = (WORD)((DWORD)iPos * dx / iRange); + wGomerY = (WORD)((DWORD)iPos * dy / iRange); + + /* get the orientation and munge rects accordingly */ + switch (pgauge->wOrientation) + { + case ZYZG_ORIENT_RIGHTTOLEFT: + rc1.left = rc2.right = rc1.right - wGomerX; + break; + + case ZYZG_ORIENT_BOTTOMTOTOP: + rc1.top = rc2.bottom = rc1.bottom - wGomerY; + break; + + case ZYZG_ORIENT_TOPTOBOTTOM: + rc1.bottom = rc2.top += wGomerY; + break; + + default: + rc1.right = rc2.left += wGomerX; + break; + } /* switch () */ + + /* select the correct font */ + hFont = SelectObject(hdc, pgauge->hFont); + + /* build up a string to blit out--ie the meaning of life: "42%" */ + wsprintf(ach, "%3d%%", (WORD)((DWORD)iPos * 100 / iRange)); +/* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */ +#if defined(__WIN32__) + GetTextExtentPoint(hdc, ach, wGomerX = lstrlen(ach), &size); + dwExtent = size.cx; +#else + dwExtent = GetTextExtent(hdc, ach, wGomerX = lstrlen(ach)); +#endif + + + /* Draw the finished (ie the percent done) side of box. If + * ZYZG_WW_POSITION is 42, (in range of 0 to 100) this ExtTextOut + * draws the meaning of life (42%) bar. + */ + ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset, + (dy - HIWORD(dwExtent)) / 2 + Offset, + ETO_OPAQUE | ETO_CLIPPED, &rc2, ach, wGomerX, NULL); + + /* Reverse fore and back colors for drawing the undone (ie the non- + * finished) side of the box. + */ + SetBkColor(hdc, pgauge->rgbTextColor); + SetTextColor(hdc, pgauge->rgbBkColor); + + ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset, + (dy - HIWORD(dwExtent)) / 2 + Offset, + ETO_OPAQUE | ETO_CLIPPED, &rc1, ach, wGomerX, NULL); + + /* unselect the font */ + SelectObject(hdc, hFont); +} /* gaugePaint() */ + + +/** LRESULT FAR PASCAL gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) + * + * DESCRIPTION: + * This is the control's window procedure. Its purpose is to handle + * special messages for this custom control. + * + * The special control messages for the gauge control are: + * + * ZYZG_SETRANGE : Sets the range of the gauge. In other + * words, the number of parts that make a + * whole. + * + * ZYZG_GETRANGE : Returns the current range of the gauge. + * + * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This + * can be one of the ZYZG_ORIENT_?? msgs. + * + * ZYZG_GETORIENTATION : Gets the current orientation of the + * gauge. + * + * ZYZG_SETPOSITION : Sets the current position of the gauge. + * In other words, how many pieces of the + * whole have been used. + * + * ZYZG_GETPOSITION : Gets the current position of the gauge. + * + * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the + * specified amount. + * + * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color. + * + * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color. + * + * ZYZG_SETBKCOLOR : Sets the background (percent not done) + * color. + * + * ZYZG_GETBKCOLOR : Gets the background (percent not done) + * color. + * + * WM_SETFONT : Sets the font to use for the percentage + * text of the gauge. + * + * WM_GETFONT : Gets the current font in use by the + * gauge. + * + * NOTES: + * + ** cjp */ + +/* LRESULT FAR PASCAL */ + +LRESULT APIENTRY _EXPORT gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + HFONT hFont; + PAINTSTRUCT ps; + PZYZGAUGE pgauge; + RECT rc; + +// pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE); + pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE); + + /* break to get DefWindowProc() */ + switch (uMsg) + { + case WM_CREATE: + /* need to allocate a control block */ +// pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE)); + pgauge = (PZYZGAUGE)malloc(sizeof(ZYZGAUGE)); + if (!pgauge) + return (0L); + + /* hang on to this control block */ +// SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge); + SetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE, (LONG)pgauge); + + /* fill control block with defaults */ + pgauge->wRange = ZYZG_DEF_RANGE; + pgauge->wPosition = ZYZG_DEF_POSITION; + pgauge->wOrientation = ZYZG_DEF_ORIENTATION; + pgauge->wWidth3D = ZYZG_DEF_WIDTH3D; + pgauge->wWidthBezelFace = ZYZG_DEF_BEZELFACE; + pgauge->rgbTextColor = rgbDefTextColor; + pgauge->rgbBkColor = rgbDefBkColor; + + /* use system font */ + SendMessage(hwnd, WM_SETFONT, (WPARAM)NULL, 0L); + + /* go to DefWindowProc() to finish the job */ + break; + + case WM_DESTROY: + /* get rid of the control's memory */ + if (pgauge) +// LocalFree((HANDLE)pgauge); + free(pgauge); + break; + + case ZYZG_GETPOSITION: + return (pgauge->wPosition); + + case ZYZG_GETRANGE: + return (pgauge->wRange); + + case ZYZG_GETORIENTATION: + return (pgauge->wOrientation); + + case ZYZG_GETWIDTH3D: + return (pgauge->wWidth3D); + + case ZYZG_GETBEZELFACE: + return (pgauge->wWidthBezelFace); + + case ZYZG_GETBKCOLOR: + return (pgauge->rgbTextColor); + + case ZYZG_GETFGCOLOR: + return (pgauge->rgbBkColor); + + case ZYZG_SETBKCOLOR: + pgauge->rgbBkColor = lParam; + return (0L); + + case ZYZG_SETFGCOLOR: + pgauge->rgbTextColor = lParam; + return (0L); + + + case ZYZG_SETPOSITION: + pgauge->wPosition = wParam; + +zyzgForceRepaint: + GetClientRect(hwnd, &rc); + if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D) + { + wParam = (2 * pgauge->wWidth3D) + + pgauge->wWidthBezelFace + 2; + } + + else + wParam = 1; + + InflateRect(&rc, ~(wParam), ~(wParam)); + InvalidateRect(hwnd, &rc, FALSE); + UpdateWindow(hwnd); + return (0L); + + case ZYZG_SETRANGE: + pgauge->wRange = wParam; + goto zyzgForceRepaint; + + case ZYZG_SETORIENTATION: + pgauge->wOrientation = wParam; + goto zyzgForceRepaint; + + case ZYZG_SETWIDTH3D: + pgauge->wWidth3D = wParam; + +zyzgForceRepaint3D: + InvalidateRect(hwnd, NULL, FALSE); + UpdateWindow(hwnd); + return (0L); + + case ZYZG_SETBEZELFACE: + pgauge->wWidthBezelFace = wParam; + goto zyzgForceRepaint3D; + + case ZYZG_SETDELTAPOS: +/* Watcom doesn't like the following line so removing typecasts */ +/* (int)pgauge->wPosition += (int)wParam; */ + pgauge->wPosition += wParam; + goto zyzgForceRepaint; + + case WM_PAINT: + BeginPaint(hwnd, &ps); + gaugePaint(hwnd, ps.hdc); + EndPaint(hwnd, &ps); + return (0L); + + case WM_GETFONT: + hFont = pgauge->hFont; + + /* if system font, then return NULL handle */ + return (long)((hFont == GetStockObject(SYSTEM_FONT)) ? NULL : hFont); + + case WM_SETFONT: + /* if NULL hFont, use system font */ + if (!(hFont = (HFONT)wParam)) + hFont = GetStockObject(SYSTEM_FONT); + + pgauge->hFont = hFont; + + /* redraw if indicated in message */ + if ((BOOL)lParam) + { + InvalidateRect(hwnd, NULL, TRUE); + UpdateWindow(hwnd); + } + return (0L); + } /* switch () */ + + /* let the dialog mangler take care of this message */ + return (DefWindowProc(hwnd, uMsg, wParam, lParam)); +} /* gaugeWndProc() */ + + +/** EOF: zyzgauge.c **/ + +#endif // USE_GAUGE diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 6d38a1c526..5a7242ced4 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -902,8 +902,6 @@ long wxListCtrl::HitTest(const wxPoint& point, int& flags) // Inserts an item, returning the index of the new item if successful, // -1 otherwise. -// TOD: Should also have some further convenience functions -// which don't require setting a wxListItem object long wxListCtrl::InsertItem(wxListItem& info) { LV_ITEM item; diff --git a/src/msw/makefile.b32 b/src/msw/makefile.b32 index 5c54df4c22..5af01f3c54 100644 --- a/src/msw/makefile.b32 +++ b/src/msw/makefile.b32 @@ -139,6 +139,8 @@ MSWOBJS = \ $(MSWDIR)\fontdlg.obj \ $(MSWDIR)\frame.obj \ $(MSWDIR)\gauge.obj \ + $(MSWDIR)\gauge95.obj \ + $(MSWDIR)\gaugemsw.obj \ $(MSWDIR)\gdiobj.obj \ $(MSWDIR)\helpwin.obj \ $(MSWDIR)\icon.obj \ @@ -166,7 +168,8 @@ MSWOBJS = \ $(MSWDIR)\registry.obj \ $(MSWDIR)\scrolbar.obj \ $(MSWDIR)\settings.obj \ - $(MSWDIR)\slider.obj \ + $(MSWDIR)\slidrmsw.obj \ + $(MSWDIR)\slider95.obj \ $(MSWDIR)\spinbutt.obj \ $(MSWDIR)\statbmp.obj \ $(MSWDIR)\statbox.obj \ @@ -278,7 +281,9 @@ $(MSWDIR)\fontdlg.obj: $(MSWDIR)\fontdlg.$(SRCSUFF) $(MSWDIR)\frame.obj: $(MSWDIR)\frame.$(SRCSUFF) -$(MSWDIR)\gauge.obj: $(MSWDIR)\gauge.$(SRCSUFF) +$(MSWDIR)\gaugemsw.obj: $(MSWDIR)\gaugemsw.$(SRCSUFF) + +$(MSWDIR)\gauge95.obj: $(MSWDIR)\gauge95.$(SRCSUFF) $(MSWDIR)\gdiobj.obj: $(MSWDIR)\gdiobj.$(SRCSUFF) @@ -332,7 +337,9 @@ $(MSWDIR)\scrolbar.obj: $(MSWDIR)\scrolbar.$(SRCSUFF) $(MSWDIR)\settings.obj: $(MSWDIR)\settings.$(SRCSUFF) -$(MSWDIR)\slider.obj: $(MSWDIR)\slider.$(SRCSUFF) +$(MSWDIR)\slidrmsw.obj: $(MSWDIR)\slidrmsw.$(SRCSUFF) + +$(MSWDIR)\slider95.obj: $(MSWDIR)\slider95.$(SRCSUFF) $(MSWDIR)\spinbutt.obj: $(MSWDIR)\spinbutt.$(SRCSUFF) diff --git a/src/msw/makefile.dos b/src/msw/makefile.dos index aaa369bbb4..495269d746 100644 --- a/src/msw/makefile.dos +++ b/src/msw/makefile.dos @@ -139,7 +139,7 @@ MSWOBJS = \ $(MSWDIR)\font.obj \ $(MSWDIR)\fontdlg.obj \ $(MSWDIR)\frame.obj \ - $(MSWDIR)\gauge.obj \ + $(MSWDIR)\gaugemsw.obj \ $(MSWDIR)\gdiobj.obj \ $(MSWDIR)\helpwin.obj \ $(MSWDIR)\icon.obj \ @@ -166,12 +166,11 @@ MSWOBJS = \ $(MSWDIR)\region.obj \ $(MSWDIR)\scrolbar.obj \ $(MSWDIR)\settings.obj \ - $(MSWDIR)\slider.obj \ + $(MSWDIR)\slidrmsw.obj \ $(MSWDIR)\spinbutt.obj \ $(MSWDIR)\statbmp.obj \ $(MSWDIR)\statbox.obj \ $(MSWDIR)\stattext.obj \ - $(MSWDIR)\tbar95.obj \ $(MSWDIR)\tbarmsw.obj \ $(MSWDIR)\textctrl.obj \ $(MSWDIR)\timer.obj \ @@ -394,7 +393,7 @@ $(MSWDIR)/frame.obj: $*.$(SRCSUFF) $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) << -$(MSWDIR)/gauge.obj: $*.$(SRCSUFF) +$(MSWDIR)/gaugemsw.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) << @@ -534,7 +533,7 @@ $(MSWDIR)/settings.obj: $*.$(SRCSUFF) $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) << -$(MSWDIR)/slider.obj: $*.$(SRCSUFF) +$(MSWDIR)/slidrmsw.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) << @@ -559,11 +558,6 @@ $(MSWDIR)/stattext.obj: $*.$(SRCSUFF) $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) << -$(MSWDIR)/tbar95.obj: $*.$(SRCSUFF) - cl @<< -$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) -<< - $(MSWDIR)/tbarmsw.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) diff --git a/src/msw/makefile.g95 b/src/msw/makefile.g95 index 8e972d826e..ac7a357e2c 100644 --- a/src/msw/makefile.g95 +++ b/src/msw/makefile.g95 @@ -144,7 +144,8 @@ MSWOBJS = \ font.$(OBJSUFF) \ fontdlg.$(OBJSUFF) \ frame.$(OBJSUFF) \ - gauge.$(OBJSUFF) \ + gaugemsw.$(OBJSUFF) \ + gauge95.$(OBJSUFF) \ gdiobj.$(OBJSUFF) \ helpwin.$(OBJSUFF) \ icon.$(OBJSUFF) \ @@ -172,7 +173,8 @@ MSWOBJS = \ registry.$(OBJSUFF) \ scrolbar.$(OBJSUFF) \ settings.$(OBJSUFF) \ - slider.$(OBJSUFF) \ + slidrmsw.$(OBJSUFF) \ + slider95.$(OBJSUFF) \ spinbutt.$(OBJSUFF) \ statbmp.$(OBJSUFF) \ statbox.$(OBJSUFF) \ diff --git a/src/msw/makefile.nt b/src/msw/makefile.nt index 607e08a1fa..9246301775 100644 --- a/src/msw/makefile.nt +++ b/src/msw/makefile.nt @@ -143,7 +143,8 @@ MSWOBJS = \ $(MSWDIR)\font.obj \ $(MSWDIR)\fontdlg.obj \ $(MSWDIR)\frame.obj \ - $(MSWDIR)\gauge.obj \ + $(MSWDIR)\gauge95.obj \ + $(MSWDIR)\gaugemsw.obj \ $(MSWDIR)\gdiobj.obj \ $(MSWDIR)\helpwin.obj \ $(MSWDIR)\icon.obj \ @@ -172,7 +173,8 @@ MSWOBJS = \ $(MSWDIR)\registry.obj \ $(MSWDIR)\scrolbar.obj \ $(MSWDIR)\settings.obj \ - $(MSWDIR)\slider.obj \ + $(MSWDIR)\slidrmsw.obj \ + $(MSWDIR)\slider95.obj \ $(MSWDIR)\spinbutt.obj \ $(MSWDIR)\statbmp.obj \ $(MSWDIR)\statbox.obj \ @@ -414,7 +416,12 @@ $(MSWDIR)/frame.obj: $*.$(SRCSUFF) $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ << -$(MSWDIR)/gauge.obj: $*.$(SRCSUFF) +$(MSWDIR)/gauge95.obj: $*.$(SRCSUFF) + cl @<< +$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ +<< + +$(MSWDIR)/gaugemsw.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ << @@ -559,7 +566,12 @@ $(MSWDIR)/settings.obj: $*.$(SRCSUFF) $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ << -$(MSWDIR)/slider.obj: $*.$(SRCSUFF) +$(MSWDIR)/slidrmsw.obj: $*.$(SRCSUFF) + cl @<< +$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ +<< + +$(MSWDIR)/slider95.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@ << diff --git a/src/msw/slider.cpp b/src/msw/slider.cpp deleted file mode 100644 index 1114477aa2..0000000000 --- a/src/msw/slider.cpp +++ /dev/null @@ -1,790 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: slider.cpp -// Purpose: wxSlider -// Author: Julian Smart -// Modified by: -// Created: 04/01/98 -// RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "slider.h" -#endif - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#include -#include "wx/slider.h" -#endif - -#include "wx/msw/private.h" - -// Can opt to not use track bar under Win95 if you prefer it - set to 0 -#define USE_TRACK_BAR 1 - -#if defined(__WIN95__) && !defined(__GNUWIN32__) -#include -#endif - -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) - -#if WXWIN_COMPATIBILITY -BEGIN_EVENT_TABLE(wxSlider, wxControl) - EVT_SCROLL(wxSlider::OnScroll) -END_EVENT_TABLE() -#endif - -#endif - -// Slider -wxSlider::wxSlider(void) -{ - m_staticValue = 0; - m_staticMin = 0; - m_staticMax = 0; - m_pageSize = 1; - m_lineSize = 1; - m_rangeMax = 0; - m_rangeMin = 0; - m_tickFreq = 0; -} - -bool wxSlider::Create(wxWindow *parent, const wxWindowID id, - const int value, const int minValue, const int maxValue, - const wxPoint& pos, - const wxSize& size, const long style, - const wxValidator& validator, - const wxString& name) -{ - SetName(name); - SetValidator(validator); - - if (parent) parent->AddChild(this); - SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; - SetForegroundColour(parent->GetDefaultForegroundColour()) ; - - m_staticValue = 0; - m_staticMin = 0; - m_staticMax = 0; - m_pageSize = 1; - m_lineSize = 1; - m_windowStyle = style; - m_tickFreq = 0; - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; - - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; - -#if defined(__WIN95__) && USE_TRACK_BAR - long msStyle ; - - if ( m_windowStyle & wxSL_LABELS ) - { - msStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER; - - bool want3D; - WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; - - m_staticValue = (WXHWND) CreateWindowEx(exStyle, "STATIC", NULL, - msStyle, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), - wxGetInstance(), NULL); - - // Now create min static control - sprintf(wxBuffer, "%d", minValue); - m_staticMin = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, - STATIC_FLAGS, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), - wxGetInstance(), NULL); - } - - msStyle = 0; - if (m_windowStyle & wxSL_VERTICAL) - msStyle = TBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; - else - msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; - - if ( m_windowStyle & wxSL_AUTOTICKS ) - msStyle |= TBS_AUTOTICKS ; - - if ( m_windowStyle & wxSL_LEFT ) - msStyle |= TBS_LEFT; - else if ( m_windowStyle & wxSL_RIGHT ) - msStyle |= TBS_RIGHT; - else if ( m_windowStyle & wxSL_TOP ) - msStyle |= TBS_TOP; - else if ( m_windowStyle & wxSL_BOTTOM ) - msStyle |= TBS_BOTTOM; - else if ( m_windowStyle & wxSL_BOTH ) - msStyle |= TBS_BOTH; - else if ( ! (m_windowStyle & wxSL_AUTOTICKS) ) - msStyle |= TBS_NOTICKS; - - if ( m_windowStyle & wxSL_SELRANGE ) - msStyle |= TBS_ENABLESELRANGE ; - - HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), TRACKBAR_CLASS, wxBuffer, - msStyle, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, - wxGetInstance(), NULL); - - m_rangeMax = maxValue; - m_rangeMin = minValue; - - m_pageSize = (int)((maxValue-minValue)/10); - - ::SendMessage(scroll_bar, TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); - ::SendMessage(scroll_bar, TBM_SETPOS, TRUE, (LPARAM)value); - ::SendMessage(scroll_bar, TBM_SETPAGESIZE, 0, (LPARAM)m_pageSize); - - m_hWnd = (WXHWND)scroll_bar; - - SubclassWin(GetHWND()); - - SetFont(parent->GetFont()); - - if ( m_windowStyle & wxSL_LABELS ) - { - // Finally, create max value static item - sprintf(wxBuffer, "%d", maxValue); - m_staticMax = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, - STATIC_FLAGS, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), - wxGetInstance(), NULL); - - if (GetFont()) - { -// GetFont()->RealizeResource(); - if (GetFont()->GetResourceHandle()) - { - if ( m_staticMin ) - SendMessage((HWND)m_staticMin,WM_SETFONT, - (WPARAM)GetFont()->GetResourceHandle(),0L); - if ( m_staticMax ) - SendMessage((HWND)m_staticMax,WM_SETFONT, - (WPARAM)GetFont()->GetResourceHandle(),0L); - if (m_staticValue) - SendMessage((HWND)m_staticValue,WM_SETFONT, - (WPARAM)GetFont()->GetResourceHandle(),0L); - } - } - } -#else - // non-Win95 implementation - - long msStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER; - - bool want3D; - WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; - - m_staticValue = (WXHWND) CreateWindowEx(exStyle, "STATIC", NULL, - msStyle, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), - wxGetInstance(), NULL); - - // Now create min static control - sprintf(wxBuffer, "%d", minValue); - m_staticMin = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, - STATIC_FLAGS, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), - wxGetInstance(), NULL); - - // Now create slider - m_windowId = (int)NewControlId(); - - msStyle = 0; - if (m_windowStyle & wxSL_VERTICAL) - msStyle = SBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; - else - msStyle = SBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; - - HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), "SCROLLBAR", wxBuffer, - msStyle, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, - wxGetInstance(), NULL); - - m_pageSize = (int)((maxValue-minValue)/10); - m_rangeMax = maxValue; - m_rangeMin = minValue; - - ::SetScrollRange(scroll_bar, SB_CTL, minValue, maxValue, FALSE); - ::SetScrollPos(scroll_bar, SB_CTL, value, FALSE); - ShowWindow(scroll_bar, SW_SHOW); - - m_hWnd = (WXHWND)scroll_bar; - - // Subclass again for purposes of dialog editing mode - SubclassWin(GetHWND()); - - // Finally, create max value static item - sprintf(wxBuffer, "%d", maxValue); - m_staticMax = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, - STATIC_FLAGS, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), - wxGetInstance(), NULL); - - SetFont(* parent->GetFont()); - - if (GetFont()) - { -// GetFont()->RealizeResource(); - if (GetFont()->GetResourceHandle()) - { - if ( m_staticMin ) - SendMessage((HWND)m_staticMin,WM_SETFONT, - (WPARAM)GetFont()->GetResourceHandle(),0L); - if ( m_staticMax ) - SendMessage((HWND)m_staticMax,WM_SETFONT, - (WPARAM)GetFont()->GetResourceHandle(),0L); - if (m_staticValue) - SendMessage((HWND)m_staticValue,WM_SETFONT, - (WPARAM)GetFont()->GetResourceHandle(),0L); - } - } -#endif - - SetSize(x, y, width, height); - SetValue(value); - - return TRUE; -} - -void wxSlider::MSWOnVScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - int position = 0; // Dummy - not used in this mode -#else - int position = ::GetScrollPos((HWND)control, SB_CTL); -#endif - - int nScrollInc; - wxEventType scrollEvent = wxEVT_NULL; - switch ( wParam ) - { - case SB_TOP: - nScrollInc = m_rangeMax - position; - scrollEvent = wxEVT_SCROLL_TOP; - break; - - case SB_BOTTOM: - nScrollInc = - position; - scrollEvent = wxEVT_SCROLL_BOTTOM; - break; - - case SB_LINEUP: - nScrollInc = - GetLineSize(); - scrollEvent = wxEVT_SCROLL_LINEUP; - break; - - case SB_LINEDOWN: - nScrollInc = GetLineSize(); - scrollEvent = wxEVT_SCROLL_LINEDOWN; - break; - - case SB_PAGEUP: - nScrollInc = -GetPageSize(); - scrollEvent = wxEVT_SCROLL_PAGEUP; - break; - - case SB_PAGEDOWN: - nScrollInc = GetPageSize(); - scrollEvent = wxEVT_SCROLL_PAGEDOWN; - break; - - case SB_THUMBTRACK: - case SB_THUMBPOSITION: -#ifdef __WIN32__ - nScrollInc = (signed short)pos - position; -#else - nScrollInc = pos - position; -#endif - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - break; - - default: - nScrollInc = 0; - return; - } - -#if !(WIN95 && USE_TRACK_BAR) - if (nScrollInc != 0) -#endif - { - -#if defined(__WIN95__) && USE_TRACK_BAR - int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0); -#else - int newPos = position + nScrollInc; -#endif - if (!(newPos < GetMin() || newPos > GetMax())) - { - SetValue(newPos); - - wxScrollEvent event(scrollEvent, m_windowId); - event.SetPosition(newPos); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - } - } -} - -void wxSlider::MSWOnHScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) -{ - MSWOnVScroll(wParam, pos, control); -} - -wxSlider::~wxSlider(void) -{ - if (m_staticMin) - DestroyWindow((HWND) m_staticMin); - if (m_staticMax) - DestroyWindow((HWND) m_staticMax); - if (m_staticValue) - DestroyWindow((HWND) m_staticValue); -} - -int wxSlider::GetValue(void) const -{ -#if defined(__WIN95__) && USE_TRACK_BAR - return ::SendMessage((HWND) GetHWND(), TBM_GETPOS, 0, 0); -#else - return ::GetScrollPos((HWND) GetHWND(), SB_CTL); -#endif -} - -void wxSlider::SetValue(const int value) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage((HWND) GetHWND(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); -#else - ::SetScrollPos((HWND) GetHWND(), SB_CTL, value, TRUE); -#endif - if (m_staticValue) - { - sprintf(wxBuffer, "%d", value); - SetWindowText((HWND) m_staticValue, wxBuffer); - } -} - -void wxSlider::GetSize(int *width, int *height) const -{ - RECT rect; - rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; - - wxFindMaxSize(GetHWND(), &rect); - - if (m_staticMin) - wxFindMaxSize(m_staticMin, &rect); - if (m_staticMax) - wxFindMaxSize(m_staticMax, &rect); - if (m_staticValue) - wxFindMaxSize(m_staticValue, &rect); - - *width = rect.right - rect.left; - *height = rect.bottom - rect.top; -} - -void wxSlider::GetPosition(int *x, int *y) const -{ - wxWindow *parent = GetParent(); - RECT rect; - rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; - - wxFindMaxSize(GetHWND(), &rect); - - if (m_staticMin) - wxFindMaxSize(m_staticMin, &rect); - if (m_staticMax) - wxFindMaxSize(m_staticMax, &rect); - if (m_staticValue) - wxFindMaxSize(m_staticValue, &rect); - - // Since we now have the absolute screen coords, - // if there's a parent we must subtract its top left corner - POINT point; - point.x = rect.left; - point.y = rect.top; - if (parent) - ::ScreenToClient((HWND) parent->GetHWND(), &point); - - *x = point.x; - *y = point.y; -} - -void wxSlider::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) -{ - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - int currentX, currentY; - GetPosition(¤tX, ¤tY); - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - char buf[300]; - - int x_offset = x; - int y_offset = y; - - int cx; // slider,min,max sizes - int cy; - float cyf; - - wxGetCharSize(GetHWND(), &cx, &cy,GetFont()); - - if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) - { - if ( m_windowStyle & wxSL_LABELS ) - { - float min_len = 0.0; - - GetWindowText((HWND) m_staticMin, buf, 300); - GetTextExtent(buf, &min_len, &cyf,NULL,NULL, GetFont()); - - float max_len = 0.0; - - GetWindowText((HWND) m_staticMax, buf, 300); - GetTextExtent(buf, &max_len, &cyf,NULL,NULL, GetFont()); - if (m_staticValue) - { - int new_width = (int)(wxMax(min_len, max_len)); - int valueHeight = (int)cyf; -#ifdef __WIN32__ - // For some reason, under Win95, the text edit control has - // a lot of space before the first character - new_width += 3*cx; -#endif -#if defined(__WIN95__) - // The height needs to be a bit bigger under Win95 if using native - // 3D effects. - valueHeight = (int) (valueHeight * 1.5) ; -#endif - MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); - x_offset += new_width + cx; - } - - MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); - x_offset += (int)(min_len + cx); - - int slider_length = (int)(w1 - x_offset - max_len - cx); - -#if defined(__WIN95__) && USE_TRACK_BAR - int slider_height = h1; - if (slider_height < 0 ) - slider_height = 20; -#else - int slider_height = cy; -#endif - - // Slider must have a minimum/default length/height - if (slider_length < 100) - slider_length = 100; - - MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_length, slider_height, TRUE); - x_offset += slider_length + cx; - - MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); - } - else - { - // No labels - if ( w1 < 0 ) - w1 = 200; - if ( h1 < 0 ) - h1 = 20; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); - } - } - else - { - if ( m_windowStyle & wxSL_LABELS ) - { - float min_len; - GetWindowText((HWND) m_staticMin, buf, 300); - GetTextExtent(buf, &min_len, &cyf,NULL,NULL,GetFont()); - - float max_len; - GetWindowText((HWND) m_staticMax, buf, 300); - GetTextExtent(buf, &max_len, &cyf,NULL,NULL, GetFont()); - - if (m_staticValue) - { - int new_width = (int)(wxMax(min_len, max_len)); - int valueHeight = (int)cyf; -/*** Suggested change by George Tasker - remove this block... -#ifdef __WIN32__ - // For some reason, under Win95, the text edit control has - // a lot of space before the first character - new_width += 3*cx; -#endif - ... and replace with following line: */ - new_width += cx; - -#if defined(__WIN95__) - // The height needs to be a bit bigger under Win95 if using native - // 3D effects. - valueHeight = (int) (valueHeight * 1.5) ; -#endif - - MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); - y_offset += valueHeight; - } - - MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); - y_offset += cy; - - int slider_length = (int)(h1 - y_offset - cy - cy); -#if defined(__WIN95__) && USE_TRACK_BAR - int slider_width = w1; - if (slider_width < 0 ) - slider_width = 20; -#else - // Use character height as an estimate of slider width (yes, width) - int slider_width = cy; -#endif - - // Slider must have a minimum/default length - if (slider_length < 100) - slider_length = 100; - - MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_width, slider_length, TRUE); - y_offset += slider_length; - - MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); - } - else - { - // No labels - if ( w1 < 0 ) - w1 = 20; - if ( h1 < 0 ) - h1 = 200; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); - } - } - -/* -#if WXWIN_COMPATIBILITY - GetEventHandler()->OldOnSize(width, height); -#else - wxSizeEvent event(wxSize(width, height), m_windowId); - event.eventObject = this; - GetEventHandler()->ProcessEvent(event); -#endif -*/ - -} - -void wxSlider::SetRange(const int minValue, const int maxValue) -{ - m_rangeMin = minValue; - m_rangeMax = maxValue; - -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage((HWND) GetHWND(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); -#else - ::SetScrollRange((HWND) GetHWND(), SB_CTL, m_rangeMin, m_rangeMax, TRUE); -#endif - char buf[40]; - if ( m_staticMin ) - { - sprintf(buf, "%d", m_rangeMin); - SetWindowText((HWND) m_staticMin, buf); - } - - if ( m_staticMax ) - { - sprintf(buf, "%d", m_rangeMax); - SetWindowText((HWND) m_staticMax, buf); - } -} - -WXHBRUSH wxSlider::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) -{ - if ( nCtlColor == CTLCOLOR_SCROLLBAR ) - return 0; - - // Otherwise, it's a static - if (GetParent()->GetTransparentBackground()) - SetBkMode((HDC) pDC, TRANSPARENT); - else - SetBkMode((HDC) pDC, OPAQUE); - - ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); - ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); - - wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); - - // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush - // has a zero usage count. -// backgroundBrush->RealizeResource(); - return (WXHBRUSH) backgroundBrush->GetResourceHandle(); -} - -// For trackbars only -void wxSlider::SetTickFreq(const int n, const int pos) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - m_tickFreq = n; - ::SendMessage( (HWND) GetHWND(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); -#endif -} - -void wxSlider::SetPageSize(const int pageSize) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage( (HWND) GetHWND(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); -#endif - m_pageSize = pageSize; -} - -int wxSlider::GetPageSize(void) const -{ - return m_pageSize; -} - -void wxSlider::ClearSel(void) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage( (HWND) GetHWND(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 ); -#endif -} - -void wxSlider::ClearTicks(void) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage( (HWND) GetHWND(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 ); -#endif -} - -void wxSlider::SetLineSize(const int lineSize) -{ - m_lineSize = lineSize; -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage( (HWND) GetHWND(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize ); -#endif -} - -int wxSlider::GetLineSize(void) const -{ -#if defined(__WIN95__) && USE_TRACK_BAR - return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 ); -#else - return m_lineSize; -#endif -} - -int wxSlider::GetSelEnd(void) const -{ -#if defined(__WIN95__) && USE_TRACK_BAR - return (int) ::SendMessage( (HWND) GetHWND(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 ); -#else - return 0; -#endif -} - -int wxSlider::GetSelStart(void) const -{ -#if defined(__WIN95__) && USE_TRACK_BAR - return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 ); -#else - return 0; -#endif -} - -void wxSlider::SetSelection(const int minPos, const int maxPos) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage( (HWND) GetHWND(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) ); -#endif -} - -void wxSlider::SetThumbLength(const int len) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage( (HWND) GetHWND(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 ); -#endif -} - -int wxSlider::GetThumbLength(void) const -{ -#if defined(__WIN95__) && USE_TRACK_BAR - return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 ); -#else - return 0; -#endif -} - -void wxSlider::SetTick(const int tickPos) -{ -#if defined(__WIN95__) && USE_TRACK_BAR - ::SendMessage( (HWND) GetHWND(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); -#endif -} - -bool wxSlider::ContainsHWND(WXHWND hWnd) const -{ - return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); -} - -#if WXWIN_COMPATIBILITY -// Backward compatibility -void wxSlider::OnScroll(wxScrollEvent& event) -{ - wxEventType oldEvent = event.GetEventType(); - event.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED ); - if ( !GetEventHandler()->ProcessEvent(event) ) - { - event.SetEventType( oldEvent ); - if (!GetParent()->GetEventHandler()->ProcessEvent(event)) - event.Skip(); - } -} -#endif - -void wxSlider::Command (wxCommandEvent & event) -{ - SetValue (event.GetInt()); - ProcessCommand (event); -} - -bool wxSlider::Show(const bool show) -{ - wxWindow::Show(show); - - int cshow; - if (show) - cshow = SW_SHOW; - else - cshow = SW_HIDE; - - if(m_staticValue) - ShowWindow((HWND) m_staticValue, (BOOL)cshow); - if(m_staticMin) - ShowWindow((HWND) m_staticMin, (BOOL)cshow); - if(m_staticMax) - ShowWindow((HWND) m_staticMax, (BOOL)cshow); - return TRUE; -} - - diff --git a/src/msw/slider95.cpp b/src/msw/slider95.cpp new file mode 100644 index 0000000000..4eb5ad1075 --- /dev/null +++ b/src/msw/slider95.cpp @@ -0,0 +1,636 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: slider95.cpp +// Purpose: wxSlider95, using the Win95 trackbar control +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart and Markus Holzem +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "slider95.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include +#endif + +#ifdef __WIN95__ + +#include "wx/msw/slider95.h" +#include "wx/msw/private.h" + +#if defined(__WIN95__) && !defined(__GNUWIN32__) +#include +#endif + +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxSlider95, wxControl) + +#if WXWIN_COMPATIBILITY +BEGIN_EVENT_TABLE(wxSlider95, wxControl) + EVT_SCROLL(wxSlider95::OnScroll) +END_EVENT_TABLE() +#endif + +#endif + +// Slider +wxSlider95::wxSlider95(void) +{ + m_staticValue = 0; + m_staticMin = 0; + m_staticMax = 0; + m_pageSize = 1; + m_lineSize = 1; + m_rangeMax = 0; + m_rangeMin = 0; + m_tickFreq = 0; +} + +bool wxSlider95::Create(wxWindow *parent, const wxWindowID id, + const int value, const int minValue, const int maxValue, + const wxPoint& pos, + const wxSize& size, const long style, + const wxValidator& validator, + const wxString& name) +{ + SetName(name); + SetValidator(validator); + + if (parent) parent->AddChild(this); + SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; + SetForegroundColour(parent->GetDefaultForegroundColour()) ; + + m_staticValue = 0; + m_staticMin = 0; + m_staticMax = 0; + m_pageSize = 1; + m_lineSize = 1; + m_windowStyle = style; + m_tickFreq = 0; + + if ( id == -1 ) + m_windowId = (int)NewControlId(); + else + m_windowId = id; + + int x = pos.x; + int y = pos.y; + int width = size.x; + int height = size.y; + + long msStyle ; + + if ( m_windowStyle & wxSL_LABELS ) + { + msStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER; + + bool want3D; + WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; + + m_staticValue = (WXHWND) CreateWindowEx(exStyle, "STATIC", NULL, + msStyle, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), + wxGetInstance(), NULL); + + // Now create min static control + sprintf(wxBuffer, "%d", minValue); + m_staticMin = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, + STATIC_FLAGS, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), + wxGetInstance(), NULL); + } + + msStyle = 0; + if (m_windowStyle & wxSL_VERTICAL) + msStyle = TBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; + else + msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; + + if ( m_windowStyle & wxSL_AUTOTICKS ) + msStyle |= TBS_AUTOTICKS ; + + if ( m_windowStyle & wxSL_LEFT ) + msStyle |= TBS_LEFT; + else if ( m_windowStyle & wxSL_RIGHT ) + msStyle |= TBS_RIGHT; + else if ( m_windowStyle & wxSL_TOP ) + msStyle |= TBS_TOP; + else if ( m_windowStyle & wxSL_BOTTOM ) + msStyle |= TBS_BOTTOM; + else if ( m_windowStyle & wxSL_BOTH ) + msStyle |= TBS_BOTH; + else if ( ! (m_windowStyle & wxSL_AUTOTICKS) ) + msStyle |= TBS_NOTICKS; + + if ( m_windowStyle & wxSL_SELRANGE ) + msStyle |= TBS_ENABLESELRANGE ; + + HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), TRACKBAR_CLASS, wxBuffer, + msStyle, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, + wxGetInstance(), NULL); + + m_rangeMax = maxValue; + m_rangeMin = minValue; + + m_pageSize = (int)((maxValue-minValue)/10); + + ::SendMessage(scroll_bar, TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); + ::SendMessage(scroll_bar, TBM_SETPOS, TRUE, (LPARAM)value); + ::SendMessage(scroll_bar, TBM_SETPAGESIZE, 0, (LPARAM)m_pageSize); + + m_hWnd = (WXHWND)scroll_bar; + + SubclassWin(GetHWND()); + + if ( m_windowStyle & wxSL_LABELS ) + { + // Finally, create max value static item + sprintf(wxBuffer, "%d", maxValue); + m_staticMax = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, + STATIC_FLAGS, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), + wxGetInstance(), NULL); + + SetFont(parent->GetFont()); + + if (GetFont()) + { +// GetFont()->RealizeResource(); + if (GetFont()->GetResourceHandle()) + { + if ( m_staticMin ) + SendMessage((HWND)m_staticMin,WM_SETFONT, + (WPARAM)GetFont()->GetResourceHandle(),0L); + if ( m_staticMax ) + SendMessage((HWND)m_staticMax,WM_SETFONT, + (WPARAM)GetFont()->GetResourceHandle(),0L); + if (m_staticValue) + SendMessage((HWND)m_staticValue,WM_SETFONT, + (WPARAM)GetFont()->GetResourceHandle(),0L); + } + } + } + + SetSize(x, y, width, height); + SetValue(value); + + return TRUE; +} + +void wxSlider95::MSWOnVScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) +{ + int position = 0; // Dummy - not used in this mode + + int nScrollInc; + wxEventType scrollEvent = wxEVT_NULL; + switch ( wParam ) + { + case SB_TOP: + nScrollInc = m_rangeMax - position; + scrollEvent = wxEVT_SCROLL_TOP; + break; + + case SB_BOTTOM: + nScrollInc = - position; + scrollEvent = wxEVT_SCROLL_BOTTOM; + break; + + case SB_LINEUP: + nScrollInc = - GetLineSize(); + scrollEvent = wxEVT_SCROLL_LINEUP; + break; + + case SB_LINEDOWN: + nScrollInc = GetLineSize(); + scrollEvent = wxEVT_SCROLL_LINEDOWN; + break; + + case SB_PAGEUP: + nScrollInc = -GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEUP; + break; + + case SB_PAGEDOWN: + nScrollInc = GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + break; + + case SB_THUMBTRACK: + case SB_THUMBPOSITION: +#ifdef __WIN32__ + nScrollInc = (signed short)pos - position; +#else + nScrollInc = pos - position; +#endif + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; + + default: + nScrollInc = 0; + return; + } + + { + + int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0); + if (!(newPos < GetMin() || newPos > GetMax())) + { + SetValue(newPos); + + wxScrollEvent event(scrollEvent, m_windowId); + event.SetPosition(newPos); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + } + } +} + +void wxSlider95::MSWOnHScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) +{ + MSWOnVScroll(wParam, pos, control); +} + +wxSlider95::~wxSlider95(void) +{ + if (m_staticMin) + DestroyWindow((HWND) m_staticMin); + if (m_staticMax) + DestroyWindow((HWND) m_staticMax); + if (m_staticValue) + DestroyWindow((HWND) m_staticValue); +} + +int wxSlider95::GetValue(void) const +{ + return ::SendMessage((HWND) GetHWND(), TBM_GETPOS, 0, 0); +} + +void wxSlider95::SetValue(const int value) +{ + ::SendMessage((HWND) GetHWND(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); + if (m_staticValue) + { + sprintf(wxBuffer, "%d", value); + SetWindowText((HWND) m_staticValue, wxBuffer); + } +} + +void wxSlider95::GetSize(int *width, int *height) const +{ + RECT rect; + rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; + + wxFindMaxSize(GetHWND(), &rect); + + if (m_staticMin) + wxFindMaxSize(m_staticMin, &rect); + if (m_staticMax) + wxFindMaxSize(m_staticMax, &rect); + if (m_staticValue) + wxFindMaxSize(m_staticValue, &rect); + + *width = rect.right - rect.left; + *height = rect.bottom - rect.top; +} + +void wxSlider95::GetPosition(int *x, int *y) const +{ + wxWindow *parent = GetParent(); + RECT rect; + rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; + + wxFindMaxSize(GetHWND(), &rect); + + if (m_staticMin) + wxFindMaxSize(m_staticMin, &rect); + if (m_staticMax) + wxFindMaxSize(m_staticMax, &rect); + if (m_staticValue) + wxFindMaxSize(m_staticValue, &rect); + + // Since we now have the absolute screen coords, + // if there's a parent we must subtract its top left corner + POINT point; + point.x = rect.left; + point.y = rect.top; + if (parent) + ::ScreenToClient((HWND) parent->GetHWND(), &point); + + *x = point.x; + *y = point.y; +} + +void wxSlider95::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) +{ + int x1 = x; + int y1 = y; + int w1 = width; + int h1 = height; + + int currentX, currentY; + GetPosition(¤tX, ¤tY); + if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + x1 = currentX; + if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + y1 = currentY; + + char buf[300]; + + int x_offset = x; + int y_offset = y; + + int cx; // slider,min,max sizes + int cy; + float cyf; + + wxGetCharSize(GetHWND(), &cx, &cy,GetFont()); + + if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) + { + if ( m_windowStyle & wxSL_LABELS ) + { + float min_len = 0.0; + + GetWindowText((HWND) m_staticMin, buf, 300); + GetTextExtent(buf, &min_len, &cyf,NULL,NULL, GetFont()); + + float max_len = 0.0; + + GetWindowText((HWND) m_staticMax, buf, 300); + GetTextExtent(buf, &max_len, &cyf,NULL,NULL, GetFont()); + if (m_staticValue) + { + int new_width = (int)(wxMax(min_len, max_len)); + int valueHeight = (int)cyf; +#ifdef __WIN32__ + // For some reason, under Win95, the text edit control has + // a lot of space before the first character + new_width += 3*cx; +#endif + // The height needs to be a bit bigger under Win95 if using native + // 3D effects. + valueHeight = (int) (valueHeight * 1.5) ; + MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); + x_offset += new_width + cx; + } + + MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); + x_offset += (int)(min_len + cx); + + int slider_length = (int)(w1 - x_offset - max_len - cx); + + int slider_height = h1; + if (slider_height < 0 ) + slider_height = 20; + + // Slider must have a minimum/default length/height + if (slider_length < 100) + slider_length = 100; + + MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_length, slider_height, TRUE); + x_offset += slider_length + cx; + + MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); + } + else + { + // No labels + if ( w1 < 0 ) + w1 = 200; + if ( h1 < 0 ) + h1 = 20; + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + } + } + else + { + if ( m_windowStyle & wxSL_LABELS ) + { + float min_len; + GetWindowText((HWND) m_staticMin, buf, 300); + GetTextExtent(buf, &min_len, &cyf,NULL,NULL,GetFont()); + + float max_len; + GetWindowText((HWND) m_staticMax, buf, 300); + GetTextExtent(buf, &max_len, &cyf,NULL,NULL, GetFont()); + + if (m_staticValue) + { + int new_width = (int)(wxMax(min_len, max_len)); + int valueHeight = (int)cyf; +/*** Suggested change by George Tasker - remove this block... +#ifdef __WIN32__ + // For some reason, under Win95, the text edit control has + // a lot of space before the first character + new_width += 3*cx; +#endif + ... and replace with following line: */ + new_width += cx; + + // The height needs to be a bit bigger under Win95 if using native + // 3D effects. + valueHeight = (int) (valueHeight * 1.5) ; + + MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); + y_offset += valueHeight; + } + + MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); + y_offset += cy; + + int slider_length = (int)(h1 - y_offset - cy - cy); + + int slider_width = w1; + if (slider_width < 0 ) + slider_width = 20; + + // Slider must have a minimum/default length + if (slider_length < 100) + slider_length = 100; + + MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_width, slider_length, TRUE); + y_offset += slider_length; + + MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); + } + else + { + // No labels + if ( w1 < 0 ) + w1 = 20; + if ( h1 < 0 ) + h1 = 200; + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + } + } +} + +void wxSlider95::SetRange(const int minValue, const int maxValue) +{ + m_rangeMin = minValue; + m_rangeMax = maxValue; + + ::SendMessage((HWND) GetHWND(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); + + char buf[40]; + if ( m_staticMin ) + { + sprintf(buf, "%d", m_rangeMin); + SetWindowText((HWND) m_staticMin, buf); + } + + if ( m_staticMax ) + { + sprintf(buf, "%d", m_rangeMax); + SetWindowText((HWND) m_staticMax, buf); + } +} + +WXHBRUSH wxSlider95::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor, + WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +{ + if ( nCtlColor == CTLCOLOR_SCROLLBAR ) + return 0; + + // Otherwise, it's a static + if (GetParent()->GetTransparentBackground()) + SetBkMode((HDC) pDC, TRANSPARENT); + else + SetBkMode((HDC) pDC, OPAQUE); + + ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); + ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); + + wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); + return (WXHBRUSH) backgroundBrush->GetResourceHandle(); +} + +// For trackbars only +void wxSlider95::SetTickFreq(const int n, const int pos) +{ + m_tickFreq = n; + ::SendMessage( (HWND) GetHWND(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); +} + +void wxSlider95::SetPageSize(const int pageSize) +{ + ::SendMessage( (HWND) GetHWND(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); + m_pageSize = pageSize; +} + +int wxSlider95::GetPageSize(void) const +{ + return m_pageSize; +} + +void wxSlider95::ClearSel(void) +{ + ::SendMessage( (HWND) GetHWND(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 ); +} + +void wxSlider95::ClearTicks(void) +{ + ::SendMessage( (HWND) GetHWND(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 ); +} + +void wxSlider95::SetLineSize(const int lineSize) +{ + m_lineSize = lineSize; + ::SendMessage( (HWND) GetHWND(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize ); +} + +int wxSlider95::GetLineSize(void) const +{ + return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 ); +} + +int wxSlider95::GetSelEnd(void) const +{ + return (int) ::SendMessage( (HWND) GetHWND(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 ); +} + +int wxSlider95::GetSelStart(void) const +{ + return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 ); +} + +void wxSlider95::SetSelection(const int minPos, const int maxPos) +{ + ::SendMessage( (HWND) GetHWND(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) ); +} + +void wxSlider95::SetThumbLength(const int len) +{ + ::SendMessage( (HWND) GetHWND(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 ); +} + +int wxSlider95::GetThumbLength(void) const +{ + return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 ); +} + +void wxSlider95::SetTick(const int tickPos) +{ + ::SendMessage( (HWND) GetHWND(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); +} + +bool wxSlider95::ContainsHWND(WXHWND hWnd) const +{ + return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); +} + +#if WXWIN_COMPATIBILITY +// Backward compatibility +void wxSlider95::OnScroll(wxScrollEvent& event) +{ + wxEventType oldEvent = event.GetEventType(); + event.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED ); + if ( !GetEventHandler()->ProcessEvent(event) ) + { + event.SetEventType( oldEvent ); + if (!GetParent()->GetEventHandler()->ProcessEvent(event)) + event.Skip(); + } +} +#endif + +void wxSlider95::Command (wxCommandEvent & event) +{ + SetValue (event.GetInt()); + ProcessCommand (event); +} + +bool wxSlider95::Show(const bool show) +{ + wxWindow::Show(show); + + int cshow; + if (show) + cshow = SW_SHOW; + else + cshow = SW_HIDE; + + if(m_staticValue) + ShowWindow((HWND) m_staticValue, (BOOL)cshow); + if(m_staticMin) + ShowWindow((HWND) m_staticMin, (BOOL)cshow); + if(m_staticMax) + ShowWindow((HWND) m_staticMax, (BOOL)cshow); + return TRUE; +} + +#endif + // __WIN95__ + diff --git a/src/msw/slidrmsw.cpp b/src/msw/slidrmsw.cpp new file mode 100644 index 0000000000..aa01a17495 --- /dev/null +++ b/src/msw/slidrmsw.cpp @@ -0,0 +1,589 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: slidermsw.cpp +// Purpose: wxSliderMSW +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart and Markus Holzem +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "slidrmsw.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include +#endif + +#include "wx/msw/slidrmsw.h" +#include "wx/msw/private.h" + +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxSliderMSW, wxControl) + +#if WXWIN_COMPATIBILITY +BEGIN_EVENT_TABLE(wxSliderMSW, wxControl) + EVT_SCROLL(wxSliderMSW::OnScroll) +END_EVENT_TABLE() +#endif + +#endif + +// Slider +wxSliderMSW::wxSliderMSW(void) +{ + m_staticValue = 0; + m_staticMin = 0; + m_staticMax = 0; + m_pageSize = 1; + m_lineSize = 1; + m_rangeMax = 0; + m_rangeMin = 0; + m_tickFreq = 0; +} + +bool wxSliderMSW::Create(wxWindow *parent, const wxWindowID id, + const int value, const int minValue, const int maxValue, + const wxPoint& pos, + const wxSize& size, const long style, + const wxValidator& validator, + const wxString& name) +{ + SetName(name); + SetValidator(validator); + + if (parent) parent->AddChild(this); + SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; + SetForegroundColour(parent->GetDefaultForegroundColour()) ; + + m_staticValue = 0; + m_staticMin = 0; + m_staticMax = 0; + m_pageSize = 1; + m_lineSize = 1; + m_windowStyle = style; + m_tickFreq = 0; + + if ( id == -1 ) + m_windowId = (int)NewControlId(); + else + m_windowId = id; + + int x = pos.x; + int y = pos.y; + int width = size.x; + int height = size.y; + + // non-Win95 implementation + + long msStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER; + + bool want3D; + WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; + + m_staticValue = (WXHWND) CreateWindowEx(exStyle, "STATIC", NULL, + msStyle, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), + wxGetInstance(), NULL); + + // Now create min static control + sprintf(wxBuffer, "%d", minValue); + m_staticMin = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, + STATIC_FLAGS, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), + wxGetInstance(), NULL); + + // Now create slider + m_windowId = (int)NewControlId(); + + msStyle = 0; + if (m_windowStyle & wxSL_VERTICAL) + msStyle = SBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; + else + msStyle = SBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; + + HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), "SCROLLBAR", wxBuffer, + msStyle, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, + wxGetInstance(), NULL); + + m_pageSize = (int)((maxValue-minValue)/10); + m_rangeMax = maxValue; + m_rangeMin = minValue; + + ::SetScrollRange(scroll_bar, SB_CTL, minValue, maxValue, FALSE); + ::SetScrollPos(scroll_bar, SB_CTL, value, FALSE); + ShowWindow(scroll_bar, SW_SHOW); + + m_hWnd = (WXHWND)scroll_bar; + + // Subclass again for purposes of dialog editing mode + SubclassWin(GetHWND()); + + // Finally, create max value static item + sprintf(wxBuffer, "%d", maxValue); + m_staticMax = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer, + STATIC_FLAGS, + 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(), + wxGetInstance(), NULL); + + SetFont(* parent->GetFont()); + + if (GetFont()) + { +// GetFont()->RealizeResource(); + if (GetFont()->GetResourceHandle()) + { + if ( m_staticMin ) + SendMessage((HWND)m_staticMin,WM_SETFONT, + (WPARAM)GetFont()->GetResourceHandle(),0L); + if ( m_staticMax ) + SendMessage((HWND)m_staticMax,WM_SETFONT, + (WPARAM)GetFont()->GetResourceHandle(),0L); + if (m_staticValue) + SendMessage((HWND)m_staticValue,WM_SETFONT, + (WPARAM)GetFont()->GetResourceHandle(),0L); + } + } + + SetSize(x, y, width, height); + SetValue(value); + + return TRUE; +} + +void wxSliderMSW::MSWOnVScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) +{ + int position = ::GetScrollPos((HWND)control, SB_CTL); + + int nScrollInc; + wxEventType scrollEvent = wxEVT_NULL; + switch ( wParam ) + { + case SB_TOP: + nScrollInc = m_rangeMax - position; + scrollEvent = wxEVT_SCROLL_TOP; + break; + + case SB_BOTTOM: + nScrollInc = - position; + scrollEvent = wxEVT_SCROLL_BOTTOM; + break; + + case SB_LINEUP: + nScrollInc = - GetLineSize(); + scrollEvent = wxEVT_SCROLL_LINEUP; + break; + + case SB_LINEDOWN: + nScrollInc = GetLineSize(); + scrollEvent = wxEVT_SCROLL_LINEDOWN; + break; + + case SB_PAGEUP: + nScrollInc = -GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEUP; + break; + + case SB_PAGEDOWN: + nScrollInc = GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + break; + + case SB_THUMBTRACK: + case SB_THUMBPOSITION: +#ifdef __WIN32__ + nScrollInc = (signed short)pos - position; +#else + nScrollInc = pos - position; +#endif + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; + + default: + nScrollInc = 0; + return; + } + + if (nScrollInc != 0) + { + + int newPos = position + nScrollInc; + + if (!(newPos < GetMin() || newPos > GetMax())) + { + SetValue(newPos); + + wxScrollEvent event(scrollEvent, m_windowId); + event.SetPosition(newPos); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + } + } +} + +void wxSliderMSW::MSWOnHScroll(const WXWORD wParam, const WXWORD pos, const WXHWND control) +{ + MSWOnVScroll(wParam, pos, control); +} + +wxSliderMSW::~wxSliderMSW(void) +{ + if (m_staticMin) + DestroyWindow((HWND) m_staticMin); + if (m_staticMax) + DestroyWindow((HWND) m_staticMax); + if (m_staticValue) + DestroyWindow((HWND) m_staticValue); +} + +int wxSliderMSW::GetValue(void) const +{ + return ::GetScrollPos((HWND) GetHWND(), SB_CTL); +} + +void wxSliderMSW::SetValue(const int value) +{ + ::SetScrollPos((HWND) GetHWND(), SB_CTL, value, TRUE); + if (m_staticValue) + { + sprintf(wxBuffer, "%d", value); + SetWindowText((HWND) m_staticValue, wxBuffer); + } +} + +void wxSliderMSW::GetSize(int *width, int *height) const +{ + RECT rect; + rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; + + wxFindMaxSize(GetHWND(), &rect); + + if (m_staticMin) + wxFindMaxSize(m_staticMin, &rect); + if (m_staticMax) + wxFindMaxSize(m_staticMax, &rect); + if (m_staticValue) + wxFindMaxSize(m_staticValue, &rect); + + *width = rect.right - rect.left; + *height = rect.bottom - rect.top; +} + +void wxSliderMSW::GetPosition(int *x, int *y) const +{ + wxWindow *parent = GetParent(); + RECT rect; + rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1; + + wxFindMaxSize(GetHWND(), &rect); + + if (m_staticMin) + wxFindMaxSize(m_staticMin, &rect); + if (m_staticMax) + wxFindMaxSize(m_staticMax, &rect); + if (m_staticValue) + wxFindMaxSize(m_staticValue, &rect); + + // Since we now have the absolute screen coords, + // if there's a parent we must subtract its top left corner + POINT point; + point.x = rect.left; + point.y = rect.top; + if (parent) + ::ScreenToClient((HWND) parent->GetHWND(), &point); + + *x = point.x; + *y = point.y; +} + +void wxSliderMSW::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) +{ + int x1 = x; + int y1 = y; + int w1 = width; + int h1 = height; + + int currentX, currentY; + GetPosition(¤tX, ¤tY); + if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + x1 = currentX; + if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + y1 = currentY; + + char buf[300]; + + int x_offset = x; + int y_offset = y; + + int cx; // slider,min,max sizes + int cy; + float cyf; + + wxGetCharSize(GetHWND(), &cx, &cy,GetFont()); + + if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) + { + if ( m_windowStyle & wxSL_LABELS ) + { + float min_len = 0.0; + + GetWindowText((HWND) m_staticMin, buf, 300); + GetTextExtent(buf, &min_len, &cyf,NULL,NULL, GetFont()); + + float max_len = 0.0; + + GetWindowText((HWND) m_staticMax, buf, 300); + GetTextExtent(buf, &max_len, &cyf,NULL,NULL, GetFont()); + if (m_staticValue) + { + int new_width = (int)(wxMax(min_len, max_len)); + int valueHeight = (int)cyf; +#ifdef __WIN32__ + // For some reason, under Win95, the text edit control has + // a lot of space before the first character + new_width += 3*cx; +#endif + MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); + x_offset += new_width + cx; + } + + MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); + x_offset += (int)(min_len + cx); + + int slider_length = (int)(w1 - x_offset - max_len - cx); + + int slider_height = cy; + + // Slider must have a minimum/default length/height + if (slider_length < 100) + slider_length = 100; + + MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_length, slider_height, TRUE); + x_offset += slider_length + cx; + + MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); + } + else + { + // No labels + if ( w1 < 0 ) + w1 = 200; + if ( h1 < 0 ) + h1 = 20; + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + } + } + else + { + if ( m_windowStyle & wxSL_LABELS ) + { + float min_len; + GetWindowText((HWND) m_staticMin, buf, 300); + GetTextExtent(buf, &min_len, &cyf,NULL,NULL,GetFont()); + + float max_len; + GetWindowText((HWND) m_staticMax, buf, 300); + GetTextExtent(buf, &max_len, &cyf,NULL,NULL, GetFont()); + + if (m_staticValue) + { + int new_width = (int)(wxMax(min_len, max_len)); + int valueHeight = (int)cyf; +/*** Suggested change by George Tasker - remove this block... +#ifdef __WIN32__ + // For some reason, under Win95, the text edit control has + // a lot of space before the first character + new_width += 3*cx; +#endif + ... and replace with following line: */ + new_width += cx; + + MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); + y_offset += valueHeight; + } + + MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE); + y_offset += cy; + + int slider_length = (int)(h1 - y_offset - cy - cy); + + // Use character height as an estimate of slider width (yes, width) + int slider_width = cy; + + // Slider must have a minimum/default length + if (slider_length < 100) + slider_length = 100; + + MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_width, slider_length, TRUE); + y_offset += slider_length; + + MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); + } + else + { + // No labels + if ( w1 < 0 ) + w1 = 20; + if ( h1 < 0 ) + h1 = 200; + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + } + } +} + +void wxSliderMSW::SetRange(const int minValue, const int maxValue) +{ + m_rangeMin = minValue; + m_rangeMax = maxValue; + + ::SetScrollRange((HWND) GetHWND(), SB_CTL, m_rangeMin, m_rangeMax, TRUE); + char buf[40]; + if ( m_staticMin ) + { + sprintf(buf, "%d", m_rangeMin); + SetWindowText((HWND) m_staticMin, buf); + } + + if ( m_staticMax ) + { + sprintf(buf, "%d", m_rangeMax); + SetWindowText((HWND) m_staticMax, buf); + } +} + +WXHBRUSH wxSliderMSW::OnCtlColor(const WXHDC pDC, const WXHWND pWnd, const WXUINT nCtlColor, + WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +{ + if ( nCtlColor == CTLCOLOR_SCROLLBAR ) + return 0; + + // Otherwise, it's a static + if (GetParent()->GetTransparentBackground()) + SetBkMode((HDC) pDC, TRANSPARENT); + else + SetBkMode((HDC) pDC, OPAQUE); + + ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); + ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); + + wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); + + return (WXHBRUSH) backgroundBrush->GetResourceHandle(); +} + +// For trackbars only +void wxSliderMSW::SetTickFreq(const int n, const int pos) +{ +} + +void wxSliderMSW::SetPageSize(const int pageSize) +{ + m_pageSize = pageSize; +} + +int wxSliderMSW::GetPageSize(void) const +{ + return m_pageSize; +} + +void wxSliderMSW::ClearSel(void) +{ +} + +void wxSliderMSW::ClearTicks(void) +{ +} + +void wxSliderMSW::SetLineSize(const int lineSize) +{ + m_lineSize = lineSize; +} + +int wxSliderMSW::GetLineSize(void) const +{ + return m_lineSize; +} + +int wxSliderMSW::GetSelEnd(void) const +{ + return 0; +} + +int wxSliderMSW::GetSelStart(void) const +{ + return 0; +} + +void wxSliderMSW::SetSelection(const int minPos, const int maxPos) +{ +} + +void wxSliderMSW::SetThumbLength(const int len) +{ +} + +int wxSliderMSW::GetThumbLength(void) const +{ + return 0; +} + +void wxSliderMSW::SetTick(const int tickPos) +{ +} + +bool wxSliderMSW::ContainsHWND(WXHWND hWnd) const +{ + return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); +} + +#if WXWIN_COMPATIBILITY +// Backward compatibility +void wxSliderMSW::OnScroll(wxScrollEvent& event) +{ + wxEventType oldEvent = event.GetEventType(); + event.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED ); + if ( !GetEventHandler()->ProcessEvent(event) ) + { + event.SetEventType( oldEvent ); + if (!GetParent()->GetEventHandler()->ProcessEvent(event)) + event.Skip(); + } +} +#endif + +void wxSliderMSW::Command (wxCommandEvent & event) +{ + SetValue (event.GetInt()); + ProcessCommand (event); +} + +bool wxSliderMSW::Show(const bool show) +{ + wxWindow::Show(show); + + int cshow; + if (show) + cshow = SW_SHOW; + else + cshow = SW_HIDE; + + if(m_staticValue) + ShowWindow((HWND) m_staticValue, (BOOL)cshow); + if(m_staticMin) + ShowWindow((HWND) m_staticMin, (BOOL)cshow); + if(m_staticMax) + ShowWindow((HWND) m_staticMax, (BOOL)cshow); + return TRUE; +} + + diff --git a/src/msw/tabctrl.cpp b/src/msw/tabctrl.cpp index 179c51311c..0bda814675 100644 --- a/src/msw/tabctrl.cpp +++ b/src/msw/tabctrl.cpp @@ -228,6 +228,12 @@ int wxTabCtrl::GetSelection() const return (int) TabCtrl_GetCurSel( (HWND) GetHWND() ); } +// Get the tab with the current keyboard focus +int wxTabCtrl::GetCurFocus() const +{ + return (int) TabCtrl_GetCurFocus( (HWND) GetHWND() ); +} + // Get the associated image list wxImageList* wxTabCtrl::GetImageList() const {