widgets.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Program: wxWidgets Widgets Sample
  3. // Name: widgets.h
  4. // Purpose: Common stuff for all widgets project files
  5. // Author: Vadim Zeitlin
  6. // Created: 27.03.01
  7. // Copyright: (c) 2001 Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_SAMPLE_WIDGETS_H_
  11. #define _WX_SAMPLE_WIDGETS_H_
  12. #if wxUSE_TREEBOOK && !defined(__WXHANDHELD__)
  13. #include "wx/treebook.h"
  14. #define USE_TREEBOOK 1
  15. #define WidgetsBookCtrl wxTreebook
  16. #define WidgetsBookCtrlEvent wxTreebookEvent
  17. #define EVT_WIDGETS_PAGE_CHANGING(id,func) EVT_TREEBOOK_PAGE_CHANGING(id,func)
  18. #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_TREEBOOK_PAGE_CHANGED
  19. #define wxWidgetsbookEventHandler(func) wxTreebookEventHandler(func)
  20. #else
  21. #include "wx/bookctrl.h"
  22. #define USE_TREEBOOK 0
  23. #define WidgetsBookCtrl wxBookCtrl
  24. #define WidgetsBookCtrlEvent wxBookCtrlEvent
  25. #define EVT_WIDGETS_PAGE_CHANGING(id,func) EVT_BOOKCTRL_PAGE_CHANGING(id,func)
  26. #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_BOOKCTRL_PAGE_CHANGED
  27. #define wxWidgetsbookEventHandler(func) wxBookCtrlEventHandler(func)
  28. #endif
  29. #if wxUSE_LOG && !defined(__WXHANDHELD__)
  30. #define USE_LOG 1
  31. #else
  32. #define USE_LOG 0
  33. #endif
  34. #if defined(__WXHANDHELD__)
  35. #define USE_ICONS_IN_BOOK 0
  36. #else
  37. #define USE_ICONS_IN_BOOK 1
  38. #define ICON_SIZE 16
  39. #endif
  40. class WXDLLIMPEXP_FWD_CORE wxCheckBox;
  41. class WXDLLIMPEXP_FWD_CORE wxSizer;
  42. class WXDLLIMPEXP_FWD_CORE wxImageList;
  43. class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
  44. class WXDLLIMPEXP_FWD_CORE WidgetsBookCtrl;
  45. class WidgetsPageInfo;
  46. #include "wx/panel.h"
  47. #include "wx/vector.h"
  48. // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
  49. enum
  50. {
  51. // In wxUniversal-based builds 'native' means 'made with wxUniv port
  52. // renderer'
  53. NATIVE_PAGE = 0,
  54. UNIVERSAL_PAGE = NATIVE_PAGE,
  55. GENERIC_PAGE,
  56. PICKER_PAGE,
  57. COMBO_PAGE,
  58. WITH_ITEMS_PAGE,
  59. EDITABLE_PAGE,
  60. BOOK_PAGE,
  61. ALL_PAGE,
  62. MAX_PAGES
  63. };
  64. enum
  65. {
  66. NATIVE_CTRLS = 1 << NATIVE_PAGE,
  67. UNIVERSAL_CTRLS = NATIVE_CTRLS,
  68. GENERIC_CTRLS = 1 << GENERIC_PAGE,
  69. PICKER_CTRLS = 1 << PICKER_PAGE,
  70. COMBO_CTRLS = 1 << COMBO_PAGE,
  71. WITH_ITEMS_CTRLS = 1 << WITH_ITEMS_PAGE,
  72. EDITABLE_CTRLS = 1 << EDITABLE_PAGE,
  73. BOOK_CTRLS = 1 << BOOK_PAGE,
  74. ALL_CTRLS = 1 << ALL_PAGE
  75. };
  76. typedef wxVector<wxControl *> Widgets;
  77. // ----------------------------------------------------------------------------
  78. // WidgetsPage: a book page demonstrating some widget
  79. // ----------------------------------------------------------------------------
  80. class WidgetsPage : public wxPanel
  81. {
  82. public:
  83. WidgetsPage(WidgetsBookCtrl *book,
  84. wxImageList *imaglist,
  85. const char *const icon[]);
  86. // return the control shown by this page
  87. virtual wxControl *GetWidget() const = 0;
  88. // return the control shown by this page, if it supports text entry interface
  89. virtual wxTextEntryBase *GetTextEntry() const { return NULL; }
  90. // lazy creation of the content
  91. virtual void CreateContent() = 0;
  92. // some pages show additional controls, in this case override this one to
  93. // return all of them (including the one returned by GetWidget())
  94. virtual Widgets GetWidgets() const
  95. {
  96. Widgets widgets;
  97. widgets.push_back(GetWidget());
  98. return widgets;
  99. }
  100. // recreate the control shown by this page
  101. //
  102. // this is currently used only to take into account the border flags
  103. virtual void RecreateWidget() = 0;
  104. // the default flags for the widget, currently only contains border flags
  105. static int ms_defaultFlags;
  106. protected:
  107. // several helper functions for page creation
  108. // create a horz sizer containing the given control and the text ctrl
  109. // (pointer to which will be saved in the provided variable if not NULL)
  110. // with the specified id
  111. wxSizer *CreateSizerWithText(wxControl *control,
  112. wxWindowID id = wxID_ANY,
  113. wxTextCtrl **ppText = NULL);
  114. // create a sizer containing a label and a text ctrl
  115. wxSizer *CreateSizerWithTextAndLabel(const wxString& label,
  116. wxWindowID id = wxID_ANY,
  117. wxTextCtrl **ppText = NULL);
  118. // create a sizer containing a button and a text ctrl
  119. wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn,
  120. const wxString& labelBtn,
  121. wxWindowID id = wxID_ANY,
  122. wxTextCtrl **ppText = NULL);
  123. // create a checkbox and add it to the sizer
  124. wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer,
  125. const wxString& label,
  126. wxWindowID id = wxID_ANY);
  127. public:
  128. // the head of the linked list containinginfo about all pages
  129. static WidgetsPageInfo *ms_widgetPages;
  130. };
  131. // ----------------------------------------------------------------------------
  132. // dynamic WidgetsPage creation helpers
  133. // ----------------------------------------------------------------------------
  134. class WidgetsPageInfo
  135. {
  136. public:
  137. typedef WidgetsPage *(*Constructor)(WidgetsBookCtrl *book,
  138. wxImageList *imaglist);
  139. // our ctor
  140. WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories);
  141. // accessors
  142. const wxString& GetLabel() const { return m_label; }
  143. int GetCategories() const { return m_categories; }
  144. Constructor GetCtor() const { return m_ctor; }
  145. WidgetsPageInfo *GetNext() const { return m_next; }
  146. void SetNext(WidgetsPageInfo *next) { m_next = next; }
  147. private:
  148. // the label of the page
  149. wxString m_label;
  150. // the list (flags) for sharing page between categories
  151. int m_categories;
  152. // the function to create this page
  153. Constructor m_ctor;
  154. // next node in the linked list or NULL
  155. WidgetsPageInfo *m_next;
  156. };
  157. // to declare a page, this macro must be used in the class declaration
  158. #define DECLARE_WIDGETS_PAGE(classname) \
  159. private: \
  160. static WidgetsPageInfo ms_info##classname; \
  161. public: \
  162. const WidgetsPageInfo *GetPageInfo() const \
  163. { return &ms_info##classname; }
  164. // and this one must be inserted somewhere in the source file
  165. #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
  166. WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
  167. wxImageList *imaglist) \
  168. { return new classname(book, imaglist); } \
  169. WidgetsPageInfo classname:: \
  170. ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
  171. #endif // _WX_SAMPLE_WIDGETS_H_