]> git.saurik.com Git - wxWidgets.git/blame - include/wx/hyperlink.h
rename Inside(x,y) parameters to avoid gcc warnings about parameters shadowing member...
[wxWidgets.git] / include / wx / hyperlink.h
CommitLineData
17e91437 1/////////////////////////////////////////////////////////////////////////////
98159dd8 2// Name: wx/hyperlink.h
17e91437
VZ
3// Purpose: Hyperlink control
4// Author: David Norris <danorris@gmail.com>, Otto Wyss
5// Modified by: Ryan Norton, Francesco Montorsi
6// Created: 04/02/2005
7// RCS-ID: $Id$
8// Copyright: (c) 2005 David Norris
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_HYPERLINK_H__
13#define _WX_HYPERLINK_H__
14
17e91437
VZ
15#include "wx/defs.h"
16
17#if wxUSE_HYPERLINKCTRL
18
19#include "wx/control.h"
20
21// ----------------------------------------------------------------------------
22// constants
23// ----------------------------------------------------------------------------
24
25#define wxHL_CONTEXTMENU 0x0001
914f5157
VZ
26#define wxHL_ALIGN_LEFT 0x0002
27#define wxHL_ALIGN_RIGHT 0x0004
28#define wxHL_ALIGN_CENTRE 0x0008
29#define wxHL_DEFAULT_STYLE (wxHL_CONTEXTMENU|wxNO_BORDER|wxHL_ALIGN_CENTRE)
17e91437 30
870597ef 31extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxHyperlinkCtrlNameStr[];
17e91437
VZ
32
33
34// ----------------------------------------------------------------------------
35// wxHyperlinkCtrl
36// ----------------------------------------------------------------------------
37
38// A static text control that emulates a hyperlink. The link is displayed
39// in an appropriate text style, derived from the control's normal font.
40// When the mouse rolls over the link, the cursor changes to a hand and the
41// link's color changes to the active color.
42//
43// Clicking on the link does not launch a web browser; instead, a
44// HyperlinkEvent is fired. The event propagates upward until it is caught,
45// just like a wxCommandEvent.
46//
47// Use the EVT_HYPERLINK() to catch link events.
870597ef 48class WXDLLIMPEXP_ADV wxHyperlinkCtrl : public wxControl
17e91437
VZ
49{
50public:
51 // Default constructor (for two-step construction).
52 wxHyperlinkCtrl() { }
53
54 // Constructor.
55 wxHyperlinkCtrl(wxWindow *parent,
56 wxWindowID id,
57 const wxString& label, const wxString& url,
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize,
60 long style = wxHL_DEFAULT_STYLE,
61 const wxString& name = wxHyperlinkCtrlNameStr)
62 {
63 (void)Create(parent, id, label, url, pos, size, style, name);
64 }
65
66 // Creation function (for two-step construction).
67 bool Create(wxWindow *parent,
68 wxWindowID id,
69 const wxString& label, const wxString& url,
70 const wxPoint& pos = wxDefaultPosition,
71 const wxSize& size = wxDefaultSize,
72 long style = wxHL_DEFAULT_STYLE,
73 const wxString& name = wxHyperlinkCtrlNameStr);
74
75
76 // get/set
77 wxColour GetHoverColour() const { return m_hoverColour; }
78 void SetHoverColour(const wxColour &colour) { m_hoverColour = colour; }
79
80 wxColour GetNormalColour() const { return m_normalColour; }
81 void SetNormalColour(const wxColour &colour);
82
83 wxColour GetVisitedColour() const { return m_visitedColour; }
84 void SetVisitedColour(const wxColour &colour);
85
86 wxString GetURL() const { return m_url; }
87 void SetURL (const wxString &url) { m_url=url; }
88
89 void SetVisited(bool visited = true) { m_visited=visited; }
90 bool GetVisited() const { return m_visited; }
91
92 // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
93 // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
94
95
96protected:
97 // event handlers
98
99 // Renders the hyperlink.
100 void OnPaint(wxPaintEvent& event);
101
914f5157
VZ
102 // Returns the wxRect of the label of this hyperlink.
103 // This is different from the clientsize's rectangle when
104 // clientsize != bestsize and this rectangle is influenced
105 // by the alignment of the label (wxHL_ALIGN_*).
106 wxRect GetLabelRect() const;
107
17e91437
VZ
108 // If the click originates inside the bounding box of the label,
109 // a flag is set so that an event will be fired when the left
110 // button is released.
111 void OnLeftDown(wxMouseEvent& event);
112
113 // If the click both originated and finished inside the bounding box
114 // of the label, a HyperlinkEvent is fired.
115 void OnLeftUp(wxMouseEvent& event);
116 void OnRightUp(wxMouseEvent& event);
117
118 // Changes the cursor to a hand, if the mouse is inside the label's
119 // bounding box.
914f5157 120 void OnMotion(wxMouseEvent& event);
17e91437
VZ
121
122 // Changes the cursor back to the default, if necessary.
123 void OnLeaveWindow(wxMouseEvent& event);
124
125 // handles "Copy URL" menuitem
126 void OnPopUpCopy(wxCommandEvent& event);
127
914f5157
VZ
128 // Refreshes the control to update label's position if necessary
129 void OnSize(wxSizeEvent& event);
130
17e91437
VZ
131
132 // overridden base class virtuals
133
134 // Returns the best size for the window, which is the size needed
135 // to display the text label.
17e91437
VZ
136 virtual wxSize DoGetBestSize() const;
137
138 // creates a context menu with "Copy URL" menuitem
139 virtual void DoContextMenu(const wxPoint &);
140
141private:
142 // URL associated with the link. This is transmitted inside
143 // the HyperlinkEvent fired when the user clicks on the label.
144 wxString m_url;
145
146 // Foreground colours for various link types.
147 // NOTE: wxWindow::m_backgroundColour is used for background,
148 // wxWindow::m_foregroundColour is used to render non-visited links
149 wxColour m_hoverColour;
150 wxColour m_normalColour;
151 wxColour m_visitedColour;
152
153 // True if the mouse cursor is inside the label's bounding box.
154 bool m_rollover;
155
156 // True if the link has been clicked before.
157 bool m_visited;
158
159 // True if a click is in progress (left button down) and the click
160 // originated inside the label's bounding box.
161 bool m_clicking;
162
163private:
164 DECLARE_DYNAMIC_CLASS(wxHyperlinkCtrl)
165 DECLARE_EVENT_TABLE()
166};
167
168
169// ----------------------------------------------------------------------------
170// wxHyperlinkEvent
171// ----------------------------------------------------------------------------
172
173// Declare an event identifier.
174BEGIN_DECLARE_EVENT_TYPES()
870597ef 175 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_HYPERLINK, 3700)
17e91437
VZ
176END_DECLARE_EVENT_TYPES()
177
178//
179// An event fired when the user clicks on the label in a hyperlink control.
180// See HyperlinkControl for details.
181//
870597ef 182class WXDLLIMPEXP_ADV wxHyperlinkEvent : public wxCommandEvent
17e91437
VZ
183{
184public:
17e91437
VZ
185 wxHyperlinkEvent() {}
186 wxHyperlinkEvent(wxObject *generator, wxWindowID id, const wxString& url)
258b2ca6
RD
187 : wxCommandEvent(wxEVT_COMMAND_HYPERLINK, id),
188 m_url(url)
189 {
190 SetEventObject(generator);
191 }
17e91437
VZ
192
193 // Returns the URL associated with the hyperlink control
194 // that the user clicked on.
195 wxString GetURL() const { return m_url; }
196 void SetURL(const wxString &url) { m_url=url; }
197
258b2ca6
RD
198 // default copy ctor, assignment operator and dtor are ok
199 virtual wxEvent *Clone() const { return new wxHyperlinkEvent(*this); }
200
17e91437
VZ
201private:
202
203 // URL associated with the hyperlink control that the used clicked on.
204 wxString m_url;
258b2ca6
RD
205
206 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHyperlinkEvent)
17e91437
VZ
207};
208
17e91437 209
258b2ca6
RD
210// ----------------------------------------------------------------------------
211// event types and macros
212// ----------------------------------------------------------------------------
213
214typedef void (wxEvtHandler::*wxHyperlinkEventFunction)(wxHyperlinkEvent&);
17e91437 215
17e91437
VZ
216#define wxHyperlinkEventHandler(func) \
217 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHyperlinkEventFunction, &func)
218
258b2ca6
RD
219#define EVT_HYPERLINK(id, fn) \
220 wx__DECLARE_EVT1(wxEVT_COMMAND_HYPERLINK, id, wxHyperlinkEventHandler(fn))
221
222#ifdef _WX_DEFINE_DATE_EVENTS_
223 DEFINE_EVENT_TYPE(wxEVT_COMMAND_HYPERLINK)
224
225 IMPLEMENT_DYNAMIC_CLASS(wxHyperlinkEvent, wxCommandEvent)
226#endif
227
228
17e91437
VZ
229#endif // wxUSE_HYPERLINKCTRL
230
231#endif // _WX_HYPERLINK_H__