]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/hyperlink.cpp
streamlining slider, scroller, spinbutton for osx carbon and cocoa
[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
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
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);
10bd1f7d 88 gtk_widget_show(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);
110 SetInitialSize(size);
111
112 // wxWindowGTK will connect to the enter_notify and leave_notify GTK+ signals
113 // thus overriding GTK+'s internal signal handlers which set the cursor of
f4322df6 114 // the widget - thus we need to manually set it here:
c105dda0
VZ
115 SetCursor(wxCursor(wxCURSOR_HAND));
116 }
117 else
118 return wxGenericHyperlinkCtrl::Create(parent, id, label, url, pos, size, style, name);
119
120 return true;
121}
122
123wxSize wxHyperlinkCtrl::DoGetBestSize() const
124{
125 if ( UseNative() )
126 return wxControl::DoGetBestSize();
127 return wxGenericHyperlinkCtrl::DoGetBestSize();
128}
129
130void wxHyperlinkCtrl::SetLabel(const wxString &label)
131{
132 if ( UseNative() )
133 {
134 wxControl::SetLabel(label);
135 const wxString labelGTK = GTKConvertMnemonics(label);
136 gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK));
137 }
138 else
139 wxGenericHyperlinkCtrl::SetLabel(label);
140}
141
142void wxHyperlinkCtrl::SetURL(const wxString &uri)
143{
144 if ( UseNative() )
e678981e 145 gtk_link_button_set_uri(GTK_LINK_BUTTON(m_widget), wxGTK_CONV(uri));
c105dda0
VZ
146 else
147 wxGenericHyperlinkCtrl::SetURL(uri);
148}
149
150wxString wxHyperlinkCtrl::GetURL() const
151{
152 if ( UseNative() )
153 {
154 const gchar *str = gtk_link_button_get_uri(GTK_LINK_BUTTON(m_widget));
86501081 155 return wxString(str, *wxConvFileName);
c105dda0
VZ
156 }
157
158 return wxGenericHyperlinkCtrl::GetURL();
159}
160
161void wxHyperlinkCtrl::SetNormalColour(const wxColour &colour)
162{
163 if ( UseNative() )
164 {
165 // simply do nothing: GTK+ does not allow us to change it :(
166 }
167 else
168 wxGenericHyperlinkCtrl::SetNormalColour(colour);
169}
170
171wxColour wxHyperlinkCtrl::GetNormalColour() const
172{
cc9ffc23 173 wxColour ret;
c105dda0
VZ
174 if ( UseNative() )
175 {
176 GdkColor *link_color = NULL;
c105dda0
VZ
177
178 // convert GdkColor in wxColour
179 gtk_widget_style_get(m_widget, "link-color", &link_color, NULL);
180 if (link_color)
cc9ffc23 181 ret = wxColour(*link_color);
c105dda0 182 gdk_color_free (link_color);
c105dda0
VZ
183 }
184 else
cc9ffc23
PC
185 ret = wxGenericHyperlinkCtrl::GetNormalColour();
186
187 return ret;
c105dda0
VZ
188}
189
190void wxHyperlinkCtrl::SetVisitedColour(const wxColour &colour)
191{
192 if ( UseNative() )
193 {
194 // simply do nothing: GTK+ does not allow us to change it :(
195 }
196 else
197 wxGenericHyperlinkCtrl::SetVisitedColour(colour);
198}
199
200wxColour wxHyperlinkCtrl::GetVisitedColour() const
201{
cc9ffc23 202 wxColour ret;
c105dda0
VZ
203 if ( UseNative() )
204 {
205 GdkColor *link_color = NULL;
c105dda0
VZ
206
207 // convert GdkColor in wxColour
208 gtk_widget_style_get(m_widget, "visited-link-color", &link_color, NULL);
209 if (link_color)
cc9ffc23 210 ret = wxColour(*link_color);
c105dda0 211 gdk_color_free (link_color);
c105dda0
VZ
212 }
213 else
214 return wxGenericHyperlinkCtrl::GetVisitedColour();
cc9ffc23
PC
215
216 return ret;
c105dda0
VZ
217}
218
219void wxHyperlinkCtrl::SetHoverColour(const wxColour &colour)
220{
221 if ( UseNative() )
222 {
223 // simply do nothing: GTK+ does not allow us to change it :(
224 }
225 else
226 wxGenericHyperlinkCtrl::SetHoverColour(colour);
227}
228
229wxColour wxHyperlinkCtrl::GetHoverColour() const
230{
231 if ( UseNative() )
232 {
233 // hover colour == normal colour for native GTK+ widget
234 return GetNormalColour();
235 }
236
237 return wxGenericHyperlinkCtrl::GetHoverColour();
238}
239
240GdkWindow *wxHyperlinkCtrl::GTKGetWindow(wxArrayGdkWindows& windows) const
241{
242 return UseNative() ? GTK_BUTTON(m_widget)->event_window
243 : wxGenericHyperlinkCtrl::GTKGetWindow(windows);
244}
245
246#endif // wxUSE_HYPERLINKCTRL && GTK+ 2.10+