]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/hyperlink.h
fix infinite recursion typo in operator!=() (patch 1665591)
[wxWidgets.git] / include / wx / generic / hyperlink.h
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 // RCS-ID: $Id$
8 // Copyright: (c) 2005 David Norris
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __GENERICHYPERLINKCTRLH__
13 #define __GENERICHYPERLINKCTRLH__
14
15 #include "wx/defs.h"
16 #include "wx/control.h"
17
18
19 // ----------------------------------------------------------------------------
20 // wxGenericHyperlinkCtrl
21 // ----------------------------------------------------------------------------
22
23 class WXDLLIMPEXP_ADV wxGenericHyperlinkCtrl : public wxHyperlinkCtrlBase
24 {
25 public:
26 // Default constructor (for two-step construction).
27 wxGenericHyperlinkCtrl() { }
28
29 // Constructor.
30 wxGenericHyperlinkCtrl(wxWindow *parent,
31 wxWindowID id,
32 const wxString& label, const wxString& url,
33 const wxPoint& pos = wxDefaultPosition,
34 const wxSize& size = wxDefaultSize,
35 long style = wxHL_DEFAULT_STYLE,
36 const wxString& name = wxHyperlinkCtrlNameStr)
37 {
38 (void)Create(parent, id, label, url, pos, size, style, name);
39 }
40
41 // Creation function (for two-step construction).
42 bool Create(wxWindow *parent,
43 wxWindowID id,
44 const wxString& label, const wxString& url,
45 const wxPoint& pos = wxDefaultPosition,
46 const wxSize& size = wxDefaultSize,
47 long style = wxHL_DEFAULT_STYLE,
48 const wxString& name = wxHyperlinkCtrlNameStr);
49
50
51 // get/set
52 wxColour GetHoverColour() const { return m_hoverColour; }
53 void SetHoverColour(const wxColour &colour) { m_hoverColour = colour; }
54
55 wxColour GetNormalColour() const { return m_normalColour; }
56 void SetNormalColour(const wxColour &colour);
57
58 wxColour GetVisitedColour() const { return m_visitedColour; }
59 void SetVisitedColour(const wxColour &colour);
60
61 wxString GetURL() const { return m_url; }
62 void SetURL (const wxString &url) { m_url=url; }
63
64 void SetVisited(bool visited = true) { m_visited=visited; }
65 bool GetVisited() const { return m_visited; }
66
67 // NOTE: also wxWindow::Set/GetLabel, wxWindow::Set/GetBackgroundColour,
68 // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important !
69
70
71 protected:
72 // event handlers
73
74 // Renders the hyperlink.
75 void OnPaint(wxPaintEvent& event);
76
77 // Returns the wxRect of the label of this hyperlink.
78 // This is different from the clientsize's rectangle when
79 // clientsize != bestsize and this rectangle is influenced
80 // by the alignment of the label (wxHL_ALIGN_*).
81 wxRect GetLabelRect() const;
82
83 // If the click originates inside the bounding box of the label,
84 // a flag is set so that an event will be fired when the left
85 // button is released.
86 void OnLeftDown(wxMouseEvent& event);
87
88 // If the click both originated and finished inside the bounding box
89 // of the label, a HyperlinkEvent is fired.
90 void OnLeftUp(wxMouseEvent& event);
91 void OnRightUp(wxMouseEvent& event);
92
93 // Changes the cursor to a hand, if the mouse is inside the label's
94 // bounding box.
95 void OnMotion(wxMouseEvent& event);
96
97 // Changes the cursor back to the default, if necessary.
98 void OnLeaveWindow(wxMouseEvent& event);
99
100 // handles "Copy URL" menuitem
101 void OnPopUpCopy(wxCommandEvent& event);
102
103 // Refreshes the control to update label's position if necessary
104 void OnSize(wxSizeEvent& event);
105
106
107 // overridden base class virtuals
108
109 // Returns the best size for the window, which is the size needed
110 // to display the text label.
111 virtual wxSize DoGetBestSize() const;
112
113 // creates a context menu with "Copy URL" menuitem
114 virtual void DoContextMenu(const wxPoint &);
115
116 private:
117 // URL associated with the link. This is transmitted inside
118 // the HyperlinkEvent fired when the user clicks on the label.
119 wxString m_url;
120
121 // Foreground colours for various link types.
122 // NOTE: wxWindow::m_backgroundColour is used for background,
123 // wxWindow::m_foregroundColour is used to render non-visited links
124 wxColour m_hoverColour;
125 wxColour m_normalColour;
126 wxColour m_visitedColour;
127
128 // True if the mouse cursor is inside the label's bounding box.
129 bool m_rollover;
130
131 // True if the link has been clicked before.
132 bool m_visited;
133
134 // True if a click is in progress (left button down) and the click
135 // originated inside the label's bounding box.
136 bool m_clicking;
137
138 private:
139 DECLARE_DYNAMIC_CLASS(wxGenericHyperlinkCtrl)
140 };
141
142 #endif // __GENERICHYPERLINKCTRLH__