]>
Commit | Line | Data |
---|---|---|
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 | // 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; | |
16 | class WXDLLEXPORT wxBookCtrl; | |
17 | class WXDLLEXPORT wxSizer; | |
18 | class WXDLLEXPORT wxTextCtrl; | |
19 | ||
20 | class WidgetsPageInfo; | |
21 | ||
22 | #include "wx/panel.h" | |
23 | ||
24 | // all source files use wxImageList | |
25 | #include "wx/imaglist.h" | |
26 | ||
27 | // ---------------------------------------------------------------------------- | |
28 | // WidgetsPage: a book page demonstrating some widget | |
29 | // ---------------------------------------------------------------------------- | |
30 | ||
31 | class WidgetsPage : public wxPanel | |
32 | { | |
33 | public: | |
34 | WidgetsPage(wxBookCtrl *book); | |
35 | ||
36 | // return the control shown by this page | |
37 | virtual wxControl *GetWidget() const = 0; | |
38 | ||
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, | |
46 | wxWindowID id = wxID_ANY, | |
47 | wxTextCtrl **ppText = NULL); | |
48 | ||
49 | // create a sizer containing a label and a text ctrl | |
50 | wxSizer *CreateSizerWithTextAndLabel(const wxString& label, | |
51 | wxWindowID id = wxID_ANY, | |
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, | |
57 | wxWindowID id = wxID_ANY, | |
58 | wxTextCtrl **ppText = NULL); | |
59 | ||
60 | // create a checkbox and add it to the sizer | |
61 | wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer, | |
62 | const wxString& label, | |
63 | wxWindowID id = wxID_ANY); | |
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 | ||
74 | class WidgetsPageInfo | |
75 | { | |
76 | public: | |
77 | typedef WidgetsPage *(*Constructor)(wxBookCtrl *book, | |
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 | ||
88 | void SetNext(WidgetsPageInfo *next) { m_next = next; } | |
89 | ||
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) \ | |
111 | WidgetsPage *wxCtorFor##classname(wxBookCtrl *book, \ | |
112 | wxImageList *imaglist) \ | |
113 | { return new classname(book, imaglist); } \ | |
114 | WidgetsPageInfo classname:: \ | |
115 | ms_info##classname(wxCtorFor##classname, label) | |
116 | ||
117 | #endif // _WX_SAMPLE_WIDGETS_H_ |