1
// RCS-ID: $Id: HtmlWindow.cpp,v 1.6 2006/02/25 15:15:59 cecilios Exp $
2
//--------------------------------------------------------------------------------------
3
// LenMus Phonascus: The teacher of music
4
// Copyright (c) 2002-2006 Cecilio Salmeron
6
// This program is free software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the Free Software Foundation;
8
// either version 2 of the License, or (at your option) any later version.
10
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License along with this
15
// program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
16
// Fifth Floor, Boston, MA 02110-1301, USA.
18
// For any comment, suggestion or feature request, please contact the manager of
19
// the project at cecilios@users.sourceforge.net
21
//-------------------------------------------------------------------------------------
22
/*! @file HtmlWindow.cpp
23
@brief Implementation file for class lmHtmlWindow
24
@ingroup html_management
26
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
27
#pragma implementation "HtmlWindow.h"
30
#include "wx/wxprec.h"
38
#include "HtmlWindow.h"
40
// access to textBookController
41
#include "../app/MainFrame.h"
42
extern lmMainFrame* g_pMainFrame;
45
/*! @page InternalLinks
47
<h2>Internal links: rationale and syntax</h2>
48
<!-- ====================================== -->
50
There are cases in which it is necessary to have links containing commands for the
51
program. For example, embbeding a SideReadingCtrol in side reading books is not a
52
good solution as normally there are two or more exercises associated to a lesson.
53
So, it is necessary to jump to a sideReading dialog customized
54
according exercises needs; and this dialog must have a "return to theory" link. All
55
these forward/backward links must be managed by the program, as well as the dynamic
56
generation of the html page.
58
Although wxHtmlHelpController Display() method deals with books, pages IDs and other
59
posibilities to specify the page to display, once a page is displayed the URLs specified
60
in \<a href=xx\> tags are normal links, that is, they will be interpreted as references
63
Then, for links in pages, it is required that either the relative path
64
is included or that all html pages are stored in the same folder. Moreover,
65
if .htb books (zip files) are used, the html page is only looked for inside
68
In order to allow for including
69
commands in an URL the OnLinkClicked() handler analyzes the requested URL, identifies
70
those for LenMus commnads, and execute them.
72
Normal URLs are only useful for links to html documents (not the case for this
73
application) or for links to other book pages. In this second case, either it
74
must be a reference to an html document including the relative path (not useful
75
when, as it is here the case, the pages of each book are in different folder).
76
And it does not work when the book is in zip format (.htb)
78
So, to allow for a method to refer to other books or to pages in other books the
79
following URL syntax is defined:
82
href="#[LenMusType]/[parm_1]/[parm_2]/.../[parm_n]
87
[LenMusType] - a string to identify the the link as an internal one and its type:
88
"LenMusPage" - a link to a page in this/other book
89
"LenMusEmbedded" - an html page embedded into the url
91
//"LenMusCmd" - a command for an embedded object (score, control, ...)
92
//"LenMusLink" - a command to close the book and open a window
94
The syntax for each type of internal link is as follows:
99
Format: #LenMusPage/[PageName.htm]
102
<a href="#LenMusPage/book3_page2.htm">Link to a page</a>
104
b) Embedded html content
105
------------------------
107
Format: #LenMusEmbedded/[html content using "{" and "}" instead of "<" and ">"]
110
<a href="#LenMusEmbedded/
113
{p}This is an example{/p}
115
">Link to an embedded page</a>
119
// c) LenMusCmd links
121
// href="#LenMusCmd/[ObjId]/[object]/[command]"
123
// [ObjId] - a number. It must be the index (0 based) for locating the object in
124
// the global array of embedded controls
125
// [object] - a string identifying object class, i.e. "TeoArmaduras", "TeoEscalas",
126
// "TeoIntervalos", "Solfeo", "OidoIntervalos", "OidoComparar"
127
// [command] - a string with the command name, optionally followed by parameters:
128
// [cmdName]/[parm_1]/[parm_2]/.../[parm_n]
130
// [cmdName] - a string with no blanks
131
// [parm_i] - a string with no blanks
135
// "#LenMusCmd/3/ScoreAuxCtrol/Play"
136
// "#LenMusCmd/3/ScoreAuxCtrol/PlayMeassure/5"
139
// The sytax for links is:
141
// href="#LenMusLink/[object]/[command]"
143
// [object] - a string identifying object class, i.e. "TeoArmaduras", "TeoEscalas",
144
// "TeoIntervalos", "Solfeo", "OidoIntervalos", "OidoComparar"
145
// [command] - a string with the command name, optionally followed by parameters:
146
// [cmdName]/[parm_1]/[parm_2]/.../[parm_n]
148
// [cmdName] - a string with no blanks
149
// [parm_i] - a string with no blanks
152
//<Phonascus migration notes>
153
// - Los enlaces de tipos D y P no son necesarios pues est�n cubiertos por la funcionalidad
154
// normal de un link html.
156
// - Los enlaces O corresponden a URLs de tipo LenMusCmd
157
// - Los enlaces T son un caso particular de los O
159
// - Los enlaces de tipo F corresponden a URLs de tipo LenMusLink
162
// ' Tipos de enlaces para etiquetas <a>
163
// ' -------------------------------------
164
// ' El primer caracter indica el tipo de enlace:
165
// ' D - link a otro documento
167
// ' D<documento>#<Ref.tema>
168
// ' F - link a un formulario
169
// ' F<nombre del formulario>
170
// ' O - orden para objeto empotrado
172
// ' P - link a otra p�gina de este documento
174
// ' T - Tocar partitura/compas
178
// ' <documento> = nombre archivo sin path ni extension. Ej: "Curso2Teoria"
179
// ' <Ref.tema> = <capitulo><seccion><tema>. Ej: "C1S2T17"
183
void lmHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
185
wxString sLocation = link.GetHref();
186
//verify if it is a LenMus command link
187
int iPos = sLocation.Find(wxT("#LenMus"));
188
if (iPos == wxNOT_FOUND) {
189
// normal link. Forward it to controller for normal processing
190
wxHtmlWindow::OnLinkClicked(link);
195
// lenMus internal link processing
198
//wxLogMessage(_T("[lmHtmlWindow::OnLinkClicked] Internal link. url <%s>"), sLocation);
201
// analyze command type and process it
204
// embedded html content: an html page embedded into the url
205
// Format: #LenMusEmbedded/[html content using "{" and "}" instead of "<" and ">"]
206
wxString sTag = _T("#LenMusEmbedded/");
207
iPos = sLocation.Find(sTag);
208
if (iPos != wxNOT_FOUND) {
210
wxString sContent = sLocation.Mid(sTag.Len());
212
// replace "{" and "}" by "<" and ">", respectively
213
sContent.Replace(_T("{"), _T("<"));
214
sContent.Replace(_T("}"), _T(">"));
215
//wxLogMessage(_T("[lmHtmlWindow::OnLinkClicked] Embedded content = %s"), sContent);
217
// show the embedded page
222
// link to an html page in this/other book
223
// Format: #LenMusPage/[PageName.htm]
224
sTag = _T("#LenMusPage/");
225
iPos = sLocation.Find(sTag);
226
if (iPos != wxNOT_FOUND) {
228
wxString sPageName = sLocation.Mid(sTag.Len());
230
// get text book controller
231
lmTextBookController* pBook = g_pMainFrame->GetBookController();
233
// jump to the requested page
234
//wxLogMessage(_T("[lmHtmlWindow::OnLinkClicked] Display PageName <%s>"), sPageName);
235
pBook->Display(sPageName);
240
wxString sMsg = wxString::Format(_T("Bad syntax in link href <%s>"), sLocation);
241
wxLogMessage(_T("[lmHtmlWindow::OnLinkClicked] %s"), sMsg);
242
return; // ignore the link