summaryrefslogtreecommitdiffstats
path: root/perl-install/ugtk2.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/ugtk2.pm')
-rw-r--r--perl-install/ugtk2.pm130
1 files changed, 86 insertions, 44 deletions
diff --git a/perl-install/ugtk2.pm b/perl-install/ugtk2.pm
index d04285fd0..5883d4cc0 100644
--- a/perl-install/ugtk2.pm
+++ b/perl-install/ugtk2.pm
@@ -5,7 +5,7 @@ use strict;
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK @icon_paths $wm_icon $force_center_at_pos $force_center $force_focus $grab $pop_it $border); #- leave it on one line, for automatic removal of the line at package creation
use lang;
-$::o = { locale => lang::read() } if !$::isInstall;
+$::o = { locale => lang::read(1) } if !$::isInstall;
@ISA = qw(Exporter);
%EXPORT_TAGS = (
@@ -134,9 +134,9 @@ sub gtkappenditems {
# append page to a notebook
sub gtkappend_page {
- my $w = shift;
- $w->append_page(@_);
- $w
+ my ($notebook, $page, $o_title) = @_;
+ $notebook->append_page($page, $o_title);
+ $notebook;
}
sub gtkentry {
@@ -236,7 +236,7 @@ sub gtkpowerpack {
}
#- Get and pack the widget (create it if necessary to a label...)
my $widget = ref($_[0]) ? shift : Gtk2::WrappedLabel->new(shift);
- my $pack_call = 'pack_'.($attr{pack_end} ? 'end' : 'start');
+ my $pack_call = 'pack_' . ($attr{pack_end} ? 'end' : 'start');
$box->$pack_call($widget, $attr{expand}, $attr{fill}, $attr{padding});
$widget->show;
}
@@ -287,6 +287,7 @@ sub create_scrolled_window {
}
$o_viewport_shadow and gtkset_shadow_type($w->child, $o_viewport_shadow);
$W->can('set_focus_vadjustment') and $W->set_focus_vadjustment($w->get_vadjustment);
+ $W->set_left_margin(6) if ref($W) =~ /Gtk2::TextView/;
$W->show;
if (ref($W) =~ /Gtk2::TextView|Gtk2::TreeView/) {
gtkadd(gtkset_shadow_type(Gtk2::Frame->new, 'in'), $w)
@@ -303,16 +304,16 @@ sub n_line_size {
}
sub create_box_with_title {
- my $o = shift;
+ my ($o, @l) = @_;
- my $nbline = sum(map { round(length($_) / 60 + 1/2) } map { split "\n" } @_);
+ my $nbline = sum(map { round(length($_) / 60 + 1/2) } map { split "\n" } @l);
my $box = Gtk2::VBox->new(0,0);
if ($nbline == 0) {
$o->{box_size} = 0;
return $box;
}
$o->{box_size} = n_line_size($nbline, 'text', $box);
- if (@_ <= 2 && $nbline > 4) {
+ if (@l <= 2 && $nbline > 4) {
$o->{icon} && !$::isWizard and
eval { gtkpack__($box, gtkset_border_width(gtkpack_(Gtk2::HBox->new(0,0), 1, gtkcreate_img($o->{icon})),5)) };
my $wanted = $o->{box_size};
@@ -323,7 +324,7 @@ sub create_box_with_title {
$wtext->set_left_margin(3);
$wtext->can_focus($has_scroll);
$wtext->signal_connect(button_press_event => sub { 1 }); #- disable selecting text and popping the contextual menu (GUI team says it's *horrible* to be able to do select text!)
- chomp(my $text = join("\n", @_));
+ chomp(my $text = join("\n", @l));
my $scroll = create_scrolled_window(gtktext_insert($wtext, $text));
my $width = 400;
$scroll->signal_connect(realize => sub {
@@ -334,7 +335,7 @@ sub create_box_with_title {
$o->{rwindow}->queue_resize;
});
$scroll->set_size_request($width, 200);
- gtkpack_($box, 0, $scroll);
+ gtkpack_($box, $o->{box_allow_grow} || 0, $scroll);
} else {
my $a = !$::no_separator;
undef $::no_separator;
@@ -355,7 +356,7 @@ sub create_box_with_title {
my $w = $new_label->($_);
$::isWizard and $w->set_justify("left");
(0, $w);
- } @_),
+ } @l),
1, Gtk2::HBox->new(0,0),
)
),
@@ -368,7 +369,7 @@ sub create_box_with_title {
my $w = $new_label->($_);
$::isWizard ? gtkpack__(Gtk2::HBox->new(0,0), gtkset_size_request(Gtk2::Label->new, 20, 0), $w)
: $w
- } @_),
+ } @l),
if_($::isWizard, gtkset_size_request(Gtk2::Label->new, 0, 15)),
if_($a, Gtk2::HSeparator->new)
)
@@ -393,12 +394,15 @@ sub _create_dialog {
sub create_dialog {
my ($title, $label, $o_options) = @_;
my $ret = 0;
- my $dialog = _create_dialog($title, $o_options);
+ my $dialog = gtkset_border_width(_create_dialog($title, $o_options), 10);
$dialog->set_border_width(10);
my $text = ref($label) ? $label : $o_options->{use_markup} ? gtkset_markup(Gtk2::WrappedLabel->new, $label) : Gtk2::WrappedLabel->new($label);
gtkpack($dialog->vbox,
gtkpack_(Gtk2::HBox->new,
- if_($o_options->{stock}, 0, Gtk2::Image->new_from_stock($o_options->{stock}, 'dialog')),
+ if_($o_options->{stock},
+ 0, Gtk2::Image->new_from_stock($o_options->{stock}, 'dialog'),
+ 0, Gtk2::Label->new(" "),
+ ),
1, $o_options->{scroll} ? create_scrolled_window($text, [ 'never', 'automatic' ]) : $text,
),
);
@@ -416,6 +420,7 @@ sub create_dialog {
$dialog->action_area->pack_start($button, 1, 1, 0);
$button->grab_default;
+ $dialog->set_has_separator(0);;
$dialog->show_all;
Gtk2->main;
$ret;
@@ -442,7 +447,7 @@ sub err_dialog {
create_dialog($title, $label, $o_options);
}
-sub create_hbox { gtkset_layout(gtkset_border_width(Gtk2::HButtonBox->new, 3), $_[0] || 'spread') }
+sub create_hbox { gtkset_layout(Gtk2::HButtonBox->new, $_[0] || 'spread') }
sub create_vbox { gtkset_layout(Gtk2::VButtonBox->new, $_[0] || 'spread') }
sub create_factory_menu_ {
@@ -464,12 +469,12 @@ sub create_menu {
}
sub create_notebook {
- my $n = Gtk2::Notebook->new;
+ my $book = Gtk2::Notebook->new;
while (@_) {
- my ($title, $book) = splice(@_, 0, 2);
- add2notebook($n, $title, $book);
+ my ($page, $title) = splice(@_, 0, 2);
+ gtkappend_page($book, $page, $title);
}
- $n
+ $book
}
sub create_packtable {
@@ -493,7 +498,7 @@ sub create_packtable {
} @l;
$w->set_col_spacings($options->{col_spacings} || 0);
$w->set_row_spacings($options->{row_spacings} || 0);
- $w
+ gtkset_border_width($w, $::isInstall ? 3 : 10);
}
sub create_okcancel {
@@ -617,27 +622,61 @@ sub may_set_icon {
}
}
-# choose one of the two styles:
-# - gtktext_insert($textview, "My text..");
-# - gtktext_insert($textview, [ [ 'first text', { 'foreground' => 'blue', 'background' => 'green', ... } ],
+# gtktext_insert() can be used with any of choose one of theses styles:
+# - no tags:
+# gtktext_insert($textview, "My text..");
+# - anonymous tags:
+# gtktext_insert($textview, [ [ 'first text', { 'foreground' => 'blue', 'background' => 'green', ... } ],
# [ 'second text' ],
# [ 'third', { 'font' => 'Serif 15', ... } ],
# ... ]);
+# - named tags:
+# $textview->{tags} = {
+# 'blue_green' => { 'foreground' => 'blue', 'background' => 'green', ... },
+# 'big_font' => { 'font' => 'Serif 35', ... },
+# }
+# gtktext_insert($textview, [ [ 'first text', 'blue_green' ],
+# [ 'second', 'big_font' ],
+# ... ]);
+# - mixed anonymous and named tags:
+# $textview->{tags} = {
+# 'blue_green' => { 'foreground' => 'blue', 'background' => 'green', ... },
+# 'big_font' => { 'font' => 'Serif 35', ... },
+# }
+# gtktext_insert($textview, [ [ 'first text', 'blue_green' ],
+# [ 'second text' ],
+# [ 'third', 'big_font' ],
+# [ 'fourth', { 'font' => 'Serif 15', ... } ],
+# ... ]);
sub gtktext_insert {
my ($textview, $t, %opts) = @_;
my $buffer = $textview->get_buffer;
+ $buffer->{tags} ||= {};
+ $buffer->{gtk_tags} ||= {};
+ my $gtk_tags = $buffer->{gtk_tags};
+ my $tags = $buffer->{tags};
if (ref($t) eq 'ARRAY') {
$opts{append} or $buffer->set_text('');
foreach my $token (@$t) {
+ my ($item, $tag) = @$token;
my $iter1 = $buffer->get_end_iter;
- if ($token->[0] =~ /^Gtk2::Gdk::Pixbuf/) {
- $buffer->insert_pixbuf($iter1, $token->[0]);
+ if ($item =~ /^Gtk2::Gdk::Pixbuf/) {
+ $buffer->insert_pixbuf($iter1, $item);
next;
}
- if ($token->[1]) {
- $buffer->insert_with_tags($iter1, $token->[0], $buffer->create_tag(undef, %{$token->[1]}));
+ if ($tag) {
+ if (ref($tag)) {
+ # use anonymous tags
+ $buffer->insert_with_tags($iter1, $item, $buffer->create_tag(undef, %$tag));
+ } else {
+ # fast text insertion:
+ # since in some contexts (eg: localedrake, rpmdrake), we use quite a lot of identical tags,
+ # it's much more efficient and less memory pressure to use named tags
+ $gtk_tags->{$tag} ||= $buffer->create_tag($tag, %{$tags->{$token->[1]}});
+ $buffer->insert_with_tags($iter1, $item, $gtk_tags->{$tag});
+ }
} else {
- $buffer->insert($iter1, $token->[0]);
+ $buffer->insert($iter1, $item);
}
}
} else {
@@ -747,17 +786,18 @@ sub string_height {
}
sub get_text_coord {
- my ($text, $widget4style, $max_width, $currentx, $currenty, $o_wrap_char) = @_;
- my $wrap_char = $o_wrap_char || ' ';
+ my ($text, $widget4style, $max_width, $currentx, $currenty) = @_;
+ my $wrap_char = ' ';
my @lines;
my $current_text;
my @t = split($wrap_char, $text);
my @t2;
if ($::isInstall && $::o->{locale}{lang} =~ /ja|zh/) {
+ use locale;
@t = map { $_ . $wrap_char } @t;
$wrap_char = '';
foreach (@t) {
- my @c = split('');
+ my @c = split(/\b/);
my $i = 0;
my $el = '';
while (1) {
@@ -937,15 +977,18 @@ sub new {
if ($::isInstall) {
$::WizardWindow->signal_connect(key_press_event => sub {
my (undef, $event) = @_;
- my $d = ${{ $Gtk2::Gdk::Keysyms{F2} => 'screenshot' }}{$event->keyval};
+ my $d = ${{ $Gtk2::Gdk::Keysyms{F2} => 'screenshot', $Gtk2::Gdk::Keysyms{Delete} => 'restart' }}{$event->keyval};
if ($d eq 'screenshot') {
common::take_screenshot();
- }
+ } elsif ($d eq 'restart' && member('control-mask', @{$event->state}) && member('mod1-mask', @{$event->state})) {
+ log::l("restarting install");
+ $o->exit(0x35);
+ }
0;
});
} elsif (!$o->{isEmbedded}) {
$::WizardWindow->set_position('center_always') if !$::isStandalone;
- eval { gtkpack__($::WizardTable, Gtk2::Banner->new($::Wizard_pix_up || "wiz_default_up.png", $::Wizard_title)) };
+ eval { gtkpack__($::WizardTable, Gtk2::Banner->new($::Wizard_pix_up || $wm_icon || "wiz_default_up.png", $::Wizard_title)) };
$@ and log::l("ERROR: missing wizard banner");
may_set_icon($::WizardWindow, $o->{wm_icon});
}
@@ -997,11 +1040,7 @@ sub sync {
sub flush() { gtkflush() }
sub shrink_topwindow {
my ($o) = @_;
- if ($Gtk2::VERSION < 1.040) {
- $o->{rwindow}->signal_emit('size_allocate', Gtk2::Allocation->new(-1, -1, -1, -1));
- } else {
- $o->{rwindow}->signal_emit('size_allocate', Gtk2::Gdk::Rectangle->new(-1, -1, -1, -1));
- }
+ $o->{rwindow}->signal_emit('size_allocate', Gtk2::Gdk::Rectangle->new(-1, -1, -1, -1));
}
sub exit {
gtkset_mousecursor_normal(); #- for restoring a normal in any case
@@ -1015,6 +1054,7 @@ END { &exit() }
sub _create_window {
my ($title) = @_;
my $w = Gtk2::Window->new('toplevel');
+ $w->set_border_width(5) if !$::isInstall && !$::isWizard;
$w->set_name("Title");
$w->set_title($title || '');
@@ -1146,7 +1186,7 @@ sub _ask_dir {
$f->selection_entry->get_parent->hide;
$f->ok_button->signal_connect(clicked => sub {
my ($model, $iter) = $f->dir_list->get_selection->get_selected;
- $o->{retval} .= '/'.$model->get($iter, 0) if $model;
+ $o->{retval} .= '/' . $model->get($iter, 0) if $model;
});
}
@@ -1237,8 +1277,10 @@ sub ask_browse_tree_info_given_widgets {
my ($curr, $prev_label, $idle, $mouse_toggle_pending);
my (%wtree, %ptree, %pix, %node_state, %state_stats);
my $update_size = sub {
- my $new_label = $common->{get_status}();
- $prev_label ne $new_label and $w->{status}->set($prev_label = $new_label);
+ if ($w->{status}) {
+ my $new_label = $common->{get_status}();
+ $prev_label ne $new_label and $w->{status}->set($prev_label = $new_label);
+ }
};
my $set_node_state_flat = sub {
@@ -1377,7 +1419,6 @@ sub ask_browse_tree_info_given_widgets {
$w->{tree}->toggle_expansion($w->{tree_model}->get_path($curr));
} else {
if (ref $curr) {
- my @_a = $children->($curr);
my @l = $common->{grep_allowed_to_toggle}($children->($curr)) or return;
my @unsel = $common->{grep_unselected}(@l);
my @p = @unsel ?
@@ -1622,7 +1663,7 @@ sub set_popdown_strings {
sub new_with_strings {
my ($class, $strs, $o_val) = @_;
- my $w = $class->new;
+ my $w = $class->new_text;
$w->set_popdown_strings(@$strs);
$w->set_text($o_val) if $o_val;
$w;
@@ -1644,6 +1685,7 @@ sub set_text {
my $val_index = find_index { $_ eq $val } @{$w->{strings}};
$w->set_active($val_index);
};
+ # internal_error(qq(impossible to lookup "$val":\n\t) . chomp_($@)) if $@;
}