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