Ignore:
Timestamp:
Dec 16, 2009, 9:20:29 PM (14 years ago)
Author:
ronosman
Message:

Feature 1332 added : new list and thumbnail display mode for photo selection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/pLoader/trunk/src/Uploader/GUI/wxImageListCtrl.pm

    r4324 r4504  
    2222use Wx;
    2323use Wx::DND;
     24use POSIX qw(ceil floor);
    2425use Wx qw/
    2526             wxDefaultPosition
     
    2930             wxLC_EDIT_LABELS
    3031             wxLC_ICON
     32                         wxLC_REPORT
    3133             wxLC_SMALL_ICON
    3234             wxIMAGE_LIST_NORMAL
     
    3638             wxLC_VIRTUAL
    3739             wxLC_REPORT
     40                         wxLC_AUTOARRANGE
    3841             wxBORDER_THEME
    3942             wxLIST_HITTEST_ONITEM
     
    4245             wxLIST_STATE_DONTCARE
    4346             wxLIST_STATE_FOCUSED
     47                         wxIMAGE_LIST_SMALL
    4448         /;
    4549use Wx::Event qw/
    4650                    EVT_LIST_BEGIN_DRAG
    4751                    EVT_LIST_ITEM_SELECTED
     52                                        EVT_SIZE
    4853                /;
    4954         
     
    5459          imagenames
    5560          imagelist
     61          wx_imagelist
     62                  image_size
     63                  arrange_items
     64                  styles
     65                  insert_items
     66                  initialize
     67                  columns
     68                  change_display_mode
     69                  wx_img
     70                  item_refresh
    5671      /
    5772);
    5873use Data::Dumper;
     74
     75
    5976sub new {
    60   my( $class, $params ) = @_;
    61   my( $self ) = $class->SUPER::new(
    62                                        $params->{parentwnd},
    63                                        -1,
    64                                        wxDefaultPosition,
    65                                        wxDefaultSize,
    66                                        wxNO_BORDER|
    67                                        wxLC_ICON|
    68                                        wxLC_EDIT_LABELS
    69                                   );
    70 
    71   $self->imagelist(
    72       $params->{imagelist}
    73   );
    74 
    75                                  
    76   $self->prevItemCount(-1);
    77 
    78   EVT_LIST_BEGIN_DRAG( $self, $self, \&OnBeginDrag);
    79 
    80 
    81   $self;
     77    my( $class, $params ) = @_;
     78
     79 
     80    my( $self ) = $class->SUPER::new(
     81        $params->{parentwnd},
     82        -1,
     83        wxDefaultPosition,
     84        wxDefaultSize,
     85                wxNO_BORDER
     86    );
     87       
     88        $self->wx_img(
     89        Wx::ImageList->new( 16, 16, 1 )
     90        );
     91        $self->wx_img->Add(
     92        Wx::Bitmap->new( '../res/image.png', wxBITMAP_TYPE_PNG )       
     93        );
     94
     95    $self->imagelist(
     96        $params->{imagelist}
     97    );
     98    # bitmap container for photo selection
     99    $self->wx_imagelist(
     100        $params->{wx_imagelist}||$self->imagelist->wx_thumb_imglist
     101    );
     102
     103    $self->image_size(
     104        $params->{image_size}
     105    );
     106
     107        $self->columns(
     108            $params->{columns}
     109        );
     110        print Dumper $self->columns;
     111    $self->prevItemCount(-1);
     112
     113    EVT_LIST_BEGIN_DRAG( $self, $self, \&OnBeginDrag);
     114
     115    EVT_SIZE($self, sub {
     116            my ( $this, $event ) = @_;
     117   
     118                        $this->arrange_items(1);
     119            $event->Skip();
     120        }
     121    );
     122       
     123        Wx::Event::EVT_IDLE(
     124            $self,
     125                sub {
     126                    my ($self, $event)=@_;
     127
     128                        if($self->arrange_items){
     129                            $self->Refresh;
     130                            $self->arrange_items(0);
     131                        }
     132                        if($self->change_display_mode){
     133                            my $dm = $self->imagelist->display_mode;
     134                    $self->initialize->{$dm}->($self) if exists $self->initialize->{$dm};
     135                            $self->Refresh;
     136                $self->change_display_mode(0);
     137                        }
     138                }
     139        );
     140       
     141        $self->initialize(
     142            {
     143
     144            'Thumbnail' => sub {  my ( $self ) = @_;
     145                                                                $self->Freeze;
     146                                                                $self->ClearAll;
     147                                                                $self->SetSingleStyle(wxLC_ICON);
     148                                                                $self->SetSingleStyle(wxLC_EDIT_LABELS, 0);
     149                                $self->SetImageList( $self->wx_imagelist, wxIMAGE_LIST_NORMAL ) ;
     150                                                                $self->Thaw;
     151                     },                 
     152            'Thumbnail and caption' => sub {  my ( $self ) = @_;
     153                                                                $self->Freeze;
     154                                                                $self->ClearAll;
     155                                                                $self->SetSingleStyle(wxLC_ICON);
     156                                                                $self->SetSingleStyle(wxLC_EDIT_LABELS);
     157                                $self->SetImageList( $self->wx_imagelist, wxIMAGE_LIST_NORMAL ) ;
     158                                                                $self->Thaw;
     159                     },                 
     160                'Property list' => sub { my ( $self ) = @_;
     161                                            my $i=0;
     162                                                               
     163                                                                $self->Freeze;
     164                                                                $self->ClearAll;
     165                                                                $self->SetSingleStyle(wxLC_REPORT);
     166                                                                $self->SetSingleStyle(wxLC_EDIT_LABELS);
     167                                $self->SetImageList( $self->wx_img, wxIMAGE_LIST_SMALL ) ;
     168                                map     {
     169                                                                    $self->InsertColumn($i, $_->{label});
     170                                                                        $i++;
     171                                }@{$self->columns};                                                             
     172                                                                $self->Thaw;
     173                                        },
     174                }
     175        );
     176
     177        $self->item_refresh(
     178            {
     179                    'Thumbnail' => sub {},
     180                    'Thumbnail and caption' => sub { my ( $self, $index ) = @_;
     181                                        my $image = $self->imagelist->GetImage($index);
     182                                        $self->SetItem(
     183                                                    $index,
     184                                                        0,
     185                                                        $image->site_name,
     186                                        ) if defined $image;
     187                                                },
     188            'Property list' => sub { my ( $self, $index ) = @_;
     189                                my $col = 0;
     190                                my $image = $self->imagelist->GetImage($index);
     191                                map{
     192                                    $self->SetItem(
     193                                        $index,
     194                                        $col,
     195                                        $image->$_
     196                                    ) if defined $image;
     197                                    $col++;
     198                                }
     199                                qw/site_name site_comment site_author file create_date/;
     200                            },
     201                }
     202        );
     203       
     204        $self->insert_items(
     205            {
     206                    'Thumbnail' => sub { my ( $self, $index ) = @_; $self->InsertImageItem($index, $index);},
     207                    'Thumbnail and caption' => sub { my ( $self, $index ) = @_;
     208                                                       $self->InsertImageStringItem(
     209                                               $index,
     210                                               $self->imagelist->GetImage($index)->site_name,
     211                                               $index,
     212                                           );
     213                                     },
     214            'Property list' => sub { my ( $self, $index ) = @_;
     215                                                   
     216                                                            $self->InsertImageStringItem(
     217                                    $index,
     218                                    "",
     219                                                                        0
     220                                                                );
     221                                                                $self->ItemRefresh($index);
     222
     223                                        },
     224                }
     225        );
     226
     227       
     228        $self->initialize->{$self->imagelist->display_mode}->($self) if exists $self->initialize->{$self->imagelist->display_mode};
     229
     230    $self;
     231}
     232
     233sub ItemRefresh {
     234    my ( $self, $index ) = @_;
     235       
     236        $self->item_refresh->{$self->imagelist->display_mode}->($self, $index) if exists $self->item_refresh->{$self->imagelist->display_mode};
    82237}
    83238
     
    141296
    142297sub Refresh {
    143     my ( $self, $wximagelist ) = @_;   
    144 
    145    $self->SetImageList( $wximagelist, wxIMAGE_LIST_NORMAL ) if defined $wximagelist ;
     298    my ( $self ) = @_; 
     299
     300   $self->Freeze();
    146301   $self->DeleteAllItems;
    147302   eval {
    148        for( my $i = 0 ; $i < $self->GetImageList(wxIMAGE_LIST_NORMAL)->GetImageCount ; $i++){
    149             my $indx = $self->InsertImageStringItem(
    150                 $i,
    151                 $self->imagelist->GetImage($i)->site_name,
    152                 $i,
    153             );
     303       my $y0 = 0;
     304       my $x0 = 0;
     305
     306       my $x_spacing = $self->image_size + 2;
     307       my $y_spacing = $self->image_size + 2;
     308       my $ipr = floor(($self->GetClientSize->GetWidth - 0.20*$x_spacing)/$x_spacing)||1;
     309       for( my $i = 0 ; $i < $self->imagelist->count ; $i++){
     310                # call the method corresponding to the display mode
     311            my $indx = $self->insert_items->{$self->imagelist->display_mode}->($self, $i);
     312                        if( 'Thumbnail' eq $self->imagelist->display_mode){
     313                my $row = floor($i/$ipr);
     314                my $col = $i%$ipr;
     315                $self->SetItemPosition(
     316                    $i,
     317                    Wx::Point->new(
     318                        $x0 + $x_spacing*$col,
     319                        $y0 + $y_spacing*$row,
     320                    ),
     321                );
     322                        }
    154323       }   
    155324   };
     325
     326   map{
     327       $self->SelectItem(
     328           $_
     329       );
     330           
     331           $self->EnsureVisible($_);
     332   } @{$self->imagelist->image_selection||[]};
     333
     334   $self->Thaw();
     335   $self->SetFocus;
    156336}
    157337
Note: See TracChangeset for help on using the changeset viewer.