X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/792f83f038067323c1c28900dcb1a03557295dff..c8326d649c00a47d3e77770a8e0a0a3b7ead56bb:/src/msw/wince/checklst.cpp diff --git a/src/msw/wince/checklst.cpp b/src/msw/wince/checklst.cpp index 5f5bf98304..b0044c8443 100644 --- a/src/msw/wince/checklst.cpp +++ b/src/msw/wince/checklst.cpp @@ -154,10 +154,9 @@ void wxCheckListBox::OnSize(wxSizeEvent& event) // misc overloaded methods // ----------------------- -void wxCheckListBox::Delete(int n) +void wxCheckListBox::Delete(unsigned int n) { - wxCHECK_RET( n >= 0 && n < GetCount(), - _T("invalid index in wxCheckListBox::Delete") ); + wxCHECK_RET( IsValid( n ), _T("invalid index in wxCheckListBox::Delete") ); if ( !ListView_DeleteItem(GetHwnd(), n) ) { @@ -169,17 +168,17 @@ void wxCheckListBox::Delete(int n) // check items // ----------- -bool wxCheckListBox::IsChecked(size_t uiIndex) const +bool wxCheckListBox::IsChecked(unsigned int uiIndex) const { - wxCHECK_MSG( uiIndex < (size_t)GetCount(), false, + wxCHECK_MSG( IsValid( uiIndex ), false, _T("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(), + wxCHECK_RET( IsValid( uiIndex ), _T("invalid index in wxCheckListBox::Check") ); ListView_SetCheckState(((HWND)GetHWND()), uiIndex, bCheck) @@ -190,7 +189,7 @@ void wxCheckListBox::Check(size_t uiIndex, bool bCheck) void wxCheckListBox::Clear() { - int n = GetCount(); + unsigned int n = GetCount(); while ( n > 0 ) { @@ -204,29 +203,38 @@ void wxCheckListBox::Clear() _T("broken wxCheckListBox::Clear()") ); } -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; (unsigned int)i < GetCount(); i++) + { + int selState = ListView_GetItemState(GetHwnd(), i, LVIS_SELECTED); + if (selState == LVIS_SELECTED) + return i; + } + return wxNOT_FOUND; } int wxCheckListBox::GetSelections(wxArrayInt& aSelections) const { - int n = GetCount(); - while ( n > 0 ) + int i; + for (i = 0; (unsigned int)i < GetCount(); i++) { - n--; - if(IsChecked(n)) aSelections.Insert(n,0); + int selState = ListView_GetItemState(GetHwnd(), i, LVIS_SELECTED); + if (selState == LVIS_SELECTED) + aSelections.Add(i); } return aSelections.GetCount(); } -wxString wxCheckListBox::GetString(int n) const +wxString wxCheckListBox::GetString(unsigned int n) const { const int bufSize = 513; wxChar buf[bufSize]; @@ -238,12 +246,13 @@ wxString wxCheckListBox::GetString(int n) const bool wxCheckListBox::IsSelected(int n) const { - return IsChecked(n); + int selState = ListView_GetItemState(GetHwnd(), n, LVIS_SELECTED); + 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(), + wxCHECK_RET( IsValid( n ), _T("invalid index in wxCheckListBox::SetString") ); wxChar *buf = new wxChar[s.length()+1]; wxStrcpy(buf, s.c_str()); @@ -253,7 +262,7 @@ void wxCheckListBox::SetString(int n, const wxString& s) int wxCheckListBox::DoAppend(const wxString& item) { - int n = GetCount(); + int n = (int)GetCount(); LVITEM newItem; wxZeroMemory(newItem); newItem.iItem = n; @@ -264,21 +273,30 @@ int wxCheckListBox::DoAppend(const wxString& item) 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 +wxClientData* wxCheckListBox::DoGetItemClientObject(unsigned int n) const { return (wxClientData *)DoGetItemClientData(n); } -void wxCheckListBox::DoInsertItems(const wxArrayString& items, int pos) +void wxCheckListBox::DoInsertItems(const wxArrayString& items, unsigned int pos) { - for( size_t i = 0; i < items.GetCount(); i++ ) + wxCHECK_RET( IsValidInsert( pos ), + wxT("invalid index in wxListBox::InsertItems") ); + + for( unsigned int i = 0; i < items.GetCount(); i++ ) { - Insert(items[i],pos+i); + LVITEM newItem; + wxZeroMemory(newItem); + newItem.iItem = i+pos; + int ret = ListView_InsertItem( (HWND)GetHWND(), & newItem ); + wxASSERT_MSG( int(i+pos) == ret , _T("Item not added") ); + SetString( ret , items[i] ); + m_itemsClientData.Insert(NULL, ret); } } @@ -293,12 +311,12 @@ void wxCheckListBox::DoSetFirstItem(int n) 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) +void wxCheckListBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData) { DoSetItemClientData(n, clientData); } @@ -307,7 +325,7 @@ void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData) { ListView_SetItemCount( GetHwnd(), GetCount() + items.GetCount() ); - for( size_t i = 0; i < items.GetCount(); i++ ) + for( unsigned int i = 0; i < items.GetCount(); i++ ) { int pos = Append(items[i]); if( pos >= 0 && clientData ) @@ -317,7 +335,93 @@ void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData) void wxCheckListBox::DoSetSelection(int n, bool select) { - Check(n,select); + ListView_SetItemState(GetHwnd(), n, select ? LVIS_SELECTED : 0, LVIS_SELECTED); } +bool wxCheckListBox::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) +{ + // prepare the event + // ----------------- + + wxCommandEvent event(wxEVT_NULL, m_windowId); + event.SetEventObject(this); + + wxEventType eventType = wxEVT_NULL; + + NMHDR *nmhdr = (NMHDR *)lParam; + + if ( nmhdr->hwndFrom == GetHwnd() ) + { + // almost all messages use NM_LISTVIEW + NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr; + + const int iItem = nmLV->iItem; + + bool processed = true; + switch ( nmhdr->code ) + { + case LVN_ITEMCHANGED: + // we translate this catch all message into more interesting + // (and more easy to process) wxWidgets events + + // first of all, we deal with the state change events only and + // only for valid items (item == -1 for the virtual list + // control) + if ( nmLV->uChanged & LVIF_STATE && iItem != -1 ) + { + // temp vars for readability + const UINT stOld = nmLV->uOldState; + const UINT stNew = nmLV->uNewState; + + // Check image changed + if ((stOld & LVIS_STATEIMAGEMASK) != (stNew & LVIS_STATEIMAGEMASK)) + { + event.SetEventType(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED); + event.SetInt(IsChecked(iItem)); + (void) GetEventHandler()->ProcessEvent(event); + } + + if ( (stNew & LVIS_SELECTED) != (stOld & LVIS_SELECTED) ) + { + eventType = wxEVT_COMMAND_LISTBOX_SELECTED; + + event.SetExtraLong( (stNew & LVIS_SELECTED) != 0 ); // is a selection + event.SetInt(iItem); + } + } + + if ( eventType == wxEVT_NULL ) + { + // not an interesting event for us + return false; + } + + break; + + default: + processed = false; + } + + if ( !processed ) + return wxControl::MSWOnNotify(idCtrl, lParam, result); + } + else + { + // where did this one come from? + return false; + } + + // process the event + // ----------------- + + event.SetEventType(eventType); + + bool processed = GetEventHandler()->ProcessEvent(event); + if ( processed ) + *result = 0; + + return processed; +} + + #endif