1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWindows Widgets Sample
4 // Purpose: Part of the widgets sample showing various static controls
5 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 Vadim Zeitlin
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers
31 #include "wx/button.h"
32 #include "wx/checkbox.h"
33 #include "wx/radiobox.h"
34 #include "wx/statbox.h"
35 #include "wx/stattext.h"
36 #include "wx/textctrl.h"
41 #include "wx/statline.h"
45 #include "icons/statbox.xpm"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
54 StaticPage_Reset
= 100,
59 // alignment radiobox values
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 class StaticWidgetsPage
: public WidgetsPage
83 StaticWidgetsPage(wxNotebook
*notebook
, wxImageList
*imaglist
);
84 virtual ~StaticWidgetsPage();
88 void OnCheckOrRadioBox(wxCommandEvent
& event
);
90 void OnButtonReset(wxCommandEvent
& event
);
91 void OnButtonBoxText(wxCommandEvent
& event
);
92 void OnButtonLabelText(wxCommandEvent
& event
);
94 // reset all parameters
97 // (re)create all controls
103 // the check/radio boxes for styles
104 wxCheckBox
*m_chkVert
,
107 wxRadioBox
*m_radioHAlign
,
110 // the controls and the sizer containing them
111 wxStaticBoxSizer
*m_sizerStatBox
;
112 wxStaticText
*m_statText
;
113 wxStaticLine
*m_statLine
;
114 wxSizer
*m_sizerStatic
;
116 // the text entries for command parameters
117 wxTextCtrl
*m_textBox
,
121 DECLARE_EVENT_TABLE()
122 DECLARE_WIDGETS_PAGE(StaticWidgetsPage
)
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 BEGIN_EVENT_TABLE(StaticWidgetsPage
, WidgetsPage
)
130 EVT_BUTTON(StaticPage_Reset
, StaticWidgetsPage::OnButtonReset
)
131 EVT_BUTTON(StaticPage_LabelText
, StaticWidgetsPage::OnButtonLabelText
)
132 EVT_BUTTON(StaticPage_BoxText
, StaticWidgetsPage::OnButtonBoxText
)
134 EVT_CHECKBOX(-1, StaticWidgetsPage::OnCheckOrRadioBox
)
135 EVT_RADIOBOX(-1, StaticWidgetsPage::OnCheckOrRadioBox
)
138 // ============================================================================
140 // ============================================================================
142 IMPLEMENT_WIDGETS_PAGE(StaticWidgetsPage
, _T("Static"));
144 StaticWidgetsPage::StaticWidgetsPage(wxNotebook
*notebook
,
145 wxImageList
*imaglist
)
146 : WidgetsPage(notebook
)
148 imaglist
->Add(wxBitmap(statbox_xpm
));
152 m_chkAutoResize
= (wxCheckBox
*)NULL
;
155 m_radioVAlign
= (wxRadioBox
*)NULL
;
157 m_statLine
= (wxStaticLine
*)NULL
;
158 m_statText
= (wxStaticText
*)NULL
;
160 m_sizerStatBox
= (wxStaticBoxSizer
*)NULL
;
161 m_sizerStatic
= (wxSizer
*)NULL
;
163 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
166 wxStaticBox
*box
= new wxStaticBox(this, -1, _T("&Set style"));
168 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
170 m_chkVert
= CreateCheckBoxAndAddToSizer(sizerLeft
, _T("&Vertical line"));
171 m_chkAutoResize
= CreateCheckBoxAndAddToSizer(sizerLeft
, _T("&Fit to text"));
172 sizerLeft
->Add(5, 5, 0, wxGROW
| wxALL
, 5); // spacer
174 static const wxString halign
[] =
181 static const wxString valign
[] =
188 m_radioHAlign
= new wxRadioBox(this, -1, _T("&Horz alignment"),
189 wxDefaultPosition
, wxDefaultSize
,
190 WXSIZEOF(halign
), halign
);
191 m_radioVAlign
= new wxRadioBox(this, -1, _T("&Vert alignment"),
192 wxDefaultPosition
, wxDefaultSize
,
193 WXSIZEOF(valign
), valign
);
195 sizerLeft
->Add(m_radioHAlign
, 0, wxGROW
| wxALL
, 5);
196 sizerLeft
->Add(m_radioVAlign
, 0, wxGROW
| wxALL
, 5);
198 wxButton
*btn
= new wxButton(this, StaticPage_Reset
, _T("&Reset"));
199 sizerLeft
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
202 wxStaticBox
*box2
= new wxStaticBox(this, -1, _T("&Change labels"));
203 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
207 sizerRow
= CreateSizerWithTextAndButton(StaticPage_BoxText
,
208 _T("Change &box label"),
210 sizerMiddle
->Add(sizerRow
, 0, wxGROW
| wxALL
, 5);
212 sizerRow
= CreateSizerWithTextAndButton(StaticPage_LabelText
,
213 _T("Change &text label"),
215 sizerMiddle
->Add(sizerRow
, 0, wxGROW
| wxALL
, 5);
217 m_textBox
->SetValue(_T("This is a box"));
218 m_textLabel
->SetValue(_T("And this is a label\ninside the box"));
221 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
222 sizerRight
->SetMinSize(150, 0);
223 m_sizerStatic
= sizerRight
;
227 // the 3 panes panes compose the window
228 sizerTop
->Add(sizerLeft
, 0, wxGROW
| (wxALL
& ~wxLEFT
), 10);
229 sizerTop
->Add(sizerMiddle
, 0, wxGROW
| wxALL
, 10);
230 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
232 // final initializations
241 StaticWidgetsPage::~StaticWidgetsPage()
245 // ----------------------------------------------------------------------------
247 // ----------------------------------------------------------------------------
249 void StaticWidgetsPage::Reset()
251 m_chkVert
->SetValue(FALSE
);
252 m_chkAutoResize
->SetValue(TRUE
);
254 m_radioHAlign
->SetSelection(StaticHAlign_Left
);
255 m_radioVAlign
->SetSelection(StaticVAlign_Top
);
258 void StaticWidgetsPage::CreateStatic()
260 bool isVert
= m_chkVert
->GetValue();
262 if ( m_sizerStatBox
)
264 m_sizerStatic
->Remove(m_sizerStatBox
);
266 // delete m_sizerStatBox; -- deleted by Remove()
274 if ( !m_chkAutoResize
->GetValue() )
276 flagsText
|= wxST_NO_AUTORESIZE
;
280 switch ( m_radioHAlign
->GetSelection() )
283 wxFAIL_MSG(_T("unexpected radiobox selection"));
286 case StaticHAlign_Left
:
287 align
|= wxALIGN_LEFT
;
290 case StaticHAlign_Centre
:
291 align
|= wxALIGN_CENTRE_HORIZONTAL
;
294 case StaticHAlign_Right
:
295 align
|= wxALIGN_RIGHT
;
299 switch ( m_radioVAlign
->GetSelection() )
302 wxFAIL_MSG(_T("unexpected radiobox selection"));
305 case StaticVAlign_Top
:
306 align
|= wxALIGN_TOP
;
309 case StaticVAlign_Centre
:
310 align
|= wxALIGN_CENTRE_VERTICAL
;
313 case StaticVAlign_Bottom
:
314 align
|= wxALIGN_BOTTOM
;
321 wxStaticBox
*box
= new wxStaticBox(this, -1, m_textBox
->GetValue(),
322 wxDefaultPosition
, wxDefaultSize
,
324 m_sizerStatBox
= new wxStaticBoxSizer(box
, isVert
? wxHORIZONTAL
327 m_statText
= new wxStaticText(this, -1, m_textLabel
->GetValue(),
328 wxDefaultPosition
, wxDefaultSize
,
331 m_statLine
= new wxStaticLine(this, -1,
332 wxDefaultPosition
, wxDefaultSize
,
333 isVert
? wxLI_VERTICAL
: wxLI_HORIZONTAL
);
335 m_sizerStatBox
->Add(m_statText
, 1, wxGROW
| wxALL
, 5);
336 m_sizerStatBox
->Add(m_statLine
, 0, wxGROW
| wxALL
, 5);
337 m_sizerStatBox
->Add(0, 0, 1);
339 m_sizerStatic
->Add(m_sizerStatBox
, 1, wxGROW
);
341 m_sizerStatic
->Layout();
344 // ----------------------------------------------------------------------------
346 // ----------------------------------------------------------------------------
348 void StaticWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
355 void StaticWidgetsPage::OnCheckOrRadioBox(wxCommandEvent
& event
)
360 void StaticWidgetsPage::OnButtonBoxText(wxCommandEvent
& event
)
362 m_sizerStatBox
->GetStaticBox()->SetLabel(m_textBox
->GetValue());
365 void StaticWidgetsPage::OnButtonLabelText(wxCommandEvent
& event
)
367 m_statText
->SetLabel(m_textLabel
->GetValue());