home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / STORE.al < prev    next >
Encoding:
Text File  |  2004-06-01  |  2.5 KB  |  81 lines

  1. # NOTE: Derived from ..\blib\lib\Tk\Listbox.pm.
  2. # Changes made here will be lost when autosplit is run again.
  3. # See AutoSplit.pm.
  4. package Tk::Listbox;
  5.  
  6. #line 232 "..\blib\lib\Tk\Listbox.pm (autosplit into ..\blib\lib\auto\Tk\Listbox\STORE.al)"
  7. # STORE
  8. # -----
  9. # If tied to an array we will modify the Listbox contents, while if tied
  10. # to a scalar we will select and clear elements.
  11. sub STORE {
  12.  
  13.   if ( scalar(@_) == 2 ) {
  14.      # we have a tied scalar
  15.      my ( $class, $selected ) = @_;
  16.      my $self = ${$class->{OBJECT}};
  17.      my %options = %{$class->{OPTION}} if defined $class->{OPTION};;
  18.  
  19.      # clear currently selected elements
  20.      $self->selectionClear(0,'end');
  21.  
  22.      # set selected elements
  23.      if ( defined $options{ReturnType} ) {
  24.  
  25.         # THREE-WAY SWITCH
  26.         if ( $options{ReturnType} eq "index" ) {
  27.            for ( my $i=0; $i < scalar(@$selected) ; $i++ ) {
  28.               for ( my $j=0; $j < $self->size() ; $j++ ) {
  29.                   if( $j == $$selected[$i] ) {
  30.                  $self->selectionSet($j); last; }
  31.               }
  32.            }
  33.         } elsif ( $options{ReturnType} eq "element" ) {
  34.            for ( my $k=0; $k < scalar(@$selected) ; $k++ ) {
  35.               for ( my $l=0; $l < $self->size() ; $l++ ) {
  36.                  if( $self->get($l) eq $$selected[$k] ) {
  37.                 $self->selectionSet($l); last; }
  38.               }
  39.            }
  40.     } elsif ( $options{ReturnType} eq "both" ) {
  41.            foreach my $key ( keys %$selected ) {
  42.               $self->selectionSet($key)
  43.                   if $$selected{$key} eq $self->get($key);
  44.        }
  45.     }
  46.      } else {
  47.         # return elements (default)
  48.         for ( my $k=0; $k < scalar(@$selected) ; $k++ ) {
  49.            for ( my $l=0; $l < $self->size() ; $l++ ) {
  50.               if( $self->get($l) eq $$selected[$k] ) {
  51.              $self->selectionSet($l); last; }
  52.            }
  53.         }
  54.      }
  55.  
  56.   } else {
  57.      # we have a tied array
  58.      my ( $class, $index, $value ) = @_;
  59.      my $self = ${$class->{OBJECT}};
  60.  
  61.      # check size of current contents list
  62.      my $sizeof = $self->size();
  63.  
  64.      if ( $index <= $sizeof ) {
  65.         # Change a current listbox entry
  66.         $self->delete($index);
  67.         $self->insert($index, $value);
  68.      } else {
  69.         # Add a new value
  70.         if ( defined $index ) {
  71.            $self->insert($index, $value);
  72.         } else {
  73.            $self->insert("end", $value);
  74.         }
  75.      }
  76.    }
  77. }
  78.  
  79. # end of Tk::Listbox::STORE
  80. 1;
  81.