2006-05-28 13:41:09 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-05-29 03:31:24 -04:00
|
|
|
// Name: wx/hyperlink.h
|
2006-05-28 13:41:09 -04:00
|
|
|
// Purpose: Hyperlink control
|
|
|
|
// Author: David Norris <danorris@gmail.com>, Otto Wyss
|
|
|
|
// Modified by: Ryan Norton, Francesco Montorsi
|
|
|
|
// Created: 04/02/2005
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2005 David Norris
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_HYPERLINK_H__
|
|
|
|
#define _WX_HYPERLINK_H__
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_HYPERLINKCTRL
|
|
|
|
|
|
|
|
#include "wx/control.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define wxHL_CONTEXTMENU 0x0001
|
2006-09-10 19:57:26 -04:00
|
|
|
#define wxHL_ALIGN_LEFT 0x0002
|
|
|
|
#define wxHL_ALIGN_RIGHT 0x0004
|
|
|
|
#define wxHL_ALIGN_CENTRE 0x0008
|
|
|
|
#define wxHL_DEFAULT_STYLE (wxHL_CONTEXTMENU|wxNO_BORDER|wxHL_ALIGN_CENTRE)
|
2006-05-28 13:41:09 -04:00
|
|
|
|
2006-05-29 16:07:30 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxHyperlinkCtrlNameStr[];
|
2006-05-28 13:41:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxHyperlinkCtrl
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// A static text control that emulates a hyperlink. The link is displayed
|
|
|
|
// in an appropriate text style, derived from the control's normal font.
|
|
|
|
// When the mouse rolls over the link, the cursor changes to a hand and the
|
|
|
|
// link's color changes to the active color.
|
|
|
|
//
|
|
|
|
// Clicking on the link does not launch a web browser; instead, a
|
|
|
|
// HyperlinkEvent is fired. The event propagates upward until it is caught,
|
|
|
|
// just like a wxCommandEvent.
|
|
|
|
//
|
|
|
|
// Use the EVT_HYPERLINK() to catch link events.
|
2006-05-29 16:07:30 -04:00
|
|
|
class WXDLLIMPEXP_ADV wxHyperlinkCtrl : public wxControl
|
2006-05-28 13:41:09 -04:00
|
|
|
{
|
|
|
|
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; }
|
|
|
|
|
|
|
|
wxColour GetNormalColour() const { return m_normalColour; }
|
|
|
|
void SetNormalColour(const wxColour &colour);
|
|
|
|
|
|
|
|
wxColour GetVisitedColour() const { return m_visitedColour; }
|
|
|
|
void SetVisitedColour(const wxColour &colour);
|
|
|
|
|
|
|
|
wxString GetURL() const { return m_url; }
|
|
|
|
void SetURL (const wxString &url) { m_url=url; }
|
|
|
|
|
|
|
|
void SetVisited(bool visited = true) { m_visited=visited; }
|
|
|
|
bool GetVisited() const { return m_visited; }
|
|
|
|
|
|
|
|
// NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
|
|
|
|
// wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// event handlers
|
|
|
|
|
|
|
|
// Renders the hyperlink.
|
|
|
|
void OnPaint(wxPaintEvent& event);
|
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
// 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;
|
|
|
|
|
2006-05-28 13:41:09 -04:00
|
|
|
// 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.
|
2006-09-10 19:57:26 -04:00
|
|
|
void OnMotion(wxMouseEvent& event);
|
2006-05-28 13:41:09 -04:00
|
|
|
|
|
|
|
// Changes the cursor back to the default, if necessary.
|
|
|
|
void OnLeaveWindow(wxMouseEvent& event);
|
|
|
|
|
|
|
|
// handles "Copy URL" menuitem
|
|
|
|
void OnPopUpCopy(wxCommandEvent& event);
|
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
// Refreshes the control to update label's position if necessary
|
|
|
|
void OnSize(wxSizeEvent& event);
|
|
|
|
|
2006-05-28 13:41:09 -04:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxHyperlinkEvent
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Declare an event identifier.
|
|
|
|
BEGIN_DECLARE_EVENT_TYPES()
|
2006-05-29 16:07:30 -04:00
|
|
|
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_HYPERLINK, 3700)
|
2006-05-28 13:41:09 -04:00
|
|
|
END_DECLARE_EVENT_TYPES()
|
|
|
|
|
|
|
|
//
|
|
|
|
// An event fired when the user clicks on the label in a hyperlink control.
|
|
|
|
// See HyperlinkControl for details.
|
|
|
|
//
|
2006-05-29 16:07:30 -04:00
|
|
|
class WXDLLIMPEXP_ADV wxHyperlinkEvent : public wxCommandEvent
|
2006-05-28 13:41:09 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxHyperlinkEvent() {}
|
|
|
|
wxHyperlinkEvent(wxObject *generator, wxWindowID id, const wxString& url)
|
2006-06-08 14:27:44 -04:00
|
|
|
: wxCommandEvent(wxEVT_COMMAND_HYPERLINK, id),
|
|
|
|
m_url(url)
|
|
|
|
{
|
|
|
|
SetEventObject(generator);
|
|
|
|
}
|
2006-05-28 13:41:09 -04:00
|
|
|
|
|
|
|
// Returns the URL associated with the hyperlink control
|
|
|
|
// that the user clicked on.
|
|
|
|
wxString GetURL() const { return m_url; }
|
|
|
|
void SetURL(const wxString &url) { m_url=url; }
|
|
|
|
|
2006-06-08 14:27:44 -04:00
|
|
|
// default copy ctor, assignment operator and dtor are ok
|
|
|
|
virtual wxEvent *Clone() const { return new wxHyperlinkEvent(*this); }
|
|
|
|
|
2006-05-28 13:41:09 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
// URL associated with the hyperlink control that the used clicked on.
|
|
|
|
wxString m_url;
|
2006-06-08 14:27:44 -04:00
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHyperlinkEvent)
|
2006-05-28 13:41:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-06-08 14:27:44 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event types and macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef void (wxEvtHandler::*wxHyperlinkEventFunction)(wxHyperlinkEvent&);
|
2006-05-28 13:41:09 -04:00
|
|
|
|
|
|
|
#define wxHyperlinkEventHandler(func) \
|
|
|
|
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHyperlinkEventFunction, &func)
|
|
|
|
|
2006-06-08 14:27:44 -04:00
|
|
|
#define EVT_HYPERLINK(id, fn) \
|
|
|
|
wx__DECLARE_EVT1(wxEVT_COMMAND_HYPERLINK, id, wxHyperlinkEventHandler(fn))
|
|
|
|
|
|
|
|
#ifdef _WX_DEFINE_DATE_EVENTS_
|
|
|
|
DEFINE_EVENT_TYPE(wxEVT_COMMAND_HYPERLINK)
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxHyperlinkEvent, wxCommandEvent)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-05-28 13:41:09 -04:00
|
|
|
#endif // wxUSE_HYPERLINKCTRL
|
|
|
|
|
|
|
|
#endif // _WX_HYPERLINK_H__
|