OpenASIP  2.0
HelpBrowser.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file HelpBrowser.cc
26  *
27  * Implementation of the HelpBrowser class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  */
31 
32 #include <wx/string.h>
33 #include <wx/menu.h>
34 #include <wx/html/htmlwin.h>
35 #include <wx/toolbar.h>
36 #include <wx/image.h>
37 
38 #include "HelpBrowser.hh"
39 #include "WxConversion.hh"
40 #include "Environment.hh"
41 #include "FileSystem.hh"
42 
43 BEGIN_EVENT_TABLE(HelpBrowser, wxFrame)
44  EVT_CLOSE(HelpBrowser::onClose)
45  EVT_MENU(ID_BACK, HelpBrowser::onBack)
46  EVT_MENU(ID_FORWARD, HelpBrowser::onForward)
47  EVT_MENU(wxID_CLOSE, HelpBrowser::onMenuClose)
49 
50 /**
51  * The Constructor.
52  *
53  * Creates a browser window and opens the given file in the
54  * html-widget.
55  *
56  * @param parent Parent window of the window.
57  * @param title Title of the help browser frame.
58  * @param file Html file to open in the frame.
59  * @param position Help frame position on the screen.
60  * @param size Help frame size.
61  */
62 HelpBrowser::HelpBrowser(wxString title, wxString file,
63  wxPoint position, wxSize size):
64  wxFrame(NULL, -1, title, position, size), html_(NULL) {
65 
66  wxToolBar* toolbar =
67  new wxToolBar(this, -1, wxDefaultPosition, wxDefaultSize,
68  wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT);
69 
70  wxBitmap icon;
71 
72  if (wxImage::FindHandler(wxBITMAP_TYPE_PNG) == NULL) {
73  // load image handler for pngs
74  wxImage::AddHandler(new wxPNGHandler);
75  }
76 
77  // toolbar icon locations
78  wxString backIconFile = WxConversion::toWxString(
81  "back.png");
82  wxString forwardIconFile = WxConversion::toWxString(
85  "forward.png");
86  wxString closeIconFile = WxConversion::toWxString(
89  "close_document.png");
90 
91  // add toolbar buttons
92  icon.LoadFile(closeIconFile, wxBITMAP_TYPE_PNG);
93 
94  toolbar->AddTool(wxID_CLOSE, _T("Close"), icon,
95  wxNullBitmap, wxITEM_NORMAL, _T("Close window"),
96  _T("CloseWindow"));
97 
98  toolbar->AddSeparator();
99 
100  icon.LoadFile(backIconFile, wxBITMAP_TYPE_PNG);
101  toolbar->AddTool(ID_BACK, _T("Back"), icon,
102  wxNullBitmap, wxITEM_NORMAL, _T("Back"));
103 
104  icon.LoadFile(forwardIconFile, wxBITMAP_TYPE_PNG);
105  toolbar->AddTool(ID_FORWARD, _T("Forward"), icon,
106  wxNullBitmap, wxITEM_NORMAL, _T("Forward"));
107 
108  toolbar->Realize();
109  SetToolBar(toolbar);
110 
111  // create html-widget and open the given file in it
112  html_ = new wxHtmlWindow(this);
113  html_->LoadPage(file);
114 }
115 
116 
117 /**
118  * The Destructor.
119  */
121 }
122 
123 
124 /**
125  * Destroys the window when a close event is received.
126  */
127 void
128 HelpBrowser::onClose(wxCloseEvent&) {
129  Destroy();
130 }
131 
132 /**
133  * Destroys the window when a close event is received.
134  */
135 void
136 HelpBrowser::onMenuClose(wxCommandEvent&) {
137  Destroy();
138 }
139 
140 
141 /**
142  * Loads the previous page in the html-widget.
143  */
144 void
145 HelpBrowser::onBack(wxCommandEvent&) {
146  html_->HistoryBack();
147 }
148 
149 
150 /**
151  * Loads the next page in html-widget history.
152  */
153 void
154 HelpBrowser::onForward(wxCommandEvent&) {
155  html_->HistoryForward();
156 }
HelpBrowser::onBack
void onBack(wxCommandEvent &event)
Definition: HelpBrowser.cc:145
FileSystem.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HelpBrowser::onClose
void onClose(wxCloseEvent &event)
Definition: HelpBrowser.cc:128
HelpBrowser::onForward
void onForward(wxCommandEvent &event)
Definition: HelpBrowser.cc:154
HelpBrowser::~HelpBrowser
~HelpBrowser()
Definition: HelpBrowser.cc:120
Environment::bitmapsDirPath
static std::string bitmapsDirPath(const std::string &prog)
Definition: Environment.cc:201
HelpBrowser
Definition: HelpBrowser.hh:42
HelpBrowser::onMenuClose
void onMenuClose(wxCommandEvent &event)
Definition: HelpBrowser.cc:136
Environment.hh
HelpBrowser::html_
wxHtmlWindow * html_
Definition: HelpBrowser.hh:55
HelpBrowser.hh
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
WxConversion.hh
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF