]> git.saurik.com Git - wxWidgets.git/blame - samples/splitter/test.cpp
More-or-less finished reasonably cool wxToolBar class with tooltips.
[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:
0d57be45 69 MyCanvas(wxWindow* parent, wxWindowID id, int x, int y, int w, int h);
c801d85f
KB
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
0d57be45
JS
86// Window ids
87#define SPLITTER_WINDOW 100
88#define SPLITTER_FRAME 101
89#define CANVAS1 102
90#define CANVAS2 103
91
c801d85f
KB
92IMPLEMENT_APP(MyApp)
93
94bool MyApp::OnInit(void)
95{
c67daf87 96 MyFrame* frame = new MyFrame((wxFrame *) NULL, (char *) "wxSplitterWindow Example", wxPoint(50, 50), wxSize(400, 300));
c801d85f
KB
97
98 // Show the frame
99 frame->Show(TRUE);
100
101 SetTopWindow(frame);
102
103 return TRUE;
104}
105
106BEGIN_EVENT_TABLE(MyFrame, wxFrame)
107 EVT_MENU(SPLIT_VERTICAL, MyFrame::SplitVertical)
108 EVT_MENU(SPLIT_HORIZONTAL, MyFrame::SplitHorizontal)
109 EVT_MENU(SPLIT_UNSPLIT, MyFrame::Unsplit)
110 EVT_MENU(SPLIT_QUIT, MyFrame::Quit)
111 EVT_UPDATE_UI(SPLIT_VERTICAL, MyFrame::UpdateUIVertical)
112 EVT_UPDATE_UI(SPLIT_HORIZONTAL, MyFrame::UpdateUIHorizontal)
113 EVT_UPDATE_UI(SPLIT_UNSPLIT, MyFrame::UpdateUIUnsplit)
114 EVT_IDLE(MyFrame::OnIdle)
115END_EVENT_TABLE()
116
117// My frame constructor
118MyFrame::MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size):
0d57be45 119 wxFrame(frame, SPLITTER_FRAME, title, pos, size)
c801d85f
KB
120{
121 // set the icon
2049ba38 122#ifdef __WXMSW__
c801d85f
KB
123 SetIcon(wxIcon("mondrian"));
124#endif
c801d85f 125
b7346a70
JS
126 CreateStatusBar(1);
127
c801d85f
KB
128 // Make a menubar
129 fileMenu = new wxMenu;
130 fileMenu->Append(SPLIT_VERTICAL, "Split &Vertically", "Split vertically");
131 fileMenu->Append(SPLIT_HORIZONTAL, "Split &Horizontally", "Split horizontally");
132 fileMenu->Append(SPLIT_UNSPLIT, "&Unsplit", "Unsplit");
133 fileMenu->Append(SPLIT_QUIT, "E&xit", "Exit");
134
135 menuBar = new wxMenuBar;
136 menuBar->Append(fileMenu, "&File");
137
138 SetMenuBar(menuBar);
139
0d57be45 140 splitter = new wxSplitterWindow(this, SPLITTER_WINDOW, wxPoint(0, 0), wxSize(400, 400),
c801d85f
KB
141// wxSP_BORDER);
142 wxSP_3D);
143// wxSP_NOBORDER);
144
0d57be45 145 leftCanvas = new MyCanvas(splitter, CANVAS1, 0, 0, 400, 400);
c801d85f
KB
146 leftCanvas->SetBackgroundColour(*wxRED);
147 leftCanvas->SetScrollbars(20, 20, 50, 50);
148
0d57be45 149 rightCanvas = new MyCanvas(splitter, CANVAS2, 0, 0, 400, 400);
c801d85f
KB
150 rightCanvas->SetBackgroundColour(*wxCYAN);
151 rightCanvas->SetScrollbars(20, 20, 50, 50);
152 rightCanvas->Show(FALSE);
153
154 splitter->Initialize(leftCanvas);
155
156 // Set this to prevent unsplitting
157// splitter->SetMinimumPaneSize(20);
c801d85f
KB
158}
159
160MyFrame::~MyFrame()
161{
162}
163
164bool MyFrame::OnClose()
165{
166 return TRUE;
167}
168
e3e65dac 169void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
170{
171 Close(TRUE);
172}
173
e3e65dac 174void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
175{
176 if ( splitter->IsSplit() )
177 splitter->Unsplit();
178 leftCanvas->Show(TRUE);
179 rightCanvas->Show(TRUE);
180 splitter->SplitHorizontally( leftCanvas, rightCanvas );
181}
182
e3e65dac 183void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
184{
185 if ( splitter->IsSplit() )
186 splitter->Unsplit();
187 leftCanvas->Show(TRUE);
188 rightCanvas->Show(TRUE);
189 splitter->SplitVertically( leftCanvas, rightCanvas );
190}
191
e3e65dac 192void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
c801d85f
KB
193{
194 if ( splitter->IsSplit() )
195 splitter->Unsplit();
196}
197
198void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event)
199{
200 event.Enable( ( (!splitter->IsSplit()) || (splitter->GetSplitMode() != wxSPLIT_HORIZONTAL) ) );
201}
202
203void MyFrame::UpdateUIVertical(wxUpdateUIEvent& event)
204{
205 event.Enable( ( (!splitter->IsSplit()) || (splitter->GetSplitMode() != wxSPLIT_VERTICAL) ) );
206}
207
208void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent& event)
209{
210 event.Enable( splitter->IsSplit() );
211}
212
213void MyFrame::OnIdle(wxIdleEvent& event)
214{
215 if ( GetStatusBar()->GetStatusText(0) != "Ready" )
216 SetStatusText("Ready");
d29d303b
JS
217
218 wxFrame::OnIdle(event);
c801d85f
KB
219}
220
0d57be45
JS
221MyCanvas::MyCanvas(wxWindow* parent, wxWindowID id, int x, int y, int w, int h) :
222 wxScrolledWindow(parent, id, wxPoint(x, y), wxSize(w, h))
c801d85f
KB
223{
224}
225
226MyCanvas::~MyCanvas()
227{
228}
229
230void MyCanvas::OnDraw(wxDC& dc)
231{
b7346a70 232 dc.SetPen(*wxBLACK_PEN);
c801d85f
KB
233 dc.DrawLine(0, 0, 100, 100);
234
235 dc.SetBackgroundMode(wxTRANSPARENT);
236 dc.DrawText("Testing", 50, 50);
b7346a70
JS
237
238 dc.SetPen(*wxRED_PEN);
239 dc.SetBrush(*wxGREEN_BRUSH);
240 dc.DrawRectangle(120, 120, 100, 80);
c801d85f 241}