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