00001 /*========================================================================= 00002 Program: bbtk 00003 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $ 00004 Language: C++ 00005 Date: $Date: 2008/10/17 08:18:15 $ 00006 Version: $Revision: 1.10 $ 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 00070 }; 00071 00072 00073 /*EED 00074 //======================================================================== 00075 void WxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& e) 00076 { 00077 std::cout << "WxHtmlWindow::OnLink"<<std::endl; 00078 // std::cout << e.GetHref()<<std::endl; 00079 LoadPage(e.GetHref()); 00080 if ( ! GetOpenedAnchor().IsEmpty() ) 00081 { 00082 // std::cout << "#" << GetOpenedAnchor() << std::endl; 00083 LoadPage(_T("#"+GetOpenedAnchor())); 00084 } 00085 mBrowser->UpdateURL(); 00086 } 00087 //======================================================================== 00088 */ 00089 00090 00091 //EED2 BEGIN_EVENT_TABLE(WxHtmlWindow, wxPanel) 00092 //EED2 EVT_SIZE(WxHtmlWindow::OnSize) 00093 //EED2 END_EVENT_TABLE() 00094 00095 //EED2 void WxHtmlWindow::OnSize( wxSizeEvent& ) 00096 //EED2 { 00097 //EED2 printf("EED WxHtmlWindow::OnSize \n" ); 00098 //EED2 Scroll(10,500); 00099 //EED2 } 00100 00101 00102 //======================================================================== 00103 00104 BEGIN_EVENT_TABLE(WxGUIHtmlBrowser, wxPanel) 00105 EVT_BUTTON(bwd_id, WxGUIHtmlBrowser::OnBackButton ) 00106 EVT_BUTTON(fwd_id, WxGUIHtmlBrowser::OnForwardButton ) 00107 EVT_BUTTON(home_id, WxGUIHtmlBrowser::OnHomeButton ) 00108 EVT_BUTTON(reload_id, WxGUIHtmlBrowser::OnReloadButton ) 00109 // EVT_BUTTON(include_id, WxGUIHtmlBrowser::OnIncludeFileButton ) 00110 EVT_TEXT_ENTER(url_id, WxGUIHtmlBrowser::OnURLEnter ) 00111 EVT_HTML_LINK_CLICKED(html_id, WxGUIHtmlBrowser::OnLinkClicked) 00112 EVT_SIZE(WxGUIHtmlBrowser::OnSize) 00113 00114 END_EVENT_TABLE() 00115 //======================================================================== 00116 00117 00118 //======================================================================== 00119 WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size, 00120 WxGUIHtmlBrowserUser* user) 00121 : 00122 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), 00123 mUser(user) 00124 00125 { 00126 wxPanel* panel = this; 00127 00128 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); 00129 00130 00131 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL); 00132 00133 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition, 00134 wxDefaultSize,wxBU_EXACTFIT); 00135 bsizer->Add ( mwxBackButton , 0, wxALIGN_CENTRE ); 00136 00137 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition, 00138 wxDefaultSize,wxBU_EXACTFIT); 00139 bsizer->Add ( mwxForwardButton , 0, wxALIGN_CENTRE ); 00140 00141 mwxHomeButton = new wxButton( panel, home_id,_T("Home"),wxDefaultPosition, 00142 wxDefaultSize,wxBU_EXACTFIT); 00143 bsizer->Add ( mwxHomeButton , 0, wxALIGN_CENTRE ); 00144 00145 mwxReloadButton = new wxButton( panel, reload_id,_T("Reload"),wxDefaultPosition, 00146 wxDefaultSize,wxBU_EXACTFIT); 00147 bsizer->Add ( mwxReloadButton , 0, wxALIGN_CENTRE ); 00148 00149 /* 00150 mwxIncludeFileButton = new wxButton( panel, include_id, 00151 _T("RUN"),wxDefaultPosition, 00152 wxDefaultSize,wxBU_EXACTFIT); 00153 bsizer->Add ( mwxIncludeFileButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 ); 00154 */ 00155 00156 mwxURL = new wxTextCtrl(panel,url_id,_T(""), 00157 wxDefaultPosition, 00158 wxDefaultSize, 00159 wxTE_PROCESS_ENTER); 00160 mwxURL->SetLabel(_T("URL")); 00161 bsizer->Add(mwxURL, 1, wxEXPAND); 00162 00163 00164 // mwxHtmlWindow = new WxHtmlWindow(parent,html_id,this,size); 00165 mwxHtmlWindow = new WxHtmlWindow(this,html_id,this,size); 00166 00167 /* 00168 00169 -1, 00170 wxDefaultPosition, 00171 size, 00172 wxHW_SCROLLBAR_AUTO, 00173 "bbtk::WxGUIHtmlBrowser"); 00174 */ 00175 mwxHtmlWindow->SetBorders(5); 00176 // mwxHtmlWindow->FitInside(); 00177 00178 wxStaticBoxSizer* hw = 00179 new wxStaticBoxSizer( new wxStaticBox( this, -1, _T(""), 00180 wxDefaultPosition, 00181 size ), 00182 wxVERTICAL ); 00183 //EED hw->Add ( mwxHtmlWindow, 1, wxGROW ); 00184 hw->Add ( mwxHtmlWindow, 1, wxEXPAND ); 00185 00186 00187 00188 00189 00190 //sizer->Add ( mwxHtmlWindow, 1, wxGROW ); 00191 //EED sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 ); 00192 00193 sizer->Add ( bsizer , 0, wxEXPAND ); 00194 sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 ); 00195 00196 00197 00198 panel -> SetSizer(sizer); 00199 panel -> SetAutoLayout(true); 00200 panel -> Layout(); 00201 00202 // GoHome(); 00203 00204 } 00205 //======================================================================== 00206 00207 00208 //======================================================================== 00209 bool WxGUIHtmlBrowser::GoTo(std::string& file) 00210 { 00211 bool r = mwxHtmlWindow->LoadPage(std2wx(file)); 00212 UpdateURL(); 00213 return r; 00214 } 00215 //======================================================================== 00216 00217 //======================================================================== 00218 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& ) 00219 { 00220 mwxHtmlWindow->HistoryBack(); 00221 UpdateURL(); 00222 } 00223 //======================================================================== 00224 00225 //======================================================================== 00226 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& ) 00227 { 00228 mwxHtmlWindow->HistoryForward(); 00229 UpdateURL(); 00230 } 00231 //======================================================================== 00232 00233 //======================================================================== 00234 void WxGUIHtmlBrowser::GoHome() 00235 { 00236 std::string url = ConfigurationFile::GetInstance().Get_doc_path(); 00237 url += "/help_contents.html"; 00238 GoTo(url); 00239 } 00240 //======================================================================== 00241 00242 //======================================================================== 00243 void WxGUIHtmlBrowser::OnHomeButton(wxCommandEvent& ) 00244 { 00245 GoHome(); 00246 } 00247 //======================================================================== 00248 00249 //======================================================================== 00250 void WxGUIHtmlBrowser::OnReloadButton(wxCommandEvent& e) 00251 { 00252 OnURLEnter(e); 00253 } 00254 //======================================================================== 00255 //======================================================================== 00256 std::string WxGUIHtmlBrowser::GetCurrentPage() 00257 { 00258 return wx2std(mwxURL->GetValue()); 00259 } 00260 //======================================================================== 00261 00262 /* 00263 //======================================================================== 00264 void WxGUIHtmlBrowser::OnIncludeFileButton(wxCommandEvent& ) 00265 { 00266 std::string filename = wx2std(mwxURL->GetValue()); 00267 size_t s = filename.length(); 00268 00269 WxGUIConsole* C = mWxGUIConsole; //::GetInstance(); 00270 // MessageManager::SetMessageLevel("All",9); 00271 Interpreter* I = new Interpreter; 00272 00273 if ((s>3) && (filename[s-1]=='s') 00274 && (filename[s-2]=='b') 00275 && (filename[s-3]=='b') 00276 && (filename[s-4]=='.')) 00277 { 00278 std::cout << "stat"<<std::endl; 00279 if (C!=0) C->SetStatusText(_T("Executing ")+mwxURL->GetValue()); 00280 std::cout << "int"<<std::endl; 00281 I->InterpretFile(filename); 00282 std::cout << "eoint"<<std::endl; 00283 } 00284 else 00285 { 00286 if (C!=0) C->SetStatusText(_T("The current page is not a bbs file : cannot execute it")); 00287 } 00288 00289 delete I; 00290 } 00291 //======================================================================== 00292 */ 00293 00294 00295 //======================================================================== 00296 void WxGUIHtmlBrowser::OnURLEnter( wxCommandEvent&) 00297 { 00298 mwxHtmlWindow->LoadPage(mwxURL->GetValue()); 00299 } 00300 //======================================================================== 00301 00302 00303 //======================================================================== 00304 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e) 00305 { 00306 00307 bool go = true; 00308 if (mUser) 00309 { 00310 /* 00311 wxString file = wxPathOnly(mwxURL->GetValue()); 00312 file += std2wx(ConfigurationFile::GetInstance().Get_file_separator()); 00313 file += e.GetLinkInfo().GetHref(); 00314 */ 00315 wxString file = e.GetLinkInfo().GetHref(); 00316 go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) ); 00317 } 00318 if (go) 00319 { 00320 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() ); 00321 UpdateURL(); 00322 // OnURLEnter(e); 00323 // mwxHtmlWindow->LoadPage(mwxURL->GetValue()); 00324 } 00325 00326 // mwxHtmlWindow->LoadPage( mwxURL->GetValue() ); 00327 } 00328 //======================================================================== 00329 00330 00331 //======================================================================== 00332 void WxGUIHtmlBrowser::OnSize(wxSizeEvent& e) 00333 { 00334 mwxHtmlWindow->EnableScrolling(true,true); 00335 if ( mwxURL->GetValue()!=wxString(_T("")) ) 00336 { 00337 // ?????????? No funciona ....????? 00338 //EED2 mwxHtmlWindow->LoadPage(mwxURL->GetValue()); 00339 // printf("EED WxGUIHtmlBrowser::OnSize %s \n", mwxURL->GetValue().c_str() ); 00340 //EED2 mwxHtmlWindow->Scroll( 10, 500); 00341 } else { 00342 // GoHome(); 00343 } 00344 e.Skip(true); 00345 } 00346 00347 /* 00348 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& ) 00349 { 00350 std::cout << "OnCell"<<std::endl; 00351 } 00352 */ 00353 00354 //======================================================================== 00355 void WxGUIHtmlBrowser::UpdateURL() 00356 { 00357 00358 wxString s = mwxHtmlWindow->GetOpenedPage(); 00359 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty()) 00360 { 00361 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor(); 00362 } 00363 mwxURL->Clear(); 00364 mwxURL->AppendText(s); 00365 } 00366 //======================================================================== 00367 00368 //======================================================================== 00369 void WxGUIHtmlBrowser::SetSize( wxSize s) 00370 { 00371 // wxPanel::SetSize(s); 00372 mwxHtmlWindow->SetSize(s); 00373 Fit(); 00374 } 00375 //======================================================================== 00376 } 00377 00378 #endif