1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/hyperlink.h
3 // Purpose: Hyperlink control
4 // Author: David Norris <danorris@gmail.com>, Otto Wyss
5 // Modified by: Ryan Norton, Francesco Montorsi
8 // Copyright: (c) 2005 David Norris
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __GENERICHYPERLINKCTRLH__
13 #define __GENERICHYPERLINKCTRLH__
16 #include "wx/control.h"
19 // ----------------------------------------------------------------------------
20 // wxGenericHyperlinkCtrl
21 // ----------------------------------------------------------------------------
23 class WXDLLIMPEXP_ADV wxGenericHyperlinkCtrl
: public wxHyperlinkCtrlBase
26 // Default constructor (for two-step construction).
27 wxGenericHyperlinkCtrl() { }
30 wxGenericHyperlinkCtrl(wxWindow
*parent
,
32 const wxString
& label
, const wxString
& url
,
33 const wxPoint
& pos
= wxDefaultPosition
,
34 const wxSize
& size
= wxDefaultSize
,
35 long style
= wxHL_DEFAULT_STYLE
,
36 const wxString
& name
= wxHyperlinkCtrlNameStr
)
38 (void)Create(parent
, id
, label
, url
, pos
, size
, style
, name
);
41 // Creation function (for two-step construction).
42 bool Create(wxWindow
*parent
,
44 const wxString
& label
, const wxString
& url
,
45 const wxPoint
& pos
= wxDefaultPosition
,
46 const wxSize
& size
= wxDefaultSize
,
47 long style
= wxHL_DEFAULT_STYLE
,
48 const wxString
& name
= wxHyperlinkCtrlNameStr
);
52 wxColour
GetHoverColour() const { return m_hoverColour
; }
53 void SetHoverColour(const wxColour
&colour
) { m_hoverColour
= colour
; }
55 wxColour
GetNormalColour() const { return m_normalColour
; }
56 void SetNormalColour(const wxColour
&colour
);
58 wxColour
GetVisitedColour() const { return m_visitedColour
; }
59 void SetVisitedColour(const wxColour
&colour
);
61 wxString
GetURL() const { return m_url
; }
62 void SetURL (const wxString
&url
) { m_url
=url
; }
64 void SetVisited(bool visited
= true) { m_visited
=visited
; }
65 bool GetVisited() const { return m_visited
; }
67 // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
68 // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
74 // Renders the hyperlink.
75 void OnPaint(wxPaintEvent
& event
);
77 // Returns the wxRect of the label of this hyperlink.
78 // This is different from the clientsize's rectangle when
79 // clientsize != bestsize and this rectangle is influenced
80 // by the alignment of the label (wxHL_ALIGN_*).
81 wxRect
GetLabelRect() const;
83 // If the click originates inside the bounding box of the label,
84 // a flag is set so that an event will be fired when the left
85 // button is released.
86 void OnLeftDown(wxMouseEvent
& event
);
88 // If the click both originated and finished inside the bounding box
89 // of the label, a HyperlinkEvent is fired.
90 void OnLeftUp(wxMouseEvent
& event
);
91 void OnRightUp(wxMouseEvent
& event
);
93 // Changes the cursor to a hand, if the mouse is inside the label's
95 void OnMotion(wxMouseEvent
& event
);
97 // Changes the cursor back to the default, if necessary.
98 void OnLeaveWindow(wxMouseEvent
& event
);
100 // handles "Copy URL" menuitem
101 void OnPopUpCopy(wxCommandEvent
& event
);
103 // Refreshes the control to update label's position if necessary
104 void OnSize(wxSizeEvent
& event
);
107 // overridden base class virtuals
109 // Returns the best size for the window, which is the size needed
110 // to display the text label.
111 virtual wxSize
DoGetBestSize() const;
113 // creates a context menu with "Copy URL" menuitem
114 virtual void DoContextMenu(const wxPoint
&);
117 // URL associated with the link. This is transmitted inside
118 // the HyperlinkEvent fired when the user clicks on the label.
121 // Foreground colours for various link types.
122 // NOTE: wxWindow::m_backgroundColour is used for background,
123 // wxWindow::m_foregroundColour is used to render non-visited links
124 wxColour m_hoverColour
;
125 wxColour m_normalColour
;
126 wxColour m_visitedColour
;
128 // True if the mouse cursor is inside the label's bounding box.
131 // True if the link has been clicked before.
134 // True if a click is in progress (left button down) and the click
135 // originated inside the label's bounding box.
139 DECLARE_DYNAMIC_CLASS(wxGenericHyperlinkCtrl
)
142 #endif // __GENERICHYPERLINKCTRLH__