hyperlink.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/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_GENERICHYPERLINKCTRL_H_
  11. #define _WX_GENERICHYPERLINKCTRL_H_
  12. // ----------------------------------------------------------------------------
  13. // wxGenericHyperlinkCtrl
  14. // ----------------------------------------------------------------------------
  15. class WXDLLIMPEXP_ADV wxGenericHyperlinkCtrl : public wxHyperlinkCtrlBase
  16. {
  17. public:
  18. // Default constructor (for two-step construction).
  19. wxGenericHyperlinkCtrl() { Init(); }
  20. // Constructor.
  21. wxGenericHyperlinkCtrl(wxWindow *parent,
  22. wxWindowID id,
  23. const wxString& label, const wxString& url,
  24. const wxPoint& pos = wxDefaultPosition,
  25. const wxSize& size = wxDefaultSize,
  26. long style = wxHL_DEFAULT_STYLE,
  27. const wxString& name = wxHyperlinkCtrlNameStr)
  28. {
  29. Init();
  30. (void) Create(parent, id, label, url, pos, size, style, name);
  31. }
  32. // Creation function (for two-step construction).
  33. bool Create(wxWindow *parent,
  34. wxWindowID id,
  35. const wxString& label, const wxString& url,
  36. const wxPoint& pos = wxDefaultPosition,
  37. const wxSize& size = wxDefaultSize,
  38. long style = wxHL_DEFAULT_STYLE,
  39. const wxString& name = wxHyperlinkCtrlNameStr);
  40. // get/set
  41. wxColour GetHoverColour() const { return m_hoverColour; }
  42. void SetHoverColour(const wxColour &colour) { m_hoverColour = colour; }
  43. wxColour GetNormalColour() const { return m_normalColour; }
  44. void SetNormalColour(const wxColour &colour);
  45. wxColour GetVisitedColour() const { return m_visitedColour; }
  46. void SetVisitedColour(const wxColour &colour);
  47. wxString GetURL() const { return m_url; }
  48. void SetURL (const wxString &url) { m_url=url; }
  49. void SetVisited(bool visited = true) { m_visited=visited; }
  50. bool GetVisited() const { return m_visited; }
  51. // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
  52. // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
  53. protected:
  54. // Helper used by this class itself and native MSW implementation that
  55. // connects OnRightUp() and OnPopUpCopy() handlers.
  56. void ConnectMenuHandlers();
  57. // event handlers
  58. // Renders the hyperlink.
  59. void OnPaint(wxPaintEvent& event);
  60. // Handle set/kill focus events (invalidate for painting focus rect)
  61. void OnFocus(wxFocusEvent& event);
  62. // Fire a HyperlinkEvent on space
  63. void OnChar(wxKeyEvent& event);
  64. // Returns the wxRect of the label of this hyperlink.
  65. // This is different from the clientsize's rectangle when
  66. // clientsize != bestsize and this rectangle is influenced
  67. // by the alignment of the label (wxHL_ALIGN_*).
  68. wxRect GetLabelRect() const;
  69. // If the click originates inside the bounding box of the label,
  70. // a flag is set so that an event will be fired when the left
  71. // button is released.
  72. void OnLeftDown(wxMouseEvent& event);
  73. // If the click both originated and finished inside the bounding box
  74. // of the label, a HyperlinkEvent is fired.
  75. void OnLeftUp(wxMouseEvent& event);
  76. void OnRightUp(wxMouseEvent& event);
  77. // Changes the cursor to a hand, if the mouse is inside the label's
  78. // bounding box.
  79. void OnMotion(wxMouseEvent& event);
  80. // Changes the cursor back to the default, if necessary.
  81. void OnLeaveWindow(wxMouseEvent& event);
  82. // handles "Copy URL" menuitem
  83. void OnPopUpCopy(wxCommandEvent& event);
  84. // overridden base class virtuals
  85. // Returns the best size for the window, which is the size needed
  86. // to display the text label.
  87. virtual wxSize DoGetBestClientSize() const;
  88. // creates a context menu with "Copy URL" menuitem
  89. virtual void DoContextMenu(const wxPoint &);
  90. private:
  91. // Common part of all ctors.
  92. void Init();
  93. // URL associated with the link. This is transmitted inside
  94. // the HyperlinkEvent fired when the user clicks on the label.
  95. wxString m_url;
  96. // Foreground colours for various link types.
  97. // NOTE: wxWindow::m_backgroundColour is used for background,
  98. // wxWindow::m_foregroundColour is used to render non-visited links
  99. wxColour m_hoverColour;
  100. wxColour m_normalColour;
  101. wxColour m_visitedColour;
  102. // True if the mouse cursor is inside the label's bounding box.
  103. bool m_rollover;
  104. // True if the link has been clicked before.
  105. bool m_visited;
  106. // True if a click is in progress (left button down) and the click
  107. // originated inside the label's bounding box.
  108. bool m_clicking;
  109. };
  110. #endif // _WX_GENERICHYPERLINKCTRL_H_