ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/superchat.pl
(Generate patch)

Comparing kgsueme/kgsueme/superchat.pl (file contents):
Revision 1.2 by pcg, Fri May 21 03:18:15 2004 UTC vs.
Revision 1.9 by pcg, Wed May 26 03:28:37 2004 UTC

1use utf8;
2
1package superchat; 3package 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
5use Gtk2; 7use 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
113sub do_command { 116sub do_command {
134} 137}
135 138
136sub append_text { 139sub 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
144sub _append_text { 145sub _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
166sub set_text { 171sub set_text {
167 my ($self, $text) = @_; 172 my ($self, $text) = @_;
168 173
207sub new_switchable_inlay { 212sub 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
247package superchat::inlay; 243package 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
259sub visible { $_[0]{visible} }
260sub set_visible {
261 my ($self, $visible) = @_;
262
263 return if $self->{visible} == $visible;
264 $self->{visible} = $visible;
265
266 $self->refresh;
267}
268
269sub 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
263sub DESTROY { 284sub 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}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines