File: GtkToolbar.t

package info (click to toggle)
libgtk2-perl 1%3A1.190-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,132 kB
  • ctags: 516
  • sloc: perl: 16,575; sh: 149; ansic: 148; makefile: 76
file content (235 lines) | stat: -rw-r--r-- 7,998 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#
# $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/t/GtkToolbar.t,v 1.9 2007/08/01 18:41:16 kaffeetisch Exp $
#

use Gtk2::TestHelper tests => 52;

use strict;
use warnings;

#
# the new 2.4 API and the pre-2.4 API cannot be used on the same widget,
# so we create completely separate toolbars for the two APIs.
#

SKIP: {
	skip "new and improved 2.4 toolbar API", 21
		unless Gtk2->CHECK_VERSION (2, 4, 0);

	my $toolbar = Gtk2::Toolbar->new;
	isa_ok ($toolbar, 'Gtk2::Toolbar');

	my @toolitems = map { Gtk2::ToolButton->new (undef, "$_") } 0..9;

	foreach (@toolitems) {
		$toolbar->insert ($_, -1);
	}

	is ($toolbar->get_n_items, scalar(@toolitems));
	is ($toolbar->get_item_index ($toolitems[4]), 4);

	is ($toolbar->get_nth_item (-1), undef, "get_nth_item -1");
	for (0..12) {
		is ($toolbar->get_nth_item ($_), $toolitems[$_],
		    "get_nth_item $_");
	}

	$toolbar->set_show_arrow (FALSE);
	ok (!$toolbar->get_show_arrow);

	$toolbar->set_show_arrow (TRUE);
	ok ($toolbar->get_show_arrow);


	my $reliefstyle = $toolbar->get_relief_style;
	ok (defined $reliefstyle);

	# this assumes that 0,0 will get the first item in the toolbar.
	# i hope that this isn't subject to theme borders and the like.
	is (0, $toolbar->get_drop_index (0, 0));

	# can't use an item with a parent...
	$toolbar->set_drop_highlight_item (Gtk2::ToolButton->new (undef, ''), 3);
	# turn off the highlighting
	$toolbar->set_drop_highlight_item (undef, 0);
}


#
# just about everything from here to the end is deprecated as of 2.4.0,
# but will not be disabled because it wasn't deprecated in 2.0.x and 2.2.x.
#

my $toolbar = Gtk2::Toolbar->new;

my $widget;

     # text tooltip private     icon           callback  data
for ([   '',    '',      '', 'Gtk2::Image', sub {1},    [] ],
     [   '', undef,   undef,         undef ],  # test default params
     )
{
	my $icontype = $_->[3];

	$_->[3] = new $icontype if defined $icontype;
	$widget = $toolbar->append_item (@$_);
	isa_ok ($widget, 'Gtk2::Widget');

	$_->[3] = new $icontype if defined $icontype;
	$widget = $toolbar->prepend_item (@$_);
	isa_ok ($widget, 'Gtk2::Widget');

	$_->[3] = new $icontype if defined $icontype;
	$widget = $toolbar->insert_item ($_->[0], # text
					 $_->[1], # tooltip_text
					 $_->[2], # tooltip_private_text
					 $_->[3], # icon
					 $_->[4], # callback
					 $_->[5], # user_data
					 1); # position
	isa_ok ($widget, 'Gtk2::Widget');

	$widget = $toolbar->insert_stock ('gtk-open', # stock-id
					  $_->[1], # tooltip_text
					  $_->[2], # tooltip_private_text
					  $_->[4], # callback
					  $_->[5], # user_data
					  2); # position
	isa_ok ($widget, 'Gtk2::Widget');
}


#
# this is highly obnoxious, but we need to test prepend, insert, and append
# with multiple sets of arguments to ensure that we get the marshaling right.
# unfortunately, there's not really any good way to loop this, so the code
# is quite repetitive.  (and wide.)
#

# GtkToolbarChildType
#   space        a space in the style of the toolbar's GtkToolbarSpaceStyle.
#   button       a GtkButton.
#   togglebutton a GtkToggleButton.
#   radiobutton  a GtkRadioButton.
#   widget       a standard GtkWidget.

#
#$widget = $toolbar->prepend_element (type, widget, text, tooltip_text, tooltip_private_text, icon, callback=NULL, user_data=NULL)
#
$widget = $toolbar->prepend_element ('space', undef, undef, undef, undef, undef);
is ($widget, undef, 'prepend_element with a space');

$widget = $toolbar->prepend_element ('button', undef, '', undef, undef, undef, sub {1});
isa_ok ($widget, 'Gtk2::Widget', 'prepend_element with a button and a callback');

$widget = $toolbar->prepend_element ('togglebutton', undef, '', undef, undef, undef);
isa_ok ($widget, 'Gtk2::Widget', 'prepend_element with a togglebutton');

