The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Gtk2::Ex::ComboBox - A simple ComboBox with multiple selection capabilities.

DESCRIPTION

The Gtk2::ComboBox widget allows the user to select only one of the several drop down options. But if your application requires multiple selection capability in the ComboBox, then try this widget instead.

This widget also serves as an example implementation using the Gtk2::Ex::PopupWindow module.

SYNOPSIS

        use Glib qw(TRUE FALSE);
        use Gtk2 qw/-init/;
        use Gtk2::Ex::ComboBox;

        my $button = Gtk2::Button->new('click me');
        my $combobox = Gtk2::Ex::ComboBox->new($button);
        # Or you can call the constructor with two arguments
        # my $combobox = Gtk2::Ex::ComboBox->new($button, 'no-checkbox' );
        $combobox->set_list(['this', 'that', 'what']);
        $button->signal_connect('button-release-event' => sub { $combobox->show; } );

METHODS

new($parent, <$type>);

The $parent refers to the widget to which the ComboBox is attached.

The $type parameter is optional. It can be of one of the three types

        'with-buttons' (this is the default option if none specified)
        'with-checkbox' 
        'no-checkbox'
        

These three types control the way the user selects the multiple entries. Please refer to the examples/combobox.pl for a demonstration.

set_list([$list]);

The list of choices is entered using this method. Accepts an array (of strings) as the argument.

        $combobox->set_list(['this', 'that', 'what']);

set_list_preselected([$list]);

The list of choices is entered using this method. Accepts an array of arrays as the argument. Each element array should have a boolean and a string. The boolean denotes whether this element should be marked as selected or not.

        $combobox->set_list([[0,'this'], [1,'that'], [1,'what']]);

In the example shown above, the elements 'that' and 'what' will be marked as selected in the dropdown list.

get_treeview;

Returns the treeview that serves as the model for the ComboBox. This widget internally uses Gtk2::Ex::Simple::List and therefore the return object will be of that class.

get_selected_values;

Returns a hash containing two lists.

$hash{'selected-values'} contains a list of all the values that are marked as selected.

$hash{'unselected-values'} contains a list of all the values that are not marked as selected.

get_selected_indices;

Returns a hash containing two lists.

$hash{'selected-indices'} contains a list of all the indices that are marked as selected.

$hash{'unselected-indices'} contains a list of all the indices that are not marked as selected.

show;

Call this method to display the ComboBox. Typically on a 'button-release-event' on the parent widget.

        $button->signal_connect('button-release-event' => sub { $combobox->show; } );

hide;

Call this method to hide the ComboBox. This method does not have to be called explicitly since the ComboBox is automatically closed if the user clicks anywhere outside.

SIGNALS

changed - This signal gets emitted whenever the selection is changed.

        $combobox1->signal_connect('changed' => 
                sub {
                        print "combobox1 selection changed\n";
                }
        );

AUTHOR

Ofey Aikon

ACKNOWLEDGEMENTS

To the wonderful gtk-perl-list.

SEE ALSO

Gtk2::Ex::PopupWindow

COPYRIGHT & LICENSE

Copyright 2005 Ofey Aikon, All Rights Reserved.

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.