]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/fl/fl_sample3.cpp
use given position for page insertion instead of trying to find the page to insert...
[wxWidgets.git] / contrib / samples / fl / fl_sample3.cpp
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
39 class MyApp: public wxApp
40 {
41 public:
42 bool OnInit(void);
43 };
44
45 class MyFrame: public wxFrame
46 {
47 protected:
48 wxFrameLayout* mpLayout;
49 wxWindow* mpClientWnd;
50
51 wxButton * my_butt;
52
53 wxTextCtrl* CreateTextCtrl( const wxString& value );
54 public:
55 MyFrame( wxWindow* parent, const wxChar *title );
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 );
64 bool OnClose(void) { return true; }
65
66 DECLARE_EVENT_TABLE()
67 };
68
69 /***** Implementation for class MyApp *****/
70
71 IMPLEMENT_APP (MyApp)
72
73 bool MyApp::OnInit(void)
74 {
75 // wxWidgets boiler-plate:
76
77 MyFrame *frame = new MyFrame(NULL, _("wxFrameLayout sample"));
78
79 wxMenu *file_menu = new wxMenu;
80
81 file_menu->Append( ID_LOAD, _("&Load layout") );
82 file_menu->Append( ID_STORE, _("&Store layout") );
83 file_menu->AppendSeparator();
84
85 file_menu->Append( ID_QUIT, _("E&xit") );
86
87 wxMenuBar *menu_bar = new wxMenuBar;
88
89 menu_bar->Append(file_menu, _("&File"));
90
91 #if wxUSE_STATUSBAR
92 frame->CreateStatusBar(3);
93 #endif // wxUSE_STATUSBAR
94 frame->SetMenuBar(menu_bar);
95
96 frame->Show(true);
97 SetTopWindow(frame);
98
99 return true;
100 }
101
102 /***** Immlementation for class MyFrame *****/
103
104 BEGIN_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 )
110 END_EVENT_TABLE()
111
112 MyFrame::MyFrame( wxWindow* parent, const wxChar *title )
113 : wxFrame( parent, wxID_ANY, title, wxDefaultPosition,
114 wxSize( 700, 500 ),
115 wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
116 wxTHICK_FRAME | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX,
117 wxT("freimas") )
118 {
119
120 mpClientWnd = new wxWindow(this, wxID_ANY);
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
130 true, // the bar is fixed-size
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 {
140 wxChar buf[4];
141 wxSprintf( buf, wxT("%d"), i );
142 wxString name = wxString(wxT("Bar-"));
143 name += buf;
144
145 sizes.mIsFixed = (i !=3); // every fifth bar is not fixed-size
146
147 if ( !sizes.mIsFixed ) name += wxT(" (flexible)");
148 // mpLayout->AddBar( CreateTextCtrl(name), // bar window
149 if(i != 4 && i!= 5 && i!=11) {
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
156 );
157 } else if(i==4){
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
164 );
165 } else if(i==5) {
166 my_butt = new wxButton(this, ID_BUTT, name);
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
173 );
174 } else if(i==11) {
175 mpLayout->AddBar( new wxButton(this, ID_BUTT2, name+wxT("_2")),
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
181 );
182 }
183
184 // mpLayout->RecalcLayout(true);
185 // Layout();
186 // Refresh();
187 }
188 }
189
190 MyFrame::~MyFrame()
191 {
192 // layout is not a window, should be released manually
193 if ( mpLayout )
194 delete mpLayout;
195 }
196
197 wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
198 {
199 wxTextCtrl* pCtrl = new wxTextCtrl( this, wxID_ANY, value,
200 wxPoint(0,0), wxSize(1,1), wxTE_MULTILINE );
201
202 pCtrl->SetBackgroundColour( wxColour( 255,255,255 ) );
203
204 return pCtrl;
205 }
206
207 void MyFrame::OnLoad( wxCommandEvent& WXUNUSED(event) )
208 {
209 wxMessageBox(_("Hey - you found a BIG question-mark !!"));
210 }
211
212 void MyFrame::OnStore( wxCommandEvent& WXUNUSED(event) )
213 {
214 wxMessageBox(_("Hey - you found another BIG question-mark !!"));
215 }
216
217 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
218 {
219 Show( false ); // TRICK:: hide it, to avoid flickered destruction
220
221 Close(true);
222 }
223
224 void MyFrame::OnButt( wxCommandEvent& WXUNUSED(event) )
225 {
226 static int i =0;
227
228 // cbBarInfo* FindBarByName( const wxString& name );
229
230 switch(i % 2) {
231 case 0:
232 {
233 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
234 if(x)
235 mpLayout->InverseVisibility(x);
236 else
237 wxBell();
238 break;
239 }
240 case 1:
241 {
242 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-6")));
243 if(x)
244 {
245 if(i % 4 == 1)
246 {
247 mpLayout->SetBarState(x, wxCBAR_FLOATING, true);
248 //mpLayout->RecalcLayout(true);
249 mpLayout->RepositionFloatedBar(x);
250 }
251 else
252 {
253 mpLayout->SetBarState(x, 0, true);
254 //mpLayout->RecalcLayout(true);
255 //mpLayout->RepositionFloatedBar(x);
256 }
257 // // // x->mState = wxCBAR_FLOATING;
258 // // // mpLayout->ApplyBarProperties(x);
259 }
260 else
261 {
262 wxBell();
263 }
264
265 break;
266 }
267 }
268 i++;
269 }
270
271 void MyFrame::OnButt2( wxCommandEvent& WXUNUSED(event) )
272 {
273 static int i =0;
274
275 // cbBarInfo* FindBarByName( const wxString& name );
276
277 switch(i % 2) {
278 case 0:
279 {
280 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
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);
289 mpLayout->SetBarState(x, wxCBAR_FLOATING, true); // HACK !!!
290 mpLayout->SetBarState(x, 0, true); // HACK !!!
291 wxYield(); // HACK !!! needed to resize BEFORE redraw
292 mpLayout->RefreshNow( true ); // HACK !!! needed to trigger redraw
293 }
294 else
295 {
296 wxBell();
297 }
298
299 break;
300 }
301 case 1:
302 {
303 cbBarInfo* x = mpLayout->FindBarByName(wxString(wxT("Bar-1")));
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);
314 mpLayout->SetBarState(x, wxCBAR_FLOATING, true); // HACK !!!
315 mpLayout->SetBarState(x, 0, true); // HACK !!!
316 wxYield(); // HACK !!! needed to resize BEFORE redraw
317 mpLayout->RefreshNow( true ); // HACK !!! needed to trigger redraw
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);
328 }
329 else
330 {
331 wxBell();
332 }
333
334 break;
335 }
336 }
337 i++;
338 }
339