]> git.saurik.com Git - wxWidgets.git/blob - utils/framelayout/samples/test/fl_test.cpp
Added Aleksandras' framelayout code, with more or less working Linux Makefiles
[wxWidgets.git] / utils / framelayout / samples / test / fl_test.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: minimal.cpp
3 // Purpose: Minimal wxWindows 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
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 #ifdef __GNUG__
14 #pragma implementation "minimal.cpp"
15 #pragma interface "minimal.cpp"
16 #endif
17
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
20
21 /*
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25 */
26
27 #ifndef WX_PRECOMP
28 #include "wx/wx.h"
29 #endif
30
31 #include "wx/textctrl.h"
32
33 #include "controlbar.h" // core API
34 #include "fl_test.h"
35
36 // extra plugins
37 #include "barhintspl.h" // beveal for bars with "X"s and grooves
38 #include "rowdragpl.h" // NC-look with dragable rows
39 #include "cbcustom.h" // customization plugin
40 #include "hintanimpl.h"
41
42 // beuty-care
43 #include "gcupdatesmgr.h" // smooth d&d
44 #include "antiflickpl.h" // double-buffered repaint of decorations
45
46 #include "dyntbar.h" // auto-layouting toolbar
47 #include "dyntbarhnd.h" // control-bar dimension handler for it
48
49 // comment it out if it breaks, (this is my workaround for MSDev 4.0 linker)
50
51 char wxDummyChar;
52
53
54 IMPLEMENT_APP (MyApp)
55
56 bool MyApp::OnInit(void)
57 {
58 MyFrame *frame = new MyFrame(NULL);
59
60 frame->SetBackgroundColour( wxColour(192,192,192) );
61
62 wxMenu *file_menu = new wxMenu;
63
64 file_menu->Append( NEW_TEST_LOAD, "&Load layouts" );
65 file_menu->Append( NEW_TEST_SAVE, "&Store layouts" );
66 file_menu->Append( NEW_TEST_EXIT, "E&xit" );
67
68 wxMenuBar *menu_bar = new wxMenuBar;
69
70 menu_bar->Append(file_menu, "&File");
71
72 frame->SetMenuBar(menu_bar);
73
74 frame->CreateStatusBar(3);
75
76 frame->Show(TRUE);
77
78 frame->mpClientWnd->Refresh();
79
80 SetTopWindow(frame);
81
82 return TRUE;
83
84 /*
85 wxMessageBox("Hello, this demo has a bunch of yet-not-fixed-bugs and misssing functionality\n\
86 The ONLY purpose is to demostrate self-layouting toolbars,\n flat-bitmapped-buttons and 2-new FL-plugins\
87 (cbRowDragPlugin & cbBarHintsPlugin)\n\n\
88 BTW, disabled images and label-text are rendered at run-time" );
89 */
90
91
92 return TRUE;
93 }
94
95 /***** Implementation for class MyFrame *****/
96
97 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
98
99 // EVT_CHAR_HOOK(MyFrame::OnKeyDown)
100 // EVT_PAINT( MyFrame::OnPaint )
101 EVT_MENU( NEW_TEST_SAVE, MyFrame::OnSave )
102 EVT_MENU( NEW_TEST_LOAD, MyFrame::OnLoad )
103 EVT_MENU( NEW_TEST_EXIT, MyFrame::OnExit )
104
105 END_EVENT_TABLE()
106
107 void MyFrame::OnLoad( wxCommandEvent& event )
108 {
109 mpLayout->HideBarWindows();
110 mpLayout->DestroyBarWindows();
111 delete mpLayout;
112
113 if ( mpClientWnd )
114 {
115 mpClientWnd->Destroy();
116 mpClientWnd = NULL;
117 }
118
119 mpLayout = NULL;
120
121 wxIOStreamWrapper& stm = *(new wxIOStreamWrapper());
122
123 stm.CreateForInput( "layouts1.dat" );
124
125 mStore.SetDataStream( stm );
126
127 mStore.XchgObjPtr( (wxObject**) &mpLayout );
128
129 mStore.Finalize(); // finish serialization
130
131 mpLayout->Activate();
132 }
133
134 void MyFrame::OnSave( wxCommandEvent& event )
135 {
136 wxIOStreamWrapper& stm = *(new wxIOStreamWrapper());
137
138 stm.CreateForOutput( "layouts1.dat" );
139
140 mStore.SetDataStream( stm );
141
142 mStore.XchgObjPtr( (wxObject**) &mpLayout );
143
144 mStore.Finalize(); // finish serialization
145 }
146
147 void MyFrame::OnExit( wxCommandEvent& event )
148 {
149 Destroy();
150 }
151
152 wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
153 {
154 wxTextCtrl* pCtrl =
155
156 new wxTextCtrl( mpInternalFrm, -1, value,
157 wxDefaultPosition, wxSize(0,0), wxTE_MULTILINE );
158
159 pCtrl->SetBackgroundColour( wxColour( 255,255,255 ) );
160
161 return pCtrl;
162 }
163
164 MyFrame::MyFrame(wxFrame *frame)
165
166 : wxFrame( frame, -1, "wxWindows 2.0 wxFrameLayout Test Application", wxDefaultPosition,
167 wxSize( 700, 500 ),
168 wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
169 wxTHICK_FRAME | wxSYSTEM_MENU | wxCAPTION,
170 "freimas" )
171 {
172 #ifdef __WXMSW__
173 mpInternalFrm = (wxPanel*)this;
174 #else
175 mpInternalFrm = new wxPanel( this, -1 );
176 #endif
177
178
179 mpClientWnd = CreateTextCtrl( "Client window" );
180
181 mStore.AddInitialRef( this );
182 mStore.AddInitialRef( mpInternalFrm );
183 //mStore.AddInitialRef( mpClientWnd );
184
185 mpLayout = new wxFrameLayout( mpInternalFrm, mpClientWnd );
186
187
188 #ifdef __WXGTK__
189
190 cbCommonPaneProperties props;
191 mpLayout->GetPaneProperties( props );
192
193 props.mRealTimeUpdatesOn = FALSE; // real-time OFF!!!
194
195 mpLayout->SetPaneProperties( props, wxALL_PANES );
196
197 #endif
198
199 mpLayout->SetUpdatesManager( new cbGCUpdatesMgr() );
200
201 // this is now default...
202 //mpLayout->SetMargins( 1,1,1,1 ); // gaps for vertical/horizontal/right/left panes
203
204 // setup plugins for testing
205
206 mpLayout->PushDefaultPlugins();
207
208 mpLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for bars
209
210 mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
211 mpLayout->AddPlugin( CLASSINFO( cbRowDragPlugin ) );
212 mpLayout->AddPlugin( CLASSINFO( cbAntiflickerPlugin ) );
213 mpLayout->AddPlugin( CLASSINFO( cbSimpleCustomizationPlugin ) );
214
215 // drop in some bars
216
217 cbDimInfo sizes0(200,45, // when docked horizontally
218 200,85, // when docked vertically
219 175,35, // when floated
220 FALSE, // the bar is not fixed-size
221 4, // vertical gap (bar border)
222 4 // horizontal gap (bar border)
223 );
224
225 cbDimInfo sizes1(150,35, // when docked horizontally
226 150,85, // when docked vertically
227 175,35, // when floated
228 TRUE, // the bar is not fixed-size
229 4, // vertical gap (bar border)
230 4 // horizontal gap (bar border)
231 );
232
233 cbDimInfo sizes2(175,45, // when docked horizontally
234 175,37, // when docked vertically
235 170,35, // when floated
236 TRUE, // the bar is not fixed-size
237 4, // vertical gap (bar border)
238 4, // horizontal gap (bar border)
239 new cbDynToolBarDimHandler()
240 );
241
242 mpLayout->AddBar( CreateTextCtrl("Hello"), // bar window
243 sizes0, wxTOP, // alignment ( 0-top,1-bottom, etc)
244 0, // insert into 0th row (vert. position)
245 0, // offset from the start of row (in pixels)
246 "InfoViewer1", // name to refere in customization pop-ups
247 TRUE
248 );
249
250 mpLayout->AddBar( CreateTextCtrl("Bye"), // bar window
251 sizes0, wxTOP, // alignment ( 0-top,1-bottom, etc)
252 1, // insert into 0th row (vert. position)
253 0, // offset from the start of row (in pixels)
254 "InfoViewer2", // name to refere in customization pop-ups
255 TRUE
256 );
257
258 mpLayout->AddBar( CreateTextCtrl("Fixed0"), // bar window
259 sizes1, wxTOP, // alignment ( 0-top,1-bottom, etc)
260 0, // insert into 0th row (vert. position)
261 0, // offset from the start of row (in pixels)
262 "ToolBar1", // name to refere in customization pop-ups
263 TRUE
264 );
265
266 wxDynamicToolBar* pToolBar = new wxDynamicToolBar();
267
268 pToolBar->Create( mpInternalFrm, -1 );
269
270 // 1001-1006 ids of command events fired by added tool-buttons
271
272 pToolBar->AddTool( 1001, "new.bmp" );
273 pToolBar->AddTool( 1002, "open.bmp" );
274 pToolBar->AddTool( 1003, "save.bmp" );
275
276 pToolBar->AddTool( 1004, "cut.bmp" );
277 pToolBar->AddTool( 1005, "copy.bmp" );
278 pToolBar->AddTool( 1006, "paste.bmp" );
279
280
281 mpLayout->AddBar( pToolBar, // bar window (can be NULL)
282 sizes2, wxTOP, // alignment ( 0-top,1-bottom, etc)
283 0, // insert into 0th row (vert. position)
284 0, // offset from the start of row (in pixels)
285 "ToolBar2", // name to refere in customization pop-ups
286 FALSE
287 );
288
289 mpLayout->EnableFloating( TRUE ); // off, thinking bout wxGtk...
290 }
291
292 MyFrame::~MyFrame()
293 {
294 if ( mpLayout) delete mpLayout; // should be destroyed manually
295 }
296
297 #ifdef __HACK_MY_MSDEV40__
298
299 ////////////// new 2.0-magic (linker errors...) ////////////////
300
301 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
302 {
303 wxCHECK_MSG( m_frameToolBar == NULL, FALSE,
304 "recreating toolbar in wxFrame" );
305
306 wxToolBar* toolBar = OnCreateToolBar(style, id, name);
307 if (toolBar)
308 {
309 SetToolBar(toolBar);
310 PositionToolBar();
311 return toolBar;
312 }
313 else
314 {
315 return NULL;
316 }
317 }
318
319 wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
320 {
321 return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name);
322 }
323
324 #endif