~s-cecilio/lenmus/v5.3

« back to all changes in this revision

Viewing changes to src/app/WelcomeWnd.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 program is free software; you can redistribute it and/or modify it under the
6
 
//    terms of the GNU General Public License as published by the Free Software Foundation,
7
 
//    either version 3 of the License, or (at your option) any later version.
8
 
//
9
 
//    This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
 
//    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
 
//    PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12
 
//
13
 
//    You should have received a copy of the GNU General Public License along with this
14
 
//    program. If not, see <http://www.gnu.org/licenses/>.
15
 
//
16
 
//    For any comment, suggestion or feature request, please contact the manager of
17
 
//    the project at cecilios@users.sourceforge.net
18
 
//
19
 
//-------------------------------------------------------------------------------------
20
 
 
21
 
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
22
 
#pragma implementation "WelcomeWnd.h"
23
 
#endif
24
 
 
25
 
// For compilers that support precompilation, includes <wx/wx.h>.
26
 
#include <wx/wxprec.h>
27
 
 
28
 
#ifdef __BORLANDC__
29
 
#pragma hdrstop
30
 
#endif
31
 
 
32
 
#ifndef WX_PRECOMP
33
 
#include <wx/wx.h>
34
 
#endif
35
 
 
36
 
#include <wx/hyperlink.h>
37
 
 
38
 
#include "WelcomeWnd.h"
39
 
#include "TheApp.h"         //to get access to locale info.
40
 
#include "ArtProvider.h"        // to use ArtProvider for managing icons
41
 
//access to MainFrame
42
 
#include "../app/MainFrame.h"
43
 
extern lmMainFrame* g_pMainFrame;
44
 
 
45
 
// Paths names
46
 
#include "../globals/Paths.h"
47
 
extern lmPaths* g_pPaths;
48
 
 
49
 
//IDs for controls
50
 
const int lmLINK_NewInLenmus = wxNewId();
51
 
const int lmLINK_NewScore = wxNewId();
52
 
const int lmLINK_QuickGuide = wxNewId();
53
 
const int lmLINK_OpenEBooks = wxNewId();
54
 
const int lmLINK_Recent1 = wxNewId();
55
 
const int lmLINK_Recent2 = wxNewId();
56
 
const int lmLINK_Recent3 = wxNewId();
57
 
const int lmLINK_Recent4 = wxNewId();
58
 
const int lmLINK_Recent5 = wxNewId();
59
 
const int lmLINK_Recent6 = wxNewId();
60
 
const int lmLINK_Recent7 = wxNewId();
61
 
const int lmLINK_Recent8 = wxNewId();
62
 
const int lmLINK_Recent9 = wxNewId();
63
 
 
64
 
 
65
 
BEGIN_EVENT_TABLE(lmWelcomeWnd, lmTDIChildFrame)
66
 
    EVT_HYPERLINK   (lmLINK_NewInLenmus, lmWelcomeWnd::OnNewInLenmus)
67
 
    EVT_HYPERLINK   (lmLINK_NewScore, lmWelcomeWnd::OnNewScore)
68
 
    EVT_HYPERLINK   (lmLINK_QuickGuide, lmWelcomeWnd::OnQuickGuide)
69
 
    EVT_HYPERLINK   (lmLINK_OpenEBooks, lmWelcomeWnd::OnOpenEBooks)
70
 
    EVT_HYPERLINK   (lmLINK_Recent1, lmWelcomeWnd::OnOpenRecent)
71
 
    EVT_HYPERLINK   (lmLINK_Recent2, lmWelcomeWnd::OnOpenRecent)
72
 
    EVT_HYPERLINK   (lmLINK_Recent3, lmWelcomeWnd::OnOpenRecent)
73
 
    EVT_HYPERLINK   (lmLINK_Recent4, lmWelcomeWnd::OnOpenRecent)
74
 
    EVT_HYPERLINK   (lmLINK_Recent5, lmWelcomeWnd::OnOpenRecent)
75
 
    EVT_HYPERLINK   (lmLINK_Recent6, lmWelcomeWnd::OnOpenRecent)
76
 
    EVT_HYPERLINK   (lmLINK_Recent7, lmWelcomeWnd::OnOpenRecent)
