|
|
1 | use utf8; |
|
|
2 | |
1 | package superchat; |
3 | package superchat; |
2 | |
4 | |
3 | # waaay cool widget. well... maybe at one point in the future |
5 | # waaay cool widget. well... maybe at one point in the future |
4 | |
6 | |
5 | use Gtk2; |
7 | use Gtk2; |
… | |
… | |
103 | } |
105 | } |
104 | |
106 | |
105 | $self->signal_emit (command => $cmd, $arg); |
107 | $self->signal_emit (command => $cmd, $arg); |
106 | }); |
108 | }); |
107 | |
109 | |
108 | $self->{end} = $self->{buffer}->create_mark (undef, $self->{buffer}->get_end_iter, 0); |
110 | #$self->{end} = $self->{buffer}->create_mark (undef, $self->{buffer}->get_end_iter, 0);#d##todo# use this one for gtk-1.050+ |
|
|
111 | $self->{end} = $self->{buffer}->create_mark (++$USELESSNAME, $self->{buffer}->get_end_iter, 0); # workaround for gtk-perl bug |
109 | |
112 | |
110 | $self->set_end; |
113 | $self->set_end; |
111 | } |
114 | } |
112 | |
115 | |
113 | sub do_command { |
116 | sub do_command { |
… | |
… | |
134 | } |
137 | } |
135 | |
138 | |
136 | sub append_text { |
139 | sub append_text { |
137 | my ($self, $text) = @_; |
140 | my ($self, $text) = @_; |
138 | |
141 | |
139 | my $at_end = $self->at_end; |
|
|
140 | $self->_append_text ($self->{end}, $text); |
142 | $self->_append_text ($self->{end}, $text); |
141 | $self->set_end if $at_end; |
|
|
142 | } |
143 | } |
143 | |
144 | |
144 | sub _append_text { |
145 | sub _append_text { |
145 | my ($self, $mark, $text) = @_; |
146 | my ($self, $mark, $text) = @_; |
|
|
147 | |
|
|
148 | my $at_end = $self->at_end; |
146 | |
149 | |
147 | $text = "<default>$text</default>"; |
150 | $text = "<default>$text</default>"; |
148 | |
151 | |
149 | my @tag; |
152 | my @tag; |
150 | # pseudo-simplistic-xml-parser |
153 | # pseudo-simplistic-xml-parser |
… | |
… | |
159 | |
162 | |
160 | $text =~ /\G([^<]*)/gc or last; |
163 | $text =~ /\G([^<]*)/gc or last; |
161 | $self->{buffer}->insert_with_tags_by_name ($self->{buffer}->get_iter_at_mark ($mark), util::xmlto $1, @tag) |
164 | $self->{buffer}->insert_with_tags_by_name ($self->{buffer}->get_iter_at_mark ($mark), util::xmlto $1, @tag) |
162 | if length $1; |
165 | if length $1; |
163 | } |
166 | } |
|
|
167 | |
|
|
168 | $self->set_end if $at_end; |
164 | } |
169 | } |
165 | |
170 | |
166 | sub set_text { |
171 | sub set_text { |
167 | my ($self, $text) = @_; |
172 | my ($self, $text) = @_; |
168 | |
173 | |
… | |
… | |
207 | sub new_switchable_inlay { |
212 | sub new_switchable_inlay { |
208 | my ($self, $header, $cb, $visible) = @_; |
213 | my ($self, $header, $cb, $visible) = @_; |
209 | |
214 | |
210 | my $inlay; |
215 | my $inlay; |
211 | |
216 | |
212 | my $setvisible = sub { |
|
|
213 | if ($inlay->{visible}) { |
|
|
214 | $inlay->{cb}->($inlay); |
|
|
215 | } else { |
|
|
216 | $inlay->clear; |
|
|
217 | } |
|
|
218 | }; |
|
|
219 | |
|
|
220 | my $tag = $self->new_eventtag (sub { |
217 | my $tag = $self->new_eventtag (sub { |
221 | my ($tag, $view, $event, $iter) = @_; |
218 | my ($tag, $view, $event, $iter) = @_; |
222 | |
219 | |
223 | if ($event->type eq "button-press") { |
220 | if ($event->type eq "button-press") { |
224 | $inlay->{visible} = !$inlay->{visible}; |
221 | $inlay->set_visible (!$inlay->{visible}); |
225 | $setvisible->(); |
|
|
226 | } |
222 | } |
227 | |
223 | |
228 | 1; |
224 | 1; |
229 | }); |
225 | }); |
230 | |
226 | |
231 | $tag->set (background => "#e0e0ff"); |
227 | $tag->set (background => "#e0e0ff"); |
232 | |
228 | |
233 | $self->{buffer}->insert ($self->{buffer}->get_end_iter, "\n"); |
|
|
234 | $self->{buffer}->insert_with_tags ($self->{buffer}->get_end_iter, util::xmlto "$header \x{21f3}", $tag); |
|
|
235 | |
|
|
236 | $inlay = $self->new_inlay; |
229 | $inlay = $self->new_inlay; |
237 | |
230 | |
238 | $inlay->{visible} = $visible; |
231 | $inlay->{visible} = 0; |
|
|
232 | $inlay->{header} = $header; |
239 | $inlay->{tag} = $tag; |
233 | $inlay->{tag} = $tag; |
240 | $inlay->{cb} = $cb; |
234 | $inlay->{cb} = $cb; |
241 | |
235 | |
242 | $setvisible->(); |
236 | Scalar::Util::weaken $inlay->{tag}; |
|
|
237 | |
|
|
238 | $inlay->set_visible ($visible); |
243 | |
239 | |
244 | $inlay; |
240 | $inlay; |
245 | } |
241 | } |
246 | |
242 | |
247 | package superchat::inlay; |
243 | package superchat::inlay; |
… | |
… | |
258 | my ($self, $text) = @_; |
254 | my ($self, $text) = @_; |
259 | |
255 | |
260 | $self->{parent}->_append_text ($self->{r}, $text); |
256 | $self->{parent}->_append_text ($self->{r}, $text); |
261 | } |
257 | } |
262 | |
258 | |
|
|
259 | sub visible { $_[0]{visible} } |
|
|
260 | sub set_visible { |
|
|
261 | my ($self, $visible) = @_; |
|
|
262 | |
|
|
263 | return if $self->{visible} == $visible; |
|
|
264 | $self->{visible} = $visible; |
|
|
265 | |
|
|
266 | $self->refresh; |
|
|
267 | } |
|
|
268 | |
|
|
269 | sub refresh { |
|
|
270 | my ($self) = @_; |
|
|
271 | |
|
|
272 | $self->clear; |
|
|
273 | |
|
|
274 | my $arrow = $self->{visible} ? "⊟" : "⊞"; |
|
|
275 | |
|
|
276 | $self->{buffer}->insert ($self->riter, "\n"); |
|
|
277 | $self->{buffer}->insert_with_tags ($self->riter, util::xmlto "$arrow $self->{header}", $self->{tag}); |
|
|
278 | |
|
|
279 | return unless $self->{visible}; |
|
|
280 | |
|
|
281 | $self->{cb}->($self); |
|
|
282 | } |
|
|
283 | |
263 | sub DESTROY { |
284 | sub DESTROY { |
264 | my ($self) = @_; |
285 | my ($self) = @_; |
265 | |
286 | |
266 | $self->{parent}{tagtable}->remove (delete $self->{tag}) if $self->{tag}; |
287 | $self->{parent}{tagtable}->remove (delete $self->{tag}) if $self->{tag}; |
267 | } |
288 | } |