summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TImage.php
blob: 0033209ad4df921135aa09b5c6c7f9a21d1d1899 (plain)
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
<?php
/**
 * TImage class file.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.xisc.com/
 * @copyright Copyright &copy; 2004-2005, Qiang Xue
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
 * @version $Revision: $  $Date: $
 * @package System.Web.UI.WebControls
 */

/**
 * TImage class
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @version $Revision: $  $Date: $
 * @package System.Web.UI.WebControls
 * @since 3.0
 */
class TImage extends TWebControl
{
	public static $IMAGE_ALIGN=array('NotSet','AbsBottom','AbsMiddle','Baseline','Bottom','Left','Middle','Right','TextTop','Top');
	// todo: TControl::resolveClientUrl()
	/**
	 * @return string tag name of the image
	 */
	protected function getTagName()
	{
		return 'img';
	}

	protected function addAttributesToRender($writer)
	{
		$writer->addAttribute('src',$this->getImageUrl());
		$writer->addAttribute('alt',$this->getAlternateText());
		if(($desc=$this->getDescriptionUrl())!=='')
			$writer->addAttribute('longdesc',$this->resolveClientUrl($desc));
		if(($align=$this->getImageAlign())!=='NotSet')
			$writer->addAttribute('align',strtolower($align));
		parent::addAttributesToRender($writer);
	}

	/**
	 * Renders the body content of the image.
	 * None will be rendered for an image.
	 * @param THtmlWriter the writer for rendering
	 */
	protected function renderContents($writer)
	{
	}

	/**
	 * @return string the alternative text displayed in the TImage component when the image is unavailable.
	 */
	public function getAlternateText()
	{
		return $this->getViewState('AlternateText','');
	}

	/**
	 * Sets the alternative text to be displayed in the TImage when the image is unavailable.
	 * @param string the alternative text
	 */
	public function setAlternateText($value)
	{
		$this->setViewState('AlternateText',$value,'');
	}

	/**
	 * @return string the alignment of the image with respective to other elements on the page.
	 */
	public function getImageAlign()
	{
		return $this->getViewState('ImageAlign','');
	}

	/**
	 * Sets the alignment of the image with respective to other elements on the page.
	 * @param string the alignment of the image
	 */
	public function setImageAlign($value)
	{
		$this->setViewState('ImageAlign',TPropertyValue::ensureEnum($value,self::$IMAGE_ALIGN),'NotSet');
	}

	/**
	 * @return string the location of the image file to be displayed
	 */
	public function getImageUrl()
	{
		return $this->getViewState('ImageUrl','');
	}

	/**
	 * Sets the location of the image file to be displayed.
	 * @param string the location of the image file (file path or URL)
	 */
	public function setImageUrl($value)
	{
		$this->setViewState('ImageUrl',$value,'');
	}

	/**
	 * @return string link to long description
	 */
	public function getDescriptionUrl()
	{
		return $this->getViewState('DescriptionUrl','');
	}

	/**
	 * Sets the link to long description
	 * @param string the link to long description
	 */
	public function setDescriptionUrl($value)
	{
		$this->setViewState('DescriptionUrl',$value,'');
	}
}

?>