]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/hyperlink.cpp
Don't create GtkScrolledWindow if neither wxHSCROLL
[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
26#if wxUSE_HYPERLINKCTRL && defined(__WXGTK210__)
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
43 return !gtk_check_version(2, 10, 0);
44}
45
46// ============================================================================
47// implementation
48// ============================================================================
49
50IMPLEMENT_DYNAMIC_CLASS(wxHyperlinkCtrl, wxGenericHyperlinkCtrl)
51
52
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
79 m_needParent = true;
c105dda0
VZ
80
81 if (!PreCreation( parent, pos, size ) ||
82 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
83 {
84 wxFAIL_MSG( wxT("wxHyperlinkCtrl creation failed") );
85 return false;
86 }
87
88 m_widget = gtk_link_button_new("asdfsaf asdfdsaf asdfdsa");
89 gtk_widget_show( GTK_WIDGET(m_widget) );
90
91 // alignment
92 float x_alignment = 0.5;
93 if (HasFlag(wxHL_ALIGN_LEFT))
94 x_alignment = 0.0;
95 else if (HasFlag(wxHL_ALIGN_RIGHT))
96 x_alignment = 1.0;
97 gtk_button_set_alignment(GTK_BUTTON(m_widget), x_alignment, 0.5);
98
99 // set to non empty strings both the url and the label
100 SetURL(url.empty() ? label : url);
101 SetLabel(label.empty() ? url : label);
102
103 // our signal handlers:
104 g_signal_connect_after (m_widget, "clicked",
105 G_CALLBACK (gtk_hyperlink_clicked_callback),
106 this);
107
108 m_parent->DoAddChild( this );
109
110 PostCreation(size);
111 SetInitialSize(size);
112
113 // wxWindowGTK will connect to the enter_notify and leave_notify GTK+ signals
114 // thus overriding GTK+'s internal signal handlers which set the cursor of
f4322df6 115 // the widget - thus we need to manually set it here:
c105dda0
VZ
116 SetCursor(wxCursor(wxCURSOR_HAND));
117 }
118 else
119 return wxGenericHyperlinkCtrl::Create(parent, id, label, url, pos, size, style, name);
120
121 return true;
122}
123
124wxSize wxHyperlinkCtrl::DoGetBestSize() const
125{
126 if ( UseNative() )
127 return wxControl::DoGetBestSize();
128 return wxGenericHyperlinkCtrl::DoGetBestSize();
129}
130
131void wxHyperlinkCtrl::SetLabel(const wxString &label)
132{
133 if ( UseNative() )
134 {
135 wxControl::SetLabel(label);
136 const wxString labelGTK = GTKConvertMnemonics(label);
137 gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK));
138 }
139 else
140 wxGenericHyperlinkCtrl::SetLabel(label);
141}
142
143void wxHyperlinkCtrl::SetURL(const wxString &uri)
144{
145 if ( UseNative() )
e678981e 146 gtk_link_button_set_uri(GTK_LINK_BUTTON(m_widget), wxGTK_CONV(uri));
c105dda0
VZ
147 else
148 wxGenericHyperlinkCtrl::SetURL(uri);
149}
150
151wxString wxHyperlinkCtrl::GetURL() const
152{
153 if ( UseNative() )
154 {
155 const gchar *str = gtk_link_button_get_uri(GTK_LINK_BUTTON(m_widget));
156 return wxConvFileName->cMB2WX(str);
157 }
158
159 return wxGenericHyperlinkCtrl::GetURL();
160}
161
162void wxHyperlinkCtrl::SetNormalColour(const wxColour &colour)
163{
164 if ( UseNative() )
165 {
166 // simply do nothing: GTK+ does not allow us to change it :(
167 }
168 else
169 wxGenericHyperlinkCtrl::SetNormalColour(colour);
170}
171
172wxColour wxHyperlinkCtrl::GetNormalColour() const
173{
cc9ffc23 174 wxColour ret;
c105dda0
VZ
175 if ( UseNative() )
176 {
177 GdkColor *link_color = NULL;
c105dda0
VZ
178
179 // convert GdkColor in wxColour
180 gtk_widget_style_get(m_widget, "link-color", &link_color, NULL);
181 if (link_color)
cc9ffc23 182 ret = wxColour(*link_color);
c105dda0 183 gdk_color_free (link_color);
c105dda0
VZ
184 }
185 else
cc9ffc23
PC
186 ret = wxGenericHyperlinkCtrl::GetNormalColour();
187
188 return ret;
c105dda0
VZ
189}
190
191void wxHyperlinkCtrl::SetVisitedColour(const wxColour &colour)
192{
193 if ( UseNative() )
194 {
195 // simply do nothing: GTK+ does not allow us to change it :(
196 }
197 else
198 wxGenericHyperlinkCtrl::SetVisitedColour(colour);
199}
200
201wxColour wxHyperlinkCtrl::GetVisitedColour() const
202{
cc9ffc23 203 wxColour ret;
c105dda0
VZ
204 if ( UseNative() )
205 {
206 GdkColor *link_color = NULL;
c105dda0
VZ
207
208 // convert GdkColor in wxColour
209 gtk_widget_style_get(m_widget, "visited-link-color", &link_color, NULL);
210 if (link_color)
cc9ffc23 211 ret = wxColour(*link_color);
c105dda0 212 gdk_color_free (link_color);
c105dda0
VZ
213 }
214 else
215 return wxGenericHyperlinkCtrl::GetVisitedColour();
cc9ffc23
PC
216
217 return ret;
c105dda0
VZ
218}
219
220void wxHyperlinkCtrl::SetHoverColour(const wxColour &colour)
221{
222 if ( UseNative() )
223 {
224 // simply do nothing: GTK+ does not allow us to change it :(
225 }
226 else
227 wxGenericHyperlinkCtrl::SetHoverColour(colour);
228}
229
230wxColour wxHyperlinkCtrl::GetHoverColour() const
231{
232 if ( UseNative() )
233 {
234 // hover colour == normal colour for native GTK+ widget
235 return GetNormalColour();
236 }
237
238 return wxGenericHyperlinkCtrl::GetHoverColour();
239}
240
241GdkWindow *wxHyperlinkCtrl::GTKGetWindow(wxArrayGdkWindows& windows) const
242{
243 return UseNative() ? GTK_BUTTON(m_widget)->event_window
244 : wxGenericHyperlinkCtrl::GTKGetWindow(windows);
245}
246
247#endif // wxUSE_HYPERLINKCTRL && GTK+ 2.10+