77
 
    EVT_HYPERLINK   (lmLINK_Recent8, lmWelcomeWnd::OnOpenRecent)
78
 
    EVT_HYPERLINK   (lmLINK_Recent9, lmWelcomeWnd::OnOpenRecent)
79
 
    EVT_CLOSE       (lmWelcomeWnd::OnCloseWindow)
80
 
END_EVENT_TABLE()
81
 
 
82
 
IMPLEMENT_CLASS(lmWelcomeWnd, lmTDIChildFrame)
83
 
 
84
 
 
85
 
lmWelcomeWnd::lmWelcomeWnd(wxWindow* parent, wxWindowID id)
86
 
    : lmTDIChildFrame((lmTDIParentFrame*)parent, id, _("Welcome"))
87
 
{
88
 
    //get recent open files history and get number of files saved
89
 
    wxFileHistory* pHistory = g_pMainFrame->GetFileHistory();
90
 
    int nRecentFiles = pHistory->GetCount();
91
 
        CreateControls(nRecentFiles, pHistory);
92
 
 
93
 
    this->SetBackgroundColour(*wxWHITE);
94
 
 
95
 
    //in linux, links background must also be changed
96
 
        m_pLinkNewInLenmus->SetBackgroundColour(*wxWHITE);
97
 
        m_pLinkVisitWebsite->SetBackgroundColour(*wxWHITE);
98
 
        m_pLinkOpenEBooks->SetBackgroundColour(*wxWHITE);
99
 
    m_pLinkQuickGuide->SetBackgroundColour(*wxWHITE);
100
 
        m_pLinkNewScore->SetBackgroundColour(*wxWHITE);
101
 
    for (int i=0; i < nRecentFiles; i++)
102
 
            m_pLinkRecent[i]->SetBackgroundColour(*wxWHITE);
103
 
 
104
 
    //load icons
105
 
    m_pLearnIcon->SetBitmap( wxArtProvider::GetIcon(_T("welcome_news"), wxART_OTHER) );
106
 
    m_pScoreIcon->SetBitmap( wxArtProvider::GetIcon(_T("welcome_editor"), wxART_OTHER) );
107
 
    m_pPhonascusIcon->SetBitmap( wxArtProvider::GetIcon(_T("welcome_theory"), wxART_OTHER) );
108
 
    m_pBmpLeftBanner->SetBitmap( wxArtProvider::GetIcon(_T("welcome_left"), wxART_OTHER) );
109
 
 
110
 
    this->Refresh();
111
 
}
112
 
 
113
 
void lmWelcomeWnd::CreateControls(int nRecentFiles, wxFileHistory* pHistory)
114
 
{
115
 
    //Controls creation for WelcomeWnd
116
 
 
117
 
        this->SetSizeHints( wxDefaultSize, wxDefaultSize );
118
 
 
119
 
        wxBoxSizer* pMainSizer;
120
 
        pMainSizer = new wxBoxSizer( wxHORIZONTAL );
121
 
 
122
 
        wxBoxSizer* pLeftBannerSizer;
123
 
        pLeftBannerSizer = new wxBoxSizer( wxHORIZONTAL );
124
 
 
125
 
        m_pBmpLeftBanner = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 165,773 ), 0 );
126
 
        pLeftBannerSizer->Add( m_pBmpLeftBanner, 0, 0, 5 );
127
 
 
128
 
        pMainSizer->Add( pLeftBannerSizer, 0, wxEXPAND, 20 );
129
 
 
130
 
        wxBoxSizer* pContentSizer;
131
 
        pContentSizer = new wxBoxSizer( wxHORIZONTAL );
132
 
 
133
 
 
134
 
        pContentSizer->Add( 0, 0, 1, wxEXPAND, 5 );
135
 
 
136
 
        wxBoxSizer* pItemsSizer;
137
 
        pItemsSizer = new wxBoxSizer( wxVERTICAL );
138
 
 
139
 
        wxBoxSizer* pHeadersSizer;
140
 
        pHeadersSizer = new wxBoxSizer( wxHORIZONTAL );
141
 
 
142
 
 
143
 
        pHeadersSizer->Add( 40, 0, 1, 0, 5 );
