3 * TTableCell class file
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link https://github.com/pradosoft/prado
7 * @copyright Copyright © 2005-2016 The PRADO Group
8 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9 * @package System.Web.UI.WebControls
15 * TTableCell displays a table cell on a Web page. Content of the table cell
16 * is specified by the {@link setText Text} property. If {@link setText Text}
17 * is empty, the body contents enclosed by the table cell component tag are rendered.
18 * Note, {@link setText Text} is not HTML-encoded when displayed. So make sure
19 * it does not contain dangerous characters.
21 * The horizontal and vertical alignments of the contents in the cell
22 * are specified via {@link setHorizontalAlign HorizontalAlign} and
23 * {@link setVerticalAlign VerticalAlign} properties, respectively.
25 * The colspan and rowspan of the cell are specified via {@link setColumnSpan ColumnSpan}
26 * and {@link setRowSpan RowSpan} properties. And the {@link setWrap Wrap} property
27 * indicates whether the contents in the cell should be wrapped.
29 * @author Qiang Xue <qiang.xue@gmail.com>
30 * @package System.Web.UI.WebControls
33 class TTableCell extends TWebControl implements IDataRenderer
36 * @return string tag name for the table cell
38 protected function getTagName()
44 * Creates a style object for the control.
45 * This method creates a {@link TTableItemStyle} to be used by the table cell.
46 * @return TStyle control style to be used
48 protected function createStyle()
50 return new TTableItemStyle;
54 * @return string the horizontal alignment of the contents within the table item, defaults to 'NotSet'.
56 public function getHorizontalAlign()
58 if($this->getHasStyle())
59 return $this->getStyle()->getHorizontalAlign();
65 * Sets the horizontal alignment of the contents within the table item.
66 * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
67 * @param string the horizontal alignment
69 public function setHorizontalAlign($value)
71 $this->getStyle()->setHorizontalAlign($value);
75 * @return string the vertical alignment of the contents within the table item, defaults to 'NotSet'.
77 public function getVerticalAlign()
79 if($this->getHasStyle())
80 return $this->getStyle()->getVerticalAlign();
86 * Sets the vertical alignment of the contents within the table item.
87 * Valid values include 'NotSet','Top','Bottom','Middle'
88 * @param string the horizontal alignment
90 public function setVerticalAlign($value)
92 $this->getStyle()->setVerticalAlign($value);
96 * @return integer the columnspan for the table cell, 0 if not set.
98 public function getColumnSpan()
100 return $this->getViewState('ColumnSpan', 0);
104 * Sets the columnspan for the table cell.
105 * @param integer the columnspan for the table cell, 0 if not set.
107 public function setColumnSpan($value)
109 $this->setViewState('ColumnSpan', TPropertyValue::ensureInteger($value), 0);
113 * @return integer the rowspan for the table cell, 0 if not set.
115 public function getRowSpan()
117 return $this->getViewState('RowSpan', 0);
121 * Sets the rowspan for the table cell.
122 * @param integer the rowspan for the table cell, 0 if not set.
124 public function setRowSpan($value)
126 $this->setViewState('RowSpan', TPropertyValue::ensureInteger($value), 0);
130 * @return boolean whether the text content wraps within a table cell. Defaults to true.
132 public function getWrap()
134 if($this->getHasStyle())
135 return $this->getStyle()->getWrap();
141 * Sets the value indicating whether the text content wraps within a table cell.
142 * @param boolean whether the text content wraps within a table cell.
144 public function setWrap($value)
146 $this->getStyle()->setWrap($value);
150 * @return string the text content of the table cell.
152 public function getText()
154 return $this->getViewState('Text','');
158 * Sets the text content of the table cell.
159 * If the text content is empty, body content (child controls) of the cell will be rendered.
160 * @param string the text content
162 public function setText($value)
164 $this->setViewState('Text',$value,'');
168 * Returns the text content of the table cell.
169 * This method is required by {@link IDataRenderer}.
170 * It is the same as {@link getText()}.
171 * @return string the text content of the table cell.
175 public function getData()
177 return $this->getText();
181 * Sets the text content of the table cell.
182 * This method is required by {@link IDataRenderer}.
183 * It is the same as {@link setText()}.
184 * @param string the text content of the table cell.
188 public function setData($value)
190 $this->setText($value);
194 * Adds attributes to renderer.
195 * @param THtmlWriter the renderer
197 protected function addAttributesToRender($writer)
199 parent::addAttributesToRender($writer);
200 if(($colspan=$this->getColumnSpan())>0)
201 $writer->addAttribute('colspan',"$colspan");
202 if(($rowspan=$this->getRowSpan())>0)
203 $writer->addAttribute('rowspan',"$rowspan");
207 * Renders body contents of the table cell.
208 * @param THtmlWriter the writer used for the rendering purpose.
210 public function renderContents($writer)
212 if(($text=$this->getText())!=='')
213 $writer->write($text);
214 else if($this->getHasControls())
215 parent::renderContents($writer);
217 $writer->write(' ');