#if wxUSE_LISTBOX
-#ifndef WX_PRECOMP
#include "wx/listbox.h"
-#include "wx/settings.h"
-#include "wx/brush.h"
-#include "wx/font.h"
-#include "wx/dc.h"
-#include "wx/utils.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/dynarray.h"
+ #include "wx/settings.h"
+ #include "wx/brush.h"
+ #include "wx/font.h"
+ #include "wx/dc.h"
+ #include "wx/utils.h"
+ #include "wx/log.h"
+ #include "wx/window.h"
#endif
-#include "wx/window.h"
#include "wx/msw/private.h"
#include <windowsx.h>
-#include "wx/dynarray.h"
-#include "wx/log.h"
-
#if wxUSE_OWNER_DRAWN
#include "wx/ownerdrw.h"
#endif
void wxListBox::DoSetFirstItem(int N)
{
- wxCHECK_RET( N >= 0 && N < m_noItems,
+ wxCHECK_RET( IsValid(N),
wxT("invalid index in wxListBox::SetFirstItem") );
SendMessage(GetHwnd(), LB_SETTOPINDEX, (WPARAM)N, (LPARAM)0);
}
-void wxListBox::Delete(int N)
+void wxListBox::Delete(unsigned int n)
{
- wxCHECK_RET( N >= 0 && N < m_noItems,
+ wxCHECK_RET( IsValid(n),
wxT("invalid index in wxListBox::Delete") );
// for owner drawn objects, the data is used for storing wxOwnerDrawn
#endif // !wxUSE_OWNER_DRAWN
if ( HasClientObjectData() )
{
- delete GetClientObject(N);
+ delete GetClientObject(n);
}
- SendMessage(GetHwnd(), LB_DELETESTRING, N, 0);
+ SendMessage(GetHwnd(), LB_DELETESTRING, n, 0);
m_noItems--;
SetHorizontalExtent(wxEmptyString);
ListBox_ResetContent(GetHwnd());
m_noItems = choices.GetCount();
- int i;
+ unsigned int i;
for (i = 0; i < m_noItems; i++)
{
ListBox_AddString(GetHwnd(), choices[i]);
WX_CLEAR_ARRAY(m_aItems);
// then create new ones
- for ( size_t ui = 0; ui < (size_t)m_noItems; ui++ ) {
+ for ( unsigned int ui = 0; ui < m_noItems; ui++ ) {
wxOwnerDrawn *pNewItem = CreateLboxItem(ui);
pNewItem->SetName(choices[ui]);
m_aItems.Add(pNewItem);
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
#endif // wxUSE_OWNER_DRAWN
if ( HasClientObjectData() )
{
- for ( size_t n = 0; n < (size_t)m_noItems; n++ )
+ for ( unsigned int n = 0; n < m_noItems; n++ )
{
delete GetClientObject(n);
}
void wxListBox::DoSetSelection(int N, bool select)
{
- wxCHECK_RET( N == wxNOT_FOUND ||
- (N >= 0 && N < m_noItems),
+ wxCHECK_RET( N == wxNOT_FOUND || IsValid(N),
wxT("invalid index in wxListBox::SetSelection") );
if ( HasMultipleSelection() )
bool wxListBox::IsSelected(int N) const
{
- wxCHECK_MSG( N >= 0 && N < m_noItems, false,
+ wxCHECK_MSG( IsValid(N), false,
wxT("invalid index in wxListBox::Selected") );
return SendMessage(GetHwnd(), LB_GETSEL, N, 0) == 0 ? false : true;
}
-wxClientData* wxListBox::DoGetItemClientObject(int n) const
+wxClientData* wxListBox::DoGetItemClientObject(unsigned int n) const
{
return (wxClientData *)DoGetItemClientData(n);
}
-void *wxListBox::DoGetItemClientData(int n) const
+void *wxListBox::DoGetItemClientData(unsigned int n) const
{
- wxCHECK_MSG( n >= 0 && n < m_noItems, NULL,
+ wxCHECK_MSG( IsValid(n), NULL,
wxT("invalid index in wxListBox::GetClientData") );
return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0);
}
-void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData)
+void wxListBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
{
DoSetItemClientData(n, clientData);
}
-void wxListBox::DoSetItemClientData(int n, void *clientData)
+void wxListBox::DoSetItemClientData(unsigned int n, void *clientData)
{
- wxCHECK_RET( n >= 0 && n < m_noItems,
+ wxCHECK_RET( IsValid(n),
wxT("invalid index in wxListBox::SetClientData") );
#if wxUSE_OWNER_DRAWN
}
// Find string for position
-wxString wxListBox::GetString(int N) const
+wxString wxListBox::GetString(unsigned int n) const
{
- wxCHECK_MSG( N >= 0 && N < m_noItems, wxEmptyString,
+ wxCHECK_MSG( IsValid(n), wxEmptyString,
wxT("invalid index in wxListBox::GetString") );
- int len = ListBox_GetTextLen(GetHwnd(), N);
+ int len = ListBox_GetTextLen(GetHwnd(), n);
// +1 for terminating NUL
wxString result;
- ListBox_GetText(GetHwnd(), N, (wxChar*)wxStringBuffer(result, len + 1));
+ ListBox_GetText(GetHwnd(), n, (wxChar*)wxStringBuffer(result, len + 1));
return result;
}
void
-wxListBox::DoInsertItems(const wxArrayString& items, int pos)
+wxListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
{
- wxCHECK_RET( pos >= 0 && pos <= m_noItems,
+ wxCHECK_RET( IsValidInsert(pos),
wxT("invalid index in wxListBox::InsertItems") );
- int nItems = items.GetCount();
- for ( int i = 0; i < nItems; i++ )
+ unsigned int nItems = items.GetCount();
+ for ( unsigned int i = 0; i < nItems; i++ )
{
int idx = ListBox_InsertString(GetHwnd(), i + pos, items[i]);
InvalidateBestSize();
}
-void wxListBox::SetString(int N, const wxString& s)
+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(unsigned int n, const wxString& s)
{
- wxCHECK_RET( N >= 0 && N < m_noItems,
+ wxCHECK_RET( IsValid(n),
wxT("invalid index in wxListBox::SetString") );
// remember the state of the item
- bool wasSelected = IsSelected(N);
+ bool wasSelected = IsSelected(n);
void *oldData = NULL;
wxClientData *oldObjData = NULL;
if ( m_clientDataItemsType == wxClientData_Void )
- oldData = GetClientData(N);
+ oldData = GetClientData(n);
else if ( m_clientDataItemsType == wxClientData_Object )
- oldObjData = GetClientObject(N);
+ oldObjData = GetClientObject(n);
// delete and recreate it
- SendMessage(GetHwnd(), LB_DELETESTRING, N, 0);
+ SendMessage(GetHwnd(), LB_DELETESTRING, n, 0);
- int newN = N;
- if ( N == m_noItems - 1 )
+ int newN = n;
+ if ( n == (m_noItems - 1) )
newN = -1;
ListBox_InsertString(GetHwnd(), newN, s);
// restore the client data
if ( oldData )
- SetClientData(N, oldData);
+ SetClientData(n, oldData);
else if ( oldObjData )
- SetClientObject(N, oldObjData);
+ SetClientObject(n, oldObjData);
#if wxUSE_OWNER_DRAWN
if ( m_windowStyle & wxLB_OWNERDRAW )
{
// update item's text
- m_aItems[N]->SetName(s);
+ m_aItems[n]->SetName(s);
// reassign the item's data
- ListBox_SetItemData(GetHwnd(), N, m_aItems[N]);
+ ListBox_SetItemData(GetHwnd(), n, m_aItems[n]);
}
#endif //USE_OWNER_DRAWN
// we may have lost the selection
if ( wasSelected )
- Select(N);
+ Select(n);
InvalidateBestSize();
}
-int wxListBox::GetCount() const
+unsigned int wxListBox::GetCount() const
{
return m_noItems;
}
GetTextMetrics(dc, &lpTextMetric);
SIZE extentXY;
- ::GetTextExtentPoint32(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)
GetTextMetrics(dc, &lpTextMetric);
- for (int i = 0; i < m_noItems; i++)
+ for (unsigned int i = 0; i < m_noItems; i++)
{
wxString str = GetString(i);
SIZE extentXY;
// find the widest string
int wLine;
int wListbox = 0;
- for ( int i = 0; i < m_noItems; i++ )
+ for (unsigned int i = 0; i < m_noItems; i++)
{
wxString str(GetString(i));
GetTextExtent(str, &wLine, NULL);
else if ( HasClientUntypedData() )
event.SetClientData( GetClientData(n) );
- event.SetString( GetString(n) );
+ event.SetString(GetString(n));
event.SetExtraLong( HasMultipleSelection() ? IsSelected(n) : true );
}
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;
}