]>
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
)
51 /*** public methods ***/
53 wxFrameView::wxFrameView()
59 wxFrameView::~wxFrameView()
61 if ( mpLayout
) delete mpLayout
;
64 wxFrame
* wxFrameView::GetParentFrame()
66 return mpFrameMgr
->GetParentFrame();
69 wxWindow
* wxFrameView::GetClientWindow()
71 return mpFrameMgr
->GetClientWindow();
74 void wxFrameView::Activate()
76 mpFrameMgr
->ActivateView( this );
79 void wxFrameView::Deactivate()
81 mpFrameMgr
->DeactivateCurrentView();
84 void wxFrameView::CreateLayout()
86 mpLayout
= new wxFrameLayout( GetParentFrame(), mpFrameMgr
->GetClientWindow(), FALSE
);
89 wxFrameLayout
* wxFrameView::GetLayout()
94 void wxFrameView::SetToolUpdates( bool doToolUpdates
)
96 mDoToolUpdates
= doToolUpdates
;
99 void wxFrameView::SetLayout( wxFrameLayout
* pLayout
)
101 if ( mpLayout
) delete mpLayout
;
106 wxFrameManager
& wxFrameView::GetFrameManager()
111 void wxFrameView::RegisterMenu( const wxString
& topMenuName
)
113 mTopMenus
.Add( topMenuName
);
118 /***** Implementation for class wxFrameViewSerializer *****/
120 // NOTE:: currently "stipple" property of the brush is not serialized
122 class wxFrameViewSerializer
: public wxEvtHandlerSerializer
124 DECLARE_SERIALIZER_CLASS( wxFrameViewSerializer
);
126 static void Serialize( wxObject
* pObj
, wxObjectStorage
& store
);
129 IMPLEMENT_SERIALIZER_CLASS( wxFrameView
,
130 wxFrameViewSerializer
,
131 wxFrameViewSerializer::Serialize
,
134 void wxFrameViewSerializer::Serialize( wxObject
* pObj
, wxObjectStorage
& store
)
136 // wxFrameViewSerializer is a kind of wxEvtHandler - peform serialization of
137 // the base class first
139 info
.SerializeInherited( pObj
, store
);
141 wxFrameView
* pView
= (wxFrameView
*)pObj
;
143 store
.XchgObjPtr( (wxObject
**) &pView
->mpFrameMgr
);
144 store
.XchgObjPtr( (wxObject
**) &pView
->mpLayout
);
145 store
.XchgBool ( pView
->mDoToolUpdates
);
147 // serialize members in derived classes
149 pView
->OnSerialize( store
);
154 /***** Implementation for class wxFrameManager *****/
156 void wxFrameManager::DoSerialize( wxObjectStorage
& WXUNUSED(store
) )
159 store
.AddInitialRef( mpFrameWnd
);
160 store
.AddInitialRef( this );
161 if ( mpClientWnd
) store
.AddInitialRef( mpClientWnd
);
163 store
.XchgObj( (wxObject
*) &mViews
);
164 store
.XchgInt( mActiveViewNo
);
166 store
.Finalize(); // finish serialization
170 void wxFrameManager::DestroyViews()
172 DeactivateCurrentView();
174 wxNode
* pNode
= mViews
.GetFirst();
178 delete (wxFrameView
*)pNode
->GetData();
180 pNode
= pNode
->GetNext();
183 if ( mActiveViewNo
!= -1 && GetParentFrame() )
185 GetParentFrame()->SetNextHandler( NULL
);
188 int wxFrameManager::GetViewNo( wxFrameView
* pView
)
190 wxNode
* pNode
= mViews
.GetFirst();
195 if ( (wxFrameView
*)pNode
->GetData() == pView
)
200 pNode
= pNode
->GetNext();
206 void wxFrameManager::EnableMenusForView( wxFrameView
* pView
, bool enable
)
208 wxMenuBar
* pMenuBar
= GetParentFrame()->GetMenuBar();
209 int count
= pMenuBar
->GetMenuCount();
214 wxStringListNode
* pNode
= pView
->mTopMenus
.GetFirst();
219 for ( i
= 0; i
!= count
; ++i
)
221 if ( pMenuBar
->GetMenu(i
)->GetTitle() == pNode
->GetData() )
222 pMenuBar
->EnableTop( i
, enable
);
225 pNode
= pNode
->GetNext();
229 void wxFrameManager::SyncAllMenus()
231 wxNode
* pNode
= mViews
.GetFirst();
236 if ( i
!= mActiveViewNo
)
238 EnableMenusForView( (wxFrameView
*)pNode
->GetData(), FALSE
);
240 pNode
= pNode
->GetNext();
243 EnableMenusForView( GetView( mActiveViewNo
), TRUE
);
246 /*** public methods ***/
248 wxFrameManager::wxFrameManager()
250 : mpFrameWnd( NULL
),
256 wxFrameManager::~wxFrameManager()
262 void wxFrameManager::Init( wxWindow
* pMainFrame
, const wxString
& settingsFile
)
264 mSettingsFile
= settingsFile
;
265 mpFrameWnd
= pMainFrame
;
267 wxNode
* pNode
= mViews
.GetFirst();
271 wxFrameView
* pView
= (wxFrameView
*)pNode
->GetData();
274 pView
->OnInitMenus();
276 pNode
= pNode
->GetNext();
279 if ( !ReloadViews() )
281 // if loading of settings file failed (e.g. was not found),
282 // do recreation of items in each view
284 pNode
= mViews
.GetFirst();
288 wxFrameView
* pView
= (wxFrameView
*)pNode
->GetData();
292 pNode
= pNode
->GetNext();
296 if ( mActiveViewNo
>= (int)mViews
.GetCount() )
299 ActivateView( GetView( ( mActiveViewNo
== -1 ) ? 0 : mActiveViewNo
) );
304 void wxFrameManager::AddView( wxFrameView
* pFrmView
)
306 mViews
.Append( pFrmView
);
308 pFrmView
->mpFrameMgr
= this; // back ref.
311 void wxFrameManager::RemoveView( wxFrameView
* WXUNUSED(pFrmView
) )
314 wxFAIL_MSG( _T("wxFrameManager::RemoveView() has not been implemented yet.") );
317 int wxFrameManager::GetActiveViewNo()
319 return mActiveViewNo
;
322 wxFrameView
* wxFrameManager::GetActiveView()
324 wxNode
* pNode
= mViews
.Item( mActiveViewNo
);
326 if ( pNode
) return (wxFrameView
*)pNode
->GetData();
330 wxNode
* wxFrameManager::GetActiveViewNode()
332 return mViews
.Item( mActiveViewNo
);
335 wxFrame
* wxFrameManager::GetParentFrame()
337 return ((wxFrame
*)mpFrameWnd
);
340 wxWindow
* wxFrameManager::GetParentWindow()
345 wxFrameView
* wxFrameManager::GetView( int viewNo
)
347 wxNode
* pNode
= mViews
.Item( viewNo
);
349 if ( pNode
) return (wxFrameView
*)pNode
->GetData();
353 void wxFrameManager::ActivateView( int viewNo
)
355 ActivateView( GetView( viewNo
) );
358 void wxFrameManager::ActivateView( wxFrameView
* pFrmView
)
360 DeactivateCurrentView();
362 mActiveViewNo
= GetViewNo( pFrmView
);
364 if ( pFrmView
->mpLayout
)
366 pFrmView
->mpLayout
->Activate();
368 // FIXME:: we would have used PushEventHandler(),
369 // but wxFrame bypasses attached handlers when
370 // handling wxCommand events!
372 GetParentFrame()->PushEventHandler( pFrmView
);
374 EnableMenusForView( pFrmView
, TRUE
);
377 void wxFrameManager::SetClinetWindow( wxWindow
* pFrameClient
)
379 if ( mpClientWnd
) mpClientWnd
->Destroy();
381 mpClientWnd
= pFrameClient
;
384 wxWindow
* wxFrameManager::GetClientWindow()
388 mpClientWnd
= new wxWindow( GetParentFrame(), -1 );
393 void wxFrameManager::DeactivateCurrentView()
395 if ( mActiveViewNo
== -1 )
398 wxFrameView
* pView
= GetActiveView();
401 wxASSERT( GetParentFrame()->GetEventHandler() == pView
);
403 GetParentFrame()->PopEventHandler();
405 if ( pView
->mpLayout
)
406 pView
->mpLayout
->Deactivate();
408 EnableMenusForView( pView
, FALSE
);
411 void wxFrameManager::SaveViewsNow()
414 if ( mSettingsFile
== "" ) return;
416 wxIOStreamWrapper stm
;
417 stm
.CreateForOutput( mSettingsFile
);
419 mStore
.SetDataStream( stm
);
420 DoSerialize( mStore
);
424 bool wxFrameManager::ReloadViews()
430 if ( mSettingsFile
== "" || !wxFileExists( mSettingsFile
) )
435 wxIOStreamWrapper stm
;
436 stm
.CreateForInput( mSettingsFile
);
438 mStore
.SetDataStream( stm
);
439 DoSerialize( mStore
);
445 bool wxFrameManager::ViewsAreLoaded()
447 return ( mViews
.GetCount() != 0 );