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