- wxString strSelection;
- unsigned int nItem = event.GetInt();
- if(event.GetInt()==-1)
- return;
- strSelection.sprintf("item %d was %schecked", nItem,
- m_pListBox->IsChecked(nItem) ? "" : "un");
- SetStatusText(strSelection);
-}
\ No newline at end of file
+ unsigned int nItem = event.GetInt();
+
+ wxLogStatus(this, wxT("item %d was %schecked"), nItem,
+ m_pListBox->IsChecked(nItem) ? wxT("") : wxT("un"));
+}
+
+void CheckListBoxFrame::OnButtonUp(wxCommandEvent& WXUNUSED(event))
+{
+ OnButtonMove(TRUE);
+}
+
+void CheckListBoxFrame::OnButtonDown(wxCommandEvent& WXUNUSED(event))
+{
+ OnButtonMove(FALSE);
+}
+
+void CheckListBoxFrame::OnButtonMove(bool up)
+{
+ int selection = m_pListBox->GetSelection();
+ if ( selection != -1 )
+ {
+ wxString label = m_pListBox->GetString(selection);
+
+ int positionNew = up ? selection - 1 : selection + 2;
+ if ( positionNew < 0 || positionNew > m_pListBox->GetCount() )
+ {
+ wxLogStatus(this, wxT("Can't move this item %s"), up ? wxT("up") : wxT("down"));
+ }
+ else
+ {
+ bool wasChecked = m_pListBox->IsChecked(selection);
+
+ int positionOld = up ? selection + 1 : selection;
+
+ // insert the item
+ m_pListBox->InsertItems(1, &label, positionNew);
+
+ // and delete the old one
+ m_pListBox->Delete(positionOld);
+
+ int selectionNew = up ? positionNew : positionNew - 1;
+ m_pListBox->Check(selectionNew, wasChecked);
+ m_pListBox->SetSelection(selectionNew);
+
+ AdjustColour(selection);
+ AdjustColour(selectionNew);
+
+ wxLogStatus(this, wxT("Item moved %s"), up ? wxT("up") : wxT("down"));
+ }
+ }
+ else
+ {
+ wxLogStatus(this, wxT("Please select an item"));
+ }
+}
+
+void CheckListBoxFrame::AdjustColour(size_t index)
+{
+ // not implemented in ports other than (native) MSW yet
+#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
+ // even items have grey backround, odd ones - white
+ unsigned char c = index % 2 ? 255 : 200;
+ m_pListBox->GetItem(index)->SetBackgroundColour(wxColor(c, c, c));
+#endif // wxMSW
+}