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