summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TPanel.php
blob: ae6a1244e53f745fda6f1b8a3657dcae80e29449 (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
<?php
/**
 * TPanel class file
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2005 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @version $Revision: $  $Date: $
 * @package System.Web.UI.WebControls
 */

/**
 * TPanel class
 *
 * TPanel represents a component that acts as a container for other component.
 * It is especially useful when you want to generate components programmatically or hide/show a group of components.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @version $Revision: $  $Date: $
 * @package System.Web.UI.WebControls
 * @since 3.0
 */
class TPanel extends TWebControl
{
	/**
	 * @return string tag name of the panel
	 */
	protected function getTagName()
	{
		return 'div';
	}

	/**
	 * Adds attributes to renderer.
	 * @param THtmlWriter the renderer
	 */
	protected function addAttributesToRender($writer)
	{
		$url=trim($this->getBackImageUrl());
		if($url!=='')
			$this->getStyle
     base.AddAttributesToRender(writer);
      string text1 = this.BackImageUrl;
      if (text1.Trim().Length > 0)
      {
            writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + base.ResolveClientUrl(text1) + ")");
      }
      this.AddScrollingAttribute(this.ScrollBars, writer);
      HorizontalAlign align1 = this.HorizontalAlign;
      if (align1 != HorizontalAlign.NotSet)
      {
            TypeConverter converter1 = TypeDescriptor.GetConverter(typeof(HorizontalAlign));
            writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, converter1.ConvertToInvariantString(align1).ToLowerInvariant());
      }
      if (!this.Wrap)
      {
            if (base.EnableLegacyRendering)
            {
                  writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap", false);
            }
            else
            {
                  writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap");
            }
      }
      if (this.Direction == ContentDirection.LeftToRight)
      {
            writer.AddAttribute(HtmlTextWriterAttribute.Dir, "ltr");
      }
      else if (this.Direction == ContentDirection.RightToLeft)
      {
            writer.AddAttribute(HtmlTextWriterAttribute.Dir, "rtl");
      }
      if (((!base.DesignMode && (this.Page != null)) && ((this.Page.Request != null) && (this.Page.Request.Browser.EcmaScriptVersion.Major > 0))) && ((this.Page.Request.Browser.W3CDomVersion.Major > 0) && (this.DefaultButton.Length > 0)))
      {
            Control control1 = this.FindControl(this.DefaultButton);
            if (control1 is IButtonControl)
            {
                  this.Page.ClientScript.RegisterDefaultButtonScript(control1, writer, true);
            }
            else
            {
                  object[] objArray1 = new object[1] { this.ID } ;
                  throw new InvalidOperationException(SR.GetString("HtmlForm_OnlyIButtonControlCanBeDefaultButton", objArray1));
            }
      }

	}

	/**
	 * @return boolean whether the content wraps within the panel.
	 */
	public function getWrap()
	{
		return $this->getViewState('Wrap',true);
	}

	/**
	 * Sets the value indicating whether the content wraps within the panel.
	 * @param boolean whether the content wraps within the panel.
	 */
	public function setWrap($value)
	{
		$this->setViewState('Wrap',$value,true);
	}

	/**
	 * @return string the horizontal alignment of the contents within the panel.
	 */
	public function getHorizontalAlign()
	{
		return $this->getViewState('HorizontalAlign','');
	}

	/**
	 * Sets the horizontal alignment of the contents within the panel.
     * Valid values include 'justify', 'left', 'center', 'right' or empty string.
	 * @param string the horizontal alignment
	 */
	public function setHorizontalAlign($value)
	{
		$this->setViewState('HorizontalAlign',$value,'');
	}

	/**
	 * @return string the URL of the background image for the panel component.
	 */
	public function getBackImageUrl()
	{
		return $this->getViewState('BackImageUrl','');
	}

	/**
	 * Sets the URL of the background image for the panel component.
	 * @param string the URL
	 */
	public function setBackImageUrl($value)
	{
		$this->setViewState('BackImageUrl',$value,'');
	}

	/**
	 * This overrides the parent implementation by rendering more TPanel-specific attributes.
	 * @return ArrayObject the attributes to be rendered
	 */
	protected function getAttributesToRender()
	{
		$url=$this->getBackImageUrl();
		if(strlen($url))
			$this->setStyle(array('background-image'=>"url($url)"));
		$attributes=parent::getAttributesToRender();
		$align=$this->getHorizontalAlign();
		if(strlen($align))
			$attributes['align']=$align;
		if(!$this->isWrap())
			$attributes['nowrap']='nowrap';
		return $attributes;
	}
}

?>