]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
6718d773 | 2 | // Name: splitter.cpp |
c801d85f KB |
3 | // Purpose: wxSplitterWindow sample |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
526954c5 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
2f294a9c VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f KB |
20 | // For compilers that support precompilation, includes "wx/wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
2f294a9c | 24 | #pragma hdrstop |
c801d85f KB |
25 | #endif |
26 | ||
27 | #ifndef WX_PRECOMP | |
6faed57d VZ |
28 | #include "wx/log.h" |
29 | ||
30 | #include "wx/app.h" | |
31 | #include "wx/frame.h" | |
32 | ||
33 | #include "wx/scrolwin.h" | |
34 | #include "wx/menu.h" | |
35 | ||
36 | #include "wx/textdlg.h" // for wxGetTextFromUser | |
c801d85f KB |
37 | #endif |
38 | ||
39 | #include "wx/splitter.h" | |
a63e17c1 | 40 | #include "wx/dcmirror.h" |
c801d85f | 41 | |
e7092398 | 42 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
41f02b9a FM |
43 | #include "../sample.xpm" |
44 | #endif | |
45 | ||
2f294a9c VZ |
46 | // ---------------------------------------------------------------------------- |
47 | // constants | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | // ID for the menu commands | |
51 | enum | |
52 | { | |
77e0a6d8 | 53 | SPLIT_QUIT = 1, |
2f294a9c VZ |
54 | SPLIT_HORIZONTAL, |
55 | SPLIT_VERTICAL, | |
56 | SPLIT_UNSPLIT, | |
b795f9ca | 57 | SPLIT_LIVE, |
9b8d8755 VZ |
58 | SPLIT_BORDER, |
59 | SPLIT_3DSASH, | |
6faed57d | 60 | SPLIT_SETPOSITION, |
14b4c0ff | 61 | SPLIT_SETMINSIZE, |
8adaf733 JS |
62 | SPLIT_SETGRAVITY, |
63 | SPLIT_REPLACE | |
2f294a9c VZ |
64 | }; |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // our classes | |
68 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
69 | |
70 | class MyApp: public wxApp | |
71 | { | |
72 | public: | |
a63e17c1 VZ |
73 | MyApp() { } |
74 | ||
75 | virtual bool OnInit(); | |
76 | ||
c0c133e1 | 77 | wxDECLARE_NO_COPY_CLASS(MyApp); |
c801d85f KB |
78 | }; |
79 | ||
2f294a9c | 80 | class MyFrame: public wxFrame |
c801d85f KB |
81 | { |
82 | public: | |
2f294a9c | 83 | MyFrame(); |
8adaf733 | 84 | virtual ~MyFrame(); |
0d559d69 | 85 | |
9b8d8755 | 86 | void ToggleFlag(int flag, bool enable); |
430bdeb5 FM |
87 | |
88 | // Menu commands | |
89 | void OnSplitHorizontal(wxCommandEvent& event); | |
90 | void OnSplitVertical(wxCommandEvent& event); | |
91 | void OnUnsplit(wxCommandEvent& event); | |
92 | void OnToggleLive(wxCommandEvent& event) | |
9b8d8755 | 93 | { ToggleFlag(wxSP_LIVE_UPDATE, event.IsChecked()); } |
430bdeb5 | 94 | void OnToggleBorder(wxCommandEvent& event) |
9b8d8755 | 95 | { ToggleFlag(wxSP_BORDER, event.IsChecked()); } |
430bdeb5 | 96 | void OnToggle3DSash(wxCommandEvent& event) |
9b8d8755 | 97 | { ToggleFlag(wxSP_3DSASH, event.IsChecked()); } |
430bdeb5 FM |
98 | void OnSetPosition(wxCommandEvent& event); |
99 | void OnSetMinSize(wxCommandEvent& event); | |
100 | void OnSetGravity(wxCommandEvent& event); | |
101 | void OnReplace(wxCommandEvent &event); | |
b795f9ca | 102 | |
430bdeb5 | 103 | void OnQuit(wxCommandEvent& event); |
4a0b46a7 | 104 | |
2f294a9c | 105 | // Menu command update functions |
430bdeb5 FM |
106 | void OnUpdateUIHorizontal(wxUpdateUIEvent& event); |
107 | void OnUpdateUIVertical(wxUpdateUIEvent& event); | |
108 | void OnUpdateUIUnsplit(wxUpdateUIEvent& event); | |
4a0b46a7 | 109 | |
0d559d69 | 110 | private: |
2f294a9c VZ |
111 | wxScrolledWindow *m_left, *m_right; |
112 | ||
113 | wxSplitterWindow* m_splitter; | |
8adaf733 | 114 | wxWindow *m_replacewindow; |
2f294a9c VZ |
115 | |
116 | DECLARE_EVENT_TABLE() | |
c0c133e1 | 117 | wxDECLARE_NO_COPY_CLASS(MyFrame); |
0d559d69 | 118 | }; |
c801d85f | 119 | |
2f294a9c | 120 | class MySplitterWindow : public wxSplitterWindow |
0d559d69 VZ |
121 | { |
122 | public: | |
2f294a9c | 123 | MySplitterWindow(wxFrame *parent); |
c801d85f | 124 | |
2f294a9c VZ |
125 | // event handlers |
126 | void OnPositionChanged(wxSplitterEvent& event); | |
127 | void OnPositionChanging(wxSplitterEvent& event); | |
128 | void OnDClick(wxSplitterEvent& event); | |
8ad18dc3 | 129 | void OnUnsplitEvent(wxSplitterEvent& event); |
c801d85f KB |
130 | |
131 | private: | |
2f294a9c | 132 | wxFrame *m_frame; |
0d559d69 | 133 | |
2f294a9c | 134 | DECLARE_EVENT_TABLE() |
c0c133e1 | 135 | wxDECLARE_NO_COPY_CLASS(MySplitterWindow); |
c801d85f KB |
136 | }; |
137 | ||
138 | class MyCanvas: public wxScrolledWindow | |
139 | { | |
140 | public: | |
a63e17c1 | 141 | MyCanvas(wxWindow* parent, bool mirror); |
925e9792 | 142 | virtual ~MyCanvas(){}; |
c801d85f | 143 | |
2f294a9c | 144 | virtual void OnDraw(wxDC& dc); |
a63e17c1 VZ |
145 | |
146 | private: | |
147 | bool m_mirror; | |
148 | ||
c0c133e1 | 149 | wxDECLARE_NO_COPY_CLASS(MyCanvas); |
c801d85f KB |
150 | }; |
151 | ||
2f294a9c VZ |
152 | // ============================================================================ |
153 | // implementation | |
154 | // ============================================================================ | |
c801d85f | 155 | |
2f294a9c VZ |
156 | // ---------------------------------------------------------------------------- |
157 | // MyApp | |
158 | // ---------------------------------------------------------------------------- | |
0d57be45 | 159 | |
c801d85f KB |
160 | IMPLEMENT_APP(MyApp) |
161 | ||
2f294a9c | 162 | bool MyApp::OnInit() |
c801d85f | 163 | { |
45e6e6f8 VZ |
164 | if ( !wxApp::OnInit() ) |
165 | return false; | |
166 | ||
2f294a9c VZ |
167 | // create and show the main frame |
168 | MyFrame* frame = new MyFrame; | |
4a0b46a7 | 169 | |
8ad18dc3 | 170 | frame->Show(true); |
c801d85f | 171 | |
8ad18dc3 | 172 | return true; |
c801d85f KB |
173 | } |
174 | ||
2f294a9c VZ |
175 | // ---------------------------------------------------------------------------- |
176 | // MyFrame | |
177 | // ---------------------------------------------------------------------------- | |
178 | ||
c801d85f | 179 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
430bdeb5 FM |
180 | EVT_MENU(SPLIT_VERTICAL, MyFrame::OnSplitVertical) |
181 | EVT_MENU(SPLIT_HORIZONTAL, MyFrame::OnSplitHorizontal) | |
182 | EVT_MENU(SPLIT_UNSPLIT, MyFrame::OnUnsplit) | |
183 | EVT_MENU(SPLIT_LIVE, MyFrame::OnToggleLive) | |
184 | EVT_MENU(SPLIT_BORDER, MyFrame::OnToggleBorder) | |
185 | EVT_MENU(SPLIT_3DSASH, MyFrame::OnToggle3DSash) | |
186 | EVT_MENU(SPLIT_SETPOSITION, MyFrame::OnSetPosition) | |
187 | EVT_MENU(SPLIT_SETMINSIZE, MyFrame::OnSetMinSize) | |
188 | EVT_MENU(SPLIT_SETGRAVITY, MyFrame::OnSetGravity) | |
189 | EVT_MENU(SPLIT_REPLACE, MyFrame::OnReplace) | |
190 | ||
191 | EVT_MENU(SPLIT_QUIT, MyFrame::OnQuit) | |
192 | ||
193 | EVT_UPDATE_UI(SPLIT_VERTICAL, MyFrame::OnUpdateUIVertical) | |
194 | EVT_UPDATE_UI(SPLIT_HORIZONTAL, MyFrame::OnUpdateUIHorizontal) | |
195 | EVT_UPDATE_UI(SPLIT_UNSPLIT, MyFrame::OnUpdateUIUnsplit) | |
c801d85f KB |
196 | END_EVENT_TABLE() |
197 | ||
198 | // My frame constructor | |
2f294a9c | 199 | MyFrame::MyFrame() |
9a83f860 | 200 | : wxFrame(NULL, wxID_ANY, wxT("wxSplitterWindow sample"), |
2f294a9c | 201 | wxDefaultPosition, wxSize(420, 300), |
fe31f91c | 202 | wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) |
c801d85f | 203 | { |
41f02b9a FM |
204 | SetIcon(wxICON(sample)); |
205 | ||
8520f137 | 206 | #if wxUSE_STATUSBAR |
2f294a9c | 207 | CreateStatusBar(2); |
8520f137 | 208 | #endif // wxUSE_STATUSBAR |
b7346a70 | 209 | |
2f294a9c | 210 | // Make a menubar |
6faed57d VZ |
211 | wxMenu *splitMenu = new wxMenu; |
212 | splitMenu->Append(SPLIT_VERTICAL, | |
9a83f860 VZ |
213 | wxT("Split &Vertically\tCtrl-V"), |
214 | wxT("Split vertically")); | |
6faed57d | 215 | splitMenu->Append(SPLIT_HORIZONTAL, |
9a83f860 VZ |
216 | wxT("Split &Horizontally\tCtrl-H"), |
217 | wxT("Split horizontally")); | |
6faed57d | 218 | splitMenu->Append(SPLIT_UNSPLIT, |
9a83f860 VZ |
219 | wxT("&Unsplit\tCtrl-U"), |
220 | wxT("Unsplit")); | |
6faed57d VZ |
221 | splitMenu->AppendSeparator(); |
222 | ||
223 | splitMenu->AppendCheckItem(SPLIT_LIVE, | |
9a83f860 VZ |
224 | wxT("&Live update\tCtrl-L"), |
225 | wxT("Toggle live update mode")); | |
9b8d8755 | 226 | splitMenu->AppendCheckItem(SPLIT_BORDER, |
9a83f860 VZ |
227 | wxT("3D &Border"), |
228 | wxT("Toggle wxSP_BORDER flag")); | |
9b8d8755 VZ |
229 | splitMenu->Check(SPLIT_BORDER, true); |
230 | splitMenu->AppendCheckItem(SPLIT_3DSASH, | |
9a83f860 VZ |
231 | wxT("&3D Sash"), |
232 | wxT("Toggle wxSP_3DSASH flag")); | |
9b8d8755 | 233 | splitMenu->Check(SPLIT_3DSASH, true); |
6faed57d | 234 | splitMenu->Append(SPLIT_SETPOSITION, |
9a83f860 VZ |
235 | wxT("Set splitter &position\tCtrl-P"), |
236 | wxT("Set the splitter position")); | |
6faed57d | 237 | splitMenu->Append(SPLIT_SETMINSIZE, |
9a83f860 VZ |
238 | wxT("Set &min size\tCtrl-M"), |
239 | wxT("Set minimum pane size")); | |
14b4c0ff | 240 | splitMenu->Append(SPLIT_SETGRAVITY, |
9a83f860 VZ |
241 | wxT("Set &gravity\tCtrl-G"), |
242 | wxT("Set gravity of sash")); | |
6faed57d VZ |
243 | splitMenu->AppendSeparator(); |
244 | ||
8adaf733 | 245 | splitMenu->Append(SPLIT_REPLACE, |
9a83f860 VZ |
246 | wxT("&Replace right window"), |
247 | wxT("Replace right window")); | |
8adaf733 JS |
248 | splitMenu->AppendSeparator(); |
249 | ||
9a83f860 | 250 | splitMenu->Append(SPLIT_QUIT, wxT("E&xit\tAlt-X"), wxT("Exit")); |
c801d85f | 251 | |
2f294a9c | 252 | wxMenuBar *menuBar = new wxMenuBar; |
9a83f860 | 253 | menuBar->Append(splitMenu, wxT("&Splitter")); |
c801d85f | 254 | |
2f294a9c | 255 | SetMenuBar(menuBar); |
c801d85f | 256 | |
8ad18dc3 | 257 | menuBar->Check(SPLIT_LIVE, true); |
2f294a9c | 258 | m_splitter = new MySplitterWindow(this); |
430bdeb5 | 259 | |
853f4764 VZ |
260 | // If you use non-zero gravity you must initialize the splitter with its |
261 | // correct initial size, otherwise it will change the sash position by a | |
262 | // huge amount when it's resized from its initial default size to its real | |
263 | // size when the frame lays it out. This wouldn't be necessary if default | |
264 | // zero gravity were used (although it would do no harm neither). | |
265 | m_splitter->SetSize(GetClientSize()); | |
14b4c0ff | 266 | m_splitter->SetSashGravity(1.0); |
4a0b46a7 | 267 | |
6b55490a | 268 | #if 1 |
a63e17c1 | 269 | m_left = new MyCanvas(m_splitter, true); |
2f294a9c | 270 | m_left->SetBackgroundColour(*wxRED); |
a63e17c1 | 271 | m_left->SetScrollbars(20, 20, 5, 5); |
2f294a9c VZ |
272 | m_left->SetCursor(wxCursor(wxCURSOR_MAGNIFIER)); |
273 | ||
a63e17c1 | 274 | m_right = new MyCanvas(m_splitter, false); |
2f294a9c | 275 | m_right->SetBackgroundColour(*wxCYAN); |
a63e17c1 | 276 | m_right->SetScrollbars(20, 20, 5, 5); |
6b55490a | 277 | #else // for testing kbd navigation inside the splitter |
9a83f860 VZ |
278 | m_left = new wxTextCtrl(m_splitter, wxID_ANY, wxT("first text")); |
279 | m_right = new wxTextCtrl(m_splitter, wxID_ANY, wxT("second text")); | |
6b55490a | 280 | #endif |
c801d85f | 281 | |
2f294a9c | 282 | // you can also do this to start with a single window |
4a0b46a7 | 283 | #if 0 |
8ad18dc3 | 284 | m_right->Show(false); |
2f294a9c | 285 | m_splitter->Initialize(m_left); |
4a0b46a7 | 286 | #else |
74c57d1f | 287 | // you can also try -100 |
2f294a9c | 288 | m_splitter->SplitVertically(m_left, m_right, 100); |
4a0b46a7 VZ |
289 | #endif |
290 | ||
8520f137 | 291 | #if wxUSE_STATUSBAR |
9a83f860 | 292 | SetStatusText(wxT("Min pane size = 0"), 1); |
8520f137 | 293 | #endif // wxUSE_STATUSBAR |
8adaf733 | 294 | |
52ada3cd | 295 | m_replacewindow = NULL; |
8adaf733 JS |
296 | } |
297 | ||
298 | MyFrame::~MyFrame() | |
299 | { | |
300 | if (m_replacewindow) { | |
301 | m_replacewindow->Destroy(); | |
8adaf733 | 302 | } |
c801d85f KB |
303 | } |
304 | ||
2f294a9c VZ |
305 | // menu command handlers |
306 | ||
430bdeb5 | 307 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) |
c801d85f | 308 | { |
8ad18dc3 | 309 | Close(true); |
c801d85f KB |
310 | } |
311 | ||
430bdeb5 | 312 | void MyFrame::OnSplitHorizontal(wxCommandEvent& WXUNUSED(event) ) |
c801d85f | 313 | { |
2f294a9c VZ |
314 | if ( m_splitter->IsSplit() ) |
315 | m_splitter->Unsplit(); | |
8ad18dc3 JS |
316 | m_left->Show(true); |
317 | m_right->Show(true); | |
2f294a9c | 318 | m_splitter->SplitHorizontally( m_left, m_right ); |
52ada3cd | 319 | m_replacewindow = NULL; |
74c57d1f | 320 | |
8520f137 | 321 | #if wxUSE_STATUSBAR |
9a83f860 | 322 | SetStatusText(wxT("Splitter split horizontally"), 1); |
8520f137 | 323 | #endif // wxUSE_STATUSBAR |
c801d85f KB |
324 | } |
325 | ||
430bdeb5 | 326 | void MyFrame::OnSplitVertical(wxCommandEvent& WXUNUSED(event) ) |
c801d85f | 327 | { |
2f294a9c VZ |
328 | if ( m_splitter->IsSplit() ) |
329 | m_splitter->Unsplit(); | |
8ad18dc3 JS |
330 | m_left->Show(true); |
331 | m_right->Show(true); | |
2f294a9c | 332 | m_splitter->SplitVertically( m_left, m_right ); |
52ada3cd | 333 | m_replacewindow = NULL; |
74c57d1f | 334 | |
8520f137 | 335 | #if wxUSE_STATUSBAR |
9a83f860 | 336 | SetStatusText(wxT("Splitter split vertically"), 1); |
8520f137 | 337 | #endif // wxUSE_STATUSBAR |
c801d85f KB |
338 | } |
339 | ||
430bdeb5 | 340 | void MyFrame::OnUnsplit(wxCommandEvent& WXUNUSED(event) ) |
c801d85f | 341 | { |
2f294a9c VZ |
342 | if ( m_splitter->IsSplit() ) |
343 | m_splitter->Unsplit(); | |
8520f137 | 344 | #if wxUSE_STATUSBAR |
9a83f860 | 345 | SetStatusText(wxT("No splitter")); |
8520f137 | 346 | #endif // wxUSE_STATUSBAR |
0d559d69 VZ |
347 | } |
348 | ||
9b8d8755 | 349 | void MyFrame::ToggleFlag(int flag, bool enable) |
b795f9ca VZ |
350 | { |
351 | long style = m_splitter->GetWindowStyleFlag(); | |
9b8d8755 VZ |
352 | if ( enable ) |
353 | style |= flag; | |
b795f9ca | 354 | else |
9b8d8755 | 355 | style &= ~flag; |
b795f9ca VZ |
356 | |
357 | m_splitter->SetWindowStyleFlag(style); | |
9b8d8755 VZ |
358 | |
359 | // we need to move sash to redraw it | |
360 | int pos = m_splitter->GetSashPosition(); | |
361 | m_splitter->SetSashPosition(pos + 1); | |
362 | m_splitter->SetSashPosition(pos); | |
b795f9ca VZ |
363 | } |
364 | ||
430bdeb5 | 365 | void MyFrame::OnSetPosition(wxCommandEvent& WXUNUSED(event) ) |
6faed57d VZ |
366 | { |
367 | wxString str; | |
368 | str.Printf( wxT("%d"), m_splitter->GetSashPosition()); | |
9b8d8755 | 369 | #if wxUSE_TEXTDLG |
9a83f860 | 370 | str = wxGetTextFromUser(wxT("Enter splitter position:"), wxT(""), str, this); |
9b8d8755 | 371 | #endif |
6faed57d VZ |
372 | if ( str.empty() ) |
373 | return; | |
374 | ||
375 | long pos; | |
376 | if ( !str.ToLong(&pos) ) | |
377 | { | |
9a83f860 | 378 | wxLogError(wxT("The splitter position should be an integer.")); |
6faed57d VZ |
379 | return; |
380 | } | |
381 | ||
382 | m_splitter->SetSashPosition(pos); | |
383 | ||
9a83f860 | 384 | wxLogStatus(this, wxT("Splitter position set to %ld"), pos); |
6faed57d VZ |
385 | } |
386 | ||
430bdeb5 | 387 | void MyFrame::OnSetMinSize(wxCommandEvent& WXUNUSED(event) ) |
0d559d69 | 388 | { |
2f294a9c | 389 | wxString str; |
f565a6c2 | 390 | str.Printf( wxT("%d"), m_splitter->GetMinimumPaneSize()); |
9b8d8755 | 391 | #if wxUSE_TEXTDLG |
9a83f860 | 392 | str = wxGetTextFromUser(wxT("Enter minimal size for panes:"), wxT(""), str, this); |
9b8d8755 | 393 | #endif |
6faed57d | 394 | if ( str.empty() ) |
2f294a9c VZ |
395 | return; |
396 | ||
397 | int minsize = wxStrtol( str, (wxChar**)NULL, 10 ); | |
398 | m_splitter->SetMinimumPaneSize(minsize); | |
8520f137 | 399 | #if wxUSE_STATUSBAR |
f565a6c2 | 400 | str.Printf( wxT("Min pane size = %d"), minsize); |
2f294a9c | 401 | SetStatusText(str, 1); |
8520f137 | 402 | #endif // wxUSE_STATUSBAR |
c801d85f | 403 | } |
430bdeb5 FM |
404 | |
405 | void MyFrame::OnSetGravity(wxCommandEvent& WXUNUSED(event) ) | |
14b4c0ff VZ |
406 | { |
407 | wxString str; | |
408 | str.Printf( wxT("%g"), m_splitter->GetSashGravity()); | |
9b8d8755 | 409 | #if wxUSE_TEXTDLG |
9a83f860 | 410 | str = wxGetTextFromUser(wxT("Enter sash gravity (0,1):"), wxT(""), str, this); |
9b8d8755 | 411 | #endif |
14b4c0ff VZ |
412 | if ( str.empty() ) |
413 | return; | |
414 | ||
415 | double gravity = wxStrtod( str, (wxChar**)NULL); | |
416 | m_splitter->SetSashGravity(gravity); | |
417 | #if wxUSE_STATUSBAR | |
418 | str.Printf( wxT("Gravity = %g"), gravity); | |
419 | SetStatusText(str, 1); | |
420 | #endif // wxUSE_STATUSBAR | |
421 | } | |
c801d85f | 422 | |
430bdeb5 | 423 | void MyFrame::OnReplace(wxCommandEvent& WXUNUSED(event) ) |
8adaf733 | 424 | { |
52ada3cd | 425 | if (m_replacewindow == NULL) { |
8adaf733 JS |
426 | m_replacewindow = m_splitter->GetWindow2(); |
427 | m_splitter->ReplaceWindow(m_replacewindow, new wxPanel(m_splitter, wxID_ANY)); | |
428 | m_replacewindow->Hide(); | |
429 | } else { | |
430 | wxWindow *empty = m_splitter->GetWindow2(); | |
52ada3cd | 431 | wxASSERT(empty != m_replacewindow); |
8adaf733 JS |
432 | m_splitter->ReplaceWindow(empty, m_replacewindow); |
433 | m_replacewindow->Show(); | |
52ada3cd | 434 | m_replacewindow = NULL; |
8adaf733 JS |
435 | empty->Destroy(); |
436 | } | |
437 | } | |
438 | ||
2f294a9c VZ |
439 | // Update UI handlers |
440 | ||
430bdeb5 | 441 | void MyFrame::OnUpdateUIHorizontal(wxUpdateUIEvent& event) |
c801d85f | 442 | { |
2f294a9c | 443 | event.Enable( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_HORIZONTAL) ); |
c801d85f KB |
444 | } |
445 | ||
430bdeb5 | 446 | void MyFrame::OnUpdateUIVertical(wxUpdateUIEvent& event) |
c801d85f | 447 | { |
2f294a9c | 448 | event.Enable( ( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_VERTICAL) ) ); |
c801d85f KB |
449 | } |
450 | ||
430bdeb5 | 451 | void MyFrame::OnUpdateUIUnsplit(wxUpdateUIEvent& event) |
c801d85f | 452 | { |
2f294a9c | 453 | event.Enable( m_splitter->IsSplit() ); |
c801d85f KB |
454 | } |
455 | ||
2f294a9c VZ |
456 | // ---------------------------------------------------------------------------- |
457 | // MySplitterWindow | |
458 | // ---------------------------------------------------------------------------- | |
459 | ||
460 | BEGIN_EVENT_TABLE(MySplitterWindow, wxSplitterWindow) | |
8ad18dc3 JS |
461 | EVT_SPLITTER_SASH_POS_CHANGED(wxID_ANY, MySplitterWindow::OnPositionChanged) |
462 | EVT_SPLITTER_SASH_POS_CHANGING(wxID_ANY, MySplitterWindow::OnPositionChanging) | |
2f294a9c | 463 | |
8ad18dc3 | 464 | EVT_SPLITTER_DCLICK(wxID_ANY, MySplitterWindow::OnDClick) |
2f294a9c | 465 | |
8ad18dc3 | 466 | EVT_SPLITTER_UNSPLIT(wxID_ANY, MySplitterWindow::OnUnsplitEvent) |
2f294a9c VZ |
467 | END_EVENT_TABLE() |
468 | ||
469 | MySplitterWindow::MySplitterWindow(wxFrame *parent) | |
8ad18dc3 | 470 | : wxSplitterWindow(parent, wxID_ANY, |
2f294a9c | 471 | wxDefaultPosition, wxDefaultSize, |
3c2544bb JS |
472 | wxSP_3D | wxSP_LIVE_UPDATE | |
473 | wxCLIP_CHILDREN /* | wxSP_NO_XP_THEME */ ) | |
c801d85f | 474 | { |
2f294a9c | 475 | m_frame = parent; |
c801d85f KB |
476 | } |
477 | ||
2f294a9c VZ |
478 | void MySplitterWindow::OnPositionChanged(wxSplitterEvent& event) |
479 | { | |
9a83f860 | 480 | wxLogStatus(m_frame, wxT("Position has changed, now = %d (or %d)"), |
2f294a9c VZ |
481 | event.GetSashPosition(), GetSashPosition()); |
482 | ||
483 | event.Skip(); | |
484 | } | |
485 | ||
486 | void MySplitterWindow::OnPositionChanging(wxSplitterEvent& event) | |
487 | { | |
9a83f860 | 488 | wxLogStatus(m_frame, wxT("Position is changing, now = %d (or %d)"), |
2f294a9c VZ |
489 | event.GetSashPosition(), GetSashPosition()); |
490 | ||
491 | event.Skip(); | |
492 | } | |
493 | ||
494 | void MySplitterWindow::OnDClick(wxSplitterEvent& event) | |
495 | { | |
8520f137 | 496 | #if wxUSE_STATUSBAR |
9a83f860 | 497 | m_frame->SetStatusText(wxT("Splitter double clicked"), 1); |
8520f137 | 498 | #endif // wxUSE_STATUSBAR |
2f294a9c VZ |
499 | |
500 | event.Skip(); | |
501 | } | |
502 | ||
8ad18dc3 | 503 | void MySplitterWindow::OnUnsplitEvent(wxSplitterEvent& event) |
2f294a9c | 504 | { |
8520f137 | 505 | #if wxUSE_STATUSBAR |
9a83f860 | 506 | m_frame->SetStatusText(wxT("Splitter unsplit"), 1); |
8520f137 | 507 | #endif // wxUSE_STATUSBAR |
2f294a9c VZ |
508 | |
509 | event.Skip(); | |
510 | } | |
511 | ||
512 | // ---------------------------------------------------------------------------- | |
513 | // MyCanvas | |
514 | // ---------------------------------------------------------------------------- | |
515 | ||
a63e17c1 | 516 | MyCanvas::MyCanvas(wxWindow* parent, bool mirror) |
8ad18dc3 | 517 | : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, |
a63e17c1 | 518 | wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE) |
c801d85f | 519 | { |
a63e17c1 | 520 | m_mirror = mirror; |
c801d85f KB |
521 | } |
522 | ||
a63e17c1 | 523 | void MyCanvas::OnDraw(wxDC& dcOrig) |
c801d85f | 524 | { |
a63e17c1 VZ |
525 | wxMirrorDC dc(dcOrig, m_mirror); |
526 | ||
2f294a9c | 527 | dc.SetPen(*wxBLACK_PEN); |
a63e17c1 | 528 | dc.DrawLine(0, 0, 100, 200); |
c801d85f | 529 | |
9b8d8755 | 530 | dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); |
9a83f860 | 531 | dc.DrawText(wxT("Testing"), 50, 50); |
b7346a70 | 532 | |
2f294a9c VZ |
533 | dc.SetPen(*wxRED_PEN); |
534 | dc.SetBrush(*wxGREEN_BRUSH); | |
535 | dc.DrawRectangle(120, 120, 100, 80); | |
c801d85f | 536 | } |
2f294a9c | 537 |