public override void Render(HtmlMobileTextWriter writer)
        {
            writer.WriteBeginTag("div");
            String width = DesignerAdapterUtil.GetWidth(Control);

            writer.WriteAttribute("style", "cellpadding=2px;width:" + width);

            Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];

            if (alignment != Alignment.NotSet)
            {
                writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
            }
            writer.Write("/>");

            ((DesignerTextWriter)writer).EnterZeroFontSizeTag();

            //Note: Although this is an internal method of runtime, but it is still
            //      pretty easy to achieve the same goal without using this method.
            Style.ApplyTo(Control.WebCalendar);
            base.Render(writer);

            ((DesignerTextWriter)writer).ExitZeroFontSizeTag();
            writer.WriteEndTag("div");
        }
 internal static String GetWidth(Control control)
 {
     if (DesignerAdapterUtil.GetContainmentStatus(control) == ContainmentStatus.AtTopLevel)
     {
         return(Constants.ControlSizeAtToplevelInNonErrorMode);
     }
     return(Constants.ControlSizeInContainer);
 }
        public override void Render(HtmlMobileTextWriter writer)
        {
            String additionalStyle;

            Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
            Wrapping  wrapping  = (Wrapping)Style[Style.WrappingKey, true];
            bool      wrap      = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
            String    width     = DesignerAdapterUtil.GetWidth(Control);

            ((DesignerTextWriter)writer).EnterZeroFontSizeTag();
            writer.EnterLayout(Style);
            writer.WriteBeginTag("div");
            if (!wrap)
            {
                byte templateStatus;
                int  maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
                if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
                {
                    width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
                }
                additionalStyle = "overflow-x:hidden;width:" + width + ";";
            }
            else
            {
                additionalStyle = "word-wrap:break-word;width:" + width + ";";
            }

            ((DesignerTextWriter)writer).WriteStyleAttribute(Style, additionalStyle);
            if (alignment != Alignment.NotSet)
            {
                writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
            }
            writer.Write(">");

            writer.WriteText(Control.HeaderText, true);

            writer.WriteFullBeginTag("ul");
            for (int i = 1; i <= 2; i++)
            {
                writer.WriteFullBeginTag("li");
                writer.Write(SR.GetString(SR.ValidationSummary_ErrorMessage, i.ToString(CultureInfo.InvariantCulture)));
                writer.WriteEndTag("li");
            }
            writer.WriteEndTag("ul");

            writer.WriteBeginTag("a");
            writer.WriteAttribute("href", "NavigationUrl");
            writer.Write(">");
            writer.WriteText(String.IsNullOrEmpty(Control.BackLabel) ? GetDefaultLabel(BackLabel) : Control.BackLabel, true);
            writer.WriteEndTag("a");

            writer.WriteEndTag("div");
            writer.ExitLayout(Style);
            ((DesignerTextWriter)writer).ExitZeroFontSizeTag();
        }
