widgets.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Program: wxWidgets Widgets Sample
  3. // Name: samples/widgets/widgets.cpp
  4. // Purpose: Sample showing most of the simple wxWidgets widgets
  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. // for all others, include the necessary headers
  22. #ifndef WX_PRECOMP
  23. #include "wx/app.h"
  24. #include "wx/log.h"
  25. #include "wx/frame.h"
  26. #include "wx/menu.h"
  27. #include "wx/image.h"
  28. #include "wx/button.h"
  29. #include "wx/checkbox.h"
  30. #include "wx/listbox.h"
  31. #include "wx/statbox.h"
  32. #include "wx/stattext.h"
  33. #include "wx/textctrl.h"
  34. #include "wx/msgdlg.h"
  35. #endif
  36. #include "wx/sysopt.h"
  37. #include "wx/bookctrl.h"
  38. #include "wx/treebook.h"
  39. #include "wx/sizer.h"
  40. #include "wx/colordlg.h"
  41. #include "wx/fontdlg.h"
  42. #include "wx/textdlg.h"
  43. #include "wx/imaglist.h"
  44. #include "wx/wupdlock.h"
  45. #include "wx/textcompleter.h"
  46. #include "wx/persist/toplevel.h"
  47. #include "wx/persist/treebook.h"
  48. #include "widgets.h"
  49. #include "../sample.xpm"
  50. // ----------------------------------------------------------------------------
  51. // constants
  52. // ----------------------------------------------------------------------------
  53. // control ids
  54. enum
  55. {
  56. Widgets_ClearLog = 100,
  57. Widgets_Quit,
  58. Widgets_BookCtrl,
  59. #if wxUSE_TOOLTIPS
  60. Widgets_SetTooltip,
  61. #endif // wxUSE_TOOLTIPS
  62. Widgets_SetFgColour,
  63. Widgets_SetBgColour,
  64. Widgets_SetPageBg,
  65. Widgets_SetFont,
  66. Widgets_Enable,
  67. Widgets_BorderNone,
  68. Widgets_BorderStatic,
  69. Widgets_BorderSimple,
  70. Widgets_BorderRaised,
  71. Widgets_BorderSunken,
  72. Widgets_BorderDouble,
  73. Widgets_BorderDefault,
  74. Widgets_LayoutDirection,
  75. Widgets_GlobalBusyCursor,
  76. Widgets_BusyCursor,
  77. Widgets_GoToPage,
  78. Widgets_GoToPageLast = Widgets_GoToPage + 100,
  79. TextEntry_Begin,
  80. TextEntry_DisableAutoComplete = TextEntry_Begin,
  81. TextEntry_AutoCompleteFixed,
  82. TextEntry_AutoCompleteFilenames,
  83. TextEntry_AutoCompleteDirectories,
  84. TextEntry_AutoCompleteCustom,
  85. TextEntry_SetHint,
  86. TextEntry_End
  87. };
  88. const wxChar *WidgetsCategories[MAX_PAGES] = {
  89. #if defined(__WXUNIVERSAL__)
  90. wxT("Universal"),
  91. #else
  92. wxT("Native"),
  93. #endif
  94. wxT("Generic"),
  95. wxT("Pickers"),
  96. wxT("Comboboxes"),
  97. wxT("With items"),
  98. wxT("Editable"),
  99. wxT("Books"),
  100. wxT("All controls")
  101. };
  102. // ----------------------------------------------------------------------------
  103. // our classes
  104. // ----------------------------------------------------------------------------
  105. // Define a new application type, each program should derive a class from wxApp
  106. class WidgetsApp : public wxApp
  107. {
  108. public:
  109. // override base class virtuals
  110. // ----------------------------
  111. // this one is called on application startup and is a good place for the app
  112. // initialization (doing it here and not in the ctor allows to have an error
  113. // return: if OnInit() returns false, the application terminates)
  114. virtual bool OnInit();
  115. };
  116. // Define a new frame type: this is going to be our main frame
  117. class WidgetsFrame : public wxFrame
  118. {
  119. public:
  120. // ctor(s) and dtor
  121. WidgetsFrame(const wxString& title);
  122. virtual ~WidgetsFrame();
  123. protected:
  124. // event handlers
  125. #if USE_LOG
  126. void OnButtonClearLog(wxCommandEvent& event);
  127. #endif // USE_LOG
  128. void OnExit(wxCommandEvent& event);
  129. #if wxUSE_MENUS
  130. void OnPageChanging(WidgetsBookCtrlEvent& event);
  131. void OnPageChanged(WidgetsBookCtrlEvent& event);
  132. void OnGoToPage(wxCommandEvent& event);
  133. #if wxUSE_TOOLTIPS
  134. void OnSetTooltip(wxCommandEvent& event);
  135. #endif // wxUSE_TOOLTIPS
  136. void OnSetFgCol(wxCommandEvent& event);
  137. void OnSetBgCol(wxCommandEvent& event);
  138. void OnSetPageBg(wxCommandEvent& event);
  139. void OnSetFont(wxCommandEvent& event);
  140. void OnEnable(wxCommandEvent& event);
  141. void OnSetBorder(wxCommandEvent& event);
  142. void OnToggleLayoutDirection(wxCommandEvent& event);
  143. void OnToggleGlobalBusyCursor(wxCommandEvent& event);
  144. void OnToggleBusyCursor(wxCommandEvent& event);
  145. // wxTextEntry-specific tests
  146. void OnDisableAutoComplete(wxCommandEvent& event);
  147. void OnAutoCompleteFixed(wxCommandEvent& event);
  148. void OnAutoCompleteFilenames(wxCommandEvent& event);
  149. void OnAutoCompleteDirectories(wxCommandEvent& event);
  150. void OnAutoCompleteCustom(wxCommandEvent& event);
  151. void OnSetHint(wxCommandEvent& event);
  152. void OnUpdateTextUI(wxUpdateUIEvent& event)
  153. {
  154. event.Enable( CurrentPage()->GetTextEntry() != NULL );
  155. }
  156. #endif // wxUSE_MENUS
  157. // initialize the book: add all pages to it
  158. void InitBook();
  159. // return the currently selected page (never NULL)
  160. WidgetsPage *CurrentPage();
  161. private:
  162. // the panel containing everything
  163. wxPanel *m_panel;
  164. #if USE_LOG
  165. // the listbox for logging messages
  166. wxListBox *m_lboxLog;
  167. // the log target we use to redirect messages to the listbox
  168. wxLog *m_logTarget;
  169. #endif // USE_LOG
  170. // the book containing the test pages
  171. WidgetsBookCtrl *m_book;
  172. #if wxUSE_MENUS
  173. // last chosen fg/bg colours and font
  174. wxColour m_colFg,
  175. m_colBg;
  176. wxFont m_font;
  177. #endif // wxUSE_MENUS
  178. // any class wishing to process wxWidgets events must use this macro
  179. wxDECLARE_EVENT_TABLE();
  180. };
  181. #if USE_LOG
  182. // A log target which just redirects the messages to a listbox
  183. class LboxLogger : public wxLog
  184. {
  185. public:
  186. LboxLogger(wxListBox *lbox, wxLog *logOld)
  187. {
  188. m_lbox = lbox;
  189. //m_lbox->Disable(); -- looks ugly under MSW
  190. m_logOld = logOld;
  191. }
  192. virtual ~LboxLogger()
  193. {
  194. wxLog::SetActiveTarget(m_logOld);
  195. }
  196. private:
  197. // implement sink functions
  198. virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg)
  199. {
  200. if ( level == wxLOG_Trace )
  201. {
  202. if ( m_logOld )
  203. m_logOld->LogTextAtLevel(level, msg);
  204. return;
  205. }
  206. #ifdef __WXUNIVERSAL__
  207. m_lbox->AppendAndEnsureVisible(msg);
  208. #else // other ports don't have this method yet
  209. m_lbox->Append(msg);
  210. m_lbox->SetFirstItem(m_lbox->GetCount() - 1);
  211. #endif
  212. }
  213. // the control we use
  214. wxListBox *m_lbox;
  215. // the old log target
  216. wxLog *m_logOld;
  217. };
  218. #endif // USE_LOG
  219. // array of pages
  220. WX_DEFINE_ARRAY_PTR(WidgetsPage *, ArrayWidgetsPage);
  221. // ----------------------------------------------------------------------------
  222. // misc macros
  223. // ----------------------------------------------------------------------------
  224. IMPLEMENT_APP(WidgetsApp)
  225. // ----------------------------------------------------------------------------
  226. // event tables
  227. // ----------------------------------------------------------------------------
  228. wxBEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
  229. #if USE_LOG
  230. EVT_BUTTON(Widgets_ClearLog, WidgetsFrame::OnButtonClearLog)
  231. #endif // USE_LOG
  232. EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnExit)
  233. #if wxUSE_TOOLTIPS
  234. EVT_MENU(Widgets_SetTooltip, WidgetsFrame::OnSetTooltip)
  235. #endif // wxUSE_TOOLTIPS
  236. #if wxUSE_MENUS
  237. EVT_WIDGETS_PAGE_CHANGING(wxID_ANY, WidgetsFrame::OnPageChanging)
  238. EVT_MENU_RANGE(Widgets_GoToPage, Widgets_GoToPageLast,
  239. WidgetsFrame::OnGoToPage)
  240. EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol)
  241. EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol)
  242. EVT_MENU(Widgets_SetPageBg, WidgetsFrame::OnSetPageBg)
  243. EVT_MENU(Widgets_SetFont, WidgetsFrame::OnSetFont)
  244. EVT_MENU(Widgets_Enable, WidgetsFrame::OnEnable)
  245. EVT_MENU_RANGE(Widgets_BorderNone, Widgets_BorderDefault,
  246. WidgetsFrame::OnSetBorder)
  247. EVT_MENU(Widgets_LayoutDirection, WidgetsFrame::OnToggleLayoutDirection)
  248. EVT_MENU(Widgets_GlobalBusyCursor, WidgetsFrame::OnToggleGlobalBusyCursor)
  249. EVT_MENU(Widgets_BusyCursor, WidgetsFrame::OnToggleBusyCursor)
  250. EVT_MENU(TextEntry_DisableAutoComplete, WidgetsFrame::OnDisableAutoComplete)
  251. EVT_MENU(TextEntry_AutoCompleteFixed, WidgetsFrame::OnAutoCompleteFixed)
  252. EVT_MENU(TextEntry_AutoCompleteFilenames, WidgetsFrame::OnAutoCompleteFilenames)
  253. EVT_MENU(TextEntry_AutoCompleteDirectories, WidgetsFrame::OnAutoCompleteDirectories)
  254. EVT_MENU(TextEntry_AutoCompleteCustom, WidgetsFrame::OnAutoCompleteCustom)
  255. EVT_MENU(TextEntry_SetHint, WidgetsFrame::OnSetHint)
  256. EVT_UPDATE_UI_RANGE(TextEntry_Begin, TextEntry_End - 1,
  257. WidgetsFrame::OnUpdateTextUI)
  258. EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit)
  259. #endif // wxUSE_MENUS
  260. wxEND_EVENT_TABLE()
  261. // ============================================================================
  262. // implementation
  263. // ============================================================================
  264. // ----------------------------------------------------------------------------
  265. // app class
  266. // ----------------------------------------------------------------------------
  267. bool WidgetsApp::OnInit()
  268. {
  269. if ( !wxApp::OnInit() )
  270. return false;
  271. SetVendorName("wxWidgets_Samples");
  272. // the reason for having these ifdef's is that I often run two copies of
  273. // this sample side by side and it is useful to see which one is which
  274. wxString title;
  275. #if defined(__WXUNIVERSAL__)
  276. title = wxT("wxUniv/");
  277. #endif
  278. #if defined(__WXMSW__)
  279. title += wxT("wxMSW");
  280. #elif defined(__WXGTK__)
  281. title += wxT("wxGTK");
  282. #elif defined(__WXMAC__)
  283. title += wxT("wxMAC");
  284. #elif defined(__WXMOTIF__)
  285. title += wxT("wxMOTIF");
  286. #else
  287. title += wxT("wxWidgets");
  288. #endif
  289. wxFrame *frame = new WidgetsFrame(title + wxT(" widgets demo"));
  290. frame->Show();
  291. return true;
  292. }
  293. // ----------------------------------------------------------------------------
  294. // WidgetsFrame construction
  295. // ----------------------------------------------------------------------------
  296. WidgetsFrame::WidgetsFrame(const wxString& title)
  297. : wxFrame(NULL, wxID_ANY, title)
  298. {
  299. const bool sizeSet = wxPersistentRegisterAndRestore(this, "Main");
  300. // set the frame icon
  301. SetIcon(wxICON(sample));
  302. // init everything
  303. #if USE_LOG
  304. m_lboxLog = NULL;
  305. m_logTarget = NULL;
  306. #endif // USE_LOG
  307. m_book = NULL;
  308. #if wxUSE_MENUS
  309. // create the menubar
  310. wxMenuBar *mbar = new wxMenuBar;
  311. wxMenu *menuWidget = new wxMenu;
  312. #if wxUSE_TOOLTIPS
  313. menuWidget->Append(Widgets_SetTooltip, wxT("Set &tooltip...\tCtrl-T"));
  314. menuWidget->AppendSeparator();
  315. #endif // wxUSE_TOOLTIPS
  316. menuWidget->Append(Widgets_SetFgColour, wxT("Set &foreground...\tCtrl-F"));
  317. menuWidget->Append(Widgets_SetBgColour, wxT("Set &background...\tCtrl-B"));
  318. menuWidget->Append(Widgets_SetPageBg, wxT("Set &page background...\tShift-Ctrl-B"));
  319. menuWidget->Append(Widgets_SetFont, wxT("Set f&ont...\tCtrl-O"));
  320. menuWidget->AppendCheckItem(Widgets_Enable, wxT("&Enable/disable\tCtrl-E"));
  321. wxMenu *menuBorders = new wxMenu;
  322. menuBorders->AppendRadioItem(Widgets_BorderDefault, wxT("De&fault\tCtrl-Shift-9"));
  323. menuBorders->AppendRadioItem(Widgets_BorderNone, wxT("&None\tCtrl-Shift-0"));
  324. menuBorders->AppendRadioItem(Widgets_BorderSimple, wxT("&Simple\tCtrl-Shift-1"));
  325. menuBorders->AppendRadioItem(Widgets_BorderDouble, wxT("&Double\tCtrl-Shift-2"));
  326. menuBorders->AppendRadioItem(Widgets_BorderStatic, wxT("Stati&c\tCtrl-Shift-3"));
  327. menuBorders->AppendRadioItem(Widgets_BorderRaised, wxT("&Raised\tCtrl-Shift-4"));
  328. menuBorders->AppendRadioItem(Widgets_BorderSunken, wxT("S&unken\tCtrl-Shift-5"));
  329. menuWidget->AppendSubMenu(menuBorders, wxT("Set &border"));
  330. menuWidget->AppendSeparator();
  331. menuWidget->AppendCheckItem(Widgets_LayoutDirection,
  332. "Toggle &layout direction\tCtrl-L");
  333. menuWidget->AppendSeparator();
  334. menuWidget->AppendCheckItem(Widgets_GlobalBusyCursor,
  335. wxT("Toggle &global busy cursor\tCtrl-Shift-U"));
  336. menuWidget->AppendCheckItem(Widgets_BusyCursor,
  337. wxT("Toggle b&usy cursor\tCtrl-U"));
  338. menuWidget->AppendSeparator();
  339. menuWidget->Append(wxID_EXIT, wxT("&Quit\tCtrl-Q"));
  340. mbar->Append(menuWidget, wxT("&Widget"));
  341. wxMenu *menuTextEntry = new wxMenu;
  342. menuTextEntry->AppendRadioItem(TextEntry_DisableAutoComplete,
  343. wxT("&Disable auto-completion"));
  344. menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFixed,
  345. wxT("Fixed-&list auto-completion"));
  346. menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFilenames,
  347. wxT("&Files names auto-completion"));
  348. menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteDirectories,
  349. wxT("&Directories names auto-completion"));
  350. menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteCustom,
  351. wxT("&Custom auto-completion"));
  352. menuTextEntry->AppendSeparator();
  353. menuTextEntry->Append(TextEntry_SetHint, "Set help &hint");
  354. mbar->Append(menuTextEntry, wxT("&Text"));
  355. SetMenuBar(mbar);
  356. mbar->Check(Widgets_Enable, true);
  357. #endif // wxUSE_MENUS
  358. // create controls
  359. m_panel = new wxPanel(this, wxID_ANY);
  360. wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
  361. // we have 2 panes: book with pages demonstrating the controls in the
  362. // upper one and the log window with some buttons in the lower
  363. int style = wxBK_DEFAULT;
  364. // Uncomment to suppress page theme (draw in solid colour)
  365. //style |= wxNB_NOPAGETHEME;
  366. m_book = new WidgetsBookCtrl(m_panel, Widgets_BookCtrl,
  367. wxDefaultPosition, wxDefaultSize,
  368. style, "Widgets");
  369. InitBook();
  370. #ifndef __WXHANDHELD__
  371. // the lower one only has the log listbox and a button to clear it
  372. #if USE_LOG
  373. wxSizer *sizerDown = new wxStaticBoxSizer(
  374. new wxStaticBox( m_panel, wxID_ANY, wxT("&Log window") ),
  375. wxVERTICAL);
  376. m_lboxLog = new wxListBox(m_panel, wxID_ANY);
  377. sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5);
  378. sizerDown->SetMinSize(100, 150);
  379. #else
  380. wxSizer *sizerDown = new wxBoxSizer(wxVERTICAL);
  381. #endif // USE_LOG
  382. wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
  383. wxButton *btn;
  384. #if USE_LOG
  385. btn = new wxButton(m_panel, Widgets_ClearLog, wxT("Clear &log"));
  386. sizerBtns->Add(btn);
  387. sizerBtns->Add(10, 0); // spacer
  388. #endif // USE_LOG
  389. btn = new wxButton(m_panel, Widgets_Quit, wxT("E&xit"));
  390. sizerBtns->Add(btn);
  391. sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5);
  392. // put everything together
  393. sizerTop->Add(m_book, 1, wxGROW | (wxALL & ~(wxTOP | wxBOTTOM)), 10);
  394. sizerTop->Add(0, 5, 0, wxGROW); // spacer in between
  395. sizerTop->Add(sizerDown, 0, wxGROW | (wxALL & ~wxTOP), 10);
  396. #else // !__WXHANDHELD__/__WXHANDHELD__
  397. sizerTop->Add(m_book, 1, wxGROW | wxALL );
  398. #endif // __WXHANDHELD__
  399. m_panel->SetSizer(sizerTop);
  400. const wxSize sizeMin = m_panel->GetBestSize();
  401. if ( !sizeSet )
  402. SetClientSize(sizeMin);
  403. SetMinClientSize(sizeMin);
  404. #if USE_LOG && !defined(__WXCOCOA__)
  405. // wxCocoa's listbox is too flakey to use for logging right now
  406. // now that everything is created we can redirect the log messages to the
  407. // listbox
  408. m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget());
  409. wxLog::SetActiveTarget(m_logTarget);
  410. #endif
  411. }
  412. void WidgetsFrame::InitBook()
  413. {
  414. #if USE_ICONS_IN_BOOK
  415. wxImageList *imageList = new wxImageList(ICON_SIZE, ICON_SIZE);
  416. wxImage img(sample_xpm);
  417. imageList->Add(wxBitmap(img.Scale(ICON_SIZE, ICON_SIZE)));
  418. #else
  419. wxImageList *imageList = NULL;
  420. #endif
  421. #if !USE_TREEBOOK
  422. WidgetsBookCtrl *books[MAX_PAGES];
  423. #endif
  424. ArrayWidgetsPage pages[MAX_PAGES];
  425. wxArrayString labels[MAX_PAGES];
  426. wxMenu *menuPages = new wxMenu;
  427. unsigned int nPage = 0, nFKey = 0;
  428. int cat, imageId = 1;
  429. // we need to first create all pages and only then add them to the book
  430. // as we need the image list first
  431. //
  432. // we also construct the pages menu during this first iteration
  433. for ( cat = 0; cat < MAX_PAGES; cat++ )
  434. {
  435. #if USE_TREEBOOK
  436. nPage++; // increase for parent page
  437. #else
  438. books[cat] = new WidgetsBookCtrl(m_book,
  439. wxID_ANY,
  440. wxDefaultPosition,
  441. wxDefaultSize,
  442. wxBK_DEFAULT);
  443. #endif
  444. for ( WidgetsPageInfo *info = WidgetsPage::ms_widgetPages;
  445. info;
  446. info = info->GetNext() )
  447. {
  448. if( (info->GetCategories() & ( 1 << cat )) == 0)
  449. continue;
  450. WidgetsPage *page = (*info->GetCtor())(
  451. #if USE_TREEBOOK
  452. m_book
  453. #else
  454. books[cat]
  455. #endif
  456. , imageList);
  457. pages[cat].Add(page);
  458. labels[cat].Add(info->GetLabel());
  459. if ( cat == ALL_PAGE )
  460. {
  461. wxString radioLabel(info->GetLabel());
  462. nFKey++;
  463. if ( nFKey <= 12 )
  464. {
  465. radioLabel << wxT("\tF" ) << nFKey;
  466. }
  467. menuPages->AppendRadioItem(
  468. Widgets_GoToPage + nPage,
  469. radioLabel
  470. );
  471. #if !USE_TREEBOOK
  472. // consider only for book in book architecture
  473. nPage++;
  474. #endif
  475. }
  476. #if USE_TREEBOOK
  477. // consider only for treebook architecture (with subpages)
  478. nPage++;
  479. #endif
  480. }
  481. }
  482. GetMenuBar()->Append(menuPages, wxT("&Page"));
  483. #if USE_ICONS_IN_BOOK
  484. m_book->AssignImageList(imageList);
  485. #endif
  486. for ( cat = 0; cat < MAX_PAGES; cat++ )
  487. {
  488. #if USE_TREEBOOK
  489. m_book->AddPage(NULL,WidgetsCategories[cat],false,0);
  490. #else
  491. m_book->AddPage(books[cat],WidgetsCategories[cat],false,0);
  492. #if USE_ICONS_IN_BOOK
  493. books[cat]->SetImageList(imageList);
  494. #endif
  495. #endif
  496. // now do add them
  497. size_t count = pages[cat].GetCount();
  498. for ( size_t n = 0; n < count; n++ )
  499. {
  500. #if USE_TREEBOOK
  501. m_book->AddSubPage
  502. #else
  503. books[cat]->AddPage
  504. #endif
  505. (
  506. pages[cat][n],
  507. labels[cat][n],
  508. false, // don't select
  509. imageId++
  510. );
  511. }
  512. }
  513. Connect( wxID_ANY,
  514. wxEVT_COMMAND_WIDGETS_PAGE_CHANGED,
  515. wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged) );
  516. const bool pageSet = wxPersistentRegisterAndRestore(m_book);
  517. #if USE_TREEBOOK
  518. // for treebook page #0 is empty parent page only so select the first page
  519. // with some contents
  520. if ( !pageSet )
  521. m_book->SetSelection(1);
  522. // but ensure that the top of the tree is shown nevertheless
  523. wxTreeCtrl * const tree = m_book->GetTreeCtrl();
  524. wxTreeItemIdValue cookie;
  525. tree->EnsureVisible(tree->GetFirstChild(tree->GetRootItem(), cookie));
  526. #else
  527. if ( !pageSet )
  528. {
  529. // for other books set selection twice to force connected event handler
  530. // to force lazy creation of initial visible content
  531. m_book->SetSelection(1);
  532. m_book->SetSelection(0);
  533. }
  534. #endif // USE_TREEBOOK
  535. }
  536. WidgetsPage *WidgetsFrame::CurrentPage()
  537. {
  538. wxWindow *page = m_book->GetCurrentPage();
  539. #if !USE_TREEBOOK
  540. WidgetsBookCtrl *subBook = wxStaticCast(page, WidgetsBookCtrl);
  541. wxCHECK_MSG( subBook, NULL, wxT("no WidgetsBookCtrl?") );
  542. page = subBook->GetCurrentPage();
  543. #endif // !USE_TREEBOOK
  544. return wxStaticCast(page, WidgetsPage);
  545. }
  546. WidgetsFrame::~WidgetsFrame()
  547. {
  548. #if USE_LOG
  549. delete m_logTarget;
  550. #endif // USE_LOG
  551. }
  552. // ----------------------------------------------------------------------------
  553. // WidgetsFrame event handlers
  554. // ----------------------------------------------------------------------------
  555. void WidgetsFrame::OnExit(wxCommandEvent& WXUNUSED(event))
  556. {
  557. Close();
  558. }
  559. #if USE_LOG
  560. void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
  561. {
  562. m_lboxLog->Clear();
  563. }
  564. #endif // USE_LOG
  565. #if wxUSE_MENUS
  566. void WidgetsFrame::OnPageChanging(WidgetsBookCtrlEvent& event)
  567. {
  568. #if USE_TREEBOOK
  569. // don't allow selection of entries without pages (categories)
  570. if ( !m_book->GetPage(event.GetSelection()) )
  571. event.Veto();
  572. #else
  573. wxUnusedVar(event);
  574. #endif
  575. }
  576. void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent& event)
  577. {
  578. const int sel = event.GetSelection();
  579. // adjust "Page" menu selection
  580. wxMenuItem *item = GetMenuBar()->FindItem(Widgets_GoToPage + sel);
  581. if ( item )
  582. item->Check();
  583. GetMenuBar()->Check(Widgets_BusyCursor, false);
  584. // create the pages on demand, otherwise the sample startup is too slow as
  585. // it creates hundreds of controls
  586. WidgetsPage *page = CurrentPage();
  587. if ( page->GetChildren().empty() )
  588. {
  589. wxWindowUpdateLocker noUpdates(page);
  590. page->CreateContent();
  591. //page->Layout();
  592. page->GetSizer()->Fit(page);
  593. WidgetsBookCtrl *book = wxStaticCast(page->GetParent(), WidgetsBookCtrl);
  594. wxSize size;
  595. for ( size_t i = 0; i < book->GetPageCount(); ++i )
  596. {
  597. wxWindow *page = book->GetPage(i);
  598. if ( page )
  599. {
  600. size.IncTo(page->GetSize());
  601. }
  602. }
  603. page->SetSize(size);
  604. }
  605. event.Skip();
  606. }
  607. void WidgetsFrame::OnGoToPage(wxCommandEvent& event)
  608. {
  609. #if USE_TREEBOOK
  610. m_book->SetSelection(event.GetId() - Widgets_GoToPage);
  611. #else
  612. m_book->SetSelection(m_book->GetPageCount()-1);
  613. WidgetsBookCtrl *book = wxStaticCast(m_book->GetCurrentPage(), WidgetsBookCtrl);
  614. book->SetSelection(event.GetId() - Widgets_GoToPage);
  615. #endif
  616. }
  617. #if wxUSE_TOOLTIPS
  618. void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event))
  619. {
  620. static wxString s_tip = wxT("This is a tooltip");
  621. wxTextEntryDialog dialog
  622. (
  623. this,
  624. wxT("Tooltip text (may use \\n, leave empty to remove): "),
  625. wxT("Widgets sample"),
  626. s_tip
  627. );
  628. if ( dialog.ShowModal() != wxID_OK )
  629. return;
  630. s_tip = dialog.GetValue();
  631. s_tip.Replace(wxT("\\n"), wxT("\n"));
  632. WidgetsPage *page = CurrentPage();
  633. const Widgets widgets = page->GetWidgets();
  634. for ( Widgets::const_iterator it = widgets.begin();
  635. it != widgets.end();
  636. ++it )
  637. {
  638. (*it)->SetToolTip(s_tip);
  639. }
  640. }
  641. #endif // wxUSE_TOOLTIPS
  642. namespace
  643. {
  644. // Trivial wrapper for wxGetColourFromUser() which also does something even if
  645. // the colour dialog is not available in the current build (which may happen
  646. // for the ports in development and it is still useful to see how colours work)
  647. wxColour GetColourFromUser(wxWindow *parent, const wxColour& colDefault)
  648. {
  649. #if wxUSE_COLOURDLG
  650. return wxGetColourFromUser(parent, colDefault);
  651. #else // !wxUSE_COLOURDLG
  652. if ( colDefault == *wxBLACK )
  653. return *wxWHITE;
  654. else
  655. return *wxBLACK;
  656. #endif // wxUSE_COLOURDLG/!wxUSE_COLOURDLG
  657. }
  658. } // anonymous namespace
  659. void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event))
  660. {
  661. // allow for debugging the default colour the first time this is called
  662. WidgetsPage *page = CurrentPage();
  663. if (!m_colFg.IsOk())
  664. m_colFg = page->GetForegroundColour();
  665. wxColour col = GetColourFromUser(this, m_colFg);
  666. if ( !col.IsOk() )
  667. return;
  668. m_colFg = col;
  669. const Widgets widgets = page->GetWidgets();
  670. for ( Widgets::const_iterator it = widgets.begin();
  671. it != widgets.end();
  672. ++it )
  673. {
  674. (*it)->SetForegroundColour(m_colFg);
  675. (*it)->Refresh();
  676. }
  677. }
  678. void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
  679. {
  680. WidgetsPage *page = CurrentPage();
  681. if ( !m_colBg.IsOk() )
  682. m_colBg = page->GetBackgroundColour();
  683. wxColour col = GetColourFromUser(this, m_colBg);
  684. if ( !col.IsOk() )
  685. return;
  686. m_colBg = col;
  687. const Widgets widgets = page->GetWidgets();
  688. for ( Widgets::const_iterator it = widgets.begin();
  689. it != widgets.end();
  690. ++it )
  691. {
  692. (*it)->SetBackgroundColour(m_colBg);
  693. (*it)->Refresh();
  694. }
  695. }
  696. void WidgetsFrame::OnSetPageBg(wxCommandEvent& WXUNUSED(event))
  697. {
  698. wxColour col = GetColourFromUser(this, GetBackgroundColour());
  699. if ( !col.IsOk() )
  700. return;
  701. CurrentPage()->SetBackgroundColour(col);
  702. CurrentPage()->Refresh();
  703. }
  704. void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event))
  705. {
  706. #if wxUSE_FONTDLG
  707. WidgetsPage *page = CurrentPage();
  708. if (!m_font.IsOk())
  709. m_font = page->GetFont();
  710. wxFont font = wxGetFontFromUser(this, m_font);
  711. if ( !font.IsOk() )
  712. return;
  713. m_font = font;
  714. const Widgets widgets = page->GetWidgets();
  715. for ( Widgets::const_iterator it = widgets.begin();
  716. it != widgets.end();
  717. ++it )
  718. {
  719. (*it)->SetFont(m_font);
  720. (*it)->Refresh();
  721. }
  722. // The best size of the widget could have changed after changing its font,
  723. // so re-layout to show it correctly.
  724. page->Layout();
  725. #else
  726. wxLogMessage(wxT("Font selection dialog not available in current build."));
  727. #endif
  728. }
  729. void WidgetsFrame::OnEnable(wxCommandEvent& event)
  730. {
  731. const Widgets widgets = CurrentPage()->GetWidgets();
  732. for ( Widgets::const_iterator it = widgets.begin();
  733. it != widgets.end();
  734. ++it )
  735. {
  736. (*it)->Enable(event.IsChecked());
  737. }
  738. }
  739. void WidgetsFrame::OnSetBorder(wxCommandEvent& event)
  740. {
  741. int border;
  742. switch ( event.GetId() )
  743. {
  744. case Widgets_BorderNone: border = wxBORDER_NONE; break;
  745. case Widgets_BorderStatic: border = wxBORDER_STATIC; break;
  746. case Widgets_BorderSimple: border = wxBORDER_SIMPLE; break;
  747. case Widgets_BorderRaised: border = wxBORDER_RAISED; break;
  748. case Widgets_BorderSunken: border = wxBORDER_SUNKEN; break;
  749. case Widgets_BorderDouble: border = wxBORDER_DOUBLE; break;
  750. default:
  751. wxFAIL_MSG( wxT("unknown border style") );
  752. // fall through
  753. case Widgets_BorderDefault: border = wxBORDER_DEFAULT; break;
  754. }
  755. WidgetsPage::ms_defaultFlags &= ~wxBORDER_MASK;
  756. WidgetsPage::ms_defaultFlags |= border;
  757. WidgetsPage *page = CurrentPage();
  758. page->RecreateWidget();
  759. }
  760. void WidgetsFrame::OnToggleLayoutDirection(wxCommandEvent& event)
  761. {
  762. wxLayoutDirection dir = event.IsChecked() ? wxLayout_RightToLeft
  763. : wxLayout_LeftToRight;
  764. const Widgets widgets = CurrentPage()->GetWidgets();
  765. for ( Widgets::const_iterator it = widgets.begin();
  766. it != widgets.end();
  767. ++it )
  768. {
  769. (*it)->SetLayoutDirection(dir);
  770. (*it)->Refresh();
  771. }
  772. }
  773. void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent& event)
  774. {
  775. if ( event.IsChecked() )
  776. wxBeginBusyCursor();
  777. else
  778. wxEndBusyCursor();
  779. }
  780. void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent& event)
  781. {
  782. wxCursor cursor(*(event.IsChecked() ? wxHOURGLASS_CURSOR
  783. : wxSTANDARD_CURSOR));
  784. const Widgets widgets = CurrentPage()->GetWidgets();
  785. for ( Widgets::const_iterator it = widgets.begin();
  786. it != widgets.end();
  787. ++it )
  788. {
  789. (*it)->SetCursor(cursor);
  790. }
  791. }
  792. void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent& WXUNUSED(event))
  793. {
  794. wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
  795. wxCHECK_RET( entry, "menu item should be disabled" );
  796. if ( entry->AutoComplete(wxArrayString()) )
  797. {
  798. wxLogMessage("Disabled auto completion.");
  799. }
  800. else
  801. {
  802. wxLogMessage("AutoComplete() failed.");
  803. }
  804. }
  805. void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent& WXUNUSED(event))
  806. {
  807. wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
  808. wxCHECK_RET( entry, "menu item should be disabled" );
  809. wxArrayString completion_choices;
  810. // add a few strings so a completion occurs on any letter typed
  811. for ( char idxc = 'a'; idxc < 'z'; ++idxc )
  812. completion_choices.push_back(wxString::Format("%c%c", idxc, idxc));
  813. completion_choices.push_back("is this string for test?");
  814. completion_choices.push_back("this is a test string");
  815. completion_choices.push_back("this is another test string");
  816. completion_choices.push_back("this string is for test");
  817. if ( entry->AutoComplete(completion_choices) )
  818. {
  819. wxLogMessage("Enabled auto completion of a set of fixed strings.");
  820. }
  821. else
  822. {
  823. wxLogMessage("AutoComplete() failed.");
  824. }
  825. }
  826. void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent& WXUNUSED(event))
  827. {
  828. wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
  829. wxCHECK_RET( entry, "menu item should be disabled" );
  830. if ( entry->AutoCompleteFileNames() )
  831. {
  832. wxLogMessage("Enabled auto completion of file names.");
  833. }
  834. else
  835. {
  836. wxLogMessage("AutoCompleteFileNames() failed.");
  837. }
  838. }
  839. void WidgetsFrame::OnAutoCompleteDirectories(wxCommandEvent& WXUNUSED(event))
  840. {
  841. wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
  842. wxCHECK_RET( entry, "menu item should be disabled" );
  843. if ( entry->AutoCompleteDirectories() )
  844. {
  845. wxLogMessage("Enabled auto completion of directories.");
  846. }
  847. else
  848. {
  849. wxLogMessage("AutoCompleteDirectories() failed.");
  850. }
  851. }
  852. void WidgetsFrame::OnAutoCompleteCustom(wxCommandEvent& WXUNUSED(event))
  853. {
  854. wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
  855. wxCHECK_RET( entry, "menu item should be disabled" );
  856. // This is a simple (and hence rather useless) example of a custom
  857. // completer class that completes the first word (only) initially and only
  858. // build the list of the possible second words once the first word is
  859. // known. This allows to avoid building the full 676000 item list of
  860. // possible strings all at once as the we have 1000 possibilities for the
  861. // first word (000..999) and 676 (aa..zz) for the second one.
  862. class CustomTextCompleter : public wxTextCompleterSimple
  863. {
  864. public:
  865. virtual void GetCompletions(const wxString& prefix, wxArrayString& res)
  866. {
  867. // This is used for illustrative purposes only and shows how many
  868. // completions we return every time when we're called.
  869. class LogCompletions
  870. {
  871. public:
  872. LogCompletions(const wxString& prefix, const wxArrayString& res)
  873. : m_prefix(prefix),
  874. m_res(res)
  875. {
  876. }
  877. ~LogCompletions()
  878. {
  879. wxLogMessage("Returning %lu possible completions for "
  880. "prefix \"%s\"",
  881. m_res.size(), m_prefix);
  882. }
  883. private:
  884. const wxString& m_prefix;
  885. const wxArrayString& m_res;
  886. } logCompletions(prefix, res);
  887. // Normally it doesn't make sense to complete empty control, there
  888. // are too many choices and listing them all wouldn't be helpful.
  889. if ( prefix.empty() )
  890. return;
  891. // The only valid strings start with 3 digits so check for their
  892. // presence proposing to complete the remaining ones.
  893. if ( !wxIsdigit(prefix[0]) )
  894. return;
  895. if ( prefix.length() == 1 )
  896. {
  897. for ( int i = 0; i < 10; i++ )
  898. for ( int j = 0; j < 10; j++ )
  899. res.push_back(wxString::Format("%s%02d",
  900. prefix, 10*i + j));
  901. return;
  902. }
  903. else if ( !wxIsdigit(prefix[1]) )
  904. return;
  905. if ( prefix.length() == 2 )
  906. {
  907. for ( int i = 0; i < 10; i++ )
  908. res.push_back(wxString::Format("%s%d", prefix, i));
  909. return;
  910. }
  911. else if ( !wxIsdigit(prefix[2]) )
  912. return;
  913. // Next we must have a space and two letters.
  914. wxString prefix2(prefix);
  915. if ( prefix.length() == 3 )
  916. prefix2 += ' ';
  917. else if ( prefix[3] != ' ' )
  918. return;
  919. if ( prefix2.length() == 4 )
  920. {
  921. for ( char c = 'a'; c <= 'z'; c++ )
  922. for ( char d = 'a'; d <= 'z'; d++ )
  923. res.push_back(wxString::Format("%s%c%c", prefix2, c, d));
  924. return;
  925. }
  926. else if ( !wxIslower(prefix[4]) )
  927. return;
  928. if ( prefix.length() == 5 )
  929. {
  930. for ( char c = 'a'; c <= 'z'; c++ )
  931. res.push_back(prefix + c);
  932. }
  933. }
  934. };
  935. if ( entry->AutoComplete(new CustomTextCompleter) )
  936. {
  937. wxLogMessage("Enabled custom auto completer for \"NNN XX\" items "
  938. "(where N is a digit and X is a letter).");
  939. }
  940. else
  941. {
  942. wxLogMessage("AutoComplete() failed.");
  943. }
  944. }
  945. void WidgetsFrame::OnSetHint(wxCommandEvent& WXUNUSED(event))
  946. {
  947. wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
  948. wxCHECK_RET( entry, "menu item should be disabled" );
  949. static wxString s_hint("Type here");
  950. wxString
  951. hint = wxGetTextFromUser("Text hint:", "Widgets sample", s_hint, this);
  952. if ( hint.empty() )
  953. return;
  954. s_hint = hint;
  955. if ( entry->SetHint(hint) )
  956. {
  957. wxLogMessage("Set hint to \"%s\".", hint);
  958. }
  959. else
  960. {
  961. wxLogMessage("Text hints not supported.");
  962. }
  963. }
  964. #endif // wxUSE_MENUS
  965. // ----------------------------------------------------------------------------
  966. // WidgetsPageInfo
  967. // ----------------------------------------------------------------------------
  968. WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories)
  969. : m_label(label)
  970. , m_categories(categories)
  971. {
  972. m_ctor = ctor;
  973. m_next = NULL;
  974. // dummy sorting: add and immediately sort in the list according to label
  975. if ( WidgetsPage::ms_widgetPages )
  976. {
  977. WidgetsPageInfo *node_prev = WidgetsPage::ms_widgetPages;
  978. if ( wxStrcmp(label, node_prev->GetLabel().c_str()) < 0 )
  979. {
  980. // add as first
  981. m_next = node_prev;
  982. WidgetsPage::ms_widgetPages = this;
  983. }
  984. else
  985. {
  986. WidgetsPageInfo *node_next;
  987. do
  988. {
  989. node_next = node_prev->GetNext();
  990. if ( node_next )
  991. {
  992. // add if between two
  993. if ( wxStrcmp(label, node_next->GetLabel().c_str()) < 0 )
  994. {
  995. node_prev->SetNext(this);
  996. m_next = node_next;
  997. // force to break loop
  998. node_next = NULL;
  999. }
  1000. }
  1001. else
  1002. {
  1003. // add as last
  1004. node_prev->SetNext(this);
  1005. m_next = node_next;
  1006. }
  1007. node_prev = node_next;
  1008. }
  1009. while ( node_next );
  1010. }
  1011. }
  1012. else
  1013. {
  1014. // add when first
  1015. WidgetsPage::ms_widgetPages = this;
  1016. }
  1017. }
  1018. // ----------------------------------------------------------------------------
  1019. // WidgetsPage
  1020. // ----------------------------------------------------------------------------
  1021. int WidgetsPage::ms_defaultFlags = wxBORDER_DEFAULT;
  1022. WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL;
  1023. WidgetsPage::WidgetsPage(WidgetsBookCtrl *book,
  1024. wxImageList *imaglist,
  1025. const char *const icon[])
  1026. : wxPanel(book, wxID_ANY,
  1027. wxDefaultPosition, wxDefaultSize,
  1028. wxNO_FULL_REPAINT_ON_RESIZE |
  1029. wxCLIP_CHILDREN |
  1030. wxTAB_TRAVERSAL)
  1031. {
  1032. #if USE_ICONS_IN_BOOK
  1033. imaglist->Add(wxBitmap(wxImage(icon).Scale(ICON_SIZE, ICON_SIZE)));
  1034. #else
  1035. wxUnusedVar(imaglist);
  1036. wxUnusedVar(icon);
  1037. #endif
  1038. }
  1039. wxSizer *WidgetsPage::CreateSizerWithText(wxControl *control,
  1040. wxWindowID id,
  1041. wxTextCtrl **ppText)
  1042. {
  1043. wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
  1044. wxTextCtrl *text = new wxTextCtrl(this, id, wxEmptyString,
  1045. wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
  1046. sizerRow->Add(control, 0, wxRIGHT | wxALIGN_CENTRE_VERTICAL, 5);
  1047. sizerRow->Add(text, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
  1048. if ( ppText )
  1049. *ppText = text;
  1050. return sizerRow;
  1051. }
  1052. // create a sizer containing a label and a text ctrl
  1053. wxSizer *WidgetsPage::CreateSizerWithTextAndLabel(const wxString& label,
  1054. wxWindowID id,
  1055. wxTextCtrl **ppText)
  1056. {
  1057. return CreateSizerWithText(new wxStaticText(this, wxID_ANY, label),
  1058. id, ppText);
  1059. }
  1060. // create a sizer containing a button and a text ctrl
  1061. wxSizer *WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn,
  1062. const wxString& label,
  1063. wxWindowID id,
  1064. wxTextCtrl **ppText)
  1065. {
  1066. return CreateSizerWithText(new wxButton(this, idBtn, label), id, ppText);
  1067. }
  1068. wxCheckBox *WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer *sizer,
  1069. const wxString& label,
  1070. wxWindowID id)
  1071. {
  1072. wxCheckBox *checkbox = new wxCheckBox(this, id, label);
  1073. sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
  1074. sizer->Add(0, 2, 0, wxGROW); // spacer
  1075. return checkbox;
  1076. }