]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/src/fl/frmview.cpp
Don't create uneeded variables.
[wxWidgets.git] / contrib / src / fl / frmview.cpp
... / ...
CommitLineData
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// 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
28BEGIN_EVENT_TABLE( wxFrameView, wxEvtHandler )
29
30 EVT_IDLE( wxFrameView::OnIdle )
31
32END_EVENT_TABLE()
33
34void wxFrameView::OnIdle( wxIdleEvent& event)
35{
36 event.Skip();
37
38 if ( mDoToolUpdates )
39 {
40 // TBD::
41 }
42}
43
44/*** public methods ***/
45
46wxFrameView::wxFrameView()
47
48 : mpLayout( NULL ),
49 mpFrameMgr( NULL )
50{}
51
52wxFrameView::~wxFrameView()
53{
54 if ( mpLayout ) delete mpLayout;
55}
56
57wxFrame* wxFrameView::GetParentFrame()
58{
59 return mpFrameMgr->GetParentFrame();
60}
61
62wxWindow* wxFrameView::GetClientWindow()
63{
64 return mpFrameMgr->GetClientWindow();
65}
66
67void wxFrameView::Activate()
68{
69 mpFrameMgr->ActivateView( this );
70}
71
72void wxFrameView::Deactivate()
73{
74 mpFrameMgr->DeactivateCurrentView();
75}
76
77void wxFrameView::CreateLayout()
78{
79 mpLayout = new wxFrameLayout( GetParentFrame(), mpFrameMgr->GetClientWindow(), false );
80}
81
82wxFrameLayout* wxFrameView::GetLayout()
83{
84 return mpLayout;
85}
86
87void wxFrameView::SetToolUpdates( bool doToolUpdates )
88{
89 mDoToolUpdates = doToolUpdates;
90}
91
92void wxFrameView::SetLayout( wxFrameLayout* pLayout )
93{
94 if ( mpLayout ) delete mpLayout;
95
96 mpLayout = pLayout;
97}
98
99wxFrameManager& wxFrameView::GetFrameManager()
100{
101 return *mpFrameMgr;
102}
103
104void 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
115class wxFrameViewSerializer : public wxEvtHandlerSerializer
116{
117 DECLARE_SERIALIZER_CLASS( wxFrameViewSerializer );
118
119 static void Serialize( wxObject* pObj, wxObjectStorage& store );
120};
121
122IMPLEMENT_SERIALIZER_CLASS( wxFrameView,
123 wxFrameViewSerializer,
124 wxFrameViewSerializer::Serialize,
125 NO_CLASS_INIT )
126
127void 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
149void 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
163void 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
181int 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
199void wxFrameManager::EnableMenusForView( wxFrameView* pView, bool enable )
200{
201 wxMenuBar* pMenuBar = GetParentFrame()->GetMenuBar();
202 int count = pMenuBar->GetMenuCount();
203
204 if ( !pMenuBar )
205 return;
206
207 wxStringList::compatibility_iterator pNode = pView->mTopMenus.GetFirst();
208
209 int i;
210 while ( pNode )
211 {
212 for ( i = 0; i != count; ++i )
213 {
214 if ( pMenuBar->GetMenu(i)->GetTitle() == pNode->GetData() )
215 pMenuBar->EnableTop( i, enable );
216 }
217
218 pNode = pNode->GetNext();
219 }
220}
221
222void wxFrameManager::SyncAllMenus()
223{
224 wxObjectList::compatibility_iterator pNode = mViews.GetFirst();
225 int i = 0;
226
227 while ( pNode )
228 {
229 if ( i != mActiveViewNo )
230
231 EnableMenusForView( (wxFrameView*)pNode->GetData(), false );
232
233 pNode = pNode->GetNext();
234 }
235
236 EnableMenusForView( GetView( mActiveViewNo ), true );
237}
238
239/*** public methods ***/
240
241wxFrameManager::wxFrameManager()
242
243 : mpFrameWnd( NULL ),
244 mActiveViewNo( -1 ),
245 mpClientWnd( NULL )
246{
247}
248
249wxFrameManager::~wxFrameManager()
250{
251 SaveViewsNow();
252 DestroyViews();
253}
254
255void wxFrameManager::Init( wxWindow* pMainFrame, const wxString& settingsFile )
256{
257 mSettingsFile = settingsFile;
258 mpFrameWnd = pMainFrame;
259
260 wxObjectList::compatibility_iterator pNode = mViews.GetFirst();
261
262 while ( pNode )
263 {
264 wxFrameView* pView = (wxFrameView*)pNode->GetData();
265
266 pView->OnInit();
267 pView->OnInitMenus();
268
269 pNode = pNode->GetNext();
270 }
271
272 if ( !ReloadViews() )
273 {
274 // if loading of settings file failed (e.g. was not found),
275 // do recreation of items in each view
276
277 pNode = mViews.GetFirst();
278
279 while ( pNode )
280 {
281 wxFrameView* pView = (wxFrameView*)pNode->GetData();
282
283 pView->OnRecreate();
284
285 pNode = pNode->GetNext();
286 }
287 }
288
289 if ( mActiveViewNo >= (int)mViews.GetCount() )
290 mActiveViewNo = -1;
291
292 ActivateView( GetView( ( mActiveViewNo == -1 ) ? 0 : mActiveViewNo ) );
293
294 SyncAllMenus();
295}
296
297void wxFrameManager::AddView( wxFrameView* pFrmView )
298{
299 mViews.Append( pFrmView );
300
301 pFrmView->mpFrameMgr = this; // back ref.
302}
303
304void wxFrameManager::RemoveView( wxFrameView* WXUNUSED(pFrmView) )
305{
306 // TBD::
307 wxFAIL_MSG( _T("wxFrameManager::RemoveView() has not been implemented yet.") );
308}
309
310int wxFrameManager::GetActiveViewNo()
311{
312 return mActiveViewNo;
313}
314
315wxFrameView* wxFrameManager::GetActiveView()
316{
317 wxObjectList::compatibility_iterator pNode = mViews.Item( mActiveViewNo );
318
319 if ( pNode ) return (wxFrameView*)pNode->GetData();
320 else return NULL;
321}
322
323wxObjectList::compatibility_iterator wxFrameManager::GetActiveViewNode()
324{
325 return mViews.Item( mActiveViewNo );
326}
327
328wxFrame* wxFrameManager::GetParentFrame()
329{
330 return ((wxFrame*)mpFrameWnd);
331}
332
333wxWindow* wxFrameManager::GetParentWindow()
334{
335 return mpFrameWnd;
336}
337
338wxFrameView* wxFrameManager::GetView( int viewNo )
339{
340 wxObjectList::compatibility_iterator pNode = mViews.Item( viewNo );
341
342 if ( pNode ) return (wxFrameView*)pNode->GetData();
343 else return NULL;
344}
345
346void wxFrameManager::ActivateView( int viewNo )
347{
348 ActivateView( GetView( viewNo ) );
349}
350
351void wxFrameManager::ActivateView( wxFrameView* pFrmView )
352{
353 DeactivateCurrentView();
354
355 mActiveViewNo = GetViewNo( pFrmView );
356
357 if ( pFrmView->mpLayout )
358
359 pFrmView->mpLayout->Activate();
360
361 // FIXME:: we would have used PushEventHandler(),
362 // but wxFrame bypasses attached handlers when
363 // handling wxCommand events!
364
365 GetParentFrame()->PushEventHandler( pFrmView );
366
367 EnableMenusForView( pFrmView, true );
368}
369
370void wxFrameManager::SetClinetWindow( wxWindow* pFrameClient )
371{
372 if ( mpClientWnd ) mpClientWnd->Destroy();
373
374 mpClientWnd = pFrameClient;
375}
376
377wxWindow* wxFrameManager::GetClientWindow()
378{
379 if ( !mpClientWnd )
380
381 mpClientWnd = new wxWindow( GetParentFrame(), -1 );
382
383 return mpClientWnd;
384}
385
386void wxFrameManager::DeactivateCurrentView()
387{
388 if ( mActiveViewNo == -1 )
389 return;
390
391 wxFrameView* pView = GetActiveView();
392
393 // FOR NOW::
394 wxASSERT( GetParentFrame()->GetEventHandler() == pView );
395
396 GetParentFrame()->PopEventHandler();
397
398 if ( pView->mpLayout )
399 pView->mpLayout->Deactivate();
400
401 EnableMenusForView( pView, false );
402}
403
404void wxFrameManager::SaveViewsNow()
405{
406#if 0
407 if ( mSettingsFile == "" ) return;
408
409 wxIOStreamWrapper stm;
410 stm.CreateForOutput( mSettingsFile );
411
412 mStore.SetDataStream( stm );
413 DoSerialize( mStore );
414#endif
415}
416
417bool wxFrameManager::ReloadViews()
418{
419 return false;
420
421 // TBD: ????
422#if 0
423 if ( mSettingsFile == "" || !wxFileExists( mSettingsFile ) )
424 return false;
425
426 DestroyViews();
427
428 wxIOStreamWrapper stm;
429 stm.CreateForInput( mSettingsFile );
430
431 mStore.SetDataStream( stm );
432 DoSerialize( mStore );
433
434 return true;
435#endif
436}
437
438bool wxFrameManager::ViewsAreLoaded()
439{
440 return ( mViews.GetCount() != 0 );
441}
442