00001 /*========================================================================= 00002 Program: bbtk 00003 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $ 00004 Language: C++ 00005 Date: $Date: 2012/05/23 10:56:53 $ 00006 Version: $Revision: 1.14 $ 00007 =========================================================================*/ 00008 00009 /* --------------------------------------------------------------------- 00010 00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) 00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux 00013 * 00014 * This software is governed by the CeCILL-B license under French law and 00015 * abiding by the rules of distribution of free software. You can use, 00016 * modify and/ or redistribute the software under the terms of the CeCILL-B 00017 * license as circulated by CEA, CNRS and INRIA at the following URL 00018 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 00019 * or in the file LICENSE.txt. 00020 * 00021 * As a counterpart to the access to the source code and rights to copy, 00022 * modify and redistribute granted by the license, users are provided only 00023 * with a limited warranty and the software's author, the holder of the 00024 * economic rights, and the successive licensors have only limited 00025 * liability. 00026 * 00027 * The fact that you are presently reading this means that you have had 00028 * knowledge of the CeCILL-B license and that you accept its terms. 00029 * ------------------------------------------------------------------------ */ 00030 00031 00047 #ifdef _USE_WXWIDGETS_ 00048 00049 00050 #include "bbtkWxGUIHtmlBrowser.h" 00051 //#include "bbtkWxBlackBox.h" 00052 //#include "bbtkWxGUIConsole.h" 00053 00054 #include "bbtkConfigurationFile.h" 00055 #include "bbtkUtilities.h" 00056 00057 namespace bbtk 00058 { 00059 00060 //======================================================================== 00061 enum 00062 { 00063 bwd_id, 00064 fwd_id, 00065 home_id, 00066 reload_id, 00067 include_id, 00068 url_id , 00069 html_id = 10100 00070 }; 00071 00072 00073 /* 00074 //======================================================================== 00075 void WxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& e) 00076 { 00077 std::cout << "WxHtmlWindow::OnLink"<<std::endl; 00078 // std::cout << e.GetHref()<<std::endl; 00079 mBrowser->OnLinkClicked2(e); 00080 } 00081 */ 00082 00083 //EED2 BEGIN_EVENT_TABLE(WxHtmlWindow, wxPanel) 00084 //EED2 EVT_SIZE(WxHtmlWindow::OnSize) 00085 //EED2 END_EVENT_TABLE() 00086 00087 //EED2 void WxHtmlWindow::OnSize( wxSizeEvent& ) 00088 //EED2 { 00089 //EED2 printf("EED WxHtmlWindow::OnSize \n" ); 00090 //EED2 Scroll(10,500); 00091 //EED2 } 00092 00093 00094 //======================================================================== 00095 00096 BEGIN_EVENT_TABLE(WxGUIHtmlBrowser, wxPanel) 00097 EVT_BUTTON(bwd_id, WxGUIHtmlBrowser::OnBackButton ) 00098 EVT_BUTTON(fwd_id, WxGUIHtmlBrowser::OnForwardButton ) 00099 EVT_BUTTON(home_id, WxGUIHtmlBrowser::OnHomeButton ) 00100 EVT_BUTTON(reload_id, WxGUIHtmlBrowser::OnReloadButton ) 00101 // EVT_BUTTON(include_id, WxGUIHtmlBrowser::OnIncludeFileButton ) 00102 EVT_TEXT_ENTER(url_id, WxGUIHtmlBrowser::OnURLEnter ) 00103 EVT_HTML_LINK_CLICKED(html_id, WxGUIHtmlBrowser::OnLinkClicked) 00104 EVT_SIZE(WxGUIHtmlBrowser::OnSize) 00105 00106 END_EVENT_TABLE() 00107 //======================================================================== 00108 00109 00110 //======================================================================== 00111 WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size, 00112 WxGUIHtmlBrowserUser* user) 00113 : 00114 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), 00115 mUser(user) 00116 00117 { 00118 wxPanel* panel = this; 00119 00120 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); 00121 00122 00123 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL); 00124 00125 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition, 00126 wxDefaultSize,wxBU_EXACTFIT); 00127 bsizer->Add ( mwxBackButton , 0, wxALIGN_CENTRE ); 00128 00129 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition, 00130 wxDefaultSize,wxBU_EXACTFIT); 00131 bsizer->Add ( mwxForwardButton , 0, wxALIGN_CENTRE ); 00132 00133 mwxHomeButton = new wxButton( panel, home_id,_T("Home"),wxDefaultPosition, 00134 wxDefaultSize,wxBU_EXACTFIT); 00135 bsizer->Add ( mwxHomeButton , 0, wxALIGN_CENTRE ); 00136 00137 mwxReloadButton = new wxButton( panel, reload_id,_T("Reload"),wxDefaultPosition, 00138 wxDefaultSize,wxBU_EXACTFIT); 00139 bsizer->Add ( mwxReloadButton , 0, wxALIGN_CENTRE ); 00140 00141 /* 00142 mwxIncludeFileButton = new wxButton( panel, include_id, 00143 _T("RUN"),wxDefaultPosition, 00144 wxDefaultSize,wxBU_EXACTFIT); 00145 bsizer->Add ( mwxIncludeFileButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 ); 00146 */ 00147 00148 mwxURL = new wxTextCtrl(panel,url_id,_T(""), 00149 wxDefaultPosition, 00150 wxDefaultSize, 00151 wxTE_PROCESS_ENTER); 00152 mwxURL->SetLabel(_T("URL")); 00153 bsizer->Add(mwxURL, 1, wxEXPAND); 00154 00155 00156 // mwxHtmlWindow = new WxHtmlWindow(this,html_id,this,size); 00157 00158 mwxHtmlWindow = new wxHtmlWindow(this,html_id, 00159 wxDefaultPosition, 00160 size, 00161 wxHW_SCROLLBAR_AUTO, 00162 _T("bbtk::WxGUIHtmlBrowser")); 00163 00164 /* 00165 00166 -1, 00167 wxDefaultPosition, 00168 size, 00169 wxHW_SCROLLBAR_AUTO, 00170 "bbtk::WxGUIHtmlBrowser"); 00171 */ 00172 mwxHtmlWindow->SetBorders(5); 00173 // mwxHtmlWindow->FitInside(); 00174 00175 sizer->Add ( bsizer , 0, wxEXPAND ); 00176 00177 // EED: This have a problem in macOS 00178 // wxStaticBoxSizer* hw = 00179 // new wxStaticBoxSizer( 00180 // new wxStaticBox( this, -1, _T(""), wxDefaultPosition, size ), 00181 // wxVERTICAL 00182 // ); 00183 // hw->Add ( mwxHtmlWindow, 1, wxEXPAND ); 00184 //EED sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 ); 00185 00186 sizer->Add ( mwxHtmlWindow, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 ); 00187 00188 panel -> SetSizer(sizer); 00189 00190 panel -> SetAutoLayout(true); 00191 panel -> Layout(); 00192 00193 // GoHome(); 00194 00195 } 00196 //======================================================================== 00197 00198 00199 //======================================================================== 00200 bool WxGUIHtmlBrowser::GoTo(std::string& file) 00201 { 00202 bool r = mwxHtmlWindow->LoadPage(std2wx(file)); 00203 UpdateURL(); 00204 return r; 00205 } 00206 //======================================================================== 00207 00208 //======================================================================== 00209 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& ) 00210 { 00211 mwxHtmlWindow->HistoryBack(); 00212 UpdateURL(); 00213 } 00214 //======================================================================== 00215 00216 //======================================================================== 00217 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& ) 00218 { 00219 mwxHtmlWindow->HistoryForward(); 00220 UpdateURL(); 00221 } 00222 //======================================================================== 00223 00224 //======================================================================== 00225 void WxGUIHtmlBrowser::GoHome() 00226 { 00227 std::string url = ConfigurationFile::GetInstance().Get_doc_path(); 00228 url += "/help_contents.html"; 00229 GoTo(url); 00230 } 00231 //======================================================================== 00232 00233 //======================================================================== 00234 void WxGUIHtmlBrowser::OnHomeButton(wxCommandEvent& ) 00235 { 00236 GoHome(); 00237 } 00238 //======================================================================== 00239 00240 //======================================================================== 00241 void WxGUIHtmlBrowser::OnReloadButton(wxCommandEvent& e) 00242 { 00243 OnURLEnter(e); 00244 } 00245 //======================================================================== 00246 //======================================================================== 00247 std::string WxGUIHtmlBrowser::GetCurrentPage() 00248 { 00249 return wx2std(mwxURL->GetValue()); 00250 } 00251 //======================================================================== 00252 00253 /* 00254 //======================================================================== 00255 void WxGUIHtmlBrowser::OnIncludeFileButton(wxCommandEvent& ) 00256 { 00257 std::string filename = wx2std(mwxURL->GetValue()); 00258 size_t s = filename.length(); 00259 00260 WxGUIConsole* C = mWxGUIConsole; //::GetInstance(); 00261 // MessageManager::SetMessageLevel("All",9); 00262 Interpreter* I = new Interpreter; 00263 00264 if ((s>3) && (filename[s-1]=='s') 00265 && (filename[s-2]=='b') 00266 && (filename[s-3]=='b') 00267 && (filename[s-4]=='.')) 00268 { 00269 std::cout << "stat"<<std::endl; 00270 if (C!=0) C->SetStatusText(_T("Executing ")+mwxURL->GetValue()); 00271 std::cout << "int"<<std::endl; 00272 I->InterpretFile(filename); 00273 std::cout << "eoint"<<std::endl; 00274 } 00275 else 00276 { 00277 if (C!=0) C->SetStatusText(_T("The current page is not a bbs file : cannot execute it")); 00278 } 00279 00280 delete I; 00281 } 00282 //======================================================================== 00283 */ 00284 00285 00286 //======================================================================== 00287 void WxGUIHtmlBrowser::OnURLEnter( wxCommandEvent&) 00288 { 00289 mwxHtmlWindow->LoadPage(mwxURL->GetValue()); 00290 } 00291 //======================================================================== 00292 00293 //======================================================================== 00294 void WxGUIHtmlBrowser::OnLinkClicked2(const wxHtmlLinkInfo& info) 00295 { 00296 // std::cout << "OLK2"<<std::endl; 00297 bool go = true; 00298 if (mUser) 00299 { 00300 wxString file = info.GetHref(); 00301 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) ); 00302 } 00303 if (go) 00304 { 00305 mwxHtmlWindow->LoadPage( info.GetHref() ); 00306 UpdateURL(); 00307 } 00308 00309 00310 } 00311 00312 //======================================================================== 00313 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e) 00314 { 00315 // std::cout << "OLK"<<std::endl; 00316 bool go = true; 00317 if (mUser) 00318 { 00319 /* 00320 wxString file = wxPathOnly(mwxURL->GetValue()); 00321 file += std2wx(ConfigurationFile::GetInstance().Get_file_separator()); 00322 file += e.GetLinkInfo().GetHref(); 00323 */ 00324 wxString file = e.GetLinkInfo().GetHref(); 00325 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) ); 00326 } 00327 if (go) 00328 { 00329 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() ); 00330 UpdateURL(); 00331 // OnURLEnter(e); 00332 // mwxHtmlWindow->LoadPage(mwxURL->GetValue()); 00333 } 00334 00335 // mwxHtmlWindow->LoadPage( mwxURL->GetValue() ); 00336 } 00337 //======================================================================== 00338 00339 00340 //======================================================================== 00341 void WxGUIHtmlBrowser::OnSize(wxSizeEvent& e) 00342 { 00343 mwxHtmlWindow->EnableScrolling(true,true); 00344 if ( mwxURL->GetValue()!=wxString(_T("")) ) 00345 { 00346 // ?????????? No funciona ....????? 00347 //EED2 mwxHtmlWindow->LoadPage(mwxURL->GetValue()); 00348 // printf("EED WxGUIHtmlBrowser::OnSize %s \n", mwxURL->GetValue().c_str() ); 00349 //EED2 mwxHtmlWindow->Scroll( 10, 500); 00350 } else { 00351 // GoHome(); 00352 } 00353 e.Skip(true); 00354 } 00355 00356 /* 00357 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& ) 00358 { 00359 std::cout << "OnCell"<<std::endl; 00360 } 00361 */ 00362 00363 //======================================================================== 00364 void WxGUIHtmlBrowser::UpdateURL() 00365 { 00366 wxString s = mwxHtmlWindow->GetOpenedPage(); 00367 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty()) 00368 { 00369 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor(); 00370 } 00371 mwxURL->Clear(); 00372 mwxURL->AppendText(s); 00373 } 00374 //======================================================================== 00375 00376 //======================================================================== 00377 void WxGUIHtmlBrowser::SetSize( wxSize s) 00378 { 00379 // wxPanel::SetSize(s); 00380 mwxHtmlWindow->SetSize(s); 00381 Fit(); 00382 } 00383 //======================================================================== 00384 } 00385 00386 #endif