alternative to assert
[gtkD.git] / gtkD / src / gtk / ObjectGtk.d
blobaa4ad5b7f3a11ab7bd422590e531172f837e1af1
1 /*
2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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 * module aliases:
48 * local aliases:
51 module gtk.ObjectGtk;
53 version(noAssert)
55 version(Tango)
57 import tango.io.Stdout; // use the tango loging?
61 private import gtkc.gtktypes;
63 private import gtkc.gtk;
66 private import glib.Str;
71 /**
72 * Description
73 * Description
74 * GtkObject is the base class for all widgets, and for a few
75 * non-widget objects such as GtkAdjustment. GtkObject predates
76 * GObject; non-widgets that derive from GtkObject rather than
77 * GObject do so for backward compatibility reasons.
78 * GtkObjects are created with a "floating" reference count.
79 * This means that the initial reference is not owned by anyone. Calling
80 * g_object_unref() on a newly-created GtkObject is incorrect, the floating
81 * reference has to be removed first. This can be done by anyone at any time,
82 * by calling g_object_ref_sink() to convert the floating reference into a
83 * regular reference. g_object_ref_sink() returns a new reference if an object
84 * is already sunk (has no floating reference).
85 * When you add a widget to its parent container, the parent container
86 * will do this:
87 * g_object_ref_sink (G_OBJECT (child_widget));
88 * This means that the container now owns a reference to the child widget
89 * and the child widget has no floating reference.
90 * The purpose of the floating reference is to keep the child widget alive
91 * until you add it to a parent container:
92 * button = gtk_button_new ();
93 * /+* button has one floating reference to keep it alive +/
94 * gtk_container_add (GTK_CONTAINER (container), button);
95 * /+* button has one non-floating reference owned by the container +/
96 * GtkWindow is a special case, because GTK+ itself will ref/sink it on creation.
97 * That is, after calling gtk_window_new(), the GtkWindow will have one
98 * reference which is owned by GTK+, and no floating references.
99 * One more factor comes into play: the "destroy" signal, emitted by the
100 * gtk_object_destroy() method. The "destroy" signal asks all code owning a
101 * reference to an object to release said reference. So, for example, if you call
102 * gtk_object_destroy() on a GtkWindow, GTK+ will release the reference count that
103 * it owns; if you call gtk_object_destroy() on a GtkButton, then the button will
104 * be removed from its parent container and the parent container will release its
105 * reference to the button. Because these references are released, calling
106 * gtk_object_destroy() should result in freeing all memory associated with an
107 * object, unless some buggy code fails to release its references in response to
108 * the "destroy" signal. Freeing memory (referred to as
109 * finalization only happens if the reference count reaches
110 * zero.
111 * Some simple rules for handling GtkObject:
112 * Never call g_object_unref() unless you have previously called g_object_ref(),
113 * even if you created the GtkObject. (Note: this is not
114 * true for GObject; for GObject, the creator of the object owns a reference.)
115 * Call gtk_object_destroy() to get rid of most objects in most cases.
116 * In particular, widgets are almost always destroyed in this way.
117 * Because of the floating reference count, you don't need to
118 * worry about reference counting for widgets and toplevel windows, unless you
119 * explicitly call g_object_ref() yourself.
121 private import gobject.ObjectG;
122 public class ObjectGtk : ObjectG
125 /** the main Gtk struct */
126 protected GtkObject* gtkObject;
129 public GtkObject* getObjectGtkStruct()
131 return gtkObject;
135 /** the main Gtk struct as a void* */
136 protected void* getStruct()
138 return cast(void*)gtkObject;
142 * Sets our main struct and passes it to the parent class
144 public this (GtkObject* gtkObject)
146 version(noAssert)
148 if ( gtkObject is null )
150 int zero = 0;
151 version(Tango)
153 Stdout("struct gtkObject is null on constructor").newline;
155 else
157 printf("struct gtkObject is null on constructor");
159 zero = zero / zero;
162 else
164 assert(gtkObject !is null, "struct gtkObject is null on constructor");
166 super(cast(GObject*)gtkObject);
167 this.gtkObject = gtkObject;
170 public static char[] getId(StockID id)
172 return StockDesc[id];
178 // imports for the signal processing
179 private import gobject.Signals;
180 private import gtkc.gdktypes;
181 int[char[]] connectedSignals;
183 void delegate(ObjectGtk)[] onDestroyListeners;
184 void addOnDestroy(void delegate(ObjectGtk) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
186 if ( !("destroy" in connectedSignals) )
188 Signals.connectData(
189 getStruct(),
190 "destroy",
191 cast(GCallback)&callBackDestroy,
192 cast(void*)this,
193 null,
194 connectFlags);
195 connectedSignals["destroy"] = 1;
197 onDestroyListeners ~= dlg;
199 extern(C) static void callBackDestroy(GtkObject* objectStruct, ObjectGtk objectGtk)
201 bool consumed = false;
203 foreach ( void delegate(ObjectGtk) dlg ; objectGtk.onDestroyListeners )
205 dlg(objectGtk);
208 return consumed;
220 * Warning
221 * gtk_object_new is deprecated and should not be used in newly-written code. Use g_object_new() instead.
222 * Constructs an object given its arguments, enumerated in the call to the
223 * function.
224 * type:
225 * the type identifying this object. Returned by gtk_type_unique()
226 * (although for a properly-written object it should be accessible through
227 * a GTK_TYPE_FOO macro.)
228 * first_property_name:
229 * name of the first property to set when constructing
230 * the object.
231 * ...:
232 * the first argument's value, followed by any number of
233 * name/argument-value pairs, terminated with NULL.
234 * Returns:
235 * the new GtkObject.
237 public this (GtkType type, char[] firstPropertyName, ... )
239 // GtkObject* gtk_object_new (GtkType type, const gchar *first_property_name, ...);
240 this(cast(GtkObject*)gtk_object_new(type, Str.toStringz(firstPropertyName)) );
244 * Warning
245 * 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
246 * Removes the floating reference from a GtkObject, if it exists;
247 * otherwise does nothing. See the GtkObject overview documentation at
248 * the top of the page.
249 * object:
250 * the object to sink.
252 public void sink()
254 // void gtk_object_sink (GtkObject *object);
255 gtk_object_sink(gtkObject);
259 * Warning
260 * gtk_object_ref is deprecated and should not be used in newly-written code. Use g_object_ref() instead.
261 * Increases the reference count of the object.
262 * object:
263 * the object to reference.
264 * Returns:
265 * object.
267 public GtkObject* doref()
269 // GtkObject* gtk_object_ref (GtkObject *object);
270 return gtk_object_ref(gtkObject);
274 * Warning
275 * gtk_object_unref is deprecated and should not be used in newly-written code. Use g_object_unref() instead.
276 * Decreases the reference count of an object. When its reference count drops
277 * to 0, the object is finalized (i.e. its memory is freed).
278 * object:
279 * the object to dereference.
281 public void unref()
283 // void gtk_object_unref (GtkObject *object);
284 gtk_object_unref(gtkObject);
288 * Warning
289 * gtk_object_weakref is deprecated and should not be used in newly-written code. Use g_object_weak_ref() instead.
290 * Adds a weak reference callback to an object. Weak references are used for notification when an object is
291 * finalized. They are called "weak references" because they allow you to safely
292 * hold a pointer to an object without calling g_object_ref() (g_object_ref() adds
293 * a strong reference, that is, forces the object to stay alive).
294 * object:
295 * object to weakly reference.
296 * notify:
297 * callback to invoke before the object is freed.
298 * data:
299 * extra data to pass to notify.
301 public void weakref(GtkDestroyNotify notify, void* data)
303 // void gtk_object_weakref (GtkObject *object, GtkDestroyNotify notify, gpointer data);
304 gtk_object_weakref(gtkObject, notify, data);
308 * Warning
309 * gtk_object_weakunref is deprecated and should not be used in newly-written code. Use g_object_weak_unref() instead.
310 * Removes a weak reference callback to an object.
311 * object:
312 * object stop weakly referencing.
313 * notify:
314 * callback to search for.
315 * data:
316 * data to search for.
318 public void weakunref(GtkDestroyNotify notify, void* data)
320 // void gtk_object_weakunref (GtkObject *object, GtkDestroyNotify notify, gpointer data);
321 gtk_object_weakunref(gtkObject, notify, data);
325 * Emits the "destroy" signal notifying all reference holders that they should
326 * release the GtkObject. See the overview documentation at the top of the
327 * page for more details.
328 * The memory for the object itself won't be deleted until
329 * its reference count actually drops to 0; gtk_object_destroy() merely asks
330 * reference holders to release their references, it does not free the object.
331 * object:
332 * the object to destroy.
334 public void destroy()
336 // void gtk_object_destroy (GtkObject *object);
337 gtk_object_destroy(gtkObject);
341 * Warning
342 * gtk_object_get is deprecated and should not be used in newly-written code. Use g_object_get() instead.
343 * Gets properties of an object.
344 * object:
345 * a GtkObject.
346 * first_property_name:
347 * name of first property to get the value for.
348 * ...:
349 * NULL-terminated list of name-return location pairs.
351 public void get(char[] firstPropertyName, ... )
353 // void gtk_object_get (GtkObject *object, const gchar *first_property_name, ...);
354 gtk_object_get(gtkObject, Str.toStringz(firstPropertyName));
358 * Warning
359 * gtk_object_set is deprecated and should not be used in newly-written code. Use g_object_set() instead.
360 * Sets properties on an object.
361 * void set_box_properties (GtkBox* box)
363 * gtk_object_set (GTK_OBJECT (box), "homogeneous", TRUE,
364 * "spacing", 8,
365 * NULL);
367 * object:
368 * a GtkObject.
369 * first_property_name:
370 * name of the first property to set
371 * ...:
372 * the value of the first argument, followed optionally
373 * by more name/value pairs, followed by NULL.
375 public void set(char[] firstPropertyName, ... )
377 // void gtk_object_set (GtkObject *object, const gchar *first_property_name, ...);
378 gtk_object_set(gtkObject, Str.toStringz(firstPropertyName));
382 * Warning
383 * gtk_object_set_data is deprecated and should not be used in newly-written code. Use g_object_set_data() instead.
384 * Each object carries around a table of associations from
385 * strings to pointers. This function lets you set an association.
386 * If the object already had an association with that name,
387 * the old association will be destroyed.
388 * object:
389 * object containing the associations.
390 * key:
391 * name of the key.
392 * data:
393 * data to associate with that key.
395 public void setData(char[] key, void* data)
397 // void gtk_object_set_data (GtkObject *object, const gchar *key, gpointer data);
398 gtk_object_set_data(gtkObject, Str.toStringz(key), data);
402 * Warning
403 * gtk_object_set_data_full is deprecated and should not be used in newly-written code. Use g_object_set_data_full() instead.
404 * Like gtk_object_set_data() except it adds notification
405 * for when the association is destroyed, either by
406 * gtk_object_remove_data() or when the object is destroyed.
407 * object:
408 * object containing the associations.
409 * key:
410 * name of the key.
411 * data:
412 * data to associate with that key.
413 * destroy:
414 * function to call when the association is destroyed.
416 public void setDataFull(char[] key, void* data, GtkDestroyNotify destroy)
418 // void gtk_object_set_data_full (GtkObject *object, const gchar *key, gpointer data, GtkDestroyNotify destroy);
419 gtk_object_set_data_full(gtkObject, Str.toStringz(key), data, destroy);
423 * Warning
424 * 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.
425 * Removes a specified datum from the object's data associations (the object_data).
426 * Subsequent calls to gtk_object_get_data() will return NULL.
427 * If you specified a destroy handler with gtk_object_set_data_full(),
428 * it will be invoked.
429 * object:
430 * the object maintaining the association.
431 * key:
432 * name of the key for that association.
434 public void removeData(char[] key)
436 // void gtk_object_remove_data (GtkObject *object, const gchar *key);
437 gtk_object_remove_data(gtkObject, Str.toStringz(key));
441 * Warning
442 * gtk_object_get_data is deprecated and should not be used in newly-written code. Use g_object_get_data() instead.
443 * Get a named field from the object's table of associations (the object_data).
444 * object:
445 * the object maintaining the associations.
446 * key:
447 * name of the key for that association.
448 * Returns:
449 * the data if found, or NULL if no such data exists.
451 public void* getData(char[] key)
453 // gpointer gtk_object_get_data (GtkObject *object, const gchar *key);
454 return gtk_object_get_data(gtkObject, Str.toStringz(key));
458 * Warning
459 * gtk_object_remove_no_notify is deprecated and should not be used in newly-written code. Use g_object_steal_data() instead.
460 * Remove a specified datum from the object's data associations (the object_data),
461 * without invoking the association's destroy handler.
462 * Just like gtk_object_remove_data() except that any destroy handler
463 * will be ignored.
464 * Therefore this only affects data set using gtk_object_set_data_full().
465 * object:
466 * the object maintaining the association.
467 * key:
468 * name of the key for that association.
470 public void removeNoNotify(char[] key)
472 // void gtk_object_remove_no_notify (GtkObject *object, const gchar *key);
473 gtk_object_remove_no_notify(gtkObject, Str.toStringz(key));
477 * Warning
478 * gtk_object_set_user_data is deprecated and should not be used in newly-written code. Use g_object_set_data() instead.
479 * For convenience, every object offers a generic user data
480 * pointer. This function sets it.
481 * object:
482 * the object whose user data should be set.
483 * data:
484 * the new value for the user data.
486 public void setUserData(void* data)
488 // void gtk_object_set_user_data (GtkObject *object, gpointer data);
489 gtk_object_set_user_data(gtkObject, data);
493 * Warning
494 * gtk_object_get_user_data is deprecated and should not be used in newly-written code. Use g_object_get_data() instead.
495 * Get the object's user data pointer.
496 * This is intended to be a pointer for your convenience in
497 * writing applications.
498 * object:
499 * the object.
500 * Returns:
501 * the user data field for object.
503 public void* getUserData()
505 // gpointer gtk_object_get_user_data (GtkObject *object);
506 return gtk_object_get_user_data(gtkObject);
510 * Warning
511 * gtk_object_add_arg_type is deprecated and should not be used in newly-written code.
512 * Deprecated in favor of the GObject property system including GParamSpec.
513 * Add a new type of argument to an object class.
514 * Usually this is called when registering a new type of object.
515 * arg_name:
516 * fully qualify object name, for example GtkObject::user_data.
517 * arg_type:
518 * type of the argument.
519 * arg_flags:
520 * bitwise-OR of the GtkArgFlags enum. (Whether the argument is
521 * settable or gettable, whether it is set when the object is constructed.)
522 * arg_id:
523 * an internal number, passed in from here to the "set_arg" and
524 * "get_arg" handlers of the object.
526 public static void addArgType(char[] argName, GtkType argType, uint argFlags, uint argId)
528 // void gtk_object_add_arg_type (const gchar *arg_name, GtkType arg_type, guint arg_flags, guint arg_id);
529 gtk_object_add_arg_type(Str.toStringz(argName), argType, argFlags, argId);
533 * Warning
534 * gtk_object_set_data_by_id is deprecated and should not be used in newly-written code. Use g_object_set_qdata() instead.
535 * Just like gtk_object_set_data() except that it takes
536 * a GQuark instead of a string, so it is slightly faster.
537 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
538 * to get an id from a string.
539 * object:
540 * object containing the associations.
541 * data_id:
542 * quark of the key.
543 * data:
544 * data to associate with that key.
546 public void setDataById(GQuark dataId, void* data)
548 // void gtk_object_set_data_by_id (GtkObject *object, GQuark data_id, gpointer data);
549 gtk_object_set_data_by_id(gtkObject, dataId, data);
553 * Warning
554 * 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.
555 * Just like gtk_object_set_data_full() except that it takes
556 * a GQuark instead of a string, so it is slightly faster.
557 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
558 * to get an id from a string.
559 * object:
560 * object containing the associations.
561 * data_id:
562 * quark of the key.
563 * data:
564 * data to associate with that key.
565 * destroy:
566 * function to call when the association is destroyed.
568 public void setDataByIdFull(GQuark dataId, void* data, GtkDestroyNotify destroy)
570 // void gtk_object_set_data_by_id_full (GtkObject *object, GQuark data_id, gpointer data, GtkDestroyNotify destroy);
571 gtk_object_set_data_by_id_full(gtkObject, dataId, data, destroy);
575 * Warning
576 * gtk_object_get_data_by_id is deprecated and should not be used in newly-written code. Use g_object_get_qdata() instead.
577 * Just like gtk_object_get_data() except that it takes
578 * a GQuark instead of a string, so it is slightly faster.
579 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
580 * to get an id from a string.
581 * object:
582 * object containing the associations.
583 * data_id:
584 * quark of the key.
585 * Returns:
586 * the data if found, or NULL if no such data exists.
588 public void* getDataById(GQuark dataId)
590 // gpointer gtk_object_get_data_by_id (GtkObject *object, GQuark data_id);
591 return gtk_object_get_data_by_id(gtkObject, dataId);
595 * Warning
596 * 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.
597 * Just like gtk_object_remove_data() except that it takes
598 * a GQuark instead of a string, so it is slightly faster.
599 * Remove a specified datum from the object's data associations.
600 * Subsequent calls to gtk_object_get_data() will return NULL.
601 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
602 * to get an id from a string.
603 * object:
604 * object containing the associations.
605 * data_id:
606 * quark of the key.
608 public void removeDataById(GQuark dataId)
610 // void gtk_object_remove_data_by_id (GtkObject *object, GQuark data_id);
611 gtk_object_remove_data_by_id(gtkObject, dataId);
615 * Warning
616 * gtk_object_remove_no_notify_by_id is deprecated and should not be used in newly-written code. Use g_object_steal_qdata() instead.
617 * Just like gtk_object_remove_no_notify() except that it takes
618 * a GQuark instead of a string, so it is slightly faster.
619 * Use gtk_object_data_try_key() and gtk_object_data_force_id()
620 * to get an id from a string.
621 * object:
622 * object containing the associations.
623 * key_id:
624 * quark of the key.
626 public void removeNoNotifyById(GQuark keyId)
628 // void gtk_object_remove_no_notify_by_id (GtkObject *object, GQuark key_id);
629 gtk_object_remove_no_notify_by_id(gtkObject, keyId);