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"
44 #if defined(__WXMSW__) || defined(__WXOSX__)
46 #include "refresh.xpm"
51 class WebApp
: public wxApp
54 virtual bool OnInit();
57 class WebFrame
: public wxFrame
62 void OnAnimationTimer(wxTimerEvent
& evt
);
64 void OnUrl(wxCommandEvent
& evt
);
65 void OnBack(wxCommandEvent
& evt
);
66 void OnForward(wxCommandEvent
& evt
);
67 void OnStop(wxCommandEvent
& evt
);
68 void OnReload(wxCommandEvent
& evt
);
69 void OnClearHistory(wxCommandEvent
& evt
);
70 void OnEnableHistory(wxCommandEvent
& evt
);
71 void OnNavigationRequest(wxWebNavigationEvent
& evt
);
72 void OnNavigationComplete(wxWebNavigationEvent
& evt
);
73 void OnDocumentLoaded(wxWebNavigationEvent
& evt
);
74 void OnNewWindow(wxWebNavigationEvent
& evt
);
75 void OnTitleChanged(wxWebNavigationEvent
& evt
);
76 void OnViewSourceRequest(wxCommandEvent
& evt
);
77 void OnToolsClicked(wxCommandEvent
& evt
);
78 void OnSetZoom(wxCommandEvent
& evt
);
79 void OnError(wxWebNavigationEvent
& evt
);
80 void OnPrint(wxCommandEvent
& evt
);
81 void OnCut(wxCommandEvent
& evt
);
82 void OnCopy(wxCommandEvent
& evt
);
83 void OnPaste(wxCommandEvent
& evt
);
84 void OnUndo(wxCommandEvent
& evt
);
85 void OnRedo(wxCommandEvent
& evt
);
86 void OnMode(wxCommandEvent
& evt
);
87 void OnZoomLayout(wxCommandEvent
& evt
);
94 wxToolBarToolBase
* m_toolbar_back
;
95 wxToolBarToolBase
* m_toolbar_forward
;
96 wxToolBarToolBase
* m_toolbar_stop
;
97 wxToolBarToolBase
* m_toolbar_reload
;
98 wxToolBarToolBase
* m_toolbar_tools
;
100 wxMenu
* m_tools_menu
;
101 wxMenuItem
* m_tools_layout
;
102 wxMenuItem
* m_tools_tiny
;
103 wxMenuItem
* m_tools_small
;
104 wxMenuItem
* m_tools_medium
;
105 wxMenuItem
* m_tools_large
;
106 wxMenuItem
* m_tools_largest
;
107 wxMenuItem
* m_tools_handle_navigation
;
108 wxMenuItem
* m_tools_handle_new_window
;
109 wxMenuItem
* m_tools_enable_history
;
110 wxMenuItem
* m_edit_cut
;
111 wxMenuItem
* m_edit_copy
;
112 wxMenuItem
* m_edit_paste
;
113 wxMenuItem
* m_edit_undo
;
114 wxMenuItem
* m_edit_redo
;
115 wxMenuItem
* m_edit_mode
;
118 int m_animation_angle
;
121 wxStaticText
* m_info_text
;
124 class SourceViewDialog
: public wxDialog
127 SourceViewDialog(wxWindow
* parent
, wxString source
);
130 IMPLEMENT_APP(WebApp
)
132 // ============================================================================
134 // ============================================================================
136 bool WebApp::OnInit()
138 if ( !wxApp::OnInit() )
141 WebFrame
*frame
= new WebFrame();
147 WebFrame::WebFrame() : wxFrame(NULL
, wxID_ANY
, "wxWebView Sample")
149 //Required from virtual file system archive support
150 wxFileSystem::AddHandler(new wxArchiveFSHandler
);
152 // set the frame icon
153 SetIcon(wxICON(sample
));
154 SetTitle("wxWebView Sample");
157 m_animation_angle
= 0;
160 wxBoxSizer
* topsizer
= new wxBoxSizer(wxVERTICAL
);
162 // Create the toolbar
163 m_toolbar
= CreateToolBar(wxTB_TEXT
);
164 m_toolbar
->SetToolBitmapSize(wxSize(32, 32));
166 wxBitmap back
= wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
167 wxBitmap forward
= wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
169 wxBitmap stop
= wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR
);
171 wxBitmap stop
= wxBitmap(stop_xpm
);
174 wxBitmap refresh
= wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR
);
176 wxBitmap refresh
= wxBitmap(refresh_xpm
);
179 m_toolbar_back
= m_toolbar
->AddTool(wxID_ANY
, _("Back"), back
);
180 m_toolbar_forward
= m_toolbar
->AddTool(wxID_ANY
, _("Forward"), forward
);
181 m_toolbar_stop
= m_toolbar
->AddTool(wxID_ANY
, _("Stop"), stop
);
182 m_toolbar_reload
= m_toolbar
->AddTool(wxID_ANY
, _("Reload"), refresh
);
183 m_url
= new wxTextCtrl(m_toolbar
, wxID_ANY
, wxT(""), wxDefaultPosition
, wxSize(400, -1), wxTE_PROCESS_ENTER
);
184 m_toolbar
->AddControl(m_url
, _("URL"));
185 m_toolbar_tools
= m_toolbar
->AddTool(wxID_ANY
, _("Menu"), wxBitmap(wxlogo_xpm
));
187 m_toolbar
->Realize();
189 // Create the info panel
190 m_info
= new wxInfoBar(this);
191 topsizer
->Add(m_info
, wxSizerFlags().Expand());
193 // Create the webview
194 m_browser
= wxWebView::New(this, wxID_ANY
, "http://www.wxwidgets.org");
195 topsizer
->Add(m_browser
, wxSizerFlags().Expand().Proportion(1));
197 //We register the file:// protocol for testing purposes
198 m_browser
->RegisterHandler(wxSharedPtr
<wxWebHandler
>(new wxWebFileHandler()));
202 //Set a more sensible size for web browsing
203 SetSize(wxSize(800, 600));
205 // Create a log window
206 new wxLogWindow(this, _("Logging"));
208 // Create the Tools menu
209 m_tools_menu
= new wxMenu();
210 wxMenuItem
* print
= m_tools_menu
->Append(wxID_ANY
, _("Print"));
211 wxMenuItem
* viewSource
= m_tools_menu
->Append(wxID_ANY
, _("View Source"));
212 m_tools_menu
->AppendSeparator();
213 m_tools_layout
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Use Layout Zoom"));
214 m_tools_tiny
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Tiny"));
215 m_tools_small
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Small"));
216 m_tools_medium
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Medium"));
217 m_tools_large
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Large"));
218 m_tools_largest
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Largest"));
219 m_tools_menu
->AppendSeparator();
220 m_tools_handle_navigation
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle Navigation"));
221 m_tools_handle_new_window
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle New Windows"));
222 m_tools_menu
->AppendSeparator();
223 wxMenuItem
* clearhist
= m_tools_menu
->Append(wxID_ANY
, _("Clear History"));
224 m_tools_enable_history
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Enable History"));
226 //Create an editing menu
227 wxMenu
* editmenu
= new wxMenu();
228 m_edit_cut
= editmenu
->Append(wxID_ANY
, _("Cut"));
229 m_edit_copy
= editmenu
->Append(wxID_ANY
, _("Copy"));
230 m_edit_paste
= editmenu
->Append(wxID_ANY
, _("Paste"));
231 editmenu
->AppendSeparator();
232 m_edit_undo
= editmenu
->Append(wxID_ANY
, _("Undo"));
233 m_edit_redo
= editmenu
->Append(wxID_ANY
, _("Redo"));
234 editmenu
->AppendSeparator();
235 m_edit_mode
= editmenu
->AppendCheckItem(wxID_ANY
, _("Edit Mode"));
237 m_tools_menu
->AppendSeparator();
238 m_tools_menu
->AppendSubMenu(editmenu
, "Edit");
240 //By default we want to handle navigation and new windows
241 m_tools_handle_navigation
->Check();
242 m_tools_handle_new_window
->Check();
243 m_tools_enable_history
->Check();
244 if(!m_browser
->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
))
245 m_tools_layout
->Enable(false);
248 // Connect the toolbar events
249 Connect(m_toolbar_back
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
250 wxCommandEventHandler(WebFrame::OnBack
), NULL
, this );
251 Connect(m_toolbar_forward
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
252 wxCommandEventHandler(WebFrame::OnForward
), NULL
, this );
253 Connect(m_toolbar_stop
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
254 wxCommandEventHandler(WebFrame::OnStop
), NULL
, this );
255 Connect(m_toolbar_reload
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
256 wxCommandEventHandler(WebFrame::OnReload
),NULL
, this );
257 Connect(m_toolbar_tools
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
258 wxCommandEventHandler(WebFrame::OnToolsClicked
), NULL
, this );
260 Connect(m_url
->GetId(), wxEVT_COMMAND_TEXT_ENTER
,
261 wxCommandEventHandler(WebFrame::OnUrl
), NULL
, this );
263 // Connect the webview events
264 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
265 wxWebNavigationEventHandler(WebFrame::OnNavigationRequest
), NULL
, this);
266 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
267 wxWebNavigationEventHandler(WebFrame::OnNavigationComplete
), NULL
, this);
268 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED
,
269 wxWebNavigationEventHandler(WebFrame::OnDocumentLoaded
), NULL
, this);
270 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR
,
271 wxWebNavigationEventHandler(WebFrame::OnError
), NULL
, this);
272 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
273 wxWebNavigationEventHandler(WebFrame::OnNewWindow
), NULL
, this);
274 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
275 wxWebNavigationEventHandler(WebFrame::OnTitleChanged
), NULL
, this);
277 // Connect the menu events
278 Connect(viewSource
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
279 wxCommandEventHandler(WebFrame::OnViewSourceRequest
), NULL
, this );
280 Connect(print
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
281 wxCommandEventHandler(WebFrame::OnPrint
), NULL
, this );
282 Connect(m_tools_layout
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
283 wxCommandEventHandler(WebFrame::OnZoomLayout
), NULL
, this );
284 Connect(m_tools_tiny
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
285 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
286 Connect(m_tools_small
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
287 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
288 Connect(m_tools_medium
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
289 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
290 Connect(m_tools_large
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
291 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
292 Connect(m_tools_largest
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
293 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
294 Connect(clearhist
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
295 wxCommandEventHandler(WebFrame::OnClearHistory
), NULL
, this );
296 Connect(m_tools_enable_history
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
297 wxCommandEventHandler(WebFrame::OnEnableHistory
), NULL
, this );
298 Connect(m_edit_cut
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
299 wxCommandEventHandler(WebFrame::OnCut
), NULL
, this );
300 Connect(m_edit_copy
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
301 wxCommandEventHandler(WebFrame::OnCopy
), NULL
, this );
302 Connect(m_edit_paste
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
303 wxCommandEventHandler(WebFrame::OnPaste
), NULL
, this );
304 Connect(m_edit_undo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
305 wxCommandEventHandler(WebFrame::OnUndo
), NULL
, this );
306 Connect(m_edit_redo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
307 wxCommandEventHandler(WebFrame::OnRedo
), NULL
, this );
308 Connect(m_edit_mode
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
309 wxCommandEventHandler(WebFrame::OnMode
), NULL
, this );
312 void WebFrame::OnAnimationTimer(wxTimerEvent
& WXUNUSED(evt
))
314 m_animation_angle
+= 15;
315 if (m_animation_angle
> 360) m_animation_angle
-= 360;
317 wxBitmap
image(24, 24);
320 dc
.SelectObject(image
);
321 dc
.SetBackground(wxBrush(wxColour(255,0,255)));
324 if (m_animation_angle
>= 0 && m_animation_angle
<= 180)
326 dc
.SetBrush(*wxYELLOW_BRUSH
);
327 dc
.SetPen(*wxYELLOW_PEN
);
328 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
329 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
332 dc
.DrawBitmap(wxBitmap(wxlogo_xpm
), 0, 0, true);
334 if (m_animation_angle
> 180)
336 dc
.SetBrush(*wxYELLOW_BRUSH
);
337 dc
.SetPen(*wxYELLOW_PEN
);
338 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
339 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
342 image
.SetMask(new wxMask(image
, wxColour(255,0,255)));
343 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), image
);
347 * Method that retrieves the current state from the web control and updates the GUI
348 * the reflect this current state.
350 void WebFrame::UpdateState()
352 m_toolbar
->EnableTool( m_toolbar_back
->GetId(), m_browser
->CanGoBack() );
353 m_toolbar
->EnableTool( m_toolbar_forward
->GetId(), m_browser
->CanGoForward() );
355 if (m_browser
->IsBusy())
359 m_timer
= new wxTimer(this);
360 this->Connect(wxEVT_TIMER
, wxTimerEventHandler(WebFrame::OnAnimationTimer
), NULL
, this);
362 m_timer
->Start(100); // start animation timer
364 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), true );
368 if (m_timer
!= NULL
) m_timer
->Stop(); // stop animation timer
369 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), wxBitmap(wxlogo_xpm
));
370 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), false );
373 SetTitle( m_browser
->GetCurrentTitle() );
374 m_url
->SetValue( m_browser
->GetCurrentURL() );
378 * Callback invoked when user entered an URL and pressed enter
380 void WebFrame::OnUrl(wxCommandEvent
& WXUNUSED(evt
))
382 m_browser
->LoadUrl( m_url
->GetValue() );
387 * Callback invoked when user pressed the "back" button
389 void WebFrame::OnBack(wxCommandEvent
& WXUNUSED(evt
))
396 * Callback invoked when user pressed the "forward" button
398 void WebFrame::OnForward(wxCommandEvent
& WXUNUSED(evt
))
400 m_browser
->GoForward();
405 * Callback invoked when user pressed the "stop" button
407 void WebFrame::OnStop(wxCommandEvent
& WXUNUSED(evt
))
414 * Callback invoked when user pressed the "reload" button
416 void WebFrame::OnReload(wxCommandEvent
& WXUNUSED(evt
))
422 void WebFrame::OnClearHistory(wxCommandEvent
& WXUNUSED(evt
))
424 m_browser
->ClearHistory();
428 void WebFrame::OnEnableHistory(wxCommandEvent
& WXUNUSED(evt
))
430 m_browser
->EnableHistory(m_tools_enable_history
->IsChecked());
434 void WebFrame::OnCut(wxCommandEvent
& WXUNUSED(evt
))
439 void WebFrame::OnCopy(wxCommandEvent
& WXUNUSED(evt
))
444 void WebFrame::OnPaste(wxCommandEvent
& WXUNUSED(evt
))
449 void WebFrame::OnUndo(wxCommandEvent
& WXUNUSED(evt
))
454 void WebFrame::OnRedo(wxCommandEvent
& WXUNUSED(evt
))
459 void WebFrame::OnMode(wxCommandEvent
& WXUNUSED(evt
))
461 m_browser
->SetEditable(m_edit_mode
->IsChecked());
466 * Callback invoked when there is a request to load a new page (for instance
467 * when the user clicks a link)
469 void WebFrame::OnNavigationRequest(wxWebNavigationEvent
& evt
)
471 if(m_info
->IsShown())
476 wxLogMessage("%s", "Navigation request to '" + evt
.GetURL() + "' (target='" +
477 evt
.GetTarget() + "')");
479 wxASSERT(m_browser
->IsBusy());
481 //If we don't want to handle navigation then veto the event and navigation
482 //will not take place
483 if(!m_tools_handle_navigation
->IsChecked())
490 * Callback invoked when a navigation request was accepted
492 void WebFrame::OnNavigationComplete(wxWebNavigationEvent
& evt
)
494 wxLogMessage("%s", "Navigation complete; url='" + evt
.GetURL() + "'");
499 * Callback invoked when a page is finished loading
501 void WebFrame::OnDocumentLoaded(wxWebNavigationEvent
& evt
)
503 //Only notify if the document is the main frame, not a subframe
504 if(evt
.GetURL() == m_browser
->GetCurrentURL())
506 wxLogMessage("%s", "Document loaded; url='" + evt
.GetURL() + "'");
512 * On new window, we veto to stop extra windows appearing
514 void WebFrame::OnNewWindow(wxWebNavigationEvent
& evt
)
516 wxLogMessage("%s", "New window; url='" + evt
.GetURL() + "'");
518 //If we handle new window events then just load them in this window as we
519 //are a single window browser
520 if(m_tools_handle_new_window
->IsChecked())
521 m_browser
->LoadUrl(evt
.GetURL());
526 void WebFrame::OnTitleChanged(wxWebNavigationEvent
& evt
)
528 wxLogMessage("%s", "Title changed; title='" + evt
.GetString() + "'");
533 * Invoked when user selects the "View Source" menu item
535 void WebFrame::OnViewSourceRequest(wxCommandEvent
& WXUNUSED(evt
))
537 SourceViewDialog
dlg(this, m_browser
->GetPageSource());
542 * Invoked when user selects the "Menu" item
544 void WebFrame::OnToolsClicked(wxCommandEvent
& WXUNUSED(evt
))
546 if(m_browser
->GetCurrentURL() == "")
549 m_tools_tiny
->Check(false);
550 m_tools_small
->Check(false);
551 m_tools_medium
->Check(false);
552 m_tools_large
->Check(false);
553 m_tools_largest
->Check(false);
555 wxWebViewZoom zoom
= m_browser
->GetZoom();
558 case wxWEB_VIEW_ZOOM_TINY
:
559 m_tools_tiny
->Check();
561 case wxWEB_VIEW_ZOOM_SMALL
:
562 m_tools_small
->Check();
564 case wxWEB_VIEW_ZOOM_MEDIUM
:
565 m_tools_medium
->Check();
567 case wxWEB_VIEW_ZOOM_LARGE
:
568 m_tools_large
->Check();
570 case wxWEB_VIEW_ZOOM_LARGEST
:
571 m_tools_largest
->Check();
575 m_edit_cut
->Enable(m_browser
->CanCut());
576 m_edit_copy
->Enable(m_browser
->CanCopy());
577 m_edit_paste
->Enable(m_browser
->CanPaste());
579 m_edit_undo
->Enable(m_browser
->CanUndo());
580 m_edit_redo
->Enable(m_browser
->CanRedo());
582 wxPoint position
= ScreenToClient( wxGetMousePosition() );
583 PopupMenu(m_tools_menu
, position
.x
, position
.y
);
587 * Invoked when user selects the zoom size in the menu
589 void WebFrame::OnSetZoom(wxCommandEvent
& evt
)
591 if (evt
.GetId() == m_tools_tiny
->GetId())
593 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_TINY
);
595 else if (evt
.GetId() == m_tools_small
->GetId())
597 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_SMALL
);
599 else if (evt
.GetId() == m_tools_medium
->GetId())
601 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM
);
603 else if (evt
.GetId() == m_tools_large
->GetId())
605 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGE
);
607 else if (evt
.GetId() == m_tools_largest
->GetId())
609 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGEST
);
617 void WebFrame::OnZoomLayout(wxCommandEvent
& WXUNUSED(evt
))
619 if(m_tools_layout
->IsChecked())
620 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
);
622 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT
);
626 * Callback invoked when a loading error occurs
628 void WebFrame::OnError(wxWebNavigationEvent
& evt
)
630 wxString errorCategory
;
631 switch (evt
.GetInt())
633 case wxWEB_NAV_ERR_CONNECTION
:
634 errorCategory
= "wxWEB_NAV_ERR_CONNECTION";
637 case wxWEB_NAV_ERR_CERTIFICATE
:
638 errorCategory
= "wxWEB_NAV_ERR_CERTIFICATE";
641 case wxWEB_NAV_ERR_AUTH
:
642 errorCategory
= "wxWEB_NAV_ERR_AUTH";
645 case wxWEB_NAV_ERR_SECURITY
:
646 errorCategory
= "wxWEB_NAV_ERR_SECURITY";
649 case wxWEB_NAV_ERR_NOT_FOUND
:
650 errorCategory
= "wxWEB_NAV_ERR_NOT_FOUND";
653 case wxWEB_NAV_ERR_REQUEST
:
654 errorCategory
= "wxWEB_NAV_ERR_REQUEST";
657 case wxWEB_NAV_ERR_USER_CANCELLED
:
658 errorCategory
= "wxWEB_NAV_ERR_USER_CANCELLED";
661 case wxWEB_NAV_ERR_OTHER
:
662 errorCategory
= "wxWEB_NAV_ERR_OTHER";
666 wxLogMessage("Error; url='" + evt
.GetURL() + "', error='" + errorCategory
+ "' (" + evt
.GetString() + ")");
668 //Show the info bar with an error
669 m_info
->ShowMessage(_("An error occurred loading ") + evt
.GetURL() + "\n" +
670 "'" + errorCategory
+ "' (" + evt
.GetString() + ")", wxICON_ERROR
);
676 * Invoked when user selects "Print" from the menu
678 void WebFrame::OnPrint(wxCommandEvent
& WXUNUSED(evt
))
683 SourceViewDialog::SourceViewDialog(wxWindow
* parent
, wxString source
) :
684 wxDialog(parent
, wxID_ANY
, "Source Code",
685 wxDefaultPosition
, wxSize(700,500),
686 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
688 wxStyledTextCtrl
* text
= new wxStyledTextCtrl(this, wxID_ANY
);
689 text
->SetMarginWidth(1, 30);
690 text
->SetMarginType(1, wxSTC_MARGIN_NUMBER
);
691 text
->SetText(source
);
693 text
->StyleClearAll();
694 text
->SetLexer(wxSTC_LEX_HTML
);
695 text
->StyleSetForeground(wxSTC_H_DOUBLESTRING
, wxColour(255,0,0));
696 text
->StyleSetForeground(wxSTC_H_SINGLESTRING
, wxColour(255,0,0));
697 text
->StyleSetForeground(wxSTC_H_ENTITY
, wxColour(255,0,0));
698 text
->StyleSetForeground(wxSTC_H_TAG
, wxColour(0,150,0));
699 text
->StyleSetForeground(wxSTC_H_TAGUNKNOWN
, wxColour(0,150,0));
700 text
->StyleSetForeground(wxSTC_H_ATTRIBUTE
, wxColour(0,0,150));
701 text
->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN
, wxColour(0,0,150));
702 text
->StyleSetForeground(wxSTC_H_COMMENT
, wxColour(150,150,150));
704 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
705 sizer
->Add(text
, 1, wxEXPAND
);