Glade-Perl-Two

 view release on metacpan or  search on metacpan

Glade/Two/Gtk.pm  view on Meta::CPAN


    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkVSeparator {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_VSeparator";
    my $name = $proto->{'widget'}{'name'};

    $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::VSeparator;");

    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkLayout {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkLayout";
    my $name = $proto->{'widget'}{'name'};

    $class->load_class("Gtk2::Adjustment");
    my $hadjustment = $class->use_par($proto, 'hadjustment',  $MAYBE);
    my ($value, $lower, $upper, $step, $page, $page_size) =
        split(" ", $hadjustment);
    $class->add_to_UI($depth,  "\$work->{'$name-hadj'} = new Gtk2::Adjustment(".
        "$value, $lower, $upper, $step, $page, $page_size);");

    my $vadjustment = $class->use_par($proto, 'vadjustment',  $MAYBE);
    ($value, $lower, $upper, $step, $page, $page_size) =
        split(" ", $hadjustment);
    $class->add_to_UI($depth,  "\$work->{'$name-vadj'} = new Gtk2::Adjustment(".
        "$value, $lower, $upper, $step, $page, $page_size);");

    $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::Layout(".
        "\$work->{'$name-hadj'}, \$work->{'$name-vadj'});");

    my $width  = $class->use_par($proto, 'width',  $DEFAULT, 0);
    my $height = $class->use_par($proto, 'height',  $DEFAULT, 0);
    $class->add_to_UI($depth, "\$widgets->{'$name'}->set_size(".
        "$width, $height);");

    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkList {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkList";
    my $name = $proto->{'widget'}{'name'};

#    unless ($class->get_internal_child($parent, $name, $proto, $depth)) {
        $class->add_to_UI($depth,  "\$widgets->{'$name'} = new Gtk2::List;");
#    }
    $class->use_set_property($name, $proto, 'selection_mode', $LOOKUP, $depth);

    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkMenu {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkMenu";
    my $name = $proto->{'widget'}{'name'};

    $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::Menu;");

    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkMenuBar {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkMenuBar";
    my $name = $proto->{'widget'}{'name'};

    $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::MenuBar;");

    $class->use_set_property($name, $proto, 'shadow_type', $LOOKUP, $depth);

    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkMenuFactory {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkMenuFactory";
    my $name = $proto->{'widget'}{'name'};

    $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::MenuFactory(".");");

    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkImageMenuItem {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkImageMenuItem";
    my $name = $proto->{'widget'}{'name'};
    my $label = $class->use_par($proto, 'label', $DEFAULT, '');

    if ($proto->{'widget'}{'property'}{'stock'}) {
        # This is a stock menu item
        my $stock = $class->use_par($proto, 'stock', $MAYBE);
#        $label = Glade::Gnome->lookup($stock_item);
#        $stock_item = $Glade::Gnome::gnome_enums->{"GNOME_STOCK_PIXMAP_$stock_item"};
        $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
            "Gtk2::ImageMenuItem->new_from_stock('$stock', 
                $current_form\{'accelgroup'});");
    } elsif ($label) {
        if ($class->use_par($proto, 'use_underline', $BOOL)) {
            $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
                "new_with_mnemonic Gtk2::ImageMenuItem(_('$label'));");
        } else {
            $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
                "new_with_label Gtk2::ImageMenuItem(_('$label'));");
        }
    } else {
        $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
            "new Gtk2::ImageMenuItem;");
    }
    $class->load_class("Gtk2::AccelLabel");
    
    $class->set_label_properties($parent, $name, $proto, $depth);
    $class->pack_widget($parent, $name, $proto, $depth);

    return $widgets->{$name};
}

sub new_GtkListItem {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkListItem";
    my $name = $proto->{'widget'}{'name'};
    my $label = $class->use_par($proto, 'label', $DEFAULT, '');

    if ($proto->{'widget'}{'property'}{'stock_item'}) {
# FIXME - this is a Gnome stock menu item and should be in Gnome
        my $stock_item = $class->use_par($proto, 'stock_item', $DEFAULT, '');
        $proto->{'widget'}{'property'}{'label'} = 
            {'value' => Glade::Gnome->lookup($stock_item)};
#        $label = Glade::Gnome->lookup($stock_item);
#        $stock_item = $Glade::Gnome::gnome_enums->{"GNOME_STOCK_PIXMAP_$stock_item"};
#        $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
#            "Gnome::Stock->menu_item('$stock_item', '$stock_item');");
    }
    if ($label) {
        $class->add_to_UI($depth, "\$widgets->{'$name'} = new_with_label Gtk2::ListItem(".
            "_('$label'));");
    } else {
        $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::ListItem;");
    }
    $class->set_label_properties($parent, $name, $proto, $depth);
    $class->pack_widget($parent, $name, $proto, $depth);

    return $widgets->{$name};
}

sub new_GtkMenuItem {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkMenuItem";
    my $name = $proto->{'widget'}{'name'};

    $class->load_class("Gtk2::AccelLabel");
    if ($proto->{'widget'}{'property'}{'stock_item'}) {
# FIXME - this is a Gnome stock menu item and should be in Gnome
        my $stock_item = $class->use_par($proto, 'stock_item', $DEFAULT, '');
        $proto->{'widget'}{'property'}{'label'} = 
            {'value' => Glade::Gnome->lookup($stock_item)};
#        $label = Glade::Gnome->lookup($stock_item);
#        $stock_item = $Glade::Gnome::gnome_enums->{"GNOME_STOCK_PIXMAP_$stock_item"};
#        $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
#            "Gnome::Stock->menu_item('$stock_item', '$stock_item');");
    }
    my $use_underline = $class->use_par($proto, 'use_underline', $BOOL|$MAYBE);
    my $label = $class->use_par($proto, 'label', $DEFAULT, '');
    if ($label) {
        if ($use_underline) {
            $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
                "new_with_mnemonic Gtk2::MenuItem(_('$label'));");
        } else {
            $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
                "new_with_label Gtk2::MenuItem(_('$label'));");
        }
    } else {
        $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::MenuItem();");
    }
    $class->set_label_properties($parent, $name, $proto, $depth);
    $class->pack_widget($parent, $name, $proto, $depth);

    return $widgets->{$name};
}

