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 atk.Hyperlink;
26 
27 private import atk.ActionIF;
28 private import atk.ActionT;
29 private import atk.ObjectAtk;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtkc.atk;
34 public  import gtkc.atktypes;
35 public  import gtkc.gdktypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * An ATK object which encapsulates a link or set of links (for
41  * instance in the case of client-side image maps) in a hypertext
42  * document.  It may implement the AtkAction interface.  AtkHyperlink
43  * may also be used to refer to inline embedded content, since it
44  * allows specification of a start and end offset within the host
45  * AtkHypertext object.
46  */
47 public class Hyperlink : ObjectG, ActionIF
48 {
49 	/** the main Gtk struct */
50 	protected AtkHyperlink* atkHyperlink;
51 
52 	/** Get the main Gtk struct */
53 	public AtkHyperlink* getHyperlinkStruct()
54 	{
55 		return atkHyperlink;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected override void* getStruct()
60 	{
61 		return cast(void*)atkHyperlink;
62 	}
63 
64 	protected override void setStruct(GObject* obj)
65 	{
66 		atkHyperlink = cast(AtkHyperlink*)obj;
67 		super.setStruct(obj);
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (AtkHyperlink* atkHyperlink, bool ownedRef = false)
74 	{
75 		this.atkHyperlink = atkHyperlink;
76 		super(cast(GObject*)atkHyperlink, ownedRef);
77 	}
78 
79 	// add the Action capabilities
80 	mixin ActionT!(AtkHyperlink);
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return atk_hyperlink_get_type();
87 	}
88 
89 	/**
90 	 * Gets the index with the hypertext document at which this link ends.
91 	 *
92 	 * Return: the index with the hypertext document at which this link ends
93 	 */
94 	public int getEndIndex()
95 	{
96 		return atk_hyperlink_get_end_index(atkHyperlink);
97 	}
98 
99 	/**
100 	 * Gets the number of anchors associated with this hyperlink.
101 	 *
102 	 * Return: the number of anchors associated with this hyperlink
103 	 */
104 	public int getNAnchors()
105 	{
106 		return atk_hyperlink_get_n_anchors(atkHyperlink);
107 	}
108 
109 	/**
110 	 * Returns the item associated with this hyperlinks nth anchor.
111 	 * For instance, the returned #AtkObject will implement #AtkText
112 	 * if @link_ is a text hyperlink, #AtkImage if @link_ is an image
113 	 * hyperlink etc.
114 	 *
115 	 * Multiple anchors are primarily used by client-side image maps.
116 	 *
117 	 * Params:
118 	 *     i = a (zero-index) integer specifying the desired anchor
119 	 *
120 	 * Return: an #AtkObject associated with this hyperlinks
121 	 *     i-th anchor
122 	 */
123 	public ObjectAtk getObject(int i)
124 	{
125 		auto p = atk_hyperlink_get_object(atkHyperlink, i);
126 		
127 		if(p is null)
128 		{
129 			return null;
130 		}
131 		
132 		return ObjectG.getDObject!(ObjectAtk)(cast(AtkObject*) p);
133 	}
134 
135 	/**
136 	 * Gets the index with the hypertext document at which this link begins.
137 	 *
138 	 * Return: the index with the hypertext document at which this link begins
139 	 */
140 	public int getStartIndex()
141 	{
142 		return atk_hyperlink_get_start_index(atkHyperlink);
143 	}
144 
145 	/**
146 	 * Get a the URI associated with the anchor specified
147 	 * by @i of @link_.
148 	 *
149 	 * Multiple anchors are primarily used by client-side image maps.
150 	 *
151 	 * Params:
152 	 *     i = a (zero-index) integer specifying the desired anchor
153 	 *
154 	 * Return: a string specifying the URI
155 	 */
156 	public string getUri(int i)
157 	{
158 		auto retStr = atk_hyperlink_get_uri(atkHyperlink, i);
159 		
160 		scope(exit) Str.freeString(retStr);
161 		return Str.toString(retStr);
162 	}
163 
164 	/**
165 	 * Indicates whether the link currently displays some or all of its
166 	 * content inline.  Ordinary HTML links will usually return
167 	 * %FALSE, but an inline <src> HTML element will return
168 	 * %TRUE.
169 	 *
170 	 * Return: whether or not this link displays its content inline.
171 	 */
172 	public bool isInline()
173 	{
174 		return atk_hyperlink_is_inline(atkHyperlink) != 0;
175 	}
176 
177 	/**
178 	 * Determines whether this AtkHyperlink is selected
179 	 *
180 	 * Deprecated: Please use ATK_STATE_FOCUSABLE for all links,
181 	 * and ATK_STATE_FOCUSED for focused links.
182 	 *
183 	 * Return: True if the AtkHyperlink is selected, False otherwise
184 	 *
185 	 * Since: 1.4
186 	 */
187 	public bool isSelectedLink()
188 	{
189 		return atk_hyperlink_is_selected_link(atkHyperlink) != 0;
190 	}
191 
192 	/**
193 	 * Since the document that a link is associated with may have changed
194 	 * this method returns %TRUE if the link is still valid (with
195 	 * respect to the document it references) and %FALSE otherwise.
196 	 *
197 	 * Return: whether or not this link is still valid
198 	 */
199 	public bool isValid()
200 	{
201 		return atk_hyperlink_is_valid(atkHyperlink) != 0;
202 	}
203 
204 	protected class OnLinkActivatedDelegateWrapper
205 	{
206 		void delegate(Hyperlink) dlg;
207 		gulong handlerId;
208 		ConnectFlags flags;
209 		this(void delegate(Hyperlink) dlg, gulong handlerId, ConnectFlags flags)
210 		{
211 			this.dlg = dlg;
212 			this.handlerId = handlerId;
213 			this.flags = flags;
214 		}
215 	}
216 	protected OnLinkActivatedDelegateWrapper[] onLinkActivatedListeners;
217 
218 	/**
219 	 * The signal link-activated is emitted when a link is activated.
220 	 */
221 	gulong addOnLinkActivated(void delegate(Hyperlink) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
222 	{
223 		onLinkActivatedListeners ~= new OnLinkActivatedDelegateWrapper(dlg, 0, connectFlags);
224 		onLinkActivatedListeners[onLinkActivatedListeners.length - 1].handlerId = Signals.connectData(
225 			this,
226 			"link-activated",
227 			cast(GCallback)&callBackLinkActivated,
228 			cast(void*)onLinkActivatedListeners[onLinkActivatedListeners.length - 1],
229 			cast(GClosureNotify)&callBackLinkActivatedDestroy,
230 			connectFlags);
231 		return onLinkActivatedListeners[onLinkActivatedListeners.length - 1].handlerId;
232 	}
233 	
234 	extern(C) static void callBackLinkActivated(AtkHyperlink* hyperlinkStruct,OnLinkActivatedDelegateWrapper wrapper)
235 	{
236 		wrapper.dlg(wrapper.outer);
237 	}
238 	
239 	extern(C) static void callBackLinkActivatedDestroy(OnLinkActivatedDelegateWrapper wrapper, GClosure* closure)
240 	{
241 		wrapper.outer.internalRemoveOnLinkActivated(wrapper);
242 	}
243 
244 	protected void internalRemoveOnLinkActivated(OnLinkActivatedDelegateWrapper source)
245 	{
246 		foreach(index, wrapper; onLinkActivatedListeners)
247 		{
248 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
249 			{
250 				onLinkActivatedListeners[index] = null;
251 				onLinkActivatedListeners = std.algorithm.remove(onLinkActivatedListeners, index);
252 				break;
253 			}
254 		}
255 	}
256 	
257 }