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