1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
# Copyright (c) 1995-1999 Nick Ing-Simmons. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Tk::Clipboard;
use strict;
use vars qw($VERSION);
$VERSION = '3.016'; # $Id: //depot/Tk8/Tk/Clipboard.pm#16 $
use AutoLoader qw(AUTOLOAD);
use Tk qw(catch);
sub clipEvents
{
return qw[Copy Cut Paste];
}
sub ClassInit
{
my ($class,$mw) = @_;
foreach my $op ($class->clipEvents)
{
$mw->Tk::bind($class,"<<$op>>","clipboard$op");
}
return $class;
}
sub clipboardSet
{
my $w = shift;
$w->clipboardClear;
$w->clipboardAppend(@_);
}
sub clipboardCopy
{
my $w = shift;
my $val = $w->getSelected;
if (defined $val)
{
$w->clipboardSet('--',$val);
}
return $val;
}
sub clipboardCut
{
my $w = shift;
my $val = $w->clipboardCopy;
if (defined $val)
{
$w->deleteSelected;
}
return $val;
}
sub clipboardGet
{
my $w = shift;
$w->SelectionGet('-selection','CLIPBOARD',@_);
}
sub clipboardPaste
{
my $w = shift;
local $@;
catch { $w->insert('insert',$w->clipboardGet)};
}
sub clipboardOperations
{
my @class = ();
my $mw = shift;
if (ref $mw)
{
$mw = $mw->DelegateFor('bind');
}
else
{
push(@class,$mw);
$mw = shift;
}
while (@_)
{
my $op = shift;
$mw->Tk::bind(@class,"<<$op>>","clipboard$op");
}
}
# These methods work for Entry and Text
# and can be overridden where they don't work
sub deleteSelected
{
my $w = shift;
catch { $w->delete('sel.first','sel.last') };
}
1;
__END__
sub getSelected
{
my $w = shift;
my $val = Tk::catch { $w->get('sel.first','sel.last') };
return $val;
}
|