File: HtmlInputImage.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (344 lines) | stat: -rw-r--r-- 10,525 bytes parent folder | download | duplicates (7)
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
//------------------------------------------------------------------------------
// <copyright file="HtmlInputImage.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

/*
 * HtmlInputImage.cs
 *
 * Copyright (c) 2000 Microsoft Corporation
 */

namespace System.Web.UI.HtmlControls {

    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Globalization;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Security.Permissions;


/// <devdoc>
///    <para>
///       The <see langword='HtmlInputImage'/> class defines the
///       methods, properties and events for the HtmlInputImage control. This class allows
///       programmatic access to the HTML &lt;input type=
///       image&gt; element on the server.
///    </para>
/// </devdoc>
    [
    DefaultEvent("ServerClick"),
    SupportsEventValidation,
    ]
    public class HtmlInputImage : HtmlInputControl,
    IPostBackDataHandler, IPostBackEventHandler {

        private static readonly object EventServerClick = new object();
        private int _x;
        private int _y;


        /*
         * Creates an intrinsic Html INPUT type=image control.
         */

        public HtmlInputImage() : base("image") {
        }


        /// <devdoc>
        ///    <para>
        ///       Gets or sets the image
        ///       alignment within the form's content flow.
        ///    </para>
        /// </devdoc>
        /*
         * Align property.
         */
        [
        WebCategory("Appearance"),
        DefaultValue(""),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public string Align {
            get {
                string s = Attributes["align"];
                return((s != null) ? s : String.Empty);
            }
            set {
                Attributes["align"] = MapStringAttributeToString(value);
            }
        }


        /// <devdoc>
        ///    <para>
        ///       Gets or sets the alternative text
        ///       that the browser should display if the image is either unavailable or has not
        ///       been downloaded yet.
        ///    </para>
        /// </devdoc>
        /*
         * Alt property.
         */
        [
        WebCategory("Appearance"),
        DefaultValue(""),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        Localizable(true)
        ]
        public string Alt {
            get {
                string s = Attributes["alt"];
                return((s != null) ? s : String.Empty);
            }
            set {
                Attributes["alt"] = MapStringAttributeToString(value);
            }
        }


        /// <devdoc>
        ///    <para>
        ///       Gets or sets the
        ///       border width, in pixels, around the image.
        ///    </para>
        /// </devdoc>
        /*
         * Border property, size of border in pixels.
         */
        [
        WebCategory("Appearance"),
        DefaultValue(-1),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public int Border {
            get {
                string s = Attributes["border"];
                return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
            }
            set {
                Attributes["border"] = MapIntegerAttributeToString(value);
            }
        }


        /// <devdoc>
        ///    <para>
        ///       Gets or sets the location of
        ///       the image file relative to the page on which it is displayed.
        ///    </para>
        /// </devdoc>
        /*
         * Src property.
         */
        [
        WebCategory("Appearance"),
        DefaultValue(""),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        UrlProperty()
        ]
        public string Src {
            get {
                string s = Attributes["src"];
                return((s != null) ? s : String.Empty);
            }
            set {
                Attributes["src"] = MapStringAttributeToString(value);
            }
        }


        /// <devdoc>
        ///    <para>Gets or sets whether pressing the button causes page validation to fire. This defaults to True so that when
        ///          using validation controls, the validation state of all controls are updated when the button is clicked, both
        ///          on the client and the server. Setting this to False is useful when defining a cancel or reset button on a page
        ///          that has validators.</para>
        /// </devdoc>
        [
        WebCategory("Behavior"),
        DefaultValue(true),
        ]
        public virtual bool CausesValidation {
            get {
                object b = ViewState["CausesValidation"];
                return((b == null) ? true : (bool)b);
            }
            set {
                ViewState["CausesValidation"] = value;
            }
        }


        [
        WebCategory("Behavior"),
        DefaultValue(""),
        WebSysDescription(SR.PostBackControl_ValidationGroup)
        ]
        public virtual string ValidationGroup {
            get {
                string s = (string)ViewState["ValidationGroup"];
                return((s == null) ? String.Empty : s);
            }
            set {
                ViewState["ValidationGroup"] = value;
            }
        }


        /// <devdoc>
        ///    <para>
        ///       Occurs on the server when a user clicks an <see langword='HtmlInputImage'/>
        ///       control.
        ///    </para>
        /// </devdoc>
        [
        WebCategory("Action"),
        WebSysDescription(SR.HtmlInputImage_OnServerClick)
        ]
        public event ImageClickEventHandler ServerClick {
            add {
                Events.AddHandler(EventServerClick, value);
            }
            remove {
                Events.RemoveHandler(EventServerClick, value);
            }
        }


        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        /*
         * This method is invoked just prior to rendering.
         * Register requires handling postback to determine if image has been clicked.
         */
        protected internal override void OnPreRender(EventArgs e) {
            base.OnPreRender(e);

            if (Page != null) {
                if (!Disabled)
                    Page.RegisterRequiresPostBack(this);
                if (CausesValidation)
                    Page.RegisterPostBackScript();
            }
        }



        /// <devdoc>
        ///    <para>
        ///       Raised on the server when a user clicks an <see langword='HtmlInputImage'/>
        ///       control.
        ///    </para>
        /// </devdoc>
        /*
         * Method used to raise the OnServerClick event.
         */
        protected virtual void OnServerClick(ImageClickEventArgs e) {
            ImageClickEventHandler handler = (ImageClickEventHandler)Events[EventServerClick];
            if (handler != null) handler(this, e);
        }


        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        /*
         * Method of IPostBackEventHandler interface to raise events on post back.
         * HtmlInputImage fires an OnServerClick event.
         */
        void IPostBackEventHandler.RaisePostBackEvent(string eventArgument) {
            RaisePostBackEvent(eventArgument);
        }


        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        protected virtual void RaisePostBackEvent(string eventArgument) {
            if (CausesValidation) {
                Page.Validate(ValidationGroup);
            }
            OnServerClick(new ImageClickEventArgs(_x, _y));
        }
        

        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        /*
         * Method of IPostBackDataHandler interface to process posted data.
         * The image control will check to see if the x and y values were posted,
         * which indicates that the image was clicked by the user.  The image
         * control will then register with the Page that it wants to raise an event
         * during the event processing phase.
         */
        bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
            return LoadPostData(postDataKey, postCollection);
        }


        protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
            string postX = postCollection[RenderedNameAttribute + ".x"];
            string postY = postCollection[RenderedNameAttribute + ".y"];

            if (postX != null && postY != null &&
                postX.Length > 0 && postY.Length > 0) {

                ValidateEvent(UniqueID);

                _x = Int32.Parse(postX, CultureInfo.InvariantCulture);
                _y = Int32.Parse(postY, CultureInfo.InvariantCulture);

                Page.RegisterRequiresRaiseEvent(this);
            }

            return false;
        }


        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        /*
         * Method of IPostBackDataHandler interface which is invoked whenever posted data
         * for a control has changed.
         */
        void IPostBackDataHandler.RaisePostDataChangedEvent() {
            RaisePostDataChangedEvent();
        }


        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        protected virtual void RaisePostDataChangedEvent() {
        }

        /*
         * Override to render unique name attribute.
         * The name attribute is owned by the framework.
         */

        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        protected override void RenderAttributes(HtmlTextWriter writer) {
            PreProcessRelativeReferenceAttribute(writer, "src");

            if (Page != null) {
                Util.WriteOnClickAttribute(
                    writer, this, true, false,
                    (CausesValidation && Page.GetValidators(ValidationGroup).Count > 0),
                    ValidationGroup);
            }

            base.RenderAttributes(writer);
        }
    }
}