package ATR::Tk::UpdateFieldEntry;

use strict;
use warnings;
use base  qw(ATR::Tk::UpdateField Tk::Entry);
Tk::Widget->Construct('UFEntry');

=head1 NAME

ATR::Tk::UpdateFieldEntry - data-tracking text widget

=head1 DESCRIPTION

=cut

# $Id: UpdateFieldEntry.pm,v 1.6 2005/02/28 00:08:57 mca Exp $

#----------------------------------------------------------------------------

sub accessorsChanged {
    my $self = shift;
    $self->bindFocusHighlight;
    my $readWrite = $self->data->canSave;
    $self->bindEntryKeystrokes($readWrite);
    $self->configure(-normalcolour => $readWrite ? 'white' : 'LightGrey');
}

sub atrPopulatePost {
    my ($self, $args) = @_;

    # No idea why the default for this is not adequate: same problem
    # as SITk::Status, UpdateFieldButton, UpdateFieldEntry
    $self->ConfigSpecs(-foreground => [ 'SELF', 'Foreground', 'foreground', 'black']);

    $self->SUPER::atrPopulatePost($args);
}

sub set {
    my ($self, $text) = @_;
    $self->delete(0, 'end');
    $self->insert(0, $text);
    $self->icursor('end');

    # Updating the text variable is important, because if widget type
    # changes we're going to be blown away and recreated; may not be
    # told what the GUI value is supposed to be.
# XXX: need hooks to keep editted value saved in the textvariable
    my $tv = $self->cget('-textvariable');
    $$tv = $text if $tv;
}


1;
