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