3 * THyperLink class file.
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.xisc.com/
7 * @copyright Copyright © 2005-2016 The PRADO Group
8 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
9 * @package System.Web.UI.WebControls
15 * THyperLink displays a hyperlink on a page. The hyperlink URL is specified
16 * via the {@link setNavigateUrl NavigateUrl} property, and link text is via
17 * the {@link setText Text} property. It is also possible to display an image
18 * by setting the {@link setImageUrl ImageUrl} property. In this case,
19 * the alignment of the image displayed is set by the
20 * {@link setImageAlign ImageAlign} property and {@link getText Text} is
21 * displayed as the alternate text of the image.
23 * The link target is specified via the {@link setTarget Target} property.
24 * If both {@link getImageUrl ImageUrl} and {@link getText Text} are empty,
25 * the content enclosed within the control tag will be rendered.
27 * @author Qiang Xue <qiang.xue@gmail.com>
28 * @package System.Web.UI.WebControls
31 class THyperLink extends TWebControl implements IDataRenderer
34 * @return string tag name of the hyperlink
36 protected function getTagName()
42 * Adds attributes related to a hyperlink element to renderer.
43 * @param THtmlWriter the writer used for the rendering purpose
45 protected function addAttributesToRender($writer)
47 $isEnabled=$this->getEnabled(true);
48 if($this->getEnabled() && !$isEnabled)
49 $writer->addAttribute('disabled','disabled');
50 parent::addAttributesToRender($writer);
51 if(($url=$this->getNavigateUrl())!=='' && $isEnabled)
52 $writer->addAttribute('href',$url);
53 if(($target=$this->getTarget())!=='')
54 $writer->addAttribute('target',$target);
58 * Renders the body content of the hyperlink.
59 * @param THtmlWriter the writer for rendering
61 public function renderContents($writer)
63 if(($imageUrl=$this->getImageUrl())==='')
65 if(($text=$this->getText())!=='')
66 $writer->write(THttpUtility::htmlEncode($text));
67 else if($this->getHasControls())
68 parent::renderContents($writer);
70 $writer->write(THttpUtility::htmlEncode($this->getNavigateUrl()));
74 $this->createImage($imageUrl)->renderControl($writer);
79 * Gets the TImage for rendering the ImageUrl property. This is not for
80 * creating dynamic images.
81 * @param string image url.
82 * @return TImage image control for rendering.
84 protected function createImage($imageUrl)
86 $image=Prado::createComponent('System.Web.UI.WebControls.TImage');
87 $image->setImageUrl($imageUrl);
88 if(($width=$this->getImageWidth())!=='')
89 $image->setWidth($width);
90 if(($height=$this->getImageHeight())!=='')
91 $image->setHeight($height);
92 if(($toolTip=$this->getToolTip())!=='')
93 $image->setToolTip($toolTip);
94 if(($text=$this->getText())!=='')
95 $image->setAlternateText($text);
96 if(($align=$this->getImageAlign())!=='')
97 $image->setImageAlign($align);
98 $image->setBorderWidth('0');
103 * @return string the text caption of the THyperLink
105 public function getText()
107 return $this->getViewState('Text','');
111 * Sets the text caption of the THyperLink.
112 * @param string the text caption to be set
114 public function setText($value)
116 $this->setViewState('Text',$value,'');
120 * @return string the alignment of the image with respective to other elements on the page, defaults to empty.
122 public function getImageAlign()
124 return $this->getViewState('ImageAlign','');
128 * Sets the alignment of the image with respective to other elements on the page.
129 * Possible values include: absbottom, absmiddle, baseline, bottom, left,
130 * middle, right, texttop, and top. If an empty string is passed in,
131 * imagealign attribute will not be rendered.
132 * @param string the alignment of the image
134 public function setImageAlign($value)
136 $this->setViewState('ImageAlign',$value,'');
140 * @return string height of the image in the THyperLink
142 public function getImageHeight()
144 return $this->getViewState('ImageHeight','');
148 * Sets the height of the image in the THyperLink
149 * @param string height of the image in the THyperLink
151 public function setImageHeight($value)
153 $this->setViewSTate('ImageHeight',$value,'');
157 * @return string the location of the image file for the THyperLink
159 public function getImageUrl()
161 return $this->getViewState('ImageUrl','');
165 * Sets the location of image file of the THyperLink.
166 * @param string the image file location
168 public function setImageUrl($value)
170 $this->setViewState('ImageUrl',$value,'');
174 * @return string width of the image in the THyperLink
176 public function getImageWidth()
178 return $this->getViewState('ImageWidth','');
182 * Sets the width of the image in the THyperLink
183 * @param string width of the image
185 public function setImageWidth($value)
187 $this->setViewState('ImageWidth',$value,'');
191 * @return string the URL to link to when the THyperLink component is clicked.
193 public function getNavigateUrl()
195 return $this->getViewState('NavigateUrl','');
199 * Sets the URL to link to when the THyperLink component is clicked.
200 * @param string the URL
202 public function setNavigateUrl($value)
204 $this->setViewState('NavigateUrl',$value,'');
208 * Returns the URL to link to when the THyperLink component is clicked.
209 * This method is required by {@link IDataRenderer}.
210 * It is the same as {@link getText()}.
211 * @return string the text caption
215 public function getData()
217 return $this->getText();
221 * Sets the URL to link to when the THyperLink component is clicked.
222 * This method is required by {@link IDataRenderer}.
223 * It is the same as {@link setText()}.
224 * @param string the text caption to be set
228 public function setData($value)
230 $this->setText($value);
234 * @return string the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
236 public function getTarget()
238 return $this->getViewState('Target','');
242 * Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
243 * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
245 public function setTarget($value)
247 $this->setViewState('Target',$value,'');