[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TWebControl class file. 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TWebControl.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * Includes TStyle and TWebAdapter definition 15 */ 16 Prado::using('System.Web.UI.WebControls.TStyle'); 17 Prado::using('System.Web.UI.WebControls.TWebControlAdapter'); 18 19 /** 20 * TWebControl class 21 * 22 * TWebControl is the base class for controls that share a common set 23 * of UI-related properties and methods. TWebControl-derived controls 24 * are usually associated with HTML tags. They thus have tag name, attributes 25 * and body contents. You can override {@link getTagName} to specify the tag name, 26 * {@link addAttributesToRender} to specify the attributes to be rendered, 27 * and {@link renderContents} to customize the body content rendering. 28 * TWebControl encapsulates a set of properties related with CSS style fields, 29 * such as {@link getBackColor BackColor}, {@link getBorderWidth BorderWidth}, etc. 30 * 31 * Subclasses of TWebControl typically needs to override {@link addAttributesToRender} 32 * and {@link renderContents}. The former is used to render the attributes 33 * of the HTML tag associated with the control, while the latter is to render 34 * the body contents enclosed within the HTML tag. 35 * 36 * @author Qiang Xue <qiang.xue@gmail.com> 37 * @version $Id: TWebControl.php 1397 2006-09-07 07:55:53Z wei $ 38 * @package System.Web.UI.WebControls 39 * @since 3.0 40 */ 41 class TWebControl extends TControl 42 { 43 /** 44 * Copies basic control attributes from another control. 45 * Properties including AccessKey, ToolTip, TabIndex, Enabled 46 * and Attributes are copied. 47 * @param TWebControl source control 48 */ 49 public function copyBaseAttributes(TWebControl $control) 50 { 51 $this->setAccessKey($control->getAccessKey()); 52 $this->setToolTip($control->getToolTip()); 53 $this->setTabIndex($control->getTabIndex()); 54 if(!$control->getEnabled()) 55 $this->setEnabled(false); 56 if($control->getHasAttributes()) 57 $this->getAttributes()->copyFrom($control->getAttributes()); 58 } 59 60 /** 61 * @return string the access key of the control 62 */ 63 public function getAccessKey() 64 { 65 return $this->getViewState('AccessKey',''); 66 } 67 68 /** 69 * Sets the access key of the control. 70 * Only one-character string can be set, or an exception will be raised. 71 * Pass in an empty string if you want to disable access key. 72 * @param string the access key to be set 73 * @throws TInvalidDataValueException if the access key is specified with more than one character 74 */ 75 public function setAccessKey($value) 76 { 77 if(strlen($value)>1) 78 throw new TInvalidDataValueException('webcontrol_accesskey_invalid',get_class($this),$value); 79 $this->setViewState('AccessKey',$value,''); 80 } 81 82 /** 83 * @return string the background color of the control 84 */ 85 public function getBackColor() 86 { 87 if($style=$this->getViewState('Style',null)) 88 return $style->getBackColor(); 89 else 90 return ''; 91 } 92 93 /** 94 * @param string the background color of the control 95 */ 96 public function setBackColor($value) 97 { 98 $this->getStyle()->setBackColor($value); 99 } 100 101 /** 102 * @return string the border color of the control 103 */ 104 public function getBorderColor() 105 { 106 if($style=$this->getViewState('Style',null)) 107 return $style->getBorderColor(); 108 else 109 return ''; 110 } 111 112 /** 113 * @param string the border color of the control 114 */ 115 public function setBorderColor($value) 116 { 117 $this->getStyle()->setBorderColor($value); 118 } 119 120 /** 121 * @return string the border style of the control 122 */ 123 public function getBorderStyle() 124 { 125 if($style=$this->getViewState('Style',null)) 126 return $style->getBorderStyle(); 127 else 128 return ''; 129 } 130 131 /** 132 * @param string the border style of the control 133 */ 134 public function setBorderStyle($value) 135 { 136 $this->getStyle()->setBorderStyle($value); 137 } 138 139 /** 140 * @return string the border width of the control 141 */ 142 public function getBorderWidth() 143 { 144 if($style=$this->getViewState('Style',null)) 145 return $style->getBorderWidth(); 146 else 147 return ''; 148 } 149 150 /** 151 * @param string the border width of the control 152 */ 153 public function setBorderWidth($value) 154 { 155 $this->getStyle()->setBorderWidth($value); 156 } 157 158 /** 159 * @return TFont the font of the control 160 */ 161 public function getFont() 162 { 163 return $this->getStyle()->getFont(); 164 } 165 166 /** 167 * @return string the foreground color of the control 168 */ 169 public function getForeColor() 170 { 171 if($style=$this->getViewState('Style',null)) 172 return $style->getForeColor(); 173 else 174 return ''; 175 } 176 177 /** 178 * @param string the foreground color of the control 179 */ 180 public function setForeColor($value) 181 { 182 $this->getStyle()->setForeColor($value); 183 } 184 185 /** 186 * @return string the height of the control 187 */ 188 public function getHeight() 189 { 190 if($style=$this->getViewState('Style',null)) 191 return $style->getHeight(); 192 else 193 return ''; 194 } 195 196 /** 197 * @param string the css class of the control 198 */ 199 public function setCssClass($value) 200 { 201 $this->getStyle()->setCssClass($value); 202 } 203 204 /** 205 * @return string the css class of the control 206 */ 207 public function getCssClass() 208 { 209 if($style=$this->getViewState('Style',null)) 210 return $style->getCssClass(); 211 else 212 return ''; 213 } 214 215 /** 216 * @param string the height of the control 217 */ 218 public function setHeight($value) 219 { 220 $this->getStyle()->setHeight($value); 221 } 222 223 /** 224 * @return boolean whether the control has defined any style information 225 */ 226 public function getHasStyle() 227 { 228 return $this->getViewState('Style',null)!==null; 229 } 230 231 /** 232 * Creates a style object to be used by the control. 233 * This method may be overriden by controls to provide customized style. 234 */ 235 protected function createStyle() 236 { 237 return new TStyle; 238 } 239 240 /** 241 * @return TStyle the object representing the css style of the control 242 */ 243 public function getStyle() 244 { 245 if($style=$this->getViewState('Style',null)) 246 return $style; 247 else 248 { 249 $style=$this->createStyle(); 250 $this->setViewState('Style',$style,null); 251 return $style; 252 } 253 } 254 255 /** 256 * Sets the css style string of the control. 257 * The style string will be prefixed to the styles set via other control properties (e.g. Height, Width). 258 * @param string the css style string 259 * @throws TInvalidDataValueException if the parameter is not a string 260 */ 261 public function setStyle($value) 262 { 263 if(is_string($value)) 264 $this->getStyle()->setCustomStyle($value); 265 else 266 throw new TInvalidDataValueException('webcontrol_style_invalid',get_class($this)); 267 } 268 269 /** 270 * @return integer the tab index of the control 271 */ 272 public function getTabIndex() 273 { 274 return $this->getViewState('TabIndex',0); 275 } 276 277 /** 278 * Sets the tab index of the control. 279 * Pass 0 if you want to disable tab index. 280 * @param integer the tab index to be set 281 */ 282 public function setTabIndex($value) 283 { 284 $this->setViewState('TabIndex',TPropertyValue::ensureInteger($value),0); 285 } 286 287 /** 288 * Returns the tag name used for this control. 289 * By default, the tag name is 'span'. 290 * You can override this method to provide customized tag names. 291 * @return string tag name of the control to be rendered 292 */ 293 protected function getTagName() 294 { 295 return 'span'; 296 } 297 298 /** 299 * @return string the tooltip of the control 300 */ 301 public function getToolTip() 302 { 303 return $this->getViewState('ToolTip',''); 304 } 305 306 /** 307 * Sets the tooltip of the control. 308 * Pass an empty string if you want to disable tooltip. 309 * @param string the tooltip to be set 310 */ 311 public function setToolTip($value) 312 { 313 $this->setViewState('ToolTip',$value,''); 314 } 315 316 /** 317 * @return string the width of the control 318 */ 319 public function getWidth() 320 { 321 if($style=$this->getViewState('Style',null)) 322 return $style->getWidth(); 323 else 324 return ''; 325 } 326 327 /** 328 * @param string the width of the control 329 */ 330 public function setWidth($value) 331 { 332 $this->getStyle()->setWidth($value); 333 } 334 335 /** 336 * Adds attribute name-value pairs to renderer. 337 * By default, the method will render 'id', 'accesskey', 'disabled', 338 * 'tabindex', 'title' and all custom attributes. 339 * The method can be overriden to provide customized attribute rendering. 340 * @param THtmlWriter the writer used for the rendering purpose 341 */ 342 protected function addAttributesToRender($writer) 343 { 344 if($this->getID()!=='') 345 $writer->addAttribute('id',$this->getClientID()); 346 if(($accessKey=$this->getAccessKey())!=='') 347 $writer->addAttribute('accesskey',$accessKey); 348 if(!$this->getEnabled()) 349 $writer->addAttribute('disabled','disabled'); 350 if(($tabIndex=$this->getTabIndex())>0) 351 $writer->addAttribute('tabindex',"$tabIndex"); 352 if(($toolTip=$this->getToolTip())!=='') 353 $writer->addAttribute('title',$toolTip); 354 if($style=$this->getViewState('Style',null)) 355 $style->addAttributesToRender($writer); 356 if($this->getHasAttributes()) 357 { 358 foreach($this->getAttributes() as $name=>$value) 359 $writer->addAttribute($name,$value); 360 } 361 } 362 363 /** 364 * Renders the control. 365 * This method overrides the parent implementation by replacing it with 366 * the following sequence: 367 * - {@link renderBeginTag} 368 * - {@link renderContents} 369 * - {@link renderEndTag} 370 * @param THtmlWriter the writer used for the rendering purpose 371 */ 372 public function render($writer) 373 { 374 $this->renderBeginTag($writer); 375 $this->renderContents($writer); 376 $this->renderEndTag($writer); 377 } 378 379 /** 380 * Renders the openning tag for the control (including attributes) 381 * @param THtmlWriter the writer used for the rendering purpose 382 */ 383 public function renderBeginTag($writer) 384 { 385 $this->addAttributesToRender($writer); 386 $writer->renderBeginTag($this->getTagName()); 387 } 388 389 /** 390 * Renders the body content enclosed between the control tag. 391 * By default, child controls and text strings will be rendered. 392 * You can override this method to provide customized content rendering. 393 * @param THtmlWriter the writer used for the rendering purpose 394 */ 395 public function renderContents($writer) 396 { 397 parent::renderChildren($writer); 398 } 399 400 /** 401 * Renders the closing tag for the control 402 * @param THtmlWriter the writer used for the rendering purpose 403 */ 404 public function renderEndTag($writer) 405 { 406 $writer->renderEndTag(); 407 } 408 } 409 410 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |