1999-07-07 18:04:58 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: test.cpp
|
|
|
|
// Purpose: wxHtml testing example
|
2004-02-18 19:24:06 -05:00
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 1999-07-07
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Vaclav Slavik
|
|
|
|
// Licence: wxWindows licence
|
1999-07-07 18:04:58 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
2001-10-30 08:33:34 -05:00
|
|
|
#include "wx/wxprec.h"
|
1999-07-07 18:04:58 -04:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2004-02-18 19:24:06 -05:00
|
|
|
// For all others, include the necessary headers (this file is usually all you
|
2004-05-25 07:20:37 -04:00
|
|
|
// need because it includes almost all "standard" wxWidgets headers
|
1999-07-07 18:04:58 -04:00
|
|
|
#ifndef WX_PRECOMP
|
2002-01-13 12:41:56 -05:00
|
|
|
#include "wx/wx.h"
|
1999-07-07 18:04:58 -04:00
|
|
|
#endif
|
|
|
|
|
2001-08-11 20:11:45 -04:00
|
|
|
#include "wx/image.h"
|
2001-11-22 07:58:44 -05:00
|
|
|
#include "wx/sysopt.h"
|
2001-08-11 20:11:45 -04:00
|
|
|
#include "wx/html/htmlwin.h"
|
|
|
|
#include "wx/html/htmlproc.h"
|
|
|
|
#include "wx/fs_inet.h"
|
|
|
|
#include "wx/filedlg.h"
|
2005-09-05 14:07:00 -04:00
|
|
|
#include "wx/utils.h"
|
2006-10-30 11:18:45 -05:00
|
|
|
#include "wx/clipbrd.h"
|
|
|
|
#include "wx/dataobj.h"
|
2009-03-23 09:00:42 -04:00
|
|
|
#include "wx/stopwatch.h"
|
1999-07-07 18:04:58 -04:00
|
|
|
|
2005-03-18 04:44:42 -05:00
|
|
|
#include "../../sample.xpm"
|
|
|
|
|
1999-07-07 18:04:58 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
2001-05-08 18:26:39 -04:00
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
2004-02-18 19:24:06 -05:00
|
|
|
virtual bool OnInit();
|
2001-05-08 18:26:39 -04:00
|
|
|
};
|
1999-07-07 18:04:58 -04:00
|
|
|
|
2004-12-16 15:32:43 -05:00
|
|
|
// Define a new html window type: this is a wrapper for handling wxHtmlWindow events
|
|
|
|
class MyHtmlWindow : public wxHtmlWindow
|
|
|
|
{
|
|
|
|
public:
|
2009-06-18 13:32:20 -04:00
|
|
|
MyHtmlWindow(wxWindow *parent) : wxHtmlWindow( parent )
|
|
|
|
{
|
|
|
|
// no custom background initially to avoid confusing people
|
|
|
|
m_drawCustomBg = false;
|
|
|
|
}
|
2004-12-16 15:32:43 -05:00
|
|
|
|
|
|
|
virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType WXUNUSED(type),
|
|
|
|
const wxString& WXUNUSED(url),
|
|
|
|
wxString *WXUNUSED(redirect)) const;
|
|
|
|
|
2009-06-18 13:32:20 -04:00
|
|
|
// toggle drawing of custom background
|
|
|
|
void DrawCustomBg(bool draw)
|
|
|
|
{
|
|
|
|
m_drawCustomBg = draw;
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2004-12-16 15:32:43 -05:00
|
|
|
private:
|
2009-06-18 13:32:20 -04:00
|
|
|
#if wxUSE_CLIPBOARD
|
2006-10-30 11:18:45 -05:00
|
|
|
void OnClipboardEvent(wxClipboardTextEvent& event);
|
2009-06-18 13:32:20 -04:00
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
void OnEraseBgEvent(wxEraseEvent& event);
|
|
|
|
|
|
|
|
bool m_drawCustomBg;
|
2006-10-30 11:18:45 -05:00
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(MyHtmlWindow);
|
2004-12-16 15:32:43 -05:00
|
|
|
};
|
|
|
|
|
1999-07-07 18:04:58 -04:00
|
|
|
// Define a new frame type: this is going to be our main frame
|
2001-05-08 18:26:39 -04:00
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
2004-02-18 19:24:06 -05:00
|
|
|
// ctor(s)
|
2001-05-08 18:26:39 -04:00
|
|
|
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
|
|
|
|
2004-02-18 19:24:06 -05:00
|
|
|
// event handlers (these functions should _not_ be virtual)
|
2001-05-08 18:26:39 -04:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnPageOpen(wxCommandEvent& event);
|
2006-10-30 06:46:44 -05:00
|
|
|
void OnDefaultLocalBrowser(wxCommandEvent& event);
|
|
|
|
void OnDefaultWebBrowser(wxCommandEvent& event);
|
2001-05-08 18:26:39 -04:00
|
|
|
void OnBack(wxCommandEvent& event);
|
|
|
|
void OnForward(wxCommandEvent& event);
|
|
|
|
void OnProcessor(wxCommandEvent& event);
|
2009-06-18 13:32:20 -04:00
|
|
|
void OnDrawCustomBg(wxCommandEvent& event);
|
2001-05-08 18:26:39 -04:00
|
|
|
|
2006-10-29 15:26:03 -05:00
|
|
|
void OnHtmlLinkClicked(wxHtmlLinkEvent& event);
|
|
|
|
void OnHtmlCellHover(wxHtmlCellEvent &event);
|
|
|
|
void OnHtmlCellClicked(wxHtmlCellEvent &event);
|
|
|
|
|
2001-05-08 18:26:39 -04:00
|
|
|
private:
|
2004-12-16 15:32:43 -05:00
|
|
|
MyHtmlWindow *m_Html;
|
2004-02-18 19:24:06 -05:00
|
|
|
wxHtmlProcessor *m_Processor;
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// Any class wishing to process wxWidgets events must use this macro
|
2004-02-18 19:24:06 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
2001-05-08 18:26:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BoldProcessor : public wxHtmlProcessor
|
|
|
|
{
|
2004-02-18 19:24:06 -05:00
|
|
|
public:
|
|
|
|
virtual wxString Process(const wxString& s) const
|
|
|
|
{
|
|
|
|
wxString r(s);
|
|
|
|
r.Replace(wxT("<b>"), wxEmptyString);
|
|
|
|
r.Replace(wxT("<B>"), wxEmptyString);
|
|
|
|
r.Replace(wxT("</b>"), wxEmptyString);
|
|
|
|
r.Replace(wxT("</B>"), wxEmptyString);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2001-05-08 18:26:39 -04:00
|
|
|
};
|
1999-07-07 18:04:58 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
2004-02-18 19:24:06 -05:00
|
|
|
enum
|
|
|
|
{
|
1999-07-07 18:04:58 -04:00
|
|
|
// menu items
|
2004-02-18 19:24:06 -05:00
|
|
|
ID_PageOpen = wxID_HIGHEST,
|
2006-10-30 06:46:44 -05:00
|
|
|
ID_DefaultLocalBrowser,
|
|
|
|
ID_DefaultWebBrowser,
|
2004-02-18 19:24:06 -05:00
|
|
|
ID_Back,
|
|
|
|
ID_Forward,
|
2009-06-18 13:32:20 -04:00
|
|
|
ID_Processor,
|
|
|
|
ID_DrawCustomBg
|
2004-02-18 19:24:06 -05:00
|
|
|
};
|
1999-07-07 18:04:58 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-05-25 07:20:37 -04:00
|
|
|
// event tables and other macros for wxWidgets
|
1999-07-07 18:04:58 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-02-18 19:24:06 -05:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
|
|
|
EVT_MENU(ID_PageOpen, MyFrame::OnPageOpen)
|
2006-10-30 06:46:44 -05:00
|
|
|
EVT_MENU(ID_DefaultLocalBrowser, MyFrame::OnDefaultLocalBrowser)
|
|
|
|
EVT_MENU(ID_DefaultWebBrowser, MyFrame::OnDefaultWebBrowser)
|
2004-02-18 19:24:06 -05:00
|
|
|
EVT_MENU(ID_Back, MyFrame::OnBack)
|
|
|
|
EVT_MENU(ID_Forward, MyFrame::OnForward)
|
|
|
|
EVT_MENU(ID_Processor, MyFrame::OnProcessor)
|
2009-06-18 13:32:20 -04:00
|
|
|
EVT_MENU(ID_DrawCustomBg, MyFrame::OnDrawCustomBg)
|
2006-10-29 15:26:03 -05:00
|
|
|
|
|
|
|
EVT_HTML_LINK_CLICKED(wxID_ANY, MyFrame::OnHtmlLinkClicked)
|
|
|
|
EVT_HTML_CELL_HOVER(wxID_ANY, MyFrame::OnHtmlCellHover)
|
|
|
|
EVT_HTML_CELL_CLICKED(wxID_ANY, MyFrame::OnHtmlCellClicked)
|
2004-02-18 19:24:06 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// `Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2001-11-27 13:13:31 -05:00
|
|
|
#if wxUSE_SYSTEM_OPTIONS
|
2004-02-18 19:24:06 -05:00
|
|
|
wxSystemOptions::SetOption(wxT("no-maskblt"), 1);
|
2001-11-27 13:13:31 -05:00
|
|
|
#endif
|
2001-11-22 07:58:44 -05:00
|
|
|
|
2004-02-18 19:24:06 -05:00
|
|
|
wxInitAllImageHandlers();
|
2001-11-27 13:13:31 -05:00
|
|
|
#if wxUSE_FS_INET && wxUSE_STREAMS && wxUSE_SOCKETS
|
2004-02-18 19:24:06 -05:00
|
|
|
wxFileSystem::AddHandler(new wxInternetFSHandler);
|
2001-11-27 13:13:31 -05:00
|
|
|
#endif
|
2000-01-17 12:18:53 -05:00
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
SetVendorName(wxT("wxWidgets"));
|
2004-02-18 19:24:06 -05:00
|
|
|
SetAppName(wxT("wxHtmlTest"));
|
|
|
|
// the following call to wxConfig::Get will use it to create an object...
|
2000-01-17 12:18:53 -05:00
|
|
|
|
1999-07-07 18:04:58 -04:00
|
|
|
// Create the main application window
|
2004-02-18 19:24:06 -05:00
|
|
|
MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"),
|
|
|
|
wxDefaultPosition, wxSize(640, 480));
|
|
|
|
|
|
|
|
frame->Show();
|
|
|
|
|
|
|
|
return true /* continue running */;
|
|
|
|
}
|
1999-07-07 18:04:58 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// frame constructor
|
2004-02-18 19:24:06 -05:00
|
|
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|
|
|
: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size,
|
|
|
|
wxDEFAULT_FRAME_STYLE, wxT("html_test_app"))
|
|
|
|
{
|
1999-07-07 18:04:58 -04:00
|
|
|
// create a menu bar
|
2004-02-18 19:24:06 -05:00
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
wxMenu *menuNav = new wxMenu;
|
|
|
|
|
2009-03-23 09:00:42 -04:00
|
|
|
menuFile->Append(ID_PageOpen, _("&Open HTML page...\tCtrl-O"));
|
2006-10-30 06:46:44 -05:00
|
|
|
menuFile->Append(ID_DefaultLocalBrowser, _("&Open current page with default browser"));
|
|
|
|
menuFile->Append(ID_DefaultWebBrowser, _("Open a &web page with default browser"));
|
2004-02-18 19:24:06 -05:00
|
|
|
menuFile->AppendSeparator();
|
|
|
|
menuFile->Append(ID_Processor, _("&Remove bold attribute"),
|
|
|
|
wxEmptyString, wxITEM_CHECK);
|
2009-06-18 13:32:20 -04:00
|
|
|
menuFile->AppendSeparator();
|
|
|
|
menuFile->AppendCheckItem(ID_DrawCustomBg, "&Draw custom background");
|
2004-02-18 19:24:06 -05:00
|
|
|
menuFile->AppendSeparator();
|
|
|
|
menuFile->Append(wxID_EXIT, _("&Close frame"));
|
|
|
|
menuNav->Append(ID_Back, _("Go &BACK"));
|
|
|
|
menuNav->Append(ID_Forward, _("Go &FORWARD"));
|
1999-07-07 18:04:58 -04:00
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
2004-02-18 19:24:06 -05:00
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
menuBar->Append(menuFile, _("&File"));
|
|
|
|
menuBar->Append(menuNav, _("&Navigate"));
|
1999-07-07 18:04:58 -04:00
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
2004-02-18 19:24:06 -05:00
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
2005-03-18 04:44:42 -05:00
|
|
|
SetIcon(wxIcon(sample_xpm));
|
2005-03-30 14:10:46 -05:00
|
|
|
|
2004-02-18 19:24:06 -05:00
|
|
|
#if wxUSE_ACCEL
|
|
|
|
// Create convenient accelerators for Back and Forward navigation
|
|
|
|
wxAcceleratorEntry entries[2];
|
|
|
|
entries[0].Set(wxACCEL_ALT, WXK_LEFT, ID_Back);
|
|
|
|
entries[1].Set(wxACCEL_ALT, WXK_RIGHT, ID_Forward);
|
|
|
|
|
|
|
|
wxAcceleratorTable accel(WXSIZEOF(entries), entries);
|
|
|
|
SetAcceleratorTable(accel);
|
|
|
|
#endif // wxUSE_ACCEL
|
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2004-12-16 15:32:43 -05:00
|
|
|
CreateStatusBar(2);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2004-02-18 19:24:06 -05:00
|
|
|
|
|
|
|
m_Processor = new BoldProcessor;
|
|
|
|
m_Processor->Enable(false);
|
2004-12-16 15:32:43 -05:00
|
|
|
m_Html = new MyHtmlWindow(this);
|
2004-02-18 19:24:06 -05:00
|
|
|
m_Html->SetRelatedFrame(this, _("HTML : %s"));
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2009-03-23 09:00:42 -04:00
|
|
|
m_Html->SetRelatedStatusBar(1);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2004-02-18 19:24:06 -05:00
|
|
|
m_Html->ReadCustomization(wxConfig::Get());
|
|
|
|
m_Html->LoadFile(wxFileName(wxT("test.htm")));
|
|
|
|
m_Html->AddProcessor(m_Processor);
|
2006-10-29 15:26:03 -05:00
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY, wxT(""),
|
2006-10-29 15:26:03 -05:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE);
|
|
|
|
|
|
|
|
delete wxLog::SetActiveTarget(new wxLogTextCtrl(text));
|
|
|
|
|
|
|
|
wxSizer *sz = new wxBoxSizer(wxVERTICAL);
|
|
|
|
sz->Add(m_Html, 3, wxGROW);
|
|
|
|
sz->Add(text, 1, wxGROW);
|
|
|
|
SetSizer(sz);
|
2004-02-18 19:24:06 -05:00
|
|
|
}
|
1999-07-07 18:04:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
|
2001-05-08 18:26:39 -04:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-02-18 19:24:06 -05:00
|
|
|
m_Html->WriteCustomization(wxConfig::Get());
|
|
|
|
delete wxConfig::Set(NULL);
|
|
|
|
|
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
2001-05-08 18:26:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnPageOpen(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-08-24 13:47:11 -04:00
|
|
|
#if wxUSE_FILEDLG
|
2004-02-18 19:24:06 -05:00
|
|
|
wxString p = wxFileSelector(_("Open HTML document"), wxEmptyString,
|
2005-12-26 18:29:17 -05:00
|
|
|
wxEmptyString, wxEmptyString, wxT("HTML files|*.htm;*.html"));
|
2004-02-18 19:24:06 -05:00
|
|
|
|
2005-08-24 13:47:11 -04:00
|
|
|
if (!p.empty())
|
2009-03-23 09:00:42 -04:00
|
|
|
{
|
|
|
|
#if wxUSE_STOPWATCH
|
|
|
|
wxStopWatch sw;
|
|
|
|
#endif
|
2005-12-18 07:24:25 -05:00
|
|
|
m_Html->LoadFile(wxFileName(p));
|
2009-03-23 09:00:42 -04:00
|
|
|
#if wxUSE_STOPWATCH
|
|
|
|
wxLogStatus("Loaded \"%s\" in %lums", p, sw.Time());
|
|
|
|
#endif
|
|
|
|
}
|
2005-08-24 13:47:11 -04:00
|
|
|
#endif // wxUSE_FILEDLG
|
2001-05-08 18:26:39 -04:00
|
|
|
}
|
|
|
|
|
2006-10-30 06:46:44 -05:00
|
|
|
void MyFrame::OnDefaultLocalBrowser(wxCommandEvent& WXUNUSED(event))
|
2005-09-05 14:07:00 -04:00
|
|
|
{
|
|
|
|
wxString page = m_Html->GetOpenedPage();
|
|
|
|
if (!page.empty())
|
|
|
|
{
|
|
|
|
wxLaunchDefaultBrowser(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-30 06:46:44 -05:00
|
|
|
void MyFrame::OnDefaultWebBrowser(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxString page = m_Html->GetOpenedPage();
|
|
|
|
if (!page.empty())
|
|
|
|
{
|
|
|
|
wxLaunchDefaultBrowser(wxT("http://www.google.com"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-08 18:26:39 -04:00
|
|
|
void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-02-18 19:24:06 -05:00
|
|
|
if (!m_Html->HistoryBack())
|
|
|
|
{
|
|
|
|
wxMessageBox(_("You reached prehistory era!"));
|
|
|
|
}
|
2001-05-08 18:26:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-02-18 19:24:06 -05:00
|
|
|
if (!m_Html->HistoryForward())
|
|
|
|
{
|
|
|
|
wxMessageBox(_("No more items in history!"));
|
|
|
|
}
|
2001-05-08 18:26:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnProcessor(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_Processor->Enable(!m_Processor->IsEnabled());
|
|
|
|
m_Html->LoadPage(m_Html->GetOpenedPage());
|
|
|
|
}
|
2004-12-16 15:32:43 -05:00
|
|
|
|
2009-06-18 13:32:20 -04:00
|
|
|
void MyFrame::OnDrawCustomBg(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
m_Html->DrawCustomBg(event.IsChecked());
|
|
|
|
}
|
|
|
|
|
2006-10-29 15:26:03 -05:00
|
|
|
void MyFrame::OnHtmlLinkClicked(wxHtmlLinkEvent &event)
|
|
|
|
{
|
|
|
|
wxLogMessage(wxT("The url '%s' has been clicked!"), event.GetLinkInfo().GetHref().c_str());
|
|
|
|
|
|
|
|
// skipping this event the default behaviour (load the clicked URL)
|
|
|
|
// will happen...
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnHtmlCellHover(wxHtmlCellEvent &event)
|
|
|
|
{
|
2006-12-07 00:47:05 -05:00
|
|
|
wxLogMessage(wxT("Mouse moved over cell %p at %d;%d"),
|
2006-10-29 15:26:03 -05:00
|
|
|
event.GetCell(), event.GetPoint().x, event.GetPoint().y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnHtmlCellClicked(wxHtmlCellEvent &event)
|
|
|
|
{
|
2006-12-07 00:47:05 -05:00
|
|
|
wxLogMessage(wxT("Click over cell %p at %d;%d"),
|
2006-10-29 15:26:03 -05:00
|
|
|
event.GetCell(), event.GetPoint().x, event.GetPoint().y);
|
|
|
|
|
|
|
|
// if we don't skip the event, OnHtmlLinkClicked won't be called!
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2004-12-16 15:32:43 -05:00
|
|
|
wxHtmlOpeningStatus MyHtmlWindow::OnOpeningURL(wxHtmlURLType WXUNUSED(type),
|
|
|
|
const wxString& url,
|
|
|
|
wxString *WXUNUSED(redirect)) const
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
GetRelatedFrame()->SetStatusText(url + wxT(" lately opened"),1);
|
2004-12-16 15:32:43 -05:00
|
|
|
return wxHTML_OPEN;
|
|
|
|
}
|
2006-10-30 11:18:45 -05:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyHtmlWindow, wxHtmlWindow)
|
2009-06-18 13:32:20 -04:00
|
|
|
#if wxUSE_CLIPBOARD
|
2006-10-30 11:18:45 -05:00
|
|
|
EVT_TEXT_COPY(wxID_ANY, MyHtmlWindow::OnClipboardEvent)
|
2009-06-18 13:32:20 -04:00
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
EVT_ERASE_BACKGROUND(MyHtmlWindow::OnEraseBgEvent)
|
2006-10-30 11:18:45 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2009-06-18 13:32:20 -04:00
|
|
|
#if wxUSE_CLIPBOARD
|
2006-10-30 11:18:45 -05:00
|
|
|
void MyHtmlWindow::OnClipboardEvent(wxClipboardTextEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// explicitly call wxHtmlWindow::CopySelection() method
|
|
|
|
// and show the first 100 characters of the text copied in the status bar
|
|
|
|
if ( CopySelection() )
|
|
|
|
{
|
|
|
|
wxTextDataObject data;
|
2008-02-28 13:44:43 -05:00
|
|
|
if ( wxTheClipboard && wxTheClipboard->Open() && wxTheClipboard->GetData(data) )
|
2006-10-30 11:18:45 -05:00
|
|
|
{
|
|
|
|
const wxString text = data.GetText();
|
|
|
|
const size_t maxTextLength = 100;
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogStatus(wxString::Format(wxT("Clipboard: '%s%s'"),
|
2006-10-30 11:18:45 -05:00
|
|
|
wxString(text, maxTextLength).c_str(),
|
2009-07-23 16:30:22 -04:00
|
|
|
(text.length() > maxTextLength) ? wxT("...")
|
|
|
|
: wxT("")));
|
2008-02-28 13:44:43 -05:00
|
|
|
wxTheClipboard->Close();
|
|
|
|
|
2006-10-30 11:18:45 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogStatus(wxT("Clipboard: nothing"));
|
2006-10-30 11:18:45 -05:00
|
|
|
}
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
2009-06-18 13:32:20 -04:00
|
|
|
|
|
|
|
void MyHtmlWindow::OnEraseBgEvent(wxEraseEvent& event)
|
|
|
|
{
|
|
|
|
if ( !m_drawCustomBg )
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw a background grid to show that this handler is indeed executed
|
|
|
|
|
|
|
|
wxDC& dc = *event.GetDC();
|
|
|
|
dc.SetPen(*wxBLUE_PEN);
|
|
|
|
dc.Clear();
|
|
|
|
|
|
|
|
const wxSize size = GetVirtualSize();
|
|
|
|
for ( int x = 0; x < size.x; x += 15 )
|
|
|
|
{
|
|
|
|
dc.DrawLine(x, 0, x, size.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( int y = 0; y < size.y; y += 15 )
|
|
|
|
{
|
|
|
|
dc.DrawLine(0, y, size.x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|