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