Update of /cvsroot/perl-win32-gui/Win32-GUI/docs/GUI/Tutorial
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30555/docs/GUI/Tutorial

Modified Files:
        Part1.pod Part3.pod Part4.pod Part5.pod Part9.pod 
Log Message:
Bug fixes, update tutorial, add tutorial samples

Index: Part9.pod
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/docs/GUI/Tutorial/Part9.pod,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Part9.pod   26 Jun 2005 16:41:01 -0000      1.1
--- Part9.pod   5 Oct 2005 22:20:49 -0000       1.2
***************
*** 17,29 ****
  =item *
  
! Enter the command "perl MyApp.plx" from a Windows console window.
  
  =item *
  
! Enter the command "perl MyApp.plx" in the Windows "Run" box.
  
  =item *
  
! Double click on the file "MyApp.plx" (assuming you have .plx files associated
  with the perl.exe application).
  
--- 17,29 ----
  =item *
  
! Enter the command "perl MyApp.pl" from a Windows console window.
  
  =item *
  
! Enter the command "perl MyApp.pl" in the Windows "Run" box.
  
  =item *
  
! Double click on the file "MyApp.pl" (assuming you have .pl files associated
  with the perl.exe application).
  
***************
*** 46,51 ****
      editbin /subsystem:windows perlw.exe
  
! There is also an all-perl way to achieve the same result on Jenda's site:
! L<http://jenda.krynicky.cz/perl/GUIscripts.html>
  
  If you can't (or don't want to) create a perlw.exe, then a compromise is to 
hide 
--- 46,52 ----
      editbin /subsystem:windows perlw.exe
  
! ActiveState Perl comes with an executable called wperl.exe (you'll find it
! n the same place as your perl.exe).  This is an executable with exactly
! this change already made to it.
  
  If you can't (or don't want to) create a perlw.exe, then a compromise is to 
hide 
***************
*** 59,62 ****
--- 60,67 ----
      Win32::GUI::Hide($DOS);
  
+ Note that C<GetPerlWindow()> returns a windows handle, not a 
C<Win32::GUI::Window>
+ object, so we have to use the static call to C<Win32::GUI::Hide()> as 
discussed
+ in part 1 of the tutorial.
+ 
  Do this as early as possible. Obviously, if we hide the console, we must show
  it when we finish (otherwise, someone who runs your program from a command

Index: Part4.pod
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/docs/GUI/Tutorial/Part4.pod,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Part4.pod   26 Jun 2005 16:41:01 -0000      1.1
--- Part4.pod   5 Oct 2005 22:20:49 -0000       1.2
***************
*** 151,165 ****
  =item *
  
! There is a small bug in this program. The tray icon does not disappear
! immediately when the program terminates. Instead, it remains in the system
! tray until you point the mouse cursor at it, when it disappears. This is a bug
! in Win32::GUI - when you close your program, you should explicitly remove any
! system tray icons you still have displayed. Referring to the example above,
! you should place this line after the Win32::GUI::Dialog() call:
  
        $main->NI->Delete(-id => 1);
  
- Hopefully, this will be fixed in a later version.
- 
  =back
  
--- 151,159 ----
  =item *
  
! If you want to remove the tray icon before the end of your program
! you can use this line:
  
        $main->NI->Delete(-id => 1);
  
  =back
  

Index: Part3.pod
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/docs/GUI/Tutorial/Part3.pod,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Part3.pod   26 Jun 2005 16:41:01 -0000      1.1
--- Part3.pod   5 Oct 2005 22:20:49 -0000       1.2
***************
*** 59,70 ****
  
  To make the return key work as expected, you need to give one of your dialog's
! buttons the C<< -default => 1 >> option. When the return key is pressed, it is
  translated into a click event on the default button. The default button is
! also highlighted differently from the other buttons (it has a dark border).
! B<Note:> There is a related option, C<< -ok => 1 >>, which has a similar
! effect as C<-default>. However, the two seem to conflict in their effects. I
! would recommend that if your default button has the caption C<"OK">, you
! should set both the C<-ok> and C<-default> options. Otherwise, stick with just
! C<-default>.
  
  =back
--- 59,69 ----
  
  To make the return key work as expected, you need to give one of your dialog's
! buttons the C<< -ok => 1 >> option. When the return key is pressed, it is
  translated into a click event on the default button. The default button is
! also usually highlighted differently from the other buttons
! (it has a dark border), this is achieved by the C<< -default => 1 >> option,
! It is normal to give this button a caption C<"OK"> and make its click
! handler close the window, setting any changes made, but again, this is up to
! you.
  
  =back
***************
*** 96,99 ****
--- 95,103 ----
  the name of the constructor you use to create your application's main window.
  
+ Recent versions of Win32::GUI have a C<-dialogui> option that controls the
+ special keyboard handling. Setting this option to C<1> on a basic Window add 
the
+ special key handling to the window; setting it to C<0> on a DialogBox removes
+ the special key handling.
+ 
  In the L<next part|Win32::GUI::Tutorial::Part4>, we will cover some further 
ways in which you can increase
  your application's functionality.

Index: Part1.pod
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/docs/GUI/Tutorial/Part1.pod,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Part1.pod   26 Jun 2005 16:41:00 -0000      1.1
--- Part1.pod   5 Oct 2005 22:20:49 -0000       1.2
***************
*** 115,119 ****
      }
  
