File: MobileControlDesigner.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 (611 lines) | stat: -rw-r--r-- 21,357 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
//------------------------------------------------------------------------------
// <copyright file="MobileControlDesigner.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.UI.Design.MobileControls
{
    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Design;
    using System.Collections;
    using System.Globalization;
    using System.IO;
    using System.Reflection;
    using System.Web.UI;
    using System.Web.UI.Design;
    using System.Web.UI.Design.MobileControls.Adapters;
    using System.Web.UI.Design.MobileControls.Util;
    using System.Web.UI.MobileControls;

    [
        System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
        Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
    ]
    [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 MobileControlDesigner :
        ControlDesigner, IMobileDesigner, IDeviceSpecificDesigner
    {
        private bool                            _containmentStatusDirty = true;
        private ContainmentStatus               _containmentStatus;
        private IDesignerHost                   _host;
        private IWebFormsDocumentService        _iWebFormsDocumentService;
        private IMobileWebFormServices          _iMobileWebFormServices;
        private MobileControl                   _mobileControl;
        private System.Windows.Forms.Control    _header;

        internal static readonly String resourceDllUrl =
            "res://" + typeof(MobileControlDesigner).Module.FullyQualifiedName;

        internal static readonly String errorIcon =
            resourceDllUrl + "//ERROR_GIF";

        internal static readonly String infoIcon =
            resourceDllUrl + "//INFO_GIF";

        internal static readonly String defaultErrorDesignTimeHTML =
            @"
                <table cellpadding=2 cellspacing=0 width='{4}' style='font-family:tahoma;font-size:8pt;color:buttontext;background-color:buttonface;border: solid 1px;border-top-color:buttonhighlight;border-left-color:buttonhighlight;border-bottom-color:buttonshadow;border-right-color:buttonshadow'>
                    <tr><td><span style='font-weight:bold'>&nbsp;{0}</span> - {1}</td></tr>
                    <tr><td>
                        <table style='font-family:tahoma;font-size:8pt;color:window;background-color:ButtonShadow'>
                            <tr>
                                <td valign='top'><img src={3} /></td>
                                <td width='100%'>{2}</td>
                            </tr>
                        </table>
                    </td></tr>
                </table>
             ";

        internal static readonly String _formPanelContainmentErrorMessage =
            SR.GetString(SR.MobileControl_FormPanelContainmentErrorMessage);

        internal static readonly String _mobilePageErrorMessage =
            SR.GetString(SR.MobileControl_MobilePageErrorMessage);

        internal static readonly String _topPageContainmentErrorMessage =
            SR.GetString(SR.MobileControl_TopPageContainmentErrorMessage);

        internal static readonly String _userControlWarningMessage =
            SR.GetString(SR.MobileControl_UserControlWarningMessage);

        private const String _appliedDeviceFiltersPropName = "AppliedDeviceFilters";
        private const String _propertyOverridesPropName = "PropertyOverrides";
        private const String _defaultDeviceSpecificIdentifier = "unique";

        private static readonly string[] _nonBrowsableProperties = new string[] {
            "EnableTheming",
            "Expressions",
            "SkinID",
        };

        // predefined constants used for mergingContext
        internal const int MergingContextChoices = 0;
        internal const int MergingContextTemplates = 1;
        internal const int MergingContextProperties = 2;

        [
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
            Editor(typeof(AppliedDeviceFiltersTypeEditor), typeof(UITypeEditor)),
            MergableProperty(false),
            MobileCategory(SR.Category_DeviceSpecific),
            MobileSysDescription(SR.MobileControl_AppliedDeviceFiltersDescription),
            ParenthesizePropertyName(true),
        ]
        protected String AppliedDeviceFilters
        {
            get
            {
                return String.Empty;
            }
        }

        protected ContainmentStatus ContainmentStatus
        {
            get
            {
                if (!_containmentStatusDirty)
                {
                    return _containmentStatus;
                }

                _containmentStatus =
                    DesignerAdapterUtil.GetContainmentStatus(_mobileControl);

                _containmentStatusDirty = false;
                return _containmentStatus;
            }
        }

        internal Object DesignTimeElementInternal
        {
            get
            {
                return typeof(HtmlControlDesigner).InvokeMember("DesignTimeElement", 
                    BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic, 
                    null, this, null, CultureInfo.InvariantCulture);
            }
        }

        public override bool DesignTimeHtmlRequiresLoadComplete
        {
            get
            {
                return true;
            }
        }

        private IDesignerHost Host
        {
            get
            {
                if (_host != null)
                {
                    return _host;
                }
                _host = (IDesignerHost)GetService(typeof(IDesignerHost));
                Debug.Assert(_host != null);
                return _host;
            }
        }

        internal IMobileWebFormServices IMobileWebFormServices
        {
            get
            {
                if (_iMobileWebFormServices == null)
                {
                    _iMobileWebFormServices =
                        (IMobileWebFormServices)GetService(typeof(IMobileWebFormServices));
                }

                return _iMobileWebFormServices;
            }
        }

        private IWebFormsDocumentService IWebFormsDocumentService
        {
            get
            {
                if (_iWebFormsDocumentService == null)
                {
                    _iWebFormsDocumentService =
                        (IWebFormsDocumentService)GetService(typeof(IWebFormsDocumentService));

                    Debug.Assert(_iWebFormsDocumentService != null);
                }

                return _iWebFormsDocumentService;
            }
        }

        /// <summary>
        ///     Indicates whether the initial page load is completed
        /// </summary>
        protected bool LoadComplete
        {
            get
            {
                return !IWebFormsDocumentService.IsLoading;
            }
        }

        [
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
            Editor(typeof(PropertyOverridesTypeEditor), typeof(UITypeEditor)),
            MergableProperty(false),
            MobileCategory(SR.Category_DeviceSpecific),
            MobileSysDescription(SR.MobileControl_DeviceSpecificPropsDescription),
            ParenthesizePropertyName(true),
        ]
        protected String PropertyOverrides
        {
            get
            {
                return String.Empty;
            }
        }

        private bool ValidContainment
        {
            get
            {
                return (
                    ContainmentStatus == ContainmentStatus.InForm ||
                    ContainmentStatus == ContainmentStatus.InPanel ||
                    ContainmentStatus == ContainmentStatus.InTemplateFrame);
            }
        }

        protected virtual String GetErrorMessage(out bool infoMode)
        {
            infoMode = false;

            // Skip containment checking if the control is placed in MobileUserControl
            if (!DesignerAdapterUtil.InMobileUserControl(_mobileControl))
            {
                if (DesignerAdapterUtil.InUserControl(_mobileControl))
                {
                    infoMode = true;
                    return MobileControlDesigner._userControlWarningMessage;
                }

                if (!DesignerAdapterUtil.InMobilePage(_mobileControl))
                {
                    return _mobilePageErrorMessage;
                }

                if (!ValidContainment)
                {
                    return _formPanelContainmentErrorMessage;
                }
            }

            bool containsTag;
            bool containsDataboundLiteral;
            _mobileControl.GetControlText(out containsTag, out containsDataboundLiteral);

            if (containsTag)
            {
                return SR.GetString(SR.MobileControl_InnerTextCannotContainTagsDesigner);
            }

            // Containment is valid, return null;
            return null;
        }

        /// <summary>
        ///    <para>
        ///       Gets the HTML to be used for the design time representation of the control runtime.
        ///    </para>
        /// </summary>
        /// <returns>
        ///    <para>
        ///       The design time HTML.
        ///    </para>
        /// </returns>
        public sealed override String GetDesignTimeHtml()
        {
            if (!LoadComplete)
            {
                return null;
            }

            bool infoMode = false;
            String errorMessage = GetErrorMessage(out infoMode);
            SetStyleAttributes();

            if (null != errorMessage)
            {
                return GetDesignTimeErrorHtml(errorMessage, infoMode);
            }

            String designTimeHTML = null;
            try
            {
                designTimeHTML = GetDesignTimeNormalHtml();
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                designTimeHTML = GetDesignTimeErrorHtml(ex.Message, false);
            }

            return designTimeHTML;
        }

        protected virtual String GetDesignTimeNormalHtml()
        {
            return GetEmptyDesignTimeHtml();
        }

        /// <summary>
        ///    <para>
        ///       Gets the HTML to be used at design time as the representation of the
        ///       control when the control runtime does not return any rendered
        ///       HTML. The default behavior is to return a string containing the name
        ///       of the component.
        ///    </para>
        /// </summary>
        /// <returns>
        ///    <para>
        ///       The name of the component, by default.
        ///    </para>
        /// </returns>
        protected override String GetEmptyDesignTimeHtml()
        {
            return "<div style='width:100%'>" + base.GetEmptyDesignTimeHtml() + "</div>";
        }

        protected override sealed String GetErrorDesignTimeHtml(Exception e)
        {
            return base.GetErrorDesignTimeHtml(e);
        }

        /// <summary>
        ///
        /// </summary>
        protected virtual String GetDesignTimeErrorHtml(String errorMessage, bool infoMode)
        {
            return DesignerAdapterUtil.GetDesignTimeErrorHtml(
                errorMessage, infoMode, _mobileControl, Behavior, ContainmentStatus);
        }

        /// <summary>
        ///    <para>
        ///       Gets the HTML to be persisted for the content present within the associated server control runtime.
        ///    </para>
        /// </summary>
        /// <returns>
        ///    <para>
        ///       Persistable Inner HTML.
        ///    </para>
        /// </returns>
        public override String GetPersistInnerHtml()
        {
            if (!IsDirty)
            {
                // Returning a null string will prevent the actual save.
                return null;
            }

            StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);

            // HACK ALERT:
            // We need to temporarily swap out the Text property to avoid being
            // persisted into control inner text. However, setting the Text property
            // will wipe out all control collections, therefore we need to cache
            // the Text value too.
            bool hasControls = _mobileControl.HasControls();
            if ((_mobileControl is TextControl || _mobileControl is TextView)
                && hasControls)
            {
                String originalText = null;
                Control[] children = null;

                // Cache all child controls here.
                children = new Control[_mobileControl.Controls.Count];
                _mobileControl.Controls.CopyTo(children, 0);

                // Replace the text with empty string.
                if (_mobileControl is TextControl)
                {
                    originalText = ((TextControl)_mobileControl).Text;
                    ((TextControl)_mobileControl).Text = String.Empty;
                }
                else
                {
                    originalText = ((TextView)_mobileControl).Text;
                    ((TextView)_mobileControl).Text = String.Empty;
                }

                try
                {
                    // Persist inner properties without Text property.
                    MobileControlPersister.PersistInnerProperties(sw, _mobileControl, Host);
                    // Persist the child collections.
                    foreach (Control c in children)
                    {
                        MobileControlPersister.PersistControl(sw, c, Host);
                    }
                }
                finally
                {
                    // Write the original text back to control.
                    if (_mobileControl is TextControl)
                    {
                        ((TextControl)_mobileControl).Text = originalText;
                    }
                    else
                    {
                        ((TextView)_mobileControl).Text = originalText;
                    }

                    // Add the child controls back.
                    foreach (Control c in children)
                    {
                        _mobileControl.Controls.Add(c);
                    }
                }
            }
            else
            {
                MobileControlPersister.PersistInnerProperties(sw, _mobileControl, Host);
            }

            IsDirty = false;
            return sw.ToString();
        }

        /// <summary>
        ///    <para>
        ///       Initializes the designer with the component for design.
        ///    </para>
        /// </summary>
        /// <param name='component'>
        ///    The control element for design.
        /// </param>
        /// <remarks>
        ///    <para>
        ///       This is called by the designer host to establish the component for
        ///       design.
        ///    </para>
        /// </remarks>
        /// <seealso cref='System.ComponentModel.Design.IDesigner'/>
        public override void Initialize(IComponent component)
        {
            Debug.Assert(component is System.Web.UI.MobileControls.MobileControl,
                "MobileControlDesigner.Initialize - Invalid MobileControl Control");

            base.Initialize(component);

            _mobileControl = (System.Web.UI.MobileControls.MobileControl) component;
        }

        protected virtual void SetStyleAttributes()
        {
            //Debug.Assert(Behavior != null, "Behavior is null, Load completed? " + LoadComplete.ToString());

            DesignerAdapterUtil.SetStandardStyleAttributes(Behavior, ContainmentStatus);
        }

        public override void OnComponentChanged(Object sender, ComponentChangedEventArgs ce)
        {
            // Delegate to the base class implementation first!
            base.OnComponentChanged(sender, ce);

            MemberDescriptor member = ce.Member;
            if (member != null &&
                member.GetType().FullName.Equals(Constants.ReflectPropertyDescriptorTypeFullName))
            {
                PropertyDescriptor propDesc = (PropertyDescriptor)member;
                String propName = propDesc.Name;

                if ((_mobileControl is TextControl || _mobileControl is TextView)
                    && propName.Equals("Text"))
                {
                    _mobileControl.Controls.Clear();
                }
            }
        }

        /// <summary>
        ///    <para>
        ///       Notification that is called when the associated control is parented.
        ///    </para>
        /// </summary>
        public override void OnSetParent()
        {
            base.OnSetParent();

            _containmentStatusDirty = true;
            if (LoadComplete)
            {
                UpdateRendering();
            }
        }

        protected override void PreFilterProperties(IDictionary properties)
        {
            base.PreFilterProperties(properties);

            properties[_appliedDeviceFiltersPropName] =
                TypeDescriptor.CreateProperty(this.GetType(), _appliedDeviceFiltersPropName, typeof(String));

            properties[_propertyOverridesPropName] =
                TypeDescriptor.CreateProperty(this.GetType(), _propertyOverridesPropName, typeof(String));

            foreach (string propertyName in _nonBrowsableProperties) {
                PropertyDescriptor property = (PropertyDescriptor) properties[propertyName];
                Debug.Assert(property != null, "Property is null: " + propertyName);
                if (property != null) {
                    properties[propertyName] = TypeDescriptor.CreateProperty(this.GetType(), property, BrowsableAttribute.No);
                }
            }
        }

        /*
         *  IMobileDesigner INTERFACE IMPLEMENTATION
         */

        /// <summary>
        ///
        /// </summary>
        public void UpdateRendering()
        {
            _mobileControl.RefreshStyle();

            UpdateDesignTimeHtml();
        }

        ////////////////////////////////////////////////////////////////////////
        //  Begin IDeviceSpecificDesigner Implementation
        ////////////////////////////////////////////////////////////////////////

        void IDeviceSpecificDesigner.SetDeviceSpecificEditor
            (IRefreshableDeviceSpecificEditor editor)
        {
        }

        String IDeviceSpecificDesigner.CurrentDeviceSpecificID
        {
            get
            {
                return _defaultDeviceSpecificIdentifier;
            }
        }

        System.Windows.Forms.Control IDeviceSpecificDesigner.Header
        {
            get
            {
                return _header;
            }
        }

        System.Web.UI.Control IDeviceSpecificDesigner.UnderlyingControl
        {
            get
            {
                return _mobileControl;
            }
        }

        Object IDeviceSpecificDesigner.UnderlyingObject
        {
            get
            {
                return _mobileControl;
            }
        }

        void IDeviceSpecificDesigner.InitHeader(int mergingContext)
        {
            HeaderPanel panel = new HeaderPanel();
            HeaderLabel lblDescription = new HeaderLabel();

            lblDescription.TabIndex = 0;
            lblDescription.Text = SR.GetString(
                SR.MobileControl_SettingGenericChoiceDescription
            );
            panel.Height = lblDescription.Height;
            panel.Width = lblDescription.Width;
            panel.Controls.Add(lblDescription);
            _header = panel;
        }

        void IDeviceSpecificDesigner.RefreshHeader(int mergingContext)
        {
        }

        bool IDeviceSpecificDesigner.GetDeviceSpecific(String deviceSpecificParentID, out DeviceSpecific ds)
        {
            Debug.Assert(_defaultDeviceSpecificIdentifier == deviceSpecificParentID);
            ds = ((MobileControl) _mobileControl).DeviceSpecific;
            return true;
        }

        void IDeviceSpecificDesigner.SetDeviceSpecific(String deviceSpecificParentID, DeviceSpecific ds)
        {
            Debug.Assert(_defaultDeviceSpecificIdentifier == deviceSpecificParentID);
            if (null != ds)
            {
                ds.SetOwner((MobileControl) _mobileControl);
            }
            _mobileControl.DeviceSpecific = ds;
        }

        void IDeviceSpecificDesigner.UseCurrentDeviceSpecificID()
        {
        }

        ////////////////////////////////////////////////////////////////////////
        //  End IDeviceSpecificDesigner Implementation
        ////////////////////////////////////////////////////////////////////////
    }
}