From 55c4ac1bfe565f1ca7f537fdd8b7a201be28e581 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 10 Nov 2005 12:47:19 +0000 Subject: Initial import of prado framework --- framework/Web/UI/WebControls/TLabel.php | 106 ++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 framework/Web/UI/WebControls/TLabel.php (limited to 'framework/Web/UI/WebControls/TLabel.php') diff --git a/framework/Web/UI/WebControls/TLabel.php b/framework/Web/UI/WebControls/TLabel.php new file mode 100644 index 00000000..464a4cd7 --- /dev/null +++ b/framework/Web/UI/WebControls/TLabel.php @@ -0,0 +1,106 @@ + + * @link http://www.xisc.com/ + * @copyright Copyright © 2004-2005, Qiang Xue + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TLabel class + * + * TLabel represents a label control that displays text on a Web pagge. + * Use Text property to set the text to be displayed. + * TLabel will render the contents enclosed within its component tag + * if Text is empty. + * To use TLabel as a form label, associate it with a control by setting the + * AssociateControlID property. The associated control must be locatable + * within the label's naming container. + * + * Note, Text will NOT be encoded for rendering. + * Make usre it does not contain dangerous characters that you want to avoid. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TLabel extends TWebControl +{ + /** + * @return string tag name of the label, returns 'label' if there is an associated control, 'span' otherwise. + */ + protected function getTagName() + { + return ($this->getAssociatedControlID()==='')?'span':'label'; + } + + /** + * Adds attributes to renderer. + * @param THtmlTextWriter the renderer + * @throws TInvalidDataValueException if associated control cannot be found using the ID + */ + protected function addAttributesToRender($writer) + { + if(($aid=$this->getAssociatedControlID())!=='') + { + if($control=$this->findControl($aid)) + $writer->addAttribute('for',$control->getClientID()); + else + throw new TInvalidDataValueException('control_not_found',$aid); + } + parent::addAttributesToRender($writer); + } + + /** + * Renders the body content of the label. + * @param THtmlTextWriter the renderer + */ + protected function renderContents($writer) + { + if(($text=$this->getText())==='') + parent::renderContents($writer); + else + $writer->write($text); + } + + /** + * @return string the text value of the label + */ + public function getText() + { + return $this->getViewState('Text',''); + } + + /** + * @param string the text value of the label + */ + public function setText($value) + { + $this->setViewState('Text',$value,''); + } + + /** + * @return string the associated control ID + */ + public function getAssociatedControlID() + { + return $this->getViewState('AssociatedControlID',''); + } + + /** + * Sets the ID of the control that the label is associated with. + * The control must be locatable via {@link TControl::findControl} using the ID. + * @param string the associated control ID + */ + public function setAssociatedControlID($value) + { + $this->setViewState('AssociatedControlID',$value,''); + } +} + +?> \ No newline at end of file -- cgit v1.2.3