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