]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/fl/frmview.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFrameView implementation. NOT USED IN FL.
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "frmview.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/fl/frmview.h"
30 /***** Implementation for class wxFrameView *****/
32 BEGIN_EVENT_TABLE( wxFrameView
, wxEvtHandler
)
34 EVT_IDLE( wxFrameView::OnIdle
)
38 void wxFrameView::OnIdle( wxIdleEvent
& event
)
48 /*** public methods ***/
50 wxFrameView::wxFrameView()
56 wxFrameView::~wxFrameView()
58 if ( mpLayout
) delete mpLayout
;
61 wxFrame
* wxFrameView::GetParentFrame()
63 return mpFrameMgr
->GetParentFrame();
66 wxWindow
* wxFrameView::GetClientWindow()
68 return mpFrameMgr
->GetClientWindow();
71 void wxFrameView::Activate()
73 mpFrameMgr
->ActivateView( this );
76 void wxFrameView::Deactivate()
78 mpFrameMgr
->DeactivateCurrentView();
81 void wxFrameView::CreateLayout()
83 mpLayout
= new wxFrameLayout( GetParentFrame(), mpFrameMgr
->GetClientWindow(), FALSE
);
86 wxFrameLayout
* wxFrameView::GetLayout()
91 void wxFrameView::SetToolUpdates( bool doToolUpdates
)
93 mDoToolUpdates
= doToolUpdates
;
96 void wxFrameView::SetLayout( wxFrameLayout
* pLayout
)
98 if ( mpLayout
) delete mpLayout
;
103 wxFrameManager
& wxFrameView::GetFrameManager()
108 void wxFrameView::RegisterMenu( const wxString
& topMenuName
)
110 mTopMenus
.Add( topMenuName
);
115 /***** Implementation for class wxFrameViewSerializer *****/
117 // NOTE:: currently "stipple" property of the brush is not serialized
119 class wxFrameViewSerializer
: public wxEvtHandlerSerializer
121 DECLARE_SERIALIZER_CLASS( wxFrameViewSerializer
);
123 static void Serialize( wxObject
* pObj
, wxObjectStorage
& store
);
126 IMPLEMENT_SERIALIZER_CLASS( wxFrameView
,
127 wxFrameViewSerializer
,
128 wxFrameViewSerializer::Serialize
,
131 void wxFrameViewSerializer::Serialize( wxObject
* pObj
, wxObjectStorage
& store
)
133 // wxFrameViewSerializer is a kind of wxEvtHandler - peform serialization of
134 // the base class first
136 info
.SerializeInherited( pObj
, store
);
138 wxFrameView
* pView
= (wxFrameView
*)pObj
;
140 store
.XchgObjPtr( (wxObject
**) &pView
->mpFrameMgr
);
141 store
.XchgObjPtr( (wxObject
**) &pView
->mpLayout
);
142 store
.XchgBool ( pView
->mDoToolUpdates
);
144 // serialize members in derived classes
146 pView
->OnSerialize( store
);
151 /***** Implementation for class wxFrameManager *****/
153 void wxFrameManager::DoSerialize( wxObjectStorage
& WXUNUSED(store
) )
156 store
.AddInitialRef( mpFrameWnd
);
157 store
.AddInitialRef( this );
158 if ( mpClientWnd
) store
.AddInitialRef( mpClientWnd
);
160 store
.XchgObj( (wxObject
*) &mViews
);
161 store
.XchgInt( mActiveViewNo
);
163 store
.Finalize(); // finish serialization
167 void wxFrameManager::DestroyViews()
169 DeactivateCurrentView();
171 wxNode
* pNode
= mViews
.GetFirst();
175 delete (wxFrameView
*)pNode
->GetData();
177 pNode
= pNode
->GetNext();
180 if ( mActiveViewNo
!= -1 && GetParentFrame() )
182 GetParentFrame()->SetNextHandler( NULL
);
185 int wxFrameManager::GetViewNo( wxFrameView
* pView
)
187 wxNode
* pNode
= mViews
.GetFirst();
192 if ( (wxFrameView
*)pNode
->GetData() == pView
)
197 pNode
= pNode
->GetNext();
203 void wxFrameManager::EnableMenusForView( wxFrameView
* pView
, bool enable
)
205 wxMenuBar
* pMenuBar
= GetParentFrame()->GetMenuBar();
206 int count
= pMenuBar
->GetMenuCount();
211 wxStringListNode
* pNode
= pView
->mTopMenus
.GetFirst();
216 for ( i
= 0; i
!= count
; ++i
)
218 if ( pMenuBar
->GetMenu(i
)->GetTitle() == pNode
->GetData() )
219 pMenuBar
->EnableTop( i
, enable
);
222 pNode
= pNode
->GetNext();
226 void wxFrameManager::SyncAllMenus()
228 wxNode
* pNode
= mViews
.GetFirst();
233 if ( i
!= mActiveViewNo
)
235 EnableMenusForView( (wxFrameView
*)pNode
->GetData(), FALSE
);
237 pNode
= pNode
->GetNext();
240 EnableMenusForView( GetView( mActiveViewNo
), TRUE
);
243 /*** public methods ***/
245 wxFrameManager::wxFrameManager()
247 : mpFrameWnd( NULL
),
253 wxFrameManager::~wxFrameManager()
259 void wxFrameManager::Init( wxWindow
* pMainFrame
, const wxString
& settingsFile
)
261 mSettingsFile
= settingsFile
;
262 mpFrameWnd
= pMainFrame
;
264 wxNode
* pNode
= mViews
.GetFirst();
268 wxFrameView
* pView
= (wxFrameView
*)pNode
->GetData();
271 pView
->OnInitMenus();
273 pNode
= pNode
->GetNext();
276 if ( !ReloadViews() )
278 // if loading of settings file failed (e.g. was not found),
279 // do recreation of items in each view
281 pNode
= mViews
.GetFirst();
285 wxFrameView
* pView
= (wxFrameView
*)pNode
->GetData();
289 pNode
= pNode
->GetNext();
293 if ( mActiveViewNo
>= (int)mViews
.GetCount() )
296 ActivateView( GetView( ( mActiveViewNo
== -1 ) ? 0 : mActiveViewNo
) );
301 void wxFrameManager::AddView( wxFrameView
* pFrmView
)
303 mViews
.Append( pFrmView
);
305 pFrmView
->mpFrameMgr
= this; // back ref.
308 void wxFrameManager::RemoveView( wxFrameView
* WXUNUSED(pFrmView
) )
311 wxFAIL_MSG( _T("wxFrameManager::RemoveView() has not been implemented yet.") );
314 int wxFrameManager::GetActiveViewNo()
316 return mActiveViewNo
;
319 wxFrameView
* wxFrameManager::GetActiveView()
321 wxNode
* pNode
= mViews
.Item( mActiveViewNo
);
323 if ( pNode
) return (wxFrameView
*)pNode
->GetData();
327 wxNode
* wxFrameManager::GetActiveViewNode()
329 return mViews
.Item( mActiveViewNo
);
332 wxFrame
* wxFrameManager::GetParentFrame()
334 return ((wxFrame
*)mpFrameWnd
);
337 wxWindow
* wxFrameManager::GetParentWindow()
342 wxFrameView
* wxFrameManager::GetView( int viewNo
)
344 wxNode
* pNode
= mViews
.Item( viewNo
);
346 if ( pNode
) return (wxFrameView
*)pNode
->GetData();
350 void wxFrameManager::ActivateView( int viewNo
)
352 ActivateView( GetView( viewNo
) );
355 void wxFrameManager::ActivateView( wxFrameView
* pFrmView
)
357 DeactivateCurrentView();
359 mActiveViewNo
= GetViewNo( pFrmView
);
361 if ( pFrmView
->mpLayout
)
363 pFrmView
->mpLayout
->Activate();
365 // FIXME:: we would have used PushEventHandler(),
366 // but wxFrame bypasses attached handlers when
367 // handling wxCommand events!
369 GetParentFrame()->PushEventHandler( pFrmView
);
371 EnableMenusForView( pFrmView
, TRUE
);
374 void wxFrameManager::SetClinetWindow( wxWindow
* pFrameClient
)
376 if ( mpClientWnd
) mpClientWnd
->Destroy();
378 mpClientWnd
= pFrameClient
;
381 wxWindow
* wxFrameManager::GetClientWindow()
385 mpClientWnd
= new wxWindow( GetParentFrame(), -1 );
390 void wxFrameManager::DeactivateCurrentView()
392 if ( mActiveViewNo
== -1 )
395 wxFrameView
* pView
= GetActiveView();
398 wxASSERT( GetParentFrame()->GetEventHandler() == pView
);
400 GetParentFrame()->PopEventHandler();
402 if ( pView
->mpLayout
)
403 pView
->mpLayout
->Deactivate();
405 EnableMenusForView( pView
, FALSE
);
408 void wxFrameManager::SaveViewsNow()
411 if ( mSettingsFile
== "" ) return;
413 wxIOStreamWrapper stm
;
414 stm
.CreateForOutput( mSettingsFile
);
416 mStore
.SetDataStream( stm
);
417 DoSerialize( mStore
);
421 bool wxFrameManager::ReloadViews()
427 if ( mSettingsFile
== "" || !wxFileExists( mSettingsFile
) )
432 wxIOStreamWrapper stm
;
433 stm
.CreateForInput( mSettingsFile
);
435 mStore
.SetDataStream( stm
);
436 DoSerialize( mStore
);
442 bool wxFrameManager::ViewsAreLoaded()
444 return ( mViews
.GetCount() != 0 );