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