From a6be5564823be40670e0cad8dc758557dbd37549 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sat, 24 Jun 2006 05:46:22 +0000 Subject: Update active controls. --- framework/Web/UI/WebControls/TListControl.php | 78 +++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 9 deletions(-) (limited to 'framework/Web/UI/WebControls/TListControl.php') diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index a9087af5..3ad46db8 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -436,6 +436,8 @@ abstract class TListControl extends TDataBoundControl throw new TInvalidDataValueException('listcontrol_selectedindex_invalid',get_class($this),$index); } $this->_cachedSelectedIndex=$index; + if($this->getAdapter() instanceof IListControlAdaptee) + $this->getAdapter()->setSelectedIndex($index); } /** @@ -469,6 +471,9 @@ abstract class TListControl extends TDataBoundControl $this->_items->itemAt($index)->setSelected(true); } } + + if($this->getAdapter() instanceof IListControlAdaptee) + $this->getAdapter()->setSelectedIndices($indices); } /** @@ -512,6 +517,8 @@ abstract class TListControl extends TDataBoundControl throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value); } $this->_cachedSelectedValue=$value; + if($this->getAdapter() instanceof IListControlAdaptee) + $this->getAdapter()->setSelectedValue($value); } @@ -551,6 +558,9 @@ abstract class TListControl extends TDataBoundControl throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value); } } + + if($this->getAdapter() instanceof IListControlAdaptee) + $this->getAdapter()->setSelectedValues($values); } /** @@ -579,6 +589,9 @@ abstract class TListControl extends TDataBoundControl foreach($this->_items as $item) $item->setSelected(false); } + + if($this->getAdapter() instanceof IListControlAdaptee) + $this->getAdapter()->clearSelection(); } /** @@ -707,13 +720,24 @@ class TListItemCollection extends TList */ public function createListItem($index=-1) { - $item=new TListItem; + $item=$this->createNewListItem(); if($index<0) $this->add($item); else $this->insertAt($index,$item); return $item; } + + /** + * @return TListItem new item. + */ + protected function createNewListItem($text=null) + { + $item = new TListItem; + if(!is_null($text)) + $item->setText($text); + return $item; + } /** * Inserts an item into the collection. @@ -724,15 +748,11 @@ class TListItemCollection extends TList */ public function insertAt($index,$item) { - if($item instanceof TListItem) - parent::insertAt($index,$item); - else if(is_string($item)) - { - $item=$this->createListItem($index); - $item->setText($item); - } - else + if(is_string($item)) + $item = $this->createNewListItem($item); + if(!($item instanceof TListItem)) throw new TInvalidDataTypeException('listitemcollection_item_invalid',get_class($this)); + parent::insertAt($index,$item); } /** @@ -824,4 +844,44 @@ class TListItemCollection extends TList } } +/** + * IListControlAdapter interface + * + * @author Wei Zhuo + * @version $Revision: $ Sun Jun 25 04:53:43 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ +interface IListControlAdaptee +{ + /** + * Selects an item based on zero-base index on the client side. + * @param integer the index (zero-based) of the item to be selected + */ + public function setSelectedIndex($index); + /** + * Selects a list of item based on zero-base indices on the client side. + * @param array list of index of items to be selected + */ + public function setSelectedIndices($indices); + + /** + * Sets selection by item value on the client side. + * @param string the value of the item to be selected. + */ + public function setSelectedValue($value); + + /** + * Sets selection by a list of item values on the client side. + * @param array list of the selected item values + */ + public function setSelectedValues($values); + + /** + * Clears all existing selections on the client side. + */ + public function clearSelection(); +} + + ?> -- cgit v1.2.3