]> git.saurik.com Git - wxWidgets.git/blame - include/wx/hyperlink.h
removed broken and global GetLine() function from wx/protocol/protocol.h; there's...
[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.
c105dda0 48class WXDLLIMPEXP_ADV wxHyperlinkCtrlBase : public wxControl
17e91437
VZ
49{
50public:
17e91437
VZ
51
52 // get/set
c105dda0
VZ
53 virtual wxColour GetHoverColour() const = 0;
54 virtual void SetHoverColour(const wxColour &colour) = 0;
17e91437 55
c105dda0
VZ
56 virtual wxColour GetNormalColour() const = 0;
57 virtual void SetNormalColour(const wxColour &colour) = 0;
17e91437 58
c105dda0
VZ
59 virtual wxColour GetVisitedColour() const = 0;
60 virtual void SetVisitedColour(const wxColour &colour) = 0;
17e91437 61
c105dda0
VZ
62 virtual wxString GetURL() const = 0;
63 virtual void SetURL (const wxString &url) = 0;
17e91437 64
c105dda0
VZ
65 virtual void SetVisited(bool visited = true) = 0;
66 virtual bool GetVisited() const = 0;
17e91437
VZ
67
68 // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
69 // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
70
17e91437 71protected:
c105dda0
VZ
72 // checks for validity some of the ctor/Create() function parameters
73 void CheckParams(const wxString& label, const wxString& url, long style);
17e91437 74
c105dda0
VZ
75public:
76 // not part of the public API but needs to be public as used by
77 // GTK+ callbacks:
78 void SendEvent();
17e91437
VZ
79};
80
74506749
PC
81#ifndef __WXDEBUG__
82inline void wxHyperlinkCtrlBase::CheckParams(const wxString&, const wxString&, long) { }
83#endif
17e91437
VZ
84
85// ----------------------------------------------------------------------------
86// wxHyperlinkEvent
87// ----------------------------------------------------------------------------
88
89// Declare an event identifier.
90BEGIN_DECLARE_EVENT_TYPES()
870597ef 91 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_HYPERLINK, 3700)
17e91437
VZ
92END_DECLARE_EVENT_TYPES()
93
94//
95// An event fired when the user clicks on the label in a hyperlink control.
96// See HyperlinkControl for details.
97//
870597ef 98class WXDLLIMPEXP_ADV wxHyperlinkEvent : public wxCommandEvent
17e91437
VZ
99{
100public:
17e91437
VZ
101 wxHyperlinkEvent() {}
102 wxHyperlinkEvent(wxObject *generator, wxWindowID id, const wxString& url)
258b2ca6
RD
103 : wxCommandEvent(wxEVT_COMMAND_HYPERLINK, id),
104 m_url(url)
105 {
106 SetEventObject(generator);
107 }
17e91437
VZ
108
109 // Returns the URL associated with the hyperlink control
110 // that the user clicked on.
111 wxString GetURL() const { return m_url; }
112 void SetURL(const wxString &url) { m_url=url; }
113
258b2ca6
RD
114 // default copy ctor, assignment operator and dtor are ok
115 virtual wxEvent *Clone() const { return new wxHyperlinkEvent(*this); }
116
17e91437
VZ
117private:
118
119 // URL associated with the hyperlink control that the used clicked on.
120 wxString m_url;
258b2ca6
RD
121
122 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHyperlinkEvent)
17e91437
VZ
123};
124
17e91437 125
258b2ca6
RD
126// ----------------------------------------------------------------------------
127// event types and macros
128// ----------------------------------------------------------------------------
129
130typedef void (wxEvtHandler::*wxHyperlinkEventFunction)(wxHyperlinkEvent&);
17e91437 131
17e91437
VZ
132#define wxHyperlinkEventHandler(func) \
133 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHyperlinkEventFunction, &func)
134
258b2ca6
RD
135#define EVT_HYPERLINK(id, fn) \
136 wx__DECLARE_EVT1(wxEVT_COMMAND_HYPERLINK, id, wxHyperlinkEventHandler(fn))
137
138#ifdef _WX_DEFINE_DATE_EVENTS_
139 DEFINE_EVENT_TYPE(wxEVT_COMMAND_HYPERLINK)
140
141 IMPLEMENT_DYNAMIC_CLASS(wxHyperlinkEvent, wxCommandEvent)
142#endif
143
144
c105dda0
VZ
145
146#if defined(__WXGTK210__)
147 #include "wx/gtk/hyperlink.h"
148#else
149 #include "wx/generic/hyperlink.h"
150 #define wxHyperlinkCtrl wxGenericHyperlinkCtrl
151#endif
152
153
17e91437
VZ
154#endif // wxUSE_HYPERLINKCTRL
155
156#endif // _WX_HYPERLINK_H__