From: Robin Dunn Date: Wed, 18 May 2005 02:23:01 +0000 (+0000) Subject: Patch #1203934: enable best size caching for MSW widgets X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/31582e4e11d504a28461d62b05411202d3a906d0 Patch #1203934: enable best size caching for MSW widgets git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34120 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/bmpbuttn.cpp b/src/msw/bmpbuttn.cpp index e1be21611f..05d6d3807a 100644 --- a/src/msw/bmpbuttn.cpp +++ b/src/msw/bmpbuttn.cpp @@ -494,8 +494,10 @@ wxSize wxBitmapButton::DoGetBestSize() const { if ( m_bmpNormal.Ok() ) { - return wxSize(m_bmpNormal.GetWidth() + 2*m_marginX, + wxSize best(m_bmpNormal.GetWidth() + 2*m_marginX, m_bmpNormal.GetHeight() + 2*m_marginY); + CacheBestSize(best); + return best; } // no idea what our best size should be, defer to the base class diff --git a/src/msw/button.cpp b/src/msw/button.cpp index b50d0c6bd8..b9ac736375 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -241,7 +241,9 @@ wxSize wxButton::DoGetBestSize() const return sz; } - return wxSize(wBtn, hBtn); + wxSize best(wBtn, hBtn); + CacheBestSize(best); + return best; } /* static */ diff --git a/src/msw/checkbox.cpp b/src/msw/checkbox.cpp index 3955dba064..709a7491fb 100644 --- a/src/msw/checkbox.cpp +++ b/src/msw/checkbox.cpp @@ -198,7 +198,9 @@ wxSize wxCheckBox::DoGetBestSize() const hCheckbox += 1; #endif - return wxSize(wCheckbox, hCheckbox); + wxSize best(wCheckbox, hCheckbox); + CacheBestSize(best); + return best; } void wxCheckBox::SetValue(bool val) diff --git a/src/msw/checklst.cpp b/src/msw/checklst.cpp index 8327c328af..602bab2372 100644 --- a/src/msw/checklst.cpp +++ b/src/msw/checklst.cpp @@ -548,6 +548,7 @@ wxSize wxCheckListBox::DoGetBestSize() const { wxSize best = wxListBox::DoGetBestSize(); best.x += wxOwnerDrawn::GetDefaultMarginWidth(); // add room for the checkbox + CacheBestSize(best); return best; } diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 2a83571ecb..859e700b71 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -236,6 +236,7 @@ int wxChoice::DoAppend(const wxString& item) UpdateVisibleHeight(); } + InvalidateBestSize(); return n; } @@ -255,6 +256,7 @@ int wxChoice::DoInsert(const wxString& item, int pos) UpdateVisibleHeight(); } + InvalidateBestSize(); return n; } @@ -271,6 +273,8 @@ void wxChoice::Delete(int n) if ( !IsFrozen() ) UpdateVisibleHeight(); + + InvalidateBestSize(); } void wxChoice::Clear() @@ -281,6 +285,8 @@ void wxChoice::Clear() if ( !IsFrozen() ) UpdateVisibleHeight(); + + InvalidateBestSize(); } void wxChoice::Free() @@ -383,6 +389,8 @@ void wxChoice::SetString(int n, const wxString& s) DoSetItemClientData(n, data); } //else: it's already NULL by default + + InvalidateBestSize(); } wxString wxChoice::GetString(int n) const diff --git a/src/msw/datectrl.cpp b/src/msw/datectrl.cpp index 4b6c8c6e61..7f00c820f5 100644 --- a/src/msw/datectrl.cpp +++ b/src/msw/datectrl.cpp @@ -180,7 +180,9 @@ wxSize wxDatePickerCtrl::DoGetBestSize() const { const int y = GetCharHeight(); - return wxSize(DEFAULT_ITEM_WIDTH, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y)); + wxSize best(DEFAULT_ITEM_WIDTH, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y)); + CacheBestSize(best); + return best; } // ---------------------------------------------------------------------------- diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index eafc7c1909..c799cf3479 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -279,12 +279,12 @@ void wxListBox::Delete(int N) m_noItems--; SetHorizontalExtent(wxEmptyString); + + InvalidateBestSize(); } int wxListBox::DoAppend(const wxString& item) { - InvalidateBestSize(); - int index = ListBox_AddString(GetHwnd(), item); m_noItems++; @@ -300,6 +300,7 @@ int wxListBox::DoAppend(const wxString& item) SetHorizontalExtent(item); + InvalidateBestSize(); return index; } @@ -347,6 +348,8 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) // show the listbox back if we hid it ShowWindow(GetHwnd(), SW_SHOW); } + + InvalidateBestSize(); } int wxListBox::FindString(const wxString& s) const @@ -366,6 +369,8 @@ void wxListBox::Clear() m_noItems = 0; SetHorizontalExtent(); + + InvalidateBestSize(); } void wxListBox::Free() @@ -520,8 +525,6 @@ wxListBox::DoInsertItems(const wxArrayString& items, int pos) wxCHECK_RET( pos >= 0 && pos <= m_noItems, wxT("invalid index in wxListBox::InsertItems") ); - InvalidateBestSize(); - int nItems = items.GetCount(); for ( int i = 0; i < nItems; i++ ) { @@ -545,6 +548,8 @@ wxListBox::DoInsertItems(const wxArrayString& items, int pos) m_noItems += nItems; SetHorizontalExtent(); + + InvalidateBestSize(); } void wxListBox::SetString(int N, const wxString& s) @@ -591,6 +596,8 @@ void wxListBox::SetString(int N, const wxString& s) // we may have lost the selection if ( wasSelected ) Select(N); + + InvalidateBestSize(); } int wxListBox::GetCount() const @@ -691,7 +698,9 @@ wxSize wxListBox::DoGetBestSize() const int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)* wxMin(wxMax(m_noItems, 3), 10); - return wxSize(wListbox, hListbox); + wxSize best(wListbox, hListbox); + CacheBestSize(best); + return best; } // ---------------------------------------------------------------------------- diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index 21fb1fd4f4..b5cdc6eeda 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -374,6 +374,8 @@ void wxRadioBox::SetString(int item, const wxString& label) m_radioHeight[item] = wxDefaultCoord; ::SetWindowText((*m_radioButtons)[item], label.c_str()); + + InvalidateBestSize(); } void wxRadioBox::SetSelection(int N) @@ -428,7 +430,10 @@ bool wxRadioBox::Show(int item, bool show) BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE); - return (ret != 0) == show; + bool changed = (ret != 0) == show; + if( changed ) + InvalidateBestSize(); + return changed; } WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons) @@ -498,7 +503,9 @@ wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const wxSize wxRadioBox::DoGetBestSize() const { - return GetTotalButtonSize(GetMaxButtonSize()); + wxSize best = GetTotalButtonSize(GetMaxButtonSize()); + CacheBestSize(best); + return best; } // Restored old code. diff --git a/src/msw/radiobut.cpp b/src/msw/radiobut.cpp index e88d6d7829..5bab310337 100644 --- a/src/msw/radiobut.cpp +++ b/src/msw/radiobut.cpp @@ -312,7 +312,9 @@ wxSize wxRadioButton::DoGetBestSize() const hRadio = s_radioSize; } - return wxSize(wRadio, hRadio); + wxSize best(wRadio, hRadio); + CacheBestSize(best); + return best; } #endif // wxUSE_RADIOBTN diff --git a/src/msw/scrolbar.cpp b/src/msw/scrolbar.cpp index 9c9da3082d..421e47578b 100644 --- a/src/msw/scrolbar.cpp +++ b/src/msw/scrolbar.cpp @@ -325,7 +325,9 @@ wxSize wxScrollBar::DoGetBestSize() const h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); } - return wxSize(w, h); + wxSize best(w, h); + CacheBestSize(best); + return best; } WXDWORD wxScrollBar::MSWGetStyle(long style, WXDWORD *exstyle) const diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index f7c3e6e206..61d7b01e76 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -208,7 +208,11 @@ void wxStaticBitmap::Free() wxSize wxStaticBitmap::DoGetBestSize() const { if ( ImageIsOk() ) - return wxSize(m_image->GetWidth(), m_image->GetHeight()); + { + wxSize best(m_image->GetWidth(), m_image->GetHeight()); + CacheBestSize(best); + return best; + } // this is completely arbitrary return wxSize(16, 16); diff --git a/src/msw/statbox.cpp b/src/msw/statbox.cpp index 3ccf5f6e34..42fec06f70 100644 --- a/src/msw/statbox.cpp +++ b/src/msw/statbox.cpp @@ -168,7 +168,9 @@ wxSize wxStaticBox::DoGetBestSize() const wBox += 3*cx; int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); - return wxSize(wBox, hBox); + wxSize best(wBox, hBox); + CacheBestSize(best); + return best; } void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const diff --git a/src/msw/stattext.cpp b/src/msw/stattext.cpp index 124d9e471d..cc4b995d2d 100644 --- a/src/msw/stattext.cpp +++ b/src/msw/stattext.cpp @@ -143,7 +143,9 @@ wxSize wxStaticText::DoGetBestSize() const widthTextMax += 2; #endif // __WXWINCE__ - return wxSize(widthTextMax, heightTextTotal); + wxSize best(widthTextMax, heightTextTotal); + CacheBestSize(best); + return best; } void wxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags) diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 7ea83bd343..1286461f05 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -378,6 +378,7 @@ wxSize wxToolBar::DoGetBestSize() const sizeBest.y = size.cy; } + CacheBestSize(sizeBest); return sizeBest; } diff --git a/src/msw/tglbtn.cpp b/src/msw/tglbtn.cpp index 6b91280e85..c3f1af62bc 100644 --- a/src/msw/tglbtn.cpp +++ b/src/msw/tglbtn.cpp @@ -135,6 +135,7 @@ wxSize wxToggleButton::DoGetBestSize() const wxSize sz(wBtn, hBtn); #endif + CacheBestSize(sz); return sz; }