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