| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TPanel class file
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TPanel.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* Includes TPanelStyle class file
|
|
|
15 |
*/
|
|
|
16 |
Prado::using('System.Web.UI.WebControls.TPanelStyle');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* TPanel class
|
|
|
20 |
*
|
|
|
21 |
* TPanel represents a component that acts as a container for other component.
|
|
|
22 |
* It is especially useful when you want to generate components programmatically
|
|
|
23 |
* or hide/show a group of components.
|
|
|
24 |
*
|
|
|
25 |
* By default, TPanel displays a <div> element on a page.
|
|
|
26 |
* Children of TPanel are displayed as the body content of the element.
|
|
|
27 |
* The property {@link setWrap Wrap} can be used to set whether the body content
|
|
|
28 |
* should wrap or not. {@link setHorizontalAlign HorizontalAlign} governs how
|
|
|
29 |
* the content is aligned horizontally, and {@link getDirection Direction} indicates
|
|
|
30 |
* the content direction (left to right or right to left). You can set
|
|
|
31 |
* {@link setBackImageUrl BackImageUrl} to give a background image to the panel,
|
|
|
32 |
* and you can ste {@link setGroupingText GroupingText} so that the panel is
|
|
|
33 |
* displayed as a field set with a legend text. Finally, you can specify
|
|
|
34 |
* a default button to be fired when users press 'return' key within the panel
|
|
|
35 |
* by setting the {@link setDefaultButton DefaultButton} property.
|
|
|
36 |
*
|
|
|
37 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
38 |
* @version $Id: TPanel.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
39 |
* @package System.Web.UI.WebControls
|
|
|
40 |
* @since 3.0
|
|
|
41 |
*/
|
|
|
42 |
class TPanel extends TWebControl
|
|
|
43 |
{
|
|
|
44 |
/**
|
|
|
45 |
* @var string ID path to the default button
|
|
|
46 |
*/
|
|
|
47 |
private $_defaultButton='';
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* @return string tag name of the panel
|
|
|
51 |
*/
|
|
|
52 |
protected function getTagName()
|
|
|
53 |
{
|
|
|
54 |
return 'div';
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Creates a style object to be used by the control.
|
|
|
59 |
* This method overrides the parent impementation by creating a TPanelStyle object.
|
|
|
60 |
* @return TPanelStyle the style used by TPanel.
|
|
|
61 |
*/
|
|
|
62 |
protected function createStyle()
|
|
|
63 |
{
|
|
|
64 |
return new TPanelStyle;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Adds attributes to renderer.
|
|
|
69 |
* @param THtmlWriter the renderer
|
|
|
70 |
* @throws TInvalidDataValueException if default button is not right.
|
|
|
71 |
*/
|
|
|
72 |
protected function addAttributesToRender($writer)
|
|
|
73 |
{
|
|
|
74 |
parent::addAttributesToRender($writer);
|
|
|
75 |
if(($butt=$this->getDefaultButton())!=='')
|
|
|
76 |
{
|
|
|
77 |
if(($button=$this->findControl($butt))===null)
|
|
|
78 |
throw new TInvalidDataValueException('panel_defaultbutton_invalid',$butt);
|
|
|
79 |
else
|
|
|
80 |
{
|
|
|
81 |
$writer->addAttribute('id',$this->getClientID());
|
|
|
82 |
$this->getPage()->getClientScript()->registerDefaultButton($this, $button);
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* @return boolean whether the content wraps within the panel. Defaults to true.
|
|
|
89 |
*/
|
|
|
90 |
public function getWrap()
|
|
|
91 |
{
|
|
|
92 |
return $this->getStyle()->getWrap();
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Sets the value indicating whether the content wraps within the panel.
|
|
|
97 |
* @param boolean whether the content wraps within the panel.
|
|
|
98 |
*/
|
|
|
99 |
public function setWrap($value)
|
|
|
100 |
{
|
|
|
101 |
$this->getStyle()->setWrap($value);
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* @return string the horizontal alignment of the contents within the panel, defaults to 'NotSet'.
|
|
|
106 |
*/
|
|
|
107 |
public function getHorizontalAlign()
|
|
|
108 |
{
|
|
|
109 |
return $this->getStyle()->getHorizontalAlign();
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* Sets the horizontal alignment of the contents within the panel.
|
|
|
114 |
* Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
|
|
|
115 |
* @param string the horizontal alignment
|
|
|
116 |
*/
|
|
|
117 |
public function setHorizontalAlign($value)
|
|
|
118 |
{
|
|
|
119 |
$this->getStyle()->setHorizontalAlign($value);
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
* @return string the URL of the background image for the panel component.
|
|
|
124 |
*/
|
|
|
125 |
public function getBackImageUrl()
|
|
|
126 |
{
|
|
|
127 |
return $this->getStyle()->getBackImageUrl();
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
* Sets the URL of the background image for the panel component.
|
|
|
132 |
* @param string the URL
|
|
|
133 |
*/
|
|
|
134 |
public function setBackImageUrl($value)
|
|
|
135 |
{
|
|
|
136 |
$this->getStyle()->setBackImageUrl($value);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* @return string alignment of the content in the panel. Defaults to 'NotSet'.
|
|
|
141 |
*/
|
|
|
142 |
public function getDirection()
|
|
|
143 |
{
|
|
|
144 |
return $this->getStyle()->getDirection();
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
/**
|
|
|
148 |
* @param string alignment of the content in the panel.
|
|
|
149 |
* Valid values include 'NotSet', 'LeftToRight', 'RightToLeft'.
|
|
|
150 |
*/
|
|
|
151 |
public function setDirection($value)
|
|
|
152 |
{
|
|
|
153 |
$this->getStyle()->setDirection($value);
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
/**
|
|
|
157 |
* @return string the ID path to the default button. Defaults to empty.
|
|
|
158 |
*/
|
|
|
159 |
public function getDefaultButton()
|
|
|
160 |
{
|
|
|
161 |
return $this->_defaultButton;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
/**
|
|
|
165 |
* Specifies the default button for the panel.
|
|
|
166 |
* The default button will be fired (clicked) whenever a user enters 'return'
|
|
|
167 |
* key within the panel.
|
|
|
168 |
* The button must be locatable via the function call {@link TControl::findControl findControl}.
|
|
|
169 |
* @param string the ID path to the default button.
|
|
|
170 |
*/
|
|
|
171 |
public function setDefaultButton($value)
|
|
|
172 |
{
|
|
|
173 |
$this->_defaultButton=$value;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
/**
|
|
|
177 |
* @return string the legend text when the panel is used as a fieldset. Defaults to empty.
|
|
|
178 |
*/
|
|
|
179 |
public function getGroupingText()
|
|
|
180 |
{
|
|
|
181 |
return $this->getViewState('GroupingText','');
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
/**
|
|
|
185 |
* @param string the legend text. If this value is not empty, the panel will be rendered as a fieldset.
|
|
|
186 |
*/
|
|
|
187 |
public function setGroupingText($value)
|
|
|
188 |
{
|
|
|
189 |
$this->setViewState('GroupingText',$value,'');
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
/**
|
|
|
193 |
* @return string the visibility and position of scroll bars in a panel control, defaults to None.
|
|
|
194 |
*/
|
|
|
195 |
public function getScrollBars()
|
|
|
196 |
{
|
|
|
197 |
return $this->getStyle()->getScrollBars();
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* @param string the visibility and position of scroll bars in a panel control.
|
|
|
202 |
* Valid values include None, Auto, Both, Horizontal and Vertical.
|
|
|
203 |
*/
|
|
|
204 |
public function setScrollBars($value)
|
|
|
205 |
{
|
|
|
206 |
$this->getStyle()->setScrollBars($value);
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
/**
|
|
|
210 |
* Renders the openning tag for the control (including attributes)
|
|
|
211 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
212 |
*/
|
|
|
213 |
public function renderBeginTag($writer)
|
|
|
214 |
{
|
|
|
215 |
parent::renderBeginTag($writer);
|
|
|
216 |
if(($text=$this->getGroupingText())!=='')
|
|
|
217 |
{
|
|
|
218 |
$writer->renderBeginTag('fieldset');
|
|
|
219 |
$writer->renderBeginTag('legend');
|
|
|
220 |
$writer->write($text);
|
|
|
221 |
$writer->renderEndTag();
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
/**
|
|
|
226 |
* Renders the closing tag for the control
|
|
|
227 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
228 |
*/
|
|
|
229 |
public function renderEndTag($writer)
|
|
|
230 |
{
|
|
|
231 |
if($this->getGroupingText()!=='')
|
|
|
232 |
$writer->renderEndTag();
|
|
|
233 |
parent::renderEndTag($writer);
|
|
|
234 |
}
|
|
|
235 |
}
|
|
|
236 |
|