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