# Copyright (c) 1999-2009 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: ClearDot.pm,v 2.6 2009/12/14 03:26:34 nagler Exp $ package Bivio::UI::HTML::Widget::ClearDot; use strict; use Bivio::Base 'HTMLWidget.Tag'; # C displays the clear dot # # # A widget value of zero (0) will result in nothing being rendered, # i.e. zero means "doesn't exist". # # # align : string [] # # How to align the image. The allowed (case # insensitive) values are defined in # L. # The value affects the C and C attributes of the C tag. # # height : int [1] # # height : array_ref [] # # The (constant) height of the dot. # # width : int [1] # # width : array_ref [] # # The (constant) width of the dot. our($VERSION) = sprintf('%d.%02d', q$Revision: 2.6 $ =~ /\d+/g); my($_IDI) = __PACKAGE__->instance_data_index; my($_I) = b_use('FacadeComponent.Icon'); my($_R) = b_use('Agent.Request'); sub NEW_ARGS { return [qw(?width ?height ?class)]; } sub as_html { my($self, $width, $height) = @_; if (@_ > 1) { $self = $self->new($width, $height); } elsif (!ref($self)) { b_die('must pass width and height if called statically'); } $self->initialize_with_parent(parent => undef); my($b) = ''; $self->render($_R->get_current, \$b); return $b; } sub initialize { my($self) = @_; $self->put_unless_exists( tag => 'img', ALT => 'dot', class => 'b_clear_dot', SRC => $_I->get_clear_dot->{uri}, _dims($self), ); return shift->SUPER::initialize(@_); } sub _dims { my($self) = @_; return ( WIDTH => $self->unsafe_get('width'), HEIGHT => $self->unsafe_get('height'), ) unless ref($self->unsafe_get('width')) || ref($self->unsafe_get('height')); return ( STYLE => [sub { my($source) = @_; my($res) = ''; foreach my $k (qw(height width)) { if (length(my $v = $self->render_simple_attr($k, $source))) { $v .= 'px' unless $v =~ /\D/; $res .= "$k: $v;" } } return $res; }], ); } 1;