1 //------------------------------------------------------------------------------
2 // <copyright file="LabelDesigner.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 namespace System.Web.UI.Design.MobileControls
8 {
9     using System;
10     using System.ComponentModel;
11     using System.ComponentModel.Design;
12     using System.Diagnostics;
13     using System.IO;
14     using System.Web.UI;
15     using System.Web.UI.Design;
16 
17     using System.Web.UI.MobileControls;
18     using System.Web.UI.MobileControls.Adapters;
19     using System.Web.UI.Design.MobileControls.Adapters;
20 
21     /// <summary>
22     ///    <para>
23     ///       Provides a designer for the <see cref='System.Web.UI.MobileControls.Label'/>
24     ///       control.
25     ///    </para>
26     /// </summary>
27     /// <seealso cref='System.Web.UI.MobileControls.Label'/>
28     [
29         System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
30         Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
31     ]
32     [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.")]
33     internal class LabelDesigner : MobileControlDesigner
34     {
35         private System.Web.UI.MobileControls.Label _label;
36 
37         /// <summary>
38         ///    <para>
39         ///       Initializes the designer with the component for design.
40         ///    </para>
41         /// </summary>
42         /// <param name='component'>
43         ///    The control element for design.
44         /// </param>
45         /// <remarks>
46         ///    <para>
47         ///       This is called by the designer host to establish the component for
48         ///       design.
49         ///    </para>
50         /// </remarks>
51         /// <seealso cref='System.ComponentModel.Design.IDesigner'/>
Initialize(IComponent component)52         public override void Initialize(IComponent component)
53         {
54             Debug.Assert(component is System.Web.UI.MobileControls.Label,
55                          "LabelDesigner.Initialize - Invalid Label Control");
56             _label = (System.Web.UI.MobileControls.Label) component;
57             base.Initialize(component);
58         }
59 
60         /// <summary>
61         ///    <para>
62         ///       Returns the design-time HTML of the <see cref='System.Web.UI.MobileControls.Label'/>
63         ///       mobile control
64         ///    </para>
65         /// </summary>
66         /// <returns>
67         ///    <para>
68         ///       The HTML of the control.
69         ///    </para>
70         /// </returns>
71         /// <seealso cref='System.Web.UI.MobileControls.Label'/>
GetDesignTimeNormalHtml()72         protected override String GetDesignTimeNormalHtml()
73         {
74             Debug.Assert(null != _label.Text);
75 
76             String originalText  = _label.Text;
77             DesignerTextWriter tw;
78             Control[] children = null;
79 
80             bool blankText = (originalText.Trim().Length == 0);
81             bool hasControls = _label.HasControls();
82 
83             if (blankText)
84             {
85                 if (hasControls)
86                 {
87                     children = new Control[_label.Controls.Count];
88                     _label.Controls.CopyTo(children, 0);
89                 }
90                 _label.Text = "[" + _label.ID + "]";
91             }
92             try
93             {
94                 tw = new DesignerTextWriter();
95                 _label.Adapter.Render(tw);
96             }
97             finally
98             {
99                 if (blankText)
100                 {
101                     _label.Text = originalText;
102                     if (hasControls)
103                     {
104                         foreach (Control c in children)
105                         {
106                             _label.Controls.Add(c);
107                         }
108                     }
109                 }
110             }
111 
112             return tw.ToString();
113         }
114     }
115 }
116