sub new_GtkCheckMenuItem {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkCheckMenuItem";
    my $name = $proto->{'widget'}{'name'};

    $class->load_class("Gtk2::AccelLabel");

    my $use_underline = $class->use_par($proto, 'use_underline', $BOOL|$MAYBE);
    my $label  = $class->use_par($proto, 'label',  $DEFAULT, '');
    if ($label) {
        if ($use_underline) {
            $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
                "new_with_mnemonic Gtk2::CheckMenuItem(_('$label'));");
        } else {
            $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
                "new_with_label Gtk2::CheckMenuItem(_('$label'));");
        }
    } else {
        $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::CheckMenuItem();");
    }
#    $class->add_to_UI($depth,  "\$widgets->{'$name'} = ".
#        "new Gtk2::CheckMenuItem();");

#    if ($class->use_par($proto, 'right_justify',    $BOOL, 'False')) {
#        $class->add_to_UI($depth, "\$widgets->{'$name'}->right_justify;");
#    }
    $class->use_set_property($name, $proto, 'active', $BOOL, $depth);
    $class->use_set_property($name, $proto, 'always_show_toggle', $BOOL, $depth, 'set_show_toggle');

    $class->set_label_properties($parent, $name, $proto, $depth);
    $class->pack_widget($parent, $name, $proto, $depth);

    return $widgets->{$name};
}


