App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Gtk2/Ex/ToplevelBits.pm view on Meta::CPAN
# This file is part of Chart.
#
# Chart is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# Chart is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Chart. If not, see <http://www.gnu.org/licenses/>.
package App::Chart::Gtk2::Ex::ToplevelBits;
use 5.008;
use strict;
use warnings;
use Carp;
use List::Util;
use App::Chart::Gtk2::Ex::ToplevelSingleton;
# uncomment this to run the ### lines
#use Smart::Comments;
# screen
# parent
# with_properties
# init_properties
# modal
# hide_on_delete
sub popup {
my ($class, %options) = @_;
### ToplevelBits popup(): $class
my $properties = $options{'properties'} || {};
my $screen = _screen
($options{'transient_for'} || $options{'parent'} || $options{'screen'});
my $dialog = List::Util::first
{$_->isa($class)
&& (! defined $screen || $_->get_screen == $screen)
&& _object_properties_equal($_,$properties)}
Gtk2::Window->list_toplevels;
### ToplevelBits found: $dialog
if ($dialog) {
if (exists $options{'modal'}) {
$dialog->set_modal ($options{'modal'});
}
if (exists $options{'transient_for'}) {
$dialog->set_transient_for ($options{'transient_for'});
}
} else {
### new dialog $class
if (eval { require Gtk2::Ex::WidgetCursor }) {
Gtk2::Ex::WidgetCursor->busy;
}
require Module::Load;
Module::Load::load ($class);
$dialog = $class->Glib::Object::new
((defined $screen ? (screen => $screen) : ()),
(exists $options{'modal'} ? (modal => $options{'modal'}) : ()),
(exists $options{'transient_for'} ? (transient_for => $options{'transient_for'}) : ()),
%$properties);
if ($options{'hide_on_delete'}) {
$dialog->signal_connect (delete_event => \&Gtk2::Widget::hide_on_delete);
}
}
# if (! $dialog->visible) {
# if (my $func = $options{'newly_visible_func'}) {
# $func->($dialog);
# }
# }
$dialog->present;
return $dialog;
}
sub _screen {
my ($obj) = @_;
if (! defined $obj) {
return Gtk2::Gdk::Screen->get_default;
}
# don't want $display->get_screen($screennum)
if ($obj->isa('Gtk2::Gdk::Display')) {
return $obj->get_default_screen;
}
if (my $func = $obj->can('get_screen')) {
return $obj->$func || croak "No screen for target $obj";
}
if (my $func = $obj->can('get_default_screen')) {
return $obj->$func || croak "No default screen for target $obj";
}
return $obj;
}
sub _object_properties_equal {
my ($obj, $properties) = @_;
while (my ($pname, $value) = each %$properties) {
my $pspec = $obj->find_property ($pname)
|| croak "No such property '",$pname,"'";
if ($pspec->values_cmp ($value, $obj->get($pname)) != 0) {
return 0;
}
}
return 1;
}
1;
__END__
=for stopwords Ryde Chart
=head1 NAME
( run in 1.687 second using v1.01-cache-2.11-cpan-39bf76dae61 )