]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: layout.cpp | |
3 | // Purpose: Layout sample | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
2f6c54eb | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
9e023db7 VZ |
12 | // ---------------------------------------------------------------------------- |
13 | // headers | |
14 | // ---------------------------------------------------------------------------- | |
15 | ||
c801d85f KB |
16 | // For compilers that support precompilation, includes "wx/wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
c62ac5b6 | 27 | #include "wx/sizer.h" |
20b35a69 | 28 | #include "wx/gbsizer.h" |
61d514bb | 29 | #include "wx/statline.h" |
83edc0a5 | 30 | #include "wx/notebook.h" |
c62ac5b6 | 31 | |
c801d85f KB |
32 | #include "layout.h" |
33 | ||
9e023db7 VZ |
34 | // ---------------------------------------------------------------------------- |
35 | // MyApp | |
36 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
37 | |
38 | IMPLEMENT_APP(MyApp) | |
39 | ||
83edc0a5 | 40 | bool MyApp::OnInit() |
c801d85f KB |
41 | { |
42 | // Create the main frame window | |
9e023db7 VZ |
43 | MyFrame *frame = new MyFrame; |
44 | ||
9230b621 | 45 | frame->Show(true); |
9e023db7 | 46 | |
9230b621 | 47 | return true; |
9e023db7 VZ |
48 | } |
49 | ||
50 | // ---------------------------------------------------------------------------- | |
51 | // MyFrame | |
52 | // ---------------------------------------------------------------------------- | |
c801d85f | 53 | |
9e023db7 VZ |
54 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
55 | EVT_MENU(LAYOUT_ABOUT, MyFrame::OnAbout) | |
56 | EVT_MENU(LAYOUT_QUIT, MyFrame::OnQuit) | |
c801d85f | 57 | |
9e023db7 VZ |
58 | EVT_MENU(LAYOUT_TEST_SIZER, MyFrame::TestFlexSizers) |
59 | EVT_MENU(LAYOUT_TEST_NB_SIZER, MyFrame::TestNotebookSizers) | |
925e9792 | 60 | EVT_MENU(LAYOUT_TEST_GB_SIZER, MyFrame::TestGridBagSizer) |
9e023db7 | 61 | END_EVENT_TABLE() |
c801d85f | 62 | |
9e023db7 VZ |
63 | // Define my frame constructor |
64 | MyFrame::MyFrame() | |
be5a51fb | 65 | : wxFrame(NULL, wxID_ANY, _T("wxWidgets Layout Demo"), |
9e023db7 VZ |
66 | wxDefaultPosition, wxDefaultSize, |
67 | wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) | |
68 | { | |
c801d85f KB |
69 | // Make a menubar |
70 | wxMenu *file_menu = new wxMenu; | |
71 | ||
9e023db7 VZ |
72 | file_menu->Append(LAYOUT_TEST_SIZER, _T("Test wx&FlexSizer")); |
73 | file_menu->Append(LAYOUT_TEST_NB_SIZER, _T("&Test notebook sizers")); | |
20b35a69 | 74 | file_menu->Append(LAYOUT_TEST_GB_SIZER, _T("Test &gridbag sizer")); |
c801d85f KB |
75 | |
76 | file_menu->AppendSeparator(); | |
9e023db7 | 77 | file_menu->Append(LAYOUT_QUIT, _T("E&xit"), _T("Quit program")); |
c801d85f KB |
78 | |
79 | wxMenu *help_menu = new wxMenu; | |
9e023db7 | 80 | help_menu->Append(LAYOUT_ABOUT, _T("&About"), _T("About layout demo")); |
c801d85f | 81 | |
9e023db7 | 82 | wxMenuBar *menu_bar = new wxMenuBar; |
c801d85f | 83 | |
42ed7532 MB |
84 | menu_bar->Append(file_menu, _T("&File")); |
85 | menu_bar->Append(help_menu, _T("&Help")); | |
c801d85f KB |
86 | |
87 | // Associate the menu bar with the frame | |
9e023db7 VZ |
88 | SetMenuBar(menu_bar); |
89 | ||
8520f137 | 90 | #if wxUSE_STATUSBAR |
9e023db7 | 91 | CreateStatusBar(2); |
be5a51fb | 92 | SetStatusText(_T("wxWidgets layout demo")); |
8520f137 | 93 | #endif // wxUSE_STATUSBAR |
9e023db7 | 94 | |
bdbb07ed RD |
95 | wxPanel* p = new wxPanel(this, -1); |
96 | ||
9e023db7 VZ |
97 | // we want to get a dialog that is stretchable because it |
98 | // has a text ctrl in the middle. at the bottom, we have | |
99 | // two buttons which. | |
100 | ||
101 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); | |
102 | ||
103 | // 1) top: create wxStaticText with minimum size equal to its default size | |
104 | topsizer->Add( | |
bdbb07ed | 105 | new wxStaticText( p, wxID_ANY, _T("An explanation (wxALIGN_RIGHT).") ), |
e5544e77 | 106 | wxSizerFlags().Align(wxALIGN_RIGHT).Border(wxALL & ~wxBOTTOM, 5)); |
9e023db7 VZ |
107 | |
108 | // 2) top: create wxTextCtrl with minimum size (100x60) | |
109 | topsizer->Add( | |
bdbb07ed | 110 | new wxTextCtrl( p, wxID_ANY, _T("My text (wxEXPAND)."), wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE), |
e5544e77 | 111 | wxSizerFlags(1).Expand().Border(wxALL, 5)); |
9e023db7 VZ |
112 | |
113 | // 2.5) Gratuitous test of wxStaticBoxSizers | |
114 | wxBoxSizer *statsizer = new wxStaticBoxSizer( | |
bdbb07ed | 115 | new wxStaticBox(p, wxID_ANY, _T("A wxStaticBoxSizer")), wxVERTICAL ); |
9e023db7 | 116 | statsizer->Add( |
bdbb07ed | 117 | new wxStaticText(p, wxID_ANY, _T("And some TEXT inside it")), |
e5544e77 VZ |
118 | wxSizerFlags().Center().Border(wxALL, 30)); |
119 | topsizer->Add( | |
120 | statsizer, | |
121 | wxSizerFlags(1).Expand().Border(wxALL, 10)); | |
9e023db7 VZ |
122 | |
123 | // 2.7) And a test of wxGridSizer | |
124 | wxGridSizer *gridsizer = new wxGridSizer(2, 5, 5); | |
bdbb07ed | 125 | gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Label")), |
e5544e77 | 126 | wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 127 | gridsizer->Add(new wxTextCtrl(p, wxID_ANY, _T("Grid sizer demo")), |
e5544e77 | 128 | wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 129 | gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Another label")), |
e5544e77 | 130 | wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 131 | gridsizer->Add(new wxTextCtrl(p, wxID_ANY, _T("More text")), |
e5544e77 | 132 | wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 133 | gridsizer->Add(new wxStaticText(p, wxID_ANY, _T("Final label")), |
e5544e77 | 134 | wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL)); |
bdbb07ed | 135 | gridsizer->Add(new wxTextCtrl(p, wxID_ANY, _T("And yet more text")), |
e5544e77 VZ |
136 | wxSizerFlags().Align(wxGROW | wxALIGN_CENTER_VERTICAL)); |
137 | topsizer->Add( | |
138 | gridsizer, | |
139 | wxSizerFlags().Proportion(1).Expand().Border(wxALL, 10)); | |
9e023db7 VZ |
140 | |
141 | ||
4aa0bd9b | 142 | #if wxUSE_STATLINE |
9e023db7 VZ |
143 | // 3) middle: create wxStaticLine with minimum size (3x3) |
144 | topsizer->Add( | |
bdbb07ed | 145 | new wxStaticLine( p, wxID_ANY, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), |
e5544e77 | 146 | wxSizerFlags().Expand()); |
4aa0bd9b | 147 | #endif // wxUSE_STATLINE |
9e023db7 VZ |
148 | |
149 | ||
150 | // 4) bottom: create two centred wxButtons | |
151 | wxBoxSizer *button_box = new wxBoxSizer( wxHORIZONTAL ); | |
152 | button_box->Add( | |
bdbb07ed | 153 | new wxButton( p, wxID_ANY, _T("Two buttons in a box") ), |
e5544e77 | 154 | wxSizerFlags().Border(wxALL, 7)); |
9e023db7 | 155 | button_box->Add( |
bdbb07ed | 156 | new wxButton( p, wxID_ANY, _T("(wxCENTER)") ), |
e5544e77 | 157 | wxSizerFlags().Border(wxALL, 7)); |
9e023db7 | 158 | |
e5544e77 | 159 | topsizer->Add(button_box, wxSizerFlags().Center()); |
9e023db7 | 160 | |
bdbb07ed RD |
161 | p->SetSizer( topsizer ); |
162 | ||
9e023db7 VZ |
163 | // don't allow frame to get smaller than what the sizers tell it and also set |
164 | // the initial size as calculated by the sizers | |
165 | topsizer->SetSizeHints( this ); | |
9e023db7 VZ |
166 | } |
167 | ||
168 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) | |
169 | { | |
9230b621 | 170 | Close(true); |
9e023db7 VZ |
171 | } |
172 | ||
173 | void MyFrame::TestFlexSizers(wxCommandEvent& WXUNUSED(event) ) | |
174 | { | |
175 | MyFlexSizerFrame *newFrame = new MyFlexSizerFrame(_T("Flex Sizer Test Frame"), 50, 50); | |
9230b621 | 176 | newFrame->Show(true); |
9e023db7 VZ |
177 | } |
178 | ||
179 | void MyFrame::TestNotebookSizers(wxCommandEvent& WXUNUSED(event) ) | |
180 | { | |
181 | MySizerDialog dialog( this, _T("Notebook Sizer Test Dialog") ); | |
182 | ||
183 | dialog.ShowModal(); | |
184 | } | |
185 | ||
c801d85f | 186 | |
9e023db7 VZ |
187 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) |
188 | { | |
be5a51fb | 189 | (void)wxMessageBox(_T("wxWidgets GUI library layout demo\n"), |
9e023db7 VZ |
190 | _T("About Layout Demo"), wxOK|wxICON_INFORMATION); |
191 | } | |
192 | ||
20b35a69 RD |
193 | void MyFrame::TestGridBagSizer(wxCommandEvent& WXUNUSED(event) ) |
194 | { | |
195 | MyGridBagSizerFrame *newFrame = new | |
196 | MyGridBagSizerFrame(_T("wxGridBagSizer Test Frame"), 50, 50); | |
9230b621 | 197 | newFrame->Show(true); |
20b35a69 RD |
198 | } |
199 | ||
200 | ||
9e023db7 VZ |
201 | // ---------------------------------------------------------------------------- |
202 | // MyFlexSizerFrame | |
203 | // ---------------------------------------------------------------------------- | |
c62ac5b6 | 204 | |
bdbb07ed | 205 | void MyFlexSizerFrame::InitFlexSizer(wxFlexGridSizer *sizer, wxWindow* parent) |
c801d85f | 206 | { |
9e023db7 VZ |
207 | for ( int i = 0; i < 3; i++ ) |
208 | { | |
209 | for ( int j = 0; j < 3; j++ ) | |
210 | { | |
211 | sizer->Add(new wxStaticText | |
212 | ( | |
bdbb07ed | 213 | parent, |
9230b621 | 214 | wxID_ANY, |
9e023db7 VZ |
215 | wxString::Format(_T("(%d, %d)"), i + 1, j + 1), |
216 | wxDefaultPosition, | |
217 | wxDefaultSize, | |
218 | wxALIGN_CENTER | |
219 | ), | |
220 | 0, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 3); | |
221 | } | |
222 | } | |
c801d85f KB |
223 | } |
224 | ||
9e023db7 | 225 | MyFlexSizerFrame::MyFlexSizerFrame(const wxChar *title, int x, int y ) |
9230b621 | 226 | : wxFrame(NULL, wxID_ANY, title, wxPoint(x, y) ) |
c801d85f | 227 | { |
9e023db7 | 228 | wxFlexGridSizer *sizerFlex; |
bdbb07ed | 229 | wxPanel* p = new wxPanel(this, -1); |
9e023db7 VZ |
230 | |
231 | // consttuct the first column | |
232 | wxSizer *sizerCol1 = new wxBoxSizer(wxVERTICAL); | |
bdbb07ed | 233 | sizerCol1->Add(new wxStaticText(p, wxID_ANY, _T("Ungrowable:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 234 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 235 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
236 | sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); |
237 | ||
bdbb07ed | 238 | sizerCol1->Add(new wxStaticText(p, wxID_ANY, _T("Growable middle column:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 239 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 240 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
241 | sizerFlex->AddGrowableCol(1); |
242 | sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
243 | ||
bdbb07ed | 244 | sizerCol1->Add(new wxStaticText(p, wxID_ANY, _T("Growable middle row:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 245 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 246 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
247 | sizerFlex->AddGrowableRow(1); |
248 | sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
249 | ||
bdbb07ed | 250 | sizerCol1->Add(new wxStaticText(p, wxID_ANY, _T("All growable columns:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 251 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 252 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
253 | sizerFlex->AddGrowableCol(0, 1); |
254 | sizerFlex->AddGrowableCol(1, 2); | |
255 | sizerFlex->AddGrowableCol(2, 3); | |
256 | sizerCol1->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
257 | ||
258 | // the second one | |
259 | wxSizer *sizerCol2 = new wxBoxSizer(wxVERTICAL); | |
bdbb07ed | 260 | sizerCol2->Add(new wxStaticText(p, wxID_ANY, _T("Growable middle row and column:")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 261 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 262 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
263 | sizerFlex->AddGrowableCol(1); |
264 | sizerFlex->AddGrowableRow(1); | |
265 | sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
266 | ||
bdbb07ed | 267 | sizerCol2->Add(new wxStaticText(p, wxID_ANY, _T("Same with horz flex direction")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 268 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 269 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
270 | sizerFlex->AddGrowableCol(1); |
271 | sizerFlex->AddGrowableRow(1); | |
272 | sizerFlex->SetFlexibleDirection(wxHORIZONTAL); | |
273 | sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
274 | ||
bdbb07ed | 275 | sizerCol2->Add(new wxStaticText(p, wxID_ANY, _T("Same with grow mode == \"none\"")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 276 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 277 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
278 | sizerFlex->AddGrowableCol(1); |
279 | sizerFlex->AddGrowableRow(1); | |
280 | sizerFlex->SetFlexibleDirection(wxHORIZONTAL); | |
281 | sizerFlex->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE); | |
282 | sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
283 | ||
bdbb07ed | 284 | sizerCol2->Add(new wxStaticText(p, wxID_ANY, _T("Same with grow mode == \"all\"")), 0, wxCENTER | wxTOP, 20); |
9e023db7 | 285 | sizerFlex = new wxFlexGridSizer(3, 3); |
bdbb07ed | 286 | InitFlexSizer(sizerFlex, p); |
9e023db7 VZ |
287 | sizerFlex->AddGrowableCol(1); |
288 | sizerFlex->AddGrowableRow(1); | |
289 | sizerFlex->SetFlexibleDirection(wxHORIZONTAL); | |
290 | sizerFlex->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL); | |
291 | sizerCol2->Add(sizerFlex, 1, wxALL | wxEXPAND, 10); | |
292 | ||
293 | // add both columns to grid sizer | |
294 | wxGridSizer *sizerTop = new wxGridSizer(2, 0, 20); | |
295 | sizerTop->Add(sizerCol1, 1, wxEXPAND); | |
296 | sizerTop->Add(sizerCol2, 1, wxEXPAND); | |
297 | ||
bdbb07ed | 298 | p->SetSizer(sizerTop); |
9e023db7 | 299 | sizerTop->SetSizeHints(this); |
c801d85f KB |
300 | } |
301 | ||
9e023db7 VZ |
302 | // ---------------------------------------------------------------------------- |
303 | // MySizerDialog | |
304 | // ---------------------------------------------------------------------------- | |
c801d85f | 305 | |
9e023db7 | 306 | MySizerDialog::MySizerDialog(wxWindow *parent, const wxChar *title) |
9230b621 | 307 | : wxDialog(parent, wxID_ANY, wxString(title)) |
83edc0a5 | 308 | { |
83edc0a5 RR |
309 | // Begin with first hierarchy: a notebook at the top and |
310 | // and OK button at the bottom. | |
311 | ||
312 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); | |
56ac3e75 | 313 | |
9230b621 | 314 | wxNotebook *notebook = new wxNotebook( this, wxID_ANY ); |
adbf2d73 | 315 | topsizer->Add( notebook, 1, wxGROW ); |
56ac3e75 | 316 | |
9e023db7 | 317 | wxButton *button = new wxButton( this, wxID_OK, _T("OK") ); |
83edc0a5 RR |
318 | topsizer->Add( button, 0, wxALIGN_RIGHT | wxALL, 10 ); |
319 | ||
320 | // First page: one big text ctrl | |
9230b621 | 321 | wxTextCtrl *multi = new wxTextCtrl( notebook, wxID_ANY, _T("TextCtrl."), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); |
42ed7532 | 322 | notebook->AddPage( multi, _T("Page One") ); |
56ac3e75 | 323 | |
83edc0a5 | 324 | // Second page: a text ctrl and a button |
9230b621 | 325 | wxPanel *panel = new wxPanel( notebook, wxID_ANY ); |
42ed7532 | 326 | notebook->AddPage( panel, _T("Page Two") ); |
56ac3e75 | 327 | |
f6bcfd97 | 328 | wxSizer *panelsizer = new wxBoxSizer( wxVERTICAL ); |
56ac3e75 | 329 | |
9230b621 | 330 | wxTextCtrl *text = new wxTextCtrl( panel, wxID_ANY, _T("TextLine 1."), wxDefaultPosition, wxSize(250,-1) ); |
83edc0a5 | 331 | panelsizer->Add( text, 0, wxGROW|wxALL, 30 ); |
9230b621 | 332 | text = new wxTextCtrl( panel, wxID_ANY, _T("TextLine 2."), wxDefaultPosition, wxSize(250,-1) ); |
83edc0a5 | 333 | panelsizer->Add( text, 0, wxGROW|wxALL, 30 ); |
9230b621 | 334 | wxButton *button2 = new wxButton( panel, wxID_ANY, _T("Hallo") ); |
83edc0a5 | 335 | panelsizer->Add( button2, 0, wxALIGN_RIGHT | wxLEFT|wxRIGHT|wxBOTTOM, 30 ); |
56ac3e75 | 336 | |
9230b621 | 337 | panel->SetAutoLayout( true ); |
83edc0a5 | 338 | panel->SetSizer( panelsizer ); |
56ac3e75 | 339 | |
83edc0a5 | 340 | // Tell dialog to use sizer |
9e023db7 VZ |
341 | SetSizer( topsizer ); |
342 | topsizer->SetSizeHints( this ); | |
c62ac5b6 RR |
343 | } |
344 | ||
20b35a69 RD |
345 | // ---------------------------------------------------------------------------- |
346 | // MyGridBagSizerFrame | |
347 | // ---------------------------------------------------------------------------- | |
348 | ||
349 | // some simple macros to help make the sample code below more clear | |
9230b621 VS |
350 | #define TEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text)) |
351 | #define MLTEXTCTRL(text) new wxTextCtrl(p, wxID_ANY, _T(text), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE) | |
20b35a69 RD |
352 | #define POS(r, c) wxGBPosition(r,c) |
353 | #define SPAN(r, c) wxGBSpan(r,c) | |
354 | ||
77c5e923 RD |
355 | wxChar* gbsDescription =_T("\ |
356 | The wxGridBagSizer is similar to the wxFlexGridSizer except the items are explicitly positioned\n\ | |
357 | in a virtual cell of the layout grid, and column or row spanning is allowed. For example, this\n\ | |
358 | static text is positioned at (0,0) and it spans 7 columns."); | |
20b35a69 RD |
359 | |
360 | ||
361 | // Some IDs | |
362 | enum { | |
363 | GBS_HIDE_BTN = 1212, | |
364 | GBS_SHOW_BTN, | |
365 | GBS_MOVE_BTN1, | |
366 | GBS_MOVE_BTN2, | |
925e9792 | 367 | |
20b35a69 RD |
368 | GBS_MAX, |
369 | }; | |
370 | ||
371 | ||
372 | BEGIN_EVENT_TABLE(MyGridBagSizerFrame, wxFrame) | |
373 | EVT_BUTTON( GBS_HIDE_BTN, MyGridBagSizerFrame::OnHideBtn) | |
374 | EVT_BUTTON( GBS_SHOW_BTN, MyGridBagSizerFrame::OnShowBtn) | |
375 | EVT_BUTTON( GBS_MOVE_BTN1, MyGridBagSizerFrame::OnMoveBtn) | |
376 | EVT_BUTTON( GBS_MOVE_BTN2, MyGridBagSizerFrame::OnMoveBtn) | |
377 | END_EVENT_TABLE() | |
378 | ||
379 | ||
380 | MyGridBagSizerFrame::MyGridBagSizerFrame(const wxChar *title, int x, int y ) | |
9230b621 | 381 | : wxFrame( NULL, wxID_ANY, title, wxPoint(x, y) ) |
20b35a69 | 382 | { |
9230b621 | 383 | wxPanel* p = new wxPanel(this, wxID_ANY); |
20b35a69 RD |
384 | m_panel = p; |
385 | m_gbs = new wxGridBagSizer(); | |
386 | ||
925e9792 | 387 | |
9230b621 | 388 | m_gbs->Add( new wxStaticText(p, wxID_ANY, gbsDescription), |
77c5e923 RD |
389 | POS(0,0), SPAN(1, 7), |
390 | wxALIGN_CENTER | wxALL, 5); | |
925e9792 | 391 | |
20b35a69 RD |
392 | m_gbs->Add( TEXTCTRL("pos(1,0)"), POS(1,0) ); |
393 | m_gbs->Add( TEXTCTRL("pos(1,1)"), POS(1,1) ); | |
394 | m_gbs->Add( TEXTCTRL("pos(2,0)"), POS(2,0) ); | |
395 | m_gbs->Add( TEXTCTRL("pos(2,1)"), POS(2,1) ); | |
396 | m_gbs->Add( MLTEXTCTRL("pos(3,2), span(1,2)\nthis row and col are growable"), | |
397 | POS(3,2), SPAN(1,2), wxEXPAND ); | |
398 | m_gbs->Add( MLTEXTCTRL("pos(4,3)\nspan(3,1)"), | |
399 | POS(4,3), SPAN(3,1), wxEXPAND ); | |
400 | m_gbs->Add( TEXTCTRL("pos(5,4)"), POS(5,4), wxDefaultSpan, wxEXPAND ); | |
401 | m_gbs->Add( TEXTCTRL("pos(6,5)"), POS(6,5), wxDefaultSpan, wxEXPAND ); | |
402 | m_gbs->Add( TEXTCTRL("pos(7,6)"), POS(7,6) ); | |
925e9792 | 403 | |
20b35a69 RD |
404 | //m_gbs->Add( TEXTCTRL("bad position"), POS(4,3) ); // Test for assert |
405 | //m_gbs->Add( TEXTCTRL("bad position"), POS(5,3) ); // Test for assert | |
406 | ||
407 | ||
77c5e923 RD |
408 | m_moveBtn1 = new wxButton(p, GBS_MOVE_BTN1, _T("Move this to (3,6)")); |
409 | m_moveBtn2 = new wxButton(p, GBS_MOVE_BTN2, _T("Move this to (3,6)")); | |
20b35a69 RD |
410 | m_gbs->Add( m_moveBtn1, POS(10,2) ); |
411 | m_gbs->Add( m_moveBtn2, POS(10,3) ); | |
925e9792 | 412 | |
77c5e923 | 413 | m_hideBtn = new wxButton(p, GBS_HIDE_BTN, _T("Hide this item -->")); |
20b35a69 RD |
414 | m_gbs->Add(m_hideBtn, POS(12, 3)); |
415 | ||
9230b621 | 416 | m_hideTxt = new wxTextCtrl(p, wxID_ANY, _T("pos(12,4), size(150, -1)"), |
6c1ad2a8 | 417 | wxDefaultPosition, wxSize(150,-1)); |
20b35a69 | 418 | m_gbs->Add( m_hideTxt, POS(12,4) ); |
925e9792 | 419 | |
77c5e923 | 420 | m_showBtn = new wxButton(p, GBS_SHOW_BTN, _T("<-- Show it again")); |
20b35a69 RD |
421 | m_gbs->Add(m_showBtn, POS(12, 5)); |
422 | m_showBtn->Disable(); | |
423 | ||
424 | m_gbs->Add(10,10, POS(14,0)); | |
925e9792 | 425 | |
20b35a69 RD |
426 | m_gbs->AddGrowableRow(3); |
427 | m_gbs->AddGrowableCol(2); | |
925e9792 | 428 | |
20b35a69 RD |
429 | p->SetSizerAndFit(m_gbs); |
430 | SetClientSize(p->GetSize()); | |
431 | } | |
432 | ||
925e9792 | 433 | |
20b35a69 RD |
434 | void MyGridBagSizerFrame::OnHideBtn(wxCommandEvent&) |
435 | { | |
436 | m_gbs->Hide(m_hideTxt); | |
437 | m_hideBtn->Disable(); | |
438 | m_showBtn->Enable(); | |
439 | m_gbs->Layout(); | |
440 | } | |
441 | ||
442 | void MyGridBagSizerFrame::OnShowBtn(wxCommandEvent&) | |
443 | { | |
444 | m_gbs->Show(m_hideTxt); | |
445 | m_hideBtn->Enable(); | |
446 | m_showBtn->Disable(); | |
447 | m_gbs->Layout(); | |
448 | } | |
449 | ||
450 | ||
451 | void MyGridBagSizerFrame::OnMoveBtn(wxCommandEvent& event) | |
452 | { | |
453 | wxButton* btn = (wxButton*)event.GetEventObject(); | |
454 | wxGBPosition curPos = m_gbs->GetItemPosition(btn); | |
455 | ||
456 | // if it's already at the "other" spot then move it back | |
457 | if (curPos == wxGBPosition(3,6)) | |
458 | { | |
459 | m_gbs->SetItemPosition(btn, m_lastPos); | |
77c5e923 | 460 | btn->SetLabel(_T("Move this to (3,6)")); |
20b35a69 | 461 | } |
925e9792 | 462 | else |
20b35a69 | 463 | { |
77c5e923 RD |
464 | if ( m_gbs->CheckForIntersection(wxGBPosition(3,6), wxGBSpan(1,1)) ) |
465 | wxMessageBox( | |
466 | _T("wxGridBagSizer will not allow items to be in the same cell as\n\ | |
467 | another item, so this operation will fail. You will also get an assert\n\ | |
468 | when compiled in debug mode."), _T("Warning"), wxOK | wxICON_INFORMATION); | |
925e9792 | 469 | |
77c5e923 RD |
470 | if ( m_gbs->SetItemPosition(btn, wxGBPosition(3,6)) ) |
471 | { | |
472 | m_lastPos = curPos; | |
473 | btn->SetLabel(_T("Move it back")); | |
474 | } | |
20b35a69 RD |
475 | } |
476 | m_gbs->Layout(); | |
477 | } |