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
This commit is contained in:
Alex Bligh
2006-07-06 17:42:39 +00:00
parent ca5db7b213
commit d9e0958c7e
2 changed files with 49 additions and 29 deletions

View File

@@ -157,6 +157,12 @@ protected:
void OnKey(wxKeyEvent& event); void OnKey(wxKeyEvent& event);
void OnLeftClick(wxMouseEvent& 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; wxArrayString m_strings;
wxArrayPtrVoid m_clientDatas; wxArrayPtrVoid m_clientDatas;
@@ -189,6 +195,9 @@ private:
// has the mouse been released on this control? // has the mouse been released on this control?
bool m_clicked; bool m_clicked;
// Recalculate widths if they are dirty
void CalcWidths();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
@@ -293,6 +302,12 @@ public:
wxComboCtrl::SetSelection(from,to); 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 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
protected: protected:

View File

@@ -516,36 +516,8 @@ void wxVListBoxComboPopup::SetStringValue( const wxString& value )
wxVListBox::SetSelection(index); 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; bool doFindWidest = m_findWidest;
// Measure items with dirty width. // Measure items with dirty width.
@@ -631,6 +603,39 @@ wxSize wxVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int
m_findWidest = false; 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 // Take scrollbar into account in width calculations
int widestWidth = m_widestWidth + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); int widestWidth = m_widestWidth + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);