diff options
| author | xue <> | 2006-02-26 18:17:40 +0000 | 
|---|---|---|
| committer | xue <> | 2006-02-26 18:17:40 +0000 | 
| commit | f6a0691f3cd3ae16dee61b86d0fcfea27a3f751b (patch) | |
| tree | 920876c937c23ae1fff5a002a14d092d4bd7c9b2 | |
| parent | 3129cef42098493b8a67f872a405fc8b5251da0f (diff) | |
Fixed an issue about style merging.
| -rw-r--r-- | framework/Web/UI/WebControls/TDataGrid.php | 30 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TDataList.php | 30 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TFont.php | 42 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TPanel.php | 83 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TStyle.php | 112 | 
5 files changed, 194 insertions, 103 deletions
| diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php index c6d27b7e..367b2c9b 100644 --- a/framework/Web/UI/WebControls/TDataGrid.php +++ b/framework/Web/UI/WebControls/TDataGrid.php @@ -1251,15 +1251,25 @@ class TDataGrid extends TBaseDataList implements INamingContainer  	{
  		$itemStyle=$this->getViewState('ItemStyle',null);
 -		$alternatingItemStyle=new TTableItemStyle($itemStyle);
 -		if(($style=$this->getViewState('AlternatingItemStyle',null))!==null)
 -			$alternatingItemStyle->mergeWith($style);
 +		$alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null);
 +		if($itemStyle!==null)
 +		{
 +			if($alternatingItemStyle===null)
 +				$alternatingItemStyle=$itemStyle;
 +			else
 +				$alternatingItemStyle->mergeWith($itemStyle);
 +		}
  		$selectedItemStyle=$this->getViewState('SelectedItemStyle',null);
 -		$editItemStyle=new TTableItemStyle($selectedItemStyle);
 -		if(($style=$this->getViewState('EditItemStyle',null))!==null)
 -			$editItemStyle->copyFrom($style);
 +		$editItemStyle=$this->getViewState('EditItemStyle',null);
 +		if($selectedItemStyle!==null)
 +		{
 +			if($editItemStyle===null)
 +				$editItemStyle=$selectedItemStyle;
 +			else
 +				$editItemStyle->mergeWith($selectedItemStyle);
 +		}
  		$headerStyle=$this->getViewState('HeaderStyle',null);
  		$footerStyle=$this->getViewState('FooterStyle',null);
 @@ -1304,6 +1314,8 @@ class TDataGrid extends TBaseDataList implements INamingContainer  						$item->getStyle()->mergeWith($alternatingItemStyle);
  					break;
  				case 'SelectedItem':
 +					if($selectedItemStyle)
 +						$item->getStyle()->mergeWith($selectedItemStyle);
  					if($index % 2==1)
  					{
  						if($itemStyle)
 @@ -1314,10 +1326,10 @@ class TDataGrid extends TBaseDataList implements INamingContainer  						if($alternatingItemStyle)
  							$item->getStyle()->mergeWith($alternatingItemStyle);
  					}
 -					if($selectedItemStyle)
 -						$item->getStyle()->mergeWith($selectedItemStyle);
  					break;
  				case 'EditItem':
 +					if($editItemStyle)
 +						$item->getStyle()->mergeWith($editItemStyle);
  					if($index % 2==1)
  					{
  						if($itemStyle)
 @@ -1328,8 +1340,6 @@ class TDataGrid extends TBaseDataList implements INamingContainer  						if($alternatingItemStyle)
  							$item->getStyle()->mergeWith($alternatingItemStyle);
  					}
 -					if($editItemStyle)
 -						$item->getStyle()->mergeWith($editItemStyle);
  					break;
  				case 'Pager':
  					if($pagerStyle)
 diff --git a/framework/Web/UI/WebControls/TDataList.php b/framework/Web/UI/WebControls/TDataList.php index 0ac0664d..ab1e8085 100644 --- a/framework/Web/UI/WebControls/TDataList.php +++ b/framework/Web/UI/WebControls/TDataList.php @@ -904,15 +904,25 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs  	{
  		$itemStyle=$this->getViewState('ItemStyle',null);
 -		$alternatingItemStyle=new TTableItemStyle($itemStyle);
 -		if(($style=$this->getViewState('AlternatingItemStyle',null))!==null)
 -			$alternatingItemStyle->mergeWith($style);
 +		$alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null);
 +		if($itemStyle!==null)
 +		{
 +			if($alternatingItemStyle===null)
 +				$alternatingItemStyle=$itemStyle;
 +			else
 +				$alternatingItemStyle->mergeWith($itemStyle);
 +		}
  		$selectedItemStyle=$this->getViewState('SelectedItemStyle',null);
 -		$editItemStyle=new TTableItemStyle($selectedItemStyle);
 -		if(($style=$this->getViewState('EditItemStyle',null))!==null)
 -			$editItemStyle->copyFrom($style);
 +		$editItemStyle=$this->getViewState('EditItemStyle',null);
 +		if($selectedItemStyle!==null)
 +		{
 +			if($editItemStyle===null)
 +				$editItemStyle=$selectedItemStyle;
 +			else
 +				$editItemStyle->mergeWith($selectedItemStyle);
 +		}
  		$headerStyle=$this->getViewState('HeaderStyle',null);
  		$footerStyle=$this->getViewState('FooterStyle',null);
 @@ -944,6 +954,8 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs  						$item->getStyle()->mergeWith($alternatingItemStyle);
  					break;
  				case 'SelectedItem':
 +					if($selectedItemStyle)
 +						$item->getStyle()->mergeWith($selectedItemStyle);
  					if($index % 2==1)
  					{
  						if($itemStyle)
 @@ -954,10 +966,10 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs  						if($alternatingItemStyle)
  							$item->getStyle()->mergeWith($alternatingItemStyle);
  					}
 -					if($selectedItemStyle)
 -						$item->getStyle()->mergeWith($selectedItemStyle);
  					break;
  				case 'EditItem':
 +					if($editItemStyle)
 +						$item->getStyle()->mergeWith($editItemStyle);
  					if($index % 2==1)
  					{
  						if($itemStyle)
 @@ -968,8 +980,6 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs  						if($alternatingItemStyle)
  							$item->getStyle()->mergeWith($alternatingItemStyle);
  					}
 -					if($editItemStyle)
 -						$item->getStyle()->mergeWith($editItemStyle);
  					break;
  				default:
  					break;
 diff --git a/framework/Web/UI/WebControls/TFont.php b/framework/Web/UI/WebControls/TFont.php index 2f95e2bd..3fb8bbad 100644 --- a/framework/Web/UI/WebControls/TFont.php +++ b/framework/Web/UI/WebControls/TFont.php @@ -209,14 +209,40 @@ class TFont extends TComponent  	/**
  	 * Merges the font with a new one.
 -	 * If a font field is set in the new font, the current font field
 -	 * will be overwritten.
 +	 * If a font field is not set in the font, it will be overwritten with
 +	 * the new one.
  	 * @param TFont the new font
  	 */
  	public function mergeWith($font)
  	{
  		if($font===null || $font->_flags===0)
  			return;
 +		if(!($this->_flags & self::IS_SET_BOLD) && ($font->_flags & self::IS_SET_BOLD))
 +			$this->setBold($font->getBold());
 +		if(!($this->_flags & self::IS_SET_ITALIC) && ($font->_flags & self::IS_SET_ITALIC))
 +			$this->setItalic($font->getItalic());
 +		if(!($this->_flags & self::IS_SET_OVERLINE) && ($font->_flags & self::IS_SET_OVERLINE))
 +			$this->setOverline($font->getOverline());
 +		if(!($this->_flags & self::IS_SET_STRIKEOUT) && ($font->_flags & self::IS_SET_STRIKEOUT))
 +			$this->setStrikeout($font->getStrikeout());
 +		if(!($this->_flags & self::IS_SET_UNDERLINE) && ($font->_flags & self::IS_SET_UNDERLINE))
 +			$this->setUnderline($font->getUnderline());
 +		if(!($this->_flags & self::IS_SET_SIZE) && ($font->_flags & self::IS_SET_SIZE))
 +			$this->setSize($font->getSize());
 +		if(!($this->_flags & self::IS_SET_NAME) && ($font->_flags & self::IS_SET_NAME))
 +			$this->setName($font->getName());
 +	}
 +
 +	/**
 +	 * Copies the fields in a new font to this font.
 +	 * If a font field is set in the new font, the corresponding field
 +	 * in this font will be overwritten.
 +	 * @param TFont the new font
 +	 */
 +	public function copyFrom($font)
 +	{
 +		if($font===null || $font->_flags===0)
 +			return;
  		if($font->_flags & self::IS_SET_BOLD)
  			$this->setBold($font->getBold());
  		if($font->_flags & self::IS_SET_ITALIC)
 @@ -234,18 +260,6 @@ class TFont extends TComponent  	}
  	/**
 -	 * Copies the font from a new one.
 -	 * The existing font will be cleared up first.
 -	 * @param TFont the new font.
 -	 */
 -	public function copyFrom($font)
 -	{
 -		$this->_flags=$font->_flags;
 -		$this->_name=$font->_name;
 -		$this->_size=$font->_size;
 -	}
 -
 -	/**
  	 * @return string the font in a css style string representation.
  	 */
  	public function toString()
 diff --git a/framework/Web/UI/WebControls/TPanel.php b/framework/Web/UI/WebControls/TPanel.php index 33ae7cd2..ed2a7f44 100644 --- a/framework/Web/UI/WebControls/TPanel.php +++ b/framework/Web/UI/WebControls/TPanel.php @@ -242,23 +242,23 @@ class TPanelStyle extends TStyle  	/**
  	 * @var string the URL of the background image for the panel component
  	 */
 -	private $_backImageUrl='';
 +	private $_backImageUrl=null;
  	/**
  	 * @var string alignment of the content in the panel.
  	 */
 -	private $_direction='NotSet';
 +	private $_direction=null;
  	/**
  	 * @var string horizontal alignment of the contents within the panel
  	 */
 -	private $_horizontalAlign='NotSet';
 +	private $_horizontalAlign=null;
  	/**
  	 * @var string visibility and position of scroll bars
  	 */
 -	private $_scrollBars='None';
 +	private $_scrollBars=null;
  	/**
  	 * @var boolean whether the content wraps within the panel
  	 */
 -	private $_wrap=true;
 +	private $_wrap=null;
  	/**
  	 * Adds attributes related to CSS styles to renderer.
 @@ -297,7 +297,7 @@ class TPanelStyle extends TStyle  	 */
  	public function getBackImageUrl()
  	{
 -		return $this->_backImageUrl;
 +		return $this->_backImageUrl===null?'':$this->_backImageUrl;
  	}
  	/**
 @@ -314,7 +314,7 @@ class TPanelStyle extends TStyle  	 */
  	public function getDirection()
  	{
 -		return $this->_direction;
 +		return $this->_direction===null?'NotSet':$this->_direction;
  	}
  	/**
 @@ -331,7 +331,7 @@ class TPanelStyle extends TStyle  	 */
  	public function getWrap()
  	{
 -		return $this->_wrap;
 +		return $this->_wrap===null?true:$this->_wrap;
  	}
  	/**
 @@ -348,7 +348,7 @@ class TPanelStyle extends TStyle  	 */
  	public function getHorizontalAlign()
  	{
 -		return $this->_horizontalAlign;
 +		return $this->_horizontalAlign===null?'NotSet':$this->_horizontalAlign;
  	}
  	/**
 @@ -366,7 +366,7 @@ class TPanelStyle extends TStyle  	 */
  	public function getScrollBars()
  	{
 -		return $this->_scrollBars;
 +		return $this->_scrollBars===null?'None':$this->_scrollBars;
  	}
  	/**
 @@ -377,5 +377,68 @@ class TPanelStyle extends TStyle  	{
  		$this->_scrollBars=TPropertyValue::ensureEnum($value,array('None','Auto','Both','Horizontal','Vertical'));
  	}
 +
 +	/**
 +	 * Sets the style attributes to default values.
 +	 * This method overrides the parent implementation by
 +	 * resetting additional TTableStyle specific attributes.
 +	 */
 +	public function reset()
 +	{
 +		parent::reset();
 +		$this->_backImageUrl=null;
 +		$this->_direction=null;
 +		$this->_horizontalAlign=null;
 +		$this->_scrollBars=null;
 +		$this->_wrap=null;
 +	}
 +
 +	/**
 +	 * Copies the fields in a new style to this style.
 +	 * If a style field is set in the new style, the corresponding field
 +	 * in this style will be overwritten.
 +	 * @param TStyle the new style
 +	 */
 +	public function copyFrom($style)
 +	{
 +		parent::copyFrom($style);
 +		if($style instanceof TPanelStyle)
 +		{
 +			if($style->_backImageUrl!==null)
 +				$this->_backImageUrl=$style->_backImageUrl;
 +			if($style->_direction!==null)
 +				$this->_direction=$style->_direction;
 +			if($style->_horizontalAlign!==null)
 +				$this->_horizontalAlign=$style->_horizontalAlign;
 +			if($style->_scrollBars!==null)
 +				$this->_scrollBars=$style->_scrollBars;
 +			if($style->_wrap!==null)
 +				$this->_wrap=$style->_wrap;
 +		}
 +	}
 +
 +	/**
 +	 * Merges the style with a new one.
 +	 * If a style field is not set in this style, it will be overwritten by
 +	 * the new one.
 +	 * @param TStyle the new style
 +	 */
 +	public function mergeWith($style)
 +	{
 +		parent::mergeWith($style);
 +		if($style instanceof TTableStyle)
 +		{
 +			if($this->_backImageUrl===null && $style->_backImageUrl!==null)
 +				$this->_backImageUrl=$style->_backImageUrl;
 +			if($this->_direction===null && $style->_direction!==null)
 +				$this->_direction=$style->_direction;
 +			if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
 +				$this->_horizontalAlign=$style->_horizontalAlign;
 +			if($this->_scrollBars===null && $style->_scrollBars!==null)
 +				$this->_scrollBars=$style->_scrollBars;
 +			if($this->_wrap===null && $style->_wrap!==null)
 +				$this->_wrap=$style->_wrap;
 +		}
 +	}
  }
  ?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TStyle.php b/framework/Web/UI/WebControls/TStyle.php index e1636145..c6163367 100644 --- a/framework/Web/UI/WebControls/TStyle.php +++ b/framework/Web/UI/WebControls/TStyle.php @@ -144,7 +144,7 @@ class TStyle extends TComponent  	 */
  	public function setCssClass($value)
  	{
 -		$this->_class=trim($value)===''?null:$value;
 +		$this->_class=$value;
  	}
  	/**
 @@ -210,7 +210,7 @@ class TStyle extends TComponent  	 */
  	public function setCustomStyle($value)
  	{
 -		$this->_customStyle=trim($value)===''?null:$value;
 +		$this->_customStyle=$value;
  	}
  	/**
 @@ -277,37 +277,39 @@ class TStyle extends TComponent  	}
  	/**
 -	 * Copies from a style.
 -	 * Existing style will be reset first.
 +	 * Copies the fields in a new style to this style.
 +	 * If a style field is set in the new style, the corresponding field
 +	 * in this style will be overwritten.
  	 * @param TStyle the new style
  	 */
  	public function copyFrom($style)
  	{
 -		$this->reset();
  		if($style instanceof TStyle)
  		{
 -			$this->_fields=$style->_fields;
 -			$this->_class=$style->_class;
 -			$this->_customStyle=$style->_customStyle;
 +			$this->_fields=array_merge($this->_fields,$style->_fields);
 +			if($style->_class!==null)
 +				$this->_class=$style->_class;
 +			if($style->_customStyle!==null)
 +				$this->_customStyle=$style->_customStyle;
  			if($style->_font!==null)
  				$this->getFont()->copyFrom($style->_font);
  		}
  	}
  	/**
 -	 * Merges with a style.
 -	 * If a style field is set in the new style, the current style field
 -	 * will be overwritten.
 +	 * Merges the style with a new one.
 +	 * If a style field is not set in this style, it will be overwritten by
 +	 * the new one.
  	 * @param TStyle the new style
  	 */
  	public function mergeWith($style)
  	{
 -		if($style!==null)
 +		if($style instanceof TStyle)
  		{
 -			$this->_fields=array_merge($this->_fields,$style->_fields);
 -			if($style->_class!==null)
 +			$this->_fields=array_merge($style->_fields,$this->_fields);
 +			if($this->_class===null)
  				$this->_class=$style->_class;
 -			if($style->_customStyle!==null)
 +			if($this->_customStyle===null)
  				$this->_customStyle=$style->_customStyle;
  			if($style->_font!==null)
  				$this->getFont()->mergeWith($style->_font);
 @@ -384,31 +386,33 @@ class TTableStyle extends TStyle  	}
  	/**
 -	 * Copies the style content from an existing style
 -	 * This method overrides the parent implementation by
 -	 * adding additional TTableStyle specific attributes.
 -	 * @param TStyle source style
 +	 * Copies the fields in a new style to this style.
 +	 * If a style field is set in the new style, the corresponding field
 +	 * in this style will be overwritten.
 +	 * @param TStyle the new style
  	 */
  	public function copyFrom($style)
  	{
  		parent::copyFrom($style);
  		if($style instanceof TTableStyle)
  		{
 -			$this->_backImageUrl=$style->_backImageUrl;
 -			$this->_horizontalAlign=$style->_horizontalAlign;
 -			$this->_cellPadding=$style->_cellPadding;
 -			$this->_cellSpacing=$style->_cellSpacing;
 -			$this->_gridLines=$style->_gridLines;
 +			if($style->_backImageUrl!==null)
 +				$this->_backImageUrl=$style->_backImageUrl;
 +			if($style->_horizontalAlign!==null)
 +				$this->_horizontalAlign=$style->_horizontalAlign;
 +			if($style->_cellPadding!==null)
 +				$this->_cellPadding=$style->_cellPadding;
 +			if($style->_cellSpacing!==null)
 +				$this->_cellSpacing=$style->_cellSpacing;
 +			if($style->_gridLines!==null)
 +				$this->_gridLines=$style->_gridLines;
  		}
  	}
  	/**
 -	 * Merges with a style.
 -	 * Merges with a style.
 -	 * If a style field is set in the new style, the current style field
 -	 * will be overwritten.
 -	 * This method overrides the parent implementation by
 -	 * merging with additional TTableStyle specific attributes.
 +	 * Merges the style with a new one.
 +	 * If a style field is not set in this style, it will be overwritten by
 +	 * the new one.
  	 * @param TStyle the new style
  	 */
  	public function mergeWith($style)
 @@ -416,15 +420,15 @@ class TTableStyle extends TStyle  		parent::mergeWith($style);
  		if($style instanceof TTableStyle)
  		{
 -			if($style->_backImageUrl!==null)
 +			if($this->_backImageUrl===null && $style->_backImageUrl!==null)
  				$this->_backImageUrl=$style->_backImageUrl;
 -			if($style->_horizontalAlign!==null)
 +			if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
  				$this->_horizontalAlign=$style->_horizontalAlign;
 -			if($style->_cellPadding!==null)
 +			if($this->_cellPadding===null && $style->_cellPadding!==null)
  				$this->_cellPadding=$style->_cellPadding;
 -			if($style->_cellSpacing!==null)
 +			if($this->_cellSpacing===null && $style->_cellSpacing!==null)
  				$this->_cellSpacing=$style->_cellSpacing;
 -			if($style->_gridLines!==null)
 +			if($this->_gridLines===null && $style->_gridLines!==null)
  				$this->_gridLines=$style->_gridLines;
  		}
  	}
 @@ -477,7 +481,7 @@ class TTableStyle extends TStyle  	 */
  	public function setBackImageUrl($value)
  	{
 -		$this->_backImageUrl=trim($value)===''?null:$value;
 +		$this->_backImageUrl=$value;
  	}
  	/**
 @@ -496,8 +500,6 @@ class TTableStyle extends TStyle  	public function setHorizontalAlign($value)
  	{
  		$this->_horizontalAlign=TPropertyValue::ensureEnum($value,array('NotSet','Left','Right','Center','Justify'));
 -		if($this->_horizontalAlign==='NotSet')
 -			$this->_horizontalAlign=null;
  	}
  	/**
 @@ -516,8 +518,6 @@ class TTableStyle extends TStyle  	{
  		if(($this->_cellPadding=TPropertyValue::ensureInteger($value))<-1)
  			throw new TInvalidDataValueException('tablestyle_cellpadding_invalid');
 -		if($this->_cellPadding===-1)
 -			$this->_cellPadding=null;
  	}
  	/**
 @@ -536,8 +536,6 @@ class TTableStyle extends TStyle  	{
  		if(($this->_cellSpacing=TPropertyValue::ensureInteger($value))<-1)
  			throw new TInvalidDataValueException('tablestyle_cellspacing_invalid');
 -		if($this->_cellSpacing===-1)
 -			$this->_cellSpacing=null;
  	}
  	/**
 @@ -597,29 +595,29 @@ class TTableItemStyle extends TStyle  	}
  	/**
 -	 * Copies the style content from an existing style
 -	 * This method overrides the parent implementation by
 -	 * adding additional TTableItemStyle specific attributes.
 -	 * @param TStyle source style
 +	 * Copies the fields in a new style to this style.
 +	 * If a style field is set in the new style, the corresponding field
 +	 * in this style will be overwritten.
 +	 * @param TStyle the new style
  	 */
  	public function copyFrom($style)
  	{
  		parent::copyFrom($style);
  		if($style instanceof TTableItemStyle)
  		{
 -			$this->_verticalAlign=$style->_verticalAlign;
 -			$this->_horizontalAlign=$style->_horizontalAlign;
 -			$this->_wrap=$style->_wrap;
 +			if($this->_verticalAlign===null && $style->_verticalAlign!==null)
 +				$this->_verticalAlign=$style->_verticalAlign;
 +			if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
 +				$this->_horizontalAlign=$style->_horizontalAlign;
 +			if($this->_wrap===null && $style->_wrap!==null)
 +				$this->_wrap=$style->_wrap;
  		}
  	}
  	/**
 -	 * Merges with a style.
 -	 * Merges with a style.
 -	 * If a style field is set in the new style, the current style field
 -	 * will be overwritten.
 -	 * This method overrides the parent implementation by
 -	 * merging with additional TTableItemStyle specific attributes.
 +	 * Merges the style with a new one.
 +	 * If a style field is not set in this style, it will be overwritten by
 +	 * the new one.
  	 * @param TStyle the new style
  	 */
  	public function mergeWith($style)
 @@ -671,8 +669,6 @@ class TTableItemStyle extends TStyle  	public function setHorizontalAlign($value)
  	{
  		$this->_horizontalAlign=TPropertyValue::ensureEnum($value,array('NotSet','Left','Right','Center','Justify'));
 -		if($this->_horizontalAlign==='NotSet')
 -			$this->_horizontalAlign=null;
  	}
  	/**
 @@ -691,8 +687,6 @@ class TTableItemStyle extends TStyle  	public function setVerticalAlign($value)
  	{
  		$this->_verticalAlign=TPropertyValue::ensureEnum($value,array('NotSet','Top','Bottom','Middel'));
 -		if($this->_verticalAlign==='NotSet')
 -			$this->_verticalAlign=null;
  	}
  	/**
 | 
