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