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

Modified Files:
        CHANGELOG GUI.pm 
Log Message:
Re-write Win32::GUI::Textfield::new() to fix up -prompt option

Index: GUI.pm
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/GUI.pm,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** GUI.pm      16 Jul 2007 19:22:22 -0000      1.63
--- GUI.pm      16 Jul 2007 19:24:51 -0000      1.64
***************
*** 1388,1391 ****
--- 1388,1393 ----
      #         -left   => 75,
      #         -top    => 150,
+     #         -width  => 100,
+     #         -height => 20,
      #         -prompt => "Your name:",
      #     );
***************
*** 1407,1475 ****
      my($class, $parent, @options) = @_;
      my %options = @options;
      if(exists $options{-prompt}) {
!         my $add = 0;
!         my ($text, $left, $width, $height, );
!         my $visible = 1;
!         # Convert -pos and -size options to -left, -top, -width and -height 
options
!         if (exists $options{-pos}) {
!           $options{-left} = $options{-pos}[0];
!           $options{-top}  = $options{-pos}[1];
!         }
!         if (exists $options{-size}) {
!           $options{-width}  = $options{-size}[0];
!           $options{-height} = $options{-size}[1];
!         }
  
          if(ref($options{-prompt}) eq "ARRAY") {
!             $left = pop(@{$options{'-prompt'}});
!             $text = pop(@{$options{'-prompt'}});
!             if($left < 0) {
!                 $width = -$left;
!                 $left += $options{-left};
!             } else {
!                 $width = $left;
!                 $left  = $options{-left};
!                 $add   = 1;
!             }
!         } else {
!             $text = $options{-prompt};
          }
!         if(exists $options{-height}) {
!             $height = $options{-height}-3;
!         } else {
!             $height = 0;
          }
!         if(exists $options{-visible}) {
!             $visible = $options{-visible};
          }
          my $prompt = new Win32::GUI::Label(
              $parent,
!             -name    => $options{-name} . '_Prompt',
!             -width   => $width,
!             -left    => $left,
!             -top     => $options{-top} + 3,
              -text    => $text,
!             -height  => $height,
!             -visible => $visible,
          );
  
!         $options{-left} += $prompt->Width if $add;
  
!         # Update array options
!         for (my $i = 0; $i < @options; $i += 2) {
!             if ($options[$i] eq '-left') {
!                 $options[$i+1] = $options{-left};
!                 last;
!             }
!             if ($options[$i] eq '-pos') {
!                 $options[$i+1][0] = $options{-left};
!                 last;
!             }
          }
!     }
!     return Win32::GUI->_new(
!         Win32::GUI::_constant("WIN32__GUI__EDIT"),
!         $class, $parent, @options,
!     );
  }
  
--- 1409,1500 ----
      my($class, $parent, @options) = @_;
      my %options = @options;
+ 
+     # Create the textfield, invisible, and we'll
+     # make it visible if necessary at the end
+     my $visible = exists $options{-visible} ? $options{-visible} : 1;
+     my $textfield = Win32::GUI->_new(
+         Win32::GUI::_constant("WIN32__GUI__EDIT"),
+         $class, $parent, @options, '-visible', 0
+     );
+ 
+     # If we failed to create it, then return undef
+     return undef unless $textfield;
+ 
+     # If we have a -prompt option, then we need to
+     # create a label, and position it and the
+     # textfield correctly
      if(exists $options{-prompt}) {
!         my ($text, $adjust);
  
+         # extract the information we need from
+         # the -prompt option
          if(ref($options{-prompt}) eq "ARRAY") {
!             $text   = shift(@{$options{'-prompt'}});
!             $adjust = shift(@{$options{'-prompt'}}) || 0;
          }
!         else {
!             $text = $options{-prompt};
          }
! 
!         # Convert -pos to -left and -top,
!         if (exists $options{-pos}) {
!           $options{-left} = $options{-pos}[0];
!           $options{-top}  = $options{-pos}[1];
          }
+ 
+         ## Create the label; Setting width and height to
+         # zero creates it the right size for the text.
+         # XXX: This will inherit the font from the
+         # parent window, ignoring any -font option
+         # passed.
          my $prompt = new Win32::GUI::Label(
              $parent,
!             -name    => $textfield->{-name} . '_Prompt',
              -text    => $text,
!             -left    => $options{-left} || 0,
!             -top     => ($options{-top} || 0) + 3,
!             -width   => 0,
!             -height  => 0,
!             -visible => 0,
          );
  
!         # If we failed to create it, then return undef
!         return undef unless $prompt;
  
!         # Adjust the positions:
!         # $adjust < 0 : the textfield is in the correct
!         #               position, move the label left
!         # $adjust > 0 : the label is in the correct
!         #               position, move the textfield right
!         # $adjust == 0: both are correct, do nothing
!         # $adjust undefined: label needs moving to
!         #    the left of the textfield, which we will
!         #    do by setting $adjust appropriately
!         if(!defined $adjust) {
!             $adjust = -($prompt->Width() + 5);
          }
! 
!         if($adjust < 0) {
!             my $left = $prompt->Left();
!             $prompt->Left($left + $adjust);
!         }
!         elsif ($adjust > 0) {
!             my $left = $textfield->Left();
!             $textfield->Left($left + $adjust);
!         }
!         else {
!             # Adjust is zero, or we have
!             # an error;  in either case
!             # do nothing
!         }
! 
!         # Make the prompt visible if needed
!         $prompt->Show() if $visible;
!     } # finish processing prompt
! 
!     # Make the textfield visible if needed
!     $textfield->Show() if $visible;
! 
!     return $textfield;
  }
  

Index: CHANGELOG
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/CHANGELOG,v
retrieving revision 1.122
retrieving revision 1.123
diff -C2 -d -r1.122 -r1.123
*** CHANGELOG   16 Jul 2007 19:22:22 -0000      1.122
--- CHANGELOG   16 Jul 2007 19:24:51 -0000      1.123
***************
*** 8,11 ****
--- 8,12 ----
  + [Robert May] : 16 July 2007 -  Bug Fixes
      - GUI.pm - fix Win32::GUI::Imagelist::AddMasked (Tracker: 1734697)
+     - GUI.pm - fix -prompt option to Textfield (Tracker: 1734697)
  
  + [Robert May] : 15 July 2007 -  Bug Fixes


Reply via email to