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