ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/gtk.pl
Revision: 1.2
Committed: Sat May 31 09:48:48 2003 UTC (21 years ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +11 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package gtk;
2
3 our $text_renderer = new Gtk2::CellRendererText;
4 our $int_renderer = new Gtk2::CellRendererText;
5 $int_renderer->set (xalign => 1);
6
7 our $state = $util::state->{gtk} || {};
8
9 # shows the properties of a glib object
10 sub gtk_info {
11 my ($idx, $obj) = @_;
12 last if $seen{$idx}++;
13 print "\n$idx\n";
14 for ($obj->list_properties) {
15 printf "%-16s %-24s %-24s %s\n", $_->{name}, $_->{type}, (join ":", @{$_->{flags}}), $_->{descr};
16 }
17 }
18
19 # grr... more gtk+ brokenness
20 my %get = (
21 hpane_position => sub { ($_[0]->children)[0]->allocation->[2] },
22 vpane_position => sub { ($_[0]->children)[0]->allocation->[3] },
23 window_size => sub { [ ($_[0]->allocation->values)[2,3] ] },
24 #window_pos => sub { die KGS::Listener::Debug::dumpval [ $_[0]->get_root_origin ] },
25 clist_column_widths => sub {
26 $_[0]{column_widths};
27 },
28 );
29
30 my %set = (
31 hpane_position => sub { $_[0]->set_position($_[1]) },
32 vpane_position => sub { $_[0]->set_position($_[1]) },
33 window_size => sub { $_[0]->set_default_size(@{$_[1]}) },
34 #window_pos => sub { $_[0]->set_uposition(@{$_[1]}) if @{$_[1]} },
35 clist_column_widths => sub {
36 my ($w, $v) = @_;
37 $v->[$_] && $w->set_column_width($_, $v->[$_]) for 0..$#$v;
38 $w->{column_widths} = $v;
39 $w->signal_connect(resize_column => sub { $v->[$_[1]] = $_[2]; });
40 },
41 );
42
43 sub state {
44 my ($widget, $class, $instance, %attr) = @_;
45
46 while (my ($k, $v) = each %attr) {
47 my ($set, $get) = $k =~ /=/ ? split /=/, $k : ($k, $k);
48 $v = $state->{$class}{"*"}{$get} if exists $state->{$class}{"*"}{$get};
49 $v = $state->{$class}{$instance}{$get} if exists $state->{$class}{$instance}{$get};
50 $set{$get} ? $set{$get}->($widget, $v) : $widget->set($set => $v);
51 }
52
53 $widget = [$widget, $class, $instance, \%attr];
54 Scalar::Util::weaken $widget->[0];
55
56 @widgets = (grep $_->[0], @widgets, $widget);
57 }
58
59 sub save_state {
60 for (@widgets) {
61 if ($_->[0]) {
62 my ($widget, $class, $instance, $attr) = @$_;
63
64 $widget->realize if $widget->isa(Gtk2::Widget::);
65
66 while (my ($k, $v) = each %$attr) {
67 my ($set, $get) = $k =~ /=/ ? split /=/, $k : ($k, $k);
68 $v = $get{$get} ? $get{$get}->($widget) : $widget->get($get);
69
70 warn "$class : $get = $v\n";#d#
71 $state->{$class}{"*"}{$get} = $v;
72 $state->{$class}{$instance}{$get} = $v;
73 }
74 }
75 ::status("save_state", "layout saved");
76 }
77 }
78
79 # make a clist unselectable
80 sub clist_autosort {
81 my $w = shift;
82 my ($c, $o) = (-1);
83 for (0..$w->columns-1) {
84 $w->signal_connect(click_column => sub {
85 if ($_[1] != $c) {
86 $c = $_[1];
87 $o = 0;
88 } else {
89 $o = !$o;
90 }
91 $w->set_sort_column($c);
92 $w->set_sort_type($o ? "descending" : "ascending");
93 $w->sort;
94 });
95 }
96 }
97
98 package gtk::widget;
99
100 # hacked gtk pseudo-widget
101
102 sub widget { $_[0]{widget} }
103
104 sub AUTOLOAD {
105 warn $AUTOLOAD;
106 die;
107 }
108
109 1;
110