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 6 // Created: 04/02/2005 7 // Copyright: (c) 2005 David Norris 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_HYPERLINK_H_ 12 #define _WX_HYPERLINK_H_ 13 14 #include "wx/defs.h" 15 16 #if wxUSE_HYPERLINKCTRL 17 18 #include "wx/control.h" 19 20 // ---------------------------------------------------------------------------- 21 // constants 22 // ---------------------------------------------------------------------------- 23 24 #define wxHL_CONTEXTMENU 0x0001 25 #define wxHL_ALIGN_LEFT 0x0002 26 #define wxHL_ALIGN_RIGHT 0x0004 27 #define wxHL_ALIGN_CENTRE 0x0008 28 #define wxHL_DEFAULT_STYLE (wxHL_CONTEXTMENU|wxNO_BORDER|wxHL_ALIGN_CENTRE) 29 30 extern WXDLLIMPEXP_DATA_CORE(const char) wxHyperlinkCtrlNameStr[]; 31 32 33 // ---------------------------------------------------------------------------- 34 // wxHyperlinkCtrl 35 // ---------------------------------------------------------------------------- 36 37 // A static text control that emulates a hyperlink. The link is displayed 38 // in an appropriate text style, derived from the control's normal font. 39 // When the mouse rolls over the link, the cursor changes to a hand and the 40 // link's color changes to the active color. 41 // 42 // Clicking on the link does not launch a web browser; instead, a 43 // HyperlinkEvent is fired. The event propagates upward until it is caught, 44 // just like a wxCommandEvent. 45 // 46 // Use the EVT_HYPERLINK() to catch link events. 47 class WXDLLIMPEXP_CORE wxHyperlinkCtrlBase : public wxControl 48 { 49 public: 50 51 // get/set 52 virtual wxColour GetHoverColour() const = 0; 53 virtual void SetHoverColour(const wxColour &colour) = 0; 54 55 virtual wxColour GetNormalColour() const = 0; 56 virtual void SetNormalColour(const wxColour &colour) = 0; 57 58 virtual wxColour GetVisitedColour() const = 0; 59 virtual void SetVisitedColour(const wxColour &colour) = 0; 60 61 virtual wxString GetURL() const = 0; 62 virtual void SetURL (const wxString &url) = 0; 63 64 virtual void SetVisited(bool visited = true) = 0; 65 virtual bool GetVisited() const = 0; 66 67 // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour, 68 // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important ! 69 HasTransparentBackground()70 virtual bool HasTransparentBackground() wxOVERRIDE { return true; } 71 72 protected: GetDefaultBorder()73 virtual wxBorder GetDefaultBorder() const wxOVERRIDE { return wxBORDER_NONE; } 74 75 // checks for validity some of the ctor/Create() function parameters 76 void CheckParams(const wxString& label, const wxString& url, long style); 77 78 public: 79 // Send wxHyperlinkEvent and open our link in the default browser if it 80 // wasn't handled. 81 // 82 // not part of the public API but needs to be public as used by 83 // GTK+ callbacks: 84 void SendEvent(); 85 }; 86 87 // ---------------------------------------------------------------------------- 88 // wxHyperlinkEvent 89 // ---------------------------------------------------------------------------- 90 91 class WXDLLIMPEXP_FWD_CORE wxHyperlinkEvent; 92 93 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_HYPERLINK, wxHyperlinkEvent ); 94 95 // 96 // An event fired when the user clicks on the label in a hyperlink control. 97 // See HyperlinkControl for details. 98 // 99 class WXDLLIMPEXP_CORE wxHyperlinkEvent : public wxCommandEvent 100 { 101 public: wxHyperlinkEvent()102 wxHyperlinkEvent() {} wxHyperlinkEvent(wxObject * generator,wxWindowID id,const wxString & url)103 wxHyperlinkEvent(wxObject *generator, wxWindowID id, const wxString& url) 104 : wxCommandEvent(wxEVT_HYPERLINK, id), 105 m_url(url) 106 { 107 SetEventObject(generator); 108 } 109 110 // Returns the URL associated with the hyperlink control 111 // that the user clicked on. GetURL()112 wxString GetURL() const { return m_url; } SetURL(const wxString & url)113 void SetURL(const wxString &url) { m_url=url; } 114 115 // default copy ctor, assignment operator and dtor are ok Clone()116 virtual wxEvent *Clone() const wxOVERRIDE { return new wxHyperlinkEvent(*this); } 117 118 private: 119 120 // URL associated with the hyperlink control that the used clicked on. 121 wxString m_url; 122 123 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHyperlinkEvent); 124 }; 125 126 127 // ---------------------------------------------------------------------------- 128 // event types and macros 129 // ---------------------------------------------------------------------------- 130 131 typedef void (wxEvtHandler::*wxHyperlinkEventFunction)(wxHyperlinkEvent&); 132 133 #define wxHyperlinkEventHandler(func) \ 134 wxEVENT_HANDLER_CAST(wxHyperlinkEventFunction, func) 135 136 #define EVT_HYPERLINK(id, fn) \ 137 wx__DECLARE_EVT1(wxEVT_HYPERLINK, id, wxHyperlinkEventHandler(fn)) 138 139 140 #if defined(__WXGTK210__) && !defined(__WXUNIVERSAL__) 141 #include "wx/gtk/hyperlink.h" 142 // Note that the native control is only available in Unicode version under MSW. 143 #elif defined(__WXMSW__) && wxUSE_UNICODE && !defined(__WXUNIVERSAL__) 144 #include "wx/msw/hyperlink.h" 145 #else 146 #include "wx/generic/hyperlink.h" 147 148 class WXDLLIMPEXP_CORE wxHyperlinkCtrl : public wxGenericHyperlinkCtrl 149 { 150 public: wxHyperlinkCtrl()151 wxHyperlinkCtrl() { } 152 153 wxHyperlinkCtrl(wxWindow *parent, 154 wxWindowID id, 155 const wxString& label, 156 const wxString& url, 157 const wxPoint& pos = wxDefaultPosition, 158 const wxSize& size = wxDefaultSize, 159 long style = wxHL_DEFAULT_STYLE, 160 const wxString& name = wxASCII_STR(wxHyperlinkCtrlNameStr)) wxGenericHyperlinkCtrl(parent,id,label,url,pos,size,style,name)161 : wxGenericHyperlinkCtrl(parent, id, label, url, pos, size, 162 style, name) 163 { 164 } 165 166 private: 167 wxDECLARE_DYNAMIC_CLASS_NO_COPY( wxHyperlinkCtrl ); 168 }; 169 #endif 170 171 // old wxEVT_COMMAND_* constants 172 #define wxEVT_COMMAND_HYPERLINK wxEVT_HYPERLINK 173 174 #endif // wxUSE_HYPERLINKCTRL 175 176 #endif // _WX_HYPERLINK_H_ 177