File: panes.pl

package info (click to toggle)
libgtk2-perl 1%3A1.140-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,808 kB
  • ctags: 609
  • sloc: perl: 14,245; ansic: 118; makefile: 70
file content (169 lines) | stat: -rw-r--r-- 4,993 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/perl -w
#
# Paned Widgets
#
# The GtkHPaned and GtkVPaned Widgets divide their content
# area into two panes with a divider in between that the
# user can adjust. A separate child is placed into each
# pane.
#
# There are a number of options that can be set for each pane.
# This test contains both a horizontal (HPaned) and a vertical
# (VPaned) widget, and allows you to adjust the options for
# each side of each widget.
#

package panes;

use strict;
use Glib qw(TRUE FALSE);
use Gtk2;

sub toggle_resize {
  my ($widget, $child) = @_;

  my $paned = $child->parent;
  my $is_child1 = ($child == $paned->child1);

  my $resize = $is_child1 ? $paned->child1_resize : $paned->child2_resize;
  my $shrink = $is_child1 ? $paned->child1_shrink : $paned->child2_shrink;

  $child->parent->remove ($child);
  if ($is_child1) {
    $paned->pack1 ($child, !$resize, $shrink);
  } else {
    $paned->pack2 ($child, !$resize, $shrink);
  }
}

sub toggle_shrink {
  my ($widget, $child) = @_;

  my $paned = $child->parent;
  my $is_child1 = ($child == $paned->child1);

  my $resize = $is_child1 ? $paned->child1_resize : $paned->child2_resize;
  my $shrink = $is_child1 ? $paned->child1_shrink : $paned->child2_shrink;

  $child->parent->remove ($child);
  if ($is_child1) {
    $paned->pack1 ($child, $resize, !$shrink);
  } else {
    $paned->pack2 ($child, $resize, !$shrink);
  }
}

sub create_pane_options {
  my ($paned, $frame_label, $label1, $label2) = @_;

  my $frame = Gtk2::Frame->new ($frame_label);
  $frame->set_border_width (4);
  
  my $table = Gtk2::Table->new (3, 2, TRUE);
  $frame->add ($table);
  
  my $label = Gtk2::Label->new ($label1);
  $table->attach_defaults ($label, 0, 1, 0, 1);
  
  my $check_button = Gtk2::CheckButton->new ("_Resize");
  $table->attach_defaults ($check_button, 0, 1, 1, 2);
  $check_button->signal_connect (toggled => \&toggle_resize, $paned->child1);
  
  $check_button = Gtk2::CheckButton->new ("_Shrink");
  $table->attach_defaults ($check_button, 0, 1, 2, 3);
  $check_button->set_active (TRUE);
  $check_button->signal_connect (toggled => \&toggle_shrink, $paned->child1);
  
  $label = Gtk2::Label->new ($label2);
  $table->attach_defaults ($label, 1, 2, 0, 1);
  
  $check_button = Gtk2::CheckButton->new ("_Resize");
  $table->attach_defaults ($check_button, 1, 2, 1, 2);
  $check_button->set_active (TRUE);
  $check_button->signal_connect (toggled => \&toggle_resize, $paned->child2);
  
  $check_button = Gtk2::CheckButton->new ("_Shrink");
  $table->attach_defaults ($check_button, 1, 2, 2, 3);
  $check_button->set_active (TRUE);
  $check_button->signal_connect (toggled => \&toggle_shrink, $paned->child2);

  return $frame;
}

my $window = undef;
sub do {
  if (!$window) {
      $window = Gtk2::Window->new;

      $window->signal_connect (destroy => sub { $window = undef; 1 });

      $window->set_title ("Panes");
      $window->set_border_width (0);

      my $vbox = Gtk2::VBox->new (FALSE, 0);
      $window->add ($vbox);
      
      my $vpaned = Gtk2::VPaned->new;
      $vbox->pack_start ($vpaned, TRUE, TRUE, 0);
      $vpaned->set_border_width (5);

      my $hpaned = Gtk2::HPaned->new;
      $vpaned->add1 ($hpaned);

      my $frame = Gtk2::Frame->new;
      $frame->set_shadow_type ('in');
      $frame->set_size_request (60, 60);
      $hpaned->add1 ($frame);
      
      my $button = Gtk2::Button->new ("_Hi there");
      $frame->add ($button);

      $frame = Gtk2::Frame->new;
      $frame->set_shadow_type ('in');
      $frame->set_size_request (80, 60);
      $hpaned->add2 ($frame);

      $frame = Gtk2::Frame->new;
      $frame->set_shadow_type ('in');
      $frame->set_size_request (60, 80);
      $vpaned->add2 ($frame);

      # Now create toggle buttons to control sizing

      $vbox->pack_start (create_pane_options ($hpaned, "Horizontal", "Left", "Right"),
                         FALSE, FALSE, 0);

      $vbox->pack_start (create_pane_options ($vpaned, "Vertical", "Top", "Bottom"),
                         FALSE, FALSE, 0);

      $vbox->show_all;
  }

  if (!$window->visible) {
      $window->show;
  } else {
      $window->destroy;
      $window = undef;
  }

  return $window;
}

1;
__END__
Copyright (C) 2003 by the gtk2-perl team (see the file AUTHORS for the
full list)

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.