]> git.saurik.com Git - wxWidgets.git/blob - samples/web/web.cpp
Implement undo and redo for the ie and gtk webkit backends. Extend the sample to...
[wxWidgets.git] / samples / web / web.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: web.cpp
3 // Purpose: wxWebView sample
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #ifndef WX_PRECOMP
22 #include "wx/wx.h"
23 #endif
24
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
31 #if !defined(__WXMSW__) && !defined(__WXPM__)
32 #include "../sample.xpm"
33 #endif
34
35 #if wxUSE_STC
36 #include <wx/stc/stc.h>
37 #else
38 #error "wxStyledTextControl is needed by this sample"
39 #endif
40
41 #include "stop.xpm"
42 #include "refresh.xpm"
43 #include "wxlogo.xpm"
44
45 class WebApp : public wxApp
46 {
47 public:
48 virtual bool OnInit();
49 };
50
51 class WebFrame : public wxFrame
52 {
53 public:
54 WebFrame();
55
56 void OnAnimationTimer(wxTimerEvent& evt);
57 void UpdateState();
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
80 private:
81 wxTextCtrl* m_url;
82 wxWebView* m_browser;
83
84 wxToolBar* m_toolbar;
85 wxToolBarToolBase* m_toolbar_back;
86 wxToolBarToolBase* m_toolbar_forward;
87 wxToolBarToolBase* m_toolbar_stop;
88 wxToolBarToolBase* m_toolbar_reload;
89 wxToolBarToolBase* m_toolbar_tools;
90
91 wxMenu* m_tools_menu;
92 wxMenuItem* m_tools_tiny;
93 wxMenuItem* m_tools_small;
94 wxMenuItem* m_tools_medium;
95 wxMenuItem* m_tools_large;
96 wxMenuItem* m_tools_largest;
97 wxMenuItem* m_tools_handle_navigation;
98 wxMenuItem* m_tools_handle_new_window;
99 wxMenuItem* m_tools_enable_history;
100 wxMenuItem* m_edit_cut;
101 wxMenuItem* m_edit_copy;
102 wxMenuItem* m_edit_paste;
103 wxMenuItem* m_edit_undo;
104 wxMenuItem* m_edit_redo;
105
106 wxTimer* m_timer;
107 int m_animation_angle;
108
109 wxInfoBar *m_info;
110 wxStaticText* m_info_text;
111 };
112
113 class SourceViewDialog : public wxDialog
114 {
115 public:
116 SourceViewDialog(wxWindow* parent, wxString source);
117 };
118
119 IMPLEMENT_APP(WebApp)
120
121 // ============================================================================
122 // implementation
123 // ============================================================================
124
125 bool WebApp::OnInit()
126 {
127 if ( !wxApp::OnInit() )
128 return false;
129
130 WebFrame *frame = new WebFrame();
131 frame->Show();
132
133 return true;
134 }
135
136 WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
137 {
138 // set the frame icon
139 SetIcon(wxICON(sample));
140 SetTitle("wxWebView Sample");
141
142 m_timer = NULL;
143 m_animation_angle = 0;
144
145
146 wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
147
148 // Create the toolbar
149 m_toolbar = CreateToolBar(wxTB_TEXT);
150 m_toolbar->SetToolBitmapSize(wxSize(32, 32));
151
152 wxBitmap back = wxArtProvider::GetBitmap(wxART_GO_BACK , wxART_TOOLBAR);
153 wxBitmap forward = wxArtProvider::GetBitmap(wxART_GO_FORWARD , wxART_TOOLBAR);
154 #ifdef __WXGTK__
155 wxBitmap stop = wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR);
156 #else
157 wxBitmap stop = wxBitmap(stop_xpm);
158 #endif
159 #ifdef __WXGTK__
160 wxBitmap refresh = wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR);
161 #else
162 wxBitmap refresh = wxBitmap(refresh_xpm);
163 #endif
164
165 m_toolbar_back = m_toolbar->AddTool(wxID_ANY, _("Back"), back);
166 m_toolbar_forward = m_toolbar->AddTool(wxID_ANY, _("Forward"), forward);
167 m_toolbar_stop = m_toolbar->AddTool(wxID_ANY, _("Stop"), stop);
168 m_toolbar_reload = m_toolbar->AddTool(wxID_ANY, _("Reload"), refresh);
169 m_url = new wxTextCtrl(m_toolbar, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1), wxTE_PROCESS_ENTER );
170 m_toolbar->AddControl(m_url, _("URL"));
171 m_toolbar_tools = m_toolbar->AddTool(wxID_ANY, _("Menu"), wxBitmap(wxlogo_xpm));
172
173 m_toolbar->Realize();
174
175 // Create the info panel
176 m_info = new wxInfoBar(this);
177 topsizer->Add(m_info, wxSizerFlags().Expand());
178
179 // Create the webview
180 m_browser = wxWebView::New(this, wxID_ANY, "http://www.wxwidgets.org");
181 topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
182
183 SetSizer(topsizer);
184
185 //Set a more sensible size for web browsing
186 SetSize(wxSize(800, 600));
187
188 // Create a log window
189 new wxLogWindow(this, _("Logging"));
190
191 // Create the Tools menu
192 m_tools_menu = new wxMenu();
193 wxMenuItem* print = m_tools_menu->Append(wxID_ANY , _("Print"));
194 wxMenuItem* viewSource = m_tools_menu->Append(wxID_ANY , _("View Source"));
195 m_tools_menu->AppendSeparator();
196 m_tools_tiny = m_tools_menu->AppendCheckItem(wxID_ANY, _("Tiny"));
197 m_tools_small = m_tools_menu->AppendCheckItem(wxID_ANY, _("Small"));
198 m_tools_medium = m_tools_menu->AppendCheckItem(wxID_ANY, _("Medium"));
199 m_tools_large = m_tools_menu->AppendCheckItem(wxID_ANY, _("Large"));
200 m_tools_largest = m_tools_menu->AppendCheckItem(wxID_ANY, _("Largest"));
201 m_tools_menu->AppendSeparator();
202 m_tools_handle_navigation = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle Navigation"));
203 m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows"));
204 m_tools_menu->AppendSeparator();
205 wxMenuItem* clearhist = m_tools_menu->Append(wxID_ANY, _("Clear History"));
206 m_tools_enable_history = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable History"));
207
208 //Create an editing menu
209 wxMenu* editmenu = new wxMenu();
210 m_edit_cut = editmenu->Append(wxID_ANY, _("Cut"));
211 m_edit_copy = editmenu->Append(wxID_ANY, _("Copy"));
212 m_edit_paste = editmenu->Append(wxID_ANY, _("Paste"));
213 editmenu->AppendSeparator();
214 m_edit_undo = editmenu->Append(wxID_ANY, _("Undo"));
215 m_edit_redo = editmenu->Append(wxID_ANY, _("Redo"));
216
217 m_tools_menu->AppendSeparator();
218 m_tools_menu->AppendSubMenu(editmenu, "Edit");
219
220 //By default we want to handle navigation and new windows
221 m_tools_handle_navigation->Check();
222 m_tools_handle_new_window->Check();
223 m_tools_enable_history->Check();
224
225
226 // Connect the toolbar events
227 Connect(m_toolbar_back->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
228 wxCommandEventHandler(WebFrame::OnBack), NULL, this );
229 Connect(m_toolbar_forward->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
230 wxCommandEventHandler(WebFrame::OnForward), NULL, this );
231 Connect(m_toolbar_stop->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
232 wxCommandEventHandler(WebFrame::OnStop), NULL, this );
233 Connect(m_toolbar_reload->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
234 wxCommandEventHandler(WebFrame::OnReload),NULL, this );
235 Connect(m_toolbar_tools->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
236 wxCommandEventHandler(WebFrame::OnToolsClicked), NULL, this );
237
238 Connect(m_url->GetId(), wxEVT_COMMAND_TEXT_ENTER,
239 wxCommandEventHandler(WebFrame::OnUrl), NULL, this );
240
241 // Connect the webview events
242 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING,
243 wxWebNavigationEventHandler(WebFrame::OnNavigationRequest), NULL, this);
244 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
245 wxWebNavigationEventHandler(WebFrame::OnNavigationComplete), NULL, this);
246 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED,
247 wxWebNavigationEventHandler(WebFrame::OnDocumentLoaded), NULL, this);
248 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR,
249 wxWebNavigationEventHandler(WebFrame::OnError), NULL, this);
250 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
251 wxWebNavigationEventHandler(WebFrame::OnNewWindow), NULL, this);
252
253 // Connect the menu events
254 Connect(viewSource->GetId(), wxEVT_COMMAND_MENU_SELECTED,
255 wxCommandEventHandler(WebFrame::OnViewSourceRequest), NULL, this );
256 Connect(print->GetId(), wxEVT_COMMAND_MENU_SELECTED,
257 wxCommandEventHandler(WebFrame::OnPrint), NULL, this );
258 Connect(m_tools_tiny->GetId(), wxEVT_COMMAND_MENU_SELECTED,
259 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
260 Connect(m_tools_small->GetId(), wxEVT_COMMAND_MENU_SELECTED,
261 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
262 Connect(m_tools_medium->GetId(), wxEVT_COMMAND_MENU_SELECTED,
263 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
264 Connect(m_tools_large->GetId(), wxEVT_COMMAND_MENU_SELECTED,
265 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
266 Connect(m_tools_largest->GetId(), wxEVT_COMMAND_MENU_SELECTED,
267 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
268 Connect(clearhist->GetId(), wxEVT_COMMAND_MENU_SELECTED,
269 wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this );
270 Connect(m_tools_enable_history->GetId(), wxEVT_COMMAND_MENU_SELECTED,
271 wxCommandEventHandler(WebFrame::OnEnableHistory), NULL, this );
272 Connect(m_edit_cut->GetId(), wxEVT_COMMAND_MENU_SELECTED,
273 wxCommandEventHandler(WebFrame::OnCut), NULL, this );
274 Connect(m_edit_copy->GetId(), wxEVT_COMMAND_MENU_SELECTED,
275 wxCommandEventHandler(WebFrame::OnCopy), NULL, this );
276 Connect(m_edit_paste->GetId(), wxEVT_COMMAND_MENU_SELECTED,
277 wxCommandEventHandler(WebFrame::OnPaste), NULL, this );
278 Connect(m_edit_undo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
279 wxCommandEventHandler(WebFrame::OnUndo), NULL, this );
280 Connect(m_edit_redo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
281 wxCommandEventHandler(WebFrame::OnRedo), NULL, this );
282 }
283
284 void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
285 {
286 m_animation_angle += 15;
287 if (m_animation_angle > 360) m_animation_angle -= 360;
288
289 wxBitmap image(24, 24);
290 {
291 wxMemoryDC dc;
292 dc.SelectObject(image);
293 dc.SetBackground(wxBrush(wxColour(255,0,255)));
294 dc.Clear();
295
296 if (m_animation_angle >= 0 && m_animation_angle <= 180)
297 {
298 dc.SetBrush(*wxYELLOW_BRUSH);
299 dc.SetPen(*wxYELLOW_PEN);
300 dc.DrawCircle(16 - int(sin(m_animation_angle*0.01745f /* convert to radians */)*14.0f),
301 16 + int(cos(m_animation_angle*0.01745f /* convert to radians */)*14.0f), 3 );
302 }
303
304 dc.DrawBitmap(wxBitmap(wxlogo_xpm), 0, 0, true);
305
306 if (m_animation_angle > 180)
307 {
308 dc.SetBrush(*wxYELLOW_BRUSH);
309 dc.SetPen(*wxYELLOW_PEN);
310 dc.DrawCircle(16 - int(sin(m_animation_angle*0.01745f /* convert to radians */)*14.0f),
311 16 + int(cos(m_animation_angle*0.01745f /* convert to radians */)*14.0f), 3 );
312 }
313 }
314 image.SetMask(new wxMask(image, wxColour(255,0,255)));
315 m_toolbar->SetToolNormalBitmap(m_toolbar_tools->GetId(), image);
316 }
317
318 /**
319 * Method that retrieves the current state from the web control and updates the GUI
320 * the reflect this current state.
321 */
322 void WebFrame::UpdateState()
323 {
324 m_toolbar->EnableTool( m_toolbar_back->GetId(), m_browser->CanGoBack() );
325 m_toolbar->EnableTool( m_toolbar_forward->GetId(), m_browser->CanGoForward() );
326
327 if (m_browser->IsBusy())
328 {
329 if (m_timer == NULL)
330 {
331 m_timer = new wxTimer(this);
332 this->Connect(wxEVT_TIMER, wxTimerEventHandler(WebFrame::OnAnimationTimer), NULL, this);
333 }
334 m_timer->Start(100); // start animation timer
335
336 m_toolbar->EnableTool( m_toolbar_stop->GetId(), true );
337 }
338 else
339 {
340 if (m_timer != NULL) m_timer->Stop(); // stop animation timer
341 m_toolbar->SetToolNormalBitmap(m_toolbar_tools->GetId(), wxBitmap(wxlogo_xpm));
342 m_toolbar->EnableTool( m_toolbar_stop->GetId(), false );
343 }
344
345 SetTitle( m_browser->GetCurrentTitle() );
346 m_url->SetValue( m_browser->GetCurrentURL() );
347 }
348
349 /**
350 * Callback invoked when user entered an URL and pressed enter
351 */
352 void WebFrame::OnUrl(wxCommandEvent& evt)
353 {
354 m_browser->LoadUrl( m_url->GetValue() );
355 UpdateState();
356 }
357
358 /**
359 * Callback invoked when user pressed the "back" button
360 */
361 void WebFrame::OnBack(wxCommandEvent& evt)
362 {
363 m_browser->GoBack();
364 UpdateState();
365 }
366
367 /**
368 * Callback invoked when user pressed the "forward" button
369 */
370 void WebFrame::OnForward(wxCommandEvent& evt)
371 {
372 m_browser->GoForward();
373 UpdateState();
374 }
375
376 /**
377 * Callback invoked when user pressed the "stop" button
378 */
379 void WebFrame::OnStop(wxCommandEvent& evt)
380 {
381 m_browser->Stop();
382 UpdateState();
383 }
384
385 /**
386 * Callback invoked when user pressed the "reload" button
387 */
388 void WebFrame::OnReload(wxCommandEvent& evt)
389 {
390 m_browser->Reload();
391 UpdateState();
392 }
393
394 void WebFrame::OnClearHistory(wxCommandEvent& evt)
395 {
396 m_browser->ClearHistory();
397 UpdateState();
398 }
399
400 void WebFrame::OnEnableHistory(wxCommandEvent& evt)
401 {
402 m_browser->EnableHistory(m_tools_enable_history->IsChecked());
403 UpdateState();
404 }
405
406 void WebFrame::OnCut(wxCommandEvent& evt)
407 {
408 m_browser->Cut();
409 }
410
411 void WebFrame::OnCopy(wxCommandEvent& evt)
412 {
413 m_browser->Copy();
414 }
415
416 void WebFrame::OnPaste(wxCommandEvent& evt)
417 {
418 m_browser->Paste();
419 }
420
421 void WebFrame::OnUndo(wxCommandEvent& evt)
422 {
423 m_browser->Undo();
424 }
425
426 void WebFrame::OnRedo(wxCommandEvent& evt)
427 {
428 m_browser->Redo();
429 }
430
431 /**
432 * Callback invoked when there is a request to load a new page (for instance
433 * when the user clicks a link)
434 */
435 void WebFrame::OnNavigationRequest(wxWebNavigationEvent& evt)
436 {
437 wxLogMessage("%s", "Navigation request to '" + evt.GetHref() + "' (target='" +
438 evt.GetTarget() + "')");
439
440 wxASSERT(m_browser->IsBusy());
441
442 //If we don't want to handle navigation then veto the event and navigation
443 //will not take place
444 if(!m_tools_handle_navigation->IsChecked())
445 evt.Veto();
446
447 UpdateState();
448 }
449
450 /**
451 * Callback invoked when a navigation request was accepted
452 */
453 void WebFrame::OnNavigationComplete(wxWebNavigationEvent& evt)
454 {
455 wxLogMessage("%s", "Navigation complete; url='" + evt.GetHref() + "'");
456 UpdateState();
457 }
458
459 /**
460 * Callback invoked when a page is finished loading
461 */
462 void WebFrame::OnDocumentLoaded(wxWebNavigationEvent& evt)
463 {
464 wxLogMessage("%s", "Document loaded; url='" + evt.GetHref() + "'");
465 UpdateState();
466 }
467
468 /**
469 * On new window, we veto to stop extra windows appearing
470 */
471 void WebFrame::OnNewWindow(wxWebNavigationEvent& evt)
472 {
473 wxLogMessage("%s", "New window; url='" + evt.GetHref() + "'");
474
475 //If we handle new window events then just load them in this window as we
476 //are a single window browser
477 if(m_tools_handle_new_window->IsChecked())
478 m_browser->LoadUrl(evt.GetHref());
479
480 //We always veto because we handle the event, otherwise under windows a new
481 //internet explorer windowis created
482 evt.Veto();
483
484 UpdateState();
485 }
486
487 /**
488 * Invoked when user selects the "View Source" menu item
489 */
490 void WebFrame::OnViewSourceRequest(wxCommandEvent& evt)
491 {
492 SourceViewDialog dlg(this, m_browser->GetPageSource());
493 dlg.ShowModal();
494 }
495
496 /**
497 * Invoked when user selects the "Menu" item
498 */
499 void WebFrame::OnToolsClicked(wxCommandEvent& evt)
500 {
501 if(m_browser->GetCurrentURL() == "")
502 return;
503
504 m_tools_tiny->Check(false);
505 m_tools_small->Check(false);
506 m_tools_medium->Check(false);
507 m_tools_large->Check(false);
508 m_tools_largest->Check(false);
509
510 wxWebViewZoom zoom = m_browser->GetZoom();
511 switch (zoom)
512 {
513 case wxWEB_VIEW_ZOOM_TINY:
514 m_tools_tiny->Check();
515 break;
516 case wxWEB_VIEW_ZOOM_SMALL:
517 m_tools_small->Check();
518 break;
519 case wxWEB_VIEW_ZOOM_MEDIUM:
520 m_tools_medium->Check();
521 break;
522 case wxWEB_VIEW_ZOOM_LARGE:
523 m_tools_large->Check();
524 break;
525 case wxWEB_VIEW_ZOOM_LARGEST:
526 m_tools_largest->Check();
527 break;
528 }
529
530 m_edit_cut->Enable(m_browser->CanCut());
531 m_edit_copy->Enable(m_browser->CanCopy());
532 m_edit_paste->Enable(m_browser->CanPaste());
533
534 m_edit_undo->Enable(m_browser->CanUndo());
535 m_edit_redo->Enable(m_browser->CanRedo());
536
537 wxPoint position = ScreenToClient( wxGetMousePosition() );
538 PopupMenu(m_tools_menu, position.x, position.y);
539 }
540
541 /**
542 * Invoked when user selects the zoom size in the menu
543 */
544 void WebFrame::OnSetZoom(wxCommandEvent& evt)
545 {
546 if (evt.GetId() == m_tools_tiny->GetId())
547 {
548 m_browser->SetZoom(wxWEB_VIEW_ZOOM_TINY);
549 }
550 else if (evt.GetId() == m_tools_small->GetId())
551 {
552 m_browser->SetZoom(wxWEB_VIEW_ZOOM_SMALL);
553 }
554 else if (evt.GetId() == m_tools_medium->GetId())
555 {
556 m_browser->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM);
557 }
558 else if (evt.GetId() == m_tools_large->GetId())
559 {
560 m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGE);
561 }
562 else if (evt.GetId() == m_tools_largest->GetId())
563 {
564 m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGEST);
565 }
566 else
567 {
568 wxFAIL;
569 }
570 }
571
572 /**
573 * Callback invoked when a loading error occurs
574 */
575 void WebFrame::OnError(wxWebNavigationEvent& evt)
576 {
577 wxString errorCategory;
578 switch (evt.GetInt())
579 {
580 case wxWEB_NAV_ERR_CONNECTION:
581 errorCategory = "wxWEB_NAV_ERR_CONNECTION";
582 break;
583
584 case wxWEB_NAV_ERR_CERTIFICATE:
585 errorCategory = "wxWEB_NAV_ERR_CERTIFICATE";
586 break;
587
588 case wxWEB_NAV_ERR_AUTH:
589 errorCategory = "wxWEB_NAV_ERR_AUTH";
590 break;
591
592 case wxWEB_NAV_ERR_SECURITY:
593 errorCategory = "wxWEB_NAV_ERR_SECURITY";
594 break;
595
596 case wxWEB_NAV_ERR_NOT_FOUND:
597 errorCategory = "wxWEB_NAV_ERR_NOT_FOUND";
598 break;
599
600 case wxWEB_NAV_ERR_REQUEST:
601 errorCategory = "wxWEB_NAV_ERR_REQUEST";
602 break;
603
604 case wxWEB_NAV_ERR_USER_CANCELLED:
605 errorCategory = "wxWEB_NAV_ERR_USER_CANCELLED";
606 break;
607
608 case wxWEB_NAV_ERR_OTHER:
609 errorCategory = "wxWEB_NAV_ERR_OTHER";
610 break;
611 }
612
613 wxLogMessage("Error; url='" + evt.GetHref() + "', error='" + errorCategory + "' (" + evt.GetString() + ")");
614
615 //Show the info bar with an error
616 m_info->ShowMessage(_("An error occurred loading ") + evt.GetHref() + "\n" +
617 "'" + errorCategory + "' (" + evt.GetString() + ")", wxICON_ERROR);
618
619 UpdateState();
620 }
621
622 /**
623 * Invoked when user selects "Print" from the menu
624 */
625 void WebFrame::OnPrint(wxCommandEvent& evt)
626 {
627 m_browser->Print();
628 }
629
630 SourceViewDialog::SourceViewDialog(wxWindow* parent, wxString source) :
631 wxDialog(parent, wxID_ANY, "Source Code",
632 wxDefaultPosition, wxSize(700,500),
633 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
634 {
635 wxStyledTextCtrl* text = new wxStyledTextCtrl(this, wxID_ANY);
636 text->SetMarginWidth(1, 30);
637 text->SetMarginType(1, wxSTC_MARGIN_NUMBER);
638 text->SetText(source);
639
640 text->StyleClearAll();
641 text->SetLexer(wxSTC_LEX_HTML);
642 text->StyleSetForeground(wxSTC_H_DOUBLESTRING, wxColour(255,0,0));
643 text->StyleSetForeground(wxSTC_H_SINGLESTRING, wxColour(255,0,0));
644 text->StyleSetForeground(wxSTC_H_ENTITY, wxColour(255,0,0));
645 text->StyleSetForeground(wxSTC_H_TAG, wxColour(0,150,0));
646 text->StyleSetForeground(wxSTC_H_TAGUNKNOWN, wxColour(0,150,0));
647 text->StyleSetForeground(wxSTC_H_ATTRIBUTE, wxColour(0,0,150));
648 text->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, wxColour(0,0,150));
649 text->StyleSetForeground(wxSTC_H_COMMENT, wxColour(150,150,150));
650
651 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
652 sizer->Add(text, 1, wxEXPAND);
653 SetSizer(sizer);
654 }