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