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