2011-05-04 14:24:30 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2011-08-19 06:45:16 -04:00
|
|
|
// Name: webview.cpp
|
2011-05-27 15:47:57 -04:00
|
|
|
// Purpose: wxWebView sample
|
2011-05-04 14:24:30 -04:00
|
|
|
// Author: Marianne Gagnon
|
|
|
|
// Id: $Id$
|
2011-05-27 15:47:57 -04:00
|
|
|
// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton
|
2011-05-04 14:24:30 -04:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2011-09-14 08:39:30 -04:00
|
|
|
#if !wxUSE_WEBVIEW_WEBKIT && !wxUSE_WEBVIEW_IE
|
|
|
|
#error "A wxWebView backend is required by this sample"
|
|
|
|
#endif
|
|
|
|
|
2011-08-11 04:43:38 -04:00
|
|
|
#include "wx/artprov.h"
|
|
|
|
#include "wx/notifmsg.h"
|
|
|
|
#include "wx/settings.h"
|
|
|
|
#include "wx/webview.h"
|
2011-08-14 08:15:34 -04:00
|
|
|
#include "wx/webviewarchivehandler.h"
|
2011-08-11 04:43:38 -04:00
|
|
|
#include "wx/infobar.h"
|
|
|
|
#include "wx/filesys.h"
|
|
|
|
#include "wx/fs_arc.h"
|
2011-05-27 15:47:57 -04:00
|
|
|
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2011-05-27 15:47:57 -04:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
#if wxUSE_STC
|
2011-08-11 04:43:38 -04:00
|
|
|
#include "wx/stc/stc.h"
|
2011-05-04 14:24:30 -04:00
|
|
|
#else
|
|
|
|
#error "wxStyledTextControl is needed by this sample"
|
|
|
|
#endif
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
#if defined(__WXMSW__) || defined(__WXOSX__)
|
2011-05-04 14:24:30 -04:00
|
|
|
#include "stop.xpm"
|
|
|
|
#include "refresh.xpm"
|
2011-08-01 09:09:10 -04:00
|
|
|
#endif
|
|
|
|
|
2011-06-29 05:27:11 -04:00
|
|
|
#include "wxlogo.xpm"
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-08-13 10:11:32 -04:00
|
|
|
|
|
|
|
//We map menu items to their history items
|
2011-08-15 08:31:31 -04:00
|
|
|
WX_DECLARE_HASH_MAP(int, wxSharedPtr<wxWebViewHistoryItem>,
|
2011-08-13 10:11:32 -04:00
|
|
|
wxIntegerHash, wxIntegerEqual, wxMenuHistoryMap);
|
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
class WebApp : public wxApp
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
|
|
|
public:
|
2011-05-27 15:47:57 -04:00
|
|
|
virtual bool OnInit();
|
2011-05-04 14:24:30 -04:00
|
|
|
};
|
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
class WebFrame : public wxFrame
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
public:
|
|
|
|
WebFrame();
|
2011-09-28 15:44:35 -04:00
|
|
|
~WebFrame();
|
2011-05-27 15:47:57 -04:00
|
|
|
|
|
|
|
void UpdateState();
|
2011-11-12 15:49:40 -05:00
|
|
|
void OnIdle(wxIdleEvent& evt);
|
2011-05-27 15:47:57 -04:00
|
|
|
void OnUrl(wxCommandEvent& evt);
|
|
|
|
void OnBack(wxCommandEvent& evt);
|
|
|
|
void OnForward(wxCommandEvent& evt);
|
|
|
|
void OnStop(wxCommandEvent& evt);
|
|
|
|
void OnReload(wxCommandEvent& evt);
|
2011-06-30 06:03:25 -04:00
|
|
|
void OnClearHistory(wxCommandEvent& evt);
|
|
|
|
void OnEnableHistory(wxCommandEvent& evt);
|
2011-08-15 07:03:26 -04:00
|
|
|
void OnNavigationRequest(wxWebViewEvent& evt);
|
|
|
|
void OnNavigationComplete(wxWebViewEvent& evt);
|
|
|
|
void OnDocumentLoaded(wxWebViewEvent& evt);
|
|
|
|
void OnNewWindow(wxWebViewEvent& evt);
|
|
|
|
void OnTitleChanged(wxWebViewEvent& evt);
|
2011-05-27 15:47:57 -04:00
|
|
|
void OnViewSourceRequest(wxCommandEvent& evt);
|
|
|
|
void OnToolsClicked(wxCommandEvent& evt);
|
|
|
|
void OnSetZoom(wxCommandEvent& evt);
|
2011-08-15 07:03:26 -04:00
|
|
|
void OnError(wxWebViewEvent& evt);
|
2011-05-27 15:47:57 -04:00
|
|
|
void OnPrint(wxCommandEvent& evt);
|
2011-07-02 07:45:19 -04:00
|
|
|
void OnCut(wxCommandEvent& evt);
|
|
|
|
void OnCopy(wxCommandEvent& evt);
|
|
|
|
void OnPaste(wxCommandEvent& evt);
|
2011-07-02 11:07:46 -04:00
|
|
|
void OnUndo(wxCommandEvent& evt);
|
|
|
|
void OnRedo(wxCommandEvent& evt);
|
2011-07-08 15:34:56 -04:00
|
|
|
void OnMode(wxCommandEvent& evt);
|
2011-07-14 08:53:28 -04:00
|
|
|
void OnZoomLayout(wxCommandEvent& evt);
|
2011-08-13 10:11:32 -04:00
|
|
|
void OnHistory(wxCommandEvent& evt);
|
2011-08-13 10:53:46 -04:00
|
|
|
void OnRunScript(wxCommandEvent& evt);
|
2011-08-13 11:45:39 -04:00
|
|
|
void OnClearSelection(wxCommandEvent& evt);
|
|
|
|
void OnDeleteSelection(wxCommandEvent& evt);
|
|
|
|
void OnSelectAll(wxCommandEvent& evt);
|
2011-08-15 09:10:34 -04:00
|
|
|
void OnLoadScheme(wxCommandEvent& evt);
|
2011-05-27 15:47:57 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxTextCtrl* m_url;
|
|
|
|
wxWebView* m_browser;
|
|
|
|
|
2011-05-04 14:24:30 -04:00
|
|
|
wxToolBar* m_toolbar;
|
2011-05-27 15:47:57 -04:00
|
|
|
wxToolBarToolBase* m_toolbar_back;
|
|
|
|
wxToolBarToolBase* m_toolbar_forward;
|
|
|
|
wxToolBarToolBase* m_toolbar_stop;
|
|
|
|
wxToolBarToolBase* m_toolbar_reload;
|
|
|
|
wxToolBarToolBase* m_toolbar_tools;
|
|
|
|
|
|
|
|
wxMenu* m_tools_menu;
|
2011-08-13 10:11:32 -04:00
|
|
|
wxMenu* m_tools_history_menu;
|
2011-07-14 08:53:28 -04:00
|
|
|
wxMenuItem* m_tools_layout;
|
2011-05-27 15:47:57 -04:00
|
|
|
wxMenuItem* m_tools_tiny;
|
|
|
|
wxMenuItem* m_tools_small;
|
|
|
|
wxMenuItem* m_tools_medium;
|
|
|
|
wxMenuItem* m_tools_large;
|
|
|
|
wxMenuItem* m_tools_largest;
|
2011-06-29 08:03:36 -04:00
|
|
|
wxMenuItem* m_tools_handle_navigation;
|
|
|
|
wxMenuItem* m_tools_handle_new_window;
|
2011-06-30 06:03:25 -04:00
|
|
|
wxMenuItem* m_tools_enable_history;
|
2011-07-02 07:45:19 -04:00
|
|
|
wxMenuItem* m_edit_cut;
|
|
|
|
wxMenuItem* m_edit_copy;
|
|
|
|
wxMenuItem* m_edit_paste;
|
2011-07-02 11:07:46 -04:00
|
|
|
wxMenuItem* m_edit_undo;
|
|
|
|
wxMenuItem* m_edit_redo;
|
2011-07-08 15:34:56 -04:00
|
|
|
wxMenuItem* m_edit_mode;
|
2011-08-13 11:45:39 -04:00
|
|
|
wxMenuItem* m_selection_clear;
|
|
|
|
wxMenuItem* m_selection_delete;
|
2011-05-27 15:47:57 -04:00
|
|
|
|
|
|
|
wxInfoBar *m_info;
|
|
|
|
wxStaticText* m_info_text;
|
2011-08-13 10:11:32 -04:00
|
|
|
|
|
|
|
wxMenuHistoryMap m_histMenuItems;
|
2011-05-27 15:47:57 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class SourceViewDialog : public wxDialog
|
|
|
|
{
|
2011-05-04 14:24:30 -04:00
|
|
|
public:
|
2011-05-27 15:47:57 -04:00
|
|
|
SourceViewDialog(wxWindow* parent, wxString source);
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_APP(WebApp)
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
bool WebApp::OnInit()
|
|
|
|
{
|
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
WebFrame *frame = new WebFrame();
|
|
|
|
frame->Show();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
|
|
|
|
{
|
2011-07-28 12:49:48 -04:00
|
|
|
//Required from virtual file system archive support
|
|
|
|
wxFileSystem::AddHandler(new wxArchiveFSHandler);
|
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
// set the frame icon
|
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
SetTitle("wxWebView Sample");
|
|
|
|
|
|
|
|
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
// Create the toolbar
|
|
|
|
m_toolbar = CreateToolBar(wxTB_TEXT);
|
|
|
|
m_toolbar->SetToolBitmapSize(wxSize(32, 32));
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-06-29 05:27:11 -04:00
|
|
|
wxBitmap back = wxArtProvider::GetBitmap(wxART_GO_BACK , wxART_TOOLBAR);
|
|
|
|
wxBitmap forward = wxArtProvider::GetBitmap(wxART_GO_FORWARD , wxART_TOOLBAR);
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
wxBitmap stop = wxArtProvider::GetBitmap("gtk-stop", wxART_TOOLBAR);
|
2011-08-22 07:27:44 -04:00
|
|
|
#else
|
2011-06-29 05:27:11 -04:00
|
|
|
wxBitmap stop = wxBitmap(stop_xpm);
|
|
|
|
#endif
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
wxBitmap refresh = wxArtProvider::GetBitmap("gtk-refresh", wxART_TOOLBAR);
|
2011-08-22 07:27:44 -04:00
|
|
|
#else
|
2011-06-29 05:27:11 -04:00
|
|
|
wxBitmap refresh = wxBitmap(refresh_xpm);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_toolbar_back = m_toolbar->AddTool(wxID_ANY, _("Back"), back);
|
|
|
|
m_toolbar_forward = m_toolbar->AddTool(wxID_ANY, _("Forward"), forward);
|
|
|
|
m_toolbar_stop = m_toolbar->AddTool(wxID_ANY, _("Stop"), stop);
|
|
|
|
m_toolbar_reload = m_toolbar->AddTool(wxID_ANY, _("Reload"), refresh);
|
2011-05-27 15:47:57 -04:00
|
|
|
m_url = new wxTextCtrl(m_toolbar, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1), wxTE_PROCESS_ENTER );
|
2011-06-29 12:09:52 -04:00
|
|
|
m_toolbar->AddControl(m_url, _("URL"));
|
2011-05-27 15:47:57 -04:00
|
|
|
m_toolbar_tools = m_toolbar->AddTool(wxID_ANY, _("Menu"), wxBitmap(wxlogo_xpm));
|
|
|
|
|
|
|
|
m_toolbar->Realize();
|
|
|
|
|
|
|
|
// Create the info panel
|
|
|
|
m_info = new wxInfoBar(this);
|
|
|
|
topsizer->Add(m_info, wxSizerFlags().Expand());
|
|
|
|
|
|
|
|
// Create the webview
|
2011-06-29 04:27:33 -04:00
|
|
|
m_browser = wxWebView::New(this, wxID_ANY, "http://www.wxwidgets.org");
|
2011-05-27 15:47:57 -04:00
|
|
|
topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
|
|
|
|
|
2011-08-14 08:15:34 -04:00
|
|
|
//We register the wxfs:// protocol for testing purposes
|
|
|
|
m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
|
2011-07-28 12:49:48 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
SetSizer(topsizer);
|
|
|
|
|
2011-06-29 12:09:52 -04:00
|
|
|
//Set a more sensible size for web browsing
|
|
|
|
SetSize(wxSize(800, 600));
|
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
// Create a log window
|
|
|
|
new wxLogWindow(this, _("Logging"));
|
|
|
|
|
|
|
|
// Create the Tools menu
|
|
|
|
m_tools_menu = new wxMenu();
|
|
|
|
wxMenuItem* print = m_tools_menu->Append(wxID_ANY , _("Print"));
|
|
|
|
wxMenuItem* viewSource = m_tools_menu->Append(wxID_ANY , _("View Source"));
|
|
|
|
m_tools_menu->AppendSeparator();
|
2011-07-14 08:53:28 -04:00
|
|
|
m_tools_layout = m_tools_menu->AppendCheckItem(wxID_ANY, _("Use Layout Zoom"));
|
2011-05-27 15:47:57 -04:00
|
|
|
m_tools_tiny = m_tools_menu->AppendCheckItem(wxID_ANY, _("Tiny"));
|
|
|
|
m_tools_small = m_tools_menu->AppendCheckItem(wxID_ANY, _("Small"));
|
|
|
|
m_tools_medium = m_tools_menu->AppendCheckItem(wxID_ANY, _("Medium"));
|
|
|
|
m_tools_large = m_tools_menu->AppendCheckItem(wxID_ANY, _("Large"));
|
|
|
|
m_tools_largest = m_tools_menu->AppendCheckItem(wxID_ANY, _("Largest"));
|
2011-06-29 08:03:36 -04:00
|
|
|
m_tools_menu->AppendSeparator();
|
|
|
|
m_tools_handle_navigation = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle Navigation"));
|
|
|
|
m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows"));
|
2011-06-30 06:03:25 -04:00
|
|
|
m_tools_menu->AppendSeparator();
|
2011-08-13 10:11:32 -04:00
|
|
|
|
|
|
|
//History menu
|
|
|
|
m_tools_history_menu = new wxMenu();
|
|
|
|
wxMenuItem* clearhist = m_tools_history_menu->Append(wxID_ANY, _("Clear History"));
|
|
|
|
m_tools_enable_history = m_tools_history_menu->AppendCheckItem(wxID_ANY, _("Enable History"));
|
|
|
|
m_tools_history_menu->AppendSeparator();
|
|
|
|
|
2011-08-13 10:53:46 -04:00
|
|
|
m_tools_menu->AppendSubMenu(m_tools_history_menu, "History");
|
2011-06-29 08:03:36 -04:00
|
|
|
|
2011-07-02 07:45:19 -04:00
|
|
|
//Create an editing menu
|
|
|
|
wxMenu* editmenu = new wxMenu();
|
|
|
|
m_edit_cut = editmenu->Append(wxID_ANY, _("Cut"));
|
|
|
|
m_edit_copy = editmenu->Append(wxID_ANY, _("Copy"));
|
|
|
|
m_edit_paste = editmenu->Append(wxID_ANY, _("Paste"));
|
2011-07-02 11:07:46 -04:00
|
|
|
editmenu->AppendSeparator();
|
|
|
|
m_edit_undo = editmenu->Append(wxID_ANY, _("Undo"));
|
|
|
|
m_edit_redo = editmenu->Append(wxID_ANY, _("Redo"));
|
2011-07-08 15:34:56 -04:00
|
|
|
editmenu->AppendSeparator();
|
|
|
|
m_edit_mode = editmenu->AppendCheckItem(wxID_ANY, _("Edit Mode"));
|
2011-07-02 07:45:19 -04:00
|
|
|
|
|
|
|
m_tools_menu->AppendSeparator();
|
|
|
|
m_tools_menu->AppendSubMenu(editmenu, "Edit");
|
|
|
|
|
2011-08-13 10:53:46 -04:00
|
|
|
wxMenuItem* script = m_tools_menu->Append(wxID_ANY, _("Run Script"));
|
|
|
|
|
2011-08-13 11:45:39 -04:00
|
|
|
//Selection menu
|
|
|
|
wxMenu* selection = new wxMenu();
|
|
|
|
m_selection_clear = selection->Append(wxID_ANY, _("Clear Selection"));
|
|
|
|
m_selection_delete = selection->Append(wxID_ANY, _("Delete Selection"));
|
|
|
|
wxMenuItem* selectall = selection->Append(wxID_ANY, _("Select All"));
|
|
|
|
|
|
|
|
editmenu->AppendSubMenu(selection, "Selection");
|
|
|
|
|
2011-08-15 09:10:34 -04:00
|
|
|
wxMenuItem* loadscheme = m_tools_menu->Append(wxID_ANY, _("Custom Scheme Example"));
|
|
|
|
|
2011-06-29 12:04:42 -04:00
|
|
|
//By default we want to handle navigation and new windows
|
2011-06-29 08:03:36 -04:00
|
|
|
m_tools_handle_navigation->Check();
|
|
|
|
m_tools_handle_new_window->Check();
|
2011-06-30 06:03:25 -04:00
|
|
|
m_tools_enable_history->Check();
|
2011-07-14 08:53:28 -04:00
|
|
|
if(!m_browser->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT))
|
|
|
|
m_tools_layout->Enable(false);
|
2011-05-27 15:47:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
// Connect the toolbar events
|
|
|
|
Connect(m_toolbar_back->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnBack), NULL, this );
|
|
|
|
Connect(m_toolbar_forward->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnForward), NULL, this );
|
|
|
|
Connect(m_toolbar_stop->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnStop), NULL, this );
|
|
|
|
Connect(m_toolbar_reload->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnReload),NULL, this );
|
|
|
|
Connect(m_toolbar_tools->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnToolsClicked), NULL, this );
|
|
|
|
|
2011-08-22 07:27:44 -04:00
|
|
|
Connect(m_url->GetId(), wxEVT_COMMAND_TEXT_ENTER,
|
2011-05-27 15:47:57 -04:00
|
|
|
wxCommandEventHandler(WebFrame::OnUrl), NULL, this );
|
|
|
|
|
|
|
|
// Connect the webview events
|
|
|
|
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING,
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(WebFrame::OnNavigationRequest), NULL, this);
|
2011-05-27 15:47:57 -04:00
|
|
|
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(WebFrame::OnNavigationComplete), NULL, this);
|
2011-05-27 15:47:57 -04:00
|
|
|
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED,
|
2011-08-22 07:27:44 -04:00
|
|
|
wxWebViewEventHandler(WebFrame::OnDocumentLoaded), NULL, this);
|
2011-05-27 15:47:57 -04:00
|
|
|
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR,
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(WebFrame::OnError), NULL, this);
|
2011-05-27 15:47:57 -04:00
|
|
|
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(WebFrame::OnNewWindow), NULL, this);
|
2011-07-30 07:26:55 -04:00
|
|
|
Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED,
|
2011-08-15 07:03:26 -04:00
|
|
|
wxWebViewEventHandler(WebFrame::OnTitleChanged), NULL, this);
|
2011-05-27 15:47:57 -04:00
|
|
|
|
|
|
|
// Connect the menu events
|
|
|
|
Connect(viewSource->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnViewSourceRequest), NULL, this );
|
|
|
|
Connect(print->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnPrint), NULL, this );
|
2011-07-14 08:53:28 -04:00
|
|
|
Connect(m_tools_layout->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnZoomLayout), NULL, this );
|
2011-05-27 15:47:57 -04:00
|
|
|
Connect(m_tools_tiny->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
|
|
|
|
Connect(m_tools_small->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
|
|
|
|
Connect(m_tools_medium->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
|
|
|
|
Connect(m_tools_large->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
|
|
|
|
Connect(m_tools_largest->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
|
2011-06-30 06:03:25 -04:00
|
|
|
Connect(clearhist->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this );
|
|
|
|
Connect(m_tools_enable_history->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnEnableHistory), NULL, this );
|
2011-07-02 07:45:19 -04:00
|
|
|
Connect(m_edit_cut->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnCut), NULL, this );
|
|
|
|
Connect(m_edit_copy->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnCopy), NULL, this );
|
|
|
|
Connect(m_edit_paste->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnPaste), NULL, this );
|
2011-07-02 11:07:46 -04:00
|
|
|
Connect(m_edit_undo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnUndo), NULL, this );
|
|
|
|
Connect(m_edit_redo->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnRedo), NULL, this );
|
2011-07-08 15:34:56 -04:00
|
|
|
Connect(m_edit_mode->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnMode), NULL, this );
|
2011-08-13 10:53:46 -04:00
|
|
|
Connect(script->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnRunScript), NULL, this );
|
2011-08-13 11:45:39 -04:00
|
|
|
Connect(m_selection_clear->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnClearSelection), NULL, this );
|
|
|
|
Connect(m_selection_delete->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnDeleteSelection), NULL, this );
|
|
|
|
Connect(selectall->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnSelectAll), NULL, this );
|
2011-08-15 09:10:34 -04:00
|
|
|
Connect(loadscheme->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnLoadScheme), NULL, this );
|
2011-11-12 15:49:40 -05:00
|
|
|
|
|
|
|
//Connect the idle events
|
|
|
|
Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(WebFrame::OnIdle), NULL, this);
|
2011-05-27 15:47:57 -04:00
|
|
|
}
|
|
|
|
|
2011-09-28 15:44:35 -04:00
|
|
|
WebFrame::~WebFrame()
|
|
|
|
{
|
|
|
|
delete m_tools_menu;
|
|
|
|
}
|
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
/**
|
|
|
|
* Method that retrieves the current state from the web control and updates the GUI
|
|
|
|
* the reflect this current state.
|
|
|
|
*/
|
|
|
|
void WebFrame::UpdateState()
|
|
|
|
{
|
|
|
|
m_toolbar->EnableTool( m_toolbar_back->GetId(), m_browser->CanGoBack() );
|
|
|
|
m_toolbar->EnableTool( m_toolbar_forward->GetId(), m_browser->CanGoForward() );
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
if (m_browser->IsBusy())
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-08-22 07:27:44 -04:00
|
|
|
m_toolbar->EnableTool( m_toolbar_stop->GetId(), true );
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
else
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-08-22 07:27:44 -04:00
|
|
|
m_toolbar->EnableTool( m_toolbar_stop->GetId(), false );
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
SetTitle( m_browser->GetCurrentTitle() );
|
|
|
|
m_url->SetValue( m_browser->GetCurrentURL() );
|
|
|
|
}
|
|
|
|
|
2011-11-13 07:57:28 -05:00
|
|
|
void WebFrame::OnIdle(wxIdleEvent& WXUNUSED(evt))
|
2011-11-12 15:49:40 -05:00
|
|
|
{
|
|
|
|
if(m_browser->IsBusy())
|
|
|
|
{
|
|
|
|
wxSetCursor(wxCURSOR_ARROWWAIT);
|
|
|
|
m_toolbar->EnableTool(m_toolbar_stop->GetId(), true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxSetCursor(wxNullCursor);
|
|
|
|
m_toolbar->EnableTool(m_toolbar_stop->GetId(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
/**
|
|
|
|
* Callback invoked when user entered an URL and pressed enter
|
|
|
|
*/
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnUrl(wxCommandEvent& WXUNUSED(evt))
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
2011-08-17 06:55:59 -04:00
|
|
|
m_browser->LoadURL( m_url->GetValue() );
|
2011-11-13 07:57:28 -05:00
|
|
|
m_browser->SetFocus();
|
2011-05-27 15:47:57 -04:00
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when user pressed the "back" button
|
|
|
|
*/
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnBack(wxCommandEvent& WXUNUSED(evt))
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
|
|
|
m_browser->GoBack();
|
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when user pressed the "forward" button
|
|
|
|
*/
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnForward(wxCommandEvent& WXUNUSED(evt))
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
|
|
|
m_browser->GoForward();
|
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when user pressed the "stop" button
|
|
|
|
*/
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnStop(wxCommandEvent& WXUNUSED(evt))
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
|
|
|
m_browser->Stop();
|
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when user pressed the "reload" button
|
|
|
|
*/
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnReload(wxCommandEvent& WXUNUSED(evt))
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
|
|
|
m_browser->Reload();
|
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnClearHistory(wxCommandEvent& WXUNUSED(evt))
|
2011-06-30 06:03:25 -04:00
|
|
|
{
|
|
|
|
m_browser->ClearHistory();
|
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnEnableHistory(wxCommandEvent& WXUNUSED(evt))
|
2011-06-30 06:03:25 -04:00
|
|
|
{
|
|
|
|
m_browser->EnableHistory(m_tools_enable_history->IsChecked());
|
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnCut(wxCommandEvent& WXUNUSED(evt))
|
2011-07-02 07:45:19 -04:00
|
|
|
{
|
|
|
|
m_browser->Cut();
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnCopy(wxCommandEvent& WXUNUSED(evt))
|
2011-07-02 07:45:19 -04:00
|
|
|
{
|
|
|
|
m_browser->Copy();
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnPaste(wxCommandEvent& WXUNUSED(evt))
|
2011-07-02 07:45:19 -04:00
|
|
|
{
|
|
|
|
m_browser->Paste();
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnUndo(wxCommandEvent& WXUNUSED(evt))
|
2011-07-02 11:07:46 -04:00
|
|
|
{
|
|
|
|
m_browser->Undo();
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnRedo(wxCommandEvent& WXUNUSED(evt))
|
2011-07-02 11:07:46 -04:00
|
|
|
{
|
|
|
|
m_browser->Redo();
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnMode(wxCommandEvent& WXUNUSED(evt))
|
2011-07-08 15:34:56 -04:00
|
|
|
{
|
|
|
|
m_browser->SetEditable(m_edit_mode->IsChecked());
|
|
|
|
}
|
|
|
|
|
2011-08-15 09:10:34 -04:00
|
|
|
void WebFrame::OnLoadScheme(wxCommandEvent& WXUNUSED(evt))
|
|
|
|
{
|
|
|
|
wxFileName helpfile("../help/doc.zip");
|
|
|
|
helpfile.MakeAbsolute();
|
|
|
|
wxString path = helpfile.GetFullPath();
|
|
|
|
//Under MSW we need to flip the slashes
|
|
|
|
path.Replace("\\", "/");
|
|
|
|
path = "wxfs:///" + path + ";protocol=zip/doc.htm";
|
2011-08-17 06:55:59 -04:00
|
|
|
m_browser->LoadURL(path);
|
2011-08-15 09:10:34 -04:00
|
|
|
}
|
2011-07-08 15:34:56 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
/**
|
|
|
|
* Callback invoked when there is a request to load a new page (for instance
|
|
|
|
* when the user clicks a link)
|
|
|
|
*/
|
2011-08-15 07:03:26 -04:00
|
|
|
void WebFrame::OnNavigationRequest(wxWebViewEvent& evt)
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
2011-08-01 10:05:32 -04:00
|
|
|
if(m_info->IsShown())
|
|
|
|
{
|
2011-08-13 06:07:03 -04:00
|
|
|
m_info->Dismiss();
|
2011-08-01 10:05:32 -04:00
|
|
|
}
|
|
|
|
|
2011-07-25 10:30:07 -04:00
|
|
|
wxLogMessage("%s", "Navigation request to '" + evt.GetURL() + "' (target='" +
|
2011-05-27 15:47:57 -04:00
|
|
|
evt.GetTarget() + "')");
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
wxASSERT(m_browser->IsBusy());
|
2011-06-29 08:03:36 -04:00
|
|
|
|
|
|
|
//If we don't want to handle navigation then veto the event and navigation
|
2011-08-17 09:46:09 -04:00
|
|
|
//will not take place, we also need to stop the loading animation
|
2011-06-29 08:03:36 -04:00
|
|
|
if(!m_tools_handle_navigation->IsChecked())
|
2011-08-17 09:46:09 -04:00
|
|
|
{
|
2011-06-29 08:03:36 -04:00
|
|
|
evt.Veto();
|
2011-08-22 07:27:44 -04:00
|
|
|
m_toolbar->EnableTool( m_toolbar_stop->GetId(), false );
|
2011-08-17 09:46:09 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UpdateState();
|
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when a navigation request was accepted
|
|
|
|
*/
|
2011-08-15 07:03:26 -04:00
|
|
|
void WebFrame::OnNavigationComplete(wxWebViewEvent& evt)
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
2011-07-25 10:30:07 -04:00
|
|
|
wxLogMessage("%s", "Navigation complete; url='" + evt.GetURL() + "'");
|
2011-05-27 15:47:57 -04:00
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when a page is finished loading
|
|
|
|
*/
|
2011-08-15 07:03:26 -04:00
|
|
|
void WebFrame::OnDocumentLoaded(wxWebViewEvent& evt)
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
2011-07-04 14:27:14 -04:00
|
|
|
//Only notify if the document is the main frame, not a subframe
|
2011-07-25 10:30:07 -04:00
|
|
|
if(evt.GetURL() == m_browser->GetCurrentURL())
|
2011-08-01 09:09:10 -04:00
|
|
|
{
|
2011-07-25 10:30:07 -04:00
|
|
|
wxLogMessage("%s", "Document loaded; url='" + evt.GetURL() + "'");
|
2011-08-01 09:09:10 -04:00
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On new window, we veto to stop extra windows appearing
|
|
|
|
*/
|
2011-08-15 07:03:26 -04:00
|
|
|
void WebFrame::OnNewWindow(wxWebViewEvent& evt)
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
2011-07-25 10:30:07 -04:00
|
|
|
wxLogMessage("%s", "New window; url='" + evt.GetURL() + "'");
|
2011-06-29 08:03:36 -04:00
|
|
|
|
2011-08-22 07:27:44 -04:00
|
|
|
//If we handle new window events then just load them in this window as we
|
2011-06-29 08:03:36 -04:00
|
|
|
//are a single window browser
|
|
|
|
if(m_tools_handle_new_window->IsChecked())
|
2011-08-17 06:55:59 -04:00
|
|
|
m_browser->LoadURL(evt.GetURL());
|
2011-06-29 08:03:36 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
UpdateState();
|
|
|
|
}
|
|
|
|
|
2011-08-15 07:03:26 -04:00
|
|
|
void WebFrame::OnTitleChanged(wxWebViewEvent& evt)
|
2011-07-30 07:26:55 -04:00
|
|
|
{
|
2011-10-07 17:25:59 -04:00
|
|
|
SetTitle(evt.GetString());
|
2011-07-30 07:26:55 -04:00
|
|
|
wxLogMessage("%s", "Title changed; title='" + evt.GetString() + "'");
|
|
|
|
}
|
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
/**
|
|
|
|
* Invoked when user selects the "View Source" menu item
|
|
|
|
*/
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnViewSourceRequest(wxCommandEvent& WXUNUSED(evt))
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
|
|
|
SourceViewDialog dlg(this, m_browser->GetPageSource());
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when user selects the "Menu" item
|
|
|
|
*/
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt))
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
|
|
|
if(m_browser->GetCurrentURL() == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_tools_tiny->Check(false);
|
2011-08-22 07:27:44 -04:00
|
|
|
m_tools_small->Check(false);
|
2011-05-27 15:47:57 -04:00
|
|
|
m_tools_medium->Check(false);
|
|
|
|
m_tools_large->Check(false);
|
|
|
|
m_tools_largest->Check(false);
|
|
|
|
|
|
|
|
wxWebViewZoom zoom = m_browser->GetZoom();
|
|
|
|
switch (zoom)
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_VIEW_ZOOM_TINY:
|
|
|
|
m_tools_tiny->Check();
|
|
|
|
break;
|
|
|
|
case wxWEB_VIEW_ZOOM_SMALL:
|
|
|
|
m_tools_small->Check();
|
|
|
|
break;
|
|
|
|
case wxWEB_VIEW_ZOOM_MEDIUM:
|
|
|
|
m_tools_medium->Check();
|
|
|
|
break;
|
|
|
|
case wxWEB_VIEW_ZOOM_LARGE:
|
|
|
|
m_tools_large->Check();
|
|
|
|
break;
|
|
|
|
case wxWEB_VIEW_ZOOM_LARGEST:
|
|
|
|
m_tools_largest->Check();
|
|
|
|
break;
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-07-02 07:45:19 -04:00
|
|
|
|
|
|
|
m_edit_cut->Enable(m_browser->CanCut());
|
|
|
|
m_edit_copy->Enable(m_browser->CanCopy());
|
|
|
|
m_edit_paste->Enable(m_browser->CanPaste());
|
2011-07-02 11:07:46 -04:00
|
|
|
|
|
|
|
m_edit_undo->Enable(m_browser->CanUndo());
|
|
|
|
m_edit_redo->Enable(m_browser->CanRedo());
|
2011-08-13 10:11:32 -04:00
|
|
|
|
2011-08-13 11:45:39 -04:00
|
|
|
m_selection_clear->Enable(m_browser->HasSelection());
|
|
|
|
m_selection_delete->Enable(m_browser->HasSelection());
|
|
|
|
|
2011-08-13 10:11:32 -04:00
|
|
|
//Firstly we clear the existing menu items, then we add the current ones
|
|
|
|
wxMenuHistoryMap::const_iterator it;
|
|
|
|
for( it = m_histMenuItems.begin(); it != m_histMenuItems.end(); ++it )
|
|
|
|
{
|
|
|
|
m_tools_history_menu->Destroy(it->first);
|
|
|
|
}
|
|
|
|
m_histMenuItems.clear();
|
|
|
|
|
2011-08-15 08:31:31 -04:00
|
|
|
wxVector<wxSharedPtr<wxWebViewHistoryItem> > back = m_browser->GetBackwardHistory();
|
|
|
|
wxVector<wxSharedPtr<wxWebViewHistoryItem> > forward = m_browser->GetForwardHistory();
|
2011-08-13 10:11:32 -04:00
|
|
|
|
|
|
|
wxMenuItem* item;
|
|
|
|
|
2011-08-22 07:27:44 -04:00
|
|
|
unsigned int i;
|
|
|
|
for(i = 0; i < back.size(); i++)
|
2011-08-13 10:11:32 -04:00
|
|
|
{
|
|
|
|
item = m_tools_history_menu->AppendRadioItem(wxID_ANY, back[i]->GetTitle());
|
|
|
|
m_histMenuItems[item->GetId()] = back[i];
|
|
|
|
Connect(item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnHistory), NULL, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
item = m_tools_history_menu->AppendRadioItem(wxID_ANY, m_browser->GetCurrentTitle());
|
|
|
|
item->Check();
|
|
|
|
|
|
|
|
//No need to connect the current item
|
2011-08-15 08:31:31 -04:00
|
|
|
m_histMenuItems[item->GetId()] = wxSharedPtr<wxWebViewHistoryItem>(new wxWebViewHistoryItem(m_browser->GetCurrentURL(), m_browser->GetCurrentTitle()));
|
2011-08-13 10:11:32 -04:00
|
|
|
|
2011-08-22 07:27:44 -04:00
|
|
|
for(i = 0; i < forward.size(); i++)
|
2011-08-13 10:11:32 -04:00
|
|
|
{
|
|
|
|
item = m_tools_history_menu->AppendRadioItem(wxID_ANY, forward[i]->GetTitle());
|
|
|
|
m_histMenuItems[item->GetId()] = forward[i];
|
|
|
|
Connect(item->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler(WebFrame::OnHistory), NULL, this );
|
|
|
|
}
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
wxPoint position = ScreenToClient( wxGetMousePosition() );
|
|
|
|
PopupMenu(m_tools_menu, position.x, position.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when user selects the zoom size in the menu
|
|
|
|
*/
|
|
|
|
void WebFrame::OnSetZoom(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
if (evt.GetId() == m_tools_tiny->GetId())
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
m_browser->SetZoom(wxWEB_VIEW_ZOOM_TINY);
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
else if (evt.GetId() == m_tools_small->GetId())
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
m_browser->SetZoom(wxWEB_VIEW_ZOOM_SMALL);
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
else if (evt.GetId() == m_tools_medium->GetId())
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
m_browser->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM);
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
else if (evt.GetId() == m_tools_large->GetId())
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGE);
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
else if (evt.GetId() == m_tools_largest->GetId())
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGEST);
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
else
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
wxFAIL;
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-05-27 15:47:57 -04:00
|
|
|
}
|
2011-05-26 14:43:18 -04:00
|
|
|
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnZoomLayout(wxCommandEvent& WXUNUSED(evt))
|
2011-07-14 08:53:28 -04:00
|
|
|
{
|
|
|
|
if(m_tools_layout->IsChecked())
|
|
|
|
m_browser->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT);
|
|
|
|
else
|
|
|
|
m_browser->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT);
|
|
|
|
}
|
|
|
|
|
2011-08-13 10:11:32 -04:00
|
|
|
void WebFrame::OnHistory(wxCommandEvent& evt)
|
|
|
|
{
|
|
|
|
m_browser->LoadHistoryItem(m_histMenuItems[evt.GetId()]);
|
|
|
|
}
|
|
|
|
|
2011-08-13 10:53:46 -04:00
|
|
|
void WebFrame::OnRunScript(wxCommandEvent& WXUNUSED(evt))
|
|
|
|
{
|
|
|
|
wxTextEntryDialog dialog(this, "Enter JavaScript to run.", wxGetTextFromUserPromptStr, "", wxOK|wxCANCEL|wxCENTRE|wxTE_MULTILINE);
|
|
|
|
if(dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
m_browser->RunScript(dialog.GetValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-13 11:45:39 -04:00
|
|
|
void WebFrame::OnClearSelection(wxCommandEvent& WXUNUSED(evt))
|
|
|
|
{
|
|
|
|
m_browser->ClearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebFrame::OnDeleteSelection(wxCommandEvent& WXUNUSED(evt))
|
|
|
|
{
|
|
|
|
m_browser->DeleteSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebFrame::OnSelectAll(wxCommandEvent& WXUNUSED(evt))
|
|
|
|
{
|
|
|
|
m_browser->SelectAll();
|
|
|
|
}
|
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
/**
|
|
|
|
* Callback invoked when a loading error occurs
|
|
|
|
*/
|
2011-08-15 07:03:26 -04:00
|
|
|
void WebFrame::OnError(wxWebViewEvent& evt)
|
2011-05-27 15:47:57 -04:00
|
|
|
{
|
|
|
|
wxString errorCategory;
|
|
|
|
switch (evt.GetInt())
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_NAV_ERR_CONNECTION:
|
|
|
|
errorCategory = "wxWEB_NAV_ERR_CONNECTION";
|
|
|
|
break;
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_NAV_ERR_CERTIFICATE:
|
|
|
|
errorCategory = "wxWEB_NAV_ERR_CERTIFICATE";
|
|
|
|
break;
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_NAV_ERR_AUTH:
|
|
|
|
errorCategory = "wxWEB_NAV_ERR_AUTH";
|
|
|
|
break;
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_NAV_ERR_SECURITY:
|
|
|
|
errorCategory = "wxWEB_NAV_ERR_SECURITY";
|
|
|
|
break;
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_NAV_ERR_NOT_FOUND:
|
|
|
|
errorCategory = "wxWEB_NAV_ERR_NOT_FOUND";
|
|
|
|
break;
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_NAV_ERR_REQUEST:
|
|
|
|
errorCategory = "wxWEB_NAV_ERR_REQUEST";
|
|
|
|
break;
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_NAV_ERR_USER_CANCELLED:
|
|
|
|
errorCategory = "wxWEB_NAV_ERR_USER_CANCELLED";
|
|
|
|
break;
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
case wxWEB_NAV_ERR_OTHER:
|
|
|
|
errorCategory = "wxWEB_NAV_ERR_OTHER";
|
|
|
|
break;
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-11-08 08:23:45 -05:00
|
|
|
wxLogMessage("%s", "Error; url='" + evt.GetURL() + "', error='" + errorCategory + "' (" + evt.GetString() + ")");
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
//Show the info bar with an error
|
2011-07-25 10:30:07 -04:00
|
|
|
m_info->ShowMessage(_("An error occurred loading ") + evt.GetURL() + "\n" +
|
2011-05-27 15:47:57 -04:00
|
|
|
"'" + errorCategory + "' (" + evt.GetString() + ")", wxICON_ERROR);
|
2011-08-22 07:27:44 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
UpdateState();
|
|
|
|
}
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
/**
|
|
|
|
* Invoked when user selects "Print" from the menu
|
|
|
|
*/
|
2011-08-01 09:09:10 -04:00
|
|
|
void WebFrame::OnPrint(wxCommandEvent& WXUNUSED(evt))
|
2011-05-04 14:24:30 -04:00
|
|
|
{
|
2011-05-27 15:47:57 -04:00
|
|
|
m_browser->Print();
|
|
|
|
}
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
SourceViewDialog::SourceViewDialog(wxWindow* parent, wxString source) :
|
|
|
|
wxDialog(parent, wxID_ANY, "Source Code",
|
|
|
|
wxDefaultPosition, wxSize(700,500),
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
|
|
|
{
|
|
|
|
wxStyledTextCtrl* text = new wxStyledTextCtrl(this, wxID_ANY);
|
|
|
|
text->SetMarginWidth(1, 30);
|
2011-08-22 07:27:44 -04:00
|
|
|
text->SetMarginType(1, wxSTC_MARGIN_NUMBER);
|
2011-05-27 15:47:57 -04:00
|
|
|
text->SetText(source);
|
2011-05-04 14:24:30 -04:00
|
|
|
|
2011-05-27 15:47:57 -04:00
|
|
|
text->StyleClearAll();
|
|
|
|
text->SetLexer(wxSTC_LEX_HTML);
|
|
|
|
text->StyleSetForeground(wxSTC_H_DOUBLESTRING, wxColour(255,0,0));
|
|
|
|
text->StyleSetForeground(wxSTC_H_SINGLESTRING, wxColour(255,0,0));
|
|
|
|
text->StyleSetForeground(wxSTC_H_ENTITY, wxColour(255,0,0));
|
|
|
|
text->StyleSetForeground(wxSTC_H_TAG, wxColour(0,150,0));
|
|
|
|
text->StyleSetForeground(wxSTC_H_TAGUNKNOWN, wxColour(0,150,0));
|
|
|
|
text->StyleSetForeground(wxSTC_H_ATTRIBUTE, wxColour(0,0,150));
|
|
|
|
text->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, wxColour(0,0,150));
|
|
|
|
text->StyleSetForeground(wxSTC_H_COMMENT, wxColour(150,150,150));
|
2011-05-04 14:24:30 -04:00
|
|
|
|
|
|
|
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
|
2011-05-27 15:47:57 -04:00
|
|
|
sizer->Add(text, 1, wxEXPAND);
|
|
|
|
SetSizer(sizer);
|
2011-05-04 14:24:30 -04:00
|
|
|
}
|