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