]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
50 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
98ec9dbe VZ |
51 | EVT_SIZE(MyFrame::OnSize) |
52 | ||
5ea47806 VZ |
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) | |
98ec9dbe VZ |
61 | EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView) |
62 | ||
88b792af | 63 | EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast) |
58b3bdc9 | 64 | EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel) |
5ea47806 VZ |
65 | EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll) |
66 | EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll) | |
bec0a261 | 67 | EVT_MENU(LIST_DELETE, MyFrame::OnDelete) |
cf1dfa6b | 68 | EVT_MENU(LIST_ADD, MyFrame::OnAdd) |
efe23391 | 69 | EVT_MENU(LIST_EDIT, MyFrame::OnEdit) |
5ea47806 | 70 | EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll) |
fa5f6926 | 71 | EVT_MENU(LIST_SORT, MyFrame::OnSort) |
11f26ea0 VZ |
72 | EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour) |
73 | EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour) | |
7b848b0d | 74 | EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel) |
f6bcfd97 | 75 | EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo) |
b54e41c5 | 76 | EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo) |
c5c528fc VZ |
77 | EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze) |
78 | EVT_MENU(LIST_THAW, MyFrame::OnThaw) | |
98ec9dbe | 79 | |
f6bcfd97 | 80 | EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo) |
ae403b11 | 81 | EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel) |
457814b5 JS |
82 | END_EVENT_TABLE() |
83 | ||
84 | BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) | |
5ea47806 VZ |
85 | EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag) |
86 | EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag) | |
87 | EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit) | |
88 | EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit) | |
89 | EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem) | |
12c1b46a | 90 | EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems) |
5ea47806 VZ |
91 | EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo) |
92 | EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo) | |
93 | EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected) | |
94 | EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) | |
95 | EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) | |
96 | EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) | |
0ddefeb0 | 97 | EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused) |
11358d39 | 98 | |
8636aed8 | 99 | EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick) |
11358d39 VZ |
100 | EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick) |
101 | EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag) | |
102 | EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging) | |
103 | EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag) | |
104 | ||
614391dc | 105 | EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint) |
f6bcfd97 BP |
106 | |
107 | EVT_CHAR(MyListCtrl::OnChar) | |
457814b5 JS |
108 | END_EVENT_TABLE() |
109 | ||
110 | IMPLEMENT_APP(MyApp) | |
111 | ||
776a33cf VZ |
112 | // number of items in list/report view |
113 | static const int NUM_ITEMS = 30; | |
114 | ||
115 | // number of items in icon/small icon view | |
116 | static const int NUM_ICONS = 9; | |
117 | ||
c71963cd | 118 | int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData)) |
fa5f6926 VZ |
119 | { |
120 | // inverse the order | |
c71963cd VZ |
121 | if (item1 < item2) |
122 | return -1; | |
123 | if (item1 > item2) | |
124 | return 1; | |
125 | ||
2b5f62a0 | 126 | return 0; |
fa5f6926 VZ |
127 | } |
128 | ||
457814b5 | 129 | // `Main program' equivalent, creating windows and returning main app frame |
11f26ea0 | 130 | bool MyApp::OnInit() |
457814b5 JS |
131 | { |
132 | // Create the main frame window | |
4acb6ca6 | 133 | MyFrame *frame = new MyFrame(wxT("wxListCtrl Test"), 50, 50, 450, 340); |
457814b5 JS |
134 | |
135 | // Show the frame | |
1550e402 | 136 | frame->Show(true); |
5ea47806 | 137 | |
457814b5 JS |
138 | SetTopWindow(frame); |
139 | ||
1550e402 | 140 | return true; |
457814b5 JS |
141 | } |
142 | ||
143 | // My frame constructor | |
c41ea66a | 144 | MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h) |
1550e402 | 145 | : wxFrame((wxFrame *)NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) |
457814b5 | 146 | { |
5ea47806 VZ |
147 | m_listCtrl = (MyListCtrl *) NULL; |
148 | m_logWindow = (wxTextCtrl *) NULL; | |
c41ea66a VZ |
149 | |
150 | // Give it an icon | |
151 | SetIcon( wxICON(mondrian) ); | |
152 | ||
153 | // Make an image list containing large icons | |
1550e402 WS |
154 | m_imageListNormal = new wxImageList(32, 32, true); |
155 | m_imageListSmall = new wxImageList(16, 16, true); | |
c41ea66a VZ |
156 | |
157 | #ifdef __WXMSW__ | |
42ed7532 MB |
158 | m_imageListNormal->Add( wxIcon(_T("icon1"), wxBITMAP_TYPE_ICO_RESOURCE) ); |
159 | m_imageListNormal->Add( wxIcon(_T("icon2"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
160 | m_imageListNormal->Add( wxIcon(_T("icon3"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
161 | m_imageListNormal->Add( wxIcon(_T("icon4"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
162 | m_imageListNormal->Add( wxIcon(_T("icon5"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
163 | m_imageListNormal->Add( wxIcon(_T("icon6"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
164 | m_imageListNormal->Add( wxIcon(_T("icon7"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
165 | m_imageListNormal->Add( wxIcon(_T("icon8"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
166 | m_imageListNormal->Add( wxIcon(_T("icon9"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
167 | ||
168 | m_imageListSmall->Add( wxIcon(_T("iconsmall"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
c41ea66a VZ |
169 | |
170 | #else | |
171 | m_imageListNormal->Add( wxIcon( toolbrai_xpm ) ); | |
172 | m_imageListNormal->Add( wxIcon( toolchar_xpm ) ); | |
173 | m_imageListNormal->Add( wxIcon( tooldata_xpm ) ); | |
174 | m_imageListNormal->Add( wxIcon( toolnote_xpm ) ); | |
175 | m_imageListNormal->Add( wxIcon( tooltodo_xpm ) ); | |
176 | m_imageListNormal->Add( wxIcon( toolchec_xpm ) ); | |
177 | m_imageListNormal->Add( wxIcon( toolgame_xpm ) ); | |
178 | m_imageListNormal->Add( wxIcon( tooltime_xpm ) ); | |
179 | m_imageListNormal->Add( wxIcon( toolword_xpm ) ); | |
180 | ||
181 | m_imageListSmall->Add( wxIcon( small1_xpm) ); | |
182 | #endif | |
183 | ||
184 | // Make a menubar | |
185 | wxMenu *menuFile = new wxMenu; | |
98ec9dbe | 186 | menuFile->Append(LIST_ABOUT, _T("&About")); |
c41ea66a | 187 | menuFile->AppendSeparator(); |
98ec9dbe | 188 | menuFile->Append(LIST_QUIT, _T("E&xit\tAlt-X")); |
c41ea66a VZ |
189 | |
190 | wxMenu *menuView = new wxMenu; | |
98ec9dbe VZ |
191 | menuView->Append(LIST_LIST_VIEW, _T("&List view\tF1")); |
192 | menuView->Append(LIST_REPORT_VIEW, _T("&Report view\tF2")); | |
193 | menuView->Append(LIST_ICON_VIEW, _T("&Icon view\tF3")); | |
194 | menuView->Append(LIST_ICON_TEXT_VIEW, _T("Icon view with &text\tF4")); | |
195 | menuView->Append(LIST_SMALL_ICON_VIEW, _T("&Small icon view\tF5")); | |
196 | menuView->Append(LIST_SMALL_ICON_TEXT_VIEW, _T("Small icon &view with text\tF6")); | |
197 | menuView->Append(LIST_VIRTUAL_VIEW, _T("Virtual view\tF7")); | |
c41ea66a VZ |
198 | |
199 | wxMenu *menuList = new wxMenu; | |
88b792af | 200 | menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L")); |
c5c528fc | 201 | menuList->Append(LIST_TOGGLE_FIRST, _T("To&ggle first item\tCtrl-G")); |
98ec9dbe VZ |
202 | menuList->Append(LIST_DESELECT_ALL, _T("&Deselect All\tCtrl-D")); |
203 | menuList->Append(LIST_SELECT_ALL, _T("S&elect All\tCtrl-A")); | |
b54e41c5 | 204 | menuList->AppendSeparator(); |
98ec9dbe | 205 | menuList->Append(LIST_SHOW_COL_INFO, _T("Show &column info\tCtrl-C")); |
b54e41c5 | 206 | menuList->Append(LIST_SHOW_SEL_INFO, _T("Show &selected items\tCtrl-S")); |
c41ea66a | 207 | menuList->AppendSeparator(); |
98ec9dbe | 208 | menuList->Append(LIST_SORT, _T("&Sort\tCtrl-S")); |
c41ea66a | 209 | menuList->AppendSeparator(); |
cf1dfa6b | 210 | menuList->Append(LIST_ADD, _T("&Append an item\tCtrl-P")); |
efe23391 | 211 | menuList->Append(LIST_EDIT, _T("&Edit the item\tCtrl-E")); |
cf1dfa6b | 212 | menuList->Append(LIST_DELETE, _T("&Delete first item\tCtrl-X")); |
98ec9dbe | 213 | menuList->Append(LIST_DELETE_ALL, _T("Delete &all items")); |
c41ea66a | 214 | menuList->AppendSeparator(); |
c5c528fc VZ |
215 | menuList->Append(LIST_FREEZE, _T("Free&ze\tCtrl-Z")); |
216 | menuList->Append(LIST_THAW, _T("Tha&w\tCtrl-W")); | |
217 | menuList->AppendSeparator(); | |
98ec9dbe | 218 | menuList->Append(LIST_TOGGLE_MULTI_SEL, _T("&Multiple selection\tCtrl-M"), |
1550e402 | 219 | _T("Toggle multiple selection"), true); |
c41ea66a VZ |
220 | |
221 | wxMenu *menuCol = new wxMenu; | |
98ec9dbe VZ |
222 | menuCol->Append(LIST_SET_FG_COL, _T("&Foreground colour...")); |
223 | menuCol->Append(LIST_SET_BG_COL, _T("&Background colour...")); | |
c41ea66a VZ |
224 | |
225 | wxMenuBar *menubar = new wxMenuBar; | |
98ec9dbe VZ |
226 | menubar->Append(menuFile, _T("&File")); |
227 | menubar->Append(menuView, _T("&View")); | |
228 | menubar->Append(menuList, _T("&List")); | |
229 | menubar->Append(menuCol, _T("&Colour")); | |
c41ea66a VZ |
230 | SetMenuBar(menubar); |
231 | ||
1550e402 WS |
232 | m_panel = new wxPanel(this, wxID_ANY); |
233 | m_logWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, | |
c41ea66a VZ |
234 | wxDefaultPosition, wxDefaultSize, |
235 | wxTE_MULTILINE | wxSUNKEN_BORDER); | |
236 | ||
237 | m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow)); | |
238 | ||
776a33cf | 239 | RecreateList(wxLC_REPORT | wxLC_SINGLE_SEL); |
c41ea66a VZ |
240 | |
241 | CreateStatusBar(3); | |
457814b5 JS |
242 | } |
243 | ||
11f26ea0 | 244 | MyFrame::~MyFrame() |
457814b5 | 245 | { |
c41ea66a VZ |
246 | delete wxLog::SetActiveTarget(m_logOld); |
247 | ||
248 | delete m_imageListNormal; | |
249 | delete m_imageListSmall; | |
457814b5 JS |
250 | } |
251 | ||
98ec9dbe | 252 | void MyFrame::OnSize(wxSizeEvent& event) |
07bf769e VZ |
253 | { |
254 | DoSize(); | |
255 | ||
256 | event.Skip(); | |
257 | } | |
258 | ||
259 | void MyFrame::DoSize() | |
457814b5 | 260 | { |
98ec9dbe VZ |
261 | if ( !m_logWindow ) |
262 | return; | |
457814b5 | 263 | |
98ec9dbe VZ |
264 | wxSize size = GetClientSize(); |
265 | wxCoord y = (2*size.y)/3; | |
266 | m_listCtrl->SetSize(0, 0, size.x, y); | |
267 | m_logWindow->SetSize(0, y + 1, size.x, size.y - y); | |
57246713 KB |
268 | } |
269 | ||
68457180 VZ |
270 | bool MyFrame::CheckNonVirtual() const |
271 | { | |
272 | if ( !m_listCtrl->HasFlag(wxLC_VIRTUAL) ) | |
273 | return true; | |
274 | ||
275 | // "this" == whatever | |
276 | wxLogWarning(_T("Can't do this in virtual view, sorry.")); | |
277 | ||
278 | return false; | |
279 | } | |
280 | ||
98ec9dbe | 281 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
57246713 | 282 | { |
1550e402 | 283 | Close(true); |
57246713 KB |
284 | } |
285 | ||
b0d77f43 | 286 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 287 | { |
efe23391 VZ |
288 | wxMessageDialog dialog(this, _T("List test sample\nJulian Smart (c) 1997"), |
289 | _T("About list test"), wxOK|wxCANCEL); | |
457814b5 | 290 | |
5ea47806 | 291 | dialog.ShowModal(); |
457814b5 JS |
292 | } |
293 | ||
c71963cd | 294 | void MyFrame::OnFreeze(wxCommandEvent& WXUNUSED(event)) |
c5c528fc VZ |
295 | { |
296 | wxLogMessage(_T("Freezing the control")); | |
297 | ||
298 | m_listCtrl->Freeze(); | |
299 | } | |
300 | ||
c71963cd | 301 | void MyFrame::OnThaw(wxCommandEvent& WXUNUSED(event)) |
c5c528fc VZ |
302 | { |
303 | wxLogMessage(_T("Thawing the control")); | |
304 | ||
305 | m_listCtrl->Thaw(); | |
306 | } | |
307 | ||
88b792af VZ |
308 | void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event)) |
309 | { | |
310 | long index = m_listCtrl->GetItemCount() - 1; | |
311 | if ( index == -1 ) | |
312 | { | |
313 | return; | |
314 | } | |
315 | ||
316 | m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); | |
317 | m_listCtrl->EnsureVisible(index); | |
318 | } | |
319 | ||
58b3bdc9 VZ |
320 | void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event)) |
321 | { | |
95f913a9 | 322 | m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); |
58b3bdc9 VZ |
323 | } |
324 | ||
c4771147 KB |
325 | void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event)) |
326 | { | |
68457180 VZ |
327 | if ( !CheckNonVirtual() ) |
328 | return; | |
329 | ||
5ea47806 VZ |
330 | int n = m_listCtrl->GetItemCount(); |
331 | for (int i = 0; i < n; i++) | |
332 | m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED); | |
c4771147 KB |
333 | } |
334 | ||
335 | void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
336 | { | |
68457180 VZ |
337 | if ( !CheckNonVirtual() ) |
338 | return; | |
339 | ||
5ea47806 VZ |
340 | int n = m_listCtrl->GetItemCount(); |
341 | for (int i = 0; i < n; i++) | |
342 | m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | |
c4771147 KB |
343 | } |
344 | ||
776a33cf VZ |
345 | // ---------------------------------------------------------------------------- |
346 | // changing listctrl modes | |
347 | // ---------------------------------------------------------------------------- | |
348 | ||
349 | void MyFrame::RecreateList(long flags, bool withText) | |
457814b5 | 350 | { |
776a33cf VZ |
351 | // we could avoid recreating it if we don't set/clear the wxLC_VIRTUAL |
352 | // style, but it is more trouble to do it than not | |
353 | #if 0 | |
354 | if ( !m_listCtrl || ((flags & wxLC_VIRTUAL) != | |
355 | (m_listCtrl->GetWindowStyleFlag() & wxLC_VIRTUAL)) ) | |
356 | #endif | |
357 | { | |
358 | delete m_listCtrl; | |
359 | ||
2b5f62a0 | 360 | m_listCtrl = new MyListCtrl(m_panel, LIST_CTRL, |
776a33cf VZ |
361 | wxDefaultPosition, wxDefaultSize, |
362 | flags | | |
efe23391 | 363 | wxSUNKEN_BORDER | wxLC_EDIT_LABELS); |
776a33cf VZ |
364 | |
365 | switch ( flags & wxLC_MASK_TYPE ) | |
366 | { | |
367 | case wxLC_LIST: | |
368 | InitWithListItems(); | |
369 | break; | |
370 | ||
371 | case wxLC_ICON: | |
372 | InitWithIconItems(withText); | |
373 | break; | |
374 | ||
375 | case wxLC_SMALL_ICON: | |
1550e402 | 376 | InitWithIconItems(withText, true); |
776a33cf VZ |
377 | break; |
378 | ||
379 | case wxLC_REPORT: | |
380 | if ( flags & wxLC_VIRTUAL ) | |
381 | InitWithVirtualItems(); | |
382 | else | |
383 | InitWithReportItems(); | |
384 | break; | |
385 | ||
386 | default: | |
387 | wxFAIL_MSG( _T("unknown listctrl mode") ); | |
388 | } | |
389 | } | |
390 | ||
07bf769e | 391 | DoSize(); |
776a33cf | 392 | |
0180dad6 | 393 | m_logWindow->Clear(); |
776a33cf | 394 | } |
95bf655c | 395 | |
776a33cf VZ |
396 | void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event)) |
397 | { | |
398 | RecreateList(wxLC_LIST); | |
399 | } | |
457814b5 | 400 | |
776a33cf VZ |
401 | void MyFrame::InitWithListItems() |
402 | { | |
403 | for ( int i = 0; i < NUM_ITEMS; i++ ) | |
0180dad6 | 404 | { |
98ec9dbe | 405 | m_listCtrl->InsertItem(i, wxString::Format(_T("Item %d"), i)); |
0180dad6 | 406 | } |
457814b5 JS |
407 | } |
408 | ||
b0d77f43 | 409 | void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 410 | { |
776a33cf VZ |
411 | RecreateList(wxLC_REPORT); |
412 | } | |
5ea47806 | 413 | |
776a33cf VZ |
414 | void MyFrame::InitWithReportItems() |
415 | { | |
c41ea66a | 416 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); |
457814b5 | 417 | |
caa20b1e VZ |
418 | // note that under MSW for SetColumnWidth() to work we need to create the |
419 | // items with images initially even if we specify dummy image id | |
6f806543 | 420 | wxListItem itemCol; |
caa20b1e VZ |
421 | itemCol.SetText(_T("Column 1")); |
422 | itemCol.SetImage(-1); | |
6f806543 | 423 | m_listCtrl->InsertColumn(0, itemCol); |
caa20b1e VZ |
424 | |
425 | itemCol.SetText(_T("Column 2")); | |
426 | itemCol.SetAlign(wxLIST_FORMAT_CENTRE); | |
6f806543 | 427 | m_listCtrl->InsertColumn(1, itemCol); |
caa20b1e VZ |
428 | |
429 | itemCol.SetText(_T("Column 3")); | |
430 | itemCol.SetAlign(wxLIST_FORMAT_RIGHT); | |
6f806543 | 431 | m_listCtrl->InsertColumn(2, itemCol); |
0180dad6 | 432 | |
81278df2 VZ |
433 | // to speed up inserting we hide the control temporarily |
434 | m_listCtrl->Hide(); | |
435 | ||
436 | wxStopWatch sw; | |
437 | ||
81278df2 | 438 | for ( int i = 0; i < NUM_ITEMS; i++ ) |
0180dad6 | 439 | { |
5cd89174 | 440 | m_listCtrl->InsertItemInReportView(i); |
0180dad6 | 441 | } |
bdc72a22 | 442 | |
81278df2 VZ |
443 | m_logWindow->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"), |
444 | NUM_ITEMS, sw.Time())); | |
445 | m_listCtrl->Show(); | |
446 | ||
f6b77239 | 447 | // we leave all mask fields to 0 and only change the colour |
bdc72a22 VZ |
448 | wxListItem item; |
449 | item.m_itemId = 0; | |
0530737d | 450 | item.SetTextColour(*wxRED); |
bdc72a22 VZ |
451 | m_listCtrl->SetItem( item ); |
452 | ||
453 | item.m_itemId = 2; | |
d62228a6 | 454 | item.SetTextColour(*wxGREEN); |
bdc72a22 | 455 | m_listCtrl->SetItem( item ); |
d62228a6 | 456 | item.m_itemId = 4; |
bdc72a22 | 457 | item.SetTextColour(*wxLIGHT_GREY); |
d62228a6 VZ |
458 | item.SetFont(*wxITALIC_FONT); |
459 | item.SetBackgroundColour(*wxRED); | |
bdc72a22 | 460 | m_listCtrl->SetItem( item ); |
5ea47806 | 461 | |
d62228a6 VZ |
462 | m_listCtrl->SetTextColour(*wxBLUE); |
463 | m_listCtrl->SetBackgroundColour(*wxLIGHT_GREY); | |
464 | ||
0180dad6 RR |
465 | m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); |
466 | m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); | |
467 | m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE ); | |
457814b5 JS |
468 | } |
469 | ||
776a33cf | 470 | void MyFrame::InitWithIconItems(bool withText, bool sameIcon) |
457814b5 | 471 | { |
c41ea66a VZ |
472 | m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); |
473 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); | |
457814b5 | 474 | |
776a33cf | 475 | for ( int i = 0; i < NUM_ICONS; i++ ) |
5ea47806 | 476 | { |
776a33cf VZ |
477 | int image = sameIcon ? 0 : i; |
478 | ||
479 | if ( withText ) | |
480 | { | |
481 | m_listCtrl->InsertItem(i, wxString::Format(_T("Label %d"), i), | |
482 | image); | |
483 | } | |
484 | else | |
485 | { | |
486 | m_listCtrl->InsertItem(i, image); | |
487 | } | |
5ea47806 | 488 | } |
457814b5 JS |
489 | } |
490 | ||
776a33cf | 491 | void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 492 | { |
1550e402 | 493 | RecreateList(wxLC_ICON, false); |
776a33cf | 494 | } |
457814b5 | 495 | |
776a33cf VZ |
496 | void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event)) |
497 | { | |
498 | RecreateList(wxLC_ICON); | |
457814b5 JS |
499 | } |
500 | ||
b0d77f43 | 501 | void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 502 | { |
1550e402 | 503 | RecreateList(wxLC_SMALL_ICON, false); |
457814b5 JS |
504 | } |
505 | ||
b0d77f43 | 506 | void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 507 | { |
776a33cf | 508 | RecreateList(wxLC_SMALL_ICON); |
5ea47806 VZ |
509 | } |
510 | ||
98ec9dbe VZ |
511 | void MyFrame::OnVirtualView(wxCommandEvent& WXUNUSED(event)) |
512 | { | |
776a33cf VZ |
513 | RecreateList(wxLC_REPORT | wxLC_VIRTUAL); |
514 | } | |
98ec9dbe | 515 | |
776a33cf VZ |
516 | void MyFrame::InitWithVirtualItems() |
517 | { | |
27770773 VZ |
518 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); |
519 | ||
efe23391 VZ |
520 | m_listCtrl->InsertColumn(0, _T("First Column")); |
521 | m_listCtrl->InsertColumn(1, _T("Second Column")); | |
98ec9dbe VZ |
522 | m_listCtrl->SetColumnWidth(0, 150); |
523 | m_listCtrl->SetColumnWidth(1, 150); | |
524 | ||
525 | m_listCtrl->SetItemCount(1000000); | |
98ec9dbe VZ |
526 | } |
527 | ||
fa5f6926 VZ |
528 | void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event)) |
529 | { | |
81278df2 VZ |
530 | wxStopWatch sw; |
531 | ||
fa5f6926 | 532 | m_listCtrl->SortItems(MyCompareFunction, 0); |
81278df2 VZ |
533 | |
534 | m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"), | |
535 | m_listCtrl->GetItemCount(), | |
536 | sw.Time())); | |
fa5f6926 VZ |
537 | } |
538 | ||
c71963cd | 539 | void MyFrame::OnShowSelInfo(wxCommandEvent& WXUNUSED(event)) |
b54e41c5 VZ |
540 | { |
541 | int selCount = m_listCtrl->GetSelectedItemCount(); | |
542 | wxLogMessage(_T("%d items selected:"), selCount); | |
543 | ||
544 | // don't show too many items | |
545 | size_t shownCount = 0; | |
546 | ||
547 | long item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, | |
548 | wxLIST_STATE_SELECTED); | |
549 | while ( item != -1 ) | |
550 | { | |
551 | wxLogMessage(_T("\t%ld (%s)"), | |
552 | item, m_listCtrl->GetItemText(item).c_str()); | |
553 | ||
554 | if ( ++shownCount > 10 ) | |
555 | { | |
556 | wxLogMessage(_T("\t... more selected items snipped...")); | |
557 | break; | |
558 | } | |
559 | ||
560 | item = m_listCtrl->GetNextItem(item, wxLIST_NEXT_ALL, | |
561 | wxLIST_STATE_SELECTED); | |
562 | } | |
563 | } | |
564 | ||
c71963cd | 565 | void MyFrame::OnShowColInfo(wxCommandEvent& WXUNUSED(event)) |
f6bcfd97 BP |
566 | { |
567 | int count = m_listCtrl->GetColumnCount(); | |
4acb6ca6 | 568 | wxLogMessage(wxT("%d columns:"), count); |
f6bcfd97 BP |
569 | for ( int c = 0; c < count; c++ ) |
570 | { | |
4acb6ca6 | 571 | wxLogMessage(wxT("\tcolumn %d has width %d"), c, |
f6bcfd97 BP |
572 | m_listCtrl->GetColumnWidth(c)); |
573 | } | |
574 | } | |
575 | ||
576 | void MyFrame::OnUpdateShowColInfo(wxUpdateUIEvent& event) | |
577 | { | |
578 | event.Enable( (m_listCtrl->GetWindowStyleFlag() & wxLC_REPORT) != 0 ); | |
579 | } | |
580 | ||
7b848b0d VZ |
581 | void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event)) |
582 | { | |
7b848b0d VZ |
583 | long flags = m_listCtrl->GetWindowStyleFlag(); |
584 | if ( flags & wxLC_SINGLE_SEL ) | |
776a33cf | 585 | flags &= ~wxLC_SINGLE_SEL; |
7b848b0d | 586 | else |
776a33cf VZ |
587 | flags |= wxLC_SINGLE_SEL; |
588 | ||
4acb6ca6 | 589 | m_logWindow->WriteText(wxString::Format(wxT("Current selection mode: %sle\n"), |
efe23391 | 590 | (flags & wxLC_SINGLE_SEL) ? _T("sing") : _T("multip"))); |
7b848b0d | 591 | |
776a33cf | 592 | RecreateList(flags); |
7b848b0d VZ |
593 | } |
594 | ||
ae403b11 JS |
595 | void MyFrame::OnUpdateToggleMultiSel(wxUpdateUIEvent& event) |
596 | { | |
597 | event.Check((m_listCtrl->GetWindowStyleFlag() & wxLC_SINGLE_SEL) == 0); | |
598 | } | |
599 | ||
11f26ea0 VZ |
600 | void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event)) |
601 | { | |
602 | m_listCtrl->SetForegroundColour(wxGetColourFromUser(this)); | |
603 | m_listCtrl->Refresh(); | |
604 | } | |
605 | ||
606 | void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event)) | |
607 | { | |
608 | m_listCtrl->SetBackgroundColour(wxGetColourFromUser(this)); | |
609 | m_listCtrl->Refresh(); | |
610 | } | |
611 | ||
cf1dfa6b VZ |
612 | void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event)) |
613 | { | |
614 | m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), _T("Appended item")); | |
615 | } | |
616 | ||
efe23391 VZ |
617 | void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event)) |
618 | { | |
619 | long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, | |
620 | wxLIST_STATE_FOCUSED); | |
621 | ||
622 | if ( itemCur != -1 ) | |
623 | { | |
624 | m_listCtrl->EditLabel(itemCur); | |
625 | } | |
626 | else | |
627 | { | |
628 | m_logWindow->WriteText(_T("No item to edit")); | |
629 | } | |
630 | } | |
631 | ||
bec0a261 VZ |
632 | void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event)) |
633 | { | |
634 | if ( m_listCtrl->GetItemCount() ) | |
635 | { | |
636 | m_listCtrl->DeleteItem(0); | |
637 | } | |
638 | else | |
639 | { | |
efe23391 | 640 | m_logWindow->WriteText(_T("Nothing to delete")); |
bec0a261 VZ |
641 | } |
642 | } | |
643 | ||
5ea47806 VZ |
644 | void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event)) |
645 | { | |
81278df2 | 646 | wxStopWatch sw; |
5ea47806 | 647 | |
5ea47806 VZ |
648 | m_listCtrl->DeleteAllItems(); |
649 | ||
81278df2 VZ |
650 | m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"), |
651 | m_listCtrl->GetItemCount(), | |
652 | sw.Time())); | |
457814b5 JS |
653 | } |
654 | ||
655 | // MyListCtrl | |
656 | ||
614391dc VZ |
657 | void MyListCtrl::OnCacheHint(wxListEvent& event) |
658 | { | |
4acb6ca6 | 659 | wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"), |
614391dc VZ |
660 | event.GetCacheFrom(), event.GetCacheTo() ); |
661 | } | |
662 | ||
6f806543 VZ |
663 | void MyListCtrl::SetColumnImage(int col, int image) |
664 | { | |
665 | wxListItem item; | |
666 | item.SetMask(wxLIST_MASK_IMAGE); | |
667 | item.SetImage(image); | |
668 | SetColumn(col, item); | |
669 | } | |
670 | ||
8636aed8 RR |
671 | void MyListCtrl::OnColClick(wxListEvent& event) |
672 | { | |
6f806543 VZ |
673 | int col = event.GetColumn(); |
674 | SetColumnImage(col, 0); | |
675 | ||
676 | wxLogMessage( wxT("OnColumnClick at %d."), col ); | |
8636aed8 RR |
677 | } |
678 | ||
11358d39 VZ |
679 | void MyListCtrl::OnColRightClick(wxListEvent& event) |
680 | { | |
6f806543 | 681 | int col = event.GetColumn(); |
62313c27 VZ |
682 | if ( col != -1 ) |
683 | { | |
684 | SetColumnImage(col, -1); | |
685 | } | |
6f806543 | 686 | |
11358d39 VZ |
687 | wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() ); |
688 | } | |
689 | ||
2b5f62a0 VZ |
690 | void MyListCtrl::LogColEvent(const wxListEvent& event, const wxChar *name) |
691 | { | |
692 | const int col = event.GetColumn(); | |
693 | ||
694 | wxLogMessage(wxT("%s: column %d (width = %d or %d)."), | |
695 | name, | |
696 | col, | |
697 | event.GetItem().GetWidth(), | |
698 | GetColumnWidth(col)); | |
699 | } | |
700 | ||
11358d39 VZ |
701 | void MyListCtrl::OnColBeginDrag(wxListEvent& event) |
702 | { | |
2b5f62a0 | 703 | LogColEvent( event, wxT("OnColBeginDrag") ); |
355f2407 VZ |
704 | |
705 | if ( event.GetColumn() == 0 ) | |
706 | { | |
707 | wxLogMessage(_T("Resizing this column shouldn't work.")); | |
708 | ||
709 | event.Veto(); | |
710 | } | |
11358d39 VZ |
711 | } |
712 | ||
713 | void MyListCtrl::OnColDragging(wxListEvent& event) | |
714 | { | |
2b5f62a0 | 715 | LogColEvent( event, wxT("OnColDragging") ); |
11358d39 VZ |
716 | } |
717 | ||
718 | void MyListCtrl::OnColEndDrag(wxListEvent& event) | |
719 | { | |
2b5f62a0 | 720 | LogColEvent( event, wxT("OnColEndDrag") ); |
11358d39 VZ |
721 | } |
722 | ||
fd9811b1 | 723 | void MyListCtrl::OnBeginDrag(wxListEvent& event) |
457814b5 | 724 | { |
6dc34ebb VZ |
725 | const wxPoint& pt = event.m_pointDrag; |
726 | ||
727 | int flags; | |
728 | wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."), | |
729 | pt.x, pt.y, HitTest(pt, flags) ); | |
457814b5 JS |
730 | } |
731 | ||
fd9811b1 | 732 | void MyListCtrl::OnBeginRDrag(wxListEvent& event) |
457814b5 | 733 | { |
4acb6ca6 | 734 | wxLogMessage( wxT("OnBeginRDrag at %d,%d."), |
c41ea66a | 735 | event.m_pointDrag.x, event.m_pointDrag.y ); |
457814b5 JS |
736 | } |
737 | ||
fd9811b1 | 738 | void MyListCtrl::OnBeginLabelEdit(wxListEvent& event) |
457814b5 | 739 | { |
4acb6ca6 | 740 | wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str()); |
457814b5 JS |
741 | } |
742 | ||
fd9811b1 | 743 | void MyListCtrl::OnEndLabelEdit(wxListEvent& event) |
457814b5 | 744 | { |
1bf37bf5 VZ |
745 | wxLogMessage( wxT("OnEndLabelEdit: %s"), |
746 | event.IsEditCancelled() ? _T("[cancelled]") | |
747 | : event.m_item.m_text.c_str()); | |
457814b5 JS |
748 | } |
749 | ||
efbb7287 | 750 | void MyListCtrl::OnDeleteItem(wxListEvent& event) |
457814b5 | 751 | { |
c41ea66a | 752 | LogEvent(event, _T("OnDeleteItem")); |
457814b5 JS |
753 | } |
754 | ||
c41ea66a | 755 | void MyListCtrl::OnDeleteAllItems(wxListEvent& event) |
12c1b46a | 756 | { |
c41ea66a | 757 | LogEvent(event, _T("OnDeleteAllItems")); |
12c1b46a RR |
758 | } |
759 | ||
fd9811b1 | 760 | void MyListCtrl::OnGetInfo(wxListEvent& event) |
457814b5 | 761 | { |
c41ea66a | 762 | wxString msg; |
5ea47806 | 763 | |
efe23391 | 764 | msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")"); |
5ea47806 | 765 | if ( event.m_item.m_mask & wxLIST_MASK_STATE ) |
efe23391 | 766 | msg << _T(" wxLIST_MASK_STATE"); |
5ea47806 | 767 | if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) |
efe23391 | 768 | msg << _T(" wxLIST_MASK_TEXT"); |
5ea47806 | 769 | if ( event.m_item.m_mask & wxLIST_MASK_IMAGE ) |
efe23391 | 770 | msg << _T(" wxLIST_MASK_IMAGE"); |
5ea47806 | 771 | if ( event.m_item.m_mask & wxLIST_MASK_DATA ) |
efe23391 | 772 | msg << _T(" wxLIST_MASK_DATA"); |
5ea47806 | 773 | if ( event.m_item.m_mask & wxLIST_SET_ITEM ) |
efe23391 | 774 | msg << _T(" wxLIST_SET_ITEM"); |
5ea47806 | 775 | if ( event.m_item.m_mask & wxLIST_MASK_WIDTH ) |
efe23391 | 776 | msg << _T(" wxLIST_MASK_WIDTH"); |
5ea47806 | 777 | if ( event.m_item.m_mask & wxLIST_MASK_FORMAT ) |
efe23391 | 778 | msg << _T(" wxLIST_MASK_WIDTH"); |
5ea47806 VZ |
779 | |
780 | if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) | |
781 | { | |
efe23391 | 782 | event.m_item.m_text = _T("My callback text"); |
5ea47806 | 783 | } |
c41ea66a VZ |
784 | |
785 | wxLogMessage(msg); | |
457814b5 JS |
786 | } |
787 | ||
efbb7287 | 788 | void MyListCtrl::OnSetInfo(wxListEvent& event) |
457814b5 | 789 | { |
c41ea66a | 790 | LogEvent(event, _T("OnSetInfo")); |
457814b5 JS |
791 | } |
792 | ||
74b31181 | 793 | void MyListCtrl::OnSelected(wxListEvent& event) |
457814b5 | 794 | { |
c41ea66a | 795 | LogEvent(event, _T("OnSelected")); |
457814b5 | 796 | |
40779a03 | 797 | if ( GetWindowStyle() & wxLC_REPORT ) |
74b31181 | 798 | { |
40779a03 VZ |
799 | wxListItem info; |
800 | info.m_itemId = event.m_itemIndex; | |
801 | info.m_col = 1; | |
802 | info.m_mask = wxLIST_MASK_TEXT; | |
803 | if ( GetItem(info) ) | |
804 | { | |
4acb6ca6 | 805 | wxLogMessage(wxT("Value of the 2nd field of the selected item: %s"), |
c41ea66a | 806 | info.m_text.c_str()); |
40779a03 VZ |
807 | } |
808 | else | |
809 | { | |
4acb6ca6 | 810 | wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed")); |
40779a03 | 811 | } |
74b31181 | 812 | } |
457814b5 JS |
813 | } |
814 | ||
efbb7287 | 815 | void MyListCtrl::OnDeselected(wxListEvent& event) |
457814b5 | 816 | { |
c41ea66a | 817 | LogEvent(event, _T("OnDeselected")); |
457814b5 JS |
818 | } |
819 | ||
efbb7287 | 820 | void MyListCtrl::OnActivated(wxListEvent& event) |
435fe83e | 821 | { |
c41ea66a | 822 | LogEvent(event, _T("OnActivated")); |
435fe83e RR |
823 | } |
824 | ||
0ddefeb0 VZ |
825 | void MyListCtrl::OnFocused(wxListEvent& event) |
826 | { | |
827 | LogEvent(event, _T("OnFocused")); | |
27770773 VZ |
828 | |
829 | event.Skip(); | |
0ddefeb0 VZ |
830 | } |
831 | ||
8e1d4f96 | 832 | void MyListCtrl::OnListKeyDown(wxListEvent& event) |
457814b5 | 833 | { |
2936eaf0 | 834 | switch ( event.GetKeyCode() ) |
5cd89174 | 835 | { |
2d33aec9 VZ |
836 | case 'c': // colorize |
837 | case 'C': | |
6c02c329 VZ |
838 | { |
839 | wxListItem info; | |
840 | info.m_itemId = event.GetIndex(); | |
841 | GetItem(info); | |
842 | ||
843 | wxListItemAttr *attr = info.GetAttributes(); | |
844 | if ( !attr || !attr->HasTextColour() ) | |
845 | { | |
846 | info.SetTextColour(*wxCYAN); | |
847 | ||
848 | SetItem(info); | |
2d33aec9 VZ |
849 | |
850 | RefreshItem(info.m_itemId); | |
6c02c329 VZ |
851 | } |
852 | } | |
853 | break; | |
854 | ||
2d33aec9 VZ |
855 | case 'n': // next |
856 | case 'N': | |
857 | { | |
858 | long item = GetNextItem(-1, | |
859 | wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); | |
860 | if ( item++ == GetItemCount() - 1 ) | |
861 | { | |
862 | item = 0; | |
863 | } | |
864 | ||
865 | wxLogMessage(_T("Focusing item %ld"), item); | |
866 | ||
867 | SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); | |
868 | EnsureVisible(item); | |
869 | } | |
870 | break; | |
871 | ||
5cd89174 | 872 | case WXK_DELETE: |
91c6cc0e VZ |
873 | { |
874 | long item = GetNextItem(-1, | |
875 | wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | |
876 | while ( item != -1 ) | |
877 | { | |
878 | DeleteItem(item); | |
879 | ||
880 | wxLogMessage(_T("Item %ld deleted"), item); | |
f6bcfd97 | 881 | |
91c6cc0e VZ |
882 | // -1 because the indices were shifted by DeleteItem() |
883 | item = GetNextItem(item - 1, | |
884 | wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | |
885 | } | |
886 | } | |
5cd89174 VZ |
887 | break; |
888 | ||
889 | case WXK_INSERT: | |
890 | if ( GetWindowStyle() & wxLC_REPORT ) | |
891 | { | |
892 | if ( GetWindowStyle() & wxLC_VIRTUAL ) | |
893 | { | |
894 | SetItemCount(GetItemCount() + 1); | |
895 | } | |
896 | else // !virtual | |
897 | { | |
898 | InsertItemInReportView(event.GetIndex()); | |
899 | } | |
900 | } | |
901 | //else: fall through | |
902 | ||
903 | default: | |
904 | LogEvent(event, _T("OnListKeyDown")); | |
905 | ||
906 | event.Skip(); | |
907 | } | |
f6bcfd97 BP |
908 | } |
909 | ||
910 | void MyListCtrl::OnChar(wxKeyEvent& event) | |
911 | { | |
912 | wxLogMessage(_T("Got char event.")); | |
913 | ||
2d33aec9 VZ |
914 | switch ( event.GetKeyCode() ) |
915 | { | |
916 | case 'n': | |
917 | case 'N': | |
918 | case 'c': | |
919 | case 'C': | |
920 | // these are the keys we process ourselves | |
921 | break; | |
922 | ||
923 | default: | |
924 | event.Skip(); | |
925 | } | |
457814b5 JS |
926 | } |
927 | ||
c41ea66a VZ |
928 | void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName) |
929 | { | |
f6bcfd97 BP |
930 | wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"), |
931 | event.GetIndex(), eventName, | |
932 | event.GetText().c_str(), event.GetData()); | |
c41ea66a | 933 | } |
435fe83e | 934 | |
98ec9dbe VZ |
935 | wxString MyListCtrl::OnGetItemText(long item, long column) const |
936 | { | |
937 | return wxString::Format(_T("Column %ld of item %ld"), column, item); | |
938 | } | |
939 | ||
c71963cd | 940 | int MyListCtrl::OnGetItemImage(long WXUNUSED(item)) const |
98ec9dbe VZ |
941 | { |
942 | return 0; | |
943 | } | |
944 | ||
6c02c329 VZ |
945 | wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const |
946 | { | |
947 | return item % 2 ? NULL : (wxListItemAttr *)&m_attr; | |
948 | } | |
949 | ||
5cd89174 VZ |
950 | void MyListCtrl::InsertItemInReportView(int i) |
951 | { | |
952 | wxString buf; | |
953 | buf.Printf(_T("This is item %d"), i); | |
954 | long tmp = InsertItem(i, buf, 0); | |
955 | SetItemData(tmp, i); | |
956 | ||
957 | buf.Printf(_T("Col 1, item %d"), i); | |
958 | SetItem(i, 1, buf); | |
959 | ||
960 | buf.Printf(_T("Item %d in column 2"), i); | |
961 | SetItem(i, 2, buf); | |
962 | } | |
963 |