]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/hyperlink.cpp
Set missing Language: headers in PO files.
[wxWidgets.git] / src / gtk / hyperlink.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/hyperlink.cpp
3 // Purpose: Hyperlink control
4 // Author: Francesco Montorsi
5 // Created: 14/2/2007
6 // Copyright: (c) 2007 Francesco Montorsi
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // ============================================================================
11 // declarations
12 // ============================================================================
13
14 // --------------------------------------------------------------------------
15 // headers
16 // --------------------------------------------------------------------------
17
18 // For compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
20
21 #ifdef __BORLANDC__
22 #pragma hdrstop
23 #endif
24
25 #if wxUSE_HYPERLINKCTRL && defined(__WXGTK210__) && !defined(__WXUNIVERSAL__)
26
27 #include "wx/hyperlink.h"
28
29 #ifndef WX_PRECOMP
30 #endif
31
32 #include <gtk/gtk.h>
33 #include "wx/gtk/private.h"
34
35 // ----------------------------------------------------------------------------
36 // local functions
37 // ----------------------------------------------------------------------------
38
39 static inline bool UseNative()
40 {
41 // native gtk_link_button widget is only available in GTK+ 2.10 and later
42 #ifdef __WXGTK3__
43 return true;
44 #else
45 return !gtk_check_version(2, 10, 0);
46 #endif
47 }
48
49 // ============================================================================
50 // implementation
51 // ============================================================================
52
53 // ----------------------------------------------------------------------------
54 // "clicked"
55 // ----------------------------------------------------------------------------
56
57 extern "C" {
58 static void gtk_hyperlink_clicked_callback( GtkWidget *WXUNUSED(widget),
59 wxHyperlinkCtrl *linkCtrl )
60 {
61 // send the event
62 linkCtrl->SendEvent();
63 }
64 }
65
66 // ----------------------------------------------------------------------------
67 // wxHyperlinkCtrl
68 // ----------------------------------------------------------------------------
69
70 bool wxHyperlinkCtrl::Create(wxWindow *parent, wxWindowID id,
71 const wxString& label, const wxString& url, const wxPoint& pos,
72 const wxSize& size, long style, const wxString& name)
73 {
74 if ( UseNative() )
75 {
76 // do validation checks:
77 CheckParams(label, url, style);
78
79 if (!PreCreation( parent, pos, size ) ||
80 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
81 {
82 wxFAIL_MSG( wxT("wxHyperlinkCtrl creation failed") );
83 return false;
84 }
85
86 m_widget = gtk_link_button_new("asdfsaf asdfdsaf asdfdsa");
87 g_object_ref(m_widget);
88
89 // alignment
90 float x_alignment = 0.5;
91 if (HasFlag(wxHL_ALIGN_LEFT))
92 x_alignment = 0.0;
93 else if (HasFlag(wxHL_ALIGN_RIGHT))
94 x_alignment = 1.0;
95 gtk_button_set_alignment(GTK_BUTTON(m_widget), x_alignment, 0.5);
96
97 // set to non empty strings both the url and the label
98 SetURL(url.empty() ? label : url);
99 SetLabel(label.empty() ? url : label);
100
101 // our signal handlers:
102 g_signal_connect_after (m_widget, "clicked",
103 G_CALLBACK (gtk_hyperlink_clicked_callback),
104 this);
105
106 m_parent->DoAddChild( this );
107
108 PostCreation(size);
109
110 // wxWindowGTK will connect to the enter_notify and leave_notify GTK+ signals
111 // thus overriding GTK+'s internal signal handlers which set the cursor of
112 // the widget - thus we need to manually set it here:
113 SetCursor(wxCursor(wxCURSOR_HAND));
114 }
115 else
116 return wxGenericHyperlinkCtrl::Create(parent, id, label, url, pos, size, style, name);
117
118 return true;
119 }
120
121 wxSize wxHyperlinkCtrl::DoGetBestSize() const
122 {
123 if ( UseNative() )
124 return wxControl::DoGetBestSize();
125 return wxGenericHyperlinkCtrl::DoGetBestSize();
126 }
127
128 wxSize wxHyperlinkCtrl::DoGetBestClientSize() const
129 {
130 if ( UseNative() )
131 return wxControl::DoGetBestClientSize();
132 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
133 }
134
135 void wxHyperlinkCtrl::SetLabel(const wxString &label)
136 {
137 if ( UseNative() )
138 {
139 wxControl::SetLabel(label);
140 const wxString labelGTK = GTKConvertMnemonics(label);
141 gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK));
142 }
143 else
144 wxGenericHyperlinkCtrl::SetLabel(label);
145 }
146
147 void wxHyperlinkCtrl::SetURL(const wxString &uri)
148 {
149 if ( UseNative() )
150 gtk_link_button_set_uri(GTK_LINK_BUTTON(m_widget), wxGTK_CONV(uri));
151 else
152 wxGenericHyperlinkCtrl::SetURL(uri);
153 }
154
155 wxString wxHyperlinkCtrl::GetURL() const
156 {
157 if ( UseNative() )
158 {
159 const gchar *str = gtk_link_button_get_uri(GTK_LINK_BUTTON(m_widget));
160 return wxString::FromUTF8(str);
161 }
162
163 return wxGenericHyperlinkCtrl::GetURL();
164 }
165
166 void wxHyperlinkCtrl::SetNormalColour(const wxColour &colour)
167 {
168 if ( UseNative() )
169 {
170 // simply do nothing: GTK+ does not allow us to change it :(
171 }
172 else
173 wxGenericHyperlinkCtrl::SetNormalColour(colour);
174 }
175
176 wxColour wxHyperlinkCtrl::GetNormalColour() const
177 {
178 wxColour ret;
179 if ( UseNative() )
180 {
181 GdkColor *link_color = NULL;
182
183 // convert GdkColor in wxColour
184 gtk_widget_style_get(m_widget, "link-color", &link_color, NULL);
185 if (link_color)
186 ret = wxColour(*link_color);
187 gdk_color_free (link_color);
188 }
189 else
190 ret = wxGenericHyperlinkCtrl::GetNormalColour();
191
192 return ret;
193 }
194
195 void wxHyperlinkCtrl::SetVisitedColour(const wxColour &colour)
196 {
197 if ( UseNative() )
198 {
199 // simply do nothing: GTK+ does not allow us to change it :(
200 }
201 else
202 wxGenericHyperlinkCtrl::SetVisitedColour(colour);
203 }
204
205 wxColour wxHyperlinkCtrl::GetVisitedColour() const
206 {
207 wxColour ret;
208 if ( UseNative() )
209 {
210 GdkColor *link_color = NULL;
211
212 // convert GdkColor in wxColour
213 gtk_widget_style_get(m_widget, "visited-link-color", &link_color, NULL);
214 if (link_color)
215 ret = wxColour(*link_color);
216 gdk_color_free (link_color);
217 }
218 else
219 return wxGenericHyperlinkCtrl::GetVisitedColour();
220
221 return ret;
222 }
223
224 void wxHyperlinkCtrl::SetHoverColour(const wxColour &colour)
225 {
226 if ( UseNative() )
227 {
228 // simply do nothing: GTK+ does not allow us to change it :(
229 }
230 else
231 wxGenericHyperlinkCtrl::SetHoverColour(colour);
232 }
233
234 wxColour wxHyperlinkCtrl::GetHoverColour() const
235 {
236 if ( UseNative() )
237 {
238 // hover colour == normal colour for native GTK+ widget
239 return GetNormalColour();
240 }
241
242 return wxGenericHyperlinkCtrl::GetHoverColour();
243 }
244
245 GdkWindow *wxHyperlinkCtrl::GTKGetWindow(wxArrayGdkWindows& windows) const
246 {
247 return UseNative() ? gtk_button_get_event_window(GTK_BUTTON(m_widget))
248 : wxGenericHyperlinkCtrl::GTKGetWindow(windows);
249 }
250
251 #endif // wxUSE_HYPERLINKCTRL && GTK+ 2.10+