sub new_GtkRadioMenuItem {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkRadioMenuItem";
    my $name = $proto->{'widget'}{'name'};
    my $label  = $class->use_par($proto, 'label', $DEFAULT, '');
    my $use_underline = $class->use_par($proto, 'use_underline',  $MAYBE);
    $class->load_class("Gtk2::AccelLabel");
    my $method;
    if ($use_underline) {
        $method = "new_with_mnemonic";
    } else {
        $method = "new_with_label";
    }
    my $group  = $class->use_par($proto, 'group',  $DEFAULT, $name);
    my $group_widget = "$current_form\{'rb_group'}{'$group'}";
    if (eval "defined $group_widget") {
        $class->add_to_UI($depth,  "\$widgets->{'$name'} = ".
            "$method Gtk2::RadioMenuItem($group_widget->get_group(), _('$label'));");
    } else {
        $class->add_to_UI($depth,  "\$widgets->{'$name'} = ".
            "$method Gtk2::RadioMenuItem(undef, _('$label'));");

        $class->add_to_UI($depth, "$group_widget = \$widgets->{'$name'};");
    }

    $class->use_set_property($name, $proto, 'active', $BOOL, $depth);
    $class->use_set_property($name, $proto, 'always_show_toggle', $BOOL, $depth, 'set_show_toggle');

#    $class->set_label_properties($parent, $name, $proto, $depth);
    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkNotebook {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkNotebook";
    my $name = $proto->{'widget'}{'name'};

    my $ignore      = $class->use_par($proto, 'num_pages',   $DEFAULT, 0);
    
    unless ($class->get_internal_child($parent, $name, $proto, $depth)) {
        $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::Notebook;");
    }

    $class->use_set_property($name, $proto, 'tab_pos', $LOOKUP, $depth);
    $class->use_set_property($name, $proto, 'show_tabs', $BOOL, $depth);
    $class->use_set_property($name, $proto, 'show_border', $BOOL, $depth);
    $class->use_set_property($name, $proto, 'scrollable', $BOOL, $depth);
    $class->use_set_property($name, $proto, 'tab_hborder', $INT, $depth);
    $class->use_set_property($name, $proto, 'tab_vborder', $INT, $depth);

    if ($class->use_par($proto, 'enable_popup', $BOOL|$MAYBE)) { 
        $class->add_to_UI($depth,  "\$widgets->{'$name'}->popup_enable();");
    } else {
        $class->add_to_UI($depth,  "\$widgets->{'$name'}->popup_disable();");
    }
    # 'num_pages'
    $nb->{$name} = {'panes' => [], 'pane' => 0, 'tab' => 0};

    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkObject {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkObject";
    my $name = $proto->{'widget'}{'name'};

    $class->add_to_UI($depth, "\$widgets->{'$name'} = new Gtk2::Object;");

    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}

sub new_GtkOptionMenu {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkOptionMenu";
    my $name = $proto->{'widget'}{'name'};
    my $item;
    my @items;
    my $count = 0;
    my $items          = $class->use_par($proto, 'items');
    my $history = $class->use_par($proto, 'history', $DEFAULT, 0);

    $class->add_to_UI($depth,  "\$widgets->{'$name'} = new Gtk2::OptionMenu;");
    $class->pack_widget($parent, $name, $proto, $depth);

    $class->add_to_UI($depth,  "\$widgets->{'${name}_menu'} = new Gtk2::Menu;");
    $class->pack_widget("$name", "${name}_menu", $proto, $depth);
    if (defined $items) {
        @items = split(/\n/, $items);
        foreach $item (@items) {
            if ($item) {
                $class->add_to_UI($depth,  "\$widgets->{'${name}_item$count'} = ".
                    "new Gtk2::MenuItem('$item');");
                $class->pack_widget("${name}_menu", "${name}_item$count", $proto, $depth+1);
                if ($count == $history) {
                    $class->add_to_UI($depth, 
                        "${current_form}\{'${name}_item$count'}\->activate;");
                }
                $count++;
            }
        }
        $class->add_to_UI($depth, 
            "${current_form}\{'$name'}->set_history( $history);");
    }
    return $widgets->{$name};
}

#sub new_image {&new_GtkImage(@_);}
sub new_GtkImage {
    my ($class, $parent, $proto, $depth) = @_;
    my $me = "$class->new_GtkImage";
    my $name = $proto->{'widget'}{'name'};
    my $stock  = $class->use_par($proto, 'stock',  $MAYBE);
    my $icon_sizes = [
        'invalid',          #GTK_ICON_SIZE_INVALID,
        'menu',             #GTK_ICON_SIZE_MENU,
        'small-toolbar',    #GTK_ICON_SIZE_SMALL_TOOLBAR,
        'large-toolbar',    #GTK_ICON_SIZE_LARGE_TOOLBAR,
        'button',           #GTK_ICON_SIZE_BUTTON,
        'dnd',              #GTK_ICON_SIZE_DND,
        'dialog',           #GTK_ICON_SIZE_DIALOG
    ];
#    unless ($class->get_internal_child($parent, $name, $proto, $depth)) {
        if ($stock) {
            my $icon_size  = $class->use_par($proto, 'icon_size',  $DEFAULT, 0);
            $class->add_to_UI($depth,  "\$widgets->{'$name'} = ".
                "new_from_stock Gtk2::Image('$stock', '$icon_sizes->[$icon_size]');");

        } else {
            my $filename = $class->use_par($proto, 'pixbuf', $DEFAULT, '');
            unless ($filename) {
                $Glade_Perl->diag_print(2, "warn  No image file specified for $me ".
                    "'%s' so we are using the project logo instead", $name);
                $filename = $Glade_Perl->app->logo;
            }
            $class->add_to_UI($depth, "\$widgets->{'$name'} = ".
                "\$class->create_image(\"$filename\", [\"\$Glade::Two::Run::pixmaps_directory\"]);");
            unless ($Glade_Perl->source->quick_gen or defined $widgets->{$name}) { 
    #            die sprintf(("\nerror %s failed to create pixmap from file '%s'"),
                $class->log_error("\$class->create_image($filename)", 
                    (sprintf(_("\nerror %s failed to create image from file '%s'"),
                        $me, $filename)));
            }
        }
#    }
    $class->set_misc_properties($parent, $name, $proto, $depth);
#print Dumper($proto);exit;
    delete $failures->{$INTERNAL_CHILD}{$parent}{$proto->{'internal-child'}};
    delete $proto->{'internal-child'};
    $class->pack_widget($parent, $name, $proto, $depth);
    return $widgets->{$name};
}



( run in 0.955 second using v1.01-cache-2.11-cpan-39bf76dae61 )