]> git.saurik.com Git - wxWidgets.git/blob - utils/framelayout/samples/sample/fl_sample.cpp
Added Aleksandras' framelayout code, with more or less working Linux Makefiles
[wxWidgets.git] / utils / framelayout / samples / sample / fl_sample.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: main.cpp
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: 24/11/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "fl_sample.cpp"
14 #pragma interface "fl_sample.cpp"
15 #endif
16
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WX_PRECOMP
25 #include "wx/wx.h"
26 #endif
27
28 #include "controlbar.h"
29 #include "objstore.h"
30
31 // plugins used
32 #include "barhintspl.h"
33 #include "hintanimpl.h"
34
35 #include "wx/textctrl.h"
36
37 // ADDED by alex (linker complaints...):
38 char wxDummyChar=0;
39
40 #define ID_LOAD 102
41 #define ID_STORE 103
42 #define ID_QUIT 104
43
44 #define LAYOUT_FILE "layouts.dat"
45
46 class MyApp: public wxApp
47 {
48 public:
49 bool OnInit(void);
50 };
51
52 class MyFrame: public wxFrame
53 {
54 protected:
55 wxFrameLayout* mpLayout;
56 wxWindow* mpClientWnd;
57 wxPanel* mpInternalFrm;
58
59 void SerializeMe( wxObjectStorage& store );
60
61 wxTextCtrl* CreateTextCtrl( const wxString& value );
62
63
64 public:
65 MyFrame( wxWindow* parent, char *title );
66 ~MyFrame();
67
68 void OnLoad( wxCommandEvent& event );
69 void OnStore( wxCommandEvent& event );
70 void OnQuit( wxCommandEvent& event );
71
72 bool OnClose(void) { return TRUE; }
73
74 DECLARE_EVENT_TABLE()
75 };
76
77 /***** Implementation for class MyApp *****/
78
79 IMPLEMENT_APP (MyApp)
80
81 bool MyApp::OnInit(void)
82 {
83 // wxWindows boiler-plate:
84
85 MyFrame *frame = new MyFrame(NULL, "wxFrameLayout sample");
86
87 wxMenu *file_menu = new wxMenu;
88
89 file_menu->Append( ID_LOAD, "&Load layout" );
90 file_menu->Append( ID_STORE, "&Store layout" );
91 file_menu->AppendSeparator();
92
93 file_menu->Append( ID_QUIT, "E&xit" );
94
95 wxMenuBar *menu_bar = new wxMenuBar;
96
97 menu_bar->Append(file_menu, "&File");
98
99 frame->CreateStatusBar(3);
100 frame->SetMenuBar(menu_bar);
101
102 frame->Show(TRUE);
103
104 SetTopWindow(frame);
105
106 return TRUE;
107 }
108
109 /***** Immlementation for class MyFrame *****/
110
111 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
112
113 EVT_MENU( ID_LOAD, MyFrame::OnLoad )
114 EVT_MENU( ID_STORE, MyFrame::OnStore )
115 EVT_MENU( ID_QUIT, MyFrame::OnQuit )
116
117 END_EVENT_TABLE()
118
119 MyFrame::MyFrame( wxWindow* parent, char *title )
120
121 : wxFrame( parent, -1, "NewTest-II", wxDefaultPosition,
122 wxSize( 700, 500 ),
123 wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
124 wxTHICK_FRAME | wxSYSTEM_MENU | wxCAPTION,
125 "freimas" )
126 {
127 #ifdef __WXMSW__
128 mpInternalFrm = (wxPanel*)this;
129 #else
130 mpInternalFrm = new wxPanel( this, -1 );
131 #endif
132
133 mpClientWnd = CreateTextCtrl( "Client window" );
134
135 // btw, creation of internal frame is needed for wxGtk version
136 // to act correctly (since menu-bar is a separate window there..)
137
138 mpLayout = new wxFrameLayout( mpInternalFrm, mpClientWnd );
139
140 #ifdef __WXGTK__
141
142 // real-time dosn't work well under wxGtk yet
143 cbCommonPaneProperties props;
144 mpLayout->GetPaneProperties( props );
145
146 props.mRealTimeUpdatesOn = FALSE; // off
147
148 mpLayout->SetPaneProperties( props, wxALL_PANES );
149
150 #endif
151
152 mpLayout->PushDefaultPlugins();
153 mpLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for barso
154 //mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
155
156 cbDimInfo sizes( 80,65, // when docked horizontally
157 80,65, // when docked vertically
158 80,30, // when floated
159 TRUE, // the bar is fixed-size
160 5, // vertical gap (bar border)
161 5 // horizontal gap (bar border)
162 );
163
164 // drop-in 20 bars
165
166 for( int i = 1; i <= 10; ++i )
167 {
168 char buf[4];
169 sprintf( buf, "%d", i );
170 wxString name = wxString("Bar-");
171 name += buf;
172
173 sizes.mIsFixed = i % 5 > 0; // every fifth bar is not fixed-size
174
175 if ( !sizes.mIsFixed ) name += " (flexible)";
176
177 mpLayout->AddBar( CreateTextCtrl(name),// bar window
178 sizes, i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
179 0, // insert into 0th row (vert. position)
180 0, // offset from the start of row (in pixels)
181 name // name to refere in customization pop-ups
182 );
183 }
184 }
185
186 MyFrame::~MyFrame()
187 {
188 // layout is not a window, should be released manually
189
190 if ( mpLayout ) delete mpLayout;
191 }
192
193 wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
194 {
195 wxTextCtrl* pCtrl =
196
197 new wxTextCtrl( mpInternalFrm, -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 if ( !wxFileExists( LAYOUT_FILE ) )
208 {
209 wxMessageBox( "layout data file `layout.dat' not found\n\n store layout first" );
210
211 return;
212 }
213
214 mpLayout->HideBarWindows(); // hide first, to avoid flickered destruction
215 mpLayout->DestroyBarWindows();
216
217 if ( mpClientWnd )
218 {
219 mpClientWnd->Destroy();
220 delete mpLayout;
221
222 mpClientWnd = NULL;
223 }
224
225 wxIOStreamWrapper stm;
226 stm.CreateForInput( LAYOUT_FILE ); // TRUE - create stream for input
227
228 wxObjectStorage store( stm );
229
230 SerializeMe( store );
231
232 mpLayout->Activate();
233 }
234
235 void MyFrame::OnStore( wxCommandEvent& event )
236 {
237 wxIOStreamWrapper stm;
238 stm.CreateForOutput( LAYOUT_FILE ); // FALSE - create stream for output
239
240 wxObjectStorage store( stm );
241
242 SerializeMe( store );
243 }
244
245 void MyFrame::OnQuit( wxCommandEvent& event )
246 {
247 Show( FALSE ); // TRICK:: hide it, to avoid flickered destruction
248
249 Close(TRUE);
250 }
251
252 void MyFrame::SerializeMe( wxObjectStorage& store )
253 {
254 // mark contaienr-frames as not serializable
255
256 store.AddInitialRef( mpInternalFrm );
257 store.AddInitialRef( this );
258
259 // does all the rest for as
260
261 store.XchgObjPtr( (wxObject**) &(mpLayout) );
262 store.XchgObjPtr( (wxObject**) &(mpClientWnd) );
263
264 store.Finalize(); // finish serialization
265 }
266
267 #ifdef __HACK_MY_MSDEV40__
268
269 ////////////// new 2.0-magic (linker errors...) ////////////////
270
271 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
272 {
273 wxCHECK_MSG( m_frameToolBar == NULL, FALSE,
274 "recreating toolbar in wxFrame" );
275
276 wxToolBar* toolBar = OnCreateToolBar(style, id, name);
277 if (toolBar)
278 {
279 SetToolBar(toolBar);
280 PositionToolBar();
281 return toolBar;
282 }
283 else
284 {
285 return NULL;
286 }
287 }
288
289 wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
290 {
291 return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name);
292 }
293
294 #endif