]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/fl/frmview.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
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
& 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
.First();
178 delete (wxFrameView
*)pNode
->Data();
180 pNode
= pNode
->Next();
183 if ( mActiveViewNo
!= -1 && GetParentFrame() )
185 GetParentFrame()->SetNextHandler( NULL
);
188 int wxFrameManager::GetViewNo( wxFrameView
* pView
)
190 wxNode
* pNode
= mViews
.First();
195 if ( (wxFrameView
*)pNode
->Data() == pView
)
200 pNode
= pNode
->Next();
206 void wxFrameManager::EnableMenusForView( wxFrameView
* pView
, bool enable
)
208 wxMenuBar
* pMenuBar
= GetParentFrame()->GetMenuBar();
209 int count
= pMenuBar
->GetMenuCount();
211 if ( !pMenuBar
) return;
213 wxStringListNode
* pNode
= pView
->mTopMenus
.GetFirst();
217 for( int i
= 0; i
!= count
; ++i
)
219 if ( pMenuBar
->GetMenu(i
)->GetTitle() == pNode
->GetData() )
221 pMenuBar
->EnableTop( i
, enable
);
224 pNode
= pNode
->GetNext();
228 void wxFrameManager::SyncAllMenus()
230 wxNode
* pNode
= mViews
.First();
235 if ( i
!= mActiveViewNo
)
237 EnableMenusForView( (wxFrameView
*)pNode
->GetData(), FALSE
);
239 pNode
= pNode
->Next();
242 EnableMenusForView( GetView( mActiveViewNo
), TRUE
);
245 /*** public methods ***/
247 wxFrameManager::wxFrameManager()
249 : mpFrameWnd( NULL
),
255 wxFrameManager::~wxFrameManager()
261 void wxFrameManager::Init( wxWindow
* pMainFrame
, const wxString
& settingsFile
)
263 mSettingsFile
= settingsFile
;
264 mpFrameWnd
= pMainFrame
;
266 wxNode
* pNode
= mViews
.First();
270 wxFrameView
* pView
= (wxFrameView
*)pNode
->Data();
273 pView
->OnInitMenus();
275 pNode
= pNode
->Next();
278 if ( !ReloadViews() )
280 // if loading of settings file failed (e.g. was not found),
281 // do recreation of items in each view
283 pNode
= mViews
.First();
287 wxFrameView
* pView
= (wxFrameView
*)pNode
->Data();
291 pNode
= pNode
->Next();
295 if ( mActiveViewNo
>= mViews
.Number() )
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
* pFrmView
)
314 int avoidCompilerWarning
= 0;
315 wxASSERT(avoidCompilerWarning
);
318 int wxFrameManager::GetActiveViewNo()
320 return mActiveViewNo
;
323 wxFrameView
* wxFrameManager::GetActiveView()
325 wxNode
* pNode
= mViews
.Nth( mActiveViewNo
);
327 if ( pNode
) return (wxFrameView
*)pNode
->Data();
331 wxNode
* wxFrameManager::GetActiveViewNode()
333 return mViews
.Nth( mActiveViewNo
);
336 wxFrame
* wxFrameManager::GetParentFrame()
338 return ((wxFrame
*)mpFrameWnd
);
341 wxWindow
* wxFrameManager::GetParentWindow()
346 wxFrameView
* wxFrameManager::GetView( int viewNo
)
348 wxNode
* pNode
= mViews
.Nth( viewNo
);
350 if ( pNode
) return (wxFrameView
*)pNode
->Data();
354 void wxFrameManager::ActivateView( int viewNo
)
356 ActivateView( GetView( viewNo
) );
359 void wxFrameManager::ActivateView( wxFrameView
* pFrmView
)
361 DeactivateCurrentView();
363 mActiveViewNo
= GetViewNo( pFrmView
);
365 if ( pFrmView
->mpLayout
)
367 pFrmView
->mpLayout
->Activate();
369 // FIXME:: we would have used PushEventHandler(),
370 // but wxFrame bypasses attached handlers when
371 // handling wxCommand events!
373 GetParentFrame()->PushEventHandler( pFrmView
);
375 EnableMenusForView( pFrmView
, TRUE
);
378 void wxFrameManager::SetClinetWindow( wxWindow
* pFrameClient
)
380 if ( mpClientWnd
) mpClientWnd
->Destroy();
382 mpClientWnd
= pFrameClient
;
385 wxWindow
* wxFrameManager::GetClientWindow()
389 mpClientWnd
= new wxWindow( GetParentFrame(), -1 );
394 void wxFrameManager::DeactivateCurrentView()
396 if ( mActiveViewNo
== -1 ) return;
398 wxFrameView
* pView
= GetActiveView();
401 wxASSERT( GetParentFrame()->GetEventHandler() == pView
);
403 GetParentFrame()->PopEventHandler();
405 if ( pView
->mpLayout
)
407 pView
->mpLayout
->Deactivate();
409 EnableMenusForView( pView
, FALSE
);
412 void wxFrameManager::SaveViewsNow()
415 if ( mSettingsFile
== "" ) return;
417 wxIOStreamWrapper stm
;
418 stm
.CreateForOutput( mSettingsFile
);
420 mStore
.SetDataStream( stm
);
421 DoSerialize( mStore
);
425 bool wxFrameManager::ReloadViews()
431 if ( mSettingsFile
== "" || !wxFileExists( mSettingsFile
) )
437 wxIOStreamWrapper stm
;
438 stm
.CreateForInput( mSettingsFile
);
440 mStore
.SetDataStream( stm
);
441 DoSerialize( mStore
);
447 bool wxFrameManager::ViewsAreLoaded()
449 return ( mViews
.Number() != 0 );