]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/listctrl/listtest.cpp
Fixes from Mumit Khan to allow DLL compilation; most fixes related to
[wxWidgets.git] / samples / listctrl / listtest.cpp
index 0810b7d9913c085b166c045d2a75f700e1e22fd3..8c4e700899d04dbe88206f0b641e91035ed11098 100644 (file)
@@ -46,6 +46,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
     EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
     EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
+    EVT_MENU(LIST_SORT, MyFrame::OnSort)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
@@ -65,6 +66,12 @@ END_EVENT_TABLE()
 
 IMPLEMENT_APP(MyApp)
 
+int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
+{
+    // inverse the order
+    return item1 < item2;
+}
+
 // `Main program' equivalent, creating windows and returning main app frame
 bool MyApp::OnInit(void)
 {
@@ -134,6 +141,8 @@ bool MyApp::OnInit(void)
   file_menu->Append(LIST_DESELECT_ALL, "&Deselect All");
   file_menu->Append(LIST_SELECT_ALL, "S&elect All");
   file_menu->AppendSeparator();
+  file_menu->Append(LIST_SORT, "&Sort\tCtrl-S");
+  file_menu->AppendSeparator();
   file_menu->Append(LIST_DELETE_ALL, "Delete &all items");
   file_menu->AppendSeparator();
   file_menu->Append(BUSY_ON,         "&Busy cursor on");
@@ -265,11 +274,12 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
     m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
     m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
 
-    for ( int i = 0; i < 3000; i++ )
+    for ( int i = 0; i < 300; i++ )
     {
         wxChar buf[50];
         wxSprintf(buf, _T("This is item %d"), i);
         long tmp = m_listCtrl->InsertItem(i, buf, 0);
+        m_listCtrl->SetItemData(tmp, i);
 
         wxSprintf(buf, _T("Col 1, item %d"), i);
         tmp = m_listCtrl->SetItem(i, 1, buf);
@@ -278,6 +288,24 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
         tmp = m_listCtrl->SetItem(i, 2, buf);
     }
 
+    // we leave all mask fields to 0 and only change the colour
+    wxListItem item;
+    item.m_itemId = 0;
+    item.SetTextColour(*wxRED);
+    m_listCtrl->SetItem( item );
+
+    item.m_itemId = 2;
+    item.SetTextColour(*wxGREEN);
+    m_listCtrl->SetItem( item );
+    item.m_itemId = 4;
+    item.SetTextColour(*wxLIGHT_GREY);
+    item.SetFont(*wxITALIC_FONT);
+    item.SetBackgroundColour(*wxRED);
+    m_listCtrl->SetItem( item );
+
+    m_listCtrl->SetTextColour(*wxBLUE);
+    m_listCtrl->SetBackgroundColour(*wxLIGHT_GREY);
+
     m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
     m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
     m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE );
@@ -341,6 +369,11 @@ void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
     }
 }
 
+void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
+{
+    m_listCtrl->SortItems(MyCompareFunction, 0);
+}
+
 void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
 {
     (void)wxGetElapsedTime(TRUE);