summaryrefslogtreecommitdiff
path: root/framework/Web/UI/TControl.php
diff options
context:
space:
mode:
authorxue <>2006-02-12 05:15:18 +0000
committerxue <>2006-02-12 05:15:18 +0000
commit0b300b68cf9fde397c00abdc21917ac24aa042f0 (patch)
tree7d4d10aa051d3a5f832b4298d9278fce140e067d /framework/Web/UI/TControl.php
parentc6cf2568bd186fe46dea6aeefec17e046a595b52 (diff)
Added getAllowChildControls and TEmptyControlList.
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.
*