blib/lib/Tk/WidgetDump.pm untested

filter: Statementstmt 0.0% 0 / 938 Branchbran 0.0% 0 / 214 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 0.0% 0 / 91 Podpod 0.0% 0 / 53 totaltotal 0.0% 0 / 1359 CC 105 SCAR 45.0
CC
105
Cov
0%
WidgetInfo
506.0
_bind_text_tag
272.0
Flash
42.0
CRAP 89.8
1 # -*- perl -*-
2  
3 #
4 # Author: Slaven Rezic
5 #
6 # Copyright (C) 1999-2011,2013 Slaven Rezic. All rights reserved.
7 # This program is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9 #
10 # Mail: srezic@cpan.org
11 # WWW: http://www.rezic.de/eserte/
12 #
13  
14 package Tk::WidgetDump;
15 use vars qw($VERSION);
16 use strict;
17  
18 $VERSION = '1.39';
19  
20 package # hide from CPAN indexer
21 Tk::Widget;
22 use Tk;
23 use Tk::Tree;
24 use Tk::Balloon;
25  
26 sub WidgetDump {
27 my($top, %args) = @_;
28 my $t = $top->Toplevel;
29 $t->title("WidgetDump of $top");
30 $t->geometry("620x420");
31 foreach my $key (qw(Control-C q)) {
32 $t->bind("<$key>" => sub { $t->destroy });
33 }
34 $t->{Top} = $top;
35 $t->{Args} = \%args;
36  
37 bless $t, 'Tk::WidgetDump';
38  
39 my $bf = $t->Frame->pack(-fill => 'x', -side => "bottom");
40  
41 my $hl = $t->WD_HList->pack(-fill => 'both', -expand => 1);
42 $t->Advertise("HList" => $hl);
43  
44 my $rb = $bf->Button(-text => "Refresh",
45 -command => [$t, "WD_Refresh"],
46 )->pack(-side => "left");
47 my $cb = $bf->Button(-text => "Close",
48 -command => [$t, "WD_Close"],
49 )->pack(-side => "left");
50 $bf->Button(-text => "Help",
51 -command => sub {
52 if (!eval { require Tk::Pod; 1}) {
53 $bf->messageBox(-message => "Tk::Pod is not installed!");
54 return;
55 }
56 $bf->Pod(-file => $INC{"Tk/WidgetDump.pm"},
57 -title => "Tk::WidgetDump documentation");
58 })->pack(-side => "right", -anchor => "e");
59 $t->bind("<Alt-r>" => sub { $rb->invoke });
60 $t->bind("<Escape>" => sub { $cb->invoke });
61  
62 ## NYI:
63 # $t->{TrackWidgets} = 1;
64 # my $balloon;
65 # my $pathname;
66 # $balloon = $top->Balloon
67 # (-balloonposition => 'mouse',
68 # -motioncommand => sub {
69 # return unless $t->{TrackWidgets};
70 # my $ev = $top->XEvent;
71 # my($w_under) = $top->containing($ev->X, $ev->Y);
72 # $pathname = $w_under->PathName;
73 # 1;
74 # });
75 # $balloon->attach($top, -msg => \$pathname);
76 # $bf->Checkbutton(-text => "Track",
77 # -variable => \$t->{TrackWidgets},
78 # )->pack(-side => 'left');
79 if(0) { # not yet...
80 $top->bind("<1>" => [ sub { return unless $t && Tk::Exists($t);
81 shift;
82 $t->SelectWidget(@_);
83 }, Ev('X'), Ev('Y') ]);
84 }
85  
86 $t;
87 }
88  
89 sub WD_HList {
90 my($t) = @_;
91  
92 my $top = $t->{Top};
93 my $args = $t->{Args};
94  
95 my $hl;
96 $hl = $t->Scrolled('Tree', -drawbranch => 1, -header => 1,
97 #-columns => 5,
98 -columns => 4,
99 -scrollbars => "osow",
100 -selectmode => "multiple",
101 -exportselection => 1,
102 -takefocus => 1,
103 -width => 40,
104 -height => 20,
105 ($args->{-font} ? (-font => $args->{-font}) : ()),
106 -command => sub {
107 my $sw = $hl->info('data', $_[0]);
108 $t->_show_widget($sw);
109 },
110 )->pack(-fill => 'both', -expand => 1);
111 $t->Advertise("Tree" => $hl);
112 $hl->focus;
113 $hl->headerCreate(0, -text => "Tk Name");
114 $hl->headerCreate(1, -text => "Tk Class");
115 $hl->headerCreate(2, -text => "Characteristics");
116 $hl->headerCreate(3, -text => "Perl-Class");
117 #XXX $hl->headerCreate(4, -text => "Size");
118 $t->_insert_wd($hl, $top);
119 if (exists $args->{-openinfo}) {
120 #XXX needs work
121 # while(my($k,$v) = each %{ $args->{-openinfo} }) {
122 # $hl->setmode($k, $v);
123 # }
124 } else {
125 $hl->autosetmode;
126 }
127  
128 if ($hl->can("menu") and $hl->can("PostPopupMenu")) {
129 my $popup_menu = $hl->Menu
130 (-menuitems =>
131 [
132 [Cascade => "~Edit", -menuitems =>
133 [
134 [Button => "~Refresh", -command => sub { $t->WD_Refresh }],
135 [Button => "~Close", -command => sub { $t->WD_Close }],
136 ],
137 ],
138 [Cascade => "~Font", -menuitems =>
139 [
140 [Button => "~Tiny",
141 -command => sub { $hl->configure(-font => "Helvetica 6") }],
142 [Button => "~Small",
143 -command => sub { $hl->configure(-font => "Helvetica 8") }],
144 [Button => "~Normal",
145 -command => sub { $hl->configure(-font => "Helvetica 10") }],
146 [Button => "~Large",
147 -command => sub { $hl->configure(-font => "Helvetica 18") }],
148 [Button => "~Huge",
149 -command => sub { $hl->configure(-font => "Helvetica 24") }],
150 ]
151 ]
152 ]
153 );
154 $hl->menu($popup_menu);
155 $hl->bind("<3>" => sub {
156 my $e = $_[0]->XEvent;
157 $_[0]->PostPopupMenu($e->X, $e->Y);
158 });
159 }
160  
161 $hl;
162 }
163  
164 sub _WD_Size {
165 my $w = shift;
166 my $size = 0;
167 eval {
168 while(my($k,$v) = each %$w) {
169 if (defined $v) {
170 $size += length($k) + length($v);
171 }
172 }
173 };
174 warn $@ if $@;
175 $size;
176 }
177  
178 sub WD_Refresh {
179 my $t = shift;
180 my %args;
181 my %openinfo;
182 my $hl = $t->Subwidget("HList");
183 foreach ($hl->info('children')) {
184 $openinfo{$_} = $hl->getmode($_);
185 }
186 my $first_seen = $hl->nearest($hl->height/2);
187 my $see;
188 if (defined $first_seen) {
189 $see = $hl->info("data",$first_seen);
190 }
191 my %pack_info = $hl->packInfo;
192  
193 $hl->destroy;
194 $hl = $t->WD_HList($t->{Top}, $t->{Args});
195 $hl->pack(%pack_info);
196 $t->Advertise("HList" => $hl);
197  
198 if (defined $see) {
199 $t->see($see);
200 }
201 }
202  
203 sub WD_Close {
204 my $t = shift;
205 $t->destroy;
206 }
207  
208 ######################################################################
209  
210 package Tk::WidgetDump;
211 use base qw(Tk::Toplevel);
212  
213 use File::Basename;
214  
215 use vars qw(%ref2widget);
216  
217 sub Flash {
218 my $wd = shift;
219 my $w = shift;
220 eval {
221 # Wenn ein Widget während eines Flashs nochmal ausgewählt wird,
222 # muss es erst einmal zurückgesetzt werden.
223 if (defined $wd->{OldRepeat}) {
224 $wd->{OldRepeat}->cancel;
225 if (defined $wd->{OldBg}) {
226 $wd->{OldWidget}->configure(-background => $wd->{OldBg});
227 }
228 }
229  
230 my $old_bg = $w->cget(-background);
231 # leicht verzögern, damit -background nicht vom Blinken verfälscht wird
232 $w->after(10, sub { $w->configure(-background => "red") });
233 $w->Tk::raise;
234 my $i = 0;
235  
236 my $flash_rep;
237 $flash_rep = $w->repeat
238 (500,
239 sub {
240 if ($i % 2 == 0) {
241 $w->configure(-background => "red");
242 } else {
243 $w->configure(-background => $old_bg);
244 }
245 if (++$i > 8) {
246 $flash_rep->cancel;
247 undef $wd->{OldRepeat};
248 $w->configure(-background => $old_bg);
249 }
250 });
251  
252 $wd->{OldWidget} = $w;
253 $wd->{OldBg} = $old_bg;
254 $wd->{OldRepeat} = $flash_rep;
255 };
256 warn $@ if $@;
257 }
258  
259 sub SelectWidget {
260 my $wd = shift;
261 my($X,$Y) = @_;
262 my $w = $wd->containing($X, $Y);
263 return unless $w;
264  
265 my $hl = $wd->Subwidget("Tree");
266 my $c = ($hl->info("children"))[0];
267 while (defined $c and $c ne "") {
268 if ($w eq $hl->info('data', $c)) {
269 $hl->see($c);
270 $hl->anchorSet($c);
271 last;
272 }
273 $c = $hl->info("next", $c);
274 }
275  
276 $wd->_show_widget($w);
277 }
278  
279 sub WidgetInfo {
280 my $wd = shift;
281 my $w = shift;
282  
283 $wd->{WidgetInfoWidget} = $w;
284  
285 my $wi = $wd->_get_widget_info_window;
286 $wi->title("Widget Info for " . $w);
287  
288 my $txt = $wi->Subwidget("Information");
289 $txt->delete("1.0", "end");
290  
291 $txt->insert("end", "Configuration:\n\n", "title");
292 $txt->insert("end", "Option Switch\tOptionDB Name\tOptionDB Class\tDefault Value\tCurrent Value\n", "title");
293 foreach my $c ($w->configure) {
294 my $class = $c->[2];
295 my $name = $c->[1];
296 if ($name =~ m{^-}) { # an alias
297 my @c_alias = $w->configure($name);
298 $class = $c_alias[2];
299 }
300 $txt->insert("end",
301 join("\t", map { !defined $_ ? "<undef>" : $_ } @$c),
302 ["widgetlink",
303 "config-" . $w . ($c->[0]||"") . "-" . ($class||"")],
304 "\n");
305 }
306 $txt->insert("end", "\n");
307  
308 my $insert_method = sub {
309 my($meth, $label) = @_;
310 $label = $meth if !defined $label;
311 $txt->insert("end", "$label:\t" . $w->$meth() . "\n");
312 };
313  
314 $txt->insert("end", "Miscellaneous:\n\n", "title");
315  
316 $insert_method->("name", "Name");
317 $insert_method->("PathName");
318 $insert_method->("Class");
319  
320 $Tk::WidgetDump::ref2widget{$w} = $w;
321  
322 $txt->insert("end", "Self:\t" . $w . "\n");
323 if (defined $w->parent) {
324 $txt->insert("end", "Parent:\t" . $w->parent,
325 ["widgetlink", "href-" . $w->parent], "\n");
326 $Tk::WidgetDump::ref2widget{$w->parent} = $w->parent;
327 }
328  
329 if (defined $w->toplevel) {
330 $txt->insert("end", "Toplevel:\t" . $w->toplevel,
331 ["widgetlink", "href-" . $w->toplevel],
332 "\n");
333 $Tk::WidgetDump::ref2widget{$w->toplevel} = $w->toplevel;
334 }
335  
336 if (defined $w->MainWindow) {
337 $txt->insert("end", "MainWindow:\t" . $w->MainWindow,
338 ["widgetlink", "href-" . $w->MainWindow],
339 "\n");
340 $Tk::WidgetDump::ref2widget{$w->MainWindow} = $w->MainWindow;
341 }
342  
343 my @children = $w->children;
344 if (@children) {
345 $txt->insert("end", "Children:");
346 my $tab = "\t";
347 my $c_count=0;
348 foreach my $sw (@children) {
349 $txt->insert("end", $tab . $sw,
350 ["widgetlink", "href-" . $sw],
351 "\n");
352 $Tk::WidgetDump::ref2widget{$sw} = $sw;
353 $tab = "\t";
354 if ($c_count > 10) {
355 $txt->insert("end", $tab . "...");
356 }
357 }
358 }
359 my @subwidgets = keys %{ $w->{SubWidget} };
360 if (@subwidgets) {
361 $txt->insert("end", "Subwidgets:");
362 my $tab = "\t";
363 my $c_count=0;
364 foreach my $sw_name (@subwidgets) {
365 my $sw = $w->Subwidget($sw_name);
366 $txt->insert("end", $tab . $sw_name . " => " . $sw,
367 ["widgetlink", "href-" . $sw],
368 "\n");
369 $Tk::WidgetDump::ref2widget{$sw} = $sw;
370 $tab = "\t";
371 if ($c_count > 10) {
372 $txt->insert("end", $tab . "...");
373 }
374 }
375 }
376  
377 $insert_method->("manager", "GeomManager");
378 my $manager = $w->manager;
379 if ($manager) {
380 my $info_cmd = ($manager eq 'tixForm' ? 'formInfo' : $manager.'Info');
381 my %info = eval { $w->$info_cmd() };
382 warn $@ if $@;
383 if (keys %info) {
384 my $need_comma;
385 my %win_info;
386 $txt->insert("end", " info:\t");
387 if ($info{-in}) {
388 $win_info{-in} = delete $info{-in};
389 $txt->insert("end", "-in => $win_info{-in}",
390 ["widgetlink", "href-" . $win_info{-in}]);
391 $Tk::WidgetDump::ref2widget{$win_info{-in}} = $win_info{-in};
392 $need_comma++;
393 }
394 my $info = ($need_comma ? ", " : "") .
395 join(", ", map { "$_ => $info{$_}" } keys %info);
396 $txt->insert("end", $info . "\n");
397 }
398 }
399 eval {
400 my(@wrapper) = $w->wrapper;
401 if (@wrapper) {
402 $txt->insert("end", "wrapper:\t" . join(", ", @wrapper) . "\n");
403 }
404 };
405 $insert_method->("geometry");
406 $insert_method->("rootx");
407 $insert_method->("rooty");
408 $insert_method->("vrootx");
409 $insert_method->("vrooty");
410 $insert_method->("x");
411 $insert_method->("y");
412 $insert_method->("width");
413 $insert_method->("height");
414 $insert_method->("reqwidth");
415 $insert_method->("reqheight");
416 $insert_method->("id");
417 $insert_method->("ismapped");
418 $insert_method->("viewable");
419  
420 # XXX bindtags
421 # XXX bind?
422  
423 $txt->insert("end", "\nServer:\n");
424 $insert_method->("server", " id");
425 $insert_method->("visual", " visual");
426 #XXX dokumentiert, aber nicht vorhanden?!
427 # $insert_method->("visualid", " visualid");
428 $insert_method->("visualsavailable", " visualsavailable");
429  
430 $txt->insert("end", "\nRoot window:\n");
431 $insert_method->("vrootwidth", " vrootwidth");
432 $insert_method->("vrootheight", " vrootheight");
433  
434 $txt->insert("end", "\nScreen:\n");
435 $insert_method->("screen", " id");
436 $insert_method->("screencells", " cells");
437 $insert_method->("screenwidth", " width");
438 $insert_method->("screenheight", " height");
439 $insert_method->("screenmmwidth", " width (mm)");
440 $insert_method->("screenmmheight", " height (mm)");
441 $insert_method->("screenvisual", " visual");
442  
443 $txt->insert("end", "\nColor map:\n");
444 $insert_method->("cells", " cells");
445 $insert_method->("colormapfull", " full");
446 $insert_method->("depth", " depth");
447  
448 $txt->insert("end", "\n");
449  
450 {
451 my $b = $txt->Button(-text => "Flash widget",
452 -command => sub {
453 $wd->Flash($w);
454 });
455 $txt->windowCreate("end", -window => $b);
456 }
457 my $b = $txt->Button(-text => "Method call",
458 -command => sub {
459 $wd->method_call($w);
460 });
461 $txt->windowCreate("end", -window => $b);
462  
463 if ($w->isa('Tk::Canvas')) {
464 my $b = $txt->Button(-text => "Canvas dump",
465 -command => sub {
466 $wd->canvas_dump($w);
467 });
468 $txt->windowCreate("end", -window => $b);
469 }
470 if ($w->can('tagNames')) {
471 my $b = $txt->Button(-text => 'Tags',
472 -command => sub {
473 $wd->tag_dump($w);
474 });
475 $txt->windowCreate('end', -window => $b);
476 }
477  
478 my $ObjScanner;
479 if (!eval {
480 require Tk::ObjEditor;
481 $ObjScanner = "ObjEditor";
482 $Storable::forgive_me = $Storable::forgive_me = 1; # XXX hack to prevent problems with code refs
483 1;
484 }) {
485 eval { require Tk::ObjScanner;
486 $ObjScanner = "ObjScanner";
487 1;
488 };
489 }
490  
491 if (defined $ObjScanner) {
492 my $b = $txt->Button
493 (-text => $ObjScanner,
494 -command => sub {
495 my $t = $b->Toplevel(-title => $ObjScanner);
496 my $os = $t->$ObjScanner
497 (caller => $w,
498 title => "$ObjScanner $w",
499 background => 'white',
500 selectbackground => 'beige',
501 foldImage => $t->Photo(-file => Tk->findINC('folder.xpm')),
502 openImage => $t->Photo(-file => Tk->findINC('openfolder.xpm')),
503 itemImage => $t->Photo(-file => Tk->findINC('textfile.xpm')))->pack(-fill => "both", -expand => 1);
504 });
505 $txt->windowCreate("end", -window => $b);
506 }
507  
508 $b = $txt->Button
509 (-text => "Show bindings",
510 -command => [$wd, 'show_bindings', $w]);
511 $txt->windowCreate("end",
512 -window => $b,
513 );
514  
515 }
516  
517 sub show_bindings {
518 my($wd, $w) = @_;
519 my $t = $wd->Toplevel(-title => 'Bindings');
520 my $ttxt = $t->Scrolled($wd->_more_widget_class)->pack(-fill => 'both',
521 -expand => 1);
522 _text_link_config($ttxt, sub { _bind_text_tag($_[0], $wd) } );
523 foreach my $bindtag ($w->bindtags) {
524 $ttxt->insert("end", "Bind tag: $bindtag\n\n");
525 foreach my $bind ($w->Tk::bind($bindtag)) {
526 my $cb = $w->Tk::bind($bindtag, $bind);
527 my $label;
528 if (UNIVERSAL::isa($cb, 'ARRAY')) {
529 $label = join ",", @$cb;
530 } else {
531 $label = $cb;
532 }
533 $ttxt->insert("end", $bind . " => ");
534 $ttxt->insert("end", $label,
535 ["widgetlink",
536 "bind-" . $w . "|" . $bindtag . "|" . $bind]);
537 $ttxt->insert("end", "\n");
538 }
539 $ttxt->insert("end", "\n");
540 }
541 }
542  
543 sub show_binding_details {
544 my($wd, $widget, $bindtag, $bind) = @_;
545 my $t = $wd->Toplevel(-title => "Binding details");
546 my $ttxt = $t->Scrolled($wd->_more_widget_class)->pack(-fill => "both", -expand => 1);
547 my $cb = $widget->Tk::bind($bindtag, $bind);
548 $ttxt->insert("end", "Binding <$bind> for bindtag <$bindtag>:\n");
549 require Data::Dumper;
550 my $txt;
551 my $dd = Data::Dumper->new([$cb],[]);
552 if ($dd->can("Deparse")) {
553 $txt = $dd->Deparse(1)->Useqq(1)->Dump;
554 } else {
555 $txt = "Sorry, your version of Data::Dumper is not capable to deparse the CODE reference.";
556 }
557 $ttxt->insert("end", $txt);
558 }
559  
560 sub _show_widget {
561 my($wd, $w) = @_;
562 $wd->Flash($w);
563 $wd->WidgetInfo($w);
564 }
565  
566 sub see {
567 my($wd, $w) = @_;
568 my $tree = $wd->Subwidget("Tree");
569 my $entry = ($tree->info("children"))[0];
570 while (defined $entry and $entry ne "") {
571 if ($tree->info("data", $entry) eq $w) {
572 $tree->see($entry);
573 return;
574 }
575 $entry = $tree->info("next", $entry);
576 }
577 warn "Widget $w not found in Widget tree\n";
578 }
579  
580 sub _edit_config {
581 my($wd, $w, $opt, $class) = @_;
582  
583 my $val;
584 eval {
585 $val = $w->cget($opt);
586 };
587 if ($@) {
588 warn $@;
589 return;
590 }
591 my $oldval = $val;
592  
593 my $t = $wd->Toplevel(-title => "Edit config");
594 my $set_sub = sub {
595 eval {
596 $w->configure($opt => $val);
597 };
598 warn $@ if $@;
599 };
600 $t->Label(-text => "Edit $opt for $w:")->pack(-side => "left");
601 my $e;
602 $e = eval 'Tk::WidgetDump::' . $class . '->entry($t, \$val, $set_sub)';
603 #warn $@ if $@;
604 if ($@) {
605 $e = eval 'Tk::WidgetDump::Entry->entry($t, \$val, $set_sub)';
606 warn $@ if $@;
607 }
608 #XXX ja?
609 # $t->Button(-text => "Undef and close",
610 # -command => sub {
611 # $val = undef;
612 # $set_sub->();
613 # $t->destroy;
614 # }
615 # )->pack(-side => "left");
616 $t->Button(-text => "Set",
617 -command => $set_sub,
618 )->pack(-side => "left");
619 $t->Button(-text => "Close",
620 -command => [$t, 'destroy'],
621 )->pack(-side => "left");
622 $e->focus if Tk::Exists($e);
623 $t->bind("<Escape>" => [$t, 'destroy']);
624 }
625  
626 sub method_call {
627 my($wd, $w) = @_;
628  
629 my $t = $wd->Toplevel(-title => "Method call");
630 my $f = $t->Frame->pack(-fill => "x");
631 my $eval;
632 $f->Label(-text => "Method call on $w ->")->pack(-side => "left");
633 my $e = $f->_hist_entry({-textvariable => \$eval},
634 {-match => 1, -dup => 0})->pack(-side => "left");
635 $e->focus;
636 my $ww = $w;
637 my $text;
638 my $doit = sub {
639 if ($e->can('historyAdd')) {
640 $e->historyAdd;
641 }
642 $ww = $ww; # XXX ???????
643 my $cmd = '$ww->' . $eval;
644 my(@res) = eval($cmd);
645 require Data::Dumper;
646 my $res = Data::Dumper->Dumpxs([\@res, $@],[$cmd, 'Error']) .
647 "\@res = <@res>\n";
648 warn $res;
649 $text->delete("1.0", "end");
650 $text->insert("end", $res);
651 };
652 my $close = sub {
653 $t->destroy;
654 };
655 $e->bind('<Return>' => $doit);
656 $e->bind('<Escape>' => $close);
657 $f->Button(-text => "Execute!", -command => $doit)->pack(-side => "left");
658 $f->Button(-text => "Close", -command => $close)->pack(-side => "left");
659 $text = $t->Scrolled($wd->_more_widget_class,
660 -scrollbars => "osoe",
661 -font => "courier 10", # XXX do not hardcode
662 -width => 40, -height => 5)->pack(-fill => "both", -expand => 1);
663 }
664  
665 sub _text_link_config {
666 my($txt, $code) = @_;
667 $txt->tagConfigure(qw/widgetlink -underline 1/);
668 $txt->tagConfigure(qw/hot -foreground red/);
669 $txt->tagBind(qw/widgetlink <ButtonRelease-1>/ => $code);
670 $txt->{last_line} = '';
671 $txt->tagBind(qw/widgetlink <Enter>/ => sub {
672 my($text) = @_;
673 my $e = $text->XEvent;
674 my($x, $y) = ($e->x, $e->y);
675 $txt->{last_line} = $text->index("\@$x,$y linestart");
676 $text->tagAdd('hot', $txt->{last_line}, $txt->{last_line}." lineend");
677 $text->configure(qw/-cursor hand2/);
678 });
679 $txt->tagBind(qw/widgetlink <Leave>/ => sub {
680 my($text) = @_;
681 $text->tagRemove(qw/hot 1.0 end/);
682 $text->configure(qw/-cursor xterm/);
683 });
684 $txt->tagBind(qw/widgetlink <Motion>/ => sub {
685 my($text) = @_;
686 my $e = $text->XEvent;
687 my($x, $y) = ($e->x, $e->y);
688 my $new_line = $text->index("\@$x,$y linestart");
689 if ($new_line ne $txt->{last_line}) {
690 $text->tagRemove(qw/hot 1.0 end/);
691 $txt->{last_line} = $new_line;
692 $text->tagAdd('hot', $txt->{last_line}, $txt->{last_line}." lineend");
693 }
694 });
695 $txt->tagConfigure("title", -font => "Helvetica 10 bold"); # XXX do not hardcode!
696 }
697  
698 ######################################################################
699 # Canvas
700 sub canvas_config {
701 my($wd, $c, $item) = @_;
702 my $t = $wd->Toplevel(-title => "Canvas config of item $item");
703  
704 my $txt = $t->Scrolled($wd->_more_widget_class,
705 -tabs => [map { (5*$_) . "c" } (1 .. 8)],
706 -scrollbars => "osow",
707 -wrap => "none",
708 )->pack(-fill => "both", -expand => 1);
709 _text_link_config($txt, sub { _bind_text_tag($_[0], $wd) } );
710  
711 $txt->insert("end", "Canvas Item Configuration:\n\n", "title");
712 $txt->insert("end", "Option\tDefault Value\tCurrent Value\n", "title");
713 foreach my $cc ($c->itemconfigure($item)) {
714 my @cc = @{$cc}[0,3,4];
715 $txt->insert("end",
716 join("\t", map { !defined $_ ? "<undef>" : $_ } @cc),
717 ["widgetlink", "cconfig-" . $c . "-" . $item . $cc[0]],
718 "\n"
719 );
720 }
721  
722 $txt->insert("end", "\nCoords\n",
723 ["widgetlink", "ccoords-" . $c . "-" . $item],
724 "\n"
725 );
726  
727 }
728  
729 sub canvas_dump {
730 my($wd, $c) = @_;
731 my $t = $wd->Toplevel(-title => "Canvas dump of $c");
732 my $txt = $t->Scrolled($wd->_more_widget_class,
733 -scrollbars => "osow",
734 -tabs => [map { (3*$_) . "c" } (1 .. 3)],
735 )->pack(-fill => "both", -expand => 1);
736 _text_link_config($txt, sub { _bind_text_tag($_[0], $wd) } );
737  
738 $txt->insert("end", "Canvas Dump\n\n", "title");
739 $txt->insert("end", "Item number\tType\tTag list\n", "title");
740 foreach my $i ($c->find("all")) {
741 $txt->insert("end", "$i\t" . $c->type($i) . "\t[" .
742 join(",",$c->gettags($i)) . "]",
743 ["widgetlink", "c-" . $c . "-" . $i],
744 "\n");
745 }
746  
747 }
748  
749 sub edit_canvas_config {
750 my($wd, $c, $item, $opt) = @_;
751  
752 my $val;
753 eval {
754 $val = $c->itemcget($item, $opt);
755 };
756 if ($@) {
757 warn $@;
758 return;
759 }
760 my $oldval = $val;
761  
762 my $t = $wd->Toplevel(-title => "Edit canvas config");
763 my $set_sub = sub {
764 eval {
765 $c->itemconfigure($item, $opt => $val);
766 };
767 warn $@ if $@;
768 };
769 $t->Label(-text => "Edit $opt for canvas item $item:")->pack(-side => "left");
770 my $e;
771 $e = eval 'Tk::WidgetDump::Entry->entry($t, \$val, $set_sub)';
772 warn $@ if $@;
773 $e->focus if Tk::Exists($e);
774 $t->bind("<Escape>" => [$t, 'destroy']);
775 #XXX ja?
776 # $t->Button(-text => "Undef and close",
777 # -command => sub {
778 # $val = undef;
779 # $set_sub->();
780 # $t->destroy;
781 # }
782 # )->pack(-side => "left");
783 $t->Button(-text => "Close", -command => [$t, "destroy"])->pack(-side => "left");
784 }
785  
786 sub edit_canvas_coords {
787 my($wd, $c, $item) = @_;
788  
789 my $val;
790 eval {
791 $val = join(",", $c->coords($item));
792 };
793 if ($@) {
794 warn $@;
795 return;
796 }
797  
798 my $t = $wd->Toplevel(-title => "Edit canvas coords");
799 my $set_sub = sub {
800 eval {
801 my @c = split(/,/, $val);
802 $c->coords($item, @c);
803 };
804 warn $@ if $@;
805 };
806 $t->Label(-text => "Edit coords for canvas item $item:")->pack(-side => "left");
807 my $e;
808 $e = eval 'Tk::WidgetDump::Entry->entry($t, \$val, $set_sub)';
809 warn $@ if $@;
810 $e->focus if Tk::Exists($e);
811 $t->bind("<Escape>" => [$t, 'destroy']);
812 $t->Button(-text => "Close", -command => [$t, "destroy"]);
813 }
814  
815 ######################################################################
816 # Tags
817 sub tag_dump {
818 my($wd, $w) = @_;
819 my $t = $wd->Toplevel(-title => "Tag dump of $w");
820 my $txt = $t->Scrolled($wd->_more_widget_class,
821 -width => 15,
822 -height => 5,
823 -scrollbars => 'osow',
824 )->pack(-fill => "both", -expand => 1);
825 _text_link_config($txt, sub { _bind_text_tag($_[0], $wd) } );
826  
827 $txt->insert('end', "Tags\n\n", 'title');
828 for my $tag_name ($w->tagNames) {
829 $txt->insert('end', $tag_name, ["widgetlink", "tag-$w-$tag_name"], "\n");
830 }
831 }
832  
833 sub tag_options {
834 my($wd, $w, $tag) = @_;
835  
836 my $t = $wd->Toplevel(-title => "Options for tag $tag");
837 my $txt = $t->Scrolled($wd->_more_widget_class,
838 -scrollbars => 'osow',
839 -tabs => [map { (3*$_) . "c" } (1 .. 3)],
840 )->pack(-fill => "both", -expand => 1);
841 _text_link_config($txt, sub { _bind_text_tag($_[0], $wd) } );
842 $txt->insert('end', "Option Name\tDefault Value\tCurrent Value\n", 'title');
843 for my $option_def ($w->tagConfigure($tag)) {
844 my($key,undef,undef,$def_val,$curr_val) = @$option_def;
845 $txt->insert('end',
846 join("\t", map { !defined $_ ? '<undef>' : $_ } ($key, $def_val, $curr_val)),
847 ['widgetlink', "tag-config-$w-$tag-$key"],
848 "\n");
849 }
850 $txt->insert('end', "\n");
851 }
852  
853 sub edit_tag_option {
854 my($wd, $w, $tag, $key) = @_;
855  
856 my $val;
857 eval {
858 $val = $w->tagCget($tag, $key);
859 };
860 if ($@) {
861 warn $@;
862 return;
863 }
864  
865 my $t = $wd->Toplevel(-title => "Edit tag option $key");
866 my $set_sub = sub {
867 eval {
868 $w->tagConfigure($tag, $key, $val);
869 };
870 warn $@ if $@;
871 };
872  
873 $t->Label(-text => "Edit option $key for tag $tag:")->pack(-side => "left");
874 my $e;
875 $e = eval 'Tk::WidgetDump::Entry->entry($t, \$val, $set_sub)';
876 warn $@ if $@;
877 $e->focus if Tk::Exists($e);
878 $t->bind("<Escape>" => [$t, 'destroy']);
879 $t->Button(-text => "Close", -command => [$t, "destroy"]);
880 }
881  
882 ######################################################################
883 # Misc
884 sub _insert_wd {
885 my($wd, $hl, $top, $par) = @_;
886 my $i = 0;
887 foreach my $cw ($top->children) {
888 my $path = (defined $par ? $par . $hl->cget(-separator) : '') . $i;
889 my($name, $class, $size, $ref);
890 eval {
891 $name = $cw->Name || "No name";
892 $class = $cw->Class || "No class";
893 $size = $cw->_WD_Size;
894 $ref = ref($cw) || "No ref";
895 };
896 warn $@ if $@;
897 $hl->add($path, -text => $name, -data => $cw);
898 $hl->itemCreate($path, 1, -text => $class);
899 if ($cw->can('_WD_Characteristics')) {
900 my $char = $cw->_WD_Characteristics;
901 if (!defined $char) { $char = "???" }
902 $hl->itemCreate($path, 2, -text => $char);
903 }
904 $hl->itemCreate($path, 3, -text => $ref);
905 #XXX$hl->itemCreate($path, 4, -text => $size);
906 $wd->_insert_wd($hl, $cw, $path);
907 #if ($cw->can('_WD_Children')) {
908 # $cw->_WD_Children;
909 #}
910 $i++;
911 }
912 }
913  
914 sub _delete_all {
915 my($hl) = @_;
916 $hl->delete("all");
917 }
918  
919 sub _label_title {
920 my $w = shift;
921 if (defined $w->cget(-image) and
922 $w->cget(-image) ne "") {
923 my $image = "(image)";
924 eval {
925 my $i = $w->cget(-image);
926 if ($i->cget(-file) ne "") {
927 $image = _crop(basename($i->cget(-file))) . " (image)";
928 }
929 };
930 $image;
931 } elsif (defined $w->cget(-textvariable) and
932 $w->cget(-textvariable) ne "") {
933 _crop($ { $w->cget(-textvariable) });
934 } else {
935 _crop($w->cget(-text));
936 }
937 }
938  
939 sub _crop {
940 my $txt = shift;
941 if (defined $txt && length($txt) > 30) {
942 substr($txt, 0, 30) . "...";
943 } else {
944 $txt;
945 }
946 }
947  
948 sub _bind_text_tag {
949 my($text, $wd) = @_;
950  
951 my $index = $text->index('current');
952 my @tags = $text->tagNames($index);
953  
954 my $i = _lsearch('href\-.*', @tags);
955 if ($i >= 0) {
956 my($href) = $tags[$i] =~ /href-(.*)/;
957 my $widget = $ref2widget{$href};
958 $wd->_show_widget($widget);
959 return;
960 }
961  
962 $i = _lsearch('config\-.*', @tags);
963 if ($i >= 0) {
964 if ($tags[$i] =~ /^config-(.*)(-.*)-(.*)$/) {
965 my $w_name = $1;
966 my $opt = $2;
967 my $class = $3;
968 my $widget = $ref2widget{$w_name};
969 $wd->_edit_config($widget, $opt, $class);
970 return;
971 }
972 }
973  
974 $i = _lsearch('c\-.*', @tags);
975 if ($i >= 0) {
976 if ($tags[$i] =~ /^c-(.*)-(.*)$/) {
977 my $w_name = $1;
978 my $item = $2;
979 #my $canv_opt = $3;
980 my $widget = $ref2widget{$w_name};
981 $wd->canvas_config($widget, $item);
982 return;
983 }
984 }
985  
986 $i = _lsearch('cconfig\-.*', @tags);
987 if ($i >= 0) {
988 if ($tags[$i] =~ /^cconfig-(.*)-(.*)(-.*)$/) {
989 my $w_name = $1;
990 my $item = $2;
991 my $opt = $3;
992 my $widget = $ref2widget{$w_name};
993 $wd->edit_canvas_config($widget, $item, $opt);
994 return;
995 }
996 }
997  
998 $i = _lsearch('ccoords\-.*', @tags);
999 if ($i >= 0) {
1000 if ($tags[$i] =~ /^ccoords-(.*)-(.*)$/) {
1001 my $w_name = $1;
1002 my $item = $2;
1003 my $widget = $ref2widget{$w_name};
1004 $wd->edit_canvas_coords($widget, $item);
1005 return;
1006 }
1007 }
1008  
1009 $i = _lsearch('bind\-.*', @tags);
1010 if ($i >= 0) {
1011 if ($tags[$i] =~ /^bind-(.*)\|(.*)\|(.*)$/) {
1012 my $w_name = $1;
1013 my $bindtag = $2;
1014 my $bind = $3;
1015 my $widget = $ref2widget{$w_name};
1016 $wd->show_binding_details($widget, $bindtag, $bind);
1017 return;
1018 }
1019 }
1020  
1021 $i = _lsearch('tag\-config\-.*', @tags);
1022 if ($i >= 0) {
1023 if ($tags[$i] =~ /^tag-config-([^-]+)-(.*)-(-.+)$/) {
1024 my($w_name, $tag_name, $key) = ($1, $2, $3);
1025 my $widget = $ref2widget{$w_name};
1026 $wd->edit_tag_option($widget, $tag_name, $key);
1027 return;
1028 }
1029 }
1030  
1031 $i = _lsearch('tag\-.*', @tags);
1032 if ($i >= 0) {
1033 if ($tags[$i] =~ /^tag-(.*)-(.*)$/) {
1034 my $w_name = $1;
1035 my $tag_name = $2;
1036 my $widget = $ref2widget{$w_name};
1037 $wd->tag_options($widget, $tag_name);
1038 return;
1039 }
1040 }
1041  
1042 warn "Can't match $tags[$i]";
1043 }
1044  
1045 sub _get_widget_info_window {
1046 my $wd = shift;
1047  
1048 my $wi = $wd->Subwidget("WidgetInfo");
1049  
1050 if ($wi and Tk::Exists($wi)) {
1051 $wi->raise;
1052 return $wi;
1053 }
1054  
1055 $wi = $wd->Component(Toplevel => "WidgetInfo");
1056 $wi->title("Widget Info");
1057 if ($wi->screenwidth > 930 and
1058 $wi->screenheight > 450) {
1059 $wi->geometry("930x450");
1060 }
1061  
1062 my $bf = $wi->Frame->pack(-fill => 'x', -side => "bottom");
1063  
1064 my $txt = $wi->Scrolled($wd->_more_widget_class,
1065 -tabs => [map { (5*$_) . "c" } (1 .. 8)],
1066 -wrap => "none",
1067 )->pack(-expand => 1, -fill => "both");
1068 _text_link_config($txt, sub { _bind_text_tag($_[0], $wd) } );
1069  
1070 $wi->Advertise("Information" => $txt);
1071  
1072 my $rb = $bf->Button(-text => "Refresh",
1073 -command => sub {
1074 $wd->WidgetInfo($wd->{WidgetInfoWidget});
1075 })->pack(-side => "left");
1076 my $cb = $bf->Button(-text => "Close",
1077 -command => sub { $wi->destroy }
1078 )->pack(-side => "left");
1079 $wi->Advertise(Close => $cb);
1080  
1081 $wi;
1082 }
1083  
1084 sub _lsearch {
1085  
1086 # Search the list using the supplied regular expression and return it's
1087 # ordinal, or -1 if not found.
1088  
1089 my($regexp, @list) = @_;
1090 my($i);
1091  
1092 for ($i=0; $i<=$#list; $i++) {
1093 return $i if $list[$i] =~ /$regexp/;
1094 }
1095 return -1;
1096  
1097 } # end lsearch
1098  
1099 {
1100 my $more_widget_class;
1101 sub _more_widget_class {
1102 return $more_widget_class if $more_widget_class;
1103 if (eval { require Tk::More; 1 }) {
1104 return $more_widget_class = 'More';
1105 } else {
1106 require Tk::ROText;
1107 return $more_widget_class = 'ROText';
1108 }
1109 }
1110 }
1111  
1112 # XXX weitermachen
1113 # die Idee: die gesamten Konfigurationsdaten aller Widgets per configure
1114 # feststellen und als String schreiben. Und das für alle Children des
1115 # Widgets. Zusätzlich die pack/grid/etc.-Information feststellen.
1116 # Das alles gibt dann ein Perl-Programm. Parents bei der Rekursion merken.
1117 # sub dump_as_perl {
1118 # my $top = shift;
1119
1120 # }
1121  
1122 # sub dump_widget {
1123 # my $w = shift;
1124 # foreach $cdef ($w->configure) {
1125 # # if (defined $cdef->[4]) {
1126 # #
1127 # }
1128 # }
1129  
1130 # REPO BEGIN
1131 # REPO NAME _hist_entry /home/e/eserte/src/repository
1132 # REPO MD5 904022626019f774e4c0039cd8eecf78
1133 sub Tk::Widget::_hist_entry {
1134 my($top, $entry_args, $hist_entry_args) = @_;
1135 my $Entry = "Entry";
1136 my @extra_args;
1137 eval {
1138 require Tk::HistEntry;
1139 Tk::HistEntry->VERSION(0.33);
1140 $Entry = "SimpleHistEntry";
1141 @extra_args = %$hist_entry_args;
1142 };
1143 $top->$Entry(%$entry_args);
1144 }
1145 # REPO END
1146  
1147 package # hide from CPAN indexer
1148 Tk::Toplevel;
1149 sub _WD_Characteristics {
1150 my $w = shift;
1151 my $characteristics = eval {
1152 Tk::WidgetDump::_crop($w->title) . " (" . $w->geometry . ")";
1153 };
1154 if ($@) {
1155 # A "toplevel" which is not a real toplevel: this is true
1156 # for Tk::DragDrop, see the comments there.
1157 $characteristics = Tk::WidgetDump::_crop("toplevel-ish $w");
1158 }
1159 $characteristics;
1160 }
1161  
1162 package # hide from CPAN indexer
1163 Tk::Label;
1164 sub _WD_Characteristics {
1165 my $w = shift;
1166 Tk::WidgetDump::_label_title($w);
1167 }
1168  
1169 package # hide from CPAN indexer
1170 Tk::Button;
1171 sub _WD_Characteristics {
1172 my $w = shift;
1173 Tk::WidgetDump::_label_title($w);
1174 }
1175  
1176 package # hide from CPAN indexer
1177 Tk::Menu;
1178 sub _WD_Characteristics {
1179 my $w = shift;
1180 my $title = $w->cget(-title) || "(no title)";
1181 Tk::WidgetDump::_crop($title) . " (" . $w->cget("-type") . ")";
1182 }
1183  
1184 sub _WD_Children {
1185 my $w = shift;
1186 my $end = $w->index("end");
1187 for my $i (0 .. $end) {
1188 warn $w->type($i);
1189 }
1190 }
1191  
1192  
1193 package # hide from CPAN indexer
1194 Tk::Menubutton;
1195 sub _WD_Characteristics {
1196 my $w = shift;
1197 Tk::WidgetDump::_label_title($w);
1198 }
1199  
1200 package # hide from CPAN indexer
1201 Tk::Listbox;
1202 sub _WD_Characteristics {
1203 my $w = shift;
1204 my $first_elem = $w->get(0);
1205 if (defined $first_elem) {
1206 Tk::WidgetDump::_crop($first_elem) . " ...";
1207 } else {
1208 "";
1209 }
1210 }
1211  
1212 package # hide from CPAN indexer
1213 Tk::HList;
1214 sub _WD_Characteristics {
1215 my $w = shift;
1216 my $res = "";
1217 eval {
1218 my($first_entry) = $w->info("children");
1219 $res = Tk::WidgetDump::_crop($w->itemCget($first_entry, 0, -text)) . " ...";
1220 };
1221 $res;
1222 }
1223  
1224 # XXX bei Refresh openlist merken und wiederherstellen
1225  
1226 ######################################################################
1227  
1228 package Tk::WidgetDump::Entry;
1229 sub entry {
1230 my($class, $p, $valref, $set_sub) = @_;
1231 my $e = $p->_hist_entry({-textvariable => $valref},
1232 {-match => 1, -dup => 0});
1233 $e->bind("<Return>" => sub {
1234 if ($e->can('historyAdd')) {
1235 $e->historyAdd;
1236 }
1237 $set_sub->();
1238 });
1239 $e->pack(-side => "left");
1240 }
1241  
1242 package Tk::WidgetDump::BrowseEntry;
1243 sub entry {
1244 my($class, $p, $valref, $set_sub) = @_;
1245 require Tk::BrowseEntry;
1246 my $e = $p->BrowseEntry(-textvariable => $valref,
1247 -browsecmd => $set_sub)->pack(-side => "left");
1248  
1249 $e->insert("end", $class->entries);
1250 $e->bind("<Return>" => $set_sub);
1251 $e;
1252 }
1253  
1254 package Tk::WidgetDump::_MyNumEntry;
1255 eval {
1256 require Tk::NumEntry;
1257 @Tk::WidgetDump::_MyNumEntry::ISA = qw(Tk::NumEntry);
1258 Construct Tk::Widget '_MyNumEntry';
1259 sub Populate {
1260 my($w, $args) = @_;
1261 $w->SUPER::Populate($args);
1262 $w->ConfigSpecs(-setcmd => ['CALLBACK']);
1263 }
1264 sub incdec {
1265 my $w = shift;
1266 my $r = $w->Tk::NumEntry::incdec(@_);
1267 $w->Callback(-setcmd => $w);
1268 $r;
1269 }
1270 };
1271 warn $@ if $@;
1272 $Tk::WidgetDump::_MyNumEntry::can_mynumentry = 1 unless $@;
1273  
1274 package Tk::WidgetDump::NumEntry;
1275 sub entry {
1276 eval {
1277 die "No NumEntry"
1278 if !$Tk::WidgetDump::_MyNumEntry::can_mynumentry;
1279 };
1280 if ($@) {
1281 warn $@;
1282 shift->Tk::WidgetDump::Entry::entry(@_);
1283 } else {
1284 my($class, $p, $valref, $set_sub) = @_;
1285 my $e = $p->_MyNumEntry
1286 (-textvariable => $valref,
1287 -value => $$valref,
1288 -setcmd => sub { $set_sub->() },
1289 -command => sub { $set_sub->() }
1290 )->pack(-side => "left");
1291 $e->bind("<Return>" => $set_sub);
1292 $e;
1293 }
1294 }
1295  
1296 package Tk::WidgetDump::Bool;
1297 sub entry {
1298 my($class, $p, $valref, $set_sub) = @_;
1299 my $e = $p->Checkbutton(-variable => $valref,
1300 -onvalue => 1,
1301 -offvalue => 0,
1302 -command => $set_sub)->pack(-side => "left");
1303  
1304 $e->insert("end", $class->entries);
1305 $e->bind("<Return>" => $set_sub);
1306 $e;
1307 }
1308  
1309 package Tk::WidgetDump::Color;
1310 sub entry {
1311 my($class, $p, $valref, $set_sub) = @_;
1312 require Tk::BrowseEntry;
1313 my $e = $p->BrowseEntry(-textvariable => $valref,
1314 -browsecmd => $set_sub)->pack(-side => "left");
1315  
1316 $e->insert("end", sort
1317 keys %{+{
1318 map { $_ =~ s/^\s+//; ((split(/\s+/, $_, 4))[3] => 1) }
1319 split(/\n/, `showrgb`)
1320 }}
1321 );
1322 $e->bind("<Return>" => $set_sub);
1323 $e;
1324 }
1325  
1326 package Tk::WidgetDump::Background;
1327 use base qw(Tk::WidgetDump::Color);
1328  
1329 package Tk::WidgetDump::HighlightBackground;
1330 use base qw(Tk::WidgetDump::Color);
1331  
1332 package Tk::WidgetDump::HighlightColor;
1333 use base qw(Tk::WidgetDump::Color);
1334  
1335 package Tk::WidgetDump::Foreground;
1336 use base qw(Tk::WidgetDump::Color);
1337  
1338 package Tk::WidgetDump::Font;
1339 sub entry {
1340 my($class, $p, $valref, $set_sub) = @_;
1341 my $f = $p->Frame->pack(-side => "left");
1342 my $e = $p->Entry(-textvariable => $valref)->pack(-side => "left");
1343 $p->Button(-text => "Browse",
1344 -command => sub {
1345 if (!eval { require Tk::FontDialog; 1 }) {
1346 $p->messageBox(-message => "Tk::FontDialog is not installed!");
1347 return;
1348 }
1349 my $new_font = $f->FontDialog(-initfont => $$valref)->Show;
1350 if (defined $new_font) {
1351 $$valref = $new_font;
1352 $set_sub->();
1353 }
1354 }
1355 )->pack(-side => "left");
1356 $e->bind("<Return>" => $set_sub);
1357 $f;
1358 }
1359  
1360 package Tk::WidgetDump::Relief;
1361 use base qw(Tk::WidgetDump::BrowseEntry);
1362 sub entries { qw(raised sunken flat ridge solid groove) }
1363  
1364 package Tk::WidgetDump::Anchor;
1365 use base qw(Tk::WidgetDump::BrowseEntry);
1366 sub entries { qw(center n ne e se s sw w nw) }
1367  
1368 package Tk::WidgetDump::Justify;
1369 use base qw(Tk::WidgetDump::BrowseEntry);
1370 sub entries { qw(left center right) }
1371  
1372 package Tk::WidgetDump::Cursor;
1373 sub entry {
1374 my($class, $p, $valref, $set_sub) = @_;
1375 my $f = $p->Frame->pack(-side => "left");
1376 require Tk::BrowseEntry;
1377 require Tk::Config;
1378 my $e = $p->BrowseEntry(-textvariable => $valref,
1379 -browsecmd => $set_sub)->pack(-side => "left");
1380 (my $xinc = $Tk::Config::xinc) =~ s/^-I//;
1381 if (open(CF, "$xinc/X11/cursorfont.h")) {
1382 while(<CF>) {
1383 chomp;
1384 if (/#define\s+XC_(\S+)/) {
1385 $e->insert("end", $1);
1386 }
1387 }
1388 close CF;
1389 } else {
1390 warn "Can't open cursorfont.h";
1391 }
1392 $p->Button(-text => "Bitmapfile",
1393 -command => sub {
1394 my $file = $f->getOpenFile;
1395 if (defined $file) {
1396 $$valref = ['@' . $file, "black"];
1397 $set_sub->();
1398 }
1399 }
1400 )->pack(-side => "left");
1401 $e->bind("<Return>" => $set_sub);
1402 $f;
1403 }
1404  
1405 $Tk::Config::xinc = $Tk::Config::xinc if 0; # peacify -w
1406  
1407 package Tk::WidgetDump::Command;
1408 use base qw(Tk::WidgetDump::Entry);
1409  
1410 package Tk::WidgetDump::Image;
1411 sub entry {
1412 my($class, $p, $valref, $set_sub) = @_;
1413 my $f = $p->Frame->pack(-side => "left");
1414 my $e = $p->Entry(-textvariable => $valref)->pack(-side => "left");
1415 $p->Button(-text => "Browse",
1416 -command => sub {
1417 my $file = $f->getOpenFile;
1418 if (defined $file) {
1419 my $photo = $p->Photo(-file => $file);
1420 # XXX image cache
1421 if ($photo) {
1422 $$valref = $photo;
1423 $set_sub->();
1424 }
1425 }
1426 }
1427 )->pack(-side => "left");
1428 $e->bind("<Return>" => sub {
1429 if ($$valref eq '') {
1430 undef $$valref;
1431 }
1432 $set_sub->();
1433 });
1434 $f;
1435 }
1436  
1437 package Tk::WidgetDump::Tile;
1438 use base qw(Tk::WidgetDump::Image);
1439  
1440 package Tk::WidgetDump::Bitmap;
1441 sub entry {
1442 my($class, $p, $valref, $set_sub) = @_;
1443 my $f = $p->Frame->pack(-side => "left");
1444 my $e = $p->Entry(-textvariable => $valref)->pack(-side => "left");
1445 $p->Button(-text => "Browse",
1446 -command => sub {
1447 my $file = $f->getOpenFile;
1448 if (defined $file) {
1449 $$valref = '@' . $file;
1450 $set_sub->();
1451 }
1452 }
1453 )->pack(-side => "left");
1454 $e->bind("<Return>" => $set_sub);
1455 $f;
1456 }
1457  
1458 package Tk::WidgetDump::Pixels;
1459 use base qw(Tk::WidgetDump::NumEntry);
1460  
1461 package Tk::WidgetDump::BorderWidth;
1462 use base qw(Tk::WidgetDump::Pixels);
1463  
1464 package Tk::WidgetDump::Height;
1465 use base qw(Tk::WidgetDump::Pixels);
1466  
1467 package Tk::WidgetDump::Width;
1468 use base qw(Tk::WidgetDump::Pixels);
1469  
1470 package Tk::WidgetDump::HighlightThickness;
1471 use base qw(Tk::WidgetDump::Pixels);
1472  
1473 package Tk::WidgetDump::Pad;
1474 use base qw(Tk::WidgetDump::Pixels);
1475  
1476 package Tk::WidgetDump::Underline;
1477 use base qw(Tk::WidgetDump::NumEntry);
1478  
1479 1;
1480  
1481 __END__