listbox.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Program: wxWidgets Widgets Sample
  3. // Name: listbox.cpp
  4. // Purpose: Part of the widgets sample showing wxListbox
  5. // Author: Vadim Zeitlin
  6. // Created: 27.03.01
  7. // Copyright: (c) 2001 Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // ============================================================================
  11. // declarations
  12. // ============================================================================
  13. // ----------------------------------------------------------------------------
  14. // headers
  15. // ----------------------------------------------------------------------------
  16. // for compilers that support precompilation, includes "wx/wx.h".
  17. #include "wx/wxprec.h"
  18. #ifdef __BORLANDC__
  19. #pragma hdrstop
  20. #endif
  21. #if wxUSE_LISTBOX
  22. // for all others, include the necessary headers
  23. #ifndef WX_PRECOMP
  24. #include "wx/log.h"
  25. #include "wx/bitmap.h"
  26. #include "wx/button.h"
  27. #include "wx/checkbox.h"
  28. #include "wx/combobox.h"
  29. #include "wx/listbox.h"
  30. #include "wx/radiobox.h"
  31. #include "wx/statbox.h"
  32. #include "wx/textctrl.h"
  33. #endif
  34. #include "wx/sizer.h"
  35. #include "wx/checklst.h"
  36. #include "itemcontainer.h"
  37. #include "widgets.h"
  38. #include "icons/listbox.xpm"
  39. // ----------------------------------------------------------------------------
  40. // constants
  41. // ----------------------------------------------------------------------------
  42. // control ids
  43. enum
  44. {
  45. ListboxPage_Reset = wxID_HIGHEST,
  46. ListboxPage_Add,
  47. ListboxPage_AddText,
  48. ListboxPage_AddSeveral,
  49. ListboxPage_AddMany,
  50. ListboxPage_Clear,
  51. ListboxPage_Change,
  52. ListboxPage_ChangeText,
  53. ListboxPage_Delete,
  54. ListboxPage_DeleteText,
  55. ListboxPage_DeleteSel,
  56. ListboxPage_Listbox,
  57. ListboxPage_EnsureVisible,
  58. ListboxPage_EnsureVisibleText,
  59. ListboxPage_ContainerTests
  60. };
  61. // ----------------------------------------------------------------------------
  62. // ListboxWidgetsPage
  63. // ----------------------------------------------------------------------------
  64. class ListboxWidgetsPage : public ItemContainerWidgetsPage
  65. {
  66. public:
  67. ListboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
  68. virtual wxControl *GetWidget() const { return m_lbox; }
  69. virtual wxItemContainer* GetContainer() const { return m_lbox; }
  70. virtual void RecreateWidget() { CreateLbox(); }
  71. // lazy creation of the content
  72. virtual void CreateContent();
  73. protected:
  74. // event handlers
  75. void OnButtonReset(wxCommandEvent& event);
  76. void OnButtonChange(wxCommandEvent& event);
  77. void OnButtonEnsureVisible(wxCommandEvent& event);
  78. void OnButtonDelete(wxCommandEvent& event);
  79. void OnButtonDeleteSel(wxCommandEvent& event);
  80. void OnButtonClear(wxCommandEvent& event);
  81. void OnButtonAdd(wxCommandEvent& event);
  82. void OnButtonAddSeveral(wxCommandEvent& event);
  83. void OnButtonAddMany(wxCommandEvent& event);
  84. void OnListbox(wxCommandEvent& event);
  85. void OnListboxDClick(wxCommandEvent& event);
  86. void OnCheckListbox(wxCommandEvent& event);
  87. void OnCheckOrRadioBox(wxCommandEvent& event);
  88. void OnUpdateUIAddSeveral(wxUpdateUIEvent& event);
  89. void OnUpdateUIClearButton(wxUpdateUIEvent& event);
  90. void OnUpdateUIEnsureVisibleButton(wxUpdateUIEvent& event);
  91. void OnUpdateUIDeleteButton(wxUpdateUIEvent& event);
  92. void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event);
  93. void OnUpdateUIResetButton(wxUpdateUIEvent& event);
  94. // reset the listbox parameters
  95. void Reset();
  96. // (re)create the listbox
  97. void CreateLbox();
  98. // read the value of a listbox item index from the given control, return
  99. // false if it's invalid
  100. bool GetValidIndexFromText(const wxTextCtrl *text, int *n = NULL) const;
  101. // listbox parameters
  102. // ------------------
  103. // the selection mode
  104. enum LboxSelection
  105. {
  106. LboxSel_Single,
  107. LboxSel_Extended,
  108. LboxSel_Multiple
  109. } m_lboxSelMode;
  110. // should it be sorted?
  111. bool m_sorted;
  112. // should it have horz scroll/vert scrollbar permanently shown?
  113. bool m_horzScroll,
  114. m_vertScrollAlways;
  115. // the controls
  116. // ------------
  117. // the sel mode radiobox
  118. wxRadioBox *m_radioSelMode;
  119. // the checkboxes
  120. wxCheckBox *m_chkVScroll,
  121. *m_chkHScroll,
  122. *m_chkCheck,
  123. *m_chkSort,
  124. *m_chkOwnerDraw;
  125. // the listbox itself and the sizer it is in
  126. #ifdef __WXWINCE__
  127. wxListBoxBase
  128. #else
  129. wxListBox
  130. #endif
  131. *m_lbox;
  132. wxSizer *m_sizerLbox;
  133. // the text entries for "Add/change string" and "Delete" buttons
  134. wxTextCtrl *m_textAdd,
  135. *m_textChange,
  136. *m_textEnsureVisible,
  137. *m_textDelete;
  138. private:
  139. wxDECLARE_EVENT_TABLE();
  140. DECLARE_WIDGETS_PAGE(ListboxWidgetsPage)
  141. };
  142. // ----------------------------------------------------------------------------
  143. // event tables
  144. // ----------------------------------------------------------------------------
  145. wxBEGIN_EVENT_TABLE(ListboxWidgetsPage, WidgetsPage)
  146. EVT_BUTTON(ListboxPage_Reset, ListboxWidgetsPage::OnButtonReset)
  147. EVT_BUTTON(ListboxPage_Change, ListboxWidgetsPage::OnButtonChange)
  148. EVT_BUTTON(ListboxPage_Delete, ListboxWidgetsPage::OnButtonDelete)
  149. EVT_BUTTON(ListboxPage_DeleteSel, ListboxWidgetsPage::OnButtonDeleteSel)
  150. EVT_BUTTON(ListboxPage_EnsureVisible, ListboxWidgetsPage::OnButtonEnsureVisible)
  151. EVT_BUTTON(ListboxPage_Clear, ListboxWidgetsPage::OnButtonClear)
  152. EVT_BUTTON(ListboxPage_Add, ListboxWidgetsPage::OnButtonAdd)
  153. EVT_BUTTON(ListboxPage_AddSeveral, ListboxWidgetsPage::OnButtonAddSeveral)
  154. EVT_BUTTON(ListboxPage_AddMany, ListboxWidgetsPage::OnButtonAddMany)
  155. EVT_BUTTON(ListboxPage_ContainerTests, ItemContainerWidgetsPage::OnButtonTestItemContainer)
  156. EVT_TEXT_ENTER(ListboxPage_AddText, ListboxWidgetsPage::OnButtonAdd)
  157. EVT_TEXT_ENTER(ListboxPage_DeleteText, ListboxWidgetsPage::OnButtonDelete)
  158. EVT_TEXT_ENTER(ListboxPage_EnsureVisibleText, ListboxWidgetsPage::OnButtonEnsureVisible)
  159. EVT_UPDATE_UI(ListboxPage_Reset, ListboxWidgetsPage::OnUpdateUIResetButton)
  160. EVT_UPDATE_UI(ListboxPage_AddSeveral, ListboxWidgetsPage::OnUpdateUIAddSeveral)
  161. EVT_UPDATE_UI(ListboxPage_Clear, ListboxWidgetsPage::OnUpdateUIClearButton)
  162. EVT_UPDATE_UI(ListboxPage_DeleteText, ListboxWidgetsPage::OnUpdateUIClearButton)
  163. EVT_UPDATE_UI(ListboxPage_Delete, ListboxWidgetsPage::OnUpdateUIDeleteButton)
  164. EVT_UPDATE_UI(ListboxPage_Change, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
  165. EVT_UPDATE_UI(ListboxPage_ChangeText, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
  166. EVT_UPDATE_UI(ListboxPage_DeleteSel, ListboxWidgetsPage::OnUpdateUIDeleteSelButton)
  167. EVT_UPDATE_UI(ListboxPage_EnsureVisible, ListboxWidgetsPage::OnUpdateUIEnsureVisibleButton)
  168. EVT_LISTBOX(ListboxPage_Listbox, ListboxWidgetsPage::OnListbox)
  169. EVT_LISTBOX_DCLICK(ListboxPage_Listbox, ListboxWidgetsPage::OnListboxDClick)
  170. EVT_CHECKLISTBOX(ListboxPage_Listbox, ListboxWidgetsPage::OnCheckListbox)
  171. EVT_CHECKBOX(wxID_ANY, ListboxWidgetsPage::OnCheckOrRadioBox)
  172. EVT_RADIOBOX(wxID_ANY, ListboxWidgetsPage::OnCheckOrRadioBox)
  173. wxEND_EVENT_TABLE()
  174. // ============================================================================
  175. // implementation
  176. // ============================================================================
  177. #if defined(__WXUNIVERSAL__)
  178. #define FAMILY_CTRLS UNIVERSAL_CTRLS
  179. #else
  180. #define FAMILY_CTRLS NATIVE_CTRLS
  181. #endif
  182. IMPLEMENT_WIDGETS_PAGE(ListboxWidgetsPage, wxT("Listbox"),
  183. FAMILY_CTRLS | WITH_ITEMS_CTRLS
  184. );
  185. ListboxWidgetsPage::ListboxWidgetsPage(WidgetsBookCtrl *book,
  186. wxImageList *imaglist)
  187. : ItemContainerWidgetsPage(book, imaglist, listbox_xpm)
  188. {
  189. // init everything
  190. m_radioSelMode = (wxRadioBox *)NULL;
  191. m_chkVScroll =
  192. m_chkHScroll =
  193. m_chkCheck =
  194. m_chkSort =
  195. m_chkOwnerDraw = (wxCheckBox *)NULL;
  196. m_lbox = NULL;
  197. m_sizerLbox = (wxSizer *)NULL;
  198. }
  199. void ListboxWidgetsPage::CreateContent()
  200. {
  201. /*
  202. What we create here is a frame having 3 panes: style pane is the
  203. leftmost one, in the middle the pane with buttons allowing to perform
  204. miscellaneous listbox operations and the pane containing the listbox
  205. itself to the right
  206. */
  207. wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
  208. // left pane
  209. wxStaticBox *box = new wxStaticBox(this, wxID_ANY,
  210. wxT("&Set listbox parameters"));
  211. wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
  212. static const wxString modes[] =
  213. {
  214. wxT("single"),
  215. wxT("extended"),
  216. wxT("multiple"),
  217. };
  218. m_radioSelMode = new wxRadioBox(this, wxID_ANY, wxT("Selection &mode:"),
  219. wxDefaultPosition, wxDefaultSize,
  220. WXSIZEOF(modes), modes,
  221. 1, wxRA_SPECIFY_COLS);
  222. m_chkVScroll = CreateCheckBoxAndAddToSizer
  223. (
  224. sizerLeft,
  225. wxT("Always show &vertical scrollbar")
  226. );
  227. m_chkHScroll = CreateCheckBoxAndAddToSizer
  228. (
  229. sizerLeft,
  230. wxT("Show &horizontal scrollbar")
  231. );
  232. m_chkCheck = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Check list box"));
  233. m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Sort items"));
  234. m_chkOwnerDraw = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Owner drawn"));
  235. sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
  236. sizerLeft->Add(m_radioSelMode, 0, wxGROW | wxALL, 5);
  237. wxButton *btn = new wxButton(this, ListboxPage_Reset, wxT("&Reset"));
  238. sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
  239. // middle pane
  240. wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY,
  241. wxT("&Change listbox contents"));
  242. wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
  243. wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
  244. btn = new wxButton(this, ListboxPage_Add, wxT("&Add this string"));
  245. m_textAdd = new wxTextCtrl(this, ListboxPage_AddText, wxT("test item 0"));
  246. sizerRow->Add(btn, 0, wxRIGHT, 5);
  247. sizerRow->Add(m_textAdd, 1, wxLEFT, 5);
  248. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  249. btn = new wxButton(this, ListboxPage_AddSeveral, wxT("&Insert a few strings"));
  250. sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
  251. btn = new wxButton(this, ListboxPage_AddMany, wxT("Add &many strings"));
  252. sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
  253. sizerRow = new wxBoxSizer(wxHORIZONTAL);
  254. btn = new wxButton(this, ListboxPage_Change, wxT("C&hange current"));
  255. m_textChange = new wxTextCtrl(this, ListboxPage_ChangeText, wxEmptyString);
  256. sizerRow->Add(btn, 0, wxRIGHT, 5);
  257. sizerRow->Add(m_textChange, 1, wxLEFT, 5);
  258. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  259. sizerRow = new wxBoxSizer(wxHORIZONTAL);
  260. btn = new wxButton(this, ListboxPage_EnsureVisible, wxT("Make item &visible"));
  261. m_textEnsureVisible = new wxTextCtrl(this, ListboxPage_EnsureVisibleText, wxEmptyString);
  262. sizerRow->Add(btn, 0, wxRIGHT, 5);
  263. sizerRow->Add(m_textEnsureVisible, 1, wxLEFT, 5);
  264. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  265. sizerRow = new wxBoxSizer(wxHORIZONTAL);
  266. btn = new wxButton(this, ListboxPage_Delete, wxT("&Delete this item"));
  267. m_textDelete = new wxTextCtrl(this, ListboxPage_DeleteText, wxEmptyString);
  268. sizerRow->Add(btn, 0, wxRIGHT, 5);
  269. sizerRow->Add(m_textDelete, 1, wxLEFT, 5);
  270. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  271. btn = new wxButton(this, ListboxPage_DeleteSel, wxT("Delete &selection"));
  272. sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
  273. btn = new wxButton(this, ListboxPage_Clear, wxT("&Clear"));
  274. sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
  275. btn = new wxButton(this, ListboxPage_ContainerTests, wxT("Run &tests"));
  276. sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
  277. // right pane
  278. wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL);
  279. m_lbox = new wxListBox(this, ListboxPage_Listbox,
  280. wxDefaultPosition, wxDefaultSize,
  281. 0, NULL,
  282. wxLB_HSCROLL);
  283. sizerRight->Add(m_lbox, 1, wxGROW | wxALL, 5);
  284. sizerRight->SetMinSize(150, 0);
  285. m_sizerLbox = sizerRight; // save it to modify it later
  286. // the 3 panes panes compose the window
  287. sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
  288. sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
  289. sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
  290. // final initializations
  291. Reset();
  292. SetSizer(sizerTop);
  293. }
  294. // ----------------------------------------------------------------------------
  295. // operations
  296. // ----------------------------------------------------------------------------
  297. void ListboxWidgetsPage::Reset()
  298. {
  299. m_radioSelMode->SetSelection(LboxSel_Single);
  300. m_chkVScroll->SetValue(false);
  301. m_chkHScroll->SetValue(true);
  302. m_chkCheck->SetValue(false);
  303. m_chkSort->SetValue(false);
  304. m_chkOwnerDraw->SetValue(false);
  305. }
  306. void ListboxWidgetsPage::CreateLbox()
  307. {
  308. int flags = ms_defaultFlags;
  309. switch ( m_radioSelMode->GetSelection() )
  310. {
  311. default:
  312. wxFAIL_MSG( wxT("unexpected radio box selection") );
  313. case LboxSel_Single: flags |= wxLB_SINGLE; break;
  314. case LboxSel_Extended: flags |= wxLB_EXTENDED; break;
  315. case LboxSel_Multiple: flags |= wxLB_MULTIPLE; break;
  316. }
  317. if ( m_chkVScroll->GetValue() )
  318. flags |= wxLB_ALWAYS_SB;
  319. if ( m_chkHScroll->GetValue() )
  320. flags |= wxLB_HSCROLL;
  321. if ( m_chkSort->GetValue() )
  322. flags |= wxLB_SORT;
  323. if ( m_chkOwnerDraw->GetValue() )
  324. flags |= wxLB_OWNERDRAW;
  325. wxArrayString items;
  326. if ( m_lbox )
  327. {
  328. int count = m_lbox->GetCount();
  329. for ( int n = 0; n < count; n++ )
  330. {
  331. items.Add(m_lbox->GetString(n));
  332. }
  333. m_sizerLbox->Detach( m_lbox );
  334. delete m_lbox;
  335. }
  336. #if wxUSE_CHECKLISTBOX
  337. if ( m_chkCheck->GetValue() )
  338. {
  339. m_lbox = new wxCheckListBox(this, ListboxPage_Listbox,
  340. wxDefaultPosition, wxDefaultSize,
  341. 0, NULL,
  342. flags);
  343. }
  344. else // just a listbox
  345. #endif
  346. {
  347. m_lbox = new wxListBox(this, ListboxPage_Listbox,
  348. wxDefaultPosition, wxDefaultSize,
  349. 0, NULL,
  350. flags);
  351. }
  352. m_lbox->Set(items);
  353. m_sizerLbox->Add(m_lbox, 1, wxGROW | wxALL, 5);
  354. m_sizerLbox->Layout();
  355. }
  356. // ----------------------------------------------------------------------------
  357. // miscellaneous helpers
  358. // ----------------------------------------------------------------------------
  359. bool
  360. ListboxWidgetsPage::GetValidIndexFromText(const wxTextCtrl *text, int *n) const
  361. {
  362. unsigned long idx;
  363. if ( !text->GetValue().ToULong(&idx) || (idx >= m_lbox->GetCount()) )
  364. {
  365. // don't give the warning if we're just testing but do give it if we
  366. // want to retrieve the value as this is only done in answer to a user
  367. // action
  368. if ( n )
  369. {
  370. wxLogWarning("Invalid index \"%s\"", text->GetValue());
  371. }
  372. return false;
  373. }
  374. if ( n )
  375. *n = idx;
  376. return true;
  377. }
  378. // ----------------------------------------------------------------------------
  379. // event handlers
  380. // ----------------------------------------------------------------------------
  381. void ListboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
  382. {
  383. Reset();
  384. CreateLbox();
  385. }
  386. void ListboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event))
  387. {
  388. wxArrayInt selections;
  389. int count = m_lbox->GetSelections(selections);
  390. wxString s = m_textChange->GetValue();
  391. for ( int n = 0; n < count; n++ )
  392. {
  393. m_lbox->SetString(selections[n], s);
  394. }
  395. }
  396. void ListboxWidgetsPage::OnButtonEnsureVisible(wxCommandEvent& WXUNUSED(event))
  397. {
  398. int n;
  399. if ( !GetValidIndexFromText(m_textEnsureVisible, &n) )
  400. {
  401. return;
  402. }
  403. m_lbox->EnsureVisible(n);
  404. }
  405. void ListboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event))
  406. {
  407. int n;
  408. if ( !GetValidIndexFromText(m_textDelete, &n) )
  409. {
  410. return;
  411. }
  412. m_lbox->Delete(n);
  413. }
  414. void ListboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event))
  415. {
  416. wxArrayInt selections;
  417. int n = m_lbox->GetSelections(selections);
  418. while ( n > 0 )
  419. {
  420. m_lbox->Delete(selections[--n]);
  421. }
  422. }
  423. void ListboxWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event))
  424. {
  425. m_lbox->Clear();
  426. }
  427. void ListboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
  428. {
  429. static unsigned int s_item = 0;
  430. wxString s = m_textAdd->GetValue();
  431. if ( !m_textAdd->IsModified() )
  432. {
  433. // update the default string
  434. m_textAdd->SetValue(wxString::Format(wxT("test item %u"), ++s_item));
  435. }
  436. m_lbox->Append(s);
  437. }
  438. void ListboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event))
  439. {
  440. // "many" means 1000 here
  441. for ( unsigned int n = 0; n < 1000; n++ )
  442. {
  443. m_lbox->Append(wxString::Format(wxT("item #%u"), n));
  444. }
  445. }
  446. void ListboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event))
  447. {
  448. wxArrayString items;
  449. items.Add(wxT("First"));
  450. items.Add(wxT("another one"));
  451. items.Add(wxT("and the last (very very very very very very very very very very long) one"));
  452. m_lbox->InsertItems(items, 0);
  453. }
  454. void ListboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
  455. {
  456. event.Enable( (m_radioSelMode->GetSelection() != LboxSel_Single) ||
  457. m_chkSort->GetValue() ||
  458. m_chkOwnerDraw->GetValue() ||
  459. !m_chkHScroll->GetValue() ||
  460. m_chkVScroll->GetValue() );
  461. }
  462. void ListboxWidgetsPage::OnUpdateUIEnsureVisibleButton(wxUpdateUIEvent& event)
  463. {
  464. event.Enable(GetValidIndexFromText(m_textEnsureVisible));
  465. }
  466. void ListboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event)
  467. {
  468. event.Enable(GetValidIndexFromText(m_textDelete));
  469. }
  470. void ListboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event)
  471. {
  472. wxArrayInt selections;
  473. event.Enable(m_lbox->GetSelections(selections) != 0);
  474. }
  475. void ListboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event)
  476. {
  477. event.Enable(m_lbox->GetCount() != 0);
  478. }
  479. void ListboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event)
  480. {
  481. event.Enable(!(m_lbox->GetWindowStyle() & wxLB_SORT));
  482. }
  483. void ListboxWidgetsPage::OnListbox(wxCommandEvent& event)
  484. {
  485. long sel = event.GetSelection();
  486. m_textDelete->SetValue(wxString::Format(wxT("%ld"), sel));
  487. if (event.IsSelection())
  488. {
  489. wxLogMessage(wxT("Listbox item %ld selected"), sel);
  490. }
  491. else
  492. {
  493. wxLogMessage(wxT("Listbox item %ld deselected"), sel);
  494. }
  495. }
  496. void ListboxWidgetsPage::OnListboxDClick(wxCommandEvent& event)
  497. {
  498. wxLogMessage( wxT("Listbox item %d double clicked"), event.GetInt() );
  499. }
  500. void ListboxWidgetsPage::OnCheckListbox(wxCommandEvent& event)
  501. {
  502. wxLogMessage( wxT("Listbox item %d toggled"), event.GetInt() );
  503. }
  504. void ListboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
  505. {
  506. CreateLbox();
  507. }
  508. #endif // wxUSE_LISTBOX