ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/Dockable.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI/Dockable.pm (file contents):
Revision 1.3 by root, Wed Dec 26 21:03:21 2007 UTC vs.
Revision 1.4 by elmex, Sun Jan 6 16:28:49 2008 UTC

3use strict; 3use strict;
4use utf8; 4use utf8;
5 5
6our @ISA = DC::UI::Bin::; 6our @ISA = DC::UI::Bin::;
7 7
8
9# A dockable can be docked into a DC::UI::Dockbar
10# Attributes:
11# 'can_close' says: This dockable has a close button as tab.
12# 'can_undock' says that the dockable tab has a 'undock' button.
13# 'title' is the title of the tab label or the title of the undocket window
14
8sub new { 15sub new {
9 my $class = shift; 16 my $class = shift;
10 17
11 my $self = $class->SUPER::new ( 18 my $self = $class->SUPER::new (
12 title => "unset", 19 title => "unset",
13 can_close => 1, 20 can_close => 1,
21 can_undock => 0, # temporarily deactivated!
14 @_, 22 @_,
15 ); 23 );
24
25 $self->init;
16 26
17 $self 27 $self
18} 28}
19 29
30# a setup method for the constructor
31sub init {
32 my ($self) = @_;
33
34 my $bb = $self->{c_tab} = DC::UI::ButtonBin->new (tooltip => $self->{tooltip});
35 $bb->add (my $vb = DC::UI::Box->new);
36 $vb->add (
37 my $b =
38 $self->{tab_label} =
39 DC::UI::Label->new (expand => 1, valign => 0, align => 0)
40 );
41
42 if ($self->{can_close}) {
43 $vb->add (
44 my $ib = DC::UI::ImageButton->new (path => 'x1_close.png', scale => 0.3)
45 );
46 $ib->connect (activate => sub {
47 $self->close;
48 0
49 });
50 }
51
52 if ($self->{can_undock}) {
53 $vb->add (
54 my $ib2 = DC::UI::ImageButton->new (path => 'x1_close.png', scale => 0.3)
55 );
56 $ib2->connect (activate => sub {
57 $self->emit ("undock");
58 0
59 });
60 }
61
62
63 $self->set_title ($self->{title});
64}
65
66# This sets the title of the dockable. The title is displayed
67sub set_title {
68 my ($self, $title) = @_;
69 $self->{title} = $title;
70 $self->update_tab;
71}
72
73# Returns the title
74sub get_title { $_[0]->{title} }
75
76# This method activates the tab of the dockable if it is docked
77sub select_my_tab {
78 my ($self) = @_;
79 if ($self->is_docked) {
80 $self->{dockbar}->select_dockable ($self);
81 }
82}
83
84# (private) This method is used by Dockbar to tell the dockable
85# it's position in the dockbar (if it has one, if it has no position,
86# $pos is undef).
87sub set_dockbar_pos {
88 my ($self, $pos) = @_;
89 $self->{dockbar_pos} = $pos;
90 $self->update_tab;
91}
92
93# (private) This method tells the dockable that it is 'active', which means:
94# it is docked and it's tab has been activated and it is currently shown.
95sub set_dockbar_tab_active {
96 my ($self, $active) = @_;
97 $self->{dockbar_active} = $active;
98 $self->update_tab;
99}
100
101# (private) This method updates the tab and other things of the dockable
102# whenever something has been changed (title, color, ...)
103sub update_tab {
104 my ($self) = @_;
105 # TODO: set color according to dockbar_active
106
107 my $oldcolor = $self->{tab_label}->{fg};
108 if ($self->is_docked_active) {
109 $self->{tab_label}->{fg} = $self->{active_fg} || [1, 1, 1];
110 } else {
111 $self->{tab_label}->{fg} = $self->{inactive_fg} || [1, 1, 1,];
112 }
113 if (join (',', @$oldcolor) ne join (',', @{$self->{tab_label}->{fg}})) {
114 # update colors
115 $self->{tab_label}->realloc;
116 $self->{tab_label}->update;
117 }
118
119 $self->{tab_label}->set_markup (
120 $self->get_title
121 . (defined $self->{dockbar_pos}
122 ? "-" . ($self->{dockbar_pos} + 1)
123 : "")
124 );
125}
126
127# This method sets the active foreground color of the dockable tab
128sub set_active_fg {
129 my ($self, $fg) = @_;
130 $self->{active_fg} = $fg;
131 $self->update_tab;
132}
133
134# This method sets the inactive foreground color of the dockable tab
135sub set_inactive_fg {
136 my ($self, $fg) = @_;
137 $self->{inactive_fg} = $fg;
138 $self->update_tab;
139}
140
141# (private) This method is used by the Dockbar to tell the Dockable which
142# Dockbar it belongs to. Do not call this method yourself, use the dockbars
143# add_dock and remove_dock methods instead.
144sub set_dockbar {
145 my ($self, $dockbar) = @_;
146 $self->{dockbar} = $dockbar;
147 Scalar::Util::weaken $self->{dockbar};
148}
149
150# This method is called when someone wants to 'activate' the dockable,
151# the meaning of being 'activated' is given by subclasses that inherit
152# from Dockable. Eg. In ChatView the 'activation' means that the entry field
153# of for chat is activated for input.
154sub activate {
155 my ($self) = @_;
156 $self->emit ("activate");
157}
158
159# Returns whether this dockable is docked on a Dockbar.
160sub is_docked {
161 my ($self) = @_;
162 $self->{dockbar} or return 0;
163 return $self->{dockbar}->is_docked ($self);
164}
165
166# Returns whether this dockable is docked _and_ it's tab
167# is active.
168sub is_docked_active {
169 my ($self) = @_;
170 $self->{dockbar} or return 0;
171 return $self->{dockbar_active};
172}
173
174# This method is called when the Dockable wants to be closed, which means
175# that it's window is closed or tab is removed from the dockbar and it
176# is removed from the dockbar.
177sub close {
178 my ($self) = @_;
179 $self->emit ("close_dock");
180}
181
201 1821

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines