]>
git.saurik.com Git - wxWidgets.git/blob - samples/splitter/test.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: m_splitter.cpp
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 MySplitterWindow
: public wxSplitterWindow
38 MySplitterWindow(wxFrame
*parent
, wxWindowID id
) : wxSplitterWindow(parent
, id
)
43 virtual bool OnSashPositionChange(int newSashPosition
)
45 if ( !wxSplitterWindow::OnSashPositionChange(newSashPosition
) )
49 str
.Printf("Sash position = %d", newSashPosition
);
50 m_frame
->SetStatusText(str
);
59 class MyFrame
: public wxFrame
62 MyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
68 void SplitHorizontal(wxCommandEvent
& event
);
69 void SplitVertical(wxCommandEvent
& event
);
70 void Unsplit(wxCommandEvent
& event
);
71 void SetMinSize(wxCommandEvent
& event
);
72 void Quit(wxCommandEvent
& event
);
74 // Menu command update functions
75 void UpdateUIHorizontal(wxUpdateUIEvent
& event
);
76 void UpdateUIVertical(wxUpdateUIEvent
& event
);
77 void UpdateUIUnsplit(wxUpdateUIEvent
& event
);
80 void UpdatePosition();
84 MyCanvas
* m_leftCanvas
;
85 MyCanvas
* m_rightCanvas
;
86 MySplitterWindow
* m_splitter
;
91 class MyCanvas
: public wxScrolledWindow
94 MyCanvas(wxWindow
* parent
, wxWindowID id
, int x
, int y
, int w
, int h
);
97 virtual void OnDraw(wxDC
& dc
);
102 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
105 // ID for the menu commands
116 #define SPLITTER_WINDOW 100
117 #define SPLITTER_FRAME 101
123 bool MyApp::OnInit(void)
125 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, "wxSplitterWindow Example",
126 wxPoint(50, 50), wxSize(420, 300));
136 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
137 EVT_MENU(SPLIT_VERTICAL
, MyFrame::SplitVertical
)
138 EVT_MENU(SPLIT_HORIZONTAL
, MyFrame::SplitHorizontal
)
139 EVT_MENU(SPLIT_UNSPLIT
, MyFrame::Unsplit
)
140 EVT_MENU(SPLIT_QUIT
, MyFrame::Quit
)
141 EVT_MENU(SPLIT_SETMINSIZE
, MyFrame::SetMinSize
)
143 EVT_UPDATE_UI(SPLIT_VERTICAL
, MyFrame::UpdateUIVertical
)
144 EVT_UPDATE_UI(SPLIT_HORIZONTAL
, MyFrame::UpdateUIHorizontal
)
145 EVT_UPDATE_UI(SPLIT_UNSPLIT
, MyFrame::UpdateUIUnsplit
)
148 // My frame constructor
149 MyFrame::MyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
150 wxFrame(frame
, SPLITTER_FRAME
, title
, pos
, size
)
155 fileMenu
= new wxMenu
;
156 fileMenu
->Append(SPLIT_VERTICAL
, "Split &Vertically", "Split vertically");
157 fileMenu
->Append(SPLIT_HORIZONTAL
, "Split &Horizontally", "Split horizontally");
158 fileMenu
->Append(SPLIT_UNSPLIT
, "&Unsplit", "Unsplit");
159 fileMenu
->AppendSeparator();
160 fileMenu
->Append(SPLIT_SETMINSIZE
, "Set &min size", "Set minimum pane size");
161 fileMenu
->AppendSeparator();
162 fileMenu
->Append(SPLIT_QUIT
, "E&xit", "Exit");
164 menuBar
= new wxMenuBar
;
165 menuBar
->Append(fileMenu
, "&File");
169 m_splitter
= new MySplitterWindow(this, SPLITTER_WINDOW
);
171 m_leftCanvas
= new MyCanvas(m_splitter
, CANVAS1
, 0, 0, 400, 400);
172 m_leftCanvas
->SetBackgroundColour(*wxRED
);
173 m_leftCanvas
->SetScrollbars(20, 20, 50, 50);
175 m_rightCanvas
= new MyCanvas(m_splitter
, CANVAS2
, 0, 0, 400, 400);
176 m_rightCanvas
->SetBackgroundColour(*wxCYAN
);
177 m_rightCanvas
->SetScrollbars(20, 20, 50, 50);
178 m_rightCanvas
->Show(FALSE
);
180 m_splitter
->Initialize(m_leftCanvas
);
181 SetStatusText("Min pane size = 0", 1);
188 bool MyFrame::OnClose()
193 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
198 void MyFrame::SplitHorizontal(wxCommandEvent
& WXUNUSED(event
) )
200 if ( m_splitter
->IsSplit() )
201 m_splitter
->Unsplit();
202 m_leftCanvas
->Show(TRUE
);
203 m_rightCanvas
->Show(TRUE
);
204 m_splitter
->SplitHorizontally( m_leftCanvas
, m_rightCanvas
);
208 void MyFrame::SplitVertical(wxCommandEvent
& WXUNUSED(event
) )
210 if ( m_splitter
->IsSplit() )
211 m_splitter
->Unsplit();
212 m_leftCanvas
->Show(TRUE
);
213 m_rightCanvas
->Show(TRUE
);
214 m_splitter
->SplitVertically( m_leftCanvas
, m_rightCanvas
);
218 void MyFrame::Unsplit(wxCommandEvent
& WXUNUSED(event
) )
220 if ( m_splitter
->IsSplit() )
221 m_splitter
->Unsplit();
222 SetStatusText("No splitter");
225 void MyFrame::SetMinSize(wxCommandEvent
& WXUNUSED(event
) )
228 str
.Printf("%d", m_splitter
->GetMinimumPaneSize());
229 str
= wxGetTextFromUser("Enter minimal size for panes:", "", str
, this);
233 int minsize
= atoi(str
);
234 m_splitter
->SetMinimumPaneSize(minsize
);
235 str
.Printf("Min pane size = %d", minsize
);
236 SetStatusText(str
, 1);
239 void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent
& event
)
241 event
.Enable( ( (!m_splitter
->IsSplit()) || (m_splitter
->GetSplitMode() != wxSPLIT_HORIZONTAL
) ) );
244 void MyFrame::UpdateUIVertical(wxUpdateUIEvent
& event
)
246 event
.Enable( ( (!m_splitter
->IsSplit()) || (m_splitter
->GetSplitMode() != wxSPLIT_VERTICAL
) ) );
249 void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent
& event
)
251 event
.Enable( m_splitter
->IsSplit() );
254 void MyFrame::UpdatePosition()
257 str
.Printf("Sash position = %d", m_splitter
->GetSashPosition());
261 MyCanvas::MyCanvas(wxWindow
* parent
, wxWindowID id
, int x
, int y
, int w
, int h
) :
262 wxScrolledWindow(parent
, id
, wxPoint(x
, y
), wxSize(w
, h
))
266 MyCanvas::~MyCanvas()
270 void MyCanvas::OnDraw(wxDC
& dc
)
272 dc
.SetPen(*wxBLACK_PEN
);
273 dc
.DrawLine(0, 0, 100, 100);
275 dc
.SetBackgroundMode(wxTRANSPARENT
);
276 dc
.DrawText("Testing", 50, 50);
278 dc
.SetPen(*wxRED_PEN
);
279 dc
.SetBrush(*wxGREEN_BRUSH
);
280 dc
.DrawRectangle(120, 120, 100, 80);