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