]> git.saurik.com Git - wxWidgets.git/blame - samples/splitter/test.cpp
Added dde sample; added docs/index.htm
[wxWidgets.git] / samples / splitter / test.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
0d559d69 2// Name: m_splitter.cpp
c801d85f
KB
3// Purpose: wxSplitterWindow sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
0d559d69 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
23#include "wx/splitter.h"
24
25class MyApp;
26class MyFrame;
27class MyCanvas;
28
29class MyApp: public wxApp
30{
31public:
0d559d69 32 bool OnInit();
c801d85f
KB
33};
34
0d559d69 35class MySplitterWindow : public wxSplitterWindow
c801d85f
KB
36{
37public:
0d559d69
VZ
38 MySplitterWindow(wxFrame *parent, wxWindowID id) : wxSplitterWindow(parent, id)
39 {
40 m_frame = parent;
41 }
42
43 virtual bool OnSashPositionChange(int newSashPosition)
44 {
45 if ( !wxSplitterWindow::OnSashPositionChange(newSashPosition) )
46 return FALSE;
47
48 wxString str;
49 str.Printf("Sash position = %d", newSashPosition);
50 m_frame->SetStatusText(str);
51
52 return TRUE;
53 }
54
55private:
56 wxFrame *m_frame;
57};
c801d85f 58
0d559d69
VZ
59class MyFrame: public wxFrame
60{
61public:
62 MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size);
63 virtual ~MyFrame();
c801d85f 64
0d559d69 65 bool OnClose();
c801d85f 66
0d559d69
VZ
67 // Menu commands
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);
c801d85f 73
0d559d69
VZ
74 // Menu command update functions
75 void UpdateUIHorizontal(wxUpdateUIEvent& event);
76 void UpdateUIVertical(wxUpdateUIEvent& event);
77 void UpdateUIUnsplit(wxUpdateUIEvent& event);
c801d85f
KB
78
79private:
0d559d69
VZ
80 void UpdatePosition();
81
82 wxMenu* fileMenu;
83 wxMenuBar* menuBar;
84 MyCanvas* m_leftCanvas;
85 MyCanvas* m_rightCanvas;
86 MySplitterWindow* m_splitter;
c801d85f
KB
87
88DECLARE_EVENT_TABLE()
89};
90
91class MyCanvas: public wxScrolledWindow
92{
93public:
0d57be45 94 MyCanvas(wxWindow* parent, wxWindowID id, int x, int y, int w, int h);
c801d85f
KB
95 virtual ~MyCanvas();
96
0d559d69 97 virtual void OnDraw(wxDC& dc);
c801d85f
KB
98
99DECLARE_EVENT_TABLE()
100};
101
102BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
103END_EVENT_TABLE()
104
0d559d69
VZ
105// ID for the menu commands
106enum
107{
108 SPLIT_QUIT,
109 SPLIT_HORIZONTAL,
110 SPLIT_VERTICAL,
111 SPLIT_UNSPLIT,
112 SPLIT_SETMINSIZE
113};
c801d85f 114
0d57be45
JS
115// Window ids
116#define SPLITTER_WINDOW 100
117#define SPLITTER_FRAME 101
118#define CANVAS1 102
119#define CANVAS2 103
120
c801d85f
KB
121IMPLEMENT_APP(MyApp)
122
123bool MyApp::OnInit(void)
124{
0d559d69
VZ
125 MyFrame* frame = new MyFrame((wxFrame *) NULL, "wxSplitterWindow Example",
126 wxPoint(50, 50), wxSize(420, 300));
c801d85f 127
0d559d69
VZ
128 // Show the frame
129 frame->Show(TRUE);
c801d85f 130
0d559d69 131 SetTopWindow(frame);
c801d85f 132
0d559d69 133 return TRUE;
c801d85f
KB
134}
135
136BEGIN_EVENT_TABLE(MyFrame, wxFrame)
0d559d69
VZ
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)
142
143 EVT_UPDATE_UI(SPLIT_VERTICAL, MyFrame::UpdateUIVertical)
144 EVT_UPDATE_UI(SPLIT_HORIZONTAL, MyFrame::UpdateUIHorizontal)
145 EVT_UPDATE_UI(SPLIT_UNSPLIT, MyFrame::UpdateUIUnsplit)
c801d85f
KB
146END_EVENT_TABLE()
147
148// My frame constructor
149MyFrame::MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size):
0d57be45 150 wxFrame(frame, SPLITTER_FRAME, title, pos, size)
c801d85f 151{
0d559d69 152 CreateStatusBar(2);
b7346a70 153
0d559d69
VZ
154 // Make a menubar
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");
c801d85f 163
0d559d69
VZ
164 menuBar = new wxMenuBar;
165 menuBar->Append(fileMenu, "&File");
c801d85f 166
0d559d69 167 SetMenuBar(menuBar);
c801d85f 168
0d559d69 169 m_splitter = new MySplitterWindow(this, SPLITTER_WINDOW);
c801d85f 170
0d559d69
VZ
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);
c801d85f 174
0d559d69
VZ
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);
c801d85f 179
0d559d69
VZ
180 m_splitter->Initialize(m_leftCanvas);
181 SetStatusText("Min pane size = 0", 1);
c801d85f
KB
182}
183
184MyFrame::~MyFrame()
185{
186}
187
188bool MyFrame::OnClose()
189{
0d559d69 190 return TRUE;
c801d85f
KB
191}
192
e3e65dac 193void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
c801d85f 194{
0d559d69 195 Close(TRUE);
c801d85f
KB
196}
197
e3e65dac 198void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
c801d85f 199{
0d559d69
VZ
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 );
205 UpdatePosition();
c801d85f
KB
206}
207
e3e65dac 208void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
c801d85f 209{
0d559d69
VZ
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 );
215 UpdatePosition();
c801d85f
KB
216}
217
e3e65dac 218void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
c801d85f 219{
0d559d69
VZ
220 if ( m_splitter->IsSplit() )
221 m_splitter->Unsplit();
222 SetStatusText("No splitter");
223}
224
225void MyFrame::SetMinSize(wxCommandEvent& WXUNUSED(event) )
226{
227 wxString str;
228 str.Printf("%d", m_splitter->GetMinimumPaneSize());
229 str = wxGetTextFromUser("Enter minimal size for panes:", "", str, this);
230 if ( str.IsEmpty() )
231 return;
232
233 int minsize = atoi(str);
234 m_splitter->SetMinimumPaneSize(minsize);
235 str.Printf("Min pane size = %d", minsize);
236 SetStatusText(str, 1);
c801d85f
KB
237}
238
239void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event)
240{
0d559d69 241 event.Enable( ( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_HORIZONTAL) ) );
c801d85f
KB
242}
243
244void MyFrame::UpdateUIVertical(wxUpdateUIEvent& event)
245{
0d559d69 246 event.Enable( ( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_VERTICAL) ) );
c801d85f
KB
247}
248
249void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent& event)
250{
0d559d69 251 event.Enable( m_splitter->IsSplit() );
c801d85f
KB
252}
253
0d559d69 254void MyFrame::UpdatePosition()
c801d85f 255{
0d559d69
VZ
256 wxString str;
257 str.Printf("Sash position = %d", m_splitter->GetSashPosition());
258 SetStatusText(str);
c801d85f
KB
259}
260
0d57be45
JS
261MyCanvas::MyCanvas(wxWindow* parent, wxWindowID id, int x, int y, int w, int h) :
262 wxScrolledWindow(parent, id, wxPoint(x, y), wxSize(w, h))
c801d85f
KB
263{
264}
265
266MyCanvas::~MyCanvas()
267{
268}
269
270void MyCanvas::OnDraw(wxDC& dc)
271{
0d559d69
VZ
272 dc.SetPen(*wxBLACK_PEN);
273 dc.DrawLine(0, 0, 100, 100);
c801d85f 274
0d559d69
VZ
275 dc.SetBackgroundMode(wxTRANSPARENT);
276 dc.DrawText("Testing", 50, 50);
b7346a70 277
0d559d69
VZ
278 dc.SetPen(*wxRED_PEN);
279 dc.SetBrush(*wxGREEN_BRUSH);
280 dc.DrawRectangle(120, 120, 100, 80);
c801d85f 281}