]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * File: mtest.cpp | |
3 | * Purpose: wxMultiCellSizer and wxMultiCellCanvas test | |
4 | * Author: Alex Andruschak | |
5 | * Created: 2000 | |
6 | * Updated: | |
7 | * Copyright: | |
8 | * License: wxWindows licence | |
9 | */ | |
10 | ||
11 | static const char sccsid[] = "%W% %G%"; | |
12 | ||
13 | #if defined(__GNUG__) && !defined(__APPLE__) | |
14 | #pragma implementation | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/wx.h" | |
26 | #endif | |
27 | ||
28 | #include "wx/gizmos/multicell.h" | |
29 | ||
30 | class MyApp: public wxApp | |
31 | {public: | |
32 | bool OnInit(void); | |
33 | }; | |
34 | ||
35 | class MyFrame: public wxFrame | |
36 | { | |
37 | ||
38 | public: | |
39 | MyFrame(int type, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size); | |
40 | ||
41 | void OnCloseWindow(wxCloseEvent& event); | |
42 | void OnPaint(wxPaintEvent& event); | |
43 | wxMultiCellSizer *sizer; | |
44 | ||
45 | DECLARE_EVENT_TABLE() | |
46 | }; | |
47 | ||
48 | IMPLEMENT_APP(MyApp) | |
49 | ||
50 | bool MyApp::OnInit(void) | |
51 | { | |
52 | MyFrame *frame = new MyFrame(1, (wxFrame *) NULL, wxT("wxMultiCellSizer Sample"), wxPoint(50, 50), wxDefaultSize); //, wxSize(600, 500)); | |
53 | ||
54 | frame->Show(true); | |
55 | ||
56 | SetTopWindow(frame); | |
57 | frame = new MyFrame(2, (wxFrame *) NULL, wxT("wxMultiCellCanvas Sample"), wxPoint(100, 100), wxSize(600, 500)); | |
58 | ||
59 | frame->Show(true); | |
60 | ||
61 | SetTopWindow(frame); | |
62 | return true; | |
63 | } | |
64 | ||
65 | ||
66 | ||
67 | MyFrame::MyFrame(int type, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size): | |
68 | wxFrame(frame, wxID_ANY, title, pos, size, wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL) | |
69 | { | |
70 | #if wxUSE_STATUSBAR | |
71 | CreateStatusBar(1); | |
72 | #endif // wxUSE_STATUSBAR | |
73 | sizer = NULL; | |
74 | if (type == 1) | |
75 | { | |
76 | // create sizer 4 columns 5 rows | |
77 | wxSize aa(4,9); | |
78 | sizer = new wxMultiCellSizer(aa); | |
79 | sizer->SetDefaultCellSize(wxSize(15,15)); | |
80 | sizer->SetRowHeight(7,5,true); | |
81 | sizer->SetRowHeight(8,5,false); | |
82 | // add first row | |
83 | sizer->Add( | |
84 | new wxButton( this, wxID_ANY, wxT( "B1 - 0,0, horizontal resizable")), | |
85 | 0, 0, 0, new wxMultiCellItemHandle(0,0,1,1, wxDefaultSize, wxHORIZONTAL_RESIZABLE, wxSize(2,2))); | |
86 | sizer->Add( | |
87 | new wxButton( this, wxID_ANY, wxT("B2 - 0,1, vertical resizable")), | |
88 | 0, 0, 0, new wxMultiCellItemHandle(0,1,1,1, wxDefaultSize, wxVERTICAL_RESIZABLE, wxSize(2, 2))); | |
89 | sizer->Add( | |
90 | new wxButton( this, wxID_ANY, wxT("B3 - 0,2")), | |
91 | 0, 0, 0, new wxMultiCellItemHandle(0,2,1,1, wxDefaultSize, wxNOT_RESIZABLE, wxSize(1,1), wxALIGN_CENTER_HORIZONTAL)); //, wxALIGN_CENTER)); | |
92 | sizer->Add( | |
93 | new wxStaticText(this, wxID_ANY, wxT("jbb 0,3, lower-right")), | |
94 | 0, 0, 0, new wxMultiCellItemHandle(0,3,1,1, wxDefaultSize, wxNOT_RESIZABLE, wxSize(1,1), wxALIGN_BOTTOM | wxALIGN_RIGHT)); | |
95 | ||
96 | // add button for secord row | |
97 | sizer->Add( | |
98 | new wxTextCtrl(this, wxID_ANY, wxT("Text control - 1,0, 4 cols wide")), | |
99 | 0, 0, 0, new wxMultiCellItemHandle(1,0,1,4)); | |
100 | ||
101 | // add buttons for next row | |
102 | sizer->Add( | |
103 | new wxButton( this, wxID_ANY, wxT("B6 - 2,0, 2 cols wide")), | |
104 | 0, 0, 0, new wxMultiCellItemHandle(2,0,1,2)); | |
105 | sizer->Add( | |
106 | new wxButton( this, wxID_ANY, wxT("B7 - 2,3")), | |
107 | 0, 0, 0, new wxMultiCellItemHandle(2,3,1,1)); | |
108 | ||
109 | // and last additions | |
110 | sizer->Add( | |
111 | new wxButton( this, wxID_ANY, wxT("B8 - 3,0, 4 rows high, vert resizable")), | |
112 | 0, 0, 0, new wxMultiCellItemHandle(3,0,4,1,wxDefaultSize, wxVERTICAL_RESIZABLE)); | |
113 | sizer->Add( | |
114 | new wxButton( this, wxID_ANY, wxT("B9 - 3,2, 2 cols wide, vert resizable")), | |
115 | 0, 0, 0, new wxMultiCellItemHandle(3,2,1,2,wxDefaultSize, wxVERTICAL_RESIZABLE)); | |
116 | sizer->Add( | |
117 | new wxButton( this, wxID_ANY, wxT("B10 - 4,1, 3 cols wide, vert resizable")), | |
118 | 0, 0, 0, new wxMultiCellItemHandle(4,1,1,3,wxDefaultSize, wxVERTICAL_RESIZABLE)); | |
119 | ||
120 | sizer->Add( | |
121 | new wxButton( this, wxID_ANY, wxT("B11 - 5,1, 3 cols wide")), | |
122 | 0, 0, 0, new wxMultiCellItemHandle(5,1,1,3)); | |
123 | ||
124 | sizer->Add( | |
125 | new wxButton( this, wxID_ANY, wxT("B12 - 6,1, 3 cols wide")), | |
126 | 0, 0, 0, new wxMultiCellItemHandle(6,1,1,3)); | |
127 | ||
128 | sizer->Add( | |
129 | new wxButton( this, wxID_ANY, wxT("B13 - 7,1, 2 cols wide")), | |
130 | 0, 0, 0, new wxMultiCellItemHandle(7,1,1,2)); | |
131 | ||
132 | sizer->Add( | |
133 | new wxButton( this, wxID_ANY, wxT("B14 - 8,1, 3 cols wide")), | |
134 | 0, 0, 0, new wxMultiCellItemHandle(8,1,1,3)); | |
135 | ||
136 | SetAutoLayout( true ); | |
137 | // sizer->SetMinSize(sizer->CalcMin()); | |
138 | SetSizer( sizer ); | |
139 | wxSize s = sizer->CalcMin(); | |
140 | wxSize c = GetSize() - GetClientSize(); | |
141 | SetSizeHints(s.GetWidth() + c.GetWidth() , s.GetHeight() + c.GetHeight()); | |
142 | sizer->EnableGridLines(this); | |
143 | } | |
144 | else | |
145 | { | |
146 | // create sizer 4 columns 5 rows | |
147 | wxMultiCellCanvas *sizer = new wxMultiCellCanvas(this, 5,5); | |
148 | ||
149 | // add first row | |
150 | sizer->Add( | |
151 | new wxButton( this, wxID_ANY, wxT("Button 1")), | |
152 | 0, 0); | |
153 | sizer->Add( | |
154 | new wxButton( this, wxID_ANY, wxT("Button 2")), | |
155 | 0, 1); | |
156 | sizer->Add( | |
157 | new wxButton( this, wxID_ANY, wxT("Button 3")), | |
158 | 0, 2); | |
159 | sizer->Add( | |
160 | new wxStaticText(this, wxID_ANY, wxT("jbb test")), | |
161 | 0, 3); | |
162 | ||
163 | sizer->Add( | |
164 | new wxStaticText(this, wxID_ANY, wxT("jbb test 2")), | |
165 | 0, 4); | |
166 | ||
167 | // add button for secord row | |
168 | sizer->Add( | |
169 | new wxTextCtrl(this, wxID_ANY, wxT("Text control")), | |
170 | 1, 0); | |
171 | ||
172 | // add buttons for next row | |
173 | sizer->Add( | |
174 | new wxButton( this, wxID_ANY, wxT("Button 6")), | |
175 | 2, 0); | |
176 | sizer->Add( | |
177 | new wxButton( this, wxID_ANY, wxT("Button 7")), | |
178 | 2, 3); | |
179 | ||
180 | // and last additions | |
181 | sizer->Add( | |
182 | new wxButton( this, wxID_ANY, wxT("Button 8")), | |
183 | 3, 0); | |
184 | sizer->Add( | |
185 | new wxButton( this, wxID_ANY, wxT("Button 9")), | |
186 | 3, 1); | |
187 | sizer->Add( | |
188 | new wxButton( this, wxID_ANY, wxT("Button 10")), | |
189 | 4, 1); | |
190 | ||
191 | sizer->CalculateConstraints(); | |
192 | SetSizer( sizer ); | |
193 | SetAutoLayout( true ); | |
194 | } | |
195 | } | |
196 | // Define the repainting behaviour | |
197 | ||
198 | ||
199 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
200 | EVT_PAINT(MyFrame::OnPaint) | |
201 | EVT_CLOSE(MyFrame::OnCloseWindow) | |
202 | END_EVENT_TABLE() | |
203 | ||
204 | void MyFrame::OnPaint(wxPaintEvent& WXUNUSED(event) ) | |
205 | { | |
206 | wxPaintDC dc(this); | |
207 | ||
208 | if (sizer) | |
209 | { | |
210 | sizer->OnPaint(dc); | |
211 | } | |
212 | } | |
213 | ||
214 | void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) | |
215 | { | |
216 | Destroy(); | |
217 | } | |
218 |