# Copyright (c) 2001-2011 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: ControlBase.pm,v 2.9 2011/02/22 00:20:27 nagler Exp $ package Bivio::UI::Widget::ControlBase; use strict; use Bivio::Base 'UI.Widget'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.9 $ =~ /\d+/g); my($_TI) = b_use('Agent.TaskId'); my($_A) = b_use('IO.Alert'); sub control_off_render { my($self, $source, $buffer) = @_; $self->unsafe_render_attr(control_off_value => $source, $buffer); return; } sub initialize { my($self) = @_; if (defined(my $c = $self->unsafe_get('control'))) { unless (ref($c)) { if ($c =~ /^[a-z_0-9]{3,}$/ and $_TI->is_valid_name(uc($c)) ) { $_A->warn_deprecated( $c, ': change task name to upper case'); $c = uc($c); } $c = $_TI->from_name($c) if $_TI->is_valid_name($c); } $self->put(control => [['->req'], '->can_user_execute_task', $c]) if $_TI->is_blessed($c); } $self->map_invoke( unsafe_initialize_attr => [qw(control control_off_value)], ); return; } sub is_control_on { my($self, $source) = @_; my($c) = $self->unsafe_get('control'); return !defined($c) || ($c = $self->unsafe_resolve_widget_value($c, $source)) && (!$self->is_blessed($c, 'Bivio::UI::Widget') || $self->render_simple_value($c, $source)) ? 1 : 0; } sub render { my($self, $source, $buffer) = @_; my($method) = $self->is_control_on($source) ? 'control_on_render' : 'control_off_render'; return $self->$method($source, $buffer); } 1;