| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TControl, TControlCollection, TEventParameter and INamingContainer 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: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
10 |
* @package System.Web.UI
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* Includes TAttributeCollection and TControlAdapter class
|
|
|
15 |
*/
|
|
|
16 |
Prado::using('System.Collections.TAttributeCollection');
|
|
|
17 |
Prado::using('System.Web.UI.TControlAdapter');
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* TControl class
|
|
|
21 |
*
|
|
|
22 |
* TControl is the base class for all components on a page hierarchy.
|
|
|
23 |
* It implements the following features for UI-related functionalities:
|
|
|
24 |
* - databinding feature
|
|
|
25 |
* - parent and child relationship
|
|
|
26 |
* - naming container and containee relationship
|
|
|
27 |
* - viewstate and controlstate features
|
|
|
28 |
* - rendering scheme
|
|
|
29 |
* - control lifecycles
|
|
|
30 |
*
|
|
|
31 |
* A property can be data-bound with an expression. By calling {@link dataBind},
|
|
|
32 |
* expressions bound to properties will be evaluated and the results will be
|
|
|
33 |
* set to the corresponding properties.
|
|
|
34 |
*
|
|
|
35 |
* Parent and child relationship determines how the presentation of controls are
|
|
|
36 |
* enclosed within each other. A parent will determine where to place
|
|
|
37 |
* the presentation of its child controls. For example, a TPanel will enclose
|
|
|
38 |
* all its child controls' presentation within a div html tag. A control's parent
|
|
|
39 |
* can be obtained via {@link getParent Parent} property, and its
|
|
|
40 |
* {@link getControls Controls} property returns a list of the control's children,
|
|
|
41 |
* including controls and static texts. The property can be manipulated
|
|
|
42 |
* like an array for adding or removing a child (see {@link TList} for more details).
|
|
|
43 |
*
|
|
|
44 |
* A naming container control implements INamingContainer and ensures that
|
|
|
45 |
* its containee controls can be differentiated by their ID property values.
|
|
|
46 |
* Naming container and containee realtionship specifies a protocol to uniquely
|
|
|
47 |
* identify an arbitrary control on a page hierarchy by an ID path (concatenation
|
|
|
48 |
* of all naming containers' IDs and the target control's ID).
|
|
|
49 |
*
|
|
|
50 |
* Viewstate and controlstate are two approaches to preserve state across
|
|
|
51 |
* page postback requests. ViewState is mainly related with UI specific state
|
|
|
52 |
* and can be disabled if not needed. ControlState represents crucial logic state
|
|
|
53 |
* and cannot be disabled.
|
|
|
54 |
*
|
|
|
55 |
* A control is rendered via its {@link render()} method (the method is invoked
|
|
|
56 |
* by the framework.) Descendant control classes may override this method for
|
|
|
57 |
* customized rendering. By default, {@link render()} invokes {@link renderChildren()}
|
|
|
58 |
* which is responsible for rendering of children of the control.
|
|
|
59 |
* Control's {@link getVisible Visible} property governs whether the control
|
|
|
60 |
* should be rendered or not.
|
|
|
61 |
*
|
|
|
62 |
* Each control on a page will undergo a series of lifecycles, including
|
|
|
63 |
* control construction, Init, Load, PreRender, Render, and OnUnload.
|
|
|
64 |
* They work together with page lifecycles to process a page request.
|
|
|
65 |
*
|
|
|
66 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
67 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
68 |
* @package System.Web.UI
|
|
|
69 |
* @since 3.0
|
|
|
70 |
*/
|
|
|
71 |
class TControl extends TApplicationComponent implements IRenderable, IBindable
|
|
|
72 |
{
|
|
|
73 |
/**
|
|
|
74 |
* format of control ID
|
|
|
75 |
*/
|
|
|
76 |
const ID_FORMAT='/^[a-zA-Z_]\\w*$/';
|
|
|
77 |
/**
|
|
|
78 |
* separator char between IDs in a UniqueID
|
|
|
79 |
*/
|
|
|
80 |
const ID_SEPARATOR='$';
|
|
|
81 |
/**
|
|
|
82 |
* separator char between IDs in a ClientID
|
|
|
83 |
*/
|
|
|
84 |
const CLIENT_ID_SEPARATOR='_';
|
|
|
85 |
/**
|
|
|
86 |
* prefix to an ID automatically generated
|
|
|
87 |
*/
|
|
|
88 |
const AUTOMATIC_ID_PREFIX='ctl';
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* the stage of lifecycles that the control is currently at
|
|
|
92 |
*/
|
|
|
93 |
const CS_CONSTRUCTED=0;
|
|
|
94 |
const CS_CHILD_INITIALIZED=1;
|
|
|
95 |
const CS_INITIALIZED=2;
|
|
|
96 |
const CS_STATE_LOADED=3;
|
|
|
97 |
const CS_LOADED=4;
|
|
|
98 |
const CS_PRERENDERED=5;
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* State bits.
|
|
|
102 |
*/
|
|
|
103 |
const IS_ID_SET=0x01;
|
|
|
104 |
const IS_DISABLE_VIEWSTATE=0x02;
|
|
|
105 |
const IS_SKIN_APPLIED=0x04;
|
|
|
106 |
const IS_STYLESHEET_APPLIED=0x08;
|
|
|
107 |
const IS_DISABLE_THEMING=0x10;
|
|
|
108 |
const IS_CHILD_CREATED=0x20;
|
|
|
109 |
const IS_CREATING_CHILD=0x40;
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* Indexes for the rare fields.
|
|
|
113 |
* In order to save memory, rare fields will only be created if they are needed.
|
|
|
114 |
*/
|
|
|
115 |
const RF_CONTROLS=0; // child controls
|
|
|
116 |
const RF_CHILD_STATE=1; // child state field
|
|
|
117 |
const RF_NAMED_CONTROLS=2; // list of controls whose namingcontainer is this control
|
|
|
118 |
const RF_NAMED_CONTROLS_ID=3; // counter for automatic id
|
|
|
119 |
const RF_SKIN_ID=4; // skin ID
|
|
|
120 |
const RF_DATA_BINDINGS=5; // data bindings
|
|
|
121 |
const RF_EVENTS=6; // event handlers
|
|
|
122 |
const RF_CONTROLSTATE=7; // controlstate
|
|
|
123 |
const RF_NAMED_OBJECTS=8; // controls declared with ID on template
|
|
|
124 |
const RF_ADAPTER=9; // adapter
|
|
|
125 |
const RF_AUTO_BINDINGS=10; // auto data bindings
|
|
|
126 |
|
|
|
127 |
/**
|
|
|
128 |
* @var string control ID
|
|
|
129 |
*/
|
|
|
130 |
private $_id='';
|
|
|
131 |
/**
|
|
|
132 |
* @var string control unique ID
|
|
|
133 |
*/
|
|
|
134 |
private $_uid;
|
|
|
135 |
/**
|
|
|
136 |
* @var TControl parent of the control
|
|
|
137 |
*/
|
|
|
138 |
private $_parent;
|
|
|
139 |
/**
|
|
|
140 |
* @var TPage page that the control resides in
|
|
|
141 |
*/
|
|
|
142 |
private $_page;
|
|
|
143 |
/**
|
|
|
144 |
* @var TControl naming container of the control
|
|
|
145 |
*/
|
|
|
146 |
private $_namingContainer;
|
|
|
147 |
/**
|
|
|
148 |
* @var TTemplateControl control whose template contains the control
|
|
|
149 |
*/
|
|
|
150 |
private $_tplControl;
|
|
|
151 |
/**
|
|
|
152 |
* @var array viewstate data
|
|
|
153 |
*/
|
|
|
154 |
private $_viewState=array();
|
|
|
155 |
/**
|
|
|
156 |
* @var array temporary state (usually set in template)
|
|
|
157 |
*/
|
|
|
158 |
private $_tempState=array();
|
|
|
159 |
/**
|
|
|
160 |
* @var boolean whether we should keep state in viewstate
|
|
|
161 |
*/
|
|
|
162 |
private $_trackViewState=true;
|
|
|
163 |
/**
|
|
|
164 |
* @var integer the current stage of the control lifecycles
|
|
|
165 |
*/
|
|
|
166 |
private $_stage=0;
|
|
|
167 |
/**
|
|
|
168 |
* @var integer representation of the state bits
|
|
|
169 |
*/
|
|
|
170 |
private $_flags=0;
|
|
|
171 |
/**
|
|
|
172 |
* @var array a collection of rare control data
|
|
|
173 |
*/
|
|
|
174 |
private $_rf=array();
|
|
|
175 |
|
|
|
176 |
/**
|
|
|
177 |
* Constructor.
|
|
|
178 |
*/
|
|
|
179 |
public function __construct()
|
|
|
180 |
{
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
/**
|
|
|
184 |
* Returns a property value by name or a control by ID.
|
|
|
185 |
* This overrides the parent implementation by allowing accessing
|
|
|
186 |
* a control via its ID using the following syntax,
|
|
|
187 |
* <code>
|
|
|
188 |
* $menuBar=$this->menuBar;
|
|
|
189 |
* </code>
|
|
|
190 |
* Note, the control must be configured in the template
|
|
|
191 |
* with explicit ID. If the name matches both a property and a control ID,
|
|
|
192 |
* the control ID will take the precedence.
|
|
|
193 |
*
|
|
|
194 |
* @param string the property name or control ID
|
|
|
195 |
* @return mixed the property value or the target control
|
|
|
196 |
* @throws TInvalidOperationException if the property is not defined.
|
|
|
197 |
* @see registerObject
|
|
|
198 |
*/
|
|
|
199 |
public function __get($name)
|
|
|
200 |
{
|
|
|
201 |
if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name]))
|
|
|
202 |
return $this->_rf[self::RF_NAMED_OBJECTS][$name];
|
|
|
203 |
else
|
|
|
204 |
return parent::__get($name);
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
/**
|
|
|
208 |
* @return boolean whether there is an adapter for this control
|
|
|
209 |
*/
|
|
|
210 |
public function getHasAdapter()
|
|
|
211 |
{
|
|
|
212 |
return isset($this->_rf[self::RF_ADAPTER]);
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
/**
|
|
|
216 |
* @return TControlAdapter control adapter. Null if not exists.
|
|
|
217 |
*/
|
|
|
218 |
public function getAdapter()
|
|
|
219 |
{
|
|
|
220 |
return isset($this->_rf[self::RF_ADAPTER])?$this->_rf[self::RF_ADAPTER]:null;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
/**
|
|
|
224 |
* @param TControlAdapter control adapter
|
|
|
225 |
*/
|
|
|
226 |
public function setAdapter(TControlAdapter $adapter)
|
|
|
227 |
{
|
|
|
228 |
$this->_rf[self::RF_ADAPTER]=$adapter;
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
/**
|
|
|
232 |
* @return TControl the parent of this control
|
|
|
233 |
*/
|
|
|
234 |
public function getParent()
|
|
|
235 |
{
|
|
|
236 |
return $this->_parent;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
/**
|
|
|
240 |
* @return TControl the naming container of this control
|
|
|
241 |
*/
|
|
|
242 |
public function getNamingContainer()
|
|
|
243 |
{
|
|
|
244 |
if(!$this->_namingContainer && $this->_parent)
|
|
|
245 |
{
|
|
|
246 |
if($this->_parent instanceof INamingContainer)
|
|
|
247 |
$this->_namingContainer=$this->_parent;
|
|
|
248 |
else
|
|
|
249 |
$this->_namingContainer=$this->_parent->getNamingContainer();
|
|
|
250 |
}
|
|
|
251 |
return $this->_namingContainer;
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
/**
|
|
|
255 |
* @return TPage the page that contains this control
|
|
|
256 |
*/
|
|
|
257 |
public function getPage()
|
|
|
258 |
{
|
|
|
259 |
if(!$this->_page)
|
|
|
260 |
{
|
|
|
261 |
if($this->_parent)
|
|
|
262 |
$this->_page=$this->_parent->getPage();
|
|
|
263 |
else if($this->_tplControl)
|
|
|
264 |
$this->_page=$this->_tplControl->getPage();
|
|
|
265 |
}
|
|
|
266 |
return $this->_page;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
/**
|
|
|
270 |
* Sets the page for a control.
|
|
|
271 |
* Only framework developers should use this method.
|
|
|
272 |
* @param TPage the page that contains this control
|
|
|
273 |
*/
|
|
|
274 |
public function setPage($page)
|
|
|
275 |
{
|
|
|
276 |
$this->_page=$page;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
/**
|
|
|
280 |
* Sets the control whose template contains this control.
|
|
|
281 |
* Only framework developers should use this method.
|
|
|
282 |
* @param TTemplateControl the control whose template contains this control
|
|
|
283 |
*/
|
|
|
284 |
public function setTemplateControl($control)
|
|
|
285 |
{
|
|
|
286 |
$this->_tplControl=$control;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
/**
|
|
|
290 |
* @return TTemplateControl the control whose template contains this control
|
|
|
291 |
*/
|
|
|
292 |
public function getTemplateControl()
|
|
|
293 |
{
|
|
|
294 |
if(!$this->_tplControl && $this->_parent)
|
|
|
295 |
$this->_tplControl=$this->_parent->getTemplateControl();
|
|
|
296 |
return $this->_tplControl;
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
/**
|
|
|
300 |
* @return TTemplateControl the control whose template is loaded from
|
|
|
301 |
* some external storage, such as file, db, and whose template ultimately
|
|
|
302 |
* contains this control.
|
|
|
303 |
*/
|
|
|
304 |
public function getSourceTemplateControl()
|
|
|
305 |
{
|
|
|
306 |
$control=$this;
|
|
|
307 |
while(($control instanceof TControl) && ($control=$control->getTemplateControl())!==null)
|
|
|
308 |
{
|
|
|
309 |
if(($control instanceof TTemplateControl) && $control->getIsSourceTemplateControl())
|
|
|
310 |
return $control;
|
|
|
311 |
}
|
|
|
312 |
return $this->getPage();
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
/**
|
|
|
316 |
* Gets the lifecycle step the control is currently at.
|
|
|
317 |
* This method should only be used by control developers.
|
|
|
318 |
* @return integer the lifecycle step the control is currently at.
|
|
|
319 |
* The value can be CS_CONSTRUCTED, CS_CHILD_INITIALIZED, CS_INITIALIZED,
|
|
|
320 |
* CS_STATE_LOADED, CS_LOADED, CS_PRERENDERED.
|
|
|
321 |
*/
|
|
|
322 |
protected function getControlStage()
|
|
|
323 |
{
|
|
|
324 |
return $this->_stage;
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
/**
|
|
|
328 |
* Sets the lifecycle step the control is currently at.
|
|
|
329 |
* This method should only be used by control developers.
|
|
|
330 |
* @param integer the lifecycle step the control is currently at.
|
|
|
331 |
* Valid values include CS_CONSTRUCTED, CS_CHILD_INITIALIZED, CS_INITIALIZED,
|
|
|
332 |
* CS_STATE_LOADED, CS_LOADED, CS_PRERENDERED.
|
|
|
333 |
*/
|
|
|
334 |
protected function setControlStage($value)
|
|
|
335 |
{
|
|
|
336 |
$this->_stage=$value;
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
/**
|
|
|
340 |
* Returns the id of the control.
|
|
|
341 |
* Control ID can be either manually set or automatically generated.
|
|
|
342 |
* If $hideAutoID is true, automatically generated ID will be returned as an empty string.
|
|
|
343 |
* @param boolean whether to hide automatically generated ID
|
|
|
344 |
* @return string the ID of the control
|
|
|
345 |
*/
|
|
|
346 |
public function getID($hideAutoID=true)
|
|
|
347 |
{
|
|
|
348 |
if($hideAutoID)
|
|
|
349 |
return ($this->_flags & self::IS_ID_SET) ? $this->_id : '';
|
|
|
350 |
else
|
|
|
351 |
return $this->_id;
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
/**
|
|
|
355 |
* @param string the new control ID. The value must consist of word characters [a-zA-Z0-9_] only
|
|
|
356 |
* @throws TInvalidDataValueException if ID is in a bad format
|
|
|
357 |
*/
|
|
|
358 |
public function setID($id)
|
|
|
359 |
{
|
|
|
360 |
if(!preg_match(self::ID_FORMAT,$id))
|
|
|
361 |
throw new TInvalidDataValueException('control_id_invalid',get_class($this),$id);
|
|
|
362 |
$this->_id=$id;
|
|
|
363 |
$this->_flags |= self::IS_ID_SET;
|
|
|
364 |
$this->clearCachedUniqueID($this instanceof INamingContainer);
|
|
|
365 |
if($this->_namingContainer)
|
|
|
366 |
$this->_namingContainer->clearNameTable();
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
/**
|
|
|
370 |
* Returns a unique ID that identifies the control in the page hierarchy.
|
|
|
371 |
* A unique ID is the contenation of all naming container controls' IDs and the control ID.
|
|
|
372 |
* These IDs are separated by '$' character.
|
|
|
373 |
* Control users should not rely on the specific format of UniqueID, however.
|
|
|
374 |
* @return string a unique ID that identifies the control in the page hierarchy
|
|
|
375 |
*/
|
|
|
376 |
public function getUniqueID()
|
|
|
377 |
{
|
|
|
378 |
if($this->_uid==='' || $this->_uid===null) // need to build the UniqueID
|
|
|
379 |
{
|
|
|
380 |
$this->_uid=''; // set to not-null, so that clearCachedUniqueID() may take action
|
|
|
381 |
if($namingContainer=$this->getNamingContainer())
|
|
|
382 |
{
|
|
|
383 |
if($this->getPage()===$namingContainer)
|
|
|
384 |
return ($this->_uid=$this->_id);
|
|
|
385 |
else if(($prefix=$namingContainer->getUniqueID())==='')
|
|
|
386 |
return $this->_id;
|
|
|
387 |
else
|
|
|
388 |
return ($this->_uid=$prefix.self::ID_SEPARATOR.$this->_id);
|
|
|
389 |
}
|
|
|
390 |
else // no naming container
|
|
|
391 |
return $this->_id;
|
|
|
392 |
}
|
|
|
393 |
else
|
|
|
394 |
return $this->_uid;
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
/**
|
|
|
398 |
* Sets input focus to this control.
|
|
|
399 |
*/
|
|
|
400 |
public function focus()
|
|
|
401 |
{
|
|
|
402 |
$this->getPage()->setFocus($this);
|
|
|
403 |
}
|
|
|
404 |
|
|
|
405 |
/**
|
|
|
406 |
* Returns the client ID of the control.
|
|
|
407 |
* The client ID can be used to uniquely identify
|
|
|
408 |
* the control in client-side scripts (such as JavaScript).
|
|
|
409 |
* Do not rely on the explicit format of the return ID.
|
|
|
410 |
* @return string the client ID of the control
|
|
|
411 |
*/
|
|
|
412 |
public function getClientID()
|
|
|
413 |
{
|
|
|
414 |
return strtr($this->getUniqueID(),self::ID_SEPARATOR,self::CLIENT_ID_SEPARATOR);
|
|
|
415 |
}
|
|
|
416 |
|
|
|
417 |
/**
|
|
|
418 |
* Converts a unique ID to a client ID.
|
|
|
419 |
* @param string the unique ID of a control
|
|
|
420 |
* @return string the client ID of the control
|
|
|
421 |
*/
|
|
|
422 |
public static function convertUniqueIdToClientId($uniqueID)
|
|
|
423 |
{
|
|
|
424 |
return strtr($uniqueID,self::ID_SEPARATOR,self::CLIENT_ID_SEPARATOR);
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
/**
|
|
|
428 |
* @return string the skin ID of this control, '' if not set
|
|
|
429 |
*/
|
|
|
430 |
public function getSkinID()
|
|
|
431 |
{
|
|
|
432 |
return isset($this->_rf[self::RF_SKIN_ID])?$this->_rf[self::RF_SKIN_ID]:'';
|
|
|
433 |
}
|
|
|
434 |
|
|
|
435 |
/**
|
|
|
436 |
* @param string the skin ID of this control
|
|
|
437 |
* @throws TInvalidOperationException if the SkinID is set in a stage later than PreInit, or if the skin is applied already.
|
|
|
438 |
*/
|
|
|
439 |
public function setSkinID($value)
|
|
|
440 |
{
|
|
|
441 |
if(($this->_flags & self::IS_SKIN_APPLIED) || $this->_stage>=self::CS_CHILD_INITIALIZED)
|
|
|
442 |
throw new TInvalidOperationException('control_skinid_unchangeable',get_class($this));
|
|
|
443 |
else
|
|
|
444 |
$this->_rf[self::RF_SKIN_ID]=$value;
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
/**
|
|
|
448 |
* @return boolean whether theming is enabled for this control.
|
|
|
449 |
* The theming is enabled if the control and all its parents have it enabled.
|
|
|
450 |
*/
|
|
|
451 |
public function getEnableTheming()
|
|
|
452 |
{
|
|
|
453 |
if($this->_flags & self::IS_DISABLE_THEMING)
|
|
|
454 |
return false;
|
|
|
455 |
else
|
|
|
456 |
return $this->_parent?$this->_parent->getEnableTheming():true;
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
/**
|
|
|
460 |
* @param boolean whether to enable theming
|
|
|
461 |
* @throws TInvalidOperationException if this method is invoked after OnPreInit
|
|
|
462 |
*/
|
|
|
463 |
public function setEnableTheming($value)
|
|
|
464 |
{
|
|
|
465 |
if($this->_stage>=self::CS_CHILD_INITIALIZED)
|
|
|
466 |
throw new TInvalidOperationException('control_enabletheming_unchangeable',get_class($this),$this->getUniqueID());
|
|
|
467 |
else if(TPropertyValue::ensureBoolean($value))
|
|
|
468 |
$this->_flags &= ~self::IS_DISABLE_THEMING;
|
|
|
469 |
else
|
|
|
470 |
$this->_flags |= self::IS_DISABLE_THEMING;
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
/**
|
|
|
474 |
* Returns custom data associated with this control.
|
|
|
475 |
* A control may be associated with some custom data for various purposes.
|
|
|
476 |
* For example, a button may be associated with a string to identify itself
|
|
|
477 |
* in a generic OnClick event handler.
|
|
|
478 |
* @return mixed custom data associated with this control. Defaults to null.
|
|
|
479 |
*/
|
|
|
480 |
public function getCustomData()
|
|
|
481 |
{
|
|
|
482 |
return $this->getViewState('CustomData',null);
|
|
|
483 |
}
|
|
|
484 |
|
|
|
485 |
/**
|
|
|
486 |
* Associates custom data with this control.
|
|
|
487 |
* Note, the custom data must be serializable and unserializable.
|
|
|
488 |
* @param mixed custom data
|
|
|
489 |
*/
|
|
|
490 |
public function setCustomData($value)
|
|
|
491 |
{
|
|
|
492 |
$this->setViewState('CustomData',$value,null);
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
/**
|
|
|
496 |
* @return boolean whether the control has child controls
|
|
|
497 |
*/
|
|
|
498 |
public function getHasControls()
|
|
|
499 |
{
|
|
|
500 |
return isset($this->_rf[self::RF_CONTROLS]) && $this->_rf[self::RF_CONTROLS]->getCount()>0;
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
/**
|
|
|
504 |
* @return TControlCollection the child control collection
|
|
|
505 |
*/
|
|
|
506 |
public function getControls()
|
|
|
507 |
{
|
|
|
508 |
if(!isset($this->_rf[self::RF_CONTROLS]))
|
|
|
509 |
$this->_rf[self::RF_CONTROLS]=$this->createControlCollection();
|
|
|
510 |
return $this->_rf[self::RF_CONTROLS];
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
/**
|
|
|
514 |
* Creates a control collection object that is to be used to hold child controls
|
|
|
515 |
* @return TControlCollection control collection
|
|
|
516 |
* @see getControls
|
|
|
517 |
*/
|
|
|
518 |
protected function createControlCollection()
|
|
|
519 |
{
|
|
|
520 |
return $this->getAllowChildControls()?new TControlCollection($this):new TEmptyControlCollection($this);
|
|
|
521 |
}
|
|
|
522 |
|
|
|
523 |
/**
|
|
|
524 |
* Checks if a control is visible.
|
|
|
525 |
* If parent check is required, then a control is visible only if the control
|
|
|
526 |
* and all its ancestors are visible.
|
|
|
527 |
* @param boolean whether the parents should also be checked if visible
|
|
|
528 |
* @return boolean whether the control is visible (default=true).
|
|
|
529 |
*/
|
|
|
530 |
public function getVisible($checkParents=true)
|
|
|
531 |
{
|
|
|
532 |
if($checkParents)
|
|
|
533 |
{
|
|
|
534 |
for($control=$this;$control;$control=$control->_parent)
|
|
|
535 |
if(!$control->getVisible(false))
|
|
|
536 |
return false;
|
|
|
537 |
return true;
|
|
|
538 |
}
|
|
|
539 |
else
|
|
|
540 |
return $this->getViewState('Visible',true);
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
/**
|
|
|
544 |
* @param boolean whether the control is visible
|
|
|
545 |
*/
|
|
|
546 |
public function setVisible($value)
|
|
|
547 |
{
|
|
|
548 |
$this->setViewState('Visible',TPropertyValue::ensureBoolean($value),true);
|
|
|
549 |
}
|
|
|
550 |
|
|
|
551 |
/**
|
|
|
552 |
* Returns a value indicating whether the control is enabled.
|
|
|
553 |
* A control is enabled if it allows client user interaction.
|
|
|
554 |
* If $checkParents is true, all parent controls will be checked,
|
|
|
555 |
* and unless they are all enabled, false will be returned.
|
|
|
556 |
* The property Enabled is mainly used for {@link TWebControl}
|
|
|
557 |
* derived controls.
|
|
|
558 |
* @param boolean whether the parents should also be checked enabled
|
|
|
559 |
* @return boolean whether the control is enabled.
|
|
|
560 |
*/
|
|
|
561 |
public function getEnabled($checkParents=false)
|
|
|
562 |
{
|
|
|
563 |
if($checkParents)
|
|
|
564 |
{
|
|
|
565 |
for($control=$this;$control;$control=$control->_parent)
|
|
|
566 |
if(!$control->getViewState('Enabled',true))
|
|
|
567 |
return false;
|
|
|
568 |
return true;
|
|
|
569 |
}
|
|
|
570 |
else
|
|
|
571 |
return $this->getViewState('Enabled',true);
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
/**
|
|
|
575 |
* @param boolean whether the control is to be enabled.
|
|
|
576 |
*/
|
|
|
577 |
public function setEnabled($value)
|
|
|
578 |
{
|
|
|
579 |
$this->setViewState('Enabled',TPropertyValue::ensureBoolean($value),true);
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
/**
|
|
|
583 |
* @return boolean whether the control has custom attributes
|
|
|
584 |
*/
|
|
|
585 |
public function getHasAttributes()
|
|
|
586 |
{
|
|
|
587 |
if($attributes=$this->getViewState('Attributes',null))
|
|
|
588 |
return $attributes->getCount()>0;
|
|
|
589 |
else
|
|
|
590 |
return false;
|
|
|
591 |
}
|
|
|
592 |
|
|
|
593 |
/**
|
|
|
594 |
* Returns the list of custom attributes.
|
|
|
595 |
* Custom attributes are name-value pairs that may be rendered
|
|
|
596 |
* as HTML tags' attributes.
|
|
|
597 |
* @return TAttributeCollection the list of custom attributes
|
|
|
598 |
*/
|
|
|
599 |
public function getAttributes()
|
|
|
600 |
{
|
|
|
601 |
if($attributes=$this->getViewState('Attributes',null))
|
|
|
602 |
return $attributes;
|
|
|
603 |
else
|
|
|
604 |
{
|
|
|
605 |
$attributes=new TAttributeCollection;
|
|
|
606 |
$this->setViewState('Attributes',$attributes,null);
|
|
|
607 |
return $attributes;
|
|
|
608 |
}
|
|
|
609 |
}
|
|
|
610 |
|
|
|
611 |
/**
|
|
|
612 |
* @return boolean whether the named attribute exists
|
|
|
613 |
*/
|
|
|
614 |
public function hasAttribute($name)
|
|
|
615 |
{
|
|
|
616 |
if($attributes=$this->getViewState('Attributes',null))
|
|
|
617 |
return $attributes->contains($name);
|
|
|
618 |
else
|
|
|
619 |
return false;
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
/**
|
|
|
623 |
* @return string attribute value, null if attribute does not exist
|
|
|
624 |
*/
|
|
|
625 |
public function getAttribute($name)
|
|
|
626 |
{
|
|
|
627 |
if($attributes=$this->getViewState('Attributes',null))
|
|
|
628 |
return $attributes->itemAt($name);
|
|
|
629 |
else
|
|
|
630 |
return null;
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
/**
|
|
|
634 |
* Sets a custom control attribute.
|
|
|
635 |
* @param string attribute name
|
|
|
636 |
* @param string value of the attribute
|
|
|
637 |
*/
|
|
|
638 |
public function setAttribute($name,$value)
|
|
|
639 |
{
|
|
|
640 |
$this->getAttributes()->add($name,$value);
|
|
|
641 |
}
|
|
|
642 |
|
|
|
643 |
/**
|
|
|
644 |
* Removes the named attribute.
|
|
|
645 |
* @param string the name of the attribute to be removed.
|
|
|
646 |
* @return string attribute value removed, null if attribute does not exist.
|
|
|
647 |
*/
|
|
|
648 |
public function removeAttribute($name)
|
|
|
649 |
{
|
|
|
650 |
if($attributes=$this->getViewState('Attributes',null))
|
|
|
651 |
return $attributes->remove($name);
|
|
|
652 |
else
|
|
|
653 |
return null;
|
|
|
654 |
}
|
|
|
655 |
|
|
|
656 |
/**
|
|
|
657 |
* @return boolean whether viewstate is enabled
|
|
|
658 |
*/
|
|
|
659 |
public function getEnableViewState($checkParents=false)
|
|
|
660 |
{
|
|
|
661 |
if($checkParents)
|
|
|
662 |
{
|
|
|
663 |
for($control=$this;$control!==null;$control=$control->getParent())
|
|
|
664 |
if($control->_flags & self::IS_DISABLE_VIEWSTATE)
|
|
|
665 |
return false;
|
|
|
666 |
return true;
|
|
|
667 |
}
|
|
|
668 |
else
|
|
|
669 |
return !($this->_flags & self::IS_DISABLE_VIEWSTATE);
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
/**
|
|
|
673 |
* @param boolean set whether to enable viewstate
|
|
|
674 |
*/
|
|
|
675 |
public function setEnableViewState($value)
|
|
|
676 |
{
|
|
|
677 |
if(TPropertyValue::ensureBoolean($value))
|
|
|
678 |
$this->_flags &= ~self::IS_DISABLE_VIEWSTATE;
|
|
|
679 |
else
|
|
|
680 |
$this->_flags |= self::IS_DISABLE_VIEWSTATE;
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
/**
|
|
|
684 |
* Returns a controlstate value.
|
|
|
685 |
*
|
|
|
686 |
* This function is mainly used in defining getter functions for control properties
|
|
|
687 |
* that must be kept in controlstate.
|
|
|
688 |
* @param string the name of the controlstate value to be returned
|
|
|
689 |
* @param mixed the default value. If $key is not found in controlstate, $defaultValue will be returned
|
|
|
690 |
* @return mixed the controlstate value corresponding to $key
|
|
|
691 |
*/
|
|
|
692 |
protected function getControlState($key,$defaultValue=null)
|
|
|
693 |
{
|
|
|
694 |
return isset($this->_rf[self::RF_CONTROLSTATE][$key])?$this->_rf[self::RF_CONTROLSTATE][$key]:$defaultValue;
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
/**
|
|
|
698 |
* Sets a controlstate value.
|
|
|
699 |
*
|
|
|
700 |
* This function is very useful in defining setter functions for control properties
|
|
|
701 |
* that must be kept in controlstate.
|
|
|
702 |
* Make sure that the controlstate value must be serializable and unserializable.
|
|
|
703 |
* @param string the name of the controlstate value
|
|
|
704 |
* @param mixed the controlstate value to be set
|
|
|
705 |
* @param mixed default value. If $value===$defaultValue, the item will be cleared from controlstate
|
|
|
706 |
*/
|
|
|
707 |
protected function setControlState($key,$value,$defaultValue=null)
|
|
|
708 |
{
|
|
|
709 |
if($value===$defaultValue)
|
|
|
710 |
unset($this->_rf[self::RF_CONTROLSTATE][$key]);
|
|
|
711 |
else
|
|
|
712 |
$this->_rf[self::RF_CONTROLSTATE][$key]=$value;
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
/**
|
|
|
716 |
* Clears a controlstate value.
|
|
|
717 |
* @param string the name of the controlstate value to be cleared
|
|
|
718 |
*/
|
|
|
719 |
protected function clearControlState($key)
|
|
|
720 |
{
|
|
|
721 |
unset($this->_rf[self::RF_CONTROLSTATE][$key]);
|
|
|
722 |
}
|
|
|
723 |
|
|
|
724 |
/**
|
|
|
725 |
* Sets a value indicating whether we should keep data in viewstate.
|
|
|
726 |
* When it is false, data saved via setViewState() will not be persisted.
|
|
|
727 |
* By default, it is true, meaning data will be persisted across postbacks.
|
|
|
728 |
* @param boolean whether data should be persisted
|
|
|
729 |
*/
|
|
|
730 |
public function trackViewState($enabled)
|
|
|
731 |
{
|
|
|
732 |
$this->_trackViewState=TPropertyValue::ensureBoolean($enabled);
|
|
|
733 |
}
|
|
|
734 |
|
|
|
735 |
/**
|
|
|
736 |
* Returns a viewstate value.
|
|
|
737 |
*
|
|
|
738 |
* This function is very useful in defining getter functions for component properties
|
|
|
739 |
* that must be kept in viewstate.
|
|
|
740 |
* @param string the name of the viewstate value to be returned
|
|
|
741 |
* @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
|
|
|
742 |
* @return mixed the viewstate value corresponding to $key
|
|
|
743 |
*/
|
|
|
744 |
public function getViewState($key,$defaultValue=null)
|
|
|
745 |
{
|
|
|
746 |
if(isset($this->_viewState[$key]))
|
|
|
747 |
return $this->_viewState[$key]!==null?$this->_viewState[$key]:$defaultValue;
|
|
|
748 |
else if(isset($this->_tempState[$key]))
|
|
|
749 |
{
|
|
|
750 |
if(is_object($this->_tempState[$key]) && $this->_trackViewState)
|
|
|
751 |
$this->_viewState[$key]=$this->_tempState[$key];
|
|
|
752 |
return $this->_tempState[$key];
|
|
|
753 |
}
|
|
|
754 |
else
|
|
|
755 |
return $defaultValue;
|
|
|
756 |
}
|
|
|
757 |
|
|
|
758 |
/**
|
|
|
759 |
* Sets a viewstate value.
|
|
|
760 |
*
|
|
|
761 |
* This function is very useful in defining setter functions for control properties
|
|
|
762 |
* that must be kept in viewstate.
|
|
|
763 |
* Make sure that the viewstate value must be serializable and unserializable.
|
|
|
764 |
* @param string the name of the viewstate value
|
|
|
765 |
* @param mixed the viewstate value to be set
|
|
|
766 |
* @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
|
|
|
767 |
*/
|
|
|
768 |
public function setViewState($key,$value,$defaultValue=null)
|
|
|
769 |
{
|
|
|
770 |
if($this->_trackViewState)
|
|
|
771 |
{
|
|
|
772 |
$this->_viewState[$key]=$value;
|
|
|
773 |
unset($this->_tempState[$key]);
|
|
|
774 |
}
|
|
|
775 |
else
|
|
|
776 |
{
|
|
|
777 |
unset($this->_viewState[$key]);
|
|
|
778 |
$this->_tempState[$key]=$value;
|
|
|
779 |
}
|
|
|
780 |
}
|
|
|
781 |
|
|
|
782 |
/**
|
|
|
783 |
* Clears a viewstate value.
|
|
|
784 |
* @param string the name of the viewstate value to be cleared
|
|
|
785 |
*/
|
|
|
786 |
public function clearViewState($key)
|
|
|
787 |
{
|
|
|
788 |
unset($this->_viewState[$key]);
|
|
|
789 |
unset($this->_tempState[$key]);
|
|
|
790 |
}
|
|
|
791 |
|
|
|
792 |
/**
|
|
|
793 |
* Sets up the binding between a property (or property path) and an expression.
|
|
|
794 |
* The context of the expression is the template control (or the control itself if it is a page).
|
|
|
795 |
* @param string the property name, or property path
|
|
|
796 |
* @param string the expression
|
|
|
797 |
*/
|
|
|
798 |
public function bindProperty($name,$expression)
|
|
|
799 |
{
|
|
|
800 |
$this->_rf[self::RF_DATA_BINDINGS][$name]=$expression;
|
|
|
801 |
}
|
|
|
802 |
|
|
|
803 |
/**
|
|
|
804 |
* Breaks the binding between a property (or property path) and an expression.
|
|
|
805 |
* @param string the property name (or property path)
|
|
|
806 |
*/
|
|
|
807 |
public function unbindProperty($name)
|
|
|
808 |
{
|
|
|
809 |
unset($this->_rf[self::RF_DATA_BINDINGS][$name]);
|
|
|
810 |
}
|
|
|
811 |
|
|
|
812 |
/**
|
|
|
813 |
* Sets up the binding between a property (or property path) and an expression.
|
|
|
814 |
* Unlike regular databinding, the expression bound by this method
|
|
|
815 |
* is automatically evaluated during {@link prerenderRecursive()}.
|
|
|
816 |
* The context of the expression is the template control (or the control itself if it is a page).
|
|
|
817 |
* @param string the property name, or property path
|
|
|
818 |
* @param string the expression
|
|
|
819 |
*/
|
|
|
820 |
public function autoBindProperty($name,$expression)
|
|
|
821 |
{
|
|
|
822 |
$this->_rf[self::RF_AUTO_BINDINGS][$name]=$expression;
|
|
|
823 |
}
|
|
|
824 |
|
|
|
825 |
/**
|
|
|
826 |
* Performs the databinding for this control.
|
|
|
827 |
*/
|
|
|
828 |
public function dataBind()
|
|
|
829 |
{
|
|
|
830 |
$this->dataBindProperties();
|
|
|
831 |
$this->onDataBinding(null);
|
|
|
832 |
$this->dataBindChildren();
|
|
|
833 |
}
|
|
|
834 |
|
|
|
835 |
/**
|
|
|
836 |
* Databinding properties of the control.
|
|
|
837 |
*/
|
|
|
838 |
protected function dataBindProperties()
|
|
|
839 |
{
|
|
|
840 |
Prado::trace("Data bind properties",'System.Web.UI.TControl');
|
|
|
841 |
if(isset($this->_rf[self::RF_DATA_BINDINGS]))
|
|
|
842 |
{
|
|
|
843 |
if(($context=$this->getTemplateControl())===null)
|
|
|
844 |
$context=$this;
|
|
|
845 |
foreach($this->_rf[self::RF_DATA_BINDINGS] as $property=>$expression)
|
|
|
846 |
$this->setSubProperty($property,$context->evaluateExpression($expression));
|
|
|
847 |
}
|
|
|
848 |
}
|
|
|
849 |
|
|
|
850 |
/**
|
|
|
851 |
* Auto databinding properties of the control.
|
|
|
852 |
*/
|
|
|
853 |
protected function autoDataBindProperties()
|
|
|
854 |
{
|
|
|
855 |
if(isset($this->_rf[self::RF_AUTO_BINDINGS]))
|
|
|
856 |
{
|
|
|
857 |
if(($context=$this->getTemplateControl())===null)
|
|
|
858 |
$context=$this;
|
|
|
859 |
foreach($this->_rf[self::RF_AUTO_BINDINGS] as $property=>$expression)
|
|
|
860 |
$this->setSubProperty($property,$context->evaluateExpression($expression));
|
|
|
861 |
}
|
|
|
862 |
}
|
|
|
863 |
|
|
|
864 |
/**
|
|
|
865 |
* Databinding child controls.
|
|
|
866 |
*/
|
|
|
867 |
protected function dataBindChildren()
|
|
|
868 |
{
|
|
|
869 |
Prado::trace("dataBindChildren()",'System.Web.UI.TControl');
|
|
|
870 |
if(isset($this->_rf[self::RF_CONTROLS]))
|
|
|
871 |
{
|
|
|
872 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
873 |
if($control instanceof IBindable)
|
|
|
874 |
$control->dataBind();
|
|
|
875 |
}
|
|
|
876 |
}
|
|
|
877 |
|
|
|
878 |
/**
|
|
|
879 |
* @return boolean whether child controls have been created
|
|
|
880 |
*/
|
|
|
881 |
final protected function getChildControlsCreated()
|
|
|
882 |
{
|
|
|
883 |
return ($this->_flags & self::IS_CHILD_CREATED)!==0;
|
|
|
884 |
}
|
|
|
885 |
|
|
|
886 |
/**
|
|
|
887 |
* Sets a value indicating whether child controls are created.
|
|
|
888 |
* If false, any existing child controls will be cleared up.
|
|
|
889 |
* @param boolean whether child controls are created
|
|
|
890 |
*/
|
|
|
891 |
final protected function setChildControlsCreated($value)
|
|
|
892 |
{
|
|
|
893 |
if($value)
|
|
|
894 |
$this->_flags |= self::IS_CHILD_CREATED;
|
|
|
895 |
else
|
|
|
896 |
{
|
|
|
897 |
if($this->getHasControls() && ($this->_flags & self::IS_CHILD_CREATED))
|
|
|
898 |
$this->getControls()->clear();
|
|
|
899 |
$this->_flags &= ~self::IS_CHILD_CREATED;
|
|
|
900 |
}
|
|
|
901 |
}
|
|
|
902 |
|
|
|
903 |
/**
|
|
|
904 |
* Ensures child controls are created.
|
|
|
905 |
* If child controls are not created yet, this method will invoke
|
|
|
906 |
* {@link createChildControls} to create them.
|
|
|
907 |
*/
|
|
|
908 |
public function ensureChildControls()
|
|
|
909 |
{
|
|
|
910 |
if(!($this->_flags & self::IS_CHILD_CREATED) && !($this->_flags & self::IS_CREATING_CHILD))
|
|
|
911 |
{
|
|
|
912 |
try
|
|
|
913 |
{
|
|
|
914 |
$this->_flags |= self::IS_CREATING_CHILD;
|
|
|
915 |
if(isset($this->_rf[self::RF_ADAPTER]))
|
|
|
916 |
$this->_rf[self::RF_ADAPTER]->createChildControls();
|
|
|
917 |
else
|
|
|
918 |
$this->createChildControls();
|
|
|
919 |
$this->_flags &= ~self::IS_CREATING_CHILD;
|
|
|
920 |
$this->_flags |= self::IS_CHILD_CREATED;
|
|
|
921 |
}
|
|
|
922 |
catch(Exception $e)
|
|
|
923 |
{
|
|
|
924 |
$this->_flags &= ~self::IS_CREATING_CHILD;
|
|
|
925 |
$this->_flags |= self::IS_CHILD_CREATED;
|
|
|
926 |
throw $e;
|
|
|
927 |
}
|
|
|
928 |
}
|
|
|
929 |
}
|
|
|
930 |
|
|
|
931 |
/**
|
|
|
932 |
* Creates child controls.
|
|
|
933 |
* This method can be overriden for controls who want to have their controls.
|
|
|
934 |
* Do not call this method directly. Instead, call {@link ensureChildControls}
|
|
|
935 |
* to ensure child controls are created only once.
|
|
|
936 |
*/
|
|
|
937 |
public function createChildControls()
|
|
|
938 |
{
|
|
|
939 |
}
|
|
|
940 |
|
|
|
941 |
/**
|
|
|
942 |
* Finds a control by ID path within the current naming container.
|
|
|
943 |
* The current naming container is either the control itself
|
|
|
944 |
* if it implements {@link INamingContainer} or the control's naming container.
|
|
|
945 |
* The ID path is an ID sequence separated by {@link TControl::ID_SEPARATOR}.
|
|
|
946 |
* For example, 'Repeater1.Item1.Button1' looks for a control with ID 'Button1'
|
|
|
947 |
* whose naming container is 'Item1' whose naming container is 'Repeater1'.
|
|
|
948 |
* @param string ID of the control to be looked up
|
|
|
949 |
* @return TControl|null the control found, null if not found
|
|
|
950 |
* @throws TInvalidDataValueException if a control's ID is found not unique within its naming container.
|
|
|
951 |
*/
|
|
|
952 |
public function findControl($id)
|
|
|
953 |
{
|
|
|
954 |
$id=strtr($id,'.',self::ID_SEPARATOR);
|
|
|
955 |
$container=($this instanceof INamingContainer)?$this:$this->getNamingContainer();
|
|
|
956 |
if(!$container || !$container->getHasControls())
|
|
|
957 |
return null;
|
|
|
958 |
if(!isset($container->_rf[self::RF_NAMED_CONTROLS]))
|
|
|
959 |
{
|
|
|
960 |
$container->_rf[self::RF_NAMED_CONTROLS]=array();
|
|
|
961 |
$container->fillNameTable($container,$container->_rf[self::RF_CONTROLS]);
|
|
|
962 |
}
|
|
|
963 |
if(($pos=strpos($id,self::ID_SEPARATOR))===false)
|
|
|
964 |
return isset($container->_rf[self::RF_NAMED_CONTROLS][$id])?$container->_rf[self::RF_NAMED_CONTROLS][$id]:null;
|
|
|
965 |
else
|
|
|
966 |
{
|
|
|
967 |
$cid=substr($id,0,$pos);
|
|
|
968 |
$sid=substr($id,$pos+1);
|
|
|
969 |
if(isset($container->_rf[self::RF_NAMED_CONTROLS][$cid]))
|
|
|
970 |
return $container->_rf[self::RF_NAMED_CONTROLS][$cid]->findControl($sid);
|
|
|
971 |
else
|
|
|
972 |
return null;
|
|
|
973 |
}
|
|
|
974 |
}
|
|
|
975 |
|
|
|
976 |
/**
|
|
|
977 |
* Finds all child and grand-child controls that are of the specified type.
|
|
|
978 |
* @param string the class name
|
|
|
979 |
* @param boolean whether the type comparison is strict or not. If false, controls of the parent classes of the specified class will also be returned.
|
|
|
980 |
* @return array list of controls found
|
|
|
981 |
*/
|
|
|
982 |
public function findControlsByType($type,$strict=true)
|
|
|
983 |
{
|
|
|
984 |
$controls=array();
|
|
|
985 |
if($this->getHasControls())
|
|
|
986 |
{
|
|
|
987 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
988 |
{
|
|
|
989 |
if(is_object($control) && (get_class($control)===$type || (!$strict && ($control instanceof $type))))
|
|
|
990 |
$controls[]=$control;
|
|
|
991 |
if(($control instanceof TControl) && $control->getHasControls())
|
|
|
992 |
$controls=array_merge($controls,$control->findControlsByType($type,$strict));
|
|
|
993 |
}
|
|
|
994 |
}
|
|
|
995 |
return $controls;
|
|
|
996 |
}
|
|
|
997 |
|
|
|
998 |
/**
|
|
|
999 |
* Finds all child and grand-child controls with the specified ID.
|
|
|
1000 |
* Note, this method is different from {@link findControl} in that
|
|
|
1001 |
* it searches through all controls that have this control as the ancestor
|
|
|
1002 |
* while {@link findcontrol} only searches through controls that have this
|
|
|
1003 |
* control as the direct naming container.
|
|
|
1004 |
* @param string the ID being looked for
|
|
|
1005 |
* @return array list of controls found
|
|
|
1006 |
*/
|
|
|
1007 |
public function findControlsByID($id)
|
|
|
1008 |
{
|
|
|
1009 |
$controls=array();
|
|
|
1010 |
if($this->getHasControls())
|
|
|
1011 |
{
|
|
|
1012 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1013 |
{
|
|
|
1014 |
if($control instanceof TControl)
|
|
|
1015 |
{
|
|
|
1016 |
if($control->_id===$id)
|
|
|
1017 |
$controls[]=$control;
|
|
|
1018 |
$controls=array_merge($controls,$control->findControlsByID($id));
|
|
|
1019 |
}
|
|
|
1020 |
}
|
|
|
1021 |
}
|
|
|
1022 |
return $controls;
|
|
|
1023 |
}
|
|
|
1024 |
|
|
|
1025 |
/**
|
|
|
1026 |
* Resets the control as a naming container.
|
|
|
1027 |
* Only framework developers should use this method.
|
|
|
1028 |
*/
|
|
|
1029 |
public function clearNamingContainer()
|
|
|
1030 |
{
|
|
|
1031 |
unset($this->_rf[self::RF_NAMED_CONTROLS_ID]);
|
|
|
1032 |
$this->clearNameTable();
|
|
|
1033 |
}
|
|
|
1034 |
|
|
|
1035 |
/**
|
|
|
1036 |
* Registers an object by a name.
|
|
|
1037 |
* A registered object can be accessed like a public member variable.
|
|
|
1038 |
* This method should only be used by framework and control developers.
|
|
|
1039 |
* @param string name of the object
|
|
|
1040 |
* @param object object to be declared
|
|
|
1041 |
* @see __get
|
|
|
1042 |
*/
|
|
|
1043 |
public function registerObject($name,$object)
|
|
|
1044 |
{
|
|
|
1045 |
if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name]))
|
|
|
1046 |
throw new TInvalidOperationException('control_object_reregistered',$name);
|
|
|
1047 |
$this->_rf[self::RF_NAMED_OBJECTS][$name]=$object;
|
|
|
1048 |
}
|
|
|
1049 |
|
|
|
1050 |
/**
|
|
|
1051 |
* Unregisters an object by name.
|
|
|
1052 |
* @param string name of the object
|
|
|
1053 |
* @see registerObject
|
|
|
1054 |
*/
|
|
|
1055 |
public function unregisterObject($name)
|
|
|
1056 |
{
|
|
|
1057 |
unset($this->_rf[self::RF_NAMED_OBJECTS][$name]);
|
|
|
1058 |
}
|
|
|
1059 |
|
|
|
1060 |
/**
|
|
|
1061 |
* @return boolean whether an object has been registered with the name
|
|
|
1062 |
* @see registerObject
|
|
|
1063 |
*/
|
|
|
1064 |
public function isObjectRegistered($name)
|
|
|
1065 |
{
|
|
|
1066 |
return isset($this->_rf[self::RF_NAMED_OBJECTS][$name]);
|
|
|
1067 |
}
|
|
|
1068 |
|
|
|
1069 |
/**
|
|
|
1070 |
* @return boolean true if the child control has been initialized.
|
|
|
1071 |
*/
|
|
|
1072 |
public function getHasChildInitialized()
|
|
|
1073 |
{
|
|
|
1074 |
return $this->getControlStage() >= self::CS_CHILD_INITIALIZED;
|
|
|
1075 |
}
|
|
|
1076 |
|
|
|
1077 |
/**
|
|
|
1078 |
* @return boolean true if the onInit event has raised.
|
|
|
1079 |
*/
|
|
|
1080 |
public function getHasInitialized()
|
|
|
1081 |
{
|
|
|
1082 |
return $this->getControlStage() >= self::CS_INITIALIZED;
|
|
|
1083 |
}
|
|
|
1084 |
|
|
|
1085 |
/**
|
|
|
1086 |
* @return boolean true if the control has loaded post data.
|
|
|
1087 |
*/
|
|
|
1088 |
public function getHasLoadedPostData()
|
|
|
1089 |
{
|
|
|
1090 |
return $this->getControlStage() >= self::CS_STATE_LOADED;
|
|
|
1091 |
}
|
|
|
1092 |
|
|
|
1093 |
/**
|
|
|
1094 |
* @return boolean true if the onLoad event has raised.
|
|
|
1095 |
*/
|
|
|
1096 |
public function getHasLoaded()
|
|
|
1097 |
{
|
|
|
1098 |
return $this->getControlStage() >= self::CS_LOADED;
|
|
|
1099 |
}
|
|
|
1100 |
|
|
|
1101 |
/**
|
|
|
1102 |
* @return boolean true if onPreRender event has raised.
|
|
|
1103 |
*/
|
|
|
1104 |
public function getHasPreRendered()
|
|
|
1105 |
{
|
|
|
1106 |
return $this->getControlStage() >= self::CS_PRERENDERED;
|
|
|
1107 |
}
|
|
|
1108 |
|
|
|
1109 |
/**
|
|
|
1110 |
* Returns the named registered object.
|
|
|
1111 |
* A component with explicit ID on a template will be registered to
|
|
|
1112 |
* the template owner. This method allows you to obtain this component
|
|
|
1113 |
* with the ID.
|
|
|
1114 |
* @return mixed the named registered object. Null if object is not found.
|
|
|
1115 |
*/
|
|
|
1116 |
public function getRegisteredObject($name)
|
|
|
1117 |
{
|
|
|
1118 |
return isset($this->_rf[self::RF_NAMED_OBJECTS][$name])?$this->_rf[self::RF_NAMED_OBJECTS][$name]:null;
|
|
|
1119 |
}
|
|
|
1120 |
|
|
|
1121 |
/**
|
|
|
1122 |
* @return boolean whether body contents are allowed for this control. Defaults to true.
|
|
|
1123 |
*/
|
|
|
1124 |
public function getAllowChildControls()
|
|
|
1125 |
{
|
|
|
1126 |
return true;
|
|
|
1127 |
}
|
|
|
1128 |
|
|
|
1129 |
/**
|
|
|
1130 |
* Adds the object instantiated on a template to the child control collection.
|
|
|
1131 |
* This method overrides the parent implementation.
|
|
|
1132 |
* Only framework developers and control developers should use this method.
|
|
|
1133 |
* @param string|TComponent text string or component parsed and instantiated in template
|
|
|
1134 |
* @see createdOnTemplate
|
|
|
1135 |
*/
|
|
|
1136 |
public function addParsedObject($object)
|
|
|
1137 |
{
|
|
|
1138 |
$this->getControls()->add($object);
|
|
|
1139 |
}
|
|
|
1140 |
|
|
|
1141 |
/**
|
|
|
1142 |
* Clears up the child state data.
|
|
|
1143 |
* After a control loads its state, those state that do not belong to
|
|
|
1144 |
* any existing child controls are stored as child state.
|
|
|
1145 |
* This method will remove these state.
|
|
|
1146 |
* Only frameworker developers and control developers should use this method.
|
|
|
1147 |
*/
|
|
|
1148 |
final protected function clearChildState()
|
|
|
1149 |
{
|
|
|
1150 |
unset($this->_rf[self::RF_CHILD_STATE]);
|
|
|
1151 |
}
|
|
|
1152 |
|
|
|
1153 |
/**
|
|
|
1154 |
* @param TControl the potential ancestor control
|
|
|
1155 |
* @return boolean if the control is a descendent (parent, parent of parent, etc.)
|
|
|
1156 |
* of the specified control
|
|
|
1157 |
*/
|
|
|
1158 |
final protected function isDescendentOf($ancestor)
|
|
|
1159 |
{
|
|
|
1160 |
$control=$this;
|
|
|
1161 |
while($control!==$ancestor && $control->_parent)
|
|
|
1162 |
$control=$control->_parent;
|
|
|
1163 |
return $control===$ancestor;
|
|
|
1164 |
}
|
|
|
1165 |
|
|
|
1166 |
/**
|
|
|
1167 |
* Adds a control into the child collection of the control.
|
|
|
1168 |
* Control lifecycles will be caught up during the addition.
|
|
|
1169 |
* Only framework developers should use this method.
|
|
|
1170 |
* @param TControl the new child control
|
|
|
1171 |
*/
|
|
|
1172 |
public function addedControl($control)
|
|
|
1173 |
{
|
|
|
1174 |
if($control->_parent)
|
|
|
1175 |
$control->_parent->getControls()->remove($control);
|
|
|
1176 |
$control->_parent=$this;
|
|
|
1177 |
$control->_page=$this->getPage();
|
|
|
1178 |
$namingContainer=($this instanceof INamingContainer)?$this:$this->_namingContainer;
|
|
|
1179 |
if($namingContainer)
|
|
|
1180 |
{
|
|
|
1181 |
$control->_namingContainer=$namingContainer;
|
|
|
1182 |
if($control->_id==='')
|
|
|
1183 |
$control->generateAutomaticID();
|
|
|
1184 |
else
|
|
|
1185 |
$namingContainer->clearNameTable();
|
|
|
1186 |
$control->clearCachedUniqueID($control instanceof INamingContainer);
|
|
|
1187 |
}
|
|
|
1188 |
|
|
|
1189 |
if($this->_stage>=self::CS_CHILD_INITIALIZED)
|
|
|
1190 |
{
|
|
|
1191 |
$control->initRecursive($namingContainer);
|
|
|
1192 |
if($this->_stage>=self::CS_STATE_LOADED)
|
|
|
1193 |
{
|
|
|
1194 |
if(isset($this->_rf[self::RF_CHILD_STATE][$control->_id]))
|
|
|
1195 |
{
|
|
|
1196 |
$state=$this->_rf[self::RF_CHILD_STATE][$control->_id];
|
|
|
1197 |
unset($this->_rf[self::RF_CHILD_STATE][$control->_id]);
|
|
|
1198 |
}
|
|
|
1199 |
else
|
|
|
1200 |
$state=null;
|
|
|
1201 |
$control->loadStateRecursive($state,!($this->_flags & self::IS_DISABLE_VIEWSTATE));
|
|
|
1202 |
if($this->_stage>=self::CS_LOADED)
|
|
|
1203 |
{
|
|
|
1204 |
$control->loadRecursive();
|
|
|
1205 |
if($this->_stage>=self::CS_PRERENDERED)
|
|
|
1206 |
$control->preRenderRecursive();
|
|
|
1207 |
}
|
|
|
1208 |
}
|
|
|
1209 |
}
|
|
|
1210 |
}
|
|
|
1211 |
|
|
|
1212 |
/**
|
|
|
1213 |
* Removes a control from the child collection of the control.
|
|
|
1214 |
* Only framework developers should use this method.
|
|
|
1215 |
* @param TControl the child control removed
|
|
|
1216 |
*/
|
|
|
1217 |
public function removedControl($control)
|
|
|
1218 |
{
|
|
|
1219 |
if($this->_namingContainer)
|
|
|
1220 |
$this->_namingContainer->clearNameTable();
|
|
|
1221 |
$control->unloadRecursive();
|
|
|
1222 |
$control->_parent=null;
|
|
|
1223 |
$control->_page=null;
|
|
|
1224 |
$control->_namingContainer=null;
|
|
|
1225 |
$control->_tplControl=null;
|
|
|
1226 |
//$control->_stage=self::CS_CONSTRUCTED;
|
|
|
1227 |
if(!($control->_flags & self::IS_ID_SET))
|
|
|
1228 |
$control->_id='';
|
|
|
1229 |
else
|
|
|
1230 |
unset($this->_rf[self::RF_NAMED_OBJECTS][$control->_id]);
|
|
|
1231 |
$control->clearCachedUniqueID(true);
|
|
|
1232 |
}
|
|
|
1233 |
|
|
|
1234 |
/**
|
|
|
1235 |
* Performs the Init step for the control and all its child controls.
|
|
|
1236 |
* Only framework developers should use this method.
|
|
|
1237 |
* @param TControl the naming container control
|
|
|
1238 |
*/
|
|
|
1239 |
protected function initRecursive($namingContainer=null)
|
|
|
1240 |
{
|
|
|
1241 |
$this->ensureChildControls();
|
|
|
1242 |
if($this->getHasControls())
|
|
|
1243 |
{
|
|
|
1244 |
if($this instanceof INamingContainer)
|
|
|
1245 |
$namingContainer=$this;
|
|
|
1246 |
$page=$this->getPage();
|
|
|
1247 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1248 |
{
|
|
|
1249 |
if($control instanceof TControl)
|
|
|
1250 |
{
|
|
|
1251 |
$control->_namingContainer=$namingContainer;
|
|
|
1252 |
$control->_page=$page;
|
|
|
1253 |
if($control->_id==='' && $namingContainer)
|
|
|
1254 |
$control->generateAutomaticID();
|
|
|
1255 |
$control->initRecursive($namingContainer);
|
|
|
1256 |
}
|
|
|
1257 |
}
|
|
|
1258 |
}
|
|
|
1259 |
if($this->_stage<self::CS_INITIALIZED)
|
|
|
1260 |
{
|
|
|
1261 |
$this->_stage=self::CS_CHILD_INITIALIZED;
|
|
|
1262 |
if(($page=$this->getPage()) && $this->getEnableTheming() && !($this->_flags & self::IS_SKIN_APPLIED))
|
|
|
1263 |
{
|
|
|
1264 |
$page->applyControlSkin($this);
|
|
|
1265 |
$this->_flags |= self::IS_SKIN_APPLIED;
|
|
|
1266 |
}
|
|
|
1267 |
if(isset($this->_rf[self::RF_ADAPTER]))
|
|
|
1268 |
$this->_rf[self::RF_ADAPTER]->onInit(null);
|
|
|
1269 |
else
|
|
|
1270 |
$this->onInit(null);
|
|
|
1271 |
$this->_stage=self::CS_INITIALIZED;
|
|
|
1272 |
}
|
|
|
1273 |
}
|
|
|
1274 |
|
|
|
1275 |
/**
|
|
|
1276 |
* Performs the Load step for the control and all its child controls.
|
|
|
1277 |
* Only framework developers should use this method.
|
|
|
1278 |
*/
|
|
|
1279 |
protected function loadRecursive()
|
|
|
1280 |
{
|
|
|
1281 |
if($this->_stage<self::CS_LOADED)
|
|
|
1282 |
{
|
|
|
1283 |
if(isset($this->_rf[self::RF_ADAPTER]))
|
|
|
1284 |
$this->_rf[self::RF_ADAPTER]->onLoad(null);
|
|
|
1285 |
else
|
|
|
1286 |
$this->onLoad(null);
|
|
|
1287 |
}
|
|
|
1288 |
if($this->getHasControls())
|
|
|
1289 |
{
|
|
|
1290 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1291 |
{
|
|
|
1292 |
if($control instanceof TControl)
|
|
|
1293 |
$control->loadRecursive();
|
|
|
1294 |
}
|
|
|
1295 |
}
|
|
|
1296 |
if($this->_stage<self::CS_LOADED)
|
|
|
1297 |
$this->_stage=self::CS_LOADED;
|
|
|
1298 |
}
|
|
|
1299 |
|
|
|
1300 |
/**
|
|
|
1301 |
* Performs the PreRender step for the control and all its child controls.
|
|
|
1302 |
* Only framework developers should use this method.
|
|
|
1303 |
*/
|
|
|
1304 |
protected function preRenderRecursive()
|
|
|
1305 |
{
|
|
|
1306 |
$this->autoDataBindProperties();
|
|
|
1307 |
|
|
|
1308 |
if($this->getVisible(false))
|
|
|
1309 |
{
|
|
|
1310 |
if(isset($this->_rf[self::RF_ADAPTER]))
|
|
|
1311 |
$this->_rf[self::RF_ADAPTER]->onPreRender(null);
|
|
|
1312 |
else
|
|
|
1313 |
$this->onPreRender(null);
|
|
|
1314 |
if($this->getHasControls())
|
|
|
1315 |
{
|
|
|
1316 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1317 |
{
|
|
|
1318 |
if($control instanceof TControl)
|
|
|
1319 |
$control->preRenderRecursive();
|
|
|
1320 |
else if($control instanceof TCompositeLiteral)
|
|
|
1321 |
$control->evaluateDynamicContent();
|
|
|
1322 |
}
|
|
|
1323 |
}
|
|
|
1324 |
$this->addToPostDataLoader();
|
|
|
1325 |
}
|
|
|
1326 |
$this->_stage=self::CS_PRERENDERED;
|
|
|
1327 |
}
|
|
|
1328 |
|
|
|
1329 |
/**
|
|
|
1330 |
* Add controls implementing IPostBackDataHandler to post data loaders.
|
|
|
1331 |
*/
|
|
|
1332 |
protected function addToPostDataLoader()
|
|
|
1333 |
{
|
|
|
1334 |
if($this instanceof IPostBackDataHandler)
|
|
|
1335 |
$this->getPage()->registerPostDataLoader($this);
|
|
|
1336 |
}
|
|
|
1337 |
|
|
|
1338 |
/**
|
|
|
1339 |
* Performs the Unload step for the control and all its child controls.
|
|
|
1340 |
* Only framework developers should use this method.
|
|
|
1341 |
*/
|
|
|
1342 |
protected function unloadRecursive()
|
|
|
1343 |
{
|
|
|
1344 |
if(!($this->_flags & self::IS_ID_SET))
|
|
|
1345 |
$this->_id='';
|
|
|
1346 |
if($this->getHasControls())
|
|
|
1347 |
{
|
|
|
1348 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1349 |
if($control instanceof TControl)
|
|
|
1350 |
$control->unloadRecursive();
|
|
|
1351 |
}
|
|
|
1352 |
if(isset($this->_rf[self::RF_ADAPTER]))
|
|
|
1353 |
$this->_rf[self::RF_ADAPTER]->onUnload(null);
|
|
|
1354 |
else
|
|
|
1355 |
$this->onUnload(null);
|
|
|
1356 |
}
|
|
|
1357 |
|
|
|
1358 |
/**
|
|
|
1359 |
* This method is invoked when the control enters 'OnInit' stage.
|
|
|
1360 |
* The method raises 'OnInit' event.
|
|
|
1361 |
* If you override this method, be sure to call the parent implementation
|
|
|
1362 |
* so that the event handlers can be invoked.
|
|
|
1363 |
* @param TEventParameter event parameter to be passed to the event handlers
|
|
|
1364 |
*/
|
|
|
1365 |
public function onInit($param)
|
|
|
1366 |
{
|
|
|
1367 |
$this->raiseEvent('OnInit',$this,$param);
|
|
|
1368 |
}
|
|
|
1369 |
|
|
|
1370 |
/**
|
|
|
1371 |
* This method is invoked when the control enters 'OnLoad' stage.
|
|
|
1372 |
* The method raises 'OnLoad' event.
|
|
|
1373 |
* If you override this method, be sure to call the parent implementation
|
|
|
1374 |
* so that the event handlers can be invoked.
|
|
|
1375 |
* @param TEventParameter event parameter to be passed to the event handlers
|
|
|
1376 |
*/
|
|
|
1377 |
public function onLoad($param)
|
|
|
1378 |
{
|
|
|
1379 |
$this->raiseEvent('OnLoad',$this,$param);
|
|
|
1380 |
}
|
|
|
1381 |
|
|
|
1382 |
/**
|
|
|
1383 |
* Raises 'OnDataBinding' event.
|
|
|
1384 |
* This method is invoked when {@link dataBind} is invoked.
|
|
|
1385 |
* @param TEventParameter event parameter to be passed to the event handlers
|
|
|
1386 |
*/
|
|
|
1387 |
public function onDataBinding($param)
|
|
|
1388 |
{
|
|
|
1389 |
Prado::trace("onDataBinding()",'System.Web.UI.TControl');
|
|
|
1390 |
$this->raiseEvent('OnDataBinding',$this,$param);
|
|
|
1391 |
}
|
|
|
1392 |
|
|
|
1393 |
|
|
|
1394 |
/**
|
|
|
1395 |
* This method is invoked when the control enters 'OnUnload' stage.
|
|
|
1396 |
* The method raises 'OnUnload' event.
|
|
|
1397 |
* If you override this method, be sure to call the parent implementation
|
|
|
1398 |
* so that the event handlers can be invoked.
|
|
|
1399 |
* @param TEventParameter event parameter to be passed to the event handlers
|
|
|
1400 |
*/
|
|
|
1401 |
public function onUnload($param)
|
|
|
1402 |
{
|
|
|
1403 |
$this->raiseEvent('OnUnload',$this,$param);
|
|
|
1404 |
}
|
|
|
1405 |
|
|
|
1406 |
/**
|
|
|
1407 |
* This method is invoked when the control enters 'OnPreRender' stage.
|
|
|
1408 |
* The method raises 'OnPreRender' event.
|
|
|
1409 |
* If you override this method, be sure to call the parent implementation
|
|
|
1410 |
* so that the event handlers can be invoked.
|
|
|
1411 |
* @param TEventParameter event parameter to be passed to the event handlers
|
|
|
1412 |
*/
|
|
|
1413 |
public function onPreRender($param)
|
|
|
1414 |
{
|
|
|
1415 |
$this->raiseEvent('OnPreRender',$this,$param);
|
|
|
1416 |
}
|
|
|
1417 |
|
|
|
1418 |
/**
|
|
|
1419 |
* Invokes the parent's bubbleEvent method.
|
|
|
1420 |
* A control who wants to bubble an event must call this method in its onEvent method.
|
|
|
1421 |
* @param TControl sender of the event
|
|
|
1422 |
* @param TEventParameter event parameter
|
|
|
1423 |
* @see bubbleEvent
|
|
|
1424 |
*/
|
|
|
1425 |
protected function raiseBubbleEvent($sender,$param)
|
|
|
1426 |
{
|
|
|
1427 |
$control=$this;
|
|
|
1428 |
while($control=$control->_parent)
|
|
|
1429 |
{
|
|
|
1430 |
if($control->bubbleEvent($sender,$param))
|
|
|
1431 |
break;
|
|
|
1432 |
}
|
|
|
1433 |
}
|
|
|
1434 |
|
|
|
1435 |
/**
|
|
|
1436 |
* This method responds to a bubbled event.
|
|
|
1437 |
* This method should be overriden to provide customized response to a bubbled event.
|
|
|
1438 |
* Check the type of event parameter to determine what event is bubbled currently.
|
|
|
1439 |
* @param TControl sender of the event
|
|
|
1440 |
* @param TEventParameter event parameters
|
|
|
1441 |
* @return boolean true if the event bubbling is handled and no more bubbling.
|
|
|
1442 |
* @see raiseBubbleEvent
|
|
|
1443 |
*/
|
|
|
1444 |
public function bubbleEvent($sender,$param)
|
|
|
1445 |
{
|
|
|
1446 |
return false;
|
|
|
1447 |
}
|
|
|
1448 |
|
|
|
1449 |
/**
|
|
|
1450 |
* Broadcasts an event.
|
|
|
1451 |
* The event will be sent to all controls on the current page hierarchy.
|
|
|
1452 |
* If a control defines the event, the event will be raised for the control.
|
|
|
1453 |
* If a control implements {@link IBroadcastEventReceiver}, its
|
|
|
1454 |
* {@link IBroadcastEventReceiver::broadcastEventReceived broadcastEventReceived()} method will
|
|
|
1455 |
* be invoked which gives the control a chance to respond to the event.
|
|
|
1456 |
* For example, when broadcasting event 'OnClick', all controls having 'OnClick'
|
|
|
1457 |
* event will have this event raised, and all controls implementing
|
|
|
1458 |
* {@link IBroadcastEventReceiver} will also have its
|
|
|
1459 |
* {@link IBroadcastEventReceiver::broadcastEventReceived broadcastEventReceived()}
|
|
|
1460 |
* invoked.
|
|
|
1461 |
* @param string name of the broadcast event
|
|
|
1462 |
* @param TControl sender of this event
|
|
|
1463 |
* @param TEventParameter event parameter
|
|
|
1464 |
*/
|
|
|
1465 |
public function broadcastEvent($name,$sender,$param)
|
|
|
1466 |
{
|
|
|
1467 |
$rootControl=(($page=$this->getPage())===null)?$this:$page;
|
|
|
1468 |
$rootControl->broadcastEventInternal($name,$sender,new TBroadcastEventParameter($name,$param));
|
|
|
1469 |
}
|
|
|
1470 |
|
|
|
1471 |
/**
|
|
|
1472 |
* Recursively broadcasts an event.
|
|
|
1473 |
* This method should only be used by framework developers.
|
|
|
1474 |
* @param string name of the broadcast event
|
|
|
1475 |
* @param TControl sender of the event
|
|
|
1476 |
* @param TBroadcastEventParameter event parameter
|
|
|
1477 |
*/
|
|
|
1478 |
private function broadcastEventInternal($name,$sender,$param)
|
|
|
1479 |
{
|
|
|
1480 |
if($this->hasEvent($name))
|
|
|
1481 |
$this->raiseEvent($name,$sender,$param->getParameter());
|
|
|
1482 |
if($this instanceof IBroadcastEventReceiver)
|
|
|
1483 |
$this->broadcastEventReceived($sender,$param);
|
|
|
1484 |
if($this->getHasControls())
|
|
|
1485 |
{
|
|
|
1486 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1487 |
{
|
|
|
1488 |
if($control instanceof TControl)
|
|
|
1489 |
$control->broadcastEventInternal($name,$sender,$param);
|
|
|
1490 |
}
|
|
|
1491 |
}
|
|
|
1492 |
}
|
|
|
1493 |
|
|
|
1494 |
/**
|
|
|
1495 |
* Traverse the whole control hierarchy rooted at this control.
|
|
|
1496 |
* Callback function may be invoked for each control being visited.
|
|
|
1497 |
* A pre-callback is invoked before traversing child controls;
|
|
|
1498 |
* A post-callback is invoked after traversing child controls.
|
|
|
1499 |
* Callback functions can be global functions or class methods.
|
|
|
1500 |
* They must be of the following signature:
|
|
|
1501 |
* <code>
|
|
|
1502 |
* function callback_func($control,$param) {...}
|
|
|
1503 |
* </code>
|
|
|
1504 |
* where $control refers to the control being visited and $param
|
|
|
1505 |
* is the parameter that is passed originally when calling this traverse function.
|
|
|
1506 |
*
|
|
|
1507 |
* @param mixed parameter to be passed to callbacks for each control
|
|
|
1508 |
* @param callback callback invoked before traversing child controls. If null, it is ignored.
|
|
|
1509 |
* @param callback callback invoked after traversing child controls. If null, it is ignored.
|
|
|
1510 |
*/
|
|
|
1511 |
protected function traverseChildControls($param,$preCallback=null,$postCallback=null)
|
|
|
1512 |
{
|
|
|
1513 |
if($preCallback!==null)
|
|
|
1514 |
call_user_func($preCallback,$this,$param);
|
|
|
1515 |
if($this->getHasControls())
|
|
|
1516 |
{
|
|
|
1517 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1518 |
{
|
|
|
1519 |
if($control instanceof TControl)
|
|
|
1520 |
{
|
|
|
1521 |
$control->traverseChildControls($param,$preCallback,$postCallback);
|
|
|
1522 |
}
|
|
|
1523 |
}
|
|
|
1524 |
}
|
|
|
1525 |
if($postCallback!==null)
|
|
|
1526 |
call_user_func($postCallback,$this,$param);
|
|
|
1527 |
}
|
|
|
1528 |
|
|
|
1529 |
/**
|
|
|
1530 |
* Renders the control.
|
|
|
1531 |
* Only when the control is visible will the control be rendered.
|
|
|
1532 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
1533 |
*/
|
|
|
1534 |
public function renderControl($writer)
|
|
|
1535 |
{
|
|
|
1536 |
if($this->getVisible(false))
|
|
|
1537 |
{
|
|
|
1538 |
if(isset($this->_rf[self::RF_ADAPTER]))
|
|
|
1539 |
$this->_rf[self::RF_ADAPTER]->render($writer);
|
|
|
1540 |
else
|
|
|
1541 |
$this->render($writer);
|
|
|
1542 |
}
|
|
|
1543 |
}
|
|
|
1544 |
|
|
|
1545 |
/**
|
|
|
1546 |
* Renders the control.
|
|
|
1547 |
* This method is invoked by {@link renderControl} when the control is visible.
|
|
|
1548 |
* You can override this method to provide customized rendering of the control.
|
|
|
1549 |
* By default, the control simply renders all its child contents.
|
|
|
1550 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
1551 |
*/
|
|
|
1552 |
public function render($writer)
|
|
|
1553 |
{
|
|
|
1554 |
$this->renderChildren($writer);
|
|
|
1555 |
}
|
|
|
1556 |
|
|
|
1557 |
/**
|
|
|
1558 |
* Renders the children of the control.
|
|
|
1559 |
* This method iterates through all child controls and static text strings
|
|
|
1560 |
* and renders them in order.
|
|
|
1561 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
1562 |
*/
|
|
|
1563 |
public function renderChildren($writer)
|
|
|
1564 |
{
|
|
|
1565 |
if($this->getHasControls())
|
|
|
1566 |
{
|
|
|
1567 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1568 |
{
|
|
|
1569 |
if(is_string($control))
|
|
|
1570 |
$writer->write($control);
|
|
|
1571 |
else if($control instanceof TControl)
|
|
|
1572 |
$control->renderControl($writer);
|
|
|
1573 |
else if($control instanceof IRenderable)
|
|
|
1574 |
$control->render($writer);
|
|
|
1575 |
}
|
|
|
1576 |
}
|
|
|
1577 |
}
|
|
|
1578 |
|
|
|
1579 |
/**
|
|
|
1580 |
* This method is invoked when control state is to be saved.
|
|
|
1581 |
* You can override this method to do last step state saving.
|
|
|
1582 |
* Parent implementation must be invoked.
|
|
|
1583 |
*/
|
|
|
1584 |
public function saveState()
|
|
|
1585 |
{
|
|
|
1586 |
}
|
|
|
1587 |
|
|
|
1588 |
/**
|
|
|
1589 |
* This method is invoked right after the control has loaded its state.
|
|
|
1590 |
* You can override this method to initialize data from the control state.
|
|
|
1591 |
* Parent implementation must be invoked.
|
|
|
1592 |
*/
|
|
|
1593 |
public function loadState()
|
|
|
1594 |
{
|
|
|
1595 |
}
|
|
|
1596 |
|
|
|
1597 |
/**
|
|
|
1598 |
* Loads state (viewstate and controlstate) into a control and its children.
|
|
|
1599 |
* This method should only be used by framework developers.
|
|
|
1600 |
* @param array the collection of the state
|
|
|
1601 |
* @param boolean whether the viewstate should be loaded
|
|
|
1602 |
*/
|
|
|
1603 |
protected function loadStateRecursive(&$state,$needViewState=true)
|
|
|
1604 |
{
|
|
|
1605 |
if(is_array($state))
|
|
|
1606 |
{
|
|
|
1607 |
// A null state means the stateful properties all take default values.
|
|
|
1608 |
// So if the state is enabled, we have to assign the null value.
|
|
|
1609 |
$needViewState=($needViewState && !($this->_flags & self::IS_DISABLE_VIEWSTATE));
|
|
|
1610 |
if(isset($state[1]))
|
|
|
1611 |
{
|
|
|
1612 |
$this->_rf[self::RF_CONTROLSTATE]=&$state[1];
|
|
|
1613 |
unset($state[1]);
|
|
|
1614 |
}
|
|
|
1615 |
else
|
|
|
1616 |
unset($this->_rf[self::RF_CONTROLSTATE]);
|
|
|
1617 |
if($needViewState)
|
|
|
1618 |
{
|
|
|
1619 |
if(isset($state[0]))
|
|
|
1620 |
$this->_viewState=&$state[0];
|
|
|
1621 |
else
|
|
|
1622 |
$this->_viewState=array();
|
|
|
1623 |
}
|
|
|
1624 |
unset($state[0]);
|
|
|
1625 |
if($this->getHasControls())
|
|
|
1626 |
{
|
|
|
1627 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1628 |
{
|
|
|
1629 |
if($control instanceof TControl)
|
|
|
1630 |
{
|
|
|
1631 |
if(isset($state[$control->_id]))
|
|
|
1632 |
{
|
|
|
1633 |
$control->loadStateRecursive($state[$control->_id],$needViewState);
|
|
|
1634 |
unset($state[$control->_id]);
|
|
|
1635 |
}
|
|
|
1636 |
}
|
|
|
1637 |
}
|
|
|
1638 |
}
|
|
|
1639 |
if(!empty($state))
|
|
|
1640 |
$this->_rf[self::RF_CHILD_STATE]=&$state;
|
|
|
1641 |
}
|
|
|
1642 |
$this->_stage=self::CS_STATE_LOADED;
|
|
|
1643 |
if(isset($this->_rf[self::RF_ADAPTER]))
|
|
|
1644 |
$this->_rf[self::RF_ADAPTER]->loadState();
|
|
|
1645 |
else
|
|
|
1646 |
$this->loadState();
|
|
|
1647 |
}
|
|
|
1648 |
|
|
|
1649 |
/**
|
|
|
1650 |
* Saves all control state (viewstate and controlstate) as a collection.
|
|
|
1651 |
* This method should only be used by framework developers.
|
|
|
1652 |
* @param boolean whether the viewstate should be saved
|
|
|
1653 |
* @return array the collection of the control state (including its children's state).
|
|
|
1654 |
*/
|
|
|
1655 |
protected function &saveStateRecursive($needViewState=true)
|
|
|
1656 |
{
|
|
|
1657 |
if(isset($this->_rf[self::RF_ADAPTER]))
|
|
|
1658 |
$this->_rf[self::RF_ADAPTER]->saveState();
|
|
|
1659 |
else
|
|
|
1660 |
$this->saveState();
|
|
|
1661 |
$needViewState=($needViewState && !($this->_flags & self::IS_DISABLE_VIEWSTATE));
|
|
|
1662 |
$state=array();
|
|
|
1663 |
if($this->getHasControls())
|
|
|
1664 |
{
|
|
|
1665 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1666 |
{
|
|
|
1667 |
if($control instanceof TControl)
|
|
|
1668 |
$state[$control->_id]=&$control->saveStateRecursive($needViewState);
|
|
|
1669 |
}
|
|
|
1670 |
}
|
|
|
1671 |
if($needViewState && !empty($this->_viewState))
|
|
|
1672 |
$state[0]=&$this->_viewState;
|
|
|
1673 |
if(isset($this->_rf[self::RF_CONTROLSTATE]))
|
|
|
1674 |
$state[1]=&$this->_rf[self::RF_CONTROLSTATE];
|
|
|
1675 |
return $state;
|
|
|
1676 |
}
|
|
|
1677 |
|
|
|
1678 |
/**
|
|
|
1679 |
* Applies a stylesheet skin to a control.
|
|
|
1680 |
* @param TPage the page containing the control
|
|
|
1681 |
* @throws TInvalidOperationException if the stylesheet skin is applied already
|
|
|
1682 |
*/
|
|
|
1683 |
public function applyStyleSheetSkin($page)
|
|
|
1684 |
{
|
|
|
1685 |
if($page && !($this->_flags & self::IS_STYLESHEET_APPLIED))
|
|
|
1686 |
{
|
|
|
1687 |
$page->applyControlStyleSheet($this);
|
|
|
1688 |
$this->_flags |= self::IS_STYLESHEET_APPLIED;
|
|
|
1689 |
}
|
|
|
1690 |
else if($this->_flags & self::IS_STYLESHEET_APPLIED)
|
|
|
1691 |
throw new TInvalidOperationException('control_stylesheet_applied',get_class($this));
|
|
|
1692 |
}
|
|
|
1693 |
|
|
|
1694 |
/**
|
|
|
1695 |
* Clears the cached UniqueID.
|
|
|
1696 |
* If $recursive=true, all children's cached UniqueID will be cleared as well.
|
|
|
1697 |
* @param boolean whether the clearing is recursive.
|
|
|
1698 |
*/
|
|
|
1699 |
private function clearCachedUniqueID($recursive)
|
|
|
1700 |
{
|
|
|
1701 |
if($recursive && $this->_uid!==null && isset($this->_rf[self::RF_CONTROLS]))
|
|
|
1702 |
{
|
|
|
1703 |
foreach($this->_rf[self::RF_CONTROLS] as $control)
|
|
|
1704 |
if($control instanceof TControl)
|
|
|
1705 |
$control->clearCachedUniqueID($recursive);
|
|
|
1706 |
}
|
|
|
1707 |
$this->_uid=null;
|
|
|
1708 |
}
|
|
|
1709 |
|
|
|
1710 |
/**
|
|
|
1711 |
* Generates an automatic ID for the control.
|
|
|
1712 |
*/
|
|
|
1713 |
private function generateAutomaticID()
|
|
|
1714 |
{
|
|
|
1715 |
$this->_flags &= ~self::IS_ID_SET;
|
|
|
1716 |
if(!isset($this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]))
|
|
|
1717 |
$this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]=0;
|
|
|
1718 |
$id=$this->_namingContainer->_rf[self::RF_NAMED_CONTROLS_ID]++;
|
|
|
1719 |
$this->_id=self::AUTOMATIC_ID_PREFIX . $id;
|
|
|
1720 |
$this->_namingContainer->clearNameTable();
|
|
|
1721 |
}
|
|
|
1722 |
|
|
|
1723 |
/**
|
|
|
1724 |
* Clears the list of the controls whose IDs are managed by the specified naming container.
|
|
|
1725 |
*/
|
|
|
1726 |
private function clearNameTable()
|
|
|
1727 |
{
|
|
|
1728 |
unset($this->_rf[self::RF_NAMED_CONTROLS]);
|
|
|
1729 |
}
|
|
|
1730 |
|
|
|
1731 |
/**
|
|
|
1732 |
* Updates the list of the controls whose IDs are managed by the specified naming container.
|
|
|
1733 |
* @param TControl the naming container
|
|
|
1734 |
* @param TControlCollection list of controls
|
|
|
1735 |
* @throws TInvalidDataValueException if a control's ID is not unique within its naming container.
|
|
|
1736 |
*/
|
|
|
1737 |
private function fillNameTable($container,$controls)
|
|
|
1738 |
{
|
|
|
1739 |
foreach($controls as $control)
|
|
|
1740 |
{
|
|
|
1741 |
if($control instanceof TControl)
|
|
|
1742 |
{
|
|
|
1743 |
if($control->_id!=='')
|
|
|
1744 |
{
|
|
|
1745 |
if(isset($container->_rf[self::RF_NAMED_CONTROLS][$control->_id]))
|
|
|
1746 |
throw new TInvalidDataValueException('control_id_nonunique',get_class($control),$control->_id);
|
|
|
1747 |
else
|
|
|
1748 |
$container->_rf[self::RF_NAMED_CONTROLS][$control->_id]=$control;
|
|
|
1749 |
}
|
|
|
1750 |
if(!($control instanceof INamingContainer) && $control->getHasControls())
|
|
|
1751 |
$this->fillNameTable($container,$control->_rf[self::RF_CONTROLS]);
|
|
|
1752 |
}
|
|
|
1753 |
}
|
|
|
1754 |
}
|
|
|
1755 |
}
|
|
|
1756 |
|
|
|
1757 |
|
|
|
1758 |
/**
|
|
|
1759 |
* TControlCollection class
|
|
|
1760 |
*
|
|
|
1761 |
* TControlCollection implements a collection that enables
|
|
|
1762 |
* controls to maintain a list of their child controls.
|
|
|
1763 |
*
|
|
|
1764 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
1765 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
1766 |
* @package System.Web.UI
|
|
|
1767 |
* @since 3.0
|
|
|
1768 |
*/
|
|
|
1769 |
class TControlCollection extends TList
|
|
|
1770 |
{
|
|
|
1771 |
/**
|
|
|
1772 |
* the control that owns this collection.
|
|
|
1773 |
* @var TControl
|
|
|
1774 |
*/
|
|
|
1775 |
private $_o;
|
|
|
1776 |
|
|
|
1777 |
/**
|
|
|
1778 |
* Constructor.
|
|
|
1779 |
* @param TControl the control that owns this collection.
|
|
|
1780 |
* @param boolean whether the list is read-only
|
|
|
1781 |
*/
|
|
|
1782 |
public function __construct(TControl $owner,$readOnly=false)
|
|
|
1783 |
{
|
|
|
1784 |
$this->_o=$owner;
|
|
|
1785 |
parent::__construct(null,$readOnly);
|
|
|
1786 |
}
|
|
|
1787 |
|
|
|
1788 |
/**
|
|
|
1789 |
* @return TControl the control that owns this collection.
|
|
|
1790 |
*/
|
|
|
1791 |
protected function getOwner()
|
|
|
1792 |
{
|
|
|
1793 |
return $this->_o;
|
|
|
1794 |
}
|
|
|
1795 |
|
|
|
1796 |
/**
|
|
|
1797 |
* Inserts an item at the specified position.
|
|
|
1798 |
* This overrides the parent implementation by performing additional
|
|
|
1799 |
* operations for each newly added child control.
|
|
|
1800 |
* @param integer the speicified position.
|
|
|
1801 |
* @param mixed new item
|
|
|
1802 |
* @throws TInvalidDataTypeException if the item to be inserted is neither a string nor a TControl.
|
|
|
1803 |
*/
|
|
|
1804 |
public function insertAt($index,$item)
|
|
|
1805 |
{
|
|
|
1806 |
if($item instanceof TControl)
|
|
|
1807 |
{
|
|
|
1808 |
parent::insertAt($index,$item);
|
|
|
1809 |
$this->_o->addedControl($item);
|
|
|
1810 |
}
|
|
|
1811 |
else if(is_string($item) || ($item instanceof IRenderable))
|
|
|
1812 |
parent::insertAt($index,$item);
|
|
|
1813 |
else
|
|
|
1814 |
throw new TInvalidDataTypeException('controlcollection_control_required');
|
|
|
1815 |
}
|
|
|
1816 |
|
|
|
1817 |
/**
|
|
|
1818 |
* Removes an item at the specified position.
|
|
|
1819 |
* This overrides the parent implementation by performing additional
|
|
|
1820 |
* cleanup work when removing a child control.
|
|
|
1821 |
* @param integer the index of the item to be removed.
|
|
|
1822 |
* @return mixed the removed item.
|
|
|
1823 |
*/
|
|
|
1824 |
public function removeAt($index)
|
|
|
1825 |
{
|
|
|
1826 |
$item=parent::removeAt($index);
|
|
|
1827 |
if($item instanceof TControl)
|
|
|
1828 |
$this->_o->removedControl($item);
|
|
|
1829 |
return $item;
|
|
|
1830 |
}
|
|
|
1831 |
|
|
|
1832 |
/**
|
|
|
1833 |
* Overrides the parent implementation by invoking {@link TControl::clearNamingContainer}
|
|
|
1834 |
*/
|
|
|
1835 |
public function clear()
|
|
|
1836 |
{
|
|
|
1837 |
parent::clear();
|
|
|
1838 |
if($this->_o instanceof INamingContainer)
|
|
|
1839 |
$this->_o->clearNamingContainer();
|
|
|
1840 |
}
|
|
|
1841 |
}
|
|
|
1842 |
|
|
|
1843 |
/**
|
|
|
1844 |
* TEmptyControlCollection class
|
|
|
1845 |
*
|
|
|
1846 |
* TEmptyControlCollection implements an empty control list that prohibits adding
|
|
|
1847 |
* controls to it. This is useful for controls that do not allow child controls.
|
|
|
1848 |
*
|
|
|
1849 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
1850 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
1851 |
* @package System.Web.UI
|
|
|
1852 |
* @since 3.0
|
|
|
1853 |
*/
|
|
|
1854 |
class TEmptyControlCollection extends TControlCollection
|
|
|
1855 |
{
|
|
|
1856 |
/**
|
|
|
1857 |
* Constructor.
|
|
|
1858 |
* @param TControl the control that owns this collection.
|
|
|
1859 |
*/
|
|
|
1860 |
public function __construct(TControl $owner)
|
|
|
1861 |
{
|
|
|
1862 |
parent::__construct($owner,true);
|
|
|
1863 |
}
|
|
|
1864 |
|
|
|
1865 |
/**
|
|
|
1866 |
* Inserts an item at the specified position.
|
|
|
1867 |
* This overrides the parent implementation by ignoring new addition.
|
|
|
1868 |
* @param integer the speicified position.
|
|
|
1869 |
* @param mixed new item
|
|
|
1870 |
*/
|
|
|
1871 |
public function insertAt($index,$item)
|
|
|
1872 |
{
|
|
|
1873 |
if(!is_string($item)) // string is possible if property tag is used. we simply ignore it in this case
|
|
|
1874 |
parent::insertAt($index,$item); // this will generate an exception in parent implementation
|
|
|
1875 |
}
|
|
|
1876 |
}
|
|
|
1877 |
|
|
|
1878 |
/**
|
|
|
1879 |
* INamingContainer interface.
|
|
|
1880 |
* INamingContainer marks a control as a naming container.
|
|
|
1881 |
*
|
|
|
1882 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
1883 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
1884 |
* @package System.Web.UI
|
|
|
1885 |
* @since 3.0
|
|
|
1886 |
*/
|
|
|
1887 |
interface INamingContainer
|
|
|
1888 |
{
|
|
|
1889 |
}
|
|
|
1890 |
|
|
|
1891 |
/**
|
|
|
1892 |
* IPostBackEventHandler interface
|
|
|
1893 |
*
|
|
|
1894 |
* If a control wants to respond to postback event, it must implement this interface.
|
|
|
1895 |
*
|
|
|
1896 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
1897 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
1898 |
* @package System.Web.UI
|
|
|
1899 |
* @since 3.0
|
|
|
1900 |
*/
|
|
|
1901 |
interface IPostBackEventHandler
|
|
|
1902 |
{
|
|
|
1903 |
/**
|
|
|
1904 |
* Raises postback event.
|
|
|
1905 |
* The implementation of this function should raise appropriate event(s) (e.g. OnClick, OnCommand)
|
|
|
1906 |
* indicating the component is responsible for the postback event.
|
|
|
1907 |
* @param string the parameter associated with the postback event
|
|
|
1908 |
*/
|
|
|
1909 |
public function raisePostBackEvent($param);
|
|
|
1910 |
}
|
|
|
1911 |
|
|
|
1912 |
/**
|
|
|
1913 |
* IPostBackDataHandler interface
|
|
|
1914 |
*
|
|
|
1915 |
* If a control wants to load post data, it must implement this interface.
|
|
|
1916 |
*
|
|
|
1917 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
1918 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
1919 |
* @package System.Web.UI
|
|
|
1920 |
* @since 3.0
|
|
|
1921 |
*/
|
|
|
1922 |
interface IPostBackDataHandler
|
|
|
1923 |
{
|
|
|
1924 |
/**
|
|
|
1925 |
* Loads user input data.
|
|
|
1926 |
* The implementation of this function can use $values[$key] to get the user input
|
|
|
1927 |
* data that are meant for the particular control.
|
|
|
1928 |
* @param string the key that can be used to retrieve data from the input data collection
|
|
|
1929 |
* @param array the input data collection
|
|
|
1930 |
* @return boolean whether the data of the control has been changed
|
|
|
1931 |
*/
|
|
|
1932 |
public function loadPostData($key,$values);
|
|
|
1933 |
/**
|
|
|
1934 |
* Raises postdata changed event.
|
|
|
1935 |
* The implementation of this function should raise appropriate event(s) (e.g. OnTextChanged)
|
|
|
1936 |
* indicating the control data is changed.
|
|
|
1937 |
*/
|
|
|
1938 |
public function raisePostDataChangedEvent();
|
|
|
1939 |
/**
|
|
|
1940 |
* @return boolean whether postback causes the data change. Defaults to false for non-postback state.
|
|
|
1941 |
*/
|
|
|
1942 |
public function getDataChanged();
|
|
|
1943 |
}
|
|
|
1944 |
|
|
|
1945 |
|
|
|
1946 |
/**
|
|
|
1947 |
* IValidator interface
|
|
|
1948 |
*
|
|
|
1949 |
* If a control wants to validate user input, it must implement this interface.
|
|
|
1950 |
*
|
|
|
1951 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
1952 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
1953 |
* @package System.Web.UI
|
|
|
1954 |
* @since 3.0
|
|
|
1955 |
*/
|
|
|
1956 |
interface IValidator
|
|
|
1957 |
{
|
|
|
1958 |
/**
|
|
|
1959 |
* Validates certain data.
|
|
|
1960 |
* The implementation of this function should validate certain data
|
|
|
1961 |
* (e.g. data entered into TTextBox control).
|
|
|
1962 |
* @return boolean whether the data passes the validation
|
|
|
1963 |
*/
|
|
|
1964 |
public function validate();
|
|
|
1965 |
/**
|
|
|
1966 |
* @return boolean whether the previous {@link validate()} is successful.
|
|
|
1967 |
*/
|
|
|
1968 |
public function getIsValid();
|
|
|
1969 |
/**
|
|
|
1970 |
* @param boolean whether the validator validates successfully
|
|
|
1971 |
*/
|
|
|
1972 |
public function setIsValid($value);
|
|
|
1973 |
/**
|
|
|
1974 |
* @return string error message during last validate
|
|
|
1975 |
*/
|
|
|
1976 |
public function getErrorMessage();
|
|
|
1977 |
/**
|
|
|
1978 |
* @param string error message for the validation
|
|
|
1979 |
*/
|
|
|
1980 |
public function setErrorMessage($value);
|
|
|
1981 |
}
|
|
|
1982 |
|
|
|
1983 |
|
|
|
1984 |
/**
|
|
|
1985 |
* IValidatable interface
|
|
|
1986 |
*
|
|
|
1987 |
* If a control wants to be validated by a validator, it must implement this interface.
|
|
|
1988 |
*
|
|
|
1989 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
1990 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
1991 |
* @package System.Web.UI
|
|
|
1992 |
* @since 3.0
|
|
|
1993 |
*/
|
|
|
1994 |
interface IValidatable
|
|
|
1995 |
{
|
|
|
1996 |
/**
|
|
|
1997 |
* @return mixed the value of the property to be validated.
|
|
|
1998 |
*/
|
|
|
1999 |
public function getValidationPropertyValue();
|
|
|
2000 |
/**
|
|
|
2001 |
* @return boolean wether this control's validators validated successfully (must default to true)
|
|
|
2002 |
*/
|
|
|
2003 |
public function getIsValid();
|
|
|
2004 |
/**
|
|
|
2005 |
* @return boolean wether this control's validators validated successfully
|
|
|
2006 |
*/
|
|
|
2007 |
public function setIsValid($value);
|
|
|
2008 |
}
|
|
|
2009 |
|
|
|
2010 |
/**
|
|
|
2011 |
* IBroadcastEventReceiver interface
|
|
|
2012 |
*
|
|
|
2013 |
* If a control wants to check broadcast event, it must implement this interface.
|
|
|
2014 |
*
|
|
|
2015 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
2016 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
2017 |
* @package System.Web.UI
|
|
|
2018 |
* @since 3.0
|
|
|
2019 |
*/
|
|
|
2020 |
interface IBroadcastEventReceiver
|
|
|
2021 |
{
|
|
|
2022 |
/**
|
|
|
2023 |
* Handles broadcast event.
|
|
|
2024 |
* This method is invoked automatically when an event is broadcasted.
|
|
|
2025 |
* Within this method, you may check the event name given in
|
|
|
2026 |
* the event parameter to determine whether you should respond to
|
|
|
2027 |
* this event.
|
|
|
2028 |
* @param TControl sender of the event
|
|
|
2029 |
* @param TBroadCastEventParameter event parameter
|
|
|
2030 |
*/
|
|
|
2031 |
public function broadcastEventReceived($sender,$param);
|
|
|
2032 |
}
|
|
|
2033 |
|
|
|
2034 |
/**
|
|
|
2035 |
* ITheme interface.
|
|
|
2036 |
*
|
|
|
2037 |
* This interface must be implemented by theme.
|
|
|
2038 |
*
|
|
|
2039 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
2040 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
2041 |
* @package System.Web.UI
|
|
|
2042 |
* @since 3.0
|
|
|
2043 |
*/
|
|
|
2044 |
interface ITheme
|
|
|
2045 |
{
|
|
|
2046 |
/**
|
|
|
2047 |
* Applies this theme to the specified control.
|
|
|
2048 |
* @param TControl the control to be applied with this theme
|
|
|
2049 |
*/
|
|
|
2050 |
public function applySkin($control);
|
|
|
2051 |
}
|
|
|
2052 |
|
|
|
2053 |
/**
|
|
|
2054 |
* ITemplate interface
|
|
|
2055 |
*
|
|
|
2056 |
* ITemplate specifies the interface for classes encapsulating
|
|
|
2057 |
* parsed template structures.
|
|
|
2058 |
*
|
|
|
2059 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
2060 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
2061 |
* @package System.Web.UI
|
|
|
2062 |
* @since 3.0
|
|
|
2063 |
*/
|
|
|
2064 |
interface ITemplate
|
|
|
2065 |
{
|
|
|
2066 |
/**
|
|
|
2067 |
* Instantiates the template.
|
|
|
2068 |
* Content in the template will be instantiated as components and text strings
|
|
|
2069 |
* and passed to the specified parent control.
|
|
|
2070 |
* @param TControl the parent control
|
|
|
2071 |
*/
|
|
|
2072 |
public function instantiateIn($parent);
|
|
|
2073 |
}
|
|
|
2074 |
|
|
|
2075 |
/**
|
|
|
2076 |
* IButtonControl interface
|
|
|
2077 |
*
|
|
|
2078 |
* IButtonControl specifies the common properties and events that must
|
|
|
2079 |
* be implemented by a button control, such as {@link TButton}, {@link TLinkButton},
|
|
|
2080 |
* {@link TImageButton}.
|
|
|
2081 |
*
|
|
|
2082 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
2083 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
2084 |
* @package System.Web.UI
|
|
|
2085 |
* @since 3.0
|
|
|
2086 |
*/
|
|
|
2087 |
interface IButtonControl
|
|
|
2088 |
{
|
|
|
2089 |
/**
|
|
|
2090 |
* @return string caption of the button
|
|
|
2091 |
*/
|
|
|
2092 |
public function getText();
|
|
|
2093 |
|
|
|
2094 |
/**
|
|
|
2095 |
* @param string caption of the button
|
|
|
2096 |
*/
|
|
|
2097 |
public function setText($value);
|
|
|
2098 |
|
|
|
2099 |
/**
|
|
|
2100 |
* @return boolean whether postback event trigger by this button will cause input validation
|
|
|
2101 |
*/
|
|
|
2102 |
public function getCausesValidation();
|
|
|
2103 |
|
|
|
2104 |
/**
|
|
|
2105 |
* @param boolean whether postback event trigger by this button will cause input validation
|
|
|
2106 |
*/
|
|
|
2107 |
public function setCausesValidation($value);
|
|
|
2108 |
|
|
|
2109 |
/**
|
|
|
2110 |
* @return string the command name associated with the {@link onCommand OnCommand} event.
|
|
|
2111 |
*/
|
|
|
2112 |
public function getCommandName();
|
|
|
2113 |
|
|
|
2114 |
/**
|
|
|
2115 |
* @param string the command name associated with the {@link onCommand OnCommand} event.
|
|
|
2116 |
*/
|
|
|
2117 |
public function setCommandName($value);
|
|
|
2118 |
|
|
|
2119 |
/**
|
|
|
2120 |
* @return string the parameter associated with the {@link onCommand OnCommand} event
|
|
|
2121 |
*/
|
|
|
2122 |
public function getCommandParameter();
|
|
|
2123 |
|
|
|
2124 |
/**
|
|
|
2125 |
* @param string the parameter associated with the {@link onCommand OnCommand} event.
|
|
|
2126 |
*/
|
|
|
2127 |
public function setCommandParameter($value);
|
|
|
2128 |
|
|
|
2129 |
/**
|
|
|
2130 |
* @return string the group of validators which the button causes validation upon postback
|
|
|
2131 |
*/
|
|
|
2132 |
public function getValidationGroup();
|
|
|
2133 |
|
|
|
2134 |
/**
|
|
|
2135 |
* @param string the group of validators which the button causes validation upon postback
|
|
|
2136 |
*/
|
|
|
2137 |
public function setValidationGroup($value);
|
|
|
2138 |
|
|
|
2139 |
/**
|
|
|
2140 |
* Raises <b>OnClick</b> event.
|
|
|
2141 |
* @param TEventParameter event parameter to be passed to the event handlers
|
|
|
2142 |
*/
|
|
|
2143 |
public function onClick($param);
|
|
|
2144 |
|
|
|
2145 |
/**
|
|
|
2146 |
* Raises <b>OnCommand</b> event.
|
|
|
2147 |
* @param TCommandEventParameter event parameter to be passed to the event handlers
|
|
|
2148 |
*/
|
|
|
2149 |
public function onCommand($param);
|
|
|
2150 |
|
|
|
2151 |
/**
|
|
|
2152 |
* @param boolean set by a panel to register this button as the default button for the panel.
|
|
|
2153 |
*/
|
|
|
2154 |
public function setIsDefaultButton($value);
|
|
|
2155 |
|
|
|
2156 |
/**
|
|
|
2157 |
* @return boolean true if this button is registered as a default button for a panel.
|
|
|
2158 |
*/
|
|
|
2159 |
public function getIsDefaultButton();
|
|
|
2160 |
}
|
|
|
2161 |
|
|
|
2162 |
/**
|
|
|
2163 |
* ISurroundable interface
|
|
|
2164 |
*
|
|
|
2165 |
* Identifies controls that may create an additional surrounding tag. The id of the
|
|
|
2166 |
* tag can be obtained with {@link getSurroundingTagID}.
|
|
|
2167 |
*
|
|
|
2168 |
* @package System.Web.UI
|
|
|
2169 |
* @since 3.1.2
|
|
|
2170 |
*/
|
|
|
2171 |
interface ISurroundable
|
|
|
2172 |
{
|
|
|
2173 |
/**
|
|
|
2174 |
* @return string the id of the embedding tag of the control or the control's clientID if not surrounded
|
|
|
2175 |
*/
|
|
|
2176 |
public function getSurroundingTagID();
|
|
|
2177 |
}
|
|
|
2178 |
|
|
|
2179 |
/**
|
|
|
2180 |
* TBroadcastEventParameter class
|
|
|
2181 |
*
|
|
|
2182 |
* TBroadcastEventParameter encapsulates the parameter data for
|
|
|
2183 |
* events that are broadcasted. The name of of the event is specified via
|
|
|
2184 |
* {@link setName Name} property while the event parameter is via
|
|
|
2185 |
* {@link setParameter Parameter} property.
|
|
|
2186 |
*
|
|
|
2187 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
2188 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
2189 |
* @package System.Web.UI
|
|
|
2190 |
* @since 3.0
|
|
|
2191 |
*/
|
|
|
2192 |
class TBroadcastEventParameter extends TEventParameter
|
|
|
2193 |
{
|
|
|
2194 |
private $_name;
|
|
|
2195 |
private $_param;
|
|
|
2196 |
|
|
|
2197 |
/**
|
|
|
2198 |
* Constructor.
|
|
|
2199 |
* @param string name of the broadcast event
|
|
|
2200 |
* @param mixed parameter of the broadcast event
|
|
|
2201 |
*/
|
|
|
2202 |
public function __construct($name='',$parameter=null)
|
|
|
2203 |
{
|
|
|
2204 |
$this->_name=$name;
|
|
|
2205 |
$this->_param=$parameter;
|
|
|
2206 |
}
|
|
|
2207 |
|
|
|
2208 |
/**
|
|
|
2209 |
* @return string name of the broadcast event
|
|
|
2210 |
*/
|
|
|
2211 |
public function getName()
|
|
|
2212 |
{
|
|
|
2213 |
return $this->_name;
|
|
|
2214 |
}
|
|
|
2215 |
|
|
|
2216 |
/**
|
|
|
2217 |
* @param string name of the broadcast event
|
|
|
2218 |
*/
|
|
|
2219 |
public function setName($value)
|
|
|
2220 |
{
|
|
|
2221 |
$this->_name=$value;
|
|
|
2222 |
}
|
|
|
2223 |
|
|
|
2224 |
/**
|
|
|
2225 |
* @return mixed parameter of the broadcast event
|
|
|
2226 |
*/
|
|
|
2227 |
public function getParameter()
|
|
|
2228 |
{
|
|
|
2229 |
return $this->_param;
|
|
|
2230 |
}
|
|
|
2231 |
|
|
|
2232 |
/**
|
|
|
2233 |
* @param mixed parameter of the broadcast event
|
|
|
2234 |
*/
|
|
|
2235 |
public function setParameter($value)
|
|
|
2236 |
{
|
|
|
2237 |
$this->_param=$value;
|
|
|
2238 |
}
|
|
|
2239 |
}
|
|
|
2240 |
|
|
|
2241 |
/**
|
|
|
2242 |
* TCommandEventParameter class
|
|
|
2243 |
*
|
|
|
2244 |
* TCommandEventParameter encapsulates the parameter data for <b>Command</b>
|
|
|
2245 |
* event of button controls. You can access the name of the command via
|
|
|
2246 |
* {@link getCommandName CommandName} property, and the parameter carried
|
|
|
2247 |
* with the command via {@link getCommandParameter CommandParameter} property.
|
|
|
2248 |
*
|
|
|
2249 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
2250 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
2251 |
* @package System.Web.UI
|
|
|
2252 |
* @since 3.0
|
|
|
2253 |
*/
|
|
|
2254 |
class TCommandEventParameter extends TEventParameter
|
|
|
2255 |
{
|
|
|
2256 |
private $_name;
|
|
|
2257 |
private $_param;
|
|
|
2258 |
|
|
|
2259 |
/**
|
|
|
2260 |
* Constructor.
|
|
|
2261 |
* @param string name of the command
|
|
|
2262 |
* @param string parameter of the command
|
|
|
2263 |
*/
|
|
|
2264 |
public function __construct($name='',$parameter='')
|
|
|
2265 |
{
|
|
|
2266 |
$this->_name=$name;
|
|
|
2267 |
$this->_param=$parameter;
|
|
|
2268 |
}
|
|
|
2269 |
|
|
|
2270 |
/**
|
|
|
2271 |
* @return string name of the command
|
|
|
2272 |
*/
|
|
|
2273 |
public function getCommandName()
|
|
|
2274 |
{
|
|
|
2275 |
return $this->_name;
|
|
|
2276 |
}
|
|
|
2277 |
|
|
|
2278 |
/**
|
|
|
2279 |
* @return string parameter of the command
|
|
|
2280 |
*/
|
|
|
2281 |
public function getCommandParameter()
|
|
|
2282 |
{
|
|
|
2283 |
return $this->_param;
|
|
|
2284 |
}
|
|
|
2285 |
}
|
|
|
2286 |
|
|
|
2287 |
|
|
|
2288 |
/**
|
|
|
2289 |
* TCompositeLiteral class
|
|
|
2290 |
*
|
|
|
2291 |
* TCompositeLiteral is used internally by {@link TTemplate} for representing
|
|
|
2292 |
* consecutive static strings, expressions and statements.
|
|
|
2293 |
*
|
|
|
2294 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
2295 |
* @version $Id: TControl.php 2522 2008-10-13 21:40:53Z mikl $
|
|
|
2296 |
* @package System.Web.UI
|
|
|
2297 |
* @since 3.0
|
|
|
2298 |
*/
|
|
|
2299 |
class TCompositeLiteral extends TComponent implements IRenderable, IBindable
|
|
|
2300 |
{
|
|
|
2301 |
const TYPE_EXPRESSION=0;
|
|
|
2302 |
const TYPE_STATEMENTS=1;
|
|
|
2303 |
const TYPE_DATABINDING=2;
|
|
|
2304 |
private $_container=null;
|
|
|
2305 |
private $_items=array();
|
|
|
2306 |
private $_expressions=array();
|
|
|
2307 |
private $_statements=array();
|
|
|
2308 |
private $_bindings=array();
|
|
|
2309 |
|
|
|
2310 |
/**
|
|
|
2311 |
* Constructor.
|
|
|
2312 |
* @param array list of items to be represented by TCompositeLiteral
|
|
|
2313 |
*/
|
|
|
2314 |
public function __construct($items)
|
|
|
2315 |
{
|
|
|
2316 |
$this->_items=array();
|
|
|
2317 |
$this->_expressions=array();
|
|
|
2318 |
$this->_statements=array();
|
|
|
2319 |
foreach($items as $id=>$item)
|
|
|
2320 |
{
|
|
|
2321 |
if(is_array($item))
|
|
|
2322 |
{
|
|
|
2323 |
if($item[0]===self::TYPE_EXPRESSION)
|
|
|
2324 |
$this->_expressions[$id]=$item[1];
|
|
|
2325 |
else if($item[0]===self::TYPE_STATEMENTS)
|
|
|
2326 |
$this->_statements[$id]=$item[1];
|
|
|
2327 |
else if($item[0]===self::TYPE_DATABINDING)
|
|
|
2328 |
$this->_bindings[$id]=$item[1];
|
|
|
2329 |
$this->_items[$id]='';
|
|
|
2330 |
}
|
|
|
2331 |
else
|
|
|
2332 |
$this->_items[$id]=$item;
|
|
|
2333 |
}
|
|
|
2334 |
}
|
|
|
2335 |
|
|
|
2336 |
/**
|
|
|
2337 |
* @return TComponent container of this component. It serves as the evaluation context of expressions and statements.
|
|
|
2338 |
*/
|
|
|
2339 |
public function getContainer()
|
|
|
2340 |
{
|
|
|
2341 |
return $this->_container;
|
|
|
2342 |
}
|
|
|
2343 |
|
|
|
2344 |
/**
|
|
|
2345 |
* @param TComponent container of this component. It serves as the evaluation context of expressions and statements.
|
|
|
2346 |
*/
|
|
|
2347 |
public function setContainer(TComponent $value)
|
|
|
2348 |
{
|
|
|
2349 |
$this->_container=$value;
|
|
|
2350 |
}
|
|
|
2351 |
|
|
|
2352 |
/**
|
|
|
2353 |
* Evaluates the expressions and/or statements in the component.
|
|
|
2354 |
*/
|
|
|
2355 |
public function evaluateDynamicContent()
|
|
|
2356 |
{
|
|
|
2357 |
$context=$this->_container===null?$this:$this->_container;
|
|
|
2358 |
foreach($this->_expressions as $id=>$expression)
|
|
|
2359 |
$this->_items[$id]=$context->evaluateExpression($expression);
|
|
|
2360 |
foreach($this->_statements as $id=>$statement)
|
|
|
2361 |
$this->_items[$id]=$context->evaluateStatements($statement);
|
|
|
2362 |
}
|
|
|
2363 |
|
|
|
2364 |
/**
|
|
|
2365 |
* Performs databindings.
|
|
|
2366 |
* This method is required by {@link IBindable}
|
|
|
2367 |
*/
|
|
|
2368 |
public function dataBind()
|
|
|
2369 |
{
|
|
|
2370 |
$context=$this->_container===null?$this:$this->_container;
|
|
|
2371 |
foreach($this->_bindings as $id=>$binding)
|
|
|
2372 |
$this->_items[$id]=$context->evaluateExpression($binding);
|
|
|
2373 |
}
|
|
|
2374 |
|
|
|
2375 |
/**
|
|
|
2376 |
* Renders the content stored in this component.
|
|
|
2377 |
* This method is required by {@link IRenderable}
|
|
|
2378 |
* @param ITextWriter
|
|
|
2379 |
*/
|
|
|
2380 |
public function render($writer)
|
|
|
2381 |
{
|
|
|
2382 |
$writer->write(implode('',$this->_items));
|
|
|
2383 |
}
|
|
|
2384 |
}
|
|
|
2385 |
|
|
|
2386 |
?>
|