#include "wx/brush.h"
#include "wx/font.h"
#include "wx/dc.h"
+#include "wx/utils.h"
#endif
#include <windowsx.h>
#ifndef __TWIN32__
#if defined(__GNUWIN32__)
- #include <wx/msw/gnuwin32/extra.h>
+ #ifndef wxUSE_NORLANDER_HEADERS
+ #include <wx/msw/gnuwin32/extra.h>
+ #endif
#endif
#endif
return result;
}
-void wxListBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
- int currentX, currentY;
- GetPosition(¤tX, ¤tY);
-
- int x1 = x;
- int y1 = y;
- int w1 = width;
- int h1 = height;
-
- if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
- x1 = currentX;
- if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
- y1 = currentY;
-
- AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
- // If we're prepared to use the existing size, then...
- if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
- {
- GetSize(&w1, &h1);
- }
-
- int cx; // button font dimensions
- int cy;
-
- wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
-
- float control_width, control_height, control_x, control_y;
-
- // Deal with default size (using -1 values)
- if (w1<=0)
- w1 = DEFAULT_ITEM_WIDTH;
-
- if (h1<=0)
- h1 = DEFAULT_ITEM_HEIGHT;
-
- control_x = (float)x1;
- control_y = (float)y1;
- control_width = (float)w1;
- control_height = (float)h1;
-
- // Calculations may have made size too small
- if (control_height <= 0)
- control_height = (float)DEFAULT_ITEM_HEIGHT;
-
- if (control_width <= 0)
- control_width = (float)DEFAULT_ITEM_WIDTH;
-
- MoveWindow(GetHwnd(),
- (int)control_x, (int)control_y,
- (int)control_width, (int)control_height,
- TRUE);
-
-}
-
-// Windows-specific code to set the horizontal extent of
-// the listbox, if necessary. If s is non-NULL, it's
-// used to calculate the horizontal extent.
+// Windows-specific code to set the horizontal extent of the listbox, if
+// necessary. If s is non-NULL, it's used to calculate the horizontal extent.
// Otherwise, all strings are used.
void wxListBox::SetHorizontalExtent(const wxString& s)
{
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