! Put that in a file (say, hello.plx) and run it using C<perl hello.plx>. 
  
  =for html <br /><center><img src="part1-1.gif" /></center>
--- 115,119 ----
      }
  
! Put that in a file (say, hello.pl) and run it using C<perl hello.pl>. 
  
  =for html <br /><center><img src="part1-1.gif" /></center>
***************
*** 302,327 ****
  
      sub Main_Resize {
!         my $w = $main->Width();
!         my $h = $main->Height();
          my $lw = $label->Width();
          my $lh = $label->Height();
!         if ($lw > $w) {
!             $main->Width($lw) + $ncw; # Remember the non-client width!
          }
          else {
!             $label->Left(($w - $lw) / 2);
          }
!         if ($lh > $h) {
!             $main->Height($lh) + $nch; # Remember the non-client height!
          }
          else {
!             $label->Top(($h - $lh) / 2);
          }
      }
  
- This does not work in build 340 of Win32::GUI, as there is a bug in the Left()
- and Top() methods for client windows (such as the label used here). Hopefully,
- this bug will be fixed in the next version.
- 
  Note that co-ordinates are calculated from the top left of the enclosing
  window.
--- 302,323 ----
  
      sub Main_Resize {
!         my $mw = $main->ScaleWidth();
!         my $mh = $main->ScaleHeight();
          my $lw = $label->Width();
          my $lh = $label->Height();
!         if ($lw > $mw) {
!             $main->Width($lw + $ncw); # Remember the non-client width!
          }
          else {
!             $label->Left(($mw - $lw) / 2);
          }
!         if ($lh > $mh) {
!             $main->Height($lh + $nch); # Remember the non-client height!
          }
          else {
!             $label->Top(($mh - $lh) / 2);
          }
      }
  
  Note that co-ordinates are calculated from the top left of the enclosing
  window.
***************
*** 385,388 ****
--- 381,385 ----
  
      $main->Change(-minsize => [$w, $h]);
+     $main->Resize($w, $h);
      $main->Move($x, $y);
      $main->Show();
***************
*** 395,404 ****
  
      sub Main_Resize {
!         my $w = $main->ScaleWidth();
!         my $h = $main->ScaleHeight();
          my $lw = $label->Width();
          my $lh = $label->Height();
!               $label->Left(int(($w - $lw) / 2));
!               $label->Top(int(($h - $lh) / 2));
      }
  
--- 392,402 ----
  
      sub Main_Resize {
!         my $mw = $main->ScaleWidth();
!         my $mh = $main->ScaleHeight();
          my $lw = $label->Width();
          my $lh = $label->Height();
! 
!       $label->Left(int(($mw - $lw) / 2));
!       $label->Top(int(($mh - $lh) / 2));
      }
  

Index: Part5.pod
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/docs/GUI/Tutorial/Part5.pod,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Part5.pod   26 Jun 2005 16:41:01 -0000      1.1
--- Part5.pod   5 Oct 2005 22:20:49 -0000       1.2
***************
*** 141,155 ****
  
  If you choose to close the second window with the Close (little X)
