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.DocumentT;
26 
27 public  import glib.Str;
28 public  import gobject.Signals;
29 public  import gtkc.atk;
30 public  import gtkc.atktypes;
31 public  import gtkc.gdktypes;
32 public  import std.algorithm;
33 
34 
35 /**
36  * The AtkDocument interface should be supported by any object whose
37  * content is a representation or view of a document.  The AtkDocument
38  * interface should appear on the toplevel container for the document
39  * content; however AtkDocument instances may be nested (i.e. an
40  * AtkDocument may be a descendant of another AtkDocument) in those
41  * cases where one document contains "embedded content" which can
42  * reasonably be considered a document in its own right.
43  */
44 public template DocumentT(TStruct)
45 {
46 	/** Get the main Gtk struct */
47 	public AtkDocument* getDocumentStruct()
48 	{
49 		return cast(AtkDocument*)getStruct();
50 	}
51 
52 
53 	/**
54 	 *
55 	 * Params:
56 	 *     attributeName = a character string representing the name of the attribute
57 	 *         whose value is being queried.
58 	 * Return: a string value associated with the named
59 	 *     attribute for this document, or NULL if a value for
60 	 *     #attribute_name has not been specified for this document.
61 	 *
62 	 * Since: 1.12
63 	 */
64 	public string getAttributeValue(string attributeName)
65 	{
66 		return Str.toString(atk_document_get_attribute_value(getDocumentStruct(), Str.toStringz(attributeName)));
67 	}
68 
69 	/**
70 	 * Gets an AtkAttributeSet which describes document-wide
71 	 * attributes as name-value pairs.
72 	 *
73 	 * Return: An AtkAttributeSet containing the explicitly
74 	 *     set name-value-pair attributes associated with this document
75 	 *     as a whole.
76 	 *
77 	 * Since: 1.12
78 	 */
79 	public override AtkAttributeSet* getAttributes()
80 	{
81 		return atk_document_get_attributes(getDocumentStruct());
82 	}
83 
84 	/**
85 	 * Return: current page number inside @document. -1 if not
86 	 *     implemented, not know by the implementor or irrelevant.
87 	 *
88 	 * Since: 2.12
89 	 */
90 	public int getCurrentPageNumber()
91 	{
92 		return atk_document_get_current_page_number(getDocumentStruct());
93 	}
94 
95 	/**
96 	 * Gets a %gpointer that points to an instance of the DOM.  It is
97 	 * up to the caller to check atk_document_get_type to determine
98 	 * how to cast this pointer.
99 	 *
100 	 * Deprecated: Since 2.12. @document is already a representation of
101 	 * the document. Use it directly, or one of its children, as an
102 	 * instance of the DOM.
103 	 *
104 	 * Return: a %gpointer that points to an instance of the DOM.
105 	 */
106 	public void* getDocument()
107 	{
108 		return atk_document_get_document(getDocumentStruct());
109 	}
110 
111 	/**
112 	 * Gets a string indicating the document type.
113 	 *
114 	 * Deprecated: Since 2.12. Please use atk_document_get_attributes() to
115 	 * ask for the document type if it applies.
116 	 *
117 	 * Return: a string indicating the document type
118 	 */
119 	public string getDocumentType()
120 	{
121 		return Str.toString(atk_document_get_document_type(getDocumentStruct()));
122 	}
123 
124 	/**
125 	 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
126 	 * of the content of this document instance.  Individual
127 	 * text substrings or images within this document may have
128 	 * a different locale, see atk_text_get_attributes and
129 	 * atk_image_get_image_locale.
130 	 *
131 	 * Deprecated: Please use atk_object_get_object_locale() instead.
132 	 *
133 	 * Return: a UTF-8 string indicating the POSIX-style LC_MESSAGES
134 	 *     locale of the document content as a whole, or NULL if
135 	 *     the document content does not specify a locale.
136 	 */
137 	public string getLocale()
138 	{
139 		return Str.toString(atk_document_get_locale(getDocumentStruct()));
140 	}
141 
142 	/**
143 	 * Return: total page count of @document. -1 if not implemented, not
144 	 *     know by the implementor or irrelevant.
145 	 *
146 	 * Since: 2.12
147 	 */
148 	public int getPageCount()
149 	{
150 		return atk_document_get_page_count(getDocumentStruct());
151 	}
152 
153 	/**
154 	 *
155 	 * Params:
156 	 *     attributeName = a character string representing the name of the attribute
157 	 *         whose value is being set.
158 	 *     attributeValue = a string value to be associated with #attribute_name.
159 	 * Return: TRUE if #value is successfully associated with #attribute_name
160 	 *     for this document, FALSE otherwise (e.g. if the document does not
161 	 *     allow the attribute to be modified).
162 	 *
163 	 * Since: 1.12
164 	 */
165 	public bool setAttributeValue(string attributeName, string attributeValue)
166 	{
167 		return atk_document_set_attribute_value(getDocumentStruct(), Str.toStringz(attributeName), Str.toStringz(attributeValue)) != 0;
168 	}
169 
170 	protected class OnLoadCompleteDelegateWrapper
171 	{
172 		void delegate(DocumentIF) dlg;
173 		gulong handlerId;
174 		ConnectFlags flags;
175 		this(void delegate(DocumentIF) dlg, gulong handlerId, ConnectFlags flags)
176 		{
177 			this.dlg = dlg;
178 			this.handlerId = handlerId;
179 			this.flags = flags;
180 		}
181 	}
182 	protected OnLoadCompleteDelegateWrapper[] onLoadCompleteListeners;
183 
184 	/**
185 	 * The 'load-complete' signal is emitted when a pending load of
186 	 * a static document has completed.  This signal is to be
187 	 * expected by ATK clients if and when AtkDocument implementors
188 	 * expose ATK_STATE_BUSY.  If the state of an AtkObject which
189 	 * implements AtkDocument does not include ATK_STATE_BUSY, it
190 	 * should be safe for clients to assume that the AtkDocument's
191 	 * static contents are fully loaded into the container.
192 	 * (Dynamic document contents should be exposed via other
193 	 * signals.)
194 	 */
195 	gulong addOnLoadComplete(void delegate(DocumentIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
196 	{
197 		onLoadCompleteListeners ~= new OnLoadCompleteDelegateWrapper(dlg, 0, connectFlags);
198 		onLoadCompleteListeners[onLoadCompleteListeners.length - 1].handlerId = Signals.connectData(
199 			this,
200 			"load-complete",
201 			cast(GCallback)&callBackLoadComplete,
202 			cast(void*)onLoadCompleteListeners[onLoadCompleteListeners.length - 1],
203 			cast(GClosureNotify)&callBackLoadCompleteDestroy,
204 			connectFlags);
205 		return onLoadCompleteListeners[onLoadCompleteListeners.length - 1].handlerId;
206 	}
207 	
208 	extern(C) static void callBackLoadComplete(AtkDocument* documentStruct,OnLoadCompleteDelegateWrapper wrapper)
209 	{
210 		wrapper.dlg(wrapper.outer);
211 	}
212 	
213 	extern(C) static void callBackLoadCompleteDestroy(OnLoadCompleteDelegateWrapper wrapper, GClosure* closure)
214 	{
215 		wrapper.outer.internalRemoveOnLoadComplete(wrapper);
216 	}
217 
218 	protected void internalRemoveOnLoadComplete(OnLoadCompleteDelegateWrapper source)
219 	{
220 		foreach(index, wrapper; onLoadCompleteListeners)
221 		{
222 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
223 			{
224 				onLoadCompleteListeners[index] = null;
225 				onLoadCompleteListeners = std.algorithm.remove(onLoadCompleteListeners, index);
226 				break;
227 			}
228 		}
229 	}
230 	
231 
232 	protected class OnLoadStoppedDelegateWrapper
233 	{
234 		void delegate(DocumentIF) dlg;
235 		gulong handlerId;
236 		ConnectFlags flags;
237 		this(void delegate(DocumentIF) dlg, gulong handlerId, ConnectFlags flags)
238 		{
239 			this.dlg = dlg;
240 			this.handlerId = handlerId;
241 			this.flags = flags;
242 		}
243 	}
244 	protected OnLoadStoppedDelegateWrapper[] onLoadStoppedListeners;
245 
246 	/**
247 	 * The 'load-stopped' signal is emitted when a pending load of
248 	 * document contents is cancelled, paused, or otherwise
249 	 * interrupted by the user or application logic.  It should not
250 	 * however be emitted while waiting for a resource (for instance
251 	 * while blocking on a file or network read) unless a
252 	 * user-significant timeout has occurred.
253 	 */
254 	gulong addOnLoadStopped(void delegate(DocumentIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
255 	{
256 		onLoadStoppedListeners ~= new OnLoadStoppedDelegateWrapper(dlg, 0, connectFlags);
257 		onLoadStoppedListeners[onLoadStoppedListeners.length - 1].handlerId = Signals.connectData(
258 			this,
259 			"load-stopped",
260 			cast(GCallback)&callBackLoadStopped,
261 			cast(void*)onLoadStoppedListeners[onLoadStoppedListeners.length - 1],
262 			cast(GClosureNotify)&callBackLoadStoppedDestroy,
263 			connectFlags);
264 		return onLoadStoppedListeners[onLoadStoppedListeners.length - 1].handlerId;
265 	}
266 	
267 	extern(C) static void callBackLoadStopped(AtkDocument* documentStruct,OnLoadStoppedDelegateWrapper wrapper)
268 	{
269 		wrapper.dlg(wrapper.outer);
270 	}
271 	
272 	extern(C) static void callBackLoadStoppedDestroy(OnLoadStoppedDelegateWrapper wrapper, GClosure* closure)
273 	{
274 		wrapper.outer.internalRemoveOnLoadStopped(wrapper);
275 	}
276 
277 	protected void internalRemoveOnLoadStopped(OnLoadStoppedDelegateWrapper source)
278 	{
279 		foreach(index, wrapper; onLoadStoppedListeners)
280 		{
281 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
282 			{
283 				onLoadStoppedListeners[index] = null;
284 				onLoadStoppedListeners = std.algorithm.remove(onLoadStoppedListeners, index);
285 				break;
286 			}
287 		}
288 	}
289 	
290 
291 	protected class OnPageChangedDelegateWrapper
292 	{
293 		void delegate(int, DocumentIF) dlg;
294 		gulong handlerId;
295 		ConnectFlags flags;
296 		this(void delegate(int, DocumentIF) dlg, gulong handlerId, ConnectFlags flags)
297 		{
298 			this.dlg = dlg;
299 			this.handlerId = handlerId;
300 			this.flags = flags;
301 		}
302 	}
303 	protected OnPageChangedDelegateWrapper[] onPageChangedListeners;
304 
305 	/**
306 	 * The 'page-changed' signal is emitted when the current page of
307 	 * a document changes, e.g. pressing page up/down in a document
308 	 * viewer.
309 	 *
310 	 * Params:
311 	 *     pageNumber = the new page number. If this value is unknown
312 	 *         or not applicable, -1 should be provided.
313 	 *
314 	 * Since: 2.12
315 	 */
316 	gulong addOnPageChanged(void delegate(int, DocumentIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
317 	{
318 		onPageChangedListeners ~= new OnPageChangedDelegateWrapper(dlg, 0, connectFlags);
319 		onPageChangedListeners[onPageChangedListeners.length - 1].handlerId = Signals.connectData(
320 			this,
321 			"page-changed",
322 			cast(GCallback)&callBackPageChanged,
323 			cast(void*)onPageChangedListeners[onPageChangedListeners.length - 1],
324 			cast(GClosureNotify)&callBackPageChangedDestroy,
325 			connectFlags);
326 		return onPageChangedListeners[onPageChangedListeners.length - 1].handlerId;
327 	}
328 	
329 	extern(C) static void callBackPageChanged(AtkDocument* documentStruct, int pageNumber,OnPageChangedDelegateWrapper wrapper)
330 	{
331 		wrapper.dlg(pageNumber, wrapper.outer);
332 	}
333 	
334 	extern(C) static void callBackPageChangedDestroy(OnPageChangedDelegateWrapper wrapper, GClosure* closure)
335 	{
336 		wrapper.outer.internalRemoveOnPageChanged(wrapper);
337 	}
338 
339 	protected void internalRemoveOnPageChanged(OnPageChangedDelegateWrapper source)
340 	{
341 		foreach(index, wrapper; onPageChangedListeners)
342 		{
343 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
344 			{
345 				onPageChangedListeners[index] = null;
346 				onPageChangedListeners = std.algorithm.remove(onPageChangedListeners, index);
347 				break;
348 			}
349 		}
350 	}
351 	
352 
353 	protected class OnReloadDelegateWrapper
354 	{
355 		void delegate(DocumentIF) dlg;
356 		gulong handlerId;
357 		ConnectFlags flags;
358 		this(void delegate(DocumentIF) dlg, gulong handlerId, ConnectFlags flags)
359 		{
360 			this.dlg = dlg;
361 			this.handlerId = handlerId;
362 			this.flags = flags;
363 		}
364 	}
365 	protected OnReloadDelegateWrapper[] onReloadListeners;
366 
367 	/**
368 	 * The 'reload' signal is emitted when the contents of a
369 	 * document is refreshed from its source.  Once 'reload' has
370 	 * been emitted, a matching 'load-complete' or 'load-stopped'
371 	 * signal should follow, which clients may await before
372 	 * interrogating ATK for the latest document content.
373 	 */
374 	gulong addOnReload(void delegate(DocumentIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
375 	{
376 		onReloadListeners ~= new OnReloadDelegateWrapper(dlg, 0, connectFlags);
377 		onReloadListeners[onReloadListeners.length - 1].handlerId = Signals.connectData(
378 			this,
379 			"reload",
380 			cast(GCallback)&callBackReload,
381 			cast(void*)onReloadListeners[onReloadListeners.length - 1],
382 			cast(GClosureNotify)&callBackReloadDestroy,
383 			connectFlags);
384 		return onReloadListeners[onReloadListeners.length - 1].handlerId;
385 	}
386 	
387 	extern(C) static void callBackReload(AtkDocument* documentStruct,OnReloadDelegateWrapper wrapper)
388 	{
389 		wrapper.dlg(wrapper.outer);
390 	}
391 	
392 	extern(C) static void callBackReloadDestroy(OnReloadDelegateWrapper wrapper, GClosure* closure)
393 	{
394 		wrapper.outer.internalRemoveOnReload(wrapper);
395 	}
396 
397 	protected void internalRemoveOnReload(OnReloadDelegateWrapper source)
398 	{
399 		foreach(index, wrapper; onReloadListeners)
400 		{
401 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
402 			{
403 				onReloadListeners[index] = null;
404 				onReloadListeners = std.algorithm.remove(onReloadListeners, index);
405 				break;
406 			}
407 		}
408 	}
409 	
410 }