~s-cecilio/lenmus/v5.1.x

« back to all changes in this revision

Viewing changes to src/mdi/ChildFrame.cpp

  • Committer: cecilios
  • Date: 2011-06-12 17:25:18 UTC
  • Revision ID: svn-v4:2587a929-2f0e-0410-ae78-fe6f687d5efe:branches/TRY-5.0:687
Initial update for v5.0 first working core using lomse

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//--------------------------------------------------------------------------------------
2
 
//    LenMus Phonascus: The teacher of music
3
 
//    Copyright (c) 2002-2010 LenMus project
4
 
//
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
8
 
//
9
 
//    Modified by:
10
 
//        Cecilio Salmeron
11
 
//
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.
15
 
//
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.
19
 
//
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/>.
22
 
//
23
 
//    For any comment, suggestion or feature request, please contact the manager of
24
 
//    the project at cecilios@users.sourceforge.net
25
 
//
26
 
//-------------------------------------------------------------------------------------
27
 
//----------------------------------------------------------------------------
28
 
// The main menu is fixed. Child window dosen't change it
29
 
 
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)
34
 
//
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).
39
 
 
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).
46
 
//
47
 
//
48
 
 
49
 
//----------------------------------------------------------------------------
50
 
 
51
 
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
52
 
#pragma implementation "ChildFrame.h"
53
 
#endif
54
 
 
55
 
#include "../app/global.h"
56
 
 
57
 
 
58
 
// For compilers that support precompilation, includes <wx.h>.
59
 
#include <wx/wxprec.h>
60
 
 
61
 
#ifdef __BORLANDC__
62
 
    #pragma hdrstop
63
 
#endif
64
 
 
65
 
 
66
 
#include "ParentFrame.h"
67
 
#include "ChildFrame.h"
68
 
#include "ClientWindow.h"
69
 
 
70
 
#include <wx/panel.h>
71
 
#include <wx/menu.h>
72
 
 
73
 
//-----------------------------------------------------------------------------
74
 
// lmTDIChildFrame implementation
75
 
//-----------------------------------------------------------------------------
76
 
 
77
 
IMPLEMENT_DYNAMIC_CLASS(lmTDIChildFrame, wxPanel)
78
 
 
79
 
BEGIN_EVENT_TABLE(lmTDIChildFrame, wxPanel)
80
 
    EVT_CLOSE(lmTDIChildFrame::OnCloseWindow)
81
 
    EVT_SIZE(lmTDIChildFrame::OnSize)
82
 
END_EVENT_TABLE()
83
 
 
84
 
lmTDIChildFrame::lmTDIChildFrame()
85
 
{
86
 
    Init();
87
 
}
88
 
 
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 )
93
 
{
94
 
    Init();
95
 
 
96
 
    Create( parent, id, title, wxDefaultPosition, size, style, name );
97
 
}
98
 
 
99
 
lmTDIChildFrame::~lmTDIChildFrame()
100
 
{
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();
104
 
    if (pParentFrame)
105
 
        pParentFrame->RemoveChildFrame(this);
106
 
 
107
 
}
108
 
 
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 )
113
 
{
114
 
    lmTDIClientWindow* pClientWindow = parent->GetClientWindow();
115
 
 
116
 
    wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), wxT("Missing MDI client window.") );
117
 
 
118
 
    wxPanel::Create(pClientWindow, id, wxDefaultPosition, size, style, name);
119
 
 
120
 
    SetMDIParentFrame(parent);
121
 
 
122
 
    //// This is the currently active child
123
 
    //parent->SetActiveChild(this);
124
 
 
125
 
    m_Title = title;
126
 
 
127
 
    pClientWindow->AddPage(this, title, true);
128
 
    ApplyMDIChildFrameRect();   // Ok confirme the size change!
129
 
    pClientWindow->Refresh();
130
 
 
131
 
    return true;
132
 
}
133
 
 
134
 
 
135
 
void lmTDIChildFrame::SetTitle(const wxString& title)
136
 
{
137
 
    m_Title = title;
138
 
 
139
 
    lmTDIParentFrame *pParentFrame = GetMDIParentFrame();
140
 
 
141
 
    if (pParentFrame != NULL)
142
 
    {
143
 
        lmTDIClientWindow * pClientWindow = pParentFrame->GetClientWindow();
144
 
 
145
 
        if (pClientWindow != NULL)
146
 
        {
147
 
            size_t pos;
148
 
            for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
149
 
            {
150
 
                if (pClientWindow->GetPage(pos) == this)
151
 
                {
152
 
                    pClientWindow->SetPageText(pos, m_Title);
153
 
                    break;
154
 
                }
155
 
            }
156
 
        }
157
 
    }
158
 
}
159
 
 
160
 
