]> git.saurik.com Git - wxWidgets.git/blob - samples/listctrl/listtest.cpp
many fixed for configure for Win32 - cross-compiling should work now
[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->ClearAll();
252 m_logWindow->Clear();
253
254 m_listCtrl->SetSingleStyle(wxLC_LIST);
255 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
256 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_SMALL);
257
258 for ( int i=0; i < 30; i++)
259 {
260 wxChar buf[20];
261 wxSprintf(buf, _T("Item %d"), i);
262 m_listCtrl->InsertItem(i, buf);
263 }
264 }
265
266 void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
267 {
268 m_logWindow->Clear();
269 m_listCtrl->ClearAll();
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_logWindow->Clear();
329 m_listCtrl->ClearAll();
330
331 m_listCtrl->SetSingleStyle(wxLC_ICON);
332 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
333 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
334
335 for ( int i=0; i < 9; i++)
336 {
337 m_listCtrl->InsertItem(i, i);
338 }
339 }
340
341 void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event))
342 {
343 m_logWindow->Clear();
344 m_listCtrl->ClearAll();
345
346 m_listCtrl->SetSingleStyle(wxLC_ICON);
347 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
348 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
349
350 for ( int i=0; i < 9; i++)
351 {
352 wxChar buf[20];
353 wxSprintf(buf, _T("Label %d"), i);
354 m_listCtrl->InsertItem(i, buf, i);
355 }
356 }
357
358 void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
359 {
360 m_logWindow->Clear();
361 m_listCtrl->ClearAll();
362
363 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
364 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
365 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
366
367 for ( int i=0; i < 9; i++)
368 {
369 m_listCtrl->InsertItem(i, 0);
370 }
371 }
372
373 void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
374 {
375 m_logWindow->Clear();
376 m_listCtrl->ClearAll();
377
378 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
379 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
380 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
381
382 for ( int i=0; i < 9; i++)
383 {
384 m_listCtrl->InsertItem(i, "Label", 0);
385 }
386 }
387
388 void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
389 {
390 wxStopWatch sw;
391
392 m_listCtrl->SortItems(MyCompareFunction, 0);
393
394 m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
395 m_listCtrl->GetItemCount(),
396 sw.Time()));
397 }
398
399 void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
400 {
401 wxStopWatch sw;
402
403 m_listCtrl->DeleteAllItems();
404
405 m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
406 m_listCtrl->GetItemCount(),
407 sw.Time()));
408 }
409
410 // MyListCtrl
411
412 void MyListCtrl::OnColClick(wxListEvent& event)
413 {
414 if ( !wxGetApp().GetTopWindow() )
415 return;
416
417 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
418 if ( !text )
419 return;
420
421 wxString msg;
422 msg.Printf( "OnColumnClick at %d.\n", event.GetColumn() );
423 text->WriteText(msg);
424 }
425
426 void MyListCtrl::OnBeginDrag(wxListEvent& event)
427 {
428 if ( !wxGetApp().GetTopWindow() )
429 return;
430
431 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
432 if ( !text )
433 return;
434
435 wxString msg;
436 msg.Printf( "OnBeginDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y );
437 text->WriteText(msg);
438 }
439
440 void MyListCtrl::OnBeginRDrag(wxListEvent& event)
441 {
442 if ( !wxGetApp().GetTopWindow() )
443 return;
444
445 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
446 if ( !text )
447 return;
448
449 wxString msg;
450 msg.Printf( "OnBeginRDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y );
451 text->WriteText(msg);
452 }
453
454 void MyListCtrl::OnBeginLabelEdit(wxListEvent& event)
455 {
456 if ( !wxGetApp().GetTopWindow() )
457 return;
458
459 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
460 if ( !text )
461 return;
462
463 text->WriteText("OnBeginLabelEdit: ");
464 text->WriteText(event.m_item.m_text);
465 text->WriteText("\n");
466 }
467
468 void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
469 {
470 if ( !wxGetApp().GetTopWindow() )
471 return;
472
473 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
474 if ( !text )
475 return;
476
477 text->WriteText("OnEndLabelEdit: ");
478 text->WriteText(event.m_item.m_text);
479 text->WriteText("\n");
480 }
481
482 void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(event))
483 {
484 if ( !wxGetApp().GetTopWindow() )
485 return;
486
487 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
488 if ( !text )
489 return;
490
491 text->WriteText("OnDeleteItem\n");
492 }
493
494 void MyListCtrl::OnDeleteAllItems(wxListEvent& WXUNUSED(event))
495 {
496 if ( !wxGetApp().GetTopWindow() )
497 return;
498
499 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
500 if ( !text )
501 return;
502
503 text->WriteText("OnDeleteAllItems\n");
504 }
505
506 void MyListCtrl::OnGetInfo(wxListEvent& event)
507 {
508 if ( !wxGetApp().GetTopWindow() )
509 return;
510
511 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
512 if ( !text )
513 return;
514
515 text->WriteText("OnGetInfo\n");
516
517 (*text) << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")";
518 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
519 (*text) << " wxLIST_MASK_STATE";
520 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
521 (*text) << " wxLIST_MASK_TEXT";
522 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
523 (*text) << " wxLIST_MASK_IMAGE";
524 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
525 (*text) << " wxLIST_MASK_DATA";
526 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
527 (*text) << " wxLIST_SET_ITEM";
528 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
529 (*text) << " wxLIST_MASK_WIDTH";
530 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
531 (*text) << " wxLIST_MASK_WIDTH";
532
533 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
534 {
535 event.m_item.m_text = "My callback text";
536 }
537 (*text) << "\n";
538 }
539
540 void MyListCtrl::OnSetInfo(wxListEvent& WXUNUSED(event))
541 {
542 if ( !wxGetApp().GetTopWindow() )
543 return;
544
545 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
546 if ( !text )
547 return;
548
549 text->WriteText("OnSetInfo\n");
550 }
551
552 void MyListCtrl::OnSelected(wxListEvent& event)
553 {
554 if ( !wxGetApp().GetTopWindow() )
555 return;
556
557 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
558 if ( !text )
559 return;
560
561 if ( GetWindowStyle() & wxLC_REPORT )
562 {
563 wxListItem info;
564 info.m_itemId = event.m_itemIndex;
565 info.m_col = 1;
566 info.m_mask = wxLIST_MASK_TEXT;
567 if ( GetItem(info) )
568 {
569 *text << "Value of the 2nd field of the selected item: "
570 << info.m_text << '\n';
571 }
572 else
573 {
574 wxFAIL_MSG("wxListCtrl::GetItem() failed");
575 }
576 }
577
578 text->WriteText("OnSelected\n");
579 }
580
581 void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event))
582 {
583 if ( !wxGetApp().GetTopWindow() )
584 return;
585
586 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
587 if ( !text )
588 return;
589
590 text->WriteText("OnDeselected\n");
591 }
592
593 void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(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("OnActivated\n");
603 }
604
605 void MyListCtrl::OnListKeyDown(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 text->WriteText("OnListKeyDown\n");
615 }
616
617