Exemple #4
0
        public override void Render(HtmlMobileTextWriter writer)
        {
            Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];

            byte   templateStatus;
            int    maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
            String width    = DesignerAdapterUtil.GetWidth(Control);

            if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
            {
                width = maxWidth.ToString() + "px";
            }

            writer.WriteBeginTag("div");
            if (alignment == Alignment.Center)
            {
                writer.WriteAttribute("align", "center");
            }
            writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
            writer.Write(">");

            String source = Control.ImageUrl;

            writer.WriteBeginTag("img");
            ((DesignerTextWriter)writer).WriteStyleAttribute(Style);
            if (source != "")
            {
                writer.WriteAttribute("src", source, true);
            }
            if (Control.AlternateText != "")
            {
                writer.Write(" alt=\"");
                writer.WriteText(Control.AlternateText, true);
                writer.Write("\"");
            }

            // center alignment not part of HTML for images.
            if (alignment == Alignment.Right ||
                alignment == Alignment.Left)
            {
                writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
            }

            writer.WriteAttribute("border", "0");
            writer.Write(">");
            writer.WriteEndTag("div");
        }
        public override void Render(HtmlMobileTextWriter writer)
        {
            Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
            Wrapping  wrapping  = (Wrapping)Style[Style.WrappingKey, true];
            bool      wrap      = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
            String    width     = DesignerAdapterUtil.GetWidth(Control);

            ((DesignerTextWriter)writer).EnterZeroFontSizeTag();
            writer.WriteBeginTag("div");

            if (!wrap)
            {
                byte templateStatus;
                int  maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);

                if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
                {
                    width = maxWidth.ToString() + "px";
                }
                writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
            }
            else
            {
                writer.WriteAttribute("style", "word-wrap:break-word;width:" + width);
            }

            if (alignment != Alignment.NotSet)
            {
                writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
            }
            writer.Write(">");

            if (Control.Text.Trim().Length > 0)
            {
                ((DesignerTextWriter)writer).WriteCssStyleText(Style, null, Control.Text, true);
            }
            else
            {
                ((DesignerTextWriter)writer).WriteCssStyleText(Style, null, Control.ErrorMessage, true);
            }

            writer.WriteEndTag("div");
            ((DesignerTextWriter)writer).ExitZeroFontSizeTag();
        }
        public override void Render(HtmlMobileTextWriter writer)
        {
            Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
            String    width     = DesignerAdapterUtil.GetWidth(Control);

            byte templateStatus;
            int  maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);

            if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
            {
                width = maxWidth.ToString() + "px";
            }

            writer.WriteBeginTag("div");
            if (alignment == Alignment.Center)
            {
                writer.WriteAttribute("align", "center");
            }
            writer.WriteAttribute("style", "padding=2px;overflow-x:hidden;width:" + width);
            writer.Write(">");

            ((DesignerTextWriter)writer).EnterZeroFontSizeTag();

            writer.WriteBeginTag("img");
            writer.WriteAttribute("alt", Control.ID);
            ((DesignerTextWriter)writer).WriteStyleAttribute(Style);

            // center alignment not part of HTML for images.
            if (alignment == Alignment.Right ||
                alignment == Alignment.Left)
            {
                writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
            }

            writer.WriteAttribute("height", "40");
            writer.WriteAttribute("width", "250");
            writer.WriteAttribute("border", "0");
            writer.Write(">");

            ((DesignerTextWriter)writer).ExitZeroFontSizeTag();
            writer.WriteEndTag("div");
        }
        public override void Render(HtmlMobileTextWriter writer)
        {
            Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
            Wrapping  wrapping  = (Wrapping)Style[Style.WrappingKey, true];
            bool      wrap      = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);
            String    width     = DesignerAdapterUtil.GetWidth(Control);

            ((DesignerTextWriter)writer).EnterZeroFontSizeTag();
            writer.WriteBeginTag("div");
            if (!wrap)
            {
                byte templateStatus;
                int  maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
                if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
                {
                    width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
                }
                writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
            }
            else
            {
                writer.WriteAttribute("style", "word-wrap:break-word;width:" + width);
            }

            if (alignment != Alignment.NotSet)
            {
                writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
            }
            writer.Write(">");

            MSHTMLHostUtil.ApplyStyle(null, null, null);
            String filteredText     = FilterTags(Control.Text.Trim());
            int    uniqueLineHeight = MSHTMLHostUtil.GetHtmlFragmentHeight("a");
            int    requiredHeight   = MSHTMLHostUtil.GetHtmlFragmentHeight(filteredText);
            int    requiredWidth    = MSHTMLHostUtil.GetHtmlFragmentWidth(filteredText);

            ((DesignerTextWriter)writer).WriteCssStyleText(Style, null, (requiredHeight > uniqueLineHeight || requiredWidth > 1) ? filteredText : "&nbsp;", false);
            writer.WriteEndTag("div");
            ((DesignerTextWriter)writer).ExitZeroFontSizeTag();
        }
