1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
<?php
/**
* TBulletedList class file
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
*/
/**
* TBulletedList class
*
* TBulletedList displays items in a bullet format.
* The bullet style is specified by {@link setBulletStyle BulletStyle}. When
* the style is 'CustomImage', the {@link setBackImageUrl BulletImageUrl}
* specifies the image used as bullets.
*
* TBulletedList displays the item texts in three different modes, specified
* via {@link setDisplayMode DisplayMode}. When the mode is 'Text', the item texts
* are displayed as static texts; When the mode is 'HyperLink', each item
* is displayed as a hyperlink whose URL is given by the item value, and the
* {@link setTarget Target} property can be used to specify the target browser window;
* When the mode is 'LinkButton', each item is displayed as a link button which
* posts back to the page if a user clicks on that and the event {@link onClick Click}
* will be raised under such a circumstance.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TBulletedList extends TListControl implements IPostBackEventHandler
{
/**
* @var boolean cached property value of Enabled
*/
private $_isEnabled;
/**
* @var TPostBackOptions postback options
*/
private $_postBackOptions;
/**
* Raises the postback event.
* This method is required by {@link IPostBackEventHandler} interface.
* If {@link getCausesValidation CausesValidation} is true, it will
* invoke the page's {@link TPage::validate validate} method first.
* It will raise {@link onClick Click} events.
* This method is mainly used by framework and control developers.
* @param TEventParameter the event parameter
*/
public function raisePostBackEvent($param)
{
if($this->getCausesValidation())
$this->getPage()->validate($this->getValidationGroup());
$this->onClick(new TBulletedListEventParameter((int)$param));
}
/**
* @return string tag name of the bulleted list
*/
protected function getTagName()
{
switch($this->getBulletStyle())
{
case 'Numbered':
case 'LowerAlpha':
case 'UpperAlpha':
case 'LowerRoman':
case 'UpperRoman':
return 'ol';
}
return 'ul';
}
/**
* Adds attribute name-value pairs to renderer.
* This overrides the parent implementation with additional bulleted list specific attributes.
* @param THtmlWriter the writer used for the rendering purpose
*/
protected function addAttributesToRender($writer)
{
$needStart=false;
switch($this->getBulletStyle())
{
case 'Numbered':
$writer->addStyleAttribute('list-style-type','decimal');
$needStart=true;
break;
case 'LowerAlpha':
$writer->addStyleAttribute('list-style-type','lower-alpha');
$needStart=true;
break;
case 'UpperAlpha':
$writer->addStyleAttribute('list-style-type','upper-alpha');
$needStart=true;
break;
case 'LowerRoman':
$writer->addStyleAttribute('list-style-type','lower-roman');
$needStart=true;
break;
case 'UpperRoman':
$writer->addStyleAttribute('list-style-type','upper-roman');
$needStart=true;
break;
case 'Disc':
$writer->addStyleAttribute('list-style-type','disc');
break;
case 'Circle':
$writer->addStyleAttribute('list-style-type','circle');
break;
case 'Square':
$writer->addStyleAttribute('list-style-type','square');
break;
case 'CustomImage':
$url=$this->getBulletImageUrl();
$writer->addStyleAttribute('list-style-image',"url($url)");
break;
}
if($needStart && ($start=$this->getFirstBulletNumber())!=1)
$writer->addAttribute('start',"$start");
parent::addAttributesToRender($writer);
}
/**
* @return string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
*/
public function getBulletImageUrl()
{
return $this->getViewState('BulletImageUrl','');
}
/**
* @param string image URL used for bullets when {@link getBulletStyle BulletStyle} is 'CustomImage'.
*/
public function setBulletImageUrl($value)
{
$this->setViewState('BulletImageUrl',$value,'');
}
/**
* @return string style of bullets. Defaults to 'NotSet'.
*/
public function getBulletStyle()
{
return $this->getViewState('BulletStyle','NotSet');
}
/**
* @return string style of bullets. Valid values include
* 'NotSet','Numbered','LowerAlpha','UpperAlpha','LowerRoman','UpperRoman','Disc','Circle','Square','CustomImage'
*/
public function setBulletStyle($value)
{
$this->setViewState('BulletStyle',TPropertyValue::ensureEnum($value,'NotSet','Numbered','LowerAlpha','UpperAlpha','LowerRoman','UpperRoman','Disc','Circle','Square','CustomImage'),'NotSet');
}
/**
* @param string display mode of the list. Defaults to 'Text'.
*/
public function getDisplayMode()
{
return $this->getViewState('DisplayMode','Text');
}
/**
* @return string display mode of the list. Valid values include
* 'Text', 'HyperLink', 'LinkButton'.
*/
public function setDisplayMode($value)
{
$this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'Text','HyperLink','LinkButton'),'Text');
}
/**
* @return integer starting index when {@link getBulletStyle BulletStyle} is one of
* the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
* Defaults to 1.
*/
public function getFirstBulletNumber()
{
return $this->getViewState('FirstBulletNumber',1);
}
/**
* @param integer starting index when {@link getBulletStyle BulletStyle} is one of
* the following: 'Numbered', 'LowerAlpha', 'UpperAlpha', 'LowerRoman', 'UpperRoman'.
*/
public function setFirstBulletNumber($value)
{
$this->setViewState('FirstBulletNumber',TPropertyValue::ensureInteger($value),1);
}
/**
* Raises 'Click' event.
* This method is invoked when the {@link getDisplayMode DisplayMode} is 'LinkButton'
* and end-users click on one of the buttons.
* @param TBulletedListEventParameter event parameter.
*/
public function onClick($param)
{
$this->raiseEvent('Click',$this,$param);
}
/**
* @return string the target window or frame to display the Web page content
* linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
* the hyperlinks is clicked.
*/
public function getTarget()
{
return $this->getViewState('Target','');
}
/**
* @param string the target window or frame to display the Web page content
* linked to when {@link getDisplayMode DisplayMode} is 'HyperLink' and one of
* the hyperlinks is clicked.
*/
public function setTarget($value)
{
$this->setViewState('Target',$value,'');
}
/**
* Renders the control.
* @param THtmlWriter the writer for the rendering purpose.
*/
protected function render($writer)
{
if($this->getHasItems())
parent::render($writer);
}
/**
* Renders the body contents.
* @param THtmlWriter the writer for the rendering purpose.
*/
protected function renderContents($writer)
{
$this->_isEnabled=$this->getEnabled(true);
$this->_postBackOptions=$this->getPostBackOptions();
$writer->writeLine();
foreach($this->getItems() as $index=>$item)
{
if($item->getHasAttributes())
{
foreach($item->getAttributes() as $name=>$value)
$writer->addAttribute($name,$value);
}
$writer->renderBeginTag('li');
$this->renderBulletText($writer,$item,$index);
$writer->renderEndTag();
$writer->writeLine();
}
}
/**
* Renders each item
* @param THtmlWriter writer for the rendering purpose
* @param TListItem item to be rendered
* @param integer index of the item being rendered
*/
protected function renderBulletText($writer,$item,$index)
{
switch($this->getDisplayMode())
{
case 'Text':
if($item->getEnabled())
$writer->write(THttpUtility::htmlEncode($item->getText()));
else
{
$writer->addAttribute('disabled','disabled');
$writer->renderBeginTag('span');
$writer->write(THttpUtility::htmlEncode($item->getText()));
$writer->renderEndTag();
}
return;
case 'HyperLink':
if(!$this->_isEnabled || !$item->getEnabled())
$writer->addAttribute('disabled','disabled');
else
{
$writer->addAttribute('href',$item->getValue());
if(($target=$this->getTarget())!=='')
$writer->addAttribute('target',$target);
}
break;
case 'LinkButton':
if(!$this->_isEnabled || !$item->getEnabled())
$writer->addAttribute('disabled','disabled');
else
{
$postback=$this->getPage()->getClientScript()->getPostBackEventReference($this,"$index",$this->_postBackOptions);
$writer->addAttribute('href',$postback);
}
}
if(($accesskey=$this->getAccessKey())!=='')
$writer->addAttribute('accesskey',$accesskey);
$writer->renderBeginTag('a');
$writer->write(THttpUtility::htmlEncode($item->getText()));
$writer->renderEndTag();
}
/**
* @return TPostBackOptions postback options used for linkbuttons.
*/
protected function getPostBackOptions()
{
$option=new TPostBackOptions();
$group = $this->getValidationGroup();
$hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
if($this->getCausesValidation() && $hasValidators)
{
$options->setPerformValidation(true);
$options->setValidationGroup($this->getValidationGroup());
return $options;
}
else
return null;
}
}
/**
* TBulletedListEventParameter
* Event parameter for {@link TBulletedList::onClick Click} event of the
* bulleted list. The {@link getIndex Index} gives the zero-based index
* of the item that is currently being clicked.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TBulletedListEventParameter extends TEventParameter
{
/**
* @var integer index of the item clicked
*/
private $_index;
/**
* Constructor.
* @param integer index of the item clicked
*/
public function __construct($index)
{
$this->_index=$index;
}
/**
* @return integer zero-based index of the item (rendered as a link button) that is clicked
*/
public function getIndex()
{
return $this->_index;
}
}
?>
|