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