| 1 |
package Tk::ColorDialog; |
| 2 |
require Tk::Toplevel; |
| 3 |
use base qw(Tk::Toplevel); |
| 4 |
|
| 5 |
use vars qw($VERSION); |
| 6 |
$VERSION = '4.014'; |
| 7 |
|
| 8 |
Construct Tk::Widget 'ColorDialog'; |
| 9 |
|
| 10 |
sub Accept |
| 11 |
{ |
| 12 |
my $cw = shift; |
| 13 |
$cw->withdraw; |
| 14 |
$cw->{'done'} = 1; |
| 15 |
} |
| 16 |
|
| 17 |
sub Cancel |
| 18 |
{ |
| 19 |
my $cw = shift; |
| 20 |
# $cw->configure(-color => undef); |
| 21 |
$cw->configure(-color => 'cancel'); |
| 22 |
$cw->Accept; |
| 23 |
} |
| 24 |
|
| 25 |
sub Populate |
| 26 |
{ |
| 27 |
my ($cw,$args) = @_; |
| 28 |
$cw->SUPER::Populate($args); |
| 29 |
$cw->protocol('WM_DELETE_WINDOW' => [ 'Cancel' => $cw ]); |
| 30 |
$cw->transient($cw->Parent->toplevel); |
| 31 |
$cw->withdraw; |
| 32 |
my $sel = $cw->ColorSelect; |
| 33 |
my $accept = $cw->Button(-text => 'Accept', -command => ['Accept', $cw]); |
| 34 |
my $cancel = $cw->Button(-text => 'Cancel', -command => ['Cancel', $cw]); |
| 35 |
Tk::grid($sel); |
| 36 |
Tk::grid($accept,$cancel); |
| 37 |
$cw->ConfigSpecs(DEFAULT => [$sel]); |
| 38 |
} |
| 39 |
|
| 40 |
sub Show |
| 41 |
{ |
| 42 |
my $cw = shift; |
| 43 |
$cw->configure(@_) if @_; |
| 44 |
$cw->Popup(); |
| 45 |
$cw->OnDestroy(sub { $cw->{'done'} = 0 }); # auto-cancel |
| 46 |
$cw->waitVariable(\$cw->{'done'}); |
| 47 |
if (Tk::Exists($cw)) |
| 48 |
{ |
| 49 |
$cw->withdraw; |
| 50 |
$cw->cget('-color'); |
| 51 |
} |
| 52 |
else |
| 53 |
{ |
| 54 |
undef; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
1; |