Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TTableCell class file
4
 *
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TTableCell.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Web.UI.WebControls
11
 */
12
 
13
/**
14
 * TTableCell class.
15
 *
16
 * TTableCell displays a table cell on a Web page. Content of the table cell
17
 * is specified by the {@link setText Text} property. If {@link setText Text}
18
 * is empty, the body contents enclosed by the table cell component tag are rendered.
19
 * Note, {@link setText Text} is not HTML-encoded when displayed. So make sure
20
 * it does not contain dangerous characters.
21
 *
22
 * The horizontal and vertical alignments of the contents in the cell
23
 * are specified via {@link setHorizontalAlign HorizontalAlign} and
24
 * {@link setVerticalAlign VerticalAlign} properties, respectively.
25
 *
26
 * The colspan and rowspan of the cell are specified via {@link setColumnSpan ColumnSpan}
27
 * and {@link setRowSpan RowSpan} properties. And the {@link setWrap Wrap} property
28
 * indicates whether the contents in the cell should be wrapped.
29
 *
30
 * @author Qiang Xue <qiang.xue@gmail.com>
31
 * @version $Id: TTableCell.php 2541 2008-10-21 15:05:13Z qiang.xue $
32
 * @package System.Web.UI.WebControls
33
 * @since 3.0
34
 */
35
class TTableCell extends TWebControl implements IDataRenderer
36
{
37
	/**
38
	 * @return string tag name for the table cell
39
	 */
40
	protected function getTagName()
41
	{
42
		return 'td';
43
	}
44
 
45
	/**
46
	 * Creates a style object for the control.
47
	 * This method creates a {@link TTableItemStyle} to be used by the table cell.
48
	 * @return TStyle control style to be used
49
	 */
50
	protected function createStyle()
51
	{
52
		return new TTableItemStyle;
53
	}
54
 
55
	/**
56
	 * @return string the horizontal alignment of the contents within the table item, defaults to 'NotSet'.
57
	 */
58
	public function getHorizontalAlign()
59
	{
60
		if($this->getHasStyle())
61
			return $this->getStyle()->getHorizontalAlign();
62
		else
63
			return 'NotSet';
64
	}
65
 
66
	/**
67
	 * Sets the horizontal alignment of the contents within the table item.
68
     * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
69
	 * @param string the horizontal alignment
70
	 */
71
	public function setHorizontalAlign($value)
72
	{
73
		$this->getStyle()->setHorizontalAlign($value);
74
	}
75
 
76
	/**
77
	 * @return string the vertical alignment of the contents within the table item, defaults to 'NotSet'.
78
	 */
79
	public function getVerticalAlign()
80
	{
81
		if($this->getHasStyle())
82
			return $this->getStyle()->getVerticalAlign();
83
		else
84
			return 'NotSet';
85
	}
86
 
87
	/**
88
	 * Sets the vertical alignment of the contents within the table item.
89
     * Valid values include 'NotSet','Top','Bottom','Middle'
90
	 * @param string the horizontal alignment
91
	 */
92
	public function setVerticalAlign($value)
93
	{
94
		$this->getStyle()->setVerticalAlign($value);
95
	}
96
 
97
	/**
98
	 * @return integer the columnspan for the table cell, 0 if not set.
99
	 */
100
	public function getColumnSpan()
101
	{
102
		return $this->getViewState('ColumnSpan', 0);
103
	}
104
 
105
	/**
106
	 * Sets the columnspan for the table cell.
107
	 * @param integer the columnspan for the table cell, 0 if not set.
108
	 */
109
	public function setColumnSpan($value)
110
	{
111
		$this->setViewState('ColumnSpan', TPropertyValue::ensureInteger($value), 0);
112
	}
113
 
114
	/**
115
	 * @return integer the rowspan for the table cell, 0 if not set.
116
	 */
117
	public function getRowSpan()
118
	{
119
		return $this->getViewState('RowSpan', 0);
120
	}
121
 
122
	/**
123
	 * Sets the rowspan for the table cell.
124
	 * @param integer the rowspan for the table cell, 0 if not set.
125
	 */
126
	public function setRowSpan($value)
127
	{
128
		$this->setViewState('RowSpan', TPropertyValue::ensureInteger($value), 0);
129
	}
130
 
131
	/**
132
	 * @return boolean whether the text content wraps within a table cell. Defaults to true.
133
	 */
134
	public function getWrap()
135
	{
136
		if($this->getHasStyle())
137
			return $this->getStyle()->getWrap();
138
		else
139
			return true;
140
	}
141
 
142
	/**
143
	 * Sets the value indicating whether the text content wraps within a table cell.
144
	 * @param boolean whether the text content wraps within a table cell.
145
	 */
146
	public function setWrap($value)
147
	{
148
		$this->getStyle()->setWrap($value);
149
	}
150
 
151
	/**
152
	 * @return string the text content of the table cell.
153
	 */
154
	public function getText()
155
	{
156
		return $this->getViewState('Text','');
157
	}
158
 
159
	/**
160
	 * Sets the text content of the table cell.
161
	 * If the text content is empty, body content (child controls) of the cell will be rendered.
162
	 * @param string the text content
163
	 */
164
	public function setText($value)
165
	{
166
		$this->setViewState('Text',$value,'');
167
	}
168
 
169
	/**
170
	 * Returns the text content of the table cell.
171
	 * This method is required by {@link IDataRenderer}.
172
	 * It is the same as {@link getText()}.
173
	 * @return string the text content of the table cell.
174
	 * @see getText
175
	 * @since 3.1.0
176
	 */
177
	public function getData()
178
	{
179
		return $this->getText();
180
	}
181
 
182
	/**
183
	 * Sets the text content of the table cell.
184
	 * This method is required by {@link IDataRenderer}.
185
	 * It is the same as {@link setText()}.
186
	 * @param string the text content of the table cell.
187
	 * @see setText
188
	 * @since 3.1.0
189
	 */
190
	public function setData($value)
191
	{
192
		$this->setText($value);
193
	}
194
 
195
	/**
196
	 * Adds attributes to renderer.
197
	 * @param THtmlWriter the renderer
198
	 */
199
	protected function addAttributesToRender($writer)
200
	{
201
		parent::addAttributesToRender($writer);
202
		if(($colspan=$this->getColumnSpan())>0)
203
			$writer->addAttribute('colspan',"$colspan");
204
		if(($rowspan=$this->getRowSpan())>0)
205
			$writer->addAttribute('rowspan',"$rowspan");
206
	}
207
 
208
	/**
209
	 * Renders body contents of the table cell.
210
	 * @param THtmlWriter the writer used for the rendering purpose.
211
	 */
212
	public function renderContents($writer)
213
	{
214
		if(($text=$this->getText())!=='')
215
			$writer->write($text);
216
		else if($this->getHasControls())
217
			parent::renderContents($writer);
218
		else
219
			$writer->write('&nbsp;');
220
	}
221
}
222