From fa5f6926ecc17eebf4442611b066367eb17e11c4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin <vadim@wxwidgets.org> Date: Wed, 1 Dec 1999 22:07:25 +0000 Subject: [PATCH] sorting test added git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4790 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/listctrl/listtest.cpp | 17 ++++- samples/listctrl/listtest.h | 41 ++++++------ samples/listctrl/test.dsp | 118 ---------------------------------- samples/listctrl/test.dsw | 29 --------- 4 files changed, 39 insertions(+), 166 deletions(-) delete mode 100644 samples/listctrl/test.dsp delete mode 100644 samples/listctrl/test.dsw diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 0810b7d991..3582c99cf4 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -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); @@ -341,6 +351,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); diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index 3ec89ec930..aebe3fe242 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -11,8 +11,9 @@ // Define a new application type class MyApp: public wxApp -{ public: - bool OnInit(); +{ +public: + virtual bool OnInit(); wxImageList *m_imageListNormal; wxImageList *m_imageListSmall; @@ -26,7 +27,7 @@ public: wxListCtrl(parent, id, pos, size, style) { } - + void OnColClick(wxListEvent& event); void OnBeginDrag(wxListEvent& event); void OnBeginRDrag(wxListEvent& event); @@ -67,6 +68,7 @@ public: void OnDeselectAll(wxCommandEvent& event); void OnSelectAll(wxCommandEvent& event); void OnDeleteAll(wxCommandEvent& event); + void OnSort(wxCommandEvent& event); void BusyOn(wxCommandEvent& event); void BusyOff(wxCommandEvent& event); @@ -76,20 +78,23 @@ public: // ID for the menu quit command -#define LIST_QUIT 1 -#define LIST_LIST_VIEW 2 -#define LIST_ICON_VIEW 3 -#define LIST_ICON_TEXT_VIEW 4 -#define LIST_SMALL_ICON_VIEW 5 -#define LIST_SMALL_ICON_TEXT_VIEW 6 -#define LIST_REPORT_VIEW 7 -#define LIST_DESELECT_ALL 8 -#define LIST_SELECT_ALL 9 -#define LIST_ABOUT 102 -#define BUSY_ON 10 -#define BUSY_OFF 11 -#define LIST_DELETE_ALL 12 - -#define LIST_CTRL 1000 +enum +{ + LIST_QUIT = 1, + LIST_LIST_VIEW = 2, + LIST_ICON_VIEW = 3, + LIST_ICON_TEXT_VIEW = 4, + LIST_SMALL_ICON_VIEW = 5, + LIST_SMALL_ICON_TEXT_VIEW = 6, + LIST_REPORT_VIEW = 7, + LIST_DESELECT_ALL = 8, + LIST_SELECT_ALL = 9, + LIST_ABOUT = 102, + BUSY_ON = 10, + BUSY_OFF = 11, + LIST_DELETE_ALL = 12, + LIST_SORT, + LIST_CTRL = 1000 +}; diff --git a/samples/listctrl/test.dsp b/samples/listctrl/test.dsp deleted file mode 100644 index 41e5828244..0000000000 --- a/samples/listctrl/test.dsp +++ /dev/null @@ -1,118 +0,0 @@ -# Microsoft Developer Studio Project File - Name="test" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** NICHT BEARBEITEN ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=test - Win32 Release -!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit\ - NMAKE -!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den\ - Befehl -!MESSAGE -!MESSAGE NMAKE /f "test.mak". -!MESSAGE -!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben -!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: -!MESSAGE -!MESSAGE NMAKE /f "test.mak" CFG="test - Win32 Release" -!MESSAGE -!MESSAGE Für die Konfiguration stehen zur Auswahl: -!MESSAGE -!MESSAGE "test - Win32 Release" (basierend auf "Win32 (x86) Application") -!MESSAGE "test - Win32 Debug" (basierend auf "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "test - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir ".\Release" -# PROP BASE Intermediate_Dir ".\Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir ".\Release" -# PROP Intermediate_Dir ".\Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c -# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /I "funcs" /I "santis2" /I "funcdefs" /I "tnt" /D "__WIN32__" /D "__WXMSW__" /D "__WIN95__" /D "STRICT" /D "__WINDOWS__" /YX /FD /D /c -# ADD BASE MTL /nologo /D "NDEBUG" /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x407 /d "NDEBUG" -# ADD RSC /l 0x407 /i "..\..\include" /d "__WXMSW__" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib oldnames.lib comctl32.lib ctl3d32.lib odbc32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib ..\..\release\wxwin.lib ctl3d32.lib /nologo /subsystem:windows /machine:I386 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "test - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir ".\Debug" -# PROP BASE Intermediate_Dir ".\Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir ".\Debug" -# PROP Intermediate_Dir ".\Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c -# ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /I "funcs" /I "santis2" /I "funcdefs" /I "tnt" /D "__WIN32__" /D "__WXMSW__" /D "__WIN95__" /D DEBUG=2 /D "STRICT" /D "__WINDOWS__" /YX /FD /D /c -# ADD BASE MTL /nologo /D "_DEBUG" /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x407 /d "_DEBUG" -# ADD RSC /l 0x407 /i "..\..\include" /d "__WXMSW__" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib oldnames.lib comctl32.lib ctl3d32.lib odbc32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib ..\..\debug\wxwin.lib ctl3d32.lib /nologo /subsystem:windows /debug /machine:I386 -# SUBTRACT LINK32 /pdb:none - -!ENDIF - -# Begin Target - -# Name "test - Win32 Release" -# Name "test - Win32 Debug" -# Begin Group "Quellcodedateien" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90" -# Begin Source File - -SOURCE=.\listtest.cpp -# End Source File -# End Group -# Begin Group "Header-Dateien" - -# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd" -# Begin Source File - -SOURCE=.\listtest.h -# End Source File -# End Group -# Begin Group "Ressourcendateien" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" -# Begin Source File - -SOURCE=.\listtest.rc -# End Source File -# End Group -# End Target -# End Project diff --git a/samples/listctrl/test.dsw b/samples/listctrl/test.dsw deleted file mode 100644 index 1fe8c87bde..0000000000 --- a/samples/listctrl/test.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 5.00 -# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN! - -############################################################################### - -Project: "test"=.\santis.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - -- 2.47.2