X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/598ddd96f45745188c96f16757f7ceeaa0c8d70d..b9efe021b554fa3967d1442cf758435c5cd5ae8f:/src/msw/listbox.cpp?ds=sidebyside diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index df49c91cc6..ffe24da141 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -43,10 +43,6 @@ #include "wx/ownerdrw.h" #endif -#ifdef __GNUWIN32_OLD__ - #include "wx/msw/gnuwin32/extra.h" -#endif - #if wxUSE_EXTENDED_RTTI WX_DEFINE_FLAGS( wxListBoxStyle ) @@ -178,6 +174,10 @@ bool wxListBox::Create(wxWindow *parent, return false; } + // Necessary to prevent scroll problems within a notebook with Windows + // effects enabled + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + // initialize the contents for ( int i = 0; i < n; i++ ) { @@ -283,12 +283,12 @@ void wxListBox::Delete(int N) m_noItems--; SetHorizontalExtent(wxEmptyString); + + InvalidateBestSize(); } int wxListBox::DoAppend(const wxString& item) { - InvalidateBestSize(); - int index = ListBox_AddString(GetHwnd(), item); m_noItems++; @@ -304,6 +304,7 @@ int wxListBox::DoAppend(const wxString& item) SetHorizontalExtent(item); + InvalidateBestSize(); return index; } @@ -351,6 +352,8 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) // show the listbox back if we hid it ShowWindow(GetHwnd(), SW_SHOW); } + + InvalidateBestSize(); } int wxListBox::FindString(const wxString& s) const @@ -370,6 +373,8 @@ void wxListBox::Clear() m_noItems = 0; SetHorizontalExtent(); + + InvalidateBestSize(); } void wxListBox::Free() @@ -390,7 +395,7 @@ void wxListBox::Free() } } -void wxListBox::SetSelection(int N, bool select) +void wxListBox::DoSetSelection(int N, bool select) { wxCHECK_RET( N == wxNOT_FOUND || (N >= 0 && N < m_noItems), @@ -507,13 +512,13 @@ int wxListBox::GetSelection() const wxString wxListBox::GetString(int N) const { wxCHECK_MSG( N >= 0 && N < m_noItems, wxEmptyString, - wxT("invalid index in wxListBox::GetClientData") ); + wxT("invalid index in wxListBox::GetString") ); int len = ListBox_GetTextLen(GetHwnd(), N); // +1 for terminating NUL wxString result; - ListBox_GetText(GetHwnd(), N, wxStringBuffer(result, len + 1)); + ListBox_GetText(GetHwnd(), N, (wxChar*)wxStringBuffer(result, len + 1)); return result; } @@ -524,8 +529,6 @@ wxListBox::DoInsertItems(const wxArrayString& items, int pos) wxCHECK_RET( pos >= 0 && pos <= m_noItems, wxT("invalid index in wxListBox::InsertItems") ); - InvalidateBestSize(); - int nItems = items.GetCount(); for ( int i = 0; i < nItems; i++ ) { @@ -549,6 +552,8 @@ wxListBox::DoInsertItems(const wxArrayString& items, int pos) m_noItems += nItems; SetHorizontalExtent(); + + InvalidateBestSize(); } void wxListBox::SetString(int N, const wxString& s) @@ -595,6 +600,8 @@ void wxListBox::SetString(int N, const wxString& s) // we may have lost the selection if ( wasSelected ) Select(N); + + InvalidateBestSize(); } int wxListBox::GetCount() const @@ -616,17 +623,17 @@ void wxListBox::SetHorizontalExtent(const wxString& s) return; TEXTMETRIC lpTextMetric; - if ( !s.IsEmpty() ) + if ( !s.empty() ) { int existingExtent = (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT, 0, 0L); HDC dc = GetWindowDC(GetHwnd()); HFONT oldFont = 0; - if (GetFont().Ok() && GetFont().GetResourceHandle()) + if (GetFont().Ok() && GetFont().GetResourceHandle() != 0) oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); GetTextMetrics(dc, &lpTextMetric); SIZE extentXY; - ::GetTextExtentPoint(dc, (LPTSTR) (const wxChar *)s, s.Length(), &extentXY); + ::GetTextExtentPoint32(dc, (LPTSTR) (const wxChar *)s, s.Length(), &extentXY); int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth); if (oldFont) @@ -641,19 +648,16 @@ void wxListBox::SetHorizontalExtent(const wxString& s) int largestExtent = 0; HDC dc = GetWindowDC(GetHwnd()); HFONT oldFont = 0; - if (GetFont().Ok() && GetFont().GetResourceHandle()) + if (GetFont().Ok() && GetFont().GetResourceHandle() != 0) oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); GetTextMetrics(dc, &lpTextMetric); - // FIXME: buffer overflow!! - wxChar buf[1024]; for (int i = 0; i < m_noItems; i++) { - int len = (int)SendMessage(GetHwnd(), LB_GETTEXT, i, (LPARAM)buf); - buf[len] = 0; + wxString str = GetString(i); SIZE extentXY; - ::GetTextExtentPoint(dc, buf, len, &extentXY); + ::GetTextExtentPoint32(dc, str.c_str(), str.length(), &extentXY); int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth); if (extentX > largestExtent) largestExtent = extentX; @@ -690,12 +694,17 @@ wxSize wxListBox::DoGetBestSize() const wListbox += 3*cx; + // Add room for the scrollbar + wListbox += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + // don't make the listbox too tall (limit height to 10 items) but don't // make it too small neither int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)* wxMin(wxMax(m_noItems, 3), 10); - return wxSize(wListbox, hListbox); + wxSize best(wListbox, hListbox); + CacheBestSize(best); + return best; } // ---------------------------------------------------------------------------- @@ -735,7 +744,7 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) event.SetExtraLong( HasMultipleSelection() ? IsSelected(n) : true ); } - event.m_commandInt = n; + event.SetInt(n); return GetEventHandler()->ProcessEvent(event); } @@ -805,8 +814,9 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item) wxListBoxItem *pItem = (wxListBoxItem *)data; wxDCTemp dc((WXHDC)pStruct->hDC); - wxRect rect(wxPoint(pStruct->rcItem.left, pStruct->rcItem.top), - wxPoint(pStruct->rcItem.right, pStruct->rcItem.bottom)); + wxPoint pt1(pStruct->rcItem.left, pStruct->rcItem.top); + wxPoint pt2(pStruct->rcItem.right, pStruct->rcItem.bottom); + wxRect rect(pt1, pt2); return pItem->OnDrawItem(dc, rect, (wxOwnerDrawn::wxODAction)pStruct->itemAction,