X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42841dfcaddc6045ffc618acbb620b1fde1bc618..0aed40087460f9424a6d948282ffa4cb5c798cc6:/src/msw/listbox.cpp diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 1fc6d08142..7abbf18e2b 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -9,10 +9,6 @@ // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "listbox.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -43,10 +39,6 @@ #include "wx/ownerdrw.h" #endif -#ifdef __GNUWIN32_OLD__ - #include "wx/msw/gnuwin32/extra.h" -#endif - #if wxUSE_EXTENDED_RTTI WX_DEFINE_FLAGS( wxListBoxStyle ) @@ -283,12 +275,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 +296,7 @@ int wxListBox::DoAppend(const wxString& item) SetHorizontalExtent(item); + InvalidateBestSize(); return index; } @@ -351,11 +344,17 @@ 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 +int wxListBox::FindString(const wxString& s, bool bCase) const { - int pos = ListBox_FindStringExact(GetHwnd(), (WPARAM)-1, s); + // back to base class search for not native search type + if (bCase) + return wxItemContainerImmutable::FindString( s, bCase ); + + int pos = ListBox_FindStringExact(GetHwnd(), -1, s); if (pos == LB_ERR) return wxNOT_FOUND; else @@ -370,6 +369,8 @@ void wxListBox::Clear() m_noItems = 0; SetHorizontalExtent(); + + InvalidateBestSize(); } void wxListBox::Free() @@ -390,7 +391,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,15 +508,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; - wxChar* buffer = result.GetWriteBuf(len + 1); - ListBox_GetText(GetHwnd(), N, buffer); - result.UngetWriteBuf(); + ListBox_GetText(GetHwnd(), N, (wxChar*)wxStringBuffer(result, len + 1)); return result; } @@ -526,8 +525,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++ ) { @@ -551,6 +548,18 @@ wxListBox::DoInsertItems(const wxArrayString& items, int pos) m_noItems += nItems; SetHorizontalExtent(); + + InvalidateBestSize(); +} + +int wxListBox::DoListHitTest(const wxPoint& point) const +{ + LRESULT lRes = ::SendMessage(GetHwnd(), LB_ITEMFROMPOINT, + 0L, MAKELONG(point.x, point.y)); + + // non zero high-order word means that this item is outside of the client + // area, IOW the point is outside of the listbox + return HIWORD(lRes) ? wxNOT_FOUND : lRes; } void wxListBox::SetString(int N, const wxString& s) @@ -597,6 +606,8 @@ void wxListBox::SetString(int N, const wxString& s) // we may have lost the selection if ( wasSelected ) Select(N); + + InvalidateBestSize(); } int wxListBox::GetCount() const @@ -618,17 +629,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) @@ -643,19 +654,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; @@ -692,12 +700,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; } // ---------------------------------------------------------------------------- @@ -737,7 +750,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); } @@ -773,16 +786,19 @@ bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item) HDC hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0); #endif - wxDC dc; - dc.SetHDC((WXHDC)hdc); - dc.SetFont(GetFont()); - - pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE; - pStruct->itemWidth = dc.GetCharWidth(); + { + wxDCTemp dc((WXHDC)hdc); + dc.SetFont(GetFont()); - dc.SetHDC(0); + pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE; + pStruct->itemWidth = dc.GetCharWidth(); + } +#ifdef __WXWINCE__ + ReleaseDC(NULL, hdc); +#else DeleteDC(hdc); +#endif return true; }