1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gobject.ObjectG; 26 27 private import core.memory; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import glib.c.functions : g_datalist_get_flags; 31 private import gobject.Binding; 32 private import gobject.Closure; 33 private import gobject.DClosure; 34 private import gobject.ObjectG; 35 private import gobject.ParamSpec; 36 private import gobject.Signals; 37 private import gobject.TypeInterface; 38 private import gobject.Value; 39 private import gobject.c.functions; 40 public import gobject.c.types; 41 public import gtkc.gobjecttypes; 42 private import gtkd.Loader; 43 private import std.traits; 44 45 46 /** 47 * All the fields in the GObject structure are private 48 * to the #GObject implementation and should never be accessed directly. 49 */ 50 public class ObjectG 51 { 52 /** the main Gtk struct */ 53 protected GObject* gObject; 54 protected bool ownedRef; 55 56 /** Get the main Gtk struct */ 57 public GObject* getObjectGStruct(bool transferOwnership = false) 58 { 59 if (transferOwnership) 60 ownedRef = false; 61 return gObject; 62 } 63 64 /** the main Gtk struct as a void* */ 65 protected void* getStruct() 66 { 67 return cast(void*)gObject; 68 } 69 70 protected bool isGcRoot; 71 package DClosure[gulong] signals; 72 73 /** 74 * Sets our main struct and passes store it on the gobject. 75 * Add a gabage collector root to the gtk+ struct so it doesn't get collect 76 */ 77 public this (GObject* gObject, bool ownedRef = false) 78 { 79 this.gObject = gObject; 80 if ( gObject !is null ) 81 { 82 setDataFull("GObject", cast(void*)this, cast(GDestroyNotify)&destroyNotify); 83 addToggleRef(cast(GToggleNotify)&toggleNotify, cast(void*)this); 84 85 //If the refCount is larger then 1 toggleNotify isn't called 86 if (gObject.refCount > 1 && !isGcRoot) 87 { 88 GC.addRoot(cast(void*)this); 89 isGcRoot = true; 90 } 91 92 //Remove the floating reference if there is one. 93 if ( isFloating() ) 94 { 95 refSink(); 96 unref(); 97 } 98 //If we already owned this reference remove the one added by addToggleRef. 99 else if ( ownedRef ) 100 { 101 unref(); 102 } 103 } 104 } 105 106 extern(C) 107 { 108 static void destroyNotify(ObjectG obj) 109 { 110 if ( obj.isGcRoot ) 111 { 112 GC.removeRoot(cast(void*)obj); 113 obj.isGcRoot = false; 114 } 115 116 if ( obj.hasToggleRef() ) 117 obj.removeToggleRef(cast(GToggleNotify)&toggleNotify, cast(void*)obj); 118 119 obj.gObject = null; 120 } 121 122 static void toggleNotify(ObjectG obj, GObject* object, int isLastRef) 123 { 124 if ( isLastRef && obj.isGcRoot ) 125 { 126 GC.removeRoot(cast(void*)obj); 127 obj.isGcRoot = false; 128 } 129 else if ( !obj.isGcRoot ) 130 { 131 GC.addRoot(cast(void*)obj); 132 obj.isGcRoot = true; 133 } 134 } 135 } 136 137 ~this() 138 { 139 static if ( isPointer!(typeof(g_object_steal_data)) ) 140 bool libLoaded = Linker.isLoaded(LIBRARY_GOBJECT); 141 else 142 enum libLoaded = true; 143 144 if ( libLoaded && gObject !is null ) 145 { 146 // Remove the GDestroyNotify callback, 147 // for when the D object is destroyed before the C one. 148 g_object_steal_data(gObject, cast(char*)"GObject"); 149 150 if ( isGcRoot ) 151 { 152 GC.removeRoot(cast(void*)this); 153 isGcRoot = false; 154 } 155 156 if ( hasToggleRef() ) 157 g_object_remove_toggle_ref(gObject, cast(GToggleNotify)&toggleNotify, cast(void*)this); 158 else 159 g_object_unref(gObject); 160 } 161 } 162 163 /** */ 164 T opCast(T)() 165 { 166 if ( !this ) 167 return null; 168 169 static if ( is(T : ObjectG) 170 && !is(T == interface) 171 && is(typeof(new T(cast(typeof(T.tupleof[0]))gObject, false))) ) 172 { 173 //If a regular cast works, return the result. 174 if ( auto r = cast(T)super ) 175 return r; 176 177 //Prints a warning if the cast is invalid. 178 //g_type_check_instance_cast(cast(GTypeInstance*)gObject, T.getType()); 179 180 //Can we cast this type to T. 181 if ( !g_type_is_a(gObject.gTypeInstance.gClass.gType, T.getType()) ) 182 return null; 183 184 //Remove the GDestroyNotify callback for the original d object. 185 g_object_steal_data(gObject, "GObject"); 186 //Remove the original object as a GC root if needed. 187 if ( isGcRoot ) 188 { 189 GC.removeRoot(cast(void*)this); 190 isGcRoot = false; 191 } 192 193 if ( hasToggleRef() ) 194 { 195 //Add a reference for the original D object before we remove the toggle reference. 196 g_object_ref(gObject); 197 g_object_remove_toggle_ref(gObject, cast(GToggleNotify)&toggleNotify, cast(void*)this); 198 } 199 200 //The new object handles the memory management. 201 return new T(cast(typeof(T.tupleof[0]))gObject, false); 202 } 203 else static if ( is(T == interface) 204 && hasStaticMember!(T, "getType") 205 && is(ReturnType!(T.getType) == GType) ) 206 { 207 //If a regular cast works, return the result. 208 if ( auto r = cast(T)super ) 209 return r; 210 211 //Do we implement interface T. 212 if ( !g_type_is_a(gObject.gTypeInstance.gClass.gType, T.getType()) ) 213 return null; 214 215 return getInterfaceInstance!T(gObject); 216 } 217 else 218 return cast(T)super; 219 } 220 221 unittest 222 { 223 ObjectG obj = null; 224 225 assert( (cast(Binding)obj) is null ); 226 } 227 228 /** 229 * Gets a D Object from the objects table of associations. 230 * Params: 231 * obj = GObject containing the associations. 232 * Returns: the D Object if found, or a newly constructed object if no such Object exists. 233 */ 234 public static RT getDObject(T, RT=T, U)(U obj, bool ownedRef = false) 235 { 236 if ( obj is null ) 237 { 238 return null; 239 } 240 241 static if ( is(T : ObjectG) && !is(RT == interface) ) 242 { 243 auto p = g_object_get_data(cast(GObject*)obj, Str.toStringz("GObject")); 244 245 if ( p !is null ) 246 return cast(RT)cast(ObjectG)p; 247 else 248 return new T(obj, ownedRef); 249 } 250 else static if ( is(RT == interface) && hasMember!(RT, "getType") && is(ReturnType!(RT.getType) == GType) ) 251 { 252 auto p = g_object_get_data(cast(GObject*)obj, Str.toStringz("GObject")); 253 254 if ( p !is null ) 255 return cast(RT)cast(ObjectG)p; 256 else 257 return getInterfaceInstance!RT(cast(GObject*)obj); 258 } 259 else 260 { 261 return new T(obj, ownedRef); 262 } 263 } 264 265 private static I getInterfaceInstance(I)(GObject* instance) 266 { 267 static class Impl: ObjectG, I 268 { 269 public this (GObject* gObject, bool ownedRef = false) 270 { 271 super(gObject, ownedRef); 272 } 273 274 /** the main Gtk struct as a void* */ 275 protected override void* getStruct() 276 { 277 return cast(void*)gObject; 278 } 279 280 // add the interface capabilities 281 mixin("import "~ moduleName!I[0..$-2] ~"T;import "~ moduleName!I ~"; mixin "~ __traits(identifier, I)[0..$-2] ~"T!("~__traits(identifier, Impl)~");"); 282 } 283 284 ClassInfo ci = Impl.classinfo; 285 Impl iface; 286 void* p; 287 288 //Skip all the setup for the memory management, 289 //and only add an extra reference for the instance returned. 290 p = GC.malloc(ci.initializer.length, GC.BlkAttr.FINALIZE, ci); 291 p[0..ci.initializer.length] = ci.initializer; 292 iface = cast(Impl)p; 293 iface.gObject = instance; 294 iface.doref(); 295 296 return iface; 297 } 298 299 /** 300 * Is there a toggle ref connected to this object. 301 */ 302 private bool hasToggleRef() 303 { 304 enum TOGGLE_REF_FLAG = 0x1; 305 306 if ( (g_datalist_get_flags(&gObject.qdata) & TOGGLE_REF_FLAG) != 0 ) 307 //TODO: Assumes we always have the gObject data set if the toggleRef is connected to this instance. 308 return (g_object_get_data(gObject, cast(char*)"GObject") is cast(void*)this); 309 else 310 return false; 311 } 312 313 public void removeGcRoot() 314 { 315 if ( hasToggleRef() ) 316 { 317 g_object_ref(gObject); 318 g_object_remove_toggle_ref(gObject, cast(GToggleNotify)&toggleNotify, cast(void*)this); 319 } 320 321 if ( isGcRoot ) 322 { 323 GC.removeRoot(cast(void*)this); 324 isGcRoot = false; 325 } 326 } 327 328 /** */ 329 public void setProperty(T)(string propertyName, T value) 330 { 331 setProperty(propertyName, new Value(value)); 332 } 333 334 deprecated("Use the member function") 335 public static void unref(ObjectG obj) 336 { 337 obj.unref(); 338 } 339 340 deprecated("Use the member function") 341 public static ObjectG doref(ObjectG obj) 342 { 343 return obj.doref(); 344 } 345 346 /** 347 * The notify signal is emitted on an object when one of its 348 * properties has been changed. Note that getting this signal 349 * doesn't guarantee that the value of the property has actually 350 * changed, it may also be emitted when the setter for the property 351 * is called to reinstate the previous value. 352 * 353 * This signal is typically used to obtain change notification for a 354 * single property. 355 * 356 * It is important to note that you must use 357 * canonical parameter names for the property. 358 * 359 * Params: 360 * dlg = The callback. 361 * property = Set this if you only want to receive the signal for a specific property. 362 * connectFlags = The behavior of the signal's connection. 363 */ 364 gulong addOnNotify(void delegate(ParamSpec, ObjectG) dlg, string property = "", ConnectFlags connectFlags=cast(ConnectFlags)0) 365 { 366 string signalName; 367 368 if ( property == "" ) 369 signalName = "notify"; 370 else 371 signalName = "notify::"~ property; 372 373 return Signals.connect(this, signalName, dlg, connectFlags ^ ConnectFlags.SWAPPED); 374 } 375 376 /** 377 */ 378 379 /** */ 380 public static GType getType() 381 { 382 return g_initially_unowned_get_type(); 383 } 384 385 /** 386 * Creates a new instance of a #GObject subtype and sets its properties. 387 * 388 * Construction parameters (see #G_PARAM_CONSTRUCT, #G_PARAM_CONSTRUCT_ONLY) 389 * which are not explicitly specified are set to their default values. 390 * 391 * Params: 392 * objectType = the type id of the #GObject subtype to instantiate 393 * firstPropertyName = the name of the first property 394 * varArgs = the value of the first property, followed optionally by more 395 * name/value pairs, followed by %NULL 396 * 397 * Returns: a new instance of @object_type 398 * 399 * Throws: ConstructionException GTK+ fails to create the object. 400 */ 401 public this(GType objectType, string firstPropertyName, void* varArgs) 402 { 403 auto p = g_object_new_valist(objectType, Str.toStringz(firstPropertyName), varArgs); 404 405 if(p is null) 406 { 407 throw new ConstructionException("null returned by new_valist"); 408 } 409 410 this(cast(GObject*) p, true); 411 } 412 413 /** 414 * Creates a new instance of a #GObject subtype and sets its properties using 415 * the provided arrays. Both arrays must have exactly @n_properties elements, 416 * and the names and values correspond by index. 417 * 418 * Construction parameters (see %G_PARAM_CONSTRUCT, %G_PARAM_CONSTRUCT_ONLY) 419 * which are not explicitly specified are set to their default values. 420 * 421 * Params: 422 * objectType = the object type to instantiate 423 * names = the names of each property to be set 424 * values = the values of each property to be set 425 * 426 * Returns: a new instance of 427 * @object_type 428 * 429 * Since: 2.54 430 * 431 * Throws: ConstructionException GTK+ fails to create the object. 432 */ 433 public this(GType objectType, string[] names, Value[] values) 434 { 435 GValue[] valuesArray = new GValue[values.length]; 436 for ( int i = 0; i < values.length; i++ ) 437 { 438 valuesArray[i] = *(values[i].getValueStruct()); 439 } 440 441 auto p = g_object_new_with_properties(objectType, cast(uint)values.length, Str.toStringzArray(names), valuesArray.ptr); 442 443 if(p is null) 444 { 445 throw new ConstructionException("null returned by new_with_properties"); 446 } 447 448 this(cast(GObject*) p, true); 449 } 450 451 /** 452 * Creates a new instance of a #GObject subtype and sets its properties. 453 * 454 * Construction parameters (see #G_PARAM_CONSTRUCT, #G_PARAM_CONSTRUCT_ONLY) 455 * which are not explicitly specified are set to their default values. 456 * 457 * Deprecated: Use g_object_new_with_properties() instead. 458 * deprecated. See #GParameter for more information. 459 * 460 * Params: 461 * objectType = the type id of the #GObject subtype to instantiate 462 * parameters = an array of #GParameter 463 * 464 * Returns: a new instance of 465 * @object_type 466 * 467 * Throws: ConstructionException GTK+ fails to create the object. 468 */ 469 public this(GType objectType, GParameter[] parameters) 470 { 471 auto p = g_object_newv(objectType, cast(uint)parameters.length, parameters.ptr); 472 473 if(p is null) 474 { 475 throw new ConstructionException("null returned by newv"); 476 } 477 478 this(cast(GObject*) p, true); 479 } 480 481 /** */ 482 public static size_t compatControl(size_t what, void* data) 483 { 484 return g_object_compat_control(what, data); 485 } 486 487 /** 488 * Find the #GParamSpec with the given name for an 489 * interface. Generally, the interface vtable passed in as @g_iface 490 * will be the default vtable from g_type_default_interface_ref(), or, 491 * if you know the interface has already been loaded, 492 * g_type_default_interface_peek(). 493 * 494 * Params: 495 * gIface = any interface vtable for the 496 * interface, or the default vtable for the interface 497 * propertyName = name of a property to lookup. 498 * 499 * Returns: the #GParamSpec for the property of the 500 * interface with the name @property_name, or %NULL if no 501 * such property exists. 502 * 503 * Since: 2.4 504 */ 505 public static ParamSpec interfaceFindProperty(TypeInterface gIface, string propertyName) 506 { 507 auto p = g_object_interface_find_property((gIface is null) ? null : gIface.getTypeInterfaceStruct(), Str.toStringz(propertyName)); 508 509 if(p is null) 510 { 511 return null; 512 } 513 514 return ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p); 515 } 516 517 /** 518 * Add a property to an interface; this is only useful for interfaces 519 * that are added to GObject-derived types. Adding a property to an 520 * interface forces all objects classes with that interface to have a 521 * compatible property. The compatible property could be a newly 522 * created #GParamSpec, but normally 523 * g_object_class_override_property() will be used so that the object 524 * class only needs to provide an implementation and inherits the 525 * property description, default value, bounds, and so forth from the 526 * interface property. 527 * 528 * This function is meant to be called from the interface's default 529 * vtable initialization function (the @class_init member of 530 * #GTypeInfo.) It must not be called after after @class_init has 531 * been called for any object types implementing this interface. 532 * 533 * If @pspec is a floating reference, it will be consumed. 534 * 535 * Params: 536 * gIface = any interface vtable for the 537 * interface, or the default 538 * vtable for the interface. 539 * pspec = the #GParamSpec for the new property 540 * 541 * Since: 2.4 542 */ 543 public static void interfaceInstallProperty(TypeInterface gIface, ParamSpec pspec) 544 { 545 g_object_interface_install_property((gIface is null) ? null : gIface.getTypeInterfaceStruct(), (pspec is null) ? null : pspec.getParamSpecStruct()); 546 } 547 548 /** 549 * Lists the properties of an interface.Generally, the interface 550 * vtable passed in as @g_iface will be the default vtable from 551 * g_type_default_interface_ref(), or, if you know the interface has 552 * already been loaded, g_type_default_interface_peek(). 553 * 554 * Params: 555 * gIface = any interface vtable for the 556 * interface, or the default vtable for the interface 557 * 558 * Returns: a 559 * pointer to an array of pointers to #GParamSpec 560 * structures. The paramspecs are owned by GLib, but the 561 * array should be freed with g_free() when you are done with 562 * it. 563 * 564 * Since: 2.4 565 */ 566 public static ParamSpec[] interfaceListProperties(TypeInterface gIface) 567 { 568 uint nPropertiesP; 569 570 auto p = g_object_interface_list_properties((gIface is null) ? null : gIface.getTypeInterfaceStruct(), &nPropertiesP); 571 572 if(p is null) 573 { 574 return null; 575 } 576 577 ParamSpec[] arr = new ParamSpec[nPropertiesP]; 578 for(int i = 0; i < nPropertiesP; i++) 579 { 580 arr[i] = ObjectG.getDObject!(ParamSpec)(cast(GParamSpec*) p[i]); 581 } 582 583 return arr; 584 } 585 586 /** 587 * Increases the reference count of the object by one and sets a 588 * callback to be called when all other references to the object are 589 * dropped, or when this is already the last reference to the object 590 * and another reference is established. 591 * 592 * This functionality is intended for binding @object to a proxy 593 * object managed by another memory manager. This is done with two 594 * paired references: the strong reference added by 595 * g_object_add_toggle_ref() and a reverse reference to the proxy 596 * object which is either a strong reference or weak reference. 597 * 598 * The setup is that when there are no other references to @object, 599 * only a weak reference is held in the reverse direction from @object 600 * to the proxy object, but when there are other references held to 601 * @object, a strong reference is held. The @notify callback is called 602 * when the reference from @object to the proxy object should be 603 * "toggled" from strong to weak (@is_last_ref true) or weak to strong 604 * (@is_last_ref false). 605 * 606 * Since a (normal) reference must be held to the object before 607 * calling g_object_add_toggle_ref(), the initial state of the reverse 608 * link is always strong. 609 * 610 * Multiple toggle references may be added to the same gobject, 611 * however if there are multiple toggle references to an object, none 612 * of them will ever be notified until all but one are removed. For 613 * this reason, you should only ever use a toggle reference if there 614 * is important state in the proxy object. 615 * 616 * Params: 617 * notify = a function to call when this reference is the 618 * last reference to the object, or is no longer 619 * the last reference. 620 * data = data to pass to @notify 621 * 622 * Since: 2.8 623 */ 624 public void addToggleRef(GToggleNotify notify, void* data) 625 { 626 g_object_add_toggle_ref(gObject, notify, data); 627 } 628 629 /** 630 * Adds a weak reference from weak_pointer to @object to indicate that 631 * the pointer located at @weak_pointer_location is only valid during 632 * the lifetime of @object. When the @object is finalized, 633 * @weak_pointer will be set to %NULL. 634 * 635 * Note that as with g_object_weak_ref(), the weak references created by 636 * this method are not thread-safe: they cannot safely be used in one 637 * thread if the object's last g_object_unref() might happen in another 638 * thread. Use #GWeakRef if thread-safety is required. 639 * 640 * Params: 641 * weakPointerLocation = The memory address 642 * of a pointer. 643 */ 644 public void addWeakPointer(ref void* weakPointerLocation) 645 { 646 g_object_add_weak_pointer(gObject, &weakPointerLocation); 647 } 648 649 /** 650 * Creates a binding between @source_property on @source and @target_property 651 * on @target. Whenever the @source_property is changed the @target_property is 652 * updated using the same value. For instance: 653 * 654 * |[ 655 * g_object_bind_property (action, "active", widget, "sensitive", 0); 656 * ]| 657 * 658 * Will result in the "sensitive" property of the widget #GObject instance to be 659 * updated with the same value of the "active" property of the action #GObject 660 * instance. 661 * 662 * If @flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual: 663 * if @target_property on @target changes then the @source_property on @source 664 * will be updated as well. 665 * 666 * The binding will automatically be removed when either the @source or the 667 * @target instances are finalized. To remove the binding without affecting the 668 * @source and the @target you can just call g_object_unref() on the returned 669 * #GBinding instance. 670 * 671 * A #GObject can have multiple bindings. 672 * 673 * Params: 674 * sourceProperty = the property on @source to bind 675 * target = the target #GObject 676 * targetProperty = the property on @target to bind 677 * flags = flags to pass to #GBinding 678 * 679 * Returns: the #GBinding instance representing the 680 * binding between the two #GObject instances. The binding is released 681 * whenever the #GBinding reference count reaches zero. 682 * 683 * Since: 2.26 684 */ 685 public Binding bindProperty(string sourceProperty, ObjectG target, string targetProperty, GBindingFlags flags) 686 { 687 auto p = g_object_bind_property(gObject, Str.toStringz(sourceProperty), (target is null) ? null : target.getObjectGStruct(), Str.toStringz(targetProperty), flags); 688 689 if(p is null) 690 { 691 return null; 692 } 693 694 return ObjectG.getDObject!(Binding)(cast(GBinding*) p); 695 } 696 697 /** 698 * Complete version of g_object_bind_property(). 699 * 700 * Creates a binding between @source_property on @source and @target_property 701 * on @target, allowing you to set the transformation functions to be used by 702 * the binding. 703 * 704 * If @flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual: 705 * if @target_property on @target changes then the @source_property on @source 706 * will be updated as well. The @transform_from function is only used in case 707 * of bidirectional bindings, otherwise it will be ignored 708 * 709 * The binding will automatically be removed when either the @source or the 710 * @target instances are finalized. To remove the binding without affecting the 711 * @source and the @target you can just call g_object_unref() on the returned 712 * #GBinding instance. 713 * 714 * A #GObject can have multiple bindings. 715 * 716 * The same @user_data parameter will be used for both @transform_to 717 * and @transform_from transformation functions; the @notify function will 718 * be called once, when the binding is removed. If you need different data 719 * for each transformation function, please use 720 * g_object_bind_property_with_closures() instead. 721 * 722 * Params: 723 * sourceProperty = the property on @source to bind 724 * target = the target #GObject 725 * targetProperty = the property on @target to bind 726 * flags = flags to pass to #GBinding 727 * transformTo = the transformation function 728 * from the @source to the @target, or %NULL to use the default 729 * transformFrom = the transformation function 730 * from the @target to the @source, or %NULL to use the default 731 * userData = custom data to be passed to the transformation functions, 732 * or %NULL 733 * notify = a function to call when disposing the binding, to free 734 * resources used by the transformation functions, or %NULL if not required 735 * 736 * Returns: the #GBinding instance representing the 737 * binding between the two #GObject instances. The binding is released 738 * whenever the #GBinding reference count reaches zero. 739 * 740 * Since: 2.26 741 */ 742 public Binding bindPropertyFull(string sourceProperty, ObjectG target, string targetProperty, GBindingFlags flags, GBindingTransformFunc transformTo, GBindingTransformFunc transformFrom, void* userData, GDestroyNotify notify) 743 { 744 auto p = g_object_bind_property_full(gObject, Str.toStringz(sourceProperty), (target is null) ? null : target.getObjectGStruct(), Str.toStringz(targetProperty), flags, transformTo, transformFrom, userData, notify); 745 746 if(p is null) 747 { 748 return null; 749 } 750 751 return ObjectG.getDObject!(Binding)(cast(GBinding*) p); 752 } 753 754 /** 755 * Creates a binding between @source_property on @source and @target_property 756 * on @target, allowing you to set the transformation functions to be used by 757 * the binding. 758 * 759 * This function is the language bindings friendly version of 760 * g_object_bind_property_full(), using #GClosures instead of 761 * function pointers. 762 * 763 * Params: 764 * sourceProperty = the property on @source to bind 765 * target = the target #GObject 766 * targetProperty = the property on @target to bind 767 * flags = flags to pass to #GBinding 768 * transformTo = a #GClosure wrapping the transformation function 769 * from the @source to the @target, or %NULL to use the default 770 * transformFrom = a #GClosure wrapping the transformation function 771 * from the @target to the @source, or %NULL to use the default 772 * 773 * Returns: the #GBinding instance representing the 774 * binding between the two #GObject instances. The binding is released 775 * whenever the #GBinding reference count reaches zero. 776 * 777 * Since: 2.26 778 */ 779 public Binding bindPropertyWithClosures(string sourceProperty, ObjectG target, string targetProperty, GBindingFlags flags, Closure transformTo, Closure transformFrom) 780 { 781 auto p = g_object_bind_property_with_closures(gObject, Str.toStringz(sourceProperty), (target is null) ? null : target.getObjectGStruct(), Str.toStringz(targetProperty), flags, (transformTo is null) ? null : transformTo.getClosureStruct(), (transformFrom is null) ? null : transformFrom.getClosureStruct()); 782 783 if(p is null) 784 { 785 return null; 786 } 787 788 return ObjectG.getDObject!(Binding)(cast(GBinding*) p); 789 } 790 791 /** 792 * This is a variant of g_object_get_data() which returns 793 * a 'duplicate' of the value. @dup_func defines the 794 * meaning of 'duplicate' in this context, it could e.g. 795 * take a reference on a ref-counted object. 796 * 797 * If the @key is not set on the object then @dup_func 798 * will be called with a %NULL argument. 799 * 800 * Note that @dup_func is called while user data of @object 801 * is locked. 802 * 803 * This function can be useful to avoid races when multiple 804 * threads are using object data on the same key on the same 805 * object. 806 * 807 * Params: 808 * key = a string, naming the user data pointer 809 * dupFunc = function to dup the value 810 * userData = passed as user_data to @dup_func 811 * 812 * Returns: the result of calling @dup_func on the value 813 * associated with @key on @object, or %NULL if not set. 814 * If @dup_func is %NULL, the value is returned 815 * unmodified. 816 * 817 * Since: 2.34 818 */ 819 public void* dupData(string key, GDuplicateFunc dupFunc, void* userData) 820 { 821 return g_object_dup_data(gObject, Str.toStringz(key), dupFunc, userData); 822 } 823 824 /** 825 * This is a variant of g_object_get_qdata() which returns 826 * a 'duplicate' of the value. @dup_func defines the 827 * meaning of 'duplicate' in this context, it could e.g. 828 * take a reference on a ref-counted object. 829 * 830 * If the @quark is not set on the object then @dup_func 831 * will be called with a %NULL argument. 832 * 833 * Note that @dup_func is called while user data of @object 834 * is locked. 835 * 836 * This function can be useful to avoid races when multiple 837 * threads are using object data on the same key on the same 838 * object. 839 * 840 * Params: 841 * quark = a #GQuark, naming the user data pointer 842 * dupFunc = function to dup the value 843 * userData = passed as user_data to @dup_func 844 * 845 * Returns: the result of calling @dup_func on the value 846 * associated with @quark on @object, or %NULL if not set. 847 * If @dup_func is %NULL, the value is returned 848 * unmodified. 849 * 850 * Since: 2.34 851 */ 852 public void* dupQdata(GQuark quark, GDuplicateFunc dupFunc, void* userData) 853 { 854 return g_object_dup_qdata(gObject, quark, dupFunc, userData); 855 } 856 857 /** 858 * This function is intended for #GObject implementations to re-enforce 859 * a [floating][floating-ref] object reference. Doing this is seldom 860 * required: all #GInitiallyUnowneds are created with a floating reference 861 * which usually just needs to be sunken by calling g_object_ref_sink(). 862 * 863 * Since: 2.10 864 */ 865 public void forceFloating() 866 { 867 g_object_force_floating(gObject); 868 } 869 870 /** 871 * Increases the freeze count on @object. If the freeze count is 872 * non-zero, the emission of "notify" signals on @object is 873 * stopped. The signals are queued until the freeze count is decreased 874 * to zero. Duplicate notifications are squashed so that at most one 875 * #GObject::notify signal is emitted for each property modified while the 876 * object is frozen. 877 * 878 * This is necessary for accessors that modify multiple properties to prevent 879 * premature notification while the object is still being modified. 880 */ 881 public void freezeNotify() 882 { 883 g_object_freeze_notify(gObject); 884 } 885 886 /** 887 * Gets a named field from the objects table of associations (see g_object_set_data()). 888 * 889 * Params: 890 * key = name of the key for that association 891 * 892 * Returns: the data if found, 893 * or %NULL if no such data exists. 894 */ 895 public void* getData(string key) 896 { 897 return g_object_get_data(gObject, Str.toStringz(key)); 898 } 899 900 /** 901 * Gets a property of an object. @value must have been initialized to the 902 * expected type of the property (or a type to which the expected type can be 903 * transformed) using g_value_init(). 904 * 905 * In general, a copy is made of the property contents and the caller is 906 * responsible for freeing the memory by calling g_value_unset(). 907 * 908 * Note that g_object_get_property() is really intended for language 909 * bindings, g_object_get() is much more convenient for C programming. 910 * 911 * Params: 912 * propertyName = the name of the property to get 913 * value = return location for the property value 914 */ 915 public void getProperty(string propertyName, Value value) 916 { 917 g_object_get_property(gObject, Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct()); 918 } 919 920 /** 921 * This function gets back user data pointers stored via 922 * g_object_set_qdata(). 923 * 924 * Params: 925 * quark = A #GQuark, naming the user data pointer 926 * 927 * Returns: The user data pointer set, or %NULL 928 */ 929 public void* getQdata(GQuark quark) 930 { 931 return g_object_get_qdata(gObject, quark); 932 } 933 934 /** 935 * Gets properties of an object. 936 * 937 * In general, a copy is made of the property contents and the caller 938 * is responsible for freeing the memory in the appropriate manner for 939 * the type, for instance by calling g_free() or g_object_unref(). 940 * 941 * See g_object_get(). 942 * 943 * Params: 944 * firstPropertyName = name of the first property to get 945 * varArgs = return location for the first property, followed optionally by more 946 * name/return location pairs, followed by %NULL 947 */ 948 public void getValist(string firstPropertyName, void* varArgs) 949 { 950 g_object_get_valist(gObject, Str.toStringz(firstPropertyName), varArgs); 951 } 952 953 /** 954 * Gets @n_properties properties for an @object. 955 * Obtained properties will be set to @values. All properties must be valid. 956 * Warnings will be emitted and undefined behaviour may result if invalid 957 * properties are passed in. 958 * 959 * Params: 960 * names = the names of each property to get 961 * values = the values of each property to get 962 * 963 * Since: 2.54 964 */ 965 public void getv(string[] names, Value[] values) 966 { 967 GValue[] valuesArray = new GValue[values.length]; 968 for ( int i = 0; i < values.length; i++ ) 969 { 970 valuesArray[i] = *(values[i].getValueStruct()); 971 } 972 973 g_object_getv(gObject, cast(uint)values.length, Str.toStringzArray(names), valuesArray.ptr); 974 } 975 976 /** 977 * Checks whether @object has a [floating][floating-ref] reference. 978 * 979 * Returns: %TRUE if @object has a floating reference 980 * 981 * Since: 2.10 982 */ 983 public bool isFloating() 984 { 985 return g_object_is_floating(gObject) != 0; 986 } 987 988 /** 989 * Emits a "notify" signal for the property @property_name on @object. 990 * 991 * When possible, eg. when signaling a property change from within the class 992 * that registered the property, you should use g_object_notify_by_pspec() 993 * instead. 994 * 995 * Note that emission of the notify signal may be blocked with 996 * g_object_freeze_notify(). In this case, the signal emissions are queued 997 * and will be emitted (in reverse order) when g_object_thaw_notify() is 998 * called. 999 * 1000 * Params: 1001 * propertyName = the name of a property installed on the class of @object. 1002 */ 1003 public void notify(string propertyName) 1004 { 1005 g_object_notify(gObject, Str.toStringz(propertyName)); 1006 } 1007 1008 /** 1009 * Emits a "notify" signal for the property specified by @pspec on @object. 1010 * 1011 * This function omits the property name lookup, hence it is faster than 1012 * g_object_notify(). 1013 * 1014 * One way to avoid using g_object_notify() from within the 1015 * class that registered the properties, and using g_object_notify_by_pspec() 1016 * instead, is to store the GParamSpec used with 1017 * g_object_class_install_property() inside a static array, e.g.: 1018 * 1019 * |[<!-- language="C" --> 1020 * enum 1021 * { 1022 * PROP_0, 1023 * PROP_FOO, 1024 * PROP_LAST 1025 * }; 1026 * 1027 * static GParamSpec *properties[PROP_LAST]; 1028 * 1029 * static void 1030 * my_object_class_init (MyObjectClass *klass) 1031 * { 1032 * properties[PROP_FOO] = g_param_spec_int ("foo", "Foo", "The foo", 1033 * 0, 100, 1034 * 50, 1035 * G_PARAM_READWRITE); 1036 * g_object_class_install_property (gobject_class, 1037 * PROP_FOO, 1038 * properties[PROP_FOO]); 1039 * } 1040 * ]| 1041 * 1042 * and then notify a change on the "foo" property with: 1043 * 1044 * |[<!-- language="C" --> 1045 * g_object_notify_by_pspec (self, properties[PROP_FOO]); 1046 * ]| 1047 * 1048 * Params: 1049 * pspec = the #GParamSpec of a property installed on the class of @object. 1050 * 1051 * Since: 2.26 1052 */ 1053 public void notifyByPspec(ParamSpec pspec) 1054 { 1055 g_object_notify_by_pspec(gObject, (pspec is null) ? null : pspec.getParamSpecStruct()); 1056 } 1057 1058 alias doref = ref_; 1059 /** 1060 * Increases the reference count of @object. 1061 * 1062 * Since GLib 2.56, if `GLIB_VERSION_MAX_ALLOWED` is 2.56 or greater, the type 1063 * of @object will be propagated to the return type (using the GCC typeof() 1064 * extension), so any casting the caller needs to do on the return type must be 1065 * explicit. 1066 * 1067 * Returns: the same @object 1068 */ 1069 public ObjectG ref_() 1070 { 1071 auto p = g_object_ref(gObject); 1072 1073 if(p is null) 1074 { 1075 return null; 1076 } 1077 1078 return ObjectG.getDObject!(ObjectG)(cast(GObject*) p); 1079 } 1080 1081 /** 1082 * Increase the reference count of @object, and possibly remove the 1083 * [floating][floating-ref] reference, if @object has a floating reference. 1084 * 1085 * In other words, if the object is floating, then this call "assumes 1086 * ownership" of the floating reference, converting it to a normal 1087 * reference by clearing the floating flag while leaving the reference 1088 * count unchanged. If the object is not floating, then this call 1089 * adds a new normal reference increasing the reference count by one. 1090 * 1091 * Since GLib 2.56, the type of @object will be propagated to the return type 1092 * under the same conditions as for g_object_ref(). 1093 * 1094 * Returns: @object 1095 * 1096 * Since: 2.10 1097 */ 1098 public ObjectG refSink() 1099 { 1100 auto p = g_object_ref_sink(gObject); 1101 1102 if(p is null) 1103 { 1104 return null; 1105 } 1106 1107 return ObjectG.getDObject!(ObjectG)(cast(GObject*) p); 1108 } 1109 1110 /** 1111 * Removes a reference added with g_object_add_toggle_ref(). The 1112 * reference count of the object is decreased by one. 1113 * 1114 * Params: 1115 * notify = a function to call when this reference is the 1116 * last reference to the object, or is no longer 1117 * the last reference. 1118 * data = data to pass to @notify 1119 * 1120 * Since: 2.8 1121 */ 1122 public void removeToggleRef(GToggleNotify notify, void* data) 1123 { 1124 g_object_remove_toggle_ref(gObject, notify, data); 1125 } 1126 1127 /** 1128 * Removes a weak reference from @object that was previously added 1129 * using g_object_add_weak_pointer(). The @weak_pointer_location has 1130 * to match the one used with g_object_add_weak_pointer(). 1131 * 1132 * Params: 1133 * weakPointerLocation = The memory address 1134 * of a pointer. 1135 */ 1136 public void removeWeakPointer(ref void* weakPointerLocation) 1137 { 1138 g_object_remove_weak_pointer(gObject, &weakPointerLocation); 1139 } 1140 1141 /** 1142 * Compares the user data for the key @key on @object with 1143 * @oldval, and if they are the same, replaces @oldval with 1144 * @newval. 1145 * 1146 * This is like a typical atomic compare-and-exchange 1147 * operation, for user data on an object. 1148 * 1149 * If the previous value was replaced then ownership of the 1150 * old value (@oldval) is passed to the caller, including 1151 * the registered destroy notify for it (passed out in @old_destroy). 1152 * It’s up to the caller to free this as needed, which may 1153 * or may not include using @old_destroy as sometimes replacement 1154 * should not destroy the object in the normal way. 1155 * 1156 * Params: 1157 * key = a string, naming the user data pointer 1158 * oldval = the old value to compare against 1159 * newval = the new value 1160 * destroy = a destroy notify for the new value 1161 * oldDestroy = destroy notify for the existing value 1162 * 1163 * Returns: %TRUE if the existing value for @key was replaced 1164 * by @newval, %FALSE otherwise. 1165 * 1166 * Since: 2.34 1167 */ 1168 public bool replaceData(string key, void* oldval, void* newval, GDestroyNotify destroy, out GDestroyNotify oldDestroy) 1169 { 1170 return g_object_replace_data(gObject, Str.toStringz(key), oldval, newval, destroy, &oldDestroy) != 0; 1171 } 1172 1173 /** 1174 * Compares the user data for the key @quark on @object with 1175 * @oldval, and if they are the same, replaces @oldval with 1176 * @newval. 1177 * 1178 * This is like a typical atomic compare-and-exchange 1179 * operation, for user data on an object. 1180 * 1181 * If the previous value was replaced then ownership of the 1182 * old value (@oldval) is passed to the caller, including 1183 * the registered destroy notify for it (passed out in @old_destroy). 1184 * It’s up to the caller to free this as needed, which may 1185 * or may not include using @old_destroy as sometimes replacement 1186 * should not destroy the object in the normal way. 1187 * 1188 * Params: 1189 * quark = a #GQuark, naming the user data pointer 1190 * oldval = the old value to compare against 1191 * newval = the new value 1192 * destroy = a destroy notify for the new value 1193 * oldDestroy = destroy notify for the existing value 1194 * 1195 * Returns: %TRUE if the existing value for @quark was replaced 1196 * by @newval, %FALSE otherwise. 1197 * 1198 * Since: 2.34 1199 */ 1200 public bool replaceQdata(GQuark quark, void* oldval, void* newval, GDestroyNotify destroy, out GDestroyNotify oldDestroy) 1201 { 1202 return g_object_replace_qdata(gObject, quark, oldval, newval, destroy, &oldDestroy) != 0; 1203 } 1204 1205 /** 1206 * Releases all references to other objects. This can be used to break 1207 * reference cycles. 1208 * 1209 * This function should only be called from object system implementations. 1210 */ 1211 public void runDispose() 1212 { 1213 g_object_run_dispose(gObject); 1214 } 1215 1216 /** 1217 * Each object carries around a table of associations from 1218 * strings to pointers. This function lets you set an association. 1219 * 1220 * If the object already had an association with that name, 1221 * the old association will be destroyed. 1222 * 1223 * Params: 1224 * key = name of the key 1225 * data = data to associate with that key 1226 */ 1227 public void setData(string key, void* data) 1228 { 1229 g_object_set_data(gObject, Str.toStringz(key), data); 1230 } 1231 1232 /** 1233 * Like g_object_set_data() except it adds notification 1234 * for when the association is destroyed, either by setting it 1235 * to a different value or when the object is destroyed. 1236 * 1237 * Note that the @destroy callback is not called if @data is %NULL. 1238 * 1239 * Params: 1240 * key = name of the key 1241 * data = data to associate with that key 1242 * destroy = function to call when the association is destroyed 1243 */ 1244 public void setDataFull(string key, void* data, GDestroyNotify destroy) 1245 { 1246 g_object_set_data_full(gObject, Str.toStringz(key), data, destroy); 1247 } 1248 1249 /** 1250 * Sets a property on an object. 1251 * 1252 * Params: 1253 * propertyName = the name of the property to set 1254 * value = the value 1255 */ 1256 public void setProperty(string propertyName, Value value) 1257 { 1258 g_object_set_property(gObject, Str.toStringz(propertyName), (value is null) ? null : value.getValueStruct()); 1259 } 1260 1261 /** 1262 * This sets an opaque, named pointer on an object. 1263 * The name is specified through a #GQuark (retrived e.g. via 1264 * g_quark_from_static_string()), and the pointer 1265 * can be gotten back from the @object with g_object_get_qdata() 1266 * until the @object is finalized. 1267 * Setting a previously set user data pointer, overrides (frees) 1268 * the old pointer set, using #NULL as pointer essentially 1269 * removes the data stored. 1270 * 1271 * Params: 1272 * quark = A #GQuark, naming the user data pointer 1273 * data = An opaque user data pointer 1274 */ 1275 public void setQdata(GQuark quark, void* data) 1276 { 1277 g_object_set_qdata(gObject, quark, data); 1278 } 1279 1280 /** 1281 * This function works like g_object_set_qdata(), but in addition, 1282 * a void (*destroy) (gpointer) function may be specified which is 1283 * called with @data as argument when the @object is finalized, or 1284 * the data is being overwritten by a call to g_object_set_qdata() 1285 * with the same @quark. 1286 * 1287 * Params: 1288 * quark = A #GQuark, naming the user data pointer 1289 * data = An opaque user data pointer 1290 * destroy = Function to invoke with @data as argument, when @data 1291 * needs to be freed 1292 */ 1293 public void setQdataFull(GQuark quark, void* data, GDestroyNotify destroy) 1294 { 1295 g_object_set_qdata_full(gObject, quark, data, destroy); 1296 } 1297 1298 /** 1299 * Sets properties on an object. 1300 * 1301 * Params: 1302 * firstPropertyName = name of the first property to set 1303 * varArgs = value for the first property, followed optionally by more 1304 * name/value pairs, followed by %NULL 1305 */ 1306 public void setValist(string firstPropertyName, void* varArgs) 1307 { 1308 g_object_set_valist(gObject, Str.toStringz(firstPropertyName), varArgs); 1309 } 1310 1311 /** 1312 * Sets @n_properties properties for an @object. 1313 * Properties to be set will be taken from @values. All properties must be 1314 * valid. Warnings will be emitted and undefined behaviour may result if invalid 1315 * properties are passed in. 1316 * 1317 * Params: 1318 * names = the names of each property to be set 1319 * values = the values of each property to be set 1320 * 1321 * Since: 2.54 1322 */ 1323 public void setv(string[] names, Value[] values) 1324 { 1325 GValue[] valuesArray = new GValue[values.length]; 1326 for ( int i = 0; i < values.length; i++ ) 1327 { 1328 valuesArray[i] = *(values[i].getValueStruct()); 1329 } 1330 1331 g_object_setv(gObject, cast(uint)values.length, Str.toStringzArray(names), valuesArray.ptr); 1332 } 1333 1334 /** 1335 * Remove a specified datum from the object's data associations, 1336 * without invoking the association's destroy handler. 1337 * 1338 * Params: 1339 * key = name of the key 1340 * 1341 * Returns: the data if found, or %NULL 1342 * if no such data exists. 1343 */ 1344 public void* stealData(string key) 1345 { 1346 return g_object_steal_data(gObject, Str.toStringz(key)); 1347 } 1348 1349 /** 1350 * This function gets back user data pointers stored via 1351 * g_object_set_qdata() and removes the @data from object 1352 * without invoking its destroy() function (if any was 1353 * set). 1354 * Usually, calling this function is only required to update 1355 * user data pointers with a destroy notifier, for example: 1356 * |[<!-- language="C" --> 1357 * void 1358 * object_add_to_user_list (GObject *object, 1359 * const gchar *new_string) 1360 * { 1361 * // the quark, naming the object data 1362 * GQuark quark_string_list = g_quark_from_static_string ("my-string-list"); 1363 * // retrive the old string list 1364 * GList *list = g_object_steal_qdata (object, quark_string_list); 1365 * 1366 * // prepend new string 1367 * list = g_list_prepend (list, g_strdup (new_string)); 1368 * // this changed 'list', so we need to set it again 1369 * g_object_set_qdata_full (object, quark_string_list, list, free_string_list); 1370 * } 1371 * static void 1372 * free_string_list (gpointer data) 1373 * { 1374 * GList *node, *list = data; 1375 * 1376 * for (node = list; node; node = node->next) 1377 * g_free (node->data); 1378 * g_list_free (list); 1379 * } 1380 * ]| 1381 * Using g_object_get_qdata() in the above example, instead of 1382 * g_object_steal_qdata() would have left the destroy function set, 1383 * and thus the partial string list would have been freed upon 1384 * g_object_set_qdata_full(). 1385 * 1386 * Params: 1387 * quark = A #GQuark, naming the user data pointer 1388 * 1389 * Returns: The user data pointer set, or %NULL 1390 */ 1391 public void* stealQdata(GQuark quark) 1392 { 1393 return g_object_steal_qdata(gObject, quark); 1394 } 1395 1396 /** 1397 * Reverts the effect of a previous call to 1398 * g_object_freeze_notify(). The freeze count is decreased on @object 1399 * and when it reaches zero, queued "notify" signals are emitted. 1400 * 1401 * Duplicate notifications for each property are squashed so that at most one 1402 * #GObject::notify signal is emitted for each property, in the reverse order 1403 * in which they have been queued. 1404 * 1405 * It is an error to call this function when the freeze count is zero. 1406 */ 1407 public void thawNotify() 1408 { 1409 g_object_thaw_notify(gObject); 1410 } 1411 1412 /** 1413 * Decreases the reference count of @object. When its reference count 1414 * drops to 0, the object is finalized (i.e. its memory is freed). 1415 * 1416 * If the pointer to the #GObject may be reused in future (for example, if it is 1417 * an instance variable of another object), it is recommended to clear the 1418 * pointer to %NULL rather than retain a dangling pointer to a potentially 1419 * invalid #GObject instance. Use g_clear_object() for this. 1420 */ 1421 public void unref() 1422 { 1423 g_object_unref(gObject); 1424 } 1425 1426 /** 1427 * This function essentially limits the life time of the @closure to 1428 * the life time of the object. That is, when the object is finalized, 1429 * the @closure is invalidated by calling g_closure_invalidate() on 1430 * it, in order to prevent invocations of the closure with a finalized 1431 * (nonexisting) object. Also, g_object_ref() and g_object_unref() are 1432 * added as marshal guards to the @closure, to ensure that an extra 1433 * reference count is held on @object during invocation of the 1434 * @closure. Usually, this function will be called on closures that 1435 * use this @object as closure data. 1436 * 1437 * Params: 1438 * closure = GClosure to watch 1439 */ 1440 public void watchClosure(Closure closure) 1441 { 1442 g_object_watch_closure(gObject, (closure is null) ? null : closure.getClosureStruct()); 1443 } 1444 1445 /** 1446 * Adds a weak reference callback to an object. Weak references are 1447 * used for notification when an object is finalized. They are called 1448 * "weak references" because they allow you to safely hold a pointer 1449 * to an object without calling g_object_ref() (g_object_ref() adds a 1450 * strong reference, that is, forces the object to stay alive). 1451 * 1452 * Note that the weak references created by this method are not 1453 * thread-safe: they cannot safely be used in one thread if the 1454 * object's last g_object_unref() might happen in another thread. 1455 * Use #GWeakRef if thread-safety is required. 1456 * 1457 * Params: 1458 * notify = callback to invoke before the object is freed 1459 * data = extra data to pass to notify 1460 */ 1461 public void weakRef(GWeakNotify notify, void* data) 1462 { 1463 g_object_weak_ref(gObject, notify, data); 1464 } 1465 1466 /** 1467 * Removes a weak reference callback to an object. 1468 * 1469 * Params: 1470 * notify = callback to search for 1471 * data = data to search for 1472 */ 1473 public void weakUnref(GWeakNotify notify, void* data) 1474 { 1475 g_object_weak_unref(gObject, notify, data); 1476 } 1477 1478 /** 1479 * Clears a reference to a #GObject. 1480 * 1481 * @object_ptr must not be %NULL. 1482 * 1483 * If the reference is %NULL then this function does nothing. 1484 * Otherwise, the reference count of the object is decreased and the 1485 * pointer is set to %NULL. 1486 * 1487 * A macro is also included that allows this function to be used without 1488 * pointer casts. 1489 * 1490 * Params: 1491 * objectPtr = a pointer to a #GObject reference 1492 * 1493 * Since: 2.28 1494 */ 1495 public static void clearObject(ref ObjectG objectPtr) 1496 { 1497 GObject* outobjectPtr = objectPtr.getObjectGStruct(); 1498 1499 g_clear_object(&outobjectPtr); 1500 1501 objectPtr = ObjectG.getDObject!(ObjectG)(outobjectPtr); 1502 } 1503 }