package my_gtk; # $Id$ use diagnostics; use strict; use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $border); @ISA = qw(Exporter); %EXPORT_TAGS = ( helpers => [ qw(create_okcancel createScrolledWindow create_menu create_notebook create_packtable create_hbox create_vbox create_adjustment create_box_with_title create_treeitem) ], wrappers => [ qw(gtksignal_connect gtkradio gtkpack gtkpack_ gtkpack__ gtkpack2 gtkpack3 gtkpack2_ gtkpack2__ gtkpowerpack gtkset_editable gtksetstyle gtkset_tip gtkappenditems gtkappend gtkset_shadow_type gtkset_layout gtkset_relief gtkadd gtkput gtktext_insert gtkset_usize gtksize gtkset_justify gtkset_active gtkset_sensitive gtkset_visibility gtkset_modal gtkset_border_width gtkmove gtkresize gtkshow gtkhide gtkdestroy gtkcolor gtkset_mousecursor gtkset_mousecursor_normal gtkset_mousecursor_wait gtkset_background gtkset_default_fontset gtkctree_children gtkxpm gtkpng create_pix_text get_text_coord fill_tiled gtkicons_labels_widget write_on_pixmap gtkcreate_xpm gtkcreate_png gtkbuttonset create_pixbutton gtkroot gtkentry) ], ask => [ qw(ask_warn ask_okcancel ask_yesorno ask_from_entry ask_browse_tree_info ask_browse_tree_info_given_widgets ask_dir) ], various => [ qw (add_icon_path) ], ); $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ]; @EXPORT_OK = map { @$_ } values %EXPORT_TAGS; use ugtk qw(:helpers :wrappers :various); use common; use log; add_icon_path(@icon_paths, "$ENV{SHARE_PATH}/libDrakX/pixmaps", '/usr/lib/libDrakX/icons', 'standalone/icons'); my $forgetTime = 1000; #- in milli-seconds $border = 5; #-############################################################################### #- OO stuff #-############################################################################### sub new { my ($type, $title, %opts) = @_; Gtk->set_locale; my $o = bless { %opts }, $type; $o->_create_window($title); while (my $e = shift @tempory::objects) { $e->destroy } foreach (@interactive::objects) { $_->{rwindow}->set_modal(0) if $_->{rwindow}->can('set_modal'); } push @interactive::objects, $o if !$opts{no_interactive_objects}; $o->{rwindow}->set_position('center_always') if $::isStandalone; $o->{rwindow}->set_modal(1) if $my_gtk::grab || $o->{grab}; if ($::isWizard && !$my_gtk::pop_it) { $o->{isWizard} = 1; $o->{window} = new Gtk::VBox(0,0); $o->{window}->set_border_width($::Wizard_splash ? 0 : 10); $o->{rwindow} = $o->{window}; if (!defined($::WizardWindow)) { $::WizardWindow = new Gtk::Window; $::WizardWindow->set_position('center_always'); $::WizardWindow->signal_connect(delete_event => sub { die 'wizcancel' }); $::WizardTable = new Gtk::Table(2, 2, 0); $::WizardWindow->add($::WizardTable); my $draw1 = new Gtk::DrawingArea; $draw1->set_usize(540,100); my $draw2 = new Gtk::DrawingArea; $draw2->set_usize(100,300); my ($im_up, $mask_up) = gtkcreate_png($::Wizard_pix_up || "wiz_default_up.png"); my ($y1, $x1) = $im_up->get_size; my ($im_left, $mask_left) = gtkcreate_png($::Wizard_pix_left || "wiz_default_left.png"); my ($y2, $x2) = $im_left->get_size; my $style = $draw1->style->copy(); $style->font(Gtk::Gdk::Font->fontset_load(_("-adobe-utopia-regular-r-*-*-25-*-*-*-p-*-iso8859-*,*-r-*"))); my $w = $style->font->string_width($::Wizard_title); $draw1->signal_connect(expose_event => sub { for (my $i = 0; $i < (540/$y1); $i++) { $draw1->window->draw_pixmap ($draw1->style->bg_gc('normal'), $im_up, 0, 0, 0, $y1*$i, $x1 , $y1); $draw1->window->draw_string( $style->font, $draw1->style->white_gc, 40, 62, ($::Wizard_title) ); } }); $draw2->signal_connect(expose_event => sub { for (my $i = 0; $i < (300/$y2); $i++) { $draw2->window->draw_pixmap ($draw2->style->bg_gc('normal'), $im_left, 0, 0, 0, $y2*$i, $x2 , $y2); } }); $::WizardTable->attach($draw1, 0, 2, 0, 1, 'fill', 'fill', 0, 0); #- $::WizardTable->attach($draw2, 0, 1, 1, 2, 'fill', 'fill', 0, 0); $::WizardTable->set_usize(540,420); $::WizardWindow->show_all; flush(); } $::WizardTable->attach($o->{window}, 0, 2, 1, 2, [-fill, -expand], [-fill, -expand], 0, 0); } if ($::isEmbedded && !$my_gtk::pop_it && !eval { $::Plug && $::Plug->child }) { $o->{isEmbedded} = 1; $o->{window} = new Gtk::HBox(0,0); $o->{rwindow} = $o->{window}; $::Plug ||= new Gtk::Plug ($::XID); $::Plug->show; flush(); $::Plug->add($o->{window}); } $::CCPID and kill 'USR2', $::CCPID; $o; } sub main { my ($o, $completed, $canceled) = @_; gtkset_mousecursor_normal(); my $timeout = Gtk->timeout_add(1000, sub { gtkset_mousecursor_normal(); 1 }); my $b = MDK::Common::Func::before_leaving { Gtk->timeout_remove($timeout) }; $o->show; do { local $::setstep = 1; Gtk->main; } while ($o->{retval} ? $completed && !$completed->() : $canceled && !$canceled->()); $o->destroy; $o->{retval} } sub show($) { my ($o) = @_; $o->{window}->show; $o->{rwindow}->show; } sub destroy($) { my ($o) = @_; $o->{rwindow} and $o->{rwindow}->destroy; gtkset_mousecursor_wait(); flush(); } sub DESTROY { goto &destroy } sub sync { my ($o) = @_; show($o); flush(); } sub flush { gtkflush() } sub exit { gtkset_mousecursor_normal(); #- for restoring a normal in any case flush(); $::isEmbedded and kill 'USR1', $::CCPID; c::_exit($_[1]) #- workaround } #- in case "exit" above was not called by the program END { &exit() } #-############################################################################### #- createXXX functions #- these functions return a widget #-############################################################################### sub create_okcancel { my ($w, $ok, $cancel, $spread, @other) = @_; $spread ||= $::isWizard ? "end" : "spread"; $cancel = $::isWizard ? _("<- Previous") : _("Cancel") if !defined $cancel && !defined $ok; $ok = $::isWizard ? ($::Wizard_finished ? _("Finish") : _("Next ->")) : _("Ok") if !defined $ok; my $b1 = gtksignal_connect($w->{ok} = new Gtk::Button($ok), clicked => $w->{ok_clicked} || sub { $w->{retval} = 1; Gtk->main_quit }); my $b2 = $cancel && gtksignal_connect($w->{cancel} = new Gtk::Button($cancel), clicked => $w->{cancel_clicked} || sub { log::l("default cancel_clicked"); undef $w->{retval}; Gtk->main_quit }); $::isWizard and gtksignal_connect($w->{wizcancel} = new Gtk::Button(_("Cancel")), clicked => sub { die 'wizcancel' }); my @l = grep { $_ } $::isWizard ? ($w->{wizcancel}, $::Wizard_no_previous ? () : $b2, $b1): ($b1, $b2); push @l, map { gtksignal_connect(new Gtk::Button($_->[0]), clicked => $_->[1]) } @other; $_->can_default($::isWizard) foreach @l; gtkadd(create_hbox($spread), @l); } sub _create_window($$) { my ($o, $title) = @_; my $w = new Gtk::Window; my $gc = Gtk::Gdk::GC->new(gtkroot()); !$::isStandalone && !$::live && !$::g_auto_install and $my_gtk::shape_width = 3; #- $gc->set_foreground(gtkcolor(8448, 17664, 40191)); #- in hex : 33, 69, 157 $gc->set_foreground(gtkcolor(5120, 10752, 22784)); #- in hex : 20, 42, 89 #- $gc->set_foreground(gtkcolor(16896, 16896, 16896)); #- in hex : 66, 66, 66 my $inner = gtkadd(my $f_ = gtkset_shadow_type(new Gtk::Frame(undef), 'out'), my $f = gtkset_border_width(gtkset_shadow_type(new Gtk::Frame(undef), 'none'), 3) ); my $table; if ($::isStandalone || $::live || $::g_auto_install || $::noShadow) { gtkadd($w, $inner) if !$::noBorder } else { my $sqw = $my_gtk::shape_width; gtkadd($w, $table = new Gtk::Table(2, 2, 0)); $table->attach($inner, 0, 1, 0, 1, 1|4, 1|4, 0, 0); $table->attach(gtksignal_connect(gtkset_usize(new Gtk::DrawingArea, $sqw, 1), expose_event => sub { $_[0]->window->draw_rectangle($_[0]->style->bg_gc('normal'), 1, 0, 0, $sqw, $sqw); $_[0]->window->draw_rectangle($gc, 1, 0, $sqw, $sqw, $_[0]->allocation->[3]); }), 1, 2, 0, 1, 'fill', 'fill', 0, 0); $table->attach(gtksignal_connect(gtkset_usize(new Gtk::DrawingArea, 1, $sqw), expose_event => sub { $_[0]->window->draw_rectangle($_[0]->style->bg_gc('normal'), 1, 0, 0, $sqw, $sqw); $_[0]->window->draw_rectangle($gc, 1, $sqw, 0, $_[0]->allocation->[2], $sqw); }), 0, 1, 1, 2, 'fill', 'fill', 0, 0); $table->attach(gtksignal_connect(gtkset_usize(new Gtk::DrawingArea, $sqw, $sqw), expose_event => sub { $_[0]->window->draw_rectangle($gc, 1, 0, 0, $sqw, $sqw); }), 1, 2, 1, 2, 'fill', 'fill', 0, 0); $table->show_all; } $w->set_name("Title"); $w->set_title($title); $w->signal_connect(expose_event => sub { eval { $interactive::objects[-1]{rwindow} == $w and $w->window->XSetInputFocus } }) if $my_gtk::force_focus || $o->{force_focus}; $w->signal_connect(delete_event => sub { if ($::isWizard) { $w->destroy; die 'wizcancel' } else { Gtk->main_quit } }); $w->set_uposition(@{$my_gtk::force_position || $o->{force_position}}) if $my_gtk::force_position || $o->{force_position}; my $focusing; $w->signal_connect(focus => sub { return 1 if $focusing; $focusing = 1; Gtk->idle_add(sub { $w->ensure_focus($_[0]); $focusing = 0; 0 }, $_[1]); }) if $w->can('ensure_focus'); if ($::o->{mouse}{unsafe}) { $w->set_events("pointer_motion_mask"); my $signal; $signal = $w->signal_connect(motion_notify_event => sub { delete $::o->{mouse}{unsafe}; log::l("unsetting unsafe mouse"); $w->signal_disconnect($signal); }); } $w->signal_connect(key_press_event => sub { my $d = ${{ 0xffbe => 'help', 0xffbf => 'screenshot', 0xffc2 => 'set_theme', 0xffc9 => 'next', 0xffc8 => 'previous' }}{$_[1]{keyval}}; if ($d eq "help") { require install_gtk; install_gtk::create_big_help($::o); } elsif ($::isInstall && $d eq 'screenshot') { common::take_screenshot($o); } elsif ($::isInstall && $d eq 'set_ $l1 = Gtk2::Label->new($ARGV[0]); my $v = Gtk2::VBox->new(1, 0); $v->pack_start($l1, 0, 0, 0); my $window = Gtk2::Window->new('toplevel'); $window->set_size_request(200, 50); $window->set_position('center'); $window->signal_connect(key_press_event => sub { Gtk2->main_quit }); $window->add($v); $window->show_all; install_gtk::load_font({ locale => { lang => $ENV{LANGUAGE} } }); $l2 = Gtk2::Label->new(translate($ARGV[0])); $v->pack_start($l2, 0, 0, 0); $window->show_all; Gtk2->main;