]> git.saurik.com Git - wxWidgets.git/blob - samples/listctrl/listtest.cpp
added test for selection events
[wxWidgets.git] / samples / listctrl / listtest.cpp
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
9 // Licence: wxWindows license
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
28 #ifndef __WXMSW__
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"
41 #endif
42
43 #include "wx/listctrl.h"
44 #include "wx/timer.h" // for wxStopWatch
45 #include "wx/colordlg.h" // for wxGetColourFromUser
46
47 #include "listtest.h"
48
49 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
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)
60 EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
61 EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
62 EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
63 EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
64 EVT_MENU(LIST_SORT, MyFrame::OnSort)
65 EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
66 EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
67 EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
68 END_EVENT_TABLE()
69
70 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
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)
76 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems)
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)
83 EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
84 END_EVENT_TABLE()
85
86 IMPLEMENT_APP(MyApp)
87
88 int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
89 {
90 // inverse the order
91 return item1 < item2;
92 }
93
94 // `Main program' equivalent, creating windows and returning main app frame
95 bool MyApp::OnInit()
96 {
97 // Create the main frame window
98 MyFrame *frame = new MyFrame("wxListCtrl Test", 50, 50, 450, 340);
99
100 // Show the frame
101 frame->Show(TRUE);
102
103 SetTopWindow(frame);
104
105 return TRUE;
106 }
107
108 // My frame constructor
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))
111 {
112 m_listCtrl = (MyListCtrl *) NULL;
113 m_logWindow = (wxTextCtrl *) NULL;
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;
169 menuList->Append(LIST_TOGGLE_FIRST, "&Toggle first item\tCtrl-T");
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);
230 }
231
232 MyFrame::~MyFrame()
233 {
234 delete wxLog::SetActiveTarget(m_logOld);
235
236 delete m_imageListNormal;
237 delete m_imageListSmall;
238 }
239
240 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
241 {
242 Close(TRUE);
243 }
244
245 void MyFrame::BusyOn(wxCommandEvent& WXUNUSED(event))
246 {
247 wxBeginBusyCursor();
248 }
249
250 void MyFrame::BusyOff(wxCommandEvent& WXUNUSED(event))
251 {
252 wxEndBusyCursor();
253 }
254
255 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
256 {
257 wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997",
258 "About list test", wxOK|wxCANCEL);
259
260 dialog.ShowModal();
261 }
262
263 void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event))
264 {
265 m_listCtrl->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
266 }
267
268 void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))
269 {
270 int n = m_listCtrl->GetItemCount();
271 for (int i = 0; i < n; i++)
272 m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED);
273 }
274
275 void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
276 {
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);
280 }
281
282 void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event))
283 {
284 m_listCtrl->ClearAll();
285 m_logWindow->Clear();
286
287 m_listCtrl->SetSingleStyle(wxLC_LIST);
288 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
289 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_SMALL);
290
291 for ( int i=0; i < 30; i++)
292 {
293 wxChar buf[20];
294 wxSprintf(buf, _T("Item %d"), i);
295 m_listCtrl->InsertItem(i, buf);
296 }
297 }
298
299 void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
300 {
301 m_logWindow->Clear();
302 m_listCtrl->ClearAll();
303
304 m_listCtrl->SetSingleStyle(wxLC_REPORT);
305 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
306 m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
307
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
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++ )
320 {
321 buf.Printf(_T("This is item %d"), i);
322 long tmp = m_listCtrl->InsertItem(i, buf, 0);
323 m_listCtrl->SetItemData(tmp, i);
324
325 buf.Printf(_T("Col 1, item %d"), i);
326 tmp = m_listCtrl->SetItem(i, 1, buf);
327
328 buf.Printf(_T("Item %d in column 2"), i);
329 tmp = m_listCtrl->SetItem(i, 2, buf);
330 }
331
332 m_logWindow->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"),
333 NUM_ITEMS, sw.Time()));
334 m_listCtrl->Show();
335
336 // we leave all mask fields to 0 and only change the colour
337 wxListItem item;
338 item.m_itemId = 0;
339 item.SetTextColour(*wxRED);
340 m_listCtrl->SetItem( item );
341
342 item.m_itemId = 2;
343 item.SetTextColour(*wxGREEN);
344 m_listCtrl->SetItem( item );
345 item.m_itemId = 4;
346 item.SetTextColour(*wxLIGHT_GREY);
347 item.SetFont(*wxITALIC_FONT);
348 item.SetBackgroundColour(*wxRED);
349 m_listCtrl->SetItem( item );
350
351 m_listCtrl->SetTextColour(*wxBLUE);
352 m_listCtrl->SetBackgroundColour(*wxLIGHT_GREY);
353
354 m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
355 m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
356 m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE );
357 }
358
359 void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event))
360 {
361 m_logWindow->Clear();
362 m_listCtrl->ClearAll();
363
364 m_listCtrl->SetSingleStyle(wxLC_ICON);
365 m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL);
366 m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
367
368 for ( int i=0; i < 9; i++)
369 {
370 m_listCtrl->InsertItem(i, i);
371 }
372 }
373
374 void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event))
375 {
376 m_logWindow->Clear();
377 m_listCtrl->ClearAll();
378
379 m_listCtrl->SetSingleStyle(wxLC_ICON);
380 m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL);
381 m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
382
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 }
389 }
390
391 void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
392 {
393 m_logWindow->Clear();
394 m_listCtrl->ClearAll();
395
396 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
397 m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL);
398 m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
399
400 for ( int i=0; i < 9; i++)
401 {
402 m_listCtrl->InsertItem(i, 0);
403 }
404 }
405
406 void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
407 {
408 m_logWindow->Clear();
409 m_listCtrl->ClearAll();
410
411 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
412 m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL);
413 m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
414
415 for ( int i=0; i < 9; i++)
416 {
417 m_listCtrl->InsertItem(i, "Label", 0);
418 }
419 }
420
421 void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
422 {
423 wxStopWatch sw;
424
425 m_listCtrl->SortItems(MyCompareFunction, 0);
426
427 m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
428 m_listCtrl->GetItemCount(),
429 sw.Time()));
430 }
431
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
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
463 void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
464 {
465 wxStopWatch sw;
466
467 m_listCtrl->DeleteAllItems();
468
469 m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
470 m_listCtrl->GetItemCount(),
471 sw.Time()));
472 }
473
474 // MyListCtrl
475
476 void MyListCtrl::OnColClick(wxListEvent& event)
477 {
478 wxLogMessage( "OnColumnClick at %d.", event.GetColumn() );
479 }
480
481 void MyListCtrl::OnBeginDrag(wxListEvent& event)
482 {
483 wxLogMessage( "OnBeginDrag at %d,%d.",
484 event.m_pointDrag.x, event.m_pointDrag.y );
485 }
486
487 void MyListCtrl::OnBeginRDrag(wxListEvent& event)
488 {
489 wxLogMessage( "OnBeginRDrag at %d,%d.",
490 event.m_pointDrag.x, event.m_pointDrag.y );
491 }
492
493 void MyListCtrl::OnBeginLabelEdit(wxListEvent& event)
494 {
495 wxLogMessage("OnBeginLabelEdit: %s", event.m_item.m_text.c_str());
496 }
497
498 void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
499 {
500 wxLogMessage("OnEndLabelEdit: %s", event.m_item.m_text.c_str());
501 }
502
503 void MyListCtrl::OnDeleteItem(wxListEvent& event)
504 {
505 LogEvent(event, _T("OnDeleteItem"));
506 }
507
508 void MyListCtrl::OnDeleteAllItems(wxListEvent& event)
509 {
510 LogEvent(event, _T("OnDeleteAllItems"));
511 }
512
513 void MyListCtrl::OnGetInfo(wxListEvent& event)
514 {
515 wxString msg;
516
517 msg << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")";
518 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
519 msg << " wxLIST_MASK_STATE";
520 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
521 msg << " wxLIST_MASK_TEXT";
522 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
523 msg << " wxLIST_MASK_IMAGE";
524 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
525 msg << " wxLIST_MASK_DATA";
526 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
527 msg << " wxLIST_SET_ITEM";
528 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
529 msg << " wxLIST_MASK_WIDTH";
530 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
531 msg << " wxLIST_MASK_WIDTH";
532
533 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
534 {
535 event.m_item.m_text = "My callback text";
536 }
537
538 wxLogMessage(msg);
539 }
540
541 void MyListCtrl::OnSetInfo(wxListEvent& event)
542 {
543 LogEvent(event, _T("OnSetInfo"));
544 }
545
546 void MyListCtrl::OnSelected(wxListEvent& event)
547 {
548 LogEvent(event, _T("OnSelected"));
549
550 if ( GetWindowStyle() & wxLC_REPORT )
551 {
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 {
558 wxLogMessage("Value of the 2nd field of the selected item: %s",
559 info.m_text.c_str());
560 }
561 else
562 {
563 wxFAIL_MSG("wxListCtrl::GetItem() failed");
564 }
565 }
566 }
567
568 void MyListCtrl::OnDeselected(wxListEvent& event)
569 {
570 LogEvent(event, _T("OnDeselected"));
571 }
572
573 void MyListCtrl::OnActivated(wxListEvent& event)
574 {
575 LogEvent(event, _T("OnActivated"));
576 }
577
578 void MyListCtrl::OnListKeyDown(wxListEvent& event)
579 {
580 LogEvent(event, _T("OnListKeyDown"));
581 }
582
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 }
588