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