1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
5 Date: $Date: 2008/11/25 13:18:30 $
6 Version: $Revision: 1.12 $
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 wxStaticBoxSizer* hw =
176 new wxStaticBoxSizer( new wxStaticBox( this, -1, _T(""),
181 hw->Add ( mwxHtmlWindow, 1, wxEXPAND );
183 sizer->Add ( bsizer , 0, wxEXPAND );
184 sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
186 panel -> SetSizer(sizer);
187 panel -> SetAutoLayout(true);
193 //========================================================================
196 //========================================================================
197 bool WxGUIHtmlBrowser::GoTo(std::string& file)
199 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
203 //========================================================================
205 //========================================================================
206 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& )
208 mwxHtmlWindow->HistoryBack();
211 //========================================================================
213 //========================================================================
214 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& )
216 mwxHtmlWindow->HistoryForward();
219 //========================================================================
221 //========================================================================
222 void WxGUIHtmlBrowser::GoHome()
224 std::string url = ConfigurationFile::GetInstance().Get_doc_path();
225 url += "/help_contents.html";
228 //========================================================================
230 //========================================================================
231 void WxGUIHtmlBrowser::OnHomeButton(wxCommandEvent& )
235 //========================================================================
237 //========================================================================
238 void WxGUIHtmlBrowser::OnReloadButton(wxCommandEvent& e)
242 //========================================================================
243 //========================================================================
244 std::string WxGUIHtmlBrowser::GetCurrentPage()
246 return wx2std(mwxURL->GetValue());
248 //========================================================================
251 //========================================================================
252 void WxGUIHtmlBrowser::OnIncludeFileButton(wxCommandEvent& )
254 std::string filename = wx2std(mwxURL->GetValue());
255 size_t s = filename.length();
257 WxGUIConsole* C = mWxGUIConsole; //::GetInstance();
258 // MessageManager::SetMessageLevel("All",9);
259 Interpreter* I = new Interpreter;
261 if ((s>3) && (filename[s-1]=='s')
262 && (filename[s-2]=='b')
263 && (filename[s-3]=='b')
264 && (filename[s-4]=='.'))
266 std::cout << "stat"<<std::endl;
267 if (C!=0) C->SetStatusText(_T("Executing ")+mwxURL->GetValue());
268 std::cout << "int"<<std::endl;
269 I->InterpretFile(filename);
270 std::cout << "eoint"<<std::endl;
274 if (C!=0) C->SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
279 //========================================================================
283 //========================================================================
284 void WxGUIHtmlBrowser::OnURLEnter( wxCommandEvent&)
286 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
288 //========================================================================
290 //========================================================================
291 void WxGUIHtmlBrowser::OnLinkClicked2(const wxHtmlLinkInfo& info)
293 // std::cout << "OLK2"<<std::endl;
297 wxString file = info.GetHref();
298 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
302 mwxHtmlWindow->LoadPage( info.GetHref() );
309 //========================================================================
310 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
312 // std::cout << "OLK"<<std::endl;
317 wxString file = wxPathOnly(mwxURL->GetValue());
318 file += std2wx(ConfigurationFile::GetInstance().Get_file_separator());
319 file += e.GetLinkInfo().GetHref();
321 wxString file = e.GetLinkInfo().GetHref();
322 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
326 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
329 // mwxHtmlWindow->LoadPage(mwxURL->GetValue());
332 // mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
334 //========================================================================
337 //========================================================================
338 void WxGUIHtmlBrowser::OnSize(wxSizeEvent& e)
340 mwxHtmlWindow->EnableScrolling(true,true);
341 if ( mwxURL->GetValue()!=wxString(_T("")) )
343 // ?????????? No funciona ....?????
344 //EED2 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
345 // printf("EED WxGUIHtmlBrowser::OnSize %s \n", mwxURL->GetValue().c_str() );
346 //EED2 mwxHtmlWindow->Scroll( 10, 500);
354 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& )
356 std::cout << "OnCell"<<std::endl;
360 //========================================================================
361 void WxGUIHtmlBrowser::UpdateURL()
364 wxString s = mwxHtmlWindow->GetOpenedPage();
365 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
367 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
370 mwxURL->AppendText(s);
372 //========================================================================
374 //========================================================================
375 void WxGUIHtmlBrowser::SetSize( wxSize s)
377 // wxPanel::SetSize(s);
378 mwxHtmlWindow->SetSize(s);
381 //========================================================================