]>
git.saurik.com Git - wxWidgets.git/blob - samples/splitter/test.cpp
7c842ee0cc03c3561a64c7cc7cef874387dbab23
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
, wxWindowID id
, 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
87 #define SPLITTER_WINDOW 100
88 #define SPLITTER_FRAME 101
94 bool MyApp::OnInit(void)
96 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, (char *) "wxSplitterWindow Example", wxPoint(50, 50), wxSize(400, 300));
106 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
107 EVT_MENU(SPLIT_VERTICAL
, MyFrame::SplitVertical
)
108 EVT_MENU(SPLIT_HORIZONTAL
, MyFrame::SplitHorizontal
)
109 EVT_MENU(SPLIT_UNSPLIT
, MyFrame::Unsplit
)
110 EVT_MENU(SPLIT_QUIT
, MyFrame::Quit
)
111 EVT_UPDATE_UI(SPLIT_VERTICAL
, MyFrame::UpdateUIVertical
)
112 EVT_UPDATE_UI(SPLIT_HORIZONTAL
, MyFrame::UpdateUIHorizontal
)
113 EVT_UPDATE_UI(SPLIT_UNSPLIT
, MyFrame::UpdateUIUnsplit
)
114 EVT_IDLE(MyFrame::OnIdle
)
117 // My frame constructor
118 MyFrame::MyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
119 wxFrame(frame
, SPLITTER_FRAME
, title
, pos
, size
)
123 SetIcon(wxIcon("mondrian"));
129 fileMenu
= new wxMenu
;
130 fileMenu
->Append(SPLIT_VERTICAL
, "Split &Vertically", "Split vertically");
131 fileMenu
->Append(SPLIT_HORIZONTAL
, "Split &Horizontally", "Split horizontally");
132 fileMenu
->Append(SPLIT_UNSPLIT
, "&Unsplit", "Unsplit");
133 fileMenu
->Append(SPLIT_QUIT
, "E&xit", "Exit");
135 menuBar
= new wxMenuBar
;
136 menuBar
->Append(fileMenu
, "&File");
140 splitter
= new wxSplitterWindow(this, SPLITTER_WINDOW
, wxPoint(0, 0), wxSize(400, 400),
145 leftCanvas
= new MyCanvas(splitter
, CANVAS1
, 0, 0, 400, 400);
146 leftCanvas
->SetBackgroundColour(*wxRED
);
147 leftCanvas
->SetScrollbars(20, 20, 50, 50);
149 rightCanvas
= new MyCanvas(splitter
, CANVAS2
, 0, 0, 400, 400);
150 rightCanvas
->SetBackgroundColour(*wxCYAN
);
151 rightCanvas
->SetScrollbars(20, 20, 50, 50);
152 rightCanvas
->Show(FALSE
);
154 splitter
->Initialize(leftCanvas
);
156 // Set this to prevent unsplitting
157 // splitter->SetMinimumPaneSize(20);
164 bool MyFrame::OnClose()
169 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
174 void MyFrame::SplitHorizontal(wxCommandEvent
& WXUNUSED(event
) )
176 if ( splitter
->IsSplit() )
178 leftCanvas
->Show(TRUE
);
179 rightCanvas
->Show(TRUE
);
180 splitter
->SplitHorizontally( leftCanvas
, rightCanvas
);
183 void MyFrame::SplitVertical(wxCommandEvent
& WXUNUSED(event
) )
185 if ( splitter
->IsSplit() )
187 leftCanvas
->Show(TRUE
);
188 rightCanvas
->Show(TRUE
);
189 splitter
->SplitVertically( leftCanvas
, rightCanvas
);
192 void MyFrame::Unsplit(wxCommandEvent
& WXUNUSED(event
) )
194 if ( splitter
->IsSplit() )
198 void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent
& event
)
200 event
.Enable( ( (!splitter
->IsSplit()) || (splitter
->GetSplitMode() != wxSPLIT_HORIZONTAL
) ) );
203 void MyFrame::UpdateUIVertical(wxUpdateUIEvent
& event
)
205 event
.Enable( ( (!splitter
->IsSplit()) || (splitter
->GetSplitMode() != wxSPLIT_VERTICAL
) ) );
208 void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent
& event
)
210 event
.Enable( splitter
->IsSplit() );
213 void MyFrame::OnIdle(wxIdleEvent
& event
)
215 if ( GetStatusBar()->GetStatusText(0) != "Ready" )
216 SetStatusText("Ready");
218 wxFrame::OnIdle(event
);
221 MyCanvas::MyCanvas(wxWindow
* parent
, wxWindowID id
, int x
, int y
, int w
, int h
) :
222 wxScrolledWindow(parent
, id
, wxPoint(x
, y
), wxSize(w
, h
))
226 MyCanvas::~MyCanvas()
230 void MyCanvas::OnDraw(wxDC
& dc
)
232 dc
.SetPen(*wxBLACK_PEN
);
233 dc
.DrawLine(0, 0, 100, 100);
235 dc
.SetBackgroundMode(wxTRANSPARENT
);
236 dc
.DrawText("Testing", 50, 50);
238 dc
.SetPen(*wxRED_PEN
);
239 dc
.SetBrush(*wxGREEN_BRUSH
);
240 dc
.DrawRectangle(120, 120, 100, 80);