3 * TPanelStyle class file
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright © 2005-2014 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @package System.Web.UI.WebControls
13 * Includes TStyle class file
15 Prado::using('System.Web.UI.WebControls.TStyle');
19 * TPanelStyle represents the CSS style specific for panel HTML tag.
21 * @author Qiang Xue <qiang.xue@gmail.com>
22 * @package System.Web.UI.WebControls
25 class TPanelStyle extends TStyle
28 * @var string the URL of the background image for the panel component
30 private $_backImageUrl=null;
32 * @var string alignment of the content in the panel.
34 private $_direction=null;
36 * @var string horizontal alignment of the contents within the panel
38 private $_horizontalAlign=null;
40 * @var string visibility and position of scroll bars
42 private $_scrollBars=null;
44 * @var boolean whether the content wraps within the panel
49 * Adds attributes related to CSS styles to renderer.
50 * This method overrides the parent implementation.
51 * @param THtmlWriter the writer used for the rendering purpose
53 public function addAttributesToRender($writer)
55 if(($url=trim($this->getBackImageUrl()))!=='')
56 $this->setStyleField('background-image','url('.$url.')');
58 switch($this->getScrollBars())
60 case TScrollBars::Horizontal: $this->setStyleField('overflow-x','scroll'); break;
61 case TScrollBars::Vertical: $this->setStyleField('overflow-y','scroll'); break;
62 case TScrollBars::Both: $this->setStyleField('overflow','scroll'); break;
63 case TScrollBars::Auto: $this->setStyleField('overflow','auto'); break;
66 if(($align=$this->getHorizontalAlign())!==THorizontalAlign::NotSet)
67 $this->setStyleField('text-align',strtolower($align));
70 $this->setStyleField('white-space','nowrap');
72 if(($direction=$this->getDirection())!==TContentDirection::NotSet)
74 if($direction===TContentDirection::LeftToRight)
75 $this->setStyleField('direction','ltr');
77 $this->setStyleField('direction','rtl');
80 parent::addAttributesToRender($writer);
84 * @return string the URL of the background image for the panel component.
86 public function getBackImageUrl()
88 return $this->_backImageUrl===null?'':$this->_backImageUrl;
92 * Sets the URL of the background image for the panel component.
93 * @param string the URL
95 public function setBackImageUrl($value)
97 $this->_backImageUrl=$value;
101 * @return TContentDirection alignment of the content in the panel. Defaults to TContentDirection::NotSet.
103 public function getDirection()
105 return $this->_direction===null?TContentDirection::NotSet:$this->_direction;
109 * @param TContentDirection alignment of the content in the panel.
111 public function setDirection($value)
113 $this->_direction=TPropertyValue::ensureEnum($value,'TContentDirection');
117 * @return boolean whether the content wraps within the panel. Defaults to true.
119 public function getWrap()
121 return $this->_wrap===null?true:$this->_wrap;
125 * Sets the value indicating whether the content wraps within the panel.
126 * @param boolean whether the content wraps within the panel.
128 public function setWrap($value)
130 $this->_wrap=TPropertyValue::ensureBoolean($value);
134 * @return THorizontalAlign the horizontal alignment of the contents within the panel, defaults to THorizontalAlign::NotSet.
136 public function getHorizontalAlign()
138 return $this->_horizontalAlign===null?THorizontalAlign::NotSet:$this->_horizontalAlign;
142 * Sets the horizontal alignment of the contents within the panel.
143 * @param THorizontalAlign the horizontal alignment
145 public function setHorizontalAlign($value)
147 $this->_horizontalAlign=TPropertyValue::ensureEnum($value,'THorizontalAlign');
151 * @return TScrollBars the visibility and position of scroll bars in a panel control, defaults to TScrollBars::None.
153 public function getScrollBars()
155 return $this->_scrollBars===null?TScrollBars::None:$this->_scrollBars;
159 * @param TScrollBars the visibility and position of scroll bars in a panel control.
161 public function setScrollBars($value)
163 $this->_scrollBars=TPropertyValue::ensureEnum($value,'TScrollBars');
167 * Sets the style attributes to default values.
168 * This method overrides the parent implementation by
169 * resetting additional TPanelStyle specific attributes.
171 public function reset()
174 $this->_backImageUrl=null;
175 $this->_direction=null;
176 $this->_horizontalAlign=null;
177 $this->_scrollBars=null;
182 * Copies the fields in a new style to this style.
183 * If a style field is set in the new style, the corresponding field
184 * in this style will be overwritten.
185 * @param TStyle the new style
187 public function copyFrom($style)
189 parent::copyFrom($style);
190 if($style instanceof TPanelStyle)
192 if($style->_backImageUrl!==null)
193 $this->_backImageUrl=$style->_backImageUrl;
194 if($style->_direction!==null)
195 $this->_direction=$style->_direction;
196 if($style->_horizontalAlign!==null)
197 $this->_horizontalAlign=$style->_horizontalAlign;
198 if($style->_scrollBars!==null)
199 $this->_scrollBars=$style->_scrollBars;
200 if($style->_wrap!==null)
201 $this->_wrap=$style->_wrap;
206 * Merges the style with a new one.
207 * If a style field is not set in this style, it will be overwritten by
209 * @param TStyle the new style
211 public function mergeWith($style)
213 parent::mergeWith($style);
214 if($style instanceof TPanelStyle)
216 if($this->_backImageUrl===null && $style->_backImageUrl!==null)
217 $this->_backImageUrl=$style->_backImageUrl;
218 if($this->_direction===null && $style->_direction!==null)
219 $this->_direction=$style->_direction;
220 if($this->_horizontalAlign===null && $style->_horizontalAlign!==null)
221 $this->_horizontalAlign=$style->_horizontalAlign;
222 if($this->_scrollBars===null && $style->_scrollBars!==null)
223 $this->_scrollBars=$style->_scrollBars;
224 if($this->_wrap===null && $style->_wrap!==null)
225 $this->_wrap=$style->_wrap;
231 * TContentDirection class.
232 * TContentDirection defines the enumerable type for the possible directions that a panel can be at.
234 * The following enumerable values are defined:
235 * - NotSet: the direction is not specified
236 * - LeftToRight: content in a panel is left to right
237 * - RightToLeft: content in a panel is right to left
239 * @author Qiang Xue <qiang.xue@gmail.com>
240 * @package System.Web.UI.WebControls
243 class TContentDirection extends TEnumerable
245 const NotSet='NotSet';
246 const LeftToRight='LeftToRight';
247 const RightToLeft='RightToLeft';
252 * TScrollBars defines the enumerable type for the possible scroll bar mode
253 * that a {@link TPanel} control could use.
255 * The following enumerable values are defined:
256 * - None: no scroll bars.
257 * - Auto: scroll bars automatically appeared when needed.
258 * - Both: show both horizontal and vertical scroll bars all the time.
259 * - Horizontal: horizontal scroll bar only
260 * - Vertical: vertical scroll bar only
262 * @author Qiang Xue <qiang.xue@gmail.com>
263 * @package System.Web.UI.WebControls
266 class TScrollBars extends TEnumerable
271 const Horizontal='Horizontal';
272 const Vertical='Vertical';