]> git.saurik.com Git - wxWidgets.git/blob - samples/widgets/widgets.h
fixed sending 2 events (normal and bogus cancel one) when ending to edit a tree ctrl...
[wxWidgets.git] / samples / widgets / widgets.h
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 wxNotebook;
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 notebook page demonstrating some widget
29 // ----------------------------------------------------------------------------
30
31 class WidgetsPage : public wxPanel
32 {
33 public:
34 WidgetsPage(wxNotebook *notebook);
35
36 protected:
37 // several helper functions for page creation
38
39 // create a horz sizer containing the given control and the text ctrl
40 // (pointer to which will be saved in the provided variable if not NULL)
41 // with the specified id
42 wxSizer *CreateSizerWithText(wxControl *control,
43 wxWindowID id = wxID_ANY,
44 wxTextCtrl **ppText = NULL);
45
46 // create a sizer containing a label and a text ctrl
47 wxSizer *CreateSizerWithTextAndLabel(const wxString& label,
48 wxWindowID id = wxID_ANY,
49 wxTextCtrl **ppText = NULL);
50
51 // create a sizer containing a button and a text ctrl
52 wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn,
53 const wxString& labelBtn,
54 wxWindowID id = wxID_ANY,
55 wxTextCtrl **ppText = NULL);
56
57 // create a checkbox and add it to the sizer
58 wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer,
59 const wxString& label,
60 wxWindowID id = wxID_ANY);
61
62 public:
63 // the head of the linked list containinginfo about all pages
64 static WidgetsPageInfo *ms_widgetPages;
65 };
66
67 // ----------------------------------------------------------------------------
68 // dynamic WidgetsPage creation helpers
69 // ----------------------------------------------------------------------------
70
71 class WidgetsPageInfo
72 {
73 public:
74 typedef WidgetsPage *(*Constructor)(wxNotebook *notebook,
75 wxImageList *imaglist);
76
77 // our ctor
78 WidgetsPageInfo(Constructor ctor, const wxChar *label);
79
80 // accessors
81 const wxString& GetLabel() const { return m_label; }
82 Constructor GetCtor() const { return m_ctor; }
83 WidgetsPageInfo *GetNext() const { return m_next; }
84
85 void SetNext(WidgetsPageInfo *next) { m_next = next; }
86
87 private:
88 // the label of the page
89 wxString m_label;
90
91 // the function to create this page
92 Constructor m_ctor;
93
94 // next node in the linked list or NULL
95 WidgetsPageInfo *m_next;
96 };
97
98 // to declare a page, this macro must be used in the class declaration
99 #define DECLARE_WIDGETS_PAGE(classname) \
100 private: \
101 static WidgetsPageInfo ms_info##classname; \
102 public: \
103 const WidgetsPageInfo *GetPageInfo() const \
104 { return &ms_info##classname; }
105
106 // and this one must be inserted somewhere in the source file
107 #define IMPLEMENT_WIDGETS_PAGE(classname, label) \
108 WidgetsPage *wxCtorFor##classname(wxNotebook *notebook, \
109 wxImageList *imaglist) \
110 { return new classname(notebook, imaglist); } \
111 WidgetsPageInfo classname:: \
112 ms_info##classname(wxCtorFor##classname, label)
113
114 #endif // _WX_SAMPLE_WIDGETS_H_