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 * Conversion parameters: 26 * inFile = GtkObject.html 27 * outPack = gtk 28 * outFile = ObjectGtk 29 * strct = GtkObject 30 * realStrct= 31 * ctorStrct= 32 * clss = ObjectGtk 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_object_ 41 * - gtk_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * - gtk_object_ref 46 * - gtk_object_unref 47 * - gtk_object_set_data 48 * - gtk_object_get_data 49 * - gtk_object_set_data_full 50 * - gtk_object_remove_data 51 * omit signals: 52 * imports: 53 * - glib.Str 54 * - gtk.ObjectGtk 55 * structWrap: 56 * - GtkObject* -> ObjectGtk 57 * module aliases: 58 * local aliases: 59 * overrides: 60 */ 61 62 module gtk.ObjectGtk; 63 64 public import gtkc.gtktypes; 65 66 private import gtkc.gtk; 67 private import glib.ConstructionException; 68 private import gobject.ObjectG; 69 70 private import gobject.Signals; 71 public import gtkc.gdktypes; 72 73 private import glib.Str; 74 private import gtk.ObjectGtk; 75 76 77 78 private import gobject.ObjectG; 79 80 /** 81 * Description 82 * Description 83 * GtkObject is the base class for all widgets, and for a few 84 * non-widget objects such as GtkAdjustment. GtkObject predates 85 * GObject; non-widgets that derive from GtkObject rather than 86 * GObject do so for backward compatibility reasons. 87 * GtkObjects are created with a "floating" reference count. 88 * This means that the initial reference is not owned by anyone. Calling 89 * g_object_unref() on a newly-created GtkObject is incorrect, the floating 90 * reference has to be removed first. This can be done by anyone at any time, 91 * by calling g_object_ref_sink() to convert the floating reference into a 92 * regular reference. g_object_ref_sink() returns a new reference if an object 93 * is already sunk (has no floating reference). 94 * When you add a widget to its parent container, the parent container 95 * will do this: 96 * $(DDOC_COMMENT example) 97 * This means that the container now owns a reference to the child widget 98 * and the child widget has no floating reference. 99 * The purpose of the floating reference is to keep the child widget alive 100 * until you add it to a parent container: 101 * $(DDOC_COMMENT example) 102 * GtkWindow is a special case, because GTK+ itself will ref/sink it on creation. 103 * That is, after calling gtk_window_new(), the GtkWindow will have one 104 * reference which is owned by GTK+, and no floating references. 105 * One more factor comes into play: the "destroy" signal, emitted by the 106 * gtk_object_destroy() method. The "destroy" signal asks all code owning a 107 * reference to an object to release said reference. So, for example, if you call 108 * gtk_object_destroy() on a GtkWindow, GTK+ will release the reference count that 109 * it owns; if you call gtk_object_destroy() on a GtkButton, then the button will 110 * be removed from its parent container and the parent container will release its 111 * reference to the button. Because these references are released, calling 112 * gtk_object_destroy() should result in freeing all memory associated with an 113 * object, unless some buggy code fails to release its references in response to 114 * the "destroy" signal. Freeing memory (referred to as 115 * finalization only happens if the reference count reaches 116 * zero. 117 * Some simple rules for handling GtkObject: 118 * Never call g_object_unref() unless you have previously called g_object_ref(), 119 * even if you created the GtkObject. (Note: this is not 120 * true for GObject; for GObject, the creator of the object owns a reference.) 121 * Call gtk_object_destroy() to get rid of most objects in most cases. 122 * In particular, widgets are almost always destroyed in this way. 123 * Because of the floating reference count, you don't need to 124 * worry about reference counting for widgets and toplevel windows, unless you 125 * explicitly call g_object_ref() yourself. 126 */ 127 public class ObjectGtk : ObjectG 128 { 129 130 /** the main Gtk struct */ 131 protected GtkObject* gtkObject; 132 133 134 public GtkObject* getObjectGtkStruct() 135 { 136 return gtkObject; 137 } 138 139 140 /** the main Gtk struct as a void* */ 141 protected override void* getStruct() 142 { 143 return cast(void*)gtkObject; 144 } 145 146 /** 147 * Sets our main struct and passes it to the parent class 148 */ 149 public this (GtkObject* gtkObject) 150 { 151 super(cast(GObject*)gtkObject); 152 this.gtkObject = gtkObject; 153 } 154 155 protected override void setStruct(GObject* obj) 156 { 157 super.setStruct(obj); 158 gtkObject = cast(GtkObject*)obj; 159 } 160 161 /** */ 162 public static string getId(StockID id) 163 { 164 return StockDesc[id]; 165 } 166 167 /** 168 */ 169 int[string] connectedSignals; 170 171 void delegate(ObjectGtk)[] onDestroyListeners; 172 /** 173 * Signals that all holders of a reference to the GtkObject should release 174 * the reference that they hold. May result in finalization of the object 175 * if all references are released. 176 * See Also 177 * GObject 178 */ 179 void addOnDestroy(void delegate(ObjectGtk) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 180 { 181 if ( !("destroy" in connectedSignals) ) 182 { 183 Signals.connectData( 184 getStruct(), 185 "destroy", 186 cast(GCallback)&callBackDestroy, 187 cast(void*)this, 188 null, 189 connectFlags); 190 connectedSignals["destroy"] = 1; 191 } 192 onDestroyListeners ~= dlg; 193 } 194 extern(C) static void callBackDestroy(GtkObject* objectStruct, ObjectGtk _objectGtk) 195 { 196 foreach ( void delegate(ObjectGtk) dlg ; _objectGtk.onDestroyListeners ) 197 { 198 dlg(_objectGtk); 199 } 200 } 201 202 203 /** 204 * Warning 205 * 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 206 * Removes the floating reference from a GtkObject, if it exists; 207 * otherwise does nothing. See the GtkObject overview documentation at 208 * the top of the page. 209 */ 210 public void sink() 211 { 212 // void gtk_object_sink (GtkObject *object); 213 gtk_object_sink(gtkObject); 214 } 215 216 /** 217 * Warning 218 * gtk_object_weakref is deprecated and should not be used in newly-written code. Use g_object_weak_ref() instead. 219 * Adds a weak reference callback to an object. Weak references are used for notification when an object is 220 * finalized. They are called "weak references" because they allow you to safely 221 * hold a pointer to an object without calling g_object_ref() (g_object_ref() adds 222 * a strong reference, that is, forces the object to stay alive). 223 * Params: 224 * notify = callback to invoke before the object is freed. 225 * data = extra data to pass to notify. 226 */ 227 public void weakref(GDestroyNotify notify, void* data) 228 { 229 // void gtk_object_weakref (GtkObject *object, GDestroyNotify notify, gpointer data); 230 gtk_object_weakref(gtkObject, notify, data); 231 } 232 233 /** 234 * Warning 235 * gtk_object_weakunref is deprecated and should not be used in newly-written code. Use g_object_weak_unref() instead. 236 * Removes a weak reference callback to an object. 237 * Params: 238 * notify = callback to search for. 239 * data = data to search for. 240 */ 241 public void weakunref(GDestroyNotify notify, void* data) 242 { 243 // void gtk_object_weakunref (GtkObject *object, GDestroyNotify notify, gpointer data); 244 gtk_object_weakunref(gtkObject, notify, data); 245 } 246 247 /** 248 * Warning 249 * gtk_object_destroy has been deprecated since version 2.24 and should not be used in newly-written code. Use gtk_widget_destroy() instead (if object is a widget) 250 * Emits the "destroy" signal notifying all reference holders that they should 251 * release the GtkObject. See the overview documentation at the top of the 252 * page for more details. 253 * The memory for the object itself won't be deleted until 254 * its reference count actually drops to 0; gtk_object_destroy() merely asks 255 * reference holders to release their references, it does not free the object. 256 */ 257 public void destroy() 258 { 259 // void gtk_object_destroy (GtkObject *object); 260 gtk_object_destroy(gtkObject); 261 } 262 263 /** 264 * Warning 265 * gtk_object_remove_no_notify is deprecated and should not be used in newly-written code. Use g_object_steal_data() instead. 266 * Remove a specified datum from the object's data associations (the object_data), 267 * without invoking the association's destroy handler. 268 * Just like gtk_object_remove_data() except that any destroy handler 269 * will be ignored. 270 * Therefore this only affects data set using gtk_object_set_data_full(). 271 * Params: 272 * key = name of the key for that association. 273 */ 274 public void removeNoNotify(string key) 275 { 276 // void gtk_object_remove_no_notify (GtkObject *object, const gchar *key); 277 gtk_object_remove_no_notify(gtkObject, Str.toStringz(key)); 278 } 279 280 /** 281 * Warning 282 * gtk_object_set_user_data is deprecated and should not be used in newly-written code. Use g_object_set_data() instead. 283 * For convenience, every object offers a generic user data 284 * pointer. This function sets it. 285 * Params: 286 * data = the new value for the user data. 287 */ 288 public void setUserData(void* data) 289 { 290 // void gtk_object_set_user_data (GtkObject *object, gpointer data); 291 gtk_object_set_user_data(gtkObject, data); 292 } 293 294 /** 295 * Warning 296 * gtk_object_get_user_data is deprecated and should not be used in newly-written code. Use g_object_get_data() instead. 297 * Get the object's user data pointer. 298 * This is intended to be a pointer for your convenience in 299 * writing applications. 300 * Returns: the user data field for object. 301 */ 302 public void* getUserData() 303 { 304 // gpointer gtk_object_get_user_data (GtkObject *object); 305 return gtk_object_get_user_data(gtkObject); 306 } 307 308 /** 309 * Warning 310 * gtk_object_add_arg_type is deprecated and should not be used in newly-written code. 311 * Deprecated in favor of the GObject property system including GParamSpec. 312 * Add a new type of argument to an object class. 313 * Usually this is called when registering a new type of object. 314 * Params: 315 * argName = fully qualify object name, for example GtkObject::user_data. 316 * argType = type of the argument. 317 * argFlags = bitwise-OR of the GtkArgFlags enum. (Whether the argument is 318 * settable or gettable, whether it is set when the object is constructed.) 319 * argId = an internal number, passed in from here to the "set_arg" and 320 * "get_arg" handlers of the object. 321 */ 322 public static void addArgType(string argName, GType argType, uint argFlags, uint argId) 323 { 324 // void gtk_object_add_arg_type (const gchar *arg_name, GType arg_type, guint arg_flags, guint arg_id); 325 gtk_object_add_arg_type(Str.toStringz(argName), argType, argFlags, argId); 326 } 327 328 /** 329 * Warning 330 * gtk_object_set_data_by_id is deprecated and should not be used in newly-written code. Use g_object_set_qdata() instead. 331 * Just like gtk_object_set_data() except that it takes 332 * a GQuark instead of a string, so it is slightly faster. 333 * Use gtk_object_data_try_key() and gtk_object_data_force_id() 334 * to get an id from a string. 335 * Params: 336 * dataId = quark of the key. 337 * data = data to associate with that key. 338 */ 339 public void setDataById(GQuark dataId, void* data) 340 { 341 // void gtk_object_set_data_by_id (GtkObject *object, GQuark data_id, gpointer data); 342 gtk_object_set_data_by_id(gtkObject, dataId, data); 343 } 344 345 /** 346 * Warning 347 * 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. 348 * Just like gtk_object_set_data_full() except that it takes 349 * a GQuark instead of a string, so it is slightly faster. 350 * Use gtk_object_data_try_key() and gtk_object_data_force_id() 351 * to get an id from a string. 352 * Params: 353 * dataId = quark of the key. 354 * data = data to associate with that key. 355 * destroy = function to call when the association is destroyed. 356 */ 357 public void setDataByIdFull(GQuark dataId, void* data, GDestroyNotify destroy) 358 { 359 // void gtk_object_set_data_by_id_full (GtkObject *object, GQuark data_id, gpointer data, GDestroyNotify destroy); 360 gtk_object_set_data_by_id_full(gtkObject, dataId, data, destroy); 361 } 362 363 /** 364 * Warning 365 * gtk_object_get_data_by_id is deprecated and should not be used in newly-written code. Use g_object_get_qdata() instead. 366 * Just like gtk_object_get_data() except that it takes 367 * a GQuark instead of a string, so it is slightly faster. 368 * Use gtk_object_data_try_key() and gtk_object_data_force_id() 369 * to get an id from a string. 370 * Params: 371 * dataId = quark of the key. 372 * Returns: the data if found, or NULL if no such data exists. 373 */ 374 public void* getDataById(GQuark dataId) 375 { 376 // gpointer gtk_object_get_data_by_id (GtkObject *object, GQuark data_id); 377 return gtk_object_get_data_by_id(gtkObject, dataId); 378 } 379 380 /** 381 * Warning 382 * 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. 383 * Just like gtk_object_remove_data() except that it takes 384 * a GQuark instead of a string, so it is slightly faster. 385 * Remove a specified datum from the object's data associations. 386 * Subsequent calls to gtk_object_get_data() will return NULL. 387 * Use gtk_object_data_try_key() and gtk_object_data_force_id() 388 * to get an id from a string. 389 * Params: 390 * dataId = quark of the key. 391 */ 392 public void removeDataById(GQuark dataId) 393 { 394 // void gtk_object_remove_data_by_id (GtkObject *object, GQuark data_id); 395 gtk_object_remove_data_by_id(gtkObject, dataId); 396 } 397 398 /** 399 * Warning 400 * gtk_object_remove_no_notify_by_id is deprecated and should not be used in newly-written code. Use g_object_steal_qdata() instead. 401 * Just like gtk_object_remove_no_notify() except that it takes 402 * a GQuark instead of a string, so it is slightly faster. 403 * Use gtk_object_data_try_key() and gtk_object_data_force_id() 404 * to get an id from a string. 405 * Params: 406 * keyId = quark of the key. 407 */ 408 public void removeNoNotifyById(GQuark keyId) 409 { 410 // void gtk_object_remove_no_notify_by_id (GtkObject *object, GQuark key_id); 411 gtk_object_remove_no_notify_by_id(gtkObject, keyId); 412 } 413 }