]> git.saurik.com Git - wxWidgets.git/blob - samples/listctrl/listtest.cpp
7d3fc9010c7460f05059671fab89329aca85a158
[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 "listtest.h"
35
36 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
37 EVT_MENU(BUSY_ON, MyFrame::BusyOn)
38 EVT_MENU(BUSY_OFF, MyFrame::BusyOff)
39 EVT_MENU(LIST_QUIT, MyFrame::OnQuit)
40 EVT_MENU(LIST_ABOUT, MyFrame::OnAbout)
41 EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView)
42 EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView)
43 EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView)
44 EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView)
45 EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
46 EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
47 EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
48 EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
49 EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
50 EVT_MENU(LIST_SORT, MyFrame::OnSort)
51 END_EVENT_TABLE()
52
53 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
54 EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
55 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
56 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit)
57 EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit)
58 EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
59 EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo)
60 EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
61 EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected)
62 EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
63 EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
64 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
65 EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
66 END_EVENT_TABLE()
67
68 IMPLEMENT_APP(MyApp)
69
70 int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
71 {
72 // inverse the order
73 return item1 < item2;
74 }
75
76 // `Main program' equivalent, creating windows and returning main app frame
77 bool MyApp::OnInit(void)
78 {
79 // Create the main frame window
80 MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxListCtrl Test", 50, 50, 450, 340);
81
82 // This reduces flicker effects - even better would be to define OnEraseBackground
83 // to do nothing. When the list control's scrollbars are show or hidden, the
84 // frame is sent a background erase event.
85 frame->SetBackgroundColour( *wxWHITE );
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 *file_menu = new wxMenu;
135
136 file_menu->Append(LIST_LIST_VIEW, "&List view\tF1");
137 file_menu->Append(LIST_REPORT_VIEW, "&Report view\tF2");
138 file_menu->Append(LIST_ICON_VIEW, "&Icon view\tF3");
139 file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text\tF4");
140 file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view\tF5");
141 file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text\tF6");
142 file_menu->Append(LIST_DESELECT_ALL, "&Deselect All");
143 file_menu->Append(LIST_SELECT_ALL, "S&elect All");
144 file_menu->AppendSeparator();
145 file_menu->Append(LIST_SORT, "&Sort\tCtrl-S");
146 file_menu->AppendSeparator();
147 file_menu->Append(LIST_DELETE_ALL, "Delete &all items");
148 file_menu->AppendSeparator();
149 file_menu->Append(BUSY_ON, "&Busy cursor on");
150 file_menu->Append(BUSY_OFF, "&Busy cursor off");
151 file_menu->AppendSeparator();
152 file_menu->Append(LIST_ABOUT, "&About");
153 file_menu->Append(LIST_QUIT, "E&xit\tAlt-X");
154 wxMenuBar *menu_bar = new wxMenuBar;
155 menu_bar->Append(file_menu, "&File");
156 frame->SetMenuBar(menu_bar);
157
158 // Make a panel with a message
159 frame->m_listCtrl = new MyListCtrl(frame, LIST_CTRL, wxPoint(0, 0), wxSize(400, 200),
160 wxLC_LIST|wxSUNKEN_BORDER|wxLC_EDIT_LABELS );
161 // wxLC_LIST|wxLC_USER_TEXT|wxSUNKEN_BORDER); // wxLC_USER_TEXT requires app to supply all text on demand
162 frame->m_logWindow = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxSize(400, 200), wxTE_MULTILINE|wxSUNKEN_BORDER);
163
164 wxLayoutConstraints *c = new wxLayoutConstraints;
165 c->top.SameAs (frame, wxTop);
166 c->left.SameAs (frame, wxLeft);
167 c->right.SameAs (frame, wxRight);
168 c->height.PercentOf (frame, wxHeight, 66);
169 frame->m_listCtrl->SetConstraints(c);
170
171 c = new wxLayoutConstraints;
172 c->top.Below (frame->m_listCtrl);
173 c->left.SameAs (frame, wxLeft);
174 c->right.SameAs (frame, wxRight);
175 c->bottom.SameAs (frame, wxBottom);
176 frame->m_logWindow->SetConstraints(c);
177 frame->SetAutoLayout(TRUE);
178
179 for ( int i=0; i < 30; i++)
180 {
181 wxChar buf[20];
182 wxSprintf(buf, _T("Item %d"), i);
183 frame->m_listCtrl->InsertItem(i, buf);
184 }
185
186 frame->CreateStatusBar(3);
187 frame->SetStatusText("", 0);
188
189 // Show the frame
190 frame->Show(TRUE);
191
192 SetTopWindow(frame);
193
194 return TRUE;
195 }
196
197 // My frame constructor
198 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
199 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
200 {
201 m_listCtrl = (MyListCtrl *) NULL;
202 m_logWindow = (wxTextCtrl *) NULL;
203 }
204
205 MyFrame::~MyFrame(void)
206 {
207 delete wxGetApp().m_imageListNormal;
208 delete wxGetApp().m_imageListSmall;
209 }
210
211 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
212 {
213 Close(TRUE);
214 }
215
216 void MyFrame::BusyOn(wxCommandEvent& WXUNUSED(event))
217 {
218 wxBeginBusyCursor();
219 }
220
221 void MyFrame::BusyOff(wxCommandEvent& WXUNUSED(event))
222 {
223 wxEndBusyCursor();
224 }
225
226 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
227 {
228 wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997",
229 "About list test", wxOK|wxCANCEL);
230
231 dialog.ShowModal();
232 }
233
234 void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))
235 {
236 int n = m_listCtrl->GetItemCount();
237 for (int i = 0; i < n; i++)
238 m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED);
239 }
240
241 void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
242 {
243 int n = m_listCtrl->GetItemCount();
244 for (int i = 0; i < n; i++)
245 m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
246 }
247
248 void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event))
249 {
250 m_listCtrl->DeleteAllItems();
251 m_logWindow->Clear();
252 m_listCtrl->SetSingleStyle(wxLC_LIST);
253 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
254 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_SMALL);
255
256 for ( int i=0; i < 30; i++)
257 {
258 wxChar buf[20];
259 wxSprintf(buf, _T("Item %d"), i);
260 m_listCtrl->InsertItem(i, buf);
261 }
262 }
263
264 void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
265 {
266 m_listCtrl->DeleteAllItems();
267 m_listCtrl->DeleteAllColumns();
268 m_logWindow->Clear();
269
270 m_listCtrl->SetSingleStyle(wxLC_REPORT);
271 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
272 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
273
274 m_listCtrl->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140);
275 m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
276 m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
277
278 // to speed up inserting we hide the control temporarily
279 m_listCtrl->Hide();
280
281 wxStopWatch sw;
282
283 wxString buf;
284 static const int NUM_ITEMS = 3000;
285 for ( int i = 0; i < NUM_ITEMS; i++ )
286 {
287 buf.Printf(_T("This is item %d"), i);
288 long tmp = m_listCtrl->InsertItem(i, buf, 0);
289 m_listCtrl->SetItemData(tmp, i);
290
291 buf.Printf(_T("Col 1, item %d"), i);
292 tmp = m_listCtrl->SetItem(i, 1, buf);
293
294 buf.Printf(_T("Item %d in column 2"), i);
295 tmp = m_listCtrl->SetItem(i, 2, buf);
296 }
297
298 m_logWindow->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"),
299 NUM_ITEMS, sw.Time()));
300 m_listCtrl->Show();
301
302 // we leave all mask fields to 0 and only change the colour
303 wxListItem item;
304 item.m_itemId = 0;
305 item.SetTextColour(*wxRED);
306 m_listCtrl->SetItem( item );
307
308 item.m_itemId = 2;
309 item.SetTextColour(*wxGREEN);
310 m_listCtrl->SetItem( item );
311 item.m_itemId = 4;
312 item.SetTextColour(*wxLIGHT_GREY);
313 item.SetFont(*wxITALIC_FONT);
314 item.SetBackgroundColour(*wxRED);
315 m_listCtrl->SetItem( item );
316
317 m_listCtrl->SetTextColour(*wxBLUE);
318 m_listCtrl->SetBackgroundColour(*wxLIGHT_GREY);
319
320 m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
321 m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
322 m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE );
323 }
324
325 void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event))
326 {
327 m_listCtrl->DeleteAllItems();
328 m_logWindow->Clear();
329 m_listCtrl->SetSingleStyle(wxLC_ICON);
330 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
331 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
332
333 for ( int i=0; i < 9; i++)
334 {
335 m_listCtrl->InsertItem(i, i);
336 }
337 }
338
339 void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event))
340 {
341 m_listCtrl->DeleteAllItems();
342 m_logWindow->Clear();
343 m_listCtrl->SetSingleStyle(wxLC_ICON);
344 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
345 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
346
347 for ( int i=0; i < 9; i++)
348 {
349 wxChar buf[20];
350 wxSprintf(buf, _T("Label %d"), i);
351 m_listCtrl->InsertItem(i, buf, i);
352 }
353 }
354
355 void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
356 {
357 m_listCtrl->DeleteAllItems();
358 m_logWindow->Clear();
359 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
360 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
361 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
362
363 for ( int i=0; i < 9; i++)
364 {
365 m_listCtrl->InsertItem(i, 0);
366 }
367 }
368
369 void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
370 {
371 m_listCtrl->DeleteAllItems();
372 m_logWindow->Clear();
373 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
374 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
375 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
376
377 for ( int i=0; i < 9; i++)
378 {
379 m_listCtrl->InsertItem(i, "Label", 0);
380 }
381 }
382
383 void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
384 {
385 wxStopWatch sw;
386
387 m_listCtrl->SortItems(MyCompareFunction, 0);
388
389 m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
390 m_listCtrl->GetItemCount(),
391 sw.Time()));
392 }
393
394 void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
395 {
396 wxStopWatch sw;
397
398 m_listCtrl->DeleteAllItems();
399
400 m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
401 m_listCtrl->GetItemCount(),
402 sw.Time()));
403 }
404
405 // MyListCtrl
406
407 void MyListCtrl::OnColClick(wxListEvent& event)
408 {
409 if ( !wxGetApp().GetTopWindow() )
410 return;
411
412 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
413 if ( !text )
414 return;
415
416 wxString msg;
417 msg.Printf( "OnColumnClick at %d.\n", event.GetColumn() );
418 text->WriteText(msg);
419 }
420
421 void MyListCtrl::OnBeginDrag(wxListEvent& event)
422 {
423 if ( !wxGetApp().GetTopWindow() )
424 return;
425
426 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
427 if ( !text )
428 return;
429
430 wxString msg;
431 msg.Printf( "OnBeginDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y );
432 text->WriteText(msg);
433 }
434
435 void MyListCtrl::OnBeginRDrag(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( "OnBeginRDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y );
446 text->WriteText(msg);
447 }
448
449 void MyListCtrl::OnBeginLabelEdit(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 text->WriteText("OnBeginLabelEdit: ");
459 text->WriteText(event.m_item.m_text);
460 text->WriteText("\n");
461 }
462
463 void MyListCtrl::OnEndLabelEdit(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 text->WriteText("OnEndLabelEdit: ");
473 text->WriteText(event.m_item.m_text);
474 text->WriteText("\n");
475 }
476
477 void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(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("OnDeleteItem\n");
487 }
488
489 void MyListCtrl::OnGetInfo(wxListEvent& event)
490 {
491 if ( !wxGetApp().GetTopWindow() )
492 return;
493
494 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
495 if ( !text )
496 return;
497
498 text->WriteText("OnGetInfo\n");
499
500 (*text) << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")";
501 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
502 (*text) << " wxLIST_MASK_STATE";
503 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
504 (*text) << " wxLIST_MASK_TEXT";
505 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
506 (*text) << " wxLIST_MASK_IMAGE";
507 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
508 (*text) << " wxLIST_MASK_DATA";
509 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
510 (*text) << " wxLIST_SET_ITEM";
511 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
512 (*text) << " wxLIST_MASK_WIDTH";
513 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
514 (*text) << " wxLIST_MASK_WIDTH";
515
516 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
517 {
518 event.m_item.m_text = "My callback text";
519 }
520 (*text) << "\n";
521 }
522
523 void MyListCtrl::OnSetInfo(wxListEvent& WXUNUSED(event))
524 {
525 if ( !wxGetApp().GetTopWindow() )
526 return;
527
528 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
529 if ( !text )
530 return;
531
532 text->WriteText("OnSetInfo\n");
533 }
534
535 void MyListCtrl::OnSelected(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 if ( GetWindowStyle() & wxLC_REPORT )
545 {
546 wxListItem info;
547 info.m_itemId = event.m_itemIndex;
548 info.m_col = 1;
549 info.m_mask = wxLIST_MASK_TEXT;
550 if ( GetItem(info) )
551 {
552 *text << "Value of the 2nd field of the selected item: "
553 << info.m_text << '\n';
554 }
555 else
556 {
557 wxFAIL_MSG("wxListCtrl::GetItem() failed");
558 }
559 }
560
561 text->WriteText("OnSelected\n");
562 }
563
564 void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event))
565 {
566 if ( !wxGetApp().GetTopWindow() )
567 return;
568
569 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
570 if ( !text )
571 return;
572
573 text->WriteText("OnDeselected\n");
574 }
575
576 void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(event))
577 {
578 if ( !wxGetApp().GetTopWindow() )
579 return;
580
581 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
582 if ( !text )
583 return;
584
585 text->WriteText("OnActivated\n");
586 }
587
588 void MyListCtrl::OnListKeyDown(wxListEvent& event)
589 {
590 if ( !wxGetApp().GetTopWindow() )
591 return;
592
593 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
594 if ( !text )
595 return;
596
597 text->WriteText("OnListKeyDown\n");
598 }
599
600