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