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