AutoItX/Control/ListView.pm

filter: Statementstmt 50.0% 18 / 36 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 55.5% 5 / 9 Podpod 100% 2 / 2 totaltotal 40.3% 25 / 62 CC 7 SCAR 21.9
CC
7
Cov
37%
AUTOLOAD
20.0
new
12.0
selected
6.0
CRAP 8.9
« AutoItX/Control/TreeView.pm ↑ Summary
1 package Win32::AutoItX::Control::ListView;
2  
3 =head1 NAME
4  
5 Win32::AutoItX::Control::ListView - OO interface for ListView32 controls
6  
7 =head1 SYNOPSIS
8  
9 use Win32::AutoItX;
10  
11 my $a = Win32::AutoItX->new;
12  
13 my $pid = $a->Run('regedit.exe');
14 my $window = $a->get_window('Registry Editor');
15 $window->wait;
16 $window->show;
17  
18 my $listview = $window->get_control('SysListView321')->listview();
19  
20 for my $i (0 .. $listview->count - 1) {
21 print "Item #$i Column 0 = ", $listview->text($i), "\n",
22 "\tColumn 1 = ", $listview->text($i, 1), "\n",
23 "\tColumn 2 = ", $listview->text($i, 2), "\n";
24 }
25  
26 $listview->select_all;
27 my @selected = $listview->selected;
28 print "Selected items = @selected\n";
29  
30 =head1 DESCRIPTION
31  
32 Win32::AutoItX::Control::ListView provides an object-oriented interface for
33 AutoItX methods to operate with ListView32 (SysListView32) controls.
34  
35 All items/subitems are 0 based. This means that the first item/subitem in a
36 list is 0, the second is 1, and so on.
37  
38 In a "Details" view of a ListView32 control, the "item" can be thought of as the
39 "row" and the "subitem" as the "column".
40  
41 =cut
42  
43 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 1 our $VERSION = '1.00';
47  
48 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use Scalar::Util qw{ blessed };
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 0 ▶use overload fallback => 1, '""' => sub { $_[0]->{control}->{control} };
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
52  
53 1 my %Control_Commands = qw{
54 deselect DeSelect
55 find FindItem
56 count GetItemCount
57 get_selected GetSelected
58 selected_count GetSelectedCount
59 subitem_count GetSubItemCount
60 text GetText
61 is_selected IsSelected
62 select Select
63 select_all SelectAll
64 clear_select SelectClear
65 invert_select SelectInvert
66 change_view ViewChange
67 };
68  
69 =head1 METHODS
70  
71 =head2 new
72  
73 $listview = Win32::AutoItX::Control::ListView->new($control)
74  
75 creates a ListView object.
76  
77 =cut
78  
79 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
80 0 my $class = shift;
81 0 my %self;
82 0 $self{control} = shift;
83 croak "The first argument should be a Win32::AutoItX::Control object"
84 unless blessed $self{control}
85 0 ▶ and $self{control}->isa('Win32::AutoItX::Control');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self{"control"}) and $self{"control"}->isa("Win32::AutoItX::Control") 0 0 0
Condition0%0/3
builtin::blessed($self{"control"}) and $self{"control"}->isa("Win32::AutoItX::Control")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($self{"control"}) and $self{"control"}->isa("Win32::AutoItX::Control")
builtin::blessed($self{"control"}) $self{"control"}->isa("Win32::AutoItX::Control")
Truth table0%0/3
A and B
A= builtin::blessed($self{"control"})B= $self{"control"}->isa("Win32::AutoItX::Control")
ABresult
0X0
100
111
86 0 return bless \%self, $class;
87 }
88 #-------------------------------------------------------------------------------
89  
90 =head2 selected
91  
92 $index = $listview->selected()
93 @indexes = $listview->selected()
94  
95 returns a string containing the item index of selected items. In the scalar
96 context it returns the first select item only.
97  
98 =cut
99  
100 0 ▶sub selected {
Subroutine selected: not called CC=2 SCAR=17.9
Pod documented
101 0 my $self = shift;
102 0 ▶ return split(/\|/, $self->get_selected(wantarray ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
103 }
104 #-------------------------------------------------------------------------------
105  
106 =head2 find
107  
108 $index = $listview->find($string)
109 $index = $listview->find($string, $subitem)
110  
111 returns the item index of the string. Returns -1 if the string is not found.
112  
113 =head2 count
114  
115 $count = $listview->count()
116  
117 returns the number of list items.
118  
119 =head2 selected_count
120  
121 $selected_count = $listview->selected_count()
122  
123 returns the number of items that are selected.
124  
125 =head2 subitem_count
126  
127 $subitem_count = $listview->subitem_count()
128  
129 returns the number of subitems.
130  
131 =head2 text
132  
133 $text = $listview->text($item, $subitem)
134  
135 returns the text of a given item/subitem.
136  
137 =head2 is_selected
138  
139 $boolean = $listview->is_selected($item)
140  
141 returns 1 if the item is selected, otherwise returns 0.
142  
143 =head2 select
144
145 $listview->select($index)
146 $listview->select($from_index, $to_index)
147  
148 selects one or more items.
149  
150 =head2 deselect
151  
152 $listview->deselect($index)
153 $listview->deselect($from_index, $to_index)
154  
155 deselects one or more items.
156  
157 =head2 select_all
158  
159 $listview->select_all()
160  
161 selects all items.
162  
163 =head2 clear_select
164  
165 $listview->clear_select()
166  
167 clears the selection of all items.
168  
169 =head2 invert_select
170  
171 $listview->invert_select()
172  
173 inverts the current selection.
174  
175 =head2 change_view
176  
177 $listview->change_view($view)
178  
179 changes the current view. Valid views are "list", "details", "smallicons",
180 "largeicons".
181  
182 =head2 Win32::AutoItX::Control methods
183  
184 This module also provides most of L<Win32::AutoItX::Control> methods.
185  
186 =cut
187  
188 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
189 0 my $self = shift;
190 0 my $method = our $AUTOLOAD;
191 0 $method =~ s/.*:://;
192  
193 0 my @params = @_;
194 0 ▶ if (exists $Control_Commands{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Control_Commands{$method}) 0 0 0
195 0 ▶ push @params, '' unless @params;
Branch: 1 branch
BranchTrueFalseTotal
unless @params 0 0 0
196 0 ▶ push @params, '' if @params < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @params < 2 0 0 0
197 0 unshift @params, $Control_Commands{$method};
198 0 $method = 'clw';
199 }
200 0 $self->{control}->$method(@params);
201 }
202 #-------------------------------------------------------------------------------
203  
204 =head1 SEE ALSO
205  
206 =over
207  
208 =item L<Win32::AutoItX::Control>
209  
210 =item L<Win32::AutoItX>
211  
212 =item AutoItX Help
213  
214 =back
215  
216 =head1 AUTHOR
217  
218 Mikhail Telnov E<lt>Mikhail.Telnov@gmail.comE<gt>
219  
220 =head1 COPYRIGHT
221  
222 This software is copyright (c) 2017 by Mikhail Telnov.
223  
224 This library is free software; you may redistribute and/or modify it
225 under the same terms as Perl itself.
226  
227 =cut
228  
229 1 1;
« AutoItX/Control/TreeView.pm ↑ Summary