144
 
 
145
 
        m_pTxtTitle = new wxStaticText( this, wxID_ANY, _("Welcome to LenMus"), wxDefaultPosition, wxDefaultSize, 0 );
146
 
        m_pTxtTitle->Wrap( -1 );
147
 
        m_pTxtTitle->SetFont( wxFont( 16, 74, 90, 92, false, wxT("Tahoma") ) );
148
 
 
149
 
        pHeadersSizer->Add( m_pTxtTitle, 0, wxALL, 5 );
150
 
 
151
 
 
152
 
        pHeadersSizer->Add( 40, 0, 1, 0, 5 );
153
 
 
154
 
        pItemsSizer->Add( pHeadersSizer, 1, wxEXPAND, 5 );
155
 
 
156
 
        wxBoxSizer* pLearnSizer;
157
 
        pLearnSizer = new wxBoxSizer( wxVERTICAL );
158
 
 
159
 
        m_pLearnTitle = new wxStaticText( this, wxID_ANY, _("Learn about LenMus"), wxDefaultPosition, wxDefaultSize, 0 );
160
 
        m_pLearnTitle->Wrap( -1 );
161
 
        m_pLearnTitle->SetFont( wxFont( 10, 74, 90, 92, false, wxT("Tahoma") ) );
162
 
 
163
 
        pLearnSizer->Add( m_pLearnTitle, 0, wxALL, 5 );
164
 
 
165
 
        wxBoxSizer* pLearnSubsizer;
166
 
        pLearnSubsizer = new wxBoxSizer( wxHORIZONTAL );
167
 
 
168
 
        m_pLearnIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(45, 45), 0 );
169
 
        pLearnSubsizer->Add( m_pLearnIcon, 0, wxALL, 5 );
170
 
 
171
 
        wxBoxSizer* pLearnLinksSizer;
172
 
        pLearnLinksSizer = new wxBoxSizer( wxVERTICAL );
