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