1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
6 Date: $Date: 2008/03/21 14:59:39 $
7 Version: $Revision: 1.3 $
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 // std::cout << "goto"<<std::endl;
185 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
189 //========================================================================
191 //========================================================================
192 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& )
194 // std::cout << "back"<<std::endl;
195 mwxHtmlWindow->HistoryBack();
198 //========================================================================
200 //========================================================================
201 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& )
203 // std::cout << "forward"<<std::endl;
204 mwxHtmlWindow->HistoryForward();
207 //========================================================================
209 //========================================================================
210 void WxGUIHtmlBrowser::GoHome()
212 std::string url = ConfigurationFile::GetInstance().Get_doc_path();
213 url += "/bbtkWebSite/menu.html";
217 mwxURL->AppendText(std2wx(url));
221 if (Utilities::FileExists(url))
231 //========================================================================
233 //========================================================================
234 void WxGUIHtmlBrowser::OnHomeButton(wxCommandEvent& )
238 //========================================================================
240 //========================================================================
241 void WxGUIHtmlBrowser::OnReloadButton(wxCommandEvent& e)
245 //========================================================================
246 //========================================================================
247 std::string WxGUIHtmlBrowser::GetCurrentPage()
249 return wx2std(mwxURL->GetValue());
251 //========================================================================
254 //========================================================================
255 void WxGUIHtmlBrowser::OnIncludeFileButton(wxCommandEvent& )
257 std::string filename = wx2std(mwxURL->GetValue());
258 size_t s = filename.length();
260 WxGUIConsole* C = mWxGUIConsole; //::GetInstance();
261 // MessageManager::SetMessageLevel("All",9);
262 Interpreter* I = new Interpreter;
264 if ((s>3) && (filename[s-1]=='s')
265 && (filename[s-2]=='b')
266 && (filename[s-3]=='b')
267 && (filename[s-4]=='.'))
269 std::cout << "stat"<<std::endl;
270 if (C!=0) C->SetStatusText(_T("Executing ")+mwxURL->GetValue());
271 std::cout << "int"<<std::endl;
272 I->InterpretFile(filename);
273 std::cout << "eoint"<<std::endl;
277 if (C!=0) C->SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
282 //========================================================================
286 //========================================================================
287 void WxGUIHtmlBrowser::OnURLEnter( wxCommandEvent&)
289 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
291 //========================================================================
294 //========================================================================
295 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
297 std::cout << "BrOnLink"<<std::endl;
302 wxString file = wxPathOnly(mwxURL->GetValue());
303 file += std2wx(ConfigurationFile::GetInstance().Get_file_separator());
304 file += e.GetLinkInfo().GetHref();
305 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
309 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
312 // mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
314 //========================================================================
318 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& )
320 std::cout << "OnCell"<<std::endl;
324 //========================================================================
325 void WxGUIHtmlBrowser::UpdateURL()
328 wxString s = mwxHtmlWindow->GetOpenedPage();
329 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
331 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
334 mwxURL->AppendText(s);
336 //========================================================================
338 //========================================================================
339 void WxGUIHtmlBrowser::SetSize( wxSize s)
341 // wxPanel::SetSize(s);
342 mwxHtmlWindow->SetSize(s);
345 //========================================================================