native wxHyperlinkCtrl implementation for GTK+ 2.10+ (patch 1661851)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44647 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-03-07 22:12:47 +00:00
parent a48b659563
commit c105dda081
15 changed files with 974 additions and 367 deletions

View File

@@ -45,124 +45,41 @@ extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxHyperlinkCtrlNameStr[];
// just like a wxCommandEvent.
//
// Use the EVT_HYPERLINK() to catch link events.
class WXDLLIMPEXP_ADV wxHyperlinkCtrl : public wxControl
class WXDLLIMPEXP_ADV wxHyperlinkCtrlBase : public wxControl
{
public:
// Default constructor (for two-step construction).
wxHyperlinkCtrl() { }
// Constructor.
wxHyperlinkCtrl(wxWindow *parent,
wxWindowID id,
const wxString& label, const wxString& url,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHL_DEFAULT_STYLE,
const wxString& name = wxHyperlinkCtrlNameStr)
{
(void)Create(parent, id, label, url, pos, size, style, name);
}
// Creation function (for two-step construction).
bool Create(wxWindow *parent,
wxWindowID id,
const wxString& label, const wxString& url,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHL_DEFAULT_STYLE,
const wxString& name = wxHyperlinkCtrlNameStr);
// get/set
wxColour GetHoverColour() const { return m_hoverColour; }
void SetHoverColour(const wxColour &colour) { m_hoverColour = colour; }
virtual wxColour GetHoverColour() const = 0;
virtual void SetHoverColour(const wxColour &colour) = 0;
wxColour GetNormalColour() const { return m_normalColour; }
void SetNormalColour(const wxColour &colour);
virtual wxColour GetNormalColour() const = 0;
virtual void SetNormalColour(const wxColour &colour) = 0;
wxColour GetVisitedColour() const { return m_visitedColour; }
void SetVisitedColour(const wxColour &colour);
virtual wxColour GetVisitedColour() const = 0;
virtual void SetVisitedColour(const wxColour &colour) = 0;
wxString GetURL() const { return m_url; }
void SetURL (const wxString &url) { m_url=url; }
virtual wxString GetURL() const = 0;
virtual void SetURL (const wxString &url) = 0;
void SetVisited(bool visited = true) { m_visited=visited; }
bool GetVisited() const { return m_visited; }
virtual void SetVisited(bool visited = true) = 0;
virtual bool GetVisited() const = 0;
// NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
// wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
protected:
// event handlers
#ifdef __WXDEBUG__
// checks for validity some of the ctor/Create() function parameters
void CheckParams(const wxString& label, const wxString& url, long style);
#else
void CheckParams() {}
#endif
// Renders the hyperlink.
void OnPaint(wxPaintEvent& event);
// Returns the wxRect of the label of this hyperlink.
// This is different from the clientsize's rectangle when
// clientsize != bestsize and this rectangle is influenced
// by the alignment of the label (wxHL_ALIGN_*).
wxRect GetLabelRect() const;
// If the click originates inside the bounding box of the label,
// a flag is set so that an event will be fired when the left
// button is released.
void OnLeftDown(wxMouseEvent& event);
// If the click both originated and finished inside the bounding box
// of the label, a HyperlinkEvent is fired.
void OnLeftUp(wxMouseEvent& event);
void OnRightUp(wxMouseEvent& event);
// Changes the cursor to a hand, if the mouse is inside the label's
// bounding box.
void OnMotion(wxMouseEvent& event);
// Changes the cursor back to the default, if necessary.
void OnLeaveWindow(wxMouseEvent& event);
// handles "Copy URL" menuitem
void OnPopUpCopy(wxCommandEvent& event);
// Refreshes the control to update label's position if necessary
void OnSize(wxSizeEvent& event);
// overridden base class virtuals
// Returns the best size for the window, which is the size needed
// to display the text label.
virtual wxSize DoGetBestSize() const;
// creates a context menu with "Copy URL" menuitem
virtual void DoContextMenu(const wxPoint &);
private:
// URL associated with the link. This is transmitted inside
// the HyperlinkEvent fired when the user clicks on the label.
wxString m_url;
// Foreground colours for various link types.
// NOTE: wxWindow::m_backgroundColour is used for background,
// wxWindow::m_foregroundColour is used to render non-visited links
wxColour m_hoverColour;
wxColour m_normalColour;
wxColour m_visitedColour;
// True if the mouse cursor is inside the label's bounding box.
bool m_rollover;
// True if the link has been clicked before.
bool m_visited;
// True if a click is in progress (left button down) and the click
// originated inside the label's bounding box.
bool m_clicking;
private:
DECLARE_DYNAMIC_CLASS(wxHyperlinkCtrl)
DECLARE_EVENT_TABLE()
public:
// not part of the public API but needs to be public as used by
// GTK+ callbacks:
void SendEvent();
};
@@ -226,6 +143,15 @@ typedef void (wxEvtHandler::*wxHyperlinkEventFunction)(wxHyperlinkEvent&);
#endif
#if defined(__WXGTK210__)
#include "wx/gtk/hyperlink.h"
#else
#include "wx/generic/hyperlink.h"
#define wxHyperlinkCtrl wxGenericHyperlinkCtrl
#endif
#endif // wxUSE_HYPERLINKCTRL
#endif // _WX_HYPERLINK_H__