|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* TPanelStyle class file |
|
4
|
|
|
* |
|
5
|
|
|
* @author Qiang Xue <[email protected]> |
|
6
|
|
|
* @link https://github.com/pradosoft/prado |
|
7
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
8
|
|
|
* @package Prado\Web\UI\WebControls |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Prado\Web\UI\WebControls; |
|
12
|
|
|
|
|
13
|
|
|
use Prado\TPropertyValue; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* TPanelStyle class. |
|
17
|
|
|
* TPanelStyle represents the CSS style specific for panel HTML tag. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Qiang Xue <[email protected]> |
|
20
|
|
|
* @package Prado\Web\UI\WebControls |
|
21
|
|
|
* @since 3.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class TPanelStyle extends TStyle |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string the URL of the background image for the panel component |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $_backImageUrl; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var string alignment of the content in the panel. |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $_direction; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var string horizontal alignment of the contents within the panel |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $_horizontalAlign; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var string visibility and position of scroll bars |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $_scrollBars; |
|
41
|
|
|
/** |
|
42
|
|
|
* @var bool whether the content wraps within the panel |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $_wrap; |
|
45
|
|
|
/** |
|
46
|
|
|
* @var bool whether the content wraps within the panel |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $_boxshadow; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns an array with the names of all variables of this object that should NOT be serialized |
|
52
|
|
|
* because their value is the default one or useless to be cached for the next page loads. |
|
53
|
|
|
* Reimplement in derived classes to add new variables, but remember to also to call the parent |
|
54
|
|
|
* implementation first. |
|
55
|
|
|
* @param array $exprops by reference |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function _getZappableSleepProps(&$exprops) |
|
58
|
|
|
{ |
|
59
|
|
|
parent::_getZappableSleepProps($exprops); |
|
60
|
|
|
if ($this->_backImageUrl === null) { |
|
61
|
|
|
$exprops[] = "\0*\0_backImageUrl"; |
|
62
|
|
|
} |
|
63
|
|
|
if ($this->_direction === null) { |
|
64
|
|
|
$exprops[] = "\0*\0_direction"; |
|
65
|
|
|
} |
|
66
|
|
|
if ($this->_horizontalAlign === null) { |
|
67
|
|
|
$exprops[] = "\0*\0_horizontalAlign"; |
|
68
|
|
|
} |
|
69
|
|
|
if ($this->_scrollBars === null) { |
|
70
|
|
|
$exprops[] = "\0*\0_scrollBars"; |
|
71
|
|
|
} |
|
72
|
|
|
if ($this->_wrap === null) { |
|
73
|
|
|
$exprops[] = "\0*\0_wrap"; |
|
74
|
|
|
} |
|
75
|
|
|
if ($this->_boxshadow === null) { |
|
76
|
|
|
$exprops[] = "\0*\0_boxshadow"; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Adds attributes related to CSS styles to renderer. |
|
82
|
|
|
* This method overrides the parent implementation. |
|
83
|
|
|
* @param \Prado\Web\UI\THtmlWriter $writer the writer used for the rendering purpose |
|
84
|
|
|
*/ |
|
85
|
|
|
public function addAttributesToRender($writer) |
|
86
|
|
|
{ |
|
87
|
|
|
if (($url = trim($this->getBackImageUrl())) !== '') { |
|
88
|
|
|
$this->setStyleField('background-image', 'url(' . $url . ')'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
switch ($this->getScrollBars()) { |
|
92
|
|
|
case TScrollBars::Horizontal: $this->setStyleField('overflow-x', 'scroll'); break; |
|
93
|
|
|
case TScrollBars::Vertical: $this->setStyleField('overflow-y', 'scroll'); break; |
|
94
|
|
|
case TScrollBars::Both: $this->setStyleField('overflow', 'scroll'); break; |
|
95
|
|
|
case TScrollBars::Auto: $this->setStyleField('overflow', 'auto'); break; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if (($align = $this->getHorizontalAlign()) !== THorizontalAlign::NotSet) { |
|
|
|
|
|
|
99
|
|
|
$this->setStyleField('text-align', strtolower($align)); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if (!$this->getWrap()) { |
|
103
|
|
|
$this->setStyleField('white-space', 'nowrap'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
if (($direction = $this->getDirection()) !== TContentDirection::NotSet) { |
|
|
|
|
|
|
107
|
|
|
if ($direction === TContentDirection::LeftToRight) { |
|
|
|
|
|
|
108
|
|
|
$this->setStyleField('direction', 'ltr'); |
|
109
|
|
|
} else { |
|
110
|
|
|
$this->setStyleField('direction', 'rtl'); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
if ($boxShadow = $this->getBoxShadow()) { |
|
114
|
|
|
$this->setStyleField('box-shadow', $boxShadow); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
parent::addAttributesToRender($writer); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string the URL of the background image for the panel component. |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getBackImageUrl() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->_backImageUrl === null ? '' : $this->_backImageUrl; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Sets the URL of the background image for the panel component. |
|
130
|
|
|
* @param string $value the URL |
|
131
|
|
|
*/ |
|
132
|
|
|
public function setBackImageUrl($value) |
|
133
|
|
|
{ |
|
134
|
|
|
$this->_backImageUrl = $value; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return TContentDirection alignment of the content in the panel. Defaults to TContentDirection::NotSet. |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getDirection() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->_direction === null ? TContentDirection::NotSet : $this->_direction; |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param TContentDirection $value alignment of the content in the panel. |
|
147
|
|
|
*/ |
|
148
|
|
|
public function setDirection($value) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->_direction = TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\TContentDirection'); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @return bool whether the content wraps within the panel. Defaults to true. |
|
155
|
|
|
*/ |
|
156
|
|
|
public function getWrap() |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->_wrap === null ? true : $this->_wrap; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Sets the value indicating whether the content wraps within the panel. |
|
163
|
|
|
* @param bool $value whether the content wraps within the panel. |
|
164
|
|
|
*/ |
|
165
|
|
|
public function setWrap($value) |
|
166
|
|
|
{ |
|
167
|
|
|
$this->_wrap = TPropertyValue::ensureBoolean($value); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return THorizontalAlign the horizontal alignment of the contents within the panel, defaults to THorizontalAlign::NotSet. |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getHorizontalAlign() |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->_horizontalAlign === null ? THorizontalAlign::NotSet : $this->_horizontalAlign; |
|
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Sets the horizontal alignment of the contents within the panel. |
|
180
|
|
|
* @param THorizontalAlign $value the horizontal alignment |
|
181
|
|
|
*/ |
|
182
|
|
|
public function setHorizontalAlign($value) |
|
183
|
|
|
{ |
|
184
|
|
|
$this->_horizontalAlign = TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\THorizontalAlign'); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @return TScrollBars the visibility and position of scroll bars in a panel control, defaults to TScrollBars::None. |
|
189
|
|
|
*/ |
|
190
|
|
|
public function getScrollBars() |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->_scrollBars === null ? TScrollBars::None : $this->_scrollBars; |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param TScrollBars $value the visibility and position of scroll bars in a panel control. |
|
197
|
|
|
*/ |
|
198
|
|
|
public function setScrollBars($value) |
|
199
|
|
|
{ |
|
200
|
|
|
$this->_scrollBars = TPropertyValue::ensureEnum($value, 'Prado\\Web\\UI\\WebControls\\TScrollBars'); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @return string the box shadow of the panel |
|
205
|
|
|
* @since 4.2.0 |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getBoxShadow() |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->_boxshadow === null ? '' : $this->_boxshadow; |
|
|
|
|
|
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @param string $value the box shadow of the panel |
|
214
|
|
|
* @since 4.2.0 |
|
215
|
|
|
*/ |
|
216
|
|
|
public function setBoxShadow($value) |
|
217
|
|
|
{ |
|
218
|
|
|
$this->_boxshadow = $value; |
|
|
|
|
|
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Sets the style attributes to default values. |
|
223
|
|
|
* This method overrides the parent implementation by |
|
224
|
|
|
* resetting additional TPanelStyle specific attributes. |
|
225
|
|
|
*/ |
|
226
|
|
|
public function reset() |
|
227
|
|
|
{ |
|
228
|
|
|
parent::reset(); |
|
229
|
|
|
$this->_backImageUrl = null; |
|
230
|
|
|
$this->_direction = null; |
|
231
|
|
|
$this->_horizontalAlign = null; |
|
232
|
|
|
$this->_scrollBars = null; |
|
233
|
|
|
$this->_wrap = null; |
|
234
|
|
|
$this->_boxshadow = null; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Copies the fields in a new style to this style. |
|
239
|
|
|
* If a style field is set in the new style, the corresponding field |
|
240
|
|
|
* in this style will be overwritten. |
|
241
|
|
|
* @param TStyle $style the new style |
|
242
|
|
|
*/ |
|
243
|
|
|
public function copyFrom($style) |
|
244
|
|
|
{ |
|
245
|
|
|
parent::copyFrom($style); |
|
246
|
|
|
if ($style instanceof TPanelStyle) { |
|
247
|
|
|
if ($style->_backImageUrl !== null) { |
|
248
|
|
|
$this->_backImageUrl = $style->_backImageUrl; |
|
249
|
|
|
} |
|
250
|
|
|
if ($style->_direction !== null) { |
|
251
|
|
|
$this->_direction = $style->_direction; |
|
252
|
|
|
} |
|
253
|
|
|
if ($style->_horizontalAlign !== null) { |
|
254
|
|
|
$this->_horizontalAlign = $style->_horizontalAlign; |
|
255
|
|
|
} |
|
256
|
|
|
if ($style->_scrollBars !== null) { |
|
257
|
|
|
$this->_scrollBars = $style->_scrollBars; |
|
258
|
|
|
} |
|
259
|
|
|
if ($style->_wrap !== null) { |
|
260
|
|
|
$this->_wrap = $style->_wrap; |
|
261
|
|
|
} |
|
262
|
|
|
if ($style->_boxshadow !== null) { |
|
263
|
|
|
$this->_boxshadow = $style->_boxshadow; |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Merges the style with a new one. |
|
270
|
|
|
* If a style field is not set in this style, it will be overwritten by |
|
271
|
|
|
* the new one. |
|
272
|
|
|
* @param TStyle $style the new style |
|
273
|
|
|
*/ |
|
274
|
|
|
public function mergeWith($style) |
|
275
|
|
|
{ |
|
276
|
|
|
parent::mergeWith($style); |
|
277
|
|
|
if ($style instanceof TPanelStyle) { |
|
278
|
|
|
if ($this->_backImageUrl === null && $style->_backImageUrl !== null) { |
|
279
|
|
|
$this->_backImageUrl = $style->_backImageUrl; |
|
280
|
|
|
} |
|
281
|
|
|
if ($this->_direction === null && $style->_direction !== null) { |
|
282
|
|
|
$this->_direction = $style->_direction; |
|
283
|
|
|
} |
|
284
|
|
|
if ($this->_horizontalAlign === null && $style->_horizontalAlign !== null) { |
|
285
|
|
|
$this->_horizontalAlign = $style->_horizontalAlign; |
|
286
|
|
|
} |
|
287
|
|
|
if ($this->_scrollBars === null && $style->_scrollBars !== null) { |
|
288
|
|
|
$this->_scrollBars = $style->_scrollBars; |
|
289
|
|
|
} |
|
290
|
|
|
if ($this->_wrap === null && $style->_wrap !== null) { |
|
291
|
|
|
$this->_wrap = $style->_wrap; |
|
292
|
|
|
} |
|
293
|
|
|
if ($this->_boxshadow === null && $style->_boxshadow !== null) { |
|
294
|
|
|
$this->_boxshadow = $style->_boxshadow; |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|