summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TPanel.php
blob: 5cdfa3074485829c8ffe1c7f8ae3f6360eee8c3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
 * TPanel class file
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2005 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @version $Revision: $  $Date: $
 * @package System.Web.UI.WebControls
 */

/**
 * TPanel class
 *
 * TPanel represents a component that acts as a container for other component.
 * It is especially useful when you want to generate components programmatically or hide/show a group of components.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @version $Revision: $  $Date: $
 * @package System.Web.UI.WebControls
 * @since 3.0
 */
class TPanel extends TWebControl
{
	private $_defaultButton='';
	/**
	 * @return string tag name of the panel
	 */
	protected function getTagName()
	{
		return 'div';
	}

	/**
	 * Adds attributes to renderer.
	 * @param THtmlWriter the renderer
	 */
	protected function addAttributesToRender($writer)
	{
		parent::addAttributesToRender($writer);
		if(($url=trim($this->getBackImageUrl()))!=='')
			$writer->addStyleAttribute('background-image','url('.$url.')');
		//this.AddScrollingAttribute(this.ScrollBars, writer);
		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)
				throw new TInvalidOperationException('panel_defaultbutton_invalid');
			else
				$this->getPage()->getClientScript()->registerDefaultButtonScript($button,$writer);
		}
	}

	/**
	 * @return boolean whether the content wraps within the panel.
	 */
	public function getWrap()
	{
		return $this->getViewState('Wrap',true);
	}

	/**
	 * 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->setViewState('Wrap',TPropertyValue::ensureBoolean($value),true);
	}

	/**
	 * @return string the horizontal alignment of the contents within the panel.
	 */
	public function getHorizontalAlign()
	{
		return $this->getViewState('HorizontalAlign','');
	}

	/**
	 * Sets the horizontal alignment of the contents within the panel.
     * Valid values include 'justify', 'left', 'center', 'right' or empty string.
	 * @param string the horizontal alignment
	 */
	public function setHorizontalAlign($value)
	{
		$this->setViewState('HorizontalAlign',$value,'');
	}

	/**
	 * @return string the URL of the background image for the panel component.
	 */
	public function getBackImageUrl()
	{
		return $this->getViewState('BackImageUrl','');
	}

	/**
	 * Sets the URL of the background image for the panel component.
	 * @param string the URL
	 */
	public function setBackImageUrl($value)
	{
		$this->setViewState('BackImageUrl',$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.
	 */
	public function getDirection()
	{
		return $this->getViewState('Direction','');
	}

	/**
	 * @param string alignment of the content in the panel.
	 * Valid values include 'ltr' (left to right) and 'rtl' (right to left).
	 */
	public function setDirection($value)
	{
		$this->setViewState('Direction',$value,'');
	}

	public function getDefaultButton()
	{
		return $this->_defaultButton;
	}

	public function setDefaultButton($value)
	{
		$this->_defaultButton=$value;
	}

	/**
	 * @return string the legend text when the panel is used as a fieldset. Defaults to empty.
	 */
	public function getGroupingText()
	{
		return $this->getViewState('GroupingText','');
	}

	/**
	 * @param string the legend text. If this value is not empty, the panel will be rendered as a fieldset.
	 */
	public function setGroupingText($value)
	{
		$this->setViewState('GroupingText',$value,'');
	}

	/**
	 * Renders the openning tag for the control (including attributes)
	 * @param THtmlWriter the writer used for the rendering purpose
	 */
	protected function renderBeginTag($writer)
	{
		parent::renderBeginTag($writer);
		if(($text=$this->getGroupingText())!=='')
		{
			$writer->renderBeginTag('fieldset');
			$writer->renderBeginTag('legend');
			$writer->write($text);
			$writer->renderEndTag();
		}
	}

	/**
	 * Renders the closing tag for the control
	 * @param THtmlWriter the writer used for the rendering purpose
	 */
	protected function renderEndTag($writer)
	{
		if(($text=$this->getGroupingText())!=='')
			$writer->renderEndTag();
		parent::renderEndTag($writer);
	}
}

?>