]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/fl/frmview.cpp
wxUSE_STL fixes.
[wxWidgets.git] / contrib / src / fl / frmview.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: frmview.cpp
3 // Purpose: wxFrameView implementation. NOT USED IN FL.
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: 02/01/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "frmview.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/fl/frmview.h"
28 #include "wx/utils.h"
29
30 /***** Implementation for class wxFrameView *****/
31
32 BEGIN_EVENT_TABLE( wxFrameView, wxEvtHandler )
33
34 EVT_IDLE( wxFrameView::OnIdle )
35
36 END_EVENT_TABLE()
37
38 void wxFrameView::OnIdle( wxIdleEvent& event)
39 {
40 event.Skip();
41
42 if ( mDoToolUpdates )
43 {
44 // TBD::
45 }
46 }
47
48 /*** public methods ***/
49
50 wxFrameView::wxFrameView()
51
52 : mpLayout( NULL ),
53 mpFrameMgr( NULL )
54 {}
55
56 wxFrameView::~wxFrameView()
57 {
58 if ( mpLayout ) delete mpLayout;
59 }
60
61 wxFrame* wxFrameView::GetParentFrame()
62 {
63 return mpFrameMgr->GetParentFrame();
64 }
65
66 wxWindow* wxFrameView::GetClientWindow()
67 {
68 return mpFrameMgr->GetClientWindow();
69 }
70
71 void wxFrameView::Activate()
72 {
73 mpFrameMgr->ActivateView( this );
74 }
75
76 void wxFrameView::Deactivate()
77 {
78 mpFrameMgr->DeactivateCurrentView();
79 }
80
81 void wxFrameView::CreateLayout()
82 {
83 mpLayout = new wxFrameLayout( GetParentFrame(), mpFrameMgr->GetClientWindow(), false );
84 }
85
86 wxFrameLayout* wxFrameView::GetLayout()
87 {
88 return mpLayout;
89 }
90
91 void wxFrameView::SetToolUpdates( bool doToolUpdates )
92 {
93 mDoToolUpdates = doToolUpdates;
94 }
95
96 void wxFrameView::SetLayout( wxFrameLayout* pLayout )
97 {
98 if ( mpLayout ) delete mpLayout;
99
100 mpLayout = pLayout;
101 }
102
103 wxFrameManager& wxFrameView::GetFrameManager()
104 {
105 return *mpFrameMgr;
106 }
107
108 void wxFrameView::RegisterMenu( const wxString& topMenuName )
109 {
110 mTopMenus.Add( topMenuName );
111 }
112
113 #if 0
114
115 /***** Implementation for class wxFrameViewSerializer *****/
116
117 // NOTE:: currently "stipple" property of the brush is not serialized
118
119 class wxFrameViewSerializer : public wxEvtHandlerSerializer
120 {
121 DECLARE_SERIALIZER_CLASS( wxFrameViewSerializer );
122
123 static void Serialize( wxObject* pObj, wxObjectStorage& store );
124 };
125
126 IMPLEMENT_SERIALIZER_CLASS( wxFrameView,
127 wxFrameViewSerializer,
128 wxFrameViewSerializer::Serialize,
129 NO_CLASS_INIT )
130
131 void wxFrameViewSerializer::Serialize( wxObject* pObj, wxObjectStorage& store )
132 {
133 // wxFrameViewSerializer is a kind of wxEvtHandler - peform serialization of
134 // the base class first
135
136 info.SerializeInherited( pObj, store );
137
138 wxFrameView* pView = (wxFrameView*)pObj;
139
140 store.XchgObjPtr( (wxObject**) &pView->mpFrameMgr );
141 store.XchgObjPtr( (wxObject**) &pView->mpLayout );
142 store.XchgBool ( pView->mDoToolUpdates );
143
144 // serialize members in derived classes
145
146 pView->OnSerialize( store );
147 }
148
149 #endif
150
151 /***** Implementation for class wxFrameManager *****/
152
153 void wxFrameManager::DoSerialize( wxObjectStorage& WXUNUSED(store) )
154 {
155 #if 0
156 store.AddInitialRef( mpFrameWnd );
157 store.AddInitialRef( this );
158 if ( mpClientWnd ) store.AddInitialRef( mpClientWnd );
159
160 store.XchgObj( (wxObject*) &mViews );
161 store.XchgInt( mActiveViewNo );
162
163 store.Finalize(); // finish serialization
164 #endif
165 }
166
167 void wxFrameManager::DestroyViews()
168 {
169 DeactivateCurrentView();
170
171 wxObjectList::compatibility_iterator pNode = mViews.GetFirst();
172
173 while ( pNode )
174 {
175 delete (wxFrameView*)pNode->GetData();
176
177 pNode = pNode->GetNext();
178 }
179
180 if ( mActiveViewNo != -1 && GetParentFrame() )
181
182 GetParentFrame()->SetNextHandler( NULL );
183 }
184
185 int wxFrameManager::GetViewNo( wxFrameView* pView )
186 {
187 wxObjectList::compatibility_iterator pNode = mViews.GetFirst();
188 int n = 0;
189
190 while ( pNode )
191 {
192 if ( (wxFrameView*)pNode->GetData() == pView )
193
194 return n;
195
196 ++n;
197 pNode = pNode->GetNext();
198 }
199
200 return -1;
201 }
202
203 void wxFrameManager::EnableMenusForView( wxFrameView* pView, bool enable )
204 {
205 wxMenuBar* pMenuBar = GetParentFrame()->GetMenuBar();
206 int count = pMenuBar->GetMenuCount();
207
208 if ( !pMenuBar )
209 return;
210
211 wxStringListNode* pNode = pView->mTopMenus.GetFirst();
212
213 int i;
214 while ( pNode )
215 {
216 for ( i = 0; i != count; ++i )
217 {
218 if ( pMenuBar->GetMenu(i)->GetTitle() == pNode->GetData() )
219 pMenuBar->EnableTop( i, enable );
220 }
221
222 pNode = pNode->GetNext();
223 }
224 }
225
226 void wxFrameManager::SyncAllMenus()
227 {
228 wxObjectList::compatibility_iterator pNode = mViews.GetFirst();
229 int i = 0;
230
231 while ( pNode )
232 {
233 if ( i != mActiveViewNo )
234
235 EnableMenusForView( (wxFrameView*)pNode->GetData(), false );
236
237 pNode = pNode->GetNext();
238 }
239
240 EnableMenusForView( GetView( mActiveViewNo ), true );
241 }
242
243 /*** public methods ***/
244
245 wxFrameManager::wxFrameManager()
246
247 : mpFrameWnd( NULL ),
248 mActiveViewNo( -1 ),
249 mpClientWnd( NULL )
250 {
251 }
252
253 wxFrameManager::~wxFrameManager()
254 {
255 SaveViewsNow();
256 DestroyViews();
257 }
258
259 void wxFrameManager::Init( wxWindow* pMainFrame, const wxString& settingsFile )
260 {
261 mSettingsFile = settingsFile;
262 mpFrameWnd = pMainFrame;
263
264 wxObjectList::compatibility_iterator pNode = mViews.GetFirst();
265
266 while ( pNode )
267 {
268 wxFrameView* pView = (wxFrameView*)pNode->GetData();
269
270 pView->OnInit();
271 pView->OnInitMenus();
272
273 pNode = pNode->GetNext();
274 }
275
276 if ( !ReloadViews() )
277 {
278 // if loading of settings file failed (e.g. was not found),
279 // do recreation of items in each view
280
281 pNode = mViews.GetFirst();
282
283 while ( pNode )
284 {
285 wxFrameView* pView = (wxFrameView*)pNode->GetData();
286
287 pView->OnRecreate();
288
289 pNode = pNode->GetNext();
290 }
291 }
292
293 if ( mActiveViewNo >= (int)mViews.GetCount() )
294 mActiveViewNo = -1;
295
296 ActivateView( GetView( ( mActiveViewNo == -1 ) ? 0 : mActiveViewNo ) );
297
298 SyncAllMenus();
299 }
300
301 void wxFrameManager::AddView( wxFrameView* pFrmView )
302 {
303 mViews.Append( pFrmView );
304
305 pFrmView->mpFrameMgr = this; // back ref.
306 }
307
308 void wxFrameManager::RemoveView( wxFrameView* WXUNUSED(pFrmView) )
309 {
310 // TBD::
311 wxFAIL_MSG( _T("wxFrameManager::RemoveView() has not been implemented yet.") );
312 }
313
314 int wxFrameManager::GetActiveViewNo()
315 {
316 return mActiveViewNo;
317 }
318
319 wxFrameView* wxFrameManager::GetActiveView()
320 {
321 wxObjectList::compatibility_iterator pNode = mViews.Item( mActiveViewNo );
322
323 if ( pNode ) return (wxFrameView*)pNode->GetData();
324 else return NULL;
325 }
326
327 wxObjectList::compatibility_iterator wxFrameManager::GetActiveViewNode()
328 {
329 return mViews.Item( mActiveViewNo );
330 }
331
332 wxFrame* wxFrameManager::GetParentFrame()
333 {
334 return ((wxFrame*)mpFrameWnd);
335 }
336
337 wxWindow* wxFrameManager::GetParentWindow()
338 {
339 return mpFrameWnd;
340 }
341
342 wxFrameView* wxFrameManager::GetView( int viewNo )
343 {
344 wxObjectList::compatibility_iterator pNode = mViews.Item( viewNo );
345
346 if ( pNode ) return (wxFrameView*)pNode->GetData();
347 else return NULL;
348 }
349
350 void wxFrameManager::ActivateView( int viewNo )
351 {
352 ActivateView( GetView( viewNo ) );
353 }
354
355 void wxFrameManager::ActivateView( wxFrameView* pFrmView )
356 {
357 DeactivateCurrentView();
358
359 mActiveViewNo = GetViewNo( pFrmView );
360
361 if ( pFrmView->mpLayout )
362
363 pFrmView->mpLayout->Activate();
364
365 // FIXME:: we would have used PushEventHandler(),
366 // but wxFrame bypasses attached handlers when
367 // handling wxCommand events!
368
369 GetParentFrame()->PushEventHandler( pFrmView );
370
371 EnableMenusForView( pFrmView, true );
372 }
373
374 void wxFrameManager::SetClinetWindow( wxWindow* pFrameClient )
375 {
376 if ( mpClientWnd ) mpClientWnd->Destroy();
377
378 mpClientWnd = pFrameClient;
379 }
380
381 wxWindow* wxFrameManager::GetClientWindow()
382 {
383 if ( !mpClientWnd )
384
385 mpClientWnd = new wxWindow( GetParentFrame(), -1 );
386
387 return mpClientWnd;
388 }
389
390 void wxFrameManager::DeactivateCurrentView()
391 {
392 if ( mActiveViewNo == -1 )
393 return;
394
395 wxFrameView* pView = GetActiveView();
396
397 // FOR NOW::
398 wxASSERT( GetParentFrame()->GetEventHandler() == pView );
399
400 GetParentFrame()->PopEventHandler();
401
402 if ( pView->mpLayout )
403 pView->mpLayout->Deactivate();
404
405 EnableMenusForView( pView, false );
406 }
407
408 void wxFrameManager::SaveViewsNow()
409 {
410 #if 0
411 if ( mSettingsFile == "" ) return;
412
413 wxIOStreamWrapper stm;
414 stm.CreateForOutput( mSettingsFile );
415
416 mStore.SetDataStream( stm );
417 DoSerialize( mStore );
418 #endif
419 }
420
421 bool wxFrameManager::ReloadViews()
422 {
423 return false;
424
425 // TBD: ????
426 #if 0
427 if ( mSettingsFile == "" || !wxFileExists( mSettingsFile ) )
428 return false;
429
430 DestroyViews();
431
432 wxIOStreamWrapper stm;
433 stm.CreateForInput( mSettingsFile );
434
435 mStore.SetDataStream( stm );
436 DoSerialize( mStore );
437
438 return true;
439 #endif
440 }
441
442 bool wxFrameManager::ViewsAreLoaded()
443 {
444 return ( mViews.GetCount() != 0 );
445 }
446