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