X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4438caf41af49f00f3c8137ac801871f59cce386..10fcf31a2cefc6a8224a33038cb255c082669d5f:/src/msw/listbox.cpp diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index b14384f8cf..34927877b2 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -29,6 +29,7 @@ #include "wx/brush.h" #include "wx/font.h" #include "wx/dc.h" +#include "wx/utils.h" #endif #include @@ -650,6 +651,35 @@ bool wxListBox::SetStringSelection (const wxString& s, bool flag) return FALSE; } +wxSize wxListBox::DoGetBestSize() +{ + // find the widest string + int wLine; + int wListbox = 0; + for ( int i = 0; i < m_noItems; i++ ) + { + wxString str(GetString(i)); + GetTextExtent(str, &wLine, NULL); + if ( wLine > wListbox ) + wListbox = wLine; + } + + // give it some reasonable default value if there are no strings in the + // list + if ( wListbox == 0 ) + wListbox = 100; + + // the listbox should be slightly larger than the widest string + int cx, cy; + wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); + + wListbox += 3*cx; + + int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*(wxMax(m_noItems, 7)); + + return wxSize(wListbox, hListbox); +} + // Is this the right thing? Won't setselection generate a command // event too? No! It'll just generate a setselection event. // But we still can't have this being called whenever a real command