alternative to assert
[gtkD.git] / src / gtk / ObjectGtk.d
blob24100586a083269218c3be60a9289f2b4b06689d
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkObject.html
26 * outPack = gtk
27 * outFile = ObjectGtk
28 * strct = GtkObject
29 * realStrct=
30 * ctorStrct=
31 * clss = ObjectGtk
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_object_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - glib.Str
46 * structWrap:
47 * local aliases:
50 module gtk.ObjectGtk;
52 private import gtk.gtktypes;
54 private import lib.gtk;
56 private import glib.Str;
58 /**
59 * Description
60 * Description
61 * GtkObject is the base class for all widgets, and for a few
62 * non-widget objects such as GtkAdjustment. GtkObject predates
63 * GObject; non-widgets that derive from GtkObject rather than
64 * GObject do so for backward compatibility reasons.
65 * GtkObjects are created with a "floating" reference count.
66 * This means that the initial reference is not owned by anyone. Calling
67 * g_object_unref() on a newly-created GtkObject is incorrect, the floating
68 * reference has to be removed first. This can be done by anyone at any time,
69 * by calling g_object_ref_sink() to convert the floating reference into a
70 * regular reference. g_object_ref_sink() returns a new reference if an object
71 * is already sunk (has no floating reference).
72 * When you add a widget to its parent container, the parent container
73 * will do this:
74 * g_object_ref_sink (G_OBJECT (child_widget));
75 * This means that the container now owns a reference to the child widget
76 * and the child widget has no floating reference.
77 * The purpose of the floating reference is to keep the child widget alive
78 * until you add it to a parent container:
79 * button = gtk_button_new ();
80 * /+* button has one floating reference to keep it alive +/
81 * gtk_container_add (GTK_CONTAINER (container), button);
82 * /+* button has one non-floating reference owned by the container +/
83 * GtkWindow is a special case, because GTK+ itself will ref/sink it on creation.
84 * That is, after calling gtk_window_new(), the GtkWindow will have one
85 * reference which is owned by GTK+, and no floating references.
86 * One more factor comes into play: the "destroy" signal, emitted by the
87 * gtk_object_destroy() method. The "destroy" signal asks all code owning a
88 * reference to an object to release said reference. So, for example, if you call
89 * gtk_object_destroy() on a GtkWindow, GTK+ will release the reference count that
90 * it owns; if you call gtk_object_destroy() on a GtkButton, then the button will
91 * be removed from its parent container and the parent container will release its
92 * reference to the button. Because these references are released, calling
93 * gtk_object_destroy() should result in freeing all memory associated with an
94 * object, unless some buggy code fails to release its references in response to
95 * the "destroy" signal. Freeing memory (referred to as
96 * finalization only happens if the reference count reaches
97 * zero.
98 * Some simple rules for handling GtkObject:
99 * Never call g_object_unref() unless you have previously called g_object_ref(),
100 * even if you created the GtkObject. (Note: this is not
101 * true for GObject; for GObject, the creator of the object owns a reference.)
102 * Call gtk_object_destroy() to get rid of most objects in most cases.
103 * In particular, widgets are almost always destroyed in this way.
104 * Because of the floating reference count, you don't need to
105 * worry about reference counting for widgets and toplevel windows, unless you
106 * explicitly call g_object_ref() yourself.
108 private import gobject.ObjectG;
109 public class ObjectGtk : ObjectG
112 /** the main Gtk struct */
113 protected GtkObject* gtkObject;
116 public GtkObject* getObjectGtkStruct()
118 return gtkObject;
122 /** the main Gtk struct as a void* */
123 protected void* getStruct()
125 return cast(void*)gtkObject;
129 * Sets our main struct and passes it to the parent class
131 public this (GtkObject* gtkObject)
133 super(cast(GObject*)gtkObject);
134 this.gtkObject = gtkObject;
137 public static char[] getId(StockID id)
139 return StockDesc[id];
145 // imports for the signal processing
146 private import gobject.Signals;
147 private import gdk.gdktypes;
148 int[char[]] connectedSignals;
150 void delegate(ObjectGtk)[] onDestroyListeners;
151 void addOnDestroy(void delegate(ObjectGtk) dlg)
153 if ( !("destroy" in connectedSignals) )
155 Signals.connectData(
156 getStruct(),
157 "destroy",
158 cast(GCallback)&callBackDestroy,
159 this,
160 null,
161 cast(ConnectFlags)0);
162 connectedSignals["destroy"] = 1;
164 onDestroyListeners ~= dlg;
166 extern(C) static void callBackDestroy(GtkObject* objectStruct, ObjectGtk objectGtk)
168 bit consumed = false;
170 foreach ( void delegate(ObjectGtk) dlg ; objectGtk.onDestroyListeners )
172 dlg(objectGtk);
175 return consumed;
187 * Warning
188 * gtk_object_new is deprecated and should not be used in newly-written code. Use g_object_new() instead.
189 * Constructs an object given its arguments, enumerated in the call to the
190 * function.
191 * type:
192 * the type identifying this object. Returned by gtk_type_unique()
193 * (although for a properly-written object it should be accessible through
194 * a GTK_TYPE_FOO macro.)
195 * first_property_name:
196 * name of the first property to set when constructing
197 * the object.
198 * ...:
199 * the first argument's value, followed by any number of
200 * name/argument-value pairs, terminated with NULL.
201 * Returns:
202 * the new GtkObject.
204 public this (GtkType type, char[] firstPropertyName, ... )
206 // GtkObject* gtk_object_new (GtkType type, const gchar *first_property_name, ...);
207 this(cast(GtkObject*)gtk_object_new(type, Str.toStringz(firstPropertyName)) );
211 * Warning
212 * gtk_object_sink has been deprecated since version 2.10 and should not be used in newly-written code. Use g_object_ref_sink() instead
213 * Removes the floating reference from a GtkObject, if it exists;
214 * otherwise does nothing. See the GtkObject overview documentation at
215 * the top of the page.
216 * object:
217 * the object to sink.
219 public void sink()
221 // void gtk_object_sink (GtkObject *object);
222 gtk_object_sink(gtkObject);
226 * Warning
227 * gtk_object_ref is deprecated and should not be used in newly-written code. Use g_object_ref() instead.
228 * Increases the reference count of the object.
229 * object:
230 * the object to reference.
231 * Returns:
232 * object.
234 public GtkObject* ref()
236 // GtkObject* gtk_object_ref (GtkObject *object);
237 return gtk_object_ref(gtkObject);
241 * Warning
242 * gtk_object_unref is deprecated and should not be used in newly-written code. Use g_object_unref() instead.
243 * Decreases the reference count of an object. When its reference count drops
244 * to 0, the object is finalized (i.e. its memory is freed).
245 * object:
246 * the object to dereference.
248 public void unref()
250 // void gtk_object_unref (GtkObject *object);
251 gtk_object_unref(gtkObject);
255 * Warning
256 * gtk_object_weakref is deprecated and should not be used in newly-written code. Use g_object_weak_ref() instead.
257 * Adds a weak reference callback to an object. Weak references are used for notification when an object is
258 * finalized. They are called "weak references" because they allow you to safely
259 * hold a pointer to an object without calling g_object_ref() (g_object_ref() adds
260 * a strong reference, that is, forces the object to stay alive).
261 * object:
262 * object to weakly reference.
263 * notify:
264 * callback to invoke before the object is freed.
265 * data:
266 * extra data to pass to notify.
268 public void weakref(GtkDestroyNotify notify, void* data)
270 // void gtk_object_weakref (GtkObject *object, GtkDestroyNotify notify, gpointer data);
271 gtk_object_weakref(gtkObject, notify, data);
275 * Warning
276 * gtk_object_weakunref is deprecated and should not be used in newly-written code. Use g_object_weak_unref() instead.
277 * Removes a weak reference callback to an object.
278 * object:
279 * object stop weakly referencing.
280 * notify:
281 * callback to search for.
282 * data:
283 * data to search for.
285 public void weakunref(GtkDestroyNotify notify, void* data)
287 // void gtk_object_weakunref (GtkObject *object, GtkDestroyNotify notify, gpointer data);
288 gtk_object_weakunref(gtkObject, notify, data);
292 * Emits the "destroy" signal notifying all reference holders that they should
293 * release the GtkObject. See the overview documentation at the top of the
294 * page for more details.
295 * The memory for the object itself won't be deleted until
296 * its reference count actually drops to 0; gtk_object_destroy() merely asks
297 * reference holders to release their references, it does not free the object.
298 * object:
299 * the object to destroy.
301 public void destroy()
303 // void gtk_object_destroy (GtkObject *object);
304 gtk_object_destroy(gtkObject);
308 * Warning
309 * gtk_object_get is deprecated and should not be used in newly-written code. Use g_object_get() instead.
310 * Gets properties of an object.
311 * object:
312 * a GtkObject.
313 * first_property_name:
314 * name of first property to get the value for.
315 * ...:
316 * NULL-terminated list of name-return location pairs.
318 public void get(char[] firstPropertyName, ... )
320 // void gtk_object_get (GtkObject *object, const gchar *first_property_name, ...);
321 gtk_object_get(gtkObject, Str.toStringz(firstPropertyName));
325 * Warning
326 * gtk_object_set is deprecated and should not be used in newly-written code. Use g_object_set() instead.
327 * Sets properties on an object.
328 * void set_box_properties (GtkBox* box)
330 * gtk_object_set (GTK_OBJECT (box), "homogeneous", TRUE,
331 * "spacing", 8,
332 * NULL);
334 * object:
335 * a GtkObject.
336 * first_property_name:
337 * name of the first property to set
338 * ...:
339 * the value of the first argument, followed optionally
340 * by more name/value pairs, followed by NULL.
342 public void set(char[] firstPropertyName, ... )
344 // void gtk_object_set (GtkObject *object, const gchar *first_property_name, ...);
345 gtk_object_set(gtkObject, Str.toStringz(firstPropertyName));
349 * Warning
350 * gtk_object_set_data is deprecated and should not be used in newly-written code. Use g_object_set_data() instead.
351 * Each object carries around a table of associations from
352 * strings to pointers. This function lets you set an association.
353 * If the object already had an association with that name,
354 * the old association will be destroyed.
355 * object:
356 * object containing the associations.
357 * key:
358 * name of the key.
359 * data:
360 * data to associate with that key.
362 public void setData(char[] key, void* data)
364 // void gtk_object_set_data (GtkObject *object, const gchar *key, gpointer data);
365 gtk_object_set_data(gtkObject, Str.toStringz(key), data);
369 * Warning
370 * gtk_object_set_data_full is deprecated and should not be used in newly-written code. Use g_object_set_data_full() instead.
371 * Like gtk_object_set_data() except it adds notification
372 * for when the association is destroyed, either by
373 * gtk_object_remove_data() or when the object is destroyed.
374 * object:
375 * object containing the associations.
376 * key:
377 * name of the key.
378 * data:
379 * data to associate with that key.
380 * destroy:
381 * function to call when the association is destroyed.
383 public void setDataFull(char[] key, void* data, GtkDestroyNotify destroy)
385 // void gtk_object_set_data_full (GtkObject *object, const gchar *key, gpointer data, GtkDestroyNotify destroy);
386 gtk_object_set_data_full(gtkObject, Str.toStringz(key), data, destroy);
390 * Warning
391 * gtk_object_remove_data is deprecated and should not be used in newly-written code. Use g_object_set_data() to set the object data to NULL instead.
392 * Removes a specified datum from the object's data associations (the object_data).
393 * Subsequent calls to gtk_object_get_data() will return NULL.
394 * If you specified a destroy handler with gtk_object_set_data_full(),
395 * it will be invoked.
396 * object:
397 * the object maintaining the association.
398 * key:
399 * name of the key for that association.
401 public void removeData(char[] key)
403 // void gtk_object_remove_data (GtkObject *object, const gchar *key);
404 gtk_object_remove_data(gtkObject, Str.toStringz(key));
408 * Warning
409 * gtk_object_get_data is deprecated and should not be used in newly-written code. Use g_object_get_data() instead.
410 * Get a named field from the object's table of associations (the object_data).
411 * object:
412 * the object maintaining the associations.
413 * key:
414 * name of the key for that association.
415 * Returns:
416 * the data if found, or NULL if no such data exists.
418 public void* getData(char[] key)
420 // gpointer gtk_object_get_data (GtkObject *object, const gchar *key);
421 return gtk_object_get_data(gtkObject, Str.toStringz(key));
425 * Warning
426 * gtk_object_remove_no_notify is deprecated and should not be used in newly-written code. Use g_object_steal_data() instead.
427 * Remove a specified datum from the object's data associations (the object_data),
428 * without invoking the association's destroy handler.
429 * Just like gtk_object_remove_data() except that any destroy handler
430 * will be ignored.
431 * Therefore this only affects data set using gtk_object_set_data_full().
432 * object:
433 * the object maintaining the association.
434 * key:
435 * name of the key for that association.
437 public void removeNoNotify(char[] key)
439 // void gtk_object_remove_no_notify (GtkObject *object, const gchar *key);
440 gtk_object_remove_no_notify(gtkObject, Str.toStringz(key));
444 * Warning
445 * gtk_object_set_user_data is deprecated and should not be used in newly-written code. Use g_object_set_data() instead.
446 * For convenience, every object offers a generic user data
447 * pointer. This function sets it.
448 * object:
449 * the object whose user data should be set.
450 * data:
451 * the new value for the user data.
453 public void setUserData(void* data)
455 // void gtk_object_set_user_data (GtkObject *object, gpointer data);
456 gtk_object_set_user_data(gtkObject, data);
460 * Warning
461 * gtk_object_get_user_data is deprecated and should not be used in newly-written code. Use g_object_get_data() instead.
462 * Get the object's user data pointer.
463 * This is intended to be a pointer for your convenience in
464 * writing applications.
465 * object:
466 * the object.
467 * Returns:
468 * the user data field for object.
470 public void* getUserData()
472 // gpointer gtk_object_get_user_data (GtkObject *object);
473 return gtk_object_get_user_data(gtkObject);
477 * Warning
478 * gtk_object_add_arg_type is deprecated and should not be used in newly-written code.
479 * Deprecated in favor of the GObject property system including GParamSpec.
480 * Add a new type of argument to an object class.
481 * Usually this is called when registering a new type of object.
482 * arg_name:
483 * fully qualify object name, for example GtkObject::user_data.
484 * arg_type:
485 * type of the argument.
486 * arg_flags:
487 * bitwise-OR of the GtkArgFlags enum. (Whether the argument is
488 * settable or gettable, whether it is set when the object is constructed.)
489 * arg_id:
490 * an internal number, passed in from here to the "set_arg" and
491 * "get_arg" handlers of the object.
493 public static void addArgType(char[] argName, GtkType argType, uint argFlags, uint argId)
495 // void gtk_object_add_arg_type (const gchar *arg_name, GtkType arg_type, guint arg_flags, guint arg_id);
496 gtk_object_add_arg_type(Str.toStringz(argName), argType, argFlags, argId);
500 * Warning
501 * gtk_object_set_data_by_id is deprecated and should not be used in newly-written code. Use g_object_set_qdata() instead.
502 * Just like gtk_object_set_data() except that it takes
503 * a GQuark instead of a string, so it is slightly faster.
504 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
505 * to get an id from a string.
506 * object:
507 * object containing the associations.
508 * data_id:
509 * quark of the key.
510 * data:
511 * data to associate with that key.
513 public void setDataById(GQuark dataId, void* data)
515 // void gtk_object_set_data_by_id (GtkObject *object, GQuark data_id, gpointer data);
516 gtk_object_set_data_by_id(gtkObject, dataId, data);
520 * Warning
521 * gtk_object_set_data_by_id_full is deprecated and should not be used in newly-written code. Use g_object_set_qdata_full() instead.
522 * Just like gtk_object_set_data_full() except that it takes
523 * a GQuark instead of a string, so it is slightly faster.
524 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
525 * to get an id from a string.
526 * object:
527 * object containing the associations.
528 * data_id:
529 * quark of the key.
530 * data:
531 * data to associate with that key.
532 * destroy:
533 * function to call when the association is destroyed.
535 public void setDataByIdFull(GQuark dataId, void* data, GtkDestroyNotify destroy)
537 // void gtk_object_set_data_by_id_full (GtkObject *object, GQuark data_id, gpointer data, GtkDestroyNotify destroy);
538 gtk_object_set_data_by_id_full(gtkObject, dataId, data, destroy);
542 * Warning
543 * gtk_object_get_data_by_id is deprecated and should not be used in newly-written code. Use g_object_get_qdata() instead.
544 * Just like gtk_object_get_data() except that it takes
545 * a GQuark instead of a string, so it is slightly faster.
546 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
547 * to get an id from a string.
548 * object:
549 * object containing the associations.
550 * data_id:
551 * quark of the key.
552 * Returns:
553 * the data if found, or NULL if no such data exists.
555 public void* getDataById(GQuark dataId)
557 // gpointer gtk_object_get_data_by_id (GtkObject *object, GQuark data_id);
558 return gtk_object_get_data_by_id(gtkObject, dataId);
562 * Warning
563 * gtk_object_remove_data_by_id is deprecated and should not be used in newly-written code. Use g_object_set_qdata() with data of NULL instead.
564 * Just like gtk_object_remove_data() except that it takes
565 * a GQuark instead of a string, so it is slightly faster.
566 * Remove a specified datum from the object's data associations.
567 * Subsequent calls to gtk_object_get_data() will return NULL.
568 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
569 * to get an id from a string.
570 * object:
571 * object containing the associations.
572 * data_id:
573 * quark of the key.
575 public void removeDataById(GQuark dataId)
577 // void gtk_object_remove_data_by_id (GtkObject *object, GQuark data_id);
578 gtk_object_remove_data_by_id(gtkObject, dataId);
582 * Warning
583 * gtk_object_remove_no_notify_by_id is deprecated and should not be used in newly-written code. Use g_object_steal_qdata() instead.
584 * Just like gtk_object_remove_no_notify() except that it takes
585 * a GQuark instead of a string, so it is slightly faster.
586 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
587 * to get an id from a string.
588 * object:
589 * object containing the associations.
590 * key_id:
591 * quark of the key.
593 public void removeNoNotifyById(GQuark keyId)
595 // void gtk_object_remove_no_notify_by_id (GtkObject *object, GQuark key_id);
596 gtk_object_remove_no_notify_by_id(gtkObject, keyId);