1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
6 Date: $Date: 2008/04/22 14:30:25 $
7 Version: $Revision: 1.5 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*//**
18 * \brief Short description in one line
20 * Long description which
21 * can span multiple lines
32 #ifdef _USE_WXWIDGETS_
35 #include "bbtkWxGUIHtmlBrowser.h"
36 //#include "bbtkWxBlackBox.h"
37 //#include "bbtkWxGUIConsole.h"
39 #include "bbtkConfigurationFile.h"
40 #include "bbtkUtilities.h"
45 //========================================================================
59 //========================================================================
60 void WxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& e)
62 std::cout << "WxHtmlWindow::OnLink"<<std::endl;
63 // std::cout << e.GetHref()<<std::endl;
64 LoadPage(e.GetHref());
65 if ( ! GetOpenedAnchor().IsEmpty() )
67 // std::cout << "#" << GetOpenedAnchor() << std::endl;
68 LoadPage(_T("#"+GetOpenedAnchor()));
70 mBrowser->UpdateURL();
72 //========================================================================
76 //========================================================================
78 BEGIN_EVENT_TABLE(WxGUIHtmlBrowser, wxPanel)
79 EVT_BUTTON(bwd_id, WxGUIHtmlBrowser::OnBackButton )
80 EVT_BUTTON(fwd_id, WxGUIHtmlBrowser::OnForwardButton )
81 EVT_BUTTON(home_id, WxGUIHtmlBrowser::OnHomeButton )
82 EVT_BUTTON(reload_id, WxGUIHtmlBrowser::OnReloadButton )
83 // EVT_BUTTON(include_id, WxGUIHtmlBrowser::OnIncludeFileButton )
84 EVT_TEXT_ENTER(url_id, WxGUIHtmlBrowser::OnURLEnter )
85 EVT_HTML_LINK_CLICKED(html_id, WxGUIHtmlBrowser::OnLinkClicked)
87 //========================================================================
90 //========================================================================
91 WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size,
92 WxGUIHtmlBrowserUser* user)
94 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
98 wxPanel* panel = this;
100 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
103 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL);
105 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition,
106 wxDefaultSize,wxBU_EXACTFIT);
107 bsizer->Add ( mwxBackButton , 0, wxALIGN_CENTRE );
109 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition,
110 wxDefaultSize,wxBU_EXACTFIT);
111 bsizer->Add ( mwxForwardButton , 0, wxALIGN_CENTRE );
113 mwxHomeButton = new wxButton( panel, home_id,_T("Home"),wxDefaultPosition,
114 wxDefaultSize,wxBU_EXACTFIT);
115 bsizer->Add ( mwxHomeButton , 0, wxALIGN_CENTRE );
117 mwxReloadButton = new wxButton( panel, reload_id,_T("Reload"),wxDefaultPosition,
118 wxDefaultSize,wxBU_EXACTFIT);
119 bsizer->Add ( mwxReloadButton , 0, wxALIGN_CENTRE );
122 mwxIncludeFileButton = new wxButton( panel, include_id,
123 _T("RUN"),wxDefaultPosition,
124 wxDefaultSize,wxBU_EXACTFIT);
125 bsizer->Add ( mwxIncludeFileButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 );
128 mwxURL = new wxTextCtrl(panel,url_id,_T(""),
132 mwxURL->SetLabel(_T("URL"));
133 bsizer->Add(mwxURL, 1, wxEXPAND);
136 // mwxHtmlWindow = new WxHtmlWindow(parent,html_id,this,size);
137 mwxHtmlWindow = new WxHtmlWindow(this,html_id,this,size);
145 "bbtk::WxGUIHtmlBrowser");
147 mwxHtmlWindow->SetBorders(5);
148 // mwxHtmlWindow->FitInside();
150 wxStaticBoxSizer* hw =
151 new wxStaticBoxSizer( new wxStaticBox( this, -1, _T(""),
155 //EED hw->Add ( mwxHtmlWindow, 1, wxGROW );
156 hw->Add ( mwxHtmlWindow, 1, wxEXPAND );
162 //sizer->Add ( mwxHtmlWindow, 1, wxGROW );
163 //EED sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
165 sizer->Add ( bsizer , 0, wxEXPAND );
166 sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
170 panel -> SetSizer(sizer);
171 panel -> SetAutoLayout(true);
177 //========================================================================
180 //========================================================================
181 bool WxGUIHtmlBrowser::GoTo(std::string& file)
183 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
187 //========================================================================
189 //========================================================================
190 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& )
192 mwxHtmlWindow->HistoryBack();
195 //========================================================================
197 //========================================================================
198 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& )
200 mwxHtmlWindow->HistoryForward();
203 //========================================================================
205 //========================================================================
206 void WxGUIHtmlBrowser::GoHome()
208 std::string url = ConfigurationFile::GetInstance().Get_doc_path();
209 url += "/bbtkWebSite/menu.html";
213 mwxURL->AppendText(std2wx(url));
217 if (Utilities::FileExists(url))
227 //========================================================================
229 //========================================================================
230 void WxGUIHtmlBrowser::OnHomeButton(wxCommandEvent& )
234 //========================================================================
236 //========================================================================
237 void WxGUIHtmlBrowser::OnReloadButton(wxCommandEvent& e)
241 //========================================================================
242 //========================================================================
243 std::string WxGUIHtmlBrowser::GetCurrentPage()
245 return wx2std(mwxURL->GetValue());
247 //========================================================================
250 //========================================================================
251 void WxGUIHtmlBrowser::OnIncludeFileButton(wxCommandEvent& )
253 std::string filename = wx2std(mwxURL->GetValue());
254 size_t s = filename.length();
256 WxGUIConsole* C = mWxGUIConsole; //::GetInstance();
257 // MessageManager::SetMessageLevel("All",9);
258 Interpreter* I = new Interpreter;
260 if ((s>3) && (filename[s-1]=='s')
261 && (filename[s-2]=='b')
262 && (filename[s-3]=='b')
263 && (filename[s-4]=='.'))
265 std::cout << "stat"<<std::endl;
266 if (C!=0) C->SetStatusText(_T("Executing ")+mwxURL->GetValue());
267 std::cout << "int"<<std::endl;
268 I->InterpretFile(filename);
269 std::cout << "eoint"<<std::endl;
273 if (C!=0) C->SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
278 //========================================================================
282 //========================================================================
283 void WxGUIHtmlBrowser::OnURLEnter( wxCommandEvent&)
285 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
287 //========================================================================
290 //========================================================================
291 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
297 wxString file = wxPathOnly(mwxURL->GetValue());
298 file += std2wx(ConfigurationFile::GetInstance().Get_file_separator());
299 file += e.GetLinkInfo().GetHref();
300 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
304 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
307 // mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
309 //========================================================================
313 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& )
315 std::cout << "OnCell"<<std::endl;
319 //========================================================================
320 void WxGUIHtmlBrowser::UpdateURL()
323 wxString s = mwxHtmlWindow->GetOpenedPage();
324 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
326 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
329 mwxURL->AppendText(s);
331 //========================================================================
333 //========================================================================
334 void WxGUIHtmlBrowser::SetSize( wxSize s)
336 // wxPanel::SetSize(s);
337 mwxHtmlWindow->SetSize(s);
340 //========================================================================