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.HypertextT;
26 
27 public  import atk.Hyperlink;
28 public  import gobject.ObjectG;
29 public  import gobject.Signals;
30 public  import gtkc.atk;
31 public  import gtkc.atktypes;
32 public  import gtkc.gdktypes;
33 public  import std.algorithm;
34 
35 
36 /**
37  * An interface used for objects which implement linking between
38  * multiple resource or content locations, or multiple 'markers'
39  * within a single document.  A Hypertext instance is associated with
40  * one or more Hyperlinks, which are associated with particular
41  * offsets within the Hypertext's included content.  While this
42  * interface is derived from Text, there is no requirement that
43  * Hypertext instances have textual content; they may implement Image
44  * as well, and Hyperlinks need not have non-zero text offsets.
45  */
46 public template HypertextT(TStruct)
47 {
48 	/** Get the main Gtk struct */
49 	public AtkHypertext* getHypertextStruct()
50 	{
51 		return cast(AtkHypertext*)getStruct();
52 	}
53 
54 
55 	/**
56 	 * Gets the link in this hypertext document at index
57 	 * @link_index
58 	 *
59 	 * Params:
60 	 *     linkIndex = an integer specifying the desired link
61 	 *
62 	 * Return: the link in this hypertext document at
63 	 *     index @link_index
64 	 */
65 	public Hyperlink getLink(int linkIndex)
66 	{
67 		auto p = atk_hypertext_get_link(getHypertextStruct(), linkIndex);
68 		
69 		if(p is null)
70 		{
71 			return null;
72 		}
73 		
74 		return ObjectG.getDObject!(Hyperlink)(cast(AtkHyperlink*) p);
75 	}
76 
77 	/**
78 	 * Gets the index into the array of hyperlinks that is associated with
79 	 * the character specified by @char_index.
80 	 *
81 	 * Params:
82 	 *     charIndex = a character index
83 	 *
84 	 * Return: an index into the array of hyperlinks in @hypertext,
85 	 *     or -1 if there is no hyperlink associated with this character.
86 	 */
87 	public int getLinkIndex(int charIndex)
88 	{
89 		return atk_hypertext_get_link_index(getHypertextStruct(), charIndex);
90 	}
91 
92 	/**
93 	 * Gets the number of links within this hypertext document.
94 	 *
95 	 * Return: the number of links within this hypertext document
96 	 */
97 	public int getNLinks()
98 	{
99 		return atk_hypertext_get_n_links(getHypertextStruct());
100 	}
101 
102 	protected class OnLinkSelectedDelegateWrapper
103 	{
104 		void delegate(int, HypertextIF) dlg;
105 		gulong handlerId;
106 		ConnectFlags flags;
107 		this(void delegate(int, HypertextIF) dlg, gulong handlerId, ConnectFlags flags)
108 		{
109 			this.dlg = dlg;
110 			this.handlerId = handlerId;
111 			this.flags = flags;
112 		}
113 	}
114 	protected OnLinkSelectedDelegateWrapper[] onLinkSelectedListeners;
115 
116 	/**
117 	 * The "link-selected" signal is emitted by an AtkHyperText
118 	 * object when one of the hyperlinks associated with the object
119 	 * is selected.
120 	 *
121 	 * Params:
122 	 *     arg1 = the index of the hyperlink which is selected
123 	 */
124 	gulong addOnLinkSelected(void delegate(int, HypertextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
125 	{
126 		onLinkSelectedListeners ~= new OnLinkSelectedDelegateWrapper(dlg, 0, connectFlags);
127 		onLinkSelectedListeners[onLinkSelectedListeners.length - 1].handlerId = Signals.connectData(
128 			this,
129 			"link-selected",
130 			cast(GCallback)&callBackLinkSelected,
131 			cast(void*)onLinkSelectedListeners[onLinkSelectedListeners.length - 1],
132 			cast(GClosureNotify)&callBackLinkSelectedDestroy,
133 			connectFlags);
134 		return onLinkSelectedListeners[onLinkSelectedListeners.length - 1].handlerId;
135 	}
136 	
137 	extern(C) static void callBackLinkSelected(AtkHypertext* hypertextStruct, int arg1,OnLinkSelectedDelegateWrapper wrapper)
138 	{
139 		wrapper.dlg(arg1, wrapper.outer);
140 	}
141 	
142 	extern(C) static void callBackLinkSelectedDestroy(OnLinkSelectedDelegateWrapper wrapper, GClosure* closure)
143 	{
144 		wrapper.outer.internalRemoveOnLinkSelected(wrapper);
145 	}
146 
147 	protected void internalRemoveOnLinkSelected(OnLinkSelectedDelegateWrapper source)
148 	{
149 		foreach(index, wrapper; onLinkSelectedListeners)
150 		{
151 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
152 			{
153 				onLinkSelectedListeners[index] = null;
154 				onLinkSelectedListeners = std.algorithm.remove(onLinkSelectedListeners, index);
155 				break;
156 			}
157 		}
158 	}
159 	
160 }