[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

chaining to superclass in CUSTOM_TAG_START



When implementing GtkBuildable with a CUSTOM_TAG_START func like in the
program below, I seem to lose the base GtkWidget tags like
<acceleartor>.  Running it gives

    Unhandled tag: 'accelerator' at buildable-subclass.pl line 26.

Changing "MyThing" in the input string to "GtkButton" shows how I hoped
it would go, with 'x' as an accelerator key to press the button.

Do I do something special in CUSTOM_TAG_START to chain up to the
superclass's custom_tag_start?  The equivalent in C might be something
like

    buildable_parent_iface = g_type_interface_peek_parent (iface);
    ....
    if (buildable_parent_iface->custom_tag_start (...))
      return TRUE;
    ...

Wrapping that looks like hard work.  I wonder if a cheat could be a
special return value from CUSTOM_TAG_START that asks
gtk2perl_buildable_custom_tag_start to chain upwards.  (If that isn't
already possible and I've missed it ... :-)

package MyThing;
use strict;
use warnings;
use Gtk2;

use Glib::Object::Subclass
  Gtk2::Button::,
  interfaces => [ 'Gtk2::Buildable' ];

sub CUSTOM_TAG_START {
  my ($self, $builder, $child, $tagname) = @_;
  print "hello from CUSTOM_TAG_START\n";
  if ($tagname eq 'mynewtag') {
    # ... make and return a parser
  }
  # how to chain to superclass buildable ?
  return undef;
}

package main;
use strict;
use warnings;
use Gtk2 '-init';

my $builder = Gtk2::Builder->new;
$builder->add_from_string ('
<interface>
  <object class="GtkWindow" id="toplevel">
    <property name="type">toplevel</property>
    <child>
      <object class="MyThing" id="button">
        <signal name="clicked" handler="do_click"/>
        <accelerator key="x" signal="clicked"/>

        <child>
          <object class="GtkLabel" id="label">
            <property name="label">Press Me</property>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
');

sub do_click { print "the button was clicked\n"; }
$builder->connect_signals;

$builder->get_object('toplevel')->show_all;
Gtk2->main;
exit 0;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]