1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
|
/*
* Copyright (c) 2007, 2010 by the gtk2-perl team (see the file AUTHORS)
*
* Licensed under the LGPL, see LICENSE file for more information.
*
* $Id$
*/
#include "gtk2perl.h"
/*
Since perl already has a metric ton of XML parsers, Glib doesn't
wrap GMarkupParser. This is a miniature binding of just the bits
of GMarkupParser that GtkBuildable needs. The GMarkupParseContext
is blessed as a Gtk2::Builder::ParseContext, and has only the
user-usable methods bound. (Should it happen that we need to bind
GMarkupParseContext in Glib in the future, we can just move those
methods to Glib, and have Gtk2::Builder::ParseContext inherit
from Glib::Markup::ParseContext.)
Builder doesn't use passthrough() and error(), but they were easy
to implement and will be there if and when Builder does start to
use them.
*/
static SV *
newSVGtkBuildableParseContext (GMarkupParseContext * context)
{
return sv_setref_pv (newSV (0), "Gtk2::Buildable::ParseContext", context);
}
static GMarkupParseContext *
SvGtkBuildableParseContext (SV * sv)
{
if (! gperl_sv_is_defined (sv) || ! SvROK (sv))
croak ("expected a blessed reference");
if (! sv_derived_from (sv, "Gtk2::Buildable::ParseContext"))
croak ("%s is not of type Gtk2::Buildable::ParseContext",
gperl_format_variable_for_output (sv));
return INT2PTR (GMarkupParseContext *, SvIV (SvRV (sv)));
}
static SV *
check_parser (gpointer user_data)
{
SV * sv = user_data;
if (! gperl_sv_is_defined (sv) || ! SvROK (sv))
croak ("parser object is not an object");
return sv;
}
/*
* Treat parser as an SV object, and call method on it in void context, with
* the extra args from the va list. You are expected to do any necessary
* sv_2mortal() and such on those. An exception will be converted to a GError.
*/
static void
call_parser_method (GError ** error,
gpointer parser,
GMarkupParseContext * context,
const char * method,
int n_args,
...)
{
va_list ap;
dSP;
ENTER;
SAVETMPS;
PUSHMARK (SP);
EXTEND (SP, 2 + n_args);
PUSHs (check_parser (parser));
PUSHs (sv_2mortal (newSVGtkBuildableParseContext (context)));
va_start (ap, n_args);
while (n_args-- > 0) {
SV * sv = va_arg (ap, SV *);
PUSHs (sv);
}
va_end (ap);
PUTBACK;
call_method (method, G_VOID | G_DISCARD | G_EVAL);
SPAGAIN;
if (gperl_sv_is_defined (ERRSV) && SvTRUE (ERRSV)) {
if (SvROK (ERRSV) && sv_derived_from (ERRSV, "Glib::Error")) {
gperl_gerror_from_sv (ERRSV, error);
} else {
/* g_error_new_literal() won't let us pass 0 for
* the domain... */
g_set_error (error, 0, 0, "%s", SvPV_nolen (ERRSV));
}
}
FREETMPS;
LEAVE;
}
/* Called for open tags <foo bar="baz"> */
static void
gtk2perl_buildable_parser_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error)
{
HV * hv;
SV * attrs;
int i;
hv = newHV ();
attrs = newRV_noinc ((SV *) hv);
for (i = 0; attribute_names[i] != NULL ; i++)
gperl_hv_take_sv (
hv,
attribute_names[i],
strlen (attribute_names[i]),
newSVGChar (attribute_values[i]));
call_parser_method (error,
user_data,
context,
"START_ELEMENT",
2,
sv_2mortal (newSVGChar (element_name)),
sv_2mortal (attrs));
}
/* Called for close tags </foo> */
static void
gtk2perl_buildable_parser_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error)
{
call_parser_method (error,
user_data,
context,
"END_ELEMENT",
1,
sv_2mortal (newSVGChar (element_name)));
}
/* Called for character data */
/* text is not nul-terminated */
static void
gtk2perl_buildable_parser_text (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error)
{
SV * text_sv;
text_sv = newSVpv (text, text_len);
SvUTF8_on (text_sv);
call_parser_method (error,
user_data,
context,
"TEXT",
1,
sv_2mortal (text_sv));
}
/* Called for strings that should be re-saved verbatim in this same
* position, but are not otherwise interpretable. At the moment
* this includes comments and processing instructions.
*/
/* text is not nul-terminated. */
static void
gtk2perl_buildable_parser_passthrough (GMarkupParseContext *context,
const gchar *passthrough_text,
gsize text_len,
gpointer user_data,
GError **error)
{
SV * text_sv;
text_sv = newSVpv (passthrough_text, text_len);
SvUTF8_on (text_sv);
call_parser_method (error,
user_data,
context,
"PASSTHROUGH",
1,
sv_2mortal (text_sv));
}
/* Called on error, including one set by other
* methods in the vtable. The GError should not be freed.
*/
static void
gtk2perl_buildable_parser_error (GMarkupParseContext *context,
GError *error,
gpointer user_data)
{
dSP;
ENTER;
SAVETMPS;
PUSHMARK (SP);
EXTEND (SP, 2);
PUSHs (check_parser (user_data));
PUSHs (sv_2mortal (newSVGtkBuildableParseContext (context)));
PUSHs (sv_2mortal (gperl_sv_from_gerror (error)));
PUTBACK;
call_method ("ERROR", G_VOID | G_DISCARD);
SPAGAIN;
FREETMPS;
LEAVE;
PERL_UNUSED_VAR (context);
}
static const GMarkupParser mini_markup_parser = {
gtk2perl_buildable_parser_start_element,
gtk2perl_buildable_parser_end_element,
gtk2perl_buildable_parser_text,
gtk2perl_buildable_parser_passthrough,
gtk2perl_buildable_parser_error
};
/*
* Now, support for GtkBuildableIface.
*/
#define GET_METHOD(object, name) \
HV * stash = gperl_object_stash_from_type (G_OBJECT_TYPE (object)); \
GV * slot = gv_fetchmethod (stash, name);
#define METHOD_EXISTS (slot && GvCV (slot))
#define GET_METHOD_OR_DIE(obj, name) \
GET_METHOD (obj, name); \
if (! METHOD_EXISTS) \
die ("No implementation for %s::%s\n", \
gperl_package_from_type (G_OBJECT_TYPE (obj)), name);
#define PREP(obj) \
dSP; \
ENTER; \
SAVETMPS; \
PUSHMARK (SP) ; \
PUSHs (sv_2mortal (newSVGObject (G_OBJECT (obj))));
#define CALL_VOID \
PUTBACK; \
call_sv ((SV *) GvCV (slot), G_VOID | G_DISCARD);
#define CALL_SCALAR(sv) \
PUTBACK; \
(void) call_sv ((SV *) GvCV (slot), G_SCALAR); \
SPAGAIN; \
sv = POPs; \
PUTBACK;
#define FINISH \
FREETMPS; \
LEAVE;
static void
gtk2perl_buildable_set_name (GtkBuildable *buildable,
const gchar *name)
{
GET_METHOD (buildable, "SET_NAME");
if (METHOD_EXISTS) {
PREP (buildable);
XPUSHs (sv_2mortal (newSVGChar (name)));
CALL_VOID;
FINISH;
} else {
/* Convenient fallback for mere mortals who need nothing
complicated. This is the same as in the upstream
implementation. */
g_object_set_data_full (G_OBJECT (buildable),
"gtk-builder-name",
g_strdup (name),
g_free);
}
}
static const gchar *
gtk2perl_buildable_get_name (GtkBuildable *buildable)
{
const gchar * name;
GET_METHOD (buildable, "GET_NAME");
if (METHOD_EXISTS) {
SV * sv;
PREP (buildable);
CALL_SCALAR (sv);
/*
* the interface wants us to return a const pointer, which
* means this needs to stay alive. Unfortunately, we can't
* guarantee that the scalar will still be around by the
* time the string is used. My first thought here was to
* use gperl_alloc_temp(), but that suffered the same
* lifetime issue, because the string was immediately
* returned to perl code, which meant that the temp was
* cleaned up an reused before the string was read.
* So, we'll go a little nuts and store a malloc'd copy
* of the string until the next call. In theory, some
* code might be crazy enough to return a different name
* on the second call, so we won't bother with real caching.
*/
name = g_strdup (SvGChar (sv));
g_object_set_data_full (G_OBJECT (buildable),
"gtk-perl-builder-name",
g_strdup (name),
g_free);
FINISH;
} else {
/* Convenient fallback for mere mortals who need nothing
complicated. This is the same as in the upstream
implementation. */
name = (const gchar *) g_object_get_data (G_OBJECT (buildable),
"gtk-builder-name");
}
return name;
}
static void
gtk2perl_buildable_add_child (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const gchar *type)
{
GET_METHOD_OR_DIE (buildable, "ADD_CHILD");
{
PREP (buildable);
XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
XPUSHs (sv_2mortal (newSVGObject (child)));
XPUSHs (sv_2mortal (newSVGChar (type)));
CALL_VOID;
FINISH;
}
}
static void
gtk2perl_buildable_set_buildable_property (GtkBuildable *buildable,
GtkBuilder *builder,
const gchar *name,
const GValue *value)
{
GET_METHOD (buildable, "SET_BUILDABLE_PROPERTY");
if (METHOD_EXISTS) {
PREP (buildable);
XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
XPUSHs (sv_2mortal (newSVGChar (name)));
XPUSHs (sv_2mortal (gperl_sv_from_value (value)));
CALL_VOID;
FINISH;
} else
g_object_set_property (G_OBJECT (buildable), name, value);
}
/* Nobody should really ever need this one; it's a special case for
* GtkUIManager... but, just in case. */
static GObject *
gtk2perl_buildable_construct_child (GtkBuildable *buildable,
GtkBuilder *builder,
const gchar *name)
{
GObject * child;
GET_METHOD_OR_DIE (buildable, "CONSTRUCT_CHILD");
{
SV * sv;
PREP (buildable);
XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
XPUSHs (sv_2mortal (newSVGChar (name)));
CALL_SCALAR (sv);
child = SvGObject (sv);
FINISH;
}
return child;
}
static gboolean
gtk2perl_buildable_custom_tag_start (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const gchar *tagname,
GMarkupParser *parser,
gpointer *data)
{
gboolean ret = FALSE;
GET_METHOD_OR_DIE (buildable, "CUSTOM_TAG_START");
*data = NULL;
memset (parser, 0, sizeof (*parser));
{
SV * sv;
PREP (buildable);
XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
XPUSHs (sv_2mortal (newSVGObject (child)));
XPUSHs (sv_2mortal (newSVGChar (tagname)));
CALL_SCALAR (sv);
if (gperl_sv_is_defined (sv)) {
ret = TRUE;
/* keep it... we'll destroy it in custom-finished,
* below, regardless of whether the perl code
* actually does anything with it. */
*data = newSVsv (sv);
*parser = mini_markup_parser;
}
FINISH;
}
return ret;
}
static void
gtk2perl_buildable_custom_tag_end (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const gchar *tagname,
gpointer *data)
{
GET_METHOD (buildable, "CUSTOM_TAG_END");
if (METHOD_EXISTS) {
SV * parser = gperl_sv_is_defined ((SV *) data)
? (SV *) data : &PL_sv_undef;
PREP (buildable);
XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
XPUSHs (sv_2mortal (newSVGObject (child)));
XPUSHs (sv_2mortal (newSVGChar (tagname)));
XPUSHs (parser);
CALL_VOID;
FINISH;
}
}
static void
gtk2perl_buildable_custom_finished (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const gchar *tagname,
gpointer data)
{
SV * parser = gperl_sv_is_defined ((SV *) data)
? (SV *) data : &PL_sv_undef;
GET_METHOD (buildable, "CUSTOM_FINISHED");
if (METHOD_EXISTS) {
PREP (buildable);
XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
XPUSHs (sv_2mortal (newSVGObject (child)));
XPUSHs (sv_2mortal (newSVGChar (tagname)));
XPUSHs (parser);
CALL_VOID;
FINISH;
}
if (parser != &PL_sv_undef)
/* No further use for this. */
SvREFCNT_dec (parser);
}
static void
gtk2perl_buildable_parser_finished (GtkBuildable *buildable,
GtkBuilder *builder)
{
GET_METHOD (buildable, "PARSER_FINISHED");
if (METHOD_EXISTS) {
PREP (buildable);
XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
CALL_VOID;
FINISH;
}
}
static GObject *
gtk2perl_buildable_get_internal_child (GtkBuildable *buildable,
GtkBuilder *builder,
const gchar *childname)
{
GObject * child = NULL;
GET_METHOD (buildable, "GET_INTERNAL_CHILD");
if (METHOD_EXISTS) {
SV * sv;
PREP (buildable);
XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
XPUSHs (sv_2mortal (newSVGChar (childname)));
CALL_SCALAR (sv);
child = SvGObject_ornull (sv);
FINISH;
}
return child;
}
static void
gtk2perl_buildable_init (GtkBuildableIface * iface)
{
iface->set_name = gtk2perl_buildable_set_name;
iface->get_name = gtk2perl_buildable_get_name;
iface->add_child = gtk2perl_buildable_add_child;
iface->set_buildable_property = gtk2perl_buildable_set_buildable_property;
iface->construct_child = gtk2perl_buildable_construct_child;
iface->custom_tag_start = gtk2perl_buildable_custom_tag_start;
iface->custom_tag_end = gtk2perl_buildable_custom_tag_end;
iface->custom_finished = gtk2perl_buildable_custom_finished;
iface->parser_finished = gtk2perl_buildable_parser_finished;
iface->get_internal_child = gtk2perl_buildable_get_internal_child;
}
MODULE = Gtk2::Buildable PACKAGE = Gtk2::Buildable PREFIX = gtk_buildable_
=for object Gtk2::Buildable - Interface for objects that can be built by Gtk2::Builder
=cut
=for apidoc __hide__
=cut
void
_ADD_INTERFACE (class, const char * target_class)
CODE:
{
static const GInterfaceInfo iface_info = {
(GInterfaceInitFunc) gtk2perl_buildable_init,
(GInterfaceFinalizeFunc) NULL,
(gpointer) NULL
};
GType gtype = gperl_object_type_from_package (target_class);
g_type_add_interface_static (gtype, GTK_TYPE_BUILDABLE, &iface_info);
}
#
# NOTE: The interface methods here really aren't useful in perl code,
# since they are meant to be called by GtkBuilder. I find it
# highly improbable that anyone would want to go to the trouble
# to reimplement GtkBuilder in perl, though i guess it's
# technically possible... Since these were part of the 1.160
# stable release, they can't be removed. Instead, we'll just
# hide all of them, so we can focus the docs on how to implement
# a buildable, instead of on how to use one.
#
# These two theoretically collide with Gtk2::Widget::set_name and get_name when
# dealing with Gtk2::Widgets. Fortunately though, GtkWidget maps these vfuncs
# to gtk_widget_set_name and _get_name anyway.
=for apidoc __hide__
=cut
void gtk_buildable_set_name (GtkBuildable *buildable, const gchar *name);
=for apidoc __hide__
=cut
const gchar * gtk_buildable_get_name (GtkBuildable *buildable);
=for apidoc __hide__
=cut
void gtk_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar_ornull *type);
# void gtk_buildable_set_buildable_property (GtkBuildable *buildable, GtkBuilder *builder, const gchar *name, const GValue *value);
=for apidoc __hide__
=for signature $buildable->set_buildable_property ($builder, key => $value, ...)
=for arg ... (__hide__)
=cut
void
gtk_buildable_set_buildable_property (GtkBuildable *buildable, GtkBuilder *builder, ...)
PREINIT:
GValue value = {0,};
int i;
CODE:
#define OFFSET 2
if (0 != ((items - OFFSET) % 2))
croak ("set_property expects name => value pairs "
"(odd number of arguments detected)");
for (i = OFFSET; i < items; i += 2) {
gchar *name = SvGChar (ST (i));
SV *newval = ST (i + 1);
GParamSpec *pspec =
g_object_class_find_property (G_OBJECT_GET_CLASS (buildable),
name);
if (!pspec) {
const char *classname =
gperl_object_package_from_type (G_OBJECT_TYPE (buildable));
if (!classname)
classname = G_OBJECT_TYPE_NAME (buildable);
croak ("type %s does not support property '%s'",
classname, name);
}
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
gperl_value_from_sv (&value, newval);
gtk_buildable_set_buildable_property (buildable, builder, name, &value);
g_value_unset (&value);
}
#undef OFFSET
# The caller will take ownership of the child.
=for apidoc __hide__
=cut
GObject_noinc * gtk_buildable_construct_child (GtkBuildable *buildable, GtkBuilder *builder, const gchar *name);
#
# We should not need to expose these, as they are used by GtkBuilder to
# allow the Buildable to handle its own tags during parsing. Unless somebody
# wants to reimplement GtkBuilder in perl code, these won't be useful.
# Besides, the dependency on GMarkupParser is a bit problematic.
#
# gboolean gtk_buildable_custom_tag_start (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *tagname, GMarkupParser *parser, gpointer *data);
# void gtk_buildable_custom_tag_end (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *tagname, gpointer *data);
# void gtk_buildable_custom_finished (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *tagname, gpointer data);
=for apidoc __hide__
=cut
void gtk_buildable_parser_finished (GtkBuildable *buildable, GtkBuilder *builder);
=for apidoc __hide__
=cut
GObject * gtk_buildable_get_internal_child (GtkBuildable *buildable, GtkBuilder *builder, const gchar *childname);
MODULE = Gtk2::Buildable PACKAGE = Gtk2::Buildable::ParseContext PREFIX = g_markup_parse_context_
#
# NOTE: This is a minimal binding for the parts of GMarkupParseContext
# a user would need from the Buildable custom tag handlers.
# Should GMarkupParseContext be bound in Glib, remove these methods
# and have Gtk2::Builder::ParseContext inherit them from Glib.
#
=for object Gtk2::Buildable::ParseContext
=head1 DESCRIPTION
This object contains context of the XML subset parser used by Gtk2::Builder.
Objects of this type will be passed to the methods invoked on the parser
returned from your Gtk2::Buildable's C<CUSTOM_TAG_START>. You should use
these methods to create useful error messages, as necessary.
=cut
=for see_also Gtk2::Buildable
=cut
=for apidoc
=for signature string = $parse_context->get_element
Return the name of the currently open element.
=cut
const gchar * g_markup_parse_context_get_element (SV * sv);
C_ARGS:
SvGtkBuildableParseContext (sv)
#if GLIB_CHECK_VERSION(2, 16, 0)
=for apidoc
=for signature list = $parse_context->get_element_stack
Returns the element stack; the first item is the currently-open tag
(which would be returned by C<get_element()>), and the next item is
its immediate parent.
=cut
void g_markup_parse_context_get_element_stack (SV * sv);
PREINIT:
const GSList * list;
PPCODE:
list = g_markup_parse_context_get_element_stack
(SvGtkBuildableParseContext (sv));
while (list) {
XPUSHs (sv_2mortal (newSVGChar (list->data)));
list = list->next;
}
#endif
=for apidoc
=for signature (line_number, char_number) = $parse_context->get_position
=cut
void
g_markup_parse_context_get_position (SV * sv)
PREINIT:
int line_number;
int char_number;
PPCODE:
g_markup_parse_context_get_position (SvGtkBuildableParseContext (sv),
&line_number, &char_number);
EXTEND (SP, 2);
PUSHs (sv_2mortal (newSViv (line_number)));
PUSHs (sv_2mortal (newSViv (char_number)));
MODULE = Gtk2::Buildable PACKAGE = Gtk2::Buildable
=for position SYNOPSIS
=head1 SYNOPSIS
package Thing;
use Gtk2;
use Glib::Object::Subclass
Glib::Object::,
# Some signals and properties on the object...
signals => {
exploderize => {},
},
properties => [
Glib::ParamSpec->int ('force', 'Force',
'Explosive force, in megatons',
0, 1000000, 5, ['readable', 'writable']),
],
;
sub exploderize {
my $self = shift;
$self->signal_emit ('exploderize');
}
# We can accept all defaults for Buildable; see the description
# for details on custom XML.
package main;
use Gtk2 -init;
my $builder = Gtk2::Builder->new ();
$builder->add_from_string ('<interface>
<object class="Thing" id="thing1">
<property name="force">50</property>
<signal name="exploderize" handler="do_explode" />
</object>
</interface>');
$builder->connect_signals ();
my $thing = $builder->get_object ('thing1');
$thing->exploderize ();
sub do_explode {
my $thing = shift;
printf "boom * %d!\n", $thing->get ('force');
}
# This program prints "boom * 50!" on stdout.
=cut
=head1 DESCRIPTION
The Gtk2::Buildable interface allows objects and widgets to have
C<< <child> >> objects, special property settings, or extra custom
tags in a Gtk2::Builder UI description
(L<http://library.gnome.org/devel/gtk/unstable/GtkBuilder.html#BUILDER-UI>).
The main user of the Gtk2::Buildable interface is Gtk2::Builder, so
there should be very little need for applications to call any of the
Gtk2::Buildable methods. So this documentation deals with
implementing a buildable object.
Gtk2::Builder already supports plain Glib::Object or Gtk2::Widget with
C<< <object> >> construction and C<< <property> >> settings, so
often the C<Gtk2::Buildable> interface is not needed. The only thing
to note is that an object or widget implemented in Perl must be loaded
before building.
=head1 OVERRIDING BUILDABLE INTERFACE METHODS
The buildable interface can be added to a Perl code object or widget
subclass by putting C<Gtk2::Buildable> in the interfaces list and
implementing the following methods.
In current Gtk2-Perl the custom tags code doesn't
chain up to any buildable interfaces in superclasses. This means for
instance if you implement Gtk2::Buildable on a new widget subclass
then you lose the <accelerator> and <accessibility> tags normally
available from Gtk2::Widget. This will likely change in the future,
probably by chaining up by default for unhandled tags, maybe with a
way to ask deliberately not to chain.
=over
=item SET_NAME ($self, $name)
=over
=item * $name (string)
=back
This method should store I<$name> in I<$self> somehow. For example,
Gtk2::Widget maps this to the Gtk2::Widget's C<name> property. If you don't
implement this method, the name will be attached in object data down in C
code. Implement this method if your object has some notion of "name" and
it makes sense to map the XML name attribute to that.
=item string = GET_NAME ($self)
If you implement C<SET_NAME>, you need to implement this method to retrieve
that name.
=item ADD_CHILD ($self, $builder, $child, $type)
=over
=item * $builder (Gtk2::Builder)
=item * $child (Glib::Object or undef)
=item * $type (string)
=back
C<ADD_CHILD> will be called to add I<$child> to I<$self>. I<$type> can be
used to determine the kind of child. For example, Gtk2::Container implements
this method to add a child widget to the container, and Gtk2::Notebook uses
I<$type> to distinguish between "page-label" and normal children. The value
of I<$type> comes directly from the C<type> attribute of the XML C<child> tag.
=item SET_BUILDABLE_PROPERTY ($self, $builder, $name, $value)
=over
=item * $builder (Gtk2::Builder)
=item * $name (string)
=item * $value (scalar)
=back
This will be called to set the object property I<$name> on I<$self>, directly
from the C<property> XML tag. It is not normally necessary to implement this
method, as the fallback simply calls C<Glib::Object::set()>. Gtk2::Window
implements this method to delay showing itself (i.e., setting the "visible"
property) until the whole interface is created. You can also use this to
handle properties that are not wired up through the Glib::Object property
system (though simply creating the property is easier).
=item parser or undef = CUSTOM_TAG_START ($self, $builder, $child, $tagname)
=over
=item * $builder (Gtk2::Builder)
=item * $child (Glib::Object or undef)
=item * $tagname (string)
=back
When Gtk2::Builder encounters an unknown tag while parsing the definition
of I<$self>, it will call C<CUSTOM_TAG_START> to give your code a chance
to do something with it. If I<$tagname> was encountered inside a C<child>
tag, the corresponding object will be passed in I<$child>; otherwise,
I<$child> will be C<undef>.
Your C<CUSTOM_TAG_START> method should decide whether it supports I<$tagname>.
If not, return C<undef>. If you do support it, return a blessed perl object
that implements three special methods to be used to parse that tag. (These
methods are defined by GLib's GMarkupParser, which is a simple SAX-style
setup.)
=over
=item START_ELEMENT ($self, $context, $element_name, $attributes)
=over
=item * $context (Gtk2::Buildable::ParseContext)
=item * $element_name (string)
=item * $attributes (hash reference) Dictionary of all attributes of this tag.
=back
=item TEXT ($self, $context, $text)
=over
=item * $context (Gtk2::Buildable::ParseContext)
=item * $text (string) The text contained in the tag.
=back
=item END_ELEMENT ($self, $context, $element_name)
=over
=item * $context (Gtk2::Buildable::ParseContext)
=item * $element_name (string)
=back
=back
Any blessed perl object that implements these methods is valid as a parser.
(Ain't duck-typing great?) Gtk2::Builder will hang on to this object until
the parsing is complete, and will pass it to C<CUSTOM_TAG_END> and
C<CUSTOM_FINISHED>, so you shouldn't have to worry about its lifetime.
=item CUSTOM_TAG_END ($self, $builder, $child, $tagname, $parser)
=over
=item * $builder (Gtk2::Builder)
=item * $child (Glib::Object or undef)
=item * $tagname (string)
=item * $parser (some perl object) as returned from C<CUSTOM_TAG_START>
=back
This method will be called (if it exists) when the close tag for I<$tagname>
is encountered. I<$parser> will be the object you returned from
C<CUSTOM_TAG_START>. I<$child> is the same object-or-undef as passed to
C<CUSTOM_TAG_START>.
=item CUSTOM_FINISHED ($self, $builder, $child, $tagname, $parser)
=over
=item * $builder (Gtk2::Builder)
=item * $child (Glib::Object or undef)
=item * $tagname (string)
=item * $parser (some perl object) as returned from C<CUSTOM_TAG_START>
=back
This method will be called (if it exists) when the parser finishes dealing
with the custom tag I<$tagname>. I<$parser> will be the object you returned
from C<CUSTOM_TAG_START>. I<$child> is the same object-or-undef as passed
to C<CUSTOM_TAG_START>.
=item PARSER_FINISHED ($self, $builder)
=over
=item * $builder (Gtk2::Builder)
=back
If this method exists, it will be invoked when the builder finishes parsing
the description data. This method is handy if you need to defer any object
initialization until all of the rest of the input is parsed, most likely
because you need to refer to an object that is declared after I<$self> or
you need to perform special cleanup actions. It is not normally necessary
to implement this method.
=item object or undef = GET_INTERNAL_CHILD ($self, $builder, $childname)
=over
=item * $builder (Gtk2::Builder)
=item * $childname (string)
=back
This will be called to fetch an internal child of I<$self>. Implement this
method if your buildable has internal children that need to be accessed from
a UI definition. For example, Gtk2::Dialog implements this to give access
to its internal vbox child.
If I<$childname> is unknown then return C<undef>. (The builder will
then generally report a GError for the UI description referring to an
unknown child.)
=back
=cut
=for see_also http://library.gnome.org/devel/gtk/unstable/GtkBuilder.html#BUILDER-UI
=cut
=for see_also Gtk2::Buildable::ParseContext
=cut
|