]> git.saurik.com Git - wxWidgets.git/blame - samples/listctrl/listtest.cpp
fixed process termination handling
[wxWidgets.git] / samples / listctrl / listtest.cpp
CommitLineData
457814b5
JS
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
5ea47806 9// Licence: wxWindows license
457814b5
JS
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
907789a0
RR
28#ifndef __WXMSW__
29#include "mondrian.xpm"
30#endif
31
457814b5
JS
32#include "wx/listctrl.h"
33#include "listtest.h"
34
35BEGIN_EVENT_TABLE(MyFrame, wxFrame)
5ea47806
VZ
36 EVT_MENU(BUSY_ON, MyFrame::BusyOn)
37 EVT_MENU(BUSY_OFF, MyFrame::BusyOff)
38 EVT_MENU(LIST_QUIT, MyFrame::OnQuit)
39 EVT_MENU(LIST_ABOUT, MyFrame::OnAbout)
40 EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView)
41 EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView)
42 EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView)
43 EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView)
44 EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
45 EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
46 EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
47 EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
48 EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
457814b5
JS
49END_EVENT_TABLE()
50
51BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
5ea47806
VZ
52 EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
53 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
54 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit)
55 EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit)
56 EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
57 EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo)
58 EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
59 EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected)
60 EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
61 EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
62 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
8636aed8 63 EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
457814b5
JS
64END_EVENT_TABLE()
65
66IMPLEMENT_APP(MyApp)
67
68// `Main program' equivalent, creating windows and returning main app frame
69bool MyApp::OnInit(void)
70{
71 // Create the main frame window
b00c5607 72 MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxListCtrl Test", 50, 50, 450, 340);
457814b5
JS
73
74 // This reduces flicker effects - even better would be to define OnEraseBackground
75 // to do nothing. When the list control's scrollbars are show or hidden, the
76 // frame is sent a background erase event.
907789a0 77 frame->SetBackgroundColour( *wxWHITE );
457814b5
JS
78
79 // Give it an icon
907789a0 80 frame->SetIcon( wxICON(mondrian) );
457814b5
JS
81
82 // Make an image list containing large icons
83 m_imageListNormal = new wxImageList(32, 32, TRUE);
84 m_imageListSmall = new wxImageList(16, 16, TRUE);
85
b0d77f43
RR
86#ifdef __WXMSW__
87 m_imageListNormal->Add( wxIcon("icon1", wxBITMAP_TYPE_ICO_RESOURCE) );
88 m_imageListNormal->Add( wxIcon("icon2", wxBITMAP_TYPE_ICO_RESOURCE) );
89 m_imageListNormal->Add( wxIcon("icon3", wxBITMAP_TYPE_ICO_RESOURCE) );
90 m_imageListNormal->Add( wxIcon("icon4", wxBITMAP_TYPE_ICO_RESOURCE) );
91 m_imageListNormal->Add( wxIcon("icon5", wxBITMAP_TYPE_ICO_RESOURCE) );
92 m_imageListNormal->Add( wxIcon("icon6", wxBITMAP_TYPE_ICO_RESOURCE) );
93 m_imageListNormal->Add( wxIcon("icon7", wxBITMAP_TYPE_ICO_RESOURCE) );
94 m_imageListNormal->Add( wxIcon("icon8", wxBITMAP_TYPE_ICO_RESOURCE) );
95 m_imageListNormal->Add( wxIcon("icon9", wxBITMAP_TYPE_ICO_RESOURCE) );
5ea47806 96
b0d77f43 97 m_imageListSmall->Add( wxIcon("iconsmall", wxBITMAP_TYPE_ICO_RESOURCE) );
5ea47806 98
b0d77f43
RR
99#else
100
101 #include "bitmaps/toolbrai.xpm"
102 m_imageListNormal->Add( wxIcon( toolbrai_xpm ) );
103 #include "bitmaps/toolchar.xpm"
104 m_imageListNormal->Add( wxIcon( toolchar_xpm ) );
105 #include "bitmaps/tooldata.xpm"
106 m_imageListNormal->Add( wxIcon( tooldata_xpm ) );
107 #include "bitmaps/toolnote.xpm"
108 m_imageListNormal->Add( wxIcon( toolnote_xpm ) );
109 #include "bitmaps/tooltodo.xpm"
110 m_imageListNormal->Add( wxIcon( tooltodo_xpm ) );
111 #include "bitmaps/toolchec.xpm"
112 m_imageListNormal->Add( wxIcon( toolchec_xpm ) );
113 #include "bitmaps/toolgame.xpm"
114 m_imageListNormal->Add( wxIcon( toolgame_xpm ) );
115 #include "bitmaps/tooltime.xpm"
116 m_imageListNormal->Add( wxIcon( tooltime_xpm ) );
117 #include "bitmaps/toolword.xpm"
118 m_imageListNormal->Add( wxIcon( toolword_xpm ) );
5ea47806 119
b0d77f43
RR
120 #include "bitmaps/small1.xpm"
121 m_imageListSmall->Add( wxIcon( small1_xpm) );
5ea47806 122
b0d77f43 123#endif
457814b5
JS
124
125 // Make a menubar
126 wxMenu *file_menu = new wxMenu;
127
5ea47806
VZ
128 file_menu->Append(LIST_LIST_VIEW, "&List view");
129 file_menu->Append(LIST_REPORT_VIEW, "&Report view");
130 file_menu->Append(LIST_ICON_VIEW, "&Icon view");
131 file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text");
132 file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view");
133 file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text");
c4771147
KB
134 file_menu->Append(LIST_DESELECT_ALL, "&Deselect All");
135 file_menu->Append(LIST_SELECT_ALL, "S&elect All");
5ea47806
VZ
136 file_menu->AppendSeparator();
137 file_menu->Append(LIST_DELETE_ALL, "Delete &all items");
138 file_menu->AppendSeparator();
139 file_menu->Append(BUSY_ON, "&Busy cursor on");
140 file_menu->Append(BUSY_OFF, "&Busy cursor off");
457814b5
JS
141 file_menu->AppendSeparator();
142 file_menu->Append(LIST_ABOUT, "&About");
143 file_menu->Append(LIST_QUIT, "E&xit");
144 wxMenuBar *menu_bar = new wxMenuBar;
145 menu_bar->Append(file_menu, "&File");
146 frame->SetMenuBar(menu_bar);
147
148 // Make a panel with a message
149 frame->m_listCtrl = new MyListCtrl(frame, LIST_CTRL, wxPoint(0, 0), wxSize(400, 200),
8636aed8 150 wxLC_LIST|wxSUNKEN_BORDER|wxLC_EDIT_LABELS );
5ea47806 151// wxLC_LIST|wxLC_USER_TEXT|wxSUNKEN_BORDER); // wxLC_USER_TEXT requires app to supply all text on demand
457814b5
JS
152 frame->m_logWindow = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxSize(400, 200), wxTE_MULTILINE|wxSUNKEN_BORDER);
153
154 wxLayoutConstraints *c = new wxLayoutConstraints;
5ea47806
VZ
155 c->top.SameAs (frame, wxTop);
156 c->left.SameAs (frame, wxLeft);
157 c->right.SameAs (frame, wxRight);
158 c->height.PercentOf (frame, wxHeight, 66);
457814b5
JS
159 frame->m_listCtrl->SetConstraints(c);
160
161 c = new wxLayoutConstraints;
5ea47806
VZ
162 c->top.Below (frame->m_listCtrl);
163 c->left.SameAs (frame, wxLeft);
164 c->right.SameAs (frame, wxRight);
165 c->bottom.SameAs (frame, wxBottom);
457814b5
JS
166 frame->m_logWindow->SetConstraints(c);
167 frame->SetAutoLayout(TRUE);
168
169 for ( int i=0; i < 30; i++)
5ea47806
VZ
170 {
171 wxChar buf[20];
172 wxSprintf(buf, _T("Item %d"), i);
173 frame->m_listCtrl->InsertItem(i, buf);
174 }
457814b5
JS
175
176 frame->CreateStatusBar(3);
177 frame->SetStatusText("", 0);
178
179 // Show the frame
180 frame->Show(TRUE);
5ea47806 181
457814b5
JS
182 SetTopWindow(frame);
183
184 return TRUE;
185}
186
187// My frame constructor
188MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
189 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
190{
5ea47806
VZ
191 m_listCtrl = (MyListCtrl *) NULL;
192 m_logWindow = (wxTextCtrl *) NULL;
457814b5
JS
193}
194
195MyFrame::~MyFrame(void)
196{
5ea47806
VZ
197 delete wxGetApp().m_imageListNormal;
198 delete wxGetApp().m_imageListSmall;
457814b5
JS
199}
200
b0d77f43 201void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
457814b5
JS
202{
203 Close(TRUE);
204}
205
57246713
KB
206void MyFrame::BusyOn(wxCommandEvent& WXUNUSED(event))
207{
208 wxBeginBusyCursor();
209}
210
211void MyFrame::BusyOff(wxCommandEvent& WXUNUSED(event))
212{
213 wxEndBusyCursor();
214}
215
b0d77f43 216void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
457814b5 217{
5ea47806
VZ
218 wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997",
219 "About list test", wxOK|wxCANCEL);
457814b5 220
5ea47806 221 dialog.ShowModal();
457814b5
JS
222}
223
c4771147
KB
224void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))
225{
5ea47806
VZ
226 int n = m_listCtrl->GetItemCount();
227 for (int i = 0; i < n; i++)
228 m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED);
c4771147
KB
229}
230
231void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
232{
5ea47806
VZ
233 int n = m_listCtrl->GetItemCount();
234 for (int i = 0; i < n; i++)
235 m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
c4771147
KB
236}
237
b0d77f43 238void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event))
457814b5 239{
0180dad6
RR
240 m_listCtrl->DeleteAllItems();
241 m_logWindow->Clear();
242 m_listCtrl->SetSingleStyle(wxLC_LIST);
c67daf87
UR
243 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
244 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_SMALL);
457814b5 245
0180dad6
RR
246 for ( int i=0; i < 30; i++)
247 {
5ea47806
VZ
248 wxChar buf[20];
249 wxSprintf(buf, _T("Item %d"), i);
250 m_listCtrl->InsertItem(i, buf);
0180dad6 251 }
457814b5
JS
252}
253
b0d77f43 254void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
457814b5 255{
0180dad6 256 m_listCtrl->DeleteAllItems();
c50f1fb9 257 m_listCtrl->DeleteAllColumns();
0180dad6 258 m_logWindow->Clear();
5ea47806 259
0180dad6 260 m_listCtrl->SetSingleStyle(wxLC_REPORT);
c67daf87 261 m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
457814b5
JS
262 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
263
0180dad6
RR
264 m_listCtrl->InsertColumn(0, "Column 1"); // , wxLIST_FORMAT_LEFT, 140);
265 m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
266 m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
267
5ea47806 268 for ( int i = 0; i < 3000; i++ )
0180dad6 269 {
5ea47806
VZ
270 wxChar buf[50];
271 wxSprintf(buf, _T("This is item %d"), i);
272 long tmp = m_listCtrl->InsertItem(i, buf, 0);
273
274 wxSprintf(buf, _T("Col 1, item %d"), i);
275 tmp = m_listCtrl->SetItem(i, 1, buf);
276
277 wxSprintf(buf, _T("Item %d in column 2"), i);
278 tmp = m_listCtrl->SetItem(i, 2, buf);
0180dad6 279 }
5ea47806 280
0180dad6
RR
281 m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
282 m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
283 m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE );
457814b5
JS
284}
285
b0d77f43 286void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event))
457814b5 287{
5ea47806
VZ
288 m_listCtrl->DeleteAllItems();
289 m_logWindow->Clear();
290 m_listCtrl->SetSingleStyle(wxLC_ICON);
457814b5
JS
291 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
292 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
293
5ea47806
VZ
294 for ( int i=0; i < 9; i++)
295 {
296 m_listCtrl->InsertItem(i, i);
297 }
457814b5
JS
298}
299
b0d77f43 300void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event))
457814b5 301{
5ea47806
VZ
302 m_listCtrl->DeleteAllItems();
303 m_logWindow->Clear();
304 m_listCtrl->SetSingleStyle(wxLC_ICON);
457814b5
JS
305 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
306 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
307
5ea47806
VZ
308 for ( int i=0; i < 9; i++)
309 {
310 wxChar buf[20];
311 wxSprintf(buf, _T("Label %d"), i);
312 m_listCtrl->InsertItem(i, buf, i);
313 }
457814b5
JS
314}
315
b0d77f43 316void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
457814b5 317{
5ea47806
VZ
318 m_listCtrl->DeleteAllItems();
319 m_logWindow->Clear();
320 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
457814b5
JS
321 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
322 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
323
5ea47806
VZ
324 for ( int i=0; i < 9; i++)
325 {
326 m_listCtrl->InsertItem(i, 0);
327 }
457814b5
JS
328}
329
b0d77f43 330void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
457814b5 331{
5ea47806
VZ
332 m_listCtrl->DeleteAllItems();
333 m_logWindow->Clear();
334 m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON);
457814b5
JS
335 m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL);
336 m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL);
337
5ea47806
VZ
338 for ( int i=0; i < 9; i++)
339 {
340 m_listCtrl->InsertItem(i, "Label", 0);
341 }
342}
343
344void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
345{
346 (void)wxGetElapsedTime(TRUE);
347
348 int nItems = m_listCtrl->GetItemCount();
349 m_listCtrl->DeleteAllItems();
350
351 wxLogMessage("Deleting %d items took %ld ms",
352 nItems, wxGetElapsedTime());
457814b5
JS
353}
354
355// MyListCtrl
356
8636aed8
RR
357void MyListCtrl::OnColClick(wxListEvent& event)
358{
359 if ( !wxGetApp().GetTopWindow() )
360 return;
361
362 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
363 if ( !text )
364 return;
365
366 wxString msg;
367 msg.Printf( "OnColumnClick at %d.\n", event.GetColumn() );
368 text->WriteText(msg);
369}
370
fd9811b1 371void MyListCtrl::OnBeginDrag(wxListEvent& event)
457814b5 372{
5ea47806
VZ
373 if ( !wxGetApp().GetTopWindow() )
374 return;
457814b5 375
5ea47806
VZ
376 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
377 if ( !text )
378 return;
457814b5 379
fd9811b1
RR
380 wxString msg;
381 msg.Printf( "OnBeginDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y );
382 text->WriteText(msg);
457814b5
JS
383}
384
fd9811b1 385void MyListCtrl::OnBeginRDrag(wxListEvent& event)
457814b5 386{
5ea47806
VZ
387 if ( !wxGetApp().GetTopWindow() )
388 return;
457814b5 389
5ea47806
VZ
390 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
391 if ( !text )
392 return;
fd9811b1
RR
393
394 wxString msg;
395 msg.Printf( "OnBeginRDrag at %d,%d.\n", event.m_pointDrag.x, event.m_pointDrag.y );
396 text->WriteText(msg);
457814b5
JS
397}
398
fd9811b1 399void MyListCtrl::OnBeginLabelEdit(wxListEvent& event)
457814b5 400{
5ea47806
VZ
401 if ( !wxGetApp().GetTopWindow() )
402 return;
457814b5 403
5ea47806
VZ
404 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
405 if ( !text )
406 return;
457814b5 407
fd9811b1
RR
408 text->WriteText("OnBeginLabelEdit: ");
409 text->WriteText(event.m_item.m_text);
410 text->WriteText("\n");
457814b5
JS
411}
412
fd9811b1 413void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
457814b5 414{
5ea47806
VZ
415 if ( !wxGetApp().GetTopWindow() )
416 return;
457814b5 417
5ea47806
VZ
418 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
419 if ( !text )
420 return;
457814b5 421
fd9811b1
RR
422 text->WriteText("OnEndLabelEdit: ");
423 text->WriteText(event.m_item.m_text);
8636aed8 424 text->WriteText("\n");
457814b5
JS
425}
426
cb43b372 427void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(event))
457814b5 428{
5ea47806
VZ
429 if ( !wxGetApp().GetTopWindow() )
430 return;
457814b5 431
5ea47806
VZ
432 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
433 if ( !text )
434 return;
457814b5 435
a367b9b3 436 text->WriteText("OnDeleteItem\n");
457814b5
JS
437}
438
fd9811b1 439void MyListCtrl::OnGetInfo(wxListEvent& event)
457814b5 440{
5ea47806
VZ
441 if ( !wxGetApp().GetTopWindow() )
442 return;
457814b5 443
5ea47806
VZ
444 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
445 if ( !text )
446 return;
457814b5 447
fd9811b1 448 text->WriteText("OnGetInfo\n");
5ea47806 449
fd9811b1 450 (*text) << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")";
5ea47806 451 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
fd9811b1 452 (*text) << " wxLIST_MASK_STATE";
5ea47806 453 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
fd9811b1 454 (*text) << " wxLIST_MASK_TEXT";
5ea47806 455 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
fd9811b1 456 (*text) << " wxLIST_MASK_IMAGE";
5ea47806 457 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
fd9811b1 458 (*text) << " wxLIST_MASK_DATA";
5ea47806 459 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
fd9811b1 460 (*text) << " wxLIST_SET_ITEM";
5ea47806 461 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
fd9811b1 462 (*text) << " wxLIST_MASK_WIDTH";
5ea47806 463 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
fd9811b1 464 (*text) << " wxLIST_MASK_WIDTH";
5ea47806
VZ
465
466 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
467 {
468 event.m_item.m_text = "My callback text";
469 }
fd9811b1 470 (*text) << "\n";
457814b5
JS
471}
472
cb43b372 473void MyListCtrl::OnSetInfo(wxListEvent& WXUNUSED(event))
457814b5 474{
5ea47806
VZ
475 if ( !wxGetApp().GetTopWindow() )
476 return;
457814b5 477
5ea47806
VZ
478 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
479 if ( !text )
480 return;
457814b5 481
5ea47806 482 text->WriteText("OnSetInfo\n");
457814b5
JS
483}
484
74b31181 485void MyListCtrl::OnSelected(wxListEvent& event)
457814b5 486{
5ea47806
VZ
487 if ( !wxGetApp().GetTopWindow() )
488 return;
457814b5 489
5ea47806
VZ
490 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
491 if ( !text )
492 return;
457814b5 493
40779a03 494 if ( GetWindowStyle() & wxLC_REPORT )
74b31181 495 {
40779a03
VZ
496 wxListItem info;
497 info.m_itemId = event.m_itemIndex;
498 info.m_col = 1;
499 info.m_mask = wxLIST_MASK_TEXT;
500 if ( GetItem(info) )
501 {
502 *text << "Value of the 2nd field of the selected item: "
503 << info.m_text << '\n';
504 }
505 else
506 {
507 wxFAIL_MSG("wxListCtrl::GetItem() failed");
508 }
74b31181
VZ
509 }
510
5ea47806 511 text->WriteText("OnSelected\n");
457814b5
JS
512}
513
cb43b372 514void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event))
457814b5 515{
5ea47806
VZ
516 if ( !wxGetApp().GetTopWindow() )
517 return;
457814b5 518
5ea47806
VZ
519 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
520 if ( !text )
521 return;
457814b5 522
5ea47806 523 text->WriteText("OnDeselected\n");
457814b5
JS
524}
525
435fe83e
RR
526void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(event))
527{
5ea47806
VZ
528 if ( !wxGetApp().GetTopWindow() )
529 return;
435fe83e 530
5ea47806
VZ
531 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
532 if ( !text )
533 return;
435fe83e 534
5ea47806 535 text->WriteText("OnActivated\n");
435fe83e
RR
536}
537
8e1d4f96 538void MyListCtrl::OnListKeyDown(wxListEvent& event)
457814b5 539{
5ea47806
VZ
540 if ( !wxGetApp().GetTopWindow() )
541 return;
457814b5 542
5ea47806
VZ
543 wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
544 if ( !text )
545 return;
457814b5 546
5ea47806 547 text->WriteText("OnListKeyDown\n");
457814b5
JS
548}
549
435fe83e 550