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 ++++++++++++++++++++++++++++++++++- framework/Web/UI/TTemplateManager.php | 12 ++---- 2 files changed, 73 insertions(+), 9 deletions(-) (limited to 'framework/Web') 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. diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index 45884f02..abeb7466 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -252,6 +252,9 @@ class TTemplate extends TComponent implements ITemplate $controls=array(); foreach($this->_tpl as $key=>$object) { + $parent=isset($controls[$object[0]])?$controls[$object[0]]:$tplControl; + if(!$parent->getAllowChildControls()) + continue; if(isset($object[2])) // component { $component=Prado::createComponent($object[1]); @@ -270,7 +273,6 @@ class TTemplate extends TComponent implements ITemplate // apply attributes foreach($object[2] as $name=>$value) $this->configureControl($component,$name,$value); - $parent=isset($controls[$object[0]])?$controls[$object[0]]:$tplControl; $component->createdOnTemplate($parent); } else if($component instanceof TComponent) @@ -283,17 +285,11 @@ class TTemplate extends TComponent implements ITemplate } foreach($object[2] as $name=>$value) $this->configureComponent($component,$name,$value); - $parent=isset($controls[$object[0]])?$controls[$object[0]]:$tplControl; $parent->addParsedObject($component); } } else // string - { - if(isset($controls[$object[0]])) - $controls[$object[0]]->addParsedObject($object[1]); - else - $tplControl->addParsedObject($object[1]); - } + $parent->addParsedObject($object[1]); } } -- cgit v1.2.3