summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
authorxue <>2005-12-31 15:23:57 +0000
committerxue <>2005-12-31 15:23:57 +0000
commit5479507cbdcbc14685a443b1096171b5134f82bf (patch)
tree9c8d3028407e7c54c813ea76b048a6a4ec680319 /framework/Web/UI
parent16c588209ce9197f13f343c83145446c4d92822a (diff)
Refactored TPanel by adding TPanelStyle.
Added TPanel samples.
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/WebControls/TPanel.php206
-rw-r--r--framework/Web/UI/WebControls/TStyle.php124
-rw-r--r--framework/Web/UI/WebControls/TWebControl.php13
3 files changed, 271 insertions, 72 deletions
diff --git a/framework/Web/UI/WebControls/TPanel.php b/framework/Web/UI/WebControls/TPanel.php
index 22e41c20..eeee4d59 100644
--- a/framework/Web/UI/WebControls/TPanel.php
+++ b/framework/Web/UI/WebControls/TPanel.php
@@ -50,6 +50,15 @@ class TPanel extends TWebControl
}
/**
+ * Creates a style object to be used by the control.
+ * This method overrides the parent impementation by creating a TPanelStyle object.
+ */
+ protected function createStyle()
+ {
+ return new TPanelStyle;
+ }
+
+ /**
* Adds attributes to renderer.
* @param THtmlWriter the renderer
* @throws TInvalidDataValueException if default button is not right.
@@ -57,21 +66,6 @@ class TPanel extends TWebControl
protected function addAttributesToRender($writer)
{
parent::addAttributesToRender($writer);
- if(($url=trim($this->getBackImageUrl()))!=='')
- $writer->addStyleAttribute('background-image','url('.$url.')');
- switch($this->getScrollBars())
- {
- case 'Horizontal': $writer->addStyleAttribute('overflow-x','scroll'); break;
- case 'Vertical': $writer->addStyleAttribute('overflow-y','scroll'); break;
- case 'Both': $writer->addStyleAttribute('overflow','scroll'); break;
- case 'Auto': $writer->addStyleAttribute('overflow','auto'); break;
- }
- if(($align=$this->getHorizontalAlign())!=='')
- $writer->addStyleAttribute('text-align',$align);
- if(!$this->getWrap())
- $writer->addStyleAttribute('white-space','nowrap');
- if(($dir=$this->getDirection())!=='') // ltr or rtl
- $writer->addStyleAttribute('direction',$dir);
if(($butt=$this->getDefaultButton())!=='')
{
if(($button=$this->findControl($butt))===null)
@@ -85,11 +79,11 @@ class TPanel extends TWebControl
}
/**
- * @return boolean whether the content wraps within the panel.
+ * @return boolean whether the content wraps within the panel. Defaults to true.
*/
public function getWrap()
{
- return $this->getViewState('Wrap',true);
+ return $this->getStyle()->getWrap();
}
/**
@@ -98,25 +92,25 @@ class TPanel extends TWebControl
*/
public function setWrap($value)
{
- $this->setViewState('Wrap',TPropertyValue::ensureBoolean($value),true);
+ $this->getStyle()->setWrap($value);
}
/**
- * @return string the horizontal alignment of the contents within the panel, defaults to empty string (meaning not set).
+ * @return string the horizontal alignment of the contents within the panel, defaults to 'NotSet'.
*/
public function getHorizontalAlign()
{
- return $this->getViewState('HorizontalAlign','');
+ return $this->getStyle()->getHorizontalAlign();
}
/**
* Sets the horizontal alignment of the contents within the panel.
- * Valid values include 'justify', 'left', 'center', 'right' or empty string.
+ * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
* @param string the horizontal alignment
*/
public function setHorizontalAlign($value)
{
- $this->setViewState('HorizontalAlign',$value,'');
+ $this->getStyle()->setHorizontalAlign($value);
}
/**
@@ -124,7 +118,7 @@ class TPanel extends TWebControl
*/
public function getBackImageUrl()
{
- return $this->getViewState('BackImageUrl','');
+ return $this->getStyle()->getBackImageUrl();
}
/**
@@ -133,26 +127,24 @@ class TPanel extends TWebControl
*/
public function setBackImageUrl($value)
{
- $this->setViewState('BackImageUrl',$value,'');
+ $this->getStyle()->setBackImageUrl($value);
}
/**
- * @return string alignment of the content in the panel.
- * Valid values include 'ltr' (left to right) and 'rtl' (right to left).
- * Defaults to empty.
+ * @return string alignment of the content in the panel. Defaults to 'NotSet'.
*/
public function getDirection()
{
- return $this->getViewState('Direction','');
+ return $this->getStyle()->getDirection();
}
/**
* @param string alignment of the content in the panel.
- * Valid values include 'ltr' (left to right) and 'rtl' (right to left).
+ * Valid values include 'NotSet', 'LeftToRight', 'RightToLeft'.
*/
public function setDirection($value)
{
- $this->setViewState('Direction',$value,'');
+ $this->getStyle()->setDirection($value);
}
/**
@@ -196,7 +188,7 @@ class TPanel extends TWebControl
*/
public function getScrollBars()
{
- return $this->getViewState('ScrollBars','None');
+ return $this->getStyle()->getScrollBars();
}
/**
@@ -205,7 +197,7 @@ class TPanel extends TWebControl
*/
public function setScrollBars($value)
{
- $this->setViewState('ScrollBars',TPropertyValue::ensureEnum($value,array('None','Auto','Both','Horizontal','Vertical')),'None');
+ $this->getStyle()->setScrollBars($value);
}
/**
@@ -236,4 +228,154 @@ class TPanel extends TWebControl
}
}
+/**
+ * TPanelStyle class.
+ * TPanelStyle represents the CSS style specific for panel HTML tag.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TPanelStyle extends TStyle
+{
+ /**
+ * @var string the URL of the background image for the panel component
+ */
+ private $_backImageUrl='';
+ /**
+ * @var string alignment of the content in the panel.
+ */
+ private $_direction='NotSet';
+ /**
+ * @var string horizontal alignment of the contents within the panel
+ */
+ private $_horizontalAlign='NotSet';
+ /**
+ * @var string visibility and position of scroll bars
+ */
+ private $_scrollBars='None';
+ /**
+ * @var boolean whether the content wraps within the panel
+ */
+ private $_wrap=true;
+
+ /**
+ * Adds attributes related to CSS styles to renderer.
+ * This method overrides the parent implementation.
+ * @param THtmlWriter the writer used for the rendering purpose
+ */
+ public function addAttributesToRender($writer)
+ {
+ if(($url=trim($this->_backImageUrl))!=='')
+ $this->setStyleField('background-image','url('.$url.')');
+
+ switch($this->_scrollBars)
+ {
+ case 'Horizontal': $this->setStyleField('overflow-x','scroll'); break;
+ case 'Vertical': $this->setStyleField('overflow-y','scroll'); break;
+ case 'Both': $this->setStyleField('overflow','scroll'); break;
+ case 'Auto': $this->setStyleField('overflow','auto'); break;
+ }
+
+ if($this->_horizontalAlign!=='NotSet')
+ $this->setStyleField('text-align',strtolower($this->_horizontalAlign));
+
+ if(!$this->_wrap)
+ $this->setStyleField('white-space','nowrap');
+
+ if($this->_direction==='LeftToRight')
+ $this->setStyleField('direction','ltr');
+ else if($this->_direction==='RightToLeft')
+ $this->setStyleField('direction','rtl');
+
+ parent::addAttributesToRender($writer);
+ }
+
+ /**
+ * @return string the URL of the background image for the panel component.
+ */
+ public function getBackImageUrl()
+ {
+ return $this->_backImageUrl;
+ }
+
+ /**
+ * Sets the URL of the background image for the panel component.
+ * @param string the URL
+ */
+ public function setBackImageUrl($value)
+ {
+ $this->_backImageUrl=$value;
+ }
+
+ /**
+ * @return string alignment of the content in the panel. Defaults to 'NotSet'.
+ */
+ public function getDirection()
+ {
+ return $this->_direction;
+ }
+
+ /**
+ * @param string alignment of the content in the panel.
+ * Valid values include 'NotSet', 'LeftToRight', 'RightToLeft'.
+ */
+ public function setDirection($value)
+ {
+ $this->_direction=TPropertyValue::ensureEnum($value,array('NotSet','LeftToRight','RightToLeft'));
+ }
+
+ /**
+ * @return boolean whether the content wraps within the panel. Defaults to true.
+ */
+ public function getWrap()
+ {
+ return $this->_wrap;
+ }
+
+ /**
+ * Sets the value indicating whether the content wraps within the panel.
+ * @param boolean whether the content wraps within the panel.
+ */
+ public function setWrap($value)
+ {
+ $this->_wrap=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * @return string the horizontal alignment of the contents within the panel, defaults to 'NotSet'.
+ */
+ public function getHorizontalAlign()
+ {
+ return $this->_horizontalAlign;
+ }
+
+ /**
+ * Sets the horizontal alignment of the contents within the panel.
+ * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
+ * @param string the horizontal alignment
+ */
+ public function setHorizontalAlign($value)
+ {
+ $this->_horizontalAlign=TPropertyValue::ensureEnum($value,array('NotSet','Left','Right','Center','Justify'));
+ }
+
+ /**
+ * @return string the visibility and position of scroll bars in a panel control, defaults to None.
+ */
+ public function getScrollBars()
+ {
+ return $this->_scrollBars;
+ }
+
+ /**
+ * @param string the visibility and position of scroll bars in a panel control.
+ * Valid values include None, Auto, Both, Horizontal and Vertical.
+ */
+ public function setScrollBars($value)
+ {
+ $this->_scrollBars=TPropertyValue::ensureEnum($value,array('None','Auto','Both','Horizontal','Vertical'));
+ }
+}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TStyle.php b/framework/Web/UI/WebControls/TStyle.php
index 02f0de29..8db5e416 100644
--- a/framework/Web/UI/WebControls/TStyle.php
+++ b/framework/Web/UI/WebControls/TStyle.php
@@ -30,7 +30,7 @@ class TStyle extends TComponent
/**
* @var array storage of CSS fields
*/
- private $_data=array();
+ private $_fields=array();
/**
* @var TFont font object
*/
@@ -42,14 +42,14 @@ class TStyle extends TComponent
/**
* @var string CSS style string (those not represented by specific fields of TStyle)
*/
- private $_style='';
+ private $_customStyle='';
/**
* @return string the background color of the control
*/
public function getBackColor()
{
- return isset($this->_data['background-color'])?$this->_data['background-color']:'';
+ return isset($this->_fields['background-color'])?$this->_fields['background-color']:'';
}
/**
@@ -58,9 +58,9 @@ class TStyle extends TComponent
public function setBackColor($value)
{
if($value==='')
- unset($this->_data['background-color']);
+ unset($this->_fields['background-color']);
else
- $this->_data['background-color']=$value;
+ $this->_fields['background-color']=$value;
}
/**
@@ -68,7 +68,7 @@ class TStyle extends TComponent
*/
public function getBorderColor()
{
- return isset($this->_data['border-color'])?$this->_data['border-color']:'';
+ return isset($this->_fields['border-color'])?$this->_fields['border-color']:'';
}
/**
@@ -77,9 +77,9 @@ class TStyle extends TComponent
public function setBorderColor($value)
{
if($value==='')
- unset($this->_data['border-color']);
+ unset($this->_fields['border-color']);
else
- $this->_data['border-color']=$value;
+ $this->_fields['border-color']=$value;
}
/**
@@ -87,7 +87,7 @@ class TStyle extends TComponent
*/
public function getBorderStyle()
{
- return isset($this->_data['border-style'])?$this->_data['border-style']:'';
+ return isset($this->_fields['border-style'])?$this->_fields['border-style']:'';
}
/**
@@ -97,9 +97,9 @@ class TStyle extends TComponent
public function setBorderStyle($value)
{
if($value==='')
- unset($this->_data['border-style']);
+ unset($this->_fields['border-style']);
else
- $this->_data['border-style']=$value;
+ $this->_fields['border-style']=$value;
}
/**
@@ -107,7 +107,7 @@ class TStyle extends TComponent
*/
public function getBorderWidth()
{
- return isset($this->_data['border-width'])?$this->_data['border-width']:'';
+ return isset($this->_fields['border-width'])?$this->_fields['border-width']:'';
}
/**
@@ -116,9 +116,9 @@ class TStyle extends TComponent
public function setBorderWidth($value)
{
if($value==='')
- unset($this->_data['border-width']);
+ unset($this->_fields['border-width']);
else
- $this->_data['border-width']=$value;
+ $this->_fields['border-width']=$value;
}
/**
@@ -152,7 +152,7 @@ class TStyle extends TComponent
*/
public function getForeColor()
{
- return isset($this->_data['color'])?$this->_data['color']:'';
+ return isset($this->_fields['color'])?$this->_fields['color']:'';
}
/**
@@ -161,9 +161,9 @@ class TStyle extends TComponent
public function setForeColor($value)
{
if($value==='')
- unset($this->_data['color']);
+ unset($this->_fields['color']);
else
- $this->_data['color']=$value;
+ $this->_fields['color']=$value;
}
/**
@@ -171,7 +171,7 @@ class TStyle extends TComponent
*/
public function getHeight()
{
- return isset($this->_data['height'])?$this->_data['height']:'';
+ return isset($this->_fields['height'])?$this->_fields['height']:'';
}
/**
@@ -180,25 +180,63 @@ class TStyle extends TComponent
public function setHeight($value)
{
if($value==='')
- unset($this->_data['height']);
+ unset($this->_fields['height']);
else
- $this->_data['height']=$value;
+ $this->_fields['height']=$value;
}
/**
* @return string the custom style of the control
*/
- public function getStyle()
+ public function getCustomStyle()
{
- return $this->_style;
+ return $this->_customStyle;
}
/**
+ * Sets custom style fields from a string.
+ * Custom style fields will be overwritten by style fields explicitly defined.
* @param string the custom style of the control
*/
- public function setStyle($value)
+ public function setCustomStyle($value)
{
- $this->_style=$value;
+ $this->_customStyle=$value;
+ }
+
+ /**
+ * @return string a single style field value set via {@link setStyleField}. Defaults to empty string.
+ */
+ public function getStyleField($name)
+ {
+ return isset($this->_fields[$name])?$this->_fields[$name]:'';
+ }
+
+ /**
+ * Sets a single style field value.
+ * Style fields set by this method will overwrite those set by {@link setCustomStyle}.
+ * @param string style field name
+ * @param string style field value
+ */
+ public function setStyleField($name,$value)
+ {
+ $this->_fields[$name]=$value;
+ }
+
+ /**
+ * Clears a single style field value;
+ * @param string style field name
+ */
+ public function clearStyleField($name)
+ {
+ unset($this->_fields[$name]);
+ }
+
+ /**
+ * @return boolean whether a style field has been defined by {@link setStyleField}
+ */
+ public function hasStyleField($name)
+ {
+ return isset($this->_fields[$name]);
}
/**
@@ -206,7 +244,7 @@ class TStyle extends TComponent
*/
public function getWidth()
{
- return isset($this->_data['width'])?$this->_data['width']:'';
+ return isset($this->_fields['width'])?$this->_fields['width']:'';
}
/**
@@ -215,9 +253,9 @@ class TStyle extends TComponent
public function setWidth($value)
{
if($value==='')
- unset($this->_data['width']);
+ unset($this->_fields['width']);
else
- $this->_data['width']=$value;
+ $this->_fields['width']=$value;
}
/**
@@ -225,7 +263,7 @@ class TStyle extends TComponent
*/
public function getIsEmpty()
{
- return empty($this->_data) && $this->_class==='' && $this->_style==='' && (!$this->_font || $this->_font->getIsEmpty());
+ return empty($this->_fields) && $this->_class==='' && $this->_customStyle==='' && (!$this->_font || $this->_font->getIsEmpty());
}
/**
@@ -233,10 +271,10 @@ class TStyle extends TComponent
*/
public function reset()
{
- $this->_data=array();
+ $this->_fields=array();
$this->_font=null;
$this->_class='';
- $this->_style='';
+ $this->_customStyle='';
}
/**
@@ -249,12 +287,12 @@ class TStyle extends TComponent
{
if($style===null)
return;
- foreach($style->_data as $name=>$value)
- $this->_data[$name]=$value;
+ foreach($style->_fields as $name=>$value)
+ $this->_fields[$name]=$value;
if($style->_class!=='')
$this->_class=$style->_class;
- if($style->_style!=='')
- $this->_style=$style->_style;
+ if($style->_customStyle!=='')
+ $this->_customStyle=$style->_customStyle;
if($style->_font!==null)
$this->getFont()->mergeWith($style->_font);
}
@@ -277,7 +315,7 @@ class TStyle extends TComponent
public function toString()
{
$str='';
- foreach($this->_data as $name=>$value)
+ foreach($this->_fields as $name=>$value)
$str.=' '.$name.':'.$value.';';
if($this->_font)
$str.=$this->_font->toString();
@@ -290,16 +328,16 @@ class TStyle extends TComponent
*/
public function addAttributesToRender($writer)
{
- if($this->_style!=='')
+ if($this->_customStyle!=='')
{
- foreach(explode(';',$this->_style) as $style)
+ foreach(explode(';',$this->_customStyle) as $style)
{
$arr=explode(':',$style);
if(isset($arr[1]) && trim($arr[0])!=='')
$writer->addStyleAttribute(trim($arr[0]),trim($arr[1]));
}
}
- foreach($this->_data as $name=>$value)
+ foreach($this->_fields as $name=>$value)
$writer->addStyleAttribute($name,$value);
if($this->_font!==null)
$this->_font->addAttributesToRender($writer);
@@ -308,4 +346,14 @@ class TStyle extends TComponent
}
}
+
+class TTableStyle extends TStyle
+{
+}
+
+class TTableItemStyle extends TStyle
+{
+}
+
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TWebControl.php b/framework/Web/UI/WebControls/TWebControl.php
index 4f20b227..6e2a2c89 100644
--- a/framework/Web/UI/WebControls/TWebControl.php
+++ b/framework/Web/UI/WebControls/TWebControl.php
@@ -211,6 +211,15 @@ class TWebControl extends TControl
}
/**
+ * Creates a style object to be used by the control.
+ * This method may be overriden by controls to provide customized style.
+ */
+ protected function createStyle()
+ {
+ return new TStyle;
+ }
+
+ /**
* @return TStyle the object representing the css style of the control
*/
public function getStyle()
@@ -219,7 +228,7 @@ class TWebControl extends TControl
return $style;
else
{
- $style=new TStyle;
+ $style=$this->createStyle();
$this->setViewState('Style',$style,null);
return $style;
}
@@ -234,7 +243,7 @@ class TWebControl extends TControl
public function setStyle($value)
{
if(is_string($value))
- $this->getStyle()->setStyle($value);
+ $this->getStyle()->setCustomStyle($value);
else
throw new TInvalidDataValueException('webcontrol_style_invalid',get_class($this));
}