NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
documentationbrowser.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 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
21#include "NumeReWindow.h"
22#include "../common/datastructures.h"
24#include "controls/treedata.hpp"
26#include "../kernel/core/ui/language.hpp"
27#include <vector>
28#include <string>
29#include <wx/artprov.h>
30
31extern Language _guilang;
32
33using namespace std;
34
35BEGIN_EVENT_TABLE(DocumentationBrowser, ViewerFrame)
36 EVT_TREE_SEL_CHANGED(-1, DocumentationBrowser::OnTreeClick)
38 EVT_AUINOTEBOOK_PAGE_CHANGED(-1, DocumentationBrowser::onPageChange)
40
41
42
50DocumentationBrowser::DocumentationBrowser(wxWindow* parent, const wxString& titletemplate, NumeReWindow* mainwindow) : ViewerFrame(parent, titletemplate)
51{
52 // Obtain the program root directory and create a new
53 // IconManager object using this information
54 wxString programPath = mainwindow->getProgramFolder();
55 m_manager = new IconManager(programPath);
56
57 // Create the status bar and the window splitter
58 this->CreateStatusBar();
59 prepareToolbar();
60 wxSplitterWindow* splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D | wxBORDER_THEME);
61
62 // Create the tree and the viewer objects as childs
63 // of the window splitter
64 TreePanel* treePanel = new TreePanel(splitter, wxID_ANY);
65 m_doctree = new wxTreeCtrl(treePanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_SINGLE | wxTR_FULL_ROW_HIGHLIGHT | wxTR_NO_LINES | wxTR_TWIST_BUTTONS);
66 m_doctree->SetImageList(m_manager->GetImageList());
67 TreeSearchCtrl* treeSearchCtrl = new TreeSearchCtrl(treePanel,
68 wxID_ANY,
69 _guilang.get("GUI_SEARCH_DOCUMENTATION"),
70 _guilang.get("GUI_SEARCH_CALLTIP_TREE"),
71 m_doctree,
72 true);
73 treePanel->AddWindows(treeSearchCtrl, m_doctree);
74
75 m_docTabs = new ViewerBook(splitter,
76 wxID_ANY,
77 wxDefaultPosition,
78 wxDefaultSize,
79 wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_MIDDLE_CLICK_CLOSE | wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON);
80
81 // Bind the mouse middle event handler to this class
82 //m_docTabs->Bind(wxEVT_AUINOTEBOOK_TAB_MIDDLE_UP, &DocumentationBrowser::OnMiddleClick, this);
83 m_docTabs->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, &DocumentationBrowser::onPageClose, this);
84 m_titleTemplate = titletemplate;
85
86 // Set a reasonable window size and the window icon
87 this->SetSize(1050, 800);
88 this->SetIcon(mainwindow->getStandardIcon());
89
90 // Split the view using the tree and the viewer
91 splitter->SplitVertically(treePanel, m_docTabs, 150);
92
93 // Fill the index into the tree
94 fillDocTree(mainwindow);
95
96 this->Show();
97 this->SetFocus();
98}
99
100
106{
107 delete m_manager;
108}
109
110
118bool DocumentationBrowser::SetStartPage(const wxString& docId)
119{
120 return createNewPage(docId);
121}
122
123
132{
133 // Create a new tool bar
134 wxToolBar* tb = this->CreateToolBar();
135
136 // Fill the tool bar with tools
137 tb->AddTool(ID_HELP_HOME, _guilang.get("GUI_TB_DOCBROWSER_HOME"), wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_TOOLBAR), _guilang.get("GUI_TB_DOCBROWSER_HOME"));
138 tb->AddTool(ID_HELP_INDEX, _guilang.get("GUI_TB_DOCBROWSER_INDEX"), wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_TOOLBAR), _guilang.get("GUI_TB_DOCBROWSER_INDEX"));
139 tb->AddSeparator();
140 tb->AddTool(ID_HELP_GO_BACK, _guilang.get("GUI_TB_DOCBROWSER_BACK"), wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_TOOLBAR), _guilang.get("GUI_TB_DOCBROWSER_BACK"));
141 tb->AddTool(ID_HELP_GO_FORWARD, _guilang.get("GUI_TB_DOCBROWSER_FORWARD"), wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_TOOLBAR), _guilang.get("GUI_TB_DOCBROWSER_FORWARD"));
142 tb->AddSeparator();
143 tb->AddTool(ID_HELP_PRINT, _guilang.get("GUI_TB_DOCBROWSER_PRINT"), wxArtProvider::GetBitmap(wxART_PRINT, wxART_TOOLBAR), _guilang.get("GUI_TB_DOCBROWSER_PRINT"));
144// tb->AddTool(ID_HELP_HOME, _guilang.get("GUI_TB_DOCBROWSER_FORWARD"), wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_TOOLBAR));
145
146 // Display the toolbar
147 tb->Realize();
148}
149
150
160{
161 // Get the documentation index from the kernel
162 std::vector<std::string> vIndex = mainwindow->GetDocIndex();
163
164 // Search for the icon ID of the document icon and prepare the tree root
165 int iconId = m_manager->GetIconIndex("DOCUMENT");
166 wxTreeItemId root = m_doctree->AddRoot("Index", m_manager->GetIconIndex("WORKPLACE"));
167
168 // Append the index items using the document icon
169 for (size_t i = 0; i < vIndex.size(); i++)
170 m_doctree->AppendItem(root,
171 vIndex[i].substr(0, vIndex[i].find(' ')),
172 iconId, iconId,
173 new ToolTipTreeData(vIndex[i].substr(vIndex[i].find(' ')+1)));
174
175 // Expand the top-level node
176 m_doctree->Expand(root);
177}
178
179
189{
190 for (size_t i = 0; i < m_docTabs->GetPageCount(); i++)
191 {
192 if (m_docTabs->GetPageText(i) == title)
193 {
194 m_docTabs->SetSelection(i);
195 return true;
196 }
197 }
198
199 return false;
200}
201
202
212void DocumentationBrowser::OnTreeClick(wxTreeEvent& event)
213{
214 HelpViewer* viewer = static_cast<HelpViewer*>(m_docTabs->GetCurrentPage());
215
216 if (viewer)
217 {
218 viewer->ShowPageOnItem(m_doctree->GetItemText(event.GetItem()));
219 setCurrentTabText(viewer->GetOpenedPageTitle());
220 }
221}
222
223
234void DocumentationBrowser::OnToolbarEvent(wxCommandEvent& event)
235{
236 HelpViewer* viewer = static_cast<HelpViewer*>(m_docTabs->GetCurrentPage());
237
238 if (!viewer)
239 return;
240
241 switch (event.GetId())
242 {
243 case ID_HELP_HOME:
244 viewer->GoHome();
245 break;
246 case ID_HELP_INDEX:
247 viewer->GoIndex();
248 break;
249 case ID_HELP_GO_BACK:
250 viewer->HistoryGoBack();
251 break;
253 viewer->HistoryGoForward();
254 break;
255 case ID_HELP_PRINT:
256 viewer->Print();
257 break;
258 }
259
260 setCurrentTabText(viewer->GetOpenedPageTitle());
261}
262
263
271bool DocumentationBrowser::createNewPage(const wxString& docId)
272{
273 NumeReWindow* mainFrame = static_cast<NumeReWindow*>(m_parent);
274 wxString title;
275
276 // Find an already opened page with the same title
277 if (docId.substr(0, 15) != "<!DOCTYPE html>")
278 title = mainFrame->GetDocContent(docId); // Get the page content from the kernel
279 else
280 title = docId;
281
282 // Extract the title from the HTML page
283 title.erase(title.find("</title>"));
284 title.erase(0, title.find("<title>")+7);
285
286 // If the page already exists, we select it and
287 // leave this method
288 if (findAndSelectPage(title))
289 return true;
290
291 HelpViewer* viewer = new HelpViewer(m_docTabs, mainFrame, this);
292 viewer->SetRelatedFrame(this, m_titleTemplate);
293 viewer->SetRelatedStatusBar(0);
294
295 m_docTabs->AddPage(viewer, docId, true);
296 return viewer->ShowPageOnItem(docId);
297}
298
299
309{
310 if (m_docTabs->GetPageCount())
311 m_docTabs->SetPageText(m_docTabs->GetSelection(), text);
312}
313
314
323void DocumentationBrowser::onPageChange(wxAuiNotebookEvent& event)
324{
325 SetTitle(wxString::Format(m_titleTemplate, m_docTabs->GetPageText(event.GetSelection())));
326}
327
328
337void DocumentationBrowser::onPageClose(wxAuiNotebookEvent& event)
338{
339 // Is this the only page?
340 if (m_docTabs->GetPageCount() == 1)
341 Close();
342
343 event.Skip();
344}
345
346
347
This represents the main frame of the documentation browser, which contains the tabbed layout,...
void onPageClose(wxAuiNotebookEvent &event)
Event handler called, when the user closes the tab in some way.
void onPageChange(wxAuiNotebookEvent &event)
Event handler function called, when the user switches the tabs.
void OnToolbarEvent(wxCommandEvent &event)
Event handler function for clicks on the toolbar of the current window. Redirects all clicks to the H...
bool createNewPage(const wxString &docId)
Create a new viewer in a new page.
bool findAndSelectPage(const wxString &title)
Finds and selects the page with the passed title or returns false.
void prepareToolbar()
Private member function to prepare the toolbar of the main frame.
~DocumentationBrowser()
Documentation browser destructor. Removes the created IconManager object.
bool SetStartPage(const wxString &docId)
Public interface to set the start page.
void OnTreeClick(wxTreeEvent &event)
Event handler function to load the documentation article describing the clicked item.
void fillDocTree(NumeReWindow *mainwindow)
This private member function prepares the index tree of the documentation browser.
void setCurrentTabText(const wxString &text)
Change the text displayed on the current tab.
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
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
bool HistoryGoForward()
Public member function to go one step forward in the history.
Definition: helpviewer.cpp:208
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
int GetIconIndex(wxString iconInfo)
This class handles the internal language system and returns the language strings of the selected lang...
Definition: language.hpp:38
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
This class is the actual NumeRe main frame. The application's logic is implemented here.
Definition: NumeReWindow.h:177
std::vector< std::string > GetDocIndex()
This member function returns the documentation index as a vector.
wxString GetDocContent(wxString docid)
This member function returns the HTML string containing the documentation for the selected topic/doc ...
This class provides the basic functionality to provide a tooltip for a tree item.
Definition: treedata.hpp:28
void AddWindows(wxWindow *searchbar, wxWindow *tree)
Definition: treepanel.hpp:31
This class specializes the generic search control to interact with a wxTreeCtrl.
This class generalizes a set of basic floating window functionalities like being closable by pressing...
Definition: viewerframe.hpp:31
@ EVENTID_HELP_START
@ ID_HELP_GO_BACK
@ ID_HELP_GO_FORWARD
@ ID_HELP_HOME
@ ID_HELP_PRINT
@ EVENTID_HELP_END
@ ID_HELP_INDEX
Language _guilang
END_EVENT_TABLE()