]>
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"));
120 SetIcon(wxIcon("aiai.xbm"));
126 fileMenu
= new wxMenu
;
127 fileMenu
->Append(SPLIT_VERTICAL
, "Split &Vertically", "Split vertically");
128 fileMenu
->Append(SPLIT_HORIZONTAL
, "Split &Horizontally", "Split horizontally");
129 fileMenu
->Append(SPLIT_UNSPLIT
, "&Unsplit", "Unsplit");
130 fileMenu
->Append(SPLIT_QUIT
, "E&xit", "Exit");
132 menuBar
= new wxMenuBar
;
133 menuBar
->Append(fileMenu
, "&File");
137 splitter
= new wxSplitterWindow(this, -1, wxPoint(0, 0), wxSize(400, 400),
142 leftCanvas
= new MyCanvas(splitter
, 0, 0, 400, 400);
143 leftCanvas
->SetBackgroundColour(*wxRED
);
144 leftCanvas
->SetScrollbars(20, 20, 50, 50);
146 rightCanvas
= new MyCanvas(splitter
, 0, 0, 400, 400);
147 rightCanvas
->SetBackgroundColour(*wxCYAN
);
148 rightCanvas
->SetScrollbars(20, 20, 50, 50);
149 rightCanvas
->Show(FALSE
);
151 splitter
->Initialize(leftCanvas
);
153 // Set this to prevent unsplitting
154 // splitter->SetMinimumPaneSize(20);
161 bool MyFrame::OnClose()
166 void MyFrame::Quit(wxCommandEvent
& event
)
171 void MyFrame::SplitHorizontal(wxCommandEvent
& event
)
173 if ( splitter
->IsSplit() )
175 leftCanvas
->Show(TRUE
);
176 rightCanvas
->Show(TRUE
);
177 splitter
->SplitHorizontally( leftCanvas
, rightCanvas
);
180 void MyFrame::SplitVertical(wxCommandEvent
& event
)
182 if ( splitter
->IsSplit() )
184 leftCanvas
->Show(TRUE
);
185 rightCanvas
->Show(TRUE
);
186 splitter
->SplitVertically( leftCanvas
, rightCanvas
);
189 void MyFrame::Unsplit(wxCommandEvent
& event
)
191 if ( splitter
->IsSplit() )
195 void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent
& event
)
197 event
.Enable( ( (!splitter
->IsSplit()) || (splitter
->GetSplitMode() != wxSPLIT_HORIZONTAL
) ) );
200 void MyFrame::UpdateUIVertical(wxUpdateUIEvent
& event
)
202 event
.Enable( ( (!splitter
->IsSplit()) || (splitter
->GetSplitMode() != wxSPLIT_VERTICAL
) ) );
205 void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent
& event
)
207 event
.Enable( splitter
->IsSplit() );
210 void MyFrame::OnIdle(wxIdleEvent
& event
)
212 if ( GetStatusBar()->GetStatusText(0) != "Ready" )
213 SetStatusText("Ready");
216 MyCanvas::MyCanvas(wxWindow
* parent
, int x
, int y
, int w
, int h
) :
217 wxScrolledWindow(parent
, -1, wxPoint(x
, y
), wxSize(w
, h
))
221 MyCanvas::~MyCanvas()
225 void MyCanvas::OnDraw(wxDC
& dc
)
227 dc
.SetPen(*wxBLACK_PEN
);
228 dc
.DrawLine(0, 0, 100, 100);
230 dc
.SetBackgroundMode(wxTRANSPARENT
);
231 dc
.DrawText("Testing", 50, 50);
233 dc
.SetPen(*wxRED_PEN
);
234 dc
.SetBrush(*wxGREEN_BRUSH
);
235 dc
.DrawRectangle(120, 120, 100, 80);