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