From e78c4d503ecd57835502fb1bbd13a71cb99019d0 Mon Sep 17 00:00:00 2001 From: David Webster Date: Sun, 21 Nov 1999 01:03:00 +0000 Subject: [PATCH] updates for DoGetBestSize git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4639 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/os2/button.h | 2 +- include/wx/os2/checkbox.h | 2 +- include/wx/os2/choice.h | 2 +- include/wx/os2/control.h | 2 +- include/wx/os2/listbox.h | 2 +- include/wx/os2/spinbutt.h | 4 ++-- include/wx/os2/statbmp.h | 2 +- include/wx/os2/statbox.h | 2 +- include/wx/os2/stattext.h | 2 +- include/wx/os2/textctrl.h | 2 +- include/wx/os2/window.h | 4 ---- src/os2/app.cpp | 1 - src/os2/button.cpp | 4 ++-- src/os2/checkbox.cpp | 2 +- src/os2/choice.cpp | 4 ++-- src/os2/control.cpp | 2 +- src/os2/listbox.cpp | 4 ++-- src/os2/spinbutt.cpp | 2 +- src/os2/statbmp.cpp | 2 +- src/os2/statbox.cpp | 4 ++-- src/os2/stattext.cpp | 25 +++++++++++++++++------ src/os2/textctrl.cpp | 4 ++-- src/os2/thread.cpp | 42 --------------------------------------- src/os2/window.cpp | 6 ------ 24 files changed, 44 insertions(+), 84 deletions(-) diff --git a/include/wx/os2/button.h b/include/wx/os2/button.h index 2626a0aa9c..ed2c8a8f40 100644 --- a/include/wx/os2/button.h +++ b/include/wx/os2/button.h @@ -59,7 +59,7 @@ protected: // send a notification event, return TRUE if processed bool SendClickEvent(); - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; }; #endif diff --git a/include/wx/os2/checkbox.h b/include/wx/os2/checkbox.h index c3fc2e2513..4b0bff3419 100644 --- a/include/wx/os2/checkbox.h +++ b/include/wx/os2/checkbox.h @@ -53,7 +53,7 @@ class WXDLLEXPORT wxCheckBox: public wxControl WXUINT message, WXWPARAM wParam, WXLPARAM lParam); protected: - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; }; class WXDLLEXPORT wxBitmapCheckBox: public wxCheckBox diff --git a/include/wx/os2/choice.h b/include/wx/os2/choice.h index 1e3fc5a02b..f2c7efe954 100644 --- a/include/wx/os2/choice.h +++ b/include/wx/os2/choice.h @@ -70,7 +70,7 @@ protected: virtual wxClientData* DoGetItemClientObject( int n ) const; // OS2 implementation - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); diff --git a/include/wx/os2/control.h b/include/wx/os2/control.h index 28dd3626ec..9563c9e536 100644 --- a/include/wx/os2/control.h +++ b/include/wx/os2/control.h @@ -63,7 +63,7 @@ protected: // For controls like radiobuttons which are really composite wxList m_subControls; - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; // create the control of the given class with the given style, returns FALSE // if creation failed diff --git a/include/wx/os2/listbox.h b/include/wx/os2/listbox.h index 4bc2ade8be..790d8606ac 100644 --- a/include/wx/os2/listbox.h +++ b/include/wx/os2/listbox.h @@ -123,7 +123,7 @@ protected: int m_noItems; int m_selected; - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; #if wxUSE_OWNER_DRAWN // control items diff --git a/include/wx/os2/spinbutt.h b/include/wx/os2/spinbutt.h index 12d4ecb62a..f46a0b2393 100644 --- a/include/wx/os2/spinbutt.h +++ b/include/wx/os2/spinbutt.h @@ -49,7 +49,7 @@ public: ,int maxVal ); - // Implementation + // Implementation virtual bool OS2Command( WXUINT param ,WXWORD id ); @@ -64,7 +64,7 @@ public: ); protected: - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; private: DECLARE_DYNAMIC_CLASS(wxSpinButton) }; diff --git a/include/wx/os2/statbmp.h b/include/wx/os2/statbmp.h index 394977fddc..90721844b8 100644 --- a/include/wx/os2/statbmp.h +++ b/include/wx/os2/statbmp.h @@ -71,7 +71,7 @@ protected: wxBitmap *bitmap; } m_image; - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; }; #endif diff --git a/include/wx/os2/statbox.h b/include/wx/os2/statbox.h index f5a9cb5b53..a8f504fec2 100644 --- a/include/wx/os2/statbox.h +++ b/include/wx/os2/statbox.h @@ -58,7 +58,7 @@ class WXDLLEXPORT wxStaticBox: public wxControl virtual bool AcceptsFocus() const { return FALSE; } protected: - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; private: DECLARE_EVENT_TABLE() diff --git a/include/wx/os2/stattext.h b/include/wx/os2/stattext.h index bd58678f76..b410f9787b 100644 --- a/include/wx/os2/stattext.h +++ b/include/wx/os2/stattext.h @@ -56,7 +56,7 @@ class WXDLLEXPORT wxStaticText: public wxControl virtual MRESULT OS2WindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); protected: - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; }; #endif diff --git a/include/wx/os2/textctrl.h b/include/wx/os2/textctrl.h index a378830e55..7f819fe260 100644 --- a/include/wx/os2/textctrl.h +++ b/include/wx/os2/textctrl.h @@ -146,7 +146,7 @@ protected: // limit is big enough) void AdjustSpaceLimit(); - virtual wxSize DoGetBestSize(); + virtual wxSize DoGetBestSize() const; private: DECLARE_EVENT_TABLE() diff --git a/include/wx/os2/window.h b/include/wx/os2/window.h index 96c4c08469..3688662527 100644 --- a/include/wx/os2/window.h +++ b/include/wx/os2/window.h @@ -524,10 +524,6 @@ protected: ,int nHeight ); - // 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(void); - // move the window to the specified location and resize it: this is called // from both DoSetSize() and DoSetClientSize() and would usually just call // ::MoveWindow() except for composite controls which will want to arrange diff --git a/src/os2/app.cpp b/src/os2/app.cpp index aa1551b0c8..f4f9a25d9c 100644 --- a/src/os2/app.cpp +++ b/src/os2/app.cpp @@ -923,4 +923,3 @@ void wxSetInstance(HINSTANCE hInst) wxhInstance = hInst; } - diff --git a/src/os2/button.cpp b/src/os2/button.cpp index c4f5ac0f10..c9a6387c1e 100644 --- a/src/os2/button.cpp +++ b/src/os2/button.cpp @@ -72,14 +72,14 @@ wxButton::~wxButton() // size management including autosizing // ---------------------------------------------------------------------------- -wxSize wxButton::DoGetBestSize() +wxSize wxButton::DoGetBestSize() const { wxString label = wxGetWindowText(GetHWND()); int wBtn; GetTextExtent(label, &wBtn, NULL); int wChar, hChar; - wxGetCharSize(GetHWND(), &wChar, &hChar, &GetFont()); + wxGetCharSize(GetHWND(), &wChar, &hChar, (wxFont*)&GetFont()); // add a margin - the button is wider than just its label wBtn += 3*wChar; diff --git a/src/os2/checkbox.cpp b/src/os2/checkbox.cpp index c4a3b2f099..84a6ab65ae 100644 --- a/src/os2/checkbox.cpp +++ b/src/os2/checkbox.cpp @@ -96,7 +96,7 @@ void wxCheckBox::SetLabel(const wxString& label) // TODO } -wxSize wxCheckBox::DoGetBestSize() +wxSize wxCheckBox::DoGetBestSize() const { int wCheckbox, hCheckbox; diff --git a/src/os2/choice.cpp b/src/os2/choice.cpp index b5dc463a1e..be96555450 100644 --- a/src/os2/choice.cpp +++ b/src/os2/choice.cpp @@ -216,7 +216,7 @@ void wxChoice::DoSetSize(int x, int y, wxControl::DoSetSize(x, y, width, -1, sizeFlags); } -wxSize wxChoice::DoGetBestSize() +wxSize wxChoice::DoGetBestSize() const { // find the widest string int wLine; @@ -237,7 +237,7 @@ wxSize wxChoice::DoGetBestSize() // the combobox should be larger than the widest string int cx, cy; - wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); + wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont()); wChoice += 5*cx; diff --git a/src/os2/control.cpp b/src/os2/control.cpp index 57cfe9e6df..16a0cb09ad 100644 --- a/src/os2/control.cpp +++ b/src/os2/control.cpp @@ -81,7 +81,7 @@ bool wxControl::OS2CreateControl(const wxChar *classname, WXDWORD style) return TRUE; } -wxSize wxControl::DoGetBestSize() +wxSize wxControl::DoGetBestSize() const { return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT); } diff --git a/src/os2/listbox.cpp b/src/os2/listbox.cpp index f90d2d1417..5408910fb3 100644 --- a/src/os2/listbox.cpp +++ b/src/os2/listbox.cpp @@ -606,7 +606,7 @@ void wxListBox::SetHorizontalExtent(const wxString& s) */ } -wxSize wxListBox::DoGetBestSize() +wxSize wxListBox::DoGetBestSize() const { // find the widest string int wLine; @@ -626,7 +626,7 @@ wxSize wxListBox::DoGetBestSize() // the listbox should be slightly larger than the widest string int cx, cy; - wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); + wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont()); wListbox += 3*cx; diff --git a/src/os2/spinbutt.cpp b/src/os2/spinbutt.cpp index 554c1a692c..df775d9b3a 100644 --- a/src/os2/spinbutt.cpp +++ b/src/os2/spinbutt.cpp @@ -65,7 +65,7 @@ wxSpinButton::~wxSpinButton() // size calculation // ---------------------------------------------------------------------------- -wxSize wxSpinButton::DoGetBestSize() +wxSize wxSpinButton::DoGetBestSize() const { // TODO: /* diff --git a/src/os2/statbmp.cpp b/src/os2/statbmp.cpp index 8a6baa82ee..bc19e866fe 100644 --- a/src/os2/statbmp.cpp +++ b/src/os2/statbmp.cpp @@ -100,7 +100,7 @@ void wxStaticBitmap::Free() m_image.icon = NULL; } -wxSize wxStaticBitmap::DoGetBestSize() +wxSize wxStaticBitmap::DoGetBestSize() const { // reuse the current size (as wxWindow does) instead of using some // arbitrary default size (as wxControl, our immediate base class, does) diff --git a/src/os2/statbox.cpp b/src/os2/statbox.cpp index 97f0152e57..1911f67045 100644 --- a/src/os2/statbox.cpp +++ b/src/os2/statbox.cpp @@ -93,10 +93,10 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, return FALSE; } -wxSize wxStaticBox::DoGetBestSize() +wxSize wxStaticBox::DoGetBestSize() const { int cx, cy; - wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); + wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont()); int wBox; GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy); diff --git a/src/os2/stattext.cpp b/src/os2/stattext.cpp index 91b15ada8f..524cd0d9ba 100644 --- a/src/os2/stattext.cpp +++ b/src/os2/stattext.cpp @@ -60,20 +60,33 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, return FALSE; } -wxSize wxStaticText::DoGetBestSize() +wxSize wxStaticText::DoGetBestSize() const { wxString text(wxGetWindowText(GetHWND())); int widthTextMax = 0, widthLine, - heightTextTotal = 0, heightLine; + heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; wxString curLine; for ( const wxChar *pc = text; ; pc++ ) { if ( *pc == wxT('\n') || *pc == wxT('\0') ) { - GetTextExtent(curLine, &widthLine, &heightLine); - if ( widthLine > widthTextMax ) - widthTextMax = widthLine; - heightTextTotal += heightLine; + if ( !curLine ) { + // we can't use GetTextExtent - it will return 0 for both width + // and height and an empty line should count in height + // calculation + if ( !heightLineDefault ) + heightLineDefault = heightLine; + if ( !heightLineDefault ) + GetTextExtent(_T("W"), NULL, &heightLineDefault); + + heightTextTotal += heightLineDefault; + } + else { + GetTextExtent(curLine, &widthLine, &heightLine); + if ( widthLine > widthTextMax ) + widthTextMax = widthLine; + heightTextTotal += heightLine; + } if ( *pc == wxT('\n') ) { curLine.Empty(); diff --git a/src/os2/textctrl.cpp b/src/os2/textctrl.cpp index 20aeec6bb9..1069c43882 100644 --- a/src/os2/textctrl.cpp +++ b/src/os2/textctrl.cpp @@ -798,10 +798,10 @@ bool wxTextCtrl::AcceptsFocus() const return IsEditable() && wxControl::AcceptsFocus(); } -wxSize wxTextCtrl::DoGetBestSize() +wxSize wxTextCtrl::DoGetBestSize() const { int cx, cy; - wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); + wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont()); int wText = DEFAULT_ITEM_WIDTH; diff --git a/src/os2/thread.cpp b/src/os2/thread.cpp index 51c3dd4f42..a26fbf6e4b 100644 --- a/src/os2/thread.cpp +++ b/src/os2/thread.cpp @@ -239,48 +239,6 @@ void wxCondition::Broadcast() } } -// ---------------------------------------------------------------------------- -// wxCriticalSection implementation -// ---------------------------------------------------------------------------- - -class wxCriticalSectionInternal -{ -public: - // init the critical section object - wxCriticalSectionInternal() - { } - - // free the associated ressources - ~wxCriticalSectionInternal() - { } - -private: -}; - -// ---------------------------------------------------------------------------- -// wxCriticalSection implementation -// ---------------------------------------------------------------------------- - -wxCriticalSection::wxCriticalSection() -{ - m_critsect = new wxCriticalSectionInternal; -} - -wxCriticalSection::~wxCriticalSection() -{ - delete m_critsect; -} - -void wxCriticalSection::Enter() -{ - ::DosEnterCritSec(); -} - -void wxCriticalSection::Leave() -{ - ::DosExitCritSec(); -} - // ---------------------------------------------------------------------------- // wxThread implementation // ---------------------------------------------------------------------------- diff --git a/src/os2/window.cpp b/src/os2/window.cpp index ebb2c611d2..8d2385f4d1 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -814,12 +814,6 @@ void wxWindow::DoSetSize(int x, int y, // TODO: } -// 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) { // TODO: -- 2.45.2