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