summaryrefslogtreecommitdiff
path: root/lib/prado/framework/Web/UI/WebControls/TInlineFrame.php
blob: ab0fb48aada3183577316df27a2a791a281ef10d (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
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
<?php
/**
 * TInlineFrame class file.
 *
 * @author Jason Ragsdale <jrags@jasrags.net>
 * @author Harry Pottash <hpottash@gmail.com>
 * @link https://github.com/pradosoft/prado
 * @copyright Copyright &copy; 2005-2016 The PRADO Group
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
 * @package System.Web.UI.WebControls
 */

/**
 * TInlineFrame class
 *
 * TInlineFrame displays an inline frame (iframe) on a Web page.
 * The location of the frame content is specified by {@link setFrameUrl FrameUrl}.
 * The frame's alignment is specified by {@link setAlign Align}.
 * The {@link setMarginWidth MarginWidth} and {@link setMarginHeight MarginHeight}
 * properties define the number of pixels to use as the left/right margins and
 * top/bottom margins, respectively, within the inline frame.
 * The {@link setScrollBars ScrollBars} property specifies whether scrollbars are
 * provided for the inline frame. And {@link setDescriptionUrl DescriptionUrl}
 * gives the URI of a long description of the frame's contents.
 *
 * Original Prado v2 IFrame Author Information
 * @author Jason Ragsdale <jrags@jasrags.net>
 * @author Harry Pottash <hpottash@gmail.com>
 * @package System.Web.UI.WebControls
 * @since 3.0
 */
class TInlineFrame extends TWebControl implements IDataRenderer
{
	/**
	 * @return string tag name of the iframe.
	 */
	protected function getTagName()
	{
		return 'iframe';
	}

	/**
	 * @return TInlineFrameAlign alignment of the iframe. Defaults to TInlineFrameAlign::NotSet.
	 */
	public function getAlign()
	{
		return $this->getViewState('Align',TInlineFrameAlign::NotSet);
	}

	/**
	 * @param TInlineFrameAlign alignment of the iframe.
	 */
	public function setAlign($value)
	{
		$this->setViewState('Align',TPropertyValue::ensureEnum($value,'TInlineFrameAlign'),TInlineFrameAlign::NotSet);
	}

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

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

	/**
	 * @return boolean whether there should be a visual separator between the frames. Defaults to true.
	 */
	public function getShowBorder()
	{
		return $this->getViewState('ShowBorder',true);
	}

	/**
	 * @param boolean whether there should be a visual separator between the frames.
	 */
	public function setShowBorder($value)
	{
		$this->setViewState('ShowBorder',TPropertyValue::ensureBoolean($value),true);
	}

	/**
	 * @return string URL that this iframe will load content from. Defaults to ''.
	 */
	public function getFrameUrl()
	{
		return $this->getViewState('FrameUrl','');
	}

	/**
	 * @param string URL that this iframe will load content from.
	 */
	public function setFrameUrl($value)
	{
		$this->setViewState('FrameUrl',$value,'');
	}

	/**
	 * Returns the URL that this iframe will load content from
	 * This method is required by {@link IDataRenderer}.
	 * It is the same as {@link getFrameUrl()}.
	 * @return string the URL that this iframe will load content from
	 * @see getFrameUrl
	 * @since 3.1.0
	 */
	public function getData()
	{
		return $this->getFrameUrl();
	}

	/**
	 * Sets the URL that this iframe will load content from.
	 * This method is required by {@link IDataRenderer}.
	 * It is the same as {@link setFrameUrl()}.
	 * @param string the URL that this iframe will load content from
	 * @see setFrameUrl
	 * @since 3.1.0
	 */
	public function setData($value)
	{
		$this->setFrameUrl($value);
	}

	/**
	 * @return TInlineFrameScrollBars the visibility and position of scroll bars in an iframe. Defaults to TInlineFrameScrollBars::Auto.
	 */
	public function getScrollBars()
	{
		return $this->getViewState('ScrollBars',TInlineFrameScrollBars::Auto);
	}

	/**
	 * @param TInlineFrameScrollBars the visibility and position of scroll bars in an iframe.
	 */
	public function setScrollBars($value)
	{
		$this->setViewState('ScrollBars',TPropertyValue::ensureEnum($value,'TInlineFrameScrollBars'),TInlineFrameScrollBars::Auto);
	}

	/**
	 * @return integer the width of the control
	 */
	public function getWidth()
	{
	  return $this->getViewState('Width',-1);
	}
	
	/**
	 * @param integer the width of the control
	 */
	public function setWidth($value)
	{
	  if(($value=TPropertyValue::ensureInteger($value))<0)
	    $value=-1;
	  $this->setViewState('Width',$value,-1);
	}
	
	/**
	 * @return integer the height of the control
	 */
	public function getHeight()
	{
	  return $this->getViewState('Height',-1);
	}
	
	/**
	 * @param integer the height of the control
	 */
	public function setHeight($value)
	{
	  if(($value=TPropertyValue::ensureInteger($value))<0)
	    $value=-1;
	  $this->setViewState('Height',$value,-1);
	}
	
	/**
	 * @return integer the amount of space, in pixels, that should be left between
	 * the frame's contents and the left and right margins. Defaults to -1, meaning not set.
	 */
	public function getMarginWidth()
	{
		return $this->getViewState('MarginWidth',-1);
	}

	/**
	 * @param integer the amount of space, in pixels, that should be left between
	 * the frame's contents and the left and right margins.
	 */
	public function setMarginWidth($value)
	{
		if(($value=TPropertyValue::ensureInteger($value))<0)
			$value=-1;
		$this->setViewState('MarginWidth',$value,-1);
	}

	/**
	 * @return integer the amount of space, in pixels, that should be left between
	 * the frame's contents and the top and bottom margins. Defaults to -1, meaning not set.
	 */
	public function getMarginHeight()
	{
		return $this->getViewState('MarginHeight',-1);
	}

	/**
	 * @param integer the amount of space, in pixels, that should be left between
	 * the frame's contents and the top and bottom margins.
	 */
	public function setMarginHeight($value)
	{
		if(($value=TPropertyValue::ensureInteger($value))<0)
			$value=-1;
		$this->setViewState('MarginHeight',$value,-1);
	}

	/**
	 * Adds attribute name-value pairs to renderer.
	 * This overrides the parent implementation with additional button specific attributes.
	 * @param THtmlWriter the writer used for the rendering purpose
	 */
	protected function addAttributesToRender($writer)
	{
		if($this->getID()!=='')
			$writer->addAttribute('name',$this->getUniqueID());

		if(($src=$this->getFrameUrl())!=='')
			$writer->addAttribute('src',$src);

		if(($align=strtolower($this->getAlign()))!=='notset')
			$writer->addAttribute('align',$align);

		$scrollBars=$this->getScrollBars();
		if($scrollBars===TInlineFrameScrollBars::None)
			$writer->addAttribute('scrolling','no');
		else if($scrollBars===TInlineFrameScrollBars::Both)
			$writer->addAttribute('scrolling','yes');

		if (!$this->getShowBorder())
			$writer->addAttribute('frameborder','0');

		if(($longdesc=$this->getDescriptionUrl())!=='')
			$writer->addAttribute('longdesc',$longdesc);
		
		if (($width=$this->getWidth())!==-1)
		  $writer->addAttribute('width',$width);
		
		if (($height=$this->getHeight())!==-1)
		  $writer->addAttribute('height',$height);

		if(($marginheight=$this->getMarginHeight())!==-1)
			$writer->addAttribute('marginheight',$marginheight);

		if(($marginwidth=$this->getMarginWidth())!==-1)
			$writer->addAttribute('marginwidth',$marginwidth);

		parent::addAttributesToRender($writer);
	}
}

/**
 * TInlineFrameAlign class.
 * TInlineFrameAlign defines the enumerable type for the possible alignments
 * that the content in a {@link TInlineFrame} could be.
 *
 * The following enumerable values are defined:
 * - NotSet: the alignment is not specified.
 * - Left: left aligned
 * - Right: right aligned
 * - Top: top aligned
 * - Middle: middle aligned
 * - Bottom: bottom aligned
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @package System.Web.UI.WebControls
 * @since 3.0.4
 */
class TInlineFrameAlign extends TEnumerable
{
	const NotSet='NotSet';
	const Left='Left';
	const Right='Right';
	const Top='Top';
	const Middle='Middle';
	const Bottom='Bottom';
}

/**
 * TInlineFrameScrollBars class.
 * TInlineFrameScrollBars defines the enumerable type for the possible scroll bar mode
 * that a {@link TInlineFrame} control could use.
 *
 * The following enumerable values are defined:
 * - None: no scroll bars.
 * - Auto: scroll bars automatically appeared when needed.
 * - Both: show both horizontal and vertical scroll bars all the time.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @package System.Web.UI.WebControls
 * @since 3.0.4
 */
class TInlineFrameScrollBars extends TEnumerable
{
	const None='None';
	const Auto='Auto';
	const Both='Both';
}