$widget = $toolbar->prepend_element ('radiobutton', undef, '', undef, undef, undef);
isa_ok ($widget, 'Gtk2::Widget', 'prepend_element with a radiobutton');

# with radiobutton, the widget is used to determine the group.
$widget = $toolbar->prepend_element ('radiobutton', $widget, '', undef, undef, undef);
isa_ok ($widget, 'Gtk2::Widget', 'prepend_element with a radiobutton');

my $entry = Gtk2::Entry->new;
$widget = $toolbar->prepend_element ('widget', $entry, undef, undef, undef, undef);
is ($widget, $entry, 'prepend_element with a widget');


#
#$widget = $toolbar->insert_element (type, widget, text, tooltip_text, tooltip_private_text, icon, callback, user_data, position)
#
$widget = $toolbar->insert_element ('space', undef, undef, undef, undef, undef, undef, undef, -1);
is ($widget, undef, 'insert_element with a space');

$widget = $toolbar->insert_element ('button', undef, '', undef, undef, undef, sub {1}, undef, 0);
isa_ok ($widget, 'Gtk2::Widget', 'insert_element with a button and a callback');

$widget = $toolbar->insert_element ('togglebutton', undef, '', undef, undef, undef, undef, undef, 1);
isa_ok ($widget, 'Gtk2::Widget', 'insert_element with a togglebutton');

$widget = $toolbar->insert_element ('radiobutton', undef, '', undef, undef, undef, undef, undef, 2);
isa_ok ($widget, 'Gtk2::Widget', 'insert_element with a radiobutton');

# with radiobutton, the widget is used to determine the group.
$widget = $toolbar->insert_element ('radiobutton', $widget, '', undef, undef, undef, undef, undef, 3);
isa_ok ($widget, 'Gtk2::Widget', 'insert_element with a radiobutton');

$entry = Gtk2::Entry->new;
$widget = $toolbar->insert_element ('widget', $entry, undef, undef, undef, undef, undef, undef, 4);
is ($widget, $entry, 'insert_element with a widget');


#
#$widget = $toolbar->append_element (type, widget, text, tooltip_text, tooltip_private_text, icon, callback=NULL, user_data=NULL)
#
$widget = $toolbar->append_element ('space', undef, undef, undef, undef, undef);
is ($widget, undef, 'append_element with a space');

$widget = $toolbar->append_element ('button', undef, '', undef, undef, undef, sub {1});
isa_ok ($widget, 'Gtk2::Widget', 'append_element with a button and a callback');

$widget = $toolbar->append_element ('togglebutton', undef, '', undef, undef, undef);
isa_ok ($widget, 'Gtk2::Widget', 'append_element with a togglebutton');

$widget = $toolbar->append_element ('radiobutton', undef, '', undef, undef, undef);
isa_ok ($widget, 'Gtk2::Widget', 'append_element with a radiobutton');

# with radiobutton, the widget is used to determine the group.
$widget = $toolbar->append_element ('radiobutton', $widget, '', undef, undef, undef);
isa_ok ($widget, 'Gtk2::Widget', 'append_element with a radiobutton');

$entry = Gtk2::Entry->new;
$widget = $toolbar->append_element ('widget', $entry, undef, undef, undef, undef);
is ($widget, $entry, 'append_element with a widget');




$toolbar->prepend_widget (Gtk2::Image->new, 'tooltip', 'tooltip_private');
$toolbar->prepend_widget (Gtk2::Image->new, undef, undef);

$toolbar->insert_widget (Gtk2::Image->new, 'tooltip', 'tooltip_private', -1);
$toolbar->insert_widget (Gtk2::Image->new, undef, undef, 1);

$toolbar->append_widget (Gtk2::Image->new, 'tooltip', 'tooltip_private');
$toolbar->append_widget (Gtk2::Image->new, undef, undef);




$toolbar->prepend_space;
$toolbar->remove_space (0);
$toolbar->insert_space (-1);
$toolbar->insert_space (1);
$toolbar->append_space;


# GtkToolbarStyle
#  GTK_TOOLBAR_ICONS
#  GTK_TOOLBAR_TEXT
#  GTK_TOOLBAR_BOTH
#  GTK_TOOLBAR_BOTH_HORIZ

$toolbar->set_style ('icons');
is ('icons', $toolbar->get_style, '[sg]et_style');
$toolbar->set_style ('both');
is ('both', $toolbar->get_style, '[sg]et_style');
$toolbar->unset_style;

$toolbar->set_icon_size ('small-toolbar');
is ('small-toolbar', $toolbar->get_icon_size, '[sg]et_icon_size');
$toolbar->unset_icon_size;

$toolbar->set_tooltips (TRUE);
ok ($toolbar->get_tooltips, '[sg]et_tooltips');

$toolbar->set_orientation ('vertical');
is ('vertical', $toolbar->get_orientation, '[sg]et_orientation');


__END__

Copyright (C) 2003-2004 by the gtk2-perl team (see the file AUTHORS for the
full list).  See LICENSE for more information.