From d9e0958c7efdaa3866aa1e699258507884849592 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Thu, 6 Jul 2006 17:42:39 +0000 Subject: [PATCH] Added GetWidestItem() and GetWidestItemWidth() to wxVListBoxComboPopup and wxOwnerDrawnComboBox as per Jaakko Salli git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40029 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/odcombo.h | 15 ++++++++++ src/generic/odcombo.cpp | 63 ++++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/include/wx/odcombo.h b/include/wx/odcombo.h index c775096e31..451ab90e73 100644 --- a/include/wx/odcombo.h +++ b/include/wx/odcombo.h @@ -157,6 +157,12 @@ protected: void OnKey(wxKeyEvent& event); void OnLeftClick(wxMouseEvent& event); + // Return the widest item width (recalculating it if necessary) + int GetWidestItemWidth() { CalcWidths(); return m_widestWidth; } + + // Return the index of the widest item (recalculating it if necessary) + int GetWidestItem() { CalcWidths(); return m_widestItem; } + wxArrayString m_strings; wxArrayPtrVoid m_clientDatas; @@ -189,6 +195,9 @@ private: // has the mouse been released on this control? bool m_clicked; + // Recalculate widths if they are dirty + void CalcWidths(); + DECLARE_EVENT_TABLE() }; @@ -293,6 +302,12 @@ public: wxComboCtrl::SetSelection(from,to); } + // Return the widest item width (recalculating it if necessary) + virtual int GetWidestItemWidth() { EnsurePopupControl(); return GetVListBoxComboPopup()->GetWidestItemWidth(); } + + // Return the index of the widest item (recalculating it if necessary) + virtual int GetWidestItem() { EnsurePopupControl(); return GetVListBoxComboPopup()->GetWidestItem(); } + wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST protected: diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index 969d674f1d..f824fa3670 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -516,36 +516,8 @@ void wxVListBoxComboPopup::SetStringValue( const wxString& value ) wxVListBox::SetSelection(index); } -wxSize wxVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ) +void wxVListBoxComboPopup::CalcWidths() { - int height = 250; - - if ( m_strings.GetCount() ) - { - if ( prefHeight > 0 ) - height = prefHeight; - - if ( height > maxHeight ) - height = maxHeight; - - int totalHeight = GetTotalHeight(); // + 3; - if ( height >= totalHeight ) - { - height = totalHeight; - } - else - { - // Adjust height to a multiple of the height of the first item - // NB: Calculations that take variable height into account - // are unnecessary. - int fih = GetLineHeight(0); - int shown = height/fih; - height = shown * fih; - } - } - else - height = 50; - bool doFindWidest = m_findWidest; // Measure items with dirty width. @@ -631,6 +603,39 @@ wxSize wxVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int m_findWidest = false; } +} + +wxSize wxVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int maxHeight ) +{ + int height = 250; + + if ( m_strings.GetCount() ) + { + if ( prefHeight > 0 ) + height = prefHeight; + + if ( height > maxHeight ) + height = maxHeight; + + int totalHeight = GetTotalHeight(); // + 3; + if ( height >= totalHeight ) + { + height = totalHeight; + } + else + { + // Adjust height to a multiple of the height of the first item + // NB: Calculations that take variable height into account + // are unnecessary. + int fih = GetLineHeight(0); + int shown = height/fih; + height = shown * fih; + } + } + else + height = 50; + + CalcWidths(); // Take scrollbar into account in width calculations int widestWidth = m_widestWidth + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); -- 2.45.2