return false;
// now create the real HWND
- if ( !MSWCreateControl(wxT("COMBOBOX"), _T(""), pos, size) )
+ if ( !MSWCreateControl(wxT("COMBOBOX"), wxEmptyString, pos, size) )
return false;
UpdateVisibleHeight();
}
+ InvalidateBestSize();
return n;
}
UpdateVisibleHeight();
}
+ InvalidateBestSize();
return n;
}
if ( !IsFrozen() )
UpdateVisibleHeight();
+
+ InvalidateBestSize();
}
void wxChoice::Clear()
if ( !IsFrozen() )
UpdateVisibleHeight();
+
+ InvalidateBestSize();
}
void wxChoice::Free()
// ----------------------------------------------------------------------------
int wxChoice::GetSelection() const
+{
+ // if m_lastAcceptedSelection is set, it means that the dropdown is
+ // currently shown and that we want to use the last "permanent" selection
+ // instead of whatever is under the mouse pointer currently
+ //
+ // otherwise, get the selection from the control
+ return m_lastAcceptedSelection == wxID_NONE ? GetCurrentSelection()
+ : m_lastAcceptedSelection;
+}
+
+int wxChoice::GetCurrentSelection() const
{
return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0);
}
#else // !Watcom
//TODO: Evidently some MSW versions (all?) don't like empty strings
//passed to SendMessage, so we have to do it ourselves in that case
- if ( s.size() == 0 )
+ if ( s.empty() )
{
int count = GetCount();
for ( int i = 0; i < count; i++ )
{
- if ( GetString(i).size() == 0 )
+ if ( GetString(i).empty() )
return i;
}
{
int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT,
(WPARAM)-1, (LPARAM)s.c_str());
-
+
return pos == LB_ERR ? wxNOT_FOUND : pos;
}
#endif // Watcom/!Watcom
DoSetItemClientData(n, data);
}
//else: it's already NULL by default
+
+ InvalidateBestSize();
}
wxString wxChoice::GetString(int n) const
const int hItem = SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0);
height += hItem*(nItems + 1);
}
+ else
+ {
+ // We cannot pass wxDefaultCoord as height to wxControl. wxControl uses
+ // wxGetWindowRect() to determine the current height of the combobox,
+ // and then again sets the combobox's height to that value. Unfortunately,
+ // wxGetWindowRect doesn't include the dropdown list's height (at least
+ // on Win2K), so this would result in a combobox with dropdown height of
+ // 1 pixel. We have to determine the default height ourselves and call
+ // wxControl with that value instead.
+ int w, h;
+ RECT r;
+ DoGetSize(&w, &h);
+ if (::SendMessage(GetHwnd(), CB_GETDROPPEDCONTROLRECT, 0, (LPARAM) &r) != 0)
+ {
+ height = h + r.bottom - r.top;
+ }
+ }
wxControl::DoSetSize(x, y, width, height, sizeFlags);
// the combobox should be slightly larger than the widest string
wChoice += 5*GetCharWidth();
- return wxSize(wChoice, EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight()));
+ wxSize best(wChoice, EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight()));
+ CacheBestSize(best);
+ return best;
}
WXLRESULT wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
WXHWND hwnd;
UnpackCtlColor(wParam, lParam, &hdc, &hwnd);
- WXHBRUSH hbr = MSWControlColor((WXHDC)hdc);
+ WXHBRUSH hbr = MSWControlColor((WXHDC)hdc, hwnd);
if ( hbr )
return (WXLRESULT)hbr;
//else: fall through to default window proc
bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{
- if ( param != CBN_SELCHANGE)
+ switch ( param )
{
- // "selection changed" is the only event we're after
- return false;
- }
+ case CBN_DROPDOWN:
+ // we don't want to track selection using CB_GETCURSEL while the
+ // dropdown is opened
+ m_lastAcceptedSelection = GetCurrentSelection();
+ break;
- int n = GetSelection();
- if (n > -1)
- {
- wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
- event.SetInt(n);
- event.SetEventObject(this);
- event.SetString(GetStringSelection());
- if ( HasClientObjectData() )
- event.SetClientObject( GetClientObject(n) );
- else if ( HasClientUntypedData() )
- event.SetClientData( GetClientData(n) );
- ProcessCommand(event);
+ case CBN_CLOSEUP:
+ // it should be safe to use CB_GETCURSEL again
+ m_lastAcceptedSelection = wxID_NONE;
+ break;
+
+ case CBN_SELCHANGE:
+ {
+ const int n = GetSelection();
+
+ wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
+ event.SetInt(n);
+ event.SetEventObject(this);
+
+ if ( n > -1 )
+ {
+ event.SetString(GetStringSelection());
+ if ( HasClientObjectData() )
+ event.SetClientObject( GetClientObject(n) );
+ else if ( HasClientUntypedData() )
+ event.SetClientData( GetClientData(n) );
+ }
+
+ ProcessCommand(event);
+ }
+ return true;
}
- return true;
+ return false;
}
-WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC)
+WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd)
{
if ( !IsEnabled() )
return MSWControlColorDisabled(hDC);
- return wxChoiceBase::MSWControlColorSolid(hDC);
+ return wxChoiceBase::MSWControlColor(hDC, hWnd);
}
#endif // wxUSE_CHOICE && !(__SMARTPHONE__ && __WXWINCE__)