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