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 class DerivedStaticText
: public wxStaticText
79 DerivedStaticText(wxWindow
* parent
, wxWindowID id
, const wxString
& label
,
80 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
82 wxStaticText(parent
, id
, label
, pos
, size
, style
)
85 void OnMouseEvent(wxMouseEvent
& event
)
88 wxMessageBox(wxT("Clicked on static text"));
93 BEGIN_EVENT_TABLE(DerivedStaticText
, wxStaticText
)
94 EVT_MOUSE_EVENTS(DerivedStaticText::OnMouseEvent
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 class StaticWidgetsPage
: public WidgetsPage
104 StaticWidgetsPage(wxNotebook
*notebook
, wxImageList
*imaglist
);
105 virtual ~StaticWidgetsPage();
109 void OnCheckOrRadioBox(wxCommandEvent
& event
);
111 void OnButtonReset(wxCommandEvent
& event
);
112 void OnButtonBoxText(wxCommandEvent
& event
);
113 void OnButtonLabelText(wxCommandEvent
& event
);
115 // reset all parameters
118 // (re)create all controls
124 // the check/radio boxes for styles
125 wxCheckBox
*m_chkVert
,
128 wxRadioBox
*m_radioHAlign
,
131 // the controls and the sizer containing them
132 wxStaticBoxSizer
*m_sizerStatBox
;
133 wxStaticText
*m_statText
;
134 wxStaticLine
*m_statLine
;
135 wxSizer
*m_sizerStatic
;
137 // the text entries for command parameters
138 wxTextCtrl
*m_textBox
,
142 DECLARE_EVENT_TABLE()
143 DECLARE_WIDGETS_PAGE(StaticWidgetsPage
)
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 BEGIN_EVENT_TABLE(StaticWidgetsPage
, WidgetsPage
)
151 EVT_BUTTON(StaticPage_Reset
, StaticWidgetsPage::OnButtonReset
)
152 EVT_BUTTON(StaticPage_LabelText
, StaticWidgetsPage::OnButtonLabelText
)
153 EVT_BUTTON(StaticPage_BoxText
, StaticWidgetsPage::OnButtonBoxText
)
155 EVT_CHECKBOX(-1, StaticWidgetsPage::OnCheckOrRadioBox
)
156 EVT_RADIOBOX(-1, StaticWidgetsPage::OnCheckOrRadioBox
)
159 // ============================================================================
161 // ============================================================================
163 IMPLEMENT_WIDGETS_PAGE(StaticWidgetsPage
, _T("Static"));
165 StaticWidgetsPage::StaticWidgetsPage(wxNotebook
*notebook
,
166 wxImageList
*imaglist
)
167 : WidgetsPage(notebook
)
169 imaglist
->Add(wxBitmap(statbox_xpm
));
173 m_chkAutoResize
= (wxCheckBox
*)NULL
;
176 m_radioVAlign
= (wxRadioBox
*)NULL
;
178 m_statLine
= (wxStaticLine
*)NULL
;
179 m_statText
= (wxStaticText
*)NULL
;
181 m_sizerStatBox
= (wxStaticBoxSizer
*)NULL
;
182 m_sizerStatic
= (wxSizer
*)NULL
;
184 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
187 wxStaticBox
*box
= new wxStaticBox(this, -1, _T("&Set style"));
189 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
191 m_chkVert
= CreateCheckBoxAndAddToSizer(sizerLeft
, _T("&Vertical line"));
192 m_chkAutoResize
= CreateCheckBoxAndAddToSizer(sizerLeft
, _T("&Fit to text"));
193 sizerLeft
->Add(5, 5, 0, wxGROW
| wxALL
, 5); // spacer
195 static const wxString halign
[] =
202 static const wxString valign
[] =
209 m_radioHAlign
= new wxRadioBox(this, -1, _T("&Horz alignment"),
210 wxDefaultPosition
, wxDefaultSize
,
211 WXSIZEOF(halign
), halign
);
212 m_radioVAlign
= new wxRadioBox(this, -1, _T("&Vert alignment"),
213 wxDefaultPosition
, wxDefaultSize
,
214 WXSIZEOF(valign
), valign
);
216 sizerLeft
->Add(m_radioHAlign
, 0, wxGROW
| wxALL
, 5);
217 sizerLeft
->Add(m_radioVAlign
, 0, wxGROW
| wxALL
, 5);
219 wxButton
*btn
= new wxButton(this, StaticPage_Reset
, _T("&Reset"));
220 sizerLeft
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
223 wxStaticBox
*box2
= new wxStaticBox(this, -1, _T("&Change labels"));
224 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
228 sizerRow
= CreateSizerWithTextAndButton(StaticPage_BoxText
,
229 _T("Change &box label"),
231 sizerMiddle
->Add(sizerRow
, 0, wxGROW
| wxALL
, 5);
233 sizerRow
= CreateSizerWithTextAndButton(StaticPage_LabelText
,
234 _T("Change &text label"),
236 sizerMiddle
->Add(sizerRow
, 0, wxGROW
| wxALL
, 5);
238 m_textBox
->SetValue(_T("This is a box"));
239 m_textLabel
->SetValue(_T("And this is a label\ninside the box"));
242 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
243 sizerRight
->SetMinSize(150, 0);
244 m_sizerStatic
= sizerRight
;
248 // the 3 panes panes compose the window
249 sizerTop
->Add(sizerLeft
, 0, wxGROW
| (wxALL
& ~wxLEFT
), 10);
250 sizerTop
->Add(sizerMiddle
, 0, wxGROW
| wxALL
, 10);
251 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
253 // final initializations
262 StaticWidgetsPage::~StaticWidgetsPage()
266 // ----------------------------------------------------------------------------
268 // ----------------------------------------------------------------------------
270 void StaticWidgetsPage::Reset()
272 m_chkVert
->SetValue(FALSE
);
273 m_chkAutoResize
->SetValue(TRUE
);
275 m_radioHAlign
->SetSelection(StaticHAlign_Left
);
276 m_radioVAlign
->SetSelection(StaticVAlign_Top
);
279 void StaticWidgetsPage::CreateStatic()
281 bool isVert
= m_chkVert
->GetValue();
283 if ( m_sizerStatBox
)
285 m_sizerStatic
->Remove(m_sizerStatBox
);
287 // delete m_sizerStatBox; -- deleted by Remove()
295 if ( !m_chkAutoResize
->GetValue() )
297 flagsText
|= wxST_NO_AUTORESIZE
;
301 switch ( m_radioHAlign
->GetSelection() )
304 wxFAIL_MSG(_T("unexpected radiobox selection"));
307 case StaticHAlign_Left
:
308 align
|= wxALIGN_LEFT
;
311 case StaticHAlign_Centre
:
312 align
|= wxALIGN_CENTRE_HORIZONTAL
;
315 case StaticHAlign_Right
:
316 align
|= wxALIGN_RIGHT
;
320 switch ( m_radioVAlign
->GetSelection() )
323 wxFAIL_MSG(_T("unexpected radiobox selection"));
326 case StaticVAlign_Top
:
327 align
|= wxALIGN_TOP
;
330 case StaticVAlign_Centre
:
331 align
|= wxALIGN_CENTRE_VERTICAL
;
334 case StaticVAlign_Bottom
:
335 align
|= wxALIGN_BOTTOM
;
342 wxStaticBox
*box
= new wxStaticBox(this, -1, m_textBox
->GetValue(),
343 wxDefaultPosition
, wxDefaultSize
,
345 m_sizerStatBox
= new wxStaticBoxSizer(box
, isVert
? wxHORIZONTAL
348 m_statText
= new DerivedStaticText(this, -1, m_textLabel
->GetValue(),
349 wxDefaultPosition
, wxDefaultSize
,
352 m_statLine
= new wxStaticLine(this, -1,
353 wxDefaultPosition
, wxDefaultSize
,
354 isVert
? wxLI_VERTICAL
: wxLI_HORIZONTAL
);
356 m_sizerStatBox
->Add(m_statText
, 1, wxGROW
| wxALL
, 5);
357 m_sizerStatBox
->Add(m_statLine
, 0, wxGROW
| wxALL
, 5);
358 m_sizerStatBox
->Add(0, 0, 1);
360 m_sizerStatic
->Add(m_sizerStatBox
, 1, wxGROW
);
362 m_sizerStatic
->Layout();
365 // ----------------------------------------------------------------------------
367 // ----------------------------------------------------------------------------
369 void StaticWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
376 void StaticWidgetsPage::OnCheckOrRadioBox(wxCommandEvent
& event
)
381 void StaticWidgetsPage::OnButtonBoxText(wxCommandEvent
& event
)
383 m_sizerStatBox
->GetStaticBox()->SetLabel(m_textBox
->GetValue());
386 void StaticWidgetsPage::OnButtonLabelText(wxCommandEvent
& event
)
388 m_statText
->SetLabel(m_textLabel
->GetValue());