blib/lib/Tkx/WinIco.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Tkx::WinIco;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use Tkx;
Subroutine BEGIN: called CC=1 SCAR=2.6
7
8 =head1 NAME
9
10 Tkx::WinIco - The taskbar extension for Tkx on Win.
11
12 =head1 VERSION
13
14 Version 0.01
15
16 =cut
17
18 our $VERSION = '0.01';
19
20
21 =head1 SYNOPSIS
22
23 Quick summary of what the module does.
24 Perhaps a little code snippet.
25
26 use Tkx;
27 use Tkx::WinIco;
28
29 # Some Tk Stuff.
30 Tkx::option_add('*Menu.tearOff', 0);
31
32 # Get reference to "." and create context menu.
33 my $mw = Tkx::widget->new('.');
34 my $menu = $mw->new_menu();
35
36 $menu->add_command(
37 -label => 'Quit',
38 -command => sub {
39 $mw->g_destroy();
40 },
41 );
42
43 # Create icon resource.
44 my $icon = Tkx::WinIco->new('./icons/1.ico');
45
46 # Add icon to taskbar.
47 $icon->taskbar_add(text => 'Tooltip');
48
49 # Change tooltip.
50 $icon->taskbar_modify(-text => 'New tooltip');
51
52 # Hide icon.
53 $icon->taskbar_delete();
54
55 # Restore icon.
56 $icon->taskbar_add();
57
58 # Bind events.
59 $icon->bind('WM_RBUTTONUP' => sub {
60 my ($ico, $message, $x, $y) = @_;
61 $menu->g_tk___popup($x, $y);
62 });
63
64 # Main loop.
65 Tkx::MainLoop();
66 1;
67
68
69
70 =head1 INSTALLATION
71
72 Install Tkx::WinIco as usual perl package.
73
74 Download winico06.zip module from L<http://sourceforge.net/projects/tktable/files/winico/0.6/>
75 then extract Winico06.dll from archive and put it into same directory as a script.
76
77 However, you can specify any other path using
78
79 use Tkx::WinIco {dll => './libs/winico.dll'};
80
81
82
83 =head1 METHODS
84
85 =cut
86
87 BEGIN {
88 die "Tkx::WinIco is only for Win platform"
89 if $^O !~ /^MSWin/;
90 }
91
92 sub import {
93 my ($class, @fields) = @_;
94
95 my $winico_dll = 'Winico06.dll';
96
97 foreach my $field (@fields) {
98 if (ref($field) eq 'HASH') {
99 if (defined $field->{dll}) {
100 $winico_dll = $field->{dll};
101 }
102 }
103 }
104 if (!Tkx::info_commands('winico')) {
105 eval {Tkx::load($winico_dll)};
106 if ($@) {
107 croak "cannot load winico extension ($winico_dll)";
108 }
109 }
110 }
111
112 =head2 new
113
114 =cut
115
116 sub new {
117 my $class = shift @_;
118 my %param = scalar @_ == 1 ? (-createfrom => shift @_) : @_;
119
120 my $self = bless {}, $class;
121
122 # Set default parameters.
123 $self->{pos} = 0;
124 $self->{text} = '',
125 $self->{callbacks} = {};
126
127 # Load icon resource.
128 $self->{resource} = Tkx::winico_createfrom($param{-createfrom})
129 if defined $param{-createfrom};
130
131 $self->{resource} = Tkx::winico_load($param{-load})
132 if defined $param{-load};
133
134 # Return object.
135 return $self;
136 }
137
138 =head2 bind
139
140 =cut
141
142 sub bind {
143 my ($self, $ev, $cb) = @_;
144 return if @_ < 2;
145
146 if (defined $cb) {
147 $self->{callbacks}->{$ev} = $cb;
148 }
149 else {
150 return $self->{callbacks}->{$ev};
151 }
152 }
153
154 =head2 taskbar_add
155
156 =cut
157
158 sub taskbar_add {
159 my ($self, %args) = @_;
160
161 $self->{pos} = $args{-pos} if defined $args{-pos};
162 $self->{text} = $args{-text} if defined $args{-text};
163
164 return Tkx::winico_taskbar_add(
165 $self->{resource} => (
166 -pos => $self->{pos},
167 -text => $self->{text},
168 -callback => [
169 sub {
170 if (defined(my $m = shift)) {
171 $self->_call($self->{callbacks}->{$m}, $self, $m, @_);
172 }
173
174 },
175 Tkx::Ev(qw[%m %x %y %X %Y]),
176 ],
177 ),
178 );
179 }
180
181 =head2 taskbar_modify
182
183 =cut
184
185 sub taskbar_modify {
186 my ($self, %args) = @_;
187
188 $self->{pos} = $args{-pos} if defined $args{-pos};
189 $self->{text} = $args{-text} if defined $args{-text};
190
191 return Tkx::winico_taskbar_modify(
192 $self->{resource} => (
193 -pos => $self->{pos},
194 -text => $self->{text},
195 ),
196 );
197 }
198
199 =head2 taskbar_delete
200
201 =cut
202
203 sub taskbar_delete {
204 return Tkx::winico_taskbar_delete(shift->{resource});
205 }
206
207 =head2 info
208
209 =cut
210
211 sub info {
212 return Tkx::winico_info(shift->{resource});
213 }
214
215
216 sub _call {
217 my($self, $callback, @args) = @_;
218 return unless $callback;
219
220 if (ref($callback) eq 'ARRAY') {
221 my $cb_arrayref = shift @{$callback};
222
223 if (ref($cb_arrayref) eq 'CODE') {
224 return $cb_arrayref->(@{$callback}, @args);
225 }
226 }
227
228 if (ref($callback) eq 'CODE') {
229 return $callback->(@args);
230 }
231 }
232
233
234 sub DESTROY {
235 my ($self) = @_;
236
237 if (defined $self->{resource}) {
238 Tkx::winico_delete($self->{resource});
239 }
240 }
241
242 =head1 AUTHOR
243
244 Alexander Nusov, C<< <alexander.nusov+cpan at gmail.com> >>
245
246
247 =head1 BUGS
248
249 Please report any bugs or feature requests to C<bug-tkx-winico at rt.cpan.org>, or through
250 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tkx-WinIco>. I will be notified, and then you'll
251 automatically be notified of progress on your bug as I make changes.
252
253
254 =head1 SUPPORT
255
256 You can find documentation for this module with the perldoc command.
257
258 perldoc Tkx::WinIco
259
260
261 You can also look for information at:
262
263 =over 4
264
265 =item * RT: CPAN's request tracker
266
267 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tkx-WinIco>
268
269 =item * AnnoCPAN: Annotated CPAN documentation
270
271 L<http://annocpan.org/dist/Tkx-WinIco>
272
273 =item * CPAN Ratings
274
275 L<http://cpanratings.perl.org/d/Tkx-WinIco>
276
277 =item * Search CPAN
278
279 L<http://search.cpan.org/dist/Tkx-WinIco/>
280
281 =back
282
283
284 =head1 ACKNOWLEDGEMENTS
285
286 Leo Schubert, Brueckner&Jarosch Ing.-GmbH
287
288 Pat Thoyts.
289
290
291 =head1 LICENSE AND COPYRIGHT
292
293 Copyright 2010 Alexander Nusov.
294
295 This program is free software; you can redistribute it and/or modify it
296 under the terms of either: the GNU General Public License as published
297 by the Free Software Foundation; or the Artistic License.
298
299 See http://dev.perl.org/licenses/ for more information.
300
301
302 =cut
303 1;
↑ Summary