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

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

Feature 1009 : All selected should be implicit. When Photo selection has no selected item, all items are considered to be implicitly selected.

  • Property svn:eol-style set to LF
File size: 4.3 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         /;
43use Wx::Event qw/
44                    EVT_LIST_BEGIN_DRAG
45                    EVT_LIST_ITEM_SELECTED
46                /;
47         
48use base qw/Wx::ListCtrl Class::Accessor::Fast/;
49__PACKAGE__->mk_accessors( 
50    qw/
51          prevItemCount
52          imagenames
53          imagelist
54      / 
55);
56use Data::Dumper;
57sub new {
58  my( $class, $params ) = @_;
59  my( $self ) = $class->SUPER::new(
60                                       $params->{parentwnd},
61                                       -1,
62                                       wxDefaultPosition,
63                                       wxDefaultSize,
64                                       wxNO_BORDER|
65                                       wxLC_ICON|
66                                       wxLC_EDIT_LABELS
67                                  );
68
69  $self->imagelist(
70      $params->{imagelist}
71  );
72
73                                 
74  $self->prevItemCount(-1);
75
76  EVT_LIST_BEGIN_DRAG( $self, $self, \&OnBeginDrag);
77
78
79  $self;
80}
81
82sub OnBeginDrag {
83  my( $self, $event ) = @_;
84
85
86  my $data = Wx::TextDataObject->new( 
87      Dumper $self->GetSelectedItems
88  );
89  my $source = Wx::DropSource->new( $self );
90  $source->SetData( $data );
91
92  $source->DoDragDrop( 1 );
93}
94
95
96sub GetSelectedItems {
97    my ( $self ) = @_; 
98
99  # find selected items
100  my $item = -1;
101  my $items = [];
102  while(1) {
103      $item = $self->GetNextItem(
104          $item,     
105          wxLIST_NEXT_ALL,
106          wxLIST_STATE_SELECTED
107      );
108      last if(-1 == $item);
109     
110      # item is selected       
111      push @$items, $item
112  }
113 
114  $items;
115}
116
117sub GetAllItems {
118    my ( $self ) = @_; 
119
120  # find selected items
121  my $item = -1;
122  my $items = [];
123  while(1) {
124      $item = $self->GetNextItem(
125          $item,     
126          wxLIST_NEXT_ALL,
127          wxLIST_STATE_DONTCARE
128      );
129      last if(-1 == $item);
130     
131      # item is selected       
132      push @$items, $item
133  }
134 
135  $items;
136       
137}
138
139
140sub Refresh {
141    my ( $self, $wximagelist ) = @_;   
142
143   $self->SetImageList( $wximagelist, wxIMAGE_LIST_NORMAL ) if defined $wximagelist ;
144   $self->DeleteAllItems;
145   eval {
146       for( my $i = 0 ; $i < $self->GetImageList(wxIMAGE_LIST_NORMAL)->GetImageCount ; $i++){
147            my $indx = $self->InsertImageStringItem(
148                $i,
149                $self->imagelist->GetImage($i)->site_name,
150                $i,
151            );
152       }   
153   };
154}
155
156
157
1581;
159
Note: See TracBrowser for help on using the repository browser.