]> git.saurik.com Git - wxWidgets.git/blob - samples/listctrl/listtest.cpp
added option for drawing a textured background to test masks on a
[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 frame->m_listCtrl = new MyListCtrl(frame, LIST_CTRL, wxPoint(0, 0), wxSize(400, 200),
172 wxLC_LIST|wxSUNKEN_BORDER|wxLC_EDIT_LABELS );
173 // wxLC_LIST|wxLC_USER_TEXT|wxSUNKEN_BORDER); // wxLC_USER_TEXT requires app to supply all text on demand
174
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 wxChar buf[20];
196 wxSprintf(buf, _T("Item %d"), i);
197 frame->m_listCtrl->InsertItem(i, buf);
198 }
199
200 frame->CreateStatusBar(3);
201
202 // Show the frame
203 frame->Show(TRUE);
204
205 SetTopWindow(frame);
206
207 return TRUE;
208 }
209
210 // My frame constructor
211 MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
212 : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
213 {
214 m_listCtrl = (MyListCtrl *) NULL;
215 m_logWindow = (wxTextCtrl *) NULL;
216 }
217
218 MyFrame::~MyFrame()
219 {
220 delete wxGetApp().m_imageListNormal;
221 delete wxGetApp().m_imageListSmall;
222 }
223
224 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
225 {
226 Close(TRUE);
227 }
228
229 void MyFrame::BusyOn(wxCommandEvent& WXUNUSED(event))
230 {
231 wxBeginBusyCursor();
232 }
233
234 void MyFrame::BusyOff(wxCommandEvent& WXUNUSED(event))
235 {
236 wxEndBusyCursor();
237 }
238
239 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
240 {
241 wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997",
242 "About list test", wxOK|wxCANCEL);
243
244 dialog.ShowModal();
245 }
246
247 void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))
248 {
249 int n = m_listCtrl->GetItemCount();
250 for (int i = 0; i < n; i++)
251 m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED);
252 }
253
254 void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
255 {
256 int n = m_listCtrl->GetItemCount();
257 for (int i = 0; i < n; i++)
258 m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
259 }
260
261 void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event))
262 {
263 m_listCtrl->ClearAll();
264 m_logWindow->Clear();
265
266 m_listCtrl->SetSingleStyle(wxLC_LIST);
267 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
268 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_SMALL);
269
270 for ( int i=0; i < 30; i++)
271 {
272 wxChar buf[20];
273 wxSprintf(buf, _T("Item %d"), i);
274 m_listCtrl->InsertItem(i, buf);
275 }
276 }
277
278 void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
279 {
280 m_logWindow->Clear();
281 m_listCtrl->ClearAll();
282
283 m_listCtrl->SetSingleStyle(wxLC_REPORT);
284 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
285 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
286
287 m_listCtrl->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140);
288 m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
289 m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
290
291 // to speed up inserting we hide the control temporarily
292 m_listCtrl->Hide();
293
294 wxStopWatch sw;
295
296 wxString buf;
297 static const int NUM_ITEMS = 3000;
298 for ( int i = 0; i < NUM_ITEMS; i++ )
299 {
300 buf.Printf(_T("This is item %d"), i);
301 long tmp = m_listCtrl->InsertItem(i, buf, 0);
302 m_listCtrl->SetItemData(tmp, i);
303
304 buf.Printf(_T("Col 1, item %d"), i);
305 tmp = m_listCtrl->SetItem(i, 1, buf);
306
307 buf.Printf(_T("Item %d in column 2"), i);
308 tmp = m_listCtrl->SetItem(i, 2, buf);
309 }
310
311 m_logWindow->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"),
312 NUM_ITEMS, sw.Time()));
313 m_listCtrl->Show();
314
315 // we leave all mask fields to 0 and only change the colour
316 wxListItem item;
317 item.m_itemId = 0;
318 item.SetTextColour(*wxRED);
319 m_listCtrl->SetItem( item );
320
321 item.m_itemId = 2;
322 item.SetTextColour(*wxGREEN);
323 m_listCtrl->SetItem( item );
324 item.m_itemId = 4;
325 item.SetTextColour(*wxLIGHT_GREY);
326 item.SetFont(*wxITALIC_FONT);
327 item.SetBackgroundColour(*wxRED);
328 m_listCtrl->SetItem( item );
329
330 m_listCtrl->SetTextColour(*wxBLUE);
331 m_listCtrl->SetBackgroundColour(*wxLIGHT_GREY);
332
333 m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
334 m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
335 m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE );
336 }
337
338 void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event))
339 {
340 m_logWindow->Clear();
341 m_listCtrl->ClearAll();
342
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 m_listCtrl->InsertItem(i, i);
350 }
351 }
352
353 void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event))
354 {
355 m_logWindow->Clear();
356 m_listCtrl->ClearAll();
357
358 m_listCtrl->SetSingleStyle(wxLC_ICON);
359 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
360 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
361
362 for ( int i=0; i < 9; i++)
363 {
364 wxChar buf[20];
365 wxSprintf(buf, _T("Label %d"), i);
366 m_listCtrl->InsertItem(i, buf, i);
367 }
368 }
369
370 void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
371 {
372 m_logWindow->Clear();
373 m_listCtrl->ClearAll();
374
375 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
376 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
377 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
378
379 for ( int i=0; i < 9; i++)
380 {
381 m_listCtrl->InsertItem(i, 0);
382 }
383 }
384
385 void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
386 {
387 m_logWindow->Clear();
388 m_listCtrl->ClearAll();
389
390 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
391 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
392 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
393
394 for ( int i=0; i < 9; i++)
395 {
396 m_listCtrl->InsertItem(i, "Label", 0);
397 }
398 }
399
400 void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
401 {
402 wxStopWatch sw;
403
404 m_listCtrl->SortItems(MyCompareFunction, 0);
405
406 m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
407 m_listCtrl->GetItemCount(),
408 sw.Time()));
409 }
410
411 void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
412 {
413 m_listCtrl->SetForegroundColour(wxGetColourFromUser(this));
414 m_listCtrl->Refresh();
415 }
416
417 void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event))
418 {
419 m_listCtrl->SetBackgroundColour(wxGetColourFromUser(this));
420 m_listCtrl->Refresh();
421 }
422
423 void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
424 {
425 wxStopWatch sw;
426
427 m_listCtrl->DeleteAllItems();
428
429 m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
430 m_listCtrl->GetItemCount(),
431 sw.Time()));
432 }
433
434 // MyListCtrl
435
436 void MyListCtrl::OnColClick(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( "OnColumnClick at %d.\n", event.GetColumn() );
447 text->WriteText(msg);
448 }
449
450 void MyListCtrl::OnBeginDrag(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 wxString msg;
460 msg.Printf( "OnBeginDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y );
461 text->WriteText(msg);
462 }
463
464 void MyListCtrl::OnBeginRDrag(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 wxString msg;
474 msg.Printf( "OnBeginRDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y );
475 text->WriteText(msg);
476 }
477
478 void MyListCtrl::OnBeginLabelEdit(wxListEvent& 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("OnBeginLabelEdit: ");
488 text->WriteText(event.m_item.m_text);
489 text->WriteText("\n");
490 }
491
492 void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
493 {
494 if ( !wxGetApp().GetTopWindow() )
495 return;
496
497 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
498 if ( !text )
499 return;
500
501 text->WriteText("OnEndLabelEdit: ");
502 text->WriteText(event.m_item.m_text);
503 text->WriteText("\n");
504 }
505
506 void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(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("OnDeleteItem\n");
516 }
517
518 void MyListCtrl::OnDeleteAllItems(wxListEvent& WXUNUSED(event))
519 {
520 if ( !wxGetApp().GetTopWindow() )
521 return;
522
523 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
524 if ( !text )
525 return;
526
527 text->WriteText("OnDeleteAllItems\n");
528 }
529
530 void MyListCtrl::OnGetInfo(wxListEvent& event)
531 {
532 if ( !wxGetApp().GetTopWindow() )
533 return;
534
535 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
536 if ( !text )
537 return;
538
539 text->WriteText("OnGetInfo\n");
540
541 (*text) << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")";
542 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
543 (*text) << " wxLIST_MASK_STATE";
544 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
545 (*text) << " wxLIST_MASK_TEXT";
546 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
547 (*text) << " wxLIST_MASK_IMAGE";
548 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
549 (*text) << " wxLIST_MASK_DATA";
550 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
551 (*text) << " wxLIST_SET_ITEM";
552 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
553 (*text) << " wxLIST_MASK_WIDTH";
554 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
555 (*text) << " wxLIST_MASK_WIDTH";
556
557 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
558 {
559 event.m_item.m_text = "My callback text";
560 }
561 (*text) << "\n";
562 }
563
564 void MyListCtrl::OnSetInfo(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("OnSetInfo\n");
574 }
575
576 void MyListCtrl::OnSelected(wxListEvent& event)
577 {
578 if ( !wxGetApp().GetTopWindow() )
579 return;
580
581 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
582 if ( !text )
583 return;
584
585 if ( GetWindowStyle() & wxLC_REPORT )
586 {
587 wxListItem info;
588 info.m_itemId = event.m_itemIndex;
589 info.m_col = 1;
590 info.m_mask = wxLIST_MASK_TEXT;
591 if ( GetItem(info) )
592 {
593 *text << "Value of the 2nd field of the selected item: "
594 << info.m_text << '\n';
595 }
596 else
597 {
598 wxFAIL_MSG("wxListCtrl::GetItem() failed");
599 }
600 }
601
602 text->WriteText("OnSelected\n");
603 }
604
605 void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(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("OnDeselected\n");
615 }
616
617 void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(event))
618 {
619 if ( !wxGetApp().GetTopWindow() )
620 return;
621
622 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
623 if ( !text )
624 return;
625
626 text->WriteText("OnActivated\n");
627 }
628
629 void MyListCtrl::OnListKeyDown(wxListEvent& event)
630 {
631 if ( !wxGetApp().GetTopWindow() )
632 return;
633
634 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
635 if ( !text )
636 return;
637
638 text->WriteText("OnListKeyDown\n");
639 }
640
641