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