From: Vadim Zeitlin Date: Fri, 2 Jul 1999 22:02:05 +0000 (+0000) Subject: 1. DoSetSize() simplified, DoGetBestSize() introduced X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4438caf41af49f00f3c8137ac801871f59cce386 1. DoSetSize() simplified, DoGetBestSize() introduced 2. code cleanup here and there 3. attempts to make static boxes behave better (i.e. stay below other controls) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2947 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/button.h b/include/wx/msw/button.h index cd0e1df385..4d78ab2d40 100644 --- a/include/wx/msw/button.h +++ b/include/wx/msw/button.h @@ -63,9 +63,7 @@ protected: // send a notification event, return TRUE if processed bool SendClickEvent(); - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); + virtual wxSize DoGetBestSize(); }; #endif diff --git a/include/wx/msw/checkbox.h b/include/wx/msw/checkbox.h index 90e5625119..7bcd8ef308 100644 --- a/include/wx/msw/checkbox.h +++ b/include/wx/msw/checkbox.h @@ -53,9 +53,7 @@ public: WXUINT message, WXWPARAM wParam, WXLPARAM lParam); protected: - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); + virtual wxSize DoGetBestSize(); }; class WXDLLEXPORT wxBitmapCheckBox: public wxCheckBox @@ -82,15 +80,7 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxCheckBoxNameStr); - virtual void SetValue(bool value); - virtual bool GetValue() const ; - virtual void SetLabel(const wxBitmap& bitmap); - -protected: - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); }; #endif // _WX_CHECKBOX_H_ diff --git a/include/wx/msw/choice.h b/include/wx/msw/choice.h index 2870c78b71..7cdfa9a577 100644 --- a/include/wx/msw/choice.h +++ b/include/wx/msw/choice.h @@ -73,9 +73,10 @@ public: protected: int m_noStrings; + virtual wxSize DoGetBestSize(); virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); + int width, int height, + int sizeFlags = wxSIZE_AUTO); }; #endif diff --git a/include/wx/msw/combobox.h b/include/wx/msw/combobox.h index a44538e7ff..52e8a9d6db 100644 --- a/include/wx/msw/combobox.h +++ b/include/wx/msw/combobox.h @@ -6,14 +6,14 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_COMBOBOX_H_ #define _WX_COMBOBOX_H_ #ifdef __GNUG__ -#pragma interface "combobox.h" + #pragma interface "combobox.h" #endif #include "wx/choice.h" @@ -23,59 +23,64 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxComboBoxNameStr; WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; -// Combobox item +// ---------------------------------------------------------------------------- +// Combobox control +// ---------------------------------------------------------------------------- + class WXDLLEXPORT wxComboBox: public wxChoice { - DECLARE_DYNAMIC_CLASS(wxComboBox) - - public: - inline wxComboBox(void) {} - - inline wxComboBox(wxWindow *parent, wxWindowID id, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxComboBoxNameStr) - { - Create(parent, id, value, pos, size, n, choices, style, validator, name); - } - - bool Create(wxWindow *parent, wxWindowID id, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxComboBoxNameStr); - - // List functions: see wxChoice - - // Text field functions - virtual wxString GetValue(void) const ; - virtual void SetValue(const wxString& value); - - // Clipboard operations - virtual void Copy(void); - virtual void Cut(void); - virtual void Paste(void); - virtual void SetInsertionPoint(long pos); - virtual void SetInsertionPointEnd(void); - virtual long GetInsertionPoint(void) const ; - virtual long GetLastPosition(void) const ; - virtual void Replace(long from, long to, const wxString& value); - virtual void Remove(long from, long to); - virtual void SetSelection(int n) - { - wxChoice::SetSelection(n); - } - virtual void SetSelection(long from, long to); - virtual void SetEditable(bool editable); - - virtual bool MSWCommand(WXUINT param, WXWORD id); + DECLARE_DYNAMIC_CLASS(wxComboBox) + +public: + wxComboBox() { } + + wxComboBox(wxWindow *parent, wxWindowID id, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxComboBoxNameStr) + { + Create(parent, id, value, pos, size, n, choices, style, validator, name); + } + + bool Create(wxWindow *parent, wxWindowID id, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxComboBoxNameStr); + + // List functions: see wxChoice + + // Text field functions + wxString GetValue() const { return GetLabel(); } + virtual void SetValue(const wxString& value); + + // Clipboard operations + virtual void Copy(); + virtual void Cut(); + virtual void Paste(); + virtual void SetInsertionPoint(long pos); + virtual void SetInsertionPointEnd(); + virtual long GetInsertionPoint() const; + virtual long GetLastPosition() const; + virtual void Replace(long from, long to, const wxString& value); + virtual void Remove(long from, long to); + virtual void SetSelection(int n) { wxChoice::SetSelection(n); } + virtual void SetSelection(long from, long to); + virtual void SetEditable(bool editable); + + virtual bool MSWCommand(WXUINT param, WXWORD id); + +protected: + virtual void DoSetSize(int x, int y, + int width, int height, + int sizeFlags = wxSIZE_AUTO); }; #endif // wxUSE_COMBOBOX diff --git a/include/wx/msw/control.h b/include/wx/msw/control.h index 446d49f333..b4a2807543 100644 --- a/include/wx/msw/control.h +++ b/include/wx/msw/control.h @@ -69,6 +69,8 @@ protected: // For controls like radiobuttons which are really composite wxList m_subControls; + virtual wxSize DoGetBestSize(); + private: DECLARE_EVENT_TABLE() }; diff --git a/include/wx/msw/gauge95.h b/include/wx/msw/gauge95.h index 0bab3e7163..11e77bc685 100644 --- a/include/wx/msw/gauge95.h +++ b/include/wx/msw/gauge95.h @@ -70,10 +70,6 @@ public: protected: int m_rangeMax; int m_gaugePos; - - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); }; #endif diff --git a/include/wx/msw/gaugemsw.h b/include/wx/msw/gaugemsw.h index 60e2fc1702..7f0a1f39f3 100644 --- a/include/wx/msw/gaugemsw.h +++ b/include/wx/msw/gaugemsw.h @@ -70,10 +70,6 @@ public: protected: int m_rangeMax; int m_gaugePos; - - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); }; #endif diff --git a/include/wx/msw/listbox.h b/include/wx/msw/listbox.h index 0272e7e047..03f08992db 100644 --- a/include/wx/msw/listbox.h +++ b/include/wx/msw/listbox.h @@ -133,10 +133,6 @@ protected: // control items wxListBoxItemsArray m_aItems; #endif - - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); }; #endif diff --git a/include/wx/msw/statbmp.h b/include/wx/msw/statbmp.h index 6c0669b806..4da9e6f89d 100644 --- a/include/wx/msw/statbmp.h +++ b/include/wx/msw/statbmp.h @@ -83,9 +83,7 @@ protected: wxBitmap *bitmap; } m_image; - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); + virtual wxSize DoGetBestSize(); }; #endif diff --git a/include/wx/msw/statbox.h b/include/wx/msw/statbox.h index 361fc3608f..87393c2f47 100644 --- a/include/wx/msw/statbox.h +++ b/include/wx/msw/statbox.h @@ -24,7 +24,7 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxStaticBoxNameStr; class WXDLLEXPORT wxStaticBox : public wxControl { DECLARE_DYNAMIC_CLASS(wxStaticBox) - + public: wxStaticBox() { } @@ -37,30 +37,32 @@ public: { Create(parent, id, label, pos, size, style, name); } - + bool Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxStaticBoxNameStr); - + + // implementation from now on + // -------------------------- + void OnEraseBackground(wxEraseEvent& event); - + virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); - - void SetLabel(const wxString& label); 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; } - + protected: virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); + virtual wxSize DoGetBestSize(); private: DECLARE_EVENT_TABLE() diff --git a/include/wx/msw/stattext.h b/include/wx/msw/stattext.h index e59beeab30..f21a4bd3b0 100644 --- a/include/wx/msw/stattext.h +++ b/include/wx/msw/stattext.h @@ -6,7 +6,7 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_STATTEXT_H_ @@ -26,7 +26,7 @@ DECLARE_DYNAMIC_CLASS(wxStaticText) public: wxStaticText() { } - + wxStaticText(wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos = wxDefaultPosition, @@ -36,29 +36,27 @@ public: { Create(parent, id, label, pos, size, style, name); } - + bool Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxStaticTextNameStr); - + // accessors void SetLabel(const wxString& label); - + // overriden base class virtuals virtual bool AcceptsFocus() const { return FALSE; } - + // callbacks virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXUINT message, WXWPARAM wParam, WXLPARAM lParam); virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); protected: - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); + virtual wxSize DoGetBestSize(); }; #endif diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 40dbcad9e4..af31bad26f 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -59,7 +59,8 @@ public: wxTextCtrl(wxWindow *parent, wxWindowID id, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, + const wxSize& size = wxDefaultSize, + long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr) #ifndef NO_TEXT_WINDOW_STREAM @@ -72,13 +73,15 @@ public: bool Create(wxWindow *parent, wxWindowID id, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = wxTE_PROCESS_TAB, + const wxSize& size = wxDefaultSize, + long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr); // accessors // --------- - virtual wxString GetValue() const ; + + virtual wxString GetValue() const; virtual void SetValue(const wxString& value); virtual int GetLineLength(long lineNo) const; @@ -148,25 +151,9 @@ public: virtual void ShowPosition(long pos); virtual void Clear(); - // callbacks - // --------- - void OnDropFiles(wxDropFilesEvent& event); - void OnChar(wxKeyEvent& event); // Process 'enter' if required - - void OnCut(wxCommandEvent& event); - void OnCopy(wxCommandEvent& event); - void OnPaste(wxCommandEvent& event); - void OnUndo(wxCommandEvent& event); - void OnRedo(wxCommandEvent& event); - - void OnUpdateCut(wxUpdateUIEvent& event); - void OnUpdateCopy(wxUpdateUIEvent& event); - void OnUpdatePaste(wxUpdateUIEvent& event); - void OnUpdateUndo(wxUpdateUIEvent& event); - void OnUpdateRedo(wxUpdateUIEvent& event); + // Implementation from now on + // -------------------------- - // Implementation - // -------------- virtual void Command(wxCommandEvent& event); virtual bool MSWCommand(WXUINT param, WXWORD id); @@ -184,6 +171,23 @@ public: virtual bool AcceptsFocus() const; + // callbacks + // --------- + void OnDropFiles(wxDropFilesEvent& event); + void OnChar(wxKeyEvent& event); // Process 'enter' if required + + void OnCut(wxCommandEvent& event); + void OnCopy(wxCommandEvent& event); + void OnPaste(wxCommandEvent& event); + void OnUndo(wxCommandEvent& event); + void OnRedo(wxCommandEvent& event); + + void OnUpdateCut(wxUpdateUIEvent& event); + void OnUpdateCopy(wxUpdateUIEvent& event); + void OnUpdatePaste(wxUpdateUIEvent& event); + void OnUpdateUndo(wxUpdateUIEvent& event); + void OnUpdateRedo(wxUpdateUIEvent& event); + protected: #if wxUSE_RICHEDIT bool m_isRich; // Are we using rich text edit to implement this? @@ -195,9 +199,7 @@ protected: // limit is big enough) void AdjustSpaceLimit(); - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); + virtual wxSize DoGetBestSize(); private: DECLARE_EVENT_TABLE() diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 0cfca8bfc5..33f358e879 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -399,6 +399,10 @@ protected: int sizeFlags = wxSIZE_AUTO); virtual void DoSetClientSize(int width, int height); + // get the size which best suits the window: e.g., for a static text it + // will be the width and height of the text + virtual wxSize DoGetBestSize(); + #if wxUSE_TOOLTIPS virtual void DoSetToolTip( wxToolTip *tip ); #endif // wxUSE_TOOLTIPS diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 1d8bbaf990..1a34a34d0e 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -113,55 +113,28 @@ wxButton::~wxButton() // size management including autosizing // ---------------------------------------------------------------------------- -void wxButton::DoSetSize(int x, int y, int width, int height, int sizeFlags) +wxSize wxButton::DoGetBestSize() { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - int actualWidth = width; - int actualHeight = height; - int ww, hh; - GetSize(&ww, &hh); - - int current_width; - int cyf; - wxString buf = wxGetWindowText(GetHWND()); - GetTextExtent(buf, ¤t_width, &cyf, NULL, NULL, &GetFont()); - - // If we're prepared to use the existing width, then... - if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH)) - { - actualWidth = ww; - } - else if (width == -1) - { - int cx; - int cy; - wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); - actualWidth = (int)(current_width + 3*cx) ; - } + wxString label = wxGetWindowText(GetHWND()); + int wBtn; + GetTextExtent(label, &wBtn, NULL); - // If we're prepared to use the existing height, then... - if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT)) - { - actualHeight = hh; - } - else if (height == -1) - { - actualHeight = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cyf); - } + int wChar, hChar; + wxGetCharSize(GetHWND(), &wChar, &hChar, &GetFont()); + + // add a margin - the button is wider than just its label + wBtn += 3*wChar; + + // the button height is proportional to the height of the font used + int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); - MoveWindow(GetHwnd(), x1, y1, actualWidth, actualHeight, TRUE); + return wxSize(wBtn, hBtn); } +// ---------------------------------------------------------------------------- +// set this button as the default one in its panel +// ---------------------------------------------------------------------------- + void wxButton::SetDefault() { wxWindow *parent = GetParent(); diff --git a/src/msw/checkbox.cpp b/src/msw/checkbox.cpp index 89f0c52cca..e8d646892c 100644 --- a/src/msw/checkbox.cpp +++ b/src/msw/checkbox.cpp @@ -6,39 +6,59 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "checkbox.h" + #pragma implementation "checkbox.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/checkbox.h" -#include "wx/brush.h" + #include "wx/checkbox.h" + #include "wx/brush.h" #endif #include "wx/msw/private.h" +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + #if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) -IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) + IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) + IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) #endif +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxCheckBox +// ---------------------------------------------------------------------------- + bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) { - wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId); - event.SetInt(GetValue()); - event.SetEventObject(this); - ProcessCommand(event); - return TRUE; + wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId); + event.SetInt(GetValue()); + event.SetEventObject(this); + ProcessCommand(event); + return TRUE; } // Single check box item @@ -48,126 +68,102 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxValidator& validator, const wxString& name) { - SetName(name); - SetValidator(validator); - if (parent) parent->AddChild(this); - - SetBackgroundColour(parent->GetBackgroundColour()) ; - SetForegroundColour(parent->GetForegroundColour()) ; - - m_windowStyle = style; - - wxString Label = label; - if (Label == _T("")) - Label = _T(" "); // Apparently needed or checkbox won't show - - if ( id == -1 ) - m_windowId = NewControlId(); - else - m_windowId = id; - - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; - - long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_CHILD | WS_VISIBLE; - if ( style & wxALIGN_RIGHT ) - msStyle |= BS_LEFTTEXT; - - // We perhaps have different concepts of 3D here - a 3D border, - // versus a 3D button. - // So we only wish to give a border if this is specified - // in the style. - bool want3D; - WXDWORD exStyle = Determine3DEffects(0, &want3D) ; - - // Even with extended styles, need to combine with WS_BORDER - // for them to look right. -/* - if ( want3D || wxStyleHasBorder(m_windowStyle) ) - msStyle |= WS_BORDER; -*/ - - m_hWnd = (WXHWND)CreateWindowEx(exStyle, _T("BUTTON"), Label, - msStyle, - 0, 0, 0, 0, - (HWND)parent->GetHWND(), (HMENU)m_windowId, - wxGetInstance(), NULL); + SetName(name); + SetValidator(validator); + if (parent) parent->AddChild(this); + + SetBackgroundColour(parent->GetBackgroundColour()) ; + SetForegroundColour(parent->GetForegroundColour()) ; + + m_windowStyle = style; + + wxString Label = label; + if (Label == _T("")) + Label = _T(" "); // Apparently needed or checkbox won't show + + if ( id == -1 ) + m_windowId = NewControlId(); + else + m_windowId = id; + + int x = pos.x; + int y = pos.y; + int width = size.x; + int height = size.y; + + long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_CHILD | WS_VISIBLE; + if ( style & wxALIGN_RIGHT ) + msStyle |= BS_LEFTTEXT; + + // We perhaps have different concepts of 3D here - a 3D border, + // versus a 3D button. + // So we only wish to give a border if this is specified + // in the style. + bool want3D; + WXDWORD exStyle = Determine3DEffects(0, &want3D) ; + + // Even with extended styles, need to combine with WS_BORDER + // for them to look right. + /* + if ( want3D || wxStyleHasBorder(m_windowStyle) ) + msStyle |= WS_BORDER; + */ + + m_hWnd = (WXHWND)CreateWindowEx(exStyle, _T("BUTTON"), Label, + msStyle, + 0, 0, 0, 0, + (HWND)parent->GetHWND(), (HMENU)m_windowId, + wxGetInstance(), NULL); #if wxUSE_CTL3D - if (want3D) - { - Ctl3dSubclassCtl((HWND)m_hWnd); - m_useCtl3D = TRUE; - } + if (want3D) + { + Ctl3dSubclassCtl(GetHwnd()); + m_useCtl3D = TRUE; + } #endif - // Subclass again for purposes of dialog editing mode - SubclassWin(m_hWnd); - - SetFont(parent->GetFont()); + // Subclass again for purposes of dialog editing mode + SubclassWin(m_hWnd); - SetSize(x, y, width, height); + SetFont(parent->GetFont()); - return TRUE; + SetSize(x, y, width, height); + + return TRUE; } void wxCheckBox::SetLabel(const wxString& label) { - SetWindowText((HWND)GetHWND(), label); + SetWindowText(GetHwnd(), label); } -void wxCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) +wxSize wxCheckBox::DoGetBestSize() { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); + int wCheckbox, hCheckbox; - int current_width, cyf; - HWND button = (HWND) GetHWND(); + wxString str = wxGetWindowText(GetHWND()); - int nLen = GetWindowTextLength(button); - wxString str; - GetWindowText(button, str.GetWriteBuf(nLen), nLen); - str.UngetWriteBuf(); + if ( !str.IsEmpty() ) + { + GetTextExtent(str, &wCheckbox, &hCheckbox); + wCheckbox += RADIO_SIZE; - if ( !str.IsEmpty() ) - { - GetTextExtent(str, ¤t_width, &cyf, NULL, NULL, & this->GetFont()); - if (w1 < 0) - w1 = (int)(current_width + RADIO_SIZE); - if (h1 < 0) + if ( hCheckbox < RADIO_SIZE ) + hCheckbox = RADIO_SIZE; + } + else { - h1 = (int)(cyf); - if (h1 < RADIO_SIZE) - h1 = RADIO_SIZE; + wCheckbox = RADIO_SIZE; + hCheckbox = RADIO_SIZE; } - } - else - { - if (w1 < 0) - w1 = RADIO_SIZE; - if (h1 < 0) - h1 = RADIO_SIZE; - } - MoveWindow(button, x1, y1, w1, h1, TRUE); + return wxSize(wCheckbox, hCheckbox); } void wxCheckBox::SetValue(bool val) { - SendMessage((HWND) GetHWND(), BM_SETCHECK, val, 0); + SendMessage(GetHwnd(), BM_SETCHECK, val, 0); } #ifndef BST_CHECKED @@ -177,20 +173,20 @@ void wxCheckBox::SetValue(bool val) bool wxCheckBox::GetValue() const { #ifdef __WIN32__ - return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0) == BST_CHECKED); + return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED); #else - return ((0x003 & SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0)) == 0x003); + return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x003); #endif } WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) + WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { #if wxUSE_CTL3D if ( m_useCtl3D ) { HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); - + return (WXHBRUSH) hbrush; } #endif @@ -217,6 +213,10 @@ void wxCheckBox::Command (wxCommandEvent & event) ProcessCommand (event); } +// ---------------------------------------------------------------------------- +// wxBitmapCheckBox +// ---------------------------------------------------------------------------- + bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label, const wxPoint& pos, const wxSize& size, long style, @@ -231,10 +231,10 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l SetForegroundColour(parent->GetForegroundColour()) ; m_windowStyle = style; - if ( id == -1 ) - m_windowId = NewControlId(); - else - m_windowId = id; + if ( id == -1 ) + m_windowId = NewControlId(); + else + m_windowId = id; int x = pos.x; int y = pos.y; @@ -254,7 +254,7 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) { Ctl3dSubclassCtl(wx_button); - m_useCtl3D = TRUE; + m_useCtl3D = TRUE; } #endif @@ -263,53 +263,14 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l // Subclass again for purposes of dialog editing mode SubclassWin((WXHWND)wx_button); -// SetFont(parent->GetFont()); - SetSize(x, y, width, height); ShowWindow(wx_button, SW_SHOW); + return TRUE; } void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap) { + wxFAIL_MSG("not implemented"); } - -void wxBitmapCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - int currentX, currentY; - GetPosition(¤tX, ¤tY); - - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - HWND button = (HWND) GetHWND(); -/* - if (w1<0) - w1 = checkWidth + FB_MARGIN ; - if (h1<0) - h1 = checkHeight + FB_MARGIN ; -*/ - MoveWindow(button, x1, y1, w1, h1, TRUE); -} - -void wxBitmapCheckBox::SetValue(bool val) -{ - SendMessage((HWND) GetHWND(), BM_SETCHECK, val, 0); -} - -bool wxBitmapCheckBox::GetValue() const -{ - return ((0x003 & SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0)) == 0x003); -} - - diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 3f349227d3..6bcec7b964 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -123,19 +123,19 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, void wxChoice::Append(const wxString& item) { - SendMessage((HWND) GetHWND(), CB_ADDSTRING, 0, (LONG)(const wxChar *)item); + SendMessage(GetHwnd(), CB_ADDSTRING, 0, (LONG)(const wxChar *)item); m_noStrings ++; } void wxChoice::Delete(int n) { - m_noStrings = (int)SendMessage((HWND) GetHWND(), CB_DELETESTRING, n, 0); + m_noStrings = (int)SendMessage(GetHwnd(), CB_DELETESTRING, n, 0); } void wxChoice::Clear(void) { - SendMessage((HWND) GetHWND(), CB_RESETCONTENT, 0, 0); + SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0); m_noStrings = 0; } @@ -143,12 +143,12 @@ void wxChoice::Clear(void) int wxChoice::GetSelection(void) const { - return (int)SendMessage((HWND) GetHWND(), CB_GETCURSEL, 0, 0); + return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0); } void wxChoice::SetSelection(int n) { - SendMessage((HWND) GetHWND(), CB_SETCURSEL, n, 0); + SendMessage(GetHwnd(), CB_SETCURSEL, n, 0); } int wxChoice::FindString(const wxString& s) const @@ -159,14 +159,14 @@ int wxChoice::FindString(const wxString& s) const char buf[512]; for (int i = 0; i < Number(); i++) { - int len = (int)SendMessage((HWND) GetHWND(), CB_GETLBTEXT, i, (LPARAM)(LPSTR)buf); + int len = (int)SendMessage(GetHwnd(), CB_GETLBTEXT, i, (LPARAM)(LPSTR)buf); buf[len] = 0; if (strcmp(buf, (const char *)s) == 0) return i; } return -1; #else - int pos = (int)SendMessage((HWND) GetHWND(), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)(LPSTR)(const wxChar *)s); + int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)(LPSTR)(const wxChar *)s); if (pos == LB_ERR) return -1; else @@ -176,99 +176,60 @@ int wxChoice::FindString(const wxString& s) const wxString wxChoice::GetString(int n) const { - int len = (int)SendMessage((HWND) GetHWND(), CB_GETLBTEXT, n, (long)wxBuffer); - wxBuffer[len] = 0; - return wxString(wxBuffer); -} - -void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - int currentX, currentY; - GetPosition(¤tX, ¤tY); - - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } + size_t len = (size_t)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0); + wxString str; + if ( ::SendMessage(GetHwnd(), CB_GETLBTEXT, n, + (LPARAM)str.GetWriteBuf(len)) == CB_ERR ) + { + wxLogLastError("SendMessage(CB_GETLBTEXT)"); + } - int cx; // button font dimensions - int cy; - wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); + str.UngetWriteBuf(); - int control_width, control_height; + return str; +} - // Ignore height parameter because height doesn't - // mean 'initially displayed' height, it refers to the - // drop-down menu as well. The wxWindows interpretation - // is different; also, getting the size returns the - // _displayed_ size (NOT the drop down menu size) - // so setting-getting-setting size would not work. - h1 = -1; +void wxChoice::DoSetSize(int x, int y, + int width, int height, + int sizeFlags) +{ + // Ignore height parameter because height doesn't mean 'initially + // displayed' height, it refers to the drop-down menu as well. The + // wxWindows interpretation is different; also, getting the size returns + // the _displayed_ size (NOT the drop down menu size) so + // setting-getting-setting size would not work. + wxControl::DoSetSize(x, y, width, -1, sizeFlags); +} - // Deal with default size (using -1 values) - if (width <= 0) - { - // Find the longest string - if (m_noStrings == 0) - { - control_width = 100; - } - else +wxSize wxChoice::DoGetBestSize() +{ + // find the widest string + int wLine; + int wChoice = 0; + for ( int i = 0; i < m_noStrings; i++ ) { - int len, ht; - int longest = 0; - int i; - for (i = 0; i < m_noStrings; i++) - { wxString str(GetString(i)); - GetTextExtent(str, &len, &ht, NULL, NULL, & this->GetFont()); - if ( len > longest) - longest = len; - } - - control_width = longest + cx*5; + GetTextExtent(str, &wLine, NULL); + if ( wLine > wChoice ) + wChoice = wLine; } - } - else - { - // If non-default width... - control_width = w1; - } + // give it some reasonable default value if there are no strings in the + // list + if ( wChoice == 0 ) + wChoice = 100; - // Choice drop-down list depends on number of items (limited to 10) - if (h1 <= 0) - { - if (m_noStrings == 0) - h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*10; - else - h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*(wxMin(10, m_noStrings) + 1); - } - - control_height = h1; + // the combobox should be larger than the widest string + int cx, cy; + wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); - // Calculations may have made text size too small - if (control_height <= 0) - control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); + wChoice += 5*cx; - if (control_width <= 0) - control_width = 100; + // Choice drop-down list depends on number of items (limited to 10) + size_t nStrings = m_noStrings == 0 ? 10 : wxMin(10, m_noStrings) + 1; + int hChoice = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*nStrings; - MoveWindow((HWND)GetHWND(), x1, y1, - control_width, control_height, TRUE); + return wxSize(wChoice, hChoice); } WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, diff --git a/src/msw/combobox.cpp b/src/msw/combobox.cpp index f7eff22ed6..7104620710 100644 --- a/src/msw/combobox.cpp +++ b/src/msw/combobox.cpp @@ -146,11 +146,6 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, return TRUE; } -wxString wxComboBox::GetValue() const -{ - return wxGetWindowText(GetHWND()); -} - void wxComboBox::SetValue(const wxString& value) { // If newlines are denoted by just 10, must stick 13 in front. @@ -177,43 +172,43 @@ void wxComboBox::SetValue(const wxString& value) j ++; } tmp[j] = 0; - SetWindowText((HWND) GetHWND(), tmp); + SetWindowText(GetHwnd(), tmp); delete[] tmp; } else - SetWindowText((HWND) GetHWND(), (const wxChar *)value); + SetWindowText(GetHwnd(), value); } // Clipboard operations void wxComboBox::Copy() { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); SendMessage(hWnd, WM_COPY, 0, 0L); } void wxComboBox::Cut() { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); SendMessage(hWnd, WM_CUT, 0, 0L); } void wxComboBox::Paste() { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); SendMessage(hWnd, WM_PASTE, 0, 0L); } void wxComboBox::SetEditable(bool editable) { // Can't implement in MSW? -// HWND hWnd = (HWND) GetHWND(); +// HWND hWnd = GetHwnd(); // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L); } void wxComboBox::SetInsertionPoint(long pos) { /* - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); #ifdef __WIN32__ SendMessage(hWnd, EM_SETSEL, pos, pos); SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); @@ -236,7 +231,7 @@ void wxComboBox::SetInsertionPointEnd() long wxComboBox::GetInsertionPoint() const { /* - DWORD Pos=(DWORD)SendMessage((HWND) GetHWND(), EM_GETSEL, 0, 0L); + DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L); return Pos&0xFFFF; */ return 0; @@ -245,14 +240,14 @@ long wxComboBox::GetInsertionPoint() const long wxComboBox::GetLastPosition() const { /* - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); // Will always return a number > 0 (according to docs) int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L); // This gets the char index for the _beginning_ of the last line int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L); - + // Get number of characters in the last line. We'll add this to the character // index for the last line, 1st position. int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L); @@ -265,10 +260,10 @@ long wxComboBox::GetLastPosition() const void wxComboBox::Replace(long from, long to, const wxString& value) { #if wxUSE_CLIPBOARD - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); long fromChar = from; long toChar = to; - + // Set selection and remove it #ifdef __WIN32__ SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar); @@ -287,10 +282,10 @@ void wxComboBox::Replace(long from, long to, const wxString& value) void wxComboBox::Remove(long from, long to) { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); long fromChar = from; long toChar = to; - + // Cut all selected text #ifdef __WIN32__ SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar); @@ -302,7 +297,7 @@ void wxComboBox::Remove(long from, long to) void wxComboBox::SetSelection(long from, long to) { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); long fromChar = from; long toChar = to; // if from and to are both -1, it means @@ -313,7 +308,7 @@ void wxComboBox::SetSelection(long from, long to) fromChar = 0; toChar = -1; } - + #ifdef __WIN32__ SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar); // SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); @@ -323,6 +318,22 @@ void wxComboBox::SetSelection(long from, long to) #endif } +void wxComboBox::DoSetSize(int x, int y, + int width, int height, + int sizeFlags) +{ + wxControl::DoSetSize(x, y, width, height, sizeFlags); + + // VZ: for unknown (to me) reasons, if we don't do this, the combobox + // somehow is hidden by the static boxes, although static boxes do + // put themselves at the very end of Z-order. + if ( !::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE) ) + { + wxLogLastError(_T("SetWindowPos")); + } +} + #endif // wxUSE_COMBOBOX diff --git a/src/msw/control.cpp b/src/msw/control.cpp index 7f609f7bd6..b8ccc63551 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -58,6 +58,11 @@ wxControl::~wxControl() m_isBeingDeleted = TRUE; } +wxSize wxControl::DoGetBestSize() +{ + return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT); +} + bool wxControl::ProcessCommand(wxCommandEvent& event) { #if WXWIN_COMPATIBILITY diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 82d435e254..91ccc08d19 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -241,28 +241,11 @@ void wxFrame::DoGetPosition(int *x, int *y) const void wxFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags) { - int currentX, currentY; - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; + wxWindow::DoSetSize(x, y, width, height, sizeFlags); - GetPosition(¤tX, ¤tY); - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - int ww,hh ; - GetSize(&ww,&hh) ; - if (width == -1) w1 = ww ; - if (height==-1) h1 = hh ; - - MoveWindow(GetHwnd(), x1, y1, w1, h1, (BOOL)TRUE); - - wxSizeEvent event(wxSize(width, height), m_windowId); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); + wxSizeEvent event(wxSize(width, height), m_windowId); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); } bool wxFrame::Show(bool show) diff --git a/src/msw/gauge95.cpp b/src/msw/gauge95.cpp index e5c09362e2..ade3fdca7c 100644 --- a/src/msw/gauge95.cpp +++ b/src/msw/gauge95.cpp @@ -58,9 +58,9 @@ bool wxGauge95::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; @@ -108,38 +108,6 @@ bool wxGauge95::Create(wxWindow *parent, wxWindowID id, return TRUE; } -void wxGauge95::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } - - // Deal with default size (using -1 values) - if (w1<=0) - w1 = DEFAULT_ITEM_WIDTH; - - if (h1<=0) - h1 = DEFAULT_ITEM_HEIGHT; - - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); -} - void wxGauge95::SetShadowWidth(int w) { } diff --git a/src/msw/gaugemsw.cpp b/src/msw/gaugemsw.cpp index 138ac9eaf7..1af85748f9 100644 --- a/src/msw/gaugemsw.cpp +++ b/src/msw/gaugemsw.cpp @@ -126,8 +126,8 @@ bool wxGaugeMSW::Create(wxWindow *parent, wxWindowID id, SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0); SendMessage(wx_button, ZYZG_SETRANGE, range, 0); - SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); - SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); + 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()); @@ -137,85 +137,53 @@ bool wxGaugeMSW::Create(wxWindow *parent, wxWindowID id, height = 50; SetSize(x, y, width, height); - ShowWindow((HWND) GetHWND(), SW_SHOW); + ShowWindow(GetHwnd(), SW_SHOW); return TRUE; } -void wxGaugeMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } - - // Deal with default size (using -1 values) - if (w1<=0) - w1 = DEFAULT_ITEM_WIDTH; - - if (h1<=0) - h1 = DEFAULT_ITEM_HEIGHT; - - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); -} - void wxGaugeMSW::SetShadowWidth(int w) { - SendMessage((HWND) GetHWND(), ZYZG_SETWIDTH3D, w, 0); + SendMessage(GetHwnd(), ZYZG_SETWIDTH3D, w, 0); } void wxGaugeMSW::SetBezelFace(int w) { - SendMessage((HWND) GetHWND(), ZYZG_SETBEZELFACE, w, 0); + SendMessage(GetHwnd(), ZYZG_SETBEZELFACE, w, 0); } void wxGaugeMSW::SetRange(int r) { m_rangeMax = r; - SendMessage((HWND) GetHWND(), ZYZG_SETRANGE, r, 0); + SendMessage(GetHwnd(), ZYZG_SETRANGE, r, 0); } void wxGaugeMSW::SetValue(int pos) { m_gaugePos = pos; - SendMessage((HWND) GetHWND(), ZYZG_SETPOSITION, pos, 0); + SendMessage(GetHwnd(), ZYZG_SETPOSITION, pos, 0); } int wxGaugeMSW::GetShadowWidth(void) const { - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETWIDTH3D, 0, 0); + return (int) SendMessage(GetHwnd(), ZYZG_GETWIDTH3D, 0, 0); } int wxGaugeMSW::GetBezelFace(void) const { - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETBEZELFACE, 0, 0); + return (int) SendMessage(GetHwnd(), ZYZG_GETBEZELFACE, 0, 0); } int wxGaugeMSW::GetRange(void) const { - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETRANGE, 0, 0); + return (int) SendMessage(GetHwnd(), ZYZG_GETRANGE, 0, 0); } int wxGaugeMSW::GetValue(void) const { - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETPOSITION, 0, 0); + return (int) SendMessage(GetHwnd(), ZYZG_GETPOSITION, 0, 0); } bool wxGaugeMSW::SetForegroundColour(const wxColour& col) @@ -223,7 +191,7 @@ bool wxGaugeMSW::SetForegroundColour(const wxColour& col) if ( !wxControl::SetForegroundColour(col) ) return FALSE; - SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); + SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); return TRUE; } @@ -233,7 +201,7 @@ bool wxGaugeMSW::SetBackgroundColour(const wxColour& col) if ( !wxControl::SetBackgroundColour(col) ) return FALSE; - SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); + SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); return TRUE; } diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 6ef3532c9f..b14384f8cf 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -518,65 +518,8 @@ wxString wxListBox::GetString(int N) const return result; } -void wxListBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - int currentX, currentY; - GetPosition(¤tX, ¤tY); - - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } - - int cx; // button font dimensions - int cy; - - wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); - - float control_width, control_height, control_x, control_y; - - // Deal with default size (using -1 values) - if (w1<=0) - w1 = DEFAULT_ITEM_WIDTH; - - if (h1<=0) - h1 = DEFAULT_ITEM_HEIGHT; - - control_x = (float)x1; - control_y = (float)y1; - control_width = (float)w1; - control_height = (float)h1; - - // Calculations may have made size too small - if (control_height <= 0) - control_height = (float)DEFAULT_ITEM_HEIGHT; - - if (control_width <= 0) - control_width = (float)DEFAULT_ITEM_WIDTH; - - MoveWindow(GetHwnd(), - (int)control_x, (int)control_y, - (int)control_width, (int)control_height, - TRUE); - -} - -// Windows-specific code to set the horizontal extent of -// the listbox, if necessary. If s is non-NULL, it's -// used to calculate the horizontal extent. +// Windows-specific code to set the horizontal extent of the listbox, if +// necessary. If s is non-NULL, it's used to calculate the horizontal extent. // Otherwise, all strings are used. void wxListBox::SetHorizontalExtent(const wxString& s) { diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index ebd76b52bb..f0ab1b8a2d 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -351,135 +351,146 @@ wxString wxRadioBox::GetString(int N) const // Restored old code. void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - 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; - - wxChar buf[400]; - - int y_offset = yy; - int x_offset = xx; - int current_width, cyf; - - int cx1,cy1; - wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont()); - // 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; - - int i; - for (i = 0 ; i < m_noItems; i++) - { - int eachWidth; - int eachHeight; - if (m_radioWidth[i]<0) - { - // It's a labelled toggle - GetWindowText((HWND) m_radioButtons[i], buf, 300); - GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, & GetFont()); - eachWidth = (int)(current_width + RADIO_SIZE); - eachHeight = (int)((3*cyf)/2); - } - else + int currentX, currentY; + GetPosition(¤tX, ¤tY); + 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; + + int cx1,cy1; + wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont()); + + // 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; + + int i; + for (i = 0 ; i < m_noItems; i++) { - eachWidth = m_radioWidth[i]; - eachHeight = m_radioHeight[i]; + int eachWidth; + int eachHeight; + if (m_radioWidth[i]<0) + { + // 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); + } + else + { + eachWidth = m_radioWidth[i]; + eachHeight = m_radioHeight[i]; + } + + if (maxWidth0) - y_offset += cy1/2; - } - } - int eachWidth; - int eachHeight; - if (m_radioWidth[i]<0) - { - // It's a labeled item - GetWindowText((HWND) m_radioButtons[i], buf, 300); - GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, & GetFont()); - - // 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); - } - else - { - eachWidth = m_radioWidth[i]; - eachHeight = m_radioHeight[i]; - } + // Bidimensional radio adjustment + if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0? + { + if (m_windowStyle & wxRA_VERTICAL) + { + y_offset = startY; + x_offset += maxWidth + cx1; + } + else + { + x_offset = startX; + y_offset += maxHeight; + if (m_radioWidth[0]>0) + y_offset += cy1/2; + } + } + int eachWidth; + int eachHeight; + if (m_radioWidth[i]<0) + { + // 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); + } + else + { + eachWidth = m_radioWidth[i]; + eachHeight = m_radioHeight[i]; + } - 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; + 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; + } + else + x_offset += maxWidth + cx1; } - else - x_offset += maxWidth + cx1; - } } - void wxRadioBox::GetSize(int *width, int *height) const { RECT rect; diff --git a/src/msw/slider95.cpp b/src/msw/slider95.cpp index 7bfe7c1a79..ad622b84fd 100644 --- a/src/msw/slider95.cpp +++ b/src/msw/slider95.cpp @@ -277,12 +277,12 @@ wxSlider95::~wxSlider95() int wxSlider95::GetValue() const { - return ::SendMessage((HWND) GetHWND(), TBM_GETPOS, 0, 0); + return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0); } void wxSlider95::SetValue(int value) { - ::SendMessage((HWND) GetHWND(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); + ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); if (m_staticValue) { wxSprintf(wxBuffer, _T("%d"), value); @@ -344,6 +344,8 @@ void wxSlider95::GetPosition(int *x, int *y) const *y = point.y; } +// TODO one day, make sense of all this horros and replace it with a readable +// DoGetBestSize() void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) { int x1 = x; @@ -413,7 +415,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (slider_length < 100) slider_length = 100; - MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_length, slider_height, TRUE); + 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); @@ -430,7 +432,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) w1 = 200; if ( h1 < 0 ) h1 = 20; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); } } else @@ -479,7 +481,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (slider_length < 100) slider_length = 100; - MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_width, slider_length, TRUE); + 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); @@ -496,7 +498,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) w1 = 20; if ( h1 < 0 ) h1 = 200; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); } } } @@ -506,7 +508,7 @@ void wxSlider95::SetRange(int minValue, int maxValue) m_rangeMin = minValue; m_rangeMax = maxValue; - ::SendMessage((HWND) GetHWND(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); + ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); wxChar buf[40]; if ( m_staticMin ) @@ -545,12 +547,12 @@ WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, void wxSlider95::SetTickFreq(int n, int pos) { m_tickFreq = n; - ::SendMessage( (HWND) GetHWND(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); + ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); } void wxSlider95::SetPageSize(int pageSize) { - ::SendMessage( (HWND) GetHWND(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); + ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); m_pageSize = pageSize; } @@ -561,53 +563,53 @@ int wxSlider95::GetPageSize() const void wxSlider95::ClearSel() { - ::SendMessage( (HWND) GetHWND(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 ); + ::SendMessage( GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 ); } void wxSlider95::ClearTicks() { - ::SendMessage( (HWND) GetHWND(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 ); + ::SendMessage( GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 ); } void wxSlider95::SetLineSize(int lineSize) { m_lineSize = lineSize; - ::SendMessage( (HWND) GetHWND(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize ); + ::SendMessage( GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize ); } int wxSlider95::GetLineSize() const { - return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 ); + return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 ); } int wxSlider95::GetSelEnd() const { - return (int) ::SendMessage( (HWND) GetHWND(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 ); + return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 ); } int wxSlider95::GetSelStart() const { - return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 ); + return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 ); } void wxSlider95::SetSelection(int minPos, int maxPos) { - ::SendMessage( (HWND) GetHWND(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) ); + ::SendMessage( GetHwnd(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) ); } void wxSlider95::SetThumbLength(int len) { - ::SendMessage( (HWND) GetHWND(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 ); + ::SendMessage( GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 ); } int wxSlider95::GetThumbLength() const { - return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 ); + return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 ); } void wxSlider95::SetTick(int tickPos) { - ::SendMessage( (HWND) GetHWND(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); + ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); } bool wxSlider95::ContainsHWND(WXHWND hWnd) const diff --git a/src/msw/slidrmsw.cpp b/src/msw/slidrmsw.cpp index fb14495286..18f85538ea 100644 --- a/src/msw/slidrmsw.cpp +++ b/src/msw/slidrmsw.cpp @@ -248,12 +248,12 @@ wxSliderMSW::~wxSliderMSW() int wxSliderMSW::GetValue() const { - return ::GetScrollPos((HWND) GetHWND(), SB_CTL); + return ::GetScrollPos(GetHwnd(), SB_CTL); } void wxSliderMSW::SetValue(int value) { - ::SetScrollPos((HWND) GetHWND(), SB_CTL, value, TRUE); + ::SetScrollPos(GetHwnd(), SB_CTL, value, TRUE); if (m_staticValue) { wxSprintf(wxBuffer, _T("%d"), value); @@ -315,6 +315,8 @@ void wxSliderMSW::GetPosition(int *x, int *y) const *y = point.y; } +// TODO one day, make sense of all this horros and replace it with a readable +// DoGetBestSize() void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) { int x1 = x; @@ -379,7 +381,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (slider_length < 100) slider_length = 100; - MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_length, slider_height, TRUE); + 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); @@ -391,7 +393,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) w1 = 200; if ( h1 < 0 ) h1 = 20; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); } } else @@ -435,7 +437,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (slider_length < 100) slider_length = 100; - MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_width, slider_length, TRUE); + 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); @@ -447,7 +449,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) w1 = 20; if ( h1 < 0 ) h1 = 200; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE); } } } @@ -457,7 +459,7 @@ void wxSliderMSW::SetRange(int minValue, int maxValue) m_rangeMin = minValue; m_rangeMax = maxValue; - ::SetScrollRange((HWND) GetHWND(), SB_CTL, m_rangeMin, m_rangeMax, TRUE); + ::SetScrollRange(GetHwnd(), SB_CTL, m_rangeMin, m_rangeMax, TRUE); wxChar buf[40]; if ( m_staticMin ) { diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index c22387c146..200e920bd8 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -140,39 +140,11 @@ void wxStaticBitmap::Free() m_image.icon = NULL; } -void wxStaticBitmap::DoSetSize(int x, int y, int width, int height, int sizeFlags) +wxSize wxStaticBitmap::DoGetBestSize() { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - int actualWidth = width; - int actualHeight = height; - - int ww, hh; - GetSize(&ww, &hh); - - // If we're prepared to use the existing width, then... - if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH)) - actualWidth = ww; - else - actualWidth = width; - - // If we're prepared to use the existing height, then... - if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT)) - actualHeight = hh; - else - actualHeight = height; - - MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE); + // reuse the current size (as wxWindow does) instead of using some + // arbitrary default size (as wxControl, our immediate base class, does) + return wxWindow::DoGetBestSize(); } void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) diff --git a/src/msw/statbox.cpp b/src/msw/statbox.cpp index 6ca6074e54..686762f3bd 100644 --- a/src/msw/statbox.cpp +++ b/src/msw/statbox.cpp @@ -99,50 +99,31 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, return TRUE; } -void wxStaticBox::SetLabel(const wxString& label) +wxSize wxStaticBox::DoGetBestSize() { - SetWindowText((HWND)m_hWnd, (const wxChar *)label); -} - -void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - int currentX, currentY; - GetPosition(¤tX, ¤tY); + int cx, cy; + wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; + int wBox; + GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy); - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } + wBox += 3*cx; + int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); - int current_width; - - int cx; - int cy; - int cyf; - - wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); + return wxSize(wBox, hBox); +} - GetTextExtent(wxGetWindowText(m_hWnd), ¤t_width, &cyf, - NULL,NULL, & this->GetFont()); - if ( w1 < 0 ) - w1 = current_width + 3*cx; - if ( h1 < 0 ) - h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cyf); +void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) +{ + wxControl::DoSetSize(x, y, width, height, sizeFlags); - MoveWindow((HWND)m_hWnd, x1, y1, w1, h1, TRUE); + // the static box should always be on the bottom of the Z-order, otherwise + // it may hide controls which are positioned inside it + if ( !::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE) ) + { + wxLogLastError(_T("SetWindowPos")); + } } WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, @@ -202,7 +183,7 @@ void wxStaticBox::OnEraseBackground(wxEraseEvent& event) RECT rect; - ::GetClientRect((HWND) GetHWND(), &rect); + ::GetClientRect(GetHwnd(), &rect); ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush); ::DeleteObject(hBrush); ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode); @@ -215,7 +196,7 @@ void wxStaticBox::OnEraseBackground(wxEraseEvent& event) long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { - if (nMsg == WM_NCHITTEST) + if ( 0 )//nMsg == WM_NCHITTEST) { int xPos = LOWORD(lParam); // horizontal position of cursor int yPos = HIWORD(lParam); // vertical position of cursor diff --git a/src/msw/stattext.cpp b/src/msw/stattext.cpp index da9906d988..31c7c0141b 100644 --- a/src/msw/stattext.cpp +++ b/src/msw/stattext.cpp @@ -94,24 +94,8 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, return TRUE; } -void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags) +wxSize wxStaticText::DoGetBestSize() { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - - int x1 = x; - int y1 = y; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - int actualWidth = width; - int actualHeight = height; - wxString text(wxGetWindowText(GetHWND())); int widthTextMax = 0, widthLine, @@ -138,36 +122,16 @@ void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags) } } - int ww, hh; - GetSize(&ww, &hh); - - // If we're prepared to use the existing width, then... - if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH)) - { - actualWidth = ww; - } - else if (width == -1) - { - actualWidth = widthTextMax; - } - - // If we're prepared to use the existing height, then... - if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT)) - { - actualHeight = hh; - } - else if (height == -1) - { - actualHeight = heightTextTotal; - } - - MoveWindow(GetHwnd(), x1, y1, actualWidth, actualHeight, TRUE); + return wxSize(widthTextMax, heightTextTotal); } void wxStaticText::SetLabel(const wxString& label) { SetWindowText(GetHwnd(), label); + // adjust the size of the window to fit to the label (this behaviour is + // backward compatible and generally makes sense but we might want to still + // provide the user a way to disable it) (VZ) DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); } diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 97dfca82bd..9fdb36b9ef 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -336,53 +336,15 @@ void wxTextCtrl::SetValue(const wxString& value) AdjustSpaceLimit(); } -void wxTextCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags) +wxSize wxTextCtrl::DoGetBestSize() { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; + int cx, cy; + wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; + int wText = DEFAULT_ITEM_WIDTH; + int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - int cx; // button font dimensions - int cy; - - wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); - - int control_width, control_height, control_x, control_y; - - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } - - // Deal with default size (using -1 values) - if (w1<=0) - w1 = DEFAULT_ITEM_WIDTH; - - control_x = x1; - control_y = y1; - control_width = w1; - control_height = h1; - - // Calculations may have made text size too small - if (control_height <= 0) - control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); - - if (control_width <= 0) - control_width = DEFAULT_ITEM_WIDTH; - - MoveWindow(GetHwnd(), (int)control_x, (int)control_y, - (int)control_width, (int)control_height, TRUE); + return wxSize(wText, hText); } // Clipboard operations @@ -759,18 +721,23 @@ void wxTextCtrl::ShowPosition(long pos) int wxTextCtrl::GetLineLength(long lineNo) const { long charIndex = XYToPosition(0, lineNo); - HWND hWnd = GetHwnd(); - int len = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0); + int len = (int)SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0); return len; } wxString wxTextCtrl::GetLineText(long lineNo) const { - HWND hWnd = GetHwnd(); - *(WORD *)wxBuffer = 512; - int noChars = (int)SendMessage(hWnd, EM_GETLINE, (WPARAM)lineNo, (LPARAM)wxBuffer); - wxBuffer[noChars] = 0; - return wxString(wxBuffer); + size_t len = (size_t)GetLineLength(lineNo); + char *buf = (char *)malloc(len); + *(WORD *)buf = len; + int noChars = (int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf); + buf[noChars] = 0; + + wxString str(buf); + + free(buf); + + return str; } bool wxTextCtrl::CanCopy() const diff --git a/src/msw/window.cpp b/src/msw/window.cpp index dd54ee8e9b..c7a84bd1f8 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -1172,35 +1172,80 @@ void wxWindow::DoGetClientSize(int *x, int *y) const *y = rect.bottom; } +// set the size of the window: if the dimensions are positive, just use them, +// but if any of them is equal to -1, it means that we must find the value for +// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in +// which case -1 is a valid value for x and y) +// +// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate +// the width/height to best suit our contents, otherwise we reuse the current +// width/height void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) { + // get the current size and position... int currentX, currentY; GetPosition(¤tX, ¤tY); int currentW,currentH; GetSize(¤tW, ¤tH); - if ( x == currentX && y == currentY && width == currentW && height == currentH ) + // ... and don't do anything (avoiding flicker) if it's already ok + if ( x == currentX && y == currentY && + width == currentW && height == currentH ) + { return; + } - int actualWidth = width; - int actualHeight = height; - int actualX = x; - int actualY = y; if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) - actualX = currentX; + x = currentX; if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) - actualY = currentY; + y = currentY; - AdjustForParentClientOrigin(actualX, actualY, sizeFlags); + AdjustForParentClientOrigin(x, y, sizeFlags); + wxSize size(-1, -1); if ( width == -1 ) - actualWidth = currentW; + { + if ( sizeFlags && wxSIZE_AUTO_WIDTH ) + { + size = DoGetBestSize(); + width = size.x; + } + else + { + // just take the current one + width = currentW; + } + } + if ( height == -1 ) - actualHeight = currentH; + { + if ( sizeFlags && wxSIZE_AUTO_HEIGHT ) + { + if ( size.x == -1 ) + { + size= DoGetBestSize(); + } + //else: already called DoGetBestSize() above - HWND hWnd = GetHwnd(); - if ( hWnd ) - MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE); + height = size.y; + } + else + { + // just take the current one + height = currentH; + } + } + + if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) ) + { + wxLogLastError("MoveWindow"); + } +} + +// for a generic window there is no natural best size - just use the current one +wxSize wxWindow::DoGetBestSize() +{ + return GetSize(); } void wxWindow::DoSetClientSize(int width, int height) @@ -1316,7 +1361,7 @@ void wxWindow::GetTextExtent(const wxString& string, SIZE sizeRect; TEXTMETRIC tm; - GetTextExtentPoint(dc, (const wxChar *)string, (int)string.Length(), &sizeRect); + GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect); GetTextMetrics(dc, &tm); if ( fontToUse && fnt && hfontOld )