]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/fl/fl_sample3.cpp
Updated list of subprojects.
[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)
0423ae97 6// Created: 24/11/98
03206f17
VS
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
0423ae97 40{
03206f17
VS
41public:
42 bool OnInit(void);
43};
44
45class MyFrame: public wxFrame
46{
47protected:
48 wxFrameLayout* mpLayout;
49 wxWindow* mpClientWnd;
0423ae97 50
03206f17 51 wxButton * my_butt;
0423ae97 52
03206f17
VS
53 wxTextCtrl* CreateTextCtrl( const wxString& value );
54public:
05aa1fc7 55 MyFrame( wxWindow* parent, const wxChar *title );
03206f17 56 ~MyFrame();
0423ae97 57
03206f17
VS
58 void OnLoad( wxCommandEvent& event );
59 void OnStore( wxCommandEvent& event );
60 void OnQuit( wxCommandEvent& event );
0423ae97 61
03206f17
VS
62 void OnButt( wxCommandEvent& event );
63 void OnButt2( wxCommandEvent& event );
c82c42d4 64 bool OnClose(void) { return true; }
0423ae97 65
03206f17
VS
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:
0423ae97 76
05aa1fc7 77 MyFrame *frame = new MyFrame(NULL, _("wxFrameLayout sample"));
0423ae97 78
03206f17 79 wxMenu *file_menu = new wxMenu;
0423ae97 80
05aa1fc7
JS
81 file_menu->Append( ID_LOAD, _("&Load layout") );
82 file_menu->Append( ID_STORE, _("&Store layout") );
03206f17 83 file_menu->AppendSeparator();
0423ae97 84
05aa1fc7 85 file_menu->Append( ID_QUIT, _("E&xit") );
0423ae97 86
03206f17 87 wxMenuBar *menu_bar = new wxMenuBar;
0423ae97 88
05aa1fc7 89 menu_bar->Append(file_menu, _("&File"));
0423ae97 90
d96cdd4a 91#if wxUSE_STATUSBAR
03206f17 92 frame->CreateStatusBar(3);
d96cdd4a 93#endif // wxUSE_STATUSBAR
03206f17 94 frame->SetMenuBar(menu_bar);
0423ae97 95
c82c42d4 96 frame->Show(true);
03206f17 97 SetTopWindow(frame);
0423ae97 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 |
1c067fe3 116 wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX,
05aa1fc7 117 wxT("freimas") )
03206f17 118{
0423ae97
MR
119
120 mpClientWnd = new wxWindow(this, wxID_ANY);
03206f17 121 mpLayout = new wxFrameLayout( this, mpClientWnd );
0423ae97 122
03206f17
VS
123 /// mpLayout->PushDefaultPlugins();
124 /// mpLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for barso
125 /// //mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
0423ae97
MR
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)
0423ae97
MR
133 );
134
135
03206f17 136 // drop-in some bars
0423ae97 137
03206f17
VS
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 143 name += buf;
0423ae97 144
03206f17 145 sizes.mIsFixed = (i !=3); // every fifth bar is not fixed-size
0423ae97 146
05aa1fc7 147 if ( !sizes.mIsFixed ) name += wxT(" (flexible)");
0423ae97 148 // mpLayout->AddBar( CreateTextCtrl(name), // bar window
03206f17 149 if(i != 4 && i!= 5 && i!=11) {
0423ae97
MR
150 mpLayout->AddBar( new wxTextCtrl(this, wxID_ANY, name), // bar window
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
03206f17
VS
156 );
157 } else if(i==4){
0423ae97
MR
158 mpLayout->AddBar( new wxTextCtrl(this, wxID_ANY, name), // bar window
159 cbDimInfo( 100,100, 100,100, 100,100, true, 5, 5),
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
03206f17
VS
164 );
165 } else if(i==5) {
166 my_butt = new wxButton(this, ID_BUTT, name);
0423ae97
MR
167 mpLayout->AddBar( my_butt, // bar window
168 cbDimInfo( 100,100, 200,200, 400,400, true, 5, 5),
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
03206f17
VS
173 );
174 } else if(i==11) {
05aa1fc7 175 mpLayout->AddBar( new wxButton(this, ID_BUTT2, name+wxT("_2")),
0423ae97
MR
176 cbDimInfo( 100,100, 200,200, 400,400, true, 5, 5),
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
03206f17
VS
181 );
182 }
0423ae97 183
03206f17
VS
184 // mpLayout->RecalcLayout(true);
185 // Layout();
186 // Refresh();
187 }
188}
189
190MyFrame::~MyFrame()
191{
192 // layout is not a window, should be released manually
0423ae97 193 if ( mpLayout )
03206f17
VS
194 delete mpLayout;
195}
196
197wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
198{
0423ae97 199 wxTextCtrl* pCtrl = new wxTextCtrl( this, wxID_ANY, value,
03206f17 200 wxPoint(0,0), wxSize(1,1), wxTE_MULTILINE );
0423ae97 201
03206f17 202 pCtrl->SetBackgroundColour( wxColour( 255,255,255 ) );
0423ae97 203
03206f17
VS
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
0423ae97 220
c82c42d4 221 Close(true);
03206f17
VS
222}
223
8552e6f0 224void MyFrame::OnButt( wxCommandEvent& WXUNUSED(event) )
03206f17
VS
225{
226 static int i =0;
0423ae97
MR
227
228 // cbBarInfo* FindBarByName( const wxString& name );
229
03206f17 230 switch(i % 2) {
0423ae97 231 case 0:
03206f17 232 {
05aa1fc7 233 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
0423ae97
MR
234 if(x)
235 mpLayout->InverseVisibility(x);
236 else
03206f17
VS
237 wxBell();
238 break;
239 }
240 case 1:
241 {
05aa1fc7 242 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-6")));
0423ae97 243 if(x)
03206f17 244 {
0423ae97 245 if(i % 4 == 1)
03206f17 246 {
c82c42d4 247 mpLayout->SetBarState(x, wxCBAR_FLOATING, true);
03206f17
VS
248 //mpLayout->RecalcLayout(true);
249 mpLayout->RepositionFloatedBar(x);
0423ae97
MR
250 }
251 else
03206f17 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);
0423ae97
MR
259 }
260 else
03206f17
VS
261 {
262 wxBell();
263 }
0423ae97 264
03206f17
VS
265 break;
266 }
267 }
268 i++;
269}
270
8552e6f0 271void MyFrame::OnButt2( wxCommandEvent& WXUNUSED(event) )
03206f17
VS
272{
273 static int i =0;
0423ae97
MR
274
275 // cbBarInfo* FindBarByName( const wxString& name );
276
03206f17 277 switch(i % 2) {
0423ae97 278 case 0:
03206f17 279 {
05aa1fc7 280 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
0423ae97 281 if(x)
03206f17
VS
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 !!!
0423ae97 291 wxYield(); // HACK !!! needed to resize BEFORE redraw
c82c42d4 292 mpLayout->RefreshNow( true ); // HACK !!! needed to trigger redraw
03206f17 293 }
0423ae97 294 else
03206f17
VS
295 {
296 wxBell();
297 }
298
299 break;
300 }
301 case 1:
302 {
05aa1fc7 303 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
0423ae97 304 if(x)
03206f17 305 {
0423ae97 306 //mpLayout->InverseVisibility(x);
03206f17
VS
307 for(int a=0;a<MAX_BAR_STATES;a++)
308 {
0423ae97 309 // see cbPaneDrawPlugin::OnSizeBarWindow( cbSizeBarWndEvent& event )
03206f17
VS
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 !!!
0423ae97 316 wxYield(); // HACK !!! needed to resize BEFORE redraw
c82c42d4 317 mpLayout->RefreshNow( true ); // HACK !!! needed to trigger redraw
0423ae97
MR
318
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 328 }
0423ae97 329 else
03206f17
VS
330 {
331 wxBell();
332 }
333
334 break;
335 }
336 }
337 i++;
338}