diff options
Diffstat (limited to 'perl-install/mygtk2.pm')
| -rw-r--r-- | perl-install/mygtk2.pm | 471 |
1 files changed, 378 insertions, 93 deletions
diff --git a/perl-install/mygtk2.pm b/perl-install/mygtk2.pm index 1da429eec..6633decf3 100644 --- a/perl-install/mygtk2.pm +++ b/perl-install/mygtk2.pm @@ -12,7 +12,6 @@ use log; use common; use Gtk2; -use Gtk2::Gdk::Keysyms; sub init() { !check_for_xserver() and print("Cannot be run in console mode.\n"), c::_exit(0); @@ -20,13 +19,13 @@ sub init() { Gtk2->init; Locale::gettext::bind_textdomain_codeset($_, 'UTF8') foreach 'libDrakX', if_(!$::isInstall, 'libDrakX-standalone'), - if_($::isInstall, 'draksnapshot'), + if_($::isRestore, 'draksnapshot'), if_($::isInstall, 'urpmi'), 'drakx-net', 'drakx-kbd-mouse-x11', # shared translation @::textdomains; - Gtk2->croak_execeptions; + Glib->enable_exceptions2; } -init() unless ($::no_ugtk_init); -Gtk2->croak_execeptions if $::isInstall; +init() unless $::no_ugtk_init; +Glib->enable_exceptions2 if $::isInstall; @@ -119,6 +118,8 @@ sub _gtk { $w->grab_focus if delete $opts->{grab_focus}; $w->set_padding(@{delete $opts->{padding}}) if exists $opts->{padding}; $w->set_sensitive(delete $opts->{sensitive}) if exists $opts->{sensitive}; + $w->signal_connect(expose_event => delete $opts->{expose_event}) if exists $opts->{expose_event}; + $w->signal_connect(realize => delete $opts->{realize}) if exists $opts->{realize}; (delete $opts->{size_group})->add_widget($w) if $opts->{size_group}; if (my $tip = delete $opts->{tip}) { $global_tooltips ||= Gtk2::Tooltips->new; @@ -145,8 +146,7 @@ sub _gtk { } sub _gtk__Install_Button { - my ($w, $opts, $class) = @_; - $opts->{widget_name} = 'Banner'; + my ($w, $opts, $_class) = @_; $opts->{child} = gtknew('HBox', spacing => 5, children_tight => [ # FIXME: not RTL compliant (lang::text_direction_rtl() ? ...) @@ -253,12 +253,22 @@ sub _gtk__HScale { if (!$w) { $opts->{adjustment} ||= do { - add2hash_($opts, { step_increment => 1, page_increment => 5, page_size => 1, value => delete $opts->{lower} }); + add2hash_($opts, { step_increment => 1, page_increment => 5, page_size => 1 }); + add2hash_($opts, { value => $opts->{lower} }) if !exists $opts->{value}; Gtk2::Adjustment->new(delete $opts->{value}, delete $opts->{lower}, (delete $opts->{upper}) + 1, delete $opts->{step_increment}, delete $opts->{page_increment}, delete $opts->{page_size}); }; $w = Gtk2::HScale->new(delete $opts->{adjustment}); } + $w->set_digits(delete $opts->{digits}) if exists $opts->{digits}; + if (my $value_ref = delete $opts->{value_ref}) { + my $set = sub { $w->set_value($$value_ref) }; + gtkval_register($w, $value_ref, $set); + $set->(); + $w->signal_connect(value_changed => sub { + gtkval_modify($value_ref, $w->get_value, $set); + }); + } $w->signal_connect(value_changed => delete $opts->{value_changed}) if exists $opts->{value_changed}; $w; } @@ -286,12 +296,11 @@ sub _gtk__HSeparator { &_gtk_any_simple } sub _gtk__Calendar { &_gtk_any_simple } sub _gtk__DrawingArea { - my ($w, $opts) = @_; + my ($w, $_opts) = @_; if (!$w) { $w = Gtk2::DrawingArea->new; } - $w->signal_connect(expose_event => delete $opts->{expose_event}) if exists $opts->{expose_event}; $w; } @@ -300,46 +309,74 @@ sub _gtk__Pixbuf { if (!$w) { my $name = delete $opts->{file} or internal_error("missing file"); - my $file = _find_imgfile($name) or internal_error("can not find image $name"); + my $file = _find_imgfile($name) or internal_error("cannot find image $name"); if (my $size = delete $opts->{size}) { $w = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($file, $size, $size, 1); } else { $w = Gtk2::Gdk::Pixbuf->new_from_file($file); } + $w = $w->flip(1) if delete $opts->{flip}; } $w; } # Image_using_pixmap is rendered using DITHER_MAX which is much better on 16bpp displays sub _gtk__Image_using_pixmap { &_gtk__Image } +# Image_using_pixbuf is rendered using DITHER_MAX & transparency which is much better on 16bpp displays +sub _gtk__Image_using_pixbuf { &_gtk__Image } sub _gtk__Image { my ($w, $opts, $class) = @_; if (!$w) { $w = Gtk2::Image->new; $w->{format} = delete $opts->{format} if exists $opts->{format}; + + $w->set_from_stock(delete $opts->{stock}, 'button') if exists $opts->{stock}; + + $w->{options} = { flip => delete $opts->{flip} }; $w->{set_from_file} = $class =~ /using_pixmap/ ? sub { my ($w, $file) = @_; my $pixmap = mygtk2::pixmap_from_pixbuf($w, gtknew('Pixbuf', file => $file)); $w->set_from_pixmap($pixmap, undef); + } : $class =~ /using_pixbuf/ ? sub { + my ($w, $file) = @_; + my $pixbuf = _pixbuf_render_alpha(gtknew('Pixbuf', file => $file, %{$w->{options}}), 255); + my ($width, $height) = ($pixbuf->get_width, $pixbuf->get_height); + $w->set_size_request($width, $height); + $w->{pixbuf} = $pixbuf; + $w->signal_connect(expose_event => sub { + my (undef, $event) = @_; + if (!$w->{x}) { + my $alloc = $w->allocation; + $w->{x} = $alloc->x; + $w->{y} = $alloc->y; + } + # workaround Gtk+ bug: in installer, first event is not complete and rectables are bogus: + if ($::isInstall) { + $pixbuf->render_to_drawable($w->window, $w->style->fg_gc('normal'), + 0, 0, $w->{x}, $w->{y}, $width, $height, 'max', 0, 0); + return; + } + foreach my $rect ($event->region->get_rectangles) { + my @values = $rect->values; + $pixbuf->render_to_drawable($w->window, $w->style->fg_gc('normal'), + @values[0..1], $w->{x}+$values[0], $w->{y}+$values[1], @values[2..3], 'max', 0, 0); + } + }); } : sub { my ($w, $file, $o_size) = @_; - if ($o_size) { - my $pixbuf = gtknew('Pixbuf', file => $file, size => $o_size); - $w->set_from_pixbuf($pixbuf); - } else { - $w->set_from_file($file); - } + my $pixbuf = gtknew('Pixbuf', file => $file, if_($o_size, size => $o_size), %{$w->{options}}); + $w->set_from_pixbuf($pixbuf); }; } if (my $name = delete $opts->{file}) { - my $file = _find_imgfile(may_apply($w->{format}, $name)) or internal_error("can not find image $name"); + my $file = _find_imgfile(may_apply($w->{format}, $name)) or internal_error("cannot find image $name"); $w->{set_from_file}->($w, $file, delete $opts->{size}); } elsif (my $file_ref = delete $opts->{file_ref}) { my $set = sub { - my $file = _find_imgfile(may_apply($w->{format}, $$file_ref)) or internal_error("can not find image $$file_ref"); + my $file = _find_imgfile(may_apply($w->{format}, $$file_ref)) or internal_error("cannot find image $$file_ref"); $w->{set_from_file}->($w, $file, delete $opts->{size}); }; gtkval_register($w, $file_ref, $set); @@ -351,10 +388,12 @@ sub _gtk__Image { sub _gtk__WrappedLabel { my ($w, $opts) = @_; - $opts->{line_wrap} = 1; + $opts->{line_wrap} = 1 if !defined $opts->{line_wrap}; _gtk__Label($w, $opts); } +our $left_padding = 20; + sub _gtk__Label_Left { my ($w, $opts) = @_; $opts->{alignment} ||= [ 0, 0 ]; @@ -376,6 +415,7 @@ sub _gtk__Label { $w->set_text(delete $opts->{text}) if exists $opts->{text}; } else { $w = exists $opts->{text} ? Gtk2::Label->new(delete $opts->{text}) : Gtk2::Label->new; + $w->set_selectable(delete $opts->{selectable}) if exists $opts->{selectable}; $w->set_ellipsize(delete $opts->{ellipsize}) if exists $opts->{ellipsize}; $w->set_justify(delete $opts->{justify}) if exists $opts->{justify}; $w->set_line_wrap(delete $opts->{line_wrap}) if exists $opts->{line_wrap}; @@ -401,7 +441,7 @@ sub _gtk__Label { sub _gtk__Alignment { - my ($w, $opts) = @_; + my ($w, $_opts) = @_; if (!$w) { $w = Gtk2::Alignment->new(0, 0, 0, 0); @@ -412,13 +452,22 @@ sub _gtk__Alignment { sub title1_to_markup { my ($label) = @_; - $::isInstall ? '<span foreground="#5A8AD6">' . $label . '</span>' - : '<b><big>' . $label . '</big></b>'; + if ($::isInstall) { + my $font = lang::l2pango_font($::o->{locale}{lang}); + if (my ($font_size) = $font =~ /(\d+)/) { + $font_size++; + $font =~ s/\d+/$font_size/; + } + qq(<span foreground="#5A8AD6" font="$font">$label</span>); + } else { + qq(<b><big>$label</big></b>); + } } sub _gtk__Install_Title { my ($w, $opts) = @_; local $opts->{widget_name} = 'Banner'; + $opts->{text} = uc($opts->{text}) if $::isInstall; gtknew('HBox', widget_name => 'Banner', children => [ 0, gtknew('Label', padding => [ 6, 0 ]), 1, gtknew('VBox', widget_name => 'Banner', children_tight => [ @@ -458,7 +507,7 @@ sub _gtk__Sexy_IconEntry { $w->set_icon_highlight('primary', $icon); } if (my $icon = delete $opts->{secondary_icon}) { - $w->set_icon('secondary',i $icon); + $w->set_icon('secondary', $icon); $w->set_icon_highlight('secondary', $icon); } @@ -476,6 +525,18 @@ sub _gtk__Entry { $w->set_editable(delete $opts->{editable}) if exists $opts->{editable}; } + if (my $icon = delete $opts->{primary_icon}) { + $w->set_icon_from_stock('primary', $icon); + #$w->set_icon_highlight('primary', $icon); + } + if (my $icon = delete $opts->{secondary_icon}) { + $w->set_icon_from_stock('secondary', $icon); + #$w->set_icon_highlight('secondary', $icon); + } + + $w->signal_connect('icon-release' => delete $opts->{'icon-release'}) if exists $opts->{'icon-release'}; + $w->signal_connect('icon-press' => delete $opts->{'icon-press'}) if exists $opts->{'icon-press'}; + $w->set_text(delete $opts->{text}) if exists $opts->{text}; $w->signal_connect(key_press_event => delete $opts->{key_press_event}) if exists $opts->{key_press_event}; @@ -483,11 +544,31 @@ sub _gtk__Entry { my $set = sub { $w->set_text($$text_ref) }; gtkval_register($w, $text_ref, $set); $set->(); + $w->signal_connect(changed => sub { + gtkval_modify($text_ref, $w->get_text, $set); + }); } $w; } +sub _gtk__WeaknessCheckEntry { + my ($w, $opts) = @_; + + if (!$w) { + $w = _gtk__Entry($w, $opts); + } + + $w->signal_connect('changed' => sub { + require authentication; + my $password_weakness = authentication::compute_password_weakness($w->get_text); + $w->set_icon_from_pixbuf('GTK_ENTRY_ICON_SECONDARY', _get_weakness_icon($password_weakness)); + $w->set_icon_tooltip_text('GTK_ENTRY_ICON_SECONDARY', _get_weakness_tooltip($password_weakness)); + }); + + $w; +} + sub _gtk__TextView { my ($w, $opts, $_class, $action) = @_; @@ -502,6 +583,24 @@ sub _gtk__TextView { $w; } +sub _gtk__WebKit_View { + my ($w, $opts, $_class, $_action) = @_; + if (!$w) { + $w = Gtk2::WebKit::WebView->new; + } + + # disable contextual menu: + if (delete $opts->{no_popup_menu}) { + $w->signal_connect('populate-popup' => sub { + my (undef, $menu) = @_; + $menu->destroy if $menu; + 1; + }); + } + + $w; +} + sub _gtk__ComboBox { my ($w, $opts, $_class, $action) = @_; @@ -561,13 +660,13 @@ sub _gtk__ScrolledWindow { my $faked_w = $w; if (my $child = delete $opts->{child}) { - if (member(ref($child), qw(Gtk2::Layout Gtk2::Html2::View Gtk2::SimpleList Gtk2::SourceView::View Gtk2::Text Gtk2::TextView Gtk2::TreeView))) { + if (member(ref($child), qw(Gtk2::Layout Gtk2::Html2::View Gtk2::SimpleList Gtk2::SourceView::View Gtk2::Text Gtk2::TextView Gtk2::TreeView Gtk2::WebKit::WebView))) { $w->add($child); } else { $w->add_with_viewport($child); } $child->set_focus_vadjustment($w->get_vadjustment) if $child->can('set_focus_vadjustment'); - $child->set_left_margin(6) if ref($child) =~ /Gtk2::TextView/ && $child->get_left_margin() <= 6; + $child->set_left_margin(6) if ref($child) =~ /Gtk2::TextView/ && $child->get_left_margin <= 6; $child->show; $w->child->set_shadow_type(delete $opts->{shadow_type}) if exists $opts->{shadow_type}; @@ -576,7 +675,7 @@ sub _gtk__ScrolledWindow { $child->{to_bottom} = _allow_scroll_TextView_to_bottom($w, $child); } - if ($action eq 'gtknew' && ref($child) =~ /Gtk2::SimpleList|Gtk2::Html2|Gtk2::TextView|Gtk2::TreeView/) { + if (!delete $opts->{no_shadow} && $action eq 'gtknew' && ref($child) =~ /Gtk2::(Html2|SimpleList|TextView|TreeView|WebKit::WebView)/) { $faked_w = gtknew('Frame', shadow_type => 'in', child => $w); } } @@ -619,22 +718,113 @@ sub _gtk__Expander { $w; } + + +sub _gtk__MDV_Notebook { + my ($w, $opts, $_class, $_action) = @_; + if (!$w) { + import_style_ressources(); + + my ($layout, $selection_arrow, $selection_bar); + my $parent_window = delete $opts->{parent_window} || root_window(); + my $root_height = first($parent_window->get_size); + my $suffix = $root_height == 800 && !$::isStandalone ? '_600' : '_768'; + # the white square is a little bit above the actual left sidepanel: + my $offset = 20; + my $is_flip_needed = text_direction_rtl(); + my $filler = gtknew('Image', file => 'left-background-filler.png'); + my $filler_height = $filler->get_pixbuf->get_height; + my $left_background = gtknew('Image_using_pixbuf', file => 'left-background.png'); + my $lf_height = $left_background->{pixbuf}->get_height; + my @right_background = $::isInstall ? + gtknew('Image', file => "right-white-background_left_part$suffix", flip => $is_flip_needed) + : map { + gtknew('Image', file => "right-white-background_left_part-$_", flip => $is_flip_needed); + } 1, 2, 2, 3; + my $width1 = $left_background->{pixbuf}->get_width; + my $total_width = $width1 + $right_background[0]->get_pixbuf->get_width; + my $arrow_x = text_direction_rtl() ? $offset/2 - 4 : $width1 - $offset - 3; + $w = gtknew('HBox', spacing => 0, children => [ + 0, $layout = gtknew('Layout', width => $total_width - $offset, children => [ #Layout Fixed + # stacking order is important for "Z-buffer": + [ $left_background, 0, 0 ], + if_($suffix ne '_600', + [ $filler, 0, $lf_height ], + [ gtknew('Image', file => 'left-background-filler.png'), 0, $lf_height + $filler_height ], + [ gtknew('Image', file => 'left-background-filler.png'), 0, $lf_height + $filler_height*2 ], + ), + [ $selection_bar = gtknew('Image', file => 'rollover.png'), 0, 0 ], # arbitrary vertical position + ($opts->{children} ? @{ delete $opts->{children} } : ()), + [ my $box = gtknew('VBox', spacing => 0, height => -1, children => [ + 0, $right_background[0], + if_(!$::isInstall, + 1, $right_background[1], + 1, $right_background[2], # enought up to to XYZx1280 resolution + 0, $right_background[3], + ), + ]), (text_direction_rtl() ? 0 : $width1 - $offset), 0 ], + # stack on top (vertical position is arbitrary): + [ $selection_arrow = gtknew('Image', file => 'steps_on', flip => $is_flip_needed), $arrow_x, 0, ], + ]), + 1, delete $opts->{right_child} || + gtknew('Image_using_pixbuf', file => "right-white-background_right_part$suffix", flip => $is_flip_needed), + ]); + + $w->signal_connect('size-allocate' => sub { + my (undef, $requisition) = @_; + state $width ||= $right_background[0]->get_pixbuf->get_width; + $box->set_size_request($width, $requisition->height); + }); + $_->set_property('no-show-all', 1) foreach $selection_bar, $selection_arrow; + bless($w, 'Gtk2::MDV_Notebook'); + add2hash($w, { + arrow_x => $arrow_x, + layout => $layout, + selection_arrow => $selection_arrow, + selection_bar =>$selection_bar, + }); + } + $w; +} + + sub _gtk__Fixed { - my ($w, $opts, $_class, $action) = @_; + my ($w, $opts, $_class, $_action) = @_; if (!$w) { $w = Gtk2::Fixed->new; $w->set_has_window(delete $opts->{has_window}) if exists $opts->{has_window}; - $w->put(delete $opts->{child}, delete $opts->{x}, delete $opts->{y}) if exists $opts->{child}; + _gtknew_handle_layout_children($w, $opts); + } + $w; +} + +sub _gtk__Layout { + my ($w, $opts, $_class, $_action) = @_; + + if (!$w) { + $w = Gtk2::Layout->new; + _gtknew_handle_layout_children($w, $opts); + } + $w; +} + +sub _gtknew_handle_layout_children { + my ($w, $opts) = @_; + $opts->{children} ||= []; + push @{$opts->{children}}, [ delete $opts->{child}, delete $opts->{x}, delete $opts->{y} ] if exists $opts->{child}; + foreach (@{$opts->{children}}) { + $w->put(@$_); + } + delete $opts->{children}; + if ($opts->{pixbuf_file}) { - my $pixbuf = gtknew('Pixbuf', file => delete $opts->{pixbuf_file}) if $opts->{pixbuf_file}; + my $pixbuf = if_($opts->{pixbuf_file}, gtknew('Pixbuf', file => delete $opts->{pixbuf_file})); $w->signal_connect( realize => sub { ugtk2::set_back_pixbuf($w, $pixbuf); }); } - } - $w; } @@ -648,13 +838,20 @@ sub _gtk_any_Window { if ($class eq 'Window') { $w = "Gtk2::$class"->new(delete $opts->{type} || 'toplevel'); } elsif ($class eq 'Plug') { - $opts->{socket_id} or internal_error("can not create a Plug without a socket_id"); + $opts->{socket_id} or internal_error("cannot create a Plug without a socket_id"); $w = "Gtk2::$class"->new(delete $opts->{socket_id}); + } elsif ($class eq 'FileChooserDialog') { + my $action = delete $opts->{action} || internal_error("missing action for FileChooser"); + $w = Gtk2::FileChooserDialog->new(delete $opts->{title}, delete $opts->{transient_for} || $::main_window, + $action, N("Cancel") => 'cancel', delete $opts->{button1} || N("Ok") => 'ok', + ); } else { $w = "Gtk2::$class"->new; } - $w->set_type_hint('dialog'); # for matchbox window manager + if ($::isInstall || $::set_dialog_hint) { + $w->set_type_hint('dialog'); # for matchbox window manager + } $w->set_modal(delete $opts->{modal}) if exists $opts->{modal}; $opts->{transient_for} ||= $::main_window if $::main_window; @@ -669,7 +866,7 @@ sub _gtk_any_Window { if (my $f = _find_imgfile($name)) { $w->set_icon(gtknew('Pixbuf', file => $f)); } elsif (!$icon_no_error) { - internal_error("can not find $name"); + internal_error("cannot find $name"); } } } @@ -722,7 +919,7 @@ sub _gtk__MagicWindow { } elsif ($pop_it) { $opts->{child} = $sub_child; - $w = _create_Window($opts, pop_and_reuse => $pop_and_reuse); + $w = _create_Window($opts, ''); $previous_popped_and_reuse_window = $w if $pop_and_reuse; } else { if (!$::WizardWindow) { @@ -749,7 +946,7 @@ sub _gtk__MagicWindow { add2hash($opts, { child => $::WizardTable, }); - $::WizardWindow = _create_Window($opts); + $::WizardWindow = _create_Window($opts, 'special_center'); } } else { %$opts = (); @@ -823,6 +1020,8 @@ sub _gtk__FileSelection { $w; } +sub _gtk__FileChooserDialog { &_gtk_any_Window } + sub _gtk__FileChooser { my ($w, $opts) = @_; @@ -875,7 +1074,7 @@ sub _gtk_any_Box { my ($w, $opts, $class, $action) = @_; if (!$w) { - $w = "Gtk2::$class"->new(0,0); + $w = "Gtk2::$class"->new; $w->set_homogeneous(delete $opts->{homogenous}) if exists $opts->{homogenous}; $w->set_spacing(delete $opts->{spacing}) if exists $opts->{spacing}; $w->set_border_width(delete $opts->{border_width}) if exists $opts->{border_width}; @@ -945,11 +1144,11 @@ sub _gtk__Table { my $j = $::i; if ($_) { ref $_ or $_ = Gtk2::WrappedLabel->new($_); - $j != $#$l && !$w->{mcc} ? - $w->attach($_, $j, $j + 1, $i, $i + 1, - 'fill', 'fill', $w->{xpadding}, $w->{ypadding}) : - $w->attach($_, $j, $j + 1, $i, $i + 1, - ['expand', 'fill'], ref($_) eq 'Gtk2::ScrolledWindow' || $_->get_data('must_grow') ? ['expand', 'fill'] : [], 0, 0); + $w->attach($_, $j, $j + 1, $i, $i + 1, + $j != $#$l && !$w->{mcc} ? + ('fill', 'fill', $w->{xpadding}, $w->{ypadding}) : + (['expand', 'fill'], ref($_) eq 'Gtk2::ScrolledWindow' || $_->get_data('must_grow') ? + ['expand', 'fill'] : [], 0, 0)); $_->show; } } @$l; @@ -978,7 +1177,7 @@ sub _gtknew_handle_children { foreach (@child) { my ($fill, $child) = @$_; - $fill eq '0' || $fill eq '1' || $fill eq 'fill' || $fill eq 'expand' or internal_error("odd {children} parameter must be 0 or 1 (got $fill)"); + member($fill, qw(0 1 fill expand)) or internal_error("odd {children} parameter must be 0 or 1 (got $fill)"); ref $child or $child = Gtk2::WrappedLabel->new($child); my $expand = $fill && $fill ne 'fill' ? 1 : 0; $w->pack_start($child, $expand, $fill, $padding || 0); @@ -999,7 +1198,7 @@ sub mygtk2::MagicWindow::AUTOLOAD { my ($s1, @s2) = $meth eq 'show' ? ('real_window', 'banner', 'child') : - $meth eq 'destroy' || $meth eq 'hide' ? + member($meth, qw(destroy hide)) ? ($w->{pop_it} ? 'real_window' : ('child', 'banner')) : $meth eq 'get' && $args[0] eq 'window-position' || $for_real_window{$meth} || @@ -1013,8 +1212,45 @@ sub mygtk2::MagicWindow::AUTOLOAD { $w->{$s1}->$meth(@args); } +my $enable_quit_popup; +sub enable_quit_popup { + my ($bool) = @_; + $enable_quit_popup = $bool; +} + +state $in_callback; +sub quit_popup() { + return if !$enable_quit_popup; + if (!$in_callback) { + $in_callback = 1; + my $_guard = before_leaving { undef $in_callback }; + require ugtk2; + my $w = ugtk2->new(N("Confirmation"), grab => 1); + ugtk2::_ask_okcancel($w, N("Are you sure you want to quit?"), N("Quit"), N("Cancel")); + my $ret = ugtk2::main($w); + return 1 if !$ret; + } +} + +sub quit_callback { + my ($w) = @_; + + return 1 if quit_popup(); + if ($::isWizard) { + $w->destroy; + die 'wizcancel'; + } else { + if (Gtk2->main_level) { + Gtk2->main_quit; + } else { + # block window deletion if not in main loop (eg: while starting the GUI) + return 1; + } + } +} + sub _create_Window { - my ($opts) = @_; + my ($opts, $special_center) = @_; my $no_Window_Manager = exists $opts->{no_Window_Manager} ? delete $opts->{no_Window_Manager} : !$::isStandalone; @@ -1022,9 +1258,8 @@ sub _create_Window { if_(!$::isInstall && !$::isWizard, border_width => 5), #- policy: during install, we need a special code to handle the weird centering, see below - position_policy => $::isInstall ? - ($opts->{modal} ? 'center-always' : 'none') : - $no_Window_Manager ? 'center-always' : 'center-on-parent', + position_policy => $special_center ? 'none' : + $no_Window_Manager ? 'center-always' : 'center-on-parent', if_($::isInstall, position => [ $::stepswidth + ($::o->{windowwidth} - $::real_windowwidth) / 2, @@ -1034,25 +1269,9 @@ sub _create_Window { my $w = _gtk(undef, 'Window', 'gtknew', $opts); #- when the window is closed using the window manager "X" button (or alt-f4) - $w->signal_connect(delete_event => sub { - if ($::isWizard) { - $w->destroy; - die 'wizcancel'; - } else { - if (Gtk2->main_level) { - Gtk2->main_quit; - } else { - # block window deletion if not in main loop (eg: while starting the GUI) - return 1; - } - } - }); - - if ($no_Window_Manager) { - _force_keyboard_focus($w); - } + $w->signal_connect(delete_event => \&quit_callback); - if ($::isInstall) { + if ($::isInstall && !$::isStandalone) { require install::gtk; #- for perl_checker install::gtk::handle_unsafe_mouse($::o, $w); $w->signal_connect(key_press_event => \&install::gtk::special_shortcuts); @@ -1072,29 +1291,12 @@ sub _create_Window { $w->move(max(0, $::rootwidth - ($::o->{windowwidth} + $wi) / 2), max(0, ($::o->{windowheight} - $he) / 2)); - }); + }) if $special_center; } - $w; -} - -my $current_window; -sub _force_keyboard_focus { - my ($w) = @_; + $w->present if $no_Window_Manager; - sub _XSetInputFocus { - my ($w) = @_; - if ($current_window == $w) { - $w->window->XSetInputFocus; - } - 0; - } - - #- force keyboard focus instead of mouse focus - my $previous_current_window = $current_window; - $current_window = $w; - $w->signal_connect(expose_event => \&_XSetInputFocus); - $w->signal_connect(destroy => sub { $current_window = $previous_current_window }); + $w; } sub _find_imgfile { @@ -1153,11 +1355,11 @@ sub _text_insert { foreach my $token (@$t) { my ($item, $tag) = @$token; my $iter1 = $buffer->get_end_iter; - if ($item =~ /^Gtk2::Gdk::Pixbuf/) { + if (ref($item) =~ /^Gtk2::Gdk::Pixbuf/) { $buffer->insert_pixbuf($iter1, $item); next; } - if ($item =~ /^Gtk2::/) { + if (ref($item) =~ /^Gtk2::/) { my $anchor = $buffer->create_child_anchor($iter1); $textview->add_child_at_anchor($item, $anchor); $textview->{anchors} ||= []; @@ -1218,14 +1420,12 @@ sub asteriskize { } sub get_main_window_size() { - my ($width, $height) = $::real_windowwidth ? ($::real_windowwidth, $::real_windowheight) : $::isWizard ? (540, 360) : (600, 400); + $::real_windowwidth ? ($::real_windowwidth, $::real_windowheight) : $::isWizard ? (540, 360) : (600, 400); } -our $left_padding = 20; - # in order to workaround infamous 6 years old gnome bug #101968: sub get_label_width() { - first(mygtk2::get_main_window_size()) - 50 - $left_padding; + first(mygtk2::get_main_window_size()) - 55 - $left_padding; } sub set_main_window_size { @@ -1261,6 +1461,23 @@ sub flush() { Gtk2->main_iteration while Gtk2->events_pending; } +sub enable_sync_flush { + my ($w) = @_; + $w->signal_connect(expose_event => sub { $w->{displayed} = 1; 0 }); +} + +sub sync_flush { + my ($w) = @_; + # hackish :-( + mygtk2::sync($w) while !$w->{displayed}; +} + + +sub register_main_window { + my ($w) = @_; + push @::main_windows, $::main_window = $w; +} + sub may_destroy { my ($w) = @_; return if !$w; @@ -1301,6 +1518,21 @@ sub set_root_window_background_with_gc { $root->draw_rectangle($gc, 1, 0, 0, $w, $h); } +sub _new_alpha_pixbuf { + my ($pixbuf) = @_; + my ($height, $width) = ($pixbuf->get_height, $pixbuf->get_width); + my $new_pixbuf = Gtk2::Gdk::Pixbuf->new('rgb', 1, 8, $width, $height); + $new_pixbuf->fill(0x00000000); # transparent white + $width, $height, $new_pixbuf; +} + +sub _pixbuf_render_alpha { + my ($pixbuf, $alpha_threshold) = @_; + my ($width, $height, $new_pixbuf) = _new_alpha_pixbuf($pixbuf); + $pixbuf->composite($new_pixbuf, 0, 0, $width, $height, 0, 0, 1, 1, 'bilinear', $alpha_threshold); + $new_pixbuf; +} + sub pixmap_from_pixbuf { my ($widget, $pixbuf) = @_; my $window = $widget->window or internal_error("you can't use this function if the widget is not realised"); @@ -1310,4 +1542,57 @@ sub pixmap_from_pixbuf { $pixmap; } +sub import_style_ressources() { + if (!$::isInstall) { + Gtk2::Rc->parse_string(scalar cat_('/usr/share/libDrakX/themes-galaxy.rc')); # FIXME DEBUG + } +} + +sub text_direction_rtl() { + Gtk2::Widget->get_default_direction eq 'rtl'; +} + +sub _get_weakness_icon { + my ($password_weakness) = @_; + my %weakness_icon = ( + 1 => gtknew('Pixbuf', file => 'security-low'), + 2 => gtknew('Pixbuf', file => 'security-low'), + 3 => gtknew('Pixbuf', file => 'security-medium'), + 4 => gtknew('Pixbuf', file => 'security-strong'), + 5 => gtknew('Pixbuf', file => 'security-strong')); + my $weakness_icon = $weakness_icon{$password_weakness} || return undef; + $weakness_icon; +} + +sub _get_weakness_tooltip { + my ($password_weakness) = @_; + my %weakness_tooltip = ( + 1 => N("Password is trivial to guess"), + 2 => N("Password is trivial to guess"), + 3 => N("Password should be resistant to basic attacks"), + 4 => N("Password seems secure"), + 5 => N("Password seems secure")); + my $weakness_tooltip = $weakness_tooltip{$password_weakness} || return undef; + return $weakness_tooltip; +} + +package Gtk2::MDV_Notebook; # helper functions for installer & mcc +our @ISA = qw(Gtk2::Widget); + +sub hide_selection { + my ($w) = @_; + $_->hide foreach $w->{selection_bar}, $w->{selection_arrow}; +} + +sub move_selection { + my ($w, $label) = @_; + my $layout = $w->{layout}; + $layout->{arrow_ydiff} ||= + ($w->{selection_arrow}->get_pixbuf->get_height - $w->{selection_bar}->get_pixbuf->get_height)/2; + my $bar_y = $label->allocation->y - ($w->{selection_bar}->get_pixbuf->get_height - $label->allocation->height)/2; + $layout->move($w->{selection_bar}, 0, $bar_y); + $layout->move($w->{selection_arrow}, $w->{arrow_x}, $bar_y - $layout->{arrow_ydiff}); # arrow is higer + $_->show foreach $w->{selection_bar}, $w->{selection_arrow}; +} + 1; |
