2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.15 $
34 =========================================================================*/
40 * \brief Short description in one line
42 * Long description which
43 * can span multiple lines
54 #ifdef _USE_WXWIDGETS_
57 #include "bbtkWxGUIHtmlBrowser.h"
58 //#include "bbtkWxBlackBox.h"
59 //#include "bbtkWxGUIConsole.h"
61 #include "bbtkConfigurationFile.h"
62 #include "bbtkUtilities.h"
67 //========================================================================
81 //========================================================================
82 void WxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& e)
84 std::cout << "WxHtmlWindow::OnLink"<<std::endl;
85 // std::cout << e.GetHref()<<std::endl;
86 mBrowser->OnLinkClicked2(e);
90 //EED2 BEGIN_EVENT_TABLE(WxHtmlWindow, wxPanel)
91 //EED2 EVT_SIZE(WxHtmlWindow::OnSize)
92 //EED2 END_EVENT_TABLE()
94 //EED2 void WxHtmlWindow::OnSize( wxSizeEvent& )
96 //EED2 printf("EED WxHtmlWindow::OnSize \n" );
97 //EED2 Scroll(10,500);
101 //========================================================================
103 BEGIN_EVENT_TABLE(WxGUIHtmlBrowser, wxPanel)
104 EVT_BUTTON(bwd_id, WxGUIHtmlBrowser::OnBackButton )
105 EVT_BUTTON(fwd_id, WxGUIHtmlBrowser::OnForwardButton )
106 EVT_BUTTON(home_id, WxGUIHtmlBrowser::OnHomeButton )
107 EVT_BUTTON(reload_id, WxGUIHtmlBrowser::OnReloadButton )
108 // EVT_BUTTON(include_id, WxGUIHtmlBrowser::OnIncludeFileButton )
109 EVT_TEXT_ENTER(url_id, WxGUIHtmlBrowser::OnURLEnter )
110 EVT_HTML_LINK_CLICKED(html_id, WxGUIHtmlBrowser::OnLinkClicked)
111 EVT_SIZE(WxGUIHtmlBrowser::OnSize)
114 //========================================================================
117 //========================================================================
118 WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size,
119 WxGUIHtmlBrowserUser* user)
121 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
125 wxPanel* panel = this;
127 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
130 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL);
132 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition,
133 wxDefaultSize,wxBU_EXACTFIT);
134 bsizer->Add ( mwxBackButton , 0, wxALIGN_CENTRE );
136 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition,
137 wxDefaultSize,wxBU_EXACTFIT);
138 bsizer->Add ( mwxForwardButton , 0, wxALIGN_CENTRE );
140 mwxHomeButton = new wxButton( panel, home_id,_T("Home"),wxDefaultPosition,
141 wxDefaultSize,wxBU_EXACTFIT);
142 bsizer->Add ( mwxHomeButton , 0, wxALIGN_CENTRE );
144 mwxReloadButton = new wxButton( panel, reload_id,_T("Reload"),wxDefaultPosition,
145 wxDefaultSize,wxBU_EXACTFIT);
146 bsizer->Add ( mwxReloadButton , 0, wxALIGN_CENTRE );
149 mwxIncludeFileButton = new wxButton( panel, include_id,
150 _T("RUN"),wxDefaultPosition,
151 wxDefaultSize,wxBU_EXACTFIT);
152 bsizer->Add ( mwxIncludeFileButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 );
155 mwxURL = new wxTextCtrl(panel,url_id,_T(""),
159 mwxURL->SetLabel(_T("URL"));
160 bsizer->Add(mwxURL, 1, wxEXPAND);
163 // mwxHtmlWindow = new WxHtmlWindow(this,html_id,this,size);
165 mwxHtmlWindow = new wxHtmlWindow(this,html_id,
169 _T("bbtk::WxGUIHtmlBrowser"));
177 "bbtk::WxGUIHtmlBrowser");
179 mwxHtmlWindow->SetBorders(5);
180 // mwxHtmlWindow->FitInside();
182 sizer->Add ( bsizer , 0, wxEXPAND );
184 // EED: This have a problem in macOS
185 // wxStaticBoxSizer* hw =
186 // new wxStaticBoxSizer(
187 // new wxStaticBox( this, -1, _T(""), wxDefaultPosition, size ),
190 // hw->Add ( mwxHtmlWindow, 1, wxEXPAND );
191 //EED sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
193 sizer->Add ( mwxHtmlWindow, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
195 panel -> SetSizer(sizer);
197 panel -> SetAutoLayout(true);
203 //========================================================================
206 //========================================================================
207 bool WxGUIHtmlBrowser::GoTo(std::string& file)
209 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
213 //========================================================================
215 //========================================================================
216 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& )
218 mwxHtmlWindow->HistoryBack();
221 //========================================================================
223 //========================================================================
224 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& )
226 mwxHtmlWindow->HistoryForward();
229 //========================================================================
231 //========================================================================
232 void WxGUIHtmlBrowser::GoHome()
234 std::string url = ConfigurationFile::GetInstance().Get_doc_path();
235 url += "/help_contents.html";
238 //========================================================================
240 //========================================================================
241 void WxGUIHtmlBrowser::OnHomeButton(wxCommandEvent& )
245 //========================================================================
247 //========================================================================
248 void WxGUIHtmlBrowser::OnReloadButton(wxCommandEvent& e)
252 //========================================================================
253 //========================================================================
254 std::string WxGUIHtmlBrowser::GetCurrentPage()
256 return wx2std(mwxURL->GetValue());
258 //========================================================================
261 //========================================================================
262 void WxGUIHtmlBrowser::OnIncludeFileButton(wxCommandEvent& )
264 std::string filename = wx2std(mwxURL->GetValue());
265 size_t s = filename.length();
267 WxGUIConsole* C = mWxGUIConsole; //::GetInstance();
268 // MessageManager::SetMessageLevel("All",9);
269 Interpreter* I = new Interpreter;
271 if ((s>3) && (filename[s-1]=='s')
272 && (filename[s-2]=='b')
273 && (filename[s-3]=='b')
274 && (filename[s-4]=='.'))
276 std::cout << "stat"<<std::endl;
277 if (C!=0) C->SetStatusText(_T("Executing ")+mwxURL->GetValue());
278 std::cout << "int"<<std::endl;
279 I->InterpretFile(filename);
280 std::cout << "eoint"<<std::endl;
284 if (C!=0) C->SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
289 //========================================================================
293 //========================================================================
294 void WxGUIHtmlBrowser::OnURLEnter( wxCommandEvent&)
296 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
298 //========================================================================
300 //========================================================================
301 void WxGUIHtmlBrowser::OnLinkClicked2(const wxHtmlLinkInfo& info)
303 // std::cout << "OLK2"<<std::endl;
307 wxString file = info.GetHref();
308 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
312 mwxHtmlWindow->LoadPage( info.GetHref() );
319 //========================================================================
320 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
322 // std::cout << "OLK"<<std::endl;
327 wxString file = wxPathOnly(mwxURL->GetValue());
328 file += std2wx(ConfigurationFile::GetInstance().Get_file_separator());
329 file += e.GetLinkInfo().GetHref();
331 wxString file = e.GetLinkInfo().GetHref();
332 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
336 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
339 // mwxHtmlWindow->LoadPage(mwxURL->GetValue());
342 // mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
344 //========================================================================
347 //========================================================================
348 void WxGUIHtmlBrowser::OnSize(wxSizeEvent& e)
350 mwxHtmlWindow->EnableScrolling(true,true);
351 if ( mwxURL->GetValue()!=wxString(_T("")) )
353 // ?????????? No funciona ....?????
354 //EED2 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
355 // printf("EED WxGUIHtmlBrowser::OnSize %s \n", mwxURL->GetValue().c_str() );
356 //EED2 mwxHtmlWindow->Scroll( 10, 500);
364 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& )
366 std::cout << "OnCell"<<std::endl;
370 //========================================================================
371 void WxGUIHtmlBrowser::UpdateURL()
373 wxString s = mwxHtmlWindow->GetOpenedPage();
374 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
376 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
379 mwxURL->AppendText(s);
381 //========================================================================
383 //========================================================================
384 void WxGUIHtmlBrowser::SetSize( wxSize s)
386 // wxPanel::SetSize(s);
387 mwxHtmlWindow->SetSize(s);
390 //========================================================================