| [ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TImageMap and related 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: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * Includes TImage class file 15 */ 16 Prado::using('System.Web.UI.WebControls.TImage'); 17 18 /** 19 * TImageMap class 20 * 21 * TImageMap represents an image on a page. Hotspot regions can be defined 22 * within the image. Depending on the {@link setHotSpotMode HotSpotMode}, 23 * clicking on the hotspots may trigger a postback or navigate to a specified 24 * URL. The hotspots defined may be accessed via {@link getHotSpots HotSpots}. 25 * Each hotspot is described as a {@link THotSpot}, which can be a circle, 26 * rectangle, polygon, etc. To add hotspot in a template, use the following, 27 * <code> 28 * <com:TImageMap> 29 * <com:TCircleHotSpot ... /> 30 * <com:TRectangleHotSpot ... /> 31 * <com:TPolygonHotSpot ... /> 32 * </com:TImageMap> 33 * </code> 34 * 35 * @author Qiang Xue <qiang.xue@gmail.com> 36 * @version $Id: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 37 * @package System.Web.UI.WebControls 38 * @since 3.0 39 */ 40 class TImageMap extends TImage implements IPostBackEventHandler 41 { 42 const MAP_NAME_PREFIX='ImageMap'; 43 44 /** 45 * Processes an object that is created during parsing template. 46 * This method adds {@link THotSpot} objects into the hotspot collection 47 * of the imagemap. 48 * @param string|TComponent text string or component parsed and instantiated in template 49 */ 50 public function addParsedObject($object) 51 { 52 if($object instanceof THotSpot) 53 $this->getHotSpots()->add($object); 54 } 55 56 /** 57 * Adds attribute name-value pairs to renderer. 58 * This overrides the parent implementation with additional imagemap specific attributes. 59 * @param THtmlWriter the writer used for the rendering purpose 60 */ 61 protected function addAttributesToRender($writer) 62 { 63 parent::addAttributesToRender($writer); 64 if($this->getHotSpots()->getCount()>0) 65 { 66 $writer->addAttribute('usemap','#'.self::MAP_NAME_PREFIX.$this->getClientID()); 67 $writer->addAttribute('id',$this->getUniqueID()); 68 } 69 if($this->getEnabled() && !$this->getEnabled(true)) 70 $writer->addAttribute('disabled','disabled'); 71 } 72 73 /** 74 * Renders this imagemap. 75 * @param THtmlWriter 76 */ 77 public function render($writer) 78 { 79 parent::render($writer); 80 81 $hotspots=$this->getHotSpots(); 82 83 if($hotspots->getCount()>0) 84 { 85 $clientID=$this->getClientID(); 86 $cs=$this->getPage()->getClientScript(); 87 $writer->writeLine(); 88 $writer->addAttribute('name',self::MAP_NAME_PREFIX.$clientID); 89 $writer->renderBeginTag('map'); 90 $writer->writeLine(); 91 if(($mode=$this->getHotSpotMode())===THotSpotMode::NotSet) 92 $mode=THotSpotMode::Navigate; 93 $target=$this->getTarget(); 94 $i=0; 95 $options['EventTarget'] = $this->getUniqueID(); 96 $options['StopEvent'] = true; 97 foreach($hotspots as $hotspot) 98 { 99 if($hotspot->getHotSpotMode()===THotSpotMode::NotSet) 100 $hotspot->setHotSpotMode($mode); 101 if($target!=='' && $hotspot->getTarget()==='') 102 $hotspot->setTarget($target); 103 if($hotspot->getHotSpotMode()===THotSpotMode::PostBack) 104 { 105 $id=$clientID.'_'.$i; 106 $writer->addAttribute('id',$id); 107 $writer->addAttribute('href','#'.$id); //create unique no-op url references 108 $options['ID']=$id; 109 $options['EventParameter']="$i"; 110 $options['CausesValidation']=$hotspot->getCausesValidation(); 111 $options['ValidationGroup']=$hotspot->getValidationGroup(); 112 $cs->registerPostBackControl('Prado.WebUI.TImageMap',$options); 113 } 114 $hotspot->render($writer); 115 $writer->writeLine(); 116 $i++; 117 } 118 $writer->renderEndTag(); 119 } 120 } 121 122 /** 123 * Raises the postback event. 124 * This method is required by {@link IPostBackEventHandler} interface. 125 * This method is mainly used by framework and control developers. 126 * @param TEventParameter the event parameter 127 */ 128 public function raisePostBackEvent($param) 129 { 130 $postBackValue=null; 131 if($param!=='') 132 { 133 $index=TPropertyValue::ensureInteger($param); 134 $hotspots=$this->getHotSpots(); 135 if($index>=0 && $index<$hotspots->getCount()) 136 { 137 $hotspot=$hotspots->itemAt($index); 138 if(($mode=$hotspot->getHotSpotMode())===THotSpotMode::NotSet) 139 $mode=$this->getHotSpotMode(); 140 if($mode===THotSpotMode::PostBack) 141 { 142 $postBackValue=$hotspot->getPostBackValue(); 143 if($hotspot->getCausesValidation()) 144 $this->getPage()->validate($hotspot->getValidationGroup()); 145 } 146 } 147 } 148 if($postBackValue!==null) 149 $this->onClick(new TImageMapEventParameter($postBackValue)); 150 } 151 152 /** 153 * @return THotSpotMode the behavior of hotspot regions in this imagemap when they are clicked. Defaults to THotSpotMode::NotSet. 154 */ 155 public function getHotSpotMode() 156 { 157 return $this->getViewState('HotSpotMode',THotSpotMode::NotSet); 158 } 159 160 /** 161 * Sets the behavior of hotspot regions in this imagemap when they are clicked. 162 * If an individual hotspot has a mode other than 'NotSet', the mode set in this 163 * imagemap will be ignored. By default, 'NotSet' is equivalent to 'Navigate'. 164 * @param THotSpotMode the behavior of hotspot regions in this imagemap when they are clicked. 165 */ 166 public function setHotSpotMode($value) 167 { 168 $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'THotSpotMode'),THotSpotMode::NotSet); 169 } 170 171 /** 172 * @return THotSpotCollection collection of hotspots defined in this imagemap. 173 */ 174 public function getHotSpots() 175 { 176 if(($hotspots=$this->getViewState('HotSpots',null))===null) 177 { 178 $hotspots=new THotSpotCollection; 179 $this->setViewState('HotSpots',$hotspots); 180 } 181 return $hotspots; 182 } 183 184 /** 185 * @return string the target window or frame to display the new page when a hotspot region is clicked within the imagemap. Defaults to ''. 186 */ 187 public function getTarget() 188 { 189 return $this->getViewState('Target',''); 190 } 191 192 /** 193 * @param string the target window or frame to display the new page when a hotspot region is clicked within the imagemap. 194 */ 195 public function setTarget($value) 196 { 197 $this->setViewState('Target',TPropertyValue::ensureString($value),''); 198 } 199 200 /** 201 * Raises <b>OnClick</b> event. 202 * This method is invoked when a hotspot region is clicked within the imagemap. 203 * If you override this method, be sure to call the parent implementation 204 * so that the event handler can be invoked. 205 * @param TImageMapEventParameter event parameter to be passed to the event handlers 206 */ 207 public function onClick($param) 208 { 209 $this->raiseEvent('OnClick',$this,$param); 210 } 211 } 212 213 /** 214 * TImageMapEventParameter class. 215 * 216 * TImageMapEventParameter represents a postback event parameter 217 * when a hotspot is clicked and posts back in a {@link TImageMap}. 218 * To retrieve the post back value associated with the hotspot being clicked, 219 * access {@link getPostBackValue PostBackValue}. 220 * 221 * @author Qiang Xue <qiang.xue@gmail.com> 222 * @version $Id: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 223 * @package System.Web.UI.WebControls 224 * @since 3.0 225 */ 226 class TImageMapEventParameter extends TEventParameter 227 { 228 private $_postBackValue; 229 230 /** 231 * Constructor. 232 * @param string post back value associated with the hotspot clicked 233 */ 234 public function __construct($postBackValue) 235 { 236 $this->_postBackValue=$postBackValue; 237 } 238 239 /** 240 * @return string post back value associated with the hotspot clicked 241 */ 242 public function getPostBackValue() 243 { 244 return $this->_postBackValue; 245 } 246 } 247 248 /** 249 * THotSpotCollection class. 250 * 251 * THotSpotCollection represents a collection of hotspots in an imagemap. 252 * 253 * @author Qiang Xue <qiang.xue@gmail.com> 254 * @version $Id: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 255 * @package System.Web.UI.WebControls 256 * @since 3.0 257 */ 258 class THotSpotCollection extends TList 259 { 260 /** 261 * Inserts an item at the specified position. 262 * This overrides the parent implementation by inserting only {@link THotSpot}. 263 * @param integer the speicified position. 264 * @param mixed new item 265 * @throws TInvalidDataTypeException if the item to be inserted is not a THotSpot. 266 */ 267 public function insertAt($index,$item) 268 { 269 if($item instanceof THotSpot) 270 parent::insertAt($index,$item); 271 else 272 throw new TInvalidDataTypeException('hotspotcollection_hotspot_required'); 273 } 274 } 275 276 277 /** 278 * THotSpot class. 279 * 280 * THotSpot implements the basic functionality common to all hot spot shapes. 281 * Derived classes include {@link TCircleHotSpot}, {@link TPolygonHotSpot} 282 * and {@link TRectangleHotSpot}. 283 * 284 * @author Qiang Xue <qiang.xue@gmail.com> 285 * @version $Id: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 286 * @package System.Web.UI.WebControls 287 * @since 3.0 288 */ 289 abstract class THotSpot extends TComponent 290 { 291 private $_viewState=array(); 292 293 /** 294 * Returns a viewstate value. 295 * 296 * This function is very useful in defining getter functions for component properties 297 * that must be kept in viewstate. 298 * @param string the name of the viewstate value to be returned 299 * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned 300 * @return mixed the viewstate value corresponding to $key 301 */ 302 protected function getViewState($key,$defaultValue=null) 303 { 304 return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue; 305 } 306 307 /** 308 * Sets a viewstate value. 309 * 310 * This function is very useful in defining setter functions for control properties 311 * that must be kept in viewstate. 312 * Make sure that the viewstate value must be serializable and unserializable. 313 * @param string the name of the viewstate value 314 * @param mixed the viewstate value to be set 315 * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate. 316 */ 317 protected function setViewState($key,$value,$defaultValue=null) 318 { 319 if($value===$defaultValue) 320 unset($this->_viewState[$key]); 321 else 322 $this->_viewState[$key]=$value; 323 } 324 325 /** 326 * @return string shape of the hotspot, can be 'circle', 'rect', 'poly', etc. 327 */ 328 abstract public function getShape(); 329 /** 330 * @return string coordinates defining the hotspot shape. 331 */ 332 abstract public function getCoordinates(); 333 334 /** 335 * @return string the access key that allows you to quickly navigate to the HotSpot region. Defaults to ''. 336 */ 337 public function getAccessKey() 338 { 339 return $this->getViewState('AccessKey',''); 340 } 341 342 /** 343 * @param string the access key that allows you to quickly navigate to the HotSpot region. 344 */ 345 public function setAccessKey($value) 346 { 347 $this->setViewState('AccessKey',TPropertyValue::ensureString($value),''); 348 } 349 350 /** 351 * @return string the alternate text to display for a HotSpot object. Defaults to ''. 352 */ 353 public function getAlternateText() 354 { 355 return $this->getViewState('AlternateText',''); 356 } 357 358 /** 359 * @param string the alternate text to display for a HotSpot object. 360 */ 361 public function setAlternateText($value) 362 { 363 $this->setViewState('AlternateText',TPropertyValue::ensureString($value),''); 364 } 365 366 /** 367 * @return THotSpotMode the behavior of a HotSpot object when it is clicked. Defaults to THotSpotMode::NotSet. 368 */ 369 public function getHotSpotMode() 370 { 371 return $this->getViewState('HotSpotMode',THotSpotMode::NotSet); 372 } 373 374 /** 375 * @param THotSpotMode the behavior of a HotSpot object when it is clicked. 376 */ 377 public function setHotSpotMode($value) 378 { 379 $this->setViewState('HotSpotMode',TPropertyValue::ensureEnum($value,'THotSpotMode'),THotSpotMode::NotSet); 380 } 381 382 /** 383 * @return string the URL to navigate to when a HotSpot object is clicked. Defaults to ''. 384 */ 385 public function getNavigateUrl() 386 { 387 return $this->getViewState('NavigateUrl',''); 388 } 389 390 /** 391 * @param string the URL to navigate to when a HotSpot object is clicked. 392 */ 393 public function setNavigateUrl($value) 394 { 395 $this->setViewState('NavigateUrl',TPropertyValue::ensureString($value),''); 396 } 397 398 /** 399 * @return string a value that is post back when the HotSpot is clicked. Defaults to ''. 400 */ 401 public function getPostBackValue() 402 { 403 return $this->getViewState('PostBackValue',''); 404 } 405 406 /** 407 * @param string a value that is post back when the HotSpot is clicked. 408 */ 409 public function setPostBackValue($value) 410 { 411 $this->setViewState('PostBackValue',TPropertyValue::ensureString($value),''); 412 } 413 414 /** 415 * @return integer the tab index of the HotSpot region. Defaults to 0. 416 */ 417 public function getTabIndex() 418 { 419 return $this->getViewState('TabIndex',0); 420 } 421 422 /** 423 * @param integer the tab index of the HotSpot region. 424 */ 425 public function setTabIndex($value) 426 { 427 $this->setViewState('TabIndex',TPropertyValue::ensureInteger($value),0); 428 } 429 430 /** 431 * @return boolean whether postback event trigger by this hotspot will cause input validation, default is true 432 */ 433 public function getCausesValidation() 434 { 435 return $this->getViewState('CausesValidation',true); 436 } 437 438 /** 439 * @param boolean whether postback event trigger by this hotspot will cause input validation 440 */ 441 public function setCausesValidation($value) 442 { 443 $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true); 444 } 445 446 /** 447 * @return string the group of validators which the hotspot causes validation upon postback 448 */ 449 public function getValidationGroup() 450 { 451 return $this->getViewState('ValidationGroup',''); 452 } 453 454 /** 455 * @param string the group of validators which the hotspot causes validation upon postback 456 */ 457 public function setValidationGroup($value) 458 { 459 $this->setViewState('ValidationGroup',$value,''); 460 } 461 462 /** 463 * @return string the target window or frame to display the new page when the HotSpot region 464 * is clicked. Defaults to ''. 465 */ 466 public function getTarget() 467 { 468 return $this->getViewState('Target',''); 469 } 470 471 /** 472 * @param string the target window or frame to display the new page when the HotSpot region 473 * is clicked. 474 */ 475 public function setTarget($value) 476 { 477 $this->setViewState('Target',TPropertyValue::ensureString($value),''); 478 } 479 480 /** 481 * Renders this hotspot. 482 * @param THtmlWriter 483 */ 484 public function render($writer) 485 { 486 $writer->addAttribute('shape',$this->getShape()); 487 $writer->addAttribute('coords',$this->getCoordinates()); 488 if(($mode=$this->getHotSpotMode())===THotSpotMode::NotSet) 489 $mode=THotSpotMode::Navigate; 490 if($mode===THotSpotMode::Navigate) 491 { 492 $writer->addAttribute('href',$this->getNavigateUrl()); 493 if(($target=$this->getTarget())!=='') 494 $writer->addAttribute('target',$target); 495 } 496 else if($mode===THotSpotMode::Inactive) 497 $writer->addAttribute('nohref','true'); 498 $text=$this->getAlternateText(); 499 $writer->addAttribute('title',$text); 500 $writer->addAttribute('alt',$text); 501 if(($accessKey=$this->getAccessKey())!=='') 502 $writer->addAttribute('accesskey',$accessKey); 503 if(($tabIndex=$this->getTabIndex())!==0) 504 $writer->addAttribute('tabindex',"$tabIndex"); 505 $writer->renderBeginTag('area'); 506 $writer->renderEndTag(); 507 } 508 } 509 510 /** 511 * Class TCircleHotSpot. 512 * 513 * TCircleHotSpot defines a circular hot spot region in a {@link TImageMap} 514 * control. 515 * 516 * @author Qiang Xue <qiang.xue@gmail.com> 517 * @version $Id: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 518 * @package System.Web.UI.WebControls 519 * @since 3.0 520 */ 521 class TCircleHotSpot extends THotSpot 522 { 523 /** 524 * @return string shape of this hotspot. 525 */ 526 public function getShape() 527 { 528 return 'circle'; 529 } 530 531 /** 532 * @return string coordinates defining this hotspot shape 533 */ 534 public function getCoordinates() 535 { 536 return $this->getX().','.$this->getY().','.$this->getRadius(); 537 } 538 539 /** 540 * @return integer radius of the circular HotSpot region. Defaults to 0. 541 */ 542 public function getRadius() 543 { 544 return $this->getViewState('Radius',0); 545 } 546 547 /** 548 * @param integer radius of the circular HotSpot region. 549 */ 550 public function setRadius($value) 551 { 552 $this->setViewState('Radius',TPropertyValue::ensureInteger($value),0); 553 } 554 555 /** 556 * @return integer the X coordinate of the center of the circular HotSpot region. Defaults to 0. 557 */ 558 public function getX() 559 { 560 return $this->getViewState('X',0); 561 } 562 563 /** 564 * @param integer the X coordinate of the center of the circular HotSpot region. 565 */ 566 public function setX($value) 567 { 568 $this->setViewState('X',TPropertyValue::ensureInteger($value),0); 569 } 570 571 /** 572 * @return integer the Y coordinate of the center of the circular HotSpot region. Defaults to 0. 573 */ 574 public function getY() 575 { 576 return $this->getViewState('Y',0); 577 } 578 579 /** 580 * @param integer the Y coordinate of the center of the circular HotSpot region. 581 */ 582 public function setY($value) 583 { 584 $this->setViewState('Y',TPropertyValue::ensureInteger($value),0); 585 } 586 } 587 588 /** 589 * Class TRectangleHotSpot. 590 * 591 * TRectangleHotSpot defines a rectangle hot spot region in a {@link 592 * TImageMap} control. 593 * 594 * @author Qiang Xue <qiang.xue@gmail.com> 595 * @version $Id: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 596 * @package System.Web.UI.WebControls 597 * @since 3.0 598 */ 599 class TRectangleHotSpot extends THotSpot 600 { 601 /** 602 * @return string shape of this hotspot. 603 */ 604 public function getShape() 605 { 606 return 'rect'; 607 } 608 609 /** 610 * @return string coordinates defining this hotspot shape 611 */ 612 public function getCoordinates() 613 { 614 return $this->getLeft().','.$this->getTop().','.$this->getRight().','.$this->getBottom(); 615 } 616 617 /** 618 * @return integer the Y coordinate of the bottom side of the rectangle HotSpot region. Defaults to 0. 619 */ 620 public function getBottom() 621 { 622 return $this->getViewState('Bottom',0); 623 } 624 625 /** 626 * @param integer the Y coordinate of the bottom side of the rectangle HotSpot region. 627 */ 628 public function setBottom($value) 629 { 630 $this->setViewState('Bottom',TPropertyValue::ensureInteger($value),0); 631 } 632 633 /** 634 * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0. 635 */ 636 public function getLeft() 637 { 638 return $this->getViewState('Left',0); 639 } 640 641 /** 642 * @param integer the X coordinate of the right side of the rectangle HotSpot region. 643 */ 644 public function setLeft($value) 645 { 646 $this->setViewState('Left',TPropertyValue::ensureInteger($value),0); 647 } 648 649 /** 650 * @return integer the X coordinate of the right side of the rectangle HotSpot region. Defaults to 0. 651 */ 652 public function getRight() 653 { 654 return $this->getViewState('Right',0); 655 } 656 657 /** 658 * @param integer the X coordinate of the right side of the rectangle HotSpot region. 659 */ 660 public function setRight($value) 661 { 662 $this->setViewState('Right',TPropertyValue::ensureInteger($value),0); 663 } 664 665 /** 666 * @return integer the Y coordinate of the top side of the rectangle HotSpot region. Defaults to 0. 667 */ 668 public function getTop() 669 { 670 return $this->getViewState('Top',0); 671 } 672 673 /** 674 * @param integer the Y coordinate of the top side of the rectangle HotSpot region. 675 */ 676 public function setTop($value) 677 { 678 $this->setViewState('Top',TPropertyValue::ensureInteger($value),0); 679 } 680 } 681 682 /** 683 * Class TPolygonHotSpot. 684 * 685 * TPolygonHotSpot defines a polygon hot spot region in a {@link 686 * TImageMap} control. 687 * 688 * @author Qiang Xue <qiang.xue@gmail.com> 689 * @version $Id: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 690 * @package System.Web.UI.WebControls 691 * @since 3.0 692 */ 693 class TPolygonHotSpot extends THotSpot 694 { 695 /** 696 * @return string shape of this hotspot. 697 */ 698 public function getShape() 699 { 700 return 'poly'; 701 } 702 703 /** 704 * @return string coordinates of the vertices defining the polygon. 705 * Coordinates are concatenated together with comma ','. Each pair 706 * represents (x,y) of a vertex. 707 */ 708 public function getCoordinates() 709 { 710 return $this->getViewState('Coordinates',''); 711 } 712 713 /** 714 * @param string coordinates of the vertices defining the polygon. 715 * Coordinates are concatenated together with comma ','. Each pair 716 * represents (x,y) of a vertex. 717 */ 718 public function setCoordinates($value) 719 { 720 $this->setViewState('Coordinates',$value,''); 721 } 722 } 723 724 725 /** 726 * THotSpotMode class. 727 * THotSpotMode defines the enumerable type for the possible hot spot modes. 728 * 729 * The following enumerable values are defined: 730 * - NotSet: the mode is not specified 731 * - Navigate: clicking on the hotspot will redirect the browser to a different page 732 * - PostBack: clicking on the hotspot will cause a postback 733 * - Inactive: the hotspot is inactive (not clickable) 734 * 735 * @author Qiang Xue <qiang.xue@gmail.com> 736 * @version $Id: TImageMap.php 1397 2006-09-07 07:55:53Z wei $ 737 * @package System.Web.UI.WebControls 738 * @since 3.0.4 739 */ 740 class THotSpotMode extends TEnumerable 741 { 742 const NotSet='NotSet'; 743 const Navigate='Navigate'; 744 const PostBack='PostBack'; 745 const Inactive='Inactive'; 746 } 747 748 ?>
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 |