]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
be5a51fb | 2 | // Program: wxWidgets Widgets Sample |
32b8ec41 VZ |
3 | // Name: widgets.h |
4 | // Purpose: Common stuff for all widgets project files | |
5 | // Author: Vadim Zeitlin | |
6 | // Created: 27.03.01 | |
7 | // Id: $Id$ | |
8 | // Copyright: (c) 2001 Vadim Zeitlin | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_SAMPLE_WIDGETS_H_ | |
13 | #define _WX_SAMPLE_WIDGETS_H_ | |
14 | ||
15 | class WXDLLEXPORT wxCheckBox; | |
61c083e7 | 16 | class WXDLLEXPORT wxBookCtrl; |
32b8ec41 VZ |
17 | class WXDLLEXPORT wxSizer; |
18 | class WXDLLEXPORT wxTextCtrl; | |
19 | ||
2b5f62a0 | 20 | class WidgetsPageInfo; |
32b8ec41 | 21 | |
0b90b51c GD |
22 | #include "wx/panel.h" |
23 | ||
32b8ec41 VZ |
24 | // all source files use wxImageList |
25 | #include "wx/imaglist.h" | |
26 | ||
27 | // ---------------------------------------------------------------------------- | |
61c083e7 | 28 | // WidgetsPage: a book page demonstrating some widget |
32b8ec41 VZ |
29 | // ---------------------------------------------------------------------------- |
30 | ||
31 | class WidgetsPage : public wxPanel | |
32 | { | |
33 | public: | |
61c083e7 | 34 | WidgetsPage(wxBookCtrl *book); |
32b8ec41 | 35 | |
195df7a7 VZ |
36 | // return the control shown by this page |
37 | virtual wxControl *GetWidget() const = 0; | |
38 | ||
32b8ec41 VZ |
39 | protected: |
40 | // several helper functions for page creation | |
41 | ||
42 | // create a horz sizer containing the given control and the text ctrl | |
43 | // (pointer to which will be saved in the provided variable if not NULL) | |
44 | // with the specified id | |
45 | wxSizer *CreateSizerWithText(wxControl *control, | |
206d3a16 | 46 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
47 | wxTextCtrl **ppText = NULL); |
48 | ||
49 | // create a sizer containing a label and a text ctrl | |
50 | wxSizer *CreateSizerWithTextAndLabel(const wxString& label, | |
206d3a16 | 51 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
52 | wxTextCtrl **ppText = NULL); |
53 | ||
54 | // create a sizer containing a button and a text ctrl | |
55 | wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn, | |
56 | const wxString& labelBtn, | |
206d3a16 | 57 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
58 | wxTextCtrl **ppText = NULL); |
59 | ||
60 | // create a checkbox and add it to the sizer | |
61 | wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer, | |
62 | const wxString& label, | |
206d3a16 | 63 | wxWindowID id = wxID_ANY); |
32b8ec41 VZ |
64 | |
65 | public: | |
66 | // the head of the linked list containinginfo about all pages | |
67 | static WidgetsPageInfo *ms_widgetPages; | |
68 | }; | |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // dynamic WidgetsPage creation helpers | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
2b5f62a0 | 74 | class WidgetsPageInfo |
32b8ec41 VZ |
75 | { |
76 | public: | |
61c083e7 | 77 | typedef WidgetsPage *(*Constructor)(wxBookCtrl *book, |
32b8ec41 VZ |
78 | wxImageList *imaglist); |
79 | ||
80 | // our ctor | |
81 | WidgetsPageInfo(Constructor ctor, const wxChar *label); | |
82 | ||
83 | // accessors | |
84 | const wxString& GetLabel() const { return m_label; } | |
85 | Constructor GetCtor() const { return m_ctor; } | |
86 | WidgetsPageInfo *GetNext() const { return m_next; } | |
87 | ||
2673bcb0 DS |
88 | void SetNext(WidgetsPageInfo *next) { m_next = next; } |
89 | ||
32b8ec41 VZ |
90 | private: |
91 | // the label of the page | |
92 | wxString m_label; | |
93 | ||
94 | // the function to create this page | |
95 | Constructor m_ctor; | |
96 | ||
97 | // next node in the linked list or NULL | |
98 | WidgetsPageInfo *m_next; | |
99 | }; | |
100 | ||
101 | // to declare a page, this macro must be used in the class declaration | |
102 | #define DECLARE_WIDGETS_PAGE(classname) \ | |
103 | private: \ | |
104 | static WidgetsPageInfo ms_info##classname; \ | |
105 | public: \ | |
106 | const WidgetsPageInfo *GetPageInfo() const \ | |
107 | { return &ms_info##classname; } | |
108 | ||
109 | // and this one must be inserted somewhere in the source file | |
110 | #define IMPLEMENT_WIDGETS_PAGE(classname, label) \ | |
61c083e7 | 111 | WidgetsPage *wxCtorFor##classname(wxBookCtrl *book, \ |
32b8ec41 | 112 | wxImageList *imaglist) \ |
61c083e7 | 113 | { return new classname(book, imaglist); } \ |
32b8ec41 VZ |
114 | WidgetsPageInfo classname:: \ |
115 | ms_info##classname(wxCtorFor##classname, label) | |
116 | ||
117 | #endif // _WX_SAMPLE_WIDGETS_H_ |