From d653bda6c6217f160a4de77e3f2f0ee62096be67 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 15 Feb 2006 05:30:58 +0000 Subject: Added TControlAdapter and TWebControlAdapter and their support in TControl and TWebControl. --- framework/Web/UI/TControl.php | 73 +++++++++-- framework/Web/UI/TControlAdapter.php | 144 +++++++++++++++++++++ framework/Web/UI/WebControls/TWebControl.php | 3 +- .../Web/UI/WebControls/TWebControlAdapter.php | 72 +++++++++++ 4 files changed, 281 insertions(+), 11 deletions(-) create mode 100644 framework/Web/UI/TControlAdapter.php create mode 100644 framework/Web/UI/WebControls/TWebControlAdapter.php (limited to 'framework/Web') 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 @@ -187,6 +188,30 @@ class TControl extends TComponent return parent::__get($name); } + /** + * @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 */ @@ -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->_stageonLoad(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 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 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 + * @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 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 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 + * @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 -- cgit v1.2.3