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