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 glib.Hook;
26 
27 private import glib.HookList;
28 private import glib.MemorySlice;
29 private import glib.c.functions;
30 public  import glib.c.types;
31 public  import gtkc.glibtypes;
32 private import gtkd.Loader;
33 
34 
35 /**
36  * The #GHook struct represents a single hook function in a #GHookList.
37  */
38 public final class Hook
39 {
40 	/** the main Gtk struct */
41 	protected GHook* gHook;
42 	protected bool ownedRef;
43 
44 	/** Get the main Gtk struct */
45 	public GHook* getHookStruct(bool transferOwnership = false)
46 	{
47 		if (transferOwnership)
48 			ownedRef = false;
49 		return gHook;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected void* getStruct()
54 	{
55 		return cast(void*)gHook;
56 	}
57 
58 	/**
59 	 * Sets our main struct and passes it to the parent class.
60 	 */
61 	public this (GHook* gHook, bool ownedRef = false)
62 	{
63 		this.gHook = gHook;
64 		this.ownedRef = ownedRef;
65 	}
66 
67 	~this ()
68 	{
69 		if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
70 			sliceFree(gHook);
71 	}
72 
73 
74 	/**
75 	 * data which is passed to func when this hook is invoked
76 	 */
77 	public @property void* data()
78 	{
79 		return gHook.data;
80 	}
81 
82 	/** Ditto */
83 	public @property void data(void* value)
84 	{
85 		gHook.data = value;
86 	}
87 
88 	/**
89 	 * pointer to the next hook in the list
90 	 */
91 	public @property Hook next()
92 	{
93 		return new Hook(gHook.next, false);
94 	}
95 
96 	/** Ditto */
97 	public @property void next(Hook value)
98 	{
99 		gHook.next = value.getHookStruct();
100 	}
101 
102 	/**
103 	 * pointer to the previous hook in the list
104 	 */
105 	public @property Hook prev()
106 	{
107 		return new Hook(gHook.prev, false);
108 	}
109 
110 	/** Ditto */
111 	public @property void prev(Hook value)
112 	{
113 		gHook.prev = value.getHookStruct();
114 	}
115 
116 	/**
117 	 * the reference count of this hook
118 	 */
119 	public @property uint refCount()
120 	{
121 		return gHook.refCount;
122 	}
123 
124 	/** Ditto */
125 	public @property void refCount(uint value)
126 	{
127 		gHook.refCount = value;
128 	}
129 
130 	/**
131 	 * the id of this hook, which is unique within its list
132 	 */
133 	public @property gulong hookId()
134 	{
135 		return gHook.hookId;
136 	}
137 
138 	/** Ditto */
139 	public @property void hookId(gulong value)
140 	{
141 		gHook.hookId = value;
142 	}
143 
144 	/**
145 	 * flags which are set for this hook. See #GHookFlagMask for
146 	 * predefined flags
147 	 */
148 	public @property uint flags()
149 	{
150 		return gHook.flags;
151 	}
152 
153 	/** Ditto */
154 	public @property void flags(uint value)
155 	{
156 		gHook.flags = value;
157 	}
158 
159 	/**
160 	 * the function to call when this hook is invoked. The possible
161 	 * signatures for this function are #GHookFunc and #GHookCheckFunc
162 	 */
163 	public @property void* func()
164 	{
165 		return gHook.func;
166 	}
167 
168 	/** Ditto */
169 	public @property void func(void* value)
170 	{
171 		gHook.func = value;
172 	}
173 
174 	/**
175 	 * the default @finalize_hook function of a #GHookList calls
176 	 * this member of the hook that is being finalized
177 	 */
178 	public @property GDestroyNotify destroy()
179 	{
180 		return gHook.destroy;
181 	}
182 
183 	/** Ditto */
184 	public @property void destroy(GDestroyNotify value)
185 	{
186 		gHook.destroy = value;
187 	}
188 
189 	/**
190 	 * Compares the ids of two #GHook elements, returning a negative value
191 	 * if the second id is greater than the first.
192 	 *
193 	 * Params:
194 	 *     sibling = a #GHook to compare with @new_hook
195 	 *
196 	 * Returns: a value <= 0 if the id of @sibling is >= the id of @new_hook
197 	 */
198 	public int compareIds(Hook sibling)
199 	{
200 		return g_hook_compare_ids(gHook, (sibling is null) ? null : sibling.getHookStruct());
201 	}
202 
203 	/**
204 	 * Allocates space for a #GHook and initializes it.
205 	 *
206 	 * Params:
207 	 *     hookList = a #GHookList
208 	 *
209 	 * Returns: a new #GHook
210 	 */
211 	public static Hook alloc(HookList hookList)
212 	{
213 		auto __p = g_hook_alloc((hookList is null) ? null : hookList.getHookListStruct());
214 
215 		if(__p is null)
216 		{
217 			return null;
218 		}
219 
220 		return new Hook(cast(GHook*) __p);
221 	}
222 
223 	/**
224 	 * Destroys a #GHook, given its ID.
225 	 *
226 	 * Params:
227 	 *     hookList = a #GHookList
228 	 *     hookId = a hook ID
229 	 *
230 	 * Returns: %TRUE if the #GHook was found in the #GHookList and destroyed
231 	 */
232 	public static bool destroy(HookList hookList, gulong hookId)
233 	{
234 		return g_hook_destroy((hookList is null) ? null : hookList.getHookListStruct(), hookId) != 0;
235 	}
236 
237 	/**
238 	 * Removes one #GHook from a #GHookList, marking it
239 	 * inactive and calling g_hook_unref() on it.
240 	 *
241 	 * Params:
242 	 *     hookList = a #GHookList
243 	 *     hook = the #GHook to remove
244 	 */
245 	public static void destroyLink(HookList hookList, Hook hook)
246 	{
247 		g_hook_destroy_link((hookList is null) ? null : hookList.getHookListStruct(), (hook is null) ? null : hook.getHookStruct());
248 	}
249 
250 	/**
251 	 * Finds a #GHook in a #GHookList using the given function to
252 	 * test for a match.
253 	 *
254 	 * Params:
255 	 *     hookList = a #GHookList
256 	 *     needValids = %TRUE if #GHook elements which have been destroyed
257 	 *         should be skipped
258 	 *     func = the function to call for each #GHook, which should return
259 	 *         %TRUE when the #GHook has been found
260 	 *     data = the data to pass to @func
261 	 *
262 	 * Returns: the found #GHook or %NULL if no matching #GHook is found
263 	 */
264 	public static Hook find(HookList hookList, bool needValids, GHookFindFunc func, void* data)
265 	{
266 		auto __p = g_hook_find((hookList is null) ? null : hookList.getHookListStruct(), needValids, func, data);
267 
268 		if(__p is null)
269 		{
270 			return null;
271 		}
272 
273 		return new Hook(cast(GHook*) __p);
274 	}
275 
276 	/**
277 	 * Finds a #GHook in a #GHookList with the given data.
278 	 *
279 	 * Params:
280 	 *     hookList = a #GHookList
281 	 *     needValids = %TRUE if #GHook elements which have been destroyed
282 	 *         should be skipped
283 	 *     data = the data to find
284 	 *
285 	 * Returns: the #GHook with the given @data or %NULL if no matching
286 	 *     #GHook is found
287 	 */
288 	public static Hook findData(HookList hookList, bool needValids, void* data)
289 	{
290 		auto __p = g_hook_find_data((hookList is null) ? null : hookList.getHookListStruct(), needValids, data);
291 
292 		if(__p is null)
293 		{
294 			return null;
295 		}
296 
297 		return new Hook(cast(GHook*) __p);
298 	}
299 
300 	/**
301 	 * Finds a #GHook in a #GHookList with the given function.
302 	 *
303 	 * Params:
304 	 *     hookList = a #GHookList
305 	 *     needValids = %TRUE if #GHook elements which have been destroyed
306 	 *         should be skipped
307 	 *     func = the function to find
308 	 *
309 	 * Returns: the #GHook with the given @func or %NULL if no matching
310 	 *     #GHook is found
311 	 */
312 	public static Hook findFunc(HookList hookList, bool needValids, void* func)
313 	{
314 		auto __p = g_hook_find_func((hookList is null) ? null : hookList.getHookListStruct(), needValids, func);
315 
316 		if(__p is null)
317 		{
318 			return null;
319 		}
320 
321 		return new Hook(cast(GHook*) __p);
322 	}
323 
324 	/**
325 	 * Finds a #GHook in a #GHookList with the given function and data.
326 	 *
327 	 * Params:
328 	 *     hookList = a #GHookList
329 	 *     needValids = %TRUE if #GHook elements which have been destroyed
330 	 *         should be skipped
331 	 *     func = the function to find
332 	 *     data = the data to find
333 	 *
334 	 * Returns: the #GHook with the given @func and @data or %NULL if
335 	 *     no matching #GHook is found
336 	 */
337 	public static Hook findFuncData(HookList hookList, bool needValids, void* func, void* data)
338 	{
339 		auto __p = g_hook_find_func_data((hookList is null) ? null : hookList.getHookListStruct(), needValids, func, data);
340 
341 		if(__p is null)
342 		{
343 			return null;
344 		}
345 
346 		return new Hook(cast(GHook*) __p);
347 	}
348 
349 	/**
350 	 * Returns the first #GHook in a #GHookList which has not been destroyed.
351 	 * The reference count for the #GHook is incremented, so you must call
352 	 * g_hook_unref() to restore it when no longer needed. (Or call
353 	 * g_hook_next_valid() if you are stepping through the #GHookList.)
354 	 *
355 	 * Params:
356 	 *     hookList = a #GHookList
357 	 *     mayBeInCall = %TRUE if hooks which are currently running
358 	 *         (e.g. in another thread) are considered valid. If set to %FALSE,
359 	 *         these are skipped
360 	 *
361 	 * Returns: the first valid #GHook, or %NULL if none are valid
362 	 */
363 	public static Hook firstValid(HookList hookList, bool mayBeInCall)
364 	{
365 		auto __p = g_hook_first_valid((hookList is null) ? null : hookList.getHookListStruct(), mayBeInCall);
366 
367 		if(__p is null)
368 		{
369 			return null;
370 		}
371 
372 		return new Hook(cast(GHook*) __p);
373 	}
374 
375 	/**
376 	 * Calls the #GHookList @finalize_hook function if it exists,
377 	 * and frees the memory allocated for the #GHook.
378 	 *
379 	 * Params:
380 	 *     hookList = a #GHookList
381 	 *     hook = the #GHook to free
382 	 */
383 	public static void free(HookList hookList, Hook hook)
384 	{
385 		g_hook_free((hookList is null) ? null : hookList.getHookListStruct(), (hook is null) ? null : hook.getHookStruct());
386 	}
387 
388 	/**
389 	 * Returns the #GHook with the given id, or %NULL if it is not found.
390 	 *
391 	 * Params:
392 	 *     hookList = a #GHookList
393 	 *     hookId = a hook id
394 	 *
395 	 * Returns: the #GHook with the given id, or %NULL if it is not found
396 	 */
397 	public static Hook get(HookList hookList, gulong hookId)
398 	{
399 		auto __p = g_hook_get((hookList is null) ? null : hookList.getHookListStruct(), hookId);
400 
401 		if(__p is null)
402 		{
403 			return null;
404 		}
405 
406 		return new Hook(cast(GHook*) __p);
407 	}
408 
409 	/**
410 	 * Inserts a #GHook into a #GHookList, before a given #GHook.
411 	 *
412 	 * Params:
413 	 *     hookList = a #GHookList
414 	 *     sibling = the #GHook to insert the new #GHook before
415 	 *     hook = the #GHook to insert
416 	 */
417 	public static void insertBefore(HookList hookList, Hook sibling, Hook hook)
418 	{
419 		g_hook_insert_before((hookList is null) ? null : hookList.getHookListStruct(), (sibling is null) ? null : sibling.getHookStruct(), (hook is null) ? null : hook.getHookStruct());
420 	}
421 
422 	/**
423 	 * Inserts a #GHook into a #GHookList, sorted by the given function.
424 	 *
425 	 * Params:
426 	 *     hookList = a #GHookList
427 	 *     hook = the #GHook to insert
428 	 *     func = the comparison function used to sort the #GHook elements
429 	 */
430 	public static void insertSorted(HookList hookList, Hook hook, GHookCompareFunc func)
431 	{
432 		g_hook_insert_sorted((hookList is null) ? null : hookList.getHookListStruct(), (hook is null) ? null : hook.getHookStruct(), func);
433 	}
434 
435 	/**
436 	 * Returns the next #GHook in a #GHookList which has not been destroyed.
437 	 * The reference count for the #GHook is incremented, so you must call
438 	 * g_hook_unref() to restore it when no longer needed. (Or continue to call
439 	 * g_hook_next_valid() until %NULL is returned.)
440 	 *
441 	 * Params:
442 	 *     hookList = a #GHookList
443 	 *     hook = the current #GHook
444 	 *     mayBeInCall = %TRUE if hooks which are currently running
445 	 *         (e.g. in another thread) are considered valid. If set to %FALSE,
446 	 *         these are skipped
447 	 *
448 	 * Returns: the next valid #GHook, or %NULL if none are valid
449 	 */
450 	public static Hook nextValid(HookList hookList, Hook hook, bool mayBeInCall)
451 	{
452 		auto __p = g_hook_next_valid((hookList is null) ? null : hookList.getHookListStruct(), (hook is null) ? null : hook.getHookStruct(), mayBeInCall);
453 
454 		if(__p is null)
455 		{
456 			return null;
457 		}
458 
459 		return new Hook(cast(GHook*) __p);
460 	}
461 
462 	/**
463 	 * Prepends a #GHook on the start of a #GHookList.
464 	 *
465 	 * Params:
466 	 *     hookList = a #GHookList
467 	 *     hook = the #GHook to add to the start of @hook_list
468 	 */
469 	public static void prepend(HookList hookList, Hook hook)
470 	{
471 		g_hook_prepend((hookList is null) ? null : hookList.getHookListStruct(), (hook is null) ? null : hook.getHookStruct());
472 	}
473 
474 	alias doref = ref_;
475 	/**
476 	 * Increments the reference count for a #GHook.
477 	 *
478 	 * Params:
479 	 *     hookList = a #GHookList
480 	 *     hook = the #GHook to increment the reference count of
481 	 *
482 	 * Returns: the @hook that was passed in (since 2.6)
483 	 */
484 	public static Hook ref_(HookList hookList, Hook hook)
485 	{
486 		auto __p = g_hook_ref((hookList is null) ? null : hookList.getHookListStruct(), (hook is null) ? null : hook.getHookStruct());
487 
488 		if(__p is null)
489 		{
490 			return null;
491 		}
492 
493 		return new Hook(cast(GHook*) __p);
494 	}
495 
496 	/**
497 	 * Decrements the reference count of a #GHook.
498 	 * If the reference count falls to 0, the #GHook is removed
499 	 * from the #GHookList and g_hook_free() is called to free it.
500 	 *
501 	 * Params:
502 	 *     hookList = a #GHookList
503 	 *     hook = the #GHook to unref
504 	 */
505 	public static void unref(HookList hookList, Hook hook)
506 	{
507 		g_hook_unref((hookList is null) ? null : hookList.getHookListStruct(), (hook is null) ? null : hook.getHookStruct());
508 	}
509 }