NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
helpviewer.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2017 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20
21#include "helpviewer.hpp"
22#include "../documentationbrowser.hpp"
23#include "../NumeReWindow.h"
24#include <wx/html/htmprint.h>
25
26extern wxPrintData* g_printData;
27extern wxPageSetupData* g_pageSetupData;
28
29
30BEGIN_EVENT_TABLE(HelpViewer, wxHtmlWindow)
31 EVT_KEY_DOWN (HelpViewer::OnKeyDown)
32// EVT_ENTER_WINDOW (HelpViewer::OnEnter)
33 EVT_HTML_LINK_CLICKED(-1, HelpViewer::OnLinkClick)
35
36
37
45bool HelpViewer::SetPage(const wxString& source)
46{
47 if (!vHistory.size())
48 vHistory.push_back(source);
49
50 bool res = wxHtmlWindow::SetPage(source);
51 m_browser->setCurrentTabText(GetOpenedPageTitle());
52
53 return res;
54}
55
56
67bool HelpViewer::ShowPageOnItem(wxString docID)
68{
69 wxString pageContent;
70 bool openself = true;
71
72 // Determine the type of the content: is it a link, a html page
73 // or a search keyword
74 if (docID.substr(0,10) == "history://")
75 {
76 // History link: only for legacy reasons
77 //if (docID.find("?frame=new") != string::npos)
78 // openself = false;
79
80 docID.erase(0,10);
81
82 if (docID.find('?') != std::string::npos)
83 docID.erase(docID.find('?'));
84
85 // Redirect to the corresponding public interface functions
86 if (docID == "back")
87 {
88 return HistoryGoBack();
89 }
90 else if (docID == "forward")
91 {
92 return HistoryGoForward();
93 }
94 else
95 return false;
96 }
97 else if (docID.substr(0,7) == "nhlp://")
98 {
99 // Regular link
100 //
101 // Determine first, if the link shall be opened in the current
102 // window or in a new one
103 if (docID.find("?frame=new") != std::string::npos)
104 openself = false;
105
106 // Extract the search keyword from the link
107 docID.erase(0,7);
108
109 if (docID.find('?') != std::string::npos)
110 docID.erase(docID.find('?'));
111
112 // If the target is not the current window, redirect the the
113 // link to the main window, which will create a new window
114 if (!openself)
115 return m_browser->createNewPage(docID);
116
117 // Get the page content from the kernel
118 pageContent = m_mainFrame->GetDocContent(docID);
119
120 if (!pageContent.length())
121 return false;
122
123 // Open the page
124 if (m_nHistoryPointer+1 != vHistory.size())
125 {
126 // erase the obsolete history
127 vHistory.erase(vHistory.begin()+1+m_nHistoryPointer, vHistory.end());
128 }
129
130 vHistory.push_back(docID);
132 this->SetPage(pageContent);
133 }
134 else if (docID.substr(0,15) == "<!DOCTYPE html>")
135 {
136 // This is a html page, display it directly
137 this->SetPage(docID);
138 }
139 else if (docID.find("://") == std::string::npos)
140 {
141 // This is a search keyword, get the contents from
142 // the kernel
143 pageContent = m_mainFrame->GetDocContent(docID);
144
145 if (!pageContent.length())
146 return false;
147
148 // Display the page
149 if (m_nHistoryPointer+1 != vHistory.size() && vHistory.size())
150 {
151 // erase the obsolete history
152 vHistory.erase(vHistory.begin()+1+m_nHistoryPointer, vHistory.end());
153 }
154
155 if (vHistory.size())
156 {
157 vHistory.push_back(docID);
159 }
160
161 this->SetPage(pageContent);
162 }
163 else
164 return false;
165
166 return true;
167}
168
169
178{
180 {
181 // Get the content of the history and decrement the pointer
182 wxString pageContent = vHistory[m_nHistoryPointer-1];
184
185 // Depending on the type of the content, assign it directly
186 // or ask the kernel for the page contents
187 if (pageContent.substr(0,15) == "<!DOCTYPE html>")
188 {
189 return this->SetPage(pageContent);
190 }
191 else if (pageContent.length())
192 {
193 return this->SetPage(m_mainFrame->GetDocContent(pageContent));
194 }
195 }
196
197 return false;
198}
199
200
209{
210 if (m_nHistoryPointer+1 < vHistory.size())
211 {
212 // Get the content of the history and increment the pointer
213 wxString pageContent = vHistory[m_nHistoryPointer+1];
215
216 // Depending on the type of the content, assign it directly
217 // or ask the kernel for the page contents
218 if (pageContent.substr(0,15) == "<!DOCTYPE html>")
219 {
220 return this->SetPage(pageContent);
221 }
222 else if (pageContent.length())
223 {
224 return this->SetPage(m_mainFrame->GetDocContent(pageContent));
225 }
226 }
227
228 return false;
229}
230
231
240{
241 return ShowPageOnItem("numere");
242}
243
244
253{
254 return ShowPageOnItem("idx");
255}
256
257
266{
267 // If the printing setup was not filled correctly,
268 // ask the user to provide the necessary data
269 if (!g_printData->IsOk())
271
272 wxPrintDialogData printDialogData( *g_printData);
273
274 // Create a new html printout class and apply the
275 // necessary settings
276 wxHtmlPrintout* printout = new wxHtmlPrintout();
277 printout->SetFonts(wxEmptyString, "Consolas");
278 printout->SetMargins(12.6f, 12.6f, 12.6f, 12.6f, 2.5f);
279 printout->SetFooter("<div align=\"center\">@PAGENUM@ / @PAGESCNT@</div>");
280
281 // Obtain the content of the page from the history
282 wxString htmlText = vHistory[m_nHistoryPointer];
283
284 // Depending on the type of the content of the history,
285 // assign it directly or obtain the page data from the
286 // kernel
287 if (htmlText.substr(0,15) == "<!DOCTYPE html>")
288 printout->SetHtmlText(htmlText);
289 else
290 printout->SetHtmlText(m_mainFrame->GetDocContent(htmlText));
291
292 // Create a new preview object
293 wxPrintPreview *preview = new wxPrintPreview(printout, printout, g_printData);
294
295 // Ensure that the preview is filled correctly
296 if (!preview->Ok())
297 {
298 delete preview;
299 wxMessageBox(_guilang.get("GUI_PREVIEW_ERROR"), _guilang.get("GUI_PREVIEW_ERROR_HEAD"), wxOK | wxICON_WARNING);
300 return false;
301 }
302
303 // Obtain the screen size and create a new preview frame
304 wxRect rect = m_mainFrame->DeterminePrintSize();
305 wxPreviewFrame *frame = new wxPreviewFrame (preview, this, _guilang.get("GUI_PREVIEW_HEAD"));
306
307 // Start the frame and display it
308 frame->SetSize(rect);
309 frame->Centre(wxBOTH);
310 frame->Initialize();
311 frame->Show(true);
312 frame->Maximize();
313
314 return true;
315}
316
317
326void HelpViewer::OnKeyDown(wxKeyEvent& event)
327{
328 // connecting the ESC Key with closing the image
329 if (event.GetKeyCode() == WXK_ESCAPE)
330 m_browser->Close();
331}
332
333
342void HelpViewer::OnEnter(wxMouseEvent& event)
343{
344 this->SetFocus();
345 event.Skip();
346}
347
348
357void HelpViewer::OnLinkClick(wxHtmlLinkEvent& event)
358{
359 wxString linkadress = event.GetLinkInfo().GetHref();
360 ShowPageOnItem(linkadress);
361}
362
bool createNewPage(const wxString &docId)
Create a new viewer in a new page.
This class renders the contents of a single page on the DocumentationBrowser. It also governs the bro...
Definition: helpviewer.hpp:36
bool GoIndex()
Public member function to display the index page.
Definition: helpviewer.cpp:252
std::vector< wxString > vHistory
Definition: helpviewer.hpp:55
bool Print()
Public member function to open the print preview page.
Definition: helpviewer.cpp:265
bool ShowPageOnItem(wxString docID)
Public member function to display a content in the viewer window. The type of the content is determin...
Definition: helpviewer.cpp:67
NumeReWindow * m_mainFrame
Definition: helpviewer.hpp:53
bool HistoryGoForward()
Public member function to go one step forward in the history.
Definition: helpviewer.cpp:208
virtual bool SetPage(const wxString &source)
Set the contents to be displayed in this window.
Definition: helpviewer.cpp:45
bool GoHome()
Public member function to return to the home page.
Definition: helpviewer.cpp:239
bool HistoryGoBack()
Public member function to go one step back in the history.
Definition: helpviewer.cpp:177
void OnKeyDown(wxKeyEvent &event)
Event handler, which gets fired when the user presses a key.
Definition: helpviewer.cpp:326
void OnLinkClick(wxHtmlLinkEvent &event)
Event handler for the case that the user clicks on a link in the document.
Definition: helpviewer.cpp:357
size_t m_nHistoryPointer
Definition: helpviewer.hpp:56
DocumentationBrowser * m_browser
Definition: helpviewer.hpp:54
void OnEnter(wxMouseEvent &event)
Event handler to automatically focus the window below the mouse pointer.
Definition: helpviewer.cpp:342
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
wxRect DeterminePrintSize()
void OnPrintSetup()
This member function displays the printing page setup dialog.
wxString GetDocContent(wxString docid)
This member function returns the HTML string containing the documentation for the selected topic/doc ...
Language _guilang
wxPageSetupData * g_pageSetupData
wxPrintData * g_printData
global print data, to remember settings during the session
END_EVENT_TABLE()