X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/71e57cd6506760f7ca0e3195a5ecf99d78a77be9..569f027b89890ed6f5ddbaf45bb1b53810e3519d:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 719e977f41..e80ff3b166 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -127,14 +127,39 @@ bool wxChoice::Create(wxWindow *parent, validator, name); } -bool wxChoice::CreateAndInit(wxWindow *parent, wxWindowID id, +bool wxChoice::CreateAndInit(wxWindow *parent, + wxWindowID id, const wxPoint& pos, - const wxSize& size, + const wxSize& sizeOrig, int n, const wxString choices[], long style, const wxValidator& validator, const wxString& name) { + // this is a bit hackish but we want to prevent MSWCreateControl() from + // calling SetBestSize() (which it would do if any of the size components + // is not given) because it wouldn't calculate it correctly if we have any + // strings as they're not yet added to the control when it is called + // + // so: if we have any strings, we fudge the size parameter so that + // SetBestSize() is not called by MSWCreateControl() but then we do call it + // manually below + bool autoSize = false; + wxSize size = sizeOrig; + if ( n ) + { + if ( size.x < 0 ) + { + size.x = 1; + autoSize = true; + } + if ( size.y < 0 ) + { + size.y = 1; + autoSize = true; + } + } + // initialize wxControl if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return FALSE; @@ -148,12 +173,18 @@ bool wxChoice::CreateAndInit(wxWindow *parent, wxWindowID id, // course) background rather than inheriting the parent's background SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - // initialize + // initialize the controls contents for ( int i = 0; i < n; i++ ) { Append(choices[i]); } + // and now we may finally size the control properly (if needed) + if ( autoSize ) + { + SetBestSize(sizeOrig); + } + return TRUE; } @@ -202,7 +233,7 @@ wxChoice::~wxChoice() int wxChoice::DoAppend(const wxString& item) { - int n = (int)SendMessage(GetHwnd(), CB_ADDSTRING, 0, (LONG)item.c_str()); + int n = (int)SendMessage(GetHwnd(), CB_ADDSTRING, 0, (LPARAM)item.c_str()); if ( n == CB_ERR ) { wxLogLastError(wxT("SendMessage(CB_ADDSTRING)")); @@ -222,7 +253,7 @@ int wxChoice::DoInsert(const wxString& item, int pos) wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list")); wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index")); - int n = (int)SendMessage(GetHwnd(), CB_INSERTSTRING, pos, (LONG)item.c_str()); + int n = (int)SendMessage(GetHwnd(), CB_INSERTSTRING, pos, (LPARAM)item.c_str()); if ( n == CB_ERR ) { wxLogLastError(wxT("SendMessage(CB_INSERTSTRING)")); @@ -407,14 +438,10 @@ wxClientData* wxChoice::DoGetItemClientObject( int n ) const // wxMSW specific helpers // ---------------------------------------------------------------------------- -int wxChoice::GetVisibleHeight() const -{ - return ::SendMessage(GetHwnd(), CB_GETITEMHEIGHT, (WPARAM)-1, 0); -} - void wxChoice::UpdateVisibleHeight() { - DoSetSize(-1, -1, -1, GetVisibleHeight()); + // be careful to not change the width here + DoSetSize(-1, -1, -1, GetSize().y, wxSIZE_USE_EXISTING); } void wxChoice::DoMoveWindow(int x, int y, int width, int height) @@ -437,13 +464,11 @@ void wxChoice::DoMoveWindow(int x, int y, int width, int height) void wxChoice::DoGetSize(int *w, int *h) const { + // this is weird: sometimes, the height returned by Windows is clearly the + // total height of the control including the drop down list -- but only + // sometimes, and normally it isn't... I have no idea about what to do with + // this wxControl::DoGetSize(w, h); - - // we need to return only the height of the visible part, not the entire - // height in the Windows sense which includes the height of the drop down - // list as well - if ( h ) - *h = GetVisibleHeight(); } void wxChoice::DoSetSize(int x, int y, @@ -477,10 +502,11 @@ void wxChoice::DoSetSize(int x, int y, // as it is not affected by normal WM_SETSIZE if ( height != -1 ) { - const int hVisibleCurrent = GetVisibleHeight(); - if ( hVisibleCurrent != heightOrig ) + const int delta = heightOrig - GetSize().y; + if ( delta ) { - SendMessage(GetHwnd(), CB_SETITEMHEIGHT, (WPARAM)-1, heightOrig); + int h = ::SendMessage(GetHwnd(), CB_GETITEMHEIGHT, (WPARAM)-1, 0); + SendMessage(GetHwnd(), CB_SETITEMHEIGHT, (WPARAM)-1, h + delta); } } } @@ -506,10 +532,10 @@ wxSize wxChoice::DoGetBestSize() const // the combobox should be slightly larger than the widest string wChoice += 5*GetCharWidth(); - return wxSize(wChoice, GetVisibleHeight()); + return wxSize(wChoice, EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight())); } -long wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +WXLRESULT wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { if ( nMsg == WM_LBUTTONUP ) {