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"
52 //We map menu items to their history items
53 WX_DECLARE_HASH_MAP(int, wxSharedPtr
<wxWebHistoryItem
>,
54 wxIntegerHash
, wxIntegerEqual
, wxMenuHistoryMap
);
56 class WebApp
: public wxApp
59 virtual bool OnInit();
62 class WebFrame
: public wxFrame
67 void OnAnimationTimer(wxTimerEvent
& evt
);
69 void OnUrl(wxCommandEvent
& evt
);
70 void OnBack(wxCommandEvent
& evt
);
71 void OnForward(wxCommandEvent
& evt
);
72 void OnStop(wxCommandEvent
& evt
);
73 void OnReload(wxCommandEvent
& evt
);
74 void OnClearHistory(wxCommandEvent
& evt
);
75 void OnEnableHistory(wxCommandEvent
& evt
);
76 void OnNavigationRequest(wxWebNavigationEvent
& evt
);
77 void OnNavigationComplete(wxWebNavigationEvent
& evt
);
78 void OnDocumentLoaded(wxWebNavigationEvent
& evt
);
79 void OnNewWindow(wxWebNavigationEvent
& evt
);
80 void OnTitleChanged(wxWebNavigationEvent
& evt
);
81 void OnViewSourceRequest(wxCommandEvent
& evt
);
82 void OnToolsClicked(wxCommandEvent
& evt
);
83 void OnSetZoom(wxCommandEvent
& evt
);
84 void OnError(wxWebNavigationEvent
& evt
);
85 void OnPrint(wxCommandEvent
& evt
);
86 void OnCut(wxCommandEvent
& evt
);
87 void OnCopy(wxCommandEvent
& evt
);
88 void OnPaste(wxCommandEvent
& evt
);
89 void OnUndo(wxCommandEvent
& evt
);
90 void OnRedo(wxCommandEvent
& evt
);
91 void OnMode(wxCommandEvent
& evt
);
92 void OnZoomLayout(wxCommandEvent
& evt
);
93 void OnHistory(wxCommandEvent
& evt
);
100 wxToolBarToolBase
* m_toolbar_back
;
101 wxToolBarToolBase
* m_toolbar_forward
;
102 wxToolBarToolBase
* m_toolbar_stop
;
103 wxToolBarToolBase
* m_toolbar_reload
;
104 wxToolBarToolBase
* m_toolbar_tools
;
106 wxMenu
* m_tools_menu
;
107 wxMenu
* m_tools_history_menu
;
108 wxMenuItem
* m_tools_layout
;
109 wxMenuItem
* m_tools_tiny
;
110 wxMenuItem
* m_tools_small
;
111 wxMenuItem
* m_tools_medium
;
112 wxMenuItem
* m_tools_large
;
113 wxMenuItem
* m_tools_largest
;
114 wxMenuItem
* m_tools_handle_navigation
;
115 wxMenuItem
* m_tools_handle_new_window
;
116 wxMenuItem
* m_tools_enable_history
;
117 wxMenuItem
* m_edit_cut
;
118 wxMenuItem
* m_edit_copy
;
119 wxMenuItem
* m_edit_paste
;
120 wxMenuItem
* m_edit_undo
;
121 wxMenuItem
* m_edit_redo
;
122 wxMenuItem
* m_edit_mode
;
125 int m_animation_angle
;
128 wxStaticText
* m_info_text
;
130 wxMenuHistoryMap m_histMenuItems
;
133 class SourceViewDialog
: public wxDialog
136 SourceViewDialog(wxWindow
* parent
, wxString source
);
139 IMPLEMENT_APP(WebApp
)
141 // ============================================================================
143 // ============================================================================
145 bool WebApp::OnInit()
147 if ( !wxApp::OnInit() )
150 WebFrame
*frame
= new WebFrame();
156 WebFrame::WebFrame() : wxFrame(NULL
, wxID_ANY
, "wxWebView Sample")
158 //Required from virtual file system archive support
159 wxFileSystem::AddHandler(new wxArchiveFSHandler
);
161 // set the frame icon
162 SetIcon(wxICON(sample
));
163 SetTitle("wxWebView Sample");
166 m_animation_angle
= 0;
169 wxBoxSizer
* topsizer
= new wxBoxSizer(wxVERTICAL
);
171 // Create the toolbar
172 m_toolbar
= CreateToolBar(wxTB_TEXT
);
173 m_toolbar
->SetToolBitmapSize(wxSize(32, 32));
175 wxBitmap back
= wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
176 wxBitmap forward
= wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
178 wxBitmap stop
= wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR
);
180 wxBitmap stop
= wxBitmap(stop_xpm
);
183 wxBitmap refresh
= wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR
);
185 wxBitmap refresh
= wxBitmap(refresh_xpm
);
188 m_toolbar_back
= m_toolbar
->AddTool(wxID_ANY
, _("Back"), back
);
189 m_toolbar_forward
= m_toolbar
->AddTool(wxID_ANY
, _("Forward"), forward
);
190 m_toolbar_stop
= m_toolbar
->AddTool(wxID_ANY
, _("Stop"), stop
);
191 m_toolbar_reload
= m_toolbar
->AddTool(wxID_ANY
, _("Reload"), refresh
);
192 m_url
= new wxTextCtrl(m_toolbar
, wxID_ANY
, wxT(""), wxDefaultPosition
, wxSize(400, -1), wxTE_PROCESS_ENTER
);
193 m_toolbar
->AddControl(m_url
, _("URL"));
194 m_toolbar_tools
= m_toolbar
->AddTool(wxID_ANY
, _("Menu"), wxBitmap(wxlogo_xpm
));
196 m_toolbar
->Realize();
198 // Create the info panel
199 m_info
= new wxInfoBar(this);
200 topsizer
->Add(m_info
, wxSizerFlags().Expand());
202 // Create the webview
203 m_browser
= wxWebView::New(this, wxID_ANY
, "http://www.wxwidgets.org");
204 topsizer
->Add(m_browser
, wxSizerFlags().Expand().Proportion(1));
206 //We register the file:// protocol for testing purposes
207 m_browser
->RegisterHandler(wxSharedPtr
<wxWebHandler
>(new wxWebFileHandler()));
211 //Set a more sensible size for web browsing
212 SetSize(wxSize(800, 600));
214 // Create a log window
215 new wxLogWindow(this, _("Logging"));
217 // Create the Tools menu
218 m_tools_menu
= new wxMenu();
219 wxMenuItem
* print
= m_tools_menu
->Append(wxID_ANY
, _("Print"));
220 wxMenuItem
* viewSource
= m_tools_menu
->Append(wxID_ANY
, _("View Source"));
221 m_tools_menu
->AppendSeparator();
222 m_tools_layout
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Use Layout Zoom"));
223 m_tools_tiny
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Tiny"));
224 m_tools_small
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Small"));
225 m_tools_medium
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Medium"));
226 m_tools_large
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Large"));
227 m_tools_largest
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Largest"));
228 m_tools_menu
->AppendSeparator();
229 m_tools_handle_navigation
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle Navigation"));
230 m_tools_handle_new_window
= m_tools_menu
->AppendCheckItem(wxID_ANY
, _("Handle New Windows"));
231 m_tools_menu
->AppendSeparator();
234 m_tools_history_menu
= new wxMenu();
235 wxMenuItem
* clearhist
= m_tools_history_menu
->Append(wxID_ANY
, _("Clear History"));
236 m_tools_enable_history
= m_tools_history_menu
->AppendCheckItem(wxID_ANY
, _("Enable History"));
237 m_tools_history_menu
->AppendSeparator();
239 wxMenuItem
* history
= m_tools_menu
->AppendSubMenu(m_tools_history_menu
, "History");
241 //Create an editing menu
242 wxMenu
* editmenu
= new wxMenu();
243 m_edit_cut
= editmenu
->Append(wxID_ANY
, _("Cut"));
244 m_edit_copy
= editmenu
->Append(wxID_ANY
, _("Copy"));
245 m_edit_paste
= editmenu
->Append(wxID_ANY
, _("Paste"));
246 editmenu
->AppendSeparator();
247 m_edit_undo
= editmenu
->Append(wxID_ANY
, _("Undo"));
248 m_edit_redo
= editmenu
->Append(wxID_ANY
, _("Redo"));
249 editmenu
->AppendSeparator();
250 m_edit_mode
= editmenu
->AppendCheckItem(wxID_ANY
, _("Edit Mode"));
252 m_tools_menu
->AppendSeparator();
253 m_tools_menu
->AppendSubMenu(editmenu
, "Edit");
255 //By default we want to handle navigation and new windows
256 m_tools_handle_navigation
->Check();
257 m_tools_handle_new_window
->Check();
258 m_tools_enable_history
->Check();
259 if(!m_browser
->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
))
260 m_tools_layout
->Enable(false);
263 // Connect the toolbar events
264 Connect(m_toolbar_back
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
265 wxCommandEventHandler(WebFrame::OnBack
), NULL
, this );
266 Connect(m_toolbar_forward
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
267 wxCommandEventHandler(WebFrame::OnForward
), NULL
, this );
268 Connect(m_toolbar_stop
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
269 wxCommandEventHandler(WebFrame::OnStop
), NULL
, this );
270 Connect(m_toolbar_reload
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
271 wxCommandEventHandler(WebFrame::OnReload
),NULL
, this );
272 Connect(m_toolbar_tools
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
273 wxCommandEventHandler(WebFrame::OnToolsClicked
), NULL
, this );
275 Connect(m_url
->GetId(), wxEVT_COMMAND_TEXT_ENTER
,
276 wxCommandEventHandler(WebFrame::OnUrl
), NULL
, this );
278 // Connect the webview events
279 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING
,
280 wxWebNavigationEventHandler(WebFrame::OnNavigationRequest
), NULL
, this);
281 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED
,
282 wxWebNavigationEventHandler(WebFrame::OnNavigationComplete
), NULL
, this);
283 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED
,
284 wxWebNavigationEventHandler(WebFrame::OnDocumentLoaded
), NULL
, this);
285 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR
,
286 wxWebNavigationEventHandler(WebFrame::OnError
), NULL
, this);
287 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
,
288 wxWebNavigationEventHandler(WebFrame::OnNewWindow
), NULL
, this);
289 Connect(m_browser
->GetId(), wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
,
290 wxWebNavigationEventHandler(WebFrame::OnTitleChanged
), NULL
, this);
292 // Connect the menu events
293 Connect(viewSource
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
294 wxCommandEventHandler(WebFrame::OnViewSourceRequest
), NULL
, this );
295 Connect(print
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
296 wxCommandEventHandler(WebFrame::OnPrint
), NULL
, this );
297 Connect(m_tools_layout
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
298 wxCommandEventHandler(WebFrame::OnZoomLayout
), NULL
, this );
299 Connect(m_tools_tiny
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
300 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
301 Connect(m_tools_small
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
302 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
303 Connect(m_tools_medium
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
304 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
305 Connect(m_tools_large
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
306 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
307 Connect(m_tools_largest
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
308 wxCommandEventHandler(WebFrame::OnSetZoom
), NULL
, this );
309 Connect(clearhist
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
310 wxCommandEventHandler(WebFrame::OnClearHistory
), NULL
, this );
311 Connect(m_tools_enable_history
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
312 wxCommandEventHandler(WebFrame::OnEnableHistory
), NULL
, this );
313 Connect(m_edit_cut
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
314 wxCommandEventHandler(WebFrame::OnCut
), NULL
, this );
315 Connect(m_edit_copy
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
316 wxCommandEventHandler(WebFrame::OnCopy
), NULL
, this );
317 Connect(m_edit_paste
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
318 wxCommandEventHandler(WebFrame::OnPaste
), NULL
, this );
319 Connect(m_edit_undo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
320 wxCommandEventHandler(WebFrame::OnUndo
), NULL
, this );
321 Connect(m_edit_redo
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
322 wxCommandEventHandler(WebFrame::OnRedo
), NULL
, this );
323 Connect(m_edit_mode
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
324 wxCommandEventHandler(WebFrame::OnMode
), NULL
, this );
327 void WebFrame::OnAnimationTimer(wxTimerEvent
& WXUNUSED(evt
))
329 m_animation_angle
+= 15;
330 if (m_animation_angle
> 360) m_animation_angle
-= 360;
332 wxBitmap
image(24, 24);
335 dc
.SelectObject(image
);
336 dc
.SetBackground(wxBrush(wxColour(255,0,255)));
339 if (m_animation_angle
>= 0 && m_animation_angle
<= 180)
341 dc
.SetBrush(*wxYELLOW_BRUSH
);
342 dc
.SetPen(*wxYELLOW_PEN
);
343 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
344 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
347 dc
.DrawBitmap(wxBitmap(wxlogo_xpm
), 0, 0, true);
349 if (m_animation_angle
> 180)
351 dc
.SetBrush(*wxYELLOW_BRUSH
);
352 dc
.SetPen(*wxYELLOW_PEN
);
353 dc
.DrawCircle(16 - int(sin(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
),
354 16 + int(cos(m_animation_angle
*0.01745f
/* convert to radians */)*14.0f
), 3 );
357 image
.SetMask(new wxMask(image
, wxColour(255,0,255)));
358 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), image
);
362 * Method that retrieves the current state from the web control and updates the GUI
363 * the reflect this current state.
365 void WebFrame::UpdateState()
367 m_toolbar
->EnableTool( m_toolbar_back
->GetId(), m_browser
->CanGoBack() );
368 m_toolbar
->EnableTool( m_toolbar_forward
->GetId(), m_browser
->CanGoForward() );
370 if (m_browser
->IsBusy())
374 m_timer
= new wxTimer(this);
375 this->Connect(wxEVT_TIMER
, wxTimerEventHandler(WebFrame::OnAnimationTimer
), NULL
, this);
377 m_timer
->Start(100); // start animation timer
379 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), true );
383 if (m_timer
!= NULL
) m_timer
->Stop(); // stop animation timer
384 m_toolbar
->SetToolNormalBitmap(m_toolbar_tools
->GetId(), wxBitmap(wxlogo_xpm
));
385 m_toolbar
->EnableTool( m_toolbar_stop
->GetId(), false );
388 SetTitle( m_browser
->GetCurrentTitle() );
389 m_url
->SetValue( m_browser
->GetCurrentURL() );
393 * Callback invoked when user entered an URL and pressed enter
395 void WebFrame::OnUrl(wxCommandEvent
& WXUNUSED(evt
))
397 m_browser
->LoadUrl( m_url
->GetValue() );
402 * Callback invoked when user pressed the "back" button
404 void WebFrame::OnBack(wxCommandEvent
& WXUNUSED(evt
))
411 * Callback invoked when user pressed the "forward" button
413 void WebFrame::OnForward(wxCommandEvent
& WXUNUSED(evt
))
415 m_browser
->GoForward();
420 * Callback invoked when user pressed the "stop" button
422 void WebFrame::OnStop(wxCommandEvent
& WXUNUSED(evt
))
429 * Callback invoked when user pressed the "reload" button
431 void WebFrame::OnReload(wxCommandEvent
& WXUNUSED(evt
))
437 void WebFrame::OnClearHistory(wxCommandEvent
& WXUNUSED(evt
))
439 m_browser
->ClearHistory();
443 void WebFrame::OnEnableHistory(wxCommandEvent
& WXUNUSED(evt
))
445 m_browser
->EnableHistory(m_tools_enable_history
->IsChecked());
449 void WebFrame::OnCut(wxCommandEvent
& WXUNUSED(evt
))
454 void WebFrame::OnCopy(wxCommandEvent
& WXUNUSED(evt
))
459 void WebFrame::OnPaste(wxCommandEvent
& WXUNUSED(evt
))
464 void WebFrame::OnUndo(wxCommandEvent
& WXUNUSED(evt
))
469 void WebFrame::OnRedo(wxCommandEvent
& WXUNUSED(evt
))
474 void WebFrame::OnMode(wxCommandEvent
& WXUNUSED(evt
))
476 m_browser
->SetEditable(m_edit_mode
->IsChecked());
481 * Callback invoked when there is a request to load a new page (for instance
482 * when the user clicks a link)
484 void WebFrame::OnNavigationRequest(wxWebNavigationEvent
& evt
)
486 if(m_info
->IsShown())
491 wxLogMessage("%s", "Navigation request to '" + evt
.GetURL() + "' (target='" +
492 evt
.GetTarget() + "')");
494 wxASSERT(m_browser
->IsBusy());
496 //If we don't want to handle navigation then veto the event and navigation
497 //will not take place
498 if(!m_tools_handle_navigation
->IsChecked())
505 * Callback invoked when a navigation request was accepted
507 void WebFrame::OnNavigationComplete(wxWebNavigationEvent
& evt
)
509 wxLogMessage("%s", "Navigation complete; url='" + evt
.GetURL() + "'");
514 * Callback invoked when a page is finished loading
516 void WebFrame::OnDocumentLoaded(wxWebNavigationEvent
& evt
)
518 //Only notify if the document is the main frame, not a subframe
519 if(evt
.GetURL() == m_browser
->GetCurrentURL())
521 wxLogMessage("%s", "Document loaded; url='" + evt
.GetURL() + "'");
527 * On new window, we veto to stop extra windows appearing
529 void WebFrame::OnNewWindow(wxWebNavigationEvent
& evt
)
531 wxLogMessage("%s", "New window; url='" + evt
.GetURL() + "'");
533 //If we handle new window events then just load them in this window as we
534 //are a single window browser
535 if(m_tools_handle_new_window
->IsChecked())
536 m_browser
->LoadUrl(evt
.GetURL());
541 void WebFrame::OnTitleChanged(wxWebNavigationEvent
& evt
)
543 wxLogMessage("%s", "Title changed; title='" + evt
.GetString() + "'");
548 * Invoked when user selects the "View Source" menu item
550 void WebFrame::OnViewSourceRequest(wxCommandEvent
& WXUNUSED(evt
))
552 SourceViewDialog
dlg(this, m_browser
->GetPageSource());
557 * Invoked when user selects the "Menu" item
559 void WebFrame::OnToolsClicked(wxCommandEvent
& WXUNUSED(evt
))
561 if(m_browser
->GetCurrentURL() == "")
564 m_tools_tiny
->Check(false);
565 m_tools_small
->Check(false);
566 m_tools_medium
->Check(false);
567 m_tools_large
->Check(false);
568 m_tools_largest
->Check(false);
570 wxWebViewZoom zoom
= m_browser
->GetZoom();
573 case wxWEB_VIEW_ZOOM_TINY
:
574 m_tools_tiny
->Check();
576 case wxWEB_VIEW_ZOOM_SMALL
:
577 m_tools_small
->Check();
579 case wxWEB_VIEW_ZOOM_MEDIUM
:
580 m_tools_medium
->Check();
582 case wxWEB_VIEW_ZOOM_LARGE
:
583 m_tools_large
->Check();
585 case wxWEB_VIEW_ZOOM_LARGEST
:
586 m_tools_largest
->Check();
590 m_edit_cut
->Enable(m_browser
->CanCut());
591 m_edit_copy
->Enable(m_browser
->CanCopy());
592 m_edit_paste
->Enable(m_browser
->CanPaste());
594 m_edit_undo
->Enable(m_browser
->CanUndo());
595 m_edit_redo
->Enable(m_browser
->CanRedo());
597 //Firstly we clear the existing menu items, then we add the current ones
598 wxMenuHistoryMap::const_iterator it
;
599 for( it
= m_histMenuItems
.begin(); it
!= m_histMenuItems
.end(); ++it
)
601 m_tools_history_menu
->Destroy(it
->first
);
603 m_histMenuItems
.clear();
605 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > back
= m_browser
->GetBackwardHistory();
606 wxVector
<wxSharedPtr
<wxWebHistoryItem
> > forward
= m_browser
->GetForwardHistory();
610 for(unsigned int i
= 0; i
< back
.size(); i
++)
612 item
= m_tools_history_menu
->AppendRadioItem(wxID_ANY
, back
[i
]->GetTitle());
613 m_histMenuItems
[item
->GetId()] = back
[i
];
614 Connect(item
->GetId(), wxEVT_COMMAND_MENU_SELECTED
,
615 wxCommandEventHandler(WebFrame::OnHistory
), NULL
, this );
618 item
= m_tools_history_menu
->AppendRadioItem(wxID_ANY
, m_browser
->GetCurrentTitle());
621 //No need to connect the current item
622 m_histMenuItems
[item
->GetId()] = wxSharedPtr
<wxWebHistoryItem
>(new wxWebHistoryItem(m_browser
->GetCurrentURL(), m_browser
->GetCurrentTitle()));
624 for(unsigned int i
= 0; i
< forward
.size(); i
++)
626 item
= m_tools_history_menu
->AppendRadioItem(wxID_ANY
, forward
[i
]->GetTitle());
627 m_histMenuItems
[item
->GetId()] = forward
[i
];
628 Connect(item
->GetId(), wxEVT_COMMAND_TOOL_CLICKED
,
629 wxCommandEventHandler(WebFrame::OnHistory
), NULL
, this );
632 wxPoint position
= ScreenToClient( wxGetMousePosition() );
633 PopupMenu(m_tools_menu
, position
.x
, position
.y
);
637 * Invoked when user selects the zoom size in the menu
639 void WebFrame::OnSetZoom(wxCommandEvent
& evt
)
641 if (evt
.GetId() == m_tools_tiny
->GetId())
643 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_TINY
);
645 else if (evt
.GetId() == m_tools_small
->GetId())
647 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_SMALL
);
649 else if (evt
.GetId() == m_tools_medium
->GetId())
651 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM
);
653 else if (evt
.GetId() == m_tools_large
->GetId())
655 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGE
);
657 else if (evt
.GetId() == m_tools_largest
->GetId())
659 m_browser
->SetZoom(wxWEB_VIEW_ZOOM_LARGEST
);
667 void WebFrame::OnZoomLayout(wxCommandEvent
& WXUNUSED(evt
))
669 if(m_tools_layout
->IsChecked())
670 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT
);
672 m_browser
->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT
);
675 void WebFrame::OnHistory(wxCommandEvent
& evt
)
677 m_browser
->LoadHistoryItem(m_histMenuItems
[evt
.GetId()]);
681 * Callback invoked when a loading error occurs
683 void WebFrame::OnError(wxWebNavigationEvent
& evt
)
685 wxString errorCategory
;
686 switch (evt
.GetInt())
688 case wxWEB_NAV_ERR_CONNECTION
:
689 errorCategory
= "wxWEB_NAV_ERR_CONNECTION";
692 case wxWEB_NAV_ERR_CERTIFICATE
:
693 errorCategory
= "wxWEB_NAV_ERR_CERTIFICATE";
696 case wxWEB_NAV_ERR_AUTH
:
697 errorCategory
= "wxWEB_NAV_ERR_AUTH";
700 case wxWEB_NAV_ERR_SECURITY
:
701 errorCategory
= "wxWEB_NAV_ERR_SECURITY";
704 case wxWEB_NAV_ERR_NOT_FOUND
:
705 errorCategory
= "wxWEB_NAV_ERR_NOT_FOUND";
708 case wxWEB_NAV_ERR_REQUEST
:
709 errorCategory
= "wxWEB_NAV_ERR_REQUEST";
712 case wxWEB_NAV_ERR_USER_CANCELLED
:
713 errorCategory
= "wxWEB_NAV_ERR_USER_CANCELLED";
716 case wxWEB_NAV_ERR_OTHER
:
717 errorCategory
= "wxWEB_NAV_ERR_OTHER";
721 wxLogMessage("Error; url='" + evt
.GetURL() + "', error='" + errorCategory
+ "' (" + evt
.GetString() + ")");
723 //Show the info bar with an error
724 m_info
->ShowMessage(_("An error occurred loading ") + evt
.GetURL() + "\n" +
725 "'" + errorCategory
+ "' (" + evt
.GetString() + ")", wxICON_ERROR
);
731 * Invoked when user selects "Print" from the menu
733 void WebFrame::OnPrint(wxCommandEvent
& WXUNUSED(evt
))
738 SourceViewDialog::SourceViewDialog(wxWindow
* parent
, wxString source
) :
739 wxDialog(parent
, wxID_ANY
, "Source Code",
740 wxDefaultPosition
, wxSize(700,500),
741 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
743 wxStyledTextCtrl
* text
= new wxStyledTextCtrl(this, wxID_ANY
);
744 text
->SetMarginWidth(1, 30);
745 text
->SetMarginType(1, wxSTC_MARGIN_NUMBER
);
746 text
->SetText(source
);
748 text
->StyleClearAll();
749 text
->SetLexer(wxSTC_LEX_HTML
);
750 text
->StyleSetForeground(wxSTC_H_DOUBLESTRING
, wxColour(255,0,0));
751 text
->StyleSetForeground(wxSTC_H_SINGLESTRING
, wxColour(255,0,0));
752 text
->StyleSetForeground(wxSTC_H_ENTITY
, wxColour(255,0,0));
753 text
->StyleSetForeground(wxSTC_H_TAG
, wxColour(0,150,0));
754 text
->StyleSetForeground(wxSTC_H_TAGUNKNOWN
, wxColour(0,150,0));
755 text
->StyleSetForeground(wxSTC_H_ATTRIBUTE
, wxColour(0,0,150));
756 text
->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN
, wxColour(0,0,150));
757 text
->StyleSetForeground(wxSTC_H_COMMENT
, wxColour(150,150,150));
759 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
760 sizer
->Add(text
, 1, wxEXPAND
);