wxString lmTDIChildFrame::GetTitle() const
161
 
{
162
 
    return m_Title;
163
 
}
164
 
 
165
 
void lmTDIChildFrame::Activate()
166
 
{
167
 
    lmTDIParentFrame *pParentFrame = GetMDIParentFrame();
168
 
 
169
 
    if (pParentFrame != NULL)
170
 
    {
171
 
        lmTDIClientWindow * pClientWindow = pParentFrame->GetClientWindow();
172
 
 
173
 
        if (pClientWindow != NULL)
174
 
        {
175
 
            size_t pos;
176
 
            for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
177
 
            {
178
 
                if (pClientWindow->GetPage(pos) == this)
179
 
                {
180
 
                    pClientWindow->SetSelection(pos);
181
 
                    break;
182
 
                }
183
 
            }
184
 
        }
185
 
    }
186
 
}
187
 
 
188
 
/*** Copied from top level..! ***/
189
 
// default resizing behaviour - if only ONE subwindow, resize to fill the
190
 
// whole client area
191
 
void lmTDIChildFrame::OnSize(wxSizeEvent& WXUNUSED(event))
192
 
{
193
 
    // if we're using constraints or sizers - do use them
194
 
    if ( GetAutoLayout() )
195
 
    {
196
 
        Layout();
197
 
    }
198
 
    else
199
 
    {
200
 
        // do we have _exactly_ one child?
201
 
        wxWindow *child = (wxWindow *)NULL;
202
 
        for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
203
 
              node;
204
 
              node = node->GetNext() )
205
 
        {
206
 
            wxWindow *win = node->GetData();
207
 
 
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)*/ )
212
 
            {
213
 
                if ( child )
214
 
                {
215
 
                    return;     // it's our second subwindow - nothing to do
216
 
                }
217
 
 
218
 
                child = win;
219
 
            }
220
 
        }
221
 
 
222
 
        // do we have any children at all?
223
 
        if ( child )
224
 
        {
225
 
            // exactly one child - set it's size to fill the whole frame
226
 
            int clientW, clientH;
227
 
            DoGetClientSize(&clientW, &clientH);
228
 
 
229
 
            // for whatever reasons, wxGTK wants to have a small offset - it
230
 
            // probably looks better with it?
231
 
#ifdef _LM_LINUX_
232
 
            static const int ofs = 1;
233
 
#else
234
 
            static const int ofs = 0;
235
 
#endif
236
 
 
237
 
            child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
238
 
        }
239
 
    }
240
 
}
241
 
 
242
 
void lmTDIChildFrame::SetIcon(const wxIcon& icon)
243
 
{
244
 
 
245
 
    lmTDIClientWindow* pNotebook = m_pMDIParentFrame->GetClientWindow();
246
 
 
247
 
    //get index to this page
248
 
    size_t pos;
249
 
    for (pos = 0; pos < pNotebook->GetPageCount(); pos++)
250
 
    {
251
 
        if (pNotebook->GetPage(pos) == this)
252
 
        {
253
 
            pNotebook->SetSelection(pos);
254
 
            break;
255
 
        }
256
 
    }
257
 
    wxASSERT(pos < pNotebook->GetPageCount());
258
 
 
259
 
    //set bitmap
260
 
    wxBitmap bitmap;
261
 
    bitmap.CopyFromIcon(icon);
262
 
    pNotebook->SetPageBitmap(pos, bitmap);
263
 
 
264
 
}
265
 
 
266
 
 
267
 
/*** Copied from top level..! ***/
268
 
// The default implementation for the close window event.
269
 
void lmTDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
270
 
{
271
 
    Destroy();
272
 
}
273
 
 
274
 
void lmTDIChildFrame::SetMDIParentFrame(lmTDIParentFrame* parentFrame)
275
 
{
276
 
    m_pMDIParentFrame = parentFrame;
277
 
}
278
 
 
279
 
lmTDIParentFrame* lmTDIChildFrame::GetMDIParentFrame() const
280
 
{
281
 
    return m_pMDIParentFrame;
282
 
}
283
 
 
284
 
void lmTDIChildFrame::Init()
285
 
{
286
 
    m_pMDIParentFrame = (lmTDIParentFrame *) NULL;
287
 
}
288
 
 
289
 
void lmTDIChildFrame::DoMoveWindow(int x, int y, int width, int height)
290
 
{
291
 
    m_MDIRect = wxRect(x, y, width, height);
292
 
}
293
 
 
294
 
void lmTDIChildFrame::ApplyMDIChildFrameRect()
295
 
{
296
 
    wxPanel::DoMoveWindow(m_MDIRect.x, m_MDIRect.y, m_MDIRect.width, m_MDIRect.height);
297
 
}