summaryrefslogtreecommitdiff
path: root/framework/Web/UI/TControl.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/TControl.php')
-rw-r--r--framework/Web/UI/TControl.php70
1 files changed, 69 insertions, 1 deletions
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,11 +407,21 @@ 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
* and all its ancestors are visible.
@@ -883,6 +893,14 @@ class TControl extends TComponent
}
/**
+ * @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
* and has its properties initialized according to template configurations.
@@ -1530,6 +1548,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 <qiang.xue@gmail.com>
+ * @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.
*