]> git.saurik.com Git - wxWidgets.git/blame - samples/webview/webview.cpp
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[wxWidgets.git] / samples / webview / webview.cpp
CommitLineData
61b98a2d 1/////////////////////////////////////////////////////////////////////////////
467d261e 2// Name: webview.cpp
ec4ac0f7 3// Purpose: wxWebView sample
61b98a2d
SL
4// Author: Marianne Gagnon
5// Id: $Id$
ec4ac0f7 6// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
61b98a2d
SL
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
abcb9c6e 9
ec4ac0f7
SL
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
4794f127
SL
25#if !wxUSE_WEBVIEW_WEBKIT && !wxUSE_WEBVIEW_IE
26#error "A wxWebView backend is required by this sample"
27#endif
28
b8a14a17 29#include "wx/artprov.h"
0eb47013 30#include "wx/cmdline.h"
b8a14a17
SC
31#include "wx/notifmsg.h"
32#include "wx/settings.h"
33#include "wx/webview.h"
7d8d6163 34#include "wx/webviewarchivehandler.h"
0bfd90b3 35#include "wx/webviewfshandler.h"
b8a14a17
SC
36#include "wx/infobar.h"
37#include "wx/filesys.h"
38#include "wx/fs_arc.h"
0bfd90b3 39#include "wx/fs_mem.h"
ec4ac0f7 40
e7092398 41#ifndef wxHAS_IMAGES_IN_RESOURCES
ec4ac0f7
SL
42 #include "../sample.xpm"
43#endif
61b98a2d
SL
44
45#if wxUSE_STC
b8a14a17 46#include "wx/stc/stc.h"
61b98a2d
SL
47#else
48#error "wxStyledTextControl is needed by this sample"
49#endif
50
8bccab8f 51#if defined(__WXMSW__) || defined(__WXOSX__)
61b98a2d
SL
52#include "stop.xpm"
53#include "refresh.xpm"
8bccab8f
SL
54#endif
55
dffce0bd 56#include "wxlogo.xpm"
61b98a2d 57
10ad4ba6
SL
58
59//We map menu items to their history items
c13d6ac1 60WX_DECLARE_HASH_MAP(int, wxSharedPtr<wxWebViewHistoryItem>,
10ad4ba6
SL
61 wxIntegerHash, wxIntegerEqual, wxMenuHistoryMap);
62
ec4ac0f7 63class WebApp : public wxApp
61b98a2d
SL
64{
65public:
0eb47013
VZ
66 WebApp() :
67 m_url("http://www.wxwidgets.org")
68 {
69 }
70
ec4ac0f7 71 virtual bool OnInit();
0eb47013
VZ
72
73#if wxUSE_CMDLINE_PARSER
74 virtual void OnInitCmdLine(wxCmdLineParser& parser)
75 {
76 wxApp::OnInitCmdLine(parser);
77
78 parser.AddParam("URL to open",
79 wxCMD_LINE_VAL_STRING,
80 wxCMD_LINE_PARAM_OPTIONAL);
81 }
82
83 virtual bool OnCmdLineParsed(wxCmdLineParser& parser)
84 {
85 if ( !wxApp::OnCmdLineParsed(parser) )
86 return false;
87
88 if ( parser.GetParamCount() )
89 m_url = parser.GetParam(0);
90
91 return true;
92 }
93#endif // wxUSE_CMDLINE_PARSER
94
95private:
96 wxString m_url;
61b98a2d
SL
97};
98
ec4ac0f7 99class WebFrame : public wxFrame
61b98a2d 100{
ec4ac0f7 101public:
0eb47013
VZ
102 WebFrame(const wxString& url);
103 virtual ~WebFrame();
ec4ac0f7 104
ec4ac0f7 105 void UpdateState();
a1788524 106 void OnIdle(wxIdleEvent& evt);
ec4ac0f7
SL
107 void OnUrl(wxCommandEvent& evt);
108 void OnBack(wxCommandEvent& evt);
109 void OnForward(wxCommandEvent& evt);
110 void OnStop(wxCommandEvent& evt);
111 void OnReload(wxCommandEvent& evt);
152a5808
SL
112 void OnClearHistory(wxCommandEvent& evt);
113 void OnEnableHistory(wxCommandEvent& evt);
04fa04d8
SL
114 void OnNavigationRequest(wxWebViewEvent& evt);
115 void OnNavigationComplete(wxWebViewEvent& evt);
116 void OnDocumentLoaded(wxWebViewEvent& evt);
117 void OnNewWindow(wxWebViewEvent& evt);
118 void OnTitleChanged(wxWebViewEvent& evt);
ec4ac0f7
SL
119 void OnViewSourceRequest(wxCommandEvent& evt);
120 void OnToolsClicked(wxCommandEvent& evt);
121 void OnSetZoom(wxCommandEvent& evt);
04fa04d8 122 void OnError(wxWebViewEvent& evt);
ec4ac0f7 123 void OnPrint(wxCommandEvent& evt);
4681a3ea
SL
124 void OnCut(wxCommandEvent& evt);
125 void OnCopy(wxCommandEvent& evt);
126 void OnPaste(wxCommandEvent& evt);
97e49559
SL
127 void OnUndo(wxCommandEvent& evt);
128 void OnRedo(wxCommandEvent& evt);
c7cbe308 129 void OnMode(wxCommandEvent& evt);
87d482ec 130 void OnZoomLayout(wxCommandEvent& evt);
10ad4ba6 131 void OnHistory(wxCommandEvent& evt);
1f7c17f4
VZ
132 void OnScrollLineUp(wxCommandEvent&) { m_browser->LineUp(); }
133 void OnScrollLineDown(wxCommandEvent&) { m_browser->LineDown(); }
134 void OnScrollPageUp(wxCommandEvent&) { m_browser->PageUp(); }
135 void OnScrollPageDown(wxCommandEvent&) { m_browser->PageDown(); }
54883129 136 void OnRunScript(wxCommandEvent& evt);
603cfe42
SL
137 void OnClearSelection(wxCommandEvent& evt);
138 void OnDeleteSelection(wxCommandEvent& evt);
139 void OnSelectAll(wxCommandEvent& evt);
49f07bec 140 void OnLoadScheme(wxCommandEvent& evt);
0bfd90b3 141 void OnUseMemoryFS(wxCommandEvent& evt);
66ac0400
SL
142 void OnFind(wxCommandEvent& evt);
143 void OnFindDone(wxCommandEvent& evt);
144 void OnFindText(wxCommandEvent& evt);
145 void OnFindOptions(wxCommandEvent& evt);
ec4ac0f7
SL
146
147private:
148 wxTextCtrl* m_url;
149 wxWebView* m_browser;
150
61b98a2d 151 wxToolBar* m_toolbar;
ec4ac0f7
SL
152 wxToolBarToolBase* m_toolbar_back;
153 wxToolBarToolBase* m_toolbar_forward;
154 wxToolBarToolBase* m_toolbar_stop;
155 wxToolBarToolBase* m_toolbar_reload;
156 wxToolBarToolBase* m_toolbar_tools;
157
66ac0400
SL
158 wxToolBarToolBase* m_find_toolbar_done;
159 wxToolBarToolBase* m_find_toolbar_next;
160 wxToolBarToolBase* m_find_toolbar_previous;
161 wxToolBarToolBase* m_find_toolbar_options;
162 wxMenuItem* m_find_toolbar_wrap;
163 wxMenuItem* m_find_toolbar_highlight;
164 wxMenuItem* m_find_toolbar_matchcase;
165 wxMenuItem* m_find_toolbar_wholeword;
166
ec4ac0f7 167 wxMenu* m_tools_menu;
10ad4ba6 168 wxMenu* m_tools_history_menu;
87d482ec 169 wxMenuItem* m_tools_layout;
ec4ac0f7
SL
170 wxMenuItem* m_tools_tiny;
171 wxMenuItem* m_tools_small;
172 wxMenuItem* m_tools_medium;
173 wxMenuItem* m_tools_large;
174 wxMenuItem* m_tools_largest;
62e8551f
SL
175 wxMenuItem* m_tools_handle_navigation;
176 wxMenuItem* m_tools_handle_new_window;
152a5808 177 wxMenuItem* m_tools_enable_history;
4681a3ea
SL
178 wxMenuItem* m_edit_cut;
179 wxMenuItem* m_edit_copy;
180 wxMenuItem* m_edit_paste;
97e49559
SL
181 wxMenuItem* m_edit_undo;
182 wxMenuItem* m_edit_redo;
c7cbe308 183 wxMenuItem* m_edit_mode;
1f7c17f4
VZ
184 wxMenuItem* m_scroll_line_up;
185 wxMenuItem* m_scroll_line_down;
186 wxMenuItem* m_scroll_page_up;
187 wxMenuItem* m_scroll_page_down;
603cfe42
SL
188 wxMenuItem* m_selection_clear;
189 wxMenuItem* m_selection_delete;
66ac0400 190 wxMenuItem* m_find;
ec4ac0f7 191
ec4ac0f7
SL
192 wxInfoBar *m_info;
193 wxStaticText* m_info_text;
66ac0400
SL
194 wxTextCtrl* m_find_ctrl;
195 wxToolBar* m_find_toolbar;
10ad4ba6
SL
196
197 wxMenuHistoryMap m_histMenuItems;
66ac0400
SL
198 wxString m_findText;
199 int m_findFlags, m_findCount;
ec4ac0f7
SL
200};
201
202class SourceViewDialog : public wxDialog
203{
61b98a2d 204public:
ec4ac0f7
SL
205 SourceViewDialog(wxWindow* parent, wxString source);
206};
207
208IMPLEMENT_APP(WebApp)
209
210// ============================================================================
211// implementation
212// ============================================================================
213
214bool WebApp::OnInit()
215{
216 if ( !wxApp::OnInit() )
217 return false;
218
0bfd90b3
SL
219 //Required for virtual file system archive and memory support
220 wxFileSystem::AddHandler(new wxArchiveFSHandler);
221 wxFileSystem::AddHandler(new wxMemoryFSHandler);
222
223 // Create the memory files
224 wxImage::AddHandler(new wxPNGHandler);
225 wxMemoryFSHandler::AddFile("logo.png",
226 wxBitmap(wxlogo_xpm), wxBITMAP_TYPE_PNG);
227 wxMemoryFSHandler::AddFile("page1.htm",
228 "<html><head><title>File System Example</title>"
229 "<link rel='stylesheet' type='text/css' href='memory:test.css'>"
230 "</head><body><h1>Page 1</h1>"
231 "<p><img src='memory:logo.png'></p>"
232 "<p>Some text about <a href='memory:page2.htm'>Page 2</a>.</p></body>");
233 wxMemoryFSHandler::AddFile("page2.htm",
234 "<html><head><title>File System Example</title>"
235 "<link rel='stylesheet' type='text/css' href='memory:test.css'>"
236 "</head><body><h1>Page 2</h1>"
237 "<p><a href='memory:page1.htm'>Page 1</a> was better.</p></body>");
238 wxMemoryFSHandler::AddFile("test.css", "h1 {color: red;}");
239
0eb47013 240 WebFrame *frame = new WebFrame(m_url);
ec4ac0f7
SL
241 frame->Show();
242
243 return true;
244}
245
0eb47013
VZ
246WebFrame::WebFrame(const wxString& url) :
247 wxFrame(NULL, wxID_ANY, "wxWebView Sample")
ec4ac0f7
SL
248{
249 // set the frame icon
250 SetIcon(wxICON(sample));
251 SetTitle("wxWebView Sample");
252
ec4ac0f7
SL
253 wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
254
255 // Create the toolbar
256 m_toolbar = CreateToolBar(wxTB_TEXT);
257 m_toolbar->SetToolBitmapSize(wxSize(32, 32));
abcb9c6e 258
dffce0bd
SL
259 wxBitmap back = wxArtProvider::GetBitmap(wxART_GO_BACK , wxART_TOOLBAR);
260 wxBitmap forward = wxArtProvider::GetBitmap(wxART_GO_FORWARD , wxART_TOOLBAR);
261 #ifdef __WXGTK__
262 wxBitmap stop = wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR);
abcb9c6e 263 #else
dffce0bd
SL
264 wxBitmap stop = wxBitmap(stop_xpm);
265 #endif
266 #ifdef __WXGTK__
267 wxBitmap refresh = wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR);
abcb9c6e 268 #else
dffce0bd
SL
269 wxBitmap refresh = wxBitmap(refresh_xpm);
270 #endif
271
272 m_toolbar_back = m_toolbar->AddTool(wxID_ANY, _("Back"), back);
273 m_toolbar_forward = m_toolbar->AddTool(wxID_ANY, _("Forward"), forward);
274 m_toolbar_stop = m_toolbar->AddTool(wxID_ANY, _("Stop"), stop);
275 m_toolbar_reload = m_toolbar->AddTool(wxID_ANY, _("Reload"), refresh);
ec4ac0f7 276 m_url = new wxTextCtrl(m_toolbar, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1), wxTE_PROCESS_ENTER );
9a00d078 277 m_toolbar->AddControl(m_url, _("URL"));
ec4ac0f7
SL
278 m_toolbar_tools = m_toolbar->AddTool(wxID_ANY, _("Menu"), wxBitmap(wxlogo_xpm));
279
280 m_toolbar->Realize();
281
66ac0400
SL
282 // Set find values.
283 m_findFlags = wxWEB_VIEW_FIND_DEFAULT;
284 m_findText = wxEmptyString;
285 m_findCount = 0;
286
287 // Create panel for find toolbar.
288 wxPanel* panel = new wxPanel(this);
289 topsizer->Add(panel, wxSizerFlags().Expand());
290
291 // Create sizer for panel.
292 wxBoxSizer* panel_sizer = new wxBoxSizer(wxVERTICAL);
293 panel->SetSizer(panel_sizer);
294
295 // Create the find toolbar.
296 m_find_toolbar = new wxToolBar(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxTB_TEXT|wxTB_HORZ_LAYOUT);
297 m_find_toolbar->Hide();
298 panel_sizer->Add(m_find_toolbar, wxSizerFlags().Expand());
299
300 // Create find control.
301 m_find_ctrl = new wxTextCtrl(m_find_toolbar, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(140,-1), wxTE_PROCESS_ENTER);
302
303
304 //Find options menu
305 wxMenu* findmenu = new wxMenu;
306 m_find_toolbar_wrap = findmenu->AppendCheckItem(wxID_ANY,"Wrap");
307 m_find_toolbar_matchcase = findmenu->AppendCheckItem(wxID_ANY,"Match Case");
308 m_find_toolbar_wholeword = findmenu->AppendCheckItem(wxID_ANY,"Entire Word");
309 m_find_toolbar_highlight = findmenu->AppendCheckItem(wxID_ANY,"Highlight");
310 // Add find toolbar tools.
311 m_find_toolbar->SetToolSeparation(7);
312 m_find_toolbar_done = m_find_toolbar->AddTool(wxID_ANY, "Close", wxArtProvider::GetBitmap(wxART_CROSS_MARK));
313 m_find_toolbar->AddSeparator();
314 m_find_toolbar->AddControl(m_find_ctrl, "Find");
315 m_find_toolbar->AddSeparator();
316 m_find_toolbar_next = m_find_toolbar->AddTool(wxID_ANY, "Next", wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_TOOLBAR, wxSize(16,16)));
317 m_find_toolbar_previous = m_find_toolbar->AddTool(wxID_ANY, "Previous", wxArtProvider::GetBitmap(wxART_GO_UP, wxART_TOOLBAR, wxSize(16,16)));
318 m_find_toolbar->AddSeparator();
319 m_find_toolbar_options = m_find_toolbar->AddTool(wxID_ANY, "Options", wxArtProvider::GetBitmap(wxART_PLUS, wxART_TOOLBAR, wxSize(16,16)), "", wxITEM_DROPDOWN);
320 m_find_toolbar_options->SetDropdownMenu(findmenu);
321 m_find_toolbar->Realize();
322
ec4ac0f7
SL
323 // Create the info panel
324 m_info = new wxInfoBar(this);
325 topsizer->Add(m_info, wxSizerFlags().Expand());
326
327 // Create the webview
0eb47013 328 m_browser = wxWebView::New(this, wxID_ANY, url);
ec4ac0f7
SL
329 topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
330
7d8d6163
SL
331 //We register the wxfs:// protocol for testing purposes
332 m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
0bfd90b3
SL
333 //And the memory: file system
334 m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
eff8f795 335
ec4ac0f7
SL
336 SetSizer(topsizer);
337
9a00d078
SL
338 //Set a more sensible size for web browsing
339 SetSize(wxSize(800, 600));
340
ec4ac0f7
SL
341 // Create a log window
342 new wxLogWindow(this, _("Logging"));
343
344 // Create the Tools menu
345 m_tools_menu = new wxMenu();
346 wxMenuItem* print = m_tools_menu->Append(wxID_ANY , _("Print"));
347 wxMenuItem* viewSource = m_tools_menu->Append(wxID_ANY , _("View Source"));
348 m_tools_menu->AppendSeparator();
87d482ec 349 m_tools_layout = m_tools_menu->AppendCheckItem(wxID_ANY, _("Use Layout Zoom"));
ec4ac0f7
SL
350 m_tools_tiny = m_tools_menu->AppendCheckItem(wxID_ANY, _("Tiny"));
351 m_tools_small = m_tools_menu->AppendCheckItem(wxID_ANY, _("Small"));
352 m_tools_medium = m_tools_menu->AppendCheckItem(wxID_ANY, _("Medium"));
353 m_tools_large = m_tools_menu->AppendCheckItem(wxID_ANY, _("Large"));
354 m_tools_largest = m_tools_menu->AppendCheckItem(wxID_ANY, _("Largest"));
62e8551f
SL
355 m_tools_menu->AppendSeparator();
356 m_tools_handle_navigation = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle Navigation"));
357 m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows"));
152a5808 358 m_tools_menu->AppendSeparator();
10ad4ba6 359
66ac0400
SL
360 //Find
361 m_find = m_tools_menu->Append(wxID_ANY, _("Find"));
362 m_tools_menu->AppendSeparator();
363
10ad4ba6
SL
364 //History menu
365 m_tools_history_menu = new wxMenu();
366 wxMenuItem* clearhist = m_tools_history_menu->Append(wxID_ANY, _("Clear History"));
367 m_tools_enable_history = m_tools_history_menu->AppendCheckItem(wxID_ANY, _("Enable History"));
368 m_tools_history_menu->AppendSeparator();
369
54883129 370 m_tools_menu->AppendSubMenu(m_tools_history_menu, "History");
62e8551f 371
4681a3ea
SL
372 //Create an editing menu
373 wxMenu* editmenu = new wxMenu();
374 m_edit_cut = editmenu->Append(wxID_ANY, _("Cut"));
375 m_edit_copy = editmenu->Append(wxID_ANY, _("Copy"));
376 m_edit_paste = editmenu->Append(wxID_ANY, _("Paste"));
97e49559
SL
377 editmenu->AppendSeparator();
378 m_edit_undo = editmenu->Append(wxID_ANY, _("Undo"));
379 m_edit_redo = editmenu->Append(wxID_ANY, _("Redo"));
c7cbe308
SL
380 editmenu->AppendSeparator();
381 m_edit_mode = editmenu->AppendCheckItem(wxID_ANY, _("Edit Mode"));
4681a3ea
SL
382
383 m_tools_menu->AppendSeparator();
384 m_tools_menu->AppendSubMenu(editmenu, "Edit");
385
1f7c17f4
VZ
386 wxMenu* scroll_menu = new wxMenu;
387 m_scroll_line_up = scroll_menu->Append(wxID_ANY, "Line &up");
388 m_scroll_line_down = scroll_menu->Append(wxID_ANY, "Line &down");
389 m_scroll_page_up = scroll_menu->Append(wxID_ANY, "Page u&p");
390 m_scroll_page_down = scroll_menu->Append(wxID_ANY, "Page d&own");
391 m_tools_menu->AppendSubMenu(scroll_menu, "Scroll");
392
54883129
SL
393 wxMenuItem* script = m_tools_menu->Append(wxID_ANY, _("Run Script"));
394
603cfe42
SL
395 //Selection menu
396 wxMenu* selection = new wxMenu();
397 m_selection_clear = selection->Append(wxID_ANY, _("Clear Selection"));
398 m_selection_delete = selection->Append(wxID_ANY, _("Delete Selection"));
399 wxMenuItem* selectall = selection->Append(wxID_ANY, _("Select All"));
400
401 editmenu->AppendSubMenu(selection, "Selection");
402
49f07bec 403 wxMenuItem* loadscheme = m_tools_menu->Append(wxID_ANY, _("Custom Scheme Example"));
0bfd90b3 404 wxMenuItem* usememoryfs = m_tools_menu->Append(wxID_ANY, _("Memory File System Example"));
49f07bec 405
61635eed 406 //By default we want to handle navigation and new windows
62e8551f
SL
407 m_tools_handle_navigation->Check();
408 m_tools_handle_new_window->Check();
152a5808 409 m_tools_enable_history->Check();
87d482ec
SL
410 if(!m_browser->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT))
411 m_tools_layout->Enable(false);
ec4ac0f7
SL
412
413
414 // Connect the toolbar events
415 Connect(m_toolbar_back->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
416 wxCommandEventHandler(WebFrame::OnBack), NULL, this );
417 Connect(m_toolbar_forward->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
418 wxCommandEventHandler(WebFrame::OnForward), NULL, this );
419 Connect(m_toolbar_stop->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
420 wxCommandEventHandler(WebFrame::OnStop), NULL, this );
421 Connect(m_toolbar_reload->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
422 wxCommandEventHandler(WebFrame::OnReload),NULL, this );
423 Connect(m_toolbar_tools->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
424 wxCommandEventHandler(WebFrame::OnToolsClicked), NULL, this );
425
abcb9c6e 426 Connect(m_url->GetId(), wxEVT_COMMAND_TEXT_ENTER,
ec4ac0f7
SL
427 wxCommandEventHandler(WebFrame::OnUrl), NULL, this );
428
66ac0400
SL
429 // Connect find toolbar events.
430 Connect(m_find_toolbar_done->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
431 wxCommandEventHandler(WebFrame::OnFindDone), NULL, this );
432 Connect(m_find_toolbar_next->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
433 wxCommandEventHandler(WebFrame::OnFindText), NULL, this );
434 Connect(m_find_toolbar_previous->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
435 wxCommandEventHandler(WebFrame::OnFindText), NULL, this );
436
437 // Connect find control events.
438 Connect(m_find_ctrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
439 wxCommandEventHandler(WebFrame::OnFindText), NULL, this );
440 Connect(m_find_ctrl->GetId(), wxEVT_COMMAND_TEXT_ENTER,
441 wxCommandEventHandler(WebFrame::OnFindText), NULL, this );
442
ec4ac0f7
SL
443 // Connect the webview events
444 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING,
04fa04d8 445 wxWebViewEventHandler(WebFrame::OnNavigationRequest), NULL, this);
ec4ac0f7 446 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
04fa04d8 447 wxWebViewEventHandler(WebFrame::OnNavigationComplete), NULL, this);
ec4ac0f7 448 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED,
abcb9c6e 449 wxWebViewEventHandler(WebFrame::OnDocumentLoaded), NULL, this);
ec4ac0f7 450 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR,
04fa04d8 451 wxWebViewEventHandler(WebFrame::OnError), NULL, this);
ec4ac0f7 452 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
04fa04d8 453 wxWebViewEventHandler(WebFrame::OnNewWindow), NULL, this);
153530af 454 Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED,
04fa04d8 455 wxWebViewEventHandler(WebFrame::OnTitleChanged), NULL, this);
ec4ac0f7
SL
456
457 // Connect the menu events
458 Connect(viewSource->GetId(), wxEVT_COMMAND_MENU_SELECTED,
459 wxCommandEventHandler(WebFrame::OnViewSourceRequest), NULL, this );
460 Connect(print->GetId(), wxEVT_COMMAND_MENU_SELECTED,
461 wxCommandEventHandler(WebFrame::OnPrint), NULL, this );
87d482ec
SL
462 Connect(m_tools_layout->GetId(), wxEVT_COMMAND_MENU_SELECTED,
463 wxCommandEventHandler(WebFrame::OnZoomLayout), NULL, this );
ec4ac0f7
SL
464 Connect(m_tools_tiny->GetId(), wxEVT_COMMAND_MENU_SELECTED,
465 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
466 Connect(m_tools_small->GetId(), wxEVT_COMMAND_MENU_SELECTED,
467 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
468 Connect(m_tools_medium->GetId(), wxEVT_COMMAND_MENU_SELECTED,
469 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
470 Connect(m_tools_large->GetId(), wxEVT_COMMAND_MENU_SELECTED,
471 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
472 Connect(m_tools_largest->GetId(), wxEVT_COMMAND_MENU_SELECTED,
473 wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
152a5808
SL
474 Connect(clearhist->GetId(), wxEVT_COMMAND_MENU_SELECTED,
475 wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this );
476 Connect(m_tools_enable_history->GetId(), wxEVT_COMMAND_MENU_SELECTED,
477 wxCommandEventHandler(WebFrame::OnEnableHistory), NULL, this );
4681a3ea
SL
478 Connect(m_edit_cut->GetId(), wxEVT_COMMAND_MENU_SELECTED,
479 wxCommandEventHandler(WebFrame::OnCut), NULL, this );
480 Connect(m_edit_copy->GetId(), wxEVT_COMMAND_MENU_SELECTED,
481 wxCommandEventHandler(WebFrame::OnCopy), NULL, this );
482 Connect(m_edit_paste->GetId(), wxEVT_COMMAND_MENU_SELECTED,
483 wxCommandEventHandler(WebFrame::OnPaste), NULL, this );
97e49559
SL
484 Connect(m_edit_undo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
485 wxCommandEventHandler(WebFrame::OnUndo), NULL, this );
486 Connect(m_edit_redo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
487 wxCommandEventHandler(WebFrame::OnRedo), NULL, this );
c7cbe308
SL
488 Connect(m_edit_mode->GetId(), wxEVT_COMMAND_MENU_SELECTED,
489 wxCommandEventHandler(WebFrame::OnMode), NULL, this );
1f7c17f4
VZ
490 Connect(m_scroll_line_up->GetId(), wxEVT_COMMAND_MENU_SELECTED,
491 wxCommandEventHandler(WebFrame::OnScrollLineUp), NULL, this );
492 Connect(m_scroll_line_down->GetId(), wxEVT_COMMAND_MENU_SELECTED,
493 wxCommandEventHandler(WebFrame::OnScrollLineDown), NULL, this );
494 Connect(m_scroll_page_up->GetId(), wxEVT_COMMAND_MENU_SELECTED,
495 wxCommandEventHandler(WebFrame::OnScrollPageUp), NULL, this );
496 Connect(m_scroll_page_down->GetId(), wxEVT_COMMAND_MENU_SELECTED,
497 wxCommandEventHandler(WebFrame::OnScrollPageDown), NULL, this );
54883129
SL
498 Connect(script->GetId(), wxEVT_COMMAND_MENU_SELECTED,
499 wxCommandEventHandler(WebFrame::OnRunScript), NULL, this );
603cfe42
SL
500 Connect(m_selection_clear->GetId(), wxEVT_COMMAND_MENU_SELECTED,
501 wxCommandEventHandler(WebFrame::OnClearSelection), NULL, this );
502 Connect(m_selection_delete->GetId(), wxEVT_COMMAND_MENU_SELECTED,
503 wxCommandEventHandler(WebFrame::OnDeleteSelection), NULL, this );
504 Connect(selectall->GetId(), wxEVT_COMMAND_MENU_SELECTED,
505 wxCommandEventHandler(WebFrame::OnSelectAll), NULL, this );
49f07bec
SL
506 Connect(loadscheme->GetId(), wxEVT_COMMAND_MENU_SELECTED,
507 wxCommandEventHandler(WebFrame::OnLoadScheme), NULL, this );
0bfd90b3
SL
508 Connect(usememoryfs->GetId(), wxEVT_COMMAND_MENU_SELECTED,
509 wxCommandEventHandler(WebFrame::OnUseMemoryFS), NULL, this );
66ac0400
SL
510 Connect(m_find->GetId(), wxEVT_COMMAND_MENU_SELECTED,
511 wxCommandEventHandler(WebFrame::OnFind), NULL, this );
a1788524
SL
512
513 //Connect the idle events
514 Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(WebFrame::OnIdle), NULL, this);
ec4ac0f7
SL
515}
516
7892e035
SL
517WebFrame::~WebFrame()
518{
519 delete m_tools_menu;
520}
521
ec4ac0f7
SL
522/**
523 * Method that retrieves the current state from the web control and updates the GUI
524 * the reflect this current state.
525 */
526void WebFrame::UpdateState()
527{
528 m_toolbar->EnableTool( m_toolbar_back->GetId(), m_browser->CanGoBack() );
529 m_toolbar->EnableTool( m_toolbar_forward->GetId(), m_browser->CanGoForward() );
abcb9c6e 530
ec4ac0f7 531 if (m_browser->IsBusy())
61b98a2d 532 {
abcb9c6e 533 m_toolbar->EnableTool( m_toolbar_stop->GetId(), true );
61b98a2d 534 }
ec4ac0f7 535 else
61b98a2d 536 {
abcb9c6e 537 m_toolbar->EnableTool( m_toolbar_stop->GetId(), false );
61b98a2d 538 }
abcb9c6e 539
ec4ac0f7
SL
540 SetTitle( m_browser->GetCurrentTitle() );
541 m_url->SetValue( m_browser->GetCurrentURL() );
542}
543
c49d2434 544void WebFrame::OnIdle(wxIdleEvent& WXUNUSED(evt))
a1788524
SL
545{
546 if(m_browser->IsBusy())
547 {
548 wxSetCursor(wxCURSOR_ARROWWAIT);
549 m_toolbar->EnableTool(m_toolbar_stop->GetId(), true);
550 }
551 else
552 {
553 wxSetCursor(wxNullCursor);
554 m_toolbar->EnableTool(m_toolbar_stop->GetId(), false);
555 }
556}
557
ec4ac0f7
SL
558/**
559 * Callback invoked when user entered an URL and pressed enter
560 */
8bccab8f 561void WebFrame::OnUrl(wxCommandEvent& WXUNUSED(evt))
ec4ac0f7 562{
4d0dddc7 563 m_browser->LoadURL( m_url->GetValue() );
c49d2434 564 m_browser->SetFocus();
ec4ac0f7
SL
565 UpdateState();
566}
567
568/**
569 * Callback invoked when user pressed the "back" button
570 */
8bccab8f 571void WebFrame::OnBack(wxCommandEvent& WXUNUSED(evt))
ec4ac0f7
SL
572{
573 m_browser->GoBack();
574 UpdateState();
575}
576
577/**
578 * Callback invoked when user pressed the "forward" button
579 */
8bccab8f 580void WebFrame::OnForward(wxCommandEvent& WXUNUSED(evt))
ec4ac0f7
SL
581{
582 m_browser->GoForward();
583 UpdateState();
584}
585
586/**
587 * Callback invoked when user pressed the "stop" button
588 */
8bccab8f 589void WebFrame::OnStop(wxCommandEvent& WXUNUSED(evt))
ec4ac0f7
SL
590{
591 m_browser->Stop();
592 UpdateState();
593}
594
595/**
596 * Callback invoked when user pressed the "reload" button
597 */
8bccab8f 598void WebFrame::OnReload(wxCommandEvent& WXUNUSED(evt))
ec4ac0f7
SL
599{
600 m_browser->Reload();
601 UpdateState();
602}
603
8bccab8f 604void WebFrame::OnClearHistory(wxCommandEvent& WXUNUSED(evt))
152a5808
SL
605{
606 m_browser->ClearHistory();
607 UpdateState();
608}
609
8bccab8f 610void WebFrame::OnEnableHistory(wxCommandEvent& WXUNUSED(evt))
152a5808
SL
611{
612 m_browser->EnableHistory(m_tools_enable_history->IsChecked());
613 UpdateState();
614}
615
8bccab8f 616void WebFrame::OnCut(wxCommandEvent& WXUNUSED(evt))
4681a3ea
SL
617{
618 m_browser->Cut();
619}
620
8bccab8f 621void WebFrame::OnCopy(wxCommandEvent& WXUNUSED(evt))
4681a3ea
SL
622{
623 m_browser->Copy();
624}
625
8bccab8f 626void WebFrame::OnPaste(wxCommandEvent& WXUNUSED(evt))
4681a3ea
SL
627{
628 m_browser->Paste();
629}
630
8bccab8f 631void WebFrame::OnUndo(wxCommandEvent& WXUNUSED(evt))
97e49559
SL
632{
633 m_browser->Undo();
634}
635
8bccab8f 636void WebFrame::OnRedo(wxCommandEvent& WXUNUSED(evt))
97e49559
SL
637{
638 m_browser->Redo();
639}
640
8bccab8f 641void WebFrame::OnMode(wxCommandEvent& WXUNUSED(evt))
c7cbe308
SL
642{
643 m_browser->SetEditable(m_edit_mode->IsChecked());
644}
645
49f07bec
SL
646void WebFrame::OnLoadScheme(wxCommandEvent& WXUNUSED(evt))
647{
648 wxFileName helpfile("../help/doc.zip");
649 helpfile.MakeAbsolute();
650 wxString path = helpfile.GetFullPath();
651 //Under MSW we need to flip the slashes
652 path.Replace("\\", "/");
653 path = "wxfs:///" + path + ";protocol=zip/doc.htm";
4d0dddc7 654 m_browser->LoadURL(path);
66ac0400
SL
655}
656
0bfd90b3
SL
657void WebFrame::OnUseMemoryFS(wxCommandEvent& WXUNUSED(evt))
658{
659 m_browser->LoadURL("memory:page1.htm");
660}
661
66ac0400
SL
662void WebFrame::OnFind(wxCommandEvent& WXUNUSED(evt))
663{
664 wxString value = m_browser->GetSelectedText();
665 if(value.Len() > 150)
666 {
667 value.Truncate(150);
668 }
669 m_find_ctrl->SetValue(value);
670 if(!m_find_toolbar->IsShown()){
671 m_find_toolbar->Show(true);
672 SendSizeEvent();
673 }
674 m_find_ctrl->SelectAll();
675}
676
677void WebFrame::OnFindDone(wxCommandEvent& WXUNUSED(evt))
678{
679 m_browser->Find("");
680 m_find_toolbar->Show(false);
681 SendSizeEvent();
682}
683
684void WebFrame::OnFindText(wxCommandEvent& evt)
685{
686 int flags = 0;
687
688 if(m_find_toolbar_wrap->IsChecked())
689 flags |= wxWEB_VIEW_FIND_WRAP;
690 if(m_find_toolbar_wholeword->IsChecked())
691 flags |= wxWEB_VIEW_FIND_ENTIRE_WORD;
692 if(m_find_toolbar_matchcase->IsChecked())
693 flags |= wxWEB_VIEW_FIND_MATCH_CASE;
694 if(m_find_toolbar_highlight->IsChecked())
695 flags |= wxWEB_VIEW_FIND_HIGHLIGHT_RESULT;
696
697 if(m_find_toolbar_previous->GetId() == evt.GetId())
698 flags |= wxWEB_VIEW_FIND_BACKWARDS;
699
700 wxString find_text = m_find_ctrl->GetValue();
701 long count = m_browser->Find(find_text, flags);
702
703 if(m_findText != find_text)
704 {
705 m_findCount = count;
706 m_findText = find_text;
707 }
708
709 if(count != wxNOT_FOUND || find_text.IsEmpty())
710 {
711 m_find_ctrl->SetBackgroundColour(*wxWHITE);
712 }
713 else
714 {
715 m_find_ctrl->SetBackgroundColour(wxColour(255, 101, 101));
716 }
717
718 m_find_ctrl->Refresh();
719
720 //Log the result, note that count is zero indexed.
721 if(count != m_findCount)
722 {
723 count++;
724 }
725 wxLogMessage("Searching for:%s current match:%i/%i", m_findText.c_str(), count, m_findCount);
49f07bec 726}
c7cbe308 727
ec4ac0f7
SL
728/**
729 * Callback invoked when there is a request to load a new page (for instance
730 * when the user clicks a link)
731 */
04fa04d8 732void WebFrame::OnNavigationRequest(wxWebViewEvent& evt)
ec4ac0f7 733{
75b0b0bc
SL
734 if(m_info->IsShown())
735 {
70544c1e 736 m_info->Dismiss();
75b0b0bc
SL
737 }
738
e40741b9 739 wxLogMessage("%s", "Navigation request to '" + evt.GetURL() + "' (target='" +
ec4ac0f7 740 evt.GetTarget() + "')");
abcb9c6e 741
ec4ac0f7 742 wxASSERT(m_browser->IsBusy());
62e8551f
SL
743
744 //If we don't want to handle navigation then veto the event and navigation
0e830c7c 745 //will not take place, we also need to stop the loading animation
62e8551f 746 if(!m_tools_handle_navigation->IsChecked())
0e830c7c 747 {
62e8551f 748 evt.Veto();
abcb9c6e 749 m_toolbar->EnableTool( m_toolbar_stop->GetId(), false );
0e830c7c
SL
750 }
751 else
752 {
753 UpdateState();
754 }
ec4ac0f7
SL
755}
756
757/**
758 * Callback invoked when a navigation request was accepted
759 */
04fa04d8 760void WebFrame::OnNavigationComplete(wxWebViewEvent& evt)
ec4ac0f7 761{
e40741b9 762 wxLogMessage("%s", "Navigation complete; url='" + evt.GetURL() + "'");
ec4ac0f7
SL
763 UpdateState();
764}
765
766/**
767 * Callback invoked when a page is finished loading
768 */
04fa04d8 769void WebFrame::OnDocumentLoaded(wxWebViewEvent& evt)
ec4ac0f7 770{
113e0a92 771 //Only notify if the document is the main frame, not a subframe
e40741b9 772 if(evt.GetURL() == m_browser->GetCurrentURL())
8bccab8f 773 {
e40741b9 774 wxLogMessage("%s", "Document loaded; url='" + evt.GetURL() + "'");
8bccab8f 775 }
ec4ac0f7
SL
776 UpdateState();
777}
778
779/**
780 * On new window, we veto to stop extra windows appearing
781 */
04fa04d8 782void WebFrame::OnNewWindow(wxWebViewEvent& evt)
ec4ac0f7 783{
e40741b9 784 wxLogMessage("%s", "New window; url='" + evt.GetURL() + "'");
62e8551f 785
abcb9c6e 786 //If we handle new window events then just load them in this window as we
62e8551f
SL
787 //are a single window browser
788 if(m_tools_handle_new_window->IsChecked())
4d0dddc7 789 m_browser->LoadURL(evt.GetURL());
62e8551f 790
ec4ac0f7
SL
791 UpdateState();
792}
793
04fa04d8 794void WebFrame::OnTitleChanged(wxWebViewEvent& evt)
153530af 795{
7cd03861 796 SetTitle(evt.GetString());
153530af 797 wxLogMessage("%s", "Title changed; title='" + evt.GetString() + "'");
153530af
SL
798}
799
ec4ac0f7
SL
800/**
801 * Invoked when user selects the "View Source" menu item
802 */
8bccab8f 803void WebFrame::OnViewSourceRequest(wxCommandEvent& WXUNUSED(evt))
ec4ac0f7
SL
804{
805 SourceViewDialog dlg(this, m_browser->GetPageSource());
806 dlg.ShowModal();
807}
808
809/**
810 * Invoked when user selects the "Menu" item
811 */
8bccab8f 812void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt))
ec4ac0f7
SL
813{
814 if(m_browser->GetCurrentURL() == "")
815 return;
816
817 m_tools_tiny->Check(false);
abcb9c6e 818 m_tools_small->Check(false);
ec4ac0f7
SL
819 m_tools_medium->Check(false);
820 m_tools_large->Check(false);
821 m_tools_largest->Check(false);
822
823 wxWebViewZoom zoom = m_browser->GetZoom();
824 switch (zoom)
61b98a2d 825 {
ec4ac0f7
SL
826 case wxWEB_VIEW_ZOOM_TINY:
827 m_tools_tiny->Check();
828 break;
829 case wxWEB_VIEW_ZOOM_SMALL:
830 m_tools_small->Check();
831 break;
832 case wxWEB_VIEW_ZOOM_MEDIUM:
833 m_tools_medium->Check();
834 break;
835 case wxWEB_VIEW_ZOOM_LARGE:
836 m_tools_large->Check();
837 break;
838 case wxWEB_VIEW_ZOOM_LARGEST:
839 m_tools_largest->Check();
840 break;
61b98a2d 841 }
4681a3ea
SL
842
843 m_edit_cut->Enable(m_browser->CanCut());
844 m_edit_copy->Enable(m_browser->CanCopy());
845 m_edit_paste->Enable(m_browser->CanPaste());
97e49559
SL
846
847 m_edit_undo->Enable(m_browser->CanUndo());
848 m_edit_redo->Enable(m_browser->CanRedo());
10ad4ba6 849
603cfe42
SL
850 m_selection_clear->Enable(m_browser->HasSelection());
851 m_selection_delete->Enable(m_browser->HasSelection());
852
10ad4ba6
SL
853 //Firstly we clear the existing menu items, then we add the current ones
854 wxMenuHistoryMap::const_iterator it;
855 for( it = m_histMenuItems.begin(); it != m_histMenuItems.end(); ++it )
856 {
857 m_tools_history_menu->Destroy(it->first);
858 }
859 m_histMenuItems.clear();
860
c13d6ac1
SL
861 wxVector<wxSharedPtr<wxWebViewHistoryItem> > back = m_browser->GetBackwardHistory();
862 wxVector<wxSharedPtr<wxWebViewHistoryItem> > forward = m_browser->GetForwardHistory();
10ad4ba6
SL
863
864 wxMenuItem* item;
865
abcb9c6e
JS
866 unsigned int i;
867 for(i = 0; i < back.size(); i++)
10ad4ba6
SL
868 {
869 item = m_tools_history_menu->AppendRadioItem(wxID_ANY, back[i]->GetTitle());
870 m_histMenuItems[item->GetId()] = back[i];
871 Connect(item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
872 wxCommandEventHandler(WebFrame::OnHistory), NULL, this );
873 }
874
14a0b47d
VZ
875 wxString title = m_browser->GetCurrentTitle();
876 if ( title.empty() )
877 title = "(untitled)";
878 item = m_tools_history_menu->AppendRadioItem(wxID_ANY, title);
10ad4ba6
SL
879 item->Check();
880
881 //No need to connect the current item
c13d6ac1 882 m_histMenuItems[item->GetId()] = wxSharedPtr<wxWebViewHistoryItem>(new wxWebViewHistoryItem(m_browser->GetCurrentURL(), m_browser->GetCurrentTitle()));
10ad4ba6 883
abcb9c6e 884 for(i = 0; i < forward.size(); i++)
10ad4ba6
SL
885 {
886 item = m_tools_history_menu->AppendRadioItem(wxID_ANY, forward[i]->GetTitle());
887 m_histMenuItems[item->GetId()] = forward[i];
888 Connect(item->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
889 wxCommandEventHandler(WebFrame::OnHistory), NULL, this );
890 }
abcb9c6e 891
ec4ac0f7
SL
892 wxPoint position = ScreenToClient( wxGetMousePosition() );
893 PopupMenu(m_tools_menu, position.x, position.y);
894}
895
896/**
897 * Invoked when user selects the zoom size in the menu
898 */
899void WebFrame::OnSetZoom(wxCommandEvent& evt)
900{
901 if (evt.GetId() == m_tools_tiny->GetId())
61b98a2d 902 {
ec4ac0f7 903 m_browser->SetZoom(wxWEB_VIEW_ZOOM_TINY);
61b98a2d 904 }
ec4ac0f7 905 else if (evt.GetId() == m_tools_small->GetId())
61b98a2d 906 {
ec4ac0f7 907 m_browser->SetZoom(wxWEB_VIEW_ZOOM_SMALL);
61b98a2d 908 }
ec4ac0f7 909 else if (evt.GetId() == m_tools_medium->GetId())
61b98a2d 910 {
ec4ac0f7 911 m_browser->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM);
61b98a2d 912 }
ec4ac0f7 913 else if (evt.GetId() == m_tools_large->GetId())
61b98a2d 914 {
ec4ac0f7 915 m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGE);
61b98a2d 916 }
ec4ac0f7 917 else if (evt.GetId() == m_tools_largest->GetId())
61b98a2d 918 {
ec4ac0f7 919 m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGEST);
61b98a2d 920 }
ec4ac0f7 921 else
61b98a2d 922 {
ec4ac0f7 923 wxFAIL;
61b98a2d 924 }
ec4ac0f7 925}
853b6cd0 926
8bccab8f 927void WebFrame::OnZoomLayout(wxCommandEvent& WXUNUSED(evt))
87d482ec
SL
928{
929 if(m_tools_layout->IsChecked())
930 m_browser->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT);
931 else
932 m_browser->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT);
933}
934
10ad4ba6
SL
935void WebFrame::OnHistory(wxCommandEvent& evt)
936{
937 m_browser->LoadHistoryItem(m_histMenuItems[evt.GetId()]);
938}
939
54883129
SL
940void WebFrame::OnRunScript(wxCommandEvent& WXUNUSED(evt))
941{
942 wxTextEntryDialog dialog(this, "Enter JavaScript to run.", wxGetTextFromUserPromptStr, "", wxOK|wxCANCEL|wxCENTRE|wxTE_MULTILINE);
943 if(dialog.ShowModal() == wxID_OK)
944 {
945 m_browser->RunScript(dialog.GetValue());
946 }
947}
948
603cfe42
SL
949void WebFrame::OnClearSelection(wxCommandEvent& WXUNUSED(evt))
950{
951 m_browser->ClearSelection();
952}
953
954void WebFrame::OnDeleteSelection(wxCommandEvent& WXUNUSED(evt))
955{
956 m_browser->DeleteSelection();
957}
958
959void WebFrame::OnSelectAll(wxCommandEvent& WXUNUSED(evt))
960{
961 m_browser->SelectAll();
962}
963
ec4ac0f7
SL
964/**
965 * Callback invoked when a loading error occurs
966 */
04fa04d8 967void WebFrame::OnError(wxWebViewEvent& evt)
ec4ac0f7
SL
968{
969 wxString errorCategory;
970 switch (evt.GetInt())
61b98a2d 971 {
ec4ac0f7
SL
972 case wxWEB_NAV_ERR_CONNECTION:
973 errorCategory = "wxWEB_NAV_ERR_CONNECTION";
974 break;
abcb9c6e 975
ec4ac0f7
SL
976 case wxWEB_NAV_ERR_CERTIFICATE:
977 errorCategory = "wxWEB_NAV_ERR_CERTIFICATE";
978 break;
abcb9c6e 979
ec4ac0f7
SL
980 case wxWEB_NAV_ERR_AUTH:
981 errorCategory = "wxWEB_NAV_ERR_AUTH";
982 break;
abcb9c6e 983
ec4ac0f7
SL
984 case wxWEB_NAV_ERR_SECURITY:
985 errorCategory = "wxWEB_NAV_ERR_SECURITY";
986 break;
abcb9c6e 987
ec4ac0f7
SL
988 case wxWEB_NAV_ERR_NOT_FOUND:
989 errorCategory = "wxWEB_NAV_ERR_NOT_FOUND";
990 break;
abcb9c6e 991
ec4ac0f7
SL
992 case wxWEB_NAV_ERR_REQUEST:
993 errorCategory = "wxWEB_NAV_ERR_REQUEST";
994 break;
abcb9c6e 995
ec4ac0f7
SL
996 case wxWEB_NAV_ERR_USER_CANCELLED:
997 errorCategory = "wxWEB_NAV_ERR_USER_CANCELLED";
998 break;
abcb9c6e 999
ec4ac0f7
SL
1000 case wxWEB_NAV_ERR_OTHER:
1001 errorCategory = "wxWEB_NAV_ERR_OTHER";
1002 break;
61b98a2d 1003 }
abcb9c6e 1004
f9a786f8 1005 wxLogMessage("%s", "Error; url='" + evt.GetURL() + "', error='" + errorCategory + "' (" + evt.GetString() + ")");
abcb9c6e 1006
ec4ac0f7 1007 //Show the info bar with an error
e40741b9 1008 m_info->ShowMessage(_("An error occurred loading ") + evt.GetURL() + "\n" +
ec4ac0f7 1009 "'" + errorCategory + "' (" + evt.GetString() + ")", wxICON_ERROR);
abcb9c6e 1010
ec4ac0f7
SL
1011 UpdateState();
1012}
61b98a2d 1013
ec4ac0f7
SL
1014/**
1015 * Invoked when user selects "Print" from the menu
1016 */
8bccab8f 1017void WebFrame::OnPrint(wxCommandEvent& WXUNUSED(evt))
61b98a2d 1018{
ec4ac0f7
SL
1019 m_browser->Print();
1020}
61b98a2d 1021
ec4ac0f7
SL
1022SourceViewDialog::SourceViewDialog(wxWindow* parent, wxString source) :
1023 wxDialog(parent, wxID_ANY, "Source Code",
1024 wxDefaultPosition, wxSize(700,500),
1025 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
1026{
1027 wxStyledTextCtrl* text = new wxStyledTextCtrl(this, wxID_ANY);
1028 text->SetMarginWidth(1, 30);
abcb9c6e 1029 text->SetMarginType(1, wxSTC_MARGIN_NUMBER);
ec4ac0f7 1030 text->SetText(source);
61b98a2d 1031
ec4ac0f7
SL
1032 text->StyleClearAll();
1033 text->SetLexer(wxSTC_LEX_HTML);
1034 text->StyleSetForeground(wxSTC_H_DOUBLESTRING, wxColour(255,0,0));
1035 text->StyleSetForeground(wxSTC_H_SINGLESTRING, wxColour(255,0,0));
1036 text->StyleSetForeground(wxSTC_H_ENTITY, wxColour(255,0,0));
1037 text->StyleSetForeground(wxSTC_H_TAG, wxColour(0,150,0));
1038 text->StyleSetForeground(wxSTC_H_TAGUNKNOWN, wxColour(0,150,0));
1039 text->StyleSetForeground(wxSTC_H_ATTRIBUTE, wxColour(0,0,150));
1040 text->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, wxColour(0,0,150));
1041 text->StyleSetForeground(wxSTC_H_COMMENT, wxColour(150,150,150));
61b98a2d 1042
61b98a2d 1043 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
ec4ac0f7
SL
1044 sizer->Add(text, 1, wxEXPAND);
1045 SetSizer(sizer);
61b98a2d 1046}