]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.cpp | |
3 | // Purpose: wxListCtrl sample | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
526954c5 | 9 | // Licence: wxWindows licence |
457814b5 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
457814b5 JS |
12 | // For compilers that support precompilation, includes "wx/wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/wx.h" | |
21 | #endif | |
22 | ||
e7092398 | 23 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
3cb332c1 | 24 | #include "../sample.xpm" |
5f4d35b8 | 25 | #endif |
c41ea66a | 26 | |
e7092398 | 27 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
c41ea66a VZ |
28 | #include "bitmaps/toolbrai.xpm" |
29 | #include "bitmaps/toolchar.xpm" | |
30 | #include "bitmaps/tooldata.xpm" | |
31 | #include "bitmaps/toolnote.xpm" | |
32 | #include "bitmaps/tooltodo.xpm" | |
33 | #include "bitmaps/toolchec.xpm" | |
34 | #include "bitmaps/toolgame.xpm" | |
35 | #include "bitmaps/tooltime.xpm" | |
36 | #include "bitmaps/toolword.xpm" | |
37 | #include "bitmaps/small1.xpm" | |
907789a0 RR |
38 | #endif |
39 | ||
2e8a1588 | 40 | #include "wx/imaglist.h" |
457814b5 | 41 | #include "wx/listctrl.h" |
81278df2 | 42 | #include "wx/timer.h" // for wxStopWatch |
11f26ea0 | 43 | #include "wx/colordlg.h" // for wxGetColourFromUser |
107ff668 | 44 | #include "wx/settings.h" |
2458daa7 | 45 | #include "wx/sysopt.h" |
beb9e8f2 | 46 | #include "wx/numdlg.h" |
11f26ea0 | 47 | |
457814b5 JS |
48 | #include "listtest.h" |
49 | ||
a0d0799b FM |
50 | |
51 | // ---------------------------------------------------------------------------- | |
52 | // Constants and globals | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
b0401bea VZ |
55 | const wxChar *SMALL_VIRTUAL_VIEW_ITEMS[][2] = |
56 | { | |
9a83f860 VZ |
57 | { wxT("Cat"), wxT("meow") }, |
58 | { wxT("Cow"), wxT("moo") }, | |
59 | { wxT("Crow"), wxT("caw") }, | |
60 | { wxT("Dog"), wxT("woof") }, | |
61 | { wxT("Duck"), wxT("quack") }, | |
62 | { wxT("Mouse"), wxT("squeak") }, | |
63 | { wxT("Owl"), wxT("hoo") }, | |
64 | { wxT("Pig"), wxT("oink") }, | |
65 | { wxT("Pigeon"), wxT("coo") }, | |
66 | { wxT("Sheep"), wxT("baaah") }, | |
b0401bea VZ |
67 | }; |
68 | ||
a0d0799b FM |
69 | // number of items in icon/small icon view |
70 | static const int NUM_ICONS = 9; | |
71 | ||
6e2f3084 | 72 | int wxCALLBACK |
d3ca8487 | 73 | MyCompareFunction(wxIntPtr item1, wxIntPtr item2, wxIntPtr WXUNUSED(sortData)) |
a0d0799b FM |
74 | { |
75 | // inverse the order | |
76 | if (item1 < item2) | |
a0d0799b | 77 | return 1; |
c4264a83 VZ |
78 | if (item1 > item2) |
79 | return -1; | |
a0d0799b FM |
80 | |
81 | return 0; | |
82 | } | |
83 | ||
84 | ||
85 | // ---------------------------------------------------------------------------- | |
86 | // MyApp | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | IMPLEMENT_APP(MyApp) | |
90 | ||
91 | // `Main program' equivalent, creating windows and returning main app frame | |
92 | bool MyApp::OnInit() | |
93 | { | |
9e27ff75 FM |
94 | if ( !wxApp::OnInit() ) |
95 | return false; | |
a0d0799b | 96 | |
9e27ff75 FM |
97 | // Create the main frame window |
98 | MyFrame *frame = new MyFrame(wxT("wxListCtrl Test")); | |
a0d0799b | 99 | |
9e27ff75 FM |
100 | // Show the frame |
101 | frame->Show(true); | |
a0d0799b | 102 | |
9e27ff75 | 103 | return true; |
a0d0799b FM |
104 | } |
105 | ||
106 | ||
107 | ||
108 | // ---------------------------------------------------------------------------- | |
109 | // MyFrame | |
110 | // ---------------------------------------------------------------------------- | |
b0401bea | 111 | |
457814b5 | 112 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
98ec9dbe VZ |
113 | EVT_SIZE(MyFrame::OnSize) |
114 | ||
5ea47806 VZ |
115 | EVT_MENU(LIST_QUIT, MyFrame::OnQuit) |
116 | EVT_MENU(LIST_ABOUT, MyFrame::OnAbout) | |
117 | EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView) | |
118 | EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView) | |
119 | EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView) | |
120 | EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView) | |
121 | EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView) | |
122 | EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView) | |
98ec9dbe | 123 | EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView) |
b0401bea | 124 | EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView) |
98ec9dbe | 125 | |
beb9e8f2 VZ |
126 | EVT_MENU(LIST_SET_ITEMS_COUNT, MyFrame::OnSetItemsCount) |
127 | ||
6ef2b230 | 128 | EVT_MENU(LIST_GOTO, MyFrame::OnGoTo) |
88b792af | 129 | EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast) |
58b3bdc9 | 130 | EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel) |
5ea47806 VZ |
131 | EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll) |
132 | EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll) | |
bec0a261 | 133 | EVT_MENU(LIST_DELETE, MyFrame::OnDelete) |
cf1dfa6b | 134 | EVT_MENU(LIST_ADD, MyFrame::OnAdd) |
efe23391 | 135 | EVT_MENU(LIST_EDIT, MyFrame::OnEdit) |
5ea47806 | 136 | EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll) |
fa5f6926 | 137 | EVT_MENU(LIST_SORT, MyFrame::OnSort) |
11f26ea0 VZ |
138 | EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour) |
139 | EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour) | |
0ee169da | 140 | EVT_MENU(LIST_ROW_LINES, MyFrame::OnSetRowLines) |
7b848b0d | 141 | EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel) |
f6bcfd97 | 142 | EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo) |
b54e41c5 | 143 | EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo) |
929b7901 | 144 | EVT_MENU(LIST_SHOW_VIEW_RECT, MyFrame::OnShowViewRect) |
80cc5fc7 VZ |
145 | #ifdef wxHAS_LISTCTRL_COLUMN_ORDER |
146 | EVT_MENU(LIST_SET_COL_ORDER, MyFrame::OnSetColOrder) | |
147 | EVT_MENU(LIST_GET_COL_ORDER, MyFrame::OnGetColOrder) | |
148 | #endif // wxHAS_LISTCTRL_COLUMN_ORDER | |
c5c528fc VZ |
149 | EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze) |
150 | EVT_MENU(LIST_THAW, MyFrame::OnThaw) | |
494ab5de | 151 | EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines) |
1bab3627 | 152 | EVT_MENU(LIST_TOGGLE_HEADER, MyFrame::OnToggleHeader) |
d34d31f6 | 153 | EVT_MENU(LIST_TOGGLE_BELL, MyFrame::OnToggleBell) |
8a3f03ff | 154 | #ifdef __WXOSX__ |
2458daa7 | 155 | EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric) |
8a3f03ff | 156 | #endif // __WXOSX__ |
beb9e8f2 | 157 | EVT_MENU(LIST_FIND, MyFrame::OnFind) |
98ec9dbe | 158 | |
1bab3627 VZ |
159 | EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateUIEnableInReport) |
160 | EVT_UPDATE_UI(LIST_TOGGLE_HEADER, MyFrame::OnUpdateUIEnableInReport) | |
161 | ||
5f4d35b8 | 162 | EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel) |
1bab3627 | 163 | EVT_UPDATE_UI(LIST_TOGGLE_HEADER, MyFrame::OnUpdateToggleHeader) |
0ee169da | 164 | EVT_UPDATE_UI(LIST_ROW_LINES, MyFrame::OnUpdateRowLines) |
457814b5 JS |
165 | END_EVENT_TABLE() |
166 | ||
457814b5 | 167 | // My frame constructor |
107ff668 | 168 | MyFrame::MyFrame(const wxChar *title) |
9e27ff75 | 169 | : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600, 500)) |
457814b5 | 170 | { |
b0401bea VZ |
171 | m_listCtrl = NULL; |
172 | m_logWindow = NULL; | |
173 | m_smallVirtual = false; | |
beb9e8f2 | 174 | m_numListItems = 10; |
c41ea66a VZ |
175 | |
176 | // Give it an icon | |
3cb332c1 | 177 | SetIcon(wxICON(sample)); |
c41ea66a VZ |
178 | |
179 | // Make an image list containing large icons | |
1550e402 WS |
180 | m_imageListNormal = new wxImageList(32, 32, true); |
181 | m_imageListSmall = new wxImageList(16, 16, true); | |
c41ea66a | 182 | |
c1a9bcfb | 183 | #ifdef wxHAS_IMAGES_IN_RESOURCES |
9a83f860 VZ |
184 | m_imageListNormal->Add( wxIcon(wxT("icon1"), wxBITMAP_TYPE_ICO_RESOURCE) ); |
185 | m_imageListNormal->Add( wxIcon(wxT("icon2"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
186 | m_imageListNormal->Add( wxIcon(wxT("icon3"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
187 | m_imageListNormal->Add( wxIcon(wxT("icon4"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
188 | m_imageListNormal->Add( wxIcon(wxT("icon5"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
189 | m_imageListNormal->Add( wxIcon(wxT("icon6"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
190 | m_imageListNormal->Add( wxIcon(wxT("icon7"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
191 | m_imageListNormal->Add( wxIcon(wxT("icon8"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
192 | m_imageListNormal->Add( wxIcon(wxT("icon9"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
193 | ||
194 | m_imageListSmall->Add( wxIcon(wxT("iconsmall"), wxBITMAP_TYPE_ICO_RESOURCE) ); | |
c41ea66a VZ |
195 | |
196 | #else | |
197 | m_imageListNormal->Add( wxIcon( toolbrai_xpm ) ); | |
198 | m_imageListNormal->Add( wxIcon( toolchar_xpm ) ); | |
199 | m_imageListNormal->Add( wxIcon( tooldata_xpm ) ); | |
200 | m_imageListNormal->Add( wxIcon( toolnote_xpm ) ); | |
201 | m_imageListNormal->Add( wxIcon( tooltodo_xpm ) ); | |
202 | m_imageListNormal->Add( wxIcon( toolchec_xpm ) ); | |
203 | m_imageListNormal->Add( wxIcon( toolgame_xpm ) ); | |
204 | m_imageListNormal->Add( wxIcon( tooltime_xpm ) ); | |
205 | m_imageListNormal->Add( wxIcon( toolword_xpm ) ); | |
206 | ||
207 | m_imageListSmall->Add( wxIcon( small1_xpm) ); | |
208 | #endif | |
209 | ||
210 | // Make a menubar | |
211 | wxMenu *menuFile = new wxMenu; | |
9a83f860 | 212 | menuFile->Append(LIST_ABOUT, wxT("&About")); |
c41ea66a | 213 | menuFile->AppendSeparator(); |
9a83f860 | 214 | menuFile->Append(LIST_QUIT, wxT("E&xit\tAlt-X")); |
c41ea66a VZ |
215 | |
216 | wxMenu *menuView = new wxMenu; | |
9a83f860 VZ |
217 | menuView->Append(LIST_LIST_VIEW, wxT("&List view\tF1")); |
218 | menuView->Append(LIST_REPORT_VIEW, wxT("&Report view\tF2")); | |
219 | menuView->Append(LIST_ICON_VIEW, wxT("&Icon view\tF3")); | |
220 | menuView->Append(LIST_ICON_TEXT_VIEW, wxT("Icon view with &text\tF4")); | |
221 | menuView->Append(LIST_SMALL_ICON_VIEW, wxT("&Small icon view\tF5")); | |
222 | menuView->Append(LIST_SMALL_ICON_TEXT_VIEW, wxT("Small icon &view with text\tF6")); | |
223 | menuView->Append(LIST_VIRTUAL_VIEW, wxT("&Virtual view\tF7")); | |
224 | menuView->Append(LIST_SMALL_VIRTUAL_VIEW, wxT("Small virtual vie&w\tF8")); | |
beb9e8f2 VZ |
225 | menuView->AppendSeparator(); |
226 | menuView->Append(LIST_SET_ITEMS_COUNT, "Set &number of items"); | |
227 | #ifdef __WXOSX__ | |
228 | menuView->AppendSeparator(); | |
9a83f860 | 229 | menuView->AppendCheckItem(LIST_MAC_USE_GENERIC, wxT("Mac: Use Generic Control")); |
2458daa7 | 230 | #endif |
c41ea66a VZ |
231 | |
232 | wxMenu *menuList = new wxMenu; | |
9a83f860 VZ |
233 | menuList->Append(LIST_GOTO, wxT("&Go to item #3\tCtrl-3")); |
234 | menuList->Append(LIST_FOCUS_LAST, wxT("&Make last item current\tCtrl-L")); | |
235 | menuList->Append(LIST_TOGGLE_FIRST, wxT("To&ggle first item\tCtrl-G")); | |
236 | menuList->Append(LIST_DESELECT_ALL, wxT("&Deselect All\tCtrl-D")); | |
237 | menuList->Append(LIST_SELECT_ALL, wxT("S&elect All\tCtrl-A")); | |
b54e41c5 | 238 | menuList->AppendSeparator(); |
9a83f860 VZ |
239 | menuList->Append(LIST_SHOW_COL_INFO, wxT("Show &column info\tCtrl-C")); |
240 | menuList->Append(LIST_SHOW_SEL_INFO, wxT("Show &selected items\tCtrl-S")); | |
241 | menuList->Append(LIST_SHOW_VIEW_RECT, wxT("Show &view rect")); | |
80cc5fc7 | 242 | #ifdef wxHAS_LISTCTRL_COLUMN_ORDER |
9a83f860 VZ |
243 | menuList->Append(LIST_SET_COL_ORDER, wxT("Se&t columns order\tShift-Ctrl-O")); |
244 | menuList->Append(LIST_GET_COL_ORDER, wxT("Sho&w columns order\tCtrl-O")); | |
80cc5fc7 | 245 | #endif // wxHAS_LISTCTRL_COLUMN_ORDER |
c41ea66a | 246 | menuList->AppendSeparator(); |
9a83f860 | 247 | menuList->Append(LIST_SORT, wxT("Sor&t\tCtrl-T")); |
beb9e8f2 | 248 | menuList->Append(LIST_FIND, "Test Find() performance"); |
c41ea66a | 249 | menuList->AppendSeparator(); |
9a83f860 VZ |
250 | menuList->Append(LIST_ADD, wxT("&Append an item\tCtrl-P")); |
251 | menuList->Append(LIST_EDIT, wxT("&Edit the item\tCtrl-E")); | |
252 | menuList->Append(LIST_DELETE, wxT("&Delete first item\tCtrl-X")); | |
253 | menuList->Append(LIST_DELETE_ALL, wxT("Delete &all items")); | |
c41ea66a | 254 | menuList->AppendSeparator(); |
9a83f860 VZ |
255 | menuList->Append(LIST_FREEZE, wxT("Free&ze\tCtrl-Z")); |
256 | menuList->Append(LIST_THAW, wxT("Tha&w\tCtrl-W")); | |
c5c528fc | 257 | menuList->AppendSeparator(); |
9a83f860 | 258 | menuList->AppendCheckItem(LIST_TOGGLE_LINES, wxT("Toggle &lines\tCtrl-I")); |
1bab3627 VZ |
259 | menuList->AppendCheckItem(LIST_TOGGLE_MULTI_SEL, |
260 | wxT("&Multiple selection\tCtrl-M")); | |
261 | menuList->Check(LIST_TOGGLE_MULTI_SEL, true); | |
262 | menuList->AppendCheckItem(LIST_TOGGLE_HEADER, "Toggle &header\tCtrl-H"); | |
263 | menuList->Check(LIST_TOGGLE_HEADER, true); | |
d34d31f6 | 264 | menuList->AppendCheckItem(LIST_TOGGLE_BELL, "Toggle &bell on no match"); |
c41ea66a VZ |
265 | |
266 | wxMenu *menuCol = new wxMenu; | |
9a83f860 VZ |
267 | menuCol->Append(LIST_SET_FG_COL, wxT("&Foreground colour...")); |
268 | menuCol->Append(LIST_SET_BG_COL, wxT("&Background colour...")); | |
0ee169da | 269 | menuCol->AppendCheckItem(LIST_ROW_LINES, wxT("Alternating colours")); |
c41ea66a VZ |
270 | |
271 | wxMenuBar *menubar = new wxMenuBar; | |
9a83f860 VZ |
272 | menubar->Append(menuFile, wxT("&File")); |
273 | menubar->Append(menuView, wxT("&View")); | |
274 | menubar->Append(menuList, wxT("&List")); | |
275 | menubar->Append(menuCol, wxT("&Colour")); | |
c41ea66a VZ |
276 | SetMenuBar(menubar); |
277 | ||
1550e402 WS |
278 | m_panel = new wxPanel(this, wxID_ANY); |
279 | m_logWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, | |
c41ea66a | 280 | wxDefaultPosition, wxDefaultSize, |
e1641772 | 281 | wxTE_READONLY | wxTE_MULTILINE | wxSUNKEN_BORDER); |
c41ea66a VZ |
282 | |
283 | m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow)); | |
284 | ||
776a33cf | 285 | RecreateList(wxLC_REPORT | wxLC_SINGLE_SEL); |
a0d0799b | 286 | |
9e27ff75 FM |
287 | #ifdef __WXMSW__ |
288 | // this is useful to know specially when debugging :) | |
ce00f59b | 289 | wxLogMessage("Your version of comctl32.dll is: %d", |
9e27ff75 FM |
290 | wxApp::GetComCtl32Version()); |
291 | #endif | |
a0d0799b | 292 | |
8520f137 | 293 | #if wxUSE_STATUSBAR |
e1641772 | 294 | CreateStatusBar(); |
8520f137 | 295 | #endif // wxUSE_STATUSBAR |
457814b5 JS |
296 | } |
297 | ||
11f26ea0 | 298 | MyFrame::~MyFrame() |
457814b5 | 299 | { |
c41ea66a VZ |
300 | delete wxLog::SetActiveTarget(m_logOld); |
301 | ||
302 | delete m_imageListNormal; | |
303 | delete m_imageListSmall; | |
457814b5 JS |
304 | } |
305 | ||
98ec9dbe | 306 | void MyFrame::OnSize(wxSizeEvent& event) |
07bf769e VZ |
307 | { |
308 | DoSize(); | |
309 | ||
310 | event.Skip(); | |
311 | } | |
312 | ||
313 | void MyFrame::DoSize() | |
457814b5 | 314 | { |
98ec9dbe VZ |
315 | if ( !m_logWindow ) |
316 | return; | |
457814b5 | 317 | |
98ec9dbe VZ |
318 | wxSize size = GetClientSize(); |
319 | wxCoord y = (2*size.y)/3; | |
9e27ff75 | 320 | m_listCtrl->SetSize(0, 0, size.x, y); |
2a0c05eb | 321 | m_logWindow->SetSize(0, y + 1, size.x, size.y - y -1); |
57246713 KB |
322 | } |
323 | ||
68457180 VZ |
324 | bool MyFrame::CheckNonVirtual() const |
325 | { | |
326 | if ( !m_listCtrl->HasFlag(wxLC_VIRTUAL) ) | |
327 | return true; | |
328 | ||
329 | // "this" == whatever | |
9a83f860 | 330 | wxLogWarning(wxT("Can't do this in virtual view, sorry.")); |
68457180 VZ |
331 | |
332 | return false; | |
333 | } | |
334 | ||
98ec9dbe | 335 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
57246713 | 336 | { |
1550e402 | 337 | Close(true); |
57246713 KB |
338 | } |
339 | ||
b0d77f43 | 340 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 341 | { |
9a83f860 | 342 | wxMessageDialog dialog(this, wxT("List test sample\nJulian Smart (c) 1997"), |
87f0b132 | 343 | wxT("About list test")); |
457814b5 | 344 | |
5ea47806 | 345 | dialog.ShowModal(); |
457814b5 JS |
346 | } |
347 | ||
c71963cd | 348 | void MyFrame::OnFreeze(wxCommandEvent& WXUNUSED(event)) |
c5c528fc | 349 | { |
9a83f860 | 350 | wxLogMessage(wxT("Freezing the control")); |
c5c528fc VZ |
351 | |
352 | m_listCtrl->Freeze(); | |
353 | } | |
354 | ||
c71963cd | 355 | void MyFrame::OnThaw(wxCommandEvent& WXUNUSED(event)) |
c5c528fc | 356 | { |
9a83f860 | 357 | wxLogMessage(wxT("Thawing the control")); |
c5c528fc VZ |
358 | |
359 | m_listCtrl->Thaw(); | |
360 | } | |
361 | ||
494ab5de VZ |
362 | void MyFrame::OnToggleLines(wxCommandEvent& event) |
363 | { | |
364 | m_listCtrl->SetSingleStyle(wxLC_HRULES | wxLC_VRULES, event.IsChecked()); | |
365 | } | |
366 | ||
1bab3627 VZ |
367 | void MyFrame::OnToggleHeader(wxCommandEvent& event) |
368 | { | |
369 | wxLogMessage("%s the header", event.IsChecked() ? "Showing" : "Hiding"); | |
370 | ||
371 | m_listCtrl->ToggleWindowStyle(wxLC_NO_HEADER); | |
372 | } | |
373 | ||
d34d31f6 VZ |
374 | void MyFrame::OnToggleBell(wxCommandEvent& event) |
375 | { | |
376 | m_listCtrl->EnableBellOnNoMatch(event.IsChecked()); | |
377 | } | |
378 | ||
8a3f03ff VZ |
379 | #ifdef __WXOSX__ |
380 | ||
2458daa7 KO |
381 | void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event) |
382 | { | |
383 | wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), event.IsChecked()); | |
384 | } | |
385 | ||
8a3f03ff VZ |
386 | #endif // __WXOSX__ |
387 | ||
6ef2b230 VZ |
388 | void MyFrame::OnGoTo(wxCommandEvent& WXUNUSED(event)) |
389 | { | |
390 | long index = 3; | |
391 | m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); | |
392 | ||
393 | long sel = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, | |
394 | wxLIST_STATE_SELECTED); | |
395 | if ( sel != -1 ) | |
396 | m_listCtrl->SetItemState(sel, 0, wxLIST_STATE_SELECTED); | |
397 | m_listCtrl->SetItemState(index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | |
398 | } | |
399 | ||
88b792af VZ |
400 | void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event)) |
401 | { | |
402 | long index = m_listCtrl->GetItemCount() - 1; | |
403 | if ( index == -1 ) | |
404 | { | |
405 | return; | |
406 | } | |
407 | ||
408 | m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); | |
409 | m_listCtrl->EnsureVisible(index); | |
410 | } | |
411 | ||
58b3bdc9 VZ |
412 | void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event)) |
413 | { | |
95f913a9 | 414 | m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); |
58b3bdc9 VZ |
415 | } |
416 | ||
c4771147 KB |
417 | void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event)) |
418 | { | |
68457180 VZ |
419 | if ( !CheckNonVirtual() ) |
420 | return; | |
421 | ||
5ea47806 VZ |
422 | int n = m_listCtrl->GetItemCount(); |
423 | for (int i = 0; i < n; i++) | |
424 | m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED); | |
c4771147 KB |
425 | } |
426 | ||
427 | void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
428 | { | |
68457180 VZ |
429 | if ( !CheckNonVirtual() ) |
430 | return; | |
431 | ||
5ea47806 VZ |
432 | int n = m_listCtrl->GetItemCount(); |
433 | for (int i = 0; i < n; i++) | |
434 | m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); | |
c4771147 KB |
435 | } |
436 | ||
776a33cf VZ |
437 | // ---------------------------------------------------------------------------- |
438 | // changing listctrl modes | |
439 | // ---------------------------------------------------------------------------- | |
440 | ||
441 | void MyFrame::RecreateList(long flags, bool withText) | |
457814b5 | 442 | { |
776a33cf VZ |
443 | // we could avoid recreating it if we don't set/clear the wxLC_VIRTUAL |
444 | // style, but it is more trouble to do it than not | |
445 | #if 0 | |
446 | if ( !m_listCtrl || ((flags & wxLC_VIRTUAL) != | |
447 | (m_listCtrl->GetWindowStyleFlag() & wxLC_VIRTUAL)) ) | |
448 | #endif | |
449 | { | |
450 | delete m_listCtrl; | |
451 | ||
2b5f62a0 | 452 | m_listCtrl = new MyListCtrl(m_panel, LIST_CTRL, |
776a33cf VZ |
453 | wxDefaultPosition, wxDefaultSize, |
454 | flags | | |
a91a64da | 455 | wxBORDER_THEME | wxLC_EDIT_LABELS); |
776a33cf VZ |
456 | |
457 | switch ( flags & wxLC_MASK_TYPE ) | |
458 | { | |
459 | case wxLC_LIST: | |
460 | InitWithListItems(); | |
461 | break; | |
462 | ||
463 | case wxLC_ICON: | |
464 | InitWithIconItems(withText); | |
465 | break; | |
466 | ||
467 | case wxLC_SMALL_ICON: | |
1550e402 | 468 | InitWithIconItems(withText, true); |
776a33cf VZ |
469 | break; |
470 | ||
471 | case wxLC_REPORT: | |
472 | if ( flags & wxLC_VIRTUAL ) | |
473 | InitWithVirtualItems(); | |
474 | else | |
475 | InitWithReportItems(); | |
476 | break; | |
477 | ||
478 | default: | |
9a83f860 | 479 | wxFAIL_MSG( wxT("unknown listctrl mode") ); |
776a33cf | 480 | } |
d34d31f6 VZ |
481 | |
482 | wxMenuBar* const mb = GetMenuBar(); | |
483 | if ( mb ) | |
484 | m_listCtrl->EnableBellOnNoMatch(mb->IsChecked(LIST_TOGGLE_BELL)); | |
776a33cf VZ |
485 | } |
486 | ||
07bf769e | 487 | DoSize(); |
776a33cf | 488 | |
0ee169da VZ |
489 | GetMenuBar()->Check(LIST_ROW_LINES, false); |
490 | ||
0180dad6 | 491 | m_logWindow->Clear(); |
776a33cf | 492 | } |
95bf655c | 493 | |
776a33cf VZ |
494 | void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event)) |
495 | { | |
496 | RecreateList(wxLC_LIST); | |
497 | } | |
457814b5 | 498 | |
776a33cf VZ |
499 | void MyFrame::InitWithListItems() |
500 | { | |
beb9e8f2 | 501 | for ( int i = 0; i < m_numListItems; i++ ) |
0180dad6 | 502 | { |
9a83f860 | 503 | m_listCtrl->InsertItem(i, wxString::Format(wxT("Item %d"), i)); |
0180dad6 | 504 | } |
457814b5 JS |
505 | } |
506 | ||
b0d77f43 | 507 | void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 508 | { |
776a33cf VZ |
509 | RecreateList(wxLC_REPORT); |
510 | } | |
5ea47806 | 511 | |
776a33cf VZ |
512 | void MyFrame::InitWithReportItems() |
513 | { | |
c41ea66a | 514 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); |
457814b5 | 515 | |
caa20b1e VZ |
516 | // note that under MSW for SetColumnWidth() to work we need to create the |
517 | // items with images initially even if we specify dummy image id | |
6f806543 | 518 | wxListItem itemCol; |
9a83f860 | 519 | itemCol.SetText(wxT("Column 1")); |
caa20b1e | 520 | itemCol.SetImage(-1); |
6f806543 | 521 | m_listCtrl->InsertColumn(0, itemCol); |
caa20b1e | 522 | |
9a83f860 | 523 | itemCol.SetText(wxT("Column 2")); |
caa20b1e | 524 | itemCol.SetAlign(wxLIST_FORMAT_CENTRE); |
6f806543 | 525 | m_listCtrl->InsertColumn(1, itemCol); |
caa20b1e | 526 | |
9a83f860 | 527 | itemCol.SetText(wxT("Column 3")); |
caa20b1e | 528 | itemCol.SetAlign(wxLIST_FORMAT_RIGHT); |
6f806543 | 529 | m_listCtrl->InsertColumn(2, itemCol); |
0180dad6 | 530 | |
81278df2 VZ |
531 | // to speed up inserting we hide the control temporarily |
532 | m_listCtrl->Hide(); | |
533 | ||
534 | wxStopWatch sw; | |
535 | ||
beb9e8f2 | 536 | for ( int i = 0; i < m_numListItems; i++ ) |
0180dad6 | 537 | { |
5cd89174 | 538 | m_listCtrl->InsertItemInReportView(i); |
0180dad6 | 539 | } |
bdc72a22 | 540 | |
9a83f860 | 541 | m_logWindow->WriteText(wxString::Format(wxT("%d items inserted in %ldms\n"), |
beb9e8f2 | 542 | m_numListItems, sw.Time())); |
81278df2 VZ |
543 | m_listCtrl->Show(); |
544 | ||
f6b77239 | 545 | // we leave all mask fields to 0 and only change the colour |
bdc72a22 VZ |
546 | wxListItem item; |
547 | item.m_itemId = 0; | |
0530737d | 548 | item.SetTextColour(*wxRED); |
bdc72a22 VZ |
549 | m_listCtrl->SetItem( item ); |
550 | ||
551 | item.m_itemId = 2; | |
d62228a6 | 552 | item.SetTextColour(*wxGREEN); |
bdc72a22 | 553 | m_listCtrl->SetItem( item ); |
d62228a6 | 554 | item.m_itemId = 4; |
bdc72a22 | 555 | item.SetTextColour(*wxLIGHT_GREY); |
d62228a6 VZ |
556 | item.SetFont(*wxITALIC_FONT); |
557 | item.SetBackgroundColour(*wxRED); | |
bdc72a22 | 558 | m_listCtrl->SetItem( item ); |
5ea47806 | 559 | |
d62228a6 | 560 | m_listCtrl->SetTextColour(*wxBLUE); |
d62228a6 | 561 | |
0180dad6 RR |
562 | m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); |
563 | m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); | |
564 | m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE ); | |
35c2acd4 | 565 | |
06db67bc RD |
566 | // Set images in columns |
567 | m_listCtrl->SetItemColumnImage(1, 1, 0); | |
568 | ||
569 | wxListItem info; | |
570 | info.SetImage(0); | |
571 | info.SetId(3); | |
572 | info.SetColumn(2); | |
573 | m_listCtrl->SetItem(info); | |
574 | ||
35c2acd4 MW |
575 | // test SetItemFont too |
576 | m_listCtrl->SetItemFont(0, *wxITALIC_FONT); | |
457814b5 JS |
577 | } |
578 | ||
776a33cf | 579 | void MyFrame::InitWithIconItems(bool withText, bool sameIcon) |
457814b5 | 580 | { |
c41ea66a VZ |
581 | m_listCtrl->SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); |
582 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); | |
457814b5 | 583 | |
152e8878 | 584 | for ( int i = 0; i < NUM_ICONS; i++ ) |
5ea47806 | 585 | { |
152e8878 | 586 | int image = sameIcon ? 0 : i; |
776a33cf VZ |
587 | |
588 | if ( withText ) | |
589 | { | |
4d0c2308 VZ |
590 | // Make labels of different widths to test the layout. |
591 | wxString label; | |
592 | if ( !(i % 5) ) | |
593 | label.Printf("Longer label %d", i); | |
594 | else | |
595 | label.Printf("Label %d", i); | |
596 | ||
597 | m_listCtrl->InsertItem(i, label, image); | |
776a33cf VZ |
598 | } |
599 | else | |
600 | { | |
601 | m_listCtrl->InsertItem(i, image); | |
602 | } | |
5ea47806 | 603 | } |
457814b5 JS |
604 | } |
605 | ||
776a33cf | 606 | void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 607 | { |
1550e402 | 608 | RecreateList(wxLC_ICON, false); |
776a33cf | 609 | } |
457814b5 | 610 | |
776a33cf VZ |
611 | void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event)) |
612 | { | |
613 | RecreateList(wxLC_ICON); | |
457814b5 JS |
614 | } |
615 | ||
b0d77f43 | 616 | void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 617 | { |
1550e402 | 618 | RecreateList(wxLC_SMALL_ICON, false); |
457814b5 JS |
619 | } |
620 | ||
b0d77f43 | 621 | void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 622 | { |
776a33cf | 623 | RecreateList(wxLC_SMALL_ICON); |
5ea47806 VZ |
624 | } |
625 | ||
98ec9dbe VZ |
626 | void MyFrame::OnVirtualView(wxCommandEvent& WXUNUSED(event)) |
627 | { | |
b0401bea VZ |
628 | m_smallVirtual = false; |
629 | RecreateList(wxLC_REPORT | wxLC_VIRTUAL); | |
630 | } | |
631 | ||
632 | void MyFrame::OnSmallVirtualView(wxCommandEvent& WXUNUSED(event)) | |
633 | { | |
634 | m_smallVirtual = true; | |
776a33cf VZ |
635 | RecreateList(wxLC_REPORT | wxLC_VIRTUAL); |
636 | } | |
98ec9dbe | 637 | |
beb9e8f2 VZ |
638 | void MyFrame::OnSetItemsCount(wxCommandEvent& WXUNUSED(event)) |
639 | { | |
640 | int numItems = wxGetNumberFromUser | |
641 | ( | |
642 | "Enter the initial number of items for " | |
643 | "the list and report views", | |
644 | "Number of items:", | |
645 | "wxWidgets wxListCtrl sample", | |
646 | m_numListItems, | |
647 | 0, | |
648 | 10000, | |
649 | this | |
650 | ); | |
651 | if ( numItems == -1 || numItems == m_numListItems ) | |
652 | return; | |
653 | ||
654 | m_numListItems = numItems; | |
655 | ||
656 | if ( m_listCtrl->HasFlag(wxLC_REPORT) && | |
657 | !m_listCtrl->HasFlag(wxLC_VIRTUAL) ) | |
658 | RecreateList(wxLC_REPORT); | |
659 | else if ( m_listCtrl->HasFlag(wxLC_LIST) ) | |
660 | RecreateList(wxLC_LIST); | |
661 | } | |
662 | ||
776a33cf VZ |
663 | void MyFrame::InitWithVirtualItems() |
664 | { | |
27770773 VZ |
665 | m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL); |
666 | ||
b0401bea VZ |
667 | if ( m_smallVirtual ) |
668 | { | |
9a83f860 VZ |
669 | m_listCtrl->InsertColumn(0, wxT("Animal")); |
670 | m_listCtrl->InsertColumn(1, wxT("Sound")); | |
b0401bea VZ |
671 | m_listCtrl->SetItemCount(WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS)); |
672 | } | |
673 | else | |
674 | { | |
9a83f860 VZ |
675 | m_listCtrl->InsertColumn(0, wxT("First Column")); |
676 | m_listCtrl->InsertColumn(1, wxT("Second Column")); | |
b0401bea VZ |
677 | m_listCtrl->SetColumnWidth(0, 150); |
678 | m_listCtrl->SetColumnWidth(1, 150); | |
679 | m_listCtrl->SetItemCount(1000000); | |
680 | } | |
98ec9dbe VZ |
681 | } |
682 | ||
fa5f6926 VZ |
683 | void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event)) |
684 | { | |
81278df2 VZ |
685 | wxStopWatch sw; |
686 | ||
fa5f6926 | 687 | m_listCtrl->SortItems(MyCompareFunction, 0); |
81278df2 | 688 | |
9a83f860 | 689 | m_logWindow->WriteText(wxString::Format(wxT("Sorting %d items took %ld ms\n"), |
81278df2 VZ |
690 | m_listCtrl->GetItemCount(), |
691 | sw.Time())); | |
fa5f6926 VZ |
692 | } |
693 | ||
beb9e8f2 VZ |
694 | void MyFrame::OnFind(wxCommandEvent& WXUNUSED(event)) |
695 | { | |
696 | wxStopWatch sw; | |
697 | ||
698 | const int itemCount = m_listCtrl->GetItemCount(); | |
699 | for ( int i = 0; i < itemCount; i++ ) | |
700 | m_listCtrl->FindItem(-1, i); | |
701 | ||
702 | wxLogMessage("Calling Find() for all %d items took %ld ms", | |
703 | itemCount, sw.Time()); | |
704 | } | |
705 | ||
c71963cd | 706 | void MyFrame::OnShowSelInfo(wxCommandEvent& WXUNUSED(event)) |
b54e41c5 VZ |
707 | { |
708 | int selCount = m_listCtrl->GetSelectedItemCount(); | |
9a83f860 | 709 | wxLogMessage(wxT("%d items selected:"), selCount); |
b54e41c5 VZ |
710 | |
711 | // don't show too many items | |
712 | size_t shownCount = 0; | |
713 | ||
714 | long item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, | |
715 | wxLIST_STATE_SELECTED); | |
716 | while ( item != -1 ) | |
717 | { | |
9a83f860 | 718 | wxLogMessage(wxT("\t%ld (%s)"), |
b54e41c5 VZ |
719 | item, m_listCtrl->GetItemText(item).c_str()); |
720 | ||
721 | if ( ++shownCount > 10 ) | |
722 | { | |
9a83f860 | 723 | wxLogMessage(wxT("\t... more selected items snipped...")); |
b54e41c5 VZ |
724 | break; |
725 | } | |
726 | ||
727 | item = m_listCtrl->GetNextItem(item, wxLIST_NEXT_ALL, | |
728 | wxLIST_STATE_SELECTED); | |
729 | } | |
730 | } | |
731 | ||
929b7901 VZ |
732 | void MyFrame::OnShowViewRect(wxCommandEvent& WXUNUSED(event)) |
733 | { | |
734 | const wxRect r = m_listCtrl->GetViewRect(); | |
735 | wxLogMessage("View rect: (%d, %d)-(%d, %d)", | |
736 | r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom()); | |
737 | } | |
738 | ||
80cc5fc7 VZ |
739 | // ---------------------------------------------------------------------------- |
740 | // column order tests | |
741 | // ---------------------------------------------------------------------------- | |
742 | ||
743 | #ifdef wxHAS_LISTCTRL_COLUMN_ORDER | |
744 | ||
745 | static wxString DumpIntArray(const wxArrayInt& a) | |
746 | { | |
747 | wxString s("{ "); | |
748 | const size_t count = a.size(); | |
749 | for ( size_t n = 0; n < count; n++ ) | |
750 | { | |
751 | if ( n ) | |
752 | s += ", "; | |
753 | s += wxString::Format("%lu", (unsigned long)a[n]); | |
754 | } | |
755 | ||
756 | s += " }"; | |
757 | ||
758 | return s; | |
759 | } | |
760 | ||
761 | void MyFrame::OnSetColOrder(wxCommandEvent& WXUNUSED(event)) | |
762 | { | |
763 | wxArrayInt order(3); | |
764 | order[0] = 2; | |
765 | order[1] = 0; | |
766 | order[2] = 1; | |
767 | if ( m_listCtrl->SetColumnsOrder(order) ) | |
43b2d5e7 | 768 | { |
80cc5fc7 | 769 | wxLogMessage("Column order set to %s", DumpIntArray(order)); |
43b2d5e7 | 770 | } |
80cc5fc7 VZ |
771 | } |
772 | ||
773 | void MyFrame::OnGetColOrder(wxCommandEvent& WXUNUSED(event)) | |
774 | { | |
775 | // show what GetColumnsOrder() returns | |
776 | const wxArrayInt order = m_listCtrl->GetColumnsOrder(); | |
777 | wxString msg = "Columns order: " + | |
778 | DumpIntArray(m_listCtrl->GetColumnsOrder()) + "\n"; | |
779 | ||
780 | int n; | |
781 | const int count = m_listCtrl->GetColumnCount(); | |
782 | ||
783 | // show the results of GetColumnOrder() for each column | |
784 | msg += "GetColumnOrder() results:\n"; | |
785 | for ( n = 0; n < count; n++ ) | |
786 | { | |
787 | msg += wxString::Format(" %2d -> %2d\n", | |
788 | n, m_listCtrl->GetColumnOrder(n)); | |
789 | } | |
790 | ||
791 | // and the results of GetColumnIndexFromOrder() too | |
792 | msg += "GetColumnIndexFromOrder() results:\n"; | |
793 | for ( n = 0; n < count; n++ ) | |
794 | { | |
795 | msg += wxString::Format(" %2d -> %2d\n", | |
796 | n, m_listCtrl->GetColumnIndexFromOrder(n)); | |
797 | } | |
798 | ||
799 | wxLogMessage("%s", msg); | |
800 | } | |
801 | ||
802 | #endif // wxHAS_LISTCTRL_COLUMN_ORDER | |
803 | ||
c71963cd | 804 | void MyFrame::OnShowColInfo(wxCommandEvent& WXUNUSED(event)) |
f6bcfd97 BP |
805 | { |
806 | int count = m_listCtrl->GetColumnCount(); | |
4acb6ca6 | 807 | wxLogMessage(wxT("%d columns:"), count); |
f6bcfd97 BP |
808 | for ( int c = 0; c < count; c++ ) |
809 | { | |
4acb6ca6 | 810 | wxLogMessage(wxT("\tcolumn %d has width %d"), c, |
f6bcfd97 BP |
811 | m_listCtrl->GetColumnWidth(c)); |
812 | } | |
813 | } | |
814 | ||
1bab3627 | 815 | void MyFrame::OnUpdateUIEnableInReport(wxUpdateUIEvent& event) |
f6bcfd97 BP |
816 | { |
817 | event.Enable( (m_listCtrl->GetWindowStyleFlag() & wxLC_REPORT) != 0 ); | |
818 | } | |
819 | ||
7b848b0d VZ |
820 | void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event)) |
821 | { | |
7b848b0d VZ |
822 | long flags = m_listCtrl->GetWindowStyleFlag(); |
823 | if ( flags & wxLC_SINGLE_SEL ) | |
776a33cf | 824 | flags &= ~wxLC_SINGLE_SEL; |
7b848b0d | 825 | else |
776a33cf VZ |
826 | flags |= wxLC_SINGLE_SEL; |
827 | ||
4acb6ca6 | 828 | m_logWindow->WriteText(wxString::Format(wxT("Current selection mode: %sle\n"), |
9a83f860 | 829 | (flags & wxLC_SINGLE_SEL) ? wxT("sing") : wxT("multip"))); |
7b848b0d | 830 | |
776a33cf | 831 | RecreateList(flags); |
7b848b0d VZ |
832 | } |
833 | ||
ae403b11 JS |
834 | void MyFrame::OnUpdateToggleMultiSel(wxUpdateUIEvent& event) |
835 | { | |
1bab3627 VZ |
836 | event.Check(!m_listCtrl->HasFlag(wxLC_SINGLE_SEL)); |
837 | } | |
838 | ||
839 | void MyFrame::OnUpdateToggleHeader(wxUpdateUIEvent& event) | |
840 | { | |
841 | event.Check(!m_listCtrl->HasFlag(wxLC_NO_HEADER)); | |
ae403b11 JS |
842 | } |
843 | ||
0ee169da VZ |
844 | void MyFrame::OnUpdateRowLines(wxUpdateUIEvent& event) |
845 | { | |
846 | event.Enable(m_listCtrl->HasFlag(wxLC_VIRTUAL)); | |
847 | } | |
848 | ||
11f26ea0 VZ |
849 | void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event)) |
850 | { | |
851 | m_listCtrl->SetForegroundColour(wxGetColourFromUser(this)); | |
852 | m_listCtrl->Refresh(); | |
853 | } | |
854 | ||
855 | void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event)) | |
856 | { | |
857 | m_listCtrl->SetBackgroundColour(wxGetColourFromUser(this)); | |
858 | m_listCtrl->Refresh(); | |
859 | } | |
860 | ||
0ee169da VZ |
861 | void MyFrame::OnSetRowLines(wxCommandEvent& event) |
862 | { | |
863 | m_listCtrl->EnableAlternateRowColours(event.IsChecked()); | |
864 | m_listCtrl->Refresh(); | |
865 | } | |
866 | ||
cf1dfa6b VZ |
867 | void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event)) |
868 | { | |
9a83f860 | 869 | m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), wxT("Appended item")); |
cf1dfa6b VZ |
870 | } |
871 | ||
efe23391 VZ |
872 | void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event)) |
873 | { | |
747eb0f6 | 874 | // demonstrate cancelling editing: this currently is wxMSW-only |
18625292 | 875 | #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) |
747eb0f6 | 876 | if ( m_listCtrl->GetEditControl() ) |
efe23391 | 877 | { |
747eb0f6 | 878 | m_listCtrl->EndEditLabel(true); |
efe23391 | 879 | } |
747eb0f6 VZ |
880 | else // start editing |
881 | #endif // __WXMSW__ | |
efe23391 | 882 | { |
747eb0f6 VZ |
883 | long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, |
884 | wxLIST_STATE_FOCUSED); | |
885 | ||
886 | if ( itemCur != -1 ) | |
887 | { | |
888 | m_listCtrl->EditLabel(itemCur); | |
889 | } | |
890 | else | |
891 | { | |
892 | m_logWindow->WriteText(wxT("No item to edit")); | |
893 | } | |
efe23391 VZ |
894 | } |
895 | } | |
896 | ||
bec0a261 VZ |
897 | void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event)) |
898 | { | |
899 | if ( m_listCtrl->GetItemCount() ) | |
900 | { | |
901 | m_listCtrl->DeleteItem(0); | |
902 | } | |
903 | else | |
904 | { | |
9a83f860 | 905 | m_logWindow->WriteText(wxT("Nothing to delete")); |
bec0a261 VZ |
906 | } |
907 | } | |
908 | ||
5ea47806 VZ |
909 | void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event)) |
910 | { | |
81278df2 | 911 | wxStopWatch sw; |
5ea47806 | 912 | |
b143cf70 | 913 | int itemCount = m_listCtrl->GetItemCount(); |
fde548e2 | 914 | |
5ea47806 VZ |
915 | m_listCtrl->DeleteAllItems(); |
916 | ||
9a83f860 | 917 | m_logWindow->WriteText(wxString::Format(wxT("Deleting %d items took %ld ms\n"), |
fde548e2 | 918 | itemCount, |
81278df2 | 919 | sw.Time())); |
457814b5 JS |
920 | } |
921 | ||
a0d0799b FM |
922 | |
923 | // ---------------------------------------------------------------------------- | |
457814b5 | 924 | // MyListCtrl |
a0d0799b FM |
925 | // ---------------------------------------------------------------------------- |
926 | ||
927 | BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) | |
928 | EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag) | |
929 | EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag) | |
930 | EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit) | |
931 | EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit) | |
932 | EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem) | |
933 | EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems) | |
934 | EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected) | |
935 | EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) | |
936 | EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) | |
937 | EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) | |
938 | EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused) | |
939 | ||
940 | EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick) | |
941 | EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick) | |
942 | EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag) | |
943 | EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging) | |
944 | EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag) | |
945 | ||
946 | EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint) | |
947 | ||
948 | #if USE_CONTEXT_MENU | |
949 | EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu) | |
950 | #endif | |
951 | EVT_CHAR(MyListCtrl::OnChar) | |
952 | ||
953 | EVT_RIGHT_DOWN(MyListCtrl::OnRightClick) | |
954 | END_EVENT_TABLE() | |
457814b5 | 955 | |
614391dc VZ |
956 | void MyListCtrl::OnCacheHint(wxListEvent& event) |
957 | { | |
4acb6ca6 | 958 | wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"), |
614391dc VZ |
959 | event.GetCacheFrom(), event.GetCacheTo() ); |
960 | } | |
961 | ||
6f806543 VZ |
962 | void MyListCtrl::SetColumnImage(int col, int image) |
963 | { | |
964 | wxListItem item; | |
965 | item.SetMask(wxLIST_MASK_IMAGE); | |
966 | item.SetImage(image); | |
967 | SetColumn(col, item); | |
968 | } | |
969 | ||
8636aed8 RR |
970 | void MyListCtrl::OnColClick(wxListEvent& event) |
971 | { | |
6f806543 | 972 | int col = event.GetColumn(); |
f0cf38b7 VZ |
973 | |
974 | // set or unset image | |
4979a56c | 975 | static bool x = false; |
f0cf38b7 VZ |
976 | x = !x; |
977 | SetColumnImage(col, x ? 0 : -1); | |
6f806543 VZ |
978 | |
979 | wxLogMessage( wxT("OnColumnClick at %d."), col ); | |
8636aed8 RR |
980 | } |
981 | ||
11358d39 VZ |
982 | void MyListCtrl::OnColRightClick(wxListEvent& event) |
983 | { | |
6f806543 | 984 | int col = event.GetColumn(); |
62313c27 VZ |
985 | if ( col != -1 ) |
986 | { | |
987 | SetColumnImage(col, -1); | |
988 | } | |
6f806543 | 989 | |
77ace0c5 WS |
990 | // Show popupmenu at position |
991 | wxMenu menu(wxT("Test")); | |
9a83f860 | 992 | menu.Append(LIST_ABOUT, wxT("&About")); |
5f4d35b8 | 993 | PopupMenu(&menu, event.GetPoint()); |
77ace0c5 | 994 | |
11358d39 VZ |
995 | wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() ); |
996 | } | |
997 | ||
2b5f62a0 VZ |
998 | void MyListCtrl::LogColEvent(const wxListEvent& event, const wxChar *name) |
999 | { | |
1000 | const int col = event.GetColumn(); | |
1001 | ||
1002 | wxLogMessage(wxT("%s: column %d (width = %d or %d)."), | |
1003 | name, | |
1004 | col, | |
1005 | event.GetItem().GetWidth(), | |
1006 | GetColumnWidth(col)); | |
1007 | } | |
1008 | ||
11358d39 VZ |
1009 | void MyListCtrl::OnColBeginDrag(wxListEvent& event) |
1010 | { | |
2b5f62a0 | 1011 | LogColEvent( event, wxT("OnColBeginDrag") ); |
355f2407 VZ |
1012 | |
1013 | if ( event.GetColumn() == 0 ) | |
1014 | { | |
9a83f860 | 1015 | wxLogMessage(wxT("Resizing this column shouldn't work.")); |
355f2407 VZ |
1016 | |
1017 | event.Veto(); | |
1018 | } | |
11358d39 VZ |
1019 | } |
1020 | ||
1021 | void MyListCtrl::OnColDragging(wxListEvent& event) | |
1022 | { | |
2b5f62a0 | 1023 | LogColEvent( event, wxT("OnColDragging") ); |
11358d39 VZ |
1024 | } |
1025 | ||
1026 | void MyListCtrl::OnColEndDrag(wxListEvent& event) | |
1027 | { | |
2b5f62a0 | 1028 | LogColEvent( event, wxT("OnColEndDrag") ); |
11358d39 VZ |
1029 | } |
1030 | ||
fd9811b1 | 1031 | void MyListCtrl::OnBeginDrag(wxListEvent& event) |
457814b5 | 1032 | { |
6dc34ebb VZ |
1033 | const wxPoint& pt = event.m_pointDrag; |
1034 | ||
1035 | int flags; | |
1036 | wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."), | |
1037 | pt.x, pt.y, HitTest(pt, flags) ); | |
457814b5 JS |
1038 | } |
1039 | ||
fd9811b1 | 1040 | void MyListCtrl::OnBeginRDrag(wxListEvent& event) |
457814b5 | 1041 | { |
4acb6ca6 | 1042 | wxLogMessage( wxT("OnBeginRDrag at %d,%d."), |
c41ea66a | 1043 | event.m_pointDrag.x, event.m_pointDrag.y ); |
457814b5 JS |
1044 | } |
1045 | ||
fd9811b1 | 1046 | void MyListCtrl::OnBeginLabelEdit(wxListEvent& event) |
457814b5 | 1047 | { |
4acb6ca6 | 1048 | wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str()); |
508b6523 VZ |
1049 | |
1050 | wxTextCtrl * const text = GetEditControl(); | |
1051 | if ( !text ) | |
1052 | { | |
1053 | wxLogMessage("BUG: started to edit but no edit control"); | |
1054 | } | |
1055 | else | |
1056 | { | |
1057 | wxLogMessage("Edit control value: \"%s\"", text->GetValue()); | |
1058 | } | |
457814b5 JS |
1059 | } |
1060 | ||
fd9811b1 | 1061 | void MyListCtrl::OnEndLabelEdit(wxListEvent& event) |
457814b5 | 1062 | { |
1bf37bf5 | 1063 | wxLogMessage( wxT("OnEndLabelEdit: %s"), |
15836000 | 1064 | ( |
a0d0799b FM |
1065 | event.IsEditCancelled() ? |
1066 | wxString("[cancelled]") : | |
15836000 CE |
1067 | event.m_item.m_text |
1068 | ).c_str() | |
1069 | ); | |
457814b5 JS |
1070 | } |
1071 | ||
efbb7287 | 1072 | void MyListCtrl::OnDeleteItem(wxListEvent& event) |
457814b5 | 1073 | { |
9a83f860 | 1074 | LogEvent(event, wxT("OnDeleteItem")); |
a95d5751 | 1075 | wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() ); |
457814b5 JS |
1076 | } |
1077 | ||
c41ea66a | 1078 | void MyListCtrl::OnDeleteAllItems(wxListEvent& event) |
12c1b46a | 1079 | { |
9a83f860 | 1080 | LogEvent(event, wxT("OnDeleteAllItems")); |
12c1b46a RR |
1081 | } |
1082 | ||
74b31181 | 1083 | void MyListCtrl::OnSelected(wxListEvent& event) |
457814b5 | 1084 | { |
9a83f860 | 1085 | LogEvent(event, wxT("OnSelected")); |
457814b5 | 1086 | |
40779a03 | 1087 | if ( GetWindowStyle() & wxLC_REPORT ) |
74b31181 | 1088 | { |
40779a03 VZ |
1089 | wxListItem info; |
1090 | info.m_itemId = event.m_itemIndex; | |
1091 | info.m_col = 1; | |
1092 | info.m_mask = wxLIST_MASK_TEXT; | |
1093 | if ( GetItem(info) ) | |
1094 | { | |
4acb6ca6 | 1095 | wxLogMessage(wxT("Value of the 2nd field of the selected item: %s"), |
c41ea66a | 1096 | info.m_text.c_str()); |
40779a03 VZ |
1097 | } |
1098 | else | |
1099 | { | |
4acb6ca6 | 1100 | wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed")); |
40779a03 | 1101 | } |
74b31181 | 1102 | } |
457814b5 JS |
1103 | } |
1104 | ||
efbb7287 | 1105 | void MyListCtrl::OnDeselected(wxListEvent& event) |
457814b5 | 1106 | { |
9a83f860 | 1107 | LogEvent(event, wxT("OnDeselected")); |
457814b5 JS |
1108 | } |
1109 | ||
efbb7287 | 1110 | void MyListCtrl::OnActivated(wxListEvent& event) |
435fe83e | 1111 | { |
9a83f860 | 1112 | LogEvent(event, wxT("OnActivated")); |
435fe83e RR |
1113 | } |
1114 | ||
0ddefeb0 VZ |
1115 | void MyListCtrl::OnFocused(wxListEvent& event) |
1116 | { | |
9a83f860 | 1117 | LogEvent(event, wxT("OnFocused")); |
27770773 VZ |
1118 | |
1119 | event.Skip(); | |
0ddefeb0 VZ |
1120 | } |
1121 | ||
8e1d4f96 | 1122 | void MyListCtrl::OnListKeyDown(wxListEvent& event) |
457814b5 | 1123 | { |
100f649f VZ |
1124 | long item; |
1125 | ||
d34d31f6 VZ |
1126 | if ( !wxGetKeyState(WXK_SHIFT) ) |
1127 | { | |
1128 | LogEvent(event, wxT("OnListKeyDown")); | |
1129 | event.Skip(); | |
1130 | return; | |
1131 | } | |
1132 | ||
2936eaf0 | 1133 | switch ( event.GetKeyCode() ) |
5cd89174 | 1134 | { |
ebc9b89d | 1135 | case 'C': // colorize |
6c02c329 VZ |
1136 | { |
1137 | wxListItem info; | |
1138 | info.m_itemId = event.GetIndex(); | |
63c95faf VZ |
1139 | if ( info.m_itemId == -1 ) |
1140 | { | |
1141 | // no item | |
1142 | break; | |
1143 | } | |
1144 | ||
6c02c329 VZ |
1145 | GetItem(info); |
1146 | ||
1147 | wxListItemAttr *attr = info.GetAttributes(); | |
1148 | if ( !attr || !attr->HasTextColour() ) | |
1149 | { | |
1150 | info.SetTextColour(*wxCYAN); | |
1151 | ||
1152 | SetItem(info); | |
2d33aec9 VZ |
1153 | |
1154 | RefreshItem(info.m_itemId); | |
6c02c329 VZ |
1155 | } |
1156 | } | |
1157 | break; | |
1158 | ||
ebc9b89d | 1159 | case 'N': // next |
100f649f VZ |
1160 | item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); |
1161 | if ( item++ == GetItemCount() - 1 ) | |
1162 | { | |
1163 | item = 0; | |
1164 | } | |
1165 | ||
9a83f860 | 1166 | wxLogMessage(wxT("Focusing item %ld"), item); |
100f649f VZ |
1167 | |
1168 | SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); | |
1169 | EnsureVisible(item); | |
1170 | break; | |
1171 | ||
ebc9b89d | 1172 | case 'R': // show bounding rectangle |
2d33aec9 | 1173 | { |
100f649f VZ |
1174 | item = event.GetIndex(); |
1175 | wxRect r; | |
1176 | if ( !GetItemRect(item, r) ) | |
2d33aec9 | 1177 | { |
9a83f860 | 1178 | wxLogError(wxT("Failed to retrieve rect of item %ld"), item); |
100f649f | 1179 | break; |
2d33aec9 VZ |
1180 | } |
1181 | ||
9a83f860 | 1182 | wxLogMessage(wxT("Bounding rect of item %ld is (%d, %d)-(%d, %d)"), |
100f649f | 1183 | item, r.x, r.y, r.x + r.width, r.y + r.height); |
2d33aec9 VZ |
1184 | } |
1185 | break; | |
1186 | ||
92a2a0ef VZ |
1187 | case '1': // show sub item bounding rectangle for the given column |
1188 | case '2': // (and icon/label rectangle if Shift/Ctrl is pressed) | |
e974c5d2 VZ |
1189 | case '3': |
1190 | case '4': // this column is invalid but we want to test it too | |
1191 | if ( InReportView() ) | |
1192 | { | |
1193 | int subItem = event.GetKeyCode() - '1'; | |
1194 | item = event.GetIndex(); | |
1195 | wxRect r; | |
92a2a0ef VZ |
1196 | |
1197 | int code = wxLIST_RECT_BOUNDS; | |
1198 | if ( wxGetKeyState(WXK_SHIFT) ) | |
1199 | code = wxLIST_RECT_ICON; | |
1200 | else if ( wxGetKeyState(WXK_CONTROL) ) | |
1201 | code = wxLIST_RECT_LABEL; | |
1202 | ||
1203 | if ( !GetSubItemRect(item, subItem, r, code) ) | |
e974c5d2 | 1204 | { |
9a83f860 | 1205 | wxLogError(wxT("Failed to retrieve rect of item %ld column %d"), item, subItem + 1); |
e974c5d2 VZ |
1206 | break; |
1207 | } | |
1208 | ||
9a83f860 | 1209 | wxLogMessage(wxT("Bounding rect of item %ld column %d is (%d, %d)-(%d, %d)"), |
e974c5d2 VZ |
1210 | item, subItem + 1, |
1211 | r.x, r.y, r.x + r.width, r.y + r.height); | |
1212 | } | |
1213 | break; | |
1214 | ||
ebc9b89d VZ |
1215 | case 'U': // update |
1216 | if ( !IsVirtual() ) | |
1217 | break; | |
1218 | ||
1219 | if ( m_updated != -1 ) | |
1220 | RefreshItem(m_updated); | |
1221 | ||
1222 | m_updated = event.GetIndex(); | |
1223 | if ( m_updated != -1 ) | |
1224 | { | |
1225 | // we won't see changes to this item as it's selected, update | |
1226 | // the next one (or the first one if we're on the last item) | |
1227 | if ( ++m_updated == GetItemCount() ) | |
1228 | m_updated = 0; | |
1229 | ||
1230 | wxLogMessage("Updating colour of the item %ld", m_updated); | |
1231 | RefreshItem(m_updated); | |
1232 | } | |
1233 | break; | |
1234 | ||
17483f70 | 1235 | case 'D': // delete |
100f649f VZ |
1236 | item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); |
1237 | while ( item != -1 ) | |
91c6cc0e | 1238 | { |
100f649f | 1239 | DeleteItem(item); |
91c6cc0e | 1240 | |
9a83f860 | 1241 | wxLogMessage(wxT("Item %ld deleted"), item); |
f6bcfd97 | 1242 | |
100f649f VZ |
1243 | // -1 because the indices were shifted by DeleteItem() |
1244 | item = GetNextItem(item - 1, | |
1245 | wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | |
91c6cc0e | 1246 | } |
5cd89174 VZ |
1247 | break; |
1248 | ||
17483f70 | 1249 | case 'I': // insert |
5cd89174 VZ |
1250 | if ( GetWindowStyle() & wxLC_REPORT ) |
1251 | { | |
1252 | if ( GetWindowStyle() & wxLC_VIRTUAL ) | |
1253 | { | |
1254 | SetItemCount(GetItemCount() + 1); | |
1255 | } | |
1256 | else // !virtual | |
1257 | { | |
1258 | InsertItemInReportView(event.GetIndex()); | |
1259 | } | |
1260 | } | |
1261 | //else: fall through | |
1262 | ||
1263 | default: | |
9a83f860 | 1264 | LogEvent(event, wxT("OnListKeyDown")); |
5cd89174 VZ |
1265 | |
1266 | event.Skip(); | |
1267 | } | |
f6bcfd97 BP |
1268 | } |
1269 | ||
1270 | void MyListCtrl::OnChar(wxKeyEvent& event) | |
1271 | { | |
9a83f860 | 1272 | wxLogMessage(wxT("Got char event.")); |
f6bcfd97 | 1273 | |
d34d31f6 | 1274 | event.Skip(); |
457814b5 JS |
1275 | } |
1276 | ||
164a7972 VZ |
1277 | void MyListCtrl::OnRightClick(wxMouseEvent& event) |
1278 | { | |
1279 | if ( !event.ControlDown() ) | |
1280 | { | |
1281 | event.Skip(); | |
1282 | return; | |
1283 | } | |
1284 | ||
1285 | int flags; | |
1286 | long subitem; | |
1287 | long item = HitTest(event.GetPosition(), flags, &subitem); | |
1288 | ||
1289 | wxString where; | |
1290 | switch ( flags ) | |
1291 | { | |
9a83f860 VZ |
1292 | case wxLIST_HITTEST_ABOVE: where = wxT("above"); break; |
1293 | case wxLIST_HITTEST_BELOW: where = wxT("below"); break; | |
1294 | case wxLIST_HITTEST_NOWHERE: where = wxT("nowhere near"); break; | |
1295 | case wxLIST_HITTEST_ONITEMICON: where = wxT("on icon of"); break; | |
1296 | case wxLIST_HITTEST_ONITEMLABEL: where = wxT("on label of"); break; | |
1297 | case wxLIST_HITTEST_ONITEMRIGHT: where = wxT("right on"); break; | |
1298 | case wxLIST_HITTEST_TOLEFT: where = wxT("to the left of"); break; | |
1299 | case wxLIST_HITTEST_TORIGHT: where = wxT("to the right of"); break; | |
1300 | default: where = wxT("not clear exactly where on"); break; | |
164a7972 VZ |
1301 | } |
1302 | ||
9a83f860 | 1303 | wxLogMessage(wxT("Right double click %s item %ld, subitem %ld"), |
164a7972 VZ |
1304 | where.c_str(), item, subitem); |
1305 | } | |
1306 | ||
c41ea66a VZ |
1307 | void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName) |
1308 | { | |
9a83f860 | 1309 | wxLogMessage(wxT("Item %ld: %s (item text = %s, data = %ld)"), |
f6bcfd97 BP |
1310 | event.GetIndex(), eventName, |
1311 | event.GetText().c_str(), event.GetData()); | |
c41ea66a | 1312 | } |
435fe83e | 1313 | |
98ec9dbe VZ |
1314 | wxString MyListCtrl::OnGetItemText(long item, long column) const |
1315 | { | |
b0401bea VZ |
1316 | if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) ) |
1317 | { | |
1318 | return SMALL_VIRTUAL_VIEW_ITEMS[item][column]; | |
1319 | } | |
ebc9b89d | 1320 | else // "big" virtual control |
b0401bea | 1321 | { |
9a83f860 | 1322 | return wxString::Format(wxT("Column %ld of item %ld"), column, item); |
b0401bea | 1323 | } |
98ec9dbe VZ |
1324 | } |
1325 | ||
06db67bc | 1326 | int MyListCtrl::OnGetItemColumnImage(long item, long column) const |
98ec9dbe | 1327 | { |
06db67bc RD |
1328 | if (!column) |
1329 | return 0; | |
1330 | ||
ebc9b89d | 1331 | if (!(item % 3) && column == 1) |
06db67bc RD |
1332 | return 0; |
1333 | ||
1334 | return -1; | |
98ec9dbe VZ |
1335 | } |
1336 | ||
6c02c329 VZ |
1337 | wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const |
1338 | { | |
ebc9b89d VZ |
1339 | // test to check that RefreshItem() works correctly: when m_updated is |
1340 | // set to some item and it is refreshed, we highlight the item | |
1341 | if ( item == m_updated ) | |
1342 | { | |
1343 | static wxListItemAttr s_attrHighlight(*wxRED, wxNullColour, wxNullFont); | |
1344 | return &s_attrHighlight; | |
1345 | } | |
1346 | ||
0ee169da | 1347 | return wxListCtrl::OnGetItemAttr(item); |
6c02c329 VZ |
1348 | } |
1349 | ||
5cd89174 VZ |
1350 | void MyListCtrl::InsertItemInReportView(int i) |
1351 | { | |
1352 | wxString buf; | |
9a83f860 | 1353 | buf.Printf(wxT("This is item %d"), i); |
5cd89174 VZ |
1354 | long tmp = InsertItem(i, buf, 0); |
1355 | SetItemData(tmp, i); | |
1356 | ||
9a83f860 | 1357 | buf.Printf(wxT("Col 1, item %d"), i); |
eb257f65 | 1358 | SetItem(tmp, 1, buf); |
5cd89174 | 1359 | |
9a83f860 | 1360 | buf.Printf(wxT("Item %d in column 2"), i); |
eb257f65 | 1361 | SetItem(tmp, 2, buf); |
5cd89174 | 1362 | } |
107ff668 JS |
1363 | |
1364 | #if USE_CONTEXT_MENU | |
1365 | void MyListCtrl::OnContextMenu(wxContextMenuEvent& event) | |
1366 | { | |
d53b09d8 VZ |
1367 | if (GetEditControl() == NULL) |
1368 | { | |
1369 | wxPoint point = event.GetPosition(); | |
1370 | // If from keyboard | |
1371 | if ( (point.x == -1) && (point.y == -1) ) | |
1372 | { | |
1373 | wxSize size = GetSize(); | |
1374 | point.x = size.x / 2; | |
1375 | point.y = size.y / 2; | |
1376 | } | |
1377 | else | |
1378 | { | |
1379 | point = ScreenToClient(point); | |
1380 | } | |
1381 | ShowContextMenu(point); | |
1382 | } | |
1383 | else | |
1384 | { | |
1385 | // the user is editing: | |
1386 | // allow the text control to display its context menu | |
1387 | // if it has one (it has on Windows) rather than display our one | |
1388 | event.Skip(); | |
107ff668 | 1389 | } |
107ff668 JS |
1390 | } |
1391 | #endif | |
1392 | ||
1393 | void MyListCtrl::ShowContextMenu(const wxPoint& pos) | |
1394 | { | |
1395 | wxMenu menu; | |
1396 | ||
9a83f860 | 1397 | menu.Append(wxID_ABOUT, wxT("&About")); |
107ff668 | 1398 | menu.AppendSeparator(); |
9a83f860 | 1399 | menu.Append(wxID_EXIT, wxT("E&xit")); |
107ff668 JS |
1400 | |
1401 | PopupMenu(&menu, pos.x, pos.y); | |
1402 | } |