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 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
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() 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 public class LinkButton : Button
56 {
57 	/** the main Gtk struct */
58 	protected GtkLinkButton* gtkLinkButton;
59 
60 	/** Get the main Gtk struct */
61 	public GtkLinkButton* getLinkButtonStruct()
62 	{
63 		return gtkLinkButton;
64 	}
65 
66 	/** the main Gtk struct as a void* */
67 	protected override void* getStruct()
68 	{
69 		return cast(void*)gtkLinkButton;
70 	}
71 
72 	protected override void setStruct(GObject* obj)
73 	{
74 		gtkLinkButton = cast(GtkLinkButton*)obj;
75 		super.setStruct(obj);
76 	}
77 
78 	/**
79 	 * Sets our main struct and passes it to the parent class.
80 	 */
81 	public this (GtkLinkButton* gtkLinkButton, bool ownedRef = false)
82 	{
83 		this.gtkLinkButton = gtkLinkButton;
84 		super(cast(GtkButton*)gtkLinkButton, ownedRef);
85 	}
86 
87 
88 	/** */
89 	public static GType getType()
90 	{
91 		return gtk_link_button_get_type();
92 	}
93 
94 	/**
95 	 * Creates a new #GtkLinkButton with the URI as its text.
96 	 *
97 	 * Params:
98 	 *     uri = a valid URI
99 	 *
100 	 * Return: a new link button widget.
101 	 *
102 	 * Since: 2.10
103 	 *
104 	 * Throws: ConstructionException GTK+ fails to create the object.
105 	 */
106 	public this(string uri)
107 	{
108 		auto p = gtk_link_button_new(Str.toStringz(uri));
109 		
110 		if(p is null)
111 		{
112 			throw new ConstructionException("null returned by new");
113 		}
114 		
115 		this(cast(GtkLinkButton*) p);
116 	}
117 
118 	/**
119 	 * Creates a new #GtkLinkButton containing a label.
120 	 *
121 	 * Params:
122 	 *     uri = a valid URI
123 	 *     label = the text of the button
124 	 *
125 	 * Return: a new link button widget.
126 	 *
127 	 * Since: 2.10
128 	 *
129 	 * Throws: ConstructionException GTK+ fails to create the object.
130 	 */
131 	public this(string uri, string label)
132 	{
133 		auto p = gtk_link_button_new_with_label(Str.toStringz(uri), Str.toStringz(label));
134 		
135 		if(p is null)
136 		{
137 			throw new ConstructionException("null returned by new_with_label");
138 		}
139 		
140 		this(cast(GtkLinkButton*) p);
141 	}
142 
143 	/**
144 	 * Retrieves the URI set using gtk_link_button_set_uri().
145 	 *
146 	 * Return: a valid URI.  The returned string is owned by the link button
147 	 *     and should not be modified or freed.
148 	 *
149 	 * Since: 2.10
150 	 */
151 	public string getUri()
152 	{
153 		return Str.toString(gtk_link_button_get_uri(gtkLinkButton));
154 	}
155 
156 	/**
157 	 * Retrieves the “visited” state of the URI where the #GtkLinkButton
158 	 * points. The button becomes visited when it is clicked. If the URI
159 	 * is changed on the button, the “visited” state is unset again.
160 	 *
161 	 * The state may also be changed using gtk_link_button_set_visited().
162 	 *
163 	 * Return: %TRUE if the link has been visited, %FALSE otherwise
164 	 *
165 	 * Since: 2.14
166 	 */
167 	public bool getVisited()
168 	{
169 		return gtk_link_button_get_visited(gtkLinkButton) != 0;
170 	}
171 
172 	/**
173 	 * Sets @uri as the URI where the #GtkLinkButton points. As a side-effect
174 	 * this unsets the “visited” state of the button.
175 	 *
176 	 * Params:
177 	 *     uri = a valid URI
178 	 *
179 	 * Since: 2.10
180 	 */
181 	public void setUri(string uri)
182 	{
183 		gtk_link_button_set_uri(gtkLinkButton, Str.toStringz(uri));
184 	}
185 
186 	/**
187 	 * Sets the “visited” state of the URI where the #GtkLinkButton
188 	 * points.  See gtk_link_button_get_visited() for more details.
189 	 *
190 	 * Params:
191 	 *     visited = the new “visited” state
192 	 *
193 	 * Since: 2.14
194 	 */
195 	public void setVisited(bool visited)
196 	{
197 		gtk_link_button_set_visited(gtkLinkButton, visited);
198 	}
199 
200 	int[string] connectedSignals;
201 
202 	bool delegate(LinkButton)[] onActivateLinkListeners;
203 	/**
204 	 * The ::activate-link signal is emitted each time the #GtkLinkButton
205 	 * has been clicked.
206 	 *
207 	 * The default handler will call gtk_show_uri() with the URI stored inside
208 	 * the #GtkLinkButton:uri property.
209 	 *
210 	 * To override the default behavior, you can connect to the ::activate-link
211 	 * signal and stop the propagation of the signal by returning %TRUE from
212 	 * your handler.
213 	 */
214 	void addOnActivateLink(bool delegate(LinkButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
215 	{
216 		if ( "activate-link" !in connectedSignals )
217 		{
218 			Signals.connectData(
219 				this,
220 				"activate-link",
221 				cast(GCallback)&callBackActivateLink,
222 				cast(void*)this,
223 				null,
224 				connectFlags);
225 			connectedSignals["activate-link"] = 1;
226 		}
227 		onActivateLinkListeners ~= dlg;
228 	}
229 	extern(C) static int callBackActivateLink(GtkLinkButton* linkbuttonStruct, LinkButton _linkbutton)
230 	{
231 		foreach ( bool delegate(LinkButton) dlg; _linkbutton.onActivateLinkListeners )
232 		{
233 			if ( dlg(_linkbutton) )
234 			{
235 				return 1;
236 			}
237 		}
238 		
239 		return 0;
240 	}
241 }