]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/widgets.h
added GetCurrentPage()
[wxWidgets.git] / samples / widgets / widgets.h
CommitLineData
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
15class WXDLLEXPORT wxCheckBox;
16class WXDLLEXPORT wxNotebook;
17class WXDLLEXPORT wxSizer;
18class WXDLLEXPORT wxTextCtrl;
19
2b5f62a0 20class 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// ----------------------------------------------------------------------------
28// WidgetsPage: a notebook page demonstrating some widget
29// ----------------------------------------------------------------------------
30
31class WidgetsPage : public wxPanel
32{
33public:
34 WidgetsPage(wxNotebook *notebook);
35
36protected:
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,
206d3a16 43 wxWindowID id = wxID_ANY,
32b8ec41
VZ
44 wxTextCtrl **ppText = NULL);
45
46 // create a sizer containing a label and a text ctrl
47 wxSizer *CreateSizerWithTextAndLabel(const wxString& label,
206d3a16 48 wxWindowID id = wxID_ANY,
32b8ec41
VZ
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,
206d3a16 54 wxWindowID id = wxID_ANY,
32b8ec41
VZ
55 wxTextCtrl **ppText = NULL);
56
57 // create a checkbox and add it to the sizer
58 wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer,
59 const wxString& label,
206d3a16 60 wxWindowID id = wxID_ANY);
32b8ec41
VZ
61
62public:
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
2b5f62a0 71class WidgetsPageInfo
32b8ec41
VZ
72{
73public:
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
2673bcb0
DS
85 void SetNext(WidgetsPageInfo *next) { m_next = next; }
86
32b8ec41
VZ
87private:
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_