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