1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
5 Date: $Date: 2008/10/17 08:18:15 $
6 Version: $Revision: 1.10 $
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 LoadPage(e.GetHref());
80 if ( ! GetOpenedAnchor().IsEmpty() )
82 // std::cout << "#" << GetOpenedAnchor() << std::endl;
83 LoadPage(_T("#"+GetOpenedAnchor()));
85 mBrowser->UpdateURL();
87 //========================================================================
91 //EED2 BEGIN_EVENT_TABLE(WxHtmlWindow, wxPanel)
92 //EED2 EVT_SIZE(WxHtmlWindow::OnSize)
93 //EED2 END_EVENT_TABLE()
95 //EED2 void WxHtmlWindow::OnSize( wxSizeEvent& )
97 //EED2 printf("EED WxHtmlWindow::OnSize \n" );
98 //EED2 Scroll(10,500);
102 //========================================================================
104 BEGIN_EVENT_TABLE(WxGUIHtmlBrowser, wxPanel)
105 EVT_BUTTON(bwd_id, WxGUIHtmlBrowser::OnBackButton )
106 EVT_BUTTON(fwd_id, WxGUIHtmlBrowser::OnForwardButton )
107 EVT_BUTTON(home_id, WxGUIHtmlBrowser::OnHomeButton )
108 EVT_BUTTON(reload_id, WxGUIHtmlBrowser::OnReloadButton )
109 // EVT_BUTTON(include_id, WxGUIHtmlBrowser::OnIncludeFileButton )
110 EVT_TEXT_ENTER(url_id, WxGUIHtmlBrowser::OnURLEnter )
111 EVT_HTML_LINK_CLICKED(html_id, WxGUIHtmlBrowser::OnLinkClicked)
112 EVT_SIZE(WxGUIHtmlBrowser::OnSize)
115 //========================================================================
118 //========================================================================
119 WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size,
120 WxGUIHtmlBrowserUser* user)
122 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
126 wxPanel* panel = this;
128 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
131 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL);
133 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition,
134 wxDefaultSize,wxBU_EXACTFIT);
135 bsizer->Add ( mwxBackButton , 0, wxALIGN_CENTRE );
137 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition,
138 wxDefaultSize,wxBU_EXACTFIT);
139 bsizer->Add ( mwxForwardButton , 0, wxALIGN_CENTRE );
141 mwxHomeButton = new wxButton( panel, home_id,_T("Home"),wxDefaultPosition,
142 wxDefaultSize,wxBU_EXACTFIT);
143 bsizer->Add ( mwxHomeButton , 0, wxALIGN_CENTRE );
145 mwxReloadButton = new wxButton( panel, reload_id,_T("Reload"),wxDefaultPosition,
146 wxDefaultSize,wxBU_EXACTFIT);
147 bsizer->Add ( mwxReloadButton , 0, wxALIGN_CENTRE );
150 mwxIncludeFileButton = new wxButton( panel, include_id,
151 _T("RUN"),wxDefaultPosition,
152 wxDefaultSize,wxBU_EXACTFIT);
153 bsizer->Add ( mwxIncludeFileButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 );
156 mwxURL = new wxTextCtrl(panel,url_id,_T(""),
160 mwxURL->SetLabel(_T("URL"));
161 bsizer->Add(mwxURL, 1, wxEXPAND);
164 // mwxHtmlWindow = new WxHtmlWindow(parent,html_id,this,size);
165 mwxHtmlWindow = new WxHtmlWindow(this,html_id,this,size);
173 "bbtk::WxGUIHtmlBrowser");
175 mwxHtmlWindow->SetBorders(5);
176 // mwxHtmlWindow->FitInside();
178 wxStaticBoxSizer* hw =
179 new wxStaticBoxSizer( new wxStaticBox( this, -1, _T(""),
183 //EED hw->Add ( mwxHtmlWindow, 1, wxGROW );
184 hw->Add ( mwxHtmlWindow, 1, wxEXPAND );
190 //sizer->Add ( mwxHtmlWindow, 1, wxGROW );
191 //EED sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
193 sizer->Add ( bsizer , 0, wxEXPAND );
194 sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
198 panel -> SetSizer(sizer);
199 panel -> SetAutoLayout(true);
205 //========================================================================
208 //========================================================================
209 bool WxGUIHtmlBrowser::GoTo(std::string& file)
211 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
215 //========================================================================
217 //========================================================================
218 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& )
220 mwxHtmlWindow->HistoryBack();
223 //========================================================================
225 //========================================================================
226 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& )
228 mwxHtmlWindow->HistoryForward();
231 //========================================================================
233 //========================================================================
234 void WxGUIHtmlBrowser::GoHome()
236 std::string url = ConfigurationFile::GetInstance().Get_doc_path();
237 url += "/help_contents.html";
240 //========================================================================
242 //========================================================================
243 void WxGUIHtmlBrowser::OnHomeButton(wxCommandEvent& )
247 //========================================================================
249 //========================================================================
250 void WxGUIHtmlBrowser::OnReloadButton(wxCommandEvent& e)
254 //========================================================================
255 //========================================================================
256 std::string WxGUIHtmlBrowser::GetCurrentPage()
258 return wx2std(mwxURL->GetValue());
260 //========================================================================
263 //========================================================================
264 void WxGUIHtmlBrowser::OnIncludeFileButton(wxCommandEvent& )
266 std::string filename = wx2std(mwxURL->GetValue());
267 size_t s = filename.length();
269 WxGUIConsole* C = mWxGUIConsole; //::GetInstance();
270 // MessageManager::SetMessageLevel("All",9);
271 Interpreter* I = new Interpreter;
273 if ((s>3) && (filename[s-1]=='s')
274 && (filename[s-2]=='b')
275 && (filename[s-3]=='b')
276 && (filename[s-4]=='.'))
278 std::cout << "stat"<<std::endl;
279 if (C!=0) C->SetStatusText(_T("Executing ")+mwxURL->GetValue());
280 std::cout << "int"<<std::endl;
281 I->InterpretFile(filename);
282 std::cout << "eoint"<<std::endl;
286 if (C!=0) C->SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
291 //========================================================================
295 //========================================================================
296 void WxGUIHtmlBrowser::OnURLEnter( wxCommandEvent&)
298 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
300 //========================================================================
303 //========================================================================
304 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
311 wxString file = wxPathOnly(mwxURL->GetValue());
312 file += std2wx(ConfigurationFile::GetInstance().Get_file_separator());
313 file += e.GetLinkInfo().GetHref();
315 wxString file = e.GetLinkInfo().GetHref();
316 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
320 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
323 // mwxHtmlWindow->LoadPage(mwxURL->GetValue());
326 // mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
328 //========================================================================
331 //========================================================================
332 void WxGUIHtmlBrowser::OnSize(wxSizeEvent& e)
334 mwxHtmlWindow->EnableScrolling(true,true);
335 if ( mwxURL->GetValue()!=wxString(_T("")) )
337 // ?????????? No funciona ....?????
338 //EED2 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
339 // printf("EED WxGUIHtmlBrowser::OnSize %s \n", mwxURL->GetValue().c_str() );
340 //EED2 mwxHtmlWindow->Scroll( 10, 500);
348 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& )
350 std::cout << "OnCell"<<std::endl;
354 //========================================================================
355 void WxGUIHtmlBrowser::UpdateURL()
358 wxString s = mwxHtmlWindow->GetOpenedPage();
359 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
361 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
364 mwxURL->AppendText(s);
366 //========================================================================
368 //========================================================================
369 void WxGUIHtmlBrowser::SetSize( wxSize s)
371 // wxPanel::SetSize(s);
372 mwxHtmlWindow->SetSize(s);
375 //========================================================================