173
 
 
174
 
        m_pLinkNewInLenmus = new wxHyperlinkCtrl( this, lmLINK_NewInLenmus, _("What's is new in LenMus"), wxT("http://www.lenmus.org"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
175
 
        pLearnLinksSizer->Add( m_pLinkNewInLenmus, 0, wxRIGHT|wxLEFT, 5 );
176
 
 
177
 
        m_pLinkVisitWebsite = new wxHyperlinkCtrl( this, wxID_ANY, _("Visit LenMus website"), wxT("http://www.lenmus.org"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
178
 
        pLearnLinksSizer->Add( m_pLinkVisitWebsite, 0, wxRIGHT|wxLEFT, 5 );
179
 
 
180
 
        pLearnSubsizer->Add( pLearnLinksSizer, 1, wxEXPAND|wxLEFT, 10 );
181
 
 
182
 
        pLearnSizer->Add( pLearnSubsizer, 1, wxEXPAND, 5 );
183
 
 
184
 
        pItemsSizer->Add( pLearnSizer, 0, wxTOP|wxRIGHT|wxLEFT, 20 );
185
 
 
186
 
        wxBoxSizer* pPhonascusSizer;
187
 
        pPhonascusSizer = new wxBoxSizer( wxVERTICAL );
188
 
 
189
 
        m_pPhonascusTitle = new wxStaticText( this, wxID_ANY, _("Learn and practise music theory"), wxDefaultPosition, wxDefaultSize, 0 );
190
 
        m_pPhonascusTitle->Wrap( -1 );
191
 
        m_pPhonascusTitle->SetFont( wxFont( 10, 74, 90, 92, false, wxT("Tahoma") ) );
192
 
 
193
 
        pPhonascusSizer->Add( m_pPhonascusTitle, 0, wxALL, 5 );
194
 
 
195
 
        wxBoxSizer* pPhonascusSubsizer;
196
 
        pPhonascusSubsizer = new wxBoxSizer( wxHORIZONTAL );
197
 
 
198
 
        m_pPhonascusIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(45, 45), 0 );
199
 
        pPhonascusSubsizer->Add( m_pPhonascusIcon, 0, wxALL, 5 );
200
 
 
201
 
        wxBoxSizer* pPhonascusLinksSizer;
202
 
        pPhonascusLinksSizer = new wxBoxSizer( wxVERTICAL );
203
 
 
204
 
        m_pLinkOpenEBooks = new wxHyperlinkCtrl( this, lmLINK_OpenEBooks, _("Open eMusicBooks "), wxT("http://www.lenmus.org"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
205
 
        pPhonascusLinksSizer->Add( m_pLinkOpenEBooks, 0, wxRIGHT|wxLEFT, 5 );
206
 
 
207
 
        pPhonascusSubsizer->Add( pPhonascusLinksSizer, 1, wxEXPAND|wxLEFT, 10 );
208
 
 
209
 
        pPhonascusSizer->Add( pPhonascusSubsizer, 1, wxEXPAND, 5 );
210
 
 
211
 
        pItemsSizer->Add( pPhonascusSizer, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 20 );
212
 
 
213
 
        wxBoxSizer* pScoreSizer;
214
 
        pScoreSizer = new wxBoxSizer( wxVERTICAL );
215
 
 
216
 
        m_pScoreTitle = new wxStaticText( this, wxID_ANY, _("Create and edit music scores (beta 0 version)"), wxDefaultPosition, wxDefaultSize, 0 );
217
 
        m_pScoreTitle->Wrap( -1 );
218
 
        m_pScoreTitle->SetFont( wxFont( 10, 74, 90, 92, false, wxT("Tahoma") ) );
219
 
 
220
 
        pScoreSizer->Add( m_pScoreTitle, 0, wxALL, 5 );
221
 
 
222
 
        wxBoxSizer* pScoreSubsizer;
223
 
        pScoreSubsizer = new wxBoxSizer( wxHORIZONTAL );
224
 
 
225
 
        m_pScoreIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(45, 45), 0 );
226
 
        pScoreSubsizer->Add( m_pScoreIcon, 0, wxALL, 5 );
227
 
 
228
 
        wxBoxSizer* pScoreLinksSizer;
229
 
        pScoreLinksSizer = new wxBoxSizer( wxVERTICAL );
230
 
 
231
 
        m_pLinkNewScore = new wxHyperlinkCtrl( this, lmLINK_NewScore, _("New score ..."), wxT("http://www.lenmus.org"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
232
 
        pScoreLinksSizer->Add( m_pLinkNewScore, 0, wxRIGHT|wxLEFT, 5 );
233
 
 
234
 
        m_pLinkQuickGuide = new wxHyperlinkCtrl( this, lmLINK_QuickGuide, _("Editor quick guide"), wxT("http://www.lenmus.org"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
235
 
        pScoreLinksSizer->Add( m_pLinkQuickGuide, 0, wxRIGHT|wxLEFT, 5 );
236
 
 
237
 
        wxBoxSizer* pRecentScoresSizer;
238
 
        pRecentScoresSizer = new wxBoxSizer( wxVERTICAL );
239
 
 
240
 
        m_pRecentScoresTitle = new wxStaticText( this, wxID_ANY, _("Recent scores"), wxDefaultPosition, wxDefaultSize, 0 );
241
 
        m_pRecentScoresTitle->Wrap( -1 );
242
 
        m_pRecentScoresTitle->SetFont( wxFont( 10, 74, 90, 92, false, wxT("Tahoma") ) );
243
 
 
244
 
        pRecentScoresSizer->Add( m_pRecentScoresTitle, 0, wxRIGHT|wxLEFT, 5 );
245
 
 
246
 
        wxBoxSizer* pRecentScoresLinksSizer;
247
 
        pRecentScoresLinksSizer = new wxBoxSizer( wxHORIZONTAL );
248
 
 
249
 
 
250
 
        pRecentScoresLinksSizer->Add( 40, 0, 0, 0, 5 );
251
 
 
252
 
        wxBoxSizer* pRecentScoresLinksSizer1;
253
 
        pRecentScoresLinksSizer1 = new wxBoxSizer( wxVERTICAL );
254
 
 
255
 
    for (int i=0; i < nRecentFiles; i++)
256
 
    {
257
 
            m_pLinkRecent[i] =
258
 
            new wxHyperlinkCtrl(this, lmLINK_Recent1+i, pHistory->GetHistoryFile(i),
259
 
                                pHistory->GetHistoryFile(i), wxDefaultPosition, wxDefaultSize,
260
 
                                wxHL_DEFAULT_STYLE);
261
 
            pRecentScoresLinksSizer1->Add( m_pLinkRecent[i], 0, wxRIGHT|wxLEFT, 5 );
262
 
    }
263
 
 
264
 
        pRecentScoresLinksSizer->Add( pRecentScoresLinksSizer1, 1, wxEXPAND, 5 );
265
 
 
266
 
        pRecentScoresSizer->Add( pRecentScoresLinksSizer, 0, wxEXPAND, 5 );
267
 
 
268
 
        pScoreLinksSizer->Add( pRecentScoresSizer, 1, wxEXPAND|wxTOP, 5 );
269
 
 
270
 
        pScoreSubsizer->Add( pScoreLinksSizer, 1, wxEXPAND|wxLEFT, 10 );
271
 
 
272
 
        pScoreSizer->Add( pScoreSubsizer, 1, wxEXPAND, 5 );
273
 
 
274
 
        pItemsSizer->Add( pScoreSizer, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 20 );
275
 
 
276
 
        pContentSizer->Add( pItemsSizer, 6, 0, 5 );
277
 
 
278
 
 
279
 
        pContentSizer->Add( 0, 0, 1, wxEXPAND, 5 );
280
 
 
281
 
        pMainSizer->Add( pContentSizer, 1, wxEXPAND|wxTOP, 20 );
282
 
 
283
 
        this->SetSizer( pMainSizer );
284
 
        this->Layout();
285
 
}
286
 
 
287
 
lmWelcomeWnd::~lmWelcomeWnd()
288
 
{
289
 
}
290
 
 
291
 
void lmWelcomeWnd::OnNewInLenmus(wxHyperlinkEvent& event)
292
 
{
293
 
#if 1   //1 = as html page, 0= as eBook
294
 
    wxString sDoc = _T("release_notes.htm");
295
 
    ShowDocument(sDoc);
296
 
#else
297
 
    g_pMainFrame->OpenBook(_T("release_notes_1.htm"));
298
 
#endif
299
 
}
300
 
 
301
 
void lmWelcomeWnd::OnQuickGuide(wxHyperlinkEvent& event)
302
 
{
303
 
    wxString sDoc = _T("editor_quick_guide.htm");
304
 
    ShowDocument(sDoc);
305
 
}
306
 
 
307
 
void lmWelcomeWnd::ShowDocument(wxString& sDocName)
308
 
{
309
 
    wxString sPath = g_pPaths->GetLocalePath();
310
 
    wxFileName oFile(sPath, sDocName, wxPATH_NATIVE);
311
 
        if (!oFile.FileExists())
312
 
        {
313
 
                //use english version
314
 
                sPath = g_pPaths->GetLocaleRootPath();
315
 
                oFile.AssignDir(sPath);
316
 
                oFile.AppendDir(_T("en"));
317
 
                oFile.SetFullName(sDocName);
318
 
        }
319
 
    ::wxLaunchDefaultBrowser( oFile.GetFullPath() );
320
 
}
321
 
 
322
 
void lmWelcomeWnd::OnNewScore(wxHyperlinkEvent& event)
323
 
{
324
 
    wxCommandEvent myEvent;     //It is not used. So I do not initialize it
325
 
    g_pMainFrame->OnScoreWizard(myEvent);
326
 
}
327
 
 
328
 
void lmWelcomeWnd::OnOpenEBooks(wxHyperlinkEvent& event)
329
 
{
330
 
    wxCommandEvent myEvent;     //It is not used. So I do not initialize it
331
 
    g_pMainFrame->OnOpenBook(myEvent);
332
 
}
333
 
 
334
 
void lmWelcomeWnd::OnOpenRecent(wxHyperlinkEvent& event)
335
 
{
336
 
    wxString sFile = m_pLinkRecent[event.GetId() - lmLINK_Recent1]->GetURL();
337
 
    g_pMainFrame->OpenScore(sFile, false);    //false: it is not a new file
338
 
}
339
 
 
340
 
void lmWelcomeWnd::OnCloseWindow(wxCloseEvent& event)
341
 
{
342
 
    //inform parent
343
 
    g_pMainFrame->OnCloseWelcomeWnd();
344
 
 
345
 
    event.Skip();   //allow to continue
346
 
}
347
 
 
348