1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/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 _WX_HYPERLINK_H_
13 #define _WX_HYPERLINK_H_
17 #if wxUSE_HYPERLINKCTRL
19 #include "wx/control.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 #define wxHL_CONTEXTMENU 0x0001
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)
31 extern WXDLLIMPEXP_DATA_ADV(const char) wxHyperlinkCtrlNameStr
[];
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
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.
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.
47 // Use the EVT_HYPERLINK() to catch link events.
48 class WXDLLIMPEXP_ADV wxHyperlinkCtrlBase
: public wxControl
53 virtual wxColour
GetHoverColour() const = 0;
54 virtual void SetHoverColour(const wxColour
&colour
) = 0;
56 virtual wxColour
GetNormalColour() const = 0;
57 virtual void SetNormalColour(const wxColour
&colour
) = 0;
59 virtual wxColour
GetVisitedColour() const = 0;
60 virtual void SetVisitedColour(const wxColour
&colour
) = 0;
62 virtual wxString
GetURL() const = 0;
63 virtual void SetURL (const wxString
&url
) = 0;
65 virtual void SetVisited(bool visited
= true) = 0;
66 virtual bool GetVisited() const = 0;
68 // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
69 // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
72 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
74 // checks for validity some of the ctor/Create() function parameters
75 void CheckParams(const wxString
& label
, const wxString
& url
, long style
);
78 // not part of the public API but needs to be public as used by
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 class WXDLLIMPEXP_FWD_ADV wxHyperlinkEvent
;
89 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV
, wxEVT_COMMAND_HYPERLINK
, wxHyperlinkEvent
);
92 // An event fired when the user clicks on the label in a hyperlink control.
93 // See HyperlinkControl for details.
95 class WXDLLIMPEXP_ADV wxHyperlinkEvent
: public wxCommandEvent
99 wxHyperlinkEvent(wxObject
*generator
, wxWindowID id
, const wxString
& url
)
100 : wxCommandEvent(wxEVT_COMMAND_HYPERLINK
, id
),
103 SetEventObject(generator
);
106 // Returns the URL associated with the hyperlink control
107 // that the user clicked on.
108 wxString
GetURL() const { return m_url
; }
109 void SetURL(const wxString
&url
) { m_url
=url
; }
111 // default copy ctor, assignment operator and dtor are ok
112 virtual wxEvent
*Clone() const { return new wxHyperlinkEvent(*this); }
116 // URL associated with the hyperlink control that the used clicked on.
119 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHyperlinkEvent
)
123 // ----------------------------------------------------------------------------
124 // event types and macros
125 // ----------------------------------------------------------------------------
127 typedef void (wxEvtHandler::*wxHyperlinkEventFunction
)(wxHyperlinkEvent
&);
129 #define wxHyperlinkEventHandler(func) \
130 wxEVENT_HANDLER_CAST(wxHyperlinkEventFunction, func)
132 #define EVT_HYPERLINK(id, fn) \
133 wx__DECLARE_EVT1(wxEVT_COMMAND_HYPERLINK, id, wxHyperlinkEventHandler(fn))
136 #if defined(__WXGTK210__) && !defined(__WXUNIVERSAL__)
137 #include "wx/gtk/hyperlink.h"
138 // Note that the native control is only available in Unicode version under MSW.
139 #elif defined(__WXMSW__) && wxUSE_UNICODE && !defined(__WXUNIVERSAL__)
140 #include "wx/msw/hyperlink.h"
142 #include "wx/generic/hyperlink.h"
144 class WXDLLIMPEXP_ADV wxHyperlinkCtrl
: public wxGenericHyperlinkCtrl
147 wxHyperlinkCtrl() { }
149 wxHyperlinkCtrl(wxWindow
*parent
,
151 const wxString
& label
,
153 const wxPoint
& pos
= wxDefaultPosition
,
154 const wxSize
& size
= wxDefaultSize
,
155 long style
= wxHL_DEFAULT_STYLE
,
156 const wxString
& name
= wxHyperlinkCtrlNameStr
)
157 : wxGenericHyperlinkCtrl(parent
, id
, label
, url
, pos
, size
,
163 wxDECLARE_DYNAMIC_CLASS_NO_COPY( wxHyperlinkCtrl
);
168 #endif // wxUSE_HYPERLINKCTRL
170 #endif // _WX_HYPERLINK_H_