source: extensions/pLoader/trunk/src/Uploader/GUI/wxImageListCtrl.pm @ 3362

Last change on this file since 3362 was 3362, checked in by ronosman, 15 years ago

Feature 1015 added : save current image selection and reload preview when pLoader starts.

  • Property svn:eol-style set to LF
File size: 4.5 KB
Line 
1# +-----------------------------------------------------------------------+
2# | pLoader - a Perl photo uploader for Piwigo                            |
3# +-----------------------------------------------------------------------+
4# | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
5# +-----------------------------------------------------------------------+
6# | This program is free software; you can redistribute it and/or modify  |
7# | it under the terms of the GNU General Public License as published by  |
8# | the Free Software Foundation                                          |
9# |                                                                       |
10# | This program is distributed in the hope that it will be useful, but   |
11# | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13# | General Public License for more details.                              |
14# |                                                                       |
15# | You should have received a copy of the GNU General Public License     |
16# | along with this program; if not, write to the Free Software           |
17# | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18# | USA.                                                                  |
19# +-----------------------------------------------------------------------+
20package Uploader::GUI::wxImageListCtrl;
21use strict;
22use Wx;
23use Wx::DND;
24use Wx qw/
25             wxDefaultPosition
26             wxDefaultSize
27             wxLC_LIST
28             wxNO_BORDER
29             wxLC_EDIT_LABELS
30             wxLC_ICON
31             wxIMAGE_LIST_NORMAL
32             wxBITMAP_TYPE_JPEG
33             wxBITMAP_TYPE_PNG
34             wxBLACK
35             wxLC_VIRTUAL
36             wxLC_REPORT
37             wxBORDER_THEME
38             wxLIST_HITTEST_ONITEM
39             wxLIST_NEXT_ALL
40             wxLIST_STATE_SELECTED
41             wxLIST_STATE_DONTCARE
42             wxLIST_STATE_FOCUSED
43         /;
44use Wx::Event qw/
45                    EVT_LIST_BEGIN_DRAG
46                    EVT_LIST_ITEM_SELECTED
47                /;
48         
49use base qw/Wx::ListCtrl Class::Accessor::Fast/;
50__PACKAGE__->mk_accessors( 
51    qw/
52          prevItemCount
53          imagenames
54          imagelist
55      / 
56);
57use Data::Dumper;
58sub new {
59  my( $class, $params ) = @_;
60  my( $self ) = $class->SUPER::new(
61                                       $params->{parentwnd},
62                                       -1,
63                                       wxDefaultPosition,
64                                       wxDefaultSize,
65                                       wxNO_BORDER|
66                                       wxLC_ICON|
67                                       wxLC_EDIT_LABELS
68                                  );
69
70  $self->imagelist(
71      $params->{imagelist}
72  );
73
74                                 
75  $self->prevItemCount(-1);
76
77  EVT_LIST_BEGIN_DRAG( $self, $self, \&OnBeginDrag);
78
79
80  $self;
81}
82
83sub OnBeginDrag {
84  my( $self, $event ) = @_;
85
86
87  my $data = Wx::TextDataObject->new( 
88      Dumper $self->GetSelectedItems
89  );
90  my $source = Wx::DropSource->new( $self );
91  $source->SetData( $data );
92
93  $source->DoDragDrop( 1 );
94}
95
96
97sub GetSelectedItems {
98    my ( $self ) = @_; 
99
100  # find selected items
101  my $item = -1;
102  my $items = [];
103  while(1) {
104      $item = $self->GetNextItem(
105          $item,     
106          wxLIST_NEXT_ALL,
107          wxLIST_STATE_SELECTED
108      );
109      last if(-1 == $item);
110     
111      # item is selected       
112      push @$items, $item
113  }
114 
115  $items;
116}
117
118sub GetAllItems {
119    my ( $self ) = @_; 
120
121  # find selected items
122  my $item = -1;
123  my $items = [];
124  while(1) {
125      $item = $self->GetNextItem(
126          $item,     
127          wxLIST_NEXT_ALL,
128          wxLIST_STATE_DONTCARE
129      );
130      last if(-1 == $item);
131     
132      # item is selected       
133      push @$items, $item
134  }
135 
136  $items;
137       
138}
139
140
141sub Refresh {
142    my ( $self, $wximagelist ) = @_;   
143
144   $self->SetImageList( $wximagelist, wxIMAGE_LIST_NORMAL ) if defined $wximagelist ;
145   $self->DeleteAllItems;
146   eval {
147       for( my $i = 0 ; $i < $self->GetImageList(wxIMAGE_LIST_NORMAL)->GetImageCount ; $i++){
148            my $indx = $self->InsertImageStringItem(
149                $i,
150                $self->imagelist->GetImage($i)->site_name,
151                $i,
152            );
153       }   
154   };
155}
156
157sub SelectItem {
158    my ( $self, $index ) = @_;
159
160    $self->SetItemState(
161        $index,
162        wxLIST_STATE_SELECTED,
163        wxLIST_STATE_SELECTED
164    ); 
165}
166
1671;
168
Note: See TracBrowser for help on using the repository browser.