Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Panel.cs « WebControls « UI « System.Web « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc6bdc050eb348304ae4f8e17c07108d6e6a6c39 (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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

//------------------------------------------------------------------------------
// <copyright file="Panel.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.UI.WebControls {

    using System;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Web;
    using System.Web.UI;
    using System.Web.Util;

    /// <devdoc>
    ///    <para>Constructs a panel for specifies layout regions
    ///       on a page and defines its properties.</para>
    /// </devdoc>
    [
    Designer("System.Web.UI.Design.WebControls.PanelContainerDesigner, " + AssemblyRef.SystemDesign),
    ParseChildren(false),
    PersistChildren(true),
    ]
    public class Panel : WebControl {
        private string _defaultButton;
        private bool _renderedFieldSet = false;


        /// <devdoc>
        ///    Initializes a new instance of the <see cref='System.Web.UI.WebControls.Panel'/> class.
        /// </devdoc>
        public Panel()
            : base(HtmlTextWriterTag.Div) {
        }


        /// <devdoc>
        ///    <para>Gets or sets the URL of the background image for the panel control.</para>
        /// </devdoc>
        [
        WebCategory("Appearance"),
        DefaultValue(""),
        Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
        UrlProperty(),
        WebSysDescription(SR.Panel_BackImageUrl)
        ]
        public virtual string BackImageUrl {
            get {
                if (ControlStyleCreated == false) {
                    return String.Empty;
                }
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    return panelStyle.BackImageUrl;
                }
                string s = (string)ViewState["BackImageUrl"];
                return((s == null) ? String.Empty : s);
            }
            set {
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    panelStyle.BackImageUrl = value;
                }
                else {
                    ViewState["BackImageUrl"] = value;
                }
            }
        }


        /// <devdoc>
        ///     Gets or sets default button for the panel
        /// </devdoc>
        [
        DefaultValue(""),
        Themeable(false),
        WebCategory("Behavior"),
        WebSysDescription(SR.Panel_DefaultButton)
        ]
        public virtual string DefaultButton {
            get {
                if (_defaultButton == null) {
                    return String.Empty;
                }
                return _defaultButton;
            }
            set {
                _defaultButton = value;
            }
        }

        /// <devdoc>
        /// <para>Gets or sets the direction of text in the panel</para>
        /// </devdoc>
        [
        DefaultValue(ContentDirection.NotSet),
        WebCategory("Layout"),
        WebSysDescription(SR.Panel_Direction)
        ]
        public virtual ContentDirection Direction {
            get {
                if (ControlStyleCreated == false) {
                    return ContentDirection.NotSet;
                }
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    return panelStyle.Direction;
                }
                object direction = ViewState["Direction"];
                return direction == null ? ContentDirection.NotSet : (ContentDirection) direction;
            }
            set {
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    panelStyle.Direction = value;
                }
                else {
                    ViewState["Direction"] = value;
                }
            }
        }


        [
        Localizable(true),
        DefaultValue(""),
        WebCategory("Appearance"),
        WebSysDescription(SR.Panel_GroupingText)
        ]
        public virtual string GroupingText {
            get {
                string s = (string)ViewState["GroupingText"];
                return (s != null) ? s : String.Empty;
            }
            set {
                ViewState["GroupingText"] = value;
            }
        }


        /// <devdoc>
        ///    <para>Gets or sets the horizontal alignment of the contents within the panel.</para>
        /// </devdoc>
        [
        WebCategory("Layout"),
        DefaultValue(HorizontalAlign.NotSet),
        WebSysDescription(SR.Panel_HorizontalAlign)
        ]
        public virtual HorizontalAlign HorizontalAlign {
            get {
                if (ControlStyleCreated == false) {
                    return HorizontalAlign.NotSet;
                }
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    return panelStyle.HorizontalAlign;
                }
                object o = ViewState["HorizontalAlign"];
                return ((o == null) ? HorizontalAlign.NotSet : (HorizontalAlign)o);
            }
            set {
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    panelStyle.HorizontalAlign = value;
                }
                else {
                    if (value < HorizontalAlign.NotSet || value > HorizontalAlign.Justify) {
                        throw new ArgumentOutOfRangeException("value");
                    }
                    ViewState["HorizontalAlign"] = value;
                }
            }
        }

        public override bool SupportsDisabledAttribute {
            get {
                return RenderingCompatibility < VersionUtil.Framework40;
            }
        }

        /// <devdoc>
        /// <para>Gets or sets the scrollbar behavior of the panel.</para>
        /// </devdoc>
        [
        DefaultValue(ScrollBars.None),
        WebCategory("Layout"),
        WebSysDescription(SR.Panel_ScrollBars)
        ]
        public virtual ScrollBars ScrollBars {
            get {
                if (ControlStyleCreated == false) {
                    return ScrollBars.None;
                }
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    return panelStyle.ScrollBars;
                }
                object scroll = ViewState["ScrollBars"];
                return ((scroll == null) ? ScrollBars.None : (ScrollBars)scroll);
            }
            set {
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    panelStyle.ScrollBars = value;
                }
                else {
                    ViewState["ScrollBars"] = value;
                }
            }
        }


        /// <devdoc>
        ///    <para>Gets or sets a value
        ///       indicating whether the content wraps within the panel.</para>
        /// </devdoc>
        [
        WebCategory("Layout"),
        DefaultValue(true),
        WebSysDescription(SR.Panel_Wrap)
        ]
        public virtual bool Wrap {
            get {
                if (ControlStyleCreated == false) {
                    return true;
                }
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    return panelStyle.Wrap;
                }
                object b = ViewState["Wrap"];
                return ((b == null) ? true : (bool)b);
            }
            set {
                PanelStyle panelStyle = ControlStyle as PanelStyle;
                if (panelStyle != null) {
                    panelStyle.Wrap = value;
                }
                else {
                    ViewState["Wrap"] = value;
                }
            }
        }


        /// <internalonly/>
        /// <devdoc>
        ///    Add background-image to list of style attributes to render.
        ///    Add align and nowrap to list of attributes to render.
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer) {
            base.AddAttributesToRender(writer);

            string s = BackImageUrl;
            // Whidbey 12856
            if (s.Trim().Length > 0) {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + ResolveClientUrl(s) + ")");
            }

            AddScrollingAttribute(ScrollBars, writer);

            HorizontalAlign hAlign = HorizontalAlign;
            if (hAlign != HorizontalAlign.NotSet) {
                TypeConverter hac = TypeDescriptor.GetConverter(typeof(HorizontalAlign));
                writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, hac.ConvertToInvariantString(hAlign).ToLowerInvariant());
            }

            if (!Wrap) {
                if (EnableLegacyRendering) {
                    writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap", false);
                }
                else {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap");
                }
            }

            if (Direction == ContentDirection.LeftToRight) {
                writer.AddAttribute(HtmlTextWriterAttribute.Dir, "ltr");
            }
            else if (Direction == ContentDirection.RightToLeft) {
                writer.AddAttribute(HtmlTextWriterAttribute.Dir, "rtl");
            }

            if (!DesignMode &&
                (Page != null) &&
                (Page.RequestInternal != null) &&
                (Page.Request.Browser.EcmaScriptVersion.Major > 0) &&
                (Page.Request.Browser.W3CDomVersion.Major > 0)) {
                if (DefaultButton.Length > 0) {
                    // Find control from the page if it's a hierarchical ID.
                    // Dev11 bug 19915
                    Control c = FindControlFromPageIfNecessary(DefaultButton);

                    if (c is IButtonControl) {
                        Page.ClientScript.RegisterDefaultButtonScript(c, writer, true /* UseAddAttribute */);
                    }
                    else {
                        throw new InvalidOperationException(SR.GetString(SR.HtmlForm_OnlyIButtonControlCanBeDefaultButton, ID));
                    }
                }
            }
        }

        /// <devdoc>
        ///    [To be supplied.]
        /// </devdoc>
        private void AddScrollingAttribute(ScrollBars scrollBars, HtmlTextWriter writer) {
            switch (scrollBars) {
                case ScrollBars.Horizontal:
                    writer.AddStyleAttribute(HtmlTextWriterStyle.OverflowX, "scroll");
                    break;
                case ScrollBars.Vertical:
                    writer.AddStyleAttribute(HtmlTextWriterStyle.OverflowY, "scroll");
                    break;
                case ScrollBars.Both:
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "scroll");
                    break;
                case ScrollBars.Auto:
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "auto");
                    break;
                default:
                    break;
            }
        }


        /// <internalonly/>
        /// <devdoc>
        ///    <para>A protected method. Creates a panel control style.</para>
        /// </devdoc>
        protected override Style CreateControlStyle() {
            return new PanelStyle(ViewState);
        }


        /// <internalonly/>
        public override void RenderBeginTag(HtmlTextWriter writer) {
            AddAttributesToRender(writer);

            HtmlTextWriterTag tagKey = TagKey;
            if (tagKey != HtmlTextWriterTag.Unknown) {
                writer.RenderBeginTag(tagKey);
            }
            else {
                writer.RenderBeginTag(TagName);
            }

            string s = GroupingText;
            bool useGrouping = (s.Length != 0) && !(writer is Html32TextWriter);
            if (useGrouping) {
                writer.RenderBeginTag(HtmlTextWriterTag.Fieldset);
                _renderedFieldSet = true;
                writer.RenderBeginTag(HtmlTextWriterTag.Legend);
                writer.Write(s);
                writer.RenderEndTag();
            }
        }

        public override void RenderEndTag(HtmlTextWriter writer) {
            if (_renderedFieldSet) {
                writer.RenderEndTag();
            }
            base.RenderEndTag(writer);
        }
    }
}