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