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