File: ControlAdapter.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (307 lines) | stat: -rw-r--r-- 12,779 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
//------------------------------------------------------------------------------
// <copyright file="ControlAdapter.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

using System;
using System.Globalization;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.Mobile;
using RootMobile = System.Web.Mobile;
using System.Web.UI.MobileControls;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Security.Permissions;

// We don't recompile this base class in the shipped source samples, as it
// accesses some internal functionality and is a core utility (rather than an
// extension itself).
#if !COMPILING_FOR_SHIPPED_SOURCE

namespace System.Web.UI.MobileControls.Adapters
{

    /*
     * ControlAdapter base class.
     *
     * Copyright (c) 2000 Microsoft Corporation
     */
    /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter"]/*' />
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    public abstract class ControlAdapter : IControlAdapter
    {
        private static readonly String[] LabelIDs = new String[] {
                                                RootMobile.SR.ControlAdapter_BackLabel,
                                                RootMobile.SR.ControlAdapter_GoLabel,
                                                RootMobile.SR.ControlAdapter_OKLabel,
                                                RootMobile.SR.ControlAdapter_MoreLabel,
                                                RootMobile.SR.ControlAdapter_OptionsLabel,
                                                RootMobile.SR.ControlAdapter_NextLabel,
                                                RootMobile.SR.ControlAdapter_PreviousLabel,
                                                RootMobile.SR.ControlAdapter_LinkLabel,
                                                RootMobile.SR.ControlAdapter_PhoneCallLabel
                                           };

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.BackLabel"]/*' />
        protected static readonly int BackLabel     = 0;
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.GoLabel"]/*' />
        protected static readonly int GoLabel       = 1;
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.OKLabel"]/*' />
        protected static readonly int OKLabel       = 2;
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.MoreLabel"]/*' />
        protected static readonly int MoreLabel     = 3;
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.OptionsLabel"]/*' />
        protected static readonly int OptionsLabel  = 4;
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.NextLabel"]/*' />
        protected static readonly int NextLabel     = 5;
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.PreviousLabel"]/*' />
        protected static readonly int PreviousLabel = 6;
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.LinkLabel"]/*' />
        protected static readonly int LinkLabel     = 7;
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.CallLabel"]/*' />
        protected static readonly int CallLabel     = 8;

        private MobileControl _control;

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.Control"]/*' />
        public MobileControl Control
        {
            get
            {
                return _control;
            }
            set
            {
                _control = value;
            }
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.Page"]/*' />
        public virtual MobilePage Page
        {
            get
            {
                return Control.MobilePage;
            }
            set
            {
                // Do not expect to be called directly.  Subclasses should
                // override this when needed.
                throw new Exception(
                    SR.GetString(
                        SR.ControlAdapterBasePagePropertyShouldNotBeSet));
            }
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.Device"]/*' />
        public virtual MobileCapabilities Device
        {
            get
            {
                return (MobileCapabilities)Page.Request.Browser;
            }
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.OnInit"]/*' />
        public virtual void OnInit(EventArgs e){}
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.OnLoad"]/*' />
        public virtual void OnLoad(EventArgs e){}
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.OnPreRender"]/*' />
        public virtual void OnPreRender(EventArgs e){}
        
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.Render"]/*' />
        public virtual void Render(HtmlTextWriter writer)
        {
            RenderChildren(writer);
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.OnUnload"]/*' />
        public virtual void OnUnload(EventArgs e){}

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.HandlePostBackEvent"]/*' />
        public virtual bool HandlePostBackEvent(String eventArgument)
        {
            return false;
        }

        // By default, always return false, so the control itself will handle
        // it. 
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.LoadPostData"]/*' />
        public virtual bool LoadPostData(String key,
                                         NameValueCollection data,
                                         Object controlPrivateData,
                                         out bool dataChanged)
        {
            dataChanged = false;
            return false;
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.LoadAdapterState"]/*' />
        public virtual void LoadAdapterState(Object state)
        {
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.SaveAdapterState"]/*' />
        public virtual Object SaveAdapterState()
        { 
            return null;
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.CreateTemplatedUI"]/*' />
        public virtual void CreateTemplatedUI(bool doDataBind)
        {
            // No device specific templated UI to create.

            Control.CreateDefaultTemplatedUI(doDataBind);
        }

        //  convenience methods here
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.Style"]/*' />
        public Style Style
        {
            get
            {
                return Control.Style;
            }
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.RenderChildren"]/*' />
        protected void RenderChildren(HtmlTextWriter writer)
        {
            if (Control.HasControls())
            {
                foreach (Control child in Control.Controls)
                {
                    child.RenderControl(writer);
                }
            }
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.VisibleWeight"]/*' />
        public virtual int VisibleWeight
        {
            get
            {
                return ControlPager.UseDefaultWeight;
            }
        }

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.ItemWeight"]/*' />
        public virtual int ItemWeight
        {
            get
            {
                return ControlPager.UseDefaultWeight;
            }
        }

        // The following method is used by PageAdapter subclasses of
        // ControlAdapter for determining the optimum page weight for
        // a given device.  Algorithm is as follows:
        //     1) First look for the "optimumPageWeight" parameter set
        //        for the device.  If it exists, and can be converted
        //        to an integer, use it.
        //     2) Otherwise, look for the "screenCharactersHeight" parameter.
        //        If it exists, and can be converted to an integer, multiply
        //        it by 100 and use the result.
        //     3) As a last resort, use the default provided by the calling
        //        PageAdapter.
        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.CalculateOptimumPageWeight"]/*' />
        protected virtual int CalculateOptimumPageWeight(int defaultPageWeight)
        {
            int optimumPageWeight = 0;

            // Pull OptimumPageWeight from the web.config parameter of the same
            // name, when present.
            String pageWeight = Device[Constants.OptimumPageWeightParameter]; 

            if (pageWeight != null)
            {
                try
                {
                    optimumPageWeight = Convert.ToInt32(pageWeight, CultureInfo.InvariantCulture);
                }
                catch
                {
                    optimumPageWeight = 0;
                }
            }

            if (optimumPageWeight <= 0)
            {
                // If OptimumPageWeight isn't established explicitly, attempt to
                // construct it as 100 * number of lines of characters.
                String numLinesStr = Device[Constants.ScreenCharactersHeightParameter];
                if (numLinesStr != null)
                {
                    try
                    {
                        int numLines = Convert.ToInt32(numLinesStr, CultureInfo.InvariantCulture);
                        optimumPageWeight = 100 * numLines;
                    }
                    catch
                    {
                        optimumPageWeight = 0;
                    }
                }
            }

            if (optimumPageWeight <= 0)
            {
                optimumPageWeight = defaultPageWeight;
            }

            return optimumPageWeight;
        }

        private String[] _defaultLabels = null;

        /// <include file='doc\ControlAdapter.uex' path='docs/doc[@for="ControlAdapter.GetDefaultLabel"]/*' />
        protected String GetDefaultLabel(int labelID)
        {
            if ((labelID < 0) || (labelID >= LabelIDs.Length))
            {
                throw new ArgumentException(System.Web.Mobile.SR.GetString(
                                                System.Web.Mobile.SR.ControlAdapter_InvalidDefaultLabel));
            }

            MobilePage page = Page;
            if (page != null)
            {
                ControlAdapter pageAdapter = (ControlAdapter)page.Adapter;
                if (pageAdapter._defaultLabels == null)
                {
                    pageAdapter._defaultLabels = new String[LabelIDs.Length];
                }

                String labelValue = pageAdapter._defaultLabels[labelID];
                if (labelValue == null)
                {
                    labelValue = System.Web.Mobile.SR.GetString(LabelIDs[labelID]);
                    pageAdapter._defaultLabels[labelID] = labelValue;
                }

                return labelValue;
            }
            else
            {
                return System.Web.Mobile.SR.GetString(LabelIDs[labelID]);
            }
        }
    }

    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    internal class EmptyControlAdapter : ControlAdapter {
        internal EmptyControlAdapter() {}
    }

}

#endif