]>
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( _T("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
);
66 void SplitHorizontal(wxCommandEvent
& event
);
67 void SplitVertical(wxCommandEvent
& event
);
68 void Unsplit(wxCommandEvent
& event
);
69 void SetMinSize(wxCommandEvent
& event
);
70 void Quit(wxCommandEvent
& event
);
72 // Menu command update functions
73 void UpdateUIHorizontal(wxUpdateUIEvent
& event
);
74 void UpdateUIVertical(wxUpdateUIEvent
& event
);
75 void UpdateUIUnsplit(wxUpdateUIEvent
& event
);
78 void UpdatePosition();
82 MyCanvas
* m_leftCanvas
;
83 MyCanvas
* m_rightCanvas
;
84 MySplitterWindow
* m_splitter
;
89 class MyCanvas
: public wxScrolledWindow
92 MyCanvas(wxWindow
* parent
, wxWindowID id
, int x
, int y
, int w
, int h
, const wxString
&name
);
95 virtual void OnDraw(wxDC
& dc
);
100 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
103 // ID for the menu commands
114 #define SPLITTER_WINDOW 100
115 #define SPLITTER_FRAME 101
121 bool MyApp::OnInit(void)
123 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, "wxSplitterWindow Example",
124 wxPoint(50, 50), wxSize(420, 300));
134 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
135 EVT_MENU(SPLIT_VERTICAL
, MyFrame::SplitVertical
)
136 EVT_MENU(SPLIT_HORIZONTAL
, MyFrame::SplitHorizontal
)
137 EVT_MENU(SPLIT_UNSPLIT
, MyFrame::Unsplit
)
138 EVT_MENU(SPLIT_QUIT
, MyFrame::Quit
)
139 EVT_MENU(SPLIT_SETMINSIZE
, MyFrame::SetMinSize
)
141 EVT_UPDATE_UI(SPLIT_VERTICAL
, MyFrame::UpdateUIVertical
)
142 EVT_UPDATE_UI(SPLIT_HORIZONTAL
, MyFrame::UpdateUIHorizontal
)
143 EVT_UPDATE_UI(SPLIT_UNSPLIT
, MyFrame::UpdateUIUnsplit
)
146 // My frame constructor
147 MyFrame::MyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
148 wxFrame(frame
, SPLITTER_FRAME
, title
, pos
, size
)
153 fileMenu
= new wxMenu
;
154 fileMenu
->Append(SPLIT_VERTICAL
, "Split &Vertically", "Split vertically");
155 fileMenu
->Append(SPLIT_HORIZONTAL
, "Split &Horizontally", "Split horizontally");
156 fileMenu
->Append(SPLIT_UNSPLIT
, "&Unsplit", "Unsplit");
157 fileMenu
->AppendSeparator();
158 fileMenu
->Append(SPLIT_SETMINSIZE
, "Set &min size", "Set minimum pane size");
159 fileMenu
->AppendSeparator();
160 fileMenu
->Append(SPLIT_QUIT
, "E&xit", "Exit");
162 menuBar
= new wxMenuBar
;
163 menuBar
->Append(fileMenu
, "&File");
167 m_splitter
= new MySplitterWindow(this, SPLITTER_WINDOW
);
169 m_leftCanvas
= new MyCanvas(m_splitter
, CANVAS1
, 0, 0, 400, 400, "Test1" );
170 m_leftCanvas
->SetBackgroundColour(*wxRED
);
171 m_leftCanvas
->SetScrollbars(20, 20, 50, 50);
172 m_leftCanvas
->SetCursor(wxCursor(wxCURSOR_MAGNIFIER
));
174 m_rightCanvas
= new MyCanvas(m_splitter
, CANVAS2
, 0, 0, 400, 400, "Test2" );
175 m_rightCanvas
->SetBackgroundColour(*wxCYAN
);
176 m_rightCanvas
->SetScrollbars(20, 20, 50, 50);
177 m_rightCanvas
->Show(FALSE
);
179 m_splitter
->Initialize(m_leftCanvas
);
180 SetStatusText("Min pane size = 0", 1);
187 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
192 void MyFrame::SplitHorizontal(wxCommandEvent
& WXUNUSED(event
) )
194 if ( m_splitter
->IsSplit() )
195 m_splitter
->Unsplit();
196 m_leftCanvas
->Show(TRUE
);
197 m_rightCanvas
->Show(TRUE
);
198 m_splitter
->SplitHorizontally( m_leftCanvas
, m_rightCanvas
);
202 void MyFrame::SplitVertical(wxCommandEvent
& WXUNUSED(event
) )
204 if ( m_splitter
->IsSplit() )
205 m_splitter
->Unsplit();
206 m_leftCanvas
->Show(TRUE
);
207 m_rightCanvas
->Show(TRUE
);
208 m_splitter
->SplitVertically( m_leftCanvas
, m_rightCanvas
);
212 void MyFrame::Unsplit(wxCommandEvent
& WXUNUSED(event
) )
214 if ( m_splitter
->IsSplit() )
215 m_splitter
->Unsplit();
216 SetStatusText("No splitter");
219 void MyFrame::SetMinSize(wxCommandEvent
& WXUNUSED(event
) )
222 str
.Printf( _T("%d"), m_splitter
->GetMinimumPaneSize());
223 str
= wxGetTextFromUser("Enter minimal size for panes:", "", str
, this);
227 int minsize
= wxStrtol( str
, (wxChar
**)NULL
, 10 );
228 m_splitter
->SetMinimumPaneSize(minsize
);
229 str
.Printf( _T("Min pane size = %d"), minsize
);
230 SetStatusText(str
, 1);
233 void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent
& event
)
235 event
.Enable( ( (!m_splitter
->IsSplit()) || (m_splitter
->GetSplitMode() != wxSPLIT_HORIZONTAL
) ) );
238 void MyFrame::UpdateUIVertical(wxUpdateUIEvent
& event
)
240 event
.Enable( ( (!m_splitter
->IsSplit()) || (m_splitter
->GetSplitMode() != wxSPLIT_VERTICAL
) ) );
243 void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent
& event
)
245 event
.Enable( m_splitter
->IsSplit() );
248 void MyFrame::UpdatePosition()
251 str
.Printf( _("Sash position = %d"), m_splitter
->GetSashPosition());
255 MyCanvas::MyCanvas(wxWindow
* parent
, wxWindowID id
, int x
, int y
, int w
, int h
, const wxString
&name
) :
256 wxScrolledWindow(parent
, id
, wxPoint(x
, y
), wxSize(w
, h
), 0, name
)
260 MyCanvas::~MyCanvas()
264 void MyCanvas::OnDraw(wxDC
& dc
)
266 dc
.SetPen(*wxBLACK_PEN
);
267 dc
.DrawLine(0, 0, 100, 100);
269 dc
.SetBackgroundMode(wxTRANSPARENT
);
270 dc
.DrawText("Testing", 50, 50);
272 dc
.SetPen(*wxRED_PEN
);
273 dc
.SetBrush(*wxGREEN_BRUSH
);
274 dc
.DrawRectangle(120, 120, 100, 80);