summaryrefslogtreecommitdiff
path: root/framework
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
parentc6cf2568bd186fe46dea6aeefec17e046a595b52 (diff)
Added getAllowChildControls and TEmptyControlList.
Diffstat (limited to 'framework')
-rw-r--r--framework/Exceptions/messages.txt2
-rw-r--r--framework/Web/UI/TControl.php70
-rw-r--r--framework/Web/UI/TTemplateManager.php12
3 files changed, 75 insertions, 9 deletions
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index b4a91adb..ebe645e8 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -145,6 +145,8 @@ control_id_nonunique = %s.ID '%s' is not unique among all controls under the
controllist_control_required = TControlList can only accept strings or TControl objects.
+emptycontrollist_addition_disallowed = Child controls are not allowed.
+
webcontrol_accesskey_invalid = %s.AccessKey '%s' is invalid. It must be a single character only.
webcontrol_style_invalid = %s.Style must take string value only.
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.
*
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]);
}
}