From 4d8ed423f7b4a8eae2898cc5552829595717a581 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Mon, 2 Jan 2006 20:59:17 +0000
Subject: TCheckBoxList and TRadioButtonList completed.
---
.gitattributes | 2 +
.../quickstart/protected/pages/Controls/List.page | 1 +
.../pages/Controls/Samples/TCheckBoxList/Home.page | 105 +++++++++++++++-
.../pages/Controls/Samples/TCheckBoxList/Home.php | 34 ++----
.../pages/Controls/Samples/TDropDownList/Home.php | 24 ++--
.../pages/Controls/Samples/TListBox/Home.page | 16 +--
.../Controls/Samples/TRadioButtonList/Home.page | 132 +++++++++++++++++++++
.../Controls/Samples/TRadioButtonList/Home.php | 22 ++++
framework/Exceptions/messages.txt | 5 +-
framework/Web/UI/WebControls/TCheckBoxList.php | 49 ++++++--
framework/Web/UI/WebControls/TListControl.php | 4 +-
framework/Web/UI/WebControls/TRadioButtonList.php | 26 +++-
framework/Web/UI/WebControls/TRepeatInfo.php | 1 +
framework/Web/UI/WebControls/TStyle.php | 114 ++++++++++--------
14 files changed, 426 insertions(+), 109 deletions(-)
create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page
create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php
diff --git a/.gitattributes b/.gitattributes
index 53d811fb..b16270db 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -50,6 +50,8 @@ demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TPanel/hello_world.gif -text
+demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page -text
+demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TTable/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TTable/backimage.gif -text
demos/quickstart/protected/pages/Controls/Samples/TTextBox/Home.page -text
diff --git a/demos/quickstart/protected/pages/Controls/List.page b/demos/quickstart/protected/pages/Controls/List.page
index f3c4cd96..f70c4368 100644
--- a/demos/quickstart/protected/pages/Controls/List.page
+++ b/demos/quickstart/protected/pages/Controls/List.page
@@ -21,6 +21,7 @@ List controls covered in this section are all inherit directly or indirectly fro
-Check box list with initial items:
+Check box list with default settings:
|
-
+
@@ -20,15 +20,110 @@ Check box list with initial items:
-Check box list with initial items:
+Check box list with customized cellpadding, cellspacing, color and text alignment:
|
-
+
-
+
+ |
+
+
+
+
+Check box list with vertical (default) repeat direction:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Check box list with horizontal repeat direction:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Check box list with flow layout and vertical (default) repeat direction:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Check box list with flow layout and horizontal repeat direction:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Check box list's behavior upon postback:
+ |
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+Auto postback check box list:
+ |
+
+
+
+
+
+
+
+
|
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php
index 6b1d07e1..3873ca30 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php
+++ b/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php
@@ -2,50 +2,34 @@
class Home extends TPage
{
- public function selectionChanged($sender,$param)
- {
- $index=$sender->SelectedIndex;
- $value=$sender->SelectedValue;
- $text=$sender->SelectedItem->Text;
- $this->SelectionResult->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
- }
-
public function buttonClicked($sender,$param)
{
- $index=$this->ListBox1->SelectedIndex;
- $value=$this->ListBox1->SelectedValue;
- $text=$this->ListBox1->SelectedItem->Text;
- $this->SelectionResult2->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
- }
-
- public function multiSelectionChanged($sender,$param)
- {
- $indices=$sender->SelectedIndices;
+ $indices=$this->CheckBoxList->SelectedIndices;
$result='';
foreach($indices as $index)
{
- $item=$sender->Items[$index];
+ $item=$this->CheckBoxList->Items[$index];
$result.="(Index: $index, Value: $item->Value, Text: $item->Text)\n";
}
if($result==='')
- $this->MultiSelectionResult->Text='Your selection is empty.';
+ $this->SelectionResult->Text='Your selection is empty.';
else
- $this->MultiSelectionResult->Text='Your selection is: '.$result;
+ $this->SelectionResult->Text='Your selection is: '.$result;
}
- public function buttonClicked2($sender,$param)
+ public function selectionChanged($sender,$param)
{
- $indices=$this->ListBox2->SelectedIndices;
+ $indices=$sender->SelectedIndices;
$result='';
foreach($indices as $index)
{
- $item=$this->ListBox2->Items[$index];
+ $item=$sender->Items[$index];
$result.="(Index: $index, Value: $item->Value, Text: $item->Text)\n";
}
if($result==='')
- $this->MultiSelectionResult2->Text='Your selection is empty.';
+ $this->SelectionResult2->Text='Your selection is empty.';
else
- $this->MultiSelectionResult2->Text='Your selection is: '.$result;
+ $this->SelectionResult2->Text='Your selection is: '.$result;
}
}
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php
index 3835d3c3..5dfa3bba 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php
@@ -4,18 +4,26 @@ class Home extends TPage
{
public function selectionChanged($sender,$param)
{
- $index=$sender->SelectedIndex;
- $value=$sender->SelectedValue;
- $text=$sender->SelectedItem->Text;
- $this->SelectionResult->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
+ if(($index=$sender->SelectedIndex)>=0)
+ {
+ $value=$sender->SelectedValue;
+ $text=$sender->SelectedItem->Text;
+ $this->SelectionResult->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
+ }
+ else
+ $this->SelectionResult->Text="Your selection is empty.";
}
public function buttonClicked($sender,$param)
{
- $index=$this->ListBox1->SelectedIndex;
- $value=$this->ListBox1->SelectedValue;
- $text=$this->ListBox1->SelectedItem->Text;
- $this->SelectionResult2->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
+ if(($index=$this->ListBox1->SelectedIndex)>=0)
+ {
+ $value=$this->ListBox1->SelectedValue;
+ $text=$this->ListBox1->SelectedItem->Text;
+ $this->SelectionResult2->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
+ }
+ else
+ $this->SelectionResult2->Text="Your selection is empty.";
}
}
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page
index 28d0dc1a..f6640879 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page
@@ -122,33 +122,33 @@ List box with initial items:
-Auto postback list box:
+List box's behavior upon postback:
|
-
+
-
+
+
+
|
-List box's behavior upon postback:
+Auto postback list box:
|
-
+
-
-
-
+
|
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page
new file mode 100644
index 00000000..95fea89b
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.page
@@ -0,0 +1,132 @@
+
+
+TRadioButtonList Samples
+
+
+
+
+
+Radio button list with default settings:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Radio button list with customized cellpadding, cellspacing, color and text alignment:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Radio button list with vertical (default) repeat direction:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Radio button list with horizontal repeat direction:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Radio button list with flow layout and vertical (default) repeat direction:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Radio button list with flow layout and horizontal repeat direction:
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+Radio button list's behavior upon postback:
+ |
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+Auto postback radio button list:
+ |
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
\ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php
new file mode 100644
index 00000000..47d9b23b
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php
@@ -0,0 +1,22 @@
+RadioButtonList->SelectedIndex;
+ $value=$this->RadioButtonList->SelectedValue;
+ $text=$this->RadioButtonList->SelectedItem->Text;
+ $this->SelectionResult->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
+ }
+
+ public function selectionChanged($sender,$param)
+ {
+ $index=$sender->SelectedIndex;
+ $value=$sender->SelectedValue;
+ $text=$sender->SelectedItem->Text;
+ $this->SelectionResult2->Text="Your selection is (Index: $index, Value: $value, Text: $text).";
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index 8547527f..c260255d 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -146,4 +146,7 @@ hiddenfield_focus_unsupported = THiddenField does not support setting input fo
hiddenfield_theming_unsupported = THiddenField does not support theming.
hiddenfield_skinid_unsupported = THiddenField does not support control skin.
-panel_defaultbutton_invalid = TPanel.DefaultButton '%s' does not refer to an existing button control.
\ No newline at end of file
+panel_defaultbutton_invalid = TPanel.DefaultButton '%s' does not refer to an existing button control.
+
+tablestyle_cellpadding_invalid = TTableStyle.CellPadding must take an integer equal to or greater than -1.
+tablestyle_cellspacing_invalid = TTableStyle.CellSpacing must take an integer equal to or greater than -1.
\ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php
index c4addcdd..f351acba 100644
--- a/framework/Web/UI/WebControls/TCheckBoxList.php
+++ b/framework/Web/UI/WebControls/TCheckBoxList.php
@@ -6,6 +6,7 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont
{
private $_repeatedControl;
private $_isEnabled;
+ private $_changedEventRaised=false;
public function __construct()
{
@@ -154,14 +155,6 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont
$this->getStyle()->setCellPadding($value);
}
- public function loadPostData($key,$values)
- {
- }
-
- public function raisePostDataChangedEvent()
- {
- }
-
public function getHasHeader()
{
return false;
@@ -200,10 +193,50 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont
$this->_repeatedControl->setID("$index");
$this->_repeatedControl->setText($item->getText());
$this->_repeatedControl->setChecked($item->getSelected());
+ $this->_repeatedControl->setAttribute('value',$item->getValue());
$this->_repeatedControl->setEnabled($this->_isEnabled && $item->getEnabled());
$this->_repeatedControl->renderControl($writer);
}
+ public function loadPostData($key,$values)
+ {
+ if($this->getEnabled(true))
+ {
+ $index=(int)substr($key,strlen($this->getUniqueID())+1);
+ $this->ensureDataBound();
+ if($index>=0 && $index<$this->getRepeatedItemCount())
+ {
+ $item=$this->getItems()->itemAt($index);
+ if($item->getEnabled())
+ {
+ $checked=isset($values[$key]);
+ if($item->getSelected()!=$checked)
+ {
+ $item->setSelected($checked);
+ if(!$this->_changedEventRaised)
+ {
+ $this->_changedEventRaised=true;
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public function raisePostDataChangedEvent()
+ {
+ $page=$this->getPage();
+ if($this->getAutoPostBack() && !$page->getPostBackEventTarget())
+ {
+ $page->setPostBackEventTarget($this);
+ if($this->getCausesValidation())
+ $page->validate($this->getValidationGroup());
+ }
+ $this->onSelectedIndexChanged(null);
+ }
+
protected function onPreRender($param)
{
parent::onPreRender($param);
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index b32471fb..860cbc48 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -254,7 +254,7 @@ abstract class TListControl extends TDataBoundControl
}
}
- protected function getSelectedIndices()
+ public function getSelectedIndices()
{
$selections=array();
if($this->_items)
@@ -267,7 +267,7 @@ abstract class TListControl extends TDataBoundControl
return $selections;
}
- protected function setSelectedIndices($indices)
+ public function setSelectedIndices($indices)
{
if($this->_items)
{
diff --git a/framework/Web/UI/WebControls/TRadioButtonList.php b/framework/Web/UI/WebControls/TRadioButtonList.php
index 8d80745e..e434e709 100644
--- a/framework/Web/UI/WebControls/TRadioButtonList.php
+++ b/framework/Web/UI/WebControls/TRadioButtonList.php
@@ -2,17 +2,35 @@
class TRadioButtonList extends TCheckBoxList
{
- protected function createRepeatedControl()
+ protected function getIsMultiSelect()
{
- return new TRadioButton;
+ return false;
}
- public function loadPostData($key,$values)
+ protected function createRepeatedControl()
{
+ return new TRadioButton;
}
- public function raisePostDataChangedEvent()
+ public function loadPostData($key,$values)
{
+ $value=isset($values[$key])?$values[$key]:'';
+ $oldSelection=$this->getSelectedIndex();
+ $this->ensureDataBound();
+ foreach($this->getItems() as $index=>$item)
+ {
+ if($item->getEnabled() && $item->getValue()===$value)
+ {
+ if($index===$oldSelection)
+ return false;
+ else
+ {
+ $this->setSelectedIndex($index);
+ return true;
+ }
+ }
+ }
+ return false;
}
}
diff --git a/framework/Web/UI/WebControls/TRepeatInfo.php b/framework/Web/UI/WebControls/TRepeatInfo.php
index 14b57cfb..d3178c0c 100644
--- a/framework/Web/UI/WebControls/TRepeatInfo.php
+++ b/framework/Web/UI/WebControls/TRepeatInfo.php
@@ -271,6 +271,7 @@ class TRepeatInfo extends TComponent
}
if($index>=$itemCount)
continue;
+ $renderedItems++;
$user->renderItem($writer,$this,'Item',$index);
$writer->writeLine();
if(!$hasSeparators)
diff --git a/framework/Web/UI/WebControls/TStyle.php b/framework/Web/UI/WebControls/TStyle.php
index 4585cca3..bc77bfcf 100644
--- a/framework/Web/UI/WebControls/TStyle.php
+++ b/framework/Web/UI/WebControls/TStyle.php
@@ -258,14 +258,6 @@ class TStyle extends TComponent
$this->_fields['width']=$value;
}
- /**
- * @param boolean if the style contains nothing
- */
- public function getIsEmpty()
- {
- return empty($this->_fields) && $this->_class==='' && $this->_customStyle==='' && (!$this->_font || $this->_font->getIsEmpty());
- }
-
/**
* Resets the style to the original empty state.
*/
@@ -277,26 +269,6 @@ class TStyle extends TComponent
$this->_customStyle='';
}
- /**
- * Merges the current style with another one.
- * If the two styles have the same style field, the new one
- * will overwrite the current one.
- * @param TStyle the new style
- */
- public function mergeWith($style)
- {
- if($style===null)
- return;
- foreach($style->_fields as $name=>$value)
- $this->_fields[$name]=$value;
- if($style->_class!=='')
- $this->_class=$style->_class;
- if($style->_customStyle!=='')
- $this->_customStyle=$style->_customStyle;
- if($style->_font!==null)
- $this->getFont()->mergeWith($style->_font);
- }
-
/**
* Copies from a style.
* Existing style will be reset first.
@@ -304,22 +276,13 @@ class TStyle extends TComponent
*/
public function copyFrom($style)
{
- $this->reset();
- $this->mergeWith($style);
- }
-
- /**
- * Converts the style into a string representation suitable for rendering.
- * @return string the string representation of the style
- */
- public function toString()
- {
- $str='';
- foreach($this->_fields as $name=>$value)
- $str.=' '.$name.':'.$value.';';
- if($this->_font)
- $str.=$this->_font->toString();
- return $str;
+ $this->_fields=$style->_fields;
+ $this->_class=$style->_class;
+ $this->_customStyle=$style->_customStyle;
+ if($style->_font!==null)
+ $this->getFont()->copyFrom($style->_font);
+ else
+ $this->_font=null;
}
/**
@@ -378,6 +341,35 @@ class TTableStyle extends TStyle
*/
private $_gridLines='None';
+ /**
+ * Sets the style attributes to default values.
+ * This method overrides the parent implementation by
+ * resetting additional TTableStyle specific attributes.
+ */
+ public function reset()
+ {
+ $this->_backImageUrl='';
+ $this->_horizontalAlign='NotSet';
+ $this->_cellPadding=-1;
+ $this->_cellSpacing=-1;
+ $this->_gridLines='None';
+ }
+
+ /**
+ * Copies the style content from an existing style
+ * This method overrides the parent implementation by
+ * adding additional TTableStyle specific attributes.
+ * @param TStyle source style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ $this->_backImageUrl=$style->_backImageUrl;
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ $this->_cellPadding=$style->_cellPadding;
+ $this->_cellSpacing=$style->_cellSpacing;
+ $this->_gridLines=$style->_gridLines;
+ }
/**
* Adds attributes related to CSS styles to renderer.
@@ -387,10 +379,10 @@ class TTableStyle extends TStyle
public function addAttributesToRender($writer)
{
if(($url=trim($this->_backImageUrl))!=='')
- $this->setStyleField('background-image','url('.$url.')');
+ $writer->addStyleAttribute('background-image','url('.$url.')');
if($this->_horizontalAlign!=='NotSet')
- $this->setStyleField('text-align',strtolower($this->_horizontalAlign));
+ $writer->addStyleAttribute('text-align',strtolower($this->_horizontalAlign));
if($this->_cellPadding>=0)
$writer->addAttribute('cellpadding',"$this->_cellPadding");
@@ -399,7 +391,7 @@ class TTableStyle extends TStyle
{
$writer->addAttribute('cellspacing',"$this->_cellSpacing");
if($this->_cellSpacing===0)
- $this->setStyleField('border-collapse','collapse');
+ $writer->addStyleAttribute('border-collapse','collapse');
}
switch($this->_gridLines)
@@ -526,6 +518,32 @@ class TTableItemStyle extends TStyle
*/
private $_wrap=true;
+ /**
+ * Sets the style attributes to default values.
+ * This method overrides the parent implementation by
+ * resetting additional TTableItemStyle specific attributes.
+ */
+ public function reset()
+ {
+ $this->_verticalAlign='NotSet';
+ $this->_horizontalAlign='NotSet';
+ $this->_wrap=true;
+ }
+
+ /**
+ * Copies the style content from an existing style
+ * This method overrides the parent implementation by
+ * adding additional TTableItemStyle specific attributes.
+ * @param TStyle source style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ $this->_verticalAlign=$style->_verticalAlign;
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ $this->_wrap=$style->_wrap;
+ }
+
/**
* Adds attributes related to CSS styles to renderer.
* This method overrides the parent implementation.
@@ -534,7 +552,7 @@ class TTableItemStyle extends TStyle
public function addAttributesToRender($writer)
{
if(!$this->_wrap)
- $this->setStyleField('nowrap','nowrap');
+ $writer->addStyleAttribute('nowrap','nowrap');
if($this->_horizontalAlign!=='NotSet')
$writer->addAttribute('align',strtolower($this->_horizontalAlign));
--
cgit v1.2.3
|