1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.LinkButton;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.Button;
32 private import gtk.Widget;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 private import std.algorithm;
36 
37 
38 /**
39  * A GtkLinkButton is a #GtkButton with a hyperlink, similar to the one
40  * used by web browsers, which triggers an action when clicked. It is useful
41  * to show quick links to resources.
42  * 
43  * A link button is created by calling either gtk_link_button_new() or
44  * gtk_link_button_new_with_label(). If using the former, the URI you pass
45  * to the constructor is used as a label for the widget.
46  * 
47  * The URI bound to a GtkLinkButton can be set specifically using
48  * gtk_link_button_set_uri(), and retrieved using gtk_link_button_get_uri().
49  * 
50  * By default, GtkLinkButton calls gtk_show_uri_on_window() when the button is
51  * clicked. This behaviour can be overridden by connecting to the
52  * #GtkLinkButton::activate-link signal and returning %TRUE from the
53  * signal handler.
54  * 
55  * # CSS nodes
56  * 
57  * GtkLinkButton has a single CSS node with name button. To differentiate
58  * it from a plain #GtkButton, it gets the .link style class.
59  */
60 public class LinkButton : Button
61 {
62 	/** the main Gtk struct */
63 	protected GtkLinkButton* gtkLinkButton;
64 
65 	/** Get the main Gtk struct */
66 	public GtkLinkButton* getLinkButtonStruct(bool transferOwnership = false)
67 	{
68 		if (transferOwnership)
69 			ownedRef = false;
70 		return gtkLinkButton;
71 	}
72 
73 	/** the main Gtk struct as a void* */
74 	protected override void* getStruct()
75 	{
76 		return cast(void*)gtkLinkButton;
77 	}
78 
79 	protected override void setStruct(GObject* obj)
80 	{
81 		gtkLinkButton = cast(GtkLinkButton*)obj;
82 		super.setStruct(obj);
83 	}
84 
85 	/**
86 	 * Sets our main struct and passes it to the parent class.
87 	 */
88 	public this (GtkLinkButton* gtkLinkButton, bool ownedRef = false)
89 	{
90 		this.gtkLinkButton = gtkLinkButton;
91 		super(cast(GtkButton*)gtkLinkButton, ownedRef);
92 	}
93 
94 
95 	/** */
96 	public static GType getType()
97 	{
98 		return gtk_link_button_get_type();
99 	}
100 
101 	/**
102 	 * Creates a new #GtkLinkButton with the URI as its text.
103 	 *
104 	 * Params:
105 	 *     uri = a valid URI
106 	 *
107 	 * Returns: a new link button widget.
108 	 *
109 	 * Since: 2.10
110 	 *
111 	 * Throws: ConstructionException GTK+ fails to create the object.
112 	 */
113 	public this(string uri)
114 	{
115 		auto p = gtk_link_button_new(Str.toStringz(uri));
116 		
117 		if(p is null)
118 		{
119 			throw new ConstructionException("null returned by new");
120 		}
121 		
122 		this(cast(GtkLinkButton*) p);
123 	}
124 
125 	/**
126 	 * Creates a new #GtkLinkButton containing a label.
127 	 *
128 	 * Params:
129 	 *     uri = a valid URI
130 	 *     label = the text of the button
131 	 *
132 	 * Returns: a new link button widget.
133 	 *
134 	 * Since: 2.10
135 	 *
136 	 * Throws: ConstructionException GTK+ fails to create the object.
137 	 */
138 	public this(string uri, string label)
139 	{
140 		auto p = gtk_link_button_new_with_label(Str.toStringz(uri), Str.toStringz(label));
141 		
142 		if(p is null)
143 		{
144 			throw new ConstructionException("null returned by new_with_label");
145 		}
146 		
147 		this(cast(GtkLinkButton*) p);
148 	}
149 
150 	/**
151 	 * Retrieves the URI set using gtk_link_button_set_uri().
152 	 *
153 	 * Returns: a valid URI.  The returned string is owned by the link button
154 	 *     and should not be modified or freed.
155 	 *
156 	 * Since: 2.10
157 	 */
158 	public string getUri()
159 	{
160 		return Str.toString(gtk_link_button_get_uri(gtkLinkButton));
161 	}
162 
163 	/**
164 	 * Retrieves the “visited” state of the URI where the #GtkLinkButton
165 	 * points. The button becomes visited when it is clicked. If the URI
166 	 * is changed on the button, the “visited” state is unset again.
167 	 *
168 	 * The state may also be changed using gtk_link_button_set_visited().
169 	 *
170 	 * Returns: %TRUE if the link has been visited, %FALSE otherwise
171 	 *
172 	 * Since: 2.14
173 	 */
174 	public bool getVisited()
175 	{
176 		return gtk_link_button_get_visited(gtkLinkButton) != 0;
177 	}
178 
179 	/**
180 	 * Sets @uri as the URI where the #GtkLinkButton points. As a side-effect
181 	 * this unsets the “visited” state of the button.
182 	 *
183 	 * Params:
184 	 *     uri = a valid URI
185 	 *
186 	 * Since: 2.10
187 	 */
188 	public void setUri(string uri)
189 	{
190 		gtk_link_button_set_uri(gtkLinkButton, Str.toStringz(uri));
191 	}
192 
193 	/**
194 	 * Sets the “visited” state of the URI where the #GtkLinkButton
195 	 * points.  See gtk_link_button_get_visited() for more details.
196 	 *
197 	 * Params:
198 	 *     visited = the new “visited” state
199 	 *
200 	 * Since: 2.14
201 	 */
202 	public void setVisited(bool visited)
203 	{
204 		gtk_link_button_set_visited(gtkLinkButton, visited);
205 	}
206 
207 	protected class OnActivateLinkDelegateWrapper
208 	{
209 		static OnActivateLinkDelegateWrapper[] listeners;
210 		bool delegate(LinkButton) dlg;
211 		gulong handlerId;
212 		
213 		this(bool delegate(LinkButton) dlg)
214 		{
215 			this.dlg = dlg;
216 			this.listeners ~= this;
217 		}
218 		
219 		void remove(OnActivateLinkDelegateWrapper source)
220 		{
221 			foreach(index, wrapper; listeners)
222 			{
223 				if (wrapper.handlerId == source.handlerId)
224 				{
225 					listeners[index] = null;
226 					listeners = std.algorithm.remove(listeners, index);
227 					break;
228 				}
229 			}
230 		}
231 	}
232 
233 	/**
234 	 * The ::activate-link signal is emitted each time the #GtkLinkButton
235 	 * has been clicked.
236 	 *
237 	 * The default handler will call gtk_show_uri_on_window() with the URI stored inside
238 	 * the #GtkLinkButton:uri property.
239 	 *
240 	 * To override the default behavior, you can connect to the ::activate-link
241 	 * signal and stop the propagation of the signal by returning %TRUE from
242 	 * your handler.
243 	 */
244 	gulong addOnActivateLink(bool delegate(LinkButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
245 	{
246 		auto wrapper = new OnActivateLinkDelegateWrapper(dlg);
247 		wrapper.handlerId = Signals.connectData(
248 			this,
249 			"activate-link",
250 			cast(GCallback)&callBackActivateLink,
251 			cast(void*)wrapper,
252 			cast(GClosureNotify)&callBackActivateLinkDestroy,
253 			connectFlags);
254 		return wrapper.handlerId;
255 	}
256 	
257 	extern(C) static int callBackActivateLink(GtkLinkButton* linkbuttonStruct, OnActivateLinkDelegateWrapper wrapper)
258 	{
259 		return wrapper.dlg(wrapper.outer);
260 	}
261 	
262 	extern(C) static void callBackActivateLinkDestroy(OnActivateLinkDelegateWrapper wrapper, GClosure* closure)
263 	{
264 		wrapper.remove(wrapper);
265 	}
266 }