]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/fl/fl_sample3/fl_sample3.cpp
added wxGetTopLevelParent()
[wxWidgets.git] / contrib / samples / fl / fl_sample3 / 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, char *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 // wxWindows 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 frame->CreateStatusBar(3);
92 frame->SetMenuBar(menu_bar);
93
94 frame->Show(TRUE);
95 SetTopWindow(frame);
96
97 return TRUE;
98 }
99
100 /***** Immlementation for class MyFrame *****/
101
102 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
103 EVT_MENU( ID_LOAD, MyFrame::OnLoad )
104 EVT_MENU( ID_STORE, MyFrame::OnStore )
105 EVT_MENU( ID_QUIT, MyFrame::OnQuit )
106 EVT_BUTTON( ID_BUTT, MyFrame::OnButt )
107 EVT_BUTTON( ID_BUTT2, MyFrame::OnButt2 )
108 END_EVENT_TABLE()
109
110 MyFrame::MyFrame( wxWindow* parent, char *title )
111 : wxFrame( parent, -1, "NewTest-II", wxDefaultPosition,
112 wxSize( 700, 500 ),
113 wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
114 wxTHICK_FRAME | wxSYSTEM_MENU | wxCAPTION,
115 "freimas" )
116 {
117
118 mpClientWnd = new wxWindow(this, -1);
119 mpLayout = new wxFrameLayout( this, mpClientWnd );
120
121 /// mpLayout->PushDefaultPlugins();
122 /// mpLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for barso
123 /// //mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
124
125 cbDimInfo sizes( 80,65, // when docked horizontally
126 80,165, // when docked vertically
127 180,30, // when floated
128 TRUE, // the bar is fixed-size
129 5, // vertical gap (bar border)
130 5 // horizontal gap (bar border)
131 );
132
133
134 // drop-in some bars
135
136 for( int i = 1; i <= 11; ++i )
137 {
138 char buf[4];
139 sprintf( buf, "%d", i );
140 wxString name = wxString("Bar-");
141 name += buf;
142
143 sizes.mIsFixed = (i !=3); // every fifth bar is not fixed-size
144
145 if ( !sizes.mIsFixed ) name += " (flexible)";
146 // mpLayout->AddBar( CreateTextCtrl(name),// bar window
147 if(i != 4 && i!= 5 && i!=11) {
148 mpLayout->AddBar( new wxTextCtrl(this, -1, name),// bar window
149 sizes,
150 i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
151 0, // insert into 0th row (vert. position)
152 0, // offset from the start of row (in pixels)
153 name // name to refere in customization pop-ups
154 );
155 } else if(i==4){
156 mpLayout->AddBar( new wxTextCtrl(this, -1, name),// bar window
157 cbDimInfo( 100,100, 100,100, 100,100, TRUE, 5, 5),
158 i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
159 0, // insert into 0th row (vert. position)
160 0, // offset from the start of row (in pixels)
161 name // name to refere in customization pop-ups
162 );
163 } else if(i==5) {
164 my_butt = new wxButton(this, ID_BUTT, name);
165 mpLayout->AddBar( my_butt,// bar window
166 cbDimInfo( 100,100, 200,200, 400,400, TRUE, 5, 5),
167 i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
168 0, // insert into 0th row (vert. position)
169 0, // offset from the start of row (in pixels)
170 name // name to refere in customization pop-ups
171 );
172 } else if(i==11) {
173 mpLayout->AddBar( new wxButton(this, ID_BUTT2, name+"_2"),
174 cbDimInfo( 100,100, 200,200, 400,400, TRUE, 5, 5),
175 i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
176 0, // insert into 0th row (vert. position)
177 0, // offset from the start of row (in pixels)
178 name // name to refere in customization pop-ups
179 );
180 }
181
182 // mpLayout->RecalcLayout(true);
183 // Layout();
184 // Refresh();
185 }
186 }
187
188 MyFrame::~MyFrame()
189 {
190 // layout is not a window, should be released manually
191 if ( mpLayout )
192 delete mpLayout;
193 }
194
195 wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
196 {
197 wxTextCtrl* pCtrl = new wxTextCtrl( this, -1, value,
198 wxPoint(0,0), wxSize(1,1), wxTE_MULTILINE );
199
200 pCtrl->SetBackgroundColour( wxColour( 255,255,255 ) );
201
202 return pCtrl;
203 }
204
205 void MyFrame::OnLoad( wxCommandEvent& event )
206 {
207 wxMessageBox("Hey - you found a BIG question-mark !!");
208 }
209
210 void MyFrame::OnStore( wxCommandEvent& event )
211 {
212 wxMessageBox("Hey - you found another BIG question-mark !!");
213 }
214
215 void MyFrame::OnQuit( wxCommandEvent& event )
216 {
217 Show( FALSE ); // TRICK:: hide it, to avoid flickered destruction
218
219 Close(TRUE);
220 }
221
222 void MyFrame::OnButt( wxCommandEvent& event )
223 {
224 static int i =0;
225
226 // cbBarInfo* FindBarByName( const wxString& name );
227
228 switch(i % 2) {
229 case 0:
230 {
231 cbBarInfo* x = mpLayout->FindBarByName(wxString("Bar-1"));
232 if(x)
233 mpLayout->InverseVisibility(x);
234 else
235 wxBell();
236 break;
237 }
238 case 1:
239 {
240 cbBarInfo* x = mpLayout->FindBarByName(wxString("Bar-6"));
241 if(x)
242 {
243 if(i % 4 == 1)
244 {
245 mpLayout->SetBarState(x, wxCBAR_FLOATING, TRUE);
246 //mpLayout->RecalcLayout(true);
247 mpLayout->RepositionFloatedBar(x);
248 }
249 else
250 {
251 mpLayout->SetBarState(x, 0, TRUE);
252 //mpLayout->RecalcLayout(true);
253 //mpLayout->RepositionFloatedBar(x);
254 }
255 // // // x->mState = wxCBAR_FLOATING;
256 // // // mpLayout->ApplyBarProperties(x);
257 }
258 else
259 {
260 wxBell();
261 }
262
263 break;
264 }
265 }
266 i++;
267 }
268
269 void MyFrame::OnButt2( wxCommandEvent& event )
270 {
271 static int i =0;
272
273 // cbBarInfo* FindBarByName( const wxString& name );
274
275 switch(i % 2) {
276 case 0:
277 {
278 cbBarInfo* x = mpLayout->FindBarByName(wxString("Bar-1"));
279 if(x)
280 {
281 for(int a=0;a<MAX_BAR_STATES;a++)
282 {
283 x->mDimInfo.mSizes[a].x = 200;
284 x->mDimInfo.mSizes[a].y = 200;
285 }
286 x->mpBarWnd->SetSize(200,200);
287 mpLayout->SetBarState(x, wxCBAR_FLOATING, TRUE); // HACK !!!
288 mpLayout->SetBarState(x, 0, TRUE); // HACK !!!
289 wxYield(); // HACK !!! needed to resize BEFORE redraw
290 mpLayout->RefreshNow( TRUE ); // HACK !!! needed to trigger redraw
291 }
292 else
293 {
294 wxBell();
295 }
296
297 break;
298 }
299 case 1:
300 {
301 cbBarInfo* x = mpLayout->FindBarByName(wxString("Bar-1"));
302 if(x)
303 {
304 //mpLayout->InverseVisibility(x);
305 for(int a=0;a<MAX_BAR_STATES;a++)
306 {
307 // see cbPaneDrawPlugin::OnSizeBarWindow( cbSizeBarWndEvent& event )
308 x->mDimInfo.mSizes[a].x = 10 + 2 + 2*x->mDimInfo.mHorizGap;
309 x->mDimInfo.mSizes[a].y = 10 + 2 + 2*x->mDimInfo.mVertGap;
310 }
311 x->mpBarWnd->SetSize(10,10);
312 mpLayout->SetBarState(x, wxCBAR_FLOATING, TRUE); // HACK !!!
313 mpLayout->SetBarState(x, 0, TRUE); // HACK !!!
314 wxYield(); // HACK !!! needed to resize BEFORE redraw
315 mpLayout->RefreshNow( TRUE ); // HACK !!! needed to trigger redraw
316
317 // // mpLayout->SetBarState(x, wxCBAR_FLOATING, TRUE);
318 // // mpLayout->RecalcLayout(true);
319 // // // mpLayout->RepositionFloatedBar(x);
320 // // mpLayout->RecalcLayout(true);
321 // // mpLayout->RepositionFloatedBar(x);
322 // // mpLayout->SetBarState(x, 0, TRUE);
323 // // wxYield();
324 // // mpLayout->RefreshNow( TRUE );
325 // // mpLayout->RecalcLayout(true);
326 }
327 else
328 {
329 wxBell();
330 }
331
332 break;
333 }
334 }
335 i++;
336 }
337