]>
git.saurik.com Git - wxWidgets.git/blob - samples/splitter/test.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSplitterWindow sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/splitter.h"
29 class MyApp
: public wxApp
35 class MyFrame
: public wxFrame
38 MyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
44 void SplitHorizontal(wxCommandEvent
& event
);
45 void SplitVertical(wxCommandEvent
& event
);
46 void Unsplit(wxCommandEvent
& event
);
47 void Quit(wxCommandEvent
& event
);
49 // Menu command update functions
50 void UpdateUIHorizontal(wxUpdateUIEvent
& event
);
51 void UpdateUIVertical(wxUpdateUIEvent
& event
);
52 void UpdateUIUnsplit(wxUpdateUIEvent
& event
);
54 void OnIdle(wxIdleEvent
& event
);
60 MyCanvas
* rightCanvas
;
61 wxSplitterWindow
* splitter
;
66 class MyCanvas
: public wxScrolledWindow
69 MyCanvas(wxWindow
* parent
, int x
, int y
, int w
, int h
);
72 virtual void OnDraw(wxDC
& dc
);
77 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
80 // ID for the menu quit command
82 #define SPLIT_HORIZONTAL 2
83 #define SPLIT_VERTICAL 3
84 #define SPLIT_UNSPLIT 4
88 bool MyApp::OnInit(void)
90 MyFrame
* frame
= new MyFrame(NULL
, "wxSplitterWindow Example", wxPoint(50, 50), wxSize(400, 300));
100 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
101 EVT_MENU(SPLIT_VERTICAL
, MyFrame::SplitVertical
)
102 EVT_MENU(SPLIT_HORIZONTAL
, MyFrame::SplitHorizontal
)
103 EVT_MENU(SPLIT_UNSPLIT
, MyFrame::Unsplit
)
104 EVT_MENU(SPLIT_QUIT
, MyFrame::Quit
)
105 EVT_UPDATE_UI(SPLIT_VERTICAL
, MyFrame::UpdateUIVertical
)
106 EVT_UPDATE_UI(SPLIT_HORIZONTAL
, MyFrame::UpdateUIHorizontal
)
107 EVT_UPDATE_UI(SPLIT_UNSPLIT
, MyFrame::UpdateUIUnsplit
)
108 EVT_IDLE(MyFrame::OnIdle
)
111 // My frame constructor
112 MyFrame::MyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
113 wxFrame(frame
, -1, title
, pos
, size
)
117 SetIcon(wxIcon("mondrian"));
123 fileMenu
= new wxMenu
;
124 fileMenu
->Append(SPLIT_VERTICAL
, "Split &Vertically", "Split vertically");
125 fileMenu
->Append(SPLIT_HORIZONTAL
, "Split &Horizontally", "Split horizontally");
126 fileMenu
->Append(SPLIT_UNSPLIT
, "&Unsplit", "Unsplit");
127 fileMenu
->Append(SPLIT_QUIT
, "E&xit", "Exit");
129 menuBar
= new wxMenuBar
;
130 menuBar
->Append(fileMenu
, "&File");
134 splitter
= new wxSplitterWindow(this, -1, wxPoint(0, 0), wxSize(400, 400),
139 leftCanvas
= new MyCanvas(splitter
, 0, 0, 400, 400);
140 leftCanvas
->SetBackgroundColour(*wxRED
);
141 leftCanvas
->SetScrollbars(20, 20, 50, 50);
143 rightCanvas
= new MyCanvas(splitter
, 0, 0, 400, 400);
144 rightCanvas
->SetBackgroundColour(*wxCYAN
);
145 rightCanvas
->SetScrollbars(20, 20, 50, 50);
146 rightCanvas
->Show(FALSE
);
148 splitter
->Initialize(leftCanvas
);
150 // Set this to prevent unsplitting
151 // splitter->SetMinimumPaneSize(20);
158 bool MyFrame::OnClose()
163 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
168 void MyFrame::SplitHorizontal(wxCommandEvent
& WXUNUSED(event
) )
170 if ( splitter
->IsSplit() )
172 leftCanvas
->Show(TRUE
);
173 rightCanvas
->Show(TRUE
);
174 splitter
->SplitHorizontally( leftCanvas
, rightCanvas
);
177 void MyFrame::SplitVertical(wxCommandEvent
& WXUNUSED(event
) )
179 if ( splitter
->IsSplit() )
181 leftCanvas
->Show(TRUE
);
182 rightCanvas
->Show(TRUE
);
183 splitter
->SplitVertically( leftCanvas
, rightCanvas
);
186 void MyFrame::Unsplit(wxCommandEvent
& WXUNUSED(event
) )
188 if ( splitter
->IsSplit() )
192 void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent
& event
)
194 event
.Enable( ( (!splitter
->IsSplit()) || (splitter
->GetSplitMode() != wxSPLIT_HORIZONTAL
) ) );
197 void MyFrame::UpdateUIVertical(wxUpdateUIEvent
& event
)
199 event
.Enable( ( (!splitter
->IsSplit()) || (splitter
->GetSplitMode() != wxSPLIT_VERTICAL
) ) );
202 void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent
& event
)
204 event
.Enable( splitter
->IsSplit() );
207 void MyFrame::OnIdle(wxIdleEvent
& event
)
209 if ( GetStatusBar()->GetStatusText(0) != "Ready" )
210 SetStatusText("Ready");
212 wxFrame::OnIdle(event
);
215 MyCanvas::MyCanvas(wxWindow
* parent
, int x
, int y
, int w
, int h
) :
216 wxScrolledWindow(parent
, -1, wxPoint(x
, y
), wxSize(w
, h
))
220 MyCanvas::~MyCanvas()
224 void MyCanvas::OnDraw(wxDC
& dc
)
226 dc
.SetPen(*wxBLACK_PEN
);
227 dc
.DrawLine(0, 0, 100, 100);
229 dc
.SetBackgroundMode(wxTRANSPARENT
);
230 dc
.DrawText("Testing", 50, 50);
232 dc
.SetPen(*wxRED_PEN
);
233 dc
.SetBrush(*wxGREEN_BRUSH
);
234 dc
.DrawRectangle(120, 120, 100, 80);