blib/lib/Glade/PerlUI.pm untested

filter: Statementstmt 0.0% 0 / 639 Branchbran 0.0% 0 / 342 Conditioncond 0.0% 0 / 116 MC/DCmcdc 0.0% 0 / 71 Subroutinesub 0.0% 0 / 30 Podpod 0.0% 0 / 21 totaltotal 0.0% 0 / 1219 CC 172 SCAR 66.0
CC
172
Cov
0%
internal_pack_widget
2352.0
new_from_child_name
702.0
Widget_from_Proto
380.0
CRAP 736.7
1 package Glade::PerlUI;
2 require 5.000; use strict 'vars', 'refs', 'subs';
3  
4 # Copyright (c) 1999 Dermot Musgrove <dermot.musgrove@virgin.net>
5 #
6 # This library is released under the same conditions as Perl, that
7 # is, either of the following:
8 #
9 # a) the GNU General Public License as published by the Free
10 # Software Foundation; either version 1, or (at your option) any
11 # later version.
12 #
13 # b) the Artistic License.
14 #
15 # If you use this library in a commercial enterprise, you are invited,
16 # but not required, to pay what you feel is a reasonable fee to perl.org
17 # to ensure that useful software is available now and in the future.
18 #
19 # (visit http://www.perl.org/ or email donors@perlmongers.org for details)
20  
21 BEGIN {
22 use UNIVERSAL qw( can ); # in lots of subs
23 use Gtk qw( ); # Everywhere
24 # Comment out the line below if you have a really old version of Gtk-Perl
25 use Gtk::Keysyms;
26 use Glade::PerlSource qw( :VARS :METHODS );
27 use Glade::PerlUIGtk qw( :VARS );;
28 use Glade::PerlUIExtra;
29 use vars qw(
30 @ISA
31 $PACKAGE $VERSION $AUTHOR $DATE
32 @EXPORT @EXPORT_OK %EXPORT_TAGS
33 @VARS @METHODS
34  
35 $gnome_widgets
36 $gnome_db_widgets
37 $gnome_libs_depends
38 $gtk_perl_depends
39 $gtk_perl_cant_do
40 $concept_widgets
41 $ignore_widgets
42 $ignored_widgets
43 $missing_widgets
44 $cxx_properties
45 $dialogs
46 $composite_widgets
47 $toplevel_widgets
48 );
49  
50 $ignored_widgets = 0;
51 $missing_widgets = 0;
52 $PACKAGE = __PACKAGE__;
53 $VERSION = q(0.61);
54 $AUTHOR = q(Dermot Musgrove <dermot.musgrove@virgin.net>);
55 $DATE = q(Sun Nov 17 03:21:11 GMT 2002);
56 @METHODS = qw( );
57 @VARS = qw(
58 $gnome_widgets
59 $gnome_db_widgets
60 $gnome_libs_depends
61 $gtk_perl_depends
62 $gtk_perl_cant_do
63 $concept_widgets
64 $ignore_widgets
65 $ignored_widgets
66 $missing_widgets
67 $cxx_properties
68 $dialogs
69 $composite_widgets
70 $toplevel_widgets
71 );
72 # Tell interpreter who we are inheriting from
73 @ISA = qw( Glade::PerlUIGtk Glade::PerlUIExtra );
74 # These symbols (globals and functions) are always exported
75 @EXPORT = qw( );
76 # Optionally exported package symbols (globals and functions)
77 @EXPORT_OK = ( @METHODS, @VARS );
78 # Tags (groups of symbols) to export
79 %EXPORT_TAGS = (
80 'METHODS' => [@METHODS] ,
81 'VARS' => [@VARS]
82 );
83 }
84  
85 sub DESTROY {
86 # This sub will be called on object destruction
87 } # End of sub DESTROY
88  
89 #===============================================================================
90 #=========== Constants and globals ====
91 #===============================================================================
92 $gnome_libs_depends = {
93 'MINIMUM REQUIREMENTS' => '1.2.0',
94 };
95  
96 $gtk_perl_depends = {
97 'MINIMUM REQUIREMENTS' => '0.7000',
98 'LATEST_CPAN' => '0.7008',
99 'LATEST_CVS' => '20010629',
100
101 '0.6123' => '19990818',
102 '0.7000' => '20000102',
103 '0.7001' => '20000123',
104 '0.7002' => '20000129',
105 '0.7003' => '20000816',
106 '0.7004' => '20001020',
107 '0.7005' => '20010219',
108 '0.7006' => '20010328',
109 '0.7007' => '20010601',
110 '0.7008' => '20010629',
111  
112 # Those below don't work yet even in the latest CVS version
113 'GnomeDbGrid' => '99999999',
114 'GnomeDbList' => '99999999',
115 'GnomeDbCombo' => '99999999',
116 'GnomeDbReport' => '99999999',
117 'GnomeDbError' => '99999999',
118 'GnomeDbLogin' => '99999999',
119 'GnomeDbBrowser' => '99999999',
120 'GnomeDbErrorDlg' => '99999999',
121 'GnomeDbLoginDlg' => '99999999',
122  
123 # Those below work in the CPAN version after 0.7003 (CVS after 20000410)
124 'gtk_pixmap_menu_item' => '20000410',
125 # Those below work in the CPAN version after 0.7003 (CVS after 20000301)
126 'gnome_dialog_append_button'
127 => '20000301',
128 # Those below work in the CPAN version after 0.7002 (CVS after 20000129)
129 'Gnome::UIInfo' => '0.7002',
130  
131 };
132  
133 $gtk_perl_cant_do = {
134 # Those below will NOT work in specific version
135 'GtkDial' => '0.7005',
136 };
137  
138 $cxx_properties = join(' ',
139 'cxx_separate_class',
140 'cxx_separate_file',
141 'cxx_use_heap',
142 'cxx_visibility',
143 );
144  
145 $ignore_widgets = join (' ',
146 'Placeholder',
147 'Custom',
148 );
149  
150 $dialogs = join(' ',
151 'Gnome::About',
152 'Gnome::App',
153 'Gnome::Dialog',
154 'Gnome::MessageBox',
155 'Gnome::PropertyBox',
156 'Gtk::ColorSelectionDialog',
157 'Gtk::Dialog',
158 'Gtk::FileSelection',
159 'Gtk::FontSelectionDialog',
160 'Gtk::InputDialog',
161 );
162  
163 $toplevel_widgets = join(' ',
164 'Gnome::About',
165 'Gnome::App',
166 'Gnome::Dialog',
167 'Gnome::MessageBox',
168 'Gnome::PropertyBox',
169 'Gtk::Dialog',
170 'Gtk::InputDialog',
171 'Gtk::Window',
172 );
173  
174 $composite_widgets = join(' ',
175 'Gnome::Entry',
176 'Gnome::FileEntry',
177 'Gnome::NumberEntry',
178 'Gnome::PixmapEntry',
179 'Gtk::Combo',
180 );
181  
182 $gnome_widgets = join( " ",
183 'GnomeAbout',
184 'GnomeApp',
185 'GnomeAppBar',
186 'GnomeCalculator',
187 'GnomeColorPicker',
188 'GnomeDateEdit',
189 'GnomeDialog',
190 'GnomeDock',
191 'GnomeDockItem',
192 'GnomeDruid',
193 'GnomeDruidPageFinish',
194 'GnomeDruidPageStandard',
195 'GnomeDruidPageStart',
196 'GnomeEntry',
197 'GnomeFileEntry',
198 'GnomeFontPicker',
199 'GnomeHRef',
200 'GnomeIconEntry',
201 'GnomeIconList',
202 'GnomeIconSelection',
203 'GnomeLess',
204 'GnomeMessageBox',
205 'GnomeNumberEntry',
206 'GnomePaperSelector',
207 'GnomePixmap',
208 'GnomePixmapEntry',
209 'GnomePropertyBox',
210 'GnomeSpell',
211 'GtkCalendar', # In Gtk after CVS-19990914
212 'GtkClock',
213 'GtkDial',
214 'GtkPixmapMenuItem',
215 );
216  
217 $gnome_db_widgets = join( " ",
218 'GnomeDbGrid',
219 'GnomeDbList',
220 'GnomeDbCombo',
221 'GnomeDbReport',
222 'GnomeDbError',
223 'GnomeDbLogin',
224 'GnomeDbBrowser',
225 'GnomeDbErrorDlg',
226 'GnomeDbLoginDlg',
227 );
228  
229 #===============================================================================
230 #=========== Version utilities ============
231 #===============================================================================
232 sub my_gtk_perl_can_do {
233 my ($class, $action) = @_;
234 my $depends = $gtk_perl_depends->{$action} || '';
235 my $cant_do = $gtk_perl_cant_do->{$action} || '';
236 unless ($depends or $cant_do) {
237 # There is no required/cant_do information for $action
238 return 1;
239 }
240 my ($cpan, $cvs);
241 my $check = $action;
242  
243 # Check that we have at least the minimum required
244 $check = $gtk_perl_depends->{$depends} || $depends;
245 if ($check and $check > $Glade_Perl->glade2perl->my_gtk_perl) {
246 $cpan = $gtk_perl_depends->{'LATEST_CPAN'};
247 $cpan = $gtk_perl_depends->{$cpan} if $gtk_perl_depends->{$cpan};
248 if ($check > $cpan) {
249 # We need a CVS version
250 if ($check > $gtk_perl_depends->{'LATEST_CVS'}) {
251 # The CVS version can't even do it yet
252 $Glade_Perl->diag_print(1,
253 "warn Gtk-Perl dated %s cannot do '%s' (properly)".
254 " and neither can the CVS version !!!",
255 $Glade_Perl->glade2perl->my_gtk_perl, $action);
256
257 } else {
258 # We need a new CVS version
259 $Glade_Perl->diag_print(1,
260 "warn Gtk-Perl dated %s cannot do '%s' (properly)".
261 " we need CVS module 'gnome-perl' after %s",
262 $Glade_Perl->glade2perl->my_gtk_perl, $action, $check);
263 }
264  
265 } else {
266 # We need a new CPAN version
267 $Glade_Perl->diag_print(1,
268 "warn Gtk-Perl version %s cannot do '%s' (properly)".
269 " we need CPAN version %s or CVS module 'gnome-perl' after %s",
270 $Glade_Perl->glade2perl->my_gtk_perl, $action,
271 $gtk_perl_depends->{$action}, $check);
272 }
273 return undef;
274 }
275  
276 # Check that we dont have a cant_do version
277 $check = $gtk_perl_depends->{$cant_do} || $cant_do;
278 unless ($check and $check == $Glade_Perl->glade2perl->my_gtk_perl) {
279 # We can do required $action in our version
280 return 1;
281 } else {
282 # This version can't do it although earlier and later versions may
283 $Glade_Perl->diag_print(1,
284 "warn Gtk-Perl dated %s cannot do '%s' (properly)".
285 " although older and newer versions may",
286 $Glade_Perl->glade2perl->my_gtk_perl, $action);
287 return undef;
288 }
289 return undef;
290 }
291  
292 sub my_gnome_libs_can_do {
293 my ($class, $action) = @_;
294 my $depends = $gnome_libs_depends->{$action};
295 unless ($depends and $depends gt $Glade_Perl->glade2perl->my_gnome_libs) {
296 # There is no specified version or ours is sufficient
297 return 1;
298 }
299 if ($depends ge 19990914) {
300 # We need a CVS version
301 if ($depends gt 29990000) {
302 # The CVS version can't even do it yet
303 $Glade_Perl->diag_print(1,
304 "warn gnome_libs version %s cannot do '%s' (properly)".
305 " and neither can the CVS version !!!",
306 $Glade_Perl->glade2perl->my_gnome_libs, $action);
307 } else {
308 # We need a new CVS version
309 $Glade_Perl->diag_print(1,
310 "warn gnome_libs version %s cannot do '%s' (properly)".
311 " we need CVS module 'gnome-libs' after %s",
312 $Glade_Perl->glade2perl->my_gnome_libs, $action, $depends);
313 }
314 } else {
315 # We need a new released version
316 $Glade_Perl->diag_print(1,
317 "warn gnome_libs version %s cannot do '%s' (properly)".
318 " we need version %s",
319 $Glade_Perl->glade2perl->my_gnome_libs, $action, $depends);
320 }
321 return undef;
322 }
323  
324 #===============================================================================
325 #=========== Utilities to construct UI ============
326 #===============================================================================
327 sub use_par {
328 my ($class, $proto, $key, $request, $default, $dont_undef) = @_;
329 my $me = "$class->use_par";
330  
331 my $type;
332 my $self = $proto->{$key};
333 unless (defined $self) {
334 if (defined $default) {
335 $self = $default;
336 # $Glade_Perl->diag_print (8, "$indent- No value in proto->{'$key'} ".
337 # "so using DEFAULT of '$default' in $me");
338 } else {
339 # We have no value and no default to use so bail out here
340 $Glade_Perl->diag_print (1, "error No value in supplied ".
341 "%s and NO default was supplied in ".
342 "%s called from %s line %s",
343 "$proto->{'name'}\->{'$key'}", $me, (caller)[0], (caller)[2] );
344 return undef;
345 }
346 } else {
347 # We have a value to use
348 # $Glade_Perl->diag_print (8, "$indent- Value supplied in ".
349 # "proto->{'$key'} was '$self'");
350 }
351 # We must have some sort of value to use by now
352 unless ($request) {
353 # Nothing to do, we are already $proto->{$key} so
354 # just drop through to undef the supplied prot->{$key}
355 # $Glade_Perl->diag_print(8, "I have used par->{'$key'} => '$self' in $me");
356
357 } elsif ($request eq $DEFAULT) {
358 # Nothing to do, we are already $proto->{$key} (or default) so
359 # just drop through to undef the supplied prot->{$key}
360 # $Glade_Perl->diag_print(8, "I have converted '$key' from ".
361 # ($proto->{$key} || 'undef')." to default ('$self') in $me");
362
363 } elsif ($request == $LOOKUP) {
364 return '' unless $self;
365
366 my $lookup;
367 # make an effort to convert from Gtk to Gtk-Perl constant/enum name
368 if ($self =~ /^GNOME/) {
369 $lookup = Glade::PerlUIExtra->lookup($self);
370  
371 } else {
372 $lookup = Glade::PerlUIGtk->lookup($self);
373 }
374 unless ($lookup) {
375 if (defined $default) {
376 $Glade_Perl->diag_print(2,
377 "warn Unable to lookup '%s' using default of '%s'",
378 $self, $default);
379 $self = $default;
380 } else {
381 $Glade_Perl->diag_print(1,
382 "error Unable to lookup '%s' and no default",
383 $self);
384 }
385 } else {
386 $self = $lookup;
387 }
388
389 # $Glade_Perl->diag_print(8, "$indent- I have converted '$key' from '".
390 # ($proto->{$key} || $default)."' to '$self' (LOOKUP) in $me");
391  
392 } elsif ($request == $BOOL) {
393 # Now convert whatever we have ended up with to a BOOL
394 # undef becomes 0 (== false)
395 $type = $self;
396 $self = ('*true*y*yes*on*1*' =~ m/\*$self\*/i) ? '1' : '0';
397 # $Glade_Perl->diag_print(8, "$indent- I have converted proto->{'$key'} ".
398 # "from '$type' to $self (BOOL) in $me");
399  
400 } elsif ($request == $KEYSYM) {
401 $self =~ s/GDK_//;
402 ## If you have an old version of Gtk-Perl that doesn't have Gtk::Keysyms
403 ## use the next line instead of the Gtk::Keysyms{$self} line below it
404 ## $self = ord ($self );
405 # $self = $Gtk::Keysyms{$self} || Gtk::Gdk->keyval_from_name($self);
406 ## $Glade_Perl->diag_print(8, "$indent- I have converted '$key' from ".
407 ## ($proto->{$key})." to '$self' (Gtk::Keysyms)in $me");
408 }
409 # undef the parameter so that we can report any unused attributes later
410 undef $proto->{$key} unless $dont_undef;
411 # Backslash escape any single quotes (unless they are already backslashed)
412 $self =~ s/(?!\\)(.)'/$1\\'/g;
413 $self =~ s/^'/\\'/g;
414 return "$self";
415 }
416  
417 sub construct_widget {
418 my ($class, $parentname, $proto, $depth, $wh, $ch) = @_;
419 my $me = "$class->prepare_widget";
420 my ($widget_hierarchy, $class_hierarchy);
421 my ($name, $constructor, $expr);
422 unless ($proto->{name}) {
423 $Glade_Perl->diag_print (2,
424 "You have supplied a proto without a name to %s", $me);
425 $Glade_Perl->diag_print (2, $proto);
426 } else {
427 $name = $proto->{name};
428  
429 }
430 if ($depth == 1) {
431 $name = $class->fix_name($name);
432 $forms->{$name} = {};
433 if (keys %{$forms->{$name}}) {
434 die "You have already defined a form called '$name'";
435 }
436  
437 # We are a toplevel window so create a new hash and
438 # set $current_form with its name
439 # All these back-slashes are really necessary as this string
440 # is passed through so many others
441 $current_form_name = "$name-\\\\\\\$instance";
442 $current_form = "\$forms->{'$name'}";
443 $current_data = "\$data->{'$name'}\{__DATA}";
444 $current_name = $name;
445 $current_window = "\$forms->{'$name'}\{'$name'}";
446 $first_form ||= $name;
447  
448 if ($Glade_Perl->source->hierarchy =~ /^(widget|both)/) {
449 $widget_hierarchy = "\$forms->{'$name'}{__WH}";
450 }
451 if ($Glade_Perl->source->hierarchy =~ /^(class|both)/) {
452 $class_hierarchy = "\$forms->{'$name'}{__CH}";
453 }
454  
455 } else {
456 $widget_hierarchy = "$wh\{'$name'}" if $wh;
457 $class_hierarchy = "$ch\{'$proto->{class}'}{'$name'}" if $ch;
458 }
459 $class->add_to_UI( $depth, "#" );
460 $class->add_to_UI( $depth, "# ".S_("Construct a").
461 " $proto->{class} '$name'");
462 $constructor = "new_$proto->{class}";
463 if ($class->can($constructor)) {
464 # Construct the widget
465 my $eval_class = 'Glade::PerlProject';#ref $class || $class;
466 $expr = "\$widgets->{'$name'} = ".
467 "$eval_class->$constructor('$parentname', \$proto, $depth );";
468 eval $expr or
469 ($@ && die "\nin $me\n\t".("while trying to eval").
470 " '$expr'\n\t".("FAILED with Eval error")." '$@'\n" );
471 if ($widget_hierarchy) {
472 # Add to form widget hierarchy
473 $class->add_to_UI( $depth,
474 "$widget_hierarchy\{__W} = $current_form\{'$name'};" );
475 # "\$class->W($widget_hierarchy, $current_form\{'$name'});" );
476 # if ($Glade_Perl->source->hierarchy =~ /order/) {
477 # if ($depth > 1) {
478 # $class->add_to_UI( $depth,
479 # "push \@{$wh\{__C}}, $current_form\{'$name'};" );
480 ## "\$class->C($wh, $current_form\{'$name'});" );
481 # }
482 # }
483 }
484 if ($class_hierarchy) {
485 # Add to form class hierarchy
486 $class->add_to_UI( $depth,
487 "$class_hierarchy\{__W} = $current_form\{'$name'};" );
488 # "\$class->W($class_hierarchy, $current_form\{'$name'});" );
489 # if ($Glade_Perl->source->hierarchy =~ /order/) {
490 # if ($depth > 1) {
491 # $class->add_to_UI( $depth,
492 # "push \@{$ch\{__C}}, $current_form\{'$name'};" );
493 ## "\$class->C($ch, $current_form\{'$name'});" );
494 # }
495 # }
496 }
497 if ($Glade_Perl->source->hierarchy =~ /order/) {
498 if ($depth > 1) {
499 $class->add_to_UI( $depth,
500 "push \@{$wh\{__C}}, $current_form\{'$name'};" );
501 }
502 }
503 } else {
504 $Glade_Perl->diag_print(1, "error I don't have a constructor called '%s'".
505 "- I guess that it isn't written yet :-)",
506 "$class->$constructor");
507 }
508 return ($widget_hierarchy, $class_hierarchy);
509 }
510  
511 sub new_sub_widget {
512 my ($class, $parentname, $proto, $depth, $wh, $ch) = @_;
513 my $me = "$class->new_sub_widget";
514 my $childname;
515 if ($class->my_gtk_perl_can_do($proto->{'class'})) {
516 unless (" $ignore_widgets " =~ / $proto->{'class'} /) {
517 # This is a real widget subhash so recurse to expand
518 $childname = $class->Widget_from_Proto(
519 $parentname, $proto, $depth,
520 $wh, $ch );
521 $class->set_child_packing(
522 $parentname, $childname, $proto, $depth );
523 if ($Glade_Perl->diagnostics) {
524 # Check that we have used all widget properties
525 $class->check_for_unused_elements($proto);
526 }
527  
528 } else {
529 unless (" $gnome_widgets " =~ / $proto->{'class'} /) {
530 $Glade_Perl->diag_print(3,
531 "warn %s in %s ignored in %s",
532 $proto->{'class'}, $parentname, $me);
533 } else {
534 $Glade_Perl->diag_print(1, "error %s in %s ignored in %s",
535 $proto->{'class'}, ($parentname || 'Glade project'), $me);
536 }
537 $ignored_widgets++;
538 }
539 }
540 return $childname;
541 }
542  
543 sub Widget_from_Proto {
544 my ($class, $parentname, $proto, $depth, $wh, $ch) = @_;
545 my $me = "$class->Widget_from_Proto";
546 #$Glade_Perl->diag_print(2, $forms);
547 my $typekey = $class->typeKey;
548 my ($name, $widget_hierarchy, $class_hierarchy, $childname,
549 $window, $sig);
550 my ($key, $dm, $self, $expr, $object, $refself, $packing );
551 $parentname ||= "Top level application";
552  
553 if ($depth) {
554 # We are a widget of some sort (toplevel window or child)
555 ($widget_hierarchy, $class_hierarchy) =
556 $class->construct_widget($parentname, $proto, $depth, $wh, $ch);
557  
558 } else {
559 # We are a complete GTK-Interface - ie we are the application
560 #$Glade_Perl->diag_print(2, $proto);
561 unless ($Glade_Perl->app->allow_gnome) {
562 $ignore_widgets .= " $gnome_widgets";
563 }
564 unless ($Glade_Perl->app->allow_gnome_db) {
565 $ignore_widgets .= " $gnome_db_widgets";
566 }
567 }
568  
569 $self = $widgets->{$proto->{name}};
570 $refself = ref $self;
571  
572 # Iterate through keys looking for sub widgets and properties
573 foreach $key (sort keys %{$proto}) {
574 if (ref $proto->{$key} eq 'HASH') {
575 # this is a ref to a sub hash so expand it
576 $object = $proto->{$key}{$typekey};
577 if ($object) {
578 #$Glade_Perl->diag_print(2, "Considering $key $object");
579 if ( $object eq 'widget') {
580 $childname = $class->new_sub_widget(
581 $proto->{name}, $proto->{$key}, $depth+1,
582 $widget_hierarchy, $class_hierarchy);
583  
584 } elsif ($object eq 'signal') {
585 # we are a SIGNAL
586 $class->new_signal(
587 $proto->{name}, $proto->{$key}, $depth );
588  
589 } elsif ($object eq 'accelerator') {
590 # we are an ACCELERATOR
591 $class->new_accelerator(
592 $proto->{name}, $proto->{$key}, $depth );
593  
594 } elsif ($object eq 'style') {
595 # Perhaps should be in set_widget_properties
596 if ($current_form) {
597 $class->new_style(
598 $proto->{name}, $proto->{$key}, $depth );
599 }
600  
601 } elsif ($object eq 'project') {
602 # We rely on this appearing before the rest of the proto
603 # so that we know which files to write (if needed)
604 # It was dealt with in new_from_Glade so just ignore it
605  
606 } elsif ($object eq 'child') {
607 # Already dealt with above so just ignore it
608  
609 } else {
610 # I don't recognise it so do nothing but report it
611 $Glade_Perl->diag_print (1, "error Object '%s' not recognised ".
612 "or processed for %s '%s' by %s",
613 $object, $proto->{'class'}, $proto->{name}, $me);
614 $Glade_Perl->diag_print(1, $proto);
615 }
616  
617 # } else {
618 # # I don't recognise it so do nothing but report it
619 # $Glade_Perl->diag_print (1, "error Undefined object for %s '%s' by $s".
620 # $proto->{'class'}, '$proto->{name}', $me );
621 # $Glade_Perl->diag_print(1, $proto);
622 }
623 } elsif (ref $proto->{$key} eq 'ARRAY') {
624 # We are a new type array of widgets so construct each in order
625 }
626 }
627 #================== Check this and TIDY it up
628 if ($depth == 1) {
629 # We are a toplevel window so now connect all signals
630 if (eval "scalar(\@{${current_form}\{Signal_Strings}})") {
631 # We have some signals to connect
632 $class->add_to_UI( $depth, "#" );
633 $class->add_to_UI( $depth,
634 "# ".S_("Connect all signals now that widgets are constructed" ));
635 $expr = "foreach \$sig (\@{${current_form}\{Signal_Strings}}) {
636 eval \$sig;
637 }";
638 eval $expr;
639 }
640 }
641 unless ($depth) {
642 # We are the Application level (above all toplevel windows)
643 return $childname;
644 } elsif ($proto->{name}) {
645 # We are the bottom widget in the branch of the proto tree
646 return $proto->{name};
647 } elsif ($childname) {
648 # We are somewhere in the middle of the tree
649 return $childname;
650 } else {
651 # What has happened?
652 die 'error $me - failed to return anything';
653 }
654 }
655  
656 #===============================================================================
657 #=========== Utilities to build UI ============
658 #===============================================================================
659 sub internal_pack_widget {
660 my ($class, $parentname, $childname, $proto, $depth) = @_;
661 my $me = "$class->internal_pack_widget";
662 my $refpar;
663 # When we add/pack/append we do it to ${current_form}->{$parentname}
664 # rather than $widgets->{$parentname} so that we are sure that everything
665 # is packed in the right order and we can check for duplicate names
666 my $refwid = (ref $widgets->{$childname} );
667 my $child_type;
668 my $postpone_show;
669 if ($current_form && eval "exists ${current_form}\{'$childname'}") {
670 die sprintf(("\nerror %s - There is already a widget called ".
671 "'%s' constructed and packed - I will not overwrite it !"),
672 $me, $childname);
673 }
674 if (" $dialogs $toplevel_widgets " =~ m/ $refwid /) {
675 # We are a window so don't have a parent to pack into
676 $Glade_Perl->diag_print (4, "%s- Constructing a toplevel component ".
677 "(window/dialog) '%s'", $indent, $childname);
678 # $child_type = $widgets->{$childname}->type;
679 # if (' toplevel dialog '=~ m/ $child_type /) {
680 # Add a default delete_event signal connection
681 $class->add_to_UI($depth,
682 "${current_form}\{'tooltips'} = new Gtk::Tooltips;" );
683 $class->add_to_UI($depth,
684 "${current_form}\{'accelgroup'} = new Gtk::AccelGroup;" );
685 $class->add_to_UI( $depth,
686 "${current_form}\{'accelgroup'}->attach(\$widgets->{'$childname'} );" );
687 # } else {
688 # die "\nerror F$me $indent- This is a $child_type type Window".
689 # " - what should I do?";
690 # }
691 $postpone_show = 1;
692  
693 } else {
694 # We probably have a parent to pack into somehow
695 eval "\$refpar = (ref ${current_form}\{'$parentname'})||'UNDEFINED !!';";
696 unless (eval "exists ${current_form}\{'$parentname'}") {
697 if ($Glade_Perl->source->quick_gen or 'Gtk::Menu' eq $refwid) {
698 # We are a popup menu so we don't have a root window
699 # $class->add_to_UI( $depth, "${first_form}->popup_enable;" );
700 $class->add_to_UI($depth,
701 "${current_form}\{'tooltips'} = new Gtk::Tooltips;" );
702 $class->add_to_UI($depth,
703 "${current_form}\{'accelgroup'} = new Gtk::AccelGroup;" );
704 $class->add_to_UI( $depth,
705 "${current_form}\{'accelgroup'}->attach(\$widgets->{'$childname'} );" );
706 $postpone_show = 1;
707 } else {
708 die sprintf(("\nerror %s - Unable to find a widget called '%s' - ".
709 "I can not pack widget '%s' into a non-existant widget!"),
710 $me, $parentname, $childname);
711 }
712 }
713 if ($postpone_show) {
714 # Do nothing
715
716 #---------------------------------------
717 } elsif (" $composite_widgets " =~ m/ $refpar /) {
718 # We do not need to do anything for this widget
719
720 #---------------------------------------
721 } elsif (eval "${current_form}\{'$parentname'}->can(".
722 "'query_child_packing')") {# and !defined $proto->{'child_name'}) {
723 # We have a '$refpar' widget '$parentname' that can query_child_packing
724 my $ignore = $class->use_par($proto, 'child_name', $DEFAULT, '' );
725 $class->add_to_UI( $depth,
726 "${current_form}\{'$parentname'}->add(".
727 "\$widgets->{'$childname'} );");
728  
729 #---------------------------------------
730 } elsif (' Gtk::CList ' =~ m/ $refpar /) {
731 $child_type = $class->use_par($proto, 'child_name', $DEFAULT, '' );
732 if ($child_type eq 'CList:title') {
733 # We are a CList column widget (title widget)
734 $class->add_to_UI( $depth,
735 "${current_form}\{'$parentname'}->set_column_widget(".
736 "$CList_column, \$widgets->{'$childname'} );" );
737 $CList_column++;
738 } else {
739 $Glade_Perl->diag_print (1,
740 "error I don't know what to do with %s element %s",
741 $refpar, $child_type);
742 }
743  
744 #---------------------------------------
745 } elsif (' Gtk::CTree ' =~ m/ $refpar /) {
746 $child_type = $class->use_par($proto, 'child_name', $DEFAULT, '' );
747 if ($child_type eq 'CTree:title') {
748 # We are a CTree column widget (title widget)
749 $class->add_to_UI( $depth,
750 "${current_form}\{'$parentname'}->set_column_widget(".
751 "$CTree_column, \$widgets->{'$childname'} );" );
752 $CTree_column++;
753 } else {
754 $Glade_Perl->diag_print (1,
755 "error I don't know what to do with %s element %s".
756 $refpar, $child_type);
757 }
758  
759 #---------------------------------------
760 } elsif (' Gtk::Layout ' =~ m/ $refpar /) {
761 # $Glade_Perl->diag_print(2, $proto);
762 my $x = $class->use_par($proto, 'x');
763 my $y = $class->use_par($proto, 'y');
764 # my $width = $class->use_par($proto, 'width');
765 # my $height = $class->use_par($proto, 'height');
766 $class->add_to_UI( $depth,
767 "${current_form}\{'$parentname'}->put(".
768 "\$widgets->{'$childname'}, $x, $y);" );
769  
770 #---------------------------------------
771 } elsif (' Gtk::MenuBar Gtk::Menu ' =~ m/ $refpar /) {
772 # We are a menuitem
773 $class->add_to_UI( $depth,
774 "${current_form}\{'$parentname'}->append(".
775 "\$widgets->{'$childname'} );" );
776  
777 #---------------------------------------
778 } elsif (' Gtk::MenuItem Gtk::PixmapMenuItem ' =~ m/ $refpar /) {
779 # We are a menu for a meuitem
780 $class->add_to_UI( $depth,
781 "${current_form}\{'$parentname'}->set_submenu(".
782 "\$widgets->{'$childname'} );" );
783 $postpone_show = 1;
784  
785 #---------------------------------------
786 } elsif (' Gtk::OptionMenu ' =~ m/ $refpar /) {
787 # We are a menu for an optionmenu
788 $class->add_to_UI( $depth,
789 "${current_form}\{'$parentname'}->set_menu(".
790 "\$widgets->{'$childname'} );" );
791 $postpone_show = 1;
792  
793 #---------------------------------------
794 } elsif (' Gtk::Notebook ' =~ m/ $refpar /) {
795 $child_type = $class->use_par($proto, 'child_name', $DEFAULT, '' );
796 if ($child_type eq 'Notebook:tab') {
797 # We are a notebook tab widget (eg label) so we can add the
798 # previous notebook page with ourself as the label
799 unless ($nb->{$parentname}{'panes'}[$nb->{$parentname}{'tab'}]) {
800 $Glade_Perl->diag_print (1, "warn There is no widget on the ".
801 "notebook page linked to notebook tab '%s' - ".
802 "a Placeholder label was used instead",
803 $childname);
804 my $message = sprintf(S_("This is a message generated by %s\n\n".
805 "No widget was specified for the page linked to\n".
806 "notebook tab \"%s\"\n\n".
807 "You should probably use Glade to create one"),
808 $PACKAGE, $childname);
809 $class->add_to_UI( $depth,
810 "${current_form}\{'Placeholder_label'} = ".
811 "new Gtk::Label('$message');");
812 $class->add_to_UI( $depth,
813 "${current_form}\{'Placeholder_label'}->show;");
814 $nb->{$parentname}{'panes'}[$nb->{$parentname}{'tab'}] =
815 'Placeholder_label';
816 }
817 $class->add_to_UI( $depth,
818 "${current_form}\{'$parentname'}->append_page(".
819 "${current_form}\{'$nb->{$parentname}{'panes'}[$nb->{$parentname}{'tab'}]'}, ".
820 "\$widgets->{'$childname'} );" );
821 $nb->{$parentname}{'tab'}++;
822  
823 } else {
824 # We are a notebook page so just store for adding later
825 # when we get the tab widget
826 push @{$nb->{$parentname}{'panes'}}, $childname;
827 $nb->{$parentname}{'pane'}++;
828 }
829  
830 #---------------------------------------
831 } elsif (' Gtk::Packer ' =~ m/ $refpar /) {
832 my $anchor = $class->use_par($proto->{'child'}, 'anchor', $LOOKUP, 'center', 'DONT_UNDEF');
833 my $side = $class->use_par($proto->{'child'}, 'side', $LOOKUP, 'top', 'DONT_UNDEF');
834 my $expand = $class->use_par($proto->{'child'}, 'expand', $BOOL, 'False', 'DONT_UNDEF');
835 my $xfill = $class->use_par($proto->{'child'}, 'xfill', $BOOL, 'False', 'DONT_UNDEF');
836 my $yfill = $class->use_par($proto->{'child'}, 'yfill', $BOOL, 'False', 'DONT_UNDEF');
837 my $use_default = $class->use_par($proto->{'child'}, 'use_default', $BOOL,'True', 'DONT_UNDEF');
838 my $options = "";
839 if ($expand) {
840 $options .= "'expand', ";
841 }
842 $xfill && ($options .= "'fill_x', ");
843 $yfill && ($options .= "'fill_y', ");
844 $options =~ s/, $//;
845 if ($options) {$options = "[$options]";} else {$options = "[]";}
846 if ($use_default) {
847 $class->add_to_UI( $depth,
848 "${current_form}\{'$parentname'}->add_defaults(".
849 "\$widgets->{'$childname'}, ".
850 "'$side', '$anchor', $options);" );
851 } else {
852 my $border_width = $class->use_par($proto->{'child'}, 'border_width', $DEFAULT, 0, 'DONT_UNDEF');
853 my $xipad = $class->use_par($proto->{'child'}, 'xipad', $DEFAULT, 0, 'DONT_UNDEF');
854 my $xpad = $class->use_par($proto->{'child'}, 'xpad', $DEFAULT, 0, 'DONT_UNDEF');
855 my $yipad = $class->use_par($proto->{'child'}, 'yipad', $DEFAULT, 0, 'DONT_UNDEF');
856 my $ypad = $class->use_par($proto->{'child'}, 'ypad', $DEFAULT, 0, 'DONT_UNDEF');
857 $class->add_to_UI( $depth,
858 "${current_form}\{'$parentname'}->add(".
859 "\$widgets->{'$childname'}, ".
860 "'$side', '$anchor', $options, $border_width, ".
861 "$xpad, $ypad, $xipad, $yipad);" );
862 }
863
864 #---------------------------------------
865 } elsif (' Gtk::ScrolledWindow ' =~ m/ $refpar /) {
866 if (' Gtk::CList Gtk::CTree Gtk::Text Gnome::IconList ' =~ m/ $refwid /) {
867 # These handle their own scrolling and
868 # Ctree/CList column labels stay fixed
869 $class->add_to_UI( $depth,
870 "${current_form}\{'$parentname'}->add(".
871 "\$widgets->{'$childname'} );" );
872  
873 } else {
874 $class->add_to_UI( $depth,
875 "${current_form}\{'$parentname'}->add_with_viewport(".
876 "\$widgets->{'$childname'} );" );
877 }
878
879 #---------------------------------------
880 } elsif (' Gtk::Table ' =~ m/ $refpar /) {
881 # We are adding to a table so do the child packing
882 my $left_attach = $class->use_par($proto->{'child'}, 'left_attach' );
883 my $right_attach = $class->use_par($proto->{'child'}, 'right_attach' );
884 my $top_attach = $class->use_par($proto->{'child'}, 'top_attach' );
885 my $bottom_attach = $class->use_par($proto->{'child'}, 'bottom_attach' );
886  
887 my (@xoptions, @yoptions);
888 my ($xoptions, $yoptions);
889 push @xoptions, 'expand' if $class->use_par($proto->{'child'}, 'xexpand', $BOOL, 'True' );
890 push @xoptions, 'fill' if $class->use_par($proto->{'child'}, 'xfill', $BOOL, 'True' );
891 push @xoptions, 'shrink' if $class->use_par($proto->{'child'}, 'xshrink', $BOOL, 'False');
892 push @yoptions, 'expand' if $class->use_par($proto->{'child'}, 'yexpand', $BOOL, 'True' );
893 push @yoptions, 'fill' if $class->use_par($proto->{'child'}, 'yfill', $BOOL, 'True' );
894 push @yoptions, 'shrink' if $class->use_par($proto->{'child'}, 'yshrink', $BOOL, 'False');
895 if (scalar @xoptions) {$xoptions = "['".join("', '", @xoptions)."']"} else {$xoptions = '[]'};
896 if (scalar @yoptions) {$yoptions = "['".join("', '", @yoptions)."']"} else {$yoptions = '[]'};
897  
898 my $xpad = $class->use_par($proto->{'child'}, 'xpad', $DEFAULT, 0 );
899 my $ypad = $class->use_par($proto->{'child'}, 'ypad', $DEFAULT, 0 );
900  
901 $class->add_to_UI( $depth,
902 "${current_form}\{'$parentname'}->attach(".
903 "\$widgets->{'$childname'}, ".
904 "$left_attach, $right_attach, $top_attach, $bottom_attach, ".
905 "$xoptions, $yoptions, $xpad, $ypad );" );
906
907 #---------------------------------------
908 } elsif (' Gtk::Toolbar ' =~ m/ $refpar /) {
909 # FIXME - toolbar buttons with a removed label don't have a child_name
910 # but can have a sub-widget. allow for this
911 # test all possibilities
912 # Untested possibilities
913 # 4 Other type of widget
914 my $tooltip = $class->use_par($proto, 'tooltip', $DEFAULT, '' );
915 if (eval "$current_form\{'$parentname'}{'tooltips'}" &&
916 !$tooltip &&
917 (' Gtk::VSeparator Gtk::HSeparator Gtk::Combo Gtk::Label ' !~ / $refwid /)) {
918 $Glade_Perl->diag_print (1,
919 "warn Toolbar '%s' is expecting ".
920 "a tooltip but you have not set one for %s '%s'",
921 $parentname, $refwid, $childname);
922 }
923  
924 if ($proto->{'child'}{'new_group'} && $proto->{'child'}{'new_group'} eq 'True') {
925 $class->add_to_UI( $depth,
926 "${current_form}\{'$parentname'}->append_space;" );
927 }
928 # We must have a widget already constructed
929 $class->add_to_UI( $depth,
930 "${current_form}\{'$parentname'}->append_widget(".
931 "\$widgets->{'$childname'}, _('$tooltip'), '' );" );
932
933 #---------------------------------------
934 } elsif (" Gnome::App "=~ m/ $refpar /) {
935 my $type = $class->use_par($proto, 'child_name', $DEFAULT, '' );
936 if (' Gnome::AppBar ' =~ m/ $refwid /) {
937 $class->add_to_UI( $depth,
938 "${current_form}\{'$parentname'}->set_statusbar(".
939 "\$widgets->{'$childname'} );" );
940
941 } elsif (' GnomeApp:appbar ' =~ m/ $type /) {
942 $class->add_to_UI( $depth,
943 "${current_form}\{'$parentname'}->set_statusbar(".
944 "\$widgets->{'$childname'} );" );
945
946 } elsif (' Gnome::Dock ' =~ m/ $refwid /) {
947 # FIXME why have I commented this out? Is it because Gnome::Dock should not
948 # be constructed within a Gnome::App - add Gnome::DockItems by using method
949 # Gnome::App::add_docked() or Gnome::App::add_dock_item() instead?
950 # $class->add_to_UI( $depth,
951 # "${current_form}\{'$parentname'}->set_contents(".
952 # "\$widgets->{'$childname'} );" );
953  
954 } elsif (' Gtk::MenuBar ' =~ m/ $refwid /) {
955 $class->add_to_UI( $depth,
956 "${current_form}\{'$parentname'}->set_menus(".
957 "\$widgets->{'$childname'} );" );
958  
959 } else {
960 $Glade_Perl->diag_print (1,
961 "error Don't know how to pack %s %s (type '%s') - what should I do?",
962 $refwid, "${current_form}\{'${childname}'}{'child_name'}", $type);
963 }
964
965 #---------------------------------------
966 } elsif (" Gnome::Dock "=~ m/ $refpar /) {
967 # We are a Gnome::DockItem
968 my $placement= $class->use_par($proto, 'placement', $LOOKUP, 'top' );
969 my $band = $class->use_par($proto, 'band', $DEFAULT, 0 );
970 my $position = $class->use_par($proto, 'position', $DEFAULT, 0 );
971 my $offset = $class->use_par($proto, 'offset', $DEFAULT, 0 );
972 my $in_new_band = $class->use_par($proto, 'in_new_band', $DEFAULT, 0 );
973  
974 # 'Usage: Gnome::Dock::add_item(dock, item, placement, band_num, position, offset, in_new_band)
975 # Actually should be Gnome::App->add_docked() or
976 # Gnome::App->add_dock_item() if this widget is in a Gnome::App
977 # I quote Damon 20000301 on glade-devel list
978 # I think it was OK to treat dock items as children of the dock.
979 # A GnomeDock could be used in other places besides a GnomeApp (though
980 # I don't think Glade supports that completely at the moment).
981 # I also had to think about GnomeDockBands, but I decided to skip those
982 # in the output since they are created and destroyed automatically
983 # and can't be manipulated independantly.
984 #
985 # I think you're right in that libglade shouldn't create a GnomeDock inside
986 # a GnomeApp, and should be adding the dock items via the GnomeApp's
987 # GnomeDockLayout, e.g. using gnome_app_add_docked() or gnome_app_add_dock_item().
988  
989 if (" Gnome::DockItem " =~/ $refwid /) {
990 $class->add_to_UI( $depth,
991 "${current_form}\{'$parentname'}->add_item(".
992 "\$widgets->{'$childname'}, '$placement', $band, ".
993 "$position, $offset, $in_new_band );" );
994 } else {
995 # We are not a dock_item - just using set_contents
996 undef $proto->{'child_name'};
997 $class->add_to_UI( $depth,
998 "${current_window}->set_contents(".
999 "\$widgets->{'$childname'} );" );
1000 }
1001
1002 #---------------------------------------
1003 } elsif (" Gnome::Druid "=~ m/ $refpar /) {
1004 # We are a Gnome::DruidPage of some sort
1005 $class->add_to_UI( $depth,
1006 "${current_form}\{'$parentname'}->append_page(".
1007 "\$widgets->{'$childname'} );" );
1008 if (' Gnome::DruidPageStart ' =~ / $refwid /) {
1009 $class->add_to_UI( $depth, "${current_form}\{'$parentname'}->".
1010 "set_page(\$widgets->{'$childname'});" );
1011 }
1012
1013 #---------------------------------------
1014 } elsif (" $dialogs "=~ m/ $refpar /) {
1015 # We use a dialog->method to get a ref to our widget
1016 # my $ignore = $class->use_par($proto, 'label', $DEFAULT, '' );
1017 my $type = $class->use_par($proto, 'child_name' );
1018 $type =~ s/.*:(.*)/$1/;
1019 $class->add_to_UI( $depth, "\$widgets->{'$childname'} = ".
1020 "${current_form}\{'$parentname'}->$type;" );
1021  
1022 #---------------------------------------
1023 } else {
1024 # We are not a special case
1025 $class->add_to_UI( $depth, "${current_form}\{'$parentname'}->add(".
1026 "\$widgets->{'$childname'} );" );
1027 }
1028 }
1029 unless ($postpone_show || !$class->use_par($proto, 'visible', $BOOL, 'True') ) {
1030 $class->add_to_UI($depth, "\$widgets->{'$childname'}->show;" );
1031 }
1032 # FINDME This is to remove
1033 $class->add_to_UI( $depth,
1034 "${current_form}\{'$childname'} = \$widgets->{'$childname'};" );
1035  
1036 # Delete the $widget to show that it has been packed
1037 delete $widgets->{$childname};
1038  
1039 return;
1040 }
1041  
1042 sub set_child_packing {
1043 my ($class, $parentname, $childname, $proto, $depth) = @_;
1044 my $me = "$class->set_child_packing";
1045 if ($proto->{'child'} && eval "${current_form}\{'$parentname'}->can("."
1046 'set_child_packing')") {
1047 my ($refpar, $refwid);
1048 eval "\$refpar = ref ${current_form}\{'$parentname'}";
1049 eval "\$refwid = ref ${current_form}\{'$childname'}";
1050 unless (' Gtk::Packer ' =~ / $refpar /) {
1051 my $expand = $class->use_par( $proto->{'child'},
1052 'expand', $BOOL, 'False' );
1053 my $fill = $class->use_par( $proto->{'child'},
1054 'fill', $BOOL, 'True' );
1055 my $padding = $class->use_par( $proto->{'child'},
1056 'padding', $BOOL, 'False' );
1057 my $pack = $class->use_par( $proto->{'child'},
1058 'pack', $LOOKUP, 'start' );
1059 $class->add_to_UI( $depth,
1060 "${current_form}\{'$parentname'}->set_child_packing(".
1061 "${current_form}\{'$childname'}, ".
1062 "$expand, $fill, $padding, '$pack' );" );
1063 }
1064 }
1065 }
1066  
1067 sub set_tooltip {
1068 my ($class, $parentname, $proto, $depth) = @_;
1069 my $me = "$class->set_tooltip";
1070 my $tooltip = $class->use_par($proto, 'tooltip', $DEFAULT, '');
1071
1072 # FIXME What do we do if tooltip is '' - set or not ?
1073 if ($tooltip ne '') {
1074 $class->add_to_UI( $depth, "${current_form}\{'tooltips'}->set_tip(".
1075 "${current_form}\{'$parentname'}, _('$tooltip' ));" );
1076  
1077 } elsif (!defined $proto->{name}) {
1078 $Glade_Perl->diag_print (1,
1079 "error Could not set tooltip for unnamed %s", $proto->{'class'});
1080  
1081 } else {
1082 $Glade_Perl->diag_print(6,
1083 "warn No tooltip specified for widget '%s'", $proto->{name});
1084 }
1085 }
1086  
1087 sub set_container_properties {
1088 my ($class, $parent, $name, $proto, $depth) = @_;
1089 my $me = "$class->set_container_properties";
1090 if ($proto->{'border_width'}) {
1091 if (eval "$current_form\{'$name'}->can('border_width')") {
1092 my $border_width = $class->use_par($proto, 'border_width', $DEFAULT, 0);
1093 $class->add_to_UI( $depth, "$current_form\{'$name'}->border_width(".
1094 "$border_width );" );
1095 }
1096 }
1097 }
1098  
1099 sub set_range_properties {
1100 my ($class, $parent, $name, $proto, $depth) = @_;
1101 my $me = "$class->set_range_properties";
1102 # FIXME - call this from range type widgets
1103 # For use by HScale, VScale, HScrollbar, VScrollbar
1104 # my $name = $proto->{name};
1105 my $hvalue = $class->use_par($proto, 'hvalue', $DEFAULT, 0 );
1106 my $hlower = $class->use_par($proto, 'hlower', $DEFAULT, 0 );
1107 my $hupper = $class->use_par($proto, 'hupper', $DEFAULT, 0 );
1108 my $hstep = $class->use_par($proto, 'hstep', $DEFAULT, 0 );
1109 my $hpage = $class->use_par($proto, 'hpage', $DEFAULT, 0 );
1110 my $hpage_size = $class->use_par($proto, 'hpage_size', $DEFAULT, 0 );
1111 my $policy = $class->use_par($proto, 'policy', $LOOKUP );
1112  
1113 $class->add_to_UI( $depth, "\$widgets->{'$name'}->set_update_policy(".
1114 "'$policy' );" );
1115 }
1116  
1117 sub set_misc_properties {
1118 my ($class, $parent, $name, $proto, $depth) = @_;
1119 my $me = "$class->set_alignment";
1120 # For use by Arrow, Image, Label, (TipsQuery), Pixmap
1121 # Cater for all the usual properties (defaults not stored in XML file)
1122 return unless ($proto->{'xalign'} || $proto->{'yalign'} || $proto->{'xpad'} || $proto->{'ypad'});
1123 my $xalign = $class->use_par($proto, 'xalign', $DEFAULT, 0 );
1124 my $yalign = $class->use_par($proto, 'yalign', $DEFAULT, 0 );
1125 my $xpad = $class->use_par($proto, 'xpad', $DEFAULT, 0 );
1126 my $ypad = $class->use_par($proto, 'ypad', $DEFAULT, 0 );
1127  
1128 if ($xalign || $yalign) {
1129 $class->add_to_UI( $depth, "${current_form}\{'$name'}->set_alignment(".
1130 "$xalign, $yalign );" );
1131 }
1132 if ($xpad || $ypad) {
1133 $class->add_to_UI( $depth, "${current_form}\{'$name'}->set_padding(".
1134 "$xpad, $ypad );" );
1135 }
1136 # FIXME - handle padding (width & height) properly
1137 }
1138  
1139 sub set_widget_properties {
1140 my ($class, $parent, $name, $proto, $depth) = @_;
1141 my $me = "$class->set_widget_properties";
1142 # For use by all widgets
1143 # Cater for all the usual properties (defaults not stored in XML file)
1144 my $can_default = $class->use_par($proto, 'can_default',$BOOL, 'False' );
1145 my $has_default = $class->use_par($proto, 'has_default',$BOOL, 'False' );
1146 my $can_focus = $class->use_par($proto, 'can_focus', $BOOL, 'False' );
1147 my $has_focus = $class->use_par($proto, 'has_focus', $BOOL, 'False' );
1148 my $extension_events = $class->use_par($proto, 'extension_events', $LOOKUP, '' );
1149 my $events = $class->use_par($proto, 'events', $DEFAULT, 0 );
1150 my ($work, @events);
1151 foreach $work (split(/\|/, $events)) {
1152 $work =~ s/\s*//g; # Trim off any whitespace
1153 $work = Glade::PerlUIGtk->lookup($work);
1154 push @events, $work;
1155 }
1156 $events = '';
1157 $events = join("', '", @events) if $#events >= 0;
1158  
1159 if ( (defined $proto->{'x'}) || (defined $proto->{'y'}) ) {
1160 my $x = $class->use_par($proto, 'x', $DEFAULT, 0 );
1161 my $y = $class->use_par($proto, 'y', $DEFAULT, 0 );
1162 $class->add_to_UI( $depth, "${current_form}\{'$name'}->set_uposition(".
1163 "$x, $y );" );
1164 }
1165 if ( (defined $proto->{'width'}) || (defined $proto->{'height'}) ) {
1166 my $width = $class->use_par($proto, 'width', $DEFAULT, 0 );
1167 my $height = $class->use_par($proto, 'height', $DEFAULT, 0 );
1168 $class->add_to_UI( $depth, "${current_form}\{'$name'}->set_usize(".
1169 "$width, $height );" );
1170 }
1171 if ( $proto->{'sensitive'} ) {
1172 my $sensitive = $class->use_par($proto, 'sensitive', $BOOL, 'True' );
1173 $class->add_to_UI( $depth, "${current_form}\{'$name'}->set_sensitive($sensitive);");
1174 }
1175  
1176 if ( $can_default ) {
1177 $class->add_to_UI( $depth, "${current_form}\{'$name'}->can_default(".
1178 "$can_default );" );
1179 }
1180 if ( $can_focus ) {
1181 $class->add_to_UI( $depth, "${current_form}\{'$name'}->can_focus(".
1182 "$can_focus );" );
1183 }
1184 if ($has_default) {
1185 $class->add_to_UI( $depth, "${current_form}\{'$name'}->has_default(".
1186 "$has_default );" );
1187 $class->add_to_UI( $depth, "${current_form}\{'$name'}->grab_default;");
1188 }
1189 if ( $has_focus ) {
1190 $class->add_to_UI( $depth, "${current_form}\{'$name'}->has_focus(".
1191 "$has_focus );" );
1192 }
1193 if ( $extension_events ) {
1194 $class->add_to_UI( $depth, "${current_form}\{'$name'}->set_extension_events(".
1195 "'$extension_events' );" );
1196 }
1197 if ( $events ) {
1198 $class->add_to_UI( $depth, "${current_form}\{'$name'}->set_events(".
1199 "['$events'] );" );
1200 }
1201 }
1202  
1203 sub set_window_properties {
1204 my ($class, $parent, $name, $proto, $depth) = @_;
1205 my $me = "$class->set_window_properties";
1206 # For use by Window, (ColorSelectionDialog, Dialog (InputDialog), FileSelection)
1207 my $title = $class->use_par($proto,'title', $DEFAULT, '' );
1208 my $position = $class->use_par($proto,'position', $LOOKUP, 'mouse' );
1209 my $allow_grow = $class->use_par($proto,'allow_grow', $BOOL, 'True' );
1210 my $allow_shrink = $class->use_par($proto,'allow_shrink', $BOOL, 'True' );
1211 my $auto_shrink = $class->use_par($proto,'auto_shrink', $BOOL, 'False' );
1212 my $modal = $class->use_par($proto,'modal', $BOOL, 'False' );
1213 my $wmclass_name = $class->use_par($proto, 'wmclass_name', $DEFAULT, '' );
1214 my $wmclass_class = $class->use_par($proto, 'wmclass_class', $DEFAULT, '' );
1215  
1216 $class->add_to_UI( $depth, "\$widgets->{'$name'}->set_position('$position' );" );
1217 $class->add_to_UI( $depth, "\$widgets->{'$name'}->set_policy(".
1218 "$allow_shrink, $allow_grow, $auto_shrink );" );
1219 $class->add_to_UI( $depth, "\$widgets->{'$name'}->set_modal($modal );" );
1220 if ( (defined $proto->{'width'}) || (defined $proto->{'height'}) ) {
1221 my $width = $class->use_par($proto, 'width', $DEFAULT, 0 );
1222 my $height = $class->use_par($proto, 'height', $DEFAULT, 0 );
1223 $class->add_to_UI( $depth, "\$widgets->{'$name'}->set_usize(".
1224 "$width, $height );" );
1225 }
1226 if ( (defined $proto->{'default_width'}) || (defined $proto->{'default_height'}) ) {
1227 my $default_width = $class->use_par($proto, 'default_width', $DEFAULT, 0 );
1228 my $default_height = $class->use_par($proto, 'default_height', $DEFAULT, 0 );
1229 $class->add_to_UI( $depth, "\$widgets->{'$name'}->set_default_size(".
1230 "$default_width, $default_height );" );
1231 }
1232 if ( (defined $proto->{'x'}) || (defined $proto->{'y'}) ) {
1233 my $x = $class->use_par($proto, 'x', $DEFAULT, 0 );
1234 my $y = $class->use_par($proto, 'y', $DEFAULT, 0 );
1235 $Glade_Perl->diag_print(1, "warn Toplevel window uposition has been set ".
1236 "but breaks the window manager's placement policy, and is almost ".
1237 "certainly a bad idea. (Havoc Pennington)");
1238 $class->add_to_UI( $depth, "\$widgets->{'$name'}->set_uposition(".
1239 "$x, $y );" );
1240 }
1241 if ($wmclass_name && $wmclass_class) {
1242 $class->add_to_UI( $depth, "\$widgets->{'$name'}->set_wmclass(".
1243 "'$wmclass_name', '$wmclass_class' );" );
1244 }
1245 $class->add_to_UI( $depth, "\$widgets->{'$name'}->realize;" );
1246 #use Data::Dumper;print Dumper($Glade_Perl->source);
1247 unless ($Glade_Perl->source->quick_gen) {
1248 $widgets->{$name}->signal_connect("destroy" => \&Gtk::main_quit);
1249 $widgets->{$name}->signal_connect("delete_event" => \&Gtk::main_exit);
1250 }
1251 $class->pack_widget($parent, $name, $proto, $depth );
1252 }
1253  
1254 sub pack_widget {
1255 my ($class, $parent, $name, $proto, $depth) = @_;
1256 my $me = "$class->pack_widget";
1257  
1258 $class->internal_pack_widget($parent, $name, $proto, $depth );
1259 $class->set_widget_properties($parent, $name, $proto, $depth);
1260 $class->set_container_properties($parent, $name, $proto, $depth);
1261 $class->set_tooltip($name, $proto, $depth );
1262 }
1263  
1264 sub new_accelerator {
1265 my ($class, $parentname, $proto, $depth, $gnome_frig) = @_;
1266 my $me = "$class->new_accelerator";
1267 my $mods = '[]';
1268 my $accel_flags = "['visible', 'locked']";
1269 # my $key = $class->use_par($proto, 'key', $LOOKUP);
1270 my $key = $class->use_par($proto, 'key', $KEYSYM);
1271 my $modifiers = $class->use_par($proto, 'modifiers', $DEFAULT, 0);
1272 my $signal = $class->use_par($proto, 'signal');
1273 unless (defined $need_handlers->{$parentname}{$signal}) {
1274 $need_handlers->{$parentname}{$signal} = undef;
1275 }
1276  
1277 # FIXME move this to use_par
1278 #--------------------------------------
1279 # Turn GDK values into array of $LOOKUPs
1280 unless ($modifiers eq 0) {
1281 $modifiers =~ s/ *//g;
1282 $modifiers =~ s/GDK_//g;
1283 $mods = "['".lc(join ("', '", split(/\|/, $modifiers)))."']";
1284 }
1285 #--------------------------------------
1286  
1287 # gtk_widget_add_accelerator (accellabel3, "button_press_event", accel_group,
1288 # GDK_L, GDK_MOD1_MASK,
1289 # GTK_ACCEL_VISIBLE);
1290 # $class->add_to_UI( $depth, "${current_form}\{'$parentname'}->add_accelerator(".
1291 # "'$signal', ${current_form}\{'accelgroup'}, '$key', $mods, $accel_flags);");
1292  
1293 if ($gnome_frig) {
1294 $class->add_to_UI( $depth,
1295 "${current_window}\->set_accelerator(".
1296 "$gnome_frig, $key, $mods);");
1297
1298 } elsif ($Glade_Perl->source->quick_gen) {
1299 # Do no checks
1300
1301 } elsif (eval "${current_form}\{'$parentname'}->can('$signal')") {
1302 $class->add_to_UI( $depth, "${current_form}\{'accelgroup'}->add(".
1303 # ($key || "''").
1304 "\$Gtk::Keysyms{'$key'} || Gtk::Gdk->keyval_from_name('$key') || ".
1305 $Gtk::Keysyms{$key}.
1306 " , $mods, $accel_flags, ".
1307 "${current_form}\{'$parentname'}, '$signal');");
1308 } else {
1309 $Glade_Perl->diag_print (1, "error Widget '%s' can't emit signal ".
1310 "'%s' as requested - what's wrong?",
1311 $parentname, $signal);
1312 }
1313 }
1314  
1315 sub new_style {
1316 my ($class, $parentname, $proto, $depth) = @_;
1317 my $me = "$class->new_style";
1318 my ($state, $color, $value, $element, $lc_state);
1319 my ($red, $green, $blue);
1320 $class->add_to_UI( $depth, "$current_form\{'$parentname-style'} = ".
1321 "new Gtk::Style;");
1322 # $class->add_to_UI( $depth, "$current_form\{'$parentname-style'} = ".
1323 # "$current_form\{'$parentname'}->style;");
1324 my $style_font = $class->use_par($proto, 'style_font', $DEFAULT, '');
1325 if ($style_font) {
1326 $class->add_to_UI( $depth, "$current_form\{'$parentname-style'}".
1327 "->font(Gtk::Gdk::Font->load('$style_font'));");
1328 }
1329 foreach $state ("NORMAL", "ACTIVE", "PRELIGHT", "SELECTED", "INSENSITIVE") {
1330 $lc_state = lc($state);
1331 foreach $color ('fg', 'bg', 'text', 'base') {
1332 $element = "$color-$state";
1333 if ($proto->{$element}) {
1334 $value = $class->use_par($proto, $element, $DEFAULT, '');
1335 $Glade_Perl->diag_print(6, "%s- We have a style element ".
1336 "'%s' which is '%s'", $indent, $element, $value);
1337 ($red, $green, $blue) = split(',', $value);
1338 # Yes I really mean multiply by 257 (0x101)
1339 # We scale these so that 0x00 -> 0x0000
1340 # 0x0c -> 0x0c0c
1341 # 0xff -> 0xffff
1342 # This spreads the values 0x00 - 0xff throughout the possible
1343 # Gdk values of 0x0000 - 0xffff rather than 0x00 - 0xff00
1344 $red *= 257;
1345 $green *= 257;
1346 $blue *= 257;
1347 $class->add_to_UI( $depth, "$current_form\{'$parentname-$color-$lc_state'} ".
1348 "= $current_form\{'$parentname-style'}->$color('$lc_state');");
1349 $class->add_to_UI( $depth, "$current_form\{'$parentname-$color-$lc_state'}".
1350 "->red($red);");
1351 $class->add_to_UI( $depth, "$current_form\{'$parentname-$color-$lc_state'}".
1352 "->green($green);");
1353 $class->add_to_UI( $depth, "$current_form\{'$parentname-$color-$lc_state'}".
1354 "->blue($blue);");
1355 $class->add_to_UI( $depth, "$current_form\{'$parentname-style'}".
1356 "->$color('$lc_state', $current_form\{'$parentname-$color-$lc_state'});");
1357 }
1358 }
1359 $element = "bg_pixmap-${state}";
1360 if ($proto->{$element}) {
1361 $class->add_to_UI( $depth, "($current_form\{'$parentname-bg_pixmap-$lc_state'}, ".
1362 "$current_form\{'$parentname-bg_mask-$lc_state'}) = ".
1363 "Gtk::Gdk::Pixmap->create_from_xpm($current_window->get_toplevel->window, ".
1364 "$current_form\{'$parentname-style'}, '$proto->{$element}' );");
1365 $class->add_to_UI( $depth, "$current_form\{'$parentname-style'}".
1366 "->bg_pixmap('$lc_state', $current_form\{'$parentname-bg_pixmap-$lc_state'});");
1367 }
1368 }
1369 if (eval "$current_form\{'$parentname'}->can('child')") {
1370 $class->add_to_UI( $depth, "$current_form\{'$parentname'}->child->set_style(".
1371 "$current_form\{'$parentname-style'});");
1372 }
1373 $class->add_to_UI( $depth, "$current_form\{'$parentname'}->set_style(".
1374 "$current_form\{'$parentname-style'});");
1375 }
1376  
1377 sub new_from_child_name {
1378 my ($class, $parent, $name, $proto, $depth) = @_;
1379 return undef unless $proto->{'child_name'};
1380  
1381 my $type = $class->use_par($proto, 'child_name' );
1382 if ($type eq 'GnomeEntry:entry') {
1383 $type = 'gtk_entry';
1384 # $type =~ s/.*:(.*)/gtk_$1/;
1385  
1386 } elsif ($type eq 'GnomePixmapEntry:file-entry') {
1387 $type = 'gnome_file_entry';
1388  
1389 } elsif (' Toolbar:button GnomeDock:contents GnomeDruidPageStandard:vbox Dialog:action_area Dialog:vbox ' =~ m/ $type /) {
1390 # Keep the full child_name for later use
1391  
1392 } else {
1393 # Just use the bit after the colon
1394 $type =~ s/.*:(.*)/$1/;
1395  
1396 }
1397 #---------------------------------------
1398 if ($type eq 'action_area') {
1399 # Gtk|Gnome::Dialog have widget tree that is not reflected by
1400 # the methods that access them. $dialog->action_area() points to
1401 # a child of $dialog->vbox() and not of $dialog.
1402 # In any case, they cannot be used/accessed until something is
1403 # added to them by the automagic ->new('title', 'Button_Ok',...).
1404 #
1405 # For Gnome::Dialog and derivatives we can use ->append_button()
1406 # (which calls gnome_dialog_init_action_area)
1407 unless ($class->my_gtk_perl_can_do('gnome_dialog_append_button')) {
1408 # Force HButtonbox to construct its widget and add it to the VBox
1409 # This will look wrong (above the separator)
1410 return undef;
1411
1412 } else {
1413 # Append the buttons by name
1414 # $childname = $class->Widget_from_Proto( $proto->{name},
1415 # $proto->{$key}, $depth + 1,
1416 # $widget_hierarchy, $class_hierarchy );
1417 my $number_of_buttons =
1418 $class->frig_Gnome_Dialog_buttons($parent, $proto, $depth);
1419 # Return the action_area now it exists
1420 $class->add_to_UI( $depth,
1421 "\$widgets->{'$name'} = ${current_window}->$type;" );
1422 }
1423
1424 #---------------------------------------
1425 } elsif (' Dialog:action_area Dialog:vbox ' =~ / $type /) {
1426 $type =~ s/.*:(.*)/$1/;
1427 # Return the action_area now it exists
1428 $class->add_to_UI( $depth,
1429 "\$widgets->{'$name'} = ${current_window}->$type;" );
1430  
1431 #---------------------------------------
1432 } elsif ($type eq 'Toolbar:button') {
1433 my $pixmap_widget_name = 'undef';
1434 my ($group, $rb_group, $use_group);
1435 my $label = $class->use_par($proto, 'label', $DEFAULT, '');
1436 my $icon = $class->use_par($proto, 'icon', $DEFAULT, '' );
1437 # my $stock_button = $class->use_par($proto, 'stock_button', $LOOKUP, '' );
1438  
1439 my $tooltip = $class->use_par($proto, 'tooltip', $DEFAULT, '' );
1440 if (eval "$current_form\{'$parent'}{'tooltips'}" && !$tooltip) {
1441 $Glade_Perl->diag_print (1, "warn Toolbar '%s' is expecting ".
1442 "a tooltip but you have not set one for %s '%s'",
1443 $parent, $proto->{'class'}, $name);
1444 }
1445  
1446 my $new_group = $class->use_par($proto->{'child'}, 'new_group', $BOOL, 0 );
1447 if ($new_group) {
1448 $class->add_to_UI( $depth,
1449 "${current_form}\{'$parent'}->append_space;" );
1450 }
1451  
1452 if ($icon) {
1453 $pixmap_widget_name = "${current_form}\{'${name}-pixmap'}";
1454 $class->add_to_UI( $depth,
1455 "$pixmap_widget_name = \$class->create_pixmap(".
1456 "${current_window}, \"\$Glade::PerlRun::pixmaps_directory/$icon\" );" );
1457  
1458 } elsif ($proto->{'stock_pixmap'}) {
1459 my $stock_pixmap = $class->use_par($proto, 'stock_pixmap', $LOOKUP, '' );
1460 if ($Glade_Perl->app->allow_gnome) {
1461 $pixmap_widget_name = "${current_form}\{'${name}-pixmap'}";
1462 $class->add_to_UI( $depth,
1463 "$pixmap_widget_name = Gnome::Stock->pixmap_widget(".
1464 "$current_window, '$stock_pixmap');" );
1465  
1466 } else {
1467 $Glade_Perl->diag_print(1, "error You have specified a Gnome stock ".
1468 "pixmap but this is not a Gnome project - stock pixmap omitted");
1469 $pixmap_widget_name = "undef";
1470 }
1471  
1472 } else {
1473 $pixmap_widget_name = "undef";
1474 }
1475  
1476 # We have label and so on to add
1477 if ($proto->{'class'} eq 'GtkToggleButton') {
1478 $type = 'togglebutton';
1479  
1480 } elsif ($proto->{'class'} eq 'GtkRadioButton') {
1481 $type = 'radiobutton';
1482 $group = $class->use_par($proto, 'group', $DEFAULT, '' );
1483 $rb_group = "$current_form\{'rb-group-$group'}";
1484 if ($rb_group && eval "defined $rb_group") {
1485 $use_group = $rb_group;
1486 }
1487  
1488 } else {
1489 $type =~ s/.*:(.*)/$1/;
1490 }
1491  
1492 $use_group ||= 'undef';
1493 $class->add_to_UI( $depth,
1494 "\$widgets->{'$name'} = ".
1495 "${current_form}\{'$parent'}->append_element(".
1496 "'$type', $use_group, _('$label'), ".
1497 "_('$tooltip'), '', $pixmap_widget_name );" );
1498  
1499 unless (!$rb_group || eval "defined $rb_group") {
1500 $class->add_to_UI( $depth,
1501 "$rb_group = \$widgets->{'$name'};" );
1502 }
1503
1504 #---------------------------------------
1505 } elsif (' GnomeDock:contents ' =~ / $type /) {
1506 return undef;
1507 # FIXME This doesn't make sense to me, get_client_area wants a DockItem
1508 # $class->add_to_UI( $depth,
1509 # "\$widgets->{'$name'} = ".
1510 # "${current_form}\{'$parent'}->get_client_area;" );
1511 # $class->add_to_UI( $depth,
1512 # "\$widgets->{'$name'} = ".
1513 # "${current_form}\{'$parent'}->get_client_area;" );
1514  
1515 #---------------------------------------
1516 } elsif (' GnomeDruidPageStandard:vbox ' =~ / $type /) {
1517 $class->add_to_UI( $depth,
1518 "\$widgets->{'$name'} = ${current_form}\{'$parent'}->vbox;" );
1519  
1520 #---------------------------------------
1521 } elsif ($Glade_Perl->source->quick_gen || eval "${current_form}\{'$parent'}->can('$type')") {
1522 my $label = $class->use_par($proto, 'label', $DEFAULT, '');
1523 $class->add_to_UI( $depth,
1524 "\$widgets->{'$name'} = ".
1525 "${current_form}\{'$parent'}->$type;" );
1526  
1527 if ($label) {
1528 if ($Glade_Perl->source->quick_gen) {
1529 $class->add_to_UI( $depth,
1530 "\$widgets->{'$name'}->child->set_text(_('$label'));",
1531 'TO_FILE_ONLY' );
1532  
1533 } elsif ($widgets->{$name}->can('child')) {
1534 my $childref = ref $widgets->{$name}->child;
1535
1536 if ($childref eq 'Gtk::Label') {
1537 $class->add_to_UI( $depth,
1538 "\$widgets->{'$name'}->child->set_text(_('$label'));",
1539 'TO_FILE_ONLY' );
1540 } else {
1541 $Glade_Perl->diag_print (1, "error We have a label ".
1542 "('%s') to set but the child of %s ".
1543 "isn't a label (actually it's a %s)",
1544 $label, "${current_form}\{'$name'}", $childref);
1545 }
1546 } else {
1547 $Glade_Perl->diag_print (1, "error We have a label ('%s') to ".
1548 "set but %s doesn't have a ->child() accessor",
1549 $label, "${current_form}\{'${name}'}");
1550 }
1551 }
1552  
1553 #---------------------------------------
1554 } elsif ($type eq 'notebook') {
1555 return undef;
1556
1557 #---------------------------------------
1558 } else {
1559 $Glade_Perl->diag_print (1, "error Don't know how to get a ref to %s ".
1560 "(type '%s')",
1561 "${current_form}\{'${name}'}{'child_name'}", $type);
1562 return undef;
1563 }
1564  
1565 $class->add_to_UI( $depth, "\$widgets->{'$name'}->show;" );
1566 # FINDME This is to remove
1567 $class->add_to_UI( $depth,
1568 "${current_form}\{'$name'} = \$widgets->{'$name'};" );
1569 # Delete the $widget to show that it has been packed
1570 delete $widgets->{$name};
1571  
1572 # Deal with all the other widget properties that might be set
1573 $class->set_widget_properties($parent, $name, $proto, $depth);
1574 $class->set_container_properties($parent, $name, $proto, $depth);
1575 $class->set_tooltip($name, $proto, $depth );
1576  
1577 # we have constructed the widget so caller doesn't need to
1578 return 1;
1579 }
1580  
1581 sub new_signal {
1582 my ($class, $parentname, $proto, $depth) = @_;
1583 my $me = "$class->new_signal";
1584 my $signal = $proto->{name};
1585 my ($call, $expr, $when, $changes);
1586 # $class = ref $class || $class;
1587 # FIXME to do signals properly
1588 if ($proto->{'handler'}) {
1589 my $ignore = $class->use_par($proto, 'last_modification_time');
1590 my $handler = $class->use_par($proto, 'handler');
1591 my $object = $class->use_par($proto, 'object', $DEFAULT, '');
1592 my $data = $class->use_par($proto, 'data', $DEFAULT, '');
1593 my $after = $class->use_par($proto, 'after', $BOOL, 'False');
1594  
1595 # Triple escape any double-quotes so that they get passed through
1596 $changes = $data =~ s/(?!\\)(.)"/$1\\\\\\"/g;
1597 $changes += $data =~ s/^"/\\\\\\"/g;
1598 if ($changes) {
1599 $Glade_Perl->diag_print (1, "warn signal handler data ('%s') ".
1600 "contains %s double-quote(s) which has(ve) been ".
1601 "escaped so that they are preserved. ",
1602 $handler, $changes);
1603 }
1604 unless ($object) {$object = $parentname}
1605 if ($after) {
1606 $when = 'after_';
1607 $call .= 'signal_connect_after'
1608 } else {
1609 $when = '';
1610 $call .= 'signal_connect'
1611 }
1612  
1613 $handler = $class->fix_name($handler, 'TRANSLATE');
1614  
1615 if ($handler =~ /[- \.]/) {
1616 my %ents=('-'=>'MINUS',' '=>'SPACE','.'=>'DOT');
1617 $changes = $handler =~ s/([- \.])/_$ents{$1}_/g;
1618 $Glade_Perl->diag_print (1, "error signal handler ('%s') ".
1619 "contains %s minus sign/space/dot(s) which has(ve) been ".
1620 "substituted because they are illegal in a sub name in Perl. ",
1621 $handler, $changes);
1622 }
1623 # We can check dynamically below
1624 # Flag that we are done
1625 delete $need_handlers->{$parentname}{$signal};
1626 # We must log the sub name for dynamic stub handlers
1627 unless ( ($Glade::PerlSource::subs =~ m/ $handler /) or
1628 (defined $handlers->{$handler}) or
1629 ($Glade_Perl->Building_UI_only) ) {
1630 $subs .= "$handler\n$indent".(' ' x 19 );
1631 eval "$current_form\{_HANDLERS}{'$handler'} = 'signal'";
1632 }
1633 if ($class->can($handler) ||
1634 eval "$current_name->can('$handler')"
1635 ) {
1636 # Handler already available - no need to generate a stub
1637 eval "delete $current_form\{_HANDLERS}{'$handler'}";
1638 # First connect the signal handler as best we can
1639 unless ($Glade_Perl->Writing_Source_only) {
1640 $expr = "push \@{${current_form}\{'Signal_Strings'}}, ".
1641 "\"\\${current_form}\{'$object'}->$call( ".
1642 "'$signal', \\\"\$class\\\::$handler\\\", '".$data."', '$object', ".
1643 "'name of form instance' )\"";
1644 eval $expr
1645 }
1646 } else {
1647 # First we'll connect a default handler to hijack the signal
1648 # for us to use during the Build run
1649 $Glade_Perl->diag_print (4, "warn Missing signal handler '%s' ".
1650 "connected to widget '%s' needs to be written",
1651 $handler, $object);
1652 unless ($Glade_Perl->Writing_Source_only) {
1653 $expr = "push \@{${current_form}\{'Signal_Strings'}}, ".
1654 "\"\\${current_form}\{'$object'}->$call(".
1655 "'$signal', \\\"\$class\\\::missing_handler\\\", ".
1656 "'$parentname', '$signal', '$handler', '".
1657 $Glade_Perl->app->logo."' )\"";
1658 eval $expr
1659 }
1660 }
1661 # Now write a signal_connect for generated code
1662 # All these back-slashes are really necessary as these strings
1663 # are passed through so many others (evals and so on)
1664 my $id_string = "";
1665 if ($Glade_Perl->source->save_connect_id) {
1666 $id_string =
1667 "\\\\\\${current_form}\{'__CONNECT_ID'}{'$object'}{'$when$signal'} = ";
1668 }
1669 $expr = "push \@{${current_form}\{'Signal_Strings'}}, ".
1670 "\"$class->add_to_UI( 1, \\\"".$id_string.
1671 "\\\\\\${current_form}\{'$object'}->$call(".
1672 "'$signal', \\\\\\\"\\\\\\\$class\\\\\\\\\::$handler\\\\\\\", '".$data."', '$object', ".
1673 "\\\\\\\"$current_form_name\\\\\\\" );\\\", 'TO_FILE_ONLY' );\"";
1674 $Glade_Perl->diag_print (4, "warn Connecting missing signal handler '%s' ",
1675 $expr);
1676 eval $expr
1677
1678 } else {
1679 # This is a signal that we will cause
1680 }
1681 }
1682  
1683 1;
1684  
1685 __END__