]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.cpp | |
3 | // Purpose: wxListCtrl sample | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
5ea47806 | 9 | // Licence: wxWindows license |
457814b5 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation | |
14 | #pragma interface | |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx/wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/wx.h" | |
26 | #endif | |
27 | ||
907789a0 | 28 | #ifndef __WXMSW__ |
c41ea66a VZ |
29 | #include "mondrian.xpm" |
30 | ||
31 | #include "bitmaps/toolbrai.xpm" | |
32 | #include "bitmaps/toolchar.xpm" | |
33 | #include "bitmaps/tooldata.xpm" | |
34 | #include "bitmaps/toolnote.xpm" | |
35 | #include "bitmaps/tooltodo.xpm" | |
36 | #include "bitmaps/toolchec.xpm" | |
37 | #include "bitmaps/toolgame.xpm" | |
38 | #include "bitmaps/tooltime.xpm" | |
39 | #include "bitmaps/toolword.xpm" | |
40 | #include "bitmaps/small1.xpm" | |
907789a0 RR |
41 | #endif |
42 | ||
457814b5 | 43 | #include "wx/listctrl.h" |
81278df2 | 44 | #include "wx/timer.h" // for wxStopWatch |
11f26ea0 VZ |
45 | #include "wx/colordlg.h" // for wxGetColourFromUser |
46 | ||
457814b5 JS |
47 | #include "listtest.h" |
48 | ||
49 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
5ea47806 VZ |
50 | EVT_MENU(BUSY_ON, MyFrame::BusyOn) |
51 | EVT_MENU(BUSY_OFF, MyFrame::BusyOff) | |
52 | EVT_MENU(LIST_QUIT, MyFrame::OnQuit) | |
53 | EVT_MENU(LIST_ABOUT, MyFrame::OnAbout) | |
54 | EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView) | |
55 | EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView) | |
56 | EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView) | |
57 | EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView) | |
58 | EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView) | |
59 | EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView) | |
58b3bdc9 | 60 | EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel) |
5ea47806 VZ |
61 | EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll) |
62 | EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll) | |
63 | EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll) | |
fa5f6926 | 64 | EVT_MENU(LIST_SORT, MyFrame::OnSort) |
11f26ea0 VZ |
65 | EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour) |
66 | EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour) | |
7b848b0d | 67 | EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel) |
457814b5 JS |
68 | END_EVENT_TABLE() |
69 | ||
70 | BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) | |
5ea47806 VZ |
71 | EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag) |
72 | EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag) | |
73 | EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit) | |
74 | EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit) | |
75 | EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem) | |
12c1b46a | 76 | EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems) |
5ea47806 VZ |
77 | EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo) |
78 | EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo) | |
79 | EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected) | |
80 | EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) | |
81 | EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) | |
82 | EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) | |
8636aed8 | 83 | EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick) |
457814b5 JS |
84 | END_EVENT_TABLE() |
85 | ||
86 | IMPLEMENT_APP(MyApp) | |
87 | ||
fa5f6926 VZ |
88 | int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData) |
89 | { | |
90 | // inverse the order | |
91 | return item1 < item2; | |
92 | } | |
93 | ||
457814b5 | 94 | // `Main program' equivalent, creating windows and returning main app frame |
11f26ea0 | 95 | bool MyApp::OnInit() |
457814b5 JS |
96 | { |
97 | // Create the main frame window | |
c41ea66a | 98 | MyFrame *frame = new MyFrame("wxListCtrl Test", 50, 50, 450, 340); |
457814b5 JS |
99 | |
100 | // Show the frame | |
101 | frame->Show(TRUE); | |
5ea47806 | 102 | |
457814b5 JS |
103 | SetTopWindow(frame); |
104 | ||
105 | return TRUE; | |
106 | } | |
107 | ||
108 | // My frame constructor | |
c41ea66a VZ |
109 | MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h) |
110 | : wxFrame((wxFrame *)NULL, -1, title, wxPoint(x, y), wxSize(w, h)) | |
457814b5 | 111 | { |
5ea47806 VZ |
112 | m_listCtrl = (MyListCtrl *) NULL; |
113 | m_logWindow = (wxTextCtrl *) NULL; | |
c41ea66a VZ |
114 | |
115 | // Give it an icon | |
116 | SetIcon( wxICON(mondrian) ); | |
117 | ||
118 | // Make an image list containing large icons | |
119 | m_imageListNormal = new wxImageList(32, 32, TRUE); | |
120 | m_imageListSmall = new wxImageList(16, 16, TRUE); | |
121 | ||
122 | #ifdef __WXMSW__ | |
123 | m_imageListNormal->Add( wxIcon("icon1", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
124 | m_imageListNormal->Add( wxIcon("icon2", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
125 | m_imageListNormal->Add( wxIcon("icon3", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
126 | m_imageListNormal->Add( wxIcon("icon4", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
127 | m_imageListNormal->Add( wxIcon("icon5", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
128 | m_imageListNormal->Add( wxIcon("icon6", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
129 | m_imageListNormal->Add( wxIcon("icon7", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
130 | m_imageListNormal->Add( wxIcon("icon8", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
131 | m_imageListNormal->Add( wxIcon("icon9", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
132 | ||
133 | m_imageListSmall->Add( wxIcon("iconsmall", wxBITMAP_TYPE_ICO_RESOURCE) ); | |
134 | ||
135 | #else | |
136 | m_imageListNormal->Add( wxIcon( toolbrai_xpm ) ); | |
137 | m_imageListNormal->Add( wxIcon( toolchar_xpm ) ); | |
138 | m_imageListNormal->Add( wxIcon( tooldata_xpm ) ); | |
139 | m_imageListNormal->Add( wxIcon( toolnote_xpm ) ); | |
140 | m_imageListNormal->Add( wxIcon( tooltodo_xpm ) ); | |
141 | m_imageListNormal->Add( wxIcon( toolchec_xpm ) ); | |
142 | m_imageListNormal->Add( wxIcon( toolgame_xpm ) ); | |
143 | m_imageListNormal->Add( wxIcon( tooltime_xpm ) ); | |
144 | m_imageListNormal->Add( wxIcon( toolword_xpm ) ); | |
145 | ||
146 | m_imageListSmall->Add( wxIcon( small1_xpm) ); | |
147 | #endif | |
148 | ||
149 | // Make a menubar | |
150 | wxMenu *menuFile = new wxMenu; | |
151 | menuFile->Append(LIST_ABOUT, "&About"); | |
152 | menuFile->AppendSeparator(); | |
153 | #if 0 // what is this for? (VZ) | |
154 | menuFile->Append(BUSY_ON, "&Busy cursor on"); | |
155 | menuFile->Append(BUSY_OFF, "&Busy cursor off"); | |
156 | menuFile->AppendSeparator(); | |
157 | #endif | |
158 | menuFile->Append(LIST_QUIT, "E&xit\tAlt-X"); | |
159 | ||
160 | wxMenu *menuView = new wxMenu; | |
161 | menuView->Append(LIST_LIST_VIEW, "&List view\tF1"); | |
162 | menuView->Append(LIST_REPORT_VIEW, "&Report view\tF2"); | |
163 | menuView->Append(LIST_ICON_VIEW, "&Icon view\tF3"); | |
164 | menuView->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text\tF4"); | |
165 | menuView->Append(LIST_SMALL_ICON_VIEW, "&Small icon view\tF5"); | |
166 | menuView->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text\tF6"); | |
167 | ||
168 | wxMenu *menuList = new wxMenu; | |
58b3bdc9 | 169 | menuList->Append(LIST_TOGGLE_FIRST, "&Toggle first item\tCtrl-T"); |
c41ea66a VZ |
170 | menuList->Append(LIST_DESELECT_ALL, "&Deselect All\tCtrl-D"); |
171 | menuList->Append(LIST_SELECT_ALL, "S&elect All\tCtrl-A"); | |
172 | menuList->AppendSeparator(); | |
173 | menuList->Append(LIST_SORT, "&Sort\tCtrl-S"); | |
174 | menuList->AppendSeparator(); | |
175 | menuList->Append(LIST_DELETE_ALL, "Delete &all items"); | |
176 | menuList->AppendSeparator(); | |
177 | menuList->Append(LIST_TOGGLE_MULTI_SEL, "&Multiple selection\tCtrl-M", | |
178 | "Toggle multiple selection", TRUE); | |
179 | ||
180 | wxMenu *menuCol = new wxMenu; | |
181 | menuCol->Append(LIST_SET_FG_COL, "&Foreground colour..."); | |
182 | menuCol->Append(LIST_SET_BG_COL, "&Background colour..."); | |
183 | ||
184 | wxMenuBar *menubar = new wxMenuBar; | |
185 | menubar->Append(menuFile, "&File"); | |
186 | menubar->Append(menuView, "&View"); | |
187 | menubar->Append(menuList, "&List"); | |
188 | menubar->Append(menuCol, "&Colour"); | |
189 | SetMenuBar(menubar); | |
190 | ||
191 | m_listCtrl = new MyListCtrl(this, LIST_CTRL, | |
192 | wxDefaultPosition, wxDefaultSize, | |
193 | wxLC_LIST | | |
194 | wxSUNKEN_BORDER | | |
195 | wxLC_EDIT_LABELS | | |
196 | // wxLC_USER_TEXT requires app to supply all | |
197 | // text on demand | |
198 | //wxLC_USER_TEXT | | |
199 | wxLC_SINGLE_SEL | |
200 | ); | |
201 | ||
202 | m_logWindow = new wxTextCtrl(this, -1, wxEmptyString, | |
203 | wxDefaultPosition, wxDefaultSize, | |
204 | wxTE_MULTILINE | wxSUNKEN_BORDER); | |
205 | ||
206 | m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow)); | |
207 | ||
208 | wxLayoutConstraints *c = new wxLayoutConstraints; | |
209 | c->top.SameAs (this, wxTop); | |
210 | c->left.SameAs (this, wxLeft); | |
211 | c->right.SameAs (this, wxRight); | |
212 | c->height.PercentOf (this, wxHeight, 66); | |
213 | m_listCtrl->SetConstraints(c); | |
214 | ||
215 | c = new wxLayoutConstraints; | |
216 | c->top.Below (m_listCtrl); | |
217 | c->left.SameAs (this, wxLeft); | |
218 | c->right.SameAs (this, wxRight); | |
219 | c->bottom.SameAs (this, wxBottom); | |
220 | m_logWindow->SetConstraints(c); | |
221 | SetAutoLayout(TRUE); | |
222 | ||
223 | for ( int i = 0; i < 30; i++ ) | |
224 | { | |
225 | long idx = m_listCtrl->InsertItem(i, wxString::Format(_T("Item %d"), i)); | |
226 | m_listCtrl->SetItemData(idx, i*i); | |
227 | } | |
228 | ||
229 | CreateStatusBar(3); | |
457814b5 JS |
230 | } |
231 | ||
11f26ea0 | 232 | MyFrame::~MyFrame() |
457814b5 | 233 | { |
c41ea66a VZ |
234 | delete wxLog::SetActiveTarget(m_logOld); |
235 | ||
236 | delete m_imageListNormal; | |
237 | delete m_imageListSmall; | |
457814b5 JS |
238 | } |
239 | ||
b0d77f43 | 240 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 241 | { |
c41ea66a | 242 | Close(TRUE); |
457814b5 JS |
243 | } |
244 | ||
57246713 KB |
245 | void MyFrame::BusyOn(wxCommandEvent& WXUNUSED(event)) |
246 | { | |
247 | wxBeginBusyCursor(); | |
248 | } | |
249 | ||
250 | void MyFrame::BusyOff(wxCommandEvent& WXUNUSED(event)) | |
251 | { | |
252 | wxEndBusyCursor(); | |
253 | } | |
254 | ||
b0d77f43 | 255 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 256 | { |
5ea47806 VZ |
257 | wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997", |
258 | "About list test", wxOK|wxCANCEL); | |
457814b5 | 259 | |
5ea47806 | 260 | dialog.ShowModal(); |
457814b5 JS |
261 | } |
262 | ||
58b3bdc9 VZ |
263 | void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event)) |
264 | { | |
265 | m_listCtrl->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | |
266 | } | |
267 | ||
c4771147 KB |
268 | void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event)) |
269 | { | |
5ea47806 VZ |
270 | int n = m_listCtrl->GetItemCount(); |
271 | for (int i = 0; i < n; i++) | |
272 | m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED); | |
c4771147 KB |
273 | } |
274 | ||
275 | void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
276 | { | |
5ea47806 VZ |
277 | int n = m_listCtrl->GetItemCount(); |
278 | for (int i = 0; i < n; i++) | |
279 | m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | |
c4771147 KB |
280 | } |
281 | ||
b0d77f43 | 282 | void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 283 | { |
95bf655c | 284 | m_listCtrl->ClearAll(); |
0180dad6 | 285 | m_logWindow->Clear(); |
95bf655c | 286 | |
0180dad6 | 287 | m_listCtrl->SetSingleStyle(wxLC_LIST); |
c67daf87 UR |
288 | m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL); |
289 | m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_SMALL); | |
457814b5 | 290 | |
0180dad6 RR |
291 | for ( int i=0; i < 30; i++) |
292 | { | |
5ea47806 VZ |
293 | wxChar buf[20]; |
294 | wxSprintf(buf, _T("Item %d"), i); | |
295 | m_listCtrl->InsertItem(i, buf); | |
0180dad6 | 296 | } |
457814b5 JS |
297 | } |
298 | ||
b0d77f43 | 299 | void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 300 | { |
0180dad6 | 301 | m_logWindow->Clear(); |
95bf655c | 302 | m_listCtrl->ClearAll(); |
5ea47806 | 303 | |
0180dad6 | 304 | m_listCtrl->SetSingleStyle(wxLC_REPORT); |
c67daf87 | 305 | m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL); |
c41ea66a | 306 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); |
457814b5 | 307 | |
0180dad6 RR |
308 | m_listCtrl->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140); |
309 | m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140); | |
310 | m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140); | |
311 | ||
81278df2 VZ |
312 | // to speed up inserting we hide the control temporarily |
313 | m_listCtrl->Hide(); | |
314 | ||
315 | wxStopWatch sw; | |
316 | ||
317 | wxString buf; | |
318 | static const int NUM_ITEMS = 3000; | |
319 | for ( int i = 0; i < NUM_ITEMS; i++ ) | |
0180dad6 | 320 | { |
81278df2 | 321 | buf.Printf(_T("This is item %d"), i); |
5ea47806 | 322 | long tmp = m_listCtrl->InsertItem(i, buf, 0); |
d62228a6 | 323 | m_listCtrl->SetItemData(tmp, i); |
5ea47806 | 324 | |
81278df2 | 325 | buf.Printf(_T("Col 1, item %d"), i); |
5ea47806 VZ |
326 | tmp = m_listCtrl->SetItem(i, 1, buf); |
327 | ||
81278df2 | 328 | buf.Printf(_T("Item %d in column 2"), i); |
5ea47806 | 329 | tmp = m_listCtrl->SetItem(i, 2, buf); |
0180dad6 | 330 | } |
bdc72a22 | 331 | |
81278df2 VZ |
332 | m_logWindow->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"), |
333 | NUM_ITEMS, sw.Time())); | |
334 | m_listCtrl->Show(); | |
335 | ||
f6b77239 | 336 | // we leave all mask fields to 0 and only change the colour |
bdc72a22 VZ |
337 | wxListItem item; |
338 | item.m_itemId = 0; | |
0530737d | 339 | item.SetTextColour(*wxRED); |
bdc72a22 VZ |
340 | m_listCtrl->SetItem( item ); |
341 | ||
342 | item.m_itemId = 2; | |
d62228a6 | 343 | item.SetTextColour(*wxGREEN); |
bdc72a22 | 344 | m_listCtrl->SetItem( item ); |
d62228a6 | 345 | item.m_itemId = 4; |
bdc72a22 | 346 | item.SetTextColour(*wxLIGHT_GREY); |
d62228a6 VZ |
347 | item.SetFont(*wxITALIC_FONT); |
348 | item.SetBackgroundColour(*wxRED); | |
bdc72a22 | 349 | m_listCtrl->SetItem( item ); |
5ea47806 | 350 | |
d62228a6 VZ |
351 | m_listCtrl->SetTextColour(*wxBLUE); |
352 | m_listCtrl->SetBackgroundColour(*wxLIGHT_GREY); | |
353 | ||
0180dad6 RR |
354 | m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); |
355 | m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); | |
356 | m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE ); | |
457814b5 JS |
357 | } |
358 | ||
b0d77f43 | 359 | void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 360 | { |
5ea47806 | 361 | m_logWindow->Clear(); |
95bf655c RR |
362 | m_listCtrl->ClearAll(); |
363 | ||
5ea47806 | 364 | m_listCtrl->SetSingleStyle(wxLC_ICON); |
c41ea66a VZ |
365 | m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); |
366 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); | |
457814b5 | 367 | |
5ea47806 VZ |
368 | for ( int i=0; i < 9; i++) |
369 | { | |
370 | m_listCtrl->InsertItem(i, i); | |
371 | } | |
457814b5 JS |
372 | } |
373 | ||
b0d77f43 | 374 | void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 375 | { |
5ea47806 | 376 | m_logWindow->Clear(); |
95bf655c RR |
377 | m_listCtrl->ClearAll(); |
378 | ||
5ea47806 | 379 | m_listCtrl->SetSingleStyle(wxLC_ICON); |
c41ea66a VZ |
380 | m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); |
381 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); | |
457814b5 | 382 | |
5ea47806 VZ |
383 | for ( int i=0; i < 9; i++) |
384 | { | |
385 | wxChar buf[20]; | |
386 | wxSprintf(buf, _T("Label %d"), i); | |
387 | m_listCtrl->InsertItem(i, buf, i); | |
388 | } | |
457814b5 JS |
389 | } |
390 | ||
b0d77f43 | 391 | void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 392 | { |
5ea47806 | 393 | m_logWindow->Clear(); |
95bf655c RR |
394 | m_listCtrl->ClearAll(); |
395 | ||
5ea47806 | 396 | m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON); |
c41ea66a VZ |
397 | m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); |
398 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); | |
457814b5 | 399 | |
5ea47806 VZ |
400 | for ( int i=0; i < 9; i++) |
401 | { | |
402 | m_listCtrl->InsertItem(i, 0); | |
403 | } | |
457814b5 JS |
404 | } |
405 | ||
b0d77f43 | 406 | void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 407 | { |
5ea47806 | 408 | m_logWindow->Clear(); |
95bf655c RR |
409 | m_listCtrl->ClearAll(); |
410 | ||
5ea47806 | 411 | m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON); |
c41ea66a VZ |
412 | m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); |
413 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); | |
457814b5 | 414 | |
5ea47806 VZ |
415 | for ( int i=0; i < 9; i++) |
416 | { | |
417 | m_listCtrl->InsertItem(i, "Label", 0); | |
418 | } | |
419 | } | |
420 | ||
fa5f6926 VZ |
421 | void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event)) |
422 | { | |
81278df2 VZ |
423 | wxStopWatch sw; |
424 | ||
fa5f6926 | 425 | m_listCtrl->SortItems(MyCompareFunction, 0); |
81278df2 VZ |
426 | |
427 | m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"), | |
428 | m_listCtrl->GetItemCount(), | |
429 | sw.Time())); | |
fa5f6926 VZ |
430 | } |
431 | ||
7b848b0d VZ |
432 | void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event)) |
433 | { | |
434 | m_logWindow->WriteText("Current selection mode: "); | |
435 | ||
436 | long flags = m_listCtrl->GetWindowStyleFlag(); | |
437 | if ( flags & wxLC_SINGLE_SEL ) | |
438 | { | |
439 | m_listCtrl->SetWindowStyleFlag(flags & ~wxLC_SINGLE_SEL); | |
440 | m_logWindow->WriteText("multiple"); | |
441 | } | |
442 | else | |
443 | { | |
444 | m_listCtrl->SetWindowStyleFlag(flags | wxLC_SINGLE_SEL); | |
445 | m_logWindow->WriteText("single"); | |
446 | } | |
447 | ||
448 | m_logWindow->WriteText("\nRecreate the control now\n"); | |
449 | } | |
450 | ||
11f26ea0 VZ |
451 | void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event)) |
452 | { | |
453 | m_listCtrl->SetForegroundColour(wxGetColourFromUser(this)); | |
454 | m_listCtrl->Refresh(); | |
455 | } | |
456 | ||
457 | void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event)) | |
458 | { | |
459 | m_listCtrl->SetBackgroundColour(wxGetColourFromUser(this)); | |
460 | m_listCtrl->Refresh(); | |
461 | } | |
462 | ||
5ea47806 VZ |
463 | void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event)) |
464 | { | |
81278df2 | 465 | wxStopWatch sw; |
5ea47806 | 466 | |
5ea47806 VZ |
467 | m_listCtrl->DeleteAllItems(); |
468 | ||
81278df2 VZ |
469 | m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"), |
470 | m_listCtrl->GetItemCount(), | |
471 | sw.Time())); | |
457814b5 JS |
472 | } |
473 | ||
474 | // MyListCtrl | |
475 | ||
8636aed8 RR |
476 | void MyListCtrl::OnColClick(wxListEvent& event) |
477 | { | |
c41ea66a | 478 | wxLogMessage( "OnColumnClick at %d.", event.GetColumn() ); |
8636aed8 RR |
479 | } |
480 | ||
fd9811b1 | 481 | void MyListCtrl::OnBeginDrag(wxListEvent& event) |
457814b5 | 482 | { |
c41ea66a VZ |
483 | wxLogMessage( "OnBeginDrag at %d,%d.", |
484 | event.m_pointDrag.x, event.m_pointDrag.y ); | |
457814b5 JS |
485 | } |
486 | ||
fd9811b1 | 487 | void MyListCtrl::OnBeginRDrag(wxListEvent& event) |
457814b5 | 488 | { |
c41ea66a VZ |
489 | wxLogMessage( "OnBeginRDrag at %d,%d.", |
490 | event.m_pointDrag.x, event.m_pointDrag.y ); | |
457814b5 JS |
491 | } |
492 | ||
fd9811b1 | 493 | void MyListCtrl::OnBeginLabelEdit(wxListEvent& event) |
457814b5 | 494 | { |
c41ea66a | 495 | wxLogMessage("OnBeginLabelEdit: %s", event.m_item.m_text.c_str()); |
457814b5 JS |
496 | } |
497 | ||
fd9811b1 | 498 | void MyListCtrl::OnEndLabelEdit(wxListEvent& event) |
457814b5 | 499 | { |
c41ea66a | 500 | wxLogMessage("OnEndLabelEdit: %s", event.m_item.m_text.c_str()); |
457814b5 JS |
501 | } |
502 | ||
efbb7287 | 503 | void MyListCtrl::OnDeleteItem(wxListEvent& event) |
457814b5 | 504 | { |
c41ea66a | 505 | LogEvent(event, _T("OnDeleteItem")); |
457814b5 JS |
506 | } |
507 | ||
c41ea66a | 508 | void MyListCtrl::OnDeleteAllItems(wxListEvent& event) |
12c1b46a | 509 | { |
c41ea66a | 510 | LogEvent(event, _T("OnDeleteAllItems")); |
12c1b46a RR |
511 | } |
512 | ||
fd9811b1 | 513 | void MyListCtrl::OnGetInfo(wxListEvent& event) |
457814b5 | 514 | { |
c41ea66a | 515 | wxString msg; |
5ea47806 | 516 | |
c41ea66a | 517 | msg << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")"; |
5ea47806 | 518 | if ( event.m_item.m_mask & wxLIST_MASK_STATE ) |
c41ea66a | 519 | msg << " wxLIST_MASK_STATE"; |
5ea47806 | 520 | if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) |
c41ea66a | 521 | msg << " wxLIST_MASK_TEXT"; |
5ea47806 | 522 | if ( event.m_item.m_mask & wxLIST_MASK_IMAGE ) |
c41ea66a | 523 | msg << " wxLIST_MASK_IMAGE"; |
5ea47806 | 524 | if ( event.m_item.m_mask & wxLIST_MASK_DATA ) |
c41ea66a | 525 | msg << " wxLIST_MASK_DATA"; |
5ea47806 | 526 | if ( event.m_item.m_mask & wxLIST_SET_ITEM ) |
c41ea66a | 527 | msg << " wxLIST_SET_ITEM"; |
5ea47806 | 528 | if ( event.m_item.m_mask & wxLIST_MASK_WIDTH ) |
c41ea66a | 529 | msg << " wxLIST_MASK_WIDTH"; |
5ea47806 | 530 | if ( event.m_item.m_mask & wxLIST_MASK_FORMAT ) |
c41ea66a | 531 | msg << " wxLIST_MASK_WIDTH"; |
5ea47806 VZ |
532 | |
533 | if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) | |
534 | { | |
535 | event.m_item.m_text = "My callback text"; | |
536 | } | |
c41ea66a VZ |
537 | |
538 | wxLogMessage(msg); | |
457814b5 JS |
539 | } |
540 | ||
efbb7287 | 541 | void MyListCtrl::OnSetInfo(wxListEvent& event) |
457814b5 | 542 | { |
c41ea66a | 543 | LogEvent(event, _T("OnSetInfo")); |
457814b5 JS |
544 | } |
545 | ||
74b31181 | 546 | void MyListCtrl::OnSelected(wxListEvent& event) |
457814b5 | 547 | { |
c41ea66a | 548 | LogEvent(event, _T("OnSelected")); |
457814b5 | 549 | |
40779a03 | 550 | if ( GetWindowStyle() & wxLC_REPORT ) |
74b31181 | 551 | { |
40779a03 VZ |
552 | wxListItem info; |
553 | info.m_itemId = event.m_itemIndex; | |
554 | info.m_col = 1; | |
555 | info.m_mask = wxLIST_MASK_TEXT; | |
556 | if ( GetItem(info) ) | |
557 | { | |
c41ea66a VZ |
558 | wxLogMessage("Value of the 2nd field of the selected item: %s", |
559 | info.m_text.c_str()); | |
40779a03 VZ |
560 | } |
561 | else | |
562 | { | |
563 | wxFAIL_MSG("wxListCtrl::GetItem() failed"); | |
564 | } | |
74b31181 | 565 | } |
457814b5 JS |
566 | } |
567 | ||
efbb7287 | 568 | void MyListCtrl::OnDeselected(wxListEvent& event) |
457814b5 | 569 | { |
c41ea66a | 570 | LogEvent(event, _T("OnDeselected")); |
457814b5 JS |
571 | } |
572 | ||
efbb7287 | 573 | void MyListCtrl::OnActivated(wxListEvent& event) |
435fe83e | 574 | { |
c41ea66a | 575 | LogEvent(event, _T("OnActivated")); |
435fe83e RR |
576 | } |
577 | ||
8e1d4f96 | 578 | void MyListCtrl::OnListKeyDown(wxListEvent& event) |
457814b5 | 579 | { |
c41ea66a | 580 | LogEvent(event, _T("OnListKeyDown")); |
457814b5 JS |
581 | } |
582 | ||
c41ea66a VZ |
583 | void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName) |
584 | { | |
585 | wxLogMessage(_T("Item %ld: %s (item data = %ld)"), | |
586 | event.GetIndex(), eventName, event.GetData()); | |
587 | } | |
435fe83e | 588 |