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 = gobject-The-Base-Object-Type.html 27 * outPack = gobject 28 * outFile = ObjectG 29 * strct = GObject 30 * realStrct= 31 * ctorStrct= 32 * clss = ObjectG 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_object_ 41 * - g_ 42 * omit structs: 43 * - GObject 44 * - GObjectClass 45 * omit prefixes: 46 * omit code: 47 * omit signals: 48 * imports: 49 * - gobject.ObjectG 50 * - gobject.ParamSpec 51 * - gobject.Value 52 * - gobject.Closure 53 * - std.gc 54 * - glib.Str 55 * - gtkc.paths 56 * - gtkc.Loader 57 * structWrap: 58 * - GClosure* -> Closure 59 * - GObject* -> ObjectG 60 * - GParamSpec* -> ParamSpec 61 * - GValue* -> Value 62 * module aliases: 63 * local aliases: 64 * overrides: 65 */ 66 67 module gobject.ObjectG; 68 69 public import gtkc.gobjecttypes; 70 71 private import gtkc.gobject; 72 private import glib.ConstructionException; 73 private import gobject.ObjectG; 74 75 private import gobject.Signals; 76 public import gtkc.gdktypes; 77 78 private import gobject.ObjectG; 79 private import gobject.ParamSpec; 80 private import gobject.Value; 81 private import gobject.Closure; 82 private import glib.Str; 83 private import gtkc.paths; 84 private import gtkc.Loader; 85 86 87 version(Tango) { 88 private import tango.core.Memory; 89 90 version = druntime; 91 } else version(D_Version2) { 92 private import core.memory; 93 94 version = druntime; 95 } else { 96 private import std.gc; 97 } 98 99 100 101 /** 102 * Description 103 * GObject is the fundamental type providing the common attributes and 104 * methods for all object types in GTK+, Pango and other libraries 105 * based on GObject. The GObject class provides methods for object 106 * construction and destruction, property access methods, and signal 107 * support. Signals are described in detail in Signals(3). 108 * GInitiallyUnowned is derived from GObject. The only difference between 109 * the two is that the initial reference of a GInitiallyUnowned is flagged 110 * as a floating reference. 111 * This means that it is not specifically claimed to be "owned" by 112 * any code portion. The main motivation for providing floating references is 113 * C convenience. In particular, it allows code to be written as: 114 * $(DDOC_COMMENT example) 115 * If container_add_child() will g_object_ref_sink() the 116 * passed in child, no reference of the newly created child is leaked. 117 * Without floating references, container_add_child() 118 * can only g_object_ref() the new child, so to implement this code without 119 * reference leaks, it would have to be written as: 120 * $(DDOC_COMMENT example) 121 * The floating reference can be converted into 122 * an ordinary reference by calling g_object_ref_sink(). 123 * For already sunken objects (objects that don't have a floating reference 124 * anymore), g_object_ref_sink() is equivalent to g_object_ref() and returns 125 * a new reference. 126 * Since floating references are useful almost exclusively for C convenience, 127 * language bindings that provide automated reference and memory ownership 128 * maintenance (such as smart pointers or garbage collection) therefore don't 129 * need to expose floating references in their API. 130 * Some object implementations may need to save an objects floating state 131 * across certain code portions (an example is GtkMenu), to achive this, the 132 * following sequence can be used: 133 * $(DDOC_COMMENT example) 134 */ 135 public class ObjectG 136 { 137 138 /** the main Gtk struct */ 139 protected GObject* gObject; 140 141 142 public GObject* getObjectGStruct() 143 { 144 return gObject; 145 } 146 147 148 /** the main Gtk struct as a void* */ 149 protected void* getStruct() 150 { 151 return cast(void*)gObject; 152 } 153 154 155 protected bool isGcRoot; 156 157 /** 158 * Sets our main struct and passes store it on the gobject. 159 * Add a gabage collector root to the gtk+ struct so it doesn't get collect 160 */ 161 public this (GObject* gObject) 162 { 163 this.gObject = gObject; 164 if ( gObject !is null ) 165 { 166 setDataFull("GObject", cast(void*)this, cast(GDestroyNotify)&destroyNotify); 167 addToggleRef(cast(GToggleNotify)&toggleNotify, cast(void*)this); 168 169 //If the refCount is largeer then 1 toggleNotify isn't called 170 if (gObject.refCount > 1 && !isGcRoot) 171 { 172 version(druntime) GC.addRoot(cast(void*)this); 173 else std.gc.addRoot(cast(void*)this); 174 175 isGcRoot = true; 176 } 177 178 //Remove the floating reference if there is one. 179 if (isFloating(gObject)) 180 { 181 refSink(gObject); 182 unref(gObject); 183 } 184 185 //When constructed via GtkBuilder set the structs. 186 if ( getStruct() is null) 187 { 188 setStruct(gObject); 189 } 190 } 191 } 192 193 extern(C) 194 { 195 static void destroyNotify(ObjectG obj) 196 { 197 if ( obj.isGcRoot ) 198 { 199 version(druntime) GC.removeRoot(cast(void*)obj); 200 else std.gc.removeRoot(cast(void*)obj); 201 202 obj.isGcRoot = false; 203 } 204 205 obj.gObject = null; 206 } 207 208 static void toggleNotify(ObjectG obj, GObject* object, int isLastRef) 209 { 210 if ( isLastRef && obj.isGcRoot ) 211 { 212 version(druntime) GC.removeRoot(cast(void*)obj); 213 else std.gc.removeRoot(cast(void*)obj); 214 215 obj.isGcRoot = false; 216 } 217 else if ( !obj.isGcRoot ) 218 { 219 version(druntime) GC.addRoot(cast(void*)obj); 220 else std.gc.addRoot(cast(void*)obj); 221 222 obj.isGcRoot = true; 223 } 224 } 225 } 226 227 ~this() 228 { 229 if ( Linker.isLoaded(LIBRARY.GOBJECT) && gObject !is null ) 230 { 231 unref(); 232 } 233 } 234 235 /** 236 * Gets a D Object from the objects table of associations. 237 * Params: 238 * obj = GObject containing the associations. 239 * Returns: the D Object if found, or a newly constructed object if no such Object exists. 240 */ 241 public static RT getDObject(T, RT=T, U)(U obj) 242 { 243 if ( obj is null ) 244 { 245 return null; 246 } 247 248 static if ( is(T : ObjectG) ) 249 { 250 auto p = g_object_get_data(cast(GObject*)obj, Str.toStringz("GObject")); 251 252 if ( p !is null ) 253 { 254 static if ( is(RT == interface ) ) 255 { 256 return cast(RT)cast(ObjectG)p; 257 } 258 else 259 { 260 return cast(RT)p; 261 } 262 } 263 else 264 { 265 return new T(obj); 266 } 267 } 268 else 269 { 270 return new T(obj); 271 } 272 } 273 274 protected void setStruct(GObject* obj) 275 { 276 gObject = cast(GObject*)obj; 277 } 278 279 /** */ 280 public void setProperty(string propertyName, int value) 281 { 282 setProperty(propertyName, new Value(value)); 283 } 284 285 /** */ 286 public void setProperty(string propertyName, string value) 287 { 288 setProperty(propertyName, new Value(value)); 289 } 290 291 /** */ 292 public void setProperty(string propertyName, long value) 293 { 294 //We use g_object_set instead of g_object_set_property, because Value doesn't like longs and ulongs for some reason. 295 g_object_set( gObject, Str.toStringz(propertyName), value, null); 296 } 297 298 /** */ 299 public void setProperty(string propertyName, ulong value) 300 { 301 g_object_set( gObject, Str.toStringz(propertyName), value, null); 302 } 303 304 public void unref() 305 { 306 unref(gObject); 307 } 308 309 public ObjectG doref() 310 { 311 doref(gObject); 312 313 return this; 314 } 315 316 /** 317 */ 318 int[string] connectedSignals; 319 320 void delegate(ParamSpec, ObjectG)[] onNotifyListeners; 321 /** 322 * The notify signal is emitted on an object when one of its 323 * properties has been changed. Note that getting this signal 324 * doesn't guarantee that the value of the property has actually 325 * changed, it may also be emitted when the setter for the property 326 * is called to reinstate the previous value. 327 * This signal is typically used to obtain change notification for a 328 * single property, by specifying the property name as a detail in the 329 * $(DDOC_COMMENT example) 330 * It is important to note that you must use 331 * canonical parameter names as 332 * detail strings for the notify signal. 333 * See Also 334 * GParamSpecObject, g_param_spec_object() 335 */ 336 void addOnNotify(void delegate(ParamSpec, ObjectG) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 337 { 338 if ( !("notify" in connectedSignals) ) 339 { 340 Signals.connectData( 341 getStruct(), 342 "notify", 343 cast(GCallback)&callBackNotify, 344 cast(void*)this, 345 null, 346 connectFlags); 347 connectedSignals["notify"] = 1; 348 } 349 onNotifyListeners ~= dlg; 350 } 351 extern(C) static void callBackNotify(GObject* gobjectStruct, GParamSpec* pspec, ObjectG _objectG) 352 { 353 foreach ( void delegate(ParamSpec, ObjectG) dlg ; _objectG.onNotifyListeners ) 354 { 355 dlg(ObjectG.getDObject!(ParamSpec)(pspec), _objectG); 356 } 357 } 358 359 360 /** 361 * Installs a new property. This is usually done in the class initializer. 362 * Note that it is possible to redefine a property in a derived class, 363 * by installing a property with the same name. This can be useful at times, 364 * e.g. to change the range of allowed values or the default value. 365 * Params: 366 * oclass = a GObjectClass 367 * propertyId = the id for the new property 368 * pspec = the GParamSpec for the new property 369 */ 370 public static void classInstallProperty(GObjectClass* oclass, uint propertyId, ParamSpec pspec) 371 { 372 // void g_object_class_install_property (GObjectClass *oclass, guint property_id, GParamSpec *pspec); 373 g_object_class_install_property(oclass, propertyId, (pspec is null) ? null : pspec.getParamSpecStruct()); 374 } 375 376 /** 377 * Installs new properties from an array of GParamSpecs. This is 378 * usually done in the class initializer. 379 * The property id of each property is the index of each GParamSpec in 380 * the pspecs array. 381 * The property id of 0 is treated specially by GObject and it should not 382 * be used to store a GParamSpec. 383 * This function should be used if you plan to use a static array of 384 * GParamSpecs and g_object_notify_by_pspec(). For instance, this 385 * Since 2.26 386 * Params: 387 * oclass = a GObjectClass 388 * pspecs = the GParamSpecs array 389 * defining the new properties. [array length=n_pspecs] 390 */ 391 public static void classInstallProperties(GObjectClass* oclass, ParamSpec[] pspecs) 392 { 393 // void g_object_class_install_properties (GObjectClass *oclass, guint n_pspecs, GParamSpec **pspecs); 394 395 GParamSpec*[] pspecsArray = new GParamSpec*[pspecs.length]; 396 for ( int i = 0; i < pspecs.length ; i++ ) 397 { 398 pspecsArray[i] = pspecs[i].getParamSpecStruct(); 399 } 400 401 g_object_class_install_properties(oclass, cast(int) pspecs.length, pspecsArray.ptr); 402 } 403 404 /** 405 * Looks up the GParamSpec for a property of a class. 406 * Params: 407 * oclass = a GObjectClass 408 * propertyName = the name of the property to look up 409 * Returns: the GParamSpec for the property, or NULL if the class doesn't have a property of that name. [transfer none] 410 */ 411 public static ParamSpec classFindProperty(GObjectClass* oclass, string propertyName) 412 { 413 // GParamSpec * g_object_class_find_property (GObjectClass *oclass, const gchar *property_name); 414 auto p = g_object_class_find_property(oclass, Str.toStringz(propertyName)); 415 416 if(p is null) 417 { 418 return null; 419 } 420 421 return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p); 422 } 423 424 /** 425 * Get an array of GParamSpec* for all properties of a class. 426 * Params: 427 * oclass = a GObjectClass 428 * Returns: an array of GParamSpec* which should be freed after use. [array length=n_properties][transfer container] 429 */ 430 public static ParamSpec[] classListProperties(GObjectClass* oclass) 431 { 432 // GParamSpec ** g_object_class_list_properties (GObjectClass *oclass, guint *n_properties); 433 uint nProperties; 434 auto p = g_object_class_list_properties(oclass, &nProperties); 435 436 if(p is null) 437 { 438 return null; 439 } 440 441 ParamSpec[] arr = new ParamSpec[nProperties]; 442 for(int i = 0; i < nProperties; i++) 443 { 444 arr[i] = ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p[i]); 445 } 446 447 return arr; 448 } 449 450 /** 451 * Registers property_id as referring to a property with the 452 * name name in a parent class or in an interface implemented 453 * by oclass. This allows this class to override 454 * a property implementation in a parent class or to provide 455 * the implementation of a property from an interface. 456 * Note 457 * Internally, overriding is implemented by creating a property of type 458 * GParamSpecOverride; generally operations that query the properties of 459 * the object class, such as g_object_class_find_property() or 460 * g_object_class_list_properties() will return the overridden 461 * property. However, in one case, the construct_properties argument of 462 * the constructor virtual function, the GParamSpecOverride is passed 463 * instead, so that the param_id field of the GParamSpec will be 464 * correct. For virtually all uses, this makes no difference. If you 465 * need to get the overridden property, you can call 466 * g_param_spec_get_redirect_target(). 467 * Since 2.4 468 * Params: 469 * oclass = a GObjectClass 470 * propertyId = the new property ID 471 * name = the name of a property registered in a parent class or 472 * in an interface of this class. 473 */ 474 public static void classOverrideProperty(GObjectClass* oclass, uint propertyId, string name) 475 { 476 // void g_object_class_override_property (GObjectClass *oclass, guint property_id, const gchar *name); 477 g_object_class_override_property(oclass, propertyId, Str.toStringz(name)); 478 } 479 480 /** 481 * Add a property to an interface; this is only useful for interfaces 482 * that are added to GObject-derived types. Adding a property to an 483 * interface forces all objects classes with that interface to have a 484 * compatible property. The compatible property could be a newly 485 * created GParamSpec, but normally 486 * g_object_class_override_property() will be used so that the object 487 * class only needs to provide an implementation and inherits the 488 * property description, default value, bounds, and so forth from the 489 * interface property. 490 * This function is meant to be called from the interface's default 491 * vtable initialization function (the class_init member of 492 * GTypeInfo.) It must not be called after after class_init has 493 * been called for any object types implementing this interface. 494 * Since 2.4 495 * Params: 496 * iface = any interface vtable for the interface, or the default 497 * vtable for the interface. 498 * pspec = the GParamSpec for the new property 499 */ 500 public static void interfaceInstallProperty(void* iface, ParamSpec pspec) 501 { 502 // void g_object_interface_install_property (gpointer g_iface, GParamSpec *pspec); 503 g_object_interface_install_property(iface, (pspec is null) ? null : pspec.getParamSpecStruct()); 504 } 505 506 /** 507 * Find the GParamSpec with the given name for an 508 * interface. Generally, the interface vtable passed in as g_iface 509 * will be the default vtable from g_type_default_interface_ref(), or, 510 * if you know the interface has already been loaded, 511 * g_type_default_interface_peek(). 512 * Since 2.4 513 * Params: 514 * iface = any interface vtable for the interface, or the default 515 * vtable for the interface 516 * propertyName = name of a property to lookup. 517 * Returns: the GParamSpec for the property of the interface with the name property_name, or NULL if no such property exists. [transfer none] 518 */ 519 public static ParamSpec interfaceFindProperty(void* iface, string propertyName) 520 { 521 // GParamSpec * g_object_interface_find_property (gpointer g_iface, const gchar *property_name); 522 auto p = g_object_interface_find_property(iface, Str.toStringz(propertyName)); 523 524 if(p is null) 525 { 526 return null; 527 } 528 529 return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p); 530 } 531 532 /** 533 * Lists the properties of an interface.Generally, the interface 534 * vtable passed in as g_iface will be the default vtable from 535 * g_type_default_interface_ref(), or, if you know the interface has 536 * already been loaded, g_type_default_interface_peek(). 537 * Since 2.4 538 * Params: 539 * iface = any interface vtable for the interface, or the default 540 * vtable for the interface 541 * Returns: a pointer to an array of pointers to GParamSpec structures. The paramspecs are owned by GLib, but the array should be freed with g_free() when you are done with it. [array length=n_properties_p][transfer container] 542 */ 543 public static ParamSpec[] interfaceListProperties(void* iface) 544 { 545 // GParamSpec ** g_object_interface_list_properties (gpointer g_iface, guint *n_properties_p); 546 uint nPropertiesP; 547 auto p = g_object_interface_list_properties(iface, &nPropertiesP); 548 549 if(p is null) 550 { 551 return null; 552 } 553 554 ParamSpec[] arr = new ParamSpec[nPropertiesP]; 555 for(int i = 0; i < nPropertiesP; i++) 556 { 557 arr[i] = ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p[i]); 558 } 559 560 return arr; 561 } 562 563 /** 564 * Creates a new instance of a GObject subtype and sets its properties. 565 * Construction parameters (see G_PARAM_CONSTRUCT, G_PARAM_CONSTRUCT_ONLY) 566 * which are not explicitly specified are set to their default values. 567 * Rename to: g_object_new 568 * Params: 569 * objectType = the type id of the GObject subtype to instantiate 570 * parameters = an array of GParameter. [array length=n_parameters] 571 * Throws: ConstructionException GTK+ fails to create the object. 572 */ 573 public this (GType objectType, GParameter[] parameters) 574 { 575 // gpointer g_object_newv (GType object_type, guint n_parameters, GParameter *parameters); 576 auto p = g_object_newv(objectType, cast(int) parameters.length, parameters.ptr); 577 if(p is null) 578 { 579 throw new ConstructionException("null returned by g_object_newv(objectType, cast(int) parameters.length, parameters.ptr)"); 580 } 581 this(cast(GObject*) p); 582 } 583 584 /** 585 * Increases the reference count of object. 586 * Params: 587 * object = a GObject. [type GObject.Object] 588 * Returns: the same object. [type GObject.Object][transfer none] 589 */ 590 public static void* doref(void* object) 591 { 592 // gpointer g_object_ref (gpointer object); 593 return g_object_ref(object); 594 } 595 596 /** 597 * Decreases the reference count of object. When its reference count 598 * drops to 0, the object is finalized (i.e. its memory is freed). 599 * Params: 600 * object = a GObject. [type GObject.Object] 601 */ 602 public static void unref(void* object) 603 { 604 // void g_object_unref (gpointer object); 605 g_object_unref(object); 606 } 607 608 /** 609 * Increase the reference count of object, and possibly remove the 610 * floating reference, if object 611 * has a floating reference. 612 * In other words, if the object is floating, then this call "assumes 613 * ownership" of the floating reference, converting it to a normal 614 * reference by clearing the floating flag while leaving the reference 615 * count unchanged. If the object is not floating, then this call 616 * adds a new normal reference increasing the reference count by one. 617 * Since 2.10 618 * Params: 619 * object = a GObject. [type GObject.Object] 620 * Returns: object. [type GObject.Object][transfer none] 621 */ 622 public static void* refSink(void* object) 623 { 624 // gpointer g_object_ref_sink (gpointer object); 625 return g_object_ref_sink(object); 626 } 627 628 /** 629 * Clears a reference to a GObject. 630 * object_ptr must not be NULL. 631 * If the reference is NULL then this function does nothing. 632 * Otherwise, the reference count of the object is decreased and the 633 * pointer is set to NULL. 634 * This function is threadsafe and modifies the pointer atomically, 635 * using memory barriers where needed. 636 * A macro is also included that allows this function to be used without 637 * pointer casts. 638 * Since 2.28 639 * Params: 640 * objectPtr = a pointer to a GObject reference 641 */ 642 public static void clearObject(ref ObjectG objectPtr) 643 { 644 // void g_clear_object (volatile GObject **object_ptr); 645 GObject* outobjectPtr = (objectPtr is null) ? null : objectPtr.getObjectGStruct(); 646 647 g_clear_object(&outobjectPtr); 648 649 objectPtr = ObjectG.getDObject!(ObjectG)(outobjectPtr); 650 } 651 652 /** 653 * Checks whether object has a floating 654 * reference. 655 * Since 2.10 656 * Params: 657 * object = a GObject. [type GObject.Object] 658 * Returns: TRUE if object has a floating reference 659 */ 660 public static int isFloating(void* object) 661 { 662 // gboolean g_object_is_floating (gpointer object); 663 return g_object_is_floating(object); 664 } 665 666 /** 667 * This function is intended for GObject implementations to re-enforce a 668 * floating object reference. 669 * Doing this is seldomly required: all 670 * GInitiallyUnowneds are created with a floating reference which 671 * usually just needs to be sunken by calling g_object_ref_sink(). 672 * Since 2.10 673 */ 674 public void forceFloating() 675 { 676 // void g_object_force_floating (GObject *object); 677 g_object_force_floating(gObject); 678 } 679 680 /** 681 * Adds a weak reference callback to an object. Weak references are 682 * used for notification when an object is finalized. They are called 683 * "weak references" because they allow you to safely hold a pointer 684 * to an object without calling g_object_ref() (g_object_ref() adds a 685 * strong reference, that is, forces the object to stay alive). 686 * Params: 687 * notify = callback to invoke before the object is freed 688 * data = extra data to pass to notify 689 */ 690 public void weakRef(GWeakNotify notify, void* data) 691 { 692 // void g_object_weak_ref (GObject *object, GWeakNotify notify, gpointer data); 693 g_object_weak_ref(gObject, notify, data); 694 } 695 696 /** 697 * Removes a weak reference callback to an object. 698 * Params: 699 * notify = callback to search for 700 * data = data to search for 701 */ 702 public void weakUnref(GWeakNotify notify, void* data) 703 { 704 // void g_object_weak_unref (GObject *object, GWeakNotify notify, gpointer data); 705 g_object_weak_unref(gObject, notify, data); 706 } 707 708 /** 709 * Adds a weak reference from weak_pointer to object to indicate that 710 * the pointer located at weak_pointer_location is only valid during 711 * the lifetime of object. When the object is finalized, 712 * weak_pointer will be set to NULL. 713 * Params: 714 * weakPointerLocation = The memory address of a pointer. [inout] 715 */ 716 public void addWeakPointer(void** weakPointerLocation) 717 { 718 // void g_object_add_weak_pointer (GObject *object, gpointer *weak_pointer_location); 719 g_object_add_weak_pointer(gObject, weakPointerLocation); 720 } 721 722 /** 723 * Removes a weak reference from object that was previously added 724 * using g_object_add_weak_pointer(). The weak_pointer_location has 725 * to match the one used with g_object_add_weak_pointer(). 726 * Params: 727 * weakPointerLocation = The memory address of a pointer. [inout] 728 */ 729 public void removeWeakPointer(void** weakPointerLocation) 730 { 731 // void g_object_remove_weak_pointer (GObject *object, gpointer *weak_pointer_location); 732 g_object_remove_weak_pointer(gObject, weakPointerLocation); 733 } 734 735 /** 736 * Increases the reference count of the object by one and sets a 737 * callback to be called when all other references to the object are 738 * dropped, or when this is already the last reference to the object 739 * and another reference is established. 740 * This functionality is intended for binding object to a proxy 741 * object managed by another memory manager. This is done with two 742 * paired references: the strong reference added by 743 * g_object_add_toggle_ref() and a reverse reference to the proxy 744 * object which is either a strong reference or weak reference. 745 * The setup is that when there are no other references to object, 746 * only a weak reference is held in the reverse direction from object 747 * to the proxy object, but when there are other references held to 748 * object, a strong reference is held. The notify callback is called 749 * when the reference from object to the proxy object should be 750 * toggled from strong to weak (is_last_ref 751 * true) or weak to strong (is_last_ref false). 752 * Since a (normal) reference must be held to the object before 753 * calling g_object_toggle_ref(), the initial state of the reverse 754 * link is always strong. 755 * Multiple toggle references may be added to the same gobject, 756 * however if there are multiple toggle references to an object, none 757 * of them will ever be notified until all but one are removed. For 758 * this reason, you should only ever use a toggle reference if there 759 * is important state in the proxy object. 760 * Since 2.8 761 * Params: 762 * notify = a function to call when this reference is the 763 * last reference to the object, or is no longer 764 * the last reference. 765 * data = data to pass to notify 766 */ 767 public void addToggleRef(GToggleNotify notify, void* data) 768 { 769 // void g_object_add_toggle_ref (GObject *object, GToggleNotify notify, gpointer data); 770 g_object_add_toggle_ref(gObject, notify, data); 771 } 772 773 /** 774 * Removes a reference added with g_object_add_toggle_ref(). The 775 * reference count of the object is decreased by one. 776 * Since 2.8 777 * Params: 778 * notify = a function to call when this reference is the 779 * last reference to the object, or is no longer 780 * the last reference. 781 * data = data to pass to notify 782 */ 783 public void removeToggleRef(GToggleNotify notify, void* data) 784 { 785 // void g_object_remove_toggle_ref (GObject *object, GToggleNotify notify, gpointer data); 786 g_object_remove_toggle_ref(gObject, notify, data); 787 } 788 789 /** 790 * Emits a "notify" signal for the property property_name on object. 791 * When possible, eg. when signaling a property change from within the class 792 * that registered the property, you should use g_object_notify_by_pspec() 793 * instead. 794 * Params: 795 * propertyName = the name of a property installed on the class of object. 796 */ 797 public void notify(string propertyName) 798 { 799 // void g_object_notify (GObject *object, const gchar *property_name); 800 g_object_notify(gObject, Str.toStringz(propertyName)); 801 } 802 803 /** 804 * Emits a "notify" signal for the property specified by pspec on object. 805 * This function omits the property name lookup, hence it is faster than 806 * g_object_notify(). 807 * One way to avoid using g_object_notify() from within the 808 * class that registered the properties, and using g_object_notify_by_pspec() 809 * instead, is to store the GParamSpec used with 810 * Since 2.26 811 * Params: 812 * pspec = the GParamSpec of a property installed on the class of object. 813 */ 814 public void notifyByPspec(ParamSpec pspec) 815 { 816 // void g_object_notify_by_pspec (GObject *object, GParamSpec *pspec); 817 g_object_notify_by_pspec(gObject, (pspec is null) ? null : pspec.getParamSpecStruct()); 818 } 819 820 /** 821 * Increases the freeze count on object. If the freeze count is 822 * non-zero, the emission of "notify" signals on object is 823 * stopped. The signals are queued until the freeze count is decreased 824 * to zero. 825 * This is necessary for accessors that modify multiple properties to prevent 826 * premature notification while the object is still being modified. 827 */ 828 public void freezeNotify() 829 { 830 // void g_object_freeze_notify (GObject *object); 831 g_object_freeze_notify(gObject); 832 } 833 834 /** 835 * Reverts the effect of a previous call to 836 * g_object_freeze_notify(). The freeze count is decreased on object 837 * and when it reaches zero, all queued "notify" signals are emitted. 838 * It is an error to call this function when the freeze count is zero. 839 */ 840 public void thawNotify() 841 { 842 // void g_object_thaw_notify (GObject *object); 843 g_object_thaw_notify(gObject); 844 } 845 846 /** 847 * Gets a named field from the objects table of associations (see g_object_set_data()). 848 * Params: 849 * key = name of the key for that association 850 * Returns: the data if found, or NULL if no such data exists. [transfer none] 851 */ 852 public void* getData(string key) 853 { 854 // gpointer g_object_get_data (GObject *object, const gchar *key); 855 return g_object_get_data(gObject, Str.toStringz(key)); 856 } 857 858 /** 859 * Each object carries around a table of associations from 860 * strings to pointers. This function lets you set an association. 861 * If the object already had an association with that name, 862 * the old association will be destroyed. 863 * Params: 864 * key = name of the key 865 * data = data to associate with that key 866 */ 867 public void setData(string key, void* data) 868 { 869 // void g_object_set_data (GObject *object, const gchar *key, gpointer data); 870 g_object_set_data(gObject, Str.toStringz(key), data); 871 } 872 873 /** 874 * Like g_object_set_data() except it adds notification 875 * for when the association is destroyed, either by setting it 876 * to a different value or when the object is destroyed. 877 * Note that the destroy callback is not called if data is NULL. 878 * Params: 879 * key = name of the key 880 * data = data to associate with that key 881 * destroy = function to call when the association is destroyed 882 */ 883 public void setDataFull(string key, void* data, GDestroyNotify destroy) 884 { 885 // void g_object_set_data_full (GObject *object, const gchar *key, gpointer data, GDestroyNotify destroy); 886 g_object_set_data_full(gObject, Str.toStringz(key), data, destroy); 887 } 888 889 /** 890 * Remove a specified datum from the object's data associations, 891 * without invoking the association's destroy handler. 892 * Params: 893 * key = name of the key 894 * Returns: the data if found, or NULL if no such data exists. [transfer full] 895 */ 896 public void* stealData(string key) 897 { 898 // gpointer g_object_steal_data (GObject *object, const gchar *key); 899 return g_object_steal_data(gObject, Str.toStringz(key)); 900 } 901 902 /** 903 * This function gets back user data pointers stored via 904 * g_object_set_qdata(). 905 * Params: 906 * quark = A GQuark, naming the user data pointer 907 * Returns: The user data pointer set, or NULL. [transfer none] 908 */ 909 public void* getQdata(GQuark quark) 910 { 911 // gpointer g_object_get_qdata (GObject *object, GQuark quark); 912 return g_object_get_qdata(gObject, quark); 913 } 914 915 /** 916 * This sets an opaque, named pointer on an object. 917 * The name is specified through a GQuark (retrived e.g. via 918 * g_quark_from_static_string()), and the pointer 919 * can be gotten back from the object with g_object_get_qdata() 920 * until the object is finalized. 921 * Setting a previously set user data pointer, overrides (frees) 922 * the old pointer set, using NULL as pointer essentially 923 * removes the data stored. 924 * Params: 925 * quark = A GQuark, naming the user data pointer 926 * data = An opaque user data pointer 927 */ 928 public void setQdata(GQuark quark, void* data) 929 { 930 // void g_object_set_qdata (GObject *object, GQuark quark, gpointer data); 931 g_object_set_qdata(gObject, quark, data); 932 } 933 934 /** 935 * This function works like g_object_set_qdata(), but in addition, 936 * a void (*destroy) (gpointer) function may be specified which is 937 * called with data as argument when the object is finalized, or 938 * the data is being overwritten by a call to g_object_set_qdata() 939 * with the same quark. 940 * Params: 941 * quark = A GQuark, naming the user data pointer 942 * data = An opaque user data pointer 943 * destroy = Function to invoke with data as argument, when data 944 * needs to be freed 945 */ 946 public void setQdataFull(GQuark quark, void* data, GDestroyNotify destroy) 947 { 948 // void g_object_set_qdata_full (GObject *object, GQuark quark, gpointer data, GDestroyNotify destroy); 949 g_object_set_qdata_full(gObject, quark, data, destroy); 950 } 951 952 /** 953 * This function gets back user data pointers stored via 954 * g_object_set_qdata() and removes the data from object 955 * without invoking its destroy() function (if any was 956 * set). 957 * Usually, calling this function is only required to update 958 * Params: 959 * quark = A GQuark, naming the user data pointer 960 * Returns: The user data pointer set, or NULL. [transfer full] 961 */ 962 public void* stealQdata(GQuark quark) 963 { 964 // gpointer g_object_steal_qdata (GObject *object, GQuark quark); 965 return g_object_steal_qdata(gObject, quark); 966 } 967 968 /** 969 * Sets a property on an object. 970 * Params: 971 * propertyName = the name of the property to set 972 * value = the value 973 */ 974 public void setProperty(string propertyName, Value value) 975 { 976 // void g_object_set_property (GObject *object, const gchar *property_name, const GValue *value); 977 g_object_set_property(gObject, Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct()); 978 } 979 980 /** 981 * Gets a property of an object. value must have been initialized to the 982 * expected type of the property (or a type to which the expected type can be 983 * transformed) using g_value_init(). 984 * In general, a copy is made of the property contents and the caller is 985 * responsible for freeing the memory by calling g_value_unset(). 986 * Note that g_object_get_property() is really intended for language 987 * bindings, g_object_get() is much more convenient for C programming. 988 * Params: 989 * propertyName = the name of the property to get 990 * value = return location for the property value 991 */ 992 public void getProperty(string propertyName, Value value) 993 { 994 // void g_object_get_property (GObject *object, const gchar *property_name, GValue *value); 995 g_object_get_property(gObject, Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct()); 996 } 997 998 /** 999 * Creates a new instance of a GObject subtype and sets its properties. 1000 * Construction parameters (see G_PARAM_CONSTRUCT, G_PARAM_CONSTRUCT_ONLY) 1001 * which are not explicitly specified are set to their default values. 1002 * Params: 1003 * objectType = the type id of the GObject subtype to instantiate 1004 * firstPropertyName = the name of the first property 1005 * varArgs = the value of the first property, followed optionally by more 1006 * name/value pairs, followed by NULL 1007 * Throws: ConstructionException GTK+ fails to create the object. 1008 */ 1009 public this (GType objectType, string firstPropertyName, void* varArgs) 1010 { 1011 // GObject * g_object_new_valist (GType object_type, const gchar *first_property_name, va_list var_args); 1012 auto p = g_object_new_valist(objectType, Str.toStringz(firstPropertyName), varArgs); 1013 if(p is null) 1014 { 1015 throw new ConstructionException("null returned by g_object_new_valist(objectType, Str.toStringz(firstPropertyName), varArgs)"); 1016 } 1017 this(cast(GObject*) p); 1018 } 1019 1020 /** 1021 * Sets properties on an object. 1022 * Params: 1023 * firstPropertyName = name of the first property to set 1024 * varArgs = value for the first property, followed optionally by more 1025 * name/value pairs, followed by NULL 1026 */ 1027 public void setValist(string firstPropertyName, void* varArgs) 1028 { 1029 // void g_object_set_valist (GObject *object, const gchar *first_property_name, va_list var_args); 1030 g_object_set_valist(gObject, Str.toStringz(firstPropertyName), varArgs); 1031 } 1032 1033 /** 1034 * Gets properties of an object. 1035 * In general, a copy is made of the property contents and the caller 1036 * is responsible for freeing the memory in the appropriate manner for 1037 * the type, for instance by calling g_free() or g_object_unref(). 1038 * See g_object_get(). 1039 * Params: 1040 * firstPropertyName = name of the first property to get 1041 * varArgs = return location for the first property, followed optionally by more 1042 * name/return location pairs, followed by NULL 1043 */ 1044 public void getValist(string firstPropertyName, void* varArgs) 1045 { 1046 // void g_object_get_valist (GObject *object, const gchar *first_property_name, va_list var_args); 1047 g_object_get_valist(gObject, Str.toStringz(firstPropertyName), varArgs); 1048 } 1049 1050 /** 1051 * This function essentially limits the life time of the closure to 1052 * the life time of the object. That is, when the object is finalized, 1053 * the closure is invalidated by calling g_closure_invalidate() on 1054 * it, in order to prevent invocations of the closure with a finalized 1055 * (nonexisting) object. Also, g_object_ref() and g_object_unref() are 1056 * added as marshal guards to the closure, to ensure that an extra 1057 * reference count is held on object during invocation of the 1058 * closure. Usually, this function will be called on closures that 1059 * use this object as closure data. 1060 * Params: 1061 * closure = GClosure to watch 1062 */ 1063 public void watchClosure(Closure closure) 1064 { 1065 // void g_object_watch_closure (GObject *object, GClosure *closure); 1066 g_object_watch_closure(gObject, (closure is null) ? null : closure.getClosureStruct()); 1067 } 1068 1069 /** 1070 * Releases all references to other objects. This can be used to break 1071 * reference cycles. 1072 * This functions should only be called from object system implementations. 1073 */ 1074 public void runDispose() 1075 { 1076 // void g_object_run_dispose (GObject *object); 1077 g_object_run_dispose(gObject); 1078 } 1079 }