1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
6 Date: $Date: 2008/10/08 13:39:33 $
7 Version: $Revision: 1.8 $
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 //EED2 BEGIN_EVENT_TABLE(WxHtmlWindow, wxPanel)
77 //EED2 EVT_SIZE(WxHtmlWindow::OnSize)
78 //EED2 END_EVENT_TABLE()
80 //EED2 void WxHtmlWindow::OnSize( wxSizeEvent& )
82 //EED2 printf("EED WxHtmlWindow::OnSize \n" );
83 //EED2 Scroll(10,500);
87 //========================================================================
89 BEGIN_EVENT_TABLE(WxGUIHtmlBrowser, wxPanel)
90 EVT_BUTTON(bwd_id, WxGUIHtmlBrowser::OnBackButton )
91 EVT_BUTTON(fwd_id, WxGUIHtmlBrowser::OnForwardButton )
92 EVT_BUTTON(home_id, WxGUIHtmlBrowser::OnHomeButton )
93 EVT_BUTTON(reload_id, WxGUIHtmlBrowser::OnReloadButton )
94 // EVT_BUTTON(include_id, WxGUIHtmlBrowser::OnIncludeFileButton )
95 EVT_TEXT_ENTER(url_id, WxGUIHtmlBrowser::OnURLEnter )
96 EVT_HTML_LINK_CLICKED(html_id, WxGUIHtmlBrowser::OnLinkClicked)
97 EVT_SIZE(WxGUIHtmlBrowser::OnSize)
100 //========================================================================
103 //========================================================================
104 WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size,
105 WxGUIHtmlBrowserUser* user)
107 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
111 wxPanel* panel = this;
113 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
116 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL);
118 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition,
119 wxDefaultSize,wxBU_EXACTFIT);
120 bsizer->Add ( mwxBackButton , 0, wxALIGN_CENTRE );
122 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition,
123 wxDefaultSize,wxBU_EXACTFIT);
124 bsizer->Add ( mwxForwardButton , 0, wxALIGN_CENTRE );
126 mwxHomeButton = new wxButton( panel, home_id,_T("Home"),wxDefaultPosition,
127 wxDefaultSize,wxBU_EXACTFIT);
128 bsizer->Add ( mwxHomeButton , 0, wxALIGN_CENTRE );
130 mwxReloadButton = new wxButton( panel, reload_id,_T("Reload"),wxDefaultPosition,
131 wxDefaultSize,wxBU_EXACTFIT);
132 bsizer->Add ( mwxReloadButton , 0, wxALIGN_CENTRE );
135 mwxIncludeFileButton = new wxButton( panel, include_id,
136 _T("RUN"),wxDefaultPosition,
137 wxDefaultSize,wxBU_EXACTFIT);
138 bsizer->Add ( mwxIncludeFileButton , 0, wxALIGN_CENTRE | wxLEFT | wxTOP | wxBOTTOM , 10 );
141 mwxURL = new wxTextCtrl(panel,url_id,_T(""),
145 mwxURL->SetLabel(_T("URL"));
146 bsizer->Add(mwxURL, 1, wxEXPAND);
149 // mwxHtmlWindow = new WxHtmlWindow(parent,html_id,this,size);
150 mwxHtmlWindow = new WxHtmlWindow(this,html_id,this,size);
158 "bbtk::WxGUIHtmlBrowser");
160 mwxHtmlWindow->SetBorders(5);
161 // mwxHtmlWindow->FitInside();
163 wxStaticBoxSizer* hw =
164 new wxStaticBoxSizer( new wxStaticBox( this, -1, _T(""),
168 //EED hw->Add ( mwxHtmlWindow, 1, wxGROW );
169 hw->Add ( mwxHtmlWindow, 1, wxEXPAND );
175 //sizer->Add ( mwxHtmlWindow, 1, wxGROW );
176 //EED sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
178 sizer->Add ( bsizer , 0, wxEXPAND );
179 sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
183 panel -> SetSizer(sizer);
184 panel -> SetAutoLayout(true);
190 //========================================================================
193 //========================================================================
194 bool WxGUIHtmlBrowser::GoTo(std::string& file)
196 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
200 //========================================================================
202 //========================================================================
203 void WxGUIHtmlBrowser::OnBackButton(wxCommandEvent& )
205 mwxHtmlWindow->HistoryBack();
208 //========================================================================
210 //========================================================================
211 void WxGUIHtmlBrowser::OnForwardButton(wxCommandEvent& )
213 mwxHtmlWindow->HistoryForward();
216 //========================================================================
218 //========================================================================
219 void WxGUIHtmlBrowser::GoHome()
221 std::string url = ConfigurationFile::GetInstance().Get_doc_path();
222 url += "/bbtkWebSite/help_contents.html";
226 mwxURL->AppendText(std2wx(url));
230 if (Utilities::FileExists(url))
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() );
325 //========================================================================
328 //========================================================================
329 void WxGUIHtmlBrowser::OnSize(wxSizeEvent& e)
331 mwxHtmlWindow->EnableScrolling(true,true);
332 if ( mwxURL->GetValue()!=wxString(_T("")) )
334 // ?????????? No funciona ....?????
335 //EED2 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
336 // printf("EED WxGUIHtmlBrowser::OnSize %s \n", mwxURL->GetValue().c_str() );
337 //EED2 mwxHtmlWindow->Scroll( 10, 500);
345 void WxGUIHtmlBrowser::OnCell(wxHtmlCellEvent& )
347 std::cout << "OnCell"<<std::endl;
351 //========================================================================
352 void WxGUIHtmlBrowser::UpdateURL()
355 wxString s = mwxHtmlWindow->GetOpenedPage();
356 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
358 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
361 mwxURL->AppendText(s);
363 //========================================================================
365 //========================================================================
366 void WxGUIHtmlBrowser::SetSize( wxSize s)
368 // wxPanel::SetSize(s);
369 mwxHtmlWindow->SetSize(s);
372 //========================================================================