Gtk2-Ex-FormFactory

 view release on metacpan or  search on metacpan

lib/Gtk2/Ex/FormFactory/Layout.pm  view on Meta::CPAN

                } );
                0;
            });
            $gtk_button->signal_connect ( button_release_event => sub {
                Glib::Source->remove($timeout);
                $button_pressed = 0;
                0;
            });
        }
	
	1;
}

sub build_list {
	my $self = shift;
	my ($list) = @_;
	
	my $columns    = $list->get_columns;
	my $types      = $list->get_types;
	my $editable   = $list->get_editable;
	my $visible    = $list->get_visible;
	my $no_header  = $list->get_no_header;

	my (@slist, $i);

	foreach my $col ( @{$columns} ) {
		push @slist, $col, ($types->[$i]||"text");
		++$i;
	}

	my $slist = Gtk2::SimpleList->new ( @slist );

	if ( $editable ) {
		$i = 0;
		foreach my $e ( @{$editable} ) {
			$slist->set_column_editable($i, $e);
			++$i;
		}
	}

	if ( $visible ) {
		$i = 0;
		foreach my $v ( @{$visible} ) {
			$slist->get_column($i)->set_visible($v);
			++$i;
		}
	}

	if ( $no_header ) {
		$slist->set_headers_visible(0);
	}

	$slist->get_selection->set_mode ($list->get_selection_mode)
		if $list->get_selection_mode;

	$list->set_gtk_widget($slist);
	
	1;
}

sub build_popup {
	my $self = shift;
	my ($popup) = @_;
	
	my $gtk_popup_menu = Gtk2::Menu->new;
	my $gtk_popup = Gtk2::OptionMenu->new;
	$gtk_popup->set_menu($gtk_popup_menu);

	$popup->set_gtk_widget ( $gtk_popup );

	1;	
}

sub build_progress_bar {
	my $self = shift;
	my ($progress_bar) = @_;
	
	my $gtk_progress_bar = Gtk2::ProgressBar->new;
	
	$progress_bar->set_gtk_widget($gtk_progress_bar);
	
	1;
}

sub build_image {
	my $self = shift;
	my ($image) = @_;

	my $gtk_image = Gtk2::Image->new;
	$gtk_image->set_size_request(undef, undef);
	$image->set_gtk_widget($gtk_image);

	my $bgcolor = $image->get_bgcolor;
	my $gtk_event_box = Gtk2::EventBox->new;
	$gtk_event_box->modify_bg ("normal", Gtk2::Gdk::Color->parse ($bgcolor))
		if defined $bgcolor;
	$gtk_event_box->add($gtk_image);

	$image->set_gtk_event_box($gtk_event_box);

	if ( $image->get_with_frame ) {
		my $gtk_frame = Gtk2::Frame->new;
		$gtk_frame->add($gtk_event_box);
		$image->set_gtk_parent_widget($gtk_frame);
	} else {
		$image->set_gtk_parent_widget($gtk_event_box);
	}

	my $update_timeout;
	if ( $image->get_scale_to_fit or
	     $image->get_max_width or
	     $image->get_max_height ) {
		$gtk_event_box->signal_connect (
		    "size-allocate" => sub {
			return if $image->get_widget_width  == $_[1]->width and
				  $image->get_widget_height == $_[1]->height;
			$image->set_widget_width($_[1]->width);
			$image->set_widget_height($_[1]->height);
			Glib::Source->remove($update_timeout)
				if $update_timeout;
			$update_timeout = Glib::Timeout->add (
				100, sub {
					$image->update;
					$update_timeout = undef;
					0
				}
			);
			0;
		    }

lib/Gtk2/Ex/FormFactory/Layout.pm  view on Meta::CPAN


  build_form  ( ... )
  build_label ( ... )
  build_table ( ... )

The method prototype looks like this:

=over 4

=item $layout->B<build_TYPE> ($widget)

B<$widget> is the actual Gtk2::Ex::FormFactory::Widget, e.g.
Gtk2::Ex::FormFactory::Form for B<build_form>($form).

=back

The B<build_TYPE> method actually creates the necessary Gtk2 widgets,
e.g. a Gtk2::Table for a Gtk2::Ex::FormFactory::Form and adds
these to the FormFactory's widget instance using the B<set_gtk_widget>()
and B<set_gtk_parent_widget>() methods of Gtk2::Ex::FormFactory::Widget.

Call $widget->B<set_gtk_widget>($gtk_widget) for the primary Gtk2 widget
which directly displays the value in question, e.g. a Gtk2::Entry if you're
dealing with a Gtk2::Ex::FormFactory::Entry.

If you like to do more layout things which require to add the primary
Gtk2 widget to a container, e.g. a Gtk2::Frame, you must call 
$widget->B<set_gtk_parent_widget>($gtk_parent_widget) with the
most top level container widget.

B<Note:> the implemenations of all the FormFactory's widgets expect
a specific B<gtk_widget> to be set. If you like to change the primary
Gtk widget you need to create your own Gtk2::Ex::FormFactory::Widget
for this, because the default implemention most probably won't work
with a another Gtk2::Widget.

=head2 ADD...TO... METHODS

The second type of methods are so called add-to methods, which place
a widget inside a container. The prototye is as follows:

=over 4

=item $layout->B<add_TYPE_to_TYPE> ($widget, $container)

B<$widget> is the actual Gtk2::Ex::FormFactory::Widget, e.g.
Gtk2::Ex::FormFactory::Form for B<build_form>($form).

=back

Examples:

  add_form_to_window ( ... )
  add_table_to_form  ( ... )

This way you can adjust layout at a very detailed level, but
you need not. E.g. the implementation of these methods is
most likely the same:

  add_entry_to_form ( ... )
  add_popup_to_form ( ... )

because the implemenation mainly depends on the B<form>
(the container widget) and not on the widget which is added to
the form.

That's why Gtk2::Ex::FormFactory::Layout knows a default mechanism:
if no add-to method is found for a specific widget/container
pair, a generic default implementation is used instead. These
are named as follows:

  add_widget_to_window ( ... )
  add_widget_to_form   ( ... )
  add_widget_to_table  ( ... )
  add_widget_to_vbox   ( ... )
  ...

For a new Container you just need to implement the generic
B<add_widget_to_TYPE> method, and everything will work. If
you want to slightly modify the implementation for specific
child widgets, you implement only the methods for these and
you're done.

For a example for such a specific add-to message refer to
B<add_menu_to_window>() which attaches the menu without any
space around it. The default of a Gtk2::Ex::FormFactory::Window
is to have some spacing, which looks ugly around a menu.

=head1 OBJECT HIERARCHY

  Gtk2::Ex::FormFactory::Layout

=head1 ATTRIBUTES

This class has not attributes.

=head1 AUTHORS

 Jörn Reder <joern at zyn dot de>

=head1 COPYRIGHT AND LICENSE

Copyright 2004-2006 by Jörn Reder.

This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.

This library 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
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307
USA.

=cut



( run in 0.611 second using v1.01-cache-2.11-cpan-364913b4093 )