1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWebView sample
4 // Author: Marianne Gagnon
6 // Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
25 #include <wx/artprov.h>
26 #include <wx/notifmsg.h>
27 #include <wx/settings.h>
28 #include <wx/webview.h>
29 #include <wx/infobar.h>
30 #include <wx/filesys.h>
31 #include <wx/fs_arc.h>
33 #if !defined(__WXMSW__) && !defined(__WXPM__)
34 #include "../sample.xpm"
38 #include <wx/stc/stc.h>
40 #error "wxStyledTextControl is needed by this sample"
44 #include "refresh.xpm"
47 class WebApp
: public wxApp
50 virtual bool OnInit();
53 class WebFrame
: public wxFrame
58 void OnAnimationTimer(wxTimerEvent
& evt
);
60 void OnUrl(wxCommandEvent
& evt
);
61 void OnBack(wxCommandEvent
& evt
);
62 void OnForward(wxCommandEvent
& evt
);
63 void OnStop(wxCommandEvent
& evt
);
64 void OnReload(wxCommandEvent
& evt
);
65 void OnClearHistory(wxCommandEvent
& evt
);
66 void OnEnableHistory(wxCommandEvent
& evt
);
67 void OnNavigationRequest(wxWebNavigationEvent
& evt
);
68 void OnNavigationComplete(wxWebNavigationEvent
& evt
);
69 void OnDocumentLoaded(wxWebNavigationEvent
& evt
);
70 void OnNewWindow(wxWebNavigationEvent
& evt
);
71 void OnTitleChanged(wxWebNavigationEvent
& evt
);
72 void OnViewSourceRequest(wxCommandEvent
& evt
);
73 void OnToolsClicked(wxCommandEvent
& evt
);
74 void OnSetZoom(wxCommandEvent
& evt
);
75 void OnError(wxWebNavigationEvent
& evt
);
76 void OnPrint(wxCommandEvent
& evt
);
77 void OnCut(wxCommandEvent
& evt
);
78 void OnCopy(wxCommandEvent
& evt
);
79 void OnPaste(wxCommandEvent
& evt
);
80 void OnUndo(wxCommandEvent
& evt
);
81 void OnRedo(wxCommandEvent
& evt
);
82 void OnMode(wxCommandEvent
& evt
);
83 void OnZoomLayout(wxCommandEvent
& evt
);
90 wxToolBarToolBase
* m_toolbar_back
;
91 wxToolBarToolBase
* m_toolbar_forward
;
92 wxToolBarToolBase
* m_toolbar_stop
;
93 wxToolBarToolBase
* m_toolbar_reload
;
94 wxToolBarToolBase
* m_toolbar_tools
;
97 wxMenuItem
* m_tools_layout
;
98 wxMenuItem
* m_tools_tiny
;
99 wxMenuItem
* m_tools_small
;
100 wxMenuItem
* m_tools_medium
;
101 wxMenuItem
* m_tools_large
;
102 wxMenuItem
* m_tools_largest
;
103 wxMenuItem
* m_tools_handle_navigation
;
104 wxMenuItem
* m_tools_handle_new_window
;
105 wxMenuItem
* m_tools_enable_history
;
106 wxMenuItem
* m_edit_cut
;
107 wxMenuItem
* m_edit_copy
;
108 wxMenuItem
* m_edit_paste
;
109 wxMenuItem
* m_edit_undo
;
110 wxMenuItem
* m_edit_redo
;
111 wxMenuItem
* m_edit_mode
;
114 int m_animation_angle
;
117 wxStaticText
* m_info_text
;
120 class SourceViewDialog
: public wxDialog
123 SourceViewDialog(wxWindow
* parent
, wxString source
);
126 IMPLEMENT_APP(WebApp
)
128 // ============================================================================
130 // ============================================================================
132 bool WebApp::OnInit()
134 if ( !wxApp::OnInit() )
137 WebFrame
*frame
= new WebFrame();
143 WebFrame::WebFrame() : wxFrame(NULL
, wxID_ANY
, "wxWebView Sample")
145 //Required from virtual file system archive support
146 wxFileSystem::AddHandler(new wxArchiveFSHandler
);
148 // set the frame icon
149 SetIcon(wxICON(sample
));
150 SetTitle("wxWebView Sample");
153 m_animation_angle
= 0;
156 wxBoxSizer
* topsizer
= new wxBoxSizer(wxVERTICAL
);
158 // Create the toolbar
159 m_toolbar
= CreateToolBar(wxTB_TEXT
);
160 m_toolbar
->SetToolBitmapSize(wxSize(32, 32));
162 wxBitmap back
= wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
163 wxBitmap forward
= wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
165 wxBitmap stop
= wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR
);
167 wxBitmap stop
= wxBitmap(stop_xpm
);
170 wxBitmap refresh
= wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR
);
172 wxBitmap refresh
= wxBitmap(refresh_xpm
);
175 m_toolbar_back
= m_toolbar
->AddTool(wxID_ANY
, _("Back"), back
);
176 m_toolbar_forward
= m_toolbar
->AddTool(wxID_ANY
, _("Forward"), forward
);
177 m_toolbar_stop
= m_toolbar
->AddTool(wxID_ANY
, _("Stop"), stop
);
178 m_toolbar_reload
= m_toolbar
->AddTool(wxID_ANY
, _("Reload"), refresh
);
179 m_url
= new wxTextCtrl(m_toolbar
, wxID_ANY
, wxT(""), wxDefaultPosition
, wxSize(400, -1), wxTE_PROCESS_ENTER
);
180 m_toolbar
->AddControl(m_url
, _("URL"));
181 m_toolbar_tools
= m_toolbar
->AddTool(wxID_ANY
, _("Menu"), wxBitmap(wxlogo_xpm
));
183 m_toolbar
->Realize();
185 // Create the info panel
186 m_info
= new wxInfoBar(this);
187 topsizer
->Add(m_info
, wxSizerFlags().Expand());
189 // Create the webview
190 m_browser
= wxWebView::New(this, wxID_ANY
, "http://www.wxwidgets.org");
191 topsizer
->Add(m_browser
, wxSizerFlags().Expand().Proportion(1));
193 //We register the test:// protocol for testing purposes
194 m_browser
->RegisterProtocol(new wxWebFileProtocolHandler());
198 //Set a more sensible size for web browsing
199 SetSize(wxSize(800, 600));
201 // Create a log window
202 new wxLogWindow(this, _("Logging"));
204 // Create the Tools menu
205 m_tools_menu
= new wxMenu();
206 wxMenuItem
* print
= m_tools_menu
->Append(wxID_ANY
, _("Print"));
207 wxMenuItem
* viewSource
= m_tools_menu
->Append(wxID_ANY
, _("View Source"));
208 m_tools_menu
->AppendSeparator();
209 m_tools_layout
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Use Layout Zoom"));
210 m_tools_tiny
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Tiny"));
211 m_tools_small
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Small"));
212 m_tools_medium
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Medium"));
213 m_tools_large
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Large"));
214 m_tools_largest
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Largest"));
215 m_tools_menu
->AppendSeparator();
216 m_tools_handle_navigation
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle Navigation"));
217 m_tools_handle_new_window
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle New Windows"));
218 m_tools_menu
->AppendSeparator();
219 wxMenuItem
* clearhist
= m_tools_menu
->Append(wxID_ANY
, _("Clear History"));
220 m_tools_enable_history
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Enable History"));
222 //Create an editing menu
223 wxMenu
* editmenu
= new wxMenu();
224 m_edit_cut
= editmenu
->Append(wxID_ANY
, _("Cut"));
225 m_edit_copy
= editmenu
->Append(wxID_ANY
, _("Copy"));
226 m_edit_paste
= editmenu
->Append(wxID_ANY
, _("Paste"));
227 editmenu
->AppendSeparator();
228 m_edit_undo
= editmenu
->Append(wxID_ANY
, _("Undo"));
229 m_edit_redo
= editmenu
->Append(wxID_ANY
, _("Redo"));
230 editmenu
->AppendSeparator();
231 m_edit_mode
= editmenu
->AppendCheckItem(wxID_ANY
, _("Edit Mode"));
233 m_tools_menu
->AppendSeparator();
234 m_tools_menu
->AppendSubMenu(editmenu
, "Edit");
236 //By default we want to handle navigation and new windows
237 m_tools_handle_navigation
->Check();
238 m_tools_handle_new_window
->Check();
239 m_tools_enable_history
->Check();
240 if(!m_browser
->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
))
241 m_tools_layout
->Enable(false);
244 // Connect the toolbar events
245 Connect(m_toolbar_back
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
246 wxCommandEventHandler(WebFrame::OnBack
), NULL
, this );
247 Connect(m_toolbar_forward
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
248 wxCommandEventHandler(WebFrame::OnForward
), NULL
, this );
249 Connect(m_toolbar_stop
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
250 wxCommandEventHandler(WebFrame::OnStop
), NULL
, this );
251 Connect(m_toolbar_reload
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
252 wxCommandEventHandler(WebFrame::OnReload
),NULL
, this );
253 Connect(m_toolbar_tools
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
254 wxCommandEventHandler(WebFrame::OnToolsClicked
), NULL
, this );
256 Connect(m_url
->GetId(), wxEVT_COMMAND_TEXT_ENTER
,
257 wxCommandEventHandler(WebFrame::OnUrl
), NULL
, this );
259 // Connect the webview events
260 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
261 wxWebNavigationEventHandler(WebFrame::OnNavigationRequest
), NULL
, this);
262 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
263 wxWebNavigationEventHandler(WebFrame::OnNavigationComplete
), NULL
, this);
264 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED
,
265 wxWebNavigationEventHandler(WebFrame::OnDocumentLoaded
), NULL
, this);
266 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR
,
267 wxWebNavigationEventHandler(WebFrame::OnError
), NULL
, this);
268 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
269 wxWebNavigationEventHandler(WebFrame::OnNewWindow
), NULL
, this);
270 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
271 wxWebNavigationEventHandler(WebFrame::OnTitleChanged
), NULL
, this);
273 // Connect the menu events
274 Connect(viewSource
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
275 wxCommandEventHandler(WebFrame::OnViewSourceRequest
), NULL
, this );
276 Connect(print
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
277 wxCommandEventHandler(WebFrame::OnPrint
), NULL
, this );
278 Connect(m_tools_layout
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
279 wxCommandEventHandler(WebFrame::OnZoomLayout
), NULL
, this );
280 Connect(m_tools_tiny
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
281 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
282 Connect(m_tools_small
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
283 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
284 Connect(m_tools_medium
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
285 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
286 Connect(m_tools_large
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
287 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
288 Connect(m_tools_largest
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
289 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
290 Connect(clearhist
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
291 wxCommandEventHandler(WebFrame::OnClearHistory
), NULL
, this );
292 Connect(m_tools_enable_history
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
293 wxCommandEventHandler(WebFrame::OnEnableHistory
), NULL
, this );
294 Connect(m_edit_cut
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
295 wxCommandEventHandler(WebFrame::OnCut
), NULL
, this );
296 Connect(m_edit_copy
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
297 wxCommandEventHandler(WebFrame::OnCopy
), NULL
, this );
298 Connect(m_edit_paste
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
299 wxCommandEventHandler(WebFrame::OnPaste
), NULL
, this );
300 Connect(m_edit_undo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
301 wxCommandEventHandler(WebFrame::OnUndo
), NULL
, this );
302 Connect(m_edit_redo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
303 wxCommandEventHandler(WebFrame::OnRedo
), NULL
, this );
304 Connect(m_edit_mode
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
305 wxCommandEventHandler(WebFrame::OnMode
), NULL
, this );
308 void WebFrame::OnAnimationTimer(wxTimerEvent
& evt
)
310 m_animation_angle
+= 15;
311 if (m_animation_angle
> 360) m_animation_angle
-= 360;
313 wxBitmap
image(24, 24);
316 dc
.SelectObject(image
);
317 dc
.SetBackground(wxBrush(wxColour(255,0,255)));
320 if (m_animation_angle
>= 0 && m_animation_angle
<= 180)
322 dc
.SetBrush(*wxYELLOW_BRUSH
);
323 dc
.SetPen(*wxYELLOW_PEN
);
324 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
325 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
328 dc
.DrawBitmap(wxBitmap(wxlogo_xpm
), 0, 0, true);
330 if (m_animation_angle
> 180)
332 dc
.SetBrush(*wxYELLOW_BRUSH
);
333 dc
.SetPen(*wxYELLOW_PEN
);
334 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
335 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
338 image
.SetMask(new wxMask(image
, wxColour(255,0,255)));
339 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), image
);
343 * Method that retrieves the current state from the web control and updates the GUI
344 * the reflect this current state.
346 void WebFrame::UpdateState()
348 m_toolbar
->EnableTool( m_toolbar_back
->GetId(), m_browser
->CanGoBack() );
349 m_toolbar
->EnableTool( m_toolbar_forward
->GetId(), m_browser
->CanGoForward() );
351 if (m_browser
->IsBusy())
355 m_timer
= new wxTimer(this);
356 this->Connect(wxEVT_TIMER
, wxTimerEventHandler(WebFrame::OnAnimationTimer
), NULL
, this);
358 m_timer
->Start(100); // start animation timer
360 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), true );
364 if (m_timer
!= NULL
) m_timer
->Stop(); // stop animation timer
365 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), wxBitmap(wxlogo_xpm
));
366 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), false );
369 SetTitle( m_browser
->GetCurrentTitle() );
370 m_url
->SetValue( m_browser
->GetCurrentURL() );
374 * Callback invoked when user entered an URL and pressed enter
376 void WebFrame::OnUrl(wxCommandEvent
& evt
)
378 m_browser
->LoadUrl( m_url
->GetValue() );
383 * Callback invoked when user pressed the "back" button
385 void WebFrame::OnBack(wxCommandEvent
& evt
)
392 * Callback invoked when user pressed the "forward" button
394 void WebFrame::OnForward(wxCommandEvent
& evt
)
396 m_browser
->GoForward();
401 * Callback invoked when user pressed the "stop" button
403 void WebFrame::OnStop(wxCommandEvent
& evt
)
410 * Callback invoked when user pressed the "reload" button
412 void WebFrame::OnReload(wxCommandEvent
& evt
)
418 void WebFrame::OnClearHistory(wxCommandEvent
& evt
)
420 m_browser
->ClearHistory();
424 void WebFrame::OnEnableHistory(wxCommandEvent
& evt
)
426 m_browser
->EnableHistory(m_tools_enable_history
->IsChecked());
430 void WebFrame::OnCut(wxCommandEvent
& evt
)
435 void WebFrame::OnCopy(wxCommandEvent
& evt
)
440 void WebFrame::OnPaste(wxCommandEvent
& evt
)
445 void WebFrame::OnUndo(wxCommandEvent
& evt
)
450 void WebFrame::OnRedo(wxCommandEvent
& evt
)
455 void WebFrame::OnMode(wxCommandEvent
& evt
)
457 m_browser
->SetEditable(m_edit_mode
->IsChecked());
462 * Callback invoked when there is a request to load a new page (for instance
463 * when the user clicks a link)
465 void WebFrame::OnNavigationRequest(wxWebNavigationEvent
& evt
)
467 wxLogMessage("%s", "Navigation request to '" + evt
.GetURL() + "' (target='" +
468 evt
.GetTarget() + "')");
470 wxASSERT(m_browser
->IsBusy());
472 //If we don't want to handle navigation then veto the event and navigation
473 //will not take place
474 if(!m_tools_handle_navigation
->IsChecked())
481 * Callback invoked when a navigation request was accepted
483 void WebFrame::OnNavigationComplete(wxWebNavigationEvent
& evt
)
485 wxLogMessage("%s", "Navigation complete; url='" + evt
.GetURL() + "'");
490 * Callback invoked when a page is finished loading
492 void WebFrame::OnDocumentLoaded(wxWebNavigationEvent
& evt
)
494 //Only notify if the document is the main frame, not a subframe
495 if(evt
.GetURL() == m_browser
->GetCurrentURL())
496 wxLogMessage("%s", "Document loaded; url='" + evt
.GetURL() + "'");
501 * On new window, we veto to stop extra windows appearing
503 void WebFrame::OnNewWindow(wxWebNavigationEvent
& evt
)
505 wxLogMessage("%s", "New window; url='" + evt
.GetURL() + "'");
507 //If we handle new window events then just load them in this window as we
508 //are a single window browser
509 if(m_tools_handle_new_window
->IsChecked())
510 m_browser
->LoadUrl(evt
.GetURL());
515 void WebFrame::OnTitleChanged(wxWebNavigationEvent
& evt
)
517 wxLogMessage("%s", "Title changed; title='" + evt
.GetString() + "'");
522 * Invoked when user selects the "View Source" menu item
524 void WebFrame::OnViewSourceRequest(wxCommandEvent
& evt
)
526 SourceViewDialog
dlg(this, m_browser
->GetPageSource());
531 * Invoked when user selects the "Menu" item
533 void WebFrame::OnToolsClicked(wxCommandEvent
& evt
)
535 if(m_browser
->GetCurrentURL() == "")
538 m_tools_tiny
->Check(false);
539 m_tools_small
->Check(false);
540 m_tools_medium
->Check(false);
541 m_tools_large
->Check(false);
542 m_tools_largest
->Check(false);
544 wxWebViewZoom zoom
= m_browser
->GetZoom();
547 case wxWEB_VIEW_ZOOM_TINY
:
548 m_tools_tiny
->Check();
550 case wxWEB_VIEW_ZOOM_SMALL
:
551 m_tools_small
->Check();
553 case wxWEB_VIEW_ZOOM_MEDIUM
:
554 m_tools_medium
->Check();
556 case wxWEB_VIEW_ZOOM_LARGE
:
557 m_tools_large
->Check();
559 case wxWEB_VIEW_ZOOM_LARGEST
:
560 m_tools_largest
->Check();
564 m_edit_cut
->Enable(m_browser
->CanCut());
565 m_edit_copy
->Enable(m_browser
->CanCopy());
566 m_edit_paste
->Enable(m_browser
->CanPaste());
568 m_edit_undo
->Enable(m_browser
->CanUndo());
569 m_edit_redo
->Enable(m_browser
->CanRedo());
571 wxPoint position
= ScreenToClient( wxGetMousePosition() );
572 PopupMenu(m_tools_menu
, position
.x
, position
.y
);
576 * Invoked when user selects the zoom size in the menu
578 void WebFrame::OnSetZoom(wxCommandEvent
& evt
)
580 if (evt
.GetId() == m_tools_tiny
->GetId())
582 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_TINY
);
584 else if (evt
.GetId() == m_tools_small
->GetId())
586 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_SMALL
);
588 else if (evt
.GetId() == m_tools_medium
->GetId())
590 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM
);
592 else if (evt
.GetId() == m_tools_large
->GetId())
594 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGE
);
596 else if (evt
.GetId() == m_tools_largest
->GetId())
598 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGEST
);
606 void WebFrame::OnZoomLayout(wxCommandEvent
& evt
)
608 if(m_tools_layout
->IsChecked())
609 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
);
611 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT
);
615 * Callback invoked when a loading error occurs
617 void WebFrame::OnError(wxWebNavigationEvent
& evt
)
619 wxString errorCategory
;
620 switch (evt
.GetInt())
622 case wxWEB_NAV_ERR_CONNECTION
:
623 errorCategory
= "wxWEB_NAV_ERR_CONNECTION";
626 case wxWEB_NAV_ERR_CERTIFICATE
:
627 errorCategory
= "wxWEB_NAV_ERR_CERTIFICATE";
630 case wxWEB_NAV_ERR_AUTH
:
631 errorCategory
= "wxWEB_NAV_ERR_AUTH";
634 case wxWEB_NAV_ERR_SECURITY
:
635 errorCategory
= "wxWEB_NAV_ERR_SECURITY";
638 case wxWEB_NAV_ERR_NOT_FOUND
:
639 errorCategory
= "wxWEB_NAV_ERR_NOT_FOUND";
642 case wxWEB_NAV_ERR_REQUEST
:
643 errorCategory
= "wxWEB_NAV_ERR_REQUEST";
646 case wxWEB_NAV_ERR_USER_CANCELLED
:
647 errorCategory
= "wxWEB_NAV_ERR_USER_CANCELLED";
650 case wxWEB_NAV_ERR_OTHER
:
651 errorCategory
= "wxWEB_NAV_ERR_OTHER";
655 wxLogMessage("Error; url='" + evt
.GetURL() + "', error='" + errorCategory
+ "' (" + evt
.GetString() + ")");
657 //Show the info bar with an error
658 m_info
->ShowMessage(_("An error occurred loading ") + evt
.GetURL() + "\n" +
659 "'" + errorCategory
+ "' (" + evt
.GetString() + ")", wxICON_ERROR
);
665 * Invoked when user selects "Print" from the menu
667 void WebFrame::OnPrint(wxCommandEvent
& evt
)
672 SourceViewDialog::SourceViewDialog(wxWindow
* parent
, wxString source
) :
673 wxDialog(parent
, wxID_ANY
, "Source Code",
674 wxDefaultPosition
, wxSize(700,500),
675 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
677 wxStyledTextCtrl
* text
= new wxStyledTextCtrl(this, wxID_ANY
);
678 text
->SetMarginWidth(1, 30);
679 text
->SetMarginType(1, wxSTC_MARGIN_NUMBER
);
680 text
->SetText(source
);
682 text
->StyleClearAll();
683 text
->SetLexer(wxSTC_LEX_HTML
);
684 text
->StyleSetForeground(wxSTC_H_DOUBLESTRING
, wxColour(255,0,0));
685 text
->StyleSetForeground(wxSTC_H_SINGLESTRING
, wxColour(255,0,0));
686 text
->StyleSetForeground(wxSTC_H_ENTITY
, wxColour(255,0,0));
687 text
->StyleSetForeground(wxSTC_H_TAG
, wxColour(0,150,0));
688 text
->StyleSetForeground(wxSTC_H_TAGUNKNOWN
, wxColour(0,150,0));
689 text
->StyleSetForeground(wxSTC_H_ATTRIBUTE
, wxColour(0,0,150));
690 text
->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN
, wxColour(0,0,150));
691 text
->StyleSetForeground(wxSTC_H_COMMENT
, wxColour(150,150,150));
693 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
694 sizer
->Add(text
, 1, wxEXPAND
);