1
//--------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2010 LenMus project
5
// This file is derived from file src/generic/mdig.cpp from wxWidgets 2.7.1 project.
6
// Author: Hans Van Leemputten
7
// Copyright (c) Hans Van Leemputten
12
// This program is free software; you can redistribute it and/or modify it under the
13
// terms of the GNU General Public License as published by the Free Software Foundation,
14
// either version 3 of the License, or (at your option) any later version.
16
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
// You should have received a copy of the GNU General Public License along with this
21
// program. If not, see <http://www.gnu.org/licenses/>.
23
// For any comment, suggestion or feature request, please contact the manager of
24
// the project at cecilios@users.sourceforge.net
26
//-------------------------------------------------------------------------------------
27
//----------------------------------------------------------------------------
28
// The main menu is fixed. Child window dosen't change it
30
// An MDI child frame is a frame that can only exist on a MDIClientWindow,
31
// which is itself a child of MDIParentFrame.
32
// It is going to be a notebook page, to contains either a score (lmEditFrame) or
33
// the eBookManager (lmTextBookFrame)
35
// The ChildFrame is created by the aplication (either the doc/view manager, for
36
// scores, or lmMainFrame, for the eBookManager) On creation, it must inform to
37
// ClientWindow. Is is responsibility of ClientWindow to manage the new Child and
38
// take control of it (i.e. add it to the notebook).
40
// The ChildFrame is deleted by the application. For scores, it is the doc/view
41
// manager, in response to a wxID_CLOSE event. The view deletes the ChildFrame.
42
// For eBooks, when the eBooksManager is closed by the MainFrame, it must delete
43
// the TextBookManager.
44
// The ChildFrame, on its destructor, informs the ClientWindow to manage the
45
// Child deletetion (i.e. to remove it form the Notebook).
49
//----------------------------------------------------------------------------
51
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
52
#pragma implementation "ChildFrame.h"
55
#include "../app/global.h"
58
// For compilers that support precompilation, includes <wx.h>.
59
#include <wx/wxprec.h>
66
#include "ParentFrame.h"
67
#include "ChildFrame.h"
68
#include "ClientWindow.h"
73
//-----------------------------------------------------------------------------
74
// lmTDIChildFrame implementation
75
//-----------------------------------------------------------------------------
77
IMPLEMENT_DYNAMIC_CLASS(lmTDIChildFrame, wxPanel)
79
BEGIN_EVENT_TABLE(lmTDIChildFrame, wxPanel)
80
EVT_CLOSE(lmTDIChildFrame::OnCloseWindow)
81
EVT_SIZE(lmTDIChildFrame::OnSize)
84
lmTDIChildFrame::lmTDIChildFrame()
89
lmTDIChildFrame::lmTDIChildFrame( lmTDIParentFrame *parent,
90
wxWindowID id, const wxString& title,
91
const wxPoint& WXUNUSED(pos), const wxSize& size,
92
long style, const wxString& name )
96
Create( parent, id, title, wxDefaultPosition, size, style, name );
99
lmTDIChildFrame::~lmTDIChildFrame()
101
//The Child frame has been deleted by the view.
102
//Inform the parent so that it can remove the tab form the Notebook
103
lmTDIParentFrame* pParentFrame = GetMDIParentFrame();
105
pParentFrame->RemoveChildFrame(this);
109
bool lmTDIChildFrame::Create( lmTDIParentFrame *parent,
110
wxWindowID id, const wxString& title,
111
const wxPoint& WXUNUSED(pos), const wxSize& size,
112
long style, const wxString& name )
114
lmTDIClientWindow* pClientWindow = parent->GetClientWindow();
116
wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), wxT("Missing MDI client window.") );
118
wxPanel::Create(pClientWindow, id, wxDefaultPosition, size, style, name);
120
SetMDIParentFrame(parent);
122
//// This is the currently active child
123
//parent->SetActiveChild(this);
127
pClientWindow->AddPage(this, title, true);
128
ApplyMDIChildFrameRect(); // Ok confirme the size change!
129
pClientWindow->Refresh();
135
void lmTDIChildFrame::SetTitle(const wxString& title)
139
lmTDIParentFrame *pParentFrame = GetMDIParentFrame();
141
if (pParentFrame != NULL)
143
lmTDIClientWindow * pClientWindow = pParentFrame->GetClientWindow();
145
if (pClientWindow != NULL)
148
for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
150
if (pClientWindow->GetPage(pos) == this)
152
pClientWindow->SetPageText(pos, m_Title);
160
wxString lmTDIChildFrame::GetTitle() const
165
void lmTDIChildFrame::Activate()
167
lmTDIParentFrame *pParentFrame = GetMDIParentFrame();
169
if (pParentFrame != NULL)
171
lmTDIClientWindow * pClientWindow = pParentFrame->GetClientWindow();
173
if (pClientWindow != NULL)
176
for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
178
if (pClientWindow->GetPage(pos) == this)
180
pClientWindow->SetSelection(pos);
188
/*** Copied from top level..! ***/
189
// default resizing behaviour - if only ONE subwindow, resize to fill the
191
void lmTDIChildFrame::OnSize(wxSizeEvent& WXUNUSED(event))
193
// if we're using constraints or sizers - do use them
194
if ( GetAutoLayout() )
200
// do we have _exactly_ one child?
201
wxWindow *child = (wxWindow *)NULL;
202
for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
204
node = node->GetNext() )
206
wxWindow *win = node->GetData();
208
// exclude top level and managed windows (status bar isn't
209
// currently in the children list except under wxMac anyhow, but
210
// it makes no harm to test for it)
211
if ( !win->IsTopLevel() /*&& !IsOneOfBars(win)*/ )
215
return; // it's our second subwindow - nothing to do
222
// do we have any children at all?
225
// exactly one child - set it's size to fill the whole frame
226
int clientW, clientH;
227
DoGetClientSize(&clientW, &clientH);
229
// for whatever reasons, wxGTK wants to have a small offset - it
230
// probably looks better with it?
232
static const int ofs = 1;
234
static const int ofs = 0;
237
child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
242
void lmTDIChildFrame::SetIcon(const wxIcon& icon)
245
lmTDIClientWindow* pNotebook = m_pMDIParentFrame->GetClientWindow();
247
//get index to this page
249
for (pos = 0; pos < pNotebook->GetPageCount(); pos++)
251
if (pNotebook->GetPage(pos) == this)
253
pNotebook->SetSelection(pos);
257
wxASSERT(pos < pNotebook->GetPageCount());
261
bitmap.CopyFromIcon(icon);
262
pNotebook->SetPageBitmap(pos, bitmap);
267
/*** Copied from top level..! ***/
268
// The default implementation for the close window event.
269
void lmTDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
274
void lmTDIChildFrame::SetMDIParentFrame(lmTDIParentFrame* parentFrame)
276
m_pMDIParentFrame = parentFrame;
279
lmTDIParentFrame* lmTDIChildFrame::GetMDIParentFrame() const
281
return m_pMDIParentFrame;
284
void lmTDIChildFrame::Init()
286
m_pMDIParentFrame = (lmTDIParentFrame *) NULL;
289
void lmTDIChildFrame::DoMoveWindow(int x, int y, int width, int height)
291
m_MDIRect = wxRect(x, y, width, height);
294
void lmTDIChildFrame::ApplyMDIChildFrameRect()
296
wxPanel::DoMoveWindow(m_MDIRect.x, m_MDIRect.y, m_MDIRect.width, m_MDIRect.height);