]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/hyperlink.cpp
Make wxWindow::HasScrollbar() respect wxScrolled::ShowScrollbars().
[wxWidgets.git] / src / gtk / hyperlink.cpp
CommitLineData
c105dda0
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/hyperlink.cpp
3// Purpose: Hyperlink control
4// Author: Francesco Montorsi
5// Created: 14/2/2007
c105dda0
VZ
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
08809d18 25#if wxUSE_HYPERLINKCTRL && defined(__WXGTK210__) && !defined(__WXUNIVERSAL__)
c105dda0
VZ
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
cc9ffc23 39static inline bool UseNative()
c105dda0
VZ
40{
41 // native gtk_link_button widget is only available in GTK+ 2.10 and later
9dc44eff
PC
42#ifdef __WXGTK3__
43 return true;
44#else
c105dda0 45 return !gtk_check_version(2, 10, 0);
9dc44eff 46#endif
c105dda0
VZ
47}
48
49// ============================================================================
50// implementation
51// ============================================================================
52
c105dda0
VZ
53// ----------------------------------------------------------------------------
54// "clicked"
55// ----------------------------------------------------------------------------
56
57extern "C" {
58static 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
70bool 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
c105dda0
VZ
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");
9ff9d30c 87 g_object_ref(m_widget);
c105dda0
VZ
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);
c105dda0
VZ
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
f4322df6 112 // the widget - thus we need to manually set it here:
c105dda0
VZ
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
121wxSize wxHyperlinkCtrl::DoGetBestSize() const
122{
123 if ( UseNative() )
124 return wxControl::DoGetBestSize();
125 return wxGenericHyperlinkCtrl::DoGetBestSize();
126}
127
8ca8714b
PC
128wxSize wxHyperlinkCtrl::DoGetBestClientSize() const
129{
130 if ( UseNative() )
131 return wxControl::DoGetBestClientSize();
132 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
133}
134
c105dda0
VZ
135void 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
147void wxHyperlinkCtrl::SetURL(const wxString &uri)
148{
149 if ( UseNative() )
e678981e 150 gtk_link_button_set_uri(GTK_LINK_BUTTON(m_widget), wxGTK_CONV(uri));
c105dda0
VZ
151 else
152 wxGenericHyperlinkCtrl::SetURL(uri);
153}
154
155wxString wxHyperlinkCtrl::GetURL() const
156{
157 if ( UseNative() )
158 {
159 const gchar *str = gtk_link_button_get_uri(GTK_LINK_BUTTON(m_widget));
b74d7c85 160 return wxString::FromUTF8(str);
c105dda0
VZ
161 }
162
163 return wxGenericHyperlinkCtrl::GetURL();
164}
165
166void 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
176wxColour wxHyperlinkCtrl::GetNormalColour() const
177{
cc9ffc23 178 wxColour ret;
c105dda0
VZ
179 if ( UseNative() )
180 {
181 GdkColor *link_color = NULL;
c105dda0
VZ
182
183 // convert GdkColor in wxColour
184 gtk_widget_style_get(m_widget, "link-color", &link_color, NULL);
185 if (link_color)
cc9ffc23 186 ret = wxColour(*link_color);
c105dda0 187 gdk_color_free (link_color);
c105dda0
VZ
188 }
189 else
cc9ffc23
PC
190 ret = wxGenericHyperlinkCtrl::GetNormalColour();
191
192 return ret;
c105dda0
VZ
193}
194
195void 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
205wxColour wxHyperlinkCtrl::GetVisitedColour() const
206{
cc9ffc23 207 wxColour ret;
c105dda0
VZ
208 if ( UseNative() )
209 {
210 GdkColor *link_color = NULL;
c105dda0
VZ
211
212 // convert GdkColor in wxColour
213 gtk_widget_style_get(m_widget, "visited-link-color", &link_color, NULL);
214 if (link_color)
cc9ffc23 215 ret = wxColour(*link_color);
c105dda0 216 gdk_color_free (link_color);
c105dda0
VZ
217 }
218 else
219 return wxGenericHyperlinkCtrl::GetVisitedColour();
cc9ffc23
PC
220
221 return ret;
c105dda0
VZ
222}
223
224void 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
234wxColour 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
245GdkWindow *wxHyperlinkCtrl::GTKGetWindow(wxArrayGdkWindows& windows) const
246{
9dc44eff 247 return UseNative() ? gtk_button_get_event_window(GTK_BUTTON(m_widget))
c105dda0
VZ
248 : wxGenericHyperlinkCtrl::GTKGetWindow(windows);
249}
250
251#endif // wxUSE_HYPERLINKCTRL && GTK+ 2.10+