Exemple #8
0
        internal void WriteDesignerStyleAttributes(MobileControl control,
                                                   Style style)
        {
            Alignment alignment = (Alignment)style[Style.AlignmentKey, true];
            Wrapping  wrapping  = (Wrapping)style[Style.WrappingKey, true];
            Color     backColor = (Color)style[Style.BackColorKey, true];

            bool align = (alignment != Alignment.NotSet);
            bool wrap  = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);

            String width = DesignerAdapterUtil.GetWidth(control);

            byte templateStatus;
            int  maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(control, out templateStatus);

            if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
            {
                width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
            }

            if (!wrap)
            {
                Write(" style=\"overflow-x:hidden;width:" + width);
            }
            else
            {
                Write(" style=\"word-wrap:break-word;overflow-x:hidden;width:" + width);
            }

            if (backColor != Color.Empty)
            {
                Write(";background-color:" + ColorTranslator.ToHtml(backColor));
            }

            if (align)
            {
                Write(";text-align:" + Enum.GetName(typeof(Alignment), alignment));
            }
        }
Exemple #9
0
        public override void Render(HtmlMobileTextWriter writer)
        {
            // Invalid text writers are not supported in this Adapter.
            if (!(writer is DesignerTextWriter))
            {
                return;
            }

            Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
            byte      templateStatus;
            int       maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);
            String    width    = DesignerAdapterUtil.GetWidth(Control);

            if (Control.ImageUrl.Length == 0)
            {
                if (Control.Format == CommandFormat.Button)
                {
                    if (maxWidth == 0 && templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_NONEDIT)
                    {
                        maxWidth = DesignerAdapterUtil.CONTROL_MAX_WIDTH_IN_TEMPLATE;
                    }

                    if (maxWidth == 0 && DesignerAdapterUtil.InMobileUserControl(Control))
                    {
                        maxWidth = Constants.ControlMaxsizeAtToplevel;
                    }

                    if (maxWidth == 0)
                    {
                        // Render will be called a second time for which maxWidth != 0
                        return;
                    }

                    String additionalStyle = null;
                    String controlText     = Control.Text;
                    String commandCaption;
                    int    requiredWidth = 0;

                    DesignerTextWriter twTmp;
                    twTmp = new DesignerTextWriter();
                    twTmp.WriteBeginTag("input");
                    twTmp.WriteStyleAttribute(Style, null);
                    twTmp.WriteAttribute("type", "submit");
                    twTmp.Write(" value=\"");
                    twTmp.WriteText(controlText, true);
                    twTmp.Write("\"/>");
                    String htmlFragment = twTmp.ToString();

                    MSHTMLHostUtil.ApplyStyle(String.Empty, String.Empty, null);
                    requiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(htmlFragment);

                    ((DesignerTextWriter)writer).EnterZeroFontSizeTag();
                    writer.WriteBeginTag("div");
                    if (requiredWidth + SAFETY_MARGIN > maxWidth)
                    {
                        if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
                        {
                            int tmpRequiredWidth, allowedLength;
                            int captionLength = controlText.Length;
                            twTmp = new DesignerTextWriter();
                            twTmp.WriteBeginTag("input");
                            twTmp.WriteStyleAttribute(Style, null);
                            twTmp.WriteAttribute("type", "submit");
                            twTmp.WriteAttribute("value", "{0}");
                            twTmp.Write("/>");
                            htmlFragment = twTmp.ToString();
                            // At least 10 characters can fit into the caption of the command
                            for (allowedLength = (captionLength < 10 ? captionLength : 10); allowedLength <= captionLength; allowedLength++)
                            {
                                tmpRequiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(String.Format(CultureInfo.CurrentCulture, htmlFragment, HttpUtility.HtmlEncode(controlText.Substring(0, allowedLength))));
                                if (tmpRequiredWidth + SAFETY_MARGIN > maxWidth)
                                {
                                    break;
                                }
                            }
                            commandCaption = controlText.Substring(0, allowedLength - 1);
                        }
                        else
                        {
                            commandCaption = controlText;
                        }
                    }
                    else
                    {
                        writer.WriteAttribute("style", "width:" + width);
                        commandCaption = controlText;
                    }

                    if (alignment != Alignment.NotSet)
                    {
                        writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
                    }
                    writer.Write(">");

                    writer.EnterLayout(Style);

                    writer.WriteBeginTag("input");
                    if (requiredWidth + SAFETY_MARGIN > maxWidth)
                    {
                        additionalStyle = String.Format(CultureInfo.CurrentCulture, "width:{0};", width);
                    }
                    ((DesignerTextWriter)writer).WriteStyleAttribute(Style, additionalStyle);
                    writer.WriteAttribute("type", "submit");

                    writer.Write(" value=\"");
                    writer.WriteText(commandCaption, true);
                    writer.Write("\"/>");

                    writer.ExitLayout(Style);
                }
                else
                {
                    Wrapping wrapping = (Wrapping)Style[Style.WrappingKey, true];
                    bool     wrap     = (wrapping == Wrapping.Wrap || wrapping == Wrapping.NotSet);

                    ((DesignerTextWriter)writer).EnterZeroFontSizeTag();
                    writer.WriteBeginTag("div");

                    if (!wrap)
                    {
                        if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
                        {
                            width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
                        }
                        writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
                    }
                    else
                    {
                        writer.WriteAttribute("style", "word-wrap:break-word;width:" + width);
                    }

                    if (alignment != Alignment.NotSet)
                    {
                        writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
                    }
                    writer.Write(">");

                    writer.WriteBeginTag("a");
                    writer.WriteAttribute("href", "NavigationUrl");
                    writer.Write(">");
                    ((DesignerTextWriter)writer).WriteCssStyleText(Style, null, Control.Text, true);
                    writer.WriteEndTag("a");
                }
                writer.WriteEndTag("div");
                ((DesignerTextWriter)writer).ExitZeroFontSizeTag();
            }
            else
            {
                if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_EDIT)
                {
                    width = maxWidth.ToString(CultureInfo.InvariantCulture) + "px";
                }

                writer.WriteBeginTag("div");
                if (alignment == Alignment.Center)
                {
                    writer.WriteAttribute("align", "center");
                }
                writer.WriteAttribute("style", "overflow-x:hidden;width:" + width);
                writer.Write(">");

                writer.WriteBeginTag("img");
                ((DesignerTextWriter)writer).WriteStyleAttribute(Style);
                writer.WriteAttribute("src", Control.ImageUrl, true);

                // center alignment not part of HTML for images.
                if (alignment == Alignment.Right ||
                    alignment == Alignment.Left)
                {
                    writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
                }

                writer.WriteAttribute("border", "0");
                writer.Write(">");
                writer.WriteEndTag("div");
            }
        }
        internal static int GetMaxWidthToFit(MobileControl control, out byte templateStatus)
        {
            IDesigner parentDesigner  = ControlDesigner(control.Parent);
            IDesigner controlDesigner = ControlDesigner(control);
            int       defaultControlWidthInTemplate;

            NativeMethods.IHTMLElement2 htmlElement2Parent = null;

            if (controlDesigner == null)
            {
                templateStatus = CONTROL_IN_TEMPLATE_NONEDIT;
                return(0);
            }
            Debug.Assert(controlDesigner is MobileControlDesigner ||
                         controlDesigner is MobileTemplatedControlDesigner,
                         "controlDesigner is not MobileControlDesigner or MobileTemplatedControlDesigner");

            templateStatus = 0x00;
            if (parentDesigner is MobileTemplatedControlDesigner)
            {
                htmlElement2Parent =
                    (NativeMethods.IHTMLElement2)
                        ((MobileTemplatedControlDesigner)parentDesigner).DesignTimeElementInternal;
            }
            else if (parentDesigner is MobileContainerDesigner)
            {
                htmlElement2Parent =
                    (NativeMethods.IHTMLElement2)
                        ((MobileContainerDesigner)parentDesigner).DesignTimeElementInternal;
            }

            bool inTemplate;
            int  nestingLevel = DesignerAdapterUtil.NestingLevel(control, out inTemplate, out defaultControlWidthInTemplate);

            if (inTemplate)
            {
                templateStatus = CONTROL_IN_TEMPLATE_EDIT;
            }

            if (htmlElement2Parent != null)
            {
                int maxWidth;
                if (!inTemplate)
                {
                    Debug.Assert(control.Parent is MobileControl);
                    Style     parentStyle       = ((MobileControl)control.Parent).Style;
                    Alignment alignment         = (Alignment)parentStyle[Style.AlignmentKey, true];
                    int       parentChildOffset = 0;

                    // AUI 2786
                    if (alignment != Alignment.NotSet && alignment != Alignment.Left)
                    {
                        parentChildOffset = _regularParentChildOffset;
                    }
                    else
                    {
                        NativeMethods.IHTMLRectCollection rectColl = null;
                        NativeMethods.IHTMLRect           rect     = null;
                        int    index = 0;
                        Object obj   = index;

                        NativeMethods.IHTMLElement2 htmlElement2;

                        if (controlDesigner is MobileControlDesigner)
                        {
                            htmlElement2 = (NativeMethods.IHTMLElement2)((MobileControlDesigner)controlDesigner).DesignTimeElementInternal;
                        }
                        else
                        {
                            htmlElement2 = (NativeMethods.IHTMLElement2)((MobileTemplatedControlDesigner)controlDesigner).DesignTimeElementInternal;
                        }

                        if (null == htmlElement2)
                        {
                            return(0);
                        }

                        try
                        {
                            rectColl = htmlElement2.GetClientRects();
                        }
                        catch (Exception)
                        {
                            // this happens when switching from Design view to HTML view
                            return(0);
                        }

                        if (rectColl.GetLength() >= 1)
                        {
                            rect = (NativeMethods.IHTMLRect)rectColl.Item(ref obj);
                            parentChildOffset = rect.GetLeft();

                            rectColl = htmlElement2Parent.GetClientRects();
                            //Debug.Assert(rectColl.GetLength() == 1);
                            rect = (NativeMethods.IHTMLRect)rectColl.Item(ref obj);
                            parentChildOffset -= rect.GetLeft();
                        }
                    }

                    maxWidth = GetLength(htmlElement2Parent) - _marginWidth - parentChildOffset;
                    if (maxWidth > 0 && maxWidth > _defaultContainerWidth - nestingLevel * _marginPerLevel)
                    {
                        maxWidth = _defaultContainerWidth - nestingLevel * _marginPerLevel;
                    }
                }
                else
                {
                    int parentWidth = GetLength(htmlElement2Parent);
                    if (parentWidth == 0)
                    {
                        // AUI 4525
                        maxWidth = defaultControlWidthInTemplate;
                    }
                    else
                    {
                        maxWidth = parentWidth - _templateParentChildOffset;
                    }

                    if (maxWidth > 0 && maxWidth > defaultControlWidthInTemplate - nestingLevel * _marginPerLevel)
                    {
                        maxWidth = defaultControlWidthInTemplate - nestingLevel * _marginPerLevel;
                    }
                }
                return(maxWidth);
            }
            return(0);
        }
        public override void Render(HtmlMobileTextWriter writer)
        {
            // Invalid text writers are not supported in this Adapter.
            if (!(writer is DesignerTextWriter))
            {
                return;
            }

            byte templateStatus;
            bool pwd  = Control.Password;
            int  size = Control.Size;
            int  fittingSize;

            int maxWidth = DesignerAdapterUtil.GetMaxWidthToFit(Control, out templateStatus);

            if (maxWidth == 0)
            {
                if (templateStatus == DesignerAdapterUtil.CONTROL_IN_TEMPLATE_NONEDIT)
                {
                    maxWidth = DesignerAdapterUtil.CONTROL_MAX_WIDTH_IN_TEMPLATE;
                }
                else if (DesignerAdapterUtil.InMobileUserControl(Control))
                {
                    maxWidth = Constants.ControlMaxsizeAtToplevel;
                }
            }

            if (maxWidth == 0)
            {
                return;
            }

            bool restoreEmptyFontName = false;

            if ((String)Style[Style.FontNameKey, true] == String.Empty)
            {
                // MSHTMLHostUtil is using another font by default.
                // Setting the font name to the one that is actually
                // used by default for the desig-time rendering
                // assures that the requiredWidth returned by
                // MSHTMLHostUtil.GetHtmlFragmentWidth is accurate.
                Style[Style.FontNameKey] = "Arial";
                restoreEmptyFontName     = true;
            }

            int requiredWidth = 0;
            DesignerTextWriter tw;

            tw = new DesignerTextWriter(false);
            tw.EnterLayout(Style);
            String enterLayout = tw.ToString();

            tw = new DesignerTextWriter(false);
            tw.ExitLayout(Style);
            String exitLayout = tw.ToString();

            tw = new DesignerTextWriter(false);
            tw.WriteBeginTag("input");
            tw.WriteStyleAttribute(Style, null);
            if (size > 0)
            {
                tw.WriteAttribute("size", "{0}");
            }
            tw.Write("/>");
            String htmlFragment = tw.ToString();

            MSHTMLHostUtil.ApplyStyle(enterLayout, exitLayout, null);

            if (size < LARGESIZE_THRESHOLD)
            {
                requiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(size > 0 ? String.Format(htmlFragment, size.ToString()) : htmlFragment);
            }

            if (requiredWidth + SAFETY_MARGIN > maxWidth || size >= LARGESIZE_THRESHOLD)
            {
                if (size == 0)
                {
                    tw = new DesignerTextWriter(false);
                    tw.WriteBeginTag("input");
                    tw.WriteStyleAttribute(Style, null);
                    tw.WriteAttribute("size", "{0}");
                    tw.Write("/>");
                    htmlFragment = tw.ToString();
                }
                fittingSize = 0;
                do
                {
                    fittingSize++;
                    requiredWidth = MSHTMLHostUtil.GetHtmlFragmentWidth(String.Format(htmlFragment, fittingSize.ToString()));
                }while (requiredWidth + SAFETY_MARGIN <= maxWidth);

                if (fittingSize > 1)
                {
                    fittingSize--;
                }
            }
            else
            {
                fittingSize = size;
            }

            if (restoreEmptyFontName)
            {
                Style[Style.FontNameKey] = String.Empty;
            }

            Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
            String    width     = DesignerAdapterUtil.GetWidth(Control);

            writer.Write("<div style='width:" + width);
            if (alignment != Alignment.NotSet)
            {
                writer.Write(";text-align:" + Enum.GetName(typeof(Alignment), alignment));
            }
            writer.Write("'>");

            ((DesignerTextWriter)writer).EnterZeroFontSizeTag();
            writer.EnterLayout(Style);

            writer.WriteBeginTag("input");
            ((DesignerTextWriter)writer).WriteStyleAttribute(Style, null);
            if (Control.Text != String.Empty)
            {
                writer.Write(" value=\"");
                writer.WriteText(Control.Text, true);
                writer.Write("\" ");
            }
            if (fittingSize > 0)
            {
                writer.WriteAttribute("size", fittingSize.ToString());
            }
            if (pwd)
            {
                writer.WriteAttribute("type", "password");
            }
            writer.Write("/>");

            writer.ExitLayout(Style);
            ((DesignerTextWriter)writer).ExitZeroFontSizeTag();
            writer.Write("</div>");
        }