! button on the upper right corner, you'll notice that the window
! disappear, and that it does not show anymore when you press the
! button on the main window!
  
  What's happening here is that we requested a C<W2_Terminate> action,
  and since we didn't provide an event for this, Win32::GUI proceeds
  with the default behaviour for the close button, which is to destroy
! the window. The result is that you can't show $W2 anymore, because
! it does not exists anymore as a valid window (although it still exists
! as a Perl object). To let our window survive the close action, we need
! to provide a customary C<Terminate> event:
  
        sub W2_Terminate {
--- 141,152 ----
  
  If you choose to close the second window with the Close (little X)
! button on the upper right corner, you'll notice that all the windows
! disappear.
  
  What's happening here is that we requested a C<W2_Terminate> action,
  and since we didn't provide an event for this, Win32::GUI proceeds
  with the default behaviour for the close button, which is to destroy
! the window, and exit the windows message loop. To let our window survive
! the close action, we need to provide a customary C<Terminate> event:
  
        sub W2_Terminate {
***************
*** 162,169 ****
  that we can show it again using the button in C<$W1>.
  
! =head2 Simulating "modal" windows
! 
! [ This section is out of date.  Win32::GUI has native support
! for modal windows.  See the DoModal() method in the main documention.]
  
  Here is another very common functionality you may want to implement:
--- 159,163 ----
  that we can show it again using the button in C<$W1>.
  
! =head2 "modal" windows
  
  Here is another very common functionality you may want to implement:
***************
*** 173,198 ****
  program unless you have disposed of it.
  
! Win32::GUI does not have direct support for modal windows, but you can
! simulate the behaviour with this trick:
  
!       sub W1_Activate {
!               if($W2->IsVisible) {
!                       $W2->SetForegroundWindow();
!                       return 0;
!               }
!               return 1;
        }
  
! The meaning should be obvious enough: if the popup window is shown,
! trying to activate the main window automatically reports you to the
! popup window; otherwise, the main window becomes the active one as
! normal. Of course, if you have more than one popup window, you should
! add code for everyone of them:
  
!       sub W1_Activate {
!               if($W2->IsVisible) { $W2->SetForegroundWindow(); return 0; }
!               if($W3->IsVisible) { $W3->SetForegroundWindow(); return 0; }
!               # ... and so on
!               return 1;
        }
  
--- 167,234 ----
  program unless you have disposed of it.
  
! So, the behaviour of a modal window is to diable interaction with the
! window used to launch it (know as its parent window).  To achieve this
! we first have to tell the window who its parent is.  We do this when we
! create W2, using the C<-parent> option:
  
!       $W2 = new Win32::GUI::Window(
!               ...
!               -parent => $W1,
!       );
! 
! Now, when we want to display the W2 we use the C<DoModal()> method: this
! disables W2's parent window (W1), and starts a new message loop to
! process events for W2.  When we are done with W2, we return C<-1> from an
! event handler, which causes C<DoModal()> to return, but in this case does
! not cause any of the windows to be destroyed.  Here's the full code:
! 
!       use Win32::GUI;
! 
!       my $W1 = Win32::GUI::Window->new(
!               -name  => "W1",
!               -title => "First Window",
!               -pos   => [ 100, 100 ],
!               -size  => [ 300, 200 ],
!       );
! 
!       $W1->AddButton(
!               -name => "Button1",
!               -text => "Open popup window",
!               -pos  => [ 10, 10 ],
!       );
! 
!       my $W2 = Win32::GUI::Window->new(
!               -name  => "W2",
!               -title => "Second Window",
!               -pos   => [ 150, 150 ],
!               -size  => [ 300, 200 ],
!               -parent => $W1,
!       );
! 
!       $W2->AddButton(
!               -name => "Button2",
!               -text => "Close this window",
!               -pos  => [ 10, 10 ],
!       );
! 
!       $W1->Show();
!       Win32::GUI::Dialog();
!       exit(0);
! 
!       sub W1_Terminate {
!               return -1;
        }
  
!       sub Button1_Click {
!               $W2->DoModal();
!               return 0;
!       }
  
!       sub W2_Terminate {
!               return -1;
!       }
! 
!       sub Button2_Click {
!               return -1;
        }
  


Reply via email to