summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2006-02-15 05:30:58 +0000
committerxue <>2006-02-15 05:30:58 +0000
commitd653bda6c6217f160a4de77e3f2f0ee62096be67 (patch)
tree782018a54c25c0266f12528e5b18e9db71f9ae5b /framework
parent2b194248b9bbd75887c1d5f991dca1f3fd441dd5 (diff)
Added TControlAdapter and TWebControlAdapter and their support in TControl and TWebControl.
Diffstat (limited to 'framework')
-rw-r--r--framework/Web/UI/TControl.php73
-rw-r--r--framework/Web/UI/TControlAdapter.php144
-rw-r--r--framework/Web/UI/WebControls/TWebControl.php3
-rw-r--r--framework/Web/UI/WebControls/TWebControlAdapter.php72
4 files changed, 281 insertions, 11 deletions
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 6fd25f76..49ba629f 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -11,9 +11,10 @@
*/
/**
- * Includes TAttributeCollection class
+ * Includes TAttributeCollection and TControlAdapter class
*/
Prado::using('System.Collections.TAttributeCollection');
+Prado::using('System.Web.UI.TControlAdapter');
/**
* TControl class
@@ -120,6 +121,7 @@ class TControl extends TComponent
const RF_EVENTS=6; // event handlers
const RF_CONTROLSTATE=7; // controlstate
const RF_NAMED_OBJECTS=8; // controls declared with ID on template
+ const RF_ADAPTER=9; // adapter
/**
* @var string control ID
@@ -162,7 +164,6 @@ class TControl extends TComponent
*/
private $_rf=array();
-
/**
* Returns a property value by name or a control by ID.
* This overrides the parent implementation by allowing accessing
@@ -188,6 +189,30 @@ class TControl extends TComponent
}
/**
+ * @return boolean whether there is an adapter for this control
+ */
+ public function getHasAdapter()
+ {
+ return isset($this->_rf[self::RF_ADAPTER]);
+ }
+
+ /**
+ * @return TControlAdapter control adapter. Null if not exists.
+ */
+ public function getAdapter()
+ {
+ return isset($this->_rf[self::RF_ADAPTER])?$this->_rf[self::RF_ADAPTER]:null;
+ }
+
+ /**
+ * @param TControlAdapter control adapter
+ */
+ public function setAdapter(TControlAdapter $adapter)
+ {
+ $this->_rf[self::RF_ADAPTER]=$adapter;
+ }
+
+ /**
* @return TControl the parent of this control
*/
public function getParent()
@@ -773,7 +798,10 @@ class TControl extends TComponent
try
{
$this->_flags |= self::IS_CREATING_CHILD;
- $this->createChildControls();
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->createChildControls();
+ else
+ $this->createChildControls();
$this->_flags &= ~self::IS_CREATING_CHILD;
$this->_flags |= self::IS_CHILD_CREATED;
}
@@ -1068,7 +1096,10 @@ class TControl extends TComponent
$page->applyControlSkin($this);
$this->_flags |= self::IS_SKIN_APPLIED;
}
- $this->onInit(null);
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->onInit(null);
+ else
+ $this->onInit(null);
$this->_stage=self::CS_INITIALIZED;
}
}
@@ -1080,7 +1111,12 @@ class TControl extends TComponent
protected function loadRecursive()
{
if($this->_stage<self::CS_LOADED)
- $this->onLoad(null);
+ {
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->onLoad(null);
+ else
+ $this->onLoad(null);
+ }
if($this->getHasControls())
{
foreach($this->_rf[self::RF_CONTROLS] as $control)
@@ -1100,7 +1136,10 @@ class TControl extends TComponent
if($this->getVisible(false))
{
$this->ensureChildControls();
- $this->onPreRender(null);
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->onPreRender(null);
+ else
+ $this->onPreRender(null);
if($this->getHasControls())
{
foreach($this->_rf[self::RF_CONTROLS] as $control)
@@ -1125,7 +1164,10 @@ class TControl extends TComponent
if($control instanceof TControl)
$control->unloadRecursive();
}
- $this->onUnload(null);
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->onUnload(null);
+ else
+ $this->onUnload(null);
}
/**
@@ -1297,7 +1339,12 @@ class TControl extends TComponent
public function renderControl($writer)
{
if($this->getVisible(false))
- $this->render($writer);
+ {
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->render($writer);
+ else
+ $this->render($writer);
+ }
}
/**
@@ -1402,7 +1449,10 @@ class TControl extends TComponent
}
else
$this->_stage=self::CS_STATE_LOADED;
- $this->loadState();
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->loadState(null);
+ else
+ $this->loadState();
}
/**
@@ -1412,7 +1462,10 @@ class TControl extends TComponent
*/
final protected function &saveStateRecursive($needViewState=true)
{
- $this->saveState();
+ if(isset($this->_rf[self::RF_ADAPTER]))
+ $this->_rf[self::RF_ADAPTER]->saveState(null);
+ else
+ $this->saveState();
$needViewState=($needViewState && !($this->_flags & self::IS_DISABLE_VIEWSTATE));
$state=array();
if($this->getHasControls())
diff --git a/framework/Web/UI/TControlAdapter.php b/framework/Web/UI/TControlAdapter.php
new file mode 100644
index 00000000..f0663966
--- /dev/null
+++ b/framework/Web/UI/TControlAdapter.php
@@ -0,0 +1,144 @@
+<?php
+/**
+ * TControlAdapter class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ */
+
+/**
+ * TControlAdapter class
+ *
+ * TControlAdapter is the base class for adapters that customize
+ * various behaviors for the control to which the adapter is attached.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TControlAdapter extends TComponent
+{
+ /**
+ * @var TControl the control to which the adapter is attached
+ */
+ private $_control;
+
+ /**
+ * Constructor.
+ * @param TControl the control to which the adapter is attached
+ */
+ public function __construct($control)
+ {
+ $this->_control=$control;
+ }
+
+ /**
+ * @return TControl the control to which this adapter is attached
+ */
+ public function getControl()
+ {
+ return $this->_control;
+ }
+
+ /**
+ * @return TPage the page that contains the attached control
+ */
+ public function getPage()
+ {
+ return $this->_control?$this->_control->getPage():null;
+ }
+
+ /**
+ * Creates child controls for the attached control.
+ * Default implementation calls the attached control's corresponding method.
+ */
+ public function createChildControls()
+ {
+ $this->_control->createChildControls();
+ }
+
+ /**
+ * Loads additional persistent control state.
+ * Default implementation calls the attached control's corresponding method.
+ */
+ public function loadState()
+ {
+ $this->_control->loadState();
+ }
+
+ /**
+ * Saves additional persistent control state.
+ * Default implementation calls the attached control's corresponding method.
+ */
+ public function saveState()
+ {
+ $this->_control->saveState();
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnInit' stage.
+ * Default implementation calls the attached control's corresponding method.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onInit($param)
+ {
+ $this->_control->onInit($param);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnLoad' stage.
+ * Default implementation calls the attached control's corresponding method.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onLoad($param)
+ {
+ $this->_control->onLoad($param);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnPreRender' stage.
+ * Default implementation calls the attached control's corresponding method.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onPreRender($param)
+ {
+ $this->_control->onPreRender($param);
+ }
+
+ /**
+ * This method is invoked when the control enters 'OnUnload' stage.
+ * Default implementation calls the attached control's corresponding method.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ public function onUnload($param)
+ {
+ $this->_control->onUnload($param);
+ }
+
+ /**
+ * This method is invoked when the control renders itself.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function render($writer)
+ {
+ $this->_control->render($writer);
+ }
+
+ /**
+ * Renders the control's children.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderChildren($writer)
+ {
+ $this->_control->renderChildren($writer);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TWebControl.php b/framework/Web/UI/WebControls/TWebControl.php
index 18571d73..f302932d 100644
--- a/framework/Web/UI/WebControls/TWebControl.php
+++ b/framework/Web/UI/WebControls/TWebControl.php
@@ -11,9 +11,10 @@
*/
/**
- * Includes TStyle definition
+ * Includes TStyle and TWebAdapter definition
*/
Prado::using('System.Web.UI.WebControls.TStyle');
+Prado::using('System.Web.UI.WebControls.TWebAdapter');
/**
* TWebControl class
diff --git a/framework/Web/UI/WebControls/TWebControlAdapter.php b/framework/Web/UI/WebControls/TWebControlAdapter.php
new file mode 100644
index 00000000..23205bba
--- /dev/null
+++ b/framework/Web/UI/WebControls/TWebControlAdapter.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * TWebControlAdapter class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TWebControlAdapter class
+ *
+ * TWebControlAdapter is the base class for adapters that customize
+ * rendering for the Web control to which the adapter is attached.
+ * It may be used to modify the default markup or behavior for specific
+ * browsers.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TWebControlAdapter extends TControlAdapter
+{
+ /**
+ * Renders the control to which the adapter is attached.
+ * It calls {@link renderBeginTag}, {@link renderContents} and
+ * {@link renderEndTag} in order.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function render($writer)
+ {
+ $this->renderBeginTag($writer);
+ $this->renderContents($writer);
+ $this->renderEndTag($writer);
+ }
+
+ /**
+ * Renders the openning tag for the attached control.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderBeginTag($writer)
+ {
+ $this->getControl()->renderBeginTag($writer);
+ }
+
+ /**
+ * Renders the body contents within the attached control tag.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderContents($writer)
+ {
+ $this->getControl()->renderContents($writer);
+ }
+
+ /**
+ * Renders the closing tag for the attached control.
+ * Default implementation calls the attached control's corresponding method.
+ * @param THtmlWriter writer for the rendering purpose
+ */
+ public function renderEndTag($writer)
+ {
+ $this->getControl()->renderEndTag($writer);
+ }
+}
+
+?> \ No newline at end of file