From 3c299c3ab663257429983c24e6fb71450f3cf9f1 Mon Sep 17 00:00:00 2001 From: David Webster Date: Mon, 17 Dec 2001 22:56:41 +0000 Subject: [PATCH] OS/2 common controls code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13065 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/os2/gauge.h | 90 ++- include/wx/os2/private.h | 4 + include/wx/os2/radiobox.h | 241 +++--- include/wx/os2/radiobut.h | 69 +- include/wx/os2/setup0.h | 3 + include/wx/os2/slider.h | 206 +++-- include/wx/os2/spinbutt.h | 74 +- include/wx/os2/spinctrl.h | 115 ++- include/wx/os2/statbmp.h | 6 +- include/wx/os2/statbox.h | 59 +- include/wx/os2/statline.h | 63 +- include/wx/os2/stattext.h | 8 +- src/os2/control.cpp | 2 + src/os2/gauge.cpp | 1302 +++++-------------------------- src/os2/radiobox.cpp | 1561 +++++++++++++++++++++++-------------- src/os2/radiobut.cpp | 280 +++---- src/os2/slider.cpp | 1277 +++++++++++++++++++++--------- src/os2/spinbutt.cpp | 247 +++--- src/os2/spinctrl.cpp | 552 ++++++++----- src/os2/statbox.cpp | 235 ++---- src/os2/statline.cpp | 70 +- src/os2/stattext.cpp | 46 +- src/os2/utils.cpp | 75 ++ src/os2/window.cpp | 42 + 24 files changed, 3596 insertions(+), 3031 deletions(-) diff --git a/include/wx/os2/gauge.h b/include/wx/os2/gauge.h index 24c44ba4c8..67378ff770 100644 --- a/include/wx/os2/gauge.h +++ b/include/wx/os2/gauge.h @@ -18,52 +18,68 @@ WXDLLEXPORT_DATA(extern const char*) wxGaugeNameStr; class WXDLLEXPORT wxGauge: public wxControl { - DECLARE_DYNAMIC_CLASS(wxGauge) - public: - inline wxGauge() { m_rangeMax = 0; m_gaugePos = 0; } +public: + inline wxGauge() { m_nRangeMax = 0; m_nGaugePos = 0; } - inline wxGauge(wxWindow *parent, wxWindowID id, - int range, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxGA_HORIZONTAL, + inline wxGauge( wxWindow* pParent + ,wxWindowID vId + ,int nRange + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxGA_HORIZONTAL #if wxUSE_VALIDATORS - const wxValidator& validator = wxDefaultValidator, + ,const wxValidator& rValidator = wxDefaultValidator #endif - const wxString& name = wxGaugeNameStr) - { - Create(parent, id, range, pos, size, style, validator, name); - } + ,const wxString& rsName = wxGaugeNameStr + ) + { + Create( pParent + ,vId + ,nRange + ,rPos + ,rSize + ,lStyle +#if wxUSE_VALIDATORS + ,rValidator +#endif + ,rsName + ); + } - bool Create(wxWindow *parent, wxWindowID id, - int range, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxGA_HORIZONTAL, + bool Create( wxWindow* pParent + ,wxWindowID vId + ,int nRange + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxGA_HORIZONTAL #if wxUSE_VALIDATORS - const wxValidator& validator = wxDefaultValidator, + ,const wxValidator& rValidator = wxDefaultValidator #endif - const wxString& name = wxGaugeNameStr); + ,const wxString& rsName = wxGaugeNameStr + ); - void SetShadowWidth(int w); - void SetBezelFace(int w); - void SetRange(int r); - void SetValue(int pos); + int GetShadowWidth(void) const; + int GetBezelFace(void) const; + int GetRange(void) const; + int GetValue(void) const; - int GetShadowWidth() const ; - int GetBezelFace() const ; - int GetRange() const ; - int GetValue() const ; + bool SetBackgroundColour(const wxColour& rColour); + void SetBezelFace(int nWidth); + bool SetForegroundColour(const wxColour& rColour); + void SetRange(int nRange); + void SetShadowWidth(int nWidth); + void SetValue(int nPos); - bool SetForegroundColour(const wxColour& col); - bool SetBackgroundColour(const wxColour& col); + inline virtual bool AcceptsFocus(void) const { return FALSE; } + inline virtual void Command(wxCommandEvent& WXUNUSED(rEvent)) {}; - virtual void Command(wxCommandEvent& WXUNUSED(event)) {} ; +protected: + int m_nRangeMax; + int m_nGaugePos; - protected: - int m_rangeMax; - int m_gaugePos; -}; +private: + DECLARE_DYNAMIC_CLASS(wxGauge) +}; // end of CLASS wxGauge + +#endif // _WX_GAUGE_H_ -#endif - // _WX_GAUGE_H_ diff --git a/include/wx/os2/private.h b/include/wx/os2/private.h index 067a3ee8dd..17badf421f 100644 --- a/include/wx/os2/private.h +++ b/include/wx/os2/private.h @@ -232,6 +232,10 @@ inline bool wxStyleHasBorder(long style) wxSUNKEN_BORDER | wxDOUBLE_BORDER)) != 0; } +WXDLLEXPORT extern void wxOS2SetFont( HWND hWnd + ,const wxFont& rFont + ); + #endif // _WX_PRIVATE_H_ diff --git a/include/wx/os2/radiobox.h b/include/wx/os2/radiobox.h index e664ccf7bf..0e6d7b022a 100644 --- a/include/wx/os2/radiobox.h +++ b/include/wx/os2/radiobox.h @@ -19,105 +19,168 @@ class WXDLLEXPORT wxBitmap ; class WXDLLEXPORT wxRadioBox: public wxControl, public wxRadioBoxBase { - DECLARE_DYNAMIC_CLASS(wxRadioBox) public: - wxRadioBox(); - - inline wxRadioBox(wxWindow *parent, wxWindowID id, const wxString& title, - const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - int majorDim = 0, long style = wxRA_HORIZONTAL, + wxRadioBox(); + + inline wxRadioBox( wxWindow* pParent + ,wxWindowID vId + ,const wxString& rsTitle + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,int nNum = 0 + ,const wxString asChoices[] = NULL + ,int nMajorDim = 0 + ,long lStyle = wxRA_HORIZONTAL #if wxUSE_VALIDATORS - const wxValidator& val = wxDefaultValidator, const wxString& name = wxRadioBoxNameStr) + ,const wxValidator& rVal = wxDefaultValidator #endif - { - Create(parent, id, title, pos, size, n, choices, majorDim, style, val, name); - } - - ~wxRadioBox(); - - bool Create(wxWindow *parent, wxWindowID id, const wxString& title, - const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - int majorDim = 0, long style = wxRA_HORIZONTAL, + ,const wxString& rsName = wxRadioBoxNameStr + ) + { + Create( pParent + ,vId + ,rsTitle + ,rPos + ,rSize + ,nNum + ,asChoices + ,nMajorDim + ,lStyle +#if wxUSE_VALIDATORS + ,rVal +#endif + ,rsName + ); + } + + ~wxRadioBox(); + + bool Create( wxWindow* pParent + ,wxWindowID vId + ,const wxString& rsTitle + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,int nNum = 0 + ,const wxString asChoices[] = NULL + ,int nMajorDim = 0 + ,long lStyle = wxRA_HORIZONTAL #if wxUSE_VALIDATORS - const wxValidator& val = wxDefaultValidator, const wxString& name = wxRadioBoxNameStr); + ,const wxValidator& rVal = wxDefaultValidator #endif + ,const wxString& rsName = wxRadioBoxNameStr + ); + + void Command(wxCommandEvent& rEvent); + bool ContainsHWND(WXHWND hWnd) const; + bool Enable(bool bEnable); + void Enable( int nItem + ,bool bEnable + ); + int FindString(const wxString& sStr) const; + + virtual WXHBRUSH OnCtlColor( WXHDC hDC + ,WXHWND hWnd + ,WXUINT uCtlColor + ,WXUINT uMessage + ,WXWPARAM wParam + ,WXLPARAM lParam + ); + virtual bool OS2Command( WXUINT uParam + ,WXWORD wId + ); + void SendNotificationEvent(void); + void Show( int nItem + ,bool bShow = TRUE + ) ; + bool Show(bool bShow); + MRESULT WindowProc( WXUINT uMsg + ,WXWPARAM wParam + ,WXLPARAM lParam + ); + + + + + virtual int GetColumnCount(void) const; + virtual int GetCount(void) const; + inline int GetNumberOfRowsOrCols(void) const { return m_nNoRowsOrCols; } + int GetNumHor(void) const; + int GetNumVer(void) const; + void GetPosition( int* pnX + ,int* pnY + ) const; + inline WXHWND* GetRadioButtons(void) const { return m_ahRadioButtons; } + virtual int GetRowCount(void) const; + int GetSelection(void) const; + void GetSize( int* pnX + ,int* pnY + ) const; + void GetSizeFlags(void) const; + void AdjustButtons( int nX + ,int nY + ,int nWidth + ,int nHeight + ,int lSizeFlags + ); + wxString GetString(int nIndex) const; + virtual wxString GetStringSelection(void) const; + + inline void SetButtonFont(const wxFont& rFont) { SetFont(rFont); } + void SetFocus(void); + virtual bool SetFont(const wxFont& rFont); + inline void SetLabelFont(const wxFont& WXUNUSED(font)) {}; + inline void SetNumberOfRowsOrCols(int nNum) { m_nNoRowsOrCols = nNum; } + void SetSelection(int nIndex); + virtual void SetString( int nNum + ,const wxString& rsLabel + ); + virtual bool SetStringSelection(const wxString& rsStr); + + void SetLabel( int nItem + ,const wxString& rsLabel + ); + void SetLabel( int item + ,wxBitmap* pBitmap + ); + wxString GetLabel(int nItem) const; - virtual bool OS2Command(WXUINT param, WXWORD id); - virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - - int FindString(const wxString& s) const; - void SetSelection(int N); - int GetSelection() const; - virtual int GetCount() const; - wxString GetString(int N) const; - virtual void SetString(int n, const wxString& label); - virtual int GetColumnCount() const; - virtual int GetRowCount() const; - - void GetSize(int *x, int *y) const; - void GetPosition(int *x, int *y) const; - - void SetLabel(int item, const wxString& label); - void SetLabel(int item, wxBitmap *bitmap); - wxString GetLabel(int item) const; - bool Show(bool show); - void SetFocus(); - bool Enable(bool enable); - void Enable(int item, bool enable); - void Show(int item, bool show) ; - inline void SetLabelFont(const wxFont& WXUNUSED(font)) {}; - inline void SetButtonFont(const wxFont& font) { SetFont(font); } - - virtual wxString GetStringSelection() const; - virtual bool SetStringSelection(const wxString& s); - inline virtual int Number() const { return m_noItems; } ; - void Command(wxCommandEvent& event); - - inline int GetNumberOfRowsOrCols() const { return m_noRowsOrCols; } - inline void SetNumberOfRowsOrCols(int n) { m_noRowsOrCols = n; } - - // implementation only from now on - // ------------------------------- - - WXHWND *GetRadioButtons() const { return m_radioButtons; } - bool ContainsHWND(WXHWND hWnd) const; - void SendNotificationEvent(); - - // get the number of buttons per column/row - int GetNumVer() const; - int GetNumHor() const; - -#if WXWIN_COMPATIBILITY - wxRadioBox(wxWindow *parent, wxFunction func, const char *title, - int x = -1, int y = -1, int width = -1, int height = -1, - int n = 0, char **choices = NULL, - int majorDim = 0, long style = wxRA_HORIZONTAL, const char *name = wxRadioBoxNameStr); -#endif // WXWIN_COMPATIBILITY protected: - void SubclassRadioButton(WXHWND hWndBtn); - - WXHWND * m_radioButtons; - int m_majorDim ; - int * m_radioWidth; // for bitmaps - int * m_radioHeight; + void AdjustButtons( int nX + ,int nY + ,int nWidth + ,int nHeight + ,long lSizeFlags + ); + virtual wxSize DoGetBestSize(void) const; + virtual void DoSetSize( int nX + ,int nY + ,int nWidth + ,int nHeight + ,int nSizeFlags = wxSIZE_AUTO + ); + wxSize GetMaxButtonSize(void) const; + wxSize GetTotalButtonSize(const wxSize& rSizeBtn) const; + void SubclassRadioButton(WXHWND hWndBtn); + + + WXHWND* m_ahRadioButtons; + int m_nMajorDim ; + int* m_pnRadioWidth; // for bitmaps + int* m_pnRadioHeight; + int m_nNoItems; + int m_nNoRowsOrCols; + int m_nSelectedButton; + int m_nSizeFlags; - int m_noItems; - int m_noRowsOrCols; - int m_selectedButton; - - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); private: - virtual void SetLabel(const wxString& label) - { wxWindowBase::SetLabel(label); } - wxString GetLabel() const - { return(wxWindowBase::GetLabel()); } -}; + inline wxString GetLabel() const + { return wxWindowBase::GetLabel(); } + inline void SetLabel(const wxString& rsLabel) + { wxWindowBase::SetLabel(rsLabel); } + + DECLARE_DYNAMIC_CLASS(wxRadioBox) +}; // end of wxRadioBox #endif // _WX_RADIOBOX_H_ diff --git a/include/wx/os2/radiobut.h b/include/wx/os2/radiobut.h index ee96b5008b..8d23a64bcb 100644 --- a/include/wx/os2/radiobut.h +++ b/include/wx/os2/radiobut.h @@ -18,38 +18,55 @@ WXDLLEXPORT_DATA(extern const char*) wxRadioButtonNameStr; class WXDLLEXPORT wxRadioButton: public wxControl { - DECLARE_DYNAMIC_CLASS(wxRadioButton) - protected: - public: - inline wxRadioButton() {} - inline wxRadioButton(wxWindow *parent, wxWindowID id, - const wxString& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, +public: + inline wxRadioButton() {} + inline wxRadioButton( wxWindow* pParent + ,wxWindowID vId + ,const wxString& rsLabel + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = 0 #if wxUSE_VALIDATORS - const wxValidator& validator = wxDefaultValidator, + ,const wxValidator& rValidator = wxDefaultValidator #endif - const wxString& name = wxRadioButtonNameStr) - { - Create(parent, id, label, pos, size, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID id, - const wxString& label, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, + ,const wxString& rsName = wxRadioButtonNameStr + ) + { + Create( pParent + ,vId + ,rsLabel + ,rPos + ,rSize + ,lStyle #if wxUSE_VALIDATORS - const wxValidator& validator = wxDefaultValidator, + ,rValidator #endif - const wxString& name = wxRadioButtonNameStr); + ,rsName + ); + } - virtual void SetLabel(const wxString& label); - virtual void SetValue(bool val); - virtual bool GetValue() const ; + bool Create( wxWindow* pParent + ,wxWindowID vId + ,const wxString& rsLabel + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = 0 +#if wxUSE_VALIDATORS + ,const wxValidator& rValidator = wxDefaultValidator +#endif + ,const wxString& rsName = wxRadioButtonNameStr + ); + virtual void SetLabel(const wxString& rsLabel); + virtual void SetValue(bool bVal); + virtual bool GetValue(void) const ; - bool OS2Command(WXUINT param, WXWORD id); - void Command(wxCommandEvent& event); -}; + bool OS2Command( WXUINT wParam + ,WXWORD wId + ); + void Command(wxCommandEvent& rEvent); +private: + DECLARE_DYNAMIC_CLASS(wxRadioButton) +}; // end of wxRadioButton #endif // _WX_RADIOBUT_H_ diff --git a/include/wx/os2/setup0.h b/include/wx/os2/setup0.h index ac026638bc..689c1ab4c9 100644 --- a/include/wx/os2/setup0.h +++ b/include/wx/os2/setup0.h @@ -376,5 +376,8 @@ #define NO_TEXT_WINDOW_STREAM 1 // defined in textctrl.h for DLL builds #endif +#define wxUSE_UNICODE 0 +#define wxUSE_UNICODE_MSLU 0 + #endif // _WX_SETUP_H_ diff --git a/include/wx/os2/slider.h b/include/wx/os2/slider.h index ba675da4d1..66b9b282be 100644 --- a/include/wx/os2/slider.h +++ b/include/wx/os2/slider.h @@ -19,95 +19,135 @@ WXDLLEXPORT_DATA(extern const char*) wxSliderNameStr; // Slider class WXDLLEXPORT wxSlider: public wxSliderBase { - DECLARE_DYNAMIC_CLASS(wxSlider) - public: wxSlider(); - - inline wxSlider(wxWindow *parent, wxWindowID id, - int value, int minValue, int maxValue, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSL_HORIZONTAL, + inline wxSlider( wxWindow* pParent + ,wxWindowID vId + ,int nValue + ,int nMinValue + ,int nMaxValue + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxSL_HORIZONTAL #if wxUSE_VALIDATORS - const wxValidator& validator = wxDefaultValidator, + ,const wxValidator& rValidator = wxDefaultValidator #endif - const wxString& name = wxSliderNameStr) - { - Create(parent, id, value, minValue, maxValue, pos, size, style, validator, name); - } - - ~wxSlider(); - - bool Create(wxWindow *parent, wxWindowID id, - int value, int minValue, int maxValue, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSL_HORIZONTAL, + ,const wxString& rsName = wxSliderNameStr + ) + { + Create( pParent + ,vId + ,nValue + ,nMinValue + ,nMaxValue + ,rPos + ,rSize + ,lStyle #if wxUSE_VALIDATORS - const wxValidator& validator = wxDefaultValidator, + ,rValidator #endif - const wxString& name = wxSliderNameStr); - - virtual int GetValue() const ; - virtual void SetValue(int); - - void GetSize(int *x, int *y) const ; - void GetPosition(int *x, int *y) const ; - - bool Show(bool show); - - void SetRange(int minValue, int maxValue); - - inline int GetMin() const { return m_rangeMin; } - inline int GetMax() const { return m_rangeMax; } - - void SetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); - - - - // For trackbars only - void SetTickFreq(int n, int pos); - inline int GetTickFreq() const { return m_tickFreq; } - void SetPageSize(int pageSize); - int GetPageSize() const ; - void ClearSel() ; - void ClearTicks() ; - void SetLineSize(int lineSize); - int GetLineSize() const ; - int GetSelEnd() const ; - int GetSelStart() const ; - void SetSelection(int minPos, int maxPos); - void SetThumbLength(int len) ; - int GetThumbLength() const ; - void SetTick(int tickPos) ; - - // IMPLEMENTATION - WXHWND GetStaticMin() const { return m_staticMin; } - WXHWND GetStaticMax() const { return m_staticMax; } - WXHWND GetEditValue() const { return m_staticValue; } - virtual bool ContainsHWND(WXHWND hWnd) const; - - void Command(wxCommandEvent& event); - virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - virtual bool OS2OnScroll(int orientation, WXWORD wParam, - WXWORD pos, 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; - - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); -}; + ,rsName + ); + } + ~wxSlider(); + + bool Create( wxWindow* pParent + ,wxWindowID vId + ,int nValue + ,int nMinValue + ,int nMaxValue + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxSL_HORIZONTAL +#if wxUSE_VALIDATORS + ,const wxValidator& rValidator = wxDefaultValidator +#endif + ,const wxString& rsName = wxSliderNameStr + ); + + virtual int GetValue(void) const ; + virtual void SetValue(int); + + void GetSize( int* pnX + ,int* pnY + ) const; + void GetPosition( int* pnX + ,int* pnY + ) const ; + bool Show(bool bShow); + void SetRange( int nMinValue + ,int nMaxValue + ); + + inline int GetMin(void) const { return m_nRangeMin; } + inline int GetMax(void) const { return m_nRangeMax; } + + // + // For trackbars only + // + void ClearSel(void); + void ClearTicks(void); + + int GetLineSize(void) const; + int GetPageSize(void) const ; + int GetSelEnd(void) const; + int GetSelStart(void) const; + inline int GetTickFreq(void) const { return m_nTickFreq; } + int GetThumbLength(void) const ; + + void SetLineSize(int nLineSize); + void SetPageSize(int nPageSize); + void SetSelection( int nMinPos + ,int nMaxPos + ); + void SetThumbLength(int nLen) ; + void SetTick(int ntickPos) ; + void SetTickFreq( int n + ,int nPos + ); + + // + // IMPLEMENTATION + // + inline WXHWND GetStaticMin(void) const { return m_hStaticMin; } + inline WXHWND GetStaticMax(void) const { return m_hStaticMax; } + inline WXHWND GetEditValue(void) const { return m_hStaticValue; } + virtual bool ContainsHWND(WXHWND hWnd) const; + void Command(wxCommandEvent& rEvent); + virtual WXHBRUSH OnCtlColor( WXHDC hDC + ,WXHWND hWnd + ,WXUINT uCtlColor + ,WXUINT uMessage + ,WXWPARAM wParam + ,WXLPARAM lParam + ); + virtual bool OS2OnScroll( int nOrientation + ,WXWORD wParam + ,WXWORD wPos + ,WXHWND hControl + ); + +protected: + WXHWND m_hStaticMin; + WXHWND m_hStaticMax; + WXHWND m_hStaticValue; + int m_nRangeMin; + int m_nRangeMax; + int m_nPageSize; + int m_nLineSize; + int m_nTickFreq; + double m_dPixelToRange; + int m_nThumbLength; + + virtual void DoSetSize( int nX + ,int nY + ,int nWidth + ,int nHeight + ,int nSizeFlags = wxSIZE_AUTO + ); +private: + DECLARE_DYNAMIC_CLASS(wxSlider) +}; // end of CLASS wxSlider #endif // _WX_SLIDER_H_ diff --git a/include/wx/os2/spinbutt.h b/include/wx/os2/spinbutt.h index 643ae907d9..493f7fddfc 100644 --- a/include/wx/os2/spinbutt.h +++ b/include/wx/os2/spinbutt.h @@ -15,58 +15,66 @@ #include "wx/control.h" #include "wx/event.h" +extern MRESULT EXPENTRY wxSpinCtrlWndProc( + HWND hWnd +, UINT uMessage +, MPARAM wParam +, MPARAM lParam +); + class WXDLLEXPORT wxSpinButton: public wxSpinButtonBase { public: // Construction wxSpinButton() { } - - inline wxSpinButton( wxWindow *parent - ,wxWindowID id = -1 - ,const wxPoint& pos = wxDefaultPosition - ,const wxSize& size = wxDefaultSize - ,long style = wxSP_VERTICAL - ,const wxString& name = "wxSpinButton" + inline wxSpinButton( wxWindow* pParent + ,wxWindowID vId = -1 + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxSP_VERTICAL + ,const wxString& rsName = "wxSpinButton" ) { - Create(parent, id, pos, size, style, name); + Create(pParent, vId, rPos, rSize, lStyle, rsName); } - virtual ~wxSpinButton(); - bool Create( wxWindow *parent - ,wxWindowID id = -1 - ,const wxPoint& pos = wxDefaultPosition - ,const wxSize& size = wxDefaultSize - ,long style = wxSP_VERTICAL - ,const wxString& name = "wxSpinButton" + + bool Create( wxWindow* pParent + ,wxWindowID vId = -1 + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxSP_VERTICAL + ,const wxString& rsName = "wxSpinButton" ); // Accessors - virtual int GetValue() const ; - virtual void SetValue(int val) ; - virtual void SetRange( int minVal - ,int maxVal - ); + inline virtual int GetMax(void) const { return m_max; } + inline virtual int GetMin(void) const { return m_min; } + virtual int GetValue(void) const; + inline bool IsVertical(void) const {return ((m_windowStyle & wxSP_VERTICAL) != 0); } + virtual void SetValue(int nVal); + virtual void SetRange( int nMinVal + ,int nMaxVal + ); + // // Implementation - virtual bool OS2Command( WXUINT param - ,WXWORD id + // + virtual bool OS2Command( WXUINT wParam + ,WXWORD wId ); - virtual bool OS2OnNotify( int idCtrl - ,WXLPARAM lParam - ,WXLPARAM* result - ); - virtual bool OS2OnScroll( int orientation + virtual bool OS2OnScroll( int nOrientation ,WXWORD wParam - ,WXWORD pos - ,WXHWND control + ,WXWORD wPos + ,WXHWND hControl ); + inline virtual bool AcceptsFocus(void) const { return FALSE; } protected: - virtual wxSize DoGetBestSize() const; + virtual wxSize DoGetBestSize() const; private: DECLARE_DYNAMIC_CLASS(wxSpinButton) -}; -#endif - // _WX_SPINBUTT_H_ +}; // end of CLASS wxSpinButton + +#endif // _WX_SPINBUTT_H_ diff --git a/include/wx/os2/spinctrl.h b/include/wx/os2/spinctrl.h index 7423d7e2aa..4c39c123c7 100644 --- a/include/wx/os2/spinctrl.h +++ b/include/wx/os2/spinctrl.h @@ -13,6 +13,9 @@ #define _WX_MSW_SPINCTRL_H_ #include "wx/spinbutt.h" // the base class +#include "wx/dynarray.h" +class WXDLLEXPORT wxSpinCtrl; +WX_DEFINE_EXPORTED_ARRAY(wxSpinCtrl *, wxArraySpins); // ---------------------------------------------------------------------------- // Under Win32 and OS2 PM, wxSpinCtrl is a wxSpinButton with a buddy @@ -24,55 +27,99 @@ class WXDLLEXPORT wxSpinCtrl : public wxSpinButton { public: wxSpinCtrl() { } - - wxSpinCtrl(wxWindow *parent, - wxWindowID id = -1, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, - int min = 0, int max = 100, int initial = 0, - const wxString& name = _T("wxSpinCtrl")) + wxSpinCtrl( wxWindow* pParent + ,wxWindowID vId = -1 + ,const wxString& rsValue = wxEmptyString + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxSP_ARROW_KEYS + ,int nMin = 0 + ,int nMax = 100 + ,int nInitial = 0 + ,const wxString& rsName = _T("wxSpinCtrl") + ) { - Create(parent, id, value, pos, size, style, min, max, initial, name); + Create(pParent, vId, rsValue, rPos, rSize, lStyle, nMin, nMax, nInitial, rsName); } - - bool Create(wxWindow *parent, - wxWindowID id = -1, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSP_ARROW_KEYS, - int min = 0, int max = 100, int initial = 0, - const wxString& name = _T("wxSpinCtrl")); - - // a wxTextCtrl-like method (but we can't have GetValue returning wxString + virtual ~wxSpinCtrl(); + + bool Create(wxWindow* pParent + ,wxWindowID vId = -1 + ,const wxString& rsValue = wxEmptyString + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxSP_ARROW_KEYS + ,int nMin = 0 + ,int nMax = 100 + ,int nInitial = 0 + ,const wxString& rsName = _T("wxSpinCtrl") + ); + + // + // A wxTextCtrl-like method (but we can't have GetValue returning wxString // because the base class already has one returning int!) - void SetValue(const wxString& text); + // + void SetValue(const wxString& rsText); + // // implementation only from now on // ------------------------------- + // + virtual bool Enable(bool bEnable = TRUE); - virtual void SetValue(int val) { wxSpinButton::SetValue(val); } - virtual int GetValue() const; - virtual bool SetFont(const wxFont &font); + virtual int GetValue(void) const; - virtual bool Enable(bool enable = TRUE); - virtual bool Show(bool show = TRUE); -protected: - void DoMoveWindow(int x, int y, int width, int height); + virtual bool SetFont(const wxFont &rFont); + virtual void SetFocus(void); + inline virtual void SetValue(int nVal) { wxSpinButton::SetValue(nVal); } - virtual wxSize DoGetBestSize() const; + virtual bool Show(bool bShow = TRUE); - // the handler for wxSpinButton events - void OnSpinChange(wxSpinEvent& event); + // + // wxSpinButton doesn't accept focus, but we do + // + inline virtual bool AcceptsFocus(void) const { return FALSE; } - WXHWND m_hwndBuddy; + // + // Return the spinctrl object whose buddy is the given window or NULL + // Doesn't really do much under OS/2 + // + static wxSpinCtrl* GetSpinForTextCtrl(WXHWND hWndBuddy); + + // + // Process a WM_COMMAND generated by the buddy text control + // + bool ProcessTextCommand( WXWORD wCmd + ,WXWORD wId + ); + +protected: + virtual void DoGetPosition( int* nlX + ,int* nlY + ) const; + void DoMoveWindow( int nX + ,int nY + ,int nWidth + ,int nHeight + ); + virtual wxSize DoGetBestSize(void) const; + virtual void DoGetSize( int* pnWidth + ,int* pnHeight + ) const; + + // + // The handler for wxSpinButton events + // + void OnSpinChange(wxSpinEvent& rEvent); + void OnChar(wxKeyEvent& rEvent); + + WXHWND m_hWndBuddy; + static wxArraySpins m_svAllSpins; private: DECLARE_DYNAMIC_CLASS(wxSpinCtrl) DECLARE_EVENT_TABLE() -}; +}; // end of CLASS wxSpinCtrl #endif // _WX_MSW_SPINCTRL_H_ diff --git a/include/wx/os2/statbmp.h b/include/wx/os2/statbmp.h index 116e25034d..bc7d4e58fc 100644 --- a/include/wx/os2/statbmp.h +++ b/include/wx/os2/statbmp.h @@ -60,6 +60,10 @@ class WXDLLEXPORT wxStaticBitmap : public wxStaticBitmapBase // overriden base class virtuals virtual bool AcceptsFocus() const { return FALSE; } + virtual MRESULT OS2WindowProc( WXUINT uMsg + ,WXWPARAM wParam + ,WXLPARAM lParam + ); protected: virtual wxSize DoGetBestSize() const; @@ -77,7 +81,7 @@ protected: wxGDIImage* m_pImage; private: DECLARE_DYNAMIC_CLASS(wxStaticBitmap) -}; +}; // end of wxStaticBitmap #endif // _WX_STATBMP_H_ diff --git a/include/wx/os2/statbox.h b/include/wx/os2/statbox.h index df6122aeb9..1b4fface6e 100644 --- a/include/wx/os2/statbox.h +++ b/include/wx/os2/statbox.h @@ -19,50 +19,49 @@ WXDLLEXPORT_DATA(extern const char*) wxStaticBoxNameStr; // Group box class WXDLLEXPORT wxStaticBox : public wxStaticBoxBase { - DECLARE_DYNAMIC_CLASS(wxStaticBox) - - public: +public: inline wxStaticBox() {} - inline wxStaticBox( wxWindow* parent - ,wxWindowID id - ,const wxString& label - ,const wxPoint& pos = wxDefaultPosition - ,const wxSize& size = wxDefaultSize - ,long style = 0 - ,const wxString& name = wxStaticBoxNameStr + inline wxStaticBox( wxWindow* pParent + ,wxWindowID vId + ,const wxString& rsLabel + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = 0 + ,const wxString& rsName = wxStaticBoxNameStr ) { - Create(parent, id, label, pos, size, style, name); + Create(pParent, vId, rsLabel, rPos, rSize, lStyle, rsName); } - bool Create( wxWindow* parent - ,wxWindowID id - ,const wxString& label - ,const wxPoint& pos = wxDefaultPosition - ,const wxSize& size = wxDefaultSize - ,long style = 0 - ,const wxString& name = wxStaticBoxNameStr - ); + bool Create( wxWindow* pParent + ,wxWindowID vId + ,const wxString& rsLabel + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = 0 + ,const wxString& rsName = wxStaticBoxNameStr + ); + // // implementation from now on // -------------------------- + // + virtual MRESULT OS2WindowProc( WXUINT uMsg + ,WXWPARAM wParam + ,WXLPARAM lParam + ); - void OnEraseBackground(wxEraseEvent& event); - - virtual MRESULT OS2WindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); - - virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - + // // overriden base class virtuals - virtual bool AcceptsFocus() const { return FALSE; } + // + inline virtual bool AcceptsFocus(void) const { return FALSE; } protected: - virtual wxSize DoGetBestSize() const; + virtual wxSize DoGetBestSize(void) const; private: - DECLARE_EVENT_TABLE() -}; + DECLARE_DYNAMIC_CLASS(wxStaticBox) +}; // end of CLASS wxStaticBox #endif // _WX_STATBOX_H_ diff --git a/include/wx/os2/statline.h b/include/wx/os2/statline.h index ccab4479ed..a0142e87b6 100644 --- a/include/wx/os2/statline.h +++ b/include/wx/os2/statline.h @@ -21,29 +21,62 @@ class WXDLLEXPORT wxStaticLine : public wxStaticLineBase { - DECLARE_DYNAMIC_CLASS(wxStaticLine) public: // constructors and pseudo-constructors wxStaticLine() { } + wxStaticLine( wxWindow* pParent + ,wxWindowID vId + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxLI_HORIZONTAL + ,const wxString& rsName = wxStaticTextNameStr + ) + { + Create(pParent, vId, rPos, rSize, lStyle, rsName); + } + + bool Create( wxWindow* pParent + ,wxWindowID vId + ,const wxPoint& rPos = wxDefaultPosition + ,const wxSize& rSize = wxDefaultSize + ,long lStyle = wxLI_HORIZONTAL + ,const wxString& rsName = wxStaticTextNameStr + ); + + inline bool IsVertical(void) const { return((GetWindowStyleFlag() & wxLI_VERTICAL) != 0); } + inline static int GetDefaultSize(void) { return 2; } - wxStaticLine( wxWindow *parent, - wxWindowID id, - const wxPoint &pos = wxDefaultPosition, - const wxSize &size = wxDefaultSize, - long style = wxLI_HORIZONTAL, - const wxString &name = wxStaticTextNameStr ) + // + // Overriden base class virtuals + // + inline virtual bool AcceptsFocus(void) const {return FALSE;} + +protected: + inline wxSize AdjustSize(const wxSize& rSize) const { - Create(parent, id, pos, size, style, name); + wxSize vSizeReal( rSize.x + ,rSize.y + ); + + if (IsVertical()) + { + if (rSize.x == -1 ) + vSizeReal.x = GetDefaultSize(); + } + else + { + if (rSize.y == -1) + vSizeReal.y = GetDefaultSize(); + } + return vSizeReal; } - bool Create( wxWindow *parent, - wxWindowID id, - const wxPoint &pos = wxDefaultPosition, - const wxSize &size = wxDefaultSize, - long style = wxLI_HORIZONTAL, - const wxString &name = wxStaticTextNameStr ); -}; + inline wxSize DoGetBestSize(void) const { return (AdjustSize(wxDefaultSize)); } + +private: + DECLARE_DYNAMIC_CLASS(wxStaticLine) +}; // end of CLASS wxStaticLine #endif // _WX_OS2_STATLINE_H_ diff --git a/include/wx/os2/stattext.h b/include/wx/os2/stattext.h index 56fe3b63d8..66da229103 100644 --- a/include/wx/os2/stattext.h +++ b/include/wx/os2/stattext.h @@ -22,11 +22,8 @@ WXDLLEXPORT_DATA(extern const char*) wxStaticTextNameStr; class WXDLLEXPORT wxStaticText : public wxControl { - DECLARE_DYNAMIC_CLASS(wxStaticText) - - public: +public: inline wxStaticText() { } - inline wxStaticText( wxWindow* pParent ,wxWindowID vId ,const wxString& rsLabel @@ -69,6 +66,9 @@ class WXDLLEXPORT wxStaticText : public wxControl protected: virtual wxSize DoGetBestSize(void) const; + +private: + DECLARE_DYNAMIC_CLASS(wxStaticText) }; // end of CLASS wxStaticText #endif diff --git a/src/os2/control.cpp b/src/os2/control.cpp index 0d6acde226..35551cb4b4 100644 --- a/src/os2/control.cpp +++ b/src/os2/control.cpp @@ -134,6 +134,8 @@ bool wxControl::OS2CreateControl( if ((strcmp(zClassname, "COMBOBOX")) == 0) zClass = WC_COMBOBOX; + else if ((strcmp(zClassname, "STATIC")) == 0) + zClass = WC_STATIC; dwStyle |= WS_VISIBLE; m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(GetParent()) // Parent window handle ,(PSZ)zClassname // Window class diff --git a/src/os2/gauge.cpp b/src/os2/gauge.cpp index 620760fd5f..b227ebf692 100644 --- a/src/os2/gauge.cpp +++ b/src/os2/gauge.cpp @@ -19,1133 +19,257 @@ #include "wx/os2/private.h" #include "wx/gauge.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 _Optlink gaugeInit(HINSTANCE hInstance); +static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL; +extern void wxAssociateWinWithHandle( HWND hWnd + ,wxWindowOS2* pWin + ); IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) -bool wxGauge::Create(wxWindow *parent, wxWindowID id, - int range, - const wxPoint& pos, - const wxSize& size, - long style, -#if wxUSE_VALIDATORS - const wxValidator& validator, -#endif - const wxString& name) +MRESULT EXPENTRY wxGaugeWndProc( + HWND hWnd +, UINT uMessage +, MPARAM wParam +, MPARAM lParam +) { - static bool wxGaugeOS2Initialised = FALSE; - - if ( !wxGaugeOS2Initialised ) + wxGauge* pGauge = (wxGauge *)::WinQueryWindowULong( hWnd + ,QWL_USER + ); + wxWindowOS2* pWindow = NULL; + MRESULT rc = (MRESULT)0; + bool bProcessed = FALSE; + HPS hPS; + RECTL vRect; + RECTL vRect2; + double dPixelToRange = 0.0; + double dRange = 0.0; + + switch (uMessage ) { -//TODO: -/* - if (!gaugeInit((HINSTANCE) wxGetInstance())) - wxFatalError("Cannot initalize Gauge library"); -*/ - wxGaugeOS2Initialised = TRUE; + case WM_PAINT: + hPS = ::WinBeginPaint( hWnd + ,NULLHANDLE + ,&vRect + ); + if(hPS) + { + ::WinQueryWindowRect(hWnd, &vRect); + ::GpiCreateLogColorTable( hPS + ,0L + ,LCOLF_CONSECRGB + ,0L + ,(LONG)wxTheColourDatabase->m_nSize + ,(PLONG)wxTheColourDatabase->m_palTable + ); + ::GpiCreateLogColorTable( hPS + ,0L + ,LCOLF_RGB + ,0L + ,0L + ,NULL + ); + if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL) + { + dRange = (double)(vRect.yTop - vRect.yBottom); + dPixelToRange = dRange/(double)pGauge->GetRange(); + vRect2.yTop = (int)(pGauge->GetValue() * dPixelToRange); + vRect2.yBottom = vRect.yBottom; + vRect2.xLeft = vRect.xLeft; + vRect2.xRight = vRect.xRight; + vRect.yBottom = vRect2.yTop; + ::WinFillRect(hPS, &vRect, pGauge->GetBackgroundColour().GetPixel()); + ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel()); + } + else + { + dRange = (double)(vRect.xRight - vRect.xLeft); + dPixelToRange = dRange/(double)pGauge->GetRange(); + vRect2.yTop = vRect.yTop; + vRect2.yBottom = vRect.yBottom; + vRect2.xLeft = vRect.xLeft; + vRect2.xRight = (int)(pGauge->GetValue() * dPixelToRange); + vRect.xLeft = vRect2.xRight; + ::WinFillRect(hPS, &vRect, pGauge->GetBackgroundColour().GetPixel()); + ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel()); + } + ::WinEndPaint(hPS); + } } + return (fnWndProcGauge( hWnd + ,(ULONG)uMessage + ,(MPARAM)wParam + ,(MPARAM)lParam + ) + ); +} // end of wxGaugeWndProc + +bool wxGauge::Create( + wxWindowOS2* pParent +, wxWindowID vId +, int nRange +, const wxPoint& rPos +, const wxSize& rSize +, long lStyle +#if wxUSE_VALIDATORS +, const wxValidator& rValidator +#endif +, const wxString& rsName +) +{ + int nX = rPos.x; + int nY = rPos.y; + int nWidth = rSize.x; + int nHeight = rSize.y; + long lMsStyle = 0L; - SetName(name); + SetName(rsName); #if wxUSE_VALIDATORS - SetValidator(validator); + SetValidator(rValidator); #endif - if (parent) parent->AddChild(this); - m_rangeMax = range; - m_gaugePos = 0; + if (pParent) + pParent->AddChild(this); + SetBackgroundColour(pParent->GetBackgroundColour()) ; + SetForegroundColour(pParent->GetForegroundColour()) ; - m_windowStyle = style; + m_nRangeMax = nRange; + m_nGaugePos = 0; + m_windowStyle = lStyle; - if ( id == -1 ) - m_windowId = (int)NewControlId(); + if (vId == -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; - - // TODO -/* - 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), wxT("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(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); - SendMessage(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(GetHwnd(), SW_SHOW); -*/ - return TRUE; -} - -void wxGauge::SetShadowWidth(int w) -{ - // TODO optional ::SendMessage(GetHwnd(), ZYZG_SETWIDTH3D, w, 0); -} - -void wxGauge::SetBezelFace(int w) -{ - // TODO optional ::SendMessage(GetHwnd(), ZYZG_SETBEZELFACE, w, 0); -} + m_windowId = vId; + + if (m_windowStyle & wxCLIP_SIBLINGS ) + lMsStyle |= WS_CLIPSIBLINGS; + + // + // OS/2 will use an edit control for this, since there is not a native gauge + // Other choices include using an armless slider but they are more difficult + // to control and manipulate + // + + lMsStyle = WS_VISIBLE | ES_MARGIN | ES_LEFT | ES_READONLY; + if (m_windowStyle & wxCLIP_SIBLINGS) + lMsStyle |= WS_CLIPSIBLINGS; + + + + m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle + ,WC_ENTRYFIELD // Window class + ,(PSZ)NULL // Initial Text + ,(ULONG)lMsStyle // Style flags + ,0L, 0L, 0L, 0L // Origin -- 0 size + ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent + ,HWND_TOP // initial z position + ,(HMENU)m_windowId // Window identifier + ,NULL // Slider control data + ,NULL // no Presentation parameters + ); + + wxAssociateWinWithHandle( m_hWnd + ,(wxWindowOS2*)this + ); + ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this); + fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc); + SetFont(pParent->GetFont()); + if (nWidth == -1L) + nWidth = 50L; + if (nHeight == -1L) + nHeight = 28L; + SetSize( nX + ,nY + ,nWidth + ,nHeight + ); + ::WinShowWindow((HWND)GetHWND(), TRUE); + return TRUE; +} // end of wxGauge::Create -void wxGauge::SetRange(int r) +int wxGauge::GetBezelFace() const { - m_rangeMax = r; - // TODO ::SendMessage(GetHwnd(), ZYZG_SETRANGE, r, 0); -} + return 0; +} // end of wxGauge::GetBezelFace -void wxGauge::SetValue(int pos) +int wxGauge::GetRange() const { - m_gaugePos = pos; - // TODO ::SendMessage(GetHwnd(), ZYZG_SETPOSITION, pos, 0); -} + return m_nRangeMax; +} // end of wxGauge::GetRange int wxGauge::GetShadowWidth() const { - // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETWIDTH3D, 0, 0); return 0; -} - -int wxGauge::GetBezelFace() const -{ - // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETBEZELFACE, 0, 0); - return 0; -} - -int wxGauge::GetRange() const -{ - // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETRANGE, 0, 0); - return m_rangeMax; -} +} // end of wxGauge::GetShadowWidth int wxGauge::GetValue() const { - // TODO return (int) ::SendMessage(GetHwnd(), ZYZG_GETPOSITION, 0, 0); - return m_gaugePos; -} + return m_nGaugePos; +} // end of wxGauge::GetValue -bool wxGauge::SetForegroundColour(const wxColour& col) +bool wxGauge::SetBackgroundColour( + const wxColour& rColour +) { - if ( !wxControl::SetForegroundColour(col) ) + if (!wxControl::SetBackgroundColour(rColour)) return FALSE; - // TODO ::SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); + LONG lColor = (LONG)rColour.GetPixel(); + ::WinSetPresParam( GetHwnd() + ,PP_BACKGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); return TRUE; -} +} // end of wxGauge::SetBackgroundColour -bool wxGauge::SetBackgroundColour(const wxColour& col) +void wxGauge::SetBezelFace( + int WXUNUSED(nWidth) +) { - if ( !wxControl::SetBackgroundColour(col) ) - return FALSE; - - // TODO ::SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); - - return TRUE; -} - -///** 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 */ -//#define INCL_PM -//#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 _Optlink Draw3DFaceFrame(HDC, LPRECT, WORD); -//void _Optlink Draw3DRect(HDC, LPRECT, WORD, WORD); -//void _Optlink Draw3DLine(HDC, WORD, WORD, WORD, WORD, WORD); - - -///** void _Optlink 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 _Optlink): -// * The frame will have been drawn into the DC. -// * -// * NOTES: -// * -// ** cjp */ - -//void _Optlink Draw3DFaceFrame(HDC hdc, RECTL* rc, WORD wWidth) -//{ -// RECTL 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 _Optlink 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 _Optlink): -// * The 3D looking rectangle will have been drawn into the DC. -// * -// * NOTES: -// * -// ** cjp */ - -//void _Optlink 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 _Optlink 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 _Optlink): -// * The line will have been drawn into the DC. -// * -// * NOTES: -// * -// ** cjp */ - -//void _Optlink 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 = (HPEN) SelectObject(hdc, GetStockObject(NULL_PEN)); - - /* select the appropriate color for the fill */ -// if (fDark) -// hOldBrush = (HBRUSH) SelectObject(hdc, GetStockObject(GRAY_BRUSH)); -// else -// hOldBrush = (HBRUSH) 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 */ -//#if !defined(__GNUWIN32__) && !defined(__SALFORDC__) -//#include -//#endif -//#include -//#include -//#include -// #include "zyz3d.h" -// #include "zyzgauge.h" +} // end of wxGauge::SetBezelFace +bool wxGauge::SetForegroundColour( + const wxColour& rColour +) +{ + if (!wxControl::SetForegroundColour(rColour)) + return FALSE; -/* static global variables */ -//static wxChar gszzYzGaugeClass[] = wxT("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 _Optlink -//#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 _Optlink */ -//LRESULT APIENTRY _EXPORT gaugeWndProc(HWND, UINT, WPARAM, LPARAM); - - - -///** BOOL _Optlink 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 _Optlink 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. - */ -// hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0L) ; -// if (hdc) -// { - /* 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; -// wxChar 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, (HBRUSH) 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, (HBRUSH) 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 = (HFONT) SelectObject(hdc, pgauge->hFont); - - /* build up a string to blit out--ie the meaning of life: "42%" */ -// wsprintf(ach, wxT("%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 _Optlink 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 _Optlink */ - -//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); + LONG lColor = (LONG)rColour.GetPixel(); -// case WM_SETFONT: - /* if NULL hFont, use system font */ -// hFont = (HFONT)wParam ; -// if (!hFont) -// hFont = (HFONT) GetStockObject(SYSTEM_FONT); + ::WinSetPresParam( GetHwnd() + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); -// pgauge->hFont = hFont; + return TRUE; +} // end of wxGauge::SetForegroundColour - /* redraw if indicated in message */ -// if ((BOOL)lParam) -// { -// InvalidateRect(hwnd, NULL, TRUE); -// UpdateWindow(hwnd); -// } -// return (0L); -// } /* switch () */ +void wxGauge::SetRange( + int nRange +) +{ + m_nRangeMax = nRange; +} // end of wxGauge::SetRange - /* let the dialog mangler take care of this message */ -// return (DefWindowProc(hwnd, uMsg, wParam, lParam)); -//} /* gaugeWndProc() */ +void wxGauge::SetShadowWidth( + int WXUNUSED(nWidth) +) +{ +} // end of wxGauge::SetShadowWidth +void wxGauge::SetValue( + int nPos +) +{ + RECT vRect; -/** EOF: zyzgauge.c **/ + m_nGaugePos = nPos; + ::WinQueryWindowRect(GetHwnd(), &vRect); + ::WinInvalidateRect(GetHwnd(), &vRect, FALSE); +} // end of wxGauge::SetValue diff --git a/src/os2/radiobox.cpp b/src/os2/radiobox.cpp index cf31c122fb..47a6fbdd9c 100644 --- a/src/os2/radiobox.cpp +++ b/src/os2/radiobox.cpp @@ -31,17 +31,18 @@ IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) // --------------------------------------------------------------------------- // wnd proc for radio buttons -MRESULT wxRadioBtnWndProc(HWND hWnd, - UINT message, - MPARAM wParam, - MPARAM lParam); +MRESULT EXPENTRY wxRadioBtnWndProc( HWND hWnd + ,UINT uMessage + ,MPARAM wParam + ,MPARAM lParam + ); // --------------------------------------------------------------------------- // global vars // --------------------------------------------------------------------------- // the pointer to standard radio button wnd proc -static s_wndprocRadioBtn = NULL; +static WXFARPROC fnWndProcRadioBtn = NULL; // =========================================================================== // implementation @@ -51,749 +52,1131 @@ static s_wndprocRadioBtn = NULL; // wxRadioBox // --------------------------------------------------------------------------- -int wxRadioBox::GetCount() const -{ - return m_noItems; -} - -int wxRadioBox::GetColumnCount() const +// Radio box item +wxRadioBox::wxRadioBox() { - return GetNumHor(); -} + m_nSelectedButton = -1; + m_nNoItems = 0; + m_nNoRowsOrCols = 0; + m_ahRadioButtons = NULL; + m_nMajorDim = 0; + m_pnRadioWidth = NULL; + m_pnRadioHeight = NULL; +} // end of wxRadioBox::wxRadioBox -int wxRadioBox::GetRowCount() const +wxRadioBox::~wxRadioBox() { - return GetNumVer(); -} + m_isBeingDeleted = TRUE; -int wxRadioBox::GetNumVer() const -{ - if ( m_windowStyle & wxRA_SPECIFY_ROWS ) + if (m_ahRadioButtons) { - return m_majorDim; + int i; + for (i = 0; i < m_nNoItems; i++) + ::WinDestroyWindow((HWND)m_ahRadioButtons[i]); + delete[] m_ahRadioButtons; } - else - { - return (m_noItems + m_majorDim - 1)/m_majorDim; - } -} - -int wxRadioBox::GetNumHor() const + if (m_pnRadioWidth) + delete[] m_pnRadioWidth; + if (m_pnRadioHeight) + delete[] m_pnRadioHeight; +} // end of wxRadioBox::~wxRadioBox + +void wxRadioBox::AdjustButtons( + int nX +, int nY +, int nWidth +, int nHeight +, long lSizeFlags +) { - if ( m_windowStyle & wxRA_SPECIFY_ROWS ) - { - return (m_noItems + m_majorDim - 1)/m_majorDim; - } - else + wxSize vMaxSize; + int nXOffset = nX; + int nYOffset = nY + nHeight; + int nCx1; + int nCy1; + int nStartX; + int nStartY; + int nMaxWidth; + int nMaxHeight; + int nTotWidth; + int nTotHeight; + + wxGetCharSize( m_hWnd + ,&nCx1 + ,&nCy1 + ,&GetFont() + ); + vMaxSize = GetMaxButtonSize(); + nMaxWidth = vMaxSize.x; + nMaxHeight = vMaxSize.y; + + nXOffset += nCx1; + nYOffset -= (nMaxHeight + ((3*nCy1)/2)); + + nStartX = nXOffset; + nStartY = nYOffset; + + for (int i = 0; i < m_nNoItems; i++) { - return m_majorDim; - } -} + // + // The last button in the row may be wider than the other ones as the + // radiobox may be wider than the sum of the button widths (as it + // happens, for example, when the radiobox label is very long) + // + bool bIsLastInTheRow; + + if (m_windowStyle & wxRA_SPECIFY_COLS) + { + // + // Item is the last in its row if it is a multiple of the number of + // columns or if it is just the last item + // + int n = i + 1; -bool wxRadioBox::OS2Command(WXUINT cmd, WXWORD id) -{ -// TODO: -/* - if ( cmd == BN_CLICKED ) - { - int selectedButton = -1; + bIsLastInTheRow = ((n % m_nMajorDim) == 0) || (n == m_nNoItems); + } + else // winRA_SPECIFY_ROWS + { + // + // Item is the last in the row if it is in the last columns + // + bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim; + } - for ( int i = 0; i < m_noItems; i++ ) + // + // Is this the start of new row/column? + // + if (i && (i % m_nMajorDim == 0)) { - if ( id == wxGetWindowId(m_radioButtons[i]) ) + if (m_windowStyle & wxRA_SPECIFY_ROWS) { - selectedButton = i; - break; + // + // Start of new column + // + nYOffset = nStartY; + nXOffset += nMaxWidth + nCx1; + } + else // start of new row + { + nXOffset = nStartX; + nYOffset -= nMaxHeight; + if (m_pnRadioWidth[0] > 0L) + nYOffset -= nCy1/2; } } - wxASSERT_MSG( selectedButton != -1, wxT("click from alien button?") ); + int nWidthBtn; - if ( selectedButton != m_selectedButton ) + if (bIsLastInTheRow) { - m_selectedButton = selectedButton; - - SendNotificationEvent(); + // + // Make the button go to the end of radio box + // + nWidthBtn = nStartX + nWidth - nXOffset - (2 * nCx1); + if (nWidthBtn < nMaxWidth) + nWidthBtn = nMaxWidth; + } + else + { + // + // Normal button, always of the same size + // + nWidthBtn = nMaxWidth; } - //else: don't generate events when the selection doesn't change - return TRUE; + // + // Make all buttons of the same, maximal size - like this they + // cover the radiobox entirely and the radiobox tooltips are always + // shown (otherwise they are not when the mouse pointer is in the + // radiobox part not beYInt32ing to any radiobutton) + // + ::WinSetWindowPos( (HWND)m_ahRadioButtons[i] + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset + ,(LONG)nWidthBtn + ,(LONG)nMaxHeight + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + // + // Where do we put the next button? + // + if (m_windowStyle & wxRA_SPECIFY_ROWS) + { + // + // Below this one + // + nYOffset -= nMaxHeight; + if (m_pnRadioWidth[0] > 0) + nYOffset -= nCy1/2; + } + else + { + // + // To the right of this one + // + nXOffset += nWidthBtn + nCx1; + } } - else - return FALSE; -*/ - return FALSE; -} - -#if WXWIN_COMPATIBILITY -wxRadioBox::wxRadioBox(wxWindow *parent, wxFunction func, const char *title, - int x, int y, int width, int height, - int n, char **choices, - int majorDim, long style, const char *name) -{ - wxString *choices2 = new wxString[n]; - for ( int i = 0; i < n; i ++) choices2[i] = choices[i]; - Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), n, choices2, majorDim, style, - wxDefaultValidator, name); - Callback(func); - delete choices2; -} +} // end of wxRadioBox::AdjustButtons -#endif +void wxRadioBox::Command ( + wxCommandEvent& rEvent +) +{ + SetSelection (rEvent.GetInt()); + ProcessCommand(rEvent); +} // end of wxRadioBox::Command -// Radio box item -wxRadioBox::wxRadioBox() +bool wxRadioBox::ContainsHWND( + WXHWND hWnd +) const { - m_selectedButton = -1; - m_noItems = 0; - m_noRowsOrCols = 0; - m_radioButtons = NULL; - m_majorDim = 0; - m_radioWidth = NULL; - m_radioHeight = NULL; -} - -bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, - int n, const wxString choices[], - int majorDim, long style, + size_t nCount = GetCount(); + size_t i; + + for (i = 0; i < nCount; i++) + { + if (GetRadioButtons()[i] == hWnd) + return TRUE; + } + return FALSE; +} // end of wxRadioBox::ContainsHWND + +bool wxRadioBox::Create( + wxWindow* pParent +, wxWindowID vId +, const wxString& rsTitle +, const wxPoint& rPos +, const wxSize& rSize +, int nNum +, const wxString asChoices[] +, int nMajorDim +, long lStyle #if wxUSE_VALIDATORS - const wxValidator& val, const wxString& name) +, const wxValidator& rVal #endif +, const wxString& rsName +) { - m_selectedButton = -1; - m_noItems = n; - - SetName(name); + // + // System fonts are too big in OS/2 and they are blue + // We want smaller fonts and black by default. + // + wxFont& rFont = *wxSMALL_FONT; + wxColour vColour; + LONG lColor; + + vColour.Set(wxString("BLACK")); + lColor = (LONG)vColour.GetPixel(); + m_nSelectedButton = -1; + m_nNoItems = nNum; + + m_nMajorDim = nMajorDim == 0 ? nNum : nMajorDim; + m_nNoRowsOrCols = nMajorDim; + + // + // Common initialization + // + if (!OS2CreateControl( pParent + ,vId + ,rPos + ,rSize + ,lStyle #if wxUSE_VALIDATORS - SetValidator(val); + ,rVal #endif - parent->AddChild(this); - m_backgroundColour = parent->GetBackgroundColour(); - m_foregroundColour = parent->GetForegroundColour(); + ,rsName + )) - m_windowStyle = (long&)style; - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; - if (id == -1) - m_windowId = NewControlId(); - else - m_windowId = id; - if ( majorDim == 0 ) - m_majorDim = n; - else - m_majorDim = majorDim; - m_noRowsOrCols = majorDim; - - long msStyle = 0; // TODO: GROUP_FLAGS; - - bool want3D; - WXDWORD exStyle = Determine3DEffects(0, &want3D); - - HWND hwndParent = (HWND)parent->GetHWND(); -/* - m_hWnd = (WXHWND)::CreateWindowEx - ( - (DWORD)exStyle, - GROUP_CLASS, - title, - msStyle, - 0, 0, 0, 0, - hwndParent, - (HMENU)m_windowId, - wxGetInstance(), - NULL - ); - -#if wxUSE_CTL3D - if (want3D) - { - Ctl3dSubclassCtl((HWND)m_hWnd); - m_useCtl3D = TRUE; - } -#endif // wxUSE_CTL3D -*/ - SetFont(parent->GetFont()); + if (!OS2CreateControl( "STATIC" + ,SS_GROUPBOX | WS_GROUP + ,rPos + ,rSize + ,rsTitle + )) - SubclassWin(m_hWnd); +#if RADIOBTN_PARENT_IS_RADIOBOX + HWND hWndParent = GetHwnd(); +#else + HWND hWndParent = GetHwndOf(pParent); +#endif + HFONT hFont; + // // Some radio boxes test consecutive id. + // (void)NewControlId(); - m_radioButtons = new WXHWND[n]; - m_radioWidth = new int[n]; - m_radioHeight = new int[n]; - int i; - for (i = 0; i < n; i++) + m_ahRadioButtons = new WXHWND[nNum]; + m_pnRadioWidth = new int[nNum]; + m_pnRadioHeight = new int[nNum]; + + if (rFont.Ok()) + { + hFont = rFont.GetResourceHandle(); + } + + for (int i = 0; i < nNum; i++) { -// TODO: -/* - m_radioWidth[i] = m_radioHeight[i] = -1; - long groupStyle = 0; - if ( i == 0 && style == 0 ) - groupStyle = WS_GROUP; - long newId = NewControlId(); - long msStyle = groupStyle | RADIO_FLAGS; - - HWND hwndBtn = CreateWindowEx(exStyle, RADIO_CLASS, - choices[i], msStyle, - 0,0,0,0, - hwndParent, - (HMENU)newId, wxGetInstance(), - NULL); - - m_radioButtons[i] = (WXHWND)hwndBtn; - - SubclassRadioButton((WXHWND)hwndBtn); - - wxFont& font = GetFont(); - if ( font.Ok() ) + m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1; + + long lStyleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE; + int nNewId = NewControlId(); + + if (i == 0 && lStyle == 0) + lStyleBtn |= WS_GROUP; + + HWND hWndBtn = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent) + ,WC_BUTTON + ,asChoices[i] + ,lStyleBtn + ,0, 0, 0, 0 + ,GetWinHwnd(pParent) + ,HWND_TOP + ,(HMENU)nNewId + ,NULL + ,NULL + ); + ::WinSetPresParam( hWndBtn + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); + if (!hWndBtn) { - SendMessage(hwndBtn, WM_SETFONT, - (WPARAM)font.GetResourceHandle(), 0L); + return FALSE; } - - m_subControls.Append((wxObject *)(WXDWORD)(WXWORD)newId); -*/ + m_ahRadioButtons[i] = (WXHWND)hWndBtn; + SubclassRadioButton((WXHWND)hWndBtn); + wxOS2SetFont( hWndBtn + ,rFont + ); + ::WinSetWindowULong(hWndBtn, QWL_USER, (ULONG)this); + m_aSubControls.Add(nNewId); } + // // Create a dummy radio control to end the group. -// (void)CreateWindowEx(0, RADIO_CLASS, wxT(""), WS_GROUP | RADIO_FLAGS, -// 0, 0, 0, 0, hwndParent, -// (HMENU)NewControlId(), wxGetInstance(), NULL); - + // + (void)::WinCreateWindow ( GetHwndOf(pParent) + ,WC_BUTTON + ,"" + ,WS_GROUP | BS_AUTORADIOBUTTON + ,0, 0, 0, 0 + ,GetWinHwnd(pParent) + ,HWND_TOP + ,(HMENU)NewControlId() + ,NULL + ,NULL + ); + SetFont(*wxSMALL_FONT); + ::WinSetPresParam( m_hWnd + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); SetSelection(0); - - SetSize(x, y, width, height); - + SetSize( rPos.x + ,rPos.y + ,rSize.x + ,rSize.y + ); return TRUE; -} +} // end of wxRadioBox::Create -wxRadioBox::~wxRadioBox() +wxSize wxRadioBox::DoGetBestSize() const { - m_isBeingDeleted = TRUE; + return (GetTotalButtonSize(GetMaxButtonSize())); +} // end of WinGuiBase_CRadioBox::DoGetBestSize + +void wxRadioBox::DoSetSize( + int nX +, int nY +, int nWidth +, int nHeight +, int nSizeFlags +) +{ + int nCurrentX; + int nCurrentY; + int nWidthOld; + int nHeightOld; + int nXx = nX; + int nYy = nY; +#if RADIOBTN_PARENT_IS_RADIOBOX + int nXOffset = 0; + int nYOffset = 0; +#else + int nXOffset = nXx; + int nYOffset = nYy; +#endif + int nCx1; + int nCy1; + wxSize vMaxSize = GetMaxButtonSize(); + int nMaxWidth; + int nMaxHeight; + wxSize vTotSize; + int nTotWidth; + int nTotHeight; + int nStartX; + int nStartY; + + m_nSizeFlags = nSizeFlags; + GetPosition( &nCurrentX + ,&nCurrentY + ); + GetSize( &nWidthOld + ,&nHeightOld + ); + + if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + nXx = nCurrentX; + if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + nYy = nCurrentY; + + + wxGetCharSize( m_hWnd + ,&nCx1 + ,&nCy1 + ,&GetFont() + ); + + // + // Attempt to have a look coherent with other platforms: We compute the + // biggest toggle dim, then we align all items according this value. + // + vMaxSize = GetMaxButtonSize(); + nMaxWidth = vMaxSize.x; + nMaxHeight = vMaxSize.y; + + vTotSize = GetTotalButtonSize(vMaxSize); + nTotWidth = vTotSize.x; + nTotHeight = vTotSize.y; + + // + // Only change our width/height if asked for + // + if (nWidth == -1) + { + if (nSizeFlags & wxSIZE_AUTO_WIDTH ) + nWidth = nTotWidth; + else + nWidth = nWidthOld; + } - if (m_radioButtons) + if (nHeight == -1) { - int i; -// TODO: -/* - for (i = 0; i < m_noItems; i++) - ::DestroyWindow((HWND)m_radioButtons[i]); - delete[] m_radioButtons; -*/ + if (nSizeFlags & wxSIZE_AUTO_HEIGHT) + nHeight = nTotHeight; + else + nHeight = nHeightOld; } - if (m_radioWidth) - delete[] m_radioWidth; - if (m_radioHeight) - delete[] m_radioHeight; + wxWindowOS2* pParent = (wxWindowOS2*)GetParent(); -} + if (pParent) + { + nYy = pParent->GetClientSize().y - (nYy + nHeight); + nYOffset = nYy + nHeight; + } + else + { + RECTL vRect; -void wxRadioBox::SetString(int item, const wxString& label) -{ - wxCHECK_RET( item >= 0 && item < m_noItems, wxT("invalid radiobox index") ); + ::WinQueryWindowRect(HWND_DESKTOP, &vRect); + nYy = vRect.yTop - (nYy + nHeight); + } + ::WinSetWindowPos( GetHwnd() + ,HWND_TOP + ,(LONG)nXx + ,(LONG)nYy + ,(LONG)nWidth + ,(LONG)nHeight + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + + // + // Now position all the buttons: the current button will be put at + // wxPoint(x_offset, y_offset) and the new row/column will start at + // startX/startY. The size of all buttons will be the same wxSize(maxWidth, + // maxHeight) except for the buttons in the last column which should extend + // to the right border of radiobox and thus can be wider than this. + // + // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in + // left to right order and m_majorDim is the number of columns while + // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and + // m_majorDim is the number of rows. + // + nXOffset += nCx1; + nYOffset -= (nMaxHeight + ((3*nCy1)/2)); + + nStartX = nXOffset; + nStartY = nYOffset; + + for (int i = 0; i < m_nNoItems; i++) + { + // + // The last button in the row may be wider than the other ones as the + // radiobox may be wider than the sum of the button widths (as it + // happens, for example, when the radiobox label is very long) + // + bool bIsLastInTheRow; + + if (m_windowStyle & wxRA_SPECIFY_COLS) + { + // + // Item is the last in its row if it is a multiple of the number of + // columns or if it is just the last item + // + int n = i + 1; - m_radioWidth[item] = m_radioHeight[item] = -1; - ::WinSetWindowText((HWND)m_radioButtons[item], label.c_str()); -} + bIsLastInTheRow = ((n % m_nMajorDim) == 0) || (n == m_nNoItems); + } + else // winRA_SPECIFY_ROWS + { + // + // Item is the last in the row if it is in the last columns + // + bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim; + } -wxString wxRadioBox::GetLabel(int item) const -{ - wxCHECK_MSG( item >= 0 && item < m_noItems, wxT(""), wxT("invalid radiobox index") ); + // + // Is this the start of new row/column? + // + if (i && (i % m_nMajorDim == 0)) + { + if (m_windowStyle & wxRA_SPECIFY_ROWS) + { + + // + // Start of new column + // + nYOffset = nStartY; + nXOffset += nMaxWidth + nCx1; + } + else // start of new row + { + nXOffset = nStartX; + nYOffset -= nMaxHeight; + if (m_pnRadioWidth[0] > 0L) + nYOffset -= nCy1/2; + } + } + + int nWidthBtn; + + if (bIsLastInTheRow) + { + // + // Make the button go to the end of radio box + // + nWidthBtn = nStartX + nWidth - nXOffset - (2 * nCx1); + if (nWidthBtn < nMaxWidth) + nWidthBtn = nMaxWidth; + } + else + { + // + // Normal button, always of the same size + // + nWidthBtn = nMaxWidth; + } - return wxGetWindowText(m_radioButtons[item]); -} + // + // Make all buttons of the same, maximal size - like this they + // cover the radiobox entirely and the radiobox tooltips are always + // shown (otherwise they are not when the mouse pointer is in the + // radiobox part not beinting to any radiobutton) + // + ::WinSetWindowPos( (HWND)m_ahRadioButtons[i] + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset + ,(LONG)nWidthBtn + ,(LONG)nMaxHeight + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + // + // Where do we put the next button? + // + if (m_windowStyle & wxRA_SPECIFY_ROWS) + { + // + // Below this one + // + nYOffset -= nMaxHeight; + if (m_pnRadioWidth[0] > 0) + nYOffset -= nCy1/2; + } + else + { + // + // To the right of this one + // + nXOffset += nWidthBtn + nCx1; + } + } +} // end of wxRadioBox::DoSetSize -void wxRadioBox::SetLabel(int item, const wxString& label) +void wxRadioBox::Enable( + int nItem +, bool bEnable +) { - wxCHECK_RET( item >= 0 && item < m_noItems, wxT("invalid radiobox index") ); + wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems, + wxT("invalid item in wxRadioBox::Enable()") ); - m_radioWidth[item] = m_radioHeight[item] = -1; -// TODO: SetWindowText((HWND)m_radioButtons[item], label.c_str()); -} + ::WinEnableWindow((HWND) m_ahRadioButtons[nItem], bEnable); +} // end of wxRadioBox::Enable -void wxRadioBox::SetLabel(int item, wxBitmap *bitmap) +bool wxRadioBox::Enable( + bool bEnable +) { - /* - m_radioWidth[item] = bitmap->GetWidth() + FB_MARGIN; - m_radioHeight[item] = bitmap->GetHeight() + FB_MARGIN; - */ - wxFAIL_MSG(wxT("not implemented")); -} + if ( !wxControl::Enable(bEnable) ) + return FALSE; + for (int i = 0; i < m_nNoItems; i++) + ::WinEnableWindow((HWND)m_ahRadioButtons[i], bEnable); + return TRUE; +} // end of wxRadioBox::Enable -int wxRadioBox::FindString(const wxString& s) const +int wxRadioBox::FindString( + const wxString& rsStr +) const { - for (int i = 0; i < m_noItems; i++) + for (int i = 0; i < m_nNoItems; i++) { - if ( s == wxGetWindowText(m_radioButtons[i]) ) + if (rsStr == wxGetWindowText(m_ahRadioButtons[i]) ) return i; } - return wxNOT_FOUND; -} +} // end of wxRadioBox::FindString -void wxRadioBox::SetSelection(int N) -{ - wxCHECK_RET( (N >= 0) && (N < m_noItems), wxT("invalid radiobox index") ); - - // Following necessary for Win32s, because Win32s translate BM_SETCHECK -// TODO: -/* - if (m_selectedButton >= 0 && m_selectedButton < m_noItems) - ::SendMessage((HWND) m_radioButtons[m_selectedButton], BM_SETCHECK, 0, 0L); - - ::SendMessage((HWND)m_radioButtons[N], BM_SETCHECK, 1, 0L); - ::SetFocus((HWND)m_radioButtons[N]); -*/ - m_selectedButton = N; -} - -// Get single selection, for single choice list items -int wxRadioBox::GetSelection() const +int wxRadioBox::GetColumnCount() const { - return m_selectedButton; -} + return GetNumHor(); +} // end of wxRadioBox::GetColumnCount -// Find string for position -wxString wxRadioBox::GetString(int N) const +int wxRadioBox::GetCount() const { - return wxGetWindowText(m_radioButtons[N]); -} + return m_nNoItems; +} // end of wxRadioBox::GetCount -// Restored old code. -void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) +wxString wxRadioBox::GetLabel( + int nItem +) const { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int widthOld, heightOld; - GetSize(&widthOld, &heightOld); - - int xx = x; - int yy = y; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - xx = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - yy = currentY; - - wxString buf; - - int y_offset = yy; - int x_offset = xx; - int current_width, cyf; + wxCHECK_MSG(nItem >= 0 && nItem < m_nNoItems, wxT(""), wxT("invalid radiobox index") ); - int cx1,cy1; - wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont()); + return wxGetWindowText(m_ahRadioButtons[nItem]); +} // end of wxRadioBox::GetLabel - // Attempt to have a look coherent with other platforms: We compute the - // biggest toggle dim, then we align all items according this value. - int maxWidth = -1; - int maxHeight = -1; +wxSize wxRadioBox::GetMaxButtonSize() const +{ + int nWidthMax = 0; + int nHeightMax = 0; - int i; - for (i = 0 ; i < m_noItems; i++) + for (int i = 0 ; i < m_nNoItems; i++) { - int eachWidth; - int eachHeight; - if (m_radioWidth[i]<0) + int nWidth; + int nHeight; + + if (m_pnRadioWidth[i] < 0L) { - // It's a labelled toggle - buf = wxGetWindowText(m_radioButtons[i]); - GetTextExtent(buf, ¤t_width, &cyf); - eachWidth = (int)(current_width + RADIO_SIZE); - eachHeight = (int)((3*cyf)/2); + GetTextExtent( wxGetWindowText(m_ahRadioButtons[i]) + ,&nWidth + ,&nHeight + ); + + // + // Adjust the size to take into account the radio box itself + // FIXME this is totally bogus! + // + nWidth += RADIO_SIZE; + nHeight *= 3; + nHeight /= 2; } else { - eachWidth = m_radioWidth[i]; - eachHeight = m_radioHeight[i]; + nWidth = m_pnRadioWidth[i]; + nHeight = m_pnRadioHeight[i]; } + if (nWidthMax < nWidth ) + nWidthMax = nWidth; + if (nHeightMax < nHeight ) + nHeightMax = nHeight; + } + return(wxSize( nWidthMax + ,nHeightMax + ) + ); +} // end of wxRadioBox::GetMaxButtonSize - if (maxWidthGetHWND(), &vSwp); + vPoint.x = vSwp.x; + vPoint.y = vSwp.y; + } - // this formula works, but I don't know why. - // Please, be sure what you do if you modify it!! - if (m_radioWidth[0]<0) - totHeight = (nbVer * maxHeight) + cy1/2; - else - totHeight = nbVer * (maxHeight+cy1/2); - totWidth = nbHor * (maxWidth+cx1); + // + // We may be faking the client origin. So a window that's really at (0, 30) + // may appear (to wxWin apps) to be at (0, 0). + // + if (GetParent()) + { + wxPoint vPt(GetParent()->GetClientAreaOrigin()); - int extraHeight = cy1; + vPoint.x = vPt.x; + vPoint.y = vPt.y; + } + *pnX = vPoint.x; + *pnX = vPoint.y; +} // end of wxRadioBox::GetPosition - // only change our width/height if asked for - if ( width == -1 ) - { - if ( sizeFlags & wxSIZE_AUTO_WIDTH ) - width = totWidth + cx1; - else - width = widthOld; - } +int wxRadioBox::GetRowCount() const +{ + return GetNumVer(); +} // end of wxRadioBox::GetRowCount - if ( height == -1 ) - { - if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) - height = totHeight + extraHeight; - else - height = heightOld; - } +// Get single selection, for single choice list items +int wxRadioBox::GetSelection() const +{ + return m_nSelectedButton; +} // end of wxRadioBox::GetSelection -// TODO: MoveWindow(GetHwnd(), x_offset, y_offset, width, height, TRUE); +void wxRadioBox::GetSize( + int* pnWidth +, int* pnHeight +) const +{ + RECT vRect; + int i; - x_offset += cx1; - y_offset += cy1; - } + vRect.xLeft = -1; + vRect.xRight = -1; + vRect.yTop = -1; + vRect.yBottom = -1; + + if (m_hWnd) + wxFindMaxSize( m_hWnd + ,&vRect + ); + + for (i = 0; i < m_nNoItems; i++) + wxFindMaxSize( m_ahRadioButtons[i] + ,&vRect + ); + + *pnWidth = vRect.xRight - vRect.xLeft; + *pnHeight = vRect.yBottom - vRect.yTop; +} // end of wxRadioBox::GetSize - int startX = x_offset; - int startY = y_offset; +// Find string for position +wxString wxRadioBox::GetString( + int nNum +) const +{ + return wxGetWindowText(m_ahRadioButtons[nNum]); +} // end of wxRadioBox::GetString + +// For single selection items only +wxString wxRadioBox::GetStringSelection() const +{ + wxString sResult; + int nSel = GetSelection(); + + if (nSel > -1) + sResult = GetString(nSel); + return sResult; +} // end of wxRadioBox::GetStringSelection + +wxSize wxRadioBox::GetTotalButtonSize( + const wxSize& rSizeBtn +) const +{ + int nCx1; + int nCy1; + int nExtraHeight; + int nHeight; + int nWidth; + int nWidthLabel; + + wxGetCharSize( m_hWnd + ,&nCx1 + ,&nCy1 + ,(wxFont*)&GetFont() + ); + nExtraHeight = nCy1; + + nHeight = GetNumVer() * rSizeBtn.y + (2 * nCy1); + nWidth = GetNumHor() * (rSizeBtn.x + nCx1) + nCx1; + + // + // And also wide enough for its label + // + GetTextExtent( GetTitle() + ,&nWidthLabel + ,NULL + ); + nWidthLabel += RADIO_SIZE; + if (nWidthLabel > nWidth) + nWidth = nWidthLabel; + + return(wxSize( nWidth + ,nHeight + ) + ); +} // end of wxRadioBox::GetTotalButtonSize + +WXHBRUSH wxRadioBox::OnCtlColor( + WXHDC hwinDC +, WXHWND hWnd +, WXUINT uCtlColor +, WXUINT uMessage +, WXWPARAM wParam +, WXLPARAM lParam +) +{ + HPS hPS = (HPS)hwinDC; // pass in a PS handle in OS/2 + + if (GetParent()->GetTransparentBackground()) + ::GpiSetBackMix(hPS, BM_LEAVEALONE); + else + ::GpiSetBackMix(hPS, BM_OVERPAINT); + + wxColour vColBack = GetBackgroundColour(); - for ( i = 0 ; i < m_noItems; i++) + ::GpiSetBackColor(hPS, vColBack.GetPixel()); + ::GpiSetColor(hPS, vColBack.GetPixel()); + + + wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack + ,wxSOLID + ); + return ((WXHBRUSH)pBrush->GetResourceHandle()); +} // end of wxRadioBox::OnCtlColor + +bool wxRadioBox::OS2Command( + WXUINT uCmd +, WXWORD wId +) +{ + int nSelectedButton = -1; + + if (uCmd == BN_CLICKED) { - // Bidimensional radio adjustment - if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0? + if (wId == GetId()) + return TRUE; + + + for (int i = 0; i < m_nNoItems; i++) { - if (m_windowStyle & wxRA_VERTICAL) + if (wId == wxGetWindowId(m_ahRadioButtons[i])) { - y_offset = startY; - x_offset += maxWidth + cx1; - } - else - { - x_offset = startX; - y_offset += maxHeight; - if (m_radioWidth[0]>0) - y_offset += cy1/2; + nSelectedButton = i; + break; } } - int eachWidth; - int eachHeight; - if (m_radioWidth[i]<0) + if (nSelectedButton == -1) { - // It's a labeled item - buf = wxGetWindowText(m_radioButtons[i]); - GetTextExtent(buf, ¤t_width, &cyf); - - // How do we find out radio button bitmap size!! - // By adjusting them carefully, manually :-) - eachWidth = (int)(current_width + RADIO_SIZE); - eachHeight = (int)((3*cyf)/2); + // + // Just ignore it - due to a hack with WM_NCHITTEST handling in our + // wnd proc, we can receive dummy click messages when we click near + // the radiobox edge (this is ugly but Julian wouldn't let me get + // rid of this...) + return FALSE; } - else + if (nSelectedButton != m_nSelectedButton) { - eachWidth = m_radioWidth[i]; - eachHeight = m_radioHeight[i]; - } - -// TODO: -/* - MoveWindow((HWND)m_radioButtons[i], x_offset, y_offset, - eachWidth, eachHeight, - TRUE); -*/ - if (m_windowStyle & wxRA_SPECIFY_ROWS) - { - y_offset += maxHeight; - if (m_radioWidth[0]>0) - y_offset += cy1/2; + m_nSelectedButton = nSelectedButton; + SendNotificationEvent(); } - else - x_offset += maxWidth + cx1; + return TRUE; } -} - -void wxRadioBox::GetSize(int *width, int *height) const -{ - RECT rect; - rect.xLeft = -1; rect.xRight = -1; rect.yTop = -1; rect.yBottom = -1; - - if (m_hWnd) - wxFindMaxSize(m_hWnd, &rect); - - int i; - for (i = 0; i < m_noItems; i++) - wxFindMaxSize(m_radioButtons[i], &rect); - - *width = rect.xRight - rect.xLeft; - *height = rect.yBottom - rect.yTop; -} + else + return FALSE; +} // end of wxRadioBox::OS2Command -void wxRadioBox::GetPosition(int *x, int *y) const +void wxRadioBox::SendNotificationEvent() { - wxWindow *parent = GetParent(); - RECT rect; - rect.xLeft = -1; rect.xRight = -1; rect.yTop = -1; rect.yBottom = -1; - - int i; - for (i = 0; i < m_noItems; i++) - wxFindMaxSize(m_radioButtons[i], &rect); - - if (m_hWnd) - wxFindMaxSize(m_hWnd, &rect); - - // Since we now have the absolute screen coords, - // if there's a parent we must subtract its top left corner - POINTL point; - point.x = rect.xLeft; - point.y = rect.yTop; -// TODO: -/* - if (parent) - { - ::ScreenToClient((HWND) parent->GetHWND(), &point); - } -*/ - // We may be faking the client origin. - // So a window that's really at (0, 30) may appear - // (to wxWin apps) to be at (0, 0). - if (GetParent()) - { - wxPoint pt(GetParent()->GetClientAreaOrigin()); - point.x -= pt.x; - point.y -= pt.y; - } + wxCommandEvent vEvent( wxEVT_COMMAND_RADIOBOX_SELECTED + ,m_windowId + ); - *x = point.x; - *y = point.y; -} + vEvent.SetInt( m_nSelectedButton ); + vEvent.SetString( GetString(m_nSelectedButton) ); + vEvent.SetEventObject(this); + ProcessCommand(vEvent); +} // end of wxRadioBox::SendNotificationEvent void wxRadioBox::SetFocus() { -// TODO: -/* - if (m_noItems > 0) + if (m_nNoItems > 0) { - if (m_selectedButton == -1) - ::SetFocus((HWND) m_radioButtons[0]); + if (m_nSelectedButton == -1) + ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[0]); else - ::SetFocus((HWND) m_radioButtons[m_selectedButton]); + ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[m_nSelectedButton]); } -*/ -} +} // end of wxRadioBox::SetFocus -bool wxRadioBox::Show(bool show) +bool wxRadioBox::SetFont( + const wxFont& rFont +) { - if ( !wxControl::Show(show) ) + if (!wxControl::SetFont(rFont)) + { + // + // Nothing to do + // return FALSE; + } + // + // Also set the font of our radio buttons + // + WXHFONT hFont = wxFont(rFont).GetResourceHandle(); - int nCmdShow = 0; // TODO: show ? SW_SHOW : SW_HIDE; - for ( int i = 0; i < m_noItems; i++ ) + for (int n = 0; n < (int)m_nNoItems; n++) { -// TODO: ::ShowWindow((HWND)m_radioButtons[i], nCmdShow); - } + HWND hWndBtn = (HWND)m_ahRadioButtons[n]; + wxOS2SetFont( hWndBtn + ,rFont + ); + ::WinInvalidateRect(hWndBtn, NULL, FALSE); + } return TRUE; -} +} // end of wxRadioBox::SetFont -// Enable a specific button -void wxRadioBox::Enable(int item, bool enable) +void wxRadioBox::SetSelection( + int nNum +) { - wxCHECK_RET( item >= 0 && item < m_noItems, - wxT("invalid item in wxRadioBox::Enable()") ); + wxCHECK_RET( (nNum >= 0) && (nNum < m_nNoItems), wxT("invalid radiobox index") ); -// TODO: ::EnableWindow((HWND) m_radioButtons[item], enable); -} + if (m_nSelectedButton >= 0 && m_nSelectedButton < m_nNoItems) + ::WinSendMsg((HWND)m_ahRadioButtons[m_nSelectedButton], BM_SETCHECK, (MPARAM)0, (MPARAM)0); -// Enable all controls -bool wxRadioBox::Enable(bool enable) -{ - if ( !wxControl::Enable(enable) ) - return FALSE; + ::WinSendMsg((HWND)m_ahRadioButtons[nNum], BM_SETCHECK, (MPARAM)1, (MPARAM)0); + ::WinSetFocus(HWND_DESKTOP, (HWND)m_ahRadioButtons[nNum]); + m_nSelectedButton = nNum; +} // end of wxRadioBox::SetSelection -// TODO: -/* - for (int i = 0; i < m_noItems; i++) - ::EnableWindow((HWND) m_radioButtons[i], enable); -*/ - return TRUE; -} - -// Show a specific button -void wxRadioBox::Show(int item, bool show) +void wxRadioBox::SetString( + int nItem +, const wxString& rsLabel +) { - wxCHECK_RET( item >= 0 && item < m_noItems, - wxT("invalid item in wxRadioBox::Show()") ); + wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems, wxT("invalid radiobox index") ); -// TODO: ::ShowWindow((HWND)m_radioButtons[item], show ? SW_SHOW : SW_HIDE); -} + m_pnRadioWidth[nItem] = m_pnRadioHeight[nItem] = -1; + ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], rsLabel.c_str()); +} // end of wxRadioBox::SetString -WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +bool wxRadioBox::SetStringSelection( + const wxString& rsStr +) { -// TODO: -/* - 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 single selection items only -wxString wxRadioBox::GetStringSelection() const -{ - wxString result; - int sel = GetSelection(); - if (sel > -1) - result = GetString(sel); - - return result; -} + int nSel = FindString(rsStr); -bool wxRadioBox::SetStringSelection(const wxString& s) -{ - int sel = FindString (s); - if (sel > -1) + if (nSel > -1) { - SetSelection (sel); + SetSelection(nSel); return TRUE; } else return FALSE; -} +} // end of wxRadioBox::SetStringSelection -bool wxRadioBox::ContainsHWND(WXHWND hWnd) const +bool wxRadioBox::Show( + bool bShow +) { - int i; - for (i = 0; i < Number(); i++) + int nCmdShow = 0; + + if (!wxControl::Show(bShow)) + return FALSE; + + for (int i = 0; i < m_nNoItems; i++) { - if (GetRadioButtons()[i] == hWnd) - return TRUE; + ::WinShowWindow((HWND)m_ahRadioButtons[i], (BOOL)bShow); } + return TRUE; +} // end of wxRadioBox::Show - return FALSE; -} - -void wxRadioBox::Command (wxCommandEvent & event) +// Show a specific button +void wxRadioBox::Show( + int nItem +, bool bShow +) { - SetSelection (event.m_commandInt); - ProcessCommand (event); -} + wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems, + wxT("invalid item in wxRadioBox::Show()") ); -void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn) -{ - HWND hwndBtn = (HWND)hWndBtn; + ::WinShowWindow((HWND)m_ahRadioButtons[nItem], bShow); +} // end of wxRadioBox::Show -// TODO: -/* - if ( !s_wndprocRadioBtn ) - s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC); +void wxRadioBox::SubclassRadioButton( + WXHWND hWndBtn +) +{ + HWND hwndBtn = (HWND)hWndBtn; - // No GWL_USERDATA in Win16, so omit this subclassing. - ::SetWindowLong(hwndBtn, GWL_WNDPROC, (long)wxRadioBtnWndProc); - ::SetWindowLong(hwndBtn, GWL_USERDATA, (long)this); -*/ -} + fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc); +} // end of wxRadioBox::SubclassRadioButton -void wxRadioBox::SendNotificationEvent() +MRESULT wxRadioBox::WindowProc( + WXUINT uMsg +, WXWPARAM wParam +, WXLPARAM lParam +) { - wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId); - event.SetInt( m_selectedButton ); - event.SetString( GetString(m_selectedButton) ); - event.SetEventObject( this ); - ProcessCommand(event); -} + return (wxControl::OS2WindowProc( uMsg + ,wParam + ,lParam + )); +} // end of wxRadioBox::WindowProc // --------------------------------------------------------------------------- // window proc for radio buttons // --------------------------------------------------------------------------- -MRESULT wxRadioBtnWndProc(HWND hwnd, - UINT msg, - MPARAM wParam, - MPARAM lParam) +MRESULT wxRadioBtnWndProc( + HWND hWnd +, UINT uMessage +, MPARAM wParam +, MPARAM lParam +) { - bool processed = TRUE; -// if ( msg != WM_KEYDOWN ) -// processed = FALSE; - - if ( processed ) + switch (uMessage) { - wxRadioBox *radiobox = NULL; // TODO: (wxRadioBox *)::GetWindowLong(hwnd, GWL_USERDATA); - - wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") ); - - int sel = radiobox->GetSelection(); - -// TODO: -/* - switch ( wParam ) - { - case VK_UP: - sel--; - break; - - case VK_LEFT: - sel -= radiobox->GetNumVer(); - break; - - case VK_DOWN: - sel++; - break; - - case VK_RIGHT: - sel += radiobox->GetNumVer(); - break; + case WM_CHAR: + { + USHORT uKeyFlags = SHORT1FROMMP((MPARAM)wParam); - case VK_TAB: + if (!(uKeyFlags & KC_KEYUP)) // Key Down event { - wxNavigationKeyEvent event; - event.SetDirection(!(::GetKeyState(VK_SHIFT) & 0x100)); - event.SetWindowChange(FALSE); - event.SetEventObject(radiobox); - - if ( radiobox->GetEventHandler()->ProcessEvent(event) ) - return 0; + if (uKeyFlags & KC_VIRTUALKEY) + { + wxRadioBox* pRadiobox = (wxRadioBox *)::WinQueryWindowULong( hWnd + ,QWL_USER + ); + USHORT uVk = SHORT2FROMMP((MPARAM)lParam); + bool bProcessed = TRUE; + wxDirection eDir; + + switch(uVk) + { + case VK_LEFT: + eDir = wxDOWN; + break; + + case VK_RIGHT: + eDir = wxDOWN; + break; + + case VK_DOWN: + eDir = wxDOWN; + break; + + case VK_UP: + eDir = wxUP; + break; + + default: + bProcessed = FALSE; + + // + // Just to suppress the compiler warning + // + eDir = wxALL; + } + + if (bProcessed) + { + int nSelOld = pRadiobox->GetSelection(); + int nSelNew = pRadiobox->GetNextItem( nSelOld + ,eDir + ,pRadiobox->GetWindowStyleFlag() + ); + + if (nSelNew != nSelOld) + { + pRadiobox->SetSelection(nSelNew); + + // + // Emulate the button click + // + pRadiobox->SendNotificationEvent(); + return 0; + } + } + } } - // fall through - - default: - processed = FALSE; - } -*/ - if ( processed ) - { - if ( sel >= 0 && sel < radiobox->Number() ) - { - radiobox->SetSelection(sel); - - // emulate the button click - radiobox->SendNotificationEvent(); } - } + break; } -// TODO: -/* - if ( !processed ) - return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, msg, wParam, lParam); - else - return 0; -*/ - return 0; -} + return fnWndProcRadioBtn( hWnd + ,(ULONG)uMessage + ,(MPARAM)wParam + ,(MPARAM)lParam + ); +} // end of wxRadioBtnWndProc diff --git a/src/os2/radiobut.cpp b/src/os2/radiobut.cpp index d0b290c997..8878abed12 100644 --- a/src/os2/radiobut.cpp +++ b/src/os2/radiobut.cpp @@ -27,197 +27,153 @@ IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) -bool wxRadioButton::OS2Command(WXUINT param, WXWORD id) +void wxRadioButton::Command ( + wxCommandEvent& rEvent +) { - if (param == BN_CLICKED) - { - wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId); - event.SetEventObject( this ); - ProcessCommand(event); - return TRUE; - } - else return FALSE; -} - -bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, long style, + SetValue ((rEvent.GetInt() != 0) ); + ProcessCommand (rEvent); +} // end of wxRadioButton::Command + +bool wxRadioButton::Create( + wxWindow* pParent +, wxWindowID vId +, const wxString& rsLabel +, const wxPoint& rPos +, const wxSize& rSize +, long lStyle #if wxUSE_VALIDATORS - const wxValidator& validator, +, const wxValidator& rValidator #endif - const wxString& name) +, const wxString& rsName +) { - SetName(name); + int nX = rPos.x; + int nY = rPos.y; + int nWidth = rSize.x; + int nHeight = rSize.y; + long lsStyle = 0L; + long lGroupStyle = 0L; + + SetName(rsName); #if wxUSE_VALIDATORS - SetValidator(validator); + SetValidator(rValidator); #endif - if (parent) parent->AddChild(this); + if (pParent) + pParent->AddChild(this); - SetBackgroundColour(parent->GetBackgroundColour()); - SetForegroundColour(parent->GetForegroundColour()); + SetBackgroundColour(pParent->GetBackgroundColour()); + SetForegroundColour(pParent->GetForegroundColour()); - if ( id == -1 ) + if (vId == -1) m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = vId; - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; - m_windowStyle = style ; + m_windowStyle = lStyle ; -// TODO create radiobutton -/* - long groupStyle = 0; - if (m_windowStyle & wxRB_GROUP) - groupStyle = WS_GROUP; + if (m_windowStyle & wxRB_GROUP) + lGroupStyle = WS_GROUP; -// long msStyle = groupStyle | RADIO_FLAGS; - long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE ; + lsStyle = lGroupStyle | BS_AUTORADIOBUTTON | WS_VISIBLE ; - bool want3D; - WXDWORD exStyle = Determine3DEffects(0, &want3D) ; + if (m_windowStyle & wxCLIP_SIBLINGS ) + lsStyle |= WS_CLIPSIBLINGS; + m_hWnd = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent) + ,WC_BUTTON + ,rsLabel.c_str() + ,lsStyle + ,0, 0, 0, 0 + ,GetWinHwnd(pParent) + ,HWND_TOP + ,(HMENU)m_windowId + ,NULL + ,NULL + ); + wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create radiobutton")); - m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label, - msStyle,0,0,0,0, - (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); - - wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") ); - - - SetFont(parent->GetFont()); - - // Subclass again for purposes of dialog editing mode - SubclassWin((WXHWND)m_hWnd); - -// SetValue(value); -*/ - - // start GRW fix - if (label != wxT("")) - { - int label_width, label_height; - GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont()); - if (width < 0) - width = (int)(label_width + RADIO_SIZE); - if (height<0) + if (rsLabel != wxT("")) { - height = (int)(label_height); - if (height < RADIO_SIZE) - height = RADIO_SIZE; + int nLabelWidth; + int nLabelHeight; + + GetTextExtent( rsLabel + ,&nLabelWidth + ,&nLabelHeight + ,NULL + ,NULL + ,&this->GetFont() + ); + if (nWidth < 0) + nWidth = (int)(nLabelWidth + RADIO_SIZE); + if (nHeight<0) + { + nHeight = (int)(nLabelHeight); + if (nHeight < RADIO_SIZE) + nHeight = RADIO_SIZE; + } + } + else + { + if (nWidth < 0) + nWidth = RADIO_SIZE; + if (nHeight < 0) + nHeight = RADIO_SIZE; } - } - else - { - if (width < 0) - width = RADIO_SIZE; - if (height < 0) - height = RADIO_SIZE; - } - // end GRW fix - - SetSize(x, y, width, height); - return FALSE; -} - -void wxRadioButton::SetLabel(const wxString& label) -{ - // TODO -} -void wxRadioButton::SetValue(bool value) -{ - // TODO -} + // + // Subclass again for purposes of dialog editing mode + // + SubclassWin((WXHWND)m_hWnd); + SetFont(pParent->GetFont()); + SetSize( nX + ,nY + ,nWidth + ,nHeight + ); + return FALSE; +} // end of wxRadioButton::Create +// // Get single selection, for single choice list items +// bool wxRadioButton::GetValue() const { - // TODO - return FALSE; -} + return((::WinSendMsg((HWND) GetHWND(), BM_QUERYCHECK, (MPARAM)0L, (MPARAM)0L) != 0)); +} // end of wxRadioButton::GetValue -void wxRadioButton::Command (wxCommandEvent & event) -{ - SetValue ( (event.m_commandInt != 0) ); - ProcessCommand (event); -} - -// Not implemented -#if 0 - -bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, - const wxBitmap *bitmap, - const wxPoint& pos, - const wxSize& size, long style, -#if wxUSE_VALIDATORS - const wxValidator& validator, -#endif - const wxString& name) +bool wxRadioButton::OS2Command( + WXUINT wParam +, WXWORD wId +) { - SetName(name); -#if wxUSE_VALIDATORS - SetValidator(validator); -#endif - - if (parent) parent->AddChild(this); - SetBackgroundColour(parent->GetBackgroundColour()); - SetForegroundColour(parent->GetForegroundColour()); - - 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; - m_windowStyle = style ; - - long groupStyle = 0; - if (m_windowStyle & wxRB_GROUP) - groupStyle = WS_GROUP; - -// TODO: -/* -// long msStyle = groupStyle | RADIO_FLAGS; -// long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ; - - m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle", - msStyle,0,0,0,0, - (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); - - wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE ); - -*/ - // Subclass again for purposes of dialog editing mode - SubclassWin(GetHWND()); - - SetSize(x, y, width, height); - - return TRUE; -} + if (wParam == BN_CLICKED) + { + wxCommandEvent rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED + ,m_windowId + ); -void wxBitmapRadioButton::SetLabel(const wxBitmap *bitmap) -{ -} + rEvent.SetEventObject(this); + ProcessCommand(rEvent); + return TRUE; + } + else + return FALSE; +} // end of wxRadioButton::OS2Command -void wxBitmapRadioButton::SetValue(bool value) +void wxRadioButton::SetLabel( + const wxString& rsLabel +) { -// Following necessary for Win32s, because Win32s translate BM_SETCHECK -// SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); -} + ::WinSetWindowText((HWND)GetHWND(), (const char *)rsLabel.c_str()); +} // end of wxRadioButton::SetLabel -// Get single selection, for single choice list items -bool wxBitmapRadioButton::GetValue(void) const +void wxRadioButton::SetValue( + bool bValue +) { -// return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L); - return FALSE; -} + ::WinSendMsg((HWND)GetHWND(), BM_SETCHECK, (MPARAM)bValue, (MPARAM)0); +} // end of wxRadioButton::SetValue -#endif \ No newline at end of file diff --git a/src/os2/slider.cpp b/src/os2/slider.cpp index c0d6c909bb..2a9101349e 100644 --- a/src/os2/slider.cpp +++ b/src/os2/slider.cpp @@ -27,443 +27,998 @@ IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) -// Slider wxSlider::wxSlider() { - 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, wxWindowID id, - int value, int minValue, int maxValue, - const wxPoint& pos, - const wxSize& size, long style, -#if wxUSE_VALIDATORS - const wxValidator& validator, -#endif - const wxString& name) -{ - SetName(name); -#if wxUSE_VALIDATORS - SetValidator(validator); -#endif - - if (parent) parent->AddChild(this); - - m_lineSize = 1; - m_windowStyle = style; - m_tickFreq = 0; - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; - - m_rangeMax = maxValue; - m_rangeMin = minValue; - - m_pageSize = (int)((maxValue-minValue)/10); - - // TODO create slider - - return FALSE; -} - -bool wxSlider::OS2OnScroll(int WXUNUSED(orientation), WXWORD wParam, - WXWORD pos, WXHWND control) -{ - int position = 0; // Dummy - not used in this mode - - int nScrollInc; - wxEventType scrollEvent = wxEVT_NULL; -// TODO: -/* - 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 // Win16 - nScrollInc = pos - position; -#endif // Win32/16 - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - break; - - default: - nScrollInc = 0; - } - - if ( nScrollInc == 0 ) - { - // no event... - return FALSE; - } - - int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0); - if ( (newPos < GetMin()) || (newPos > GetMax()) ) - { - // out of range - but we did process it - return TRUE; - } -*/ - int newPos = 0; //temporary - SetValue(newPos); - - wxScrollEvent event(scrollEvent, m_windowId); - event.SetPosition(newPos); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - - wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); - cevent.SetEventObject( this ); - - return GetEventHandler()->ProcessEvent( cevent ); -} + m_hStaticValue = 0L; + m_hStaticMin = 0L; + m_hStaticMax = 0L; + m_nPageSize = 1; + m_nLineSize = 1; + m_nRangeMax = 0; + m_nRangeMin = 0; + m_nTickFreq = 0; +} // end of wxSlider::wxSlider wxSlider::~wxSlider() { - // TODO: -} + if (m_hStaticMin) + ::WinDestroyWindow((HWND)m_hStaticMin); + if (m_hStaticMax) + ::WinDestroyWindow((HWND)m_hStaticMax); + if (m_hStaticValue) + ::WinDestroyWindow((HWND)m_hStaticValue); +} // end of wxSlider::~wxSlider -int wxSlider::GetValue() const +void wxSlider::ClearSel() { - // TODO - return 0; -} +} // end of wxSlider::ClearSel -void wxSlider::SetValue(int value) +void wxSlider::ClearTicks() { - // TODO -} +} // end of wxSlider::ClearTicks -void wxSlider::GetSize(int *width, int *height) const +void wxSlider::Command ( + wxCommandEvent& rEvent +) { - // TODO -} + SetValue(rEvent.GetInt()); + ProcessCommand(rEvent); +} // end of wxSlider::Command -void wxSlider::GetPosition(int *x, int *y) const +bool wxSlider::ContainsHWND( + WXHWND hWnd +) const { - // TODO -} - -// TODO one day, make sense of all this horros and replace it with a readable -// DoGetBestSize() -void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags) + return ( hWnd == GetStaticMin() || + hWnd == GetStaticMax() || + hWnd == GetEditValue() + ); +} // end of wxSlider::ContainsHWND + +bool wxSlider::Create( + wxWindow* pParent +, wxWindowID vId +, int nValue +, int nMinValue +, int nMaxValue +, const wxPoint& rPos +, const wxSize& rSize +, long lStyle +#if wxUSE_VALIDATORS +, const wxValidator& rValidator +#endif +, const wxString& rsName +) { - 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; - -// TODO: -/* + int nX = rPos.x; + int nY = rPos.y; + int nWidth = rSize.x; + int nHeight = rSize.y; + long lMsStyle = 0L; + long lWstyle = 0L; + + SetName(rsName); +#if wxUSE_VALIDATORS + SetValidator(rValidator); +#endif + if (pParent) + pParent->AddChild(this); + SetBackgroundColour(pParent->GetBackgroundColour()) ; + SetForegroundColour(pParent->GetForegroundColour()) ; + + m_hStaticValue = 0L; + m_hStaticMin = 0L; + m_hStaticMax = 0L; + m_nPageSize = 1; + m_nLineSize = 1; + m_windowStyle = lStyle; + m_nTickFreq = 0; + + if (vId == -1) + m_windowId = (int)NewControlId(); + else + m_windowId = vId; - AdjustForParentClientOrigin(x1, y1, sizeFlags); + if (m_windowStyle & wxCLIP_SIBLINGS ) + lMsStyle |= WS_CLIPSIBLINGS; - wxChar buf[300]; + if (m_windowStyle & wxSL_LABELS) + { + lMsStyle |= WS_VISIBLE | SS_TEXT | DT_VCENTER; + + m_hStaticValue = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle + ,WC_STATIC // Window class + ,(PSZ)NULL // Initial Text + ,(ULONG)lMsStyle // Style flags + ,0L, 0L, 0L, 0L // Origin -- 0 size + ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent + ,HWND_TOP // initial z position + ,(ULONG)NewControlId() // Window identifier + ,NULL // no control data + ,NULL // no Presentation parameters + ); + + // + // Now create min static control + // + sprintf(wxBuffer, "%d", nMinValue); + lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE; + if (m_windowStyle & wxCLIP_SIBLINGS) + lWstyle |= WS_CLIPSIBLINGS; + m_hStaticMin = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle + ,WC_STATIC // Window class + ,(PSZ)wxBuffer // Initial Text + ,(ULONG)lWstyle // Style flags + ,0L, 0L, 0L, 0L // Origin -- 0 size + ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent + ,HWND_TOP // initial z position + ,(ULONG)NewControlId() // Window identifier + ,NULL // no control data + ,NULL // no Presentation parameters + ); + } + lMsStyle = 0; - int x_offset = x; - int y_offset = y; + SLDCDATA vSlData; - int cx; // slider,min,max sizes - int cy; - int cyf; + vSlData.cbSize = sizeof(SLDCDATA); + if (m_windowStyle & wxSL_VERTICAL) + lMsStyle = SLS_VERTICAL | WS_VISIBLE | WS_TABSTOP; + else + lMsStyle = SLS_HORIZONTAL | WS_VISIBLE | WS_TABSTOP; - wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); + if (m_windowStyle & wxCLIP_SIBLINGS) + lMsStyle |= WS_CLIPSIBLINGS; - if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) - { - if ( m_windowStyle & wxSL_LABELS ) + if (m_windowStyle & wxSL_AUTOTICKS) { - int min_len = 0; - - GetWindowText((HWND) m_staticMin, buf, 300); - GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont()); - - int max_len = 0; + vSlData.usScale1Spacing = 0; + vSlData.usScale2Spacing = 0; + } - GetWindowText((HWND) m_staticMax, buf, 300); - GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont()); - if (m_staticValue) + if (m_windowStyle & wxSL_LEFT) + lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_VERTICAL then SCALE2 is to the left + else if (m_windowStyle & wxSL_RIGHT) + lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_VERTICAL then SCALE2 is to the right + else if (m_windowStyle & wxSL_TOP) + lMsStyle |= SLS_PRIMARYSCALE1; // if SLS_HORIZONTAL then SCALE1 is to the top + else if (m_windowStyle & wxSL_BOTTOM ) + lMsStyle |= SLS_PRIMARYSCALE2; // if SLS_HORIZONTAL then SCALE1 is to the bottom + else if ( m_windowStyle & wxSL_BOTH ) + lMsStyle |= SLS_PRIMARYSCALE1 | SLS_PRIMARYSCALE2; + else + lMsStyle |= SLS_PRIMARYSCALE2; + + m_nPageSize = ((nMaxValue - nMinValue)/10); + vSlData.usScale1Increments = m_nPageSize; + vSlData.usScale2Increments = m_nPageSize; + + HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle + ,WC_SLIDER // Window class + ,(PSZ)wxBuffer // Initial Text + ,(ULONG)lMsStyle // Style flags + ,0L, 0L, 0L, 0L // Origin -- 0 size + ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent + ,HWND_TOP // initial z position + ,(HMENU)m_windowId // Window identifier + ,&vSlData // Slider control data + ,NULL // no Presentation parameters + ); + m_nRangeMax = nMaxValue; + m_nRangeMin = nMinValue; + + // + // Set the size of the ticks ... default to 6 pixels + // + ::WinSendMsg( hScrollBar + ,SLM_SETTICKSIZE + ,MPFROM2SHORT(SMA_SETALLTICKS, 6) + ,NULL + ); + // + // Set the position to the initial value + // + ::WinSendMsg( hScrollBar + ,SLM_SETSLIDERINFO + ,MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE) + ,(MPARAM)nValue + ); + + m_hWnd = (WXHWND)hScrollBar; + SubclassWin(GetHWND()); + ::WinSetWindowText((HWND)m_hWnd, ""); + SetFont(pParent->GetFont()); + if (m_windowStyle & wxSL_LABELS) { - 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; + // + // Finally, create max value static item + // + sprintf(wxBuffer, "%d", nMaxValue); + lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE; + if (m_windowStyle & wxCLIP_SIBLINGS) + lMsStyle |= WS_CLIPSIBLINGS; + m_hStaticMax = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle + ,WC_STATIC // Window class + ,(PSZ)wxBuffer // Initial Text + ,(ULONG)lWstyle // Style flags + ,0L, 0L, 0L, 0L // Origin -- 0 size + ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent + ,HWND_TOP // initial z position + ,(ULONG)NewControlId() // Window identifier + ,NULL // no control data + ,NULL // no Presentation parameters + ); + if (GetFont().Ok()) + { + if (GetFont().GetResourceHandle()) + { + if (m_hStaticMin) + wxOS2SetFont( m_hStaticMin + ,GetFont() + ); + if (m_hStaticMax) + wxOS2SetFont( m_hStaticMax + ,GetFont() + ); + if (m_hStaticValue) + wxOS2SetFont( m_hStaticValue + ,GetFont() + ); + } + } } - 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(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 + SetSize( nX + ,nY + ,nWidth + ,nHeight + ); + m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ) + 4; // for bordersizes + + wxColour vColour; + + vColour.Set(wxString("BLACK")); + + LONG lColor = (LONG)vColour.GetPixel(); + + ::WinSetPresParam( m_hStaticMin + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); + ::WinSetPresParam( m_hStaticMax + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); + ::WinSetPresParam( m_hStaticValue + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); + ::WinSetPresParam( m_hWnd + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); + SetValue(nValue); + return TRUE; +} // end of wxSlider::Create + +void wxSlider::DoSetSize( + int nX +, int nY +, int nWidth +, int nHeight +, int nSizeFlags +) +{ + int nX1 = nX; + int nY1 = nY; + int nWidth1 = nWidth; + int nHeight1 = nHeight; + int nXOffset = nX; + int nYOffset = nY; + int nCx; // slider,min,max sizes + int nCy; + int nCyf; + int nCurrentX; + int nCurrentY; + char zBuf[300]; + + // + // Adjust for OS/2's reverse coordinate system + // + wxWindowOS2* pParent = (wxWindowOS2*)GetParent(); + int nUsedHeight = 0; + int nOS2Height = nHeight; + + if (nOS2Height < 0) + nOS2Height = 20; + + if (pParent) { - // No labels - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) + // + // Under OS/2, where a frame window is the parent, most child windows + // that are not specific frame clients are actually children of the + // frame's client, not the frame itself, and so position themselves + // with regards to the client origin, not the frame. + // + if (pParent->IsKindOf(CLASSINFO(wxFrame))) + { + nYOffset = pParent->GetClientSize().y - (nYOffset + nOS2Height); + if (nY != -1) + nY1 = pParent->GetClientSize().y - (nY1 + nOS2Height); + } + else { - GetSize(&w1, &h1); + nYOffset = pParent->GetSize().y - (nYOffset + nOS2Height); + if (nY != -1) + nY1 = pParent->GetSize().y - (nY1 + nOS2Height); } - if ( w1 < 0 ) - w1 = 200; - if ( h1 < 0 ) - h1 = 20; - MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); } - } - else - { - if ( m_windowStyle & wxSL_LABELS ) + else { - int min_len; - GetWindowText((HWND) m_staticMin, buf, 300); - GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont()); + RECTL vRect; - int max_len; - GetWindowText((HWND) m_staticMax, buf, 300); - GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont()); + ::WinQueryWindowRect(HWND_DESKTOP, &vRect); + nYOffset = vRect.yTop - (nYOffset + nOS2Height); + if (nY != -1) + nY1 = vRect.yTop - (nY1 + nOS2Height); + } - if (m_staticValue) + GetPosition( &nCurrentX + ,&nCurrentY + ); + if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + nX1 = nCurrentX; + if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + nY1 = nCurrentY; + + AdjustForParentClientOrigin( nX1 + ,nY1 + ,nSizeFlags + ); + wxGetCharSize( GetHWND() + ,&nCx + ,&nCy + ,&this->GetFont() + ); + + if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) { - 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; + if (m_windowStyle & wxSL_LABELS ) + { + int nMinLen = 0; + int nMaxLen = 0; + + ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf); + GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont()); + ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf); + GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont()); + + if (m_hStaticValue) + { + int nNewWidth = (wxMax(nMinLen, nMaxLen)); + int nValueHeight = nCyf; + + ::WinSetWindowPos( (HWND)m_hStaticValue + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset - (nCyf * 1.2) + ,(LONG)nNewWidth + ,(LONG)nValueHeight + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + nXOffset += nNewWidth + nCx; + } + ::WinSetWindowPos( (HWND)m_hStaticMin + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset - nCyf + ,(LONG)nMinLen + ,(LONG)nCy + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + nXOffset += nMinLen + nCx; + + int nSliderLength = nWidth1 - nXOffset - nMaxLen - nCx; + int nSliderHeight = nHeight1; + + if (nSliderHeight < 0) + nSliderHeight = 20; + + // + // Slider must have a minimum/default length/height + // + if (nSliderLength < 100) + nSliderLength = 100; + + ::WinSetWindowPos( GetHwnd() + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset + ,(LONG)nSliderLength + ,(LONG)nSliderHeight + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + nXOffset += nSliderLength + nCx; + + ::WinSetWindowPos( (HWND)m_hStaticMax + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset - nCyf + ,(LONG)nMaxLen + ,(LONG)nCy + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + } + else + { + // + // No labels + // If we're prepared to use the existing size, then... + // + if (nWidth == -1 && nHeight == -1 && + ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) + { + GetSize( &nWidth1 + ,&nHeight1 + ); + } + if (nWidth1 < 0) + nWidth1 = 200; + if (nHeight1 < 0) + nHeight1 = 20; + ::WinSetWindowPos( GetHwnd() + ,HWND_TOP + ,(LONG)nX1 + ,(LONG)nY1 + ,(LONG)nWidth1 + ,(LONG)nHeight1 + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + } } - 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(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); - } + // + // Now deal with a vertical slider + // else { - // No labels - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) + if (m_windowStyle & wxSL_LABELS ) { - GetSize(&w1, &h1); + int nMinLen; + int nMaxLen; + + ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf); + GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont()); + ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf); + GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont()); + if (m_hStaticValue) + { + int nNewWidth = wxMax(nMinLen, nMaxLen); + int nValueHeight = nCyf; + + nNewWidth += nCx; + + // + // The height needs to be a bit bigger under Win95 if using native + // 3D effects. + // + nValueHeight = (int)(nValueHeight * 1.5); + ::WinSetWindowPos( (HWND)m_hStaticValue + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset + ,(LONG)nNewWidth + ,(LONG)nValueHeight + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + nYOffset -= nValueHeight; + nUsedHeight += nValueHeight; + } + ::WinSetWindowPos( (HWND)m_hStaticMin + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset + ,(LONG)nMinLen + ,(LONG)nCy + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + nYOffset -= nCy; + nUsedHeight += nCy; + + int nSliderLength = nHeight1 - (nUsedHeight + (2 * nCy)); + int nSliderWidth = nWidth1; + + if (nSliderWidth < 0) + nSliderWidth = 20; + + // + // Slider must have a minimum/default length + // + if (nSliderLength < 100) + nSliderLength = 100; + + ::WinSetWindowPos( (HWND)m_hStaticMin + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset + ,(LONG)nSliderWidth + ,(LONG)nSliderLength + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + nYOffset -= nSliderLength; + nUsedHeight += nSliderLength; + ::WinSetWindowPos( (HWND)m_hStaticMax + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset + ,(LONG)nMaxLen + ,(LONG)nCy + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + } + else + { + // + // No labels + // If we're prepared to use the existing size, then... + // + if (nWidth == -1 && nHeight == -1 && + ((nSizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) + { + GetSize( &nWidth1 + ,&nHeight1 + ); + } + if (nWidth1 < 0) + nWidth1 = 20; + if (nHeight1 < 0) + nHeight1 = 200; + ::WinSetWindowPos( GetHwnd() + ,HWND_TOP + ,(LONG)nX1 + ,(LONG)nY1 + ,(LONG)nWidth1 + ,(LONG)nHeight1 + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); } - if ( w1 < 0 ) - w1 = 20; - if ( h1 < 0 ) - h1 = 200; - MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); } - } -*/ -} +} // end of void wxSlider::DoSetSize -void wxSlider::SetRange(int minValue, int maxValue) +int wxSlider::GetLineSize() const { - m_rangeMin = minValue; - m_rangeMax = maxValue; + return 1; +} // end of wxSlider::GetLineSize - // TODO -} +int wxSlider::GetPageSize() const +{ + return m_nPageSize; +} // end of wxSlider::GetPageSize -WXHBRUSH wxSlider::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +void wxSlider::GetPosition( + int* pnX +, int* pnY +) const { - // TODO: -/* - if ( nCtlColor == CTLCOLOR_SCROLLBAR ) - return 0; + wxWindowOS2* pParent = GetParent(); + RECTL vRect; + + vRect.xLeft = -1; + vRect.xRight = -1; + vRect.yTop = -1; + vRect.yBottom = -1; + wxFindMaxSize( GetHWND() + ,&vRect + ); + + if (m_hStaticMin) + wxFindMaxSize( m_hStaticMin + ,&vRect + ); + if (m_hStaticMax) + wxFindMaxSize( m_hStaticMax + ,&vRect + ); + if (m_hStaticValue) + wxFindMaxSize( m_hStaticValue + ,&vRect + ); + + // + // Since we now have the absolute screen coords, + // if there's a parent we must subtract its top left corner + // + POINTL vPoint; + + vPoint.x = vRect.xLeft; + vPoint.y = vRect.yTop; + + if (pParent) + { + SWP vSwp; - // Otherwise, it's a static - if (GetParent()->GetTransparentBackground()) - SetBkMode((HDC) pDC, TRANSPARENT); - else - SetBkMode((HDC) pDC, OPAQUE); + ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp); + vPoint.x = vSwp.x; + vPoint.y = vSwp.y; + } - ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); - ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); + // + // We may be faking the client origin. + // So a window that's really at (0, 30) may appear + // (to wxWin apps) to be at (0, 0). + // + if (GetParent()) + { + wxPoint vPt(GetParent()->GetClientAreaOrigin()); - wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); - return (WXHBRUSH) backgroundBrush->GetResourceHandle(); -*/ - return (WXHBRUSH)0; -} + vPoint.x -= vPt.x; + vPoint.y -= vPt.y; + } + *pnX = vPoint.x; + *pnY = vPoint.y; +} // end of wxSlider::GetPosition -// For trackbars only -void wxSlider::SetTickFreq(int n, int pos) +int wxSlider::GetSelEnd() const { - // TODO - m_tickFreq = n; -} + return 0; +} // end of wxSlider::GetSelEnd -void wxSlider::SetPageSize(int pageSize) +int wxSlider::GetSelStart() const { - // TODO - m_pageSize = pageSize; -} + return 0; +} // end of wxSlider::GetSelStart -int wxSlider::GetPageSize() const +void wxSlider::GetSize( + int* pnWidth +, int* pnHeight +) const { - return m_pageSize; -} + RECTL vRect; + + vRect.xLeft = -1; + vRect.xRight = -1; + vRect.yTop = -1; + vRect.yBottom = -1; + + wxFindMaxSize( GetHWND() + ,&vRect + ); + + if (m_hStaticMin) + wxFindMaxSize( m_hStaticMin + ,&vRect + ); + if (m_hStaticMax) + wxFindMaxSize( m_hStaticMax + ,&vRect + ); + if (m_hStaticValue) + wxFindMaxSize( m_hStaticValue + ,&vRect + ); + *pnWidth = vRect.xRight - vRect.xLeft; + *pnHeight = vRect.yBottom - vRect.yTop; +} // end of wxSlider::GetSize -void wxSlider::ClearSel() +int wxSlider::GetThumbLength() const { - // TODO -} + return m_nThumbLength; +} // end of wxSlider::GetThumbLength -void wxSlider::ClearTicks() +int wxSlider::GetValue() const { - // TODO -} - -void wxSlider::SetLineSize(int lineSize) + int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ); + double dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin); + int nNewPos = 0; + int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SLIDERARMPOSITION + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ); + nNewPos = (int)(nPixelPos/dPixelToRange); + if (nNewPos > (m_nRangeMax - m_nRangeMin)/2) + nNewPos++; + return nNewPos; +} // end of wxSlider::GetValue + +WXHBRUSH wxSlider::OnCtlColor( + WXHDC hDC +, WXHWND hWnd +, WXUINT uCtlColor +, WXUINT uMessage +, WXWPARAM wParam +, WXLPARAM lParam +) { - m_lineSize = lineSize; - // TODO -} - -int wxSlider::GetLineSize() const + return (wxControl::OnCtlColor( hDC + ,hWnd + ,uCtlColor + ,uMessage + ,wParam + ,lParam + ) + ); +} // end of wxSlider::OnCtlColor + +bool wxSlider::OS2OnScroll( + int WXUNUSED(nOrientation) +, WXWORD wParam +, WXWORD wPos +, WXHWND hControl +) { - // TODO - return 0; -} + wxEventType eScrollEvent = wxEVT_NULL; -int wxSlider::GetSelEnd() const -{ - // TODO - return 0; -} + switch (wParam) + { + case SLN_CHANGE: + if (m_windowStyle & wxSL_TOP) + eScrollEvent = wxEVT_SCROLL_TOP; + else if (m_windowStyle & wxSL_BOTTOM) + eScrollEvent = wxEVT_SCROLL_BOTTOM; + break; -int wxSlider::GetSelStart() const + case SLN_SLIDERTRACK: + eScrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; + + default: + return FALSE; + } + + int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ); + m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin); + int nNewPos = 0; + int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SLIDERARMPOSITION + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ); + nNewPos = (nPixelPos/m_dPixelToRange); + if (nNewPos > (m_nRangeMax - m_nRangeMin)/2) + nNewPos++; + if ((nNewPos < GetMin()) || (nNewPos > GetMax())) + { + // + // Out of range - but we did process it + // + return TRUE; + } + SetValue(nNewPos); + + wxScrollEvent vEvent( eScrollEvent + ,m_windowId + ); + + vEvent.SetPosition(nNewPos); + vEvent.SetEventObject(this); + GetEventHandler()->ProcessEvent(vEvent); + + wxCommandEvent vCevent( wxEVT_COMMAND_SLIDER_UPDATED + ,GetId() + ); + + vCevent.SetInt(nNewPos); + vCevent.SetEventObject(this); + return (GetEventHandler()->ProcessEvent(vCevent)); +} // end of wxSlider::OS2OnScroll + +void wxSlider::SetLineSize( + int nLineSize +) { - // TODO - return 0; -} + m_nLineSize = nLineSize; +} // end of wxSlider::SetLineSize + -void wxSlider::SetSelection(int minPos, int maxPos) +void wxSlider::SetPageSize( + int nPageSize +) { - // TODO -} + m_nPageSize = nPageSize; +} // end of wxSlider::SetPageSize -void wxSlider::SetThumbLength(int len) +void wxSlider::SetRange( + int nMinValue +, int nMaxValue +) { - // TODO -} + wxChar zBuf[10]; + + m_nRangeMin = nMinValue; + m_nRangeMax = nMaxValue; + + int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ); + m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin); + if (m_hStaticMin) + { + wxSprintf(zBuf, wxT("%d"), m_nRangeMin); + ::WinSetWindowText((HWND)m_hStaticMin, zBuf); + } -int wxSlider::GetThumbLength() const + if (m_hStaticMax) + { + wxSprintf(zBuf, wxT("%d"), m_nRangeMax); + ::WinSetWindowText((HWND)m_hStaticMax, zBuf); + } +} // end of wxSlider::SetRange + +void wxSlider::SetSelection( + int WXUNUSED(nMinPos) +, int WXUNUSED(nMaxPos) +) { - // TODO - return 0; -} +} // end of wxSlider::SetSelection -void wxSlider::SetTick(int tickPos) +void wxSlider::SetThumbLength( + int nLen +) { - // TODO -} + int nBreadth; + + m_nThumbLength = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ) + 4; // for bordersizes + nBreadth = SHORT2FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ); + ::WinSendMsg( GetHwnd() + ,SLM_SETSLIDERINFO + ,MPFROM2SHORT( SMA_SLIDERARMDIMENSIONS + ,SMA_RANGEVALUE + ) + ,MPFROM2SHORT(nLen, nBreadth) + ); + m_nThumbLength = nLen + 4; // Borders +} // end of wxSlider::SetThumbLength + +void wxSlider::SetTick( + int nTickPos +) +{ + nTickPos *= m_dPixelToRange; + ::WinSendMsg( GetHwnd() + ,SLM_ADDDETENT + ,MPFROMSHORT(nTickPos) + ,NULL + ); +} // end of wxSlider::SetTick -bool wxSlider::ContainsHWND(WXHWND hWnd) const +// For trackbars only +void wxSlider::SetTickFreq( + int n +, int nPos +) { - return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); -} + SLDCDATA vSlData; + WNDPARAMS vWndParams; + int nPixelPos; + int i; -void wxSlider::Command (wxCommandEvent & event) + vSlData.cbSize = sizeof(SLDCDATA); + if (m_windowStyle & wxSL_AUTOTICKS) + { + vSlData.usScale1Spacing = 0; + vSlData.usScale2Spacing = 0; + } + vSlData.usScale1Increments = (m_nRangeMax - m_nRangeMin)/n; + vSlData.usScale2Increments = (m_nRangeMax - m_nRangeMin)/n; + + vWndParams.fsStatus = WPM_CTLDATA; + vWndParams.cchText = 0L; + vWndParams.pszText = NULL; + vWndParams.cbPresParams = 0L; + vWndParams.pPresParams = NULL; + vWndParams.cbCtlData = vSlData.cbSize; + vWndParams.pCtlData = (PVOID)&vSlData; + ::WinSendMsg(GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)0); + for (i = 1; i < (m_nRangeMax - m_nRangeMin)/n; i++) + { + nPixelPos = i * n * m_dPixelToRange; + ::WinSendMsg( GetHwnd() + ,SLM_ADDDETENT + ,MPFROMSHORT(nPixelPos) + ,NULL + ); + } +} // end of wxSlider::SetTickFreq + +void wxSlider::SetValue( + int nValue +) { - SetValue (event.GetInt()); - ProcessCommand (event); -} + int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SLIDERARMPOSITION + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ); + int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd() + ,SLM_QUERYSLIDERINFO + ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS + ,SMA_RANGEVALUE + ) + ,(MPARAM)0 + ) + ); + m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin); + int nNewPos = (int)(nValue * m_dPixelToRange); + + ::WinSendMsg( GetHwnd() + ,SLM_SETSLIDERINFO + ,MPFROM2SHORT( SMA_SLIDERARMPOSITION + ,SMA_RANGEVALUE + ) + ,(MPARAM)nNewPos + ); + if (m_hStaticValue) + { + wxSprintf(wxBuffer, wxT("%d"), nValue); + ::WinSetWindowText((HWND)m_hStaticValue, wxBuffer); + } +} // end of wxSlider::SetValue -bool wxSlider::Show(bool show) +bool wxSlider::Show( + bool bShow +) { - // TODO + wxWindowOS2::Show(bShow); + if(m_hStaticValue) + ::WinShowWindow((HWND)m_hStaticValue, bShow); + if(m_hStaticMin) + ::WinShowWindow((HWND)m_hStaticMin, bShow); + if(m_hStaticMax) + ::WinShowWindow((HWND)m_hStaticMax, bShow); return TRUE; -} +} // end of wxSlider::Show diff --git a/src/os2/spinbutt.cpp b/src/os2/spinbutt.cpp index 99e5852636..6e58a26322 100644 --- a/src/os2/spinbutt.cpp +++ b/src/os2/spinbutt.cpp @@ -29,6 +29,11 @@ #include "wx/spinbutt.h" +extern void wxAssociateWinWithHandle( HWND hWnd + ,wxWindowOS2* pWin + ); +static WXFARPROC fnWndProcSpinCtrl = (WXFARPROC)NULL; + IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent) #include "wx/os2/private.h" @@ -44,29 +49,106 @@ IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent) IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) bool wxSpinButton::Create( - wxWindow* parent -, wxWindowID id -, const wxPoint& pos -, const wxSize& size -, long style -, const wxString& name + wxWindow* pParent +, wxWindowID vId +, const wxPoint& rPos +, const wxSize& rSize +, long lStyle +, const wxString& rsName ) { - SetName(name); - - m_windowStyle = style; - - SetParent(parent); - - m_windowId = (id == -1) ? NewControlId() : id; + int nX = rPos.x; + int nY = rPos.y; + int nWidth = rSize.x; + int nHeight = rSize.y; + + m_min = 0; + m_max = 100; + if (vId == -1) + m_windowId = NewControlId(); + else + m_windowId = vId; + m_backgroundColour = pParent->GetBackgroundColour(); + m_foregroundColour = pParent->GetForegroundColour(); + SetName(rsName); + SetParent(pParent); + m_windowStyle = lStyle; + + // + // Get the right size for the control + // + if (nWidth <= 0 || nHeight <= 0 ) + { + wxSize vSize = DoGetBestSize(); - // TODO create spin button - return FALSE; -} + if (nWidth <= 0 ) + nWidth = vSize.x; + if (nHeight <= 0 ) + nHeight = vSize.y; + } + if (nX < 0 ) + nX = 0; + if (nY < 0 ) + nY = 0; + + long lSstyle = 0L; + + lSstyle = WS_VISIBLE | + WS_TABSTOP | + SPBS_MASTER | // We use only single field spin buttons + SPBS_NUMERICONLY; // We default to numeric data + + if (m_windowStyle & wxCLIP_SIBLINGS ) + lSstyle |= WS_CLIPSIBLINGS; + + SPBCDATA vCtrlData; + + vCtrlData.cbSize = sizeof(SPBCDATA); + vCtrlData.ulTextLimit = 10L; + vCtrlData.lLowerLimit = 0L; + vCtrlData.lUpperLimit = 100L; + vCtrlData.idMasterSpb = vId; + vCtrlData.pHWXCtlData = NULL; + + m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) + ,WC_SPINBUTTON + ,(PSZ)NULL + ,lSstyle + ,0L, 0L, 0L, 0L + ,GetWinHwnd(pParent) + ,HWND_TOP + ,(HMENU)vId + ,(PVOID)&vCtrlData + ,NULL + ); + if (m_hWnd == 0) + { + return FALSE; + } + if(pParent) + pParent->AddChild((wxSpinButton *)this); + + SetFont(pParent->GetFont()); + // + // For OS/2 we want to hide the text portion so we can substitute an + // independent text ctrl in its place. 10 device units does this + // + SetSize( nX + ,nY + ,10L + ,nHeight + ); + wxAssociateWinWithHandle( m_hWnd + ,(wxWindowOS2*)this + ); + ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this); + fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc); + return TRUE; +} // end of wxSpinButton::Create wxSpinButton::~wxSpinButton() { -} +} // end of wxSpinButton::~wxSpinButton // ---------------------------------------------------------------------------- // size calculation @@ -74,23 +156,12 @@ wxSpinButton::~wxSpinButton() wxSize wxSpinButton::DoGetBestSize() const { - // TODO: -/* - if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 ) - { - // vertical control - return wxSize(GetSystemMetrics(SM_CXVSCROLL), - 2*GetSystemMetrics(SM_CYVSCROLL)); - } - else - { - // horizontal control - return wxSize(2*GetSystemMetrics(SM_CXHSCROLL), - GetSystemMetrics(SM_CYHSCROLL)); - } -*/ - return wxSize(0, 0); -} + // + // OS/2 PM does not really have system metrics so we'll just set our best guess + // Also we have no horizontal spin buttons. + // + return (wxSize(10,20)); +} // end of wxSpinButton::DoGetBestSize // ---------------------------------------------------------------------------- // Attributes @@ -98,66 +169,68 @@ wxSize wxSpinButton::DoGetBestSize() const int wxSpinButton::GetValue() const { - // TODO - return 0; -} - -void wxSpinButton::SetValue(int val) -{ - // TODO -} - -void wxSpinButton::SetRange(int minVal, int maxVal) + int nVal = 0; + long lVal = 0L; + char zVal[10]; + + ::WinSendMsg( GetHwnd() + ,SPBM_QUERYVALUE + ,MPFROMP(zVal) + ,MPFROM2SHORT( (USHORT)10 + ,SPBQ_UPDATEIFVALID + ) + ); + lVal = atol(zVal); + return ((int)lVal); +} // end of wxSpinButton::GetValue + +bool wxSpinButton::OS2OnScroll( + int nOrientation +, WXWORD wParam +, WXWORD wPos +, WXHWND hControl +) { - // TODO -} + wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") ) -bool wxSpinButton::OS2OnScroll(int orientation, WXWORD wParam, - WXWORD pos, WXHWND control) -{ - wxCHECK_MSG( control, FALSE, wxT("scrolling what?") ) -// TODO: -/* - if ( wParam != SB_THUMBPOSITION ) - { - // probable SB_ENDSCROLL - we don't react to it - return FALSE; - } - - wxSpinEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); - event.SetPosition((short)pos); // cast is important for negative values! - event.SetEventObject(this); + wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK + ,m_windowId + ); + int nVal = (int)wPos; // cast is important for negative values! - return GetEventHandler()->ProcessEvent(event); -*/ - return FALSE; -} + vEvent.SetPosition(nVal); + vEvent.SetEventObject(this); + return(GetEventHandler()->ProcessEvent(vEvent)); +} // end of wxSpinButton::OS2OnScroll -bool wxSpinButton::OS2OnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) +bool wxSpinButton::OS2Command( + WXUINT uCmd +, WXWORD wId +) { - // TODO: -/* - LPNM_UPDOWN lpnmud = (LPNM_UPDOWN)lParam; - - wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP - : wxEVT_SCROLL_LINEDOWN, - m_windowId); - event.SetPosition(lpnmud->iPos + lpnmud->iDelta); - event.SetEventObject(this); - - bool processed = GetEventHandler()->ProcessEvent(event); - - *result = event.IsAllowed() ? 0 : 1; - - return processed; -*/ return FALSE; -} +} // end of wxSpinButton::OS2Command -bool wxSpinButton::OS2Command(WXUINT cmd, WXWORD id) +void wxSpinButton::SetRange( + int nMinVal +, int nMaxVal +) { - // No command messages - return FALSE; -} + m_min = nMinVal; + m_max = nMaxVal; + + ::WinSendMsg( GetHwnd() + ,SPBM_SETLIMITS + ,MPFROMLONG(nMaxVal) + ,MPFROMLONG(nMinVal) + ); +} // end of wxSpinButton::SetRange + +void wxSpinButton::SetValue( + int nValue +) +{ + ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0)); +} // end of wxSpinButton::SetValue #endif //wxUSE_SPINBTN diff --git a/src/os2/spinctrl.cpp b/src/os2/spinctrl.cpp index aa6b5bf2d8..ed056cafaf 100644 --- a/src/os2/spinctrl.cpp +++ b/src/os2/spinctrl.cpp @@ -40,6 +40,11 @@ // macros // ---------------------------------------------------------------------------- +extern void wxAssociateWinWithHandle( HWND hWnd + ,wxWindowOS2* pWin + ); +static WXFARPROC fnWndProcSpinCtrl = (WXFARPROC)NULL; + IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl, wxControl) BEGIN_EVENT_TABLE(wxSpinCtrl, wxSpinButton) @@ -55,244 +60,423 @@ static const int MARGIN_BETWEEN = 5; // ============================================================================ // implementation // ============================================================================ - -// ---------------------------------------------------------------------------- -// construction -// ---------------------------------------------------------------------------- - -bool wxSpinCtrl::Create(wxWindow *parent, - wxWindowID id, - const wxString& value, - const wxPoint& pos, - const wxSize& size, - long style, - int min, int max, int initial, - const wxString& name) +MRESULT EXPENTRY wxSpinCtrlWndProc( + HWND hWnd +, UINT uMessage +, MPARAM wParam +, MPARAM lParam +) { - // TODO: -/* - // before using DoGetBestSize(), have to set style to let the base class - // know whether this is a horizontal or vertical control (we're always - // vertical) - style |= wxSP_VERTICAL; - SetWindowStyle(style); - - // calculate the sizes: the size given is the toal size for both controls - // and we need to fit them both in the given width (height is the same) - wxSize sizeText(size), sizeBtn(size); - sizeBtn.x = wxSpinButton::DoGetBestSize().x; - if ( sizeText.x <= 0 ) + wxSpinCtrl* pSpin = (wxSpinCtrl *)::WinQueryWindowULong( hWnd + ,QWL_USER + ); + bool bProccesed = FALSE; + MRESULT rc = (MRESULT)0; + // + // Forward some messages (the key ones only so far) to the spin ctrl + // + switch (uMessage ) { - // DEFAULT_ITEM_WIDTH is the default width for the text control - sizeText.x = DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN + sizeBtn.x; - } + case WM_CHAR: + pSpin->OS2WindowProc( uMessage + ,wParam + ,lParam + ); + + // + // The control may have been deleted at this point, so check. + // + if (!(::WinIsWindow(vHabmain, hWnd) && ((wxSpinCtrl *)::WinQueryWindowULong( hWnd + ,QWL_USER + ) + ) == pSpin)) + return 0; + break; - sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; - if ( sizeText.x <= 0 ) - { - wxLogDebug(_T("not enough space for wxSpinCtrl!")); } + return (fnWndProcSpinCtrl( hWnd + ,(ULONG)uMessage + ,(MPARAM)wParam + ,(MPARAM)lParam + ) + ); +} // end of wxSpinCtrlWndProc + +wxSpinCtrl::~wxSpinCtrl() +{ + m_svAllSpins.Remove(this); - wxPoint posBtn(pos); - posBtn.x += sizeText.x + MARGIN_BETWEEN; + // This removes spurious memory leak reporting + if (m_svAllSpins.GetCount() == 0) + m_svAllSpins.Clear(); +} // end of wxSpinCtrl::~wxSpinCtrl - // create the spin button - if ( !wxSpinButton::Create(parent, id, posBtn, sizeBtn, style, name) ) +// ---------------------------------------------------------------------------- +// construction +// ---------------------------------------------------------------------------- + +bool wxSpinCtrl::Create( + wxWindow* pParent +, wxWindowID vId +, const wxString& rsValue +, const wxPoint& rPos +, const wxSize& rSize +, long lStyle +, int nMin +, int nMax +, int nInitial +, const wxString& rsName +) +{ + if (vId == -1) + m_windowId = NewControlId(); + else + m_windowId = vId; + m_backgroundColour = pParent->GetBackgroundColour(); + m_foregroundColour = pParent->GetForegroundColour(); + SetName(rsName); + SetParent(pParent); + m_windowStyle = lStyle; + + int lSstyle = 0L; + + lSstyle = WS_VISIBLE | + WS_TABSTOP | + SPBS_MASTER | // We use only single field spin buttons + SPBS_NUMERICONLY; // We default to numeric data + + if (m_windowStyle & wxCLIP_SIBLINGS ) + lSstyle |= WS_CLIPSIBLINGS; + + SPBCDATA vCtrlData; + + vCtrlData.cbSize = sizeof(SPBCDATA); + vCtrlData.ulTextLimit = 10L; + vCtrlData.lLowerLimit = 0L; + vCtrlData.lUpperLimit = 100L; + vCtrlData.idMasterSpb = vId; + vCtrlData.pHWXCtlData = NULL; + + m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) + ,WC_SPINBUTTON + ,(PSZ)NULL + ,lSstyle + ,0L, 0L, 0L, 0L + ,GetWinHwnd(pParent) + ,HWND_TOP + ,(HMENU)vId + ,(PVOID)&vCtrlData + ,NULL + ); + if (m_hWnd == 0) { return FALSE; } + m_hWndBuddy = m_hWnd; // One in the same for OS/2 + if(pParent) + pParent->AddChild((wxSpinButton *)this); + SetFont(pParent->GetFont()); + SetSize( rPos.x + ,rPos.y + ,rSize.x + ,rSize.y + ); + + SetRange(nMin, nMax); + SetValue(nInitial); + + // + // For OS/2 we'll just set our handle into our long data + // + wxAssociateWinWithHandle( m_hWnd + ,(wxWindowOS2*)this + ); + ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this); + fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc); + m_svAllSpins.Add(this); + return TRUE; +} // end of wxSpinCtrl::Create - SetRange(min, max); - SetValue(initial); - - // create the text window - m_hwndBuddy = (WXHWND)::CreateWindowEx - ( - WS_EX_CLIENTEDGE, // sunken border - _T("EDIT"), // window class - NULL, // no window title - WS_CHILD | WS_BORDER, // style (will be shown later) - pos.x, pos.y, // position - 0, 0, // size (will be set later) - GetHwndOf(parent), // parent - (HMENU)-1, // control id - wxGetInstance(), // app instance - NULL // unused client data - ); - - if ( !m_hwndBuddy ) - { - wxLogLastError("CreateWindow(buddy text window)"); +wxSize wxSpinCtrl::DoGetBestSize() const +{ + wxSize vSizeBtn = wxSpinButton::DoGetBestSize(); + int nHeight; - return FALSE; - } + vSizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN; - // should have the same font as the other controls - SetFont(GetParent()->GetFont()); + wxGetCharSize( GetHWND() + ,NULL + ,&nHeight + ,(wxFont*)&GetFont() + ); + nHeight = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nHeight); - // set the size of the text window - can do it only now, because we - // couldn't call DoGetBestSize() before as font wasn't set - if ( sizeText.y <= 0 ) + if (vSizeBtn.y < nHeight) { - int cx, cy; - wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); - - sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); + // + // Make the text tall enough + // + vSizeBtn.y = nHeight; } + return vSizeBtn; +} // end of wxSpinCtrl::DoGetBestSize - DoMoveWindow(pos.x, pos.y, - sizeText.x + sizeBtn.x + MARGIN_BETWEEN, sizeText.y); - - (void)::ShowWindow((HWND)m_hwndBuddy, SW_SHOW); - - // associate the text window with the spin button - (void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0); +void wxSpinCtrl::DoGetPosition( + int* pnX +, int* pnY +) const +{ + WXHWND hWnd = GetHWND(); + + wxConstCast(this, wxSpinCtrl)->m_hWnd = m_hWndBuddy; + wxSpinButton::DoGetPosition( pnX + ,pnY + ); + wxConstCast(this, wxSpinCtrl)->m_hWnd = hWnd; +} // end of wxpinCtrl::DoGetPosition + +void wxSpinCtrl::DoGetSize( + int* pnWidth +, int* pnHeight +) const +{ + RECTL vSpinrect; + + ::WinQueryWindowRect(GetHwnd(), &vSpinrect); + + if (pnWidth) + *pnWidth = vSpinrect.xRight - vSpinrect.xLeft; + if (pnHeight) + *pnHeight = vSpinrect.yTop - vSpinrect.yBottom; +} // end of wxSpinCtrl::DoGetSize + +void wxSpinCtrl::DoMoveWindow( + int nX +, int nY +, int nWidth +, int nHeight +) +{ + wxWindowOS2* pParent = (wxWindowOS2*)GetParent(); - if ( !value.IsEmpty() ) + if (pParent) { - SetValue(value); + if (pParent->IsKindOf(CLASSINFO(wxFrame))) + { + nY = pParent->GetClientSize().y - (nY + nHeight); + } + else + nY = pParent->GetSize().y - (nY + nHeight); } -*/ - return FALSE; -} - -// ---------------------------------------------------------------------------- -// wxTextCtrl-like methods -// ---------------------------------------------------------------------------- + else + { + RECTL vRect; -void wxSpinCtrl::SetValue(const wxString& text) + ::WinQueryWindowRect(HWND_DESKTOP, &vRect); + nY = vRect.yTop - (nY + nHeight); + } + ::WinSetWindowPos( GetHwnd() + ,HWND_TOP + ,nX + ,nY + ,nWidth + ,nHeight + ,SWP_SIZE | SWP_MOVE | SWP_ZORDER | SWP_SHOW + ); +} // end of wxSpinCtrl::DoMoveWindow + +bool wxSpinCtrl::Enable( + bool bEnable +) { - // TODO: - /* - if ( !::SetWindowText((HWND)m_hwndBuddy, text.c_str()) ) + if (!wxControl::Enable(bEnable)) { - wxLogLastError("SetWindowText(buddy)"); + return FALSE; } - */ -} + ::WinEnableWindow(GetHwnd(), bEnable); + return TRUE; +} // end of wxSpinCtrl::Enable -int wxSpinCtrl::GetValue() const +wxSpinCtrl* wxSpinCtrl::GetSpinForTextCtrl( + WXHWND hWndBuddy +) { - wxString val = wxGetWindowText(m_hwndBuddy); + wxSpinCtrl* pSpin = (wxSpinCtrl *)::WinQueryWindowULong( (HWND)hWndBuddy + ,QWL_USER + ); + int i = m_svAllSpins.Index(pSpin); - long n; - if ( (wxSscanf(val, wxT("%lu"), &n) != 1) ) - n = INT_MIN; + if (i == wxNOT_FOUND) + return NULL; - return n; -} + // sanity check + wxASSERT_MSG( pSpin->m_hWndBuddy == hWndBuddy, + _T("wxSpinCtrl has incorrect buddy HWND!") ); -// ---------------------------------------------------------------------------- -// forward some methods to subcontrols -// ---------------------------------------------------------------------------- + return pSpin; +} // end of wxSpinCtrl::GetSpinForTextCtrl -bool wxSpinCtrl::SetFont(const wxFont& font) +int wxSpinCtrl::GetValue() const { - if ( !wxWindowBase::SetFont(font) ) + long lVal = 0L; + char zVal[10]; + + ::WinSendMsg( GetHwnd() + ,SPBM_QUERYVALUE + ,MPFROMP(zVal) + ,MPFROM2SHORT( (USHORT)10 + ,SPBQ_UPDATEIFVALID + ) + ); + lVal - atol(zVal); + return lVal; +} // end of wxSpinCtrl::GetValue + +void wxSpinCtrl::OnChar ( + wxKeyEvent& rEvent +) +{ + switch (rEvent.KeyCode()) { - // nothing to do - return FALSE; + case WXK_RETURN: + { + wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_ENTER + ,m_windowId + ); + wxString sVal = wxGetWindowText(m_hWndBuddy); + + InitCommandEvent(vEvent); + vEvent.SetString((char*)sVal.c_str()); + vEvent.SetInt(GetValue()); + if (GetEventHandler()->ProcessEvent(vEvent)) + return; + break; + } + + case WXK_TAB: + // + // Always produce navigation event - even if we process TAB + // ourselves the fact that we got here means that the user code + // decided to skip processing of this TAB - probably to let it + // do its default job. + // + { + wxNavigationKeyEvent vEventNav; + + vEventNav.SetDirection(!rEvent.ShiftDown()); + vEventNav.SetWindowChange(rEvent.ControlDown()); + vEventNav.SetEventObject(this); + if (GetParent()->GetEventHandler()->ProcessEvent(vEventNav)) + return; + } + break; } - WXHANDLE hFont = GetFont().GetResourceHandle(); - // TODO: - /* - (void)::SendMessage((HWND)m_hwndBuddy, WM_SETFONT, (WPARAM)hFont, TRUE); - */ - return TRUE; -} + // + // No, we didn't process it + // + rEvent.Skip(); +} // end of wxSpinCtrl::OnChar -bool wxSpinCtrl::Show(bool show) +void wxSpinCtrl::OnSpinChange( + wxSpinEvent& rEventSpin +) { - if ( !wxControl::Show(show) ) + wxCommandEvent vEvent( wxEVT_COMMAND_SPINCTRL_UPDATED + ,GetId() + ); + + vEvent.SetEventObject(this); + vEvent.SetInt(rEventSpin.GetPosition()); + (void)GetEventHandler()->ProcessEvent(vEvent); + if (rEventSpin.GetSkipped()) { - return FALSE; + vEvent.Skip(); } +} // end of wxSpinCtrl::OnSpinChange - // TODO: - /* - ::ShowWindow((HWND)m_hwndBuddy, show ? SW_SHOW : SW_HIDE); - */ - return TRUE; -} - -bool wxSpinCtrl::Enable(bool enable) +bool wxSpinCtrl::ProcessTextCommand( + WXWORD wCmd +, WXWORD wId +) { - if ( !wxControl::Enable(enable) ) + switch (wCmd) { - return FALSE; + case SPBN_CHANGE: + { + wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_UPDATED + ,GetId() + ); + vEvent.SetEventObject(this); + + wxString sVal = wxGetWindowText(m_hWndBuddy); + + vEvent.SetString((char*)sVal.c_str()); + vEvent.SetInt(GetValue()); + return (GetEventHandler()->ProcessEvent(vEvent)); + } + + case SPBN_SETFOCUS: + case SPBN_KILLFOCUS: + { + wxFocusEvent vEvent( wCmd == EN_KILLFOCUS ? wxEVT_KILL_FOCUS : wxEVT_SET_FOCUS + ,m_windowId + ); + + vEvent.SetEventObject(this); + return(GetEventHandler()->ProcessEvent(vEvent)); + } + default: + break; } - // TODO: - /* - ::EnableWindow((HWND)m_hwndBuddy, enable); - */ - return TRUE; -} - -// ---------------------------------------------------------------------------- -// event processing -// ---------------------------------------------------------------------------- + // + // Not processed + // + return FALSE; +} // end of wxSpinCtrl::ProcessTextCommand -void wxSpinCtrl::OnSpinChange(wxSpinEvent& eventSpin) +void wxSpinCtrl::SetFocus() { - wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, GetId()); - event.SetEventObject(this); - event.SetInt(eventSpin.GetPosition()); - - (void)GetEventHandler()->ProcessEvent(event); + ::WinSetFocus(HWND_DESKTOP, GetHwnd()); +} // end of wxSpinCtrl::SetFocus - if ( eventSpin.GetSkipped() ) +bool wxSpinCtrl::SetFont( + const wxFont& rFont +) +{ + if (!wxWindowBase::SetFont(rFont)) { - event.Skip(); + // nothing to do + return FALSE; } -} -// ---------------------------------------------------------------------------- -// size calculations -// ---------------------------------------------------------------------------- + WXHANDLE hFont = GetFont().GetResourceHandle(); + wxOS2SetFont( m_hWnd + ,rFont + ); + return TRUE; +} // end of wxSpinCtrl::SetFont -wxSize wxSpinCtrl::DoGetBestSize() const +void wxSpinCtrl::SetValue( + const wxString& rsText +) { - wxSize sizeBtn = wxSpinButton::DoGetBestSize(); - // TODO: - /* - sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN; + long lVal; - int y; - wxGetCharSize(GetHWND(), NULL, &y, &GetFont()); - y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(y); + lVal = atol(rsText.c_str()); + wxSpinButton::SetValue(lVal); +} // end of wxSpinCtrl::SetValue - if ( sizeBtn.y < y ) - { - // make the text tall enough - sizeBtn.y = y; - } - */ - return sizeBtn; -} - -void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) +bool wxSpinCtrl::Show( + bool bShow +) { - int widthBtn = DoGetBestSize().x; - int widthText = width - widthBtn - MARGIN_BETWEEN; - if ( widthText <= 0 ) - { - wxLogDebug(_T("not enough space for wxSpinCtrl!")); - } -// TODO: -/* - if ( !::MoveWindow((HWND)m_hwndBuddy, x, y, widthText, height, TRUE) ) - { - wxLogLastError("MoveWindow(buddy)"); - } - - x += widthText + MARGIN_BETWEEN; - if ( !::MoveWindow(GetHwnd(), x, y, widthBtn, height, TRUE) ) + if (!wxControl::Show(bShow)) { - wxLogLastError("MoveWindow"); + return FALSE; } -*/ -} + return TRUE; +} // end of wxSpinCtrl::Show #endif //wxUSE_SPINBTN \ No newline at end of file diff --git a/src/os2/statbox.cpp b/src/os2/statbox.cpp index 85270d2462..16a28e6c60 100644 --- a/src/os2/statbox.cpp +++ b/src/os2/statbox.cpp @@ -24,175 +24,94 @@ IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) -BEGIN_EVENT_TABLE(wxStaticBox, wxControl) - EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground) -END_EVENT_TABLE() - - -/* - * Group box - */ - -bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) +bool wxStaticBox::Create( + wxWindow* pParent +, wxWindowID vId +, const wxString& rsLabel +, const wxPoint& rPos +, const wxSize& rSize +, long lStyle +, const wxString& rsName +) { - SetName(name); - - if (parent) parent->AddChild(this); - - SetBackgroundColour(parent->GetBackgroundColour()) ; - SetForegroundColour(parent->GetForegroundColour()) ; - - 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; - - m_windowStyle = style; - -// TODO: -/* - long msStyle = BS_GROUPBOX | WS_CHILD | WS_VISIBLE ; // GROUP_FLAGS; - - bool want3D; - WXDWORD exStyle = Determine3DEffects(0, &want3D) ; - - HWND wx_button = - CreateWindowEx(exStyle, wxT("BUTTON"), (const wxChar *)label, msStyle, - 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, - wxGetInstance(), NULL); -#if wxUSE_CTL3D - if (want3D) - { - Ctl3dSubclassCtl(wx_button); - m_useCtl3D = TRUE; - } + if(!OS2CreateControl( pParent + ,vId + ,rPos + ,rSize + ,lStyle +#if wxUSE_VALIDATORS + ,wxDefaultValidator #endif + ,rsName + )) + { + return FALSE; + } - m_hWnd = (WXHWND)wx_button; - - // Subclass again for purposes of dialog editing mode - SubclassWin(GetHWND()); - - SetFont(parent->GetFont()); + wxPoint vPos(0,0); + wxSize vSize(0,0); - SetSize(x, y, width, height); - ShowWindow(wx_button, SW_SHOW); -*/ - return FALSE; -} + if (!OS2CreateControl( "STATIC" + ,SS_GROUPBOX + ,vPos + ,vSize + ,rsLabel + )) + { + return FALSE; + } -wxSize wxStaticBox::DoGetBestSize() const -{ - int cx, cy; - wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont()); + wxColour vColour; - int wBox; - GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy); + vColour.Set(wxString("BLACK")); - wBox += 3*cx; - int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); + LONG lColor = (LONG)vColour.GetPixel(); - return wxSize(wBox, hBox); -} + ::WinSetPresParam( m_hWnd + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); + SetFont(pParent->GetFont()); + SetSize( rPos.x + ,rPos.y + ,rSize.x + ,rSize.y + ); + return TRUE; +} // end of wxStaticBox::Create -WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, - WXWPARAM wParam, - WXLPARAM lParam) -{ - // TODO: -/* - 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(); -*/ - return (WXHBRUSH)0; -} - -// Shouldn't erase the whole window, since the static box must only paint its -// outline. -void wxStaticBox::OnEraseBackground(wxEraseEvent& event) +wxSize wxStaticBox::DoGetBestSize() const { - // If we don't have this (call Default()), we don't paint the background properly. - // If we do have this, we seem to overwrite enclosed controls. - // Is it the WS_CLIPCHILDREN style that's causing the problems? - // Probably - without this style, the background of the window will show through, - // so the control doesn't have to paint it. The window background will always be - // painted before all other controls, therefore there are no problems with - // controls being hidden by the static box. - // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better. - // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel. - // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass - // this information from arbitrary wxWindow derivatives, and it depends on what you wish to - // do with the windows. - // Alternatively, just make sure that wxStaticBox is always at the back! There are probably - // few other circumstances where it matters about child clipping. But what about painting onto - // to panel, inside a groupbox? Doesn't appear, because the box wipes it out. - wxWindow *parent = GetParent(); -// TODO: -/* - if ( parent && parent->GetHWND() && (::GetWindowLong((HWND) parent->GetHWND(), GWL_STYLE) & WS_CLIPCHILDREN) ) - { - // TODO: May in fact need to generate a paint event for inside this - // control's rectangle, otherwise all controls are going to be clipped - - // ugh. - HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); - int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT); - - RECT rect; - - ::GetClientRect(GetHwnd(), &rect); - ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush); - ::DeleteObject(hBrush); - ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode); - } - else - { - event.Skip(); - } -*/ -} - -MRESULT wxStaticBox::OS2WindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) + int nCx; + int nCy; + int wBox; + + wxGetCharSize( GetHWND() + ,&nCx + ,&nCy + ,(wxFont*)&GetFont() + ); + GetTextExtent( wxGetWindowText(m_hWnd) + ,&wBox + ,&nCy + ); + wBox += 3 * nCx; + + int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy); + + return wxSize( wBox + ,hBox + ); +} // end of wxStaticBox::DoGetBestSize + +MRESULT wxStaticBox::OS2WindowProc( + WXUINT nMsg +, WXWPARAM wParam +, WXLPARAM lParam +) { - // TODO: -/* - if ( nMsg == WM_NCHITTEST) - { - int xPos = LOWORD(lParam); // horizontal position of cursor - int yPos = HIWORD(lParam); // vertical position of cursor - -// ScreenToClient(&xPos, &yPos); - - // Make sure you can drag by the top of the groupbox, but let - // other (enclosed) controls get mouse events also - if (yPos < 10) - return (long)HTCLIENT; - } -*/ - return wxControl::OS2WindowProc(nMsg, wParam, lParam); -} +} // end of wxStaticBox::OS2WindowProc diff --git a/src/os2/statline.cpp b/src/os2/statline.cpp index d14ffba774..687c060f00 100644 --- a/src/os2/statline.cpp +++ b/src/os2/statline.cpp @@ -40,48 +40,50 @@ IMPLEMENT_DYNAMIC_CLASS(wxStaticLine, wxControl) // wxStaticLine // ---------------------------------------------------------------------------- -bool wxStaticLine::Create( wxWindow *parent, - wxWindowID id, - const wxPoint &pos, - const wxSize &size, - long style, - const wxString &name) +bool wxStaticLine::Create( + wxWindow* pParent +, wxWindowID vId +, const wxPoint& rPos +, const wxSize& rSize +, long lStyle +, const wxString& rsName +) { - if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) + if (!CreateBase( pParent + ,vId + ,rPos + ,rSize + ,lStyle + ,wxDefaultValidator + ,rsName + )) return FALSE; - parent->AddChild(this); - - wxSize sizeReal = AdjustSize(size); - -// TODO: -/* - m_hWnd = (WXHWND)::CreateWindow - ( - wxT("STATIC"), - wxT(""), - WS_VISIBLE | WS_CHILD | - SS_GRAYRECT | SS_SUNKEN, // | SS_ETCHEDFRAME, - pos.x, pos.y, sizeReal.x, sizeReal.y, - GetWinHwnd(parent), - (HMENU)m_windowId, - wxGetInstance(), - NULL - ); - + pParent->AddChild(this); + + wxSize vSizeReal = AdjustSize(rSize); + + m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) + ,WC_STATIC + ,"" + ,WS_VISIBLE | SS_TEXT | DT_VCENTER | DT_CENTER + ,rPos.x + ,rPos.y + ,vSizeReal.x + ,vSizeReal.y + ,GetWinHwnd(pParent) + ,HWND_TOP + ,(ULONG)m_windowId + ,NULL + ,NULL + ); if ( !m_hWnd ) { -#ifdef __WXDEBUG__ wxLogDebug(wxT("Failed to create static control")); -#endif return FALSE; } - SubclassWin(m_hWnd); - return TRUE; -*/ - return FALSE; -} -#endif +} // end of wxStaticLine::Create +#endif // wxUSE_STATLINE diff --git a/src/os2/stattext.cpp b/src/os2/stattext.cpp index 141ccf59a3..cb8e29c0b3 100644 --- a/src/os2/stattext.cpp +++ b/src/os2/stattext.cpp @@ -80,10 +80,26 @@ bool wxStaticText::Create( wxCHECK_MSG(m_hWnd, FALSE, wxT("Failed to create static ctrl")); + wxColour vColour; + + vColour.Set(wxString("BLACK")); + + LONG lColor = (LONG)vColour.GetPixel(); + + ::WinSetPresParam( m_hWnd + ,PP_FOREGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + ); + SubclassWin(m_hWnd); wxControl::SetFont(pParent->GetFont()); - SetSize(nX, nY, nWidth, nHeight); - return FALSE; + SetSize( nX + ,nY + ,nWidth + ,nHeight + ); + return TRUE; } // end of wxStaticText::Create wxSize wxStaticText::DoGetBestSize() const @@ -96,7 +112,7 @@ wxSize wxStaticText::DoGetBestSize() const int nHeightLine = 0; wxString sCurLine; - for ( const wxChar *pc = sText; ; pc++ ) + for (const wxChar *pc = sText; ; pc++) { if ( *pc == wxT('\n') || *pc == wxT('\0') ) { @@ -143,39 +159,39 @@ wxSize wxStaticText::DoGetBestSize() const ); } // end of wxStaticText::DoGetBestSize -void wxStaticText::SetLabel( - const wxString& rsLabel +bool wxStaticText::SetFont( + const wxFont& rFont ) { - ::WinSetWindowText(GetHwnd(), rsLabel.c_str()); + bool bRet = wxControl::SetFont(rFont); // // Adjust the size of the window to fit to the label unless autoresizing is // disabled // - if (!(GetWindowStyle() & wxST_NO_AUTORESIZE)) + if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) { DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); } - DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); -} // end of wxStaticText::SetLabel + return bRet; +} // end of wxStaticText::SetFont -bool wxStaticText::SetFont( - const wxFont& rFont +void wxStaticText::SetLabel( + const wxString& rsLabel ) { - bool bRet = wxControl::SetFont(rFont); + ::WinSetWindowText(GetHwnd(), rsLabel.c_str()); // // Adjust the size of the window to fit to the label unless autoresizing is // disabled // - if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) + if (!(GetWindowStyle() & wxST_NO_AUTORESIZE)) { DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); } - return bRet; -} // end of wxStaticText::SetFont + DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); +} // end of wxStaticText::SetLabel MRESULT wxStaticText::OS2WindowProc( WXUINT uMsg diff --git a/src/os2/utils.cpp b/src/os2/utils.cpp index f49dced7e3..816ed527eb 100644 --- a/src/os2/utils.cpp +++ b/src/os2/utils.cpp @@ -1207,3 +1207,78 @@ void wxDrawBorder( } } // end of wxDrawBorder +void wxOS2SetFont( + HWND hWnd +, const wxFont& rFont +) +{ + char zFont[128]; + char zFacename[30]; + char zWeight[30]; + char zStyle[30]; + + if (hWnd == NULLHANDLE) + + // + // The fonts available for Presentation Params are just three + // outline fonts, the rest are available to the GPI, so we must + // map the families to one of these three + // + switch(rFont.GetFamily()) + { + case wxSCRIPT: + case wxDECORATIVE: + case wxROMAN: + strcpy(zFacename,"Times New Roman"); + break; + + case wxTELETYPE: + case wxMODERN: + strcpy(zFacename, "Courier"); + break; + + case wxSWISS: + case wxDEFAULT: + default: + strcpy(zFacename, "Helvetica"); + break; + } + + switch(rFont.GetWeight()) + { + default: + case wxNORMAL: + case wxLIGHT: + zWeight[0] = '\0'; + break; + + case wxBOLD: + case wxFONTWEIGHT_MAX: + strcpy(zWeight, "Bold"); + break; + } + + switch(rFont.GetStyle()) + { + case wxITALIC: + case wxSLANT: + strcpy(zStyle, "Italic"); + break; + + default: + zStyle[0] = '\0'; + break; + } + sprintf(zFont, "%d.%s", rFont.GetPointSize(), zFacename); + if (zWeight[0] != '\0') + { + strcat(zFont, " "); + strcat(zFont, zWeight); + } + if (zStyle[0] != '\0') + { + strcat(zFont, " "); + strcat(zFont, zStyle); + } + ::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont) + 1, (PVOID)zFont); +} // end of wxOS2SetFont diff --git a/src/os2/window.cpp b/src/os2/window.cpp index 846ed5696f..2c16e35794 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -2543,6 +2543,48 @@ MRESULT wxWindowOS2::OS2WindowProc( } break; + case WM_CONTROL: + switch(SHORT2FROMMP(wParam)) + { + case SPBN_UPARROW: + case SPBN_DOWNARROW: + case SPBN_CHANGE: + { + char zVal[10]; + long lVal; + + ::WinSendMsg( HWNDFROMMP(lParam) + ,SPBM_QUERYVALUE + ,&zVal + ,MPFROM2SHORT( (USHORT)10 + ,(USHORT)SPBQ_UPDATEIFVALID + ) + ); + lVal = atol(zVal); + bProcessed = OS2OnScroll( wxVERTICAL + ,(int)SHORT2FROMMP(wParam) + ,(int)lVal + ,HWNDFROMMP(lParam) + ); + } + break; + + case SLN_SLIDERTRACK: + { + HWND hWnd = ::WinWindowFromID(GetHWND(), SHORT1FROMMP(wParam)); + wxWindowOS2* pChild = wxFindWinFromHandle(hWnd); + + if (pChild->IsKindOf(CLASSINFO(wxSlider))) + bProcessed = OS2OnScroll( wxVERTICAL + ,(int)SHORT2FROMMP(wParam) + ,(int)LONGFROMMP(lParam) + ,hWnd + ); + } + break; + } + break; + #if defined(__VISAGECPP__) && (__IBMCPP__ >= 400) case WM_CTLCOLORCHANGE: { -- 2.45.2