| 1 | package Tk::Wizard; | ||
| 2 | |||
| 3 | 6 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 6 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 6 | ▶ | use warnings::register; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | our $VERSION = 2.086; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Tk::Wizard - GUI for step-by-step interactive logical process | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | 6 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 6 | ▶ | use Config; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 6 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 6 | ▶ | use File::Path; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 0 | ▶ | use Tk; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 20 | use Tk::DialogBox; | ||
| 21 | use Tk::Frame; | ||
| 22 | use Tk::Font; | ||
| 23 | use Tk::MainWindow; | ||
| 24 | use Tk::ROText; | ||
| 25 | use Tk::Wizard::Image; | ||
| 26 | use Tk::JPEG; | ||
| 27 | use Tk::PNG; | ||
| 28 | |||
| 29 | use constant DEBUG_FRAME => 0; | ||
| 30 | |||
| 31 | use vars qw( @EXPORT @ISA %LABELS ); | ||
| 32 | |||
| 33 | # use Log4perl if we have it, otherwise stub: | ||
| 34 | # See Log::Log4perl::FAQ | ||
| 35 | BEGIN { | ||
| 36 | eval { require Log::Log4perl; }; | ||
| 37 | |||
| 38 | # No Log4perl so bluff: see Log4perl FAQ | ||
| 39 | if($@) { | ||
| 40 | no strict qw"refs"; | ||
| 41 | *{__PACKAGE__."::$_"} = sub { } for qw(TRACE DEBUG INFO WARN ERROR FATAL); | ||
| 42 | } | ||
| 43 | |||
| 44 | # Setup log4perl | ||
| 45 | else { | ||
| 46 | no warnings; | ||
| 47 | no strict qw"refs"; | ||
| 48 | require Log::Log4perl::Level; | ||
| 49 | Log::Log4perl::Level->import(__PACKAGE__); | ||
| 50 | Log::Log4perl->import(":easy"); | ||
| 51 | # It took four CPAN uploads and tests to workout why | ||
| 52 | # one user was getting syntax errors for TRACE: must | ||
| 53 | # be the Mithrasmas spirit (hic): | ||
| 54 | if ($Log::Log4perl::VERSION < 1.11){ | ||
| 55 | *{__PACKAGE__."::TRACE"} = *DEBUG; | ||
| 56 | } | ||
| 57 | *{__PACKAGE__."::LOGCROAK"} = *LOGCROAK; | ||
| 58 | *{__PACKAGE__."::LOGCONFESS"} = *Carp::confess; | ||
| 59 | } | ||
| 60 | |||
| 61 | require Exporter; # Exporting Tk's MainLoop so that | ||
| 62 | @ISA = ( "Exporter", ); # I can just use strict and Tk::Wizard without | ||
| 63 | @EXPORT = ("MainLoop"); # having to use Tk | ||
| 64 | } | ||
| 65 | |||
| 66 | use base qw[ Tk::Derived Tk::Toplevel ]; | ||
| 67 | Tk::Widget->Construct('Wizard'); | ||
| 68 | |||
| 69 | # See INTERNATIONALISATION | ||
| 70 | %LABELS = ( | ||
| 71 | # Buttons | ||
| 72 | BACK => "< Back", | ||
| 73 | NEXT => "Next >", | ||
| 74 | FINISH => "Finish", | ||
| 75 | CANCEL => "Cancel", | ||
| 76 | HELP => "Help", | ||
| 77 | OK => "OK", | ||
| 78 | ); | ||
| 79 | |||
| 80 | my $WINDOZE = ($^O =~ m/MSWin32/i); | ||
| 81 | my @PAGE_EVENT_LIST = qw( | ||
| 82 | -preNextButtonAction | ||
| 83 | -postNextButtonAction | ||
| 84 | -preBackButtonAction | ||
| 85 | -postBackButtonAction | ||
| 86 | ); | ||
| 87 | |||
| 88 | my $REFRESH_MS = 1000; # Refresh the wizard every REFRESH_MS milliseconds | ||
| 89 | |||
| 90 | =head1 SYNOPSIS | ||
| 91 | |||
| 92 | use Tk::Wizard (); | ||
| 93 | my $wizard = new Tk::Wizard; | ||
| 94 | # OR my $wizard = Tk::MainWindow->new -> Wizard(); | ||
| 95 | $wizard->configure( -property=>'value' ); | ||
| 96 | $wizard->cget( "-property"); | ||
| 97 | # $wizard->addPage( | ||
| 98 | # ... code-ref to anything returning a Tk::Frame ... | ||
| 99 | # ); | ||
| 100 | $wizard->addPage( | ||
| 101 | sub { | ||
| 102 | return $wizard->blank_frame( | ||
| 103 | -title => "Page Title", | ||
| 104 | -subtitle => "Sub-title", | ||
| 105 | -text => "Some text.", | ||
| 106 | -wait => $milliseconds_b4_proceeding_anyway, | ||
| 107 | ); | ||
| 108 | } | ||
| 109 | ); | ||
| 110 | $wizard->addPage( | ||
| 111 | sub { $wizard->blank_frame(@args) }, | ||
| 112 | -preNextButtonAction => sub { warn "My -preNextButtonAction called here" }, | ||
| 113 | -postNextButtonAction => sub { warn "My -postNextButtonAction called here" }, | ||
| 114 | ); | ||
| 115 | $wizard->Show; | ||
| 116 | MainLoop; | ||
| 117 | exit; | ||
| 118 | |||
| 119 | To avoid 50 lines of SYNOPSIS, please see the files included with the | ||
| 120 | distribution in the test directory: F<t/*.t>. These are just Perl | ||
| 121 | programs that are run during the C<make test> phase of installation: you | ||
| 122 | can move/copy/rename them without harm once you have installed the module. | ||
| 123 | |||
| 124 | =head1 CHANGES | ||
| 125 | |||
| 126 | Please see the file F<Changes> included with the distribution for change history. | ||
| 127 | |||
| 128 | =head1 DEPENDENCIES | ||
| 129 | |||
| 130 | C<Tk> and modules of the current standard Perl Tk distribution. | ||
| 131 | |||
| 132 | On MS Win32 only: C<Win32API::File>. | ||
| 133 | |||
| 134 | =head1 EXPORTS | ||
| 135 | |||
| 136 | MainLoop(); | ||
| 137 | |||
| 138 | This is so that I can say C<use strict; use Tk::Wizard> without | ||
| 139 | having to C<use Tk>. You can always C<use Tk::Wizard ()> to avoid | ||
| 140 | importing this. | ||
| 141 | |||
| 142 | =head1 DESCRIPTION | ||
| 143 | |||
| 144 | In the context of this namespace, a Wizard is defined as a graphic user interface (GUI) | ||
| 145 | that presents information, and possibly performs tasks, step-by-step via a series of | ||
| 146 | different pages. Pages (or 'screens', or 'Wizard frames') may be chosen logically depending | ||
| 147 | upon user input. | ||
| 148 | |||
| 149 | The C<Tk::Wizard> module automates a large part of the creation of a wizard program | ||
| 150 | to collect information and then perform some complex task based upon it. | ||
| 151 | |||
| 152 | The wizard feel is largely based upon the Microsoft(TM,etc) wizard style: the default is | ||
| 153 | similar to that found in Windows 2000, though the more traditional Windows 95-like feel is also | ||
| 154 | supported (see the C<-style> entry in L</WIDGET-SPECIFIC OPTIONS>. Sub-classing the | ||
| 155 | module to provide different look-and-feel is highly encourage: please see | ||
| 156 | L</NOTES ON SUB-CLASSING Tk::Wizard>. If anyone would like to do a I<Darwin> or | ||
| 157 | I<Aqua> version, please let me know how you would like to handle the buttons. I'm not | ||
| 158 | hot on advertising widgets. | ||
| 159 | |||
| 160 | =head1 ADVERTISED SUB-WIDGETS | ||
| 161 | |||
| 162 | my $subwidget = $wizard->Subwidget('buttonPanel'); | ||
| 163 | |||
| 164 | =over 4 | ||
| 165 | |||
| 166 | =item buttonPanel | ||
| 167 | |||
| 168 | The C<Frame> that holds the navigation buttons and optional help button. | ||
| 169 | |||
| 170 | =item nextButton | ||
| 171 | |||
| 172 | =item backButton | ||
| 173 | |||
| 174 | =item cancelButton | ||
| 175 | |||
| 176 | =item helpButton | ||
| 177 | |||
| 178 | The buttons in the C<buttonPanel>. | ||
| 179 | |||
| 180 | =item tagLine | ||
| 181 | |||
| 182 | The line above the C<buttonpanel>, a L<Tk::Frame|Tk::Frame> object. | ||
| 183 | |||
| 184 | =item tagText | ||
| 185 | |||
| 186 | The grayed-out text above the C<buttonpanel>, a L<Tk::Label|Tk::Label> object. | ||
| 187 | |||
| 188 | =item tagBox | ||
| 189 | |||
| 190 | A L<Tk::Frame|Tk::Frame> holding the tagText and tagLine. | ||
| 191 | |||
| 192 | =item imagePane | ||
| 193 | |||
| 194 | On all pages of a C<95>-style Wizard, | ||
| 195 | and for the first and last pages of the default c<top>-style Wizard, | ||
| 196 | this is a large pane on the left, that holds an image. | ||
| 197 | For the other pages of a C<top>-style Wizard, this refers to the image box at the top of the wizard. | ||
| 198 | |||
| 199 | =item wizardFrame | ||
| 200 | |||
| 201 | The frame that holds the content frame, the current Wizard page. | ||
| 202 | |||
| 203 | =back | ||
| 204 | |||
| 205 | =head1 STANDARD OPTIONS | ||
| 206 | |||
| 207 | =over 4 | ||
| 208 | |||
| 209 | =item -title | ||
| 210 | |||
| 211 | Text that appears in the title bar. | ||
| 212 | |||
| 213 | =item -background | ||
| 214 | |||
| 215 | Main background colour of the Wizard's window. | ||
| 216 | |||
| 217 | =back | ||
| 218 | |||
| 219 | =head1 WIDGET-SPECIFIC OPTIONS | ||
| 220 | |||
| 221 | =over 4 | ||
| 222 | |||
| 223 | =item Name: style | ||
| 224 | |||
| 225 | =item Class: Style | ||
| 226 | |||
| 227 | =item Switch: -style | ||
| 228 | |||
| 229 | Sets the display style of the Wizard. | ||
| 230 | |||
| 231 | The default no-value or value of C<top> gives the Wizard will be a Windows 2000-like | ||
| 232 | look, with the initial page being a version of the traditional | ||
| 233 | style with a white background, and subsequent pages being C<SystemButtonFace> coloured, | ||
| 234 | with a white strip at the top holding a title and subtitle, and a smaller image (see | ||
| 235 | C<-topimagepath>, below). | ||
| 236 | |||
| 237 | The old default of C<95> is still available, if you wish to create a traditional, | ||
| 238 | Windows 95-style wizard, with every page being C<SystemButtonFace> coloured, with a | ||
| 239 | large image on the left (C<-imagepath>, below). | ||
| 240 | |||
| 241 | =item Name: imagepath | ||
| 242 | |||
| 243 | =item Class: Imagepath | ||
| 244 | |||
| 245 | =item Switch: -imagepath | ||
| 246 | |||
| 247 | Path to an image that will be displayed on the left-hand side | ||
| 248 | of the screen. (Dimensions are not constrained.) One of either: | ||
| 249 | |||
| 250 | =over 4 | ||
| 251 | |||
| 252 | =item * | ||
| 253 | |||
| 254 | Path to a file from which to construct a L<Tk::Photo|Tk::Photo> | ||
| 255 | object without the format being specified; | ||
| 256 | No checking is done, but paths ought to be absolute, as no effort | ||
| 257 | is made to maintain or restore any initial current working directory. | ||
| 258 | |||
| 259 | =item * | ||
| 260 | |||
| 261 | A reference to a Base64-encoded image to pass in the C<-data> field of the | ||
| 262 | L<Tk::Photo|Tk::Photo> object. This is the default form, and a couple | ||
| 263 | of extra, unused images are supplied: see L<Tk::Wizard::Image>. | ||
| 264 | |||
| 265 | =back | ||
| 266 | |||
| 267 | =item Name: topimagepath | ||
| 268 | |||
| 269 | =item Class: Topimagepath | ||
| 270 | |||
| 271 | =item Switch: -topimagepath | ||
| 272 | |||
| 273 | Only required if C<-style=E<gt>'top'> (as above): the image | ||
| 274 | this filepath specifies | ||
| 275 | will be displayed in the top-right corner of the screen. Dimensions are not | ||
| 276 | restrained (yet), but only 50x50 has been tested. | ||
| 277 | |||
| 278 | Please see notes for the C<-imagepath>>. | ||
| 279 | |||
| 280 | =item Name: nohelpbutton | ||
| 281 | |||
| 282 | =item Class: Nohelpbutton | ||
| 283 | |||
| 284 | =item Switch: -nohelpbutton | ||
| 285 | |||
| 286 | Set to anything to disable the display of the I<Help> button. | ||
| 287 | |||
| 288 | =item Name: resizable | ||
| 289 | |||
| 290 | =item Class: resizable | ||
| 291 | |||
| 292 | =item Switch: -resizable | ||
| 293 | |||
| 294 | Supply a boolean value to allow resizing of the window: default | ||
| 295 | is to disable that feature to minimise display issues. | ||
| 296 | |||
| 297 | =item Switch: -tag_text | ||
| 298 | |||
| 299 | Text to supply in a 'tag line' above the wizard's control buttons. | ||
| 300 | Specify empty string to disable the display of the tag text box. | ||
| 301 | |||
| 302 | =item -fontfamily | ||
| 303 | |||
| 304 | Specify the "family" (ie name) of the font you want to use for all Wizard elements. | ||
| 305 | The default is your operating system default (or a sans serif), which on my test computers is | ||
| 306 | "MS Sans Serif" on Windows, "Helvetica" on Linux, and "Helvetica" on Solaris. | ||
| 307 | |||
| 308 | =item -basefontsize | ||
| 309 | |||
| 310 | Specify the base size of the font you want to use for all Wizard elements. | ||
| 311 | Titles and subtitles will be drawn a little larger than this; | ||
| 312 | licenses (the proverbial fine print) will be slightly smaller. | ||
| 313 | The default is your operating system default, which on my test computers is | ||
| 314 | 8 on Windows, 12 on Linux, and 12 on Solaris. | ||
| 315 | |||
| 316 | =item -width | ||
| 317 | |||
| 318 | Specify the width of the CONTENT AREA of the Wizard, for all pages. | ||
| 319 | The default width (if you do not give any -width argument) is 50 * the basefontsize. | ||
| 320 | You can override this measure for a particular page by supplying a -width argument to the add*Page() method. | ||
| 321 | |||
| 322 | =item -height | ||
| 323 | |||
| 324 | Specify the height of the CONTENT AREA of the Wizard, for all pages. | ||
| 325 | The default height (if you do not give any -height argument) is 3/4 the default width. | ||
| 326 | You can override for a particular page by supplying a -height argument to the add*Page() method. | ||
| 327 | |||
| 328 | =item -kill_self_after_finish | ||
| 329 | |||
| 330 | The default for the Wizard is to withdraw itself after the "finish" | ||
| 331 | (or "cancel") button is clicked. This allows the Wizard to be reused | ||
| 332 | during the same session (the Wizard will be destroyed when its parent | ||
| 333 | MainWindow is destroyed). | ||
| 334 | If you supply a non-zero value to this option, | ||
| 335 | the Wizard will instead be destroyed after the "finish" button is clicked. | ||
| 336 | |||
| 337 | =back | ||
| 338 | |||
| 339 | Please see also L</ACTION EVENT HANDLERS>. | ||
| 340 | |||
| 341 | =head2 WIZARD REFRESH RATE | ||
| 342 | |||
| 343 | C<$Tk::Wizard::REFRESH_MS> is the number of milliseconds | ||
| 344 | after which an C<update> will be called to redraw the Wizard. | ||
| 345 | Current value is one second. | ||
| 346 | |||
| 347 | =head1 METHODS | ||
| 348 | |||
| 349 | =head2 import | ||
| 350 | |||
| 351 | use Tk::Wizard; | ||
| 352 | use Tk::Wizard (); | ||
| 353 | use Tk::Wizard ':old'; | ||
| 354 | use Tk::Wizard ':use' => [qw[ Choices FileSystem ]]; | ||
| 355 | |||
| 356 | All the above examples are currently equivalent. However, | ||
| 357 | as of version 3.00, later in 2008, the first two will no | ||
| 358 | longer act as the last two -- that is, they will no longer | ||
| 359 | import the methods now located in the C<Choices> and | ||
| 360 | C<FileSystem> modules (L<Tk::Wizard::Choices>, L<Tk::Wizard::FileSystem>): | ||
| 361 | you will have to do that yourself, as in the final example, | ||
| 362 | or manuall: | ||
| 363 | |||
| 364 | use Tk::Wizard; | ||
| 365 | use Tk::Wizard::Tasks; | ||
| 366 | |||
| 367 | =cut | ||
| 368 | |||
| 369 | sub import { | ||
| 370 | my $inv = shift; | ||
| 371 | # The default `use module ()` messes up the logic below; fix with: | ||
| 372 | shift if scalar(@_) and not defined $_[0]; | ||
| 373 | |||
| 374 | TRACE "Enter import for ".$inv; | ||
| 375 | if (scalar @_){ | ||
| 376 | TRACE "Import list : ", join(",",@_); | ||
| 377 | } else { | ||
| 378 | TRACE "No import list"; | ||
| 379 | } | ||
| 380 | |||
| 381 | # Maintian backwards compatabilty while $VERSION < 3 | ||
| 382 | if (not scalar(@_) or $_[0] eq ':old'){ | ||
| 383 | |||
| 384 | require Tk::Wizard::Choices; | ||
| 385 | Tk::Wizard::Choices->import if Tk::Wizard::Choices->can('import'); | ||
| 386 | |||
| 387 | require Tk::Wizard::FileSystem; | ||
| 388 | Tk::Wizard::FileSystem->import if Tk::Wizard::FileSystem->can('import'); | ||
| 389 | |||
| 390 | require Tk::Wizard::Tasks; | ||
| 391 | Tk::Wizard::Tasks->import if Tk::Wizard::Tasks->can('import'); | ||
| 392 | } | ||
| 393 | |||
| 394 | elsif (scalar @_ == 1){ | ||
| 395 | if ($_[0] eq ':none'){ | ||
| 396 | TRACE "Load no modules"; | ||
| 397 | } | ||
| 398 | } | ||
| 399 | |||
| 400 | elsif ($_[0] eq ':use'){ | ||
| 401 | shift; # drop :use - everything else is a sub-module sub-name | ||
| 402 | my $use = shift; | ||
| 403 | foreach my $m (ref $use? @$use : $use){ | ||
| 404 | my $n = 'Tk::Wizard::'.$m.'.pm'; | ||
| 405 | my $o = $n; | ||
| 406 | $n =~ s/::/\//g; | ||
| 407 | # require Tk::Wizard::Choices; | ||
| 408 | require $n; | ||
| 409 | $o->import; | ||
| 410 | } | ||
| 411 | } | ||
| 412 | |||
| 413 | return @_; | ||
| 414 | } | ||
| 415 | |||
| 416 | |||
| 417 | =head2 new | ||
| 418 | |||
| 419 | Create a new C<Tk::Wizard> object. You can provide custom values for any | ||
| 420 | or all of the standard widget options or widget-specific options | ||
| 421 | |||
| 422 | =cut | ||
| 423 | |||
| 424 | # The method is overridden to allow us to supply a MainWindow if one | ||
| 425 | # is not supplied by the caller. Not supplying one suits me, but Mr. | ||
| 426 | # Rothenberg requires one, and he was probably right. | ||
| 427 | |||
| 428 | sub new { | ||
| 429 | TRACE "Enter new with ", (@_ || 'nothing'); | ||
| 430 | my $inv = ref( $_[0] ) ? ref( $_[0] ) : $_[0]; | ||
| 431 | shift; # Ignore invocant | ||
| 432 | |||
| 433 | my @args = @_; | ||
| 434 | |||
| 435 | unless ( | ||
| 436 | ( scalar(@_) % 2 ) # Not a simple list | ||
| 437 | and ref $args[0] # Already got a MainWindow | ||
| 438 | ) { | ||
| 439 | # Get a main window: | ||
| 440 | unshift @args, Tk::MainWindow->new; | ||
| 441 | push @args, "-parent" => $args[0]; | ||
| 442 | push @args, "-kill_parent_on_destroy" => 1; | ||
| 443 | $args[0]->optionAdd( '*BorderWidth' => 1 ); | ||
| 444 | } | ||
| 445 | |||
| 446 | my $self = $inv->SUPER::new(@args); | ||
| 447 | my $font_family = $self->cget( -fontfamily ); | ||
| 448 | my $font_size = $self->cget( -basefontsize ); | ||
| 449 | |||
| 450 | # Font used for &blank_frame titles | ||
| 451 | $self->fontCreate( | ||
| 452 | 'TITLE_FONT', | ||
| 453 | -family => $font_family, | ||
| 454 | -size => $font_size + 4, | ||
| 455 | -weight => 'bold', | ||
| 456 | ); | ||
| 457 | |||
| 458 | $self->fontCreate( | ||
| 459 | 'FIXED', | ||
| 460 | -family => 'Courier', | ||
| 461 | -size => $font_size + 1, | ||
| 462 | ); | ||
| 463 | |||
| 464 | # Font used in multiple choices for radio title | ||
| 465 | $self->fontCreate( | ||
| 466 | 'RADIO_BOLD', | ||
| 467 | -family => $font_family, | ||
| 468 | -size => $font_size + 2, | ||
| 469 | -weight => 'demi', | ||
| 470 | ); | ||
| 471 | |||
| 472 | # Fonts used if -style=>"top" | ||
| 473 | $self->fontCreate( | ||
| 474 | 'TITLE_FONT_TOP', | ||
| 475 | -family => $font_family, | ||
| 476 | -size => $font_size + 4, | ||
| 477 | -weight => 'bold', | ||
| 478 | ); | ||
| 479 | |||
| 480 | $self->fontCreate( | ||
| 481 | 'SUBTITLE_FONT', | ||
| 482 | -family => $font_family, | ||
| 483 | -size => $font_size + 2, | ||
| 484 | ); | ||
| 485 | |||
| 486 | # Font used in licence agreement XXX REMOVE TO CORRECT MODULE | ||
| 487 | $self->fontCreate( | ||
| 488 | 'SMALL_FONT', | ||
| 489 | -family => $font_family, | ||
| 490 | -size => $font_size - 1, | ||
| 491 | ); | ||
| 492 | |||
| 493 | # Font used in all other places | ||
| 494 | $self->fontCreate( | ||
| 495 | 'DEFAULT_FONT', | ||
| 496 | -family => $font_family, | ||
| 497 | -size => $font_size, | ||
| 498 | ); | ||
| 499 | |||
| 500 | $self->{defaultFont} = 'DEFAULT_FONT'; | ||
| 501 | $self->{tagtext}->configure( -font => $self->{defaultFont} ); | ||
| 502 | |||
| 503 | if (not $self->cget('-width') ) { | ||
| 504 | $self->configure( -width => $font_size * 50 ); | ||
| 505 | } | ||
| 506 | |||
| 507 | if (not $self->cget('-height') ) { | ||
| 508 | $self->configure( -height => $self->cget( -width ) * 0.75 ); | ||
| 509 | } | ||
| 510 | return $self; | ||
| 511 | } | ||
| 512 | |||
| 513 | =head2 Populate | ||
| 514 | |||
| 515 | This method is part of the underlying Tk inheritance mechanisms. | ||
| 516 | You the programmer do not necessarily even need to know it exists; | ||
| 517 | we document it here only to satisfy Pod coverage tests. | ||
| 518 | |||
| 519 | =cut | ||
| 520 | |||
| 521 | sub Populate { | ||
| 522 | my ( $self, $args ) = @_; | ||
| 523 | TRACE "Enter Populate"; | ||
| 524 | $self->SUPER::Populate($args); | ||
| 525 | $self->withdraw; | ||
| 526 | my $sTagTextDefault = 'Perl Wizard'; | ||
| 527 | my $font_size = $self->_font_size; | ||
| 528 | |||
| 529 | # $composite->ConfigSpecs(-attribute => [where,dbName,dbClass,default]); | ||
| 530 | $self->ConfigSpecs( | ||
| 531 | -resizable => [ 'SELF', 'resizable', 'Resizable', undef ], | ||
| 532 | |||
| 533 | # Potentially a MainWindow: | ||
| 534 | -parent => [ 'PASSIVE', undef, undef, undef ], | ||
| 535 | -command => [ 'CALLBACK', undef, undef, undef ], | ||
| 536 | |||
| 537 | # -foreground => ['PASSIVE', 'foreground','Foreground', 'black'], | ||
| 538 | -background => [ 'METHOD', 'background', 'Background', $WINDOZE? 'SystemButtonFace' : 'gray90' ], | ||
| 539 | -style => [ 'PASSIVE', "style", "Style", "top" ], | ||
| 540 | -imagepath => [ 'PASSIVE', 'imagepath', 'Imagepath', \$Tk::Wizard::Image::LEFT{WizModernImage} ], | ||
| 541 | -topimagepath => [ 'PASSIVE', 'topimagepath', 'Topimagepath', \$Tk::Wizard::Image::TOP{WizModernSmallImage} ], | ||
| 542 | |||
| 543 | # event handling references | ||
| 544 | -nohelpbutton => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 545 | -preNextButtonAction => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 546 | -postNextButtonAction => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 547 | -preBackButtonAction => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 548 | -postBackButtonAction => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 549 | -preHelpButtonAction => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 550 | -helpButtonAction => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 551 | -postHelpButtonAction => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 552 | -preFinishButtonAction => [ 'CALLBACK', undef, undef, sub { 1 } ], | ||
| 553 | -finishButtonAction => [ 'CALLBACK', undef, undef, sub { $self->withdraw; 1 } ], | ||
| 554 | |||
| 555 | -kill_parent_on_destroy => [ 'PASSIVE', undef, undef, 0 ], | ||
| 556 | -kill_self_after_finish => [ 'PASSIVE', undef, undef, 0 ], | ||
| 557 | -debug => [ 'PASSIVE', undef, undef, 0 ], | ||
| 558 | -preCloseWindowAction => [ 'CALLBACK', undef, undef, sub { $self->DIALOGUE_really_quit } ], | ||
| 559 | -tag_text => [ 'PASSIVE', "tag_text", "TagText", $sTagTextDefault ], | ||
| 560 | -tag_width => [ 'PASSIVE', "tag_width", "TagWidth", 0 ], | ||
| 561 | -wizardFrame => [ 'PASSIVE', undef, undef, 0 ], | ||
| 562 | -width => [ 'PASSIVE', undef, undef, 0 ], | ||
| 563 | -height => [ 'PASSIVE', undef, undef, 0 ], | ||
| 564 | -basefontsize => [ 'PASSIVE', undef, undef, $self->_font_size ], | ||
| 565 | -fontfamily => [ 'PASSIVE', undef, undef, $self->_font_family ], | ||
| 566 | ); | ||
| 567 | |||
| 568 | if ( exists $args->{-imagepath} | ||
| 569 | and not ref($args->{-imagepath}) eq 'SCALAR' and not -e $args->{-imagepath} | ||
| 570 | ) { | ||
| 571 | Carp::confess "Can't find file at -imagepath: " . $args->{-imagepath}; | ||
| 572 | } | ||
| 573 | |||
| 574 | if ( exists $args->{-topimagepath} | ||
| 575 | and not ref($args->{-imagepath}) eq 'SCALAR' and not -e $args->{-topimagepath} | ||
| 576 | ) { | ||
| 577 | Carp::confess "Can't find file at -topimagepath: " . $args->{-topimagepath}; | ||
| 578 | } | ||
| 579 | |||
| 580 | $self->{-imagepath} = $args->{-imagepath}; | ||
| 581 | $self->{-topimagepath} = $args->{-topimagepath}; | ||
| 582 | |||
| 583 | # Here's why we need Page objects | ||
| 584 | $self->{_pages} = []; | ||
| 585 | |||
| 586 | # Events indexed like pages | ||
| 587 | $self->{_pages_e} = {}; | ||
| 588 | |||
| 589 | $self->{_pages_e}->{$_} = [] foreach @PAGE_EVENT_LIST; | ||
| 590 | |||
| 591 | $self->{-debug} = $args->{-debug} || $Tk::Wizard::DEBUG || undef; | ||
| 592 | $self->{background_userchoice} = $args->{-background} || $self->ConfigSpecs->{-background}[3]; | ||
| 593 | $self->{background} = $self->{background_userchoice}; | ||
| 594 | $self->{-style} = $args->{-style} || "top"; | ||
| 595 | $self->{_current_page_idx} = 0; | ||
| 596 | |||
| 597 | # $self->overrideredirect(1); # Removes borders and controls | ||
| 598 | CREATE_BUTTON_PANEL: { | ||
| 599 | my $buttonPanel = $self->Frame( -background => $self->{background}, )->pack(qw/ -side bottom -fill x/); | ||
| 600 | $buttonPanel->configure( -background => 'yellow' ) if DEBUG_FRAME; | ||
| 601 | |||
| 602 | # right margin: | ||
| 603 | my $f = $buttonPanel->Frame( | ||
| 604 | -width => 5, | ||
| 605 | -background => $self->{background}, | ||
| 606 | )->pack( -side => "right", -expand => 0 ); | ||
| 607 | $f->configure( -background => 'red' ) if DEBUG_FRAME; | ||
| 608 | $self->Advertise( buttonPanel => $buttonPanel ); | ||
| 609 | } | ||
| 610 | |||
| 611 | CREATE_TAGLINE: { | ||
| 612 | my $tagbox = $self->Frame( | ||
| 613 | -height => 12, | ||
| 614 | -background => $self->{background}, | ||
| 615 | )->pack(qw/-side bottom -fill x/); | ||
| 616 | $tagbox->configure( -background => 'magenta' ) if DEBUG_FRAME; | ||
| 617 | |||
| 618 | # This is a new, simpler, accurate-width Label way of doing it: | ||
| 619 | $self->{tagtext} = $tagbox->Label( | ||
| 620 | -border => 2, | ||
| 621 | -foreground => 'gray50', | ||
| 622 | -background => $self->{background}, | ||
| 623 | ); | ||
| 624 | $self->{tagtext}->configure( -background => 'red' ) if DEBUG_FRAME; | ||
| 625 | $self->_maybe_pack_tag_text; | ||
| 626 | |||
| 627 | # This is the line that extends to the right from the tag text: | ||
| 628 | $self->{tagline} = $tagbox->Frame( | ||
| 629 | -relief => 'groove', | ||
| 630 | -bd => 1, | ||
| 631 | -height => 2, | ||
| 632 | )->pack(qw( -side right -fill x -expand 1 )); | ||
| 633 | $self->{tagline}->configure( -background => 'yellow' ) if DEBUG_FRAME; | ||
| 634 | $self->Advertise( tagLine => $self->{tagline} ); | ||
| 635 | $self->Advertise( tagBox => $tagbox ); | ||
| 636 | $self->Advertise( tagText => $self->{tagtext} ); | ||
| 637 | } | ||
| 638 | |||
| 639 | # Desktops for dir select: thanks to Slaven Rezic who also suggested | ||
| 640 | # SHGetSpecialFolderLocation for Win32. I have no Win32 on which to test. | ||
| 641 | # There is a good module for this now | ||
| 642 | if ($WINDOZE | ||
| 643 | and exists $ENV{USERPROFILE} | ||
| 644 | and -d "$ENV{USERPROFILE}/Desktop" | ||
| 645 | ) { | ||
| 646 | $self->{desktop_dir} = "$ENV{USERPROFILE}/Desktop"; | ||
| 647 | } | ||
| 648 | elsif (exists $ENV{HOME}){ | ||
| 649 | if ( -d "$ENV{HOME}/Desktop" ) { | ||
| 650 | $self->{desktop_dir} = "$ENV{HOME}/Desktop"; | ||
| 651 | } | ||
| 652 | elsif ( -d "$ENV{HOME}/.gnome-desktop" ) { | ||
| 653 | $self->{desktop_dir} = "$ENV{HOME}/.gnome-desktop"; | ||
| 654 | } | ||
| 655 | } | ||
| 656 | |||
| 657 | } | ||
| 658 | |||
| 659 | |||
| 660 | =head2 parent | ||
| 661 | |||
| 662 | my $apps_main_window = $wizard->parent; | ||
| 663 | |||
| 664 | This returns a reference to the parent Tk widget that was used to create the wizard. | ||
| 665 | |||
| 666 | =cut | ||
| 667 | |||
| 668 | sub parent { return $_[0]->{Configure}{ -parent } || shift } | ||
| 669 | |||
| 670 | sub _maybe_pack_tag_text { | ||
| 671 | my $self = shift; | ||
| 672 | TRACE "Enter _maybe_pack_tag_text"; | ||
| 673 | return if ( ( $self->{Configure}{-tag_text} || '' ) eq '' ); | ||
| 674 | $self->{tagtext}->configure( -text => $self->{Configure}{-tag_text} . ' ' ); | ||
| 675 | $self->{tagtext}->pack(qw( -side left -padx 0 -ipadx 2 )); | ||
| 676 | } | ||
| 677 | |||
| 678 | sub _pack_forget { | ||
| 679 | my $self = shift; | ||
| 680 | foreach my $o (@_) { | ||
| 681 | $o->packForget if Tk::Exists($o); | ||
| 682 | } | ||
| 683 | } | ||
| 684 | |||
| 685 | # Private method: returns a font family name suitable for the | ||
| 686 | # operating system. (The default system font, if we can determine it) | ||
| 687 | sub _font_family { | ||
| 688 | my $self = shift; | ||
| 689 | |||
| 690 | # Find the default font on this platform: | ||
| 691 | my $label = $self->Label; | ||
| 692 | my $sFont = $label->cget( -font ); | ||
| 693 | return $1 if $sFont =~ /{(.+?)}/; | ||
| 694 | return 'Verdana' if $WINDOZE; | ||
| 695 | return 'Helvetica'; | ||
| 696 | } | ||
| 697 | |||
| 698 | |||
| 699 | # Private method: returns a font size suitable for the operating | ||
| 700 | # system. (The default system font size, if we can determine it) | ||
| 701 | sub _font_size { | ||
| 702 | my $self = shift; | ||
| 703 | |||
| 704 | # Find the default font on this platform: | ||
| 705 | my $label = $self->Label; | ||
| 706 | my $sFont = $label->cget( -font ); | ||
| 707 | return $1 if $sFont =~ /(\d+)/; | ||
| 708 | return 8 if $WINDOZE; | ||
| 709 | return 12; # Linux etc. | ||
| 710 | } | ||
| 711 | |||
| 712 | |||
| 713 | =head2 background | ||
| 714 | |||
| 715 | Get/set the background color for the body of the Wizard. | ||
| 716 | |||
| 717 | =cut | ||
| 718 | |||
| 719 | sub background { | ||
| 720 | my $self = shift; | ||
| 721 | my $operand = shift; | ||
| 722 | if ( defined($operand) ) { | ||
| 723 | $self->{background} = $operand; | ||
| 724 | } | ||
| 725 | elsif ($self->{-style} ne '95' and ( | ||
| 726 | $self->_on_first_page or $self->_on_last_page ) | ||
| 727 | ){ | ||
| 728 | $self->{background} = 'white'; | ||
| 729 | } | ||
| 730 | else { | ||
| 731 | $self->{background} = $self->{background_userchoice}; | ||
| 732 | } | ||
| 733 | return $self->{background}; | ||
| 734 | } | ||
| 735 | |||
| 736 | # Sub-class me! | ||
| 737 | # Called by Show(). | ||
| 738 | sub _initial_layout { | ||
| 739 | my $self = shift; | ||
| 740 | TRACE "Enter _initial_layout"; | ||
| 741 | return if $self->{_laid_out}; | ||
| 742 | |||
| 743 | # Wizard 98/95 style | ||
| 744 | if ( $self->_showing_side_banner ) { | ||
| 745 | my $im = $self->cget( -imagepath ); | ||
| 746 | if ( not ref $im ) { | ||
| 747 | DEBUG "Load photo from file $im"; | ||
| 748 | FATAL "No such file as $im" unless -e $im; | ||
| 749 | DEBUG $self; | ||
| 750 | $self->Photo( "sidebanner", -file => $im ); | ||
| 751 | } | ||
| 752 | else { | ||
| 753 | $self->Photo( "sidebanner", -data => $$im ); | ||
| 754 | } | ||
| 755 | |||
| 756 | # Hard-code white background for first and last page | ||
| 757 | my $bg = | ||
| 758 | $self->_on_first_page ? 'white' | ||
| 759 | : $self->_on_last_page ? 'white' | ||
| 760 | : $self->{background}; | ||
| 761 | |||
| 762 | $self->{left_object} = $self->Label( | ||
| 763 | -image => "sidebanner", | ||
| 764 | -anchor => "n", | ||
| 765 | -background => $bg, | ||
| 766 | )->pack( | ||
| 767 | -anchor => "n", | ||
| 768 | -fill => 'y', | ||
| 769 | ); | ||
| 770 | $self->{left_object}->configure( -background => 'blue' ) if DEBUG_FRAME; | ||
| 771 | } | ||
| 772 | |||
| 773 | # Wizard 2k style - builds the left side of the wizard | ||
| 774 | else { | ||
| 775 | my $im = $self->cget( -topimagepath ); | ||
| 776 | if ( ref $im ) { | ||
| 777 | $self->Photo( "topbanner", -data => $$im ); | ||
| 778 | } | ||
| 779 | else { | ||
| 780 | $self->Photo( "topbanner", -file => $im ); | ||
| 781 | } | ||
| 782 | $self->{left_object} = $self->Label( -image => "topbanner" )->pack( -side => "top", -anchor => "e", ); | ||
| 783 | } | ||
| 784 | $self->Advertise( imagePane => $self->{left_object} ); | ||
| 785 | $self->{_laid_out}++; | ||
| 786 | } | ||
| 787 | |||
| 788 | |||
| 789 | # Maybe sub-class me | ||
| 790 | sub _render_current_page { | ||
| 791 | my $self = shift; | ||
| 792 | TRACE "Enter _render_current_page $self->{_current_page_idx}"; | ||
| 793 | my %frame_pack = ( -side => "top" ); | ||
| 794 | |||
| 795 | $self->_pack_forget( $self->{tagtext} ); | ||
| 796 | |||
| 797 | if (not $self->_showing_side_banner ) { | ||
| 798 | $self->_maybe_pack_tag_text; | ||
| 799 | } | ||
| 800 | |||
| 801 | if ($self->_on_first_page or $self->_on_last_page) { | ||
| 802 | $self->{left_object}->pack( -side => "left", -anchor => "n", -fill => 'y' ); | ||
| 803 | if ( $self->{-style} ne '95' ) { | ||
| 804 | $frame_pack{-expand} = 1; | ||
| 805 | $frame_pack{-fill} = 'both'; | ||
| 806 | } | ||
| 807 | } | ||
| 808 | |||
| 809 | elsif ( $self->cget( -style ) eq 'top' ) { | ||
| 810 | $self->_pack_forget( $self->{left_object} ); | ||
| 811 | } | ||
| 812 | |||
| 813 | # Take page-event from the store and apply to the object. | ||
| 814 | # These compromises are getting silly, and indicative of the | ||
| 815 | # need for a slight refactoring. | ||
| 816 | |||
| 817 | # TRACE "Page == $self->{_current_page_idx}"; | ||
| 818 | foreach my $e (@PAGE_EVENT_LIST){ | ||
| 819 | # TRACE "E = $e"; | ||
| 820 | # TRACE Dumper $self->{_pages_e}; | ||
| 821 | my $code = $self->{_pages_e}->{$e}->[ $self->{_current_page_idx} ] || undef; | ||
| 822 | # TRACE $code if $code; | ||
| 823 | if (defined $code){ | ||
| 824 | $self->configure( $e => $code ) | ||
| 825 | } else { | ||
| 826 | # $self->configure( $e => undef ) | ||
| 827 | } | ||
| 828 | } | ||
| 829 | |||
| 830 | # $self->_repack_buttons done below; | ||
| 831 | |||
| 832 | # Process button events and re-rendering | ||
| 833 | my $panel = $self->Subwidget('buttonPanel'); | ||
| 834 | my %hssPackArgs = ( | ||
| 835 | -side => "right", -expand => 0, -pady => 5, -padx => 5, -ipadx => 8, | ||
| 836 | ); | ||
| 837 | $self->_pack_forget( | ||
| 838 | @{ $self->{_button_spacers} }, | ||
| 839 | $self->{cancelButton}, | ||
| 840 | $self->{nextButton}, $self->{backButton}, $self->{helpButton}, | ||
| 841 | ); | ||
| 842 | |||
| 843 | # No cancel button on the last page | ||
| 844 | unless ($self->_on_last_page ) { | ||
| 845 | $self->{cancelButton} = $panel->Button( | ||
| 846 | -font => $self->{defaultFont}, | ||
| 847 | -text => $LABELS{CANCEL}, | ||
| 848 | -command => [ \&_CancelButtonEventCycle, $self, $self ], | ||
| 849 | )->pack(%hssPackArgs); | ||
| 850 | |||
| 851 | # Set the cancel button a little apart from the next button: | ||
| 852 | my $f1 = $panel->Frame( | ||
| 853 | -width => 8, | ||
| 854 | -background => $panel->cget( "-background" ), | ||
| 855 | )->pack( -side => "right" ); | ||
| 856 | |||
| 857 | $f1->configure( -background => 'black' ) if DEBUG_FRAME; | ||
| 858 | push @{ $self->{_button_spacers} }, $f1; | ||
| 859 | $self->Advertise( cancelButton => $self->{cancelButton} ); | ||
| 860 | } | ||
| 861 | |||
| 862 | $self->{nextButton} = $panel->Button( | ||
| 863 | -font => $self->{defaultFont}, | ||
| 864 | -text => $self->_on_last_page ? $LABELS{FINISH} : $LABELS{NEXT}, | ||
| 865 | -command => [ \&_NextButtonEventCycle, $self ], | ||
| 866 | )->pack(%hssPackArgs); | ||
| 867 | $self->Advertise( nextButton => $self->{nextButton} ); | ||
| 868 | |||
| 869 | $self->{backButton} = $panel->Button( | ||
| 870 | -font => $self->{defaultFont}, | ||
| 871 | -text => $LABELS{BACK}, | ||
| 872 | -command => [ \&_BackButtonEventCycle, $self ], | ||
| 873 | -state => $self->_on_first_page ? 'disabled' : 'normal', | ||
| 874 | )->pack(%hssPackArgs); | ||
| 875 | $self->Advertise( backButton => $self->{backButton} ); | ||
| 876 | |||
| 877 | # Optional help button: | ||
| 878 | unless ($self->cget( -nohelpbutton ) ) { | ||
| 879 | $self->{helpButton} = $panel->Button( | ||
| 880 | -font => $self->{defaultFont}, | ||
| 881 | -text => $LABELS{HELP}, | ||
| 882 | -command => [ \&_HelpButtonEventCycle, $self ], | ||
| 883 | )->pack( | ||
| 884 | -side => 'left', -anchor => 'w', | ||
| 885 | -pady => 10, -padx => 10, | ||
| 886 | -ipadx => 8, | ||
| 887 | ); | ||
| 888 | $self->Advertise( helpButton => $self->{helpButton} ); | ||
| 889 | } | ||
| 890 | |||
| 891 | |||
| 892 | $self->configure( -background => $self->cget("-background") ); | ||
| 893 | $self->_pack_forget( $self->{wizardFrame} ); | ||
| 894 | |||
| 895 | if (not @{ $self->{_pages} } ) { | ||
| 896 | LOGCROAK '_render_current_page called without any frames: did you add frames to the wizard?'; | ||
| 897 | } | ||
| 898 | my $page = $self->{_pages}->[ $self->{_current_page_idx} ]; | ||
| 899 | |||
| 900 | if (not ref $page){ | ||
| 901 | LOGCROAK '_render_current_page() called for a non-existent frame: did you add frames to the wizard?'; | ||
| 902 | } | ||
| 903 | |||
| 904 | my $frame = $page->(); | ||
| 905 | if (not Tk::Exists($frame) ) { | ||
| 906 | LOGCROAK '_render_current_page() called for a non-frame: did your coderef argument to addPage() return something other than a Tk::Frame? '.Dumper($page); | ||
| 907 | } | ||
| 908 | |||
| 909 | $self->{wizardFrame} = $frame->pack(%frame_pack); | ||
| 910 | $self->{wizardFrame}->update; | ||
| 911 | |||
| 912 | # Update the wizard every 1000 seconds | ||
| 913 | $self->{_refresh_event_id} = $self->{wizardFrame}->repeat( | ||
| 914 | $REFRESH_MS, | ||
| 915 | sub { $self->{wizardFrame}->update } | ||
| 916 | ) if not $self->{_refresh_event_id}; | ||
| 917 | |||
| 918 | $self->Advertise( wizardFrame => $self->{wizardFrame} ); | ||
| 919 | |||
| 920 | $self->{nextButton}->focus(); | ||
| 921 | TRACE "Leave _render_current_page $self->{_current_page_idx}"; | ||
| 922 | } | ||
| 923 | |||
| 924 | =head2 update | ||
| 925 | |||
| 926 | Redraws the Wizard. | ||
| 927 | |||
| 928 | =cut | ||
| 929 | |||
| 930 | sub update { | ||
| 931 | my $self = shift; | ||
| 932 | $self->{wizardFrame}->update if $self->{wizardFrame}; | ||
| 933 | return 1; | ||
| 934 | } | ||
| 935 | |||
| 936 | |||
| 937 | # I wish I could remember why this was used, and then dropped: | ||
| 938 | sub _resize_window { | ||
| 939 | my $self = shift; | ||
| 940 | return; | ||
| 941 | if ( Tk::Exists( $self->{wizardFrame} ) ) { | ||
| 942 | if ( $self->{frame_sizes}->[ $self->{_current_page_idx} ] ) { | ||
| 943 | my ( $iW, $iH ) = @{ $self->{frame_sizes}->[ $self->{_current_page_idx} ] }; | ||
| 944 | DEBUG "Resize frame: -width => $iW, -height => $iH\n"; | ||
| 945 | $self->{wizardFrame}->configure( | ||
| 946 | -width => $iW, | ||
| 947 | -height => $iH, | ||
| 948 | ); | ||
| 949 | $self->{wizardFrame}->update; | ||
| 950 | # $self->update; | ||
| 951 | } | ||
| 952 | } | ||
| 953 | } | ||
| 954 | |||
| 955 | =head2 blank_frame | ||
| 956 | |||
| 957 | my $frame = wizard>->blank_frame( | ||
| 958 | -title => $sTitle, | ||
| 959 | -subtitle => $sSub, | ||
| 960 | -text => $sStandfirst, | ||
| 961 | -wait => $iMilliseconds | ||
| 962 | ); | ||
| 963 | |||
| 964 | Returns a L<Tk::Frame|Tk::Frame> object that is a child of the Wizard | ||
| 965 | control, with some C<pack>ing parameters applied - for more details, | ||
| 966 | please see C<-style> entry elsewhere in this document. | ||
| 967 | |||
| 968 | Arguments are name/value pairs: | ||
| 969 | |||
| 970 | =over 4 | ||
| 971 | |||
| 972 | =item -title | ||
| 973 | |||
| 974 | Printed in a big, bold font at the top of the frame | ||
| 975 | |||
| 976 | =item -subtitle | ||
| 977 | |||
| 978 | Subtitle/stand-first. | ||
| 979 | |||
| 980 | =item -text | ||
| 981 | |||
| 982 | Main body text. | ||
| 983 | |||
| 984 | =item -wait | ||
| 985 | |||
| 986 | The amount of time in milliseconds to wait before moving forward | ||
| 987 | regardless of the user. | ||
| 988 | |||
| 989 | This actually just calls the C<forward> method (see | ||
| 990 | L</forward>). Use of this feature will enable the back-button even if | ||
| 991 | you have disabled it. What's more, if the page is supposed to wait for user | ||
| 992 | input, this feature will probably not give your users a chance. | ||
| 993 | |||
| 994 | B<Beware> that if you set this value too low, you find your | ||
| 995 | callbacks interrupting previous callbacks, Values below 250 will be set to 250, | ||
| 996 | but you may need 1000. | ||
| 997 | |||
| 998 | See also: L<Tk::after>. | ||
| 999 | |||
| 1000 | =item -width -height | ||
| 1001 | |||
| 1002 | Size of the CONTENT AREA of the wizard. | ||
| 1003 | Yes, you can set a different size for each page! | ||
| 1004 | |||
| 1005 | =back | ||
| 1006 | |||
| 1007 | Also: | ||
| 1008 | |||
| 1009 | -background | ||
| 1010 | |||
| 1011 | =cut | ||
| 1012 | |||
| 1013 | # | ||
| 1014 | # Sub-class me: | ||
| 1015 | # accept the args in the POD and return a Tk::Frame | ||
| 1016 | # | ||
| 1017 | sub blank_frame { | ||
| 1018 | my $self = shift; | ||
| 1019 | my $args = {@_}; | ||
| 1020 | TRACE "Enter blank_frame"; | ||
| 1021 | DEBUG "self.bg = $self->{background}"; | ||
| 1022 | |||
| 1023 | my $wrap = $args->{-wraplength} || 375; | ||
| 1024 | if (not defined( $args->{-height} ) ) { | ||
| 1025 | $args->{-height} = $self->cget( -height ); | ||
| 1026 | } | ||
| 1027 | |||
| 1028 | if (not defined( $args->{-width} ) ) { | ||
| 1029 | $args->{-width} = $self->cget( -width ); | ||
| 1030 | $args->{-width} += $self->{left_object}->width | ||
| 1031 | if !$self->_showing_side_banner; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | $self->{frame_sizes}->[ $self->{_current_page_idx} ] = [ $args->{-width}, $args->{-height} ]; | ||
| 1035 | $self->{frame_titles}->[ $self->{_current_page_idx} ] = $args->{-title} || 'no title given'; | ||
| 1036 | |||
| 1037 | DEBUG "blank_frame setting width/height to $args->{-width}/$args->{-height}"; | ||
| 1038 | |||
| 1039 | # This is the main content frame: | ||
| 1040 | my $frame = $self->Frame( | ||
| 1041 | -width => $args->{-width}, | ||
| 1042 | -height => $args->{-height}, | ||
| 1043 | -background => $self->{background}, | ||
| 1044 | ); | ||
| 1045 | $frame->configure( -background => 'green' ) if DEBUG_FRAME; | ||
| 1046 | |||
| 1047 | # Do not let the content (body) frame auto-resize when we pack its contents: | ||
| 1048 | $frame->packPropagate(0); | ||
| 1049 | $args->{-title} ||= ''; | ||
| 1050 | |||
| 1051 | # We force the title to be one line (sorry): | ||
| 1052 | $args->{-title} =~ s/[\n\r\f]/ /g; | ||
| 1053 | $args->{-subtitle} ||= ''; | ||
| 1054 | |||
| 1055 | # We don't let the subtitle get pushed down away from the title: | ||
| 1056 | $args->{-subtitle} =~ s/^[\n\r\f]*//; | ||
| 1057 | my ($lTitle, $lSub, $lText); | ||
| 1058 | |||
| 1059 | if (not $self->_showing_side_banner ) { | ||
| 1060 | |||
| 1061 | # For 'top' style pages other than first and last | ||
| 1062 | my $top_frame = $frame->Frame( -background => 'white', )->pack( | ||
| 1063 | -fill => 'x', | ||
| 1064 | -side => 'top', | ||
| 1065 | -anchor => 'e' | ||
| 1066 | ); | ||
| 1067 | my $p = $top_frame->Frame( -background => 'white' ); | ||
| 1068 | my $photo = $self->cget( -topimagepath ); | ||
| 1069 | if ( ref $photo ) { | ||
| 1070 | $p->Photo( "topimage", -data => $$photo ); | ||
| 1071 | } | ||
| 1072 | else { | ||
| 1073 | $p->Photo( "topimage", -file => $photo ); | ||
| 1074 | } | ||
| 1075 | |||
| 1076 | $p->Label( | ||
| 1077 | -image => "topimage", | ||
| 1078 | -background => 'white', | ||
| 1079 | )->pack( | ||
| 1080 | -side => "right", | ||
| 1081 | -anchor => "e", | ||
| 1082 | -padx => 5, | ||
| 1083 | -pady => 5, | ||
| 1084 | ); | ||
| 1085 | $p->pack( -side => 'right', -anchor => 'n' ); | ||
| 1086 | |||
| 1087 | my $title_frame = $top_frame->Frame( -background => 'white', )->pack( | ||
| 1088 | -side => 'left', | ||
| 1089 | -anchor => 'w', | ||
| 1090 | -expand => 1, | ||
| 1091 | -fill => 'x', | ||
| 1092 | ); | ||
| 1093 | my $f = $title_frame->Frame(qw/-background white -width 10 -height 30/)->pack(qw/-fill x -anchor n -side left/); | ||
| 1094 | |||
| 1095 | $f->configure( -background => 'yellow' ) if DEBUG_FRAME; | ||
| 1096 | |||
| 1097 | # The title frame content proper: | ||
| 1098 | $lTitle = $title_frame->Label( | ||
| 1099 | -justify => 'left', | ||
| 1100 | -anchor => 'w', | ||
| 1101 | -text => $args->{-title}, | ||
| 1102 | -font => 'TITLE_FONT_TOP', | ||
| 1103 | -background => $title_frame->cget("-background"), | ||
| 1104 | )->pack( | ||
| 1105 | -side => 'top', | ||
| 1106 | -expand => 1, | ||
| 1107 | -fill => 'x', | ||
| 1108 | -pady => 5, | ||
| 1109 | -padx => 0, | ||
| 1110 | ); | ||
| 1111 | |||
| 1112 | $lSub = $title_frame->Label( | ||
| 1113 | -font => 'SUBTITLE_FONT', | ||
| 1114 | -justify => 'left', | ||
| 1115 | -anchor => 'w', | ||
| 1116 | -text => ' ' . $args->{-subtitle}, | ||
| 1117 | -background => $title_frame->cget("-background"), | ||
| 1118 | )->pack( | ||
| 1119 | -side => 'top', | ||
| 1120 | -expand => 0, | ||
| 1121 | -fill => 'x', | ||
| 1122 | -padx => 5, | ||
| 1123 | ); | ||
| 1124 | |||
| 1125 | # This is the line below top: | ||
| 1126 | if ( ( $self->cget( -style ) eq 'top' ) && !$self->_on_first_page ) { | ||
| 1127 | my $f = $frame->Frame( | ||
| 1128 | -relief => 'groove', | ||
| 1129 | -bd => 1, | ||
| 1130 | -height => 2, | ||
| 1131 | )->pack(qw/-side top -fill x/); | ||
| 1132 | $f->configure( -background => 'red' ) if DEBUG_FRAME; | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | if ( $args->{-text} ) { | ||
| 1136 | $lText = $frame->Label( | ||
| 1137 | -font => $self->{defaultFont}, | ||
| 1138 | -justify => 'left', | ||
| 1139 | -anchor => 'w', | ||
| 1140 | -wraplength => $wrap + 100, | ||
| 1141 | -justify => "left", | ||
| 1142 | -text => $args->{-text}, | ||
| 1143 | -background => $self->{background}, | ||
| 1144 | )->pack( | ||
| 1145 | -side => 'top', | ||
| 1146 | |||
| 1147 | # -anchor => 'n', | ||
| 1148 | # -expand => 1, | ||
| 1149 | -expand => 0, | ||
| 1150 | -fill => 'x', | ||
| 1151 | -padx => 10, | ||
| 1152 | -pady => 10, | ||
| 1153 | ); | ||
| 1154 | } | ||
| 1155 | } | ||
| 1156 | |||
| 1157 | # if 'top' style, but not first or last page | ||
| 1158 | # Whenever page does NOT have the side banner: | ||
| 1159 | else { | ||
| 1160 | $lTitle = $frame->Label( | ||
| 1161 | -justify => 'left', | ||
| 1162 | -anchor => 'w', | ||
| 1163 | -text => $args->{-title}, | ||
| 1164 | -font => 'TITLE_FONT', | ||
| 1165 | -background => $frame->cget("-background"), | ||
| 1166 | )->pack( | ||
| 1167 | -side => 'top', | ||
| 1168 | -anchor => 'n', | ||
| 1169 | -expand => 0, # 1 | ||
| 1170 | -fill => 'x', | ||
| 1171 | ); | ||
| 1172 | $lSub = $frame->Label( | ||
| 1173 | -font => 'SUBTITLE_FONT', | ||
| 1174 | -justify => 'left', | ||
| 1175 | -anchor => 'w', | ||
| 1176 | -text => ' ' . $args->{-subtitle}, | ||
| 1177 | -background => $frame->cget("-background"), | ||
| 1178 | )->pack( | ||
| 1179 | -anchor => 'n', | ||
| 1180 | -side => 'top', | ||
| 1181 | -expand => 0, | ||
| 1182 | -fill => 'x', | ||
| 1183 | ); | ||
| 1184 | |||
| 1185 | if ( $args->{-text} ) { | ||
| 1186 | $lText = $frame->Label( | ||
| 1187 | -font => $self->{defaultFont}, | ||
| 1188 | -justify => 'left', | ||
| 1189 | -anchor => 'w', | ||
| 1190 | -wraplength => $wrap, | ||
| 1191 | -justify => "left", | ||
| 1192 | -text => $args->{-text}, | ||
| 1193 | -background => $frame->cget("-background"), | ||
| 1194 | )->pack( | ||
| 1195 | -side => 'top', | ||
| 1196 | -expand => 0, | ||
| 1197 | -fill => 'x', | ||
| 1198 | -pady => 10, | ||
| 1199 | ); | ||
| 1200 | } | ||
| 1201 | else { | ||
| 1202 | $frame->Label(); | ||
| 1203 | } | ||
| 1204 | } | ||
| 1205 | |||
| 1206 | if (DEBUG_FRAME){ | ||
| 1207 | $lTitle->configure( -background => 'light blue' ); | ||
| 1208 | $lSub->configure( -background => 'light green' ); | ||
| 1209 | Tk::Exists($lText) && $lText->configure( -background => 'pink' ); | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | DEBUG "blank_frame(), raw -wait is ".($args->{-wait} || "undef"); | ||
| 1213 | $args->{ -wait } ||= 0; | ||
| 1214 | DEBUG "blank_frame(), cooked -wait is now $args->{-wait}"; | ||
| 1215 | |||
| 1216 | if ( $args->{ -wait } > 0 ) { | ||
| 1217 | _fix_wait( \$args->{ -wait } ); | ||
| 1218 | DEBUG "In blank_frame(), fixed -wait is $args->{-wait}"; | ||
| 1219 | DEBUG "Installing 'after', self is $self"; | ||
| 1220 | $self->after( | ||
| 1221 | $args->{-wait}, | ||
| 1222 | sub { | ||
| 1223 | $self->{nextButton}->configure( -state => 'normal' ); | ||
| 1224 | $self->{nextButton}->invoke; | ||
| 1225 | } | ||
| 1226 | ); | ||
| 1227 | } | ||
| 1228 | |||
| 1229 | return $frame->pack(qw/-side top -anchor n -fill both -expand 1/); | ||
| 1230 | } | ||
| 1231 | |||
| 1232 | |||
| 1233 | =head2 addPage | ||
| 1234 | |||
| 1235 | $wizard->addPage ($page_code_ref1 ... $page_code_refN) | ||
| 1236 | $wizard->addPage (@args) | ||
| 1237 | $wizard->addPage ($page_code_ref, -preNextButtonAction => $x, -postNextButtonAction => $y) | ||
| 1238 | |||
| 1239 | Adds a page to the wizard. The parameters must be references to code that | ||
| 1240 | evaluate to L<Tk::Frame|Tk::Frame> objects, such as those returned by the methods | ||
| 1241 | C<blank_frame> and C<addDirSelectPage>. | ||
| 1242 | |||
| 1243 | Pages are (currently) stored and displayed in the order added. | ||
| 1244 | |||
| 1245 | Returns the index of the page added, which is useful as a page UID when | ||
| 1246 | performing checks as the I<Next> button is pressed (see file F<test.pl> | ||
| 1247 | supplied with the distribution). | ||
| 1248 | |||
| 1249 | As of version 2.084, you can just supply the args to L<blank_frame|blank_frame>. | ||
| 1250 | |||
| 1251 | As of version 2.076, you may supply arguments: C<-preNextButtonAction>, | ||
| 1252 | C<-postNextButtonAction>, C<-preBackButtonAction>, C<-postBackButtonAction>: | ||
| 1253 | see L<ACTION EVENT HANDLERS> for further information. More handlers, and | ||
| 1254 | more documentation, may be added. | ||
| 1255 | |||
| 1256 | =cut | ||
| 1257 | |||
| 1258 | sub addPage { | ||
| 1259 | TRACE "Enter addPage"; | ||
| 1260 | my ($self, @args) = @_; | ||
| 1261 | |||
| 1262 | # Bit faster if, as of old, all args are code refs (ie no events): | ||
| 1263 | if (scalar (grep { ref $_ eq 'CODE' } @args) == scalar(@args)) { | ||
| 1264 | DEBUG "Add args to make ".scalar @{ $self->{_pages} }; | ||
| 1265 | push @{ $self->{_pages} }, @args; | ||
| 1266 | } | ||
| 1267 | |||
| 1268 | # Add pages with arguments: | ||
| 1269 | else { | ||
| 1270 | my ($code, @sub_args, $found); | ||
| 1271 | while (@args){ | ||
| 1272 | if (ref $args[0] eq 'CODE'){ | ||
| 1273 | $found = 1; | ||
| 1274 | if (defined $code){ | ||
| 1275 | DEBUG "Call _addPage_with_args..."; | ||
| 1276 | $self->_addPage_with_args($code, @sub_args); | ||
| 1277 | } | ||
| 1278 | else { | ||
| 1279 | DEBUG "No code yet..."; | ||
| 1280 | } | ||
| 1281 | @sub_args = (); | ||
| 1282 | $code = shift @args; | ||
| 1283 | } | ||
| 1284 | else { | ||
| 1285 | DEBUG "Add to sub_args..."; | ||
| 1286 | push @sub_args, shift(@args), shift(@args); | ||
| 1287 | } | ||
| 1288 | } | ||
| 1289 | |||
| 1290 | if (defined $code){ | ||
| 1291 | $found = 1; | ||
| 1292 | DEBUG "Call _addPage_with_args (finally)"; | ||
| 1293 | $self->_addPage_with_args($code, @sub_args); | ||
| 1294 | } | ||
| 1295 | |||
| 1296 | if (not $found){ | ||
| 1297 | DEBUG "No code ref found: blank frame from args: ", join", ",@sub_args; | ||
| 1298 | push @{ $self->{_pages} }, sub { $self->blank_frame(@sub_args) }; | ||
| 1299 | } | ||
| 1300 | } | ||
| 1301 | |||
| 1302 | TRACE "Leave addpage"; | ||
| 1303 | return scalar @{ $self->{_pages} }; | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | |||
| 1307 | sub _addPage_with_args { | ||
| 1308 | TRACE "Enter _addPage_with_args"; | ||
| 1309 | my ($self, $code) = (shift, shift); | ||
| 1310 | my $args = scalar(@_)? {@_} : {}; | ||
| 1311 | |||
| 1312 | # Add the page | ||
| 1313 | DEBUG "Adding code ".Dumper $code; | ||
| 1314 | push @{ $self->{_pages} }, $code; | ||
| 1315 | |||
| 1316 | # Add the arguments | ||
| 1317 | DEBUG "ARGS ",Dumper $args; | ||
| 1318 | foreach my $e (@PAGE_EVENT_LIST){ | ||
| 1319 | DEBUG "Add $e for $#{$self->{_pages}}" if defined $args->{$e}; | ||
| 1320 | $self->{_pages_e}->{$e}->[ $#{$self->{_pages}} ] = $args->{$e} || undef; | ||
| 1321 | } | ||
| 1322 | TRACE "Leave _addPage_with_args"; | ||
| 1323 | } | ||
| 1324 | |||
| 1325 | |||
| 1326 | =head2 addSplashPage | ||
| 1327 | |||
| 1328 | Add to the wizard a page containing a chunk of text, specified in | ||
| 1329 | the parameter C<-text>. Suitable for an introductory "splash" page | ||
| 1330 | and for a final "all done" page. | ||
| 1331 | |||
| 1332 | Accepts exactly the same arguments as C<blank_frame>. | ||
| 1333 | |||
| 1334 | =cut | ||
| 1335 | |||
| 1336 | sub addSplashPage { | ||
| 1337 | TRACE "Enter addSplashPage"; | ||
| 1338 | my ($self, $args) = (shift, {@_}); | ||
| 1339 | return $self->addPage( sub { $self->blank_frame(%$args) } ); | ||
| 1340 | } | ||
| 1341 | |||
| 1342 | =head2 addTextFramePage | ||
| 1343 | |||
| 1344 | Add to the wizard a page containing a scrolling textbox, specified in | ||
| 1345 | the parameter C<-boxedtext>. If this is a reference to a scalar, it is | ||
| 1346 | taken to be plain text; if a plain scalar, it is taken to be the name | ||
| 1347 | of a file to be opened and read. | ||
| 1348 | |||
| 1349 | Accepts the usual C<-title>, C<-subtitle>, and C<-text> like C<blank_frame>. | ||
| 1350 | |||
| 1351 | =cut | ||
| 1352 | |||
| 1353 | sub addTextFramePage { | ||
| 1354 | my ($self, $args) = (shift, {@_}); | ||
| 1355 | DEBUG "addTextFramePage args are ", Dumper($args); | ||
| 1356 | return $self->addPage( sub { $self->_text_frame($args) } ); | ||
| 1357 | } | ||
| 1358 | |||
| 1359 | sub _text_frame { | ||
| 1360 | my $self = shift; | ||
| 1361 | my $args = shift; | ||
| 1362 | |||
| 1363 | DEBUG "Enter _text_frame with ", Dumper($args); | ||
| 1364 | my $text; | ||
| 1365 | my $frame = $self->blank_frame(%$args); | ||
| 1366 | if ( $args->{-boxedtext} ) { | ||
| 1367 | if ( ref $args->{-boxedtext} eq 'SCALAR' ) { | ||
| 1368 | $text = $args->{-boxedtext}; | ||
| 1369 | } | ||
| 1370 | elsif ( not ref $args->{-boxedtext} ) { | ||
| 1371 | open my $in, $args->{-boxedtext} | ||
| 1372 | or LOGCROAK "Could not read file: $args->{-boxedtext}; $!"; | ||
| 1373 | read $in, $$text, -s $in; | ||
| 1374 | close $in; | ||
| 1375 | WARN "Boxedtext file $args->{-boxedtext} is empty." if not length $text; | ||
| 1376 | } | ||
| 1377 | } | ||
| 1378 | $$text = "" if not defined $text; | ||
| 1379 | my $t = $frame->Scrolled( | ||
| 1380 | "ROText", | ||
| 1381 | -background => ( $args->{ -background } || 'white' ), | ||
| 1382 | -relief => "sunken", | ||
| 1383 | -borderwidth => "1", | ||
| 1384 | -font => $self->{defaultFont}, | ||
| 1385 | -scrollbars => "osoe", | ||
| 1386 | -wrap => "word", | ||
| 1387 | )->pack(qw/-expand 1 -fill both -padx 10 -pady 10/); | ||
| 1388 | |||
| 1389 | $t->configure( -background => 'green' ) if DEBUG_FRAME; | ||
| 1390 | $t->insert( '0.0', $$text ); | ||
| 1391 | $t->configure( -state => "disabled" ); | ||
| 1392 | |||
| 1393 | return $frame; | ||
| 1394 | } | ||
| 1395 | |||
| 1396 | # | ||
| 1397 | # Function (NOT a method!): _dispatch | ||
| 1398 | # Description: Thin wrapper to dispatch event cycles as needed | ||
| 1399 | # Parameters: The _dispatch function is an internal function used to determine if the dispatch back reference | ||
| 1400 | # is undefined or if it should be dispatched. Undefined methods are used to denote dispatchback | ||
| 1401 | # methods to bypass. This reduces the number of method dispatches made for each handler and also | ||
| 1402 | # increased the usability of the set methods when trying to unregister event handlers. | ||
| 1403 | # | ||
| 1404 | sub _dispatch { | ||
| 1405 | my $handler = shift; | ||
| 1406 | DEBUG "Enter _dispatch with " . ( $handler || "undef" ); | ||
| 1407 | |||
| 1408 | if ( ref($handler) eq 'Tk::Callback' ) { | ||
| 1409 | return !$handler->Call(); | ||
| 1410 | } | ||
| 1411 | |||
| 1412 | if ( ref($handler) eq 'CODE' ) { | ||
| 1413 | return !$handler->(); | ||
| 1414 | } | ||
| 1415 | |||
| 1416 | return 1; | ||
| 1417 | |||
| 1418 | # Below is the original 1.9451 version: | ||
| 1419 | return ( !( $handler->Call() ) ) | ||
| 1420 | if defined $handler | ||
| 1421 | and ref $handler | ||
| 1422 | and ref $handler eq 'CODE'; | ||
| 1423 | |||
| 1424 | return 0; | ||
| 1425 | } | ||
| 1426 | |||
| 1427 | # Returns the number of the last page (zero-based): | ||
| 1428 | sub _last_page { | ||
| 1429 | my $self = shift; | ||
| 1430 | my $i = $#{ $self->{_pages} }; | ||
| 1431 | return $i; | ||
| 1432 | } | ||
| 1433 | |||
| 1434 | # Returns true if the current page is the last page: | ||
| 1435 | sub _on_last_page { | ||
| 1436 | my $self = shift; | ||
| 1437 | DEBUG "_on_last_page(), pagePtr is $self->{_current_page_idx}"; | ||
| 1438 | return ( $self->_last_page == $self->{_current_page_idx} ); | ||
| 1439 | } | ||
| 1440 | |||
| 1441 | # Returns true if the current page is the first page: | ||
| 1442 | sub _on_first_page { | ||
| 1443 | my $self = shift; | ||
| 1444 | return ( 0 == $self->{_current_page_idx} ); | ||
| 1445 | } | ||
| 1446 | |||
| 1447 | # Method: _NextButtonEventCycle | ||
| 1448 | # Description: Runs the complete view of the action handler cycle for the "Next>" button on the | ||
| 1449 | # wizard button bar. This includes dispatching the preNextButtonAction and | ||
| 1450 | # postNextButtonAction handler at the appropriate times. | ||
| 1451 | # | ||
| 1452 | # Dictat: Never ever use goto unless you have a very good reason, and please explain that reason | ||
| 1453 | # | ||
| 1454 | sub _NextButtonEventCycle { | ||
| 1455 | my $self = shift; | ||
| 1456 | TRACE "Enter _NextButtonEventCycle"; | ||
| 1457 | $self->{_inside_nextButtonEventCycle_}++ unless shift; | ||
| 1458 | |||
| 1459 | DEBUG "NBEC counter == $self->{_inside_nextButtonEventCycle_}"; | ||
| 1460 | |||
| 1461 | # If there is more than one pending invocation, we will re-invoke | ||
| 1462 | # ourself when we're done: | ||
| 1463 | if ( $self->{_inside_nextButtonEventCycle_} > 1) { | ||
| 1464 | DEBUG "Called recursively, bail out"; | ||
| 1465 | return; | ||
| 1466 | } | ||
| 1467 | |||
| 1468 | # XXX DEBUG "Page $self->{_current_page_idx} -preNextButtonAction"; | ||
| 1469 | if ( _dispatch( $self->cget( -preNextButtonAction ) ) ) { | ||
| 1470 | INFO "preNextButtonAction says we should not go ahead"; | ||
| 1471 | $self->{_inside_nextButtonEventCycle_}--; | ||
| 1472 | return; | ||
| 1473 | } | ||
| 1474 | |||
| 1475 | if ( $self->_on_last_page ) { | ||
| 1476 | DEBUG "On the last page"; | ||
| 1477 | if ( _dispatch( $self->cget( -preFinishButtonAction ) ) ) { | ||
| 1478 | DEBUG "preFinishButtonAction says we should not go ahead"; | ||
| 1479 | $self->{_inside_nextButtonEventCycle_}--; | ||
| 1480 | return; | ||
| 1481 | } | ||
| 1482 | elsif ( _dispatch( $self->cget( -finishButtonAction ) ) ) { | ||
| 1483 | DEBUG "finishButtonAction says we should not go ahead"; | ||
| 1484 | $self->{_inside_nextButtonEventCycle_}--; | ||
| 1485 | return; | ||
| 1486 | } | ||
| 1487 | else { | ||
| 1488 | $self->{really_quit}++; | ||
| 1489 | $self->_CloseWindowEventCycle(); | ||
| 1490 | } | ||
| 1491 | } | ||
| 1492 | |||
| 1493 | # Advance the wizard page pointer and then adjust the navigation buttons. | ||
| 1494 | # Redraw the frame when finished to get changes to take effect. | ||
| 1495 | else { | ||
| 1496 | TRACE "OK - advance to next page"; | ||
| 1497 | $self->_page_forward; | ||
| 1498 | $self->_render_current_page; | ||
| 1499 | } | ||
| 1500 | |||
| 1501 | DEBUG "Before _dispatch postNextButtonAction"; | ||
| 1502 | if ( _dispatch( $self->cget( -postNextButtonAction ) ) ) { | ||
| 1503 | INFO "postNextButtonAction says we should not go ahead"; | ||
| 1504 | $self->{_inside_nextButtonEventCycle_}--; | ||
| 1505 | return; | ||
| 1506 | } | ||
| 1507 | |||
| 1508 | DEBUG "Done, NBEC counter is now $self->{_inside_nextButtonEventCycle_}"; | ||
| 1509 | |||
| 1510 | $self->{_inside_nextButtonEventCycle_}--; | ||
| 1511 | |||
| 1512 | $self->_NextButtonEventCycle('no increment') if $self->{_inside_nextButtonEventCycle_}; | ||
| 1513 | } | ||
| 1514 | |||
| 1515 | |||
| 1516 | # Move the wizard pointer back one position and then adjust the | ||
| 1517 | # navigation buttons to reflect any state changes. Don't fall off | ||
| 1518 | # end of page pointer | ||
| 1519 | sub _BackButtonEventCycle { | ||
| 1520 | my $self = shift; | ||
| 1521 | return if _dispatch( | ||
| 1522 | $self->cget( -preBackButtonAction ) | ||
| 1523 | ); | ||
| 1524 | $self->_page_backward; | ||
| 1525 | $self->_render_current_page; | ||
| 1526 | return if _dispatch( | ||
| 1527 | $self->cget( -postBackButtonAction ) | ||
| 1528 | ); | ||
| 1529 | return; | ||
| 1530 | } | ||
| 1531 | |||
| 1532 | sub _HelpButtonEventCycle { | ||
| 1533 | my $self = shift; | ||
| 1534 | return if _dispatch( $self->cget(-preHelpButtonAction)); | ||
| 1535 | return if _dispatch( $self->cget( -helpButtonAction)); | ||
| 1536 | return if _dispatch( $self->cget( -postHelpButtonAction)); | ||
| 1537 | } | ||
| 1538 | |||
| 1539 | sub _CancelButtonEventCycle { | ||
| 1540 | my $self = shift; | ||
| 1541 | return if $self->Callback( -preCancelButtonAction => $self->{-preCancelButtonAction} ); | ||
| 1542 | $self->_CloseWindowEventCycle($_); | ||
| 1543 | } | ||
| 1544 | |||
| 1545 | sub _CloseWindowEventCycle { | ||
| 1546 | my $self = shift; | ||
| 1547 | my $gui = shift; | ||
| 1548 | TRACE "Enter _CloseWindowEventCycle... really_quit=[", ($self->{really_quit} || 'undef'), "]"; | ||
| 1549 | |||
| 1550 | if ( not $self->{really_quit} ) { | ||
| 1551 | DEBUG "Really?"; | ||
| 1552 | if ( $self->Callback( -preCloseWindowAction => $self->{-preCloseWindowAction} ) ) { | ||
| 1553 | DEBUG "preCloseWindowAction says we should not go ahead"; | ||
| 1554 | return; | ||
| 1555 | } | ||
| 1556 | } | ||
| 1557 | if ( Tk::Exists($gui) ) { | ||
| 1558 | DEBUG "gui=$gui= withdraw"; | ||
| 1559 | $gui->withdraw; | ||
| 1560 | } | ||
| 1561 | |||
| 1562 | if ( $self->{Configure}{-kill_parent_on_destroy} and Tk::Exists( $self->parent ) ) { | ||
| 1563 | DEBUG "Kill parent " . $self->parent . " " . $self->{Configure}{ -parent }; | ||
| 1564 | # This should kill us, too: | ||
| 1565 | $self->parent->destroy; | ||
| 1566 | return; | ||
| 1567 | } | ||
| 1568 | |||
| 1569 | DEBUG "Legacy withdraw"; | ||
| 1570 | $self->{_showing} = 0; | ||
| 1571 | if ( $self->{Configure}{-kill_self_after_finish} ) { | ||
| 1572 | $self->destroy; | ||
| 1573 | } | ||
| 1574 | else { | ||
| 1575 | $self->withdraw; # Legacy | ||
| 1576 | } | ||
| 1577 | |||
| 1578 | return undef; | ||
| 1579 | } | ||
| 1580 | |||
| 1581 | |||
| 1582 | =head2 Show | ||
| 1583 | |||
| 1584 | $wizard->Show(); | ||
| 1585 | |||
| 1586 | Draw and display the Wizard on the screen. | ||
| 1587 | |||
| 1588 | Usually C<MainLoop> is called immediately after this. | ||
| 1589 | |||
| 1590 | =cut | ||
| 1591 | |||
| 1592 | sub Show { | ||
| 1593 | TRACE "Enter Show"; | ||
| 1594 | my $self = shift; | ||
| 1595 | return if $self->{_showing}; | ||
| 1596 | |||
| 1597 | if ( $self->_last_page < 2 ) { | ||
| 1598 | my $lp = $self->_last_page + 1; | ||
| 1599 | warnings::warnif( | ||
| 1600 | ref($self), "Showing a Wizard with " | ||
| 1601 | . $lp . ' page' . ($lp==1? '' : 's').'!' | ||
| 1602 | ) | ||
| 1603 | } | ||
| 1604 | |||
| 1605 | $self->{_current_page_idx} = 0; | ||
| 1606 | $self->_initial_layout; | ||
| 1607 | |||
| 1608 | $self->resizable( 0, 0 ) | ||
| 1609 | unless $self->{Configure}{-resizable} | ||
| 1610 | and $self->{Configure}{-resizable} =~ /^(1|yes|true)$/i; | ||
| 1611 | |||
| 1612 | $self->parent->withdraw; | ||
| 1613 | $self->Popup; | ||
| 1614 | $self->transient; # forbid minimize | ||
| 1615 | $self->protocol( WM_DELETE_WINDOW => [ \&_CloseWindowEventCycle, $self, $self ] ); | ||
| 1616 | |||
| 1617 | $self->configure( -background => $self->cget("-background") ); | ||
| 1618 | $self->_render_current_page; | ||
| 1619 | $self->{_showing} = 1; | ||
| 1620 | |||
| 1621 | TRACE "Leave Show"; | ||
| 1622 | return 1; | ||
| 1623 | } | ||
| 1624 | |||
| 1625 | =head2 forward | ||
| 1626 | |||
| 1627 | Convenience method to move the Wizard on a page by invoking the | ||
| 1628 | callback for the C<nextButton>. | ||
| 1629 | |||
| 1630 | You can automatically move forward after C<$x> tenths of a second | ||
| 1631 | by doing something like this: | ||
| 1632 | |||
| 1633 | $frame->after($x,sub{$wizard->forward}); | ||
| 1634 | |||
| 1635 | =cut | ||
| 1636 | |||
| 1637 | sub forward { | ||
| 1638 | my $self = shift; | ||
| 1639 | return $self->_NextButtonEventCycle; | ||
| 1640 | } | ||
| 1641 | |||
| 1642 | =head2 backward | ||
| 1643 | |||
| 1644 | Convenience method to move the Wizard back a page by invoking the | ||
| 1645 | callback for the C<backButton>. | ||
| 1646 | |||
| 1647 | =cut | ||
| 1648 | |||
| 1649 | sub backward { | ||
| 1650 | my $self = shift; | ||
| 1651 | return $self->{backButton}->invoke; | ||
| 1652 | } | ||
| 1653 | |||
| 1654 | sub _showing_side_banner { | ||
| 1655 | my $self = shift; | ||
| 1656 | return 1 if $self->cget( -style ) eq '95'; | ||
| 1657 | return 1 if $self->_on_first_page; | ||
| 1658 | return 1 if $self->_on_last_page; | ||
| 1659 | return 0; | ||
| 1660 | } | ||
| 1661 | |||
| 1662 | =head2 currentPage | ||
| 1663 | |||
| 1664 | my $current_page = $wizard->currentPage() | ||
| 1665 | |||
| 1666 | This returns the index of the page currently being shown to the user. | ||
| 1667 | Page are indexes start at 1, with the first page that is associated with | ||
| 1668 | the wizard through the C<addPage> method. | ||
| 1669 | See also the L</addPage> entry. | ||
| 1670 | |||
| 1671 | =cut | ||
| 1672 | |||
| 1673 | sub currentPage { | ||
| 1674 | my $self = shift; | ||
| 1675 | # Internally, the internal _current_page_idx is zero-based. | ||
| 1676 | # But we "publish" it as one-based: | ||
| 1677 | return $self->{_current_page_idx} + 1; | ||
| 1678 | } | ||
| 1679 | |||
| 1680 | =head2 setPageSkip | ||
| 1681 | |||
| 1682 | Mark one or more pages to be skipped at runtime. | ||
| 1683 | All integer arguments are taken to be page numbers | ||
| 1684 | (ie the number returned by any of the C<add*Page> methods) | ||
| 1685 | |||
| 1686 | You should never set the first page to be skipped, and | ||
| 1687 | you can not set the last page to be skipped, though these | ||
| 1688 | rules are not (yet) enforced. | ||
| 1689 | |||
| 1690 | =cut | ||
| 1691 | |||
| 1692 | sub setPageSkip { | ||
| 1693 | my $self = shift; | ||
| 1694 | # The user's argument is 1-based, but our internal data structures | ||
| 1695 | # are zero-based, thus subtract 1: | ||
| 1696 | foreach my $i (@_) { | ||
| 1697 | $self->{page_skip}{ $i - 1 } = 1; | ||
| 1698 | } | ||
| 1699 | } | ||
| 1700 | |||
| 1701 | =head2 setPageUnskip | ||
| 1702 | |||
| 1703 | Mark one or more pages as not to be skipped at runtime | ||
| 1704 | (that is, reverse the effects of C<setPageSkip>). | ||
| 1705 | |||
| 1706 | All integer arguments are taken to be page numbers | ||
| 1707 | (that is, the number returned by any of the C<addPage> methods) | ||
| 1708 | |||
| 1709 | =cut | ||
| 1710 | |||
| 1711 | sub setPageUnskip { | ||
| 1712 | my $self = shift; | ||
| 1713 | # The user's argument is 1-based, but our internal data structures | ||
| 1714 | # are zero-based, thus subtract 1: | ||
| 1715 | foreach my $i (@_) { | ||
| 1716 | $self->{page_skip}{ $i - 1 } = 0; | ||
| 1717 | } | ||
| 1718 | } | ||
| 1719 | |||
| 1720 | =head2 next_page_number | ||
| 1721 | |||
| 1722 | Returns the number of the page the Wizard will land on if the Next button is clicked | ||
| 1723 | (ie the integer returned by C<add*Page>). | ||
| 1724 | |||
| 1725 | =cut | ||
| 1726 | |||
| 1727 | sub next_page_number { | ||
| 1728 | my $self = shift; | ||
| 1729 | return $self->_next_page_number + 1; | ||
| 1730 | } | ||
| 1731 | |||
| 1732 | |||
| 1733 | # _next_page_number | ||
| 1734 | # As public, but value is minus one | ||
| 1735 | # | ||
| 1736 | sub _next_page_number { | ||
| 1737 | my $self = shift; | ||
| 1738 | my $i = $self->{_current_page_idx}; | ||
| 1739 | DEBUG "_page_forward($i -->"; | ||
| 1740 | |||
| 1741 | do { | ||
| 1742 | $i++; | ||
| 1743 | } until ( | ||
| 1744 | not $self->{page_skip}->{$i} or $self->_last_page <= $i | ||
| 1745 | ); | ||
| 1746 | $i = $self->_last_page if ( $self->_last_page < $i ); | ||
| 1747 | |||
| 1748 | DEBUG " $i)\n"; | ||
| 1749 | return $i; | ||
| 1750 | } | ||
| 1751 | |||
| 1752 | # Increments the page pointer forward to the next logical page, | ||
| 1753 | # honouring the Skip flags: | ||
| 1754 | sub _page_forward { | ||
| 1755 | my $self = shift; | ||
| 1756 | $self->{_current_page_idx} = $self->_next_page_number; | ||
| 1757 | } | ||
| 1758 | |||
| 1759 | |||
| 1760 | =head2 back_page_number | ||
| 1761 | |||
| 1762 | Returns the number (ie the integer returned by add*Page) of the page | ||
| 1763 | the Wizard will land on if the Back button is clicked. | ||
| 1764 | |||
| 1765 | =cut | ||
| 1766 | |||
| 1767 | # sub back_page_number { | ||
| 1768 | # my $self = shift; | ||
| 1769 | # my $iPage = $self->{_current_page_idx}; | ||
| 1770 | # do { | ||
| 1771 | # $iPage--; | ||
| 1772 | # } until ( !$self->{page_skip}{$iPage} || ( $iPage <= 0 ) ); | ||
| 1773 | # $iPage = 0 if ( $iPage < 0 ); | ||
| 1774 | # return $iPage; | ||
| 1775 | # } | ||
| 1776 | |||
| 1777 | sub back_page_number { | ||
| 1778 | my $self = shift; | ||
| 1779 | return $self->_back_page_number + 1; | ||
| 1780 | } | ||
| 1781 | |||
| 1782 | sub _back_page_number { | ||
| 1783 | my $self = shift; | ||
| 1784 | my $iPage = $self->{_current_page_idx}; | ||
| 1785 | do { | ||
| 1786 | $iPage--; | ||
| 1787 | } until ( !$self->{page_skip}{$iPage} || ( $iPage <= 0 ) ); | ||
| 1788 | $iPage = 0 if ( $iPage < 0 ); | ||
| 1789 | return $iPage; | ||
| 1790 | } | ||
| 1791 | |||
| 1792 | |||
| 1793 | # Decrements the page pointer backward to the previous logical page, | ||
| 1794 | # honouring the Skip flags: | ||
| 1795 | sub _page_backward { | ||
| 1796 | my $self = shift; | ||
| 1797 | $self->{_current_page_idx} = $self->_back_page_number; | ||
| 1798 | } | ||
| 1799 | |||
| 1800 | =head2 prompt | ||
| 1801 | |||
| 1802 | Equivalent to the JavaScript method of the same name: pops up | ||
| 1803 | a dialogue box to get a text string, and returns it. Arguments | ||
| 1804 | are: | ||
| 1805 | |||
| 1806 | =over 4 | ||
| 1807 | |||
| 1808 | =item -title => | ||
| 1809 | |||
| 1810 | The title of the dialogue box. | ||
| 1811 | |||
| 1812 | =item -text => | ||
| 1813 | |||
| 1814 | The text to display above the C<Entry> widget. | ||
| 1815 | |||
| 1816 | =item -value => | ||
| 1817 | |||
| 1818 | The initial value of the C<Entry> box. | ||
| 1819 | |||
| 1820 | =item -wraplength => | ||
| 1821 | |||
| 1822 | Text C<Label>'s wraplength: defaults to 275. | ||
| 1823 | |||
| 1824 | =item -width => | ||
| 1825 | |||
| 1826 | The C<Entry> widget's width: defaults to 40. | ||
| 1827 | |||
| 1828 | =back | ||
| 1829 | |||
| 1830 | =cut | ||
| 1831 | |||
| 1832 | sub prompt { | ||
| 1833 | my $self = shift; | ||
| 1834 | my $args = {@_}; | ||
| 1835 | my ( $d, $w ); | ||
| 1836 | my $input = $self->cget( -value ); | ||
| 1837 | $d = $self->DialogBox( | ||
| 1838 | -title => $args->{-title} || "Prompt", | ||
| 1839 | -buttons => [ $LABELS{CANCEL}, $LABELS{OK} ], | ||
| 1840 | -default_button => $LABELS{OK}, | ||
| 1841 | ); | ||
| 1842 | |||
| 1843 | if ( $args->{-text} ) { | ||
| 1844 | $w = $d->add( | ||
| 1845 | "Label", | ||
| 1846 | -font => $self->{defaultFont}, | ||
| 1847 | -text => $args->{-text}, | ||
| 1848 | -width => 40, | ||
| 1849 | -wraplength => $args->{-wraplength} || 275, | ||
| 1850 | -justify => 'left', | ||
| 1851 | -anchor => 'w', | ||
| 1852 | )->pack(); | ||
| 1853 | } | ||
| 1854 | |||
| 1855 | $w = $d->add( | ||
| 1856 | "Entry", | ||
| 1857 | -font => $self->{defaultFont}, | ||
| 1858 | -relief => "sunken", | ||
| 1859 | -width => $args->{-width} || 40, | ||
| 1860 | -background => "white", | ||
| 1861 | -justify => 'left', | ||
| 1862 | -textvariable => \$input, | ||
| 1863 | )->pack(qw( -padx 2 -pady 2 -expand 1 )); | ||
| 1864 | |||
| 1865 | $d->Show; | ||
| 1866 | return $input ? $input : undef; | ||
| 1867 | } | ||
| 1868 | |||
| 1869 | # | ||
| 1870 | # Using a -wait value for After of less than this seems to cause a weird Tk dump | ||
| 1871 | # so call this whenever using a -wait | ||
| 1872 | # | ||
| 1873 | sub _fix_wait { | ||
| 1874 | my $wait_ref = shift; | ||
| 1875 | $$wait_ref += 200 if $$wait_ref < 250; | ||
| 1876 | } | ||
| 1877 | |||
| 1878 | =head1 CALLBACKS | ||
| 1879 | |||
| 1880 | =head2 DIALOGUE_really_quit | ||
| 1881 | |||
| 1882 | This is the default callback for -preCloseWindowAction. | ||
| 1883 | It gives the user a Yes/No dialog box; if the user clicks "Yes", | ||
| 1884 | this function returns a false value, otherwise a true value. | ||
| 1885 | |||
| 1886 | =cut | ||
| 1887 | |||
| 1888 | sub DIALOGUE_really_quit { | ||
| 1889 | my $self = shift; | ||
| 1890 | TRACE "Enter DIALOGUE_really_quit"; | ||
| 1891 | return 0 if $self->{nextButton}->cget( -text ) eq $LABELS{FINISH}; | ||
| 1892 | |||
| 1893 | unless ( $self->{really_quit} ) { | ||
| 1894 | DEBUG "# Get really quit info"; | ||
| 1895 | my $button = $self->messageBox( | ||
| 1896 | '-icon' => 'question', | ||
| 1897 | -type => 'yesno', | ||
| 1898 | -default => 'no', | ||
| 1899 | -title => 'Quit Wizard?', | ||
| 1900 | -message => "The Wizard has not finished running.\n\n" | ||
| 1901 | . "If you quit now, the job will not be complete.\n\nDo you really wish to quit?" | ||
| 1902 | ); | ||
| 1903 | $self->{really_quit} = lc $button eq 'yes' ? 1 : 0; | ||
| 1904 | DEBUG "# ... really=[$self->{really_quit}]"; | ||
| 1905 | } | ||
| 1906 | return !$self->{really_quit}; | ||
| 1907 | } | ||
| 1908 | |||
| 1909 | |||
| 1910 | |||
| 1911 | |||
| 1912 | =head1 ACTION EVENT HANDLERS | ||
| 1913 | |||
| 1914 | A Wizard is a series of pages that gather information and perform | ||
| 1915 | tasks based upon that information. Navigated through the pages is via | ||
| 1916 | I<Back> and I<Next> buttons, as well as I<Help>, I<Cancel> and | ||
| 1917 | I<Finish> buttons. | ||
| 1918 | |||
| 1919 | In the C<Tk::Wizard> implementation, each button has associated with | ||
| 1920 | it one or more action event handlers, supplied as code-references | ||
| 1921 | executed before, during and/or after the button press. | ||
| 1922 | |||
| 1923 | The handler code should return a Boolean value, signifying whether the | ||
| 1924 | remainder of the action should continue. If a false value is | ||
| 1925 | returned, execution of the event handler halts. | ||
| 1926 | |||
| 1927 | =over 4 | ||
| 1928 | |||
| 1929 | =item -preNextButtonAction => | ||
| 1930 | |||
| 1931 | This is a reference to a function that will be dispatched before the Next | ||
| 1932 | button is processed. | ||
| 1933 | |||
| 1934 | =item -postNextButtonAction => | ||
| 1935 | |||
| 1936 | This is a reference to a function that will be dispatched after the Next | ||
| 1937 | button is processed. The function is called after the application has logically | ||
| 1938 | advanced to the next page, but before the next page is drawn on screen. | ||
| 1939 | |||
| 1940 | |||
| 1941 | =item -preBackButtonAction => | ||
| 1942 | |||
| 1943 | This is a reference to a function that will be dispatched before the Previous | ||
| 1944 | button is processed. | ||
| 1945 | |||
| 1946 | =item -postBackButtonAction => | ||
| 1947 | |||
| 1948 | This is a reference to a function that will be dispatched after the Previous | ||
| 1949 | button is processed. | ||
| 1950 | |||
| 1951 | =item -preHelpButtonAction => | ||
| 1952 | |||
| 1953 | This is a reference to a function that will be dispatched before the Help | ||
| 1954 | button is processed. | ||
| 1955 | |||
| 1956 | =item -helpButtonAction => | ||
| 1957 | |||
| 1958 | This is a reference to a function that will be dispatched to handle the Help | ||
| 1959 | button action. | ||
| 1960 | By default there is no Help action; therefore unless you are providing this | ||
| 1961 | function, you should initialize your Wizard with -nohelpbutton => 1. | ||
| 1962 | |||
| 1963 | =item -postHelpButtonAction => | ||
| 1964 | |||
| 1965 | This is a reference to a function that will be dispatched after the Help | ||
| 1966 | button is processed. | ||
| 1967 | |||
| 1968 | =item -preFinishButtonAction => | ||
| 1969 | |||
| 1970 | This is a reference to a function that will be dispatched just before the Finish | ||
| 1971 | button action. | ||
| 1972 | |||
| 1973 | =item -finishButtonAction => | ||
| 1974 | |||
| 1975 | This is a reference to a function that will be dispatched to handle the Finish | ||
| 1976 | button action. | ||
| 1977 | |||
| 1978 | =item -preCancelButtonAction => | ||
| 1979 | |||
| 1980 | This is a reference to a function that will be dispatched before the Cancel | ||
| 1981 | button is processed. Default is to exit on user confirmation - see | ||
| 1982 | L</DIALOGUE_really_quit>. | ||
| 1983 | |||
| 1984 | =item -preCloseWindowAction => | ||
| 1985 | |||
| 1986 | This is a reference to a function that will be dispatched before the window | ||
| 1987 | is issued a close command. | ||
| 1988 | If this function returns a true value, the Wizard will close. | ||
| 1989 | If this function returns a false value, the Wizard will stay on the current page. | ||
| 1990 | Default is to exit on user confirmation - see L</DIALOGUE_really_quit>. | ||
| 1991 | |||
| 1992 | =back | ||
| 1993 | |||
| 1994 | All active event handlers can be set at construction or using configure -- | ||
| 1995 | see L</WIDGET-SPECIFIC OPTIONS> and L<Tk::options>. | ||
| 1996 | |||
| 1997 | =head1 BUTTONS | ||
| 1998 | |||
| 1999 | backButton nextButton helpButton cancelButton | ||
| 2000 | |||
| 2001 | If you must, you can access the Wizard's button through the object | ||
| 2002 | fields listed above, each of which represents a | ||
| 2003 | L<Tk::Button|Tk::Button> object. This may not be a good way to do it: | ||
| 2004 | patches always welcome ;) | ||
| 2005 | |||
| 2006 | This is not advised for anything other than disabling or re-enabling the display | ||
| 2007 | status of the buttons, as the C<-command> switch is used by the Wizard: | ||
| 2008 | |||
| 2009 | $wizard->{backButton}->configure( -state => "disabled" ) | ||
| 2010 | |||
| 2011 | Note: the I<Finish> button is simply the C<nextButton> with the label C<$LABEL{FINISH}>. | ||
| 2012 | |||
| 2013 | See also L<INTERNATIONALISATION>. | ||
| 2014 | |||
| 2015 | =head1 INTERNATIONALISATION | ||
| 2016 | |||
| 2017 | The labels of the buttons can be changed (perhaps into a language other an English) | ||
| 2018 | by changing the values of the package-global C<%LABELS> hash, where keys are | ||
| 2019 | C<BACK>, C<NEXT>, C<CANCEL>, C<HELP>, and C<FINISH>. | ||
| 2020 | |||
| 2021 | The text of the callbacks can also be changed via the | ||
| 2022 | C<%LABELS> hash: see the top of the source code for details. | ||
| 2023 | |||
| 2024 | =head1 IMPLEMENTATION NOTES | ||
| 2025 | |||
| 2026 | This widget is implemented using the Tk 'standard' API as far as possible, | ||
| 2027 | given that when I first needed a wizard in Perl/Tk, I had almost three weeks | ||
| 2028 | of exposure to the technology. Please, if you have a suggestion, | ||
| 2029 | or patch, send it to me directly via C<LGoddard@CPAN.org>, or via CPAN's RT. | ||
| 2030 | |||
| 2031 | The widget supports both C<MainWindow> and not C<TopLevel> window. | ||
| 2032 | Originally, only the former was supported - the reasoning was that | ||
| 2033 | Wizards are applications in their own right, and not usually parts of other | ||
| 2034 | applications. However, conventions are not always bad things, hence the update. | ||
| 2035 | |||
| 2036 | =head1 THE C<Tk::Wizard> NAMESPACE | ||
| 2037 | |||
| 2038 | In discussion on comp.lang.perl.tk, it was suggested by Dominique Dumont | ||
| 2039 | that the following guidelines for the use of the C<Tk::Wizard> namespace be followed: | ||
| 2040 | |||
| 2041 | =over 4 | ||
| 2042 | |||
| 2043 | =item 1 | ||
| 2044 | |||
| 2045 | That the module C<Tk::Wizard> act as a base module, providing all the | ||
| 2046 | basic services and components a Wizard might require. | ||
| 2047 | |||
| 2048 | =item 2 | ||
| 2049 | |||
| 2050 | That modules beneath the base in the hierarchy provide implementations | ||
| 2051 | based on aesthetics and/or architecture. | ||
| 2052 | |||
| 2053 | =back | ||
| 2054 | |||
| 2055 | =head1 NOTES ON SUB-CLASSING Tk::Wizard | ||
| 2056 | |||
| 2057 | If you are planning to sub-class C<Tk::Wizard> to create a different display style, | ||
| 2058 | there are three routines you will need to over-ride: | ||
| 2059 | |||
| 2060 | =over 4 | ||
| 2061 | |||
| 2062 | =item _initial_layout | ||
| 2063 | |||
| 2064 | =item _render_current_page | ||
| 2065 | |||
| 2066 | =item blank_frame | ||
| 2067 | |||
| 2068 | =back | ||
| 2069 | |||
| 2070 | This may change, please bear with me. | ||
| 2071 | |||
| 2072 | =head1 CAVEATS | ||
| 2073 | |||
| 2074 | =over 4 | ||
| 2075 | |||
| 2076 | =item * | ||
| 2077 | |||
| 2078 | Bit messy when composing frames. | ||
| 2079 | |||
| 2080 | =item * | ||
| 2081 | |||
| 2082 | Task Frame LabFrame background colour doesn't set properly under 5.6.1. | ||
| 2083 | |||
| 2084 | =item * | ||
| 2085 | |||
| 2086 | 20 January 2003: the directory tree part does not create directories | ||
| 2087 | unless the eponymous button is clicked. Is this still an issue? | ||
| 2088 | |||
| 2089 | =item * | ||
| 2090 | |||
| 2091 | In Windows, with the system font set to > 96 DPI (via Display Properties / Settings | ||
| 2092 | / Advanced / General / Display / Font Size), the Wizard will not display pro pertly. | ||
| 2093 | This seems to be a Tk feature. | ||
| 2094 | |||
| 2095 | =item * | ||
| 2096 | |||
| 2097 | Nothing is currently done to ensure text fits into the window - it is currently up to | ||
| 2098 | the client to make frames C<Scrolled>) as required. | ||
| 2099 | |||
| 2100 | =back | ||
| 2101 | |||
| 2102 | =head1 BUGS | ||
| 2103 | |||
| 2104 | Please use RT (https://rt.cpan.org/Ticket/Create.html?Queue=Tk-Wizard) | ||
| 2105 | to submit a bug report. | ||
| 2106 | |||
| 2107 | =head1 AUTHOR | ||
| 2108 | |||
| 2109 | Lee Goddard (lgoddard@cpan.org) based on work by Daniel T Hable. | ||
| 2110 | |||
| 2111 | Please see the F<README.md> file for a list of contributors and helpers - thanks to all. | ||
| 2112 | |||
| 2113 | =head1 KEYWORDS | ||
| 2114 | |||
| 2115 | Wizard; set-up; setup; installer; uninstaller; install; uninstall; Tk; GUI. | ||
| 2116 | |||
| 2117 | =head1 COPYRIGHT | ||
| 2118 | |||
| 2119 | Copyright (C) Lee Goddard, 11/2002 - 02/2010, 06/2015 ff. | ||
| 2120 | |||
| 2121 | This software is made available under the same terms as Perl itself. | ||
| 2122 | |||
| 2123 | This software is not endorsed by, or in any way associated with, the Microsoft Corp | ||
| 2124 | |||
| 2125 | Microsoft is, obviously, a registered trademark of Microsoft Corp. | ||
| 2126 | |||
| 2127 | =cut | ||
| 2128 | |||
| 2129 | REDEFINES: | ||
| 2130 | { | ||
| 2131 | no warnings 'redefine'; | ||
| 2132 | sub Tk::ErrorOFF { | ||
| 2133 | DEBUG "This is Martin's Tk::Error\n"; | ||
| 2134 | my ( $oWidget, $sError, @asLocations ) = @_; | ||
| 2135 | local $, = "\n"; | ||
| 2136 | print STDERR @asLocations; | ||
| 2137 | } | ||
| 2138 | } | ||
| 2139 | |||
| 2140 | 1; | ||
| 2141 | |||
| 2142 | __END__ | ||