]> git.saurik.com Git - wxWidgets.git/blame - samples/listctrl/listtest.cpp
Don't prematurely return from Create before appending the choices, and etc.
[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$
6aa89a22 8// Copyright: (c) Julian Smart
5ea47806 9// Licence: wxWindows license
457814b5
JS
10/////////////////////////////////////////////////////////////////////////////
11
457814b5
JS
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
5f4d35b8 23#if !defined(__WXMSW__) && !defined(__WXPM__)
c41ea66a 24 #include "mondrian.xpm"
5f4d35b8 25#endif
c41ea66a 26
5f4d35b8 27#ifndef __WXMSW__
c41ea66a
VZ
28 #include "bitmaps/toolbrai.xpm"
29 #include "bitmaps/toolchar.xpm"
30 #include "bitmaps/tooldata.xpm"
31 #include "bitmaps/toolnote.xpm"
32 #include "bitmaps/tooltodo.xpm"
33 #include "bitmaps/toolchec.xpm"
34 #include "bitmaps/toolgame.xpm"
35 #include "bitmaps/tooltime.xpm"
36 #include "bitmaps/toolword.xpm"
37 #include "bitmaps/small1.xpm"
907789a0
RR
38#endif
39
2e8a1588 40#include "wx/imaglist.h"
457814b5 41#include "wx/listctrl.h"
81278df2 42#include "wx/timer.h" // for wxStopWatch
11f26ea0 43#include "wx/colordlg.h" // for wxGetColourFromUser
107ff668 44#include "wx/settings.h"
2458daa7 45#include "wx/sysopt.h"
11f26ea0 46
457814b5
JS
47#include "listtest.h"
48
b0401bea
VZ
49const wxChar *SMALL_VIRTUAL_VIEW_ITEMS[][2] =
50{
51 { _T("Cat"), _T("meow") },
52 { _T("Cow"), _T("moo") },
53 { _T("Crow"), _T("caw") },
54 { _T("Dog"), _T("woof") },
55 { _T("Duck"), _T("quack") },
56 { _T("Mouse"), _T("squeak") },
57 { _T("Owl"), _T("hoo") },
58 { _T("Pig"), _T("oink") },
59 { _T("Pigeon"), _T("coo") },
60 { _T("Sheep"), _T("baaah") },
61};
62
63
457814b5 64BEGIN_EVENT_TABLE(MyFrame, wxFrame)
98ec9dbe
VZ
65 EVT_SIZE(MyFrame::OnSize)
66
5ea47806
VZ
67 EVT_MENU(LIST_QUIT, MyFrame::OnQuit)
68 EVT_MENU(LIST_ABOUT, MyFrame::OnAbout)
69 EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView)
70 EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView)
71 EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView)
72 EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView)
73 EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
74 EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
98ec9dbe 75 EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
b0401bea 76 EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView)
98ec9dbe 77
88b792af 78 EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast)
58b3bdc9 79 EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
5ea47806
VZ
80 EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
81 EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
bec0a261 82 EVT_MENU(LIST_DELETE, MyFrame::OnDelete)
cf1dfa6b 83 EVT_MENU(LIST_ADD, MyFrame::OnAdd)
efe23391 84 EVT_MENU(LIST_EDIT, MyFrame::OnEdit)
5ea47806 85 EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
fa5f6926 86 EVT_MENU(LIST_SORT, MyFrame::OnSort)
11f26ea0
VZ
87 EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
88 EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
7b848b0d 89 EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
f6bcfd97 90 EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
b54e41c5 91 EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
c5c528fc
VZ
92 EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze)
93 EVT_MENU(LIST_THAW, MyFrame::OnThaw)
494ab5de 94 EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines)
2458daa7 95 EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric)
98ec9dbe 96
f6bcfd97 97 EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo)
5f4d35b8 98 EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel)
457814b5
JS
99END_EVENT_TABLE()
100
101BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
5ea47806
VZ
102 EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
103 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
104 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit)
105 EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit)
106 EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
12c1b46a 107 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems)
5ea47806
VZ
108 EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected)
109 EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
110 EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
111 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
0ddefeb0 112 EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
11358d39 113
8636aed8 114 EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
11358d39
VZ
115 EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick)
116 EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag)
117 EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging)
118 EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag)
119
614391dc 120 EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
f6bcfd97 121
107ff668
JS
122#if USE_CONTEXT_MENU
123 EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu)
124#endif
f6bcfd97 125 EVT_CHAR(MyListCtrl::OnChar)
164a7972
VZ
126
127 EVT_RIGHT_DOWN(MyListCtrl::OnRightClick)
457814b5
JS
128END_EVENT_TABLE()
129
130IMPLEMENT_APP(MyApp)
131
776a33cf 132// number of items in list/report view
e1641772 133static const int NUM_ITEMS = 10;
776a33cf
VZ
134
135// number of items in icon/small icon view
136static const int NUM_ICONS = 9;
137
c71963cd 138int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
fa5f6926
VZ
139{
140 // inverse the order
c71963cd
VZ
141 if (item1 < item2)
142 return -1;
143 if (item1 > item2)
144 return 1;
145
2b5f62a0 146 return 0;
fa5f6926
VZ
147}
148
457814b5 149// `Main program' equivalent, creating windows and returning main app frame
11f26ea0 150bool MyApp::OnInit()
457814b5 151{
45e6e6f8
VZ
152 if ( !wxApp::OnInit() )
153 return false;
154
457814b5 155 // Create the main frame window
107ff668 156 MyFrame *frame = new MyFrame(wxT("wxListCtrl Test"));
457814b5
JS
157
158 // Show the frame
1550e402 159 frame->Show(true);
5ea47806 160
457814b5
JS
161 SetTopWindow(frame);
162
1550e402 163 return true;
457814b5
JS
164}
165
166// My frame constructor
107ff668 167MyFrame::MyFrame(const wxChar *title)
e1641772 168 : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600, 500))
457814b5 169{
b0401bea
VZ
170 m_listCtrl = NULL;
171 m_logWindow = NULL;
172 m_smallVirtual = false;
c41ea66a
VZ
173
174 // Give it an icon
175 SetIcon( wxICON(mondrian) );
176
177 // Make an image list containing large icons
1550e402
WS
178 m_imageListNormal = new wxImageList(32, 32, true);
179 m_imageListSmall = new wxImageList(16, 16, true);
c41ea66a
VZ
180
181#ifdef __WXMSW__
42ed7532
MB
182 m_imageListNormal->Add( wxIcon(_T("icon1"), wxBITMAP_TYPE_ICO_RESOURCE) );
183 m_imageListNormal->Add( wxIcon(_T("icon2"), wxBITMAP_TYPE_ICO_RESOURCE) );
184 m_imageListNormal->Add( wxIcon(_T("icon3"), wxBITMAP_TYPE_ICO_RESOURCE) );
185 m_imageListNormal->Add( wxIcon(_T("icon4"), wxBITMAP_TYPE_ICO_RESOURCE) );
186 m_imageListNormal->Add( wxIcon(_T("icon5"), wxBITMAP_TYPE_ICO_RESOURCE) );
187 m_imageListNormal->Add( wxIcon(_T("icon6"), wxBITMAP_TYPE_ICO_RESOURCE) );
188 m_imageListNormal->Add( wxIcon(_T("icon7"), wxBITMAP_TYPE_ICO_RESOURCE) );
189 m_imageListNormal->Add( wxIcon(_T("icon8"), wxBITMAP_TYPE_ICO_RESOURCE) );
190 m_imageListNormal->Add( wxIcon(_T("icon9"), wxBITMAP_TYPE_ICO_RESOURCE) );
191
192 m_imageListSmall->Add( wxIcon(_T("iconsmall"), wxBITMAP_TYPE_ICO_RESOURCE) );
c41ea66a
VZ
193
194#else
195 m_imageListNormal->Add( wxIcon( toolbrai_xpm ) );
196 m_imageListNormal->Add( wxIcon( toolchar_xpm ) );
197 m_imageListNormal->Add( wxIcon( tooldata_xpm ) );
198 m_imageListNormal->Add( wxIcon( toolnote_xpm ) );
199 m_imageListNormal->Add( wxIcon( tooltodo_xpm ) );
200 m_imageListNormal->Add( wxIcon( toolchec_xpm ) );
201 m_imageListNormal->Add( wxIcon( toolgame_xpm ) );
202 m_imageListNormal->Add( wxIcon( tooltime_xpm ) );
203 m_imageListNormal->Add( wxIcon( toolword_xpm ) );
204
205 m_imageListSmall->Add( wxIcon( small1_xpm) );
206#endif
207
208 // Make a menubar
209 wxMenu *menuFile = new wxMenu;
98ec9dbe 210 menuFile->Append(LIST_ABOUT, _T("&About"));
c41ea66a 211 menuFile->AppendSeparator();
98ec9dbe 212 menuFile->Append(LIST_QUIT, _T("E&xit\tAlt-X"));
c41ea66a
VZ
213
214 wxMenu *menuView = new wxMenu;
98ec9dbe
VZ
215 menuView->Append(LIST_LIST_VIEW, _T("&List view\tF1"));
216 menuView->Append(LIST_REPORT_VIEW, _T("&Report view\tF2"));
217 menuView->Append(LIST_ICON_VIEW, _T("&Icon view\tF3"));
218 menuView->Append(LIST_ICON_TEXT_VIEW, _T("Icon view with &text\tF4"));
219 menuView->Append(LIST_SMALL_ICON_VIEW, _T("&Small icon view\tF5"));
220 menuView->Append(LIST_SMALL_ICON_TEXT_VIEW, _T("Small icon &view with text\tF6"));
b0401bea
VZ
221 menuView->Append(LIST_VIRTUAL_VIEW, _T("&Virtual view\tF7"));
222 menuView->Append(LIST_SMALL_VIRTUAL_VIEW, _T("Small virtual vie&w\tF8"));
2458daa7
KO
223#ifdef __WXMAC__
224 menuView->AppendCheckItem(LIST_MAC_USE_GENERIC, _T("Mac: Use Generic Control"));
225#endif
c41ea66a
VZ
226
227 wxMenu *menuList = new wxMenu;
88b792af 228 menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L"));
c5c528fc 229 menuList->Append(LIST_TOGGLE_FIRST, _T("To&ggle first item\tCtrl-G"));
98ec9dbe
VZ
230 menuList->Append(LIST_DESELECT_ALL, _T("&Deselect All\tCtrl-D"));
231 menuList->Append(LIST_SELECT_ALL, _T("S&elect All\tCtrl-A"));
b54e41c5 232 menuList->AppendSeparator();
98ec9dbe 233 menuList->Append(LIST_SHOW_COL_INFO, _T("Show &column info\tCtrl-C"));
b54e41c5 234 menuList->Append(LIST_SHOW_SEL_INFO, _T("Show &selected items\tCtrl-S"));
c41ea66a 235 menuList->AppendSeparator();
98ec9dbe 236 menuList->Append(LIST_SORT, _T("&Sort\tCtrl-S"));
c41ea66a 237 menuList->AppendSeparator();
cf1dfa6b 238 menuList->Append(LIST_ADD, _T("&Append an item\tCtrl-P"));
efe23391 239 menuList->Append(LIST_EDIT, _T("&Edit the item\tCtrl-E"));
cf1dfa6b 240 menuList->Append(LIST_DELETE, _T("&Delete first item\tCtrl-X"));
98ec9dbe 241 menuList->Append(LIST_DELETE_ALL, _T("Delete &all items"));
c41ea66a 242 menuList->AppendSeparator();
c5c528fc
VZ
243 menuList->Append(LIST_FREEZE, _T("Free&ze\tCtrl-Z"));
244 menuList->Append(LIST_THAW, _T("Tha&w\tCtrl-W"));
245 menuList->AppendSeparator();
494ab5de 246 menuList->AppendCheckItem(LIST_TOGGLE_LINES, _T("Toggle &lines\tCtrl-I"));
98ec9dbe 247 menuList->Append(LIST_TOGGLE_MULTI_SEL, _T("&Multiple selection\tCtrl-M"),
1550e402 248 _T("Toggle multiple selection"), true);
c41ea66a
VZ
249
250 wxMenu *menuCol = new wxMenu;
98ec9dbe
VZ
251 menuCol->Append(LIST_SET_FG_COL, _T("&Foreground colour..."));
252 menuCol->Append(LIST_SET_BG_COL, _T("&Background colour..."));
c41ea66a
VZ
253
254 wxMenuBar *menubar = new wxMenuBar;
98ec9dbe
VZ
255 menubar->Append(menuFile, _T("&File"));
256 menubar->Append(menuView, _T("&View"));
257 menubar->Append(menuList, _T("&List"));
258 menubar->Append(menuCol, _T("&Colour"));
c41ea66a
VZ
259 SetMenuBar(menubar);
260
1550e402
WS
261 m_panel = new wxPanel(this, wxID_ANY);
262 m_logWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString,
c41ea66a 263 wxDefaultPosition, wxDefaultSize,
e1641772 264 wxTE_READONLY | wxTE_MULTILINE | wxSUNKEN_BORDER);
c41ea66a
VZ
265
266 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow));
267
776a33cf 268 RecreateList(wxLC_REPORT | wxLC_SINGLE_SEL);
c41ea66a 269
8520f137 270#if wxUSE_STATUSBAR
e1641772 271 CreateStatusBar();
8520f137 272#endif // wxUSE_STATUSBAR
457814b5
JS
273}
274
11f26ea0 275MyFrame::~MyFrame()
457814b5 276{
c41ea66a
VZ
277 delete wxLog::SetActiveTarget(m_logOld);
278
279 delete m_imageListNormal;
280 delete m_imageListSmall;
457814b5
JS
281}
282
98ec9dbe 283void MyFrame::OnSize(wxSizeEvent& event)
07bf769e
VZ
284{
285 DoSize();
286
287 event.Skip();
288}
289
290void MyFrame::DoSize()
457814b5 291{
98ec9dbe
VZ
292 if ( !m_logWindow )
293 return;
457814b5 294
98ec9dbe
VZ
295 wxSize size = GetClientSize();
296 wxCoord y = (2*size.y)/3;
297 m_listCtrl->SetSize(0, 0, size.x, y);
298 m_logWindow->SetSize(0, y + 1, size.x, size.y - y);
57246713
KB
299}
300
68457180
VZ
301bool MyFrame::CheckNonVirtual() const
302{
303 if ( !m_listCtrl->HasFlag(wxLC_VIRTUAL) )
304 return true;
305
306 // "this" == whatever
307 wxLogWarning(_T("Can't do this in virtual view, sorry."));
308
309 return false;
310}
311
98ec9dbe 312void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
57246713 313{
1550e402 314 Close(true);
57246713
KB
315}
316
b0d77f43 317void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
457814b5 318{
efe23391
VZ
319 wxMessageDialog dialog(this, _T("List test sample\nJulian Smart (c) 1997"),
320 _T("About list test"), wxOK|wxCANCEL);
457814b5 321
5ea47806 322 dialog.ShowModal();
457814b5
JS
323}
324
c71963cd 325void MyFrame::OnFreeze(wxCommandEvent& WXUNUSED(event))
c5c528fc
VZ
326{
327 wxLogMessage(_T("Freezing the control"));
328
329 m_listCtrl->Freeze();
330}
331
c71963cd 332void MyFrame::OnThaw(wxCommandEvent& WXUNUSED(event))
c5c528fc
VZ
333{
334 wxLogMessage(_T("Thawing the control"));
335
336 m_listCtrl->Thaw();
337}
338
494ab5de
VZ
339void MyFrame::OnToggleLines(wxCommandEvent& event)
340{
341 m_listCtrl->SetSingleStyle(wxLC_HRULES | wxLC_VRULES, event.IsChecked());
342}
343
2458daa7
KO
344void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event)
345{
346 wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), event.IsChecked());
347}
348
88b792af
VZ
349void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event))
350{
351 long index = m_listCtrl->GetItemCount() - 1;
352 if ( index == -1 )
353 {
354 return;
355 }
356
357 m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
358 m_listCtrl->EnsureVisible(index);
359}
360
58b3bdc9
VZ
361void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event))
362{
95f913a9 363 m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
58b3bdc9
VZ
364}
365
c4771147
KB
366void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))
367{
68457180
VZ
368 if ( !CheckNonVirtual() )
369 return;
370
5ea47806
VZ
371 int n = m_listCtrl->GetItemCount();
372 for (int i = 0; i < n; i++)
373 m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED);
c4771147
KB
374}
375
376void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
377{
68457180
VZ
378 if ( !CheckNonVirtual() )
379 return;
380
5ea47806
VZ
381 int n = m_listCtrl->GetItemCount();
382 for (int i = 0; i < n; i++)
383 m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
c4771147
KB
384}
385
776a33cf
VZ
386// ----------------------------------------------------------------------------
387// changing listctrl modes
388// ----------------------------------------------------------------------------
389
390void MyFrame::RecreateList(long flags, bool withText)
457814b5 391{
776a33cf
VZ
392 // we could avoid recreating it if we don't set/clear the wxLC_VIRTUAL
393 // style, but it is more trouble to do it than not
394#if 0
395 if ( !m_listCtrl || ((flags & wxLC_VIRTUAL) !=
396 (m_listCtrl->GetWindowStyleFlag() & wxLC_VIRTUAL)) )
397#endif
398 {
399 delete m_listCtrl;
400
2b5f62a0 401 m_listCtrl = new MyListCtrl(m_panel, LIST_CTRL,
776a33cf
VZ
402 wxDefaultPosition, wxDefaultSize,
403 flags |
efe23391 404 wxSUNKEN_BORDER | wxLC_EDIT_LABELS);
776a33cf
VZ
405
406 switch ( flags & wxLC_MASK_TYPE )
407 {
408 case wxLC_LIST:
409 InitWithListItems();
410 break;
411
412 case wxLC_ICON:
413 InitWithIconItems(withText);
414 break;
415
416 case wxLC_SMALL_ICON:
1550e402 417 InitWithIconItems(withText, true);
776a33cf
VZ
418 break;
419
420 case wxLC_REPORT:
421 if ( flags & wxLC_VIRTUAL )
422 InitWithVirtualItems();
423 else
424 InitWithReportItems();
425 break;
426
427 default:
428 wxFAIL_MSG( _T("unknown listctrl mode") );
429 }
430 }
431
07bf769e 432 DoSize();
776a33cf 433
0180dad6 434 m_logWindow->Clear();
776a33cf 435}
95bf655c 436
776a33cf
VZ
437void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event))
438{
439 RecreateList(wxLC_LIST);
440}
457814b5 441
776a33cf
VZ
442void MyFrame::InitWithListItems()
443{
444 for ( int i = 0; i < NUM_ITEMS; i++ )
0180dad6 445 {
98ec9dbe 446 m_listCtrl->InsertItem(i, wxString::Format(_T("Item %d"), i));
0180dad6 447 }
457814b5
JS
448}
449
b0d77f43 450void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
457814b5 451{
776a33cf
VZ
452 RecreateList(wxLC_REPORT);
453}
5ea47806 454
776a33cf
VZ
455void MyFrame::InitWithReportItems()
456{
c41ea66a 457 m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
457814b5 458
caa20b1e
VZ
459 // note that under MSW for SetColumnWidth() to work we need to create the
460 // items with images initially even if we specify dummy image id
6f806543 461 wxListItem itemCol;
caa20b1e
VZ
462 itemCol.SetText(_T("Column 1"));
463 itemCol.SetImage(-1);
6f806543 464 m_listCtrl->InsertColumn(0, itemCol);
caa20b1e
VZ
465
466 itemCol.SetText(_T("Column 2"));
467 itemCol.SetAlign(wxLIST_FORMAT_CENTRE);
6f806543 468 m_listCtrl->InsertColumn(1, itemCol);
caa20b1e
VZ
469
470 itemCol.SetText(_T("Column 3"));
471 itemCol.SetAlign(wxLIST_FORMAT_RIGHT);
6f806543 472 m_listCtrl->InsertColumn(2, itemCol);
0180dad6 473
81278df2
VZ
474 // to speed up inserting we hide the control temporarily
475 m_listCtrl->Hide();
476
477 wxStopWatch sw;
478
81278df2 479 for ( int i = 0; i < NUM_ITEMS; i++ )
0180dad6 480 {
5cd89174 481 m_listCtrl->InsertItemInReportView(i);
0180dad6 482 }
bdc72a22 483
81278df2
VZ
484 m_logWindow->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"),
485 NUM_ITEMS, sw.Time()));
486 m_listCtrl->Show();
487
f6b77239 488 // we leave all mask fields to 0 and only change the colour
bdc72a22
VZ
489 wxListItem item;
490 item.m_itemId = 0;
0530737d 491 item.SetTextColour(*wxRED);
bdc72a22
VZ
492 m_listCtrl->SetItem( item );
493
494 item.m_itemId = 2;
d62228a6 495 item.SetTextColour(*wxGREEN);
bdc72a22 496 m_listCtrl->SetItem( item );
d62228a6 497 item.m_itemId = 4;
bdc72a22 498 item.SetTextColour(*wxLIGHT_GREY);
d62228a6
VZ
499 item.SetFont(*wxITALIC_FONT);
500 item.SetBackgroundColour(*wxRED);
bdc72a22 501 m_listCtrl->SetItem( item );
5ea47806 502
d62228a6 503 m_listCtrl->SetTextColour(*wxBLUE);
d62228a6 504
0180dad6
RR
505 m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
506 m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
507 m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE );
35c2acd4 508
06db67bc
RD
509 // Set images in columns
510 m_listCtrl->SetItemColumnImage(1, 1, 0);
511
512 wxListItem info;
513 info.SetImage(0);
514 info.SetId(3);
515 info.SetColumn(2);
516 m_listCtrl->SetItem(info);
517
35c2acd4
MW
518 // test SetItemFont too
519 m_listCtrl->SetItemFont(0, *wxITALIC_FONT);
457814b5
JS
520}
521
776a33cf 522void MyFrame::InitWithIconItems(bool withText, bool sameIcon)
457814b5 523{
c41ea66a
VZ
524 m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL);
525 m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
457814b5 526
152e8878 527 for ( int i = 0; i < NUM_ICONS; i++ )
5ea47806 528 {
152e8878 529 int image = sameIcon ? 0 : i;
776a33cf
VZ
530
531 if ( withText )
532 {
533 m_listCtrl->InsertItem(i, wxString::Format(_T("Label %d"), i),
534 image);
535 }
536 else
537 {
538 m_listCtrl->InsertItem(i, image);
539 }
5ea47806 540 }
457814b5
JS
541}
542
776a33cf 543void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event))
457814b5 544{
1550e402 545 RecreateList(wxLC_ICON, false);
776a33cf 546}
457814b5 547
776a33cf
VZ
548void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event))
549{
550 RecreateList(wxLC_ICON);
457814b5
JS
551}
552
b0d77f43 553void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
457814b5 554{
1550e402 555 RecreateList(wxLC_SMALL_ICON, false);
457814b5
JS
556}
557
b0d77f43 558void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
457814b5 559{
776a33cf 560 RecreateList(wxLC_SMALL_ICON);
5ea47806
VZ
561}
562
98ec9dbe
VZ
563void MyFrame::OnVirtualView(wxCommandEvent& WXUNUSED(event))
564{
b0401bea
VZ
565 m_smallVirtual = false;
566 RecreateList(wxLC_REPORT | wxLC_VIRTUAL);
567}
568
569void MyFrame::OnSmallVirtualView(wxCommandEvent& WXUNUSED(event))
570{
571 m_smallVirtual = true;
776a33cf
VZ
572 RecreateList(wxLC_REPORT | wxLC_VIRTUAL);
573}
98ec9dbe 574
776a33cf
VZ
575void MyFrame::InitWithVirtualItems()
576{
27770773
VZ
577 m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
578
b0401bea
VZ
579 if ( m_smallVirtual )
580 {
581 m_listCtrl->InsertColumn(0, _T("Animal"));
582 m_listCtrl->InsertColumn(1, _T("Sound"));
583 m_listCtrl->SetItemCount(WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS));
584 }
585 else
586 {
587 m_listCtrl->InsertColumn(0, _T("First Column"));
588 m_listCtrl->InsertColumn(1, _T("Second Column"));
589 m_listCtrl->SetColumnWidth(0, 150);
590 m_listCtrl->SetColumnWidth(1, 150);
591 m_listCtrl->SetItemCount(1000000);
592 }
98ec9dbe
VZ
593}
594
fa5f6926
VZ
595void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
596{
81278df2
VZ
597 wxStopWatch sw;
598
fa5f6926 599 m_listCtrl->SortItems(MyCompareFunction, 0);
81278df2
VZ
600
601 m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
602 m_listCtrl->GetItemCount(),
603 sw.Time()));
fa5f6926
VZ
604}
605
c71963cd 606void MyFrame::OnShowSelInfo(wxCommandEvent& WXUNUSED(event))
b54e41c5
VZ
607{
608 int selCount = m_listCtrl->GetSelectedItemCount();
609 wxLogMessage(_T("%d items selected:"), selCount);
610
611 // don't show too many items
612 size_t shownCount = 0;
613
614 long item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
615 wxLIST_STATE_SELECTED);
616 while ( item != -1 )
617 {
618 wxLogMessage(_T("\t%ld (%s)"),
619 item, m_listCtrl->GetItemText(item).c_str());
620
621 if ( ++shownCount > 10 )
622 {
623 wxLogMessage(_T("\t... more selected items snipped..."));
624 break;
625 }
626
627 item = m_listCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
628 wxLIST_STATE_SELECTED);
629 }
630}
631
c71963cd 632void MyFrame::OnShowColInfo(wxCommandEvent& WXUNUSED(event))
f6bcfd97
BP
633{
634 int count = m_listCtrl->GetColumnCount();
4acb6ca6 635 wxLogMessage(wxT("%d columns:"), count);
f6bcfd97
BP
636 for ( int c = 0; c < count; c++ )
637 {
4acb6ca6 638 wxLogMessage(wxT("\tcolumn %d has width %d"), c,
f6bcfd97
BP
639 m_listCtrl->GetColumnWidth(c));
640 }
641}
642
643void MyFrame::OnUpdateShowColInfo(wxUpdateUIEvent& event)
644{
645 event.Enable( (m_listCtrl->GetWindowStyleFlag() & wxLC_REPORT) != 0 );
646}
647
7b848b0d
VZ
648void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event))
649{
7b848b0d
VZ
650 long flags = m_listCtrl->GetWindowStyleFlag();
651 if ( flags & wxLC_SINGLE_SEL )
776a33cf 652 flags &= ~wxLC_SINGLE_SEL;
7b848b0d 653 else
776a33cf
VZ
654 flags |= wxLC_SINGLE_SEL;
655
4acb6ca6 656 m_logWindow->WriteText(wxString::Format(wxT("Current selection mode: %sle\n"),
efe23391 657 (flags & wxLC_SINGLE_SEL) ? _T("sing") : _T("multip")));
7b848b0d 658
776a33cf 659 RecreateList(flags);
7b848b0d
VZ
660}
661
ae403b11
JS
662void MyFrame::OnUpdateToggleMultiSel(wxUpdateUIEvent& event)
663{
664 event.Check((m_listCtrl->GetWindowStyleFlag() & wxLC_SINGLE_SEL) == 0);
665}
666
11f26ea0
VZ
667void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
668{
669 m_listCtrl->SetForegroundColour(wxGetColourFromUser(this));
670 m_listCtrl->Refresh();
671}
672
673void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event))
674{
675 m_listCtrl->SetBackgroundColour(wxGetColourFromUser(this));
676 m_listCtrl->Refresh();
677}
678
cf1dfa6b
VZ
679void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event))
680{
681 m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), _T("Appended item"));
682}
683
efe23391
VZ
684void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event))
685{
686 long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
687 wxLIST_STATE_FOCUSED);
688
689 if ( itemCur != -1 )
690 {
691 m_listCtrl->EditLabel(itemCur);
692 }
693 else
694 {
695 m_logWindow->WriteText(_T("No item to edit"));
696 }
697}
698
bec0a261
VZ
699void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
700{
701 if ( m_listCtrl->GetItemCount() )
702 {
703 m_listCtrl->DeleteItem(0);
704 }
705 else
706 {
efe23391 707 m_logWindow->WriteText(_T("Nothing to delete"));
bec0a261
VZ
708 }
709}
710
5ea47806
VZ
711void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
712{
81278df2 713 wxStopWatch sw;
5ea47806 714
b143cf70 715 int itemCount = m_listCtrl->GetItemCount();
fde548e2 716
5ea47806
VZ
717 m_listCtrl->DeleteAllItems();
718
81278df2 719 m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
fde548e2 720 itemCount,
81278df2 721 sw.Time()));
457814b5
JS
722}
723
724// MyListCtrl
725
614391dc
VZ
726void MyListCtrl::OnCacheHint(wxListEvent& event)
727{
4acb6ca6 728 wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
614391dc
VZ
729 event.GetCacheFrom(), event.GetCacheTo() );
730}
731
6f806543
VZ
732void MyListCtrl::SetColumnImage(int col, int image)
733{
734 wxListItem item;
735 item.SetMask(wxLIST_MASK_IMAGE);
736 item.SetImage(image);
737 SetColumn(col, item);
738}
739
8636aed8
RR
740void MyListCtrl::OnColClick(wxListEvent& event)
741{
6f806543 742 int col = event.GetColumn();
f0cf38b7
VZ
743
744 // set or unset image
4979a56c 745 static bool x = false;
f0cf38b7
VZ
746 x = !x;
747 SetColumnImage(col, x ? 0 : -1);
6f806543
VZ
748
749 wxLogMessage( wxT("OnColumnClick at %d."), col );
8636aed8
RR
750}
751
11358d39
VZ
752void MyListCtrl::OnColRightClick(wxListEvent& event)
753{
6f806543 754 int col = event.GetColumn();
62313c27
VZ
755 if ( col != -1 )
756 {
757 SetColumnImage(col, -1);
758 }
6f806543 759
77ace0c5
WS
760 // Show popupmenu at position
761 wxMenu menu(wxT("Test"));
762 menu.Append(LIST_ABOUT, _T("&About"));
5f4d35b8 763 PopupMenu(&menu, event.GetPoint());
77ace0c5 764
11358d39
VZ
765 wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
766}
767
2b5f62a0
VZ
768void MyListCtrl::LogColEvent(const wxListEvent& event, const wxChar *name)
769{
770 const int col = event.GetColumn();
771
772 wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
773 name,
774 col,
775 event.GetItem().GetWidth(),
776 GetColumnWidth(col));
777}
778
11358d39
VZ
779void MyListCtrl::OnColBeginDrag(wxListEvent& event)
780{
2b5f62a0 781 LogColEvent( event, wxT("OnColBeginDrag") );
355f2407
VZ
782
783 if ( event.GetColumn() == 0 )
784 {
785 wxLogMessage(_T("Resizing this column shouldn't work."));
786
787 event.Veto();
788 }
11358d39
VZ
789}
790
791void MyListCtrl::OnColDragging(wxListEvent& event)
792{
2b5f62a0 793 LogColEvent( event, wxT("OnColDragging") );
11358d39
VZ
794}
795
796void MyListCtrl::OnColEndDrag(wxListEvent& event)
797{
2b5f62a0 798 LogColEvent( event, wxT("OnColEndDrag") );
11358d39
VZ
799}
800
fd9811b1 801void MyListCtrl::OnBeginDrag(wxListEvent& event)
457814b5 802{
6dc34ebb
VZ
803 const wxPoint& pt = event.m_pointDrag;
804
805 int flags;
806 wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
807 pt.x, pt.y, HitTest(pt, flags) );
457814b5
JS
808}
809
fd9811b1 810void MyListCtrl::OnBeginRDrag(wxListEvent& event)
457814b5 811{
4acb6ca6 812 wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
c41ea66a 813 event.m_pointDrag.x, event.m_pointDrag.y );
457814b5
JS
814}
815
fd9811b1 816void MyListCtrl::OnBeginLabelEdit(wxListEvent& event)
457814b5 817{
4acb6ca6 818 wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
457814b5
JS
819}
820
fd9811b1 821void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
457814b5 822{
1bf37bf5 823 wxLogMessage( wxT("OnEndLabelEdit: %s"),
15836000
CE
824 (
825 event.IsEditCancelled() ?
826 wxString("[cancelled]") :
827 event.m_item.m_text
828 ).c_str()
829 );
457814b5
JS
830}
831
efbb7287 832void MyListCtrl::OnDeleteItem(wxListEvent& event)
457814b5 833{
c41ea66a 834 LogEvent(event, _T("OnDeleteItem"));
a95d5751 835 wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
457814b5
JS
836}
837
c41ea66a 838void MyListCtrl::OnDeleteAllItems(wxListEvent& event)
12c1b46a 839{
c41ea66a 840 LogEvent(event, _T("OnDeleteAllItems"));
12c1b46a
RR
841}
842
74b31181 843void MyListCtrl::OnSelected(wxListEvent& event)
457814b5 844{
c41ea66a 845 LogEvent(event, _T("OnSelected"));
457814b5 846
40779a03 847 if ( GetWindowStyle() & wxLC_REPORT )
74b31181 848 {
40779a03
VZ
849 wxListItem info;
850 info.m_itemId = event.m_itemIndex;
851 info.m_col = 1;
852 info.m_mask = wxLIST_MASK_TEXT;
853 if ( GetItem(info) )
854 {
4acb6ca6 855 wxLogMessage(wxT("Value of the 2nd field of the selected item: %s"),
c41ea66a 856 info.m_text.c_str());
40779a03
VZ
857 }
858 else
859 {
4acb6ca6 860 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
40779a03 861 }
74b31181 862 }
457814b5
JS
863}
864
efbb7287 865void MyListCtrl::OnDeselected(wxListEvent& event)
457814b5 866{
c41ea66a 867 LogEvent(event, _T("OnDeselected"));
457814b5
JS
868}
869
efbb7287 870void MyListCtrl::OnActivated(wxListEvent& event)
435fe83e 871{
c41ea66a 872 LogEvent(event, _T("OnActivated"));
435fe83e
RR
873}
874
0ddefeb0
VZ
875void MyListCtrl::OnFocused(wxListEvent& event)
876{
877 LogEvent(event, _T("OnFocused"));
27770773
VZ
878
879 event.Skip();
0ddefeb0
VZ
880}
881
8e1d4f96 882void MyListCtrl::OnListKeyDown(wxListEvent& event)
457814b5 883{
100f649f
VZ
884 long item;
885
2936eaf0 886 switch ( event.GetKeyCode() )
5cd89174 887 {
ebc9b89d 888 case 'C': // colorize
6c02c329
VZ
889 {
890 wxListItem info;
891 info.m_itemId = event.GetIndex();
63c95faf
VZ
892 if ( info.m_itemId == -1 )
893 {
894 // no item
895 break;
896 }
897
6c02c329
VZ
898 GetItem(info);
899
900 wxListItemAttr *attr = info.GetAttributes();
901 if ( !attr || !attr->HasTextColour() )
902 {
903 info.SetTextColour(*wxCYAN);
904
905 SetItem(info);
2d33aec9
VZ
906
907 RefreshItem(info.m_itemId);
6c02c329
VZ
908 }
909 }
910 break;
911
ebc9b89d 912 case 'N': // next
100f649f
VZ
913 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
914 if ( item++ == GetItemCount() - 1 )
915 {
916 item = 0;
917 }
918
919 wxLogMessage(_T("Focusing item %ld"), item);
920
921 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
922 EnsureVisible(item);
923 break;
924
ebc9b89d 925 case 'R': // show bounding rectangle
2d33aec9 926 {
100f649f
VZ
927 item = event.GetIndex();
928 wxRect r;
929 if ( !GetItemRect(item, r) )
2d33aec9 930 {
100f649f
VZ
931 wxLogError(_T("Failed to retrieve rect of item %ld"), item);
932 break;
2d33aec9
VZ
933 }
934
100f649f
VZ
935 wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
936 item, r.x, r.y, r.x + r.width, r.y + r.height);
2d33aec9
VZ
937 }
938 break;
939
ebc9b89d
VZ
940 case 'U': // update
941 if ( !IsVirtual() )
942 break;
943
944 if ( m_updated != -1 )
945 RefreshItem(m_updated);
946
947 m_updated = event.GetIndex();
948 if ( m_updated != -1 )
949 {
950 // we won't see changes to this item as it's selected, update
951 // the next one (or the first one if we're on the last item)
952 if ( ++m_updated == GetItemCount() )
953 m_updated = 0;
954
955 wxLogMessage("Updating colour of the item %ld", m_updated);
956 RefreshItem(m_updated);
957 }
958 break;
959
5cd89174 960 case WXK_DELETE:
100f649f
VZ
961 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
962 while ( item != -1 )
91c6cc0e 963 {
100f649f 964 DeleteItem(item);
91c6cc0e 965
100f649f 966 wxLogMessage(_T("Item %ld deleted"), item);
f6bcfd97 967
100f649f
VZ
968 // -1 because the indices were shifted by DeleteItem()
969 item = GetNextItem(item - 1,
970 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
91c6cc0e 971 }
5cd89174
VZ
972 break;
973
974 case WXK_INSERT:
975 if ( GetWindowStyle() & wxLC_REPORT )
976 {
977 if ( GetWindowStyle() & wxLC_VIRTUAL )
978 {
979 SetItemCount(GetItemCount() + 1);
980 }
981 else // !virtual
982 {
983 InsertItemInReportView(event.GetIndex());
984 }
985 }
986 //else: fall through
987
988 default:
989 LogEvent(event, _T("OnListKeyDown"));
990
991 event.Skip();
992 }
f6bcfd97
BP
993}
994
995void MyListCtrl::OnChar(wxKeyEvent& event)
996{
997 wxLogMessage(_T("Got char event."));
998
2d33aec9
VZ
999 switch ( event.GetKeyCode() )
1000 {
1001 case 'n':
1002 case 'N':
1003 case 'c':
1004 case 'C':
ebc9b89d
VZ
1005 case 'r':
1006 case 'R':
1007 case 'u':
1008 case 'U':
1009 case WXK_DELETE:
1010 case WXK_INSERT:
2d33aec9
VZ
1011 // these are the keys we process ourselves
1012 break;
1013
1014 default:
1015 event.Skip();
1016 }
457814b5
JS
1017}
1018
164a7972
VZ
1019void MyListCtrl::OnRightClick(wxMouseEvent& event)
1020{
1021 if ( !event.ControlDown() )
1022 {
1023 event.Skip();
1024 return;
1025 }
1026
1027 int flags;
1028 long subitem;
1029 long item = HitTest(event.GetPosition(), flags, &subitem);
1030
1031 wxString where;
1032 switch ( flags )
1033 {
1034 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
1035 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
1036 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
1037 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
1038 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
1039 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
1040 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
1041 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
1042 default: where = _T("not clear exactly where on"); break;
1043 }
1044
1045 wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
1046 where.c_str(), item, subitem);
1047}
1048
c41ea66a
VZ
1049void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName)
1050{
f6bcfd97
BP
1051 wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
1052 event.GetIndex(), eventName,
1053 event.GetText().c_str(), event.GetData());
c41ea66a 1054}
435fe83e 1055
98ec9dbe
VZ
1056wxString MyListCtrl::OnGetItemText(long item, long column) const
1057{
b0401bea
VZ
1058 if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
1059 {
1060 return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
1061 }
ebc9b89d 1062 else // "big" virtual control
b0401bea
VZ
1063 {
1064 return wxString::Format(_T("Column %ld of item %ld"), column, item);
1065 }
98ec9dbe
VZ
1066}
1067
06db67bc 1068int MyListCtrl::OnGetItemColumnImage(long item, long column) const
98ec9dbe 1069{
06db67bc
RD
1070 if (!column)
1071 return 0;
1072
ebc9b89d 1073 if (!(item % 3) && column == 1)
06db67bc
RD
1074 return 0;
1075
1076 return -1;
98ec9dbe
VZ
1077}
1078
6c02c329
VZ
1079wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const
1080{
ebc9b89d
VZ
1081 // test to check that RefreshItem() works correctly: when m_updated is
1082 // set to some item and it is refreshed, we highlight the item
1083 if ( item == m_updated )
1084 {
1085 static wxListItemAttr s_attrHighlight(*wxRED, wxNullColour, wxNullFont);
1086 return &s_attrHighlight;
1087 }
1088
6c02c329
VZ
1089 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
1090}
1091
5cd89174
VZ
1092void MyListCtrl::InsertItemInReportView(int i)
1093{
1094 wxString buf;
1095 buf.Printf(_T("This is item %d"), i);
1096 long tmp = InsertItem(i, buf, 0);
1097 SetItemData(tmp, i);
1098
1099 buf.Printf(_T("Col 1, item %d"), i);
eb257f65 1100 SetItem(tmp, 1, buf);
5cd89174
VZ
1101
1102 buf.Printf(_T("Item %d in column 2"), i);
eb257f65 1103 SetItem(tmp, 2, buf);
5cd89174 1104}
107ff668
JS
1105
1106#if USE_CONTEXT_MENU
1107void MyListCtrl::OnContextMenu(wxContextMenuEvent& event)
1108{
1109 wxPoint point = event.GetPosition();
1110 // If from keyboard
1111 if (point.x == -1 && point.y == -1) {
1112 wxSize size = GetSize();
1113 point.x = size.x / 2;
1114 point.y = size.y / 2;
1115 } else {
1116 point = ScreenToClient(point);
1117 }
1118 ShowContextMenu(point);
1119}
1120#endif
1121
1122void MyListCtrl::ShowContextMenu(const wxPoint& pos)
1123{
1124 wxMenu menu;
1125
1126 menu.Append(wxID_ABOUT, _T("&About"));
1127 menu.AppendSeparator();
1128 menu.Append(wxID_EXIT, _T("E&xit"));
1129
1130 PopupMenu(&menu, pos.x, pos.y);
1131}