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 OnViewSourceRequest(wxCommandEvent
& evt
);
72 void OnToolsClicked(wxCommandEvent
& evt
);
73 void OnSetZoom(wxCommandEvent
& evt
);
74 void OnError(wxWebNavigationEvent
& evt
);
75 void OnPrint(wxCommandEvent
& evt
);
76 void OnCut(wxCommandEvent
& evt
);
77 void OnCopy(wxCommandEvent
& evt
);
78 void OnPaste(wxCommandEvent
& evt
);
79 void OnUndo(wxCommandEvent
& evt
);
80 void OnRedo(wxCommandEvent
& evt
);
81 void OnMode(wxCommandEvent
& evt
);
82 void OnZoomLayout(wxCommandEvent
& evt
);
89 wxToolBarToolBase
* m_toolbar_back
;
90 wxToolBarToolBase
* m_toolbar_forward
;
91 wxToolBarToolBase
* m_toolbar_stop
;
92 wxToolBarToolBase
* m_toolbar_reload
;
93 wxToolBarToolBase
* m_toolbar_tools
;
96 wxMenuItem
* m_tools_layout
;
97 wxMenuItem
* m_tools_tiny
;
98 wxMenuItem
* m_tools_small
;
99 wxMenuItem
* m_tools_medium
;
100 wxMenuItem
* m_tools_large
;
101 wxMenuItem
* m_tools_largest
;
102 wxMenuItem
* m_tools_handle_navigation
;
103 wxMenuItem
* m_tools_handle_new_window
;
104 wxMenuItem
* m_tools_enable_history
;
105 wxMenuItem
* m_edit_cut
;
106 wxMenuItem
* m_edit_copy
;
107 wxMenuItem
* m_edit_paste
;
108 wxMenuItem
* m_edit_undo
;
109 wxMenuItem
* m_edit_redo
;
110 wxMenuItem
* m_edit_mode
;
113 int m_animation_angle
;
116 wxStaticText
* m_info_text
;
119 class SourceViewDialog
: public wxDialog
122 SourceViewDialog(wxWindow
* parent
, wxString source
);
125 IMPLEMENT_APP(WebApp
)
127 // ============================================================================
129 // ============================================================================
131 bool WebApp::OnInit()
133 if ( !wxApp::OnInit() )
136 WebFrame
*frame
= new WebFrame();
142 WebFrame::WebFrame() : wxFrame(NULL
, wxID_ANY
, "wxWebView Sample")
144 //Required from virtual file system archive support
145 wxFileSystem::AddHandler(new wxArchiveFSHandler
);
147 // set the frame icon
148 SetIcon(wxICON(sample
));
149 SetTitle("wxWebView Sample");
152 m_animation_angle
= 0;
155 wxBoxSizer
* topsizer
= new wxBoxSizer(wxVERTICAL
);
157 // Create the toolbar
158 m_toolbar
= CreateToolBar(wxTB_TEXT
);
159 m_toolbar
->SetToolBitmapSize(wxSize(32, 32));
161 wxBitmap back
= wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
162 wxBitmap forward
= wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
164 wxBitmap stop
= wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR
);
166 wxBitmap stop
= wxBitmap(stop_xpm
);
169 wxBitmap refresh
= wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR
);
171 wxBitmap refresh
= wxBitmap(refresh_xpm
);
174 m_toolbar_back
= m_toolbar
->AddTool(wxID_ANY
, _("Back"), back
);
175 m_toolbar_forward
= m_toolbar
->AddTool(wxID_ANY
, _("Forward"), forward
);
176 m_toolbar_stop
= m_toolbar
->AddTool(wxID_ANY
, _("Stop"), stop
);
177 m_toolbar_reload
= m_toolbar
->AddTool(wxID_ANY
, _("Reload"), refresh
);
178 m_url
= new wxTextCtrl(m_toolbar
, wxID_ANY
, wxT(""), wxDefaultPosition
, wxSize(400, -1), wxTE_PROCESS_ENTER
);
179 m_toolbar
->AddControl(m_url
, _("URL"));
180 m_toolbar_tools
= m_toolbar
->AddTool(wxID_ANY
, _("Menu"), wxBitmap(wxlogo_xpm
));
182 m_toolbar
->Realize();
184 // Create the info panel
185 m_info
= new wxInfoBar(this);
186 topsizer
->Add(m_info
, wxSizerFlags().Expand());
188 // Create the webview
189 m_browser
= wxWebView::New(this, wxID_ANY
, "http://www.wxwidgets.org");
190 topsizer
->Add(m_browser
, wxSizerFlags().Expand().Proportion(1));
192 //We register the test:// protocol for testing purposes
193 m_browser
->RegisterProtocol(new wxWebFileProtocolHandler());
197 //Set a more sensible size for web browsing
198 SetSize(wxSize(800, 600));
200 // Create a log window
201 new wxLogWindow(this, _("Logging"));
203 // Create the Tools menu
204 m_tools_menu
= new wxMenu();
205 wxMenuItem
* print
= m_tools_menu
->Append(wxID_ANY
, _("Print"));
206 wxMenuItem
* viewSource
= m_tools_menu
->Append(wxID_ANY
, _("View Source"));
207 m_tools_menu
->AppendSeparator();
208 m_tools_layout
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Use Layout Zoom"));
209 m_tools_tiny
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Tiny"));
210 m_tools_small
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Small"));
211 m_tools_medium
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Medium"));
212 m_tools_large
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Large"));
213 m_tools_largest
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Largest"));
214 m_tools_menu
->AppendSeparator();
215 m_tools_handle_navigation
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle Navigation"));
216 m_tools_handle_new_window
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle New Windows"));
217 m_tools_menu
->AppendSeparator();
218 wxMenuItem
* clearhist
= m_tools_menu
->Append(wxID_ANY
, _("Clear History"));
219 m_tools_enable_history
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Enable History"));
221 //Create an editing menu
222 wxMenu
* editmenu
= new wxMenu();
223 m_edit_cut
= editmenu
->Append(wxID_ANY
, _("Cut"));
224 m_edit_copy
= editmenu
->Append(wxID_ANY
, _("Copy"));
225 m_edit_paste
= editmenu
->Append(wxID_ANY
, _("Paste"));
226 editmenu
->AppendSeparator();
227 m_edit_undo
= editmenu
->Append(wxID_ANY
, _("Undo"));
228 m_edit_redo
= editmenu
->Append(wxID_ANY
, _("Redo"));
229 editmenu
->AppendSeparator();
230 m_edit_mode
= editmenu
->AppendCheckItem(wxID_ANY
, _("Edit Mode"));
232 m_tools_menu
->AppendSeparator();
233 m_tools_menu
->AppendSubMenu(editmenu
, "Edit");
235 //By default we want to handle navigation and new windows
236 m_tools_handle_navigation
->Check();
237 m_tools_handle_new_window
->Check();
238 m_tools_enable_history
->Check();
239 if(!m_browser
->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
))
240 m_tools_layout
->Enable(false);
243 // Connect the toolbar events
244 Connect(m_toolbar_back
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
245 wxCommandEventHandler(WebFrame::OnBack
), NULL
, this );
246 Connect(m_toolbar_forward
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
247 wxCommandEventHandler(WebFrame::OnForward
), NULL
, this );
248 Connect(m_toolbar_stop
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
249 wxCommandEventHandler(WebFrame::OnStop
), NULL
, this );
250 Connect(m_toolbar_reload
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
251 wxCommandEventHandler(WebFrame::OnReload
),NULL
, this );
252 Connect(m_toolbar_tools
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
253 wxCommandEventHandler(WebFrame::OnToolsClicked
), NULL
, this );
255 Connect(m_url
->GetId(), wxEVT_COMMAND_TEXT_ENTER
,
256 wxCommandEventHandler(WebFrame::OnUrl
), NULL
, this );
258 // Connect the webview events
259 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
260 wxWebNavigationEventHandler(WebFrame::OnNavigationRequest
), NULL
, this);
261 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
262 wxWebNavigationEventHandler(WebFrame::OnNavigationComplete
), NULL
, this);
263 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED
,
264 wxWebNavigationEventHandler(WebFrame::OnDocumentLoaded
), NULL
, this);
265 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR
,
266 wxWebNavigationEventHandler(WebFrame::OnError
), NULL
, this);
267 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
268 wxWebNavigationEventHandler(WebFrame::OnNewWindow
), NULL
, this);
270 // Connect the menu events
271 Connect(viewSource
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
272 wxCommandEventHandler(WebFrame::OnViewSourceRequest
), NULL
, this );
273 Connect(print
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
274 wxCommandEventHandler(WebFrame::OnPrint
), NULL
, this );
275 Connect(m_tools_layout
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
276 wxCommandEventHandler(WebFrame::OnZoomLayout
), NULL
, this );
277 Connect(m_tools_tiny
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
278 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
279 Connect(m_tools_small
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
280 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
281 Connect(m_tools_medium
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
282 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
283 Connect(m_tools_large
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
284 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
285 Connect(m_tools_largest
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
286 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
287 Connect(clearhist
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
288 wxCommandEventHandler(WebFrame::OnClearHistory
), NULL
, this );
289 Connect(m_tools_enable_history
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
290 wxCommandEventHandler(WebFrame::OnEnableHistory
), NULL
, this );
291 Connect(m_edit_cut
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
292 wxCommandEventHandler(WebFrame::OnCut
), NULL
, this );
293 Connect(m_edit_copy
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
294 wxCommandEventHandler(WebFrame::OnCopy
), NULL
, this );
295 Connect(m_edit_paste
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
296 wxCommandEventHandler(WebFrame::OnPaste
), NULL
, this );
297 Connect(m_edit_undo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
298 wxCommandEventHandler(WebFrame::OnUndo
), NULL
, this );
299 Connect(m_edit_redo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
300 wxCommandEventHandler(WebFrame::OnRedo
), NULL
, this );
301 Connect(m_edit_mode
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
302 wxCommandEventHandler(WebFrame::OnMode
), NULL
, this );
305 void WebFrame::OnAnimationTimer(wxTimerEvent
& evt
)
307 m_animation_angle
+= 15;
308 if (m_animation_angle
> 360) m_animation_angle
-= 360;
310 wxBitmap
image(24, 24);
313 dc
.SelectObject(image
);
314 dc
.SetBackground(wxBrush(wxColour(255,0,255)));
317 if (m_animation_angle
>= 0 && m_animation_angle
<= 180)
319 dc
.SetBrush(*wxYELLOW_BRUSH
);
320 dc
.SetPen(*wxYELLOW_PEN
);
321 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
322 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
325 dc
.DrawBitmap(wxBitmap(wxlogo_xpm
), 0, 0, true);
327 if (m_animation_angle
> 180)
329 dc
.SetBrush(*wxYELLOW_BRUSH
);
330 dc
.SetPen(*wxYELLOW_PEN
);
331 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
332 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
335 image
.SetMask(new wxMask(image
, wxColour(255,0,255)));
336 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), image
);
340 * Method that retrieves the current state from the web control and updates the GUI
341 * the reflect this current state.
343 void WebFrame::UpdateState()
345 m_toolbar
->EnableTool( m_toolbar_back
->GetId(), m_browser
->CanGoBack() );
346 m_toolbar
->EnableTool( m_toolbar_forward
->GetId(), m_browser
->CanGoForward() );
348 if (m_browser
->IsBusy())
352 m_timer
= new wxTimer(this);
353 this->Connect(wxEVT_TIMER
, wxTimerEventHandler(WebFrame::OnAnimationTimer
), NULL
, this);
355 m_timer
->Start(100); // start animation timer
357 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), true );
361 if (m_timer
!= NULL
) m_timer
->Stop(); // stop animation timer
362 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), wxBitmap(wxlogo_xpm
));
363 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), false );
366 SetTitle( m_browser
->GetCurrentTitle() );
367 m_url
->SetValue( m_browser
->GetCurrentURL() );
371 * Callback invoked when user entered an URL and pressed enter
373 void WebFrame::OnUrl(wxCommandEvent
& evt
)
375 m_browser
->LoadUrl( m_url
->GetValue() );
380 * Callback invoked when user pressed the "back" button
382 void WebFrame::OnBack(wxCommandEvent
& evt
)
389 * Callback invoked when user pressed the "forward" button
391 void WebFrame::OnForward(wxCommandEvent
& evt
)
393 m_browser
->GoForward();
398 * Callback invoked when user pressed the "stop" button
400 void WebFrame::OnStop(wxCommandEvent
& evt
)
407 * Callback invoked when user pressed the "reload" button
409 void WebFrame::OnReload(wxCommandEvent
& evt
)
415 void WebFrame::OnClearHistory(wxCommandEvent
& evt
)
417 m_browser
->ClearHistory();
421 void WebFrame::OnEnableHistory(wxCommandEvent
& evt
)
423 m_browser
->EnableHistory(m_tools_enable_history
->IsChecked());
427 void WebFrame::OnCut(wxCommandEvent
& evt
)
432 void WebFrame::OnCopy(wxCommandEvent
& evt
)
437 void WebFrame::OnPaste(wxCommandEvent
& evt
)
442 void WebFrame::OnUndo(wxCommandEvent
& evt
)
447 void WebFrame::OnRedo(wxCommandEvent
& evt
)
452 void WebFrame::OnMode(wxCommandEvent
& evt
)
454 m_browser
->SetEditable(m_edit_mode
->IsChecked());
459 * Callback invoked when there is a request to load a new page (for instance
460 * when the user clicks a link)
462 void WebFrame::OnNavigationRequest(wxWebNavigationEvent
& evt
)
464 wxLogMessage("%s", "Navigation request to '" + evt
.GetURL() + "' (target='" +
465 evt
.GetTarget() + "')");
467 wxASSERT(m_browser
->IsBusy());
469 //If we don't want to handle navigation then veto the event and navigation
470 //will not take place
471 if(!m_tools_handle_navigation
->IsChecked())
478 * Callback invoked when a navigation request was accepted
480 void WebFrame::OnNavigationComplete(wxWebNavigationEvent
& evt
)
482 wxLogMessage("%s", "Navigation complete; url='" + evt
.GetURL() + "'");
487 * Callback invoked when a page is finished loading
489 void WebFrame::OnDocumentLoaded(wxWebNavigationEvent
& evt
)
491 //Only notify if the document is the main frame, not a subframe
492 if(evt
.GetURL() == m_browser
->GetCurrentURL())
493 wxLogMessage("%s", "Document loaded; url='" + evt
.GetURL() + "'");
498 * On new window, we veto to stop extra windows appearing
500 void WebFrame::OnNewWindow(wxWebNavigationEvent
& evt
)
502 wxLogMessage("%s", "New window; url='" + evt
.GetURL() + "'");
504 //If we handle new window events then just load them in this window as we
505 //are a single window browser
506 if(m_tools_handle_new_window
->IsChecked())
507 m_browser
->LoadUrl(evt
.GetURL());
513 * Invoked when user selects the "View Source" menu item
515 void WebFrame::OnViewSourceRequest(wxCommandEvent
& evt
)
517 SourceViewDialog
dlg(this, m_browser
->GetPageSource());
522 * Invoked when user selects the "Menu" item
524 void WebFrame::OnToolsClicked(wxCommandEvent
& evt
)
526 if(m_browser
->GetCurrentURL() == "")
529 m_tools_tiny
->Check(false);
530 m_tools_small
->Check(false);
531 m_tools_medium
->Check(false);
532 m_tools_large
->Check(false);
533 m_tools_largest
->Check(false);
535 wxWebViewZoom zoom
= m_browser
->GetZoom();
538 case wxWEB_VIEW_ZOOM_TINY
:
539 m_tools_tiny
->Check();
541 case wxWEB_VIEW_ZOOM_SMALL
:
542 m_tools_small
->Check();
544 case wxWEB_VIEW_ZOOM_MEDIUM
:
545 m_tools_medium
->Check();
547 case wxWEB_VIEW_ZOOM_LARGE
:
548 m_tools_large
->Check();
550 case wxWEB_VIEW_ZOOM_LARGEST
:
551 m_tools_largest
->Check();
555 m_edit_cut
->Enable(m_browser
->CanCut());
556 m_edit_copy
->Enable(m_browser
->CanCopy());
557 m_edit_paste
->Enable(m_browser
->CanPaste());
559 m_edit_undo
->Enable(m_browser
->CanUndo());
560 m_edit_redo
->Enable(m_browser
->CanRedo());
562 wxPoint position
= ScreenToClient( wxGetMousePosition() );
563 PopupMenu(m_tools_menu
, position
.x
, position
.y
);
567 * Invoked when user selects the zoom size in the menu
569 void WebFrame::OnSetZoom(wxCommandEvent
& evt
)
571 if (evt
.GetId() == m_tools_tiny
->GetId())
573 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_TINY
);
575 else if (evt
.GetId() == m_tools_small
->GetId())
577 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_SMALL
);
579 else if (evt
.GetId() == m_tools_medium
->GetId())
581 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM
);
583 else if (evt
.GetId() == m_tools_large
->GetId())
585 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGE
);
587 else if (evt
.GetId() == m_tools_largest
->GetId())
589 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGEST
);
597 void WebFrame::OnZoomLayout(wxCommandEvent
& evt
)
599 if(m_tools_layout
->IsChecked())
600 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
);
602 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT
);
606 * Callback invoked when a loading error occurs
608 void WebFrame::OnError(wxWebNavigationEvent
& evt
)
610 wxString errorCategory
;
611 switch (evt
.GetInt())
613 case wxWEB_NAV_ERR_CONNECTION
:
614 errorCategory
= "wxWEB_NAV_ERR_CONNECTION";
617 case wxWEB_NAV_ERR_CERTIFICATE
:
618 errorCategory
= "wxWEB_NAV_ERR_CERTIFICATE";
621 case wxWEB_NAV_ERR_AUTH
:
622 errorCategory
= "wxWEB_NAV_ERR_AUTH";
625 case wxWEB_NAV_ERR_SECURITY
:
626 errorCategory
= "wxWEB_NAV_ERR_SECURITY";
629 case wxWEB_NAV_ERR_NOT_FOUND
:
630 errorCategory
= "wxWEB_NAV_ERR_NOT_FOUND";
633 case wxWEB_NAV_ERR_REQUEST
:
634 errorCategory
= "wxWEB_NAV_ERR_REQUEST";
637 case wxWEB_NAV_ERR_USER_CANCELLED
:
638 errorCategory
= "wxWEB_NAV_ERR_USER_CANCELLED";
641 case wxWEB_NAV_ERR_OTHER
:
642 errorCategory
= "wxWEB_NAV_ERR_OTHER";
646 wxLogMessage("Error; url='" + evt
.GetURL() + "', error='" + errorCategory
+ "' (" + evt
.GetString() + ")");
648 //Show the info bar with an error
649 m_info
->ShowMessage(_("An error occurred loading ") + evt
.GetURL() + "\n" +
650 "'" + errorCategory
+ "' (" + evt
.GetString() + ")", wxICON_ERROR
);
656 * Invoked when user selects "Print" from the menu
658 void WebFrame::OnPrint(wxCommandEvent
& evt
)
663 SourceViewDialog::SourceViewDialog(wxWindow
* parent
, wxString source
) :
664 wxDialog(parent
, wxID_ANY
, "Source Code",
665 wxDefaultPosition
, wxSize(700,500),
666 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
668 wxStyledTextCtrl
* text
= new wxStyledTextCtrl(this, wxID_ANY
);
669 text
->SetMarginWidth(1, 30);
670 text
->SetMarginType(1, wxSTC_MARGIN_NUMBER
);
671 text
->SetText(source
);
673 text
->StyleClearAll();
674 text
->SetLexer(wxSTC_LEX_HTML
);
675 text
->StyleSetForeground(wxSTC_H_DOUBLESTRING
, wxColour(255,0,0));
676 text
->StyleSetForeground(wxSTC_H_SINGLESTRING
, wxColour(255,0,0));
677 text
->StyleSetForeground(wxSTC_H_ENTITY
, wxColour(255,0,0));
678 text
->StyleSetForeground(wxSTC_H_TAG
, wxColour(0,150,0));
679 text
->StyleSetForeground(wxSTC_H_TAGUNKNOWN
, wxColour(0,150,0));
680 text
->StyleSetForeground(wxSTC_H_ATTRIBUTE
, wxColour(0,0,150));
681 text
->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN
, wxColour(0,0,150));
682 text
->StyleSetForeground(wxSTC_H_COMMENT
, wxColour(150,150,150));
684 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
685 sizer
->Add(text
, 1, wxEXPAND
);