1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
5 Date: $Date: 2009/03/23 13:06:41 $
6 Version: $Revision: 1.13 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Short description in one line
35 * Long description which
36 * can span multiple lines
47 #ifdef _USE_WXWIDGETS_
50 #include "bbtkWxGUIHtmlBrowser.h"
51 //#include "bbtkWxBlackBox.h"
52 //#include "bbtkWxGUIConsole.h"
54 #include "bbtkConfigurationFile.h"
55 #include "bbtkUtilities.h"
60 //========================================================================
74 //========================================================================
75 void WxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& e)
77 std::cout << "WxHtmlWindow::OnLink"<<std::endl;
78 // std::cout << e.GetHref()<<std::endl;
79 mBrowser->OnLinkClicked2(e);
83 //EED2 BEGIN_EVENT_TABLE(WxHtmlWindow, wxPanel)
84 //EED2 EVT_SIZE(WxHtmlWindow::OnSize)
85 //EED2 END_EVENT_TABLE()
87 //EED2 void WxHtmlWindow::OnSize( wxSizeEvent& )
89 //EED2 printf("EED WxHtmlWindow::OnSize \n" );
90 //EED2 Scroll(10,500);
94 //========================================================================
96 BEGIN_EVENT_TABLE(WxGUIHtmlBrowser, wxPanel)
97 EVT_BUTTON(bwd_id, WxGUIHtmlBrowser::OnBackButton )
98 EVT_BUTTON(fwd_id, WxGUIHtmlBrowser::OnForwardButton )
99 EVT_BUTTON(home_id, WxGUIHtmlBrowser::OnHomeButton )
100 EVT_BUTTON(reload_id, WxGUIHtmlBrowser::OnReloadButton )
101 // EVT_BUTTON(include_id, WxGUIHtmlBrowser::OnIncludeFileButton )
102 EVT_TEXT_ENTER(url_id, WxGUIHtmlBrowser::OnURLEnter )
103 EVT_HTML_LINK_CLICKED(html_id, WxGUIHtmlBrowser::OnLinkClicked)
104 EVT_SIZE(WxGUIHtmlBrowser::OnSize)
107 //========================================================================
110 //========================================================================
111 WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size,
112 WxGUIHtmlBrowserUser* user)
114 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
118 wxPanel* panel = this;
120 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
123 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL);
125 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition,
126 wxDefaultSize,wxBU_EXACTFIT);
127 bsizer->Add ( mwxBackButton , 0, wxALIGN_CENTRE );
129 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition,
130 wxDefaultSize,wxBU_EXACTFIT);
131 bsizer->Add ( mwxForwardButton , 0, wxALIGN_CENTRE );
133 mwxHomeButton = new wxButton( panel, home_id,_T("Home"),wxDefaultPosition,
134 wxDefaultSize,wxBU_EXACTFIT);
135 bsizer->Add ( mwxHomeButton , 0, wxALIGN_CENTRE );
137 mwxReloadButton = new wxButton( panel, reload_id,_T("Reload"),wxDefaultPosition,
138 wxDefaultSize,wxBU_EXACTFIT);
139 bsizer->Add ( mwxReloadButton , 0, wxALIGN_CENTRE );
142 mwxIncludeFileButton = new wxButton( panel, include_id,
143 _T("RUN"),wxDefaultPosition,
144 wxDefaultSize,wxBU_EXACTFIT);
145 bsizer->Add ( mwxIncludeFileButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 );
148 mwxURL = new wxTextCtrl(panel,url_id,_T(""),
152 mwxURL->SetLabel(_T("URL"));
153 bsizer->Add(mwxURL, 1, wxEXPAND);
156 // mwxHtmlWindow = new WxHtmlWindow(this,html_id,this,size);
158 mwxHtmlWindow = new wxHtmlWindow(this,html_id,
162 _T("bbtk::WxGUIHtmlBrowser"));
170 "bbtk::WxGUIHtmlBrowser");
172 mwxHtmlWindow->SetBorders(5);
173 // mwxHtmlWindow->FitInside();
175 sizer->Add ( bsizer , 0, wxEXPAND );
177 // EED: This have a problem in macOS
178 // wxStaticBoxSizer* hw =
179 // new wxStaticBoxSizer(
180 // new wxStaticBox( this, -1, _T(""), wxDefaultPosition, size ),
183 // hw->Add ( mwxHtmlWindow, 1, wxEXPAND );
184 //EED sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
186 sizer->Add ( mwxHtmlWindow, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
188 panel -> SetSizer(sizer);
189 panel -> SetAutoLayout(true);
195 //========================================================================
198 //========================================================================
199 bool WxGUIHtmlBrowser::GoTo(std::string& file)
201 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
205 //========================================================================
207 //========================================================================
208 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& )
210 mwxHtmlWindow->HistoryBack();
213 //========================================================================
215 //========================================================================
216 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& )
218 mwxHtmlWindow->HistoryForward();
221 //========================================================================
223 //========================================================================
224 void WxGUIHtmlBrowser::GoHome()
226 std::string url = ConfigurationFile::GetInstance().Get_doc_path();
227 url += "/help_contents.html";
230 //========================================================================
232 //========================================================================
233 void WxGUIHtmlBrowser::OnHomeButton(wxCommandEvent& )
237 //========================================================================
239 //========================================================================
240 void WxGUIHtmlBrowser::OnReloadButton(wxCommandEvent& e)
244 //========================================================================
245 //========================================================================
246 std::string WxGUIHtmlBrowser::GetCurrentPage()
248 return wx2std(mwxURL->GetValue());
250 //========================================================================
253 //========================================================================
254 void WxGUIHtmlBrowser::OnIncludeFileButton(wxCommandEvent& )
256 std::string filename = wx2std(mwxURL->GetValue());
257 size_t s = filename.length();
259 WxGUIConsole* C = mWxGUIConsole; //::GetInstance();
260 // MessageManager::SetMessageLevel("All",9);
261 Interpreter* I = new Interpreter;
263 if ((s>3) && (filename[s-1]=='s')
264 && (filename[s-2]=='b')
265 && (filename[s-3]=='b')
266 && (filename[s-4]=='.'))
268 std::cout << "stat"<<std::endl;
269 if (C!=0) C->SetStatusText(_T("Executing ")+mwxURL->GetValue());
270 std::cout << "int"<<std::endl;
271 I->InterpretFile(filename);
272 std::cout << "eoint"<<std::endl;
276 if (C!=0) C->SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
281 //========================================================================
285 //========================================================================
286 void WxGUIHtmlBrowser::OnURLEnter( wxCommandEvent&)
288 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
290 //========================================================================
292 //========================================================================
293 void WxGUIHtmlBrowser::OnLinkClicked2(const wxHtmlLinkInfo& info)
295 // std::cout << "OLK2"<<std::endl;
299 wxString file = info.GetHref();
300 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
304 mwxHtmlWindow->LoadPage( info.GetHref() );
311 //========================================================================
312 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
314 // std::cout << "OLK"<<std::endl;
319 wxString file = wxPathOnly(mwxURL->GetValue());
320 file += std2wx(ConfigurationFile::GetInstance().Get_file_separator());
321 file += e.GetLinkInfo().GetHref();
323 wxString file = e.GetLinkInfo().GetHref();
324 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
328 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
331 // mwxHtmlWindow->LoadPage(mwxURL->GetValue());
334 // mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
336 //========================================================================
339 //========================================================================
340 void WxGUIHtmlBrowser::OnSize(wxSizeEvent& e)
342 mwxHtmlWindow->EnableScrolling(true,true);
343 if ( mwxURL->GetValue()!=wxString(_T("")) )
345 // ?????????? No funciona ....?????
346 //EED2 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
347 // printf("EED WxGUIHtmlBrowser::OnSize %s \n", mwxURL->GetValue().c_str() );
348 //EED2 mwxHtmlWindow->Scroll( 10, 500);
356 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& )
358 std::cout << "OnCell"<<std::endl;
362 //========================================================================
363 void WxGUIHtmlBrowser::UpdateURL()
365 wxString s = mwxHtmlWindow->GetOpenedPage();
366 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
368 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
371 mwxURL->AppendText(s);
373 //========================================================================
375 //========================================================================
376 void WxGUIHtmlBrowser::SetSize( wxSize s)
378 // wxPanel::SetSize(s);
379 mwxHtmlWindow->SetSize(s);
382 //========================================================================