ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/gde/GCE/StackView.pm
Revision: 1.19.2.2
Committed: Mon Dec 21 15:51:30 2009 UTC (16 years, 9 months ago) by elmex
Branch: cursor
Changes since 1.19.2.1: +32 -54 lines
Log Message:
rewrote main parts in internal reference handling.

File Contents

# User Rev Content
1 elmex 1.1 package GCE::StackView;
2    
3     =head1 NAME
4    
5     GCE::StackView - the stack window class for gce
6    
7     =cut
8    
9     use Gtk2;
10     use Gtk2::Gdk::Keysyms;
11     use Gtk2::SimpleMenu;
12    
13 root 1.19 use Deliantra;
14     use Deliantra::MapWidget;
15 elmex 1.1
16     use GCE::AttrEdit;
17 elmex 1.10 use GCE::Util;
18 elmex 1.1
19     use Glib::Object::Subclass Gtk2::VBox;
20    
21 elmex 1.12 use Storable qw/dclone/;
22    
23 elmex 1.1 use strict;
24    
25     sub INIT_INSTANCE {
26     my ($self) = @_;
27    
28     $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0);
29     $sw->add_with_viewport ($self->{stackbox} = Gtk2::VBox->new);
30 elmex 1.7 $sw->set_policy ('automatic', 'automatic');
31 elmex 1.18 }
32    
33 elmex 1.1 sub set_stack {
34 elmex 1.19.2.2 my ($self, $sr) = @_;
35 elmex 1.1
36 elmex 1.19.2.2 unless (defined $sr) {
37     $sr = $self->{stackref};
38     }
39 elmex 1.19.2.1
40 elmex 1.19.2.2 unless (defined $sr) {
41     delete $self->{stackref_reg_cb};
42     $sr = GCE::StackRef->new (owner => 'stack_view');
43 elmex 1.18 }
44    
45 elmex 1.19.2.2 $self->{stackref} = $sr;
46    
47     $sr->overlay;
48    
49     $self->{stackref_reg_cb} = $self->{stackref}->reg_cb (changed => sub {
50     my ($sr, $msg, $invalid) = @_;
51    
52     if ($invalid) {
53     delete $self->{stackref};
54     }
55    
56     $self->set_stack;
57     });
58 elmex 1.19.2.1
59 elmex 1.1 for ($self->{stackbox}->get_children) {
60     $self->{stackbox}->remove ($_);
61     }
62    
63 elmex 1.19.2.2 my (@stack) = $sr->get;
64    
65     if (@stack) {
66     my $idx = @stack - 1;
67    
68     for my $a (reverse @stack) {
69 elmex 1.11 # FIXME: How to change a stack with a virtual arch????
70 elmex 1.16 if ($_->{_virtual}) {
71     $idx--;
72     next
73     }
74 elmex 1.12 my $ownidx = $idx;
75 elmex 1.1
76 elmex 1.11 #my $a = $_->{_virtual} || $_;
77 elmex 1.1
78 elmex 1.11 # this is awful, is this really the best way?
79     my $pb = new Gtk2::Gdk::Pixbuf 'rgb', 1, 8, TILESIZE, TILESIZE;
80 elmex 1.1
81 elmex 1.11 fill_pb_from_arch ($pb, $a);
82 elmex 1.1
83 elmex 1.11 $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0);
84     $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0);
85     $delbtn->signal_connect (clicked => sub {
86 elmex 1.19.2.2 $sr->remove ($idx);
87 elmex 1.1 });
88 elmex 1.11
89     $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0);
90     $elemhdl->add (my $hb2 = Gtk2::HBox->new);
91     $elemhdl->signal_connect (clicked => sub {
92 elmex 1.19.2.2 $::MAINWIN->update_attr_editor ($sr->cursor ($idx));
93 elmex 1.11 });
94    
95     $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0);
96     $img->set_alignment (0, 0.5);
97    
98     $hb2->pack_start (my $lbl = Gtk2::Label->new ($a->{_name}), 0, 0, 0);
99     $lbl->set_alignment (0, 0.5);
100 elmex 1.1
101 elmex 1.11 $elemhdl->drag_source_set (['button1_mask'], ['move'],
102     { target => 'STRING', flags => [], info => 'TARGET_STRING' }
103     );
104     $elemhdl->drag_dest_set (all => ['move'],
105     { target => 'STRING', flags => [], info => 'TARGET_STRING' }
106     );
107 elmex 1.1
108 elmex 1.12 GCE::DragHelper::set_drag_source (
109 elmex 1.19.2.1 $elemhdl, arch => sub {
110 elmex 1.19.2.2 { arch => $stack[$ownidx], stk => \@stack, stk_idx => $ownidx }
111 elmex 1.12 }
112     );
113    
114     GCE::DragHelper::set_drag_sink (
115     $elemhdl, arch => sub {
116     my ($darch) = @_;
117    
118 elmex 1.19.2.1 if (defined $darch->{stk_idx}) { # FIXME: check stack source!
119 elmex 1.12 my $swapidx = $darch->{stk_idx};
120 elmex 1.19.2.2 $sr->swap ($swapidx, $ownidx);
121 elmex 1.12
122     } else {
123 elmex 1.19.2.2 $sr->replace ($ownidx, $darch->{arch});
124 elmex 1.12 }
125     }
126     );
127 elmex 1.19.2.2
128 elmex 1.11 $idx--;
129     }
130 elmex 1.1 }
131 elmex 1.19.2.1
132 elmex 1.1 $self->show_all;
133     }
134    
135     =head1 AUTHOR
136    
137     Marc Lehmann <schmorp@schmorp.de>
138     http://home.schmorp.de/
139    
140     Robin Redeker <elmex@ta-sa.org>
141     http://www.ta-sa.org/
142    
143     =cut
144     1;
145