3 #include "bbtkWxBrowser.h"
4 #include "bbtkWxBlackBox.h"
11 void WxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& e)
13 // std::cout << "WxHtmlWindow::OnLink"<<std::endl;
14 // std::cout << e.GetHref()<<std::endl;
15 LoadPage(e.GetHref());
16 if ( ! GetOpenedAnchor().IsEmpty() )
18 // std::cout << "#" << GetOpenedAnchor() << std::endl;
19 LoadPage(_T("#"+GetOpenedAnchor()));
21 mBrowser->UpdateURL();
36 BEGIN_EVENT_TABLE(WxBrowser, wxPanel)
37 EVT_BUTTON(bwd_id, WxBrowser::OnBackButton )
38 EVT_BUTTON(fwd_id, WxBrowser::OnForwardButton )
39 EVT_TEXT_ENTER(url_id, WxBrowser::OnURLEnter )
40 EVT_HTML_LINK_CLICKED(html_id, WxBrowser::OnLinkClicked)
43 WxBrowser::WxBrowser ( wxWindow *parent, wxSize size )
45 wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
48 wxPanel* panel = this;
50 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
53 wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL);
55 sizer->Add ( bsizer, 0, wxGROW );
58 mwxBackButton = new wxButton( panel, bwd_id,_T("<"),wxDefaultPosition,
59 wxDefaultSize,wxBU_EXACTFIT);
60 bsizer->Add ( mwxBackButton, 0, wxALIGN_CENTRE |
61 wxLEFT | wxTOP | wxBOTTOM , 10 );
63 mwxForwardButton = new wxButton( panel, fwd_id,_T(">"),wxDefaultPosition,
64 wxDefaultSize,wxBU_EXACTFIT);
65 bsizer->Add ( mwxForwardButton, 0, wxALIGN_CENTRE |
66 wxTOP | wxBOTTOM , 10);
69 mwxURL = new wxTextCtrl(panel,url_id,_T(""),
73 mwxURL->SetLabel(_T("URL"));
74 bsizer->Add(mwxURL, 1, wxGROW | wxALL, 10);
77 mwxHtmlWindow = new WxHtmlWindow(parent,html_id,this,size);
87 mwxHtmlWindow->SetBorders(5);
88 // mwxHtmlWindow->FitInside();
89 wxStaticBoxSizer* hw =
90 new wxStaticBoxSizer( new wxStaticBox( this, -1, _T(""),
94 hw->Add ( mwxHtmlWindow, 1, wxGROW );
95 //sizer->Add ( mwxHtmlWindow, 1, wxGROW );
97 sizer->Add ( hw, 1, wxGROW ); // | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
101 panel -> SetSizer(sizer);
102 panel -> SetAutoLayout(true);
106 Connect( mwxBackButton->GetId(),
107 wxEVT_COMMAND_BUTTON_CLICKED ,
108 (wxObjectEventFunction)
109 (void (wxPanel::*)(wxEvent&))
110 &WxBrowser::OnBackButton );
111 Connect( mwxForwardButton->GetId(),
112 wxEVT_COMMAND_BUTTON_CLICKED ,
113 (wxObjectEventFunction)
114 (void (wxPanel::*)(wxEvent&))
115 &WxBrowser::OnForwardButton );
117 std::cout << "e="<<wxEVT_COMMAND_HTML_LINK_CLICKED<<std::endl;
119 Connect( wxID_ANY, //mwxHtmlWindow->GetId(),
120 wxEVT_COMMAND_HTML_LINK_CLICKED ,
121 wxHtmlLinkEventHandler(
122 //(wxObjectEventFunction)
123 // (void (wxPanel::*)(wxEvent&))&
124 WxBrowser::OnLinkClicked ) );
125 Connect( mwxHtmlWindow->GetId(),
126 wxEVT_COMMAND_HTML_CELL_HOVER,
127 //(wxObjectEventFunction)
128 wxHtmlCellEventHandler(
129 // (void (wxPanel::*)(wxHtmlCellEvent&))&
130 WxBrowser::OnCell ) );
135 bool WxBrowser::GoTo(std::string& file)
137 // std::cout << "goto"<<std::endl;
138 bool r = mwxHtmlWindow->LoadPage(std2wx(file));
143 void WxBrowser::OnBackButton(wxCommandEvent& )
145 // std::cout << "back"<<std::endl;
146 mwxHtmlWindow->HistoryBack();
150 void WxBrowser::OnForwardButton(wxCommandEvent& )
152 // std::cout << "forward"<<std::endl;
153 mwxHtmlWindow->HistoryForward();
157 void WxBrowser::OnURLEnter( wxCommandEvent&)
159 //std::cout << "OnURL"<<std::endl;
160 mwxHtmlWindow->LoadPage(mwxURL->GetValue());
164 void WxBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
166 std::cout << "WxBrowser::OnLinkClicked"<<std::endl;
167 std::cout << e.GetLinkInfo().GetHref()<<std::endl;
168 mwxHtmlWindow->LoadPage(e.GetLinkInfo().GetHref());
172 void WxBrowser::OnCell(wxHtmlCellEvent& )
174 std::cout << "OnCell"<<std::endl;
177 void WxBrowser::UpdateURL()
180 wxString s = mwxHtmlWindow->GetOpenedPage();
181 if (!mwxHtmlWindow->GetOpenedAnchor().IsEmpty())
183 s += _T("#") + mwxHtmlWindow->GetOpenedAnchor();
186 mwxURL->AppendText(s);
188 void WxBrowser::SetSize( wxSize s)
190 // wxPanel::SetSize(s);
191 mwxHtmlWindow->SetSize(s);