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/webviewfilehandler.h>
30 #include <wx/infobar.h>
31 #include <wx/filesys.h>
32 #include <wx/fs_arc.h>
34 #if !defined(__WXMSW__) && !defined(__WXPM__)
35 #include "../sample.xpm"
39 #include <wx/stc/stc.h>
41 #error "wxStyledTextControl is needed by this sample"
45 #include "refresh.xpm"
48 class WebApp
: public wxApp
51 virtual bool OnInit();
54 class WebFrame
: public wxFrame
59 void OnAnimationTimer(wxTimerEvent
& evt
);
61 void OnUrl(wxCommandEvent
& evt
);
62 void OnBack(wxCommandEvent
& evt
);
63 void OnForward(wxCommandEvent
& evt
);
64 void OnStop(wxCommandEvent
& evt
);
65 void OnReload(wxCommandEvent
& evt
);
66 void OnClearHistory(wxCommandEvent
& evt
);
67 void OnEnableHistory(wxCommandEvent
& evt
);
68 void OnNavigationRequest(wxWebNavigationEvent
& evt
);
69 void OnNavigationComplete(wxWebNavigationEvent
& evt
);
70 void OnDocumentLoaded(wxWebNavigationEvent
& evt
);
71 void OnNewWindow(wxWebNavigationEvent
& evt
);
72 void OnTitleChanged(wxWebNavigationEvent
& evt
);
73 void OnViewSourceRequest(wxCommandEvent
& evt
);
74 void OnToolsClicked(wxCommandEvent
& evt
);
75 void OnSetZoom(wxCommandEvent
& evt
);
76 void OnError(wxWebNavigationEvent
& evt
);
77 void OnPrint(wxCommandEvent
& evt
);
78 void OnCut(wxCommandEvent
& evt
);
79 void OnCopy(wxCommandEvent
& evt
);
80 void OnPaste(wxCommandEvent
& evt
);
81 void OnUndo(wxCommandEvent
& evt
);
82 void OnRedo(wxCommandEvent
& evt
);
83 void OnMode(wxCommandEvent
& evt
);
84 void OnZoomLayout(wxCommandEvent
& evt
);
91 wxToolBarToolBase
* m_toolbar_back
;
92 wxToolBarToolBase
* m_toolbar_forward
;
93 wxToolBarToolBase
* m_toolbar_stop
;
94 wxToolBarToolBase
* m_toolbar_reload
;
95 wxToolBarToolBase
* m_toolbar_tools
;
98 wxMenuItem
* m_tools_layout
;
99 wxMenuItem
* m_tools_tiny
;
100 wxMenuItem
* m_tools_small
;
101 wxMenuItem
* m_tools_medium
;
102 wxMenuItem
* m_tools_large
;
103 wxMenuItem
* m_tools_largest
;
104 wxMenuItem
* m_tools_handle_navigation
;
105 wxMenuItem
* m_tools_handle_new_window
;
106 wxMenuItem
* m_tools_enable_history
;
107 wxMenuItem
* m_edit_cut
;
108 wxMenuItem
* m_edit_copy
;
109 wxMenuItem
* m_edit_paste
;
110 wxMenuItem
* m_edit_undo
;
111 wxMenuItem
* m_edit_redo
;
112 wxMenuItem
* m_edit_mode
;
115 int m_animation_angle
;
118 wxStaticText
* m_info_text
;
121 class SourceViewDialog
: public wxDialog
124 SourceViewDialog(wxWindow
* parent
, wxString source
);
127 IMPLEMENT_APP(WebApp
)
129 // ============================================================================
131 // ============================================================================
133 bool WebApp::OnInit()
135 if ( !wxApp::OnInit() )
138 WebFrame
*frame
= new WebFrame();
144 WebFrame::WebFrame() : wxFrame(NULL
, wxID_ANY
, "wxWebView Sample")
146 //Required from virtual file system archive support
147 wxFileSystem::AddHandler(new wxArchiveFSHandler
);
149 // set the frame icon
150 SetIcon(wxICON(sample
));
151 SetTitle("wxWebView Sample");
154 m_animation_angle
= 0;
157 wxBoxSizer
* topsizer
= new wxBoxSizer(wxVERTICAL
);
159 // Create the toolbar
160 m_toolbar
= CreateToolBar(wxTB_TEXT
);
161 m_toolbar
->SetToolBitmapSize(wxSize(32, 32));
163 wxBitmap back
= wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
164 wxBitmap forward
= wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
166 wxBitmap stop
= wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR
);
168 wxBitmap stop
= wxBitmap(stop_xpm
);
171 wxBitmap refresh
= wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR
);
173 wxBitmap refresh
= wxBitmap(refresh_xpm
);
176 m_toolbar_back
= m_toolbar
->AddTool(wxID_ANY
, _("Back"), back
);
177 m_toolbar_forward
= m_toolbar
->AddTool(wxID_ANY
, _("Forward"), forward
);
178 m_toolbar_stop
= m_toolbar
->AddTool(wxID_ANY
, _("Stop"), stop
);
179 m_toolbar_reload
= m_toolbar
->AddTool(wxID_ANY
, _("Reload"), refresh
);
180 m_url
= new wxTextCtrl(m_toolbar
, wxID_ANY
, wxT(""), wxDefaultPosition
, wxSize(400, -1), wxTE_PROCESS_ENTER
);
181 m_toolbar
->AddControl(m_url
, _("URL"));
182 m_toolbar_tools
= m_toolbar
->AddTool(wxID_ANY
, _("Menu"), wxBitmap(wxlogo_xpm
));
184 m_toolbar
->Realize();
186 // Create the info panel
187 m_info
= new wxInfoBar(this);
188 topsizer
->Add(m_info
, wxSizerFlags().Expand());
190 // Create the webview
191 m_browser
= wxWebView::New(this, wxID_ANY
, "http://www.wxwidgets.org");
192 topsizer
->Add(m_browser
, wxSizerFlags().Expand().Proportion(1));
194 //We register the test:// protocol for testing purposes
195 m_browser
->RegisterHandler(new wxWebFileHandler());
199 //Set a more sensible size for web browsing
200 SetSize(wxSize(800, 600));
202 // Create a log window
203 new wxLogWindow(this, _("Logging"));
205 // Create the Tools menu
206 m_tools_menu
= new wxMenu();
207 wxMenuItem
* print
= m_tools_menu
->Append(wxID_ANY
, _("Print"));
208 wxMenuItem
* viewSource
= m_tools_menu
->Append(wxID_ANY
, _("View Source"));
209 m_tools_menu
->AppendSeparator();
210 m_tools_layout
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Use Layout Zoom"));
211 m_tools_tiny
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Tiny"));
212 m_tools_small
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Small"));
213 m_tools_medium
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Medium"));
214 m_tools_large
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Large"));
215 m_tools_largest
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Largest"));
216 m_tools_menu
->AppendSeparator();
217 m_tools_handle_navigation
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle Navigation"));
218 m_tools_handle_new_window
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle New Windows"));
219 m_tools_menu
->AppendSeparator();
220 wxMenuItem
* clearhist
= m_tools_menu
->Append(wxID_ANY
, _("Clear History"));
221 m_tools_enable_history
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Enable History"));
223 //Create an editing menu
224 wxMenu
* editmenu
= new wxMenu();
225 m_edit_cut
= editmenu
->Append(wxID_ANY
, _("Cut"));
226 m_edit_copy
= editmenu
->Append(wxID_ANY
, _("Copy"));
227 m_edit_paste
= editmenu
->Append(wxID_ANY
, _("Paste"));
228 editmenu
->AppendSeparator();
229 m_edit_undo
= editmenu
->Append(wxID_ANY
, _("Undo"));
230 m_edit_redo
= editmenu
->Append(wxID_ANY
, _("Redo"));
231 editmenu
->AppendSeparator();
232 m_edit_mode
= editmenu
->AppendCheckItem(wxID_ANY
, _("Edit Mode"));
234 m_tools_menu
->AppendSeparator();
235 m_tools_menu
->AppendSubMenu(editmenu
, "Edit");
237 //By default we want to handle navigation and new windows
238 m_tools_handle_navigation
->Check();
239 m_tools_handle_new_window
->Check();
240 m_tools_enable_history
->Check();
241 if(!m_browser
->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
))
242 m_tools_layout
->Enable(false);
245 // Connect the toolbar events
246 Connect(m_toolbar_back
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
247 wxCommandEventHandler(WebFrame::OnBack
), NULL
, this );
248 Connect(m_toolbar_forward
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
249 wxCommandEventHandler(WebFrame::OnForward
), NULL
, this );
250 Connect(m_toolbar_stop
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
251 wxCommandEventHandler(WebFrame::OnStop
), NULL
, this );
252 Connect(m_toolbar_reload
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
253 wxCommandEventHandler(WebFrame::OnReload
),NULL
, this );
254 Connect(m_toolbar_tools
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
255 wxCommandEventHandler(WebFrame::OnToolsClicked
), NULL
, this );
257 Connect(m_url
->GetId(), wxEVT_COMMAND_TEXT_ENTER
,
258 wxCommandEventHandler(WebFrame::OnUrl
), NULL
, this );
260 // Connect the webview events
261 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
262 wxWebNavigationEventHandler(WebFrame::OnNavigationRequest
), NULL
, this);
263 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
264 wxWebNavigationEventHandler(WebFrame::OnNavigationComplete
), NULL
, this);
265 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED
,
266 wxWebNavigationEventHandler(WebFrame::OnDocumentLoaded
), NULL
, this);
267 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR
,
268 wxWebNavigationEventHandler(WebFrame::OnError
), NULL
, this);
269 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
270 wxWebNavigationEventHandler(WebFrame::OnNewWindow
), NULL
, this);
271 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
272 wxWebNavigationEventHandler(WebFrame::OnTitleChanged
), NULL
, this);
274 // Connect the menu events
275 Connect(viewSource
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
276 wxCommandEventHandler(WebFrame::OnViewSourceRequest
), NULL
, this );
277 Connect(print
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
278 wxCommandEventHandler(WebFrame::OnPrint
), NULL
, this );
279 Connect(m_tools_layout
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
280 wxCommandEventHandler(WebFrame::OnZoomLayout
), NULL
, this );
281 Connect(m_tools_tiny
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
282 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
283 Connect(m_tools_small
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
284 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
285 Connect(m_tools_medium
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
286 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
287 Connect(m_tools_large
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
288 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
289 Connect(m_tools_largest
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
290 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
291 Connect(clearhist
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
292 wxCommandEventHandler(WebFrame::OnClearHistory
), NULL
, this );
293 Connect(m_tools_enable_history
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
294 wxCommandEventHandler(WebFrame::OnEnableHistory
), NULL
, this );
295 Connect(m_edit_cut
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
296 wxCommandEventHandler(WebFrame::OnCut
), NULL
, this );
297 Connect(m_edit_copy
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
298 wxCommandEventHandler(WebFrame::OnCopy
), NULL
, this );
299 Connect(m_edit_paste
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
300 wxCommandEventHandler(WebFrame::OnPaste
), NULL
, this );
301 Connect(m_edit_undo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
302 wxCommandEventHandler(WebFrame::OnUndo
), NULL
, this );
303 Connect(m_edit_redo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
304 wxCommandEventHandler(WebFrame::OnRedo
), NULL
, this );
305 Connect(m_edit_mode
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
306 wxCommandEventHandler(WebFrame::OnMode
), NULL
, this );
309 void WebFrame::OnAnimationTimer(wxTimerEvent
& evt
)
311 m_animation_angle
+= 15;
312 if (m_animation_angle
> 360) m_animation_angle
-= 360;
314 wxBitmap
image(24, 24);
317 dc
.SelectObject(image
);
318 dc
.SetBackground(wxBrush(wxColour(255,0,255)));
321 if (m_animation_angle
>= 0 && m_animation_angle
<= 180)
323 dc
.SetBrush(*wxYELLOW_BRUSH
);
324 dc
.SetPen(*wxYELLOW_PEN
);
325 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
326 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
329 dc
.DrawBitmap(wxBitmap(wxlogo_xpm
), 0, 0, true);
331 if (m_animation_angle
> 180)
333 dc
.SetBrush(*wxYELLOW_BRUSH
);
334 dc
.SetPen(*wxYELLOW_PEN
);
335 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
336 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
339 image
.SetMask(new wxMask(image
, wxColour(255,0,255)));
340 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), image
);
344 * Method that retrieves the current state from the web control and updates the GUI
345 * the reflect this current state.
347 void WebFrame::UpdateState()
349 m_toolbar
->EnableTool( m_toolbar_back
->GetId(), m_browser
->CanGoBack() );
350 m_toolbar
->EnableTool( m_toolbar_forward
->GetId(), m_browser
->CanGoForward() );
352 if (m_browser
->IsBusy())
356 m_timer
= new wxTimer(this);
357 this->Connect(wxEVT_TIMER
, wxTimerEventHandler(WebFrame::OnAnimationTimer
), NULL
, this);
359 m_timer
->Start(100); // start animation timer
361 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), true );
365 if (m_timer
!= NULL
) m_timer
->Stop(); // stop animation timer
366 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), wxBitmap(wxlogo_xpm
));
367 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), false );
370 SetTitle( m_browser
->GetCurrentTitle() );
371 m_url
->SetValue( m_browser
->GetCurrentURL() );
375 * Callback invoked when user entered an URL and pressed enter
377 void WebFrame::OnUrl(wxCommandEvent
& evt
)
379 m_browser
->LoadUrl( m_url
->GetValue() );
384 * Callback invoked when user pressed the "back" button
386 void WebFrame::OnBack(wxCommandEvent
& evt
)
393 * Callback invoked when user pressed the "forward" button
395 void WebFrame::OnForward(wxCommandEvent
& evt
)
397 m_browser
->GoForward();
402 * Callback invoked when user pressed the "stop" button
404 void WebFrame::OnStop(wxCommandEvent
& evt
)
411 * Callback invoked when user pressed the "reload" button
413 void WebFrame::OnReload(wxCommandEvent
& evt
)
419 void WebFrame::OnClearHistory(wxCommandEvent
& evt
)
421 m_browser
->ClearHistory();
425 void WebFrame::OnEnableHistory(wxCommandEvent
& evt
)
427 m_browser
->EnableHistory(m_tools_enable_history
->IsChecked());
431 void WebFrame::OnCut(wxCommandEvent
& evt
)
436 void WebFrame::OnCopy(wxCommandEvent
& evt
)
441 void WebFrame::OnPaste(wxCommandEvent
& evt
)
446 void WebFrame::OnUndo(wxCommandEvent
& evt
)
451 void WebFrame::OnRedo(wxCommandEvent
& evt
)
456 void WebFrame::OnMode(wxCommandEvent
& evt
)
458 m_browser
->SetEditable(m_edit_mode
->IsChecked());
463 * Callback invoked when there is a request to load a new page (for instance
464 * when the user clicks a link)
466 void WebFrame::OnNavigationRequest(wxWebNavigationEvent
& evt
)
468 wxLogMessage("%s", "Navigation request to '" + evt
.GetURL() + "' (target='" +
469 evt
.GetTarget() + "')");
471 wxASSERT(m_browser
->IsBusy());
473 //If we don't want to handle navigation then veto the event and navigation
474 //will not take place
475 if(!m_tools_handle_navigation
->IsChecked())
482 * Callback invoked when a navigation request was accepted
484 void WebFrame::OnNavigationComplete(wxWebNavigationEvent
& evt
)
486 wxLogMessage("%s", "Navigation complete; url='" + evt
.GetURL() + "'");
491 * Callback invoked when a page is finished loading
493 void WebFrame::OnDocumentLoaded(wxWebNavigationEvent
& evt
)
495 //Only notify if the document is the main frame, not a subframe
496 if(evt
.GetURL() == m_browser
->GetCurrentURL())
497 wxLogMessage("%s", "Document loaded; url='" + evt
.GetURL() + "'");
502 * On new window, we veto to stop extra windows appearing
504 void WebFrame::OnNewWindow(wxWebNavigationEvent
& evt
)
506 wxLogMessage("%s", "New window; url='" + evt
.GetURL() + "'");
508 //If we handle new window events then just load them in this window as we
509 //are a single window browser
510 if(m_tools_handle_new_window
->IsChecked())
511 m_browser
->LoadUrl(evt
.GetURL());
516 void WebFrame::OnTitleChanged(wxWebNavigationEvent
& evt
)
518 wxLogMessage("%s", "Title changed; title='" + evt
.GetString() + "'");
523 * Invoked when user selects the "View Source" menu item
525 void WebFrame::OnViewSourceRequest(wxCommandEvent
& evt
)
527 SourceViewDialog
dlg(this, m_browser
->GetPageSource());
532 * Invoked when user selects the "Menu" item
534 void WebFrame::OnToolsClicked(wxCommandEvent
& evt
)
536 if(m_browser
->GetCurrentURL() == "")
539 m_tools_tiny
->Check(false);
540 m_tools_small
->Check(false);
541 m_tools_medium
->Check(false);
542 m_tools_large
->Check(false);
543 m_tools_largest
->Check(false);
545 wxWebViewZoom zoom
= m_browser
->GetZoom();
548 case wxWEB_VIEW_ZOOM_TINY
:
549 m_tools_tiny
->Check();
551 case wxWEB_VIEW_ZOOM_SMALL
:
552 m_tools_small
->Check();
554 case wxWEB_VIEW_ZOOM_MEDIUM
:
555 m_tools_medium
->Check();
557 case wxWEB_VIEW_ZOOM_LARGE
:
558 m_tools_large
->Check();
560 case wxWEB_VIEW_ZOOM_LARGEST
:
561 m_tools_largest
->Check();
565 m_edit_cut
->Enable(m_browser
->CanCut());
566 m_edit_copy
->Enable(m_browser
->CanCopy());
567 m_edit_paste
->Enable(m_browser
->CanPaste());
569 m_edit_undo
->Enable(m_browser
->CanUndo());
570 m_edit_redo
->Enable(m_browser
->CanRedo());
572 wxPoint position
= ScreenToClient( wxGetMousePosition() );
573 PopupMenu(m_tools_menu
, position
.x
, position
.y
);
577 * Invoked when user selects the zoom size in the menu
579 void WebFrame::OnSetZoom(wxCommandEvent
& evt
)
581 if (evt
.GetId() == m_tools_tiny
->GetId())
583 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_TINY
);
585 else if (evt
.GetId() == m_tools_small
->GetId())
587 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_SMALL
);
589 else if (evt
.GetId() == m_tools_medium
->GetId())
591 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM
);
593 else if (evt
.GetId() == m_tools_large
->GetId())
595 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGE
);
597 else if (evt
.GetId() == m_tools_largest
->GetId())
599 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGEST
);
607 void WebFrame::OnZoomLayout(wxCommandEvent
& evt
)
609 if(m_tools_layout
->IsChecked())
610 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
);
612 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT
);
616 * Callback invoked when a loading error occurs
618 void WebFrame::OnError(wxWebNavigationEvent
& evt
)
620 wxString errorCategory
;
621 switch (evt
.GetInt())
623 case wxWEB_NAV_ERR_CONNECTION
:
624 errorCategory
= "wxWEB_NAV_ERR_CONNECTION";
627 case wxWEB_NAV_ERR_CERTIFICATE
:
628 errorCategory
= "wxWEB_NAV_ERR_CERTIFICATE";
631 case wxWEB_NAV_ERR_AUTH
:
632 errorCategory
= "wxWEB_NAV_ERR_AUTH";
635 case wxWEB_NAV_ERR_SECURITY
:
636 errorCategory
= "wxWEB_NAV_ERR_SECURITY";
639 case wxWEB_NAV_ERR_NOT_FOUND
:
640 errorCategory
= "wxWEB_NAV_ERR_NOT_FOUND";
643 case wxWEB_NAV_ERR_REQUEST
:
644 errorCategory
= "wxWEB_NAV_ERR_REQUEST";
647 case wxWEB_NAV_ERR_USER_CANCELLED
:
648 errorCategory
= "wxWEB_NAV_ERR_USER_CANCELLED";
651 case wxWEB_NAV_ERR_OTHER
:
652 errorCategory
= "wxWEB_NAV_ERR_OTHER";
656 wxLogMessage("Error; url='" + evt
.GetURL() + "', error='" + errorCategory
+ "' (" + evt
.GetString() + ")");
658 //Show the info bar with an error
659 m_info
->ShowMessage(_("An error occurred loading ") + evt
.GetURL() + "\n" +
660 "'" + errorCategory
+ "' (" + evt
.GetString() + ")", wxICON_ERROR
);
666 * Invoked when user selects "Print" from the menu
668 void WebFrame::OnPrint(wxCommandEvent
& evt
)
673 SourceViewDialog::SourceViewDialog(wxWindow
* parent
, wxString source
) :
674 wxDialog(parent
, wxID_ANY
, "Source Code",
675 wxDefaultPosition
, wxSize(700,500),
676 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
678 wxStyledTextCtrl
* text
= new wxStyledTextCtrl(this, wxID_ANY
);
679 text
->SetMarginWidth(1, 30);
680 text
->SetMarginType(1, wxSTC_MARGIN_NUMBER
);
681 text
->SetText(source
);
683 text
->StyleClearAll();
684 text
->SetLexer(wxSTC_LEX_HTML
);
685 text
->StyleSetForeground(wxSTC_H_DOUBLESTRING
, wxColour(255,0,0));
686 text
->StyleSetForeground(wxSTC_H_SINGLESTRING
, wxColour(255,0,0));
687 text
->StyleSetForeground(wxSTC_H_ENTITY
, wxColour(255,0,0));
688 text
->StyleSetForeground(wxSTC_H_TAG
, wxColour(0,150,0));
689 text
->StyleSetForeground(wxSTC_H_TAGUNKNOWN
, wxColour(0,150,0));
690 text
->StyleSetForeground(wxSTC_H_ATTRIBUTE
, wxColour(0,0,150));
691 text
->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN
, wxColour(0,0,150));
692 text
->StyleSetForeground(wxSTC_H_COMMENT
, wxColour(150,150,150));
694 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
695 sizer
->Add(text
, 1, wxEXPAND
);