1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
6 Date: $Date: 2008/03/20 09:51:29 $
7 Version: $Revision: 1.1 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*//**
18 * \brief Short description in one line
20 * Long description which
21 * can span multiple lines
32 #ifdef _USE_WXWIDGETS_
35 #include "bbtkWxGUIHtmlBrowser.h"
36 //#include "bbtkWxBlackBox.h"
37 //#include "bbtkWxGUIConsole.h"
39 #include "bbtkConfigurationFile.h"
40 #include "bbtkUtilities.h"
45 //========================================================================
59 //========================================================================
60 void WxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& e)
62 std::cout << "WxHtmlWindow::OnLink"<<std::endl;
63 // std::cout << e.GetHref()<<std::endl;
64 LoadPage(e.GetHref());
65 if ( ! GetOpenedAnchor().IsEmpty() )
67 // std::cout << "#" << GetOpenedAnchor() << std::endl;
68 LoadPage(_T("#"+GetOpenedAnchor()));
70 mBrowser->UpdateURL();
72 //========================================================================
76 //========================================================================
78 BEGIN_EVENT_TABLE(WxGUIHtmlBrowser, wxPanel)
79 EVT_BUTTON(bwd_id, WxGUIHtmlBrowser::OnBackButton )
80 EVT_BUTTON(fwd_id, WxGUIHtmlBrowser::OnForwardButton )
81 EVT_BUTTON(home_id, WxGUIHtmlBrowser::OnHomeButton )
82 EVT_BUTTON(reload_id, WxGUIHtmlBrowser::OnReloadButton )
83 // EVT_BUTTON(include_id, WxGUIHtmlBrowser::OnIncludeFileButton )
84 EVT_TEXT_ENTER(url_id, WxGUIHtmlBrowser::OnURLEnter )
85 EVT_HTML_LINK_CLICKED(html_id, WxGUIHtmlBrowser::OnLinkClicked)
87 //========================================================================
90 //========================================================================
91 WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size )
93 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
97 wxPanel* panel = this;
99 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
102 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL);
104 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition,
105 wxDefaultSize,wxBU_EXACTFIT);
106 bsizer->Add ( mwxBackButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 );
108 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition,
109 wxDefaultSize,wxBU_EXACTFIT);
110 bsizer->Add ( mwxForwardButton , 0, wxALIGN_CENTRE | wxTOP | wxBOTTOM , 10);
112 mwxHomeButton = new wxButton( panel, home_id,_T("Home"),wxDefaultPosition,
113 wxDefaultSize,wxBU_EXACTFIT);
114 bsizer->Add ( mwxHomeButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 );
116 mwxReloadButton = new wxButton( panel, reload_id,_T("Reload"),wxDefaultPosition,
117 wxDefaultSize,wxBU_EXACTFIT);
118 bsizer->Add ( mwxReloadButton , 0, wxALIGN_CENTRE | wxTOP | wxBOTTOM , 10 );
121 mwxIncludeFileButton = new wxButton( panel, include_id,
122 _T("RUN"),wxDefaultPosition,
123 wxDefaultSize,wxBU_EXACTFIT);
124 bsizer->Add ( mwxIncludeFileButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 );
127 mwxURL = new wxTextCtrl(panel,url_id,_T(""),
131 mwxURL->SetLabel(_T("URL"));
132 bsizer->Add(mwxURL, 1, wxEXPAND | wxALL, 10);
135 // mwxHtmlWindow = new WxHtmlWindow(parent,html_id,this,size);
136 mwxHtmlWindow = new WxHtmlWindow(this,html_id,this,size);
144 "bbtk::WxGUIHtmlBrowser");
146 mwxHtmlWindow->SetBorders(5);
147 // mwxHtmlWindow->FitInside();
149 wxStaticBoxSizer* hw =
150 new wxStaticBoxSizer( new wxStaticBox( this, -1, _T(""),
154 //EED hw->Add ( mwxHtmlWindow, 1, wxGROW );
155 hw->Add ( mwxHtmlWindow, 1, wxEXPAND );
161 //sizer->Add ( mwxHtmlWindow, 1, wxGROW );
162 //EED sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
164 sizer->Add ( bsizer , 0, wxEXPAND );
165 sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
169 panel -> SetSizer(sizer);
170 panel -> SetAutoLayout(true);
176 //========================================================================
179 //========================================================================
180 bool WxGUIHtmlBrowser::GoTo(std::string& file)
182 // std::cout << "goto"<<std::endl;
184 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
188 //========================================================================
190 //========================================================================
191 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& )
193 // std::cout << "back"<<std::endl;
194 mwxHtmlWindow->HistoryBack();
197 //========================================================================
199 //========================================================================
200 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& )
202 // std::cout << "forward"<<std::endl;
203 mwxHtmlWindow->HistoryForward();
206 //========================================================================
208 //========================================================================
209 void WxGUIHtmlBrowser::GoHome()
211 std::string url = ConfigurationFile::GetInstance().Get_doc_path();
212 url += "/bbtkWebSite/menu.html";
216 mwxURL->AppendText(std2wx(url));
220 if (Utilities::FileExists(url))
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 //========================================================================
293 //========================================================================
294 void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
296 mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
298 mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
300 //========================================================================
304 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& )
306 std::cout << "OnCell"<<std::endl;
310 //========================================================================
311 void WxGUIHtmlBrowser::UpdateURL()
314 wxString s = mwxHtmlWindow->GetOpenedPage();
315 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
317 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
320 mwxURL->AppendText(s);
322 //========================================================================
324 //========================================================================
325 void WxGUIHtmlBrowser::SetSize( wxSize s)
327 // wxPanel::SetSize(s);
328 mwxHtmlWindow->SetSize(s);
331 //========================================================================