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