From 0b300b68cf9fde397c00abdc21917ac24aa042f0 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 12 Feb 2006 05:15:18 +0000 Subject: Added getAllowChildControls and TEmptyControlList. --- framework/Web/UI/TControl.php | 70 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'framework/Web/UI/TControl.php') diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index 80956312..660b1c4c 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -407,10 +407,20 @@ class TControl extends TComponent public function getControls() { if(!isset($this->_rf[self::RF_CONTROLS])) - $this->_rf[self::RF_CONTROLS]=new TControlList($this); + $this->_rf[self::RF_CONTROLS]=$this->createControlCollection(); return $this->_rf[self::RF_CONTROLS]; } + /** + * Creates a control collection object that is to be used to hold child controls + * @return TControlList control collection + * @see getControls + */ + protected function createControlCollection() + { + return $this->getAllowChildControls()?new TControlList($this):new TEmptyControlList($this); + } + /** * Checks if a control is visible. * If parent check is required, then a control is visible only if the control @@ -882,6 +892,14 @@ class TControl extends TComponent return isset($this->_rf[self::RF_NAMED_OBJECTS][$name])?$this->_rf[self::RF_NAMED_OBJECTS][$name]:null; } + /** + * @return boolean whether body contents are allowed for this control. Defaults to true. + */ + public function getAllowChildControls() + { + return true; + } + /** * This method is invoked after the control is instantiated by a template. * When this method is invoked, the control should have a valid TemplateControl @@ -1529,6 +1547,56 @@ class TControlList extends TList } } +/** + * TEmptyControlList class + * + * TEmptyControlList implements an empty control list that prohibits adding + * controls to it. This is useful for controls that do not allow child controls. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI + * @since 3.0 + */ +class TEmptyControlList extends TList +{ + /** + * the control that owns this collection. + * @var TControl + */ + private $_o; + + /** + * Constructor. + * @param TControl the control that owns this collection. + */ + public function __construct(TControl $owner) + { + parent::__construct(); + $this->_o=$owner; + } + + /** + * @return TControl the control that owns this collection. + */ + protected function getOwner() + { + return $this->_o; + } + + /** + * Inserts an item at the specified position. + * Calling this method will always throw an exception. + * @param integer the speicified position. + * @param mixed new item + * @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl. + */ + public function insertAt($index,$item) + { + throw new TNotSupportedException('emptycontrollist_addition_disallowed'); + } +} + /** * INamingContainer interface. * INamingContainer marks a control as a naming container. -- cgit v1.2.3