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