]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/fl/fl_sample3.cpp
wxString and wxChar* access for file functions. Source cleaning.
[wxWidgets.git] / contrib / samples / fl / fl_sample3.cpp
CommitLineData
03206f17
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: fl_sample3.cpp
3// Purpose: Contrib. demo
4// Author: Aleksandras Gluchovas
5// Modified by: Sebastian Haase (June 21, 2001)
6// Created: 24/11/98
7// RCS-ID: $Id$
8// Copyright: (c) Aleksandras Gluchovas
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/textctrl.h"
24
25// fl headers
26#include "wx/fl/controlbar.h"
27
28// plugins used
29#include "wx/fl/barhintspl.h"
30#include "wx/fl/hintanimpl.h"
31
32#define ID_LOAD 102
33#define ID_STORE 103
34#define ID_QUIT 104
35
36#define ID_BUTT 145
37#define ID_BUTT2 146
38
39class MyApp: public wxApp
40{
41public:
42 bool OnInit(void);
43};
44
45class MyFrame: public wxFrame
46{
47protected:
48 wxFrameLayout* mpLayout;
49 wxWindow* mpClientWnd;
50
51 wxButton * my_butt;
52
53 wxTextCtrl* CreateTextCtrl( const wxString& value );
54public:
05aa1fc7 55 MyFrame( wxWindow* parent, const wxChar *title );
03206f17
VS
56 ~MyFrame();
57
58 void OnLoad( wxCommandEvent& event );
59 void OnStore( wxCommandEvent& event );
60 void OnQuit( wxCommandEvent& event );
61
62 void OnButt( wxCommandEvent& event );
63 void OnButt2( wxCommandEvent& event );
c82c42d4 64 bool OnClose(void) { return true; }
03206f17
VS
65
66 DECLARE_EVENT_TABLE()
67};
68
69/***** Implementation for class MyApp *****/
70
71IMPLEMENT_APP (MyApp)
72
73bool MyApp::OnInit(void)
74{
be5a51fb 75 // wxWidgets boiler-plate:
03206f17 76
05aa1fc7 77 MyFrame *frame = new MyFrame(NULL, _("wxFrameLayout sample"));
03206f17
VS
78
79 wxMenu *file_menu = new wxMenu;
80
05aa1fc7
JS
81 file_menu->Append( ID_LOAD, _("&Load layout") );
82 file_menu->Append( ID_STORE, _("&Store layout") );
03206f17
VS
83 file_menu->AppendSeparator();
84
05aa1fc7 85 file_menu->Append( ID_QUIT, _("E&xit") );
03206f17
VS
86
87 wxMenuBar *menu_bar = new wxMenuBar;
88
05aa1fc7 89 menu_bar->Append(file_menu, _("&File"));
03206f17 90
d96cdd4a 91#if wxUSE_STATUSBAR
03206f17 92 frame->CreateStatusBar(3);
d96cdd4a 93#endif // wxUSE_STATUSBAR
03206f17
VS
94 frame->SetMenuBar(menu_bar);
95
c82c42d4 96 frame->Show(true);
03206f17
VS
97 SetTopWindow(frame);
98
c82c42d4 99 return true;
03206f17
VS
100}
101
102/***** Immlementation for class MyFrame *****/
103
104BEGIN_EVENT_TABLE(MyFrame, wxFrame)
105 EVT_MENU( ID_LOAD, MyFrame::OnLoad )
106 EVT_MENU( ID_STORE, MyFrame::OnStore )
107 EVT_MENU( ID_QUIT, MyFrame::OnQuit )
108 EVT_BUTTON( ID_BUTT, MyFrame::OnButt )
109 EVT_BUTTON( ID_BUTT2, MyFrame::OnButt2 )
110END_EVENT_TABLE()
111
05aa1fc7 112MyFrame::MyFrame( wxWindow* parent, const wxChar *title )
c82c42d4 113 : wxFrame( parent, wxID_ANY, title, wxDefaultPosition,
03206f17
VS
114 wxSize( 700, 500 ),
115 wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
116 wxTHICK_FRAME | wxSYSTEM_MENU | wxCAPTION,
05aa1fc7 117 wxT("freimas") )
03206f17
VS
118{
119
c82c42d4 120 mpClientWnd = new wxWindow(this, wxID_ANY);
03206f17
VS
121 mpLayout = new wxFrameLayout( this, mpClientWnd );
122
123 /// mpLayout->PushDefaultPlugins();
124 /// mpLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for barso
125 /// //mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
126
127 cbDimInfo sizes( 80,65, // when docked horizontally
128 80,165, // when docked vertically
129 180,30, // when floated
c82c42d4 130 true, // the bar is fixed-size
03206f17
VS
131 5, // vertical gap (bar border)
132 5 // horizontal gap (bar border)
133 );
134
135
136 // drop-in some bars
137
138 for( int i = 1; i <= 11; ++i )
139 {
05aa1fc7
JS
140 wxChar buf[4];
141 wxSprintf( buf, wxT("%d"), i );
142 wxString name = wxString(wxT("Bar-"));
03206f17
VS
143 name += buf;
144
145 sizes.mIsFixed = (i !=3); // every fifth bar is not fixed-size
146
05aa1fc7 147 if ( !sizes.mIsFixed ) name += wxT(" (flexible)");
03206f17
VS
148 // mpLayout->AddBar( CreateTextCtrl(name),// bar window
149 if(i != 4 && i!= 5 && i!=11) {
c82c42d4 150 mpLayout->AddBar( new wxTextCtrl(this, wxID_ANY, name),// bar window
03206f17
VS
151 sizes,
152 i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
153 0, // insert into 0th row (vert. position)
154 0, // offset from the start of row (in pixels)
155 name // name to refere in customization pop-ups
156 );
157 } else if(i==4){
c82c42d4
WS
158 mpLayout->AddBar( new wxTextCtrl(this, wxID_ANY, name),// bar window
159 cbDimInfo( 100,100, 100,100, 100,100, true, 5, 5),
03206f17
VS
160 i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
161 0, // insert into 0th row (vert. position)
162 0, // offset from the start of row (in pixels)
163 name // name to refere in customization pop-ups
164 );
165 } else if(i==5) {
166 my_butt = new wxButton(this, ID_BUTT, name);
167 mpLayout->AddBar( my_butt,// bar window
c82c42d4 168 cbDimInfo( 100,100, 200,200, 400,400, true, 5, 5),
03206f17
VS
169 i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
170 0, // insert into 0th row (vert. position)
171 0, // offset from the start of row (in pixels)
172 name // name to refere in customization pop-ups
173 );
174 } else if(i==11) {
05aa1fc7 175 mpLayout->AddBar( new wxButton(this, ID_BUTT2, name+wxT("_2")),
c82c42d4 176 cbDimInfo( 100,100, 200,200, 400,400, true, 5, 5),
03206f17
VS
177 i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
178 0, // insert into 0th row (vert. position)
179 0, // offset from the start of row (in pixels)
180 name // name to refere in customization pop-ups
181 );
182 }
183
184 // mpLayout->RecalcLayout(true);
185 // Layout();
186 // Refresh();
187 }
188}
189
190MyFrame::~MyFrame()
191{
192 // layout is not a window, should be released manually
193 if ( mpLayout )
194 delete mpLayout;
195}
196
197wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
198{
c82c42d4 199 wxTextCtrl* pCtrl = new wxTextCtrl( this, wxID_ANY, value,
03206f17
VS
200 wxPoint(0,0), wxSize(1,1), wxTE_MULTILINE );
201
202 pCtrl->SetBackgroundColour( wxColour( 255,255,255 ) );
203
204 return pCtrl;
205}
206
8552e6f0 207void MyFrame::OnLoad( wxCommandEvent& WXUNUSED(event) )
03206f17 208{
05aa1fc7 209 wxMessageBox(_("Hey - you found a BIG question-mark !!"));
03206f17
VS
210}
211
8552e6f0 212void MyFrame::OnStore( wxCommandEvent& WXUNUSED(event) )
03206f17 213{
05aa1fc7 214 wxMessageBox(_("Hey - you found another BIG question-mark !!"));
03206f17
VS
215}
216
8552e6f0 217void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
03206f17 218{
c82c42d4 219 Show( false ); // TRICK:: hide it, to avoid flickered destruction
03206f17 220
c82c42d4 221 Close(true);
03206f17
VS
222}
223
8552e6f0 224void MyFrame::OnButt( wxCommandEvent& WXUNUSED(event) )
03206f17
VS
225{
226 static int i =0;
227
228 // cbBarInfo* FindBarByName( const wxString& name );
229
230 switch(i % 2) {
231 case 0:
232 {
05aa1fc7 233 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
03206f17
VS
234 if(x)
235 mpLayout->InverseVisibility(x);
236 else
237 wxBell();
238 break;
239 }
240 case 1:
241 {
05aa1fc7 242 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-6")));
03206f17
VS
243 if(x)
244 {
245 if(i % 4 == 1)
246 {
c82c42d4 247 mpLayout->SetBarState(x, wxCBAR_FLOATING, true);
03206f17
VS
248 //mpLayout->RecalcLayout(true);
249 mpLayout->RepositionFloatedBar(x);
250 }
251 else
252 {
c82c42d4 253 mpLayout->SetBarState(x, 0, true);
03206f17
VS
254 //mpLayout->RecalcLayout(true);
255 //mpLayout->RepositionFloatedBar(x);
256 }
c82c42d4
WS
257 // // // x->mState = wxCBAR_FLOATING;
258 // // // mpLayout->ApplyBarProperties(x);
03206f17
VS
259 }
260 else
261 {
262 wxBell();
263 }
264
265 break;
266 }
267 }
268 i++;
269}
270
8552e6f0 271void MyFrame::OnButt2( wxCommandEvent& WXUNUSED(event) )
03206f17
VS
272{
273 static int i =0;
274
275 // cbBarInfo* FindBarByName( const wxString& name );
276
277 switch(i % 2) {
278 case 0:
279 {
05aa1fc7 280 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
03206f17
VS
281 if(x)
282 {
283 for(int a=0;a<MAX_BAR_STATES;a++)
284 {
285 x->mDimInfo.mSizes[a].x = 200;
286 x->mDimInfo.mSizes[a].y = 200;
287 }
288 x->mpBarWnd->SetSize(200,200);
c82c42d4
WS
289 mpLayout->SetBarState(x, wxCBAR_FLOATING, true); // HACK !!!
290 mpLayout->SetBarState(x, 0, true); // HACK !!!
03206f17 291 wxYield(); // HACK !!! needed to resize BEFORE redraw
c82c42d4 292 mpLayout->RefreshNow( true ); // HACK !!! needed to trigger redraw
03206f17
VS
293 }
294 else
295 {
296 wxBell();
297 }
298
299 break;
300 }
301 case 1:
302 {
05aa1fc7 303 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
03206f17
VS
304 if(x)
305 {
306 //mpLayout->InverseVisibility(x);
307 for(int a=0;a<MAX_BAR_STATES;a++)
308 {
309 // see cbPaneDrawPlugin::OnSizeBarWindow( cbSizeBarWndEvent& event )
310 x->mDimInfo.mSizes[a].x = 10 + 2 + 2*x->mDimInfo.mHorizGap;
311 x->mDimInfo.mSizes[a].y = 10 + 2 + 2*x->mDimInfo.mVertGap;
312 }
313 x->mpBarWnd->SetSize(10,10);
c82c42d4
WS
314 mpLayout->SetBarState(x, wxCBAR_FLOATING, true); // HACK !!!
315 mpLayout->SetBarState(x, 0, true); // HACK !!!
03206f17 316 wxYield(); // HACK !!! needed to resize BEFORE redraw
c82c42d4 317 mpLayout->RefreshNow( true ); // HACK !!! needed to trigger redraw
03206f17 318
c82c42d4
WS
319 // // mpLayout->SetBarState(x, wxCBAR_FLOATING, true);
320 // // mpLayout->RecalcLayout(true);
321 // // mpLayout->RepositionFloatedBar(x);
322 // // mpLayout->RecalcLayout(true);
323 // // mpLayout->RepositionFloatedBar(x);
324 // // mpLayout->SetBarState(x, 0, true);
325 // // wxYield();
326 // // mpLayout->RefreshNow( true );
327 // // mpLayout->RecalcLayout(true);
03206f17
VS
328 }
329 else
330 {
331 wxBell();
332 }
333
334 break;
335 }
336 }
337 i++;
338}
339