]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/splitter/test.cpp
Unicode support.
[wxWidgets.git] / samples / splitter / test.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: m_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 MySplitterWindow : public wxSplitterWindow
36{
37public:
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};
58
59class MyFrame: public wxFrame
60{
61public:
62 MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size);
63 virtual ~MyFrame();
64
65 // Menu commands
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);
71
72 // Menu command update functions
73 void UpdateUIHorizontal(wxUpdateUIEvent& event);
74 void UpdateUIVertical(wxUpdateUIEvent& event);
75 void UpdateUIUnsplit(wxUpdateUIEvent& event);
76
77private:
78 void UpdatePosition();
79
80 wxMenu* fileMenu;
81 wxMenuBar* menuBar;
82 MyCanvas* m_leftCanvas;
83 MyCanvas* m_rightCanvas;
84 MySplitterWindow* m_splitter;
85
86DECLARE_EVENT_TABLE()
87};
88
89class MyCanvas: public wxScrolledWindow
90{
91public:
92 MyCanvas(wxWindow* parent, wxWindowID id, int x, int y, int w, int h);
93 virtual ~MyCanvas();
94
95 virtual void OnDraw(wxDC& dc);
96
97DECLARE_EVENT_TABLE()
98};
99
100BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
101END_EVENT_TABLE()
102
103// ID for the menu commands
104enum
105{
106 SPLIT_QUIT,
107 SPLIT_HORIZONTAL,
108 SPLIT_VERTICAL,
109 SPLIT_UNSPLIT,
110 SPLIT_SETMINSIZE
111};
112
113// Window ids
114#define SPLITTER_WINDOW 100
115#define SPLITTER_FRAME 101
116#define CANVAS1 102
117#define CANVAS2 103
118
119IMPLEMENT_APP(MyApp)
120
121bool MyApp::OnInit(void)
122{
123 MyFrame* frame = new MyFrame((wxFrame *) NULL, "wxSplitterWindow Example",
124 wxPoint(50, 50), wxSize(420, 300));
125
126 // Show the frame
127 frame->Show(TRUE);
128
129 SetTopWindow(frame);
130
131 return TRUE;
132}
133
134BEGIN_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)
140
141 EVT_UPDATE_UI(SPLIT_VERTICAL, MyFrame::UpdateUIVertical)
142 EVT_UPDATE_UI(SPLIT_HORIZONTAL, MyFrame::UpdateUIHorizontal)
143 EVT_UPDATE_UI(SPLIT_UNSPLIT, MyFrame::UpdateUIUnsplit)
144END_EVENT_TABLE()
145
146// My frame constructor
147MyFrame::MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size):
148 wxFrame(frame, SPLITTER_FRAME, title, pos, size)
149{
150 CreateStatusBar(2);
151
152 // Make a menubar
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");
161
162 menuBar = new wxMenuBar;
163 menuBar->Append(fileMenu, "&File");
164
165 SetMenuBar(menuBar);
166
167 m_splitter = new MySplitterWindow(this, SPLITTER_WINDOW);
168
169 m_leftCanvas = new MyCanvas(m_splitter, CANVAS1, 0, 0, 400, 400);
170 m_leftCanvas->SetBackgroundColour(*wxRED);
171 m_leftCanvas->SetScrollbars(20, 20, 50, 50);
172 m_leftCanvas->SetCursor(wxCursor(wxCURSOR_MAGNIFIER));
173
174 m_rightCanvas = new MyCanvas(m_splitter, CANVAS2, 0, 0, 400, 400);
175 m_rightCanvas->SetBackgroundColour(*wxCYAN);
176 m_rightCanvas->SetScrollbars(20, 20, 50, 50);
177 m_rightCanvas->Show(FALSE);
178
179 m_splitter->Initialize(m_leftCanvas);
180 SetStatusText("Min pane size = 0", 1);
181}
182
183MyFrame::~MyFrame()
184{
185}
186
187void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
188{
189 Close(TRUE);
190}
191
192void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
193{
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 );
199 UpdatePosition();
200}
201
202void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
203{
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 );
209 UpdatePosition();
210}
211
212void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
213{
214 if ( m_splitter->IsSplit() )
215 m_splitter->Unsplit();
216 SetStatusText("No splitter");
217}
218
219void MyFrame::SetMinSize(wxCommandEvent& WXUNUSED(event) )
220{
221 wxString str;
222 str.Printf("%d", m_splitter->GetMinimumPaneSize());
223 str = wxGetTextFromUser("Enter minimal size for panes:", "", str, this);
224 if ( str.IsEmpty() )
225 return;
226
227 int minsize = atoi(str);
228 m_splitter->SetMinimumPaneSize(minsize);
229 str.Printf("Min pane size = %d", minsize);
230 SetStatusText(str, 1);
231}
232
233void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event)
234{
235 event.Enable( ( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_HORIZONTAL) ) );
236}
237
238void MyFrame::UpdateUIVertical(wxUpdateUIEvent& event)
239{
240 event.Enable( ( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_VERTICAL) ) );
241}
242
243void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent& event)
244{
245 event.Enable( m_splitter->IsSplit() );
246}
247
248void MyFrame::UpdatePosition()
249{
250 wxString str;
251 str.Printf("Sash position = %d", m_splitter->GetSashPosition());
252 SetStatusText(str);
253}
254
255MyCanvas::MyCanvas(wxWindow* parent, wxWindowID id, int x, int y, int w, int h) :
256 wxScrolledWindow(parent, id, wxPoint(x, y), wxSize(w, h))
257{
258}
259
260MyCanvas::~MyCanvas()
261{
262}
263
264void MyCanvas::OnDraw(wxDC& dc)
265{
266 dc.SetPen(*wxBLACK_PEN);
267 dc.DrawLine(0, 0, 100, 100);
268
269 dc.SetBackgroundMode(wxTRANSPARENT);
270 dc.DrawText("Testing", 50, 50);
271
272 dc.SetPen(*wxRED_PEN);
273 dc.SetBrush(*wxGREEN_BRUSH);
274 dc.DrawRectangle(120, 120, 100, 80);
275}