1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFrameView implementation. NOT USED IN FL.
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/fl/frmview.h"
26 /***** Implementation for class wxFrameView *****/
28 BEGIN_EVENT_TABLE( wxFrameView
, wxEvtHandler
)
30 EVT_IDLE( wxFrameView::OnIdle
)
34 void wxFrameView::OnIdle( wxIdleEvent
& event
)
44 /*** public methods ***/
46 wxFrameView::wxFrameView()
52 wxFrameView::~wxFrameView()
54 if ( mpLayout
) delete mpLayout
;
57 wxFrame
* wxFrameView::GetParentFrame()
59 return mpFrameMgr
->GetParentFrame();
62 wxWindow
* wxFrameView::GetClientWindow()
64 return mpFrameMgr
->GetClientWindow();
67 void wxFrameView::Activate()
69 mpFrameMgr
->ActivateView( this );
72 void wxFrameView::Deactivate()
74 mpFrameMgr
->DeactivateCurrentView();
77 void wxFrameView::CreateLayout()
79 mpLayout
= new wxFrameLayout( GetParentFrame(), mpFrameMgr
->GetClientWindow(), false );
82 wxFrameLayout
* wxFrameView::GetLayout()
87 void wxFrameView::SetToolUpdates( bool doToolUpdates
)
89 mDoToolUpdates
= doToolUpdates
;
92 void wxFrameView::SetLayout( wxFrameLayout
* pLayout
)
94 if ( mpLayout
) delete mpLayout
;
99 wxFrameManager
& wxFrameView::GetFrameManager()
104 void wxFrameView::RegisterMenu( const wxString
& topMenuName
)
106 mTopMenus
.Add( topMenuName
);
111 /***** Implementation for class wxFrameViewSerializer *****/
113 // NOTE:: currently "stipple" property of the brush is not serialized
115 class wxFrameViewSerializer
: public wxEvtHandlerSerializer
117 DECLARE_SERIALIZER_CLASS( wxFrameViewSerializer
);
119 static void Serialize( wxObject
* pObj
, wxObjectStorage
& store
);
122 IMPLEMENT_SERIALIZER_CLASS( wxFrameView
,
123 wxFrameViewSerializer
,
124 wxFrameViewSerializer::Serialize
,
127 void wxFrameViewSerializer::Serialize( wxObject
* pObj
, wxObjectStorage
& store
)
129 // wxFrameViewSerializer is a kind of wxEvtHandler - peform serialization of
130 // the base class first
132 info
.SerializeInherited( pObj
, store
);
134 wxFrameView
* pView
= (wxFrameView
*)pObj
;
136 store
.XchgObjPtr( (wxObject
**) &pView
->mpFrameMgr
);
137 store
.XchgObjPtr( (wxObject
**) &pView
->mpLayout
);
138 store
.XchgBool ( pView
->mDoToolUpdates
);
140 // serialize members in derived classes
142 pView
->OnSerialize( store
);
147 /***** Implementation for class wxFrameManager *****/
149 void wxFrameManager::DoSerialize( wxObjectStorage
& WXUNUSED(store
) )
152 store
.AddInitialRef( mpFrameWnd
);
153 store
.AddInitialRef( this );
154 if ( mpClientWnd
) store
.AddInitialRef( mpClientWnd
);
156 store
.XchgObj( (wxObject
*) &mViews
);
157 store
.XchgInt( mActiveViewNo
);
159 store
.Finalize(); // finish serialization
163 void wxFrameManager::DestroyViews()
165 DeactivateCurrentView();
167 wxObjectList::compatibility_iterator pNode
= mViews
.GetFirst();
171 delete (wxFrameView
*)pNode
->GetData();
173 pNode
= pNode
->GetNext();
176 if ( mActiveViewNo
!= -1 && GetParentFrame() )
178 GetParentFrame()->SetNextHandler( NULL
);
181 int wxFrameManager::GetViewNo( wxFrameView
* pView
)
183 wxObjectList::compatibility_iterator pNode
= mViews
.GetFirst();
188 if ( (wxFrameView
*)pNode
->GetData() == pView
)
193 pNode
= pNode
->GetNext();
199 void wxFrameManager::EnableMenusForView( wxFrameView
* pView
, bool enable
)
201 wxMenuBar
* pMenuBar
= GetParentFrame()->GetMenuBar();
202 int count
= pMenuBar
->GetMenuCount();
207 wxStringList::compatibility_iterator pNode
= pView
->mTopMenus
.GetFirst();
212 for ( i
= 0; i
!= count
; ++i
)
214 if ( pMenuBar
->GetMenu(i
)->GetTitle() == pNode
->GetData() )
215 pMenuBar
->EnableTop( i
, enable
);
218 pNode
= pNode
->GetNext();
222 void wxFrameManager::SyncAllMenus()
224 wxObjectList::compatibility_iterator pNode
= mViews
.GetFirst();
229 if ( i
!= mActiveViewNo
)
231 EnableMenusForView( (wxFrameView
*)pNode
->GetData(), false );
233 pNode
= pNode
->GetNext();
236 EnableMenusForView( GetView( mActiveViewNo
), true );
239 /*** public methods ***/
241 wxFrameManager::wxFrameManager()
243 : mpFrameWnd( NULL
),
249 wxFrameManager::~wxFrameManager()
255 void wxFrameManager::Init( wxWindow
* pMainFrame
, const wxString
& settingsFile
)
257 mSettingsFile
= settingsFile
;
258 mpFrameWnd
= pMainFrame
;
260 wxObjectList::compatibility_iterator pNode
= mViews
.GetFirst();
264 wxFrameView
* pView
= (wxFrameView
*)pNode
->GetData();
267 pView
->OnInitMenus();
269 pNode
= pNode
->GetNext();
272 if ( !ReloadViews() )
274 // if loading of settings file failed (e.g. was not found),
275 // do recreation of items in each view
277 pNode
= mViews
.GetFirst();
281 wxFrameView
* pView
= (wxFrameView
*)pNode
->GetData();
285 pNode
= pNode
->GetNext();
289 if ( mActiveViewNo
>= (int)mViews
.GetCount() )
292 ActivateView( GetView( ( mActiveViewNo
== -1 ) ? 0 : mActiveViewNo
) );
297 void wxFrameManager::AddView( wxFrameView
* pFrmView
)
299 mViews
.Append( pFrmView
);
301 pFrmView
->mpFrameMgr
= this; // back ref.
304 void wxFrameManager::RemoveView( wxFrameView
* WXUNUSED(pFrmView
) )
307 wxFAIL_MSG( _T("wxFrameManager::RemoveView() has not been implemented yet.") );
310 int wxFrameManager::GetActiveViewNo()
312 return mActiveViewNo
;
315 wxFrameView
* wxFrameManager::GetActiveView()
317 wxObjectList::compatibility_iterator pNode
= mViews
.Item( mActiveViewNo
);
319 if ( pNode
) return (wxFrameView
*)pNode
->GetData();
323 wxObjectList::compatibility_iterator
wxFrameManager::GetActiveViewNode()
325 return mViews
.Item( mActiveViewNo
);
328 wxFrame
* wxFrameManager::GetParentFrame()
330 return ((wxFrame
*)mpFrameWnd
);
333 wxWindow
* wxFrameManager::GetParentWindow()
338 wxFrameView
* wxFrameManager::GetView( int viewNo
)
340 wxObjectList::compatibility_iterator pNode
= mViews
.Item( viewNo
);
342 if ( pNode
) return (wxFrameView
*)pNode
->GetData();
346 void wxFrameManager::ActivateView( int viewNo
)
348 ActivateView( GetView( viewNo
) );
351 void wxFrameManager::ActivateView( wxFrameView
* pFrmView
)
353 DeactivateCurrentView();
355 mActiveViewNo
= GetViewNo( pFrmView
);
357 if ( pFrmView
->mpLayout
)
359 pFrmView
->mpLayout
->Activate();
361 // FIXME:: we would have used PushEventHandler(),
362 // but wxFrame bypasses attached handlers when
363 // handling wxCommand events!
365 GetParentFrame()->PushEventHandler( pFrmView
);
367 EnableMenusForView( pFrmView
, true );
370 void wxFrameManager::SetClinetWindow( wxWindow
* pFrameClient
)
372 if ( mpClientWnd
) mpClientWnd
->Destroy();
374 mpClientWnd
= pFrameClient
;
377 wxWindow
* wxFrameManager::GetClientWindow()
381 mpClientWnd
= new wxWindow( GetParentFrame(), -1 );
386 void wxFrameManager::DeactivateCurrentView()
388 if ( mActiveViewNo
== -1 )
391 wxFrameView
* pView
= GetActiveView();
394 wxASSERT( GetParentFrame()->GetEventHandler() == pView
);
396 GetParentFrame()->PopEventHandler();
398 if ( pView
->mpLayout
)
399 pView
->mpLayout
->Deactivate();
401 EnableMenusForView( pView
, false );
404 void wxFrameManager::SaveViewsNow()
407 if ( mSettingsFile
== "" ) return;
409 wxIOStreamWrapper stm
;
410 stm
.CreateForOutput( mSettingsFile
);
412 mStore
.SetDataStream( stm
);
413 DoSerialize( mStore
);
417 bool wxFrameManager::ReloadViews()
423 if ( mSettingsFile
== "" || !wxFileExists( mSettingsFile
) )
428 wxIOStreamWrapper stm
;
429 stm
.CreateForInput( mSettingsFile
);
431 mStore
.SetDataStream( stm
);
432 DoSerialize( mStore
);
438 bool wxFrameManager::ViewsAreLoaded()
440 return ( mViews
.GetCount() != 0 );