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