diff options
author | xue <> | 2006-05-04 19:57:16 +0000 |
---|---|---|
committer | xue <> | 2006-05-04 19:57:16 +0000 |
commit | 05b69a565ebf001f42fdb6558f204bf3f1a9b61a (patch) | |
tree | 78d4149cf7b6bf80bad0ced5710617ffad4e0597 | |
parent | eb93f8a2fd9f701106310a93bc6e491ec2dfa3fe (diff) |
Added TCompositeControl.
-rw-r--r-- | .gitattributes | 1 | ||||
-rw-r--r-- | HISTORY | 1 | ||||
-rw-r--r-- | demos/quickstart/protected/pages/Controls/NewControl.page | 6 | ||||
-rw-r--r-- | demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php | 2 | ||||
-rw-r--r-- | framework/Web/UI/TCompositeControl.php | 39 | ||||
-rw-r--r-- | framework/Web/UI/TPage.php | 1 | ||||
-rw-r--r-- | framework/Web/UI/TTemplateControl.php | 7 |
7 files changed, 52 insertions, 5 deletions
diff --git a/.gitattributes b/.gitattributes index fefa71e7..f07f9c3e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -753,6 +753,7 @@ framework/Web/THttpResponse.php -text framework/Web/THttpSession.php -text framework/Web/THttpUtility.php -text framework/Web/UI/TClientScriptManager.php -text +framework/Web/UI/TCompositeControl.php -text framework/Web/UI/TControl.php -text framework/Web/UI/TControlAdapter.php -text framework/Web/UI/TForm.php -text @@ -7,6 +7,7 @@ CHG: Ticket#153 - TAssetManager now ignores .svn directories (Qiang) CHG: Ticket#154 - HTML comments are now parsed as regular template strings (Qiang)
CHG: Ticket#151 - URL format is modified to handle empty GET values (Qiang)
NEW: TTableHeaderRow, TTableFooterRow and table section support (Qiang)
+NEW: TCompositeControl (Qiang)
Version 3.0.0 May 1, 2006
=========================
diff --git a/demos/quickstart/protected/pages/Controls/NewControl.page b/demos/quickstart/protected/pages/Controls/NewControl.page index 61209b6b..51d0cc02 100644 --- a/demos/quickstart/protected/pages/Controls/NewControl.page +++ b/demos/quickstart/protected/pages/Controls/NewControl.page @@ -13,7 +13,7 @@ In general, there are two ways of writing new controls: composition of existing Composition is the easiest way of creating new controls. It mainly involves instantiating existing controls, configuring them and making them the constituent components. The properties of the constituent components are exposed through <a href="?page=Fundamentals.Components">subproperties</a>.
</p>
<p>
-One can compose a new control in two ways. One is to override the <tt>TControl::createChildControls()</tt> method. The other is to extend <tt>TTemplateControl</tt> (or its child classes) and write a control template. The latter is easier to use and can organize the layout constituent compoents more intuitively, while the former is more efficient because it does not require parsing of the template.
+One can compose a new control in two ways. One is to extend <tt>TCompositeControl</tt> and override the <tt>TControl::createChildControls()</tt> method. The other is to extend <tt>TTemplateControl</tt> (or its child classes) and write a control template. The latter is easier to use and can organize the layout constituent compoents more intuitively, while the former is more efficient because it does not require parsing of the template.
</p>
<p>
As an example, we show how to create a labeled textbox called <tt>LabeledTextBox</tt> using the above two approaches. A labeled textbox displays a label besides a textbox. We want reuse the PRADO provided <tt>TLabel</tt> and <tt>TTextBox</tt> to accomplish this task.
@@ -48,13 +48,13 @@ In the above, the method call to <tt>ensureChildControls()</tt> ensures that bot <h3>Composition by Overriding <tt>createChildControls()</tt></h3>
<p>
-For a composite control as simple as <tt>LabeledTextBox</tt>, it is better to create it by extending <tt>TControl</tt> and overriding the <tt>createChildControls()</tt> method, because it does not use templates and thus saves template parsing time. Note, the new control class must implement the <tt>INamingContainer</tt> interface to ensure the global uniqueness of the ID of its constituent controls.
+For a composite control as simple as <tt>LabeledTextBox</tt>, it is better to create it by extending <tt>TCompositeControl</tt> and overriding the <tt>createChildControls()</tt> method, because it does not use templates and thus saves template parsing time.
</p>
<p>
Complete code for <tt>LabeledTextBox</tt> is shown as follows,
</p>
<com:TTextHighlighter CssClass="source">
-class LabeledTextBox extends TControl implements INamingContainer {
+class LabeledTextBox extends TCompositeControl {
private $_label;
private $_textbox;
protected function createChildControls() {
diff --git a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php index 4b8ac2c2..5bbf4ce2 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php +++ b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php @@ -1,6 +1,6 @@ <?php
-class LabeledTextBox extends TControl implements INamingContainer
+class LabeledTextBox extends TCompositeControl
{
private $_label;
private $_textbox;
diff --git a/framework/Web/UI/TCompositeControl.php b/framework/Web/UI/TCompositeControl.php new file mode 100644 index 00000000..4e33bb83 --- /dev/null +++ b/framework/Web/UI/TCompositeControl.php @@ -0,0 +1,39 @@ +<?php
+/**
+ * TCompositeControl class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ */
+
+/**
+ * TCompositeControl class.
+ * TCompositeControl is the base class for controls that are composed
+ * by other controls.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.0
+ */
+class TCompositeControl extends TControl implements INamingContainer
+{
+ /**
+ * Performs the OnInit step for the control and all its child controls.
+ * This method overrides the parent implementation
+ * by ensuring child controls are created first.
+ * Only framework developers should use this method.
+ * @param TControl the naming container control
+ */
+ protected function initRecursive($namingContainer=null)
+ {
+ $this->ensureChildControls();
+ parent::initRecursive($namingContainer);
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index b68c4996..3f98b340 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -13,6 +13,7 @@ Prado::using('System.Web.UI.WebControls.*');
Prado::using('System.Web.UI.TControl');
Prado::using('System.Web.UI.WebControls.TWebControl');
+Prado::using('System.Web.UI.TCompositeControl');
Prado::using('System.Web.UI.TTemplateControl');
Prado::using('System.Web.UI.TForm');
Prado::using('System.Web.UI.TClientScriptManager');
diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php index f18678f1..0595a9e5 100644 --- a/framework/Web/UI/TTemplateControl.php +++ b/framework/Web/UI/TTemplateControl.php @@ -11,6 +11,11 @@ */
/**
+ * Includes TCompositeControl class
+ */
+Prado::using('System.Web.UI.TCompositeControl');
+
+/**
* TTemplateControl class.
* TTemplateControl is the base class for all controls that use templates.
* By default, a control template is assumed to be in a file under the same
@@ -22,7 +27,7 @@ * @package System.Web.UI
* @since 3.0
*/
-class TTemplateControl extends TControl implements INamingContainer
+class TTemplateControl extends TCompositeControl
{
/**
* template file extension.
|