hyperlink.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: hyperlink.h
  3. // Purpose: interface of wxHyperlinkEvent
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxHL_CONTEXTMENU 0x0001
  8. #define wxHL_ALIGN_LEFT 0x0002
  9. #define wxHL_ALIGN_RIGHT 0x0004
  10. #define wxHL_ALIGN_CENTRE 0x0008
  11. #define wxHL_DEFAULT_STYLE (wxHL_CONTEXTMENU|wxNO_BORDER|wxHL_ALIGN_CENTRE)
  12. /**
  13. @class wxHyperlinkEvent
  14. This event class is used for the events generated by wxHyperlinkCtrl.
  15. @beginEventTable{wxHyperlinkEvent}
  16. @event{EVT_HYPERLINK(id, func)}
  17. User clicked on an hyperlink.
  18. @endEventTable
  19. @library{wxadv}
  20. @category{events}
  21. */
  22. class wxHyperlinkEvent : public wxCommandEvent
  23. {
  24. public:
  25. /**
  26. The constructor is not normally used by the user code.
  27. */
  28. wxHyperlinkEvent(wxObject* generator, int id, const wxString& url);
  29. /**
  30. Returns the URL of the hyperlink where the user has just clicked.
  31. */
  32. wxString GetURL() const;
  33. /**
  34. Sets the URL associated with the event.
  35. */
  36. void SetURL(const wxString& url);
  37. };
  38. wxEventType wxEVT_HYPERLINK;
  39. /**
  40. @class wxHyperlinkCtrl
  41. This class shows a static text element which links to an URL.
  42. Appearance and behaviour is completely customizable.
  43. In fact, when the user clicks on the hyperlink, a wxHyperlinkEvent is
  44. sent but if that event is not handled (or it's skipped; see wxEvent::Skip),
  45. then a call to wxLaunchDefaultBrowser() is done with the hyperlink's URL.
  46. Note that standard wxWindow functions like wxWindow::SetBackgroundColour,
  47. wxWindow::SetFont, wxWindow::SetCursor, wxWindow::SetLabel can be used to
  48. customize appearance of the hyperlink.
  49. @beginStyleTable
  50. @style{wxHL_ALIGN_LEFT}
  51. Align the text to the left.
  52. @style{wxHL_ALIGN_RIGHT}
  53. Align the text to the right. This style is not supported under
  54. Windows XP but is supported under all the other Windows versions.
  55. @style{wxHL_ALIGN_CENTRE}
  56. Center the text (horizontally). This style is not supported by the
  57. native MSW implementation used under Windows XP and later.
  58. @style{wxHL_CONTEXTMENU}
  59. Pop up a context menu when the hyperlink is right-clicked. The
  60. context menu contains a "Copy URL" menu item which is automatically
  61. handled by the hyperlink and which just copies in the clipboard the
  62. URL (not the label) of the control.
  63. @style{wxHL_DEFAULT_STYLE}
  64. The default style for wxHyperlinkCtrl:
  65. wxBORDER_NONE|wxHL_CONTEXTMENU|wxHL_ALIGN_CENTRE.
  66. @endStyleTable
  67. @beginEventEmissionTable{wxHyperlinkEvent}
  68. @event{EVT_HYPERLINK(id, func)}
  69. The hyperlink was (left) clicked. If this event is not handled in user's
  70. code (or it's skipped; see wxEvent::Skip), then a call to wxLaunchDefaultBrowser
  71. is done with the hyperlink's URL.
  72. @endEventTable
  73. Currently this class is implemented using native support in wxGTK and wxMSW
  74. (under Windows XP and later only) and a generic version is used by the
  75. other ports.
  76. @library{wxadv}
  77. @category{ctrl}
  78. @appearance{hyperlinkctrl}
  79. @see wxURL, wxHyperlinkEvent
  80. */
  81. class wxHyperlinkCtrl : public wxControl
  82. {
  83. public:
  84. wxHyperlinkCtrl();
  85. /**
  86. Constructor. See Create() for more info.
  87. */
  88. wxHyperlinkCtrl(wxWindow* parent, wxWindowID id,
  89. const wxString& label,
  90. const wxString& url,
  91. const wxPoint& pos = wxDefaultPosition,
  92. const wxSize& size = wxDefaultSize,
  93. long style = wxHL_DEFAULT_STYLE,
  94. const wxString& name = wxHyperlinkCtrlNameStr);
  95. /**
  96. Creates the hyperlink control.
  97. @param parent
  98. Parent window. Must not be @NULL.
  99. @param id
  100. Window identifier. A value of wxID_ANY indicates a default value.
  101. @param label
  102. The label of the hyperlink.
  103. @param url
  104. The URL associated with the given label.
  105. @param pos
  106. Window position.
  107. @param size
  108. Window size.
  109. If the wxDefaultSize is specified then the window is sized appropriately.
  110. @param style
  111. Window style. See wxHyperlinkCtrl.
  112. @param name
  113. Window name.
  114. */
  115. bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
  116. const wxString& url, const wxPoint& pos = wxDefaultPosition,
  117. const wxSize& size = wxDefaultSize,
  118. long style = wxHL_DEFAULT_STYLE,
  119. const wxString& name = wxHyperlinkCtrlNameStr);
  120. /**
  121. Returns the colour used to print the label of the hyperlink when the mouse is
  122. over the control.
  123. */
  124. virtual wxColour GetHoverColour() const;
  125. /**
  126. Returns the colour used to print the label when the link has never been clicked
  127. before (i.e.\ the link has not been @e visited) and the mouse is not over the control.
  128. */
  129. virtual wxColour GetNormalColour() const;
  130. /**
  131. Returns the URL associated with the hyperlink.
  132. */
  133. virtual wxString GetURL() const;
  134. /**
  135. Returns @true if the hyperlink has already been clicked by the user at least
  136. one time.
  137. */
  138. virtual bool GetVisited() const = 0;
  139. /**
  140. Returns the colour used to print the label when the mouse is not over the
  141. control and the link has already been clicked before (i.e.\ the link has
  142. been @e visited).
  143. */
  144. virtual wxColour GetVisitedColour() const;
  145. /**
  146. Sets the colour used to print the label of the hyperlink when the mouse is over
  147. the control.
  148. */
  149. virtual void SetHoverColour(const wxColour& colour);
  150. /**
  151. Sets the colour used to print the label when the link has never been clicked before
  152. (i.e.\ the link has not been @e visited) and the mouse is not over the control.
  153. */
  154. virtual void SetNormalColour(const wxColour& colour);
  155. /**
  156. Sets the URL associated with the hyperlink.
  157. */
  158. virtual void SetURL(const wxString& url);
  159. /**
  160. Marks the hyperlink as visited (see wxHyperlinkCtrl::SetVisitedColour).
  161. */
  162. virtual void SetVisited(bool visited = true) = 0;
  163. /**
  164. Sets the colour used to print the label when the mouse is not over the control
  165. and the link has already been clicked before (i.e.\ the link has been @e visited).
  166. */
  167. virtual void SetVisitedColour(const wxColour& colour);
  168. };