hyperlink.h 5.7 KB

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