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 | # +-----------------------------------------------------------------------+ |
---|
20 | package Uploader::GUI::wxImageListCtrl; |
---|
21 | use strict; |
---|
22 | use Wx; |
---|
23 | use Wx::DND; |
---|
24 | use Wx qw/ |
---|
25 | wxDefaultPosition |
---|
26 | wxDefaultSize |
---|
27 | wxLC_LIST |
---|
28 | wxNO_BORDER |
---|
29 | wxLC_EDIT_LABELS |
---|
30 | wxLC_ICON |
---|
31 | wxLC_SMALL_ICON |
---|
32 | wxIMAGE_LIST_NORMAL |
---|
33 | wxBITMAP_TYPE_JPEG |
---|
34 | wxBITMAP_TYPE_PNG |
---|
35 | wxBLACK |
---|
36 | wxLC_VIRTUAL |
---|
37 | wxLC_REPORT |
---|
38 | wxBORDER_THEME |
---|
39 | wxLIST_HITTEST_ONITEM |
---|
40 | wxLIST_NEXT_ALL |
---|
41 | wxLIST_STATE_SELECTED |
---|
42 | wxLIST_STATE_DONTCARE |
---|
43 | wxLIST_STATE_FOCUSED |
---|
44 | /; |
---|
45 | use Wx::Event qw/ |
---|
46 | EVT_LIST_BEGIN_DRAG |
---|
47 | EVT_LIST_ITEM_SELECTED |
---|
48 | /; |
---|
49 | |
---|
50 | use base qw/Wx::ListCtrl Class::Accessor::Fast/; |
---|
51 | __PACKAGE__->mk_accessors( |
---|
52 | qw/ |
---|
53 | prevItemCount |
---|
54 | imagenames |
---|
55 | imagelist |
---|
56 | / |
---|
57 | ); |
---|
58 | use Data::Dumper; |
---|
59 | sub 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; |
---|
82 | } |
---|
83 | |
---|
84 | sub OnBeginDrag { |
---|
85 | my( $self, $event ) = @_; |
---|
86 | |
---|
87 | |
---|
88 | my $data = Wx::TextDataObject->new( |
---|
89 | Dumper $self->GetSelectedItems |
---|
90 | ); |
---|
91 | my $source = Wx::DropSource->new( $self ); |
---|
92 | $source->SetData( $data ); |
---|
93 | |
---|
94 | $source->DoDragDrop( 1 ); |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | sub GetSelectedItems { |
---|
99 | my ( $self ) = @_; |
---|
100 | |
---|
101 | # find selected items |
---|
102 | my $item = -1; |
---|
103 | my $items = []; |
---|
104 | while(1) { |
---|
105 | $item = $self->GetNextItem( |
---|
106 | $item, |
---|
107 | wxLIST_NEXT_ALL, |
---|
108 | wxLIST_STATE_SELECTED |
---|
109 | ); |
---|
110 | last if(-1 == $item); |
---|
111 | |
---|
112 | # item is selected |
---|
113 | push @$items, $item |
---|
114 | } |
---|
115 | |
---|
116 | $items; |
---|
117 | } |
---|
118 | |
---|
119 | sub GetAllItems { |
---|
120 | my ( $self ) = @_; |
---|
121 | |
---|
122 | # find selected items |
---|
123 | my $item = -1; |
---|
124 | my $items = []; |
---|
125 | while(1) { |
---|
126 | $item = $self->GetNextItem( |
---|
127 | $item, |
---|
128 | wxLIST_NEXT_ALL, |
---|
129 | wxLIST_STATE_DONTCARE |
---|
130 | ); |
---|
131 | last if(-1 == $item); |
---|
132 | |
---|
133 | # item is selected |
---|
134 | push @$items, $item |
---|
135 | } |
---|
136 | |
---|
137 | $items; |
---|
138 | |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | sub Refresh { |
---|
143 | my ( $self, $wximagelist ) = @_; |
---|
144 | |
---|
145 | $self->SetImageList( $wximagelist, wxIMAGE_LIST_NORMAL ) if defined $wximagelist ; |
---|
146 | $self->DeleteAllItems; |
---|
147 | 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 | ); |
---|
154 | } |
---|
155 | }; |
---|
156 | } |
---|
157 | |
---|
158 | sub SelectItem { |
---|
159 | my ( $self, $index ) = @_; |
---|
160 | |
---|
161 | $self->SetItemState( |
---|
162 | $index, |
---|
163 | wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED, |
---|
164 | wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED, |
---|
165 | ); |
---|
166 | } |
---|
167 | |
---|
168 | 1; |
---|
169 | |
---|