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
7 // Copyright: (c) 2005 David Norris
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GENERICHYPERLINKCTRL_H_
12 #define _WX_GENERICHYPERLINKCTRL_H_
14 // ----------------------------------------------------------------------------
15 // wxGenericHyperlinkCtrl
16 // ----------------------------------------------------------------------------
18 class WXDLLIMPEXP_ADV wxGenericHyperlinkCtrl
: public wxHyperlinkCtrlBase
21 // Default constructor (for two-step construction).
22 wxGenericHyperlinkCtrl() { Init(); }
25 wxGenericHyperlinkCtrl(wxWindow
*parent
,
27 const wxString
& label
, const wxString
& url
,
28 const wxPoint
& pos
= wxDefaultPosition
,
29 const wxSize
& size
= wxDefaultSize
,
30 long style
= wxHL_DEFAULT_STYLE
,
31 const wxString
& name
= wxHyperlinkCtrlNameStr
)
34 (void) Create(parent
, id
, label
, url
, pos
, size
, style
, name
);
37 // Creation function (for two-step construction).
38 bool Create(wxWindow
*parent
,
40 const wxString
& label
, const wxString
& url
,
41 const wxPoint
& pos
= wxDefaultPosition
,
42 const wxSize
& size
= wxDefaultSize
,
43 long style
= wxHL_DEFAULT_STYLE
,
44 const wxString
& name
= wxHyperlinkCtrlNameStr
);
48 wxColour
GetHoverColour() const { return m_hoverColour
; }
49 void SetHoverColour(const wxColour
&colour
) { m_hoverColour
= colour
; }
51 wxColour
GetNormalColour() const { return m_normalColour
; }
52 void SetNormalColour(const wxColour
&colour
);
54 wxColour
GetVisitedColour() const { return m_visitedColour
; }
55 void SetVisitedColour(const wxColour
&colour
);
57 wxString
GetURL() const { return m_url
; }
58 void SetURL (const wxString
&url
) { m_url
=url
; }
60 void SetVisited(bool visited
= true) { m_visited
=visited
; }
61 bool GetVisited() const { return m_visited
; }
63 // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
64 // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
68 // Helper used by this class itself and native MSW implementation that
69 // connects OnRightUp() and OnPopUpCopy() handlers.
70 void ConnectMenuHandlers();
74 // Renders the hyperlink.
75 void OnPaint(wxPaintEvent
& event
);
77 // Handle set/kill focus events (invalidate for painting focus rect)
78 void OnFocus(wxFocusEvent
& event
);
80 // Fire a HyperlinkEvent on space
81 void OnChar(wxKeyEvent
& event
);
83 // Returns the wxRect of the label of this hyperlink.
84 // This is different from the clientsize's rectangle when
85 // clientsize != bestsize and this rectangle is influenced
86 // by the alignment of the label (wxHL_ALIGN_*).
87 wxRect
GetLabelRect() const;
89 // If the click originates inside the bounding box of the label,
90 // a flag is set so that an event will be fired when the left
91 // button is released.
92 void OnLeftDown(wxMouseEvent
& event
);
94 // If the click both originated and finished inside the bounding box
95 // of the label, a HyperlinkEvent is fired.
96 void OnLeftUp(wxMouseEvent
& event
);
97 void OnRightUp(wxMouseEvent
& event
);
99 // Changes the cursor to a hand, if the mouse is inside the label's
101 void OnMotion(wxMouseEvent
& event
);
103 // Changes the cursor back to the default, if necessary.
104 void OnLeaveWindow(wxMouseEvent
& event
);
106 // handles "Copy URL" menuitem
107 void OnPopUpCopy(wxCommandEvent
& event
);
109 // overridden base class virtuals
111 // Returns the best size for the window, which is the size needed
112 // to display the text label.
113 virtual wxSize
DoGetBestClientSize() const;
115 // creates a context menu with "Copy URL" menuitem
116 virtual void DoContextMenu(const wxPoint
&);
119 // Common part of all ctors.
122 // URL associated with the link. This is transmitted inside
123 // the HyperlinkEvent fired when the user clicks on the label.
126 // Foreground colours for various link types.
127 // NOTE: wxWindow::m_backgroundColour is used for background,
128 // wxWindow::m_foregroundColour is used to render non-visited links
129 wxColour m_hoverColour
;
130 wxColour m_normalColour
;
131 wxColour m_visitedColour
;
133 // True if the mouse cursor is inside the label's bounding box.
136 // True if the link has been clicked before.
139 // True if a click is in progress (left button down) and the click
140 // originated inside the label's bounding box.
144 #endif // _WX_GENERICHYPERLINKCTRL_H_