]> git.saurik.com Git - wxWidgets.git/blame - samples/splitter/test.cpp
* fixed a wrong line.
[wxWidgets.git] / samples / splitter / test.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: splitter.cpp
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
9// Licence: wxWindows license
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:
32 bool OnInit();
33};
34
35class MyFrame: public wxFrame
36{
37public:
38 MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size);
39 virtual ~MyFrame();
40
41 bool OnClose();
42
43 // Menu commands
44 void SplitHorizontal(wxCommandEvent& event);
45 void SplitVertical(wxCommandEvent& event);
46 void Unsplit(wxCommandEvent& event);
47 void Quit(wxCommandEvent& event);
48
49 // Menu command update functions
50 void UpdateUIHorizontal(wxUpdateUIEvent& event);
51 void UpdateUIVertical(wxUpdateUIEvent& event);
52 void UpdateUIUnsplit(wxUpdateUIEvent& event);
53
54 void OnIdle(wxIdleEvent& event);
55
56private:
57 wxMenu* fileMenu;
58 wxMenuBar* menuBar;
59 MyCanvas* leftCanvas;
60 MyCanvas* rightCanvas;
61 wxSplitterWindow* splitter;
62
63DECLARE_EVENT_TABLE()
64};
65
66class MyCanvas: public wxScrolledWindow
67{
68public:
69 MyCanvas(wxWindow* parent, int x, int y, int w, int h);
70 virtual ~MyCanvas();
71
72 virtual void OnDraw(wxDC& dc);
73
74DECLARE_EVENT_TABLE()
75};
76
77BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
78END_EVENT_TABLE()
79
80// ID for the menu quit command
81#define SPLIT_QUIT 1
82#define SPLIT_HORIZONTAL 2
83#define SPLIT_VERTICAL 3
84#define SPLIT_UNSPLIT 4
85
86IMPLEMENT_APP(MyApp)
87
88bool MyApp::OnInit(void)
89{
c67daf87 90 MyFrame* frame = new MyFrame((wxFrame *) NULL, (char *) "wxSplitterWindow Example", wxPoint(50, 50), wxSize(400, 300));
c801d85f
KB
91
92 // Show the frame
93 frame->Show(TRUE);
94
95 SetTopWindow(frame);
96
97 return TRUE;
98}
99
100BEGIN_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)
109END_EVENT_TABLE()
110
111// My frame constructor
112MyFrame::MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size):
113 wxFrame(frame, -1, title, pos, size)
114{
115 // set the icon
2049ba38 116#ifdef __WXMSW__
c801d85f
KB
117 SetIcon(wxIcon("mondrian"));
118#endif
c801d85f 119
b7346a70
JS
120 CreateStatusBar(1);
121
c801d85f
KB
122 // Make a menubar
123 fileMenu = new wxMenu;
124 fileMenu->Append(SPLIT_VERTICAL, "Split &Vertically", "Split vertically");
125 fileMenu->Append(SPLIT_HORIZONTAL, "Split &Horizontally", "Split horizontally");
126 fileMenu->Append(SPLIT_UNSPLIT, "&Unsplit", "Unsplit");
127 fileMenu->Append(SPLIT_QUIT, "E&xit", "Exit");
128
129 menuBar = new wxMenuBar;
130 menuBar->Append(fileMenu, "&File");
131
132 SetMenuBar(menuBar);
133
134 splitter = new wxSplitterWindow(this, -1, wxPoint(0, 0), wxSize(400, 400),
135// wxSP_BORDER);
136 wxSP_3D);
137// wxSP_NOBORDER);
138
139 leftCanvas = new MyCanvas(splitter, 0, 0, 400, 400);
140 leftCanvas->SetBackgroundColour(*wxRED);
141 leftCanvas->SetScrollbars(20, 20, 50, 50);
142
143 rightCanvas = new MyCanvas(splitter, 0, 0, 400, 400);
144 rightCanvas->SetBackgroundColour(*wxCYAN);
145 rightCanvas->SetScrollbars(20, 20, 50, 50);
146 rightCanvas->Show(FALSE);
147
148 splitter->Initialize(leftCanvas);
149
150 // Set this to prevent unsplitting
151// splitter->SetMinimumPaneSize(20);
c801d85f
KB
152}
153
154MyFrame::~MyFrame()
155{
156}
157
158bool MyFrame::OnClose()
159{
160 return TRUE;
161}
162
e3e65dac 163void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
164{
165 Close(TRUE);
166}
167
e3e65dac 168void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
169{
170 if ( splitter->IsSplit() )
171 splitter->Unsplit();
172 leftCanvas->Show(TRUE);
173 rightCanvas->Show(TRUE);
174 splitter->SplitHorizontally( leftCanvas, rightCanvas );
175}
176
e3e65dac 177void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
178{
179 if ( splitter->IsSplit() )
180 splitter->Unsplit();
181 leftCanvas->Show(TRUE);
182 rightCanvas->Show(TRUE);
183 splitter->SplitVertically( leftCanvas, rightCanvas );
184}
185
e3e65dac 186void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
187{
188 if ( splitter->IsSplit() )
189 splitter->Unsplit();
190}
191
192void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event)
193{
194 event.Enable( ( (!splitter->IsSplit()) || (splitter->GetSplitMode() != wxSPLIT_HORIZONTAL) ) );
195}
196
197void MyFrame::UpdateUIVertical(wxUpdateUIEvent& event)
198{
199 event.Enable( ( (!splitter->IsSplit()) || (splitter->GetSplitMode() != wxSPLIT_VERTICAL) ) );
200}
201
202void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent& event)
203{
204 event.Enable( splitter->IsSplit() );
205}
206
207void MyFrame::OnIdle(wxIdleEvent& event)
208{
209 if ( GetStatusBar()->GetStatusText(0) != "Ready" )
210 SetStatusText("Ready");
d29d303b
JS
211
212 wxFrame::OnIdle(event);
c801d85f
KB
213}
214
215MyCanvas::MyCanvas(wxWindow* parent, int x, int y, int w, int h) :
216 wxScrolledWindow(parent, -1, wxPoint(x, y), wxSize(w, h))
217{
218}
219
220MyCanvas::~MyCanvas()
221{
222}
223
224void MyCanvas::OnDraw(wxDC& dc)
225{
b7346a70 226 dc.SetPen(*wxBLACK_PEN);
c801d85f
KB
227 dc.DrawLine(0, 0, 100, 100);
228
229 dc.SetBackgroundMode(wxTRANSPARENT);
230 dc.DrawText("Testing", 50, 50);
b7346a70
JS
231
232 dc.SetPen(*wxRED_PEN);
233 dc.SetBrush(*wxGREEN_BRUSH);
234 dc.DrawRectangle(120, 120, 100, 80);
c801d85f 235}