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>
31 #if !defined(__WXMSW__) && !defined(__WXPM__)
32 #include "../sample.xpm"
36 #include <wx/stc/stc.h>
38 #error "wxStyledTextControl is needed by this sample"
42 #include "refresh.xpm"
45 class WebApp
: public wxApp
48 virtual bool OnInit();
51 class WebFrame
: public wxFrame
56 void OnAnimationTimer(wxTimerEvent
& evt
);
58 void OnUrl(wxCommandEvent
& evt
);
59 void OnBack(wxCommandEvent
& evt
);
60 void OnForward(wxCommandEvent
& evt
);
61 void OnStop(wxCommandEvent
& evt
);
62 void OnReload(wxCommandEvent
& evt
);
63 void OnClearHistory(wxCommandEvent
& evt
);
64 void OnEnableHistory(wxCommandEvent
& evt
);
65 void OnNavigationRequest(wxWebNavigationEvent
& evt
);
66 void OnNavigationComplete(wxWebNavigationEvent
& evt
);
67 void OnDocumentLoaded(wxWebNavigationEvent
& evt
);
68 void OnNewWindow(wxWebNavigationEvent
& evt
);
69 void OnViewSourceRequest(wxCommandEvent
& evt
);
70 void OnToolsClicked(wxCommandEvent
& evt
);
71 void OnSetZoom(wxCommandEvent
& evt
);
72 void OnError(wxWebNavigationEvent
& evt
);
73 void OnPrint(wxCommandEvent
& evt
);
74 void OnCut(wxCommandEvent
& evt
);
75 void OnCopy(wxCommandEvent
& evt
);
76 void OnPaste(wxCommandEvent
& evt
);
77 void OnUndo(wxCommandEvent
& evt
);
78 void OnRedo(wxCommandEvent
& evt
);
79 void OnMode(wxCommandEvent
& evt
);
80 void OnZoomLayout(wxCommandEvent
& evt
);
87 wxToolBarToolBase
* m_toolbar_back
;
88 wxToolBarToolBase
* m_toolbar_forward
;
89 wxToolBarToolBase
* m_toolbar_stop
;
90 wxToolBarToolBase
* m_toolbar_reload
;
91 wxToolBarToolBase
* m_toolbar_tools
;
94 wxMenuItem
* m_tools_layout
;
95 wxMenuItem
* m_tools_tiny
;
96 wxMenuItem
* m_tools_small
;
97 wxMenuItem
* m_tools_medium
;
98 wxMenuItem
* m_tools_large
;
99 wxMenuItem
* m_tools_largest
;
100 wxMenuItem
* m_tools_handle_navigation
;
101 wxMenuItem
* m_tools_handle_new_window
;
102 wxMenuItem
* m_tools_enable_history
;
103 wxMenuItem
* m_edit_cut
;
104 wxMenuItem
* m_edit_copy
;
105 wxMenuItem
* m_edit_paste
;
106 wxMenuItem
* m_edit_undo
;
107 wxMenuItem
* m_edit_redo
;
108 wxMenuItem
* m_edit_mode
;
111 int m_animation_angle
;
114 wxStaticText
* m_info_text
;
117 class SourceViewDialog
: public wxDialog
120 SourceViewDialog(wxWindow
* parent
, wxString source
);
123 IMPLEMENT_APP(WebApp
)
125 // ============================================================================
127 // ============================================================================
129 bool WebApp::OnInit()
131 if ( !wxApp::OnInit() )
134 WebFrame
*frame
= new WebFrame();
140 WebFrame::WebFrame() : wxFrame(NULL
, wxID_ANY
, "wxWebView Sample")
142 // set the frame icon
143 SetIcon(wxICON(sample
));
144 SetTitle("wxWebView Sample");
147 m_animation_angle
= 0;
150 wxBoxSizer
* topsizer
= new wxBoxSizer(wxVERTICAL
);
152 // Create the toolbar
153 m_toolbar
= CreateToolBar(wxTB_TEXT
);
154 m_toolbar
->SetToolBitmapSize(wxSize(32, 32));
156 wxBitmap back
= wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
157 wxBitmap forward
= wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
159 wxBitmap stop
= wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR
);
161 wxBitmap stop
= wxBitmap(stop_xpm
);
164 wxBitmap refresh
= wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR
);
166 wxBitmap refresh
= wxBitmap(refresh_xpm
);
169 m_toolbar_back
= m_toolbar
->AddTool(wxID_ANY
, _("Back"), back
);
170 m_toolbar_forward
= m_toolbar
->AddTool(wxID_ANY
, _("Forward"), forward
);
171 m_toolbar_stop
= m_toolbar
->AddTool(wxID_ANY
, _("Stop"), stop
);
172 m_toolbar_reload
= m_toolbar
->AddTool(wxID_ANY
, _("Reload"), refresh
);
173 m_url
= new wxTextCtrl(m_toolbar
, wxID_ANY
, wxT(""), wxDefaultPosition
, wxSize(400, -1), wxTE_PROCESS_ENTER
);
174 m_toolbar
->AddControl(m_url
, _("URL"));
175 m_toolbar_tools
= m_toolbar
->AddTool(wxID_ANY
, _("Menu"), wxBitmap(wxlogo_xpm
));
177 m_toolbar
->Realize();
179 // Create the info panel
180 m_info
= new wxInfoBar(this);
181 topsizer
->Add(m_info
, wxSizerFlags().Expand());
183 // Create the webview
184 m_browser
= wxWebView::New(this, wxID_ANY
, "http://www.wxwidgets.org");
185 topsizer
->Add(m_browser
, wxSizerFlags().Expand().Proportion(1));
189 //Set a more sensible size for web browsing
190 SetSize(wxSize(800, 600));
192 // Create a log window
193 new wxLogWindow(this, _("Logging"));
195 // Create the Tools menu
196 m_tools_menu
= new wxMenu();
197 wxMenuItem
* print
= m_tools_menu
->Append(wxID_ANY
, _("Print"));
198 wxMenuItem
* viewSource
= m_tools_menu
->Append(wxID_ANY
, _("View Source"));
199 m_tools_menu
->AppendSeparator();
200 m_tools_layout
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Use Layout Zoom"));
201 m_tools_tiny
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Tiny"));
202 m_tools_small
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Small"));
203 m_tools_medium
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Medium"));
204 m_tools_large
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Large"));
205 m_tools_largest
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Largest"));
206 m_tools_menu
->AppendSeparator();
207 m_tools_handle_navigation
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle Navigation"));
208 m_tools_handle_new_window
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle New Windows"));
209 m_tools_menu
->AppendSeparator();
210 wxMenuItem
* clearhist
= m_tools_menu
->Append(wxID_ANY
, _("Clear History"));
211 m_tools_enable_history
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Enable History"));
213 //Create an editing menu
214 wxMenu
* editmenu
= new wxMenu();
215 m_edit_cut
= editmenu
->Append(wxID_ANY
, _("Cut"));
216 m_edit_copy
= editmenu
->Append(wxID_ANY
, _("Copy"));
217 m_edit_paste
= editmenu
->Append(wxID_ANY
, _("Paste"));
218 editmenu
->AppendSeparator();
219 m_edit_undo
= editmenu
->Append(wxID_ANY
, _("Undo"));
220 m_edit_redo
= editmenu
->Append(wxID_ANY
, _("Redo"));
221 editmenu
->AppendSeparator();
222 m_edit_mode
= editmenu
->AppendCheckItem(wxID_ANY
, _("Edit Mode"));
224 m_tools_menu
->AppendSeparator();
225 m_tools_menu
->AppendSubMenu(editmenu
, "Edit");
227 //By default we want to handle navigation and new windows
228 m_tools_handle_navigation
->Check();
229 m_tools_handle_new_window
->Check();
230 m_tools_enable_history
->Check();
231 if(!m_browser
->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
))
232 m_tools_layout
->Enable(false);
235 // Connect the toolbar events
236 Connect(m_toolbar_back
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
237 wxCommandEventHandler(WebFrame::OnBack
), NULL
, this );
238 Connect(m_toolbar_forward
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
239 wxCommandEventHandler(WebFrame::OnForward
), NULL
, this );
240 Connect(m_toolbar_stop
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
241 wxCommandEventHandler(WebFrame::OnStop
), NULL
, this );
242 Connect(m_toolbar_reload
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
243 wxCommandEventHandler(WebFrame::OnReload
),NULL
, this );
244 Connect(m_toolbar_tools
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
245 wxCommandEventHandler(WebFrame::OnToolsClicked
), NULL
, this );
247 Connect(m_url
->GetId(), wxEVT_COMMAND_TEXT_ENTER
,
248 wxCommandEventHandler(WebFrame::OnUrl
), NULL
, this );
250 // Connect the webview events
251 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
252 wxWebNavigationEventHandler(WebFrame::OnNavigationRequest
), NULL
, this);
253 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
254 wxWebNavigationEventHandler(WebFrame::OnNavigationComplete
), NULL
, this);
255 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED
,
256 wxWebNavigationEventHandler(WebFrame::OnDocumentLoaded
), NULL
, this);
257 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR
,
258 wxWebNavigationEventHandler(WebFrame::OnError
), NULL
, this);
259 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
260 wxWebNavigationEventHandler(WebFrame::OnNewWindow
), NULL
, this);
262 // Connect the menu events
263 Connect(viewSource
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
264 wxCommandEventHandler(WebFrame::OnViewSourceRequest
), NULL
, this );
265 Connect(print
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
266 wxCommandEventHandler(WebFrame::OnPrint
), NULL
, this );
267 Connect(m_tools_layout
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
268 wxCommandEventHandler(WebFrame::OnZoomLayout
), NULL
, this );
269 Connect(m_tools_tiny
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
270 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
271 Connect(m_tools_small
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
272 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
273 Connect(m_tools_medium
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
274 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
275 Connect(m_tools_large
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
276 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
277 Connect(m_tools_largest
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
278 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
279 Connect(clearhist
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
280 wxCommandEventHandler(WebFrame::OnClearHistory
), NULL
, this );
281 Connect(m_tools_enable_history
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
282 wxCommandEventHandler(WebFrame::OnEnableHistory
), NULL
, this );
283 Connect(m_edit_cut
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
284 wxCommandEventHandler(WebFrame::OnCut
), NULL
, this );
285 Connect(m_edit_copy
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
286 wxCommandEventHandler(WebFrame::OnCopy
), NULL
, this );
287 Connect(m_edit_paste
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
288 wxCommandEventHandler(WebFrame::OnPaste
), NULL
, this );
289 Connect(m_edit_undo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
290 wxCommandEventHandler(WebFrame::OnUndo
), NULL
, this );
291 Connect(m_edit_redo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
292 wxCommandEventHandler(WebFrame::OnRedo
), NULL
, this );
293 Connect(m_edit_mode
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
294 wxCommandEventHandler(WebFrame::OnMode
), NULL
, this );
297 void WebFrame::OnAnimationTimer(wxTimerEvent
& evt
)
299 m_animation_angle
+= 15;
300 if (m_animation_angle
> 360) m_animation_angle
-= 360;
302 wxBitmap
image(24, 24);
305 dc
.SelectObject(image
);
306 dc
.SetBackground(wxBrush(wxColour(255,0,255)));
309 if (m_animation_angle
>= 0 && m_animation_angle
<= 180)
311 dc
.SetBrush(*wxYELLOW_BRUSH
);
312 dc
.SetPen(*wxYELLOW_PEN
);
313 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
314 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
317 dc
.DrawBitmap(wxBitmap(wxlogo_xpm
), 0, 0, true);
319 if (m_animation_angle
> 180)
321 dc
.SetBrush(*wxYELLOW_BRUSH
);
322 dc
.SetPen(*wxYELLOW_PEN
);
323 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
324 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
327 image
.SetMask(new wxMask(image
, wxColour(255,0,255)));
328 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), image
);
332 * Method that retrieves the current state from the web control and updates the GUI
333 * the reflect this current state.
335 void WebFrame::UpdateState()
337 m_toolbar
->EnableTool( m_toolbar_back
->GetId(), m_browser
->CanGoBack() );
338 m_toolbar
->EnableTool( m_toolbar_forward
->GetId(), m_browser
->CanGoForward() );
340 if (m_browser
->IsBusy())
344 m_timer
= new wxTimer(this);
345 this->Connect(wxEVT_TIMER
, wxTimerEventHandler(WebFrame::OnAnimationTimer
), NULL
, this);
347 m_timer
->Start(100); // start animation timer
349 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), true );
353 if (m_timer
!= NULL
) m_timer
->Stop(); // stop animation timer
354 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), wxBitmap(wxlogo_xpm
));
355 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), false );
358 SetTitle( m_browser
->GetCurrentTitle() );
359 m_url
->SetValue( m_browser
->GetCurrentURL() );
363 * Callback invoked when user entered an URL and pressed enter
365 void WebFrame::OnUrl(wxCommandEvent
& evt
)
367 m_browser
->LoadUrl( m_url
->GetValue() );
372 * Callback invoked when user pressed the "back" button
374 void WebFrame::OnBack(wxCommandEvent
& evt
)
381 * Callback invoked when user pressed the "forward" button
383 void WebFrame::OnForward(wxCommandEvent
& evt
)
385 m_browser
->GoForward();
390 * Callback invoked when user pressed the "stop" button
392 void WebFrame::OnStop(wxCommandEvent
& evt
)
399 * Callback invoked when user pressed the "reload" button
401 void WebFrame::OnReload(wxCommandEvent
& evt
)
407 void WebFrame::OnClearHistory(wxCommandEvent
& evt
)
409 m_browser
->ClearHistory();
413 void WebFrame::OnEnableHistory(wxCommandEvent
& evt
)
415 m_browser
->EnableHistory(m_tools_enable_history
->IsChecked());
419 void WebFrame::OnCut(wxCommandEvent
& evt
)
424 void WebFrame::OnCopy(wxCommandEvent
& evt
)
429 void WebFrame::OnPaste(wxCommandEvent
& evt
)
434 void WebFrame::OnUndo(wxCommandEvent
& evt
)
439 void WebFrame::OnRedo(wxCommandEvent
& evt
)
444 void WebFrame::OnMode(wxCommandEvent
& evt
)
446 m_browser
->SetEditable(m_edit_mode
->IsChecked());
451 * Callback invoked when there is a request to load a new page (for instance
452 * when the user clicks a link)
454 void WebFrame::OnNavigationRequest(wxWebNavigationEvent
& evt
)
456 wxLogMessage("%s", "Navigation request to '" + evt
.GetURL() + "' (target='" +
457 evt
.GetTarget() + "')");
459 wxASSERT(m_browser
->IsBusy());
461 //If we don't want to handle navigation then veto the event and navigation
462 //will not take place
463 if(!m_tools_handle_navigation
->IsChecked())
470 * Callback invoked when a navigation request was accepted
472 void WebFrame::OnNavigationComplete(wxWebNavigationEvent
& evt
)
474 wxLogMessage("%s", "Navigation complete; url='" + evt
.GetURL() + "'");
479 * Callback invoked when a page is finished loading
481 void WebFrame::OnDocumentLoaded(wxWebNavigationEvent
& evt
)
483 //Only notify if the document is the main frame, not a subframe
484 if(evt
.GetURL() == m_browser
->GetCurrentURL())
485 wxLogMessage("%s", "Document loaded; url='" + evt
.GetURL() + "'");
490 * On new window, we veto to stop extra windows appearing
492 void WebFrame::OnNewWindow(wxWebNavigationEvent
& evt
)
494 wxLogMessage("%s", "New window; url='" + evt
.GetURL() + "'");
496 //If we handle new window events then just load them in this window as we
497 //are a single window browser
498 if(m_tools_handle_new_window
->IsChecked())
499 m_browser
->LoadUrl(evt
.GetURL());
505 * Invoked when user selects the "View Source" menu item
507 void WebFrame::OnViewSourceRequest(wxCommandEvent
& evt
)
509 SourceViewDialog
dlg(this, m_browser
->GetPageSource());
514 * Invoked when user selects the "Menu" item
516 void WebFrame::OnToolsClicked(wxCommandEvent
& evt
)
518 if(m_browser
->GetCurrentURL() == "")
521 m_tools_tiny
->Check(false);
522 m_tools_small
->Check(false);
523 m_tools_medium
->Check(false);
524 m_tools_large
->Check(false);
525 m_tools_largest
->Check(false);
527 wxWebViewZoom zoom
= m_browser
->GetZoom();
530 case wxWEB_VIEW_ZOOM_TINY
:
531 m_tools_tiny
->Check();
533 case wxWEB_VIEW_ZOOM_SMALL
:
534 m_tools_small
->Check();
536 case wxWEB_VIEW_ZOOM_MEDIUM
:
537 m_tools_medium
->Check();
539 case wxWEB_VIEW_ZOOM_LARGE
:
540 m_tools_large
->Check();
542 case wxWEB_VIEW_ZOOM_LARGEST
:
543 m_tools_largest
->Check();
547 m_edit_cut
->Enable(m_browser
->CanCut());
548 m_edit_copy
->Enable(m_browser
->CanCopy());
549 m_edit_paste
->Enable(m_browser
->CanPaste());
551 m_edit_undo
->Enable(m_browser
->CanUndo());
552 m_edit_redo
->Enable(m_browser
->CanRedo());
554 wxPoint position
= ScreenToClient( wxGetMousePosition() );
555 PopupMenu(m_tools_menu
, position
.x
, position
.y
);
559 * Invoked when user selects the zoom size in the menu
561 void WebFrame::OnSetZoom(wxCommandEvent
& evt
)
563 if (evt
.GetId() == m_tools_tiny
->GetId())
565 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_TINY
);
567 else if (evt
.GetId() == m_tools_small
->GetId())
569 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_SMALL
);
571 else if (evt
.GetId() == m_tools_medium
->GetId())
573 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM
);
575 else if (evt
.GetId() == m_tools_large
->GetId())
577 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGE
);
579 else if (evt
.GetId() == m_tools_largest
->GetId())
581 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGEST
);
589 void WebFrame::OnZoomLayout(wxCommandEvent
& evt
)
591 if(m_tools_layout
->IsChecked())
592 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
);
594 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT
);
598 * Callback invoked when a loading error occurs
600 void WebFrame::OnError(wxWebNavigationEvent
& evt
)
602 wxString errorCategory
;
603 switch (evt
.GetInt())
605 case wxWEB_NAV_ERR_CONNECTION
:
606 errorCategory
= "wxWEB_NAV_ERR_CONNECTION";
609 case wxWEB_NAV_ERR_CERTIFICATE
:
610 errorCategory
= "wxWEB_NAV_ERR_CERTIFICATE";
613 case wxWEB_NAV_ERR_AUTH
:
614 errorCategory
= "wxWEB_NAV_ERR_AUTH";
617 case wxWEB_NAV_ERR_SECURITY
:
618 errorCategory
= "wxWEB_NAV_ERR_SECURITY";
621 case wxWEB_NAV_ERR_NOT_FOUND
:
622 errorCategory
= "wxWEB_NAV_ERR_NOT_FOUND";
625 case wxWEB_NAV_ERR_REQUEST
:
626 errorCategory
= "wxWEB_NAV_ERR_REQUEST";
629 case wxWEB_NAV_ERR_USER_CANCELLED
:
630 errorCategory
= "wxWEB_NAV_ERR_USER_CANCELLED";
633 case wxWEB_NAV_ERR_OTHER
:
634 errorCategory
= "wxWEB_NAV_ERR_OTHER";
638 wxLogMessage("Error; url='" + evt
.GetURL() + "', error='" + errorCategory
+ "' (" + evt
.GetString() + ")");
640 //Show the info bar with an error
641 m_info
->ShowMessage(_("An error occurred loading ") + evt
.GetURL() + "\n" +
642 "'" + errorCategory
+ "' (" + evt
.GetString() + ")", wxICON_ERROR
);
648 * Invoked when user selects "Print" from the menu
650 void WebFrame::OnPrint(wxCommandEvent
& evt
)
655 SourceViewDialog::SourceViewDialog(wxWindow
* parent
, wxString source
) :
656 wxDialog(parent
, wxID_ANY
, "Source Code",
657 wxDefaultPosition
, wxSize(700,500),
658 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
660 wxStyledTextCtrl
* text
= new wxStyledTextCtrl(this, wxID_ANY
);
661 text
->SetMarginWidth(1, 30);
662 text
->SetMarginType(1, wxSTC_MARGIN_NUMBER
);
663 text
->SetText(source
);
665 text
->StyleClearAll();
666 text
->SetLexer(wxSTC_LEX_HTML
);
667 text
->StyleSetForeground(wxSTC_H_DOUBLESTRING
, wxColour(255,0,0));
668 text
->StyleSetForeground(wxSTC_H_SINGLESTRING
, wxColour(255,0,0));
669 text
->StyleSetForeground(wxSTC_H_ENTITY
, wxColour(255,0,0));
670 text
->StyleSetForeground(wxSTC_H_TAG
, wxColour(0,150,0));
671 text
->StyleSetForeground(wxSTC_H_TAGUNKNOWN
, wxColour(0,150,0));
672 text
->StyleSetForeground(wxSTC_H_ATTRIBUTE
, wxColour(0,0,150));
673 text
->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN
, wxColour(0,0,150));
674 text
->StyleSetForeground(wxSTC_H_COMMENT
, wxColour(150,150,150));
676 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
677 sizer
->Add(text
, 1, wxEXPAND
);