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 gtk.Builder; 26 27 private import glib.ConstructionException; 28 private import glib.ErrorG; 29 private import glib.GException; 30 private import glib.Module; 31 private import glib.Str; 32 private import gobject.ObjectG; 33 private import gobject.ParamSpec; 34 private import gobject.Type; 35 private import gobject.Value; 36 private import gtk.Application; 37 private import gtkc.glib; 38 private import gtkc.gobject; 39 private import gtkc.gtk; 40 public import gtkc.gtktypes; 41 private import gtkc.paths; 42 private import std.string; 43 44 45 /** 46 * A GtkBuilder is an auxiliary object that reads textual descriptions 47 * of a user interface and instantiates the described objects. To create 48 * a GtkBuilder from a user interface description, call 49 * gtk_builder_new_from_file(), gtk_builder_new_from_resource() or 50 * gtk_builder_new_from_string(). 51 * 52 * In the (unusual) case that you want to add user interface 53 * descriptions from multiple sources to the same GtkBuilder you can 54 * call gtk_builder_new() to get an empty builder and populate it by 55 * (multiple) calls to gtk_builder_add_from_file(), 56 * gtk_builder_add_from_resource() or gtk_builder_add_from_string(). 57 * 58 * A GtkBuilder holds a reference to all objects that it has constructed 59 * and drops these references when it is finalized. This finalization can 60 * cause the destruction of non-widget objects or widgets which are not 61 * contained in a toplevel window. For toplevel windows constructed by a 62 * builder, it is the responsibility of the user to call gtk_widget_destroy() 63 * to get rid of them and all the widgets they contain. 64 * 65 * The functions gtk_builder_get_object() and gtk_builder_get_objects() 66 * can be used to access the widgets in the interface by the names assigned 67 * to them inside the UI description. Toplevel windows returned by these 68 * functions will stay around until the user explicitly destroys them 69 * with gtk_widget_destroy(). Other widgets will either be part of a 70 * larger hierarchy constructed by the builder (in which case you should 71 * not have to worry about their lifecycle), or without a parent, in which 72 * case they have to be added to some container to make use of them. 73 * Non-widget objects need to be reffed with g_object_ref() to keep them 74 * beyond the lifespan of the builder. 75 * 76 * The function gtk_builder_connect_signals() and variants thereof can be 77 * used to connect handlers to the named signals in the description. 78 * 79 * # GtkBuilder UI Definitions # {#BUILDER-UI} 80 * 81 * GtkBuilder parses textual descriptions of user interfaces which are 82 * specified in an XML format which can be roughly described by the 83 * RELAX NG schema below. We refer to these descriptions as 84 * “GtkBuilder UI definitions” or just 85 * “UI definitions” if the context is clear. 86 * Do not confuse GtkBuilder UI Definitions with 87 * [GtkUIManager UI Definitions][XML-UI], which 88 * are more limited in scope. It is common to use `.ui` 89 * as the filename extension for files containing GtkBuilder UI 90 * definitions. 91 * 92 * [RELAX NG Compact Syntax](https://git.gnome.org/browse/gtk+/tree/gtk/gtkbuilder.rnc) 93 * 94 * The toplevel element is <interface>. It optionally takes a “domain” 95 * attribute, which will make the builder look for translated strings 96 * using dgettext() in the domain specified. This can also be done by 97 * calling gtk_builder_set_translation_domain() on the builder. 98 * Objects are described by <object> elements, which can contain 99 * <property> elements to set properties, <signal> elements which 100 * connect signals to handlers, and <child> elements, which describe 101 * child objects (most often widgets inside a container, but also e.g. 102 * actions in an action group, or columns in a tree model). A <child> 103 * element contains an <object> element which describes the child object. 104 * The target toolkit version(s) are described by <requires> elements, 105 * the “lib” attribute specifies the widget library in question (currently 106 * the only supported value is “gtk+”) and the “version” attribute specifies 107 * the target version in the form “<major>.<minor>”. The builder will error 108 * out if the version requirements are not met. 109 * 110 * Typically, the specific kind of object represented by an <object> 111 * element is specified by the “class” attribute. If the type has not 112 * been loaded yet, GTK+ tries to find the get_type() function from the 113 * class name by applying heuristics. This works in most cases, but if 114 * necessary, it is possible to specify the name of the get_type() function 115 * explictly with the "type-func" attribute. As a special case, GtkBuilder 116 * allows to use an object that has been constructed by a #GtkUIManager in 117 * another part of the UI definition by specifying the id of the #GtkUIManager 118 * in the “constructor” attribute and the name of the object in the “id” 119 * attribute. 120 * 121 * Objects may be given a name with the “id” attribute, which allows the 122 * application to retrieve them from the builder with gtk_builder_get_object(). 123 * An id is also necessary to use the object as property value in other 124 * parts of the UI definition. GTK+ reserves ids starting and ending 125 * with ___ (3 underscores) for its own purposes. 126 * 127 * Setting properties of objects is pretty straightforward with the 128 * <property> element: the “name” attribute specifies the name of the 129 * property, and the content of the element specifies the value. 130 * If the “translatable” attribute is set to a true value, GTK+ uses 131 * gettext() (or dgettext() if the builder has a translation domain set) 132 * to find a translation for the value. This happens before the value 133 * is parsed, so it can be used for properties of any type, but it is 134 * probably most useful for string properties. It is also possible to 135 * specify a context to disambiguate short strings, and comments which 136 * may help the translators. 137 * 138 * GtkBuilder can parse textual representations for the most common 139 * property types: characters, strings, integers, floating-point numbers, 140 * booleans (strings like “TRUE”, “t”, “yes”, “y”, “1” are interpreted 141 * as %TRUE, strings like “FALSE”, “f”, “no”, “n”, “0” are interpreted 142 * as %FALSE), enumerations (can be specified by their name, nick or 143 * integer value), flags (can be specified by their name, nick, integer 144 * value, optionally combined with “|”, e.g. “GTK_VISIBLE|GTK_REALIZED”) 145 * and colors (in a format understood by gdk_rgba_parse()). Pixbufs can 146 * be specified as a filename of an image file to load. Objects can be 147 * referred to by their name and by default refer to objects declared 148 * in the local xml fragment and objects exposed via 149 * gtk_builder_expose_object(). 150 * 151 * In general, GtkBuilder allows forward references to objects — 152 * declared in the local xml; an object doesn’t have to be constructed 153 * before it can be referred to. The exception to this rule is that an 154 * object has to be constructed before it can be used as the value of 155 * a construct-only property. 156 * 157 * It is also possible to bind a property value to another object's 158 * property value using the attributes 159 * "bind-source" to specify the source object of the binding, 160 * "bind-property" to specify the source property and optionally 161 * "bind-flags" to specify the binding flags 162 * Internally builder implement this using GBinding objects. 163 * For more information see g_object_bind_property() 164 * 165 * Signal handlers are set up with the <signal> element. The “name” 166 * attribute specifies the name of the signal, and the “handler” attribute 167 * specifies the function to connect to the signal. By default, GTK+ tries 168 * to find the handler using g_module_symbol(), but this can be changed by 169 * passing a custom #GtkBuilderConnectFunc to 170 * gtk_builder_connect_signals_full(). The remaining attributes, “after”, 171 * “swapped” and “object”, have the same meaning as the corresponding 172 * parameters of the g_signal_connect_object() or 173 * g_signal_connect_data() functions. A “last_modification_time” 174 * attribute is also allowed, but it does not have a meaning to the 175 * builder. 176 * 177 * Sometimes it is necessary to refer to widgets which have implicitly 178 * been constructed by GTK+ as part of a composite widget, to set 179 * properties on them or to add further children (e.g. the @vbox of 180 * a #GtkDialog). This can be achieved by setting the “internal-child” 181 * propery of the <child> element to a true value. Note that GtkBuilder 182 * still requires an <object> element for the internal child, even if it 183 * has already been constructed. 184 * 185 * A number of widgets have different places where a child can be added 186 * (e.g. tabs vs. page content in notebooks). This can be reflected in 187 * a UI definition by specifying the “type” attribute on a <child> 188 * The possible values for the “type” attribute are described in the 189 * sections describing the widget-specific portions of UI definitions. 190 * 191 * # A GtkBuilder UI Definition 192 * 193 * |[ 194 * <interface> 195 * <object class="GtkDialog" id="dialog1"> 196 * <child internal-child="vbox"> 197 * <object class="GtkVBox" id="vbox1"> 198 * <property name="border-width">10</property> 199 * <child internal-child="action_area"> 200 * <object class="GtkHButtonBox" id="hbuttonbox1"> 201 * <property name="border-width">20</property> 202 * <child> 203 * <object class="GtkButton" id="ok_button"> 204 * <property name="label">gtk-ok</property> 205 * <property name="use-stock">TRUE</property> 206 * <signal name="clicked" handler="ok_button_clicked"/> 207 * </object> 208 * </child> 209 * </object> 210 * </child> 211 * </object> 212 * </child> 213 * </object> 214 * </interface> 215 * ]| 216 * 217 * Beyond this general structure, several object classes define their 218 * own XML DTD fragments for filling in the ANY placeholders in the DTD 219 * above. Note that a custom element in a <child> element gets parsed by 220 * the custom tag handler of the parent object, while a custom element in 221 * an <object> element gets parsed by the custom tag handler of the object. 222 * 223 * These XML fragments are explained in the documentation of the 224 * respective objects. 225 * 226 * Additionally, since 3.10 a special <template> tag has been added 227 * to the format allowing one to define a widget class’s components. 228 */ 229 public class Builder : ObjectG 230 { 231 /** the main Gtk struct */ 232 protected GtkBuilder* gtkBuilder; 233 234 /** Get the main Gtk struct */ 235 public GtkBuilder* getBuilderStruct() 236 { 237 return gtkBuilder; 238 } 239 240 /** the main Gtk struct as a void* */ 241 protected override void* getStruct() 242 { 243 return cast(void*)gtkBuilder; 244 } 245 246 protected override void setStruct(GObject* obj) 247 { 248 gtkBuilder = cast(GtkBuilder*)obj; 249 super.setStruct(obj); 250 } 251 252 /** 253 * Sets our main struct and passes it to the parent class. 254 */ 255 public this (GtkBuilder* gtkBuilder, bool ownedRef = false) 256 { 257 this.gtkBuilder = gtkBuilder; 258 super(cast(GObject*)gtkBuilder, ownedRef); 259 } 260 261 /** 262 * Creates a new builder object. 263 * Since 2.12 264 * Throws: ConstructionException GTK+ fails to create the object. 265 */ 266 public this () 267 { 268 // GtkBuilder* gtk_builder_new (void); 269 auto p = gtk_builder_new(); 270 if(p is null) 271 { 272 throw new ConstructionException("null returned by gtk_builder_new()"); 273 } 274 this(cast(GtkBuilder*) p); 275 276 GtkBuilderClass* klass = Type.getInstanceClass!(GtkBuilderClass)( this ); 277 klass.getTypeFromName = >k_builder_real_get_type_from_name_override; 278 } 279 280 /** 281 * This function is a modification of _gtk_builder_resolve_type_lazily from "gtk/gtkbuilder.c". 282 * It is needed because it assumes we are linking at compile time to the gtk libs. 283 * specifically the NULL in g_module_open( NULL, 0 ); 284 * It replaces the default function pointer "get_type_from_name" in GtkBuilderClass. 285 */ 286 extern(C) private static GType gtk_builder_real_get_type_from_name_override ( GtkBuilder* builder, const(char)* name ) 287 { 288 GType gtype; 289 gtype = g_type_from_name( name ); 290 if (gtype != GType.INVALID) 291 { 292 return gtype; 293 } 294 295 /* 296 * Try to map a type name to a _get_type function 297 * and call it, eg: 298 * 299 * GtkWindow -> gtk_window_get_type 300 * GtkHBox -> gtk_hbox_get_type 301 * GtkUIManager -> gtk_ui_manager_get_type 302 * 303 */ 304 char c; 305 string symbol_name; 306 307 for (int i = 0; name[i] != '\0'; i++) 308 { 309 c = name[i]; 310 /* skip if uppercase, first or previous is uppercase */ 311 if ((c == Str.asciiToupper (c) && 312 i > 0 && name[i-1] != Str.asciiToupper (name[i-1])) || 313 (i > 2 && name[i] == Str.asciiToupper (name[i]) && 314 name[i-1] == Str.asciiToupper (name[i-1]) && 315 name[i-2] == Str.asciiToupper (name[i-2])) 316 ) 317 318 symbol_name ~= '_'; 319 symbol_name ~= Str.asciiTolower (c); 320 } 321 symbol_name ~= "_get_type" ; 322 323 /* scan linked librarys for function symbol */ 324 foreach ( lib; importLibs ) 325 { 326 GType function() func; 327 Module mod = Module.open( lib, GModuleFlags.LAZY ); 328 if( mod is null ) 329 continue; 330 331 scope(exit) mod.close(); 332 333 if ( mod.symbol( symbol_name, cast(void**)&func ) ) { 334 return func(); 335 } 336 } 337 338 return GType.INVALID; 339 } 340 341 /** 342 * Gets the object named name. Note that this function does not 343 * increment the reference count of the returned object. 344 * Since 2.12 345 * Params: 346 * name = name of object to get 347 * Returns: the object named name or NULL if it could not be found in the object tree.. transfer none. 348 */ 349 public ObjectG getObject(string name) 350 { 351 // GObject* gtk_builder_get_object (GtkBuilder *builder, const gchar *name); 352 return newFromObject( gtk_builder_get_object(gtkBuilder, Str.toStringz(name)) ); 353 } 354 355 /** 356 * Gets all objects that have been constructed by builder. 357 * Since 2.12 358 * Returns: an array containing all the objects constructed by the GtkBuilder instance. 359 */ 360 public ObjectG[] getObjects() 361 { 362 ObjectG[] objects; 363 364 // GSList* gtk_builder_get_objects (GtkBuilder *builder); 365 GSList* list = gtk_builder_get_objects(gtkBuilder); 366 367 while ( list.next !is null ) 368 { 369 objects ~= newFromObject( cast(GObject*)list.data ); 370 list = list.next; 371 } 372 373 g_slist_free(list); 374 375 return objects; 376 } 377 378 /** 379 * This function creates an D object corresponding to the Struct pointer passed in. 380 */ 381 public ObjectG newFromObject(GObject* cobj) 382 { 383 if(cobj is null) 384 { 385 return null; 386 } 387 388 void* dObj = g_object_get_data(cobj, Str.toStringz("GObject")); 389 390 if ( dObj !is null ) 391 { 392 return cast(ObjectG)dObj; 393 } 394 395 string type = convertClassName(Type.name((cast(GTypeInstance*)cobj).gClass.gType)); 396 ClassInfo ci = cast(ClassInfo)ClassInfo.find(type); 397 398 //Gobject and Gio types both start with g, so try both. 399 if(ci is null && startsWith(type, "gobject")) 400 { 401 ci = cast(ClassInfo)ClassInfo.find("gio"~ type[7..$]); 402 } 403 404 if(ci is null) 405 { 406 return null; 407 } 408 409 ObjectG obj = cast(ObjectG)_d_newclass(ci); 410 411 obj.__ctor(cobj); 412 413 return obj; 414 } 415 416 /** 417 * Turn the name of a C Type in to the name of the corresponding D type. 418 * Note: If the prefix of the type is "G" this always usses "gobject" as 419 * the prefix, extra care should be taken for types from GIO. 420 */ 421 private string convertClassName(string gName) 422 { 423 string conv; 424 string prefix; 425 426 if ( startsWith(gName, "GtkSource" ) ) prefix = "Gsv"; 427 else if ( startsWith(gName, "Gtk") ) prefix = "Gtk"; 428 else if ( startsWith(gName, "Gdk") ) prefix = "Gdk"; 429 else if ( startsWith(gName, "Gst") ) prefix = "Gst"; 430 else if ( startsWith(gName, "Gda") ) prefix = "Gda"; 431 else if ( startsWith(gName, "Atk") ) prefix = "Atk"; 432 else if ( startsWith(gName, "G") ) prefix = "G"; 433 else if ( startsWith(gName, "Pango") ) prefix = "Pg"; 434 else if ( startsWith(gName, "cairo") ) prefix = "cairo"; 435 436 conv = gName[prefix.length..gName.length]; 437 438 if ( conv == "Object" ) conv ~= prefix; 439 if ( prefix == "Pg" ) conv = "Pg" ~ gName[5..gName.length]; 440 if ( prefix == "cairo") conv = toUpper(gName[6..7]) ~ gName[7..gName.length - 2]; 441 442 prefix = toLower(prefix); 443 444 if( prefix == "gst") prefix = "gstreamer"; 445 if( prefix == "g") prefix = "gobject"; 446 if( prefix == "pg" ) prefix = "pango"; 447 448 return prefix ~"."~ conv ~"."~ conv; 449 } 450 451 private bool startsWith(string str, string prefix) 452 { 453 return str.length >= prefix.length && str[0..prefix.length] == prefix; 454 } 455 456 /** 457 */ 458 459 public static GType getType() 460 { 461 return gtk_builder_get_type(); 462 } 463 464 /** 465 * Builds the [GtkBuilder UI definition][BUILDER-UI] 466 * in the file @filename. 467 * 468 * If there is an error opening the file or parsing the description then 469 * the program will be aborted. You should only ever attempt to parse 470 * user interface descriptions that are shipped as part of your program. 471 * 472 * Params: 473 * filename = filename of user interface description file 474 * 475 * Return: a #GtkBuilder containing the described interface 476 * 477 * Since: 3.10 478 * 479 * Throws: ConstructionException GTK+ fails to create the object. 480 */ 481 public this(string filename) 482 { 483 auto p = gtk_builder_new_from_file(Str.toStringz(filename)); 484 485 if(p is null) 486 { 487 throw new ConstructionException("null returned by new_from_file"); 488 } 489 490 this(cast(GtkBuilder*) p, true); 491 } 492 493 /** 494 * Adds the @callback_symbol to the scope of @builder under the given @callback_name. 495 * 496 * Using this function overrides the behavior of gtk_builder_connect_signals() 497 * for any callback symbols that are added. Using this method allows for better 498 * encapsulation as it does not require that callback symbols be declared in 499 * the global namespace. 500 * 501 * Params: 502 * callbackName = The name of the callback, as expected in the XML 503 * callbackSymbol = The callback pointer 504 * 505 * Since: 3.10 506 */ 507 public void addCallbackSymbol(string callbackName, GCallback callbackSymbol) 508 { 509 gtk_builder_add_callback_symbol(gtkBuilder, Str.toStringz(callbackName), callbackSymbol); 510 } 511 512 /** 513 * Parses a file containing a [GtkBuilder UI definition][BUILDER-UI] 514 * and merges it with the current contents of @builder. 515 * 516 * Most users will probably want to use gtk_builder_new_from_file(). 517 * 518 * Upon errors 0 will be returned and @error will be assigned a 519 * #GError from the #GTK_BUILDER_ERROR, #G_MARKUP_ERROR or #G_FILE_ERROR 520 * domain. 521 * 522 * It’s not really reasonable to attempt to handle failures of this 523 * call. You should not use this function with untrusted files (ie: 524 * files that are not part of your application). Broken #GtkBuilder 525 * files can easily crash your program, and it’s possible that memory 526 * was leaked leading up to the reported failure. The only reasonable 527 * thing to do when an error is detected is to call g_error(). 528 * 529 * Params: 530 * filename = the name of the file to parse 531 * 532 * Return: A positive value on success, 0 if an error occurred 533 * 534 * Since: 2.12 535 * 536 * Throws: GException on failure. 537 */ 538 public uint addFromFile(string filename) 539 { 540 GError* err = null; 541 542 auto p = gtk_builder_add_from_file(gtkBuilder, Str.toStringz(filename), &err); 543 544 if (err !is null) 545 { 546 throw new GException( new ErrorG(err) ); 547 } 548 549 return p; 550 } 551 552 /** 553 * Parses a resource file containing a [GtkBuilder UI definition][BUILDER-UI] 554 * and merges it with the current contents of @builder. 555 * 556 * Most users will probably want to use gtk_builder_new_from_resource(). 557 * 558 * Upon errors 0 will be returned and @error will be assigned a 559 * #GError from the #GTK_BUILDER_ERROR, #G_MARKUP_ERROR or #G_RESOURCE_ERROR 560 * domain. 561 * 562 * It’s not really reasonable to attempt to handle failures of this 563 * call. The only reasonable thing to do when an error is detected is 564 * to call g_error(). 565 * 566 * Params: 567 * resourcePath = the path of the resource file to parse 568 * 569 * Return: A positive value on success, 0 if an error occurred 570 * 571 * Since: 3.4 572 * 573 * Throws: GException on failure. 574 */ 575 public uint addFromResource(string resourcePath) 576 { 577 GError* err = null; 578 579 auto p = gtk_builder_add_from_resource(gtkBuilder, Str.toStringz(resourcePath), &err); 580 581 if (err !is null) 582 { 583 throw new GException( new ErrorG(err) ); 584 } 585 586 return p; 587 } 588 589 /** 590 * Parses a string containing a [GtkBuilder UI definition][BUILDER-UI] 591 * and merges it with the current contents of @builder. 592 * 593 * Most users will probably want to use gtk_builder_new_from_string(). 594 * 595 * Upon errors 0 will be returned and @error will be assigned a 596 * #GError from the #GTK_BUILDER_ERROR, #G_MARKUP_ERROR or 597 * #G_VARIANT_PARSE_ERROR domain. 598 * 599 * It’s not really reasonable to attempt to handle failures of this 600 * call. The only reasonable thing to do when an error is detected is 601 * to call g_error(). 602 * 603 * Params: 604 * buffer = the string to parse 605 * length = the length of @buffer (may be -1 if @buffer is nul-terminated) 606 * 607 * Return: A positive value on success, 0 if an error occurred 608 * 609 * Since: 2.12 610 * 611 * Throws: GException on failure. 612 */ 613 public uint addFromString(string buffer, size_t length) 614 { 615 GError* err = null; 616 617 auto p = gtk_builder_add_from_string(gtkBuilder, Str.toStringz(buffer), length, &err); 618 619 if (err !is null) 620 { 621 throw new GException( new ErrorG(err) ); 622 } 623 624 return p; 625 } 626 627 /** 628 * Parses a file containing a [GtkBuilder UI definition][BUILDER-UI] 629 * building only the requested objects and merges 630 * them with the current contents of @builder. 631 * 632 * Upon errors 0 will be returned and @error will be assigned a 633 * #GError from the #GTK_BUILDER_ERROR, #G_MARKUP_ERROR or #G_FILE_ERROR 634 * domain. 635 * 636 * If you are adding an object that depends on an object that is not 637 * its child (for instance a #GtkTreeView that depends on its 638 * #GtkTreeModel), you have to explicitly list all of them in @object_ids. 639 * 640 * Params: 641 * filename = the name of the file to parse 642 * objectIds = nul-terminated array of objects to build 643 * 644 * Return: A positive value on success, 0 if an error occurred 645 * 646 * Since: 2.14 647 * 648 * Throws: GException on failure. 649 */ 650 public uint addObjectsFromFile(string filename, string[] objectIds) 651 { 652 GError* err = null; 653 654 auto p = gtk_builder_add_objects_from_file(gtkBuilder, Str.toStringz(filename), Str.toStringzArray(objectIds), &err); 655 656 if (err !is null) 657 { 658 throw new GException( new ErrorG(err) ); 659 } 660 661 return p; 662 } 663 664 /** 665 * Parses a resource file containing a [GtkBuilder UI definition][BUILDER-UI] 666 * building only the requested objects and merges 667 * them with the current contents of @builder. 668 * 669 * Upon errors 0 will be returned and @error will be assigned a 670 * #GError from the #GTK_BUILDER_ERROR, #G_MARKUP_ERROR or #G_RESOURCE_ERROR 671 * domain. 672 * 673 * If you are adding an object that depends on an object that is not 674 * its child (for instance a #GtkTreeView that depends on its 675 * #GtkTreeModel), you have to explicitly list all of them in @object_ids. 676 * 677 * Params: 678 * resourcePath = the path of the resource file to parse 679 * objectIds = nul-terminated array of objects to build 680 * 681 * Return: A positive value on success, 0 if an error occurred 682 * 683 * Since: 3.4 684 * 685 * Throws: GException on failure. 686 */ 687 public uint addObjectsFromResource(string resourcePath, string[] objectIds) 688 { 689 GError* err = null; 690 691 auto p = gtk_builder_add_objects_from_resource(gtkBuilder, Str.toStringz(resourcePath), Str.toStringzArray(objectIds), &err); 692 693 if (err !is null) 694 { 695 throw new GException( new ErrorG(err) ); 696 } 697 698 return p; 699 } 700 701 /** 702 * Parses a string containing a [GtkBuilder UI definition][BUILDER-UI] 703 * building only the requested objects and merges 704 * them with the current contents of @builder. 705 * 706 * Upon errors 0 will be returned and @error will be assigned a 707 * #GError from the #GTK_BUILDER_ERROR or #G_MARKUP_ERROR domain. 708 * 709 * If you are adding an object that depends on an object that is not 710 * its child (for instance a #GtkTreeView that depends on its 711 * #GtkTreeModel), you have to explicitly list all of them in @object_ids. 712 * 713 * Params: 714 * buffer = the string to parse 715 * length = the length of @buffer (may be -1 if @buffer is nul-terminated) 716 * objectIds = nul-terminated array of objects to build 717 * 718 * Return: A positive value on success, 0 if an error occurred 719 * 720 * Since: 2.14 721 * 722 * Throws: GException on failure. 723 */ 724 public uint addObjectsFromString(string buffer, size_t length, string[] objectIds) 725 { 726 GError* err = null; 727 728 auto p = gtk_builder_add_objects_from_string(gtkBuilder, Str.toStringz(buffer), length, Str.toStringzArray(objectIds), &err); 729 730 if (err !is null) 731 { 732 throw new GException( new ErrorG(err) ); 733 } 734 735 return p; 736 } 737 738 /** 739 * This method is a simpler variation of gtk_builder_connect_signals_full(). 740 * It uses symbols explicitly added to @builder with prior calls to 741 * gtk_builder_add_callback_symbol(). In the case that symbols are not 742 * explicitly added; it uses #GModule’s introspective features (by opening the module %NULL) 743 * to look at the application’s symbol table. From here it tries to match 744 * the signal handler names given in the interface description with 745 * symbols in the application and connects the signals. Note that this 746 * function can only be called once, subsequent calls will do nothing. 747 * 748 * Note that unless gtk_builder_add_callback_symbol() is called for 749 * all signal callbacks which are referenced by the loaded XML, this 750 * function will require that #GModule be supported on the platform. 751 * 752 * If you rely on #GModule support to lookup callbacks in the symbol table, 753 * the following details should be noted: 754 * 755 * When compiling applications for Windows, you must declare signal callbacks 756 * with #G_MODULE_EXPORT, or they will not be put in the symbol table. 757 * On Linux and Unices, this is not necessary; applications should instead 758 * be compiled with the -Wl,--export-dynamic CFLAGS, and linked against 759 * gmodule-export-2.0. 760 * 761 * Params: 762 * userData = user data to pass back with all signals 763 * 764 * Since: 2.12 765 */ 766 public void connectSignals(void* userData) 767 { 768 gtk_builder_connect_signals(gtkBuilder, userData); 769 } 770 771 /** 772 * This function can be thought of the interpreted language binding 773 * version of gtk_builder_connect_signals(), except that it does not 774 * require GModule to function correctly. 775 * 776 * Params: 777 * func = the function used to connect the signals 778 * userData = arbitrary data that will be passed to the connection function 779 * 780 * Since: 2.12 781 */ 782 public void connectSignalsFull(GtkBuilderConnectFunc func, void* userData) 783 { 784 gtk_builder_connect_signals_full(gtkBuilder, func, userData); 785 } 786 787 /** 788 * Add @object to the @builder object pool so it can be referenced just like any 789 * other object built by builder. 790 * 791 * Params: 792 * name = the name of the object exposed to the builder 793 * object = the object to expose 794 * 795 * Since: 3.8 796 */ 797 public void exposeObject(string name, ObjectG object) 798 { 799 gtk_builder_expose_object(gtkBuilder, Str.toStringz(name), (object is null) ? null : object.getObjectGStruct()); 800 } 801 802 /** 803 * Gets the #GtkApplication associated with the builder. 804 * 805 * The #GtkApplication is used for creating action proxies as requested 806 * from XML that the builder is loading. 807 * 808 * By default, the builder uses the default application: the one from 809 * g_application_get_default(). If you want to use another application 810 * for constructing proxies, use gtk_builder_set_application(). 811 * 812 * Return: the application being used by the builder, 813 * or %NULL 814 * 815 * Since: 3.10 816 */ 817 public Application getApplication() 818 { 819 auto p = gtk_builder_get_application(gtkBuilder); 820 821 if(p is null) 822 { 823 return null; 824 } 825 826 return ObjectG.getDObject!(Application)(cast(GtkApplication*) p); 827 } 828 829 /** 830 * Gets the translation domain of @builder. 831 * 832 * Return: the translation domain. This string is owned 833 * by the builder object and must not be modified or freed. 834 * 835 * Since: 2.12 836 */ 837 public string getTranslationDomain() 838 { 839 return Str.toString(gtk_builder_get_translation_domain(gtkBuilder)); 840 } 841 842 /** 843 * Looks up a type by name, using the virtual function that 844 * #GtkBuilder has for that purpose. This is mainly used when 845 * implementing the #GtkBuildable interface on a type. 846 * 847 * Params: 848 * typeName = type name to lookup 849 * 850 * Return: the #GType found for @type_name or #G_TYPE_INVALID 851 * if no type was found 852 * 853 * Since: 2.12 854 */ 855 public GType getTypeFromName(string typeName) 856 { 857 return gtk_builder_get_type_from_name(gtkBuilder, Str.toStringz(typeName)); 858 } 859 860 /** 861 * Fetches a symbol previously added to @builder 862 * with gtk_builder_add_callback_symbols() 863 * 864 * This function is intended for possible use in language bindings 865 * or for any case that one might be cusomizing signal connections 866 * using gtk_builder_connect_signals_full() 867 * 868 * Params: 869 * callbackName = The name of the callback 870 * 871 * Return: The callback symbol in @builder for @callback_name, or %NULL 872 * 873 * Since: 3.10 874 */ 875 public GCallback lookupCallbackSymbol(string callbackName) 876 { 877 return gtk_builder_lookup_callback_symbol(gtkBuilder, Str.toStringz(callbackName)); 878 } 879 880 /** 881 * Sets the application associated with @builder. 882 * 883 * You only need this function if there is more than one #GApplication 884 * in your process. @application cannot be %NULL. 885 * 886 * Params: 887 * application = a #GtkApplication 888 * 889 * Since: 3.10 890 */ 891 public void setApplication(Application application) 892 { 893 gtk_builder_set_application(gtkBuilder, (application is null) ? null : application.getGtkApplicationStruct()); 894 } 895 896 /** 897 * Sets the translation domain of @builder. 898 * See #GtkBuilder:translation-domain. 899 * 900 * Params: 901 * domain = the translation domain or %NULL 902 * 903 * Since: 2.12 904 */ 905 public void setTranslationDomain(string domain) 906 { 907 gtk_builder_set_translation_domain(gtkBuilder, Str.toStringz(domain)); 908 } 909 910 /** 911 * This function demarshals a value from a string. This function 912 * calls g_value_init() on the @value argument, so it need not be 913 * initialised beforehand. 914 * 915 * This function can handle char, uchar, boolean, int, uint, long, 916 * ulong, enum, flags, float, double, string, #GdkColor, #GdkRGBA and 917 * #GtkAdjustment type values. Support for #GtkWidget type values is 918 * still to come. 919 * 920 * Upon errors %FALSE will be returned and @error will be assigned a 921 * #GError from the #GTK_BUILDER_ERROR domain. 922 * 923 * Params: 924 * pspec = the #GParamSpec for the property 925 * str = the string representation of the value 926 * value = the #GValue to store the result in 927 * 928 * Return: %TRUE on success 929 * 930 * Since: 2.12 931 * 932 * Throws: GException on failure. 933 */ 934 public bool valueFromString(ParamSpec pspec, string str, out Value value) 935 { 936 GValue* outvalue = new GValue; 937 GError* err = null; 938 939 auto p = gtk_builder_value_from_string(gtkBuilder, (pspec is null) ? null : pspec.getParamSpecStruct(), Str.toStringz(str), outvalue, &err) != 0; 940 941 if (err !is null) 942 { 943 throw new GException( new ErrorG(err) ); 944 } 945 946 value = ObjectG.getDObject!(Value)(outvalue); 947 948 return p; 949 } 950 951 /** 952 * Like gtk_builder_value_from_string(), this function demarshals 953 * a value from a string, but takes a #GType instead of #GParamSpec. 954 * This function calls g_value_init() on the @value argument, so it 955 * need not be initialised beforehand. 956 * 957 * Upon errors %FALSE will be returned and @error will be assigned a 958 * #GError from the #GTK_BUILDER_ERROR domain. 959 * 960 * Params: 961 * type = the #GType of the value 962 * str = the string representation of the value 963 * value = the #GValue to store the result in 964 * 965 * Return: %TRUE on success 966 * 967 * Since: 2.12 968 * 969 * Throws: GException on failure. 970 */ 971 public bool valueFromStringType(GType type, string str, out Value value) 972 { 973 GValue* outvalue = new GValue; 974 GError* err = null; 975 976 auto p = gtk_builder_value_from_string_type(gtkBuilder, type, Str.toStringz(str), outvalue, &err) != 0; 977 978 if (err !is null) 979 { 980 throw new GException( new ErrorG(err) ); 981 } 982 983 value = ObjectG.getDObject!(Value)(outvalue); 984 985 return p; 986 } 987 }