]>
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"));
124 fileMenu
= new wxMenu
;
125 fileMenu
->Append(SPLIT_VERTICAL
, "Split &Vertically", "Split vertically");
126 fileMenu
->Append(SPLIT_HORIZONTAL
, "Split &Horizontally", "Split horizontally");
127 fileMenu
->Append(SPLIT_UNSPLIT
, "&Unsplit", "Unsplit");
128 fileMenu
->Append(SPLIT_QUIT
, "E&xit", "Exit");
130 menuBar
= new wxMenuBar
;
131 menuBar
->Append(fileMenu
, "&File");
135 splitter
= new wxSplitterWindow(this, -1, wxPoint(0, 0), wxSize(400, 400),
140 leftCanvas
= new MyCanvas(splitter
, 0, 0, 400, 400);
141 leftCanvas
->SetBackgroundColour(*wxRED
);
142 leftCanvas
->SetScrollbars(20, 20, 50, 50);
144 rightCanvas
= new MyCanvas(splitter
, 0, 0, 400, 400);
145 rightCanvas
->SetBackgroundColour(*wxCYAN
);
146 rightCanvas
->SetScrollbars(20, 20, 50, 50);
147 rightCanvas
->Show(FALSE
);
149 splitter
->Initialize(leftCanvas
);
151 // Set this to prevent unsplitting
152 // splitter->SetMinimumPaneSize(20);
160 bool MyFrame::OnClose()
165 void MyFrame::Quit(wxCommandEvent
& event
)
170 void MyFrame::SplitHorizontal(wxCommandEvent
& event
)
172 if ( splitter
->IsSplit() )
174 leftCanvas
->Show(TRUE
);
175 rightCanvas
->Show(TRUE
);
176 splitter
->SplitHorizontally( leftCanvas
, rightCanvas
);
179 void MyFrame::SplitVertical(wxCommandEvent
& event
)
181 if ( splitter
->IsSplit() )
183 leftCanvas
->Show(TRUE
);
184 rightCanvas
->Show(TRUE
);
185 splitter
->SplitVertically( leftCanvas
, rightCanvas
);
188 void MyFrame::Unsplit(wxCommandEvent
& event
)
190 if ( splitter
->IsSplit() )
194 void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent
& event
)
196 event
.Enable( ( (!splitter
->IsSplit()) || (splitter
->GetSplitMode() != wxSPLIT_HORIZONTAL
) ) );
199 void MyFrame::UpdateUIVertical(wxUpdateUIEvent
& event
)
201 event
.Enable( ( (!splitter
->IsSplit()) || (splitter
->GetSplitMode() != wxSPLIT_VERTICAL
) ) );
204 void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent
& event
)
206 event
.Enable( splitter
->IsSplit() );
209 void MyFrame::OnIdle(wxIdleEvent
& event
)
211 if ( GetStatusBar()->GetStatusText(0) != "Ready" )
212 SetStatusText("Ready");
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
.DrawLine(0, 0, 100, 100);
228 dc
.SetBackgroundMode(wxTRANSPARENT
);
229 dc
.DrawText("Testing", 50, 50);