]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: checklst.cpp | |
3 | // Purpose: wxCheckListBox sample | |
4 | // Author: Vadim Zeitlin | |
655822f3 | 5 | // Modified by: |
457814b5 JS |
6 | // Created: 13.11.97 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
9 | // Licence: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
457814b5 JS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
bbdbfb0e | 16 | #pragma hdrstop |
457814b5 JS |
17 | #endif |
18 | ||
19 | #ifndef WX_PRECOMP | |
bbdbfb0e | 20 | #include "wx/wx.h" |
457814b5 JS |
21 | #endif |
22 | ||
b292e2f5 | 23 | #ifdef __WXMSW__ |
bbdbfb0e | 24 | #include "wx/ownerdrw.h" |
b292e2f5 | 25 | #endif |
bbdbfb0e VZ |
26 | |
27 | #include "wx/log.h" | |
28 | ||
d8d474af | 29 | #include "wx/sizer.h" |
457814b5 | 30 | #include "wx/menuitem.h" |
b292e2f5 RR |
31 | #include "wx/checklst.h" |
32 | ||
f62f1618 MW |
33 | #if !wxUSE_CHECKLISTBOX |
34 | #error "This sample can't be built without wxUSE_CHECKLISTBOX" | |
35 | #endif // wxUSE_CHECKLISTBOX | |
36 | ||
457814b5 JS |
37 | // Define a new application type |
38 | class CheckListBoxApp: public wxApp | |
39 | { | |
40 | public: | |
bbdbfb0e | 41 | bool OnInit(); |
457814b5 JS |
42 | }; |
43 | ||
44 | // Define a new frame type | |
45 | class CheckListBoxFrame : public wxFrame | |
46 | { | |
47 | public: | |
bbdbfb0e | 48 | // ctor & dtor |
1914bb8e | 49 | CheckListBoxFrame(wxFrame *frame, const wxChar *title); |
958d3a7e | 50 | virtual ~CheckListBoxFrame(){}; |
bbdbfb0e VZ |
51 | |
52 | // notifications | |
3dabb1e5 VZ |
53 | void OnQuit(wxCommandEvent& event); |
54 | void OnAbout(wxCommandEvent& event); | |
d553ceb2 | 55 | |
3dabb1e5 VZ |
56 | void OnCheckFirstItem(wxCommandEvent& event); |
57 | void OnUncheckFirstItem(wxCommandEvent& event); | |
58 | void OnToggleFirstItem(wxCommandEvent& event); | |
df7d383f | 59 | void OnToggleSelection(wxCommandEvent& event); |
4a46cbe8 RR |
60 | void OnToggleSorting(wxCommandEvent& event); |
61 | void OnToggleExtended(wxCommandEvent& event); | |
62 | ||
63 | void OnInsertItemsStart(wxCommandEvent& event); | |
64 | void OnInsertItemsMiddle(wxCommandEvent& event); | |
65 | void OnInsertItemsEnd(wxCommandEvent& event); | |
66 | void OnAppendItems(wxCommandEvent& event); | |
67 | void OnRemoveItems(wxCommandEvent& event); | |
68 | ||
4a46cbe8 RR |
69 | void OnGetBestSize(wxCommandEvent& event); |
70 | ||
71 | void OnMakeItemFirst(wxCommandEvent& event); | |
d553ceb2 | 72 | |
3dabb1e5 VZ |
73 | void OnListboxSelect(wxCommandEvent& event); |
74 | void OnCheckboxToggle(wxCommandEvent& event); | |
bbdbfb0e | 75 | void OnListboxDblClick(wxCommandEvent& event); |
d553ceb2 | 76 | |
3dabb1e5 VZ |
77 | void OnButtonUp(wxCommandEvent& event); |
78 | void OnButtonDown(wxCommandEvent& event); | |
457814b5 | 79 | |
bbdbfb0e | 80 | private: |
df7d383f VZ |
81 | void CreateCheckListbox(long flags = 0); |
82 | ||
bbdbfb0e | 83 | void OnButtonMove(bool up); |
457814b5 | 84 | |
f048e32f VZ |
85 | void AdjustColour(size_t index); |
86 | ||
df7d383f VZ |
87 | wxPanel *m_panel; |
88 | ||
bbdbfb0e | 89 | wxCheckListBox *m_pListBox; |
457814b5 | 90 | |
bbdbfb0e | 91 | DECLARE_EVENT_TABLE() |
457814b5 JS |
92 | }; |
93 | ||
655822f3 VZ |
94 | enum |
95 | { | |
1914bb8e WS |
96 | Menu_About = wxID_ABOUT, |
97 | Menu_Quit = wxID_EXIT, | |
3dabb1e5 | 98 | |
1914bb8e | 99 | Menu_CheckFirst = wxID_HIGHEST, |
3dabb1e5 VZ |
100 | Menu_UncheckFirst, |
101 | Menu_ToggleFirst, | |
df7d383f | 102 | Menu_Selection, |
4a46cbe8 RR |
103 | Menu_Extended, |
104 | Menu_Sorting, | |
105 | Menu_InsertItemsStart, | |
106 | Menu_InsertItemsMiddle, | |
107 | Menu_InsertItemsEnd, | |
108 | Menu_AppendItems, | |
109 | Menu_RemoveItems, | |
4a46cbe8 RR |
110 | Menu_GetBestSize, |
111 | Menu_MakeItemFirst, | |
df7d383f | 112 | |
1914bb8e | 113 | Control_First, |
bbdbfb0e | 114 | Control_Listbox, |
1914bb8e WS |
115 | |
116 | Btn_Up = wxID_UP, | |
117 | Btn_Down = wxID_DOWN | |
457814b5 JS |
118 | }; |
119 | ||
120 | BEGIN_EVENT_TABLE(CheckListBoxFrame, wxFrame) | |
df7d383f | 121 | EVT_MENU(Menu_About, CheckListBoxFrame::OnAbout) |
bbdbfb0e VZ |
122 | EVT_MENU(Menu_Quit, CheckListBoxFrame::OnQuit) |
123 | ||
3dabb1e5 VZ |
124 | EVT_MENU(Menu_CheckFirst, CheckListBoxFrame::OnCheckFirstItem) |
125 | EVT_MENU(Menu_UncheckFirst, CheckListBoxFrame::OnUncheckFirstItem) | |
126 | EVT_MENU(Menu_ToggleFirst, CheckListBoxFrame::OnToggleFirstItem) | |
df7d383f | 127 | EVT_MENU(Menu_Selection, CheckListBoxFrame::OnToggleSelection) |
4a46cbe8 RR |
128 | EVT_MENU(Menu_Extended, CheckListBoxFrame::OnToggleExtended) |
129 | EVT_MENU(Menu_Sorting, CheckListBoxFrame::OnToggleSorting) | |
c1dcb1a0 | 130 | |
4a46cbe8 RR |
131 | EVT_MENU(Menu_InsertItemsStart, CheckListBoxFrame::OnInsertItemsStart) |
132 | EVT_MENU(Menu_InsertItemsMiddle, CheckListBoxFrame::OnInsertItemsMiddle) | |
133 | EVT_MENU(Menu_InsertItemsEnd, CheckListBoxFrame::OnInsertItemsEnd) | |
134 | EVT_MENU(Menu_AppendItems, CheckListBoxFrame::OnAppendItems) | |
135 | EVT_MENU(Menu_RemoveItems, CheckListBoxFrame::OnRemoveItems) | |
136 | ||
4a46cbe8 RR |
137 | EVT_MENU(Menu_GetBestSize, CheckListBoxFrame::OnGetBestSize) |
138 | ||
139 | EVT_MENU(Menu_MakeItemFirst, CheckListBoxFrame::OnMakeItemFirst) | |
df7d383f | 140 | |
bbdbfb0e VZ |
141 | EVT_LISTBOX(Control_Listbox, CheckListBoxFrame::OnListboxSelect) |
142 | EVT_CHECKLISTBOX(Control_Listbox, CheckListBoxFrame::OnCheckboxToggle) | |
143 | EVT_LISTBOX_DCLICK(Control_Listbox, CheckListBoxFrame::OnListboxDblClick) | |
144 | ||
145 | EVT_BUTTON(Btn_Up, CheckListBoxFrame::OnButtonUp) | |
146 | EVT_BUTTON(Btn_Down, CheckListBoxFrame::OnButtonDown) | |
457814b5 JS |
147 | END_EVENT_TABLE() |
148 | ||
004f4002 | 149 | IMPLEMENT_APP(CheckListBoxApp) |
457814b5 JS |
150 | |
151 | // init our app: create windows | |
152 | bool CheckListBoxApp::OnInit(void) | |
153 | { | |
45e6e6f8 VZ |
154 | if ( !wxApp::OnInit() ) |
155 | return false; | |
156 | ||
bbdbfb0e VZ |
157 | CheckListBoxFrame *pFrame = new CheckListBoxFrame |
158 | ( | |
159 | NULL, | |
1914bb8e | 160 | _T("wxWidgets Checklistbox Sample") |
bbdbfb0e VZ |
161 | ); |
162 | SetTopWindow(pFrame); | |
163 | ||
8ad18dc3 | 164 | return true; |
457814b5 JS |
165 | } |
166 | ||
167 | // main frame constructor | |
bbdbfb0e | 168 | CheckListBoxFrame::CheckListBoxFrame(wxFrame *frame, |
1914bb8e WS |
169 | const wxChar *title) |
170 | : wxFrame(frame, wxID_ANY, title) | |
457814b5 | 171 | { |
8520f137 | 172 | #if wxUSE_STATUSBAR |
bbdbfb0e VZ |
173 | // create the status line |
174 | const int widths[] = { -1, 60 }; | |
175 | CreateStatusBar(2); | |
176 | SetStatusWidths(2, widths); | |
8520f137 | 177 | #endif // wxUSE_STATUSBAR |
bbdbfb0e VZ |
178 | |
179 | // Make a menubar | |
df7d383f | 180 | // -------------- |
bbdbfb0e | 181 | |
df7d383f VZ |
182 | // file submenu |
183 | wxMenu *menuFile = new wxMenu; | |
184 | menuFile->Append(Menu_About, _T("&About...\tF1")); | |
185 | menuFile->AppendSeparator(); | |
186 | menuFile->Append(Menu_Quit, _T("E&xit\tAlt-X")); | |
bbdbfb0e | 187 | |
df7d383f VZ |
188 | // listbox submenu |
189 | wxMenu *menuList = new wxMenu; | |
3dabb1e5 VZ |
190 | menuList->Append(Menu_CheckFirst, _T("Check the first item\tCtrl-C")); |
191 | menuList->Append(Menu_UncheckFirst, _T("Uncheck the first item\tCtrl-U")); | |
192 | menuList->Append(Menu_ToggleFirst, _T("Toggle the first item\tCtrl-T")); | |
193 | menuList->AppendSeparator(); | |
4a46cbe8 RR |
194 | menuList->Append(Menu_InsertItemsStart, _T("Insert some item at the beginning")); |
195 | menuList->Append(Menu_InsertItemsMiddle, _T("Insert some item at the middle")); | |
196 | menuList->Append(Menu_InsertItemsEnd, _T("Insert some item at the end")); | |
197 | menuList->Append(Menu_AppendItems, _T("Append some items\tCtrl-A")); | |
198 | menuList->Append(Menu_RemoveItems, _T("Remove some items")); | |
d553ceb2 | 199 | menuList->AppendSeparator(); |
df7d383f | 200 | menuList->AppendCheckItem(Menu_Selection, _T("Multiple selection\tCtrl-M")); |
4a46cbe8 RR |
201 | menuList->AppendCheckItem(Menu_Extended, _T("Extended selection")); |
202 | menuList->AppendCheckItem(Menu_Sorting, _T("Sorting")); | |
203 | menuList->AppendSeparator(); | |
4a46cbe8 RR |
204 | menuList->Append(Menu_GetBestSize, _T("Get the best size of the checklistbox control")); |
205 | menuList->AppendSeparator(); | |
206 | menuList->Append(Menu_MakeItemFirst, _T("Make selected item the first item")); | |
207 | ||
df7d383f VZ |
208 | |
209 | // put it all together | |
bbdbfb0e | 210 | wxMenuBar *menu_bar = new wxMenuBar; |
df7d383f VZ |
211 | menu_bar->Append(menuFile, _T("&File")); |
212 | menu_bar->Append(menuList, _T("&List")); | |
bbdbfb0e VZ |
213 | SetMenuBar(menu_bar); |
214 | ||
215 | // make a panel with some controls | |
1914bb8e | 216 | m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); |
df7d383f VZ |
217 | |
218 | CreateCheckListbox(); | |
219 | ||
220 | // create buttons for moving the items around | |
1914bb8e WS |
221 | wxButton *button1 = new wxButton(m_panel, Btn_Up); |
222 | wxButton *button2 = new wxButton(m_panel, Btn_Down); | |
df7d383f VZ |
223 | |
224 | ||
225 | wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); | |
226 | ||
227 | mainsizer->Add( m_pListBox, 1, wxGROW|wxALL, 10 ); | |
bbdbfb0e | 228 | |
df7d383f VZ |
229 | wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL ); |
230 | ||
231 | bottomsizer->Add( button1, 0, wxALL, 10 ); | |
232 | bottomsizer->Add( button2, 0, wxALL, 10 ); | |
233 | ||
234 | mainsizer->Add( bottomsizer, 0, wxCENTER ); | |
235 | ||
236 | // tell frame to make use of sizer (or constraints, if any) | |
8ad18dc3 | 237 | m_panel->SetAutoLayout( true ); |
df7d383f VZ |
238 | m_panel->SetSizer( mainsizer ); |
239 | ||
1914bb8e | 240 | #ifndef __WXWINCE__ |
df7d383f VZ |
241 | // don't allow frame to get smaller than what the sizers tell ye |
242 | mainsizer->SetSizeHints( this ); | |
1914bb8e | 243 | #endif |
df7d383f | 244 | |
8ad18dc3 | 245 | Show(true); |
df7d383f VZ |
246 | } |
247 | ||
248 | void CheckListBoxFrame::CreateCheckListbox(long flags) | |
249 | { | |
bbdbfb0e | 250 | // check list box |
df7d383f | 251 | static const wxChar *aszChoices[] = |
bbdbfb0e | 252 | { |
df7d383f VZ |
253 | _T("Zeroth"), |
254 | _T("First"), _T("Second"), _T("Third"), | |
255 | _T("Fourth"), _T("Fifth"), _T("Sixth"), | |
256 | _T("Seventh"), _T("Eighth"), _T("Nineth") | |
bbdbfb0e VZ |
257 | }; |
258 | ||
259 | wxString *astrChoices = new wxString[WXSIZEOF(aszChoices)]; | |
260 | unsigned int ui; | |
261 | for ( ui = 0; ui < WXSIZEOF(aszChoices); ui++ ) | |
262 | astrChoices[ui] = aszChoices[ui]; | |
263 | ||
264 | m_pListBox = new wxCheckListBox | |
265 | ( | |
df7d383f | 266 | m_panel, // parent |
bbdbfb0e VZ |
267 | Control_Listbox, // control id |
268 | wxPoint(10, 10), // listbox poistion | |
8e1d4f96 | 269 | wxSize(400, 100), // listbox size |
bbdbfb0e | 270 | WXSIZEOF(aszChoices), // number of strings |
df7d383f VZ |
271 | astrChoices, // array of strings |
272 | flags | |
bbdbfb0e VZ |
273 | ); |
274 | ||
bbdbfb0e VZ |
275 | delete [] astrChoices; |
276 | ||
bbdbfb0e VZ |
277 | // set grey background for every second entry |
278 | for ( ui = 0; ui < WXSIZEOF(aszChoices); ui += 2 ) { | |
f048e32f | 279 | AdjustColour(ui); |
bbdbfb0e | 280 | } |
457814b5 | 281 | |
bbdbfb0e | 282 | m_pListBox->Check(2); |
df7d383f | 283 | m_pListBox->Select(3); |
457814b5 JS |
284 | } |
285 | ||
4f22cf8d | 286 | void CheckListBoxFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 287 | { |
8ad18dc3 | 288 | Close(true); |
457814b5 JS |
289 | } |
290 | ||
4f22cf8d | 291 | void CheckListBoxFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 292 | { |
749bfe9a | 293 | wxMessageBox(wxT("Demo of wxCheckListBox control\n(c) Vadim Zeitlin 1998-2002"), |
e680a378 | 294 | wxT("About wxCheckListBox"), |
bbdbfb0e | 295 | wxICON_INFORMATION, this); |
457814b5 JS |
296 | } |
297 | ||
87728739 | 298 | void CheckListBoxFrame::OnCheckFirstItem(wxCommandEvent& WXUNUSED(event)) |
3dabb1e5 VZ |
299 | { |
300 | if ( !m_pListBox->IsEmpty() ) | |
301 | m_pListBox->Check(0); | |
302 | } | |
303 | ||
87728739 | 304 | void CheckListBoxFrame::OnUncheckFirstItem(wxCommandEvent& WXUNUSED(event)) |
3dabb1e5 VZ |
305 | { |
306 | if ( !m_pListBox->IsEmpty() ) | |
8ad18dc3 | 307 | m_pListBox->Check(0, false); |
3dabb1e5 VZ |
308 | } |
309 | ||
87728739 | 310 | void CheckListBoxFrame::OnToggleFirstItem(wxCommandEvent& WXUNUSED(event)) |
3dabb1e5 VZ |
311 | { |
312 | if ( !m_pListBox->IsEmpty() ) | |
313 | m_pListBox->Check(0, !m_pListBox->IsChecked(0)); | |
314 | } | |
315 | ||
4a46cbe8 | 316 | void CheckListBoxFrame::OnInsertItemsStart(wxCommandEvent& WXUNUSED(event)) |
d553ceb2 VZ |
317 | { |
318 | static size_t s_nItem = 0; | |
319 | wxArrayString items; | |
320 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
321 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
322 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
323 | ||
324 | m_pListBox->InsertItems(items, 0);//m_pListBox->GetCount()); | |
325 | } | |
326 | ||
4a46cbe8 RR |
327 | void CheckListBoxFrame::OnInsertItemsMiddle(wxCommandEvent& WXUNUSED(event)) |
328 | { | |
329 | static size_t s_nItem = 0; | |
330 | wxArrayString items; | |
331 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
332 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
333 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
334 | ||
335 | m_pListBox->InsertItems(items, m_pListBox->GetCount() ? 1 : 0); | |
336 | } | |
337 | ||
338 | void CheckListBoxFrame::OnInsertItemsEnd(wxCommandEvent& WXUNUSED(event)) | |
339 | { | |
340 | static size_t s_nItem = 0; | |
341 | wxArrayString items; | |
342 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
343 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
344 | items.Add(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
345 | ||
346 | m_pListBox->InsertItems(items, m_pListBox->GetCount() ); | |
347 | } | |
348 | ||
349 | void CheckListBoxFrame::OnAppendItems(wxCommandEvent& WXUNUSED(event)) | |
350 | { | |
351 | static size_t s_nItem = 0; | |
352 | m_pListBox->Append(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
353 | m_pListBox->Append(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
354 | m_pListBox->Append(wxString::Format(_T("New item %lu"), (unsigned long)++s_nItem)); | |
355 | } | |
356 | ||
357 | void CheckListBoxFrame::OnRemoveItems(wxCommandEvent& WXUNUSED(event)) | |
358 | { | |
359 | if(m_pListBox->GetCount()) | |
360 | m_pListBox->Delete(0); | |
361 | if(m_pListBox->GetCount()) | |
362 | m_pListBox->Delete(0); | |
363 | if(m_pListBox->GetCount()) | |
364 | m_pListBox->Delete(0); | |
365 | } | |
366 | ||
4a46cbe8 RR |
367 | void CheckListBoxFrame::OnGetBestSize(wxCommandEvent& WXUNUSED(event)) |
368 | { | |
369 | wxSize bestSize = m_pListBox->GetBestSize(); | |
370 | ||
371 | wxMessageBox(wxString::Format(wxT("Best size of the checklistbox is:[%i,%i]"), | |
372 | bestSize.x, bestSize.y | |
373 | ) | |
374 | ); | |
375 | } | |
376 | ||
377 | void CheckListBoxFrame::OnMakeItemFirst(wxCommandEvent& WXUNUSED(event)) | |
378 | { | |
379 | if(m_pListBox->GetSelection() != -1) | |
380 | m_pListBox->SetFirstItem(m_pListBox->GetSelection()); | |
381 | else | |
382 | wxMessageBox(wxT("Nothing selected!")); | |
383 | } | |
384 | ||
df7d383f VZ |
385 | void CheckListBoxFrame::OnToggleSelection(wxCommandEvent& event) |
386 | { | |
387 | wxSizer *sizer = m_panel->GetSizer(); | |
388 | ||
12a3f227 | 389 | sizer->Detach( m_pListBox ); |
df7d383f VZ |
390 | delete m_pListBox; |
391 | ||
392 | CreateCheckListbox(event.IsChecked() ? wxLB_EXTENDED : 0); | |
393 | ||
394 | sizer->Insert(0, m_pListBox, 1, wxGROW | wxALL, 10); | |
395 | ||
396 | m_panel->Layout(); | |
397 | } | |
398 | ||
4a46cbe8 RR |
399 | void CheckListBoxFrame::OnToggleExtended(wxCommandEvent& event) |
400 | { | |
401 | wxSizer *sizer = m_panel->GetSizer(); | |
402 | ||
403 | sizer->Detach( m_pListBox ); | |
404 | delete m_pListBox; | |
405 | ||
406 | CreateCheckListbox(event.IsChecked() ? wxLB_EXTENDED : 0); | |
407 | ||
408 | sizer->Insert(0, m_pListBox, 1, wxGROW | wxALL, 10); | |
409 | ||
c1dcb1a0 | 410 | m_panel->Layout(); |
4a46cbe8 RR |
411 | } |
412 | ||
413 | void CheckListBoxFrame::OnToggleSorting(wxCommandEvent& event) | |
414 | { | |
415 | wxSizer *sizer = m_panel->GetSizer(); | |
416 | ||
417 | sizer->Detach( m_pListBox ); | |
418 | delete m_pListBox; | |
419 | ||
420 | CreateCheckListbox(event.IsChecked() ? wxLB_SORT : 0); | |
421 | ||
422 | sizer->Insert(0, m_pListBox, 1, wxGROW | wxALL, 10); | |
423 | ||
c1dcb1a0 | 424 | m_panel->Layout(); |
4a46cbe8 RR |
425 | } |
426 | ||
457814b5 JS |
427 | void CheckListBoxFrame::OnListboxSelect(wxCommandEvent& event) |
428 | { | |
bbdbfb0e | 429 | int nSel = event.GetSelection(); |
e680a378 | 430 | wxLogStatus(this, wxT("Item %d selected (%schecked)"), nSel, |
8ad18dc3 | 431 | m_pListBox->IsChecked(nSel) ? wxT("") : wxT("not ")); |
457814b5 JS |
432 | } |
433 | ||
4f22cf8d | 434 | void CheckListBoxFrame::OnListboxDblClick(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 435 | { |
8ad18dc3 JS |
436 | int selection = -1; |
437 | if(m_pListBox->GetWindowStyle() & wxLB_EXTENDED) | |
438 | { | |
439 | wxArrayInt list; | |
440 | m_pListBox->GetSelections(list); | |
441 | if(list.Count()==1) | |
442 | { | |
443 | selection = list.Item(0); | |
444 | } | |
445 | } | |
446 | else | |
447 | { | |
448 | selection = m_pListBox->GetSelection(); | |
449 | } | |
450 | ||
bbdbfb0e | 451 | wxString strSelection; |
8ad18dc3 JS |
452 | if ( selection != -1 ) |
453 | { | |
454 | strSelection.Printf(wxT("Item %d double clicked"), selection); | |
455 | } | |
456 | else | |
457 | { | |
458 | strSelection = wxT("List double clicked in multiple selection mode"); | |
459 | } | |
e680a378 | 460 | wxMessageDialog dialog(this, strSelection, wxT("wxCheckListBox message"), wxICON_INFORMATION); |
bbdbfb0e | 461 | dialog.ShowModal(); |
457814b5 JS |
462 | } |
463 | ||
464 | void CheckListBoxFrame::OnCheckboxToggle(wxCommandEvent& event) | |
465 | { | |
bbdbfb0e | 466 | unsigned int nItem = event.GetInt(); |
655822f3 | 467 | |
e680a378 RR |
468 | wxLogStatus(this, wxT("item %d was %schecked"), nItem, |
469 | m_pListBox->IsChecked(nItem) ? wxT("") : wxT("un")); | |
bbdbfb0e VZ |
470 | } |
471 | ||
472 | void CheckListBoxFrame::OnButtonUp(wxCommandEvent& WXUNUSED(event)) | |
473 | { | |
8ad18dc3 | 474 | OnButtonMove(true); |
bbdbfb0e VZ |
475 | } |
476 | ||
477 | void CheckListBoxFrame::OnButtonDown(wxCommandEvent& WXUNUSED(event)) | |
478 | { | |
8ad18dc3 | 479 | OnButtonMove(false); |
bbdbfb0e VZ |
480 | } |
481 | ||
482 | void CheckListBoxFrame::OnButtonMove(bool up) | |
483 | { | |
8ad18dc3 JS |
484 | int selection = -1; |
485 | if(m_pListBox->GetWindowStyle() & wxLB_EXTENDED) | |
486 | { | |
487 | wxArrayInt list; | |
488 | m_pListBox->GetSelections(list); | |
489 | if(list.Count()==1) | |
490 | { | |
491 | selection = list.Item(0); | |
492 | } | |
493 | } | |
494 | else | |
495 | { | |
496 | selection = m_pListBox->GetSelection(); | |
497 | } | |
1914bb8e | 498 | if ( selection != wxNOT_FOUND ) |
bbdbfb0e VZ |
499 | { |
500 | wxString label = m_pListBox->GetString(selection); | |
501 | ||
502 | int positionNew = up ? selection - 1 : selection + 2; | |
8228b893 | 503 | if ( positionNew < 0 || positionNew > (int)m_pListBox->GetCount() ) |
bbdbfb0e | 504 | { |
e680a378 | 505 | wxLogStatus(this, wxT("Can't move this item %s"), up ? wxT("up") : wxT("down")); |
bbdbfb0e VZ |
506 | } |
507 | else | |
508 | { | |
509 | bool wasChecked = m_pListBox->IsChecked(selection); | |
510 | ||
511 | int positionOld = up ? selection + 1 : selection; | |
512 | ||
513 | // insert the item | |
514 | m_pListBox->InsertItems(1, &label, positionNew); | |
515 | ||
516 | // and delete the old one | |
517 | m_pListBox->Delete(positionOld); | |
518 | ||
519 | int selectionNew = up ? positionNew : positionNew - 1; | |
520 | m_pListBox->Check(selectionNew, wasChecked); | |
521 | m_pListBox->SetSelection(selectionNew); | |
1914bb8e | 522 | m_pListBox->SetFocus(); |
bbdbfb0e | 523 | |
f048e32f VZ |
524 | AdjustColour(selection); |
525 | AdjustColour(selectionNew); | |
526 | ||
e680a378 | 527 | wxLogStatus(this, wxT("Item moved %s"), up ? wxT("up") : wxT("down")); |
bbdbfb0e VZ |
528 | } |
529 | } | |
530 | else | |
531 | { | |
8ad18dc3 | 532 | wxLogStatus(this, wxT("Please select single item")); |
bbdbfb0e | 533 | } |
655822f3 | 534 | } |
f048e32f | 535 | |
8ad18dc3 | 536 | // not implemented in ports other than (native) MSW yet |
1914bb8e | 537 | #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__) |
f048e32f VZ |
538 | void CheckListBoxFrame::AdjustColour(size_t index) |
539 | { | |
f048e32f VZ |
540 | // even items have grey backround, odd ones - white |
541 | unsigned char c = index % 2 ? 255 : 200; | |
542 | m_pListBox->GetItem(index)->SetBackgroundColour(wxColor(c, c, c)); | |
f048e32f | 543 | } |
8ad18dc3 JS |
544 | #else |
545 | void CheckListBoxFrame::AdjustColour(size_t WXUNUSED(index)) | |
546 | { | |
547 | } | |
548 | #endif // wxMSW |