#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
#if wxUSE_CHECKLISTBOX
-#ifndef WX_PRECOMP
-#endif
-
#include "wx/checklst.h"
-// include <commctrl.h> "properly"
-#include "wx/msw/wrapcctl.h"
+#ifndef WX_PRECOMP
+ #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
+#endif
// ============================================================================
// implementation
m_itemsClientData.SetCount(n);
// now we can compute our best size correctly, so do it if necessary
- SetBestSize(size);
+ SetInitialSize(size);
return true;
}
// misc overloaded methods
// -----------------------
-void wxCheckListBox::Delete(int n)
+void wxCheckListBox::DoDeleteOneItem(unsigned int n)
{
- wxCHECK_RET( n >= 0 && n < GetCount(),
- _T("invalid index in wxCheckListBox::Delete") );
+ wxCHECK_RET( IsValid( n ), wxT("invalid index in wxCheckListBox::Delete") );
if ( !ListView_DeleteItem(GetHwnd(), n) )
{
- wxLogLastError(_T("ListView_DeleteItem"));
+ wxLogLastError(wxT("ListView_DeleteItem"));
}
m_itemsClientData.RemoveAt(n);
}
// check items
// -----------
-bool wxCheckListBox::IsChecked(size_t uiIndex) const
+bool wxCheckListBox::IsChecked(unsigned int uiIndex) const
{
- wxCHECK_MSG( uiIndex < (size_t)GetCount(), false,
- _T("invalid index in wxCheckListBox::IsChecked") );
+ wxCHECK_MSG( IsValid( uiIndex ), false,
+ wxT("invalid index in wxCheckListBox::IsChecked") );
return (ListView_GetCheckState(((HWND)GetHWND()), uiIndex) != 0);
}
-void wxCheckListBox::Check(size_t uiIndex, bool bCheck)
+void wxCheckListBox::Check(unsigned int uiIndex, bool bCheck)
{
- wxCHECK_RET( uiIndex < (size_t)GetCount(),
- _T("invalid index in wxCheckListBox::Check") );
+ wxCHECK_RET( IsValid( uiIndex ),
+ wxT("invalid index in wxCheckListBox::Check") );
ListView_SetCheckState(((HWND)GetHWND()), uiIndex, bCheck)
}
// interface derived from wxListBox and lower classes
// --------------------------------------------------
-void wxCheckListBox::Clear()
+void wxCheckListBox::DoClear()
{
- int n = GetCount();
+ unsigned int n = GetCount();
while ( n > 0 )
{
n--;
- Delete(n);
+ DoDeleteOneItem(n);
}
- m_itemsClientData.Clear();
-
- wxCHECK_RET( n == GetCount(),
- _T("broken wxCheckListBox::Clear()") );
+ wxASSERT_MSG( IsEmpty(), wxT("logic error in DoClear()") );
}
-int wxCheckListBox::GetCount() const
+unsigned int wxCheckListBox::GetCount() const
{
- return ListView_GetItemCount( (HWND)GetHWND() );
+ return (unsigned int)ListView_GetItemCount( (HWND)GetHWND() );
}
int wxCheckListBox::GetSelection() const
{
int i;
- for (i = 0; i < GetCount(); i++)
+ for (i = 0; (unsigned int)i < GetCount(); i++)
{
int selState = ListView_GetItemState(GetHwnd(), i, LVIS_SELECTED);
if (selState == LVIS_SELECTED)
int wxCheckListBox::GetSelections(wxArrayInt& aSelections) const
{
int i;
- for (i = 0; i < GetCount(); i++)
+ for (i = 0; (unsigned int)i < GetCount(); i++)
{
int selState = ListView_GetItemState(GetHwnd(), i, LVIS_SELECTED);
if (selState == LVIS_SELECTED)
return aSelections.GetCount();
}
-wxString wxCheckListBox::GetString(int n) const
+wxString wxCheckListBox::GetString(unsigned int n) const
{
const int bufSize = 513;
wxChar buf[bufSize];
ListView_GetItemText( (HWND)GetHWND(), n, 0, buf, bufSize - 1 );
- buf[bufSize-1] = _T('\0');
+ buf[bufSize-1] = wxT('\0');
wxString str(buf);
return str;
}
return (selState == LVIS_SELECTED);
}
-void wxCheckListBox::SetString(int n, const wxString& s)
+void wxCheckListBox::SetString(unsigned int n, const wxString& s)
{
- wxCHECK_RET( n < GetCount(),
- _T("invalid index in wxCheckListBox::SetString") );
+ wxCHECK_RET( IsValid( n ),
+ wxT("invalid index in wxCheckListBox::SetString") );
wxChar *buf = new wxChar[s.length()+1];
wxStrcpy(buf, s.c_str());
ListView_SetItemText( (HWND)GetHWND(), n, 0, buf );
delete [] buf;
}
-int wxCheckListBox::DoAppend(const wxString& item)
-{
- int n = GetCount();
- LVITEM newItem;
- wxZeroMemory(newItem);
- newItem.iItem = n;
- int ret = ListView_InsertItem( (HWND)GetHWND(), & newItem );
- wxCHECK_MSG( n == ret , -1, _T("Item not added") );
- SetString( ret , item );
- m_itemsClientData.Insert(NULL, ret);
- return ret;
-}
-
-void* wxCheckListBox::DoGetItemClientData(int n) const
+void* wxCheckListBox::DoGetItemClientData(unsigned int n) const
{
return m_itemsClientData.Item(n);
}
-wxClientData* wxCheckListBox::DoGetItemClientObject(int n) const
+int wxCheckListBox::DoInsertItems(const wxArrayStringsAdapter & items,
+ unsigned int pos,
+ void **clientData, wxClientDataType type)
{
- return (wxClientData *)DoGetItemClientData(n);
-}
+ const unsigned int count = items.GetCount();
-void wxCheckListBox::DoInsertItems(const wxArrayString& items, int pos)
-{
- for( size_t i = 0; i < items.GetCount(); i++ )
+ ListView_SetItemCount( GetHwnd(), GetCount() + count );
+
+ int n = wxNOT_FOUND;
+
+ for( unsigned int i = 0; i < count; i++ )
{
- Insert(items[i],pos+i);
+ LVITEM newItem;
+ wxZeroMemory(newItem);
+ newItem.iItem = pos + i;
+ n = ListView_InsertItem( (HWND)GetHWND(), & newItem );
+ wxCHECK_MSG( n != -1, -1, wxT("Item not added") );
+ SetString( n, items[i] );
+ m_itemsClientData.Insert(NULL, n);
+
+ AssignNewItemClientData(n, clientData, i, type);
}
+
+ return n;
}
void wxCheckListBox::DoSetFirstItem(int n)
if(pos == n) return;
POINT ppt;
BOOL ret = ListView_GetItemPosition( (HWND)GetHWND(), n, &ppt );
- wxCHECK_RET( ret == TRUE, _T("Broken DoSetFirstItem") );
+ wxCHECK_RET( ret == TRUE, wxT("Broken DoSetFirstItem") );
ListView_Scroll( (HWND)GetHWND(), 0, 0 );
ListView_Scroll( (HWND)GetHWND(), 0, ppt.y );
}
-void wxCheckListBox::DoSetItemClientData(int n, void* clientData)
+void wxCheckListBox::DoSetItemClientData(unsigned int n, void* clientData)
{
m_itemsClientData.Item(n) = clientData;
}
-void wxCheckListBox::DoSetItemClientObject(int n, wxClientData* clientData)
-{
- DoSetItemClientData(n, clientData);
-}
-
-void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData)
-{
- ListView_SetItemCount( GetHwnd(), GetCount() + items.GetCount() );
-
- for( size_t i = 0; i < items.GetCount(); i++ )
- {
- int pos = Append(items[i]);
- if( pos >= 0 && clientData )
- DoSetItemClientData(pos, clientData[i]);
- }
-}
-
void wxCheckListBox::DoSetSelection(int n, bool select)
{
ListView_SetItemState(GetHwnd(), n, select ? LVIS_SELECTED : 0, LVIS_SELECTED);