blib/lib/Tk/HideCursor.pm

filter: Statementstmt 45.1% 14 / 31 Branchbran 10.0% 1 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod n/a totaltotal 39.1% 18 / 46 CC 4 SCAR 18.5
CC
4
Cov
37%
hideCursor
12.0
showCursor
6.0
BEGIN
1.0
CRAP 6.4
↑ Summary
1 package Tk::HideCursor;
2  
3 2 our $VERSION = 0.02;
4  
5 #==============================================================================#
6  
7 =head1 NAME
8  
9 Tk::HideCursor - Hide the cursor when it passes over your widget
10  
11 =head1 SYNOPSIS
12  
13 use Tk::HideCursor;
14 $widget->hideCursor;
15 $widget->showCursor;
16  
17 =head1 DESCRIPTION
18  
19 Adds methods to the Tk::Wm base class so that any widget may hide the cursor
20  
21 =head2 METHODS
22  
23 =over 4
24  
25 =cut
26  
27 #==============================================================================#
28  
29 package Tk::Wm;
30  
31 2 require 5.6.0;
32  
33 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 #==============================================================================#
38  
39 2 my ($win32_curse, $orig_curse);
40  
41 2 ▶if ($^O =~ /Win32/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /Win32/) 0 2 2
42 0 ▶ eval "use Win32::API"; croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
43 0 $win32_curse = Win32::API->new('user32', 'ShowCursor', ['N'], 'N');
44 }
45  
46 #==============================================================================#
47  
48 =item $widget->hideCursor();
49  
50 Hide the mouse cursor when it's over $widget.
51  
52 =cut
53  
54 0 ▶sub hideCursor {
Subroutine hideCursor: not called CC=3 SCAR=24.8
55 0 my ($obj) = @_;
56  
57 0 ▶ if ($^O =~ /Win32/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /Win32/) { } 0 0 0
58  
59 # Hide the cursor
60 0 $win32_curse->Call(0);
61
62 } else {
63 #This should work to avoid embedding file but doesnt.
64 #my $bits = pack("b8"x5,
65 # "........",
66 # "...0....",
67 # "...0....",
68 # "...0....",
69 # "........",
70 #);
71 #$obj->DefineBitmap("test",8,5,$bits);
72 #$obj->configure(-cursor => "test");
73  
74
75 0 my $file = 'foo';
76 0 ▶ open(my $fh ,"> $file") || die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "> $file" or die $! 0 0 0
77 0 print $fh
78 "#define t_cur_width 1\n".
79 "#define t_cur_height 1\n".
80 "#define t_cur_x_hot 0\n".
81 "#define t_cur_y_hot 0\n".
82 "static unsigned char t_cur_bits[] = { 0x00};\n";
83 0 close $fh;
84 0 $orig_curse = ($obj->configure(
85 -cursor => ['@'.$file,$file,qw/cyan cyan/]
86 ))[3];
87 0 unlink $file;
88 }
89  
90 0 return 1;
91 }
92  
93 #==============================================================================#
94  
95 =item $widget->showCursor();
96  
97 Show the cursor again (should return to the previous specified cursor - if
98 any)
99  
100 =cut
101  
102 0 ▶sub showCursor {
Subroutine showCursor: not called CC=2 SCAR=17.9
103 0 my ($obj) = @_;
104  
105 0 ▶ if ($^O =~ /Win32/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /Win32/) { } 0 0 0
106 0 $win32_curse->Call(1);
107 } else {
108 0 $obj->configure(-cursor => $orig_curse);
109 }
110 }
111  
112 #==============================================================================#
113  
114 =back
115  
116 =head1 BUGS
117  
118 Under Win32, Tk cursor handling is (currently) very basic. Hiding is
119 achieved using the Win32::API. This has the limitation that the cursor
120 is hidden for all widgets, not just the specified one.
121  
122 =head1 AUTHOR
123  
124 This module is Copyright (c) 2002 Gavin Brock gbrock@cpan.org. All rights
125 reserved. This program is free software; you can redistribute it and/or
126 modify it under the same terms as Perl itself.
127  
128 =head1 SEE ALSO
129  
130 L<Tk>
131  
132 L<Win32::API>
133  
134 =cut
135  
136 # That's all folks..
137 #==============================================================================#
138 2 1;
↑ Summary