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