Exemplo n.º 1
0
 public unsafe override void Render(HtmlMobileTextWriter writer)
 {
     bool flag = base.get_Control().get_Password();
     int num = base.get_Control().get_Size();
     Alignment alignment = *((Alignment*) base.get_Style().get_Item(Style.AlignmentKey, true));
     writer.Write("<div style='width:" + "100%");
     if (alignment != null)
     {
         writer.Write(";text-align:" + Enum.GetName(typeof(Alignment), alignment));
     }
     writer.Write("'>");
     Utils.EnterZeroFontSizeTag(writer);
     writer.EnterLayout(base.get_Style());
     writer.WriteBeginTag("input");
     Utils.WriteStyleAttribute(writer, base.get_Style(), null);
     if (base.get_Control().get_Text() != string.Empty)
     {
         writer.Write(" value=\"");
         writer.WriteText(base.get_Control().get_Text(), true);
         writer.Write("\" ");
     }
     writer.WriteAttribute("size", num.ToString());
     if (flag)
     {
         writer.WriteAttribute("type", "password");
     }
     writer.Write("/>");
     writer.ExitLayout(base.get_Style());
     Utils.ExitZeroFontSizeTag(writer);
     writer.Write("</div>");
 }
        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();
        }
 public unsafe override void Render(HtmlMobileTextWriter writer)
 {
     string str;
     Alignment alignment = *((Alignment*) base.get_Style().get_Item(Style.AlignmentKey, true));
     Wrapping wrapping = *((Wrapping*) base.get_Style().get_Item(Style.WrappingKey, true));
     bool flag = (wrapping == 1) || (wrapping == 0);
     string str2 = "100%";
     Utils.EnterZeroFontSizeTag(writer);
     writer.EnterLayout(base.get_Style());
     writer.WriteBeginTag("div");
     if (!flag)
     {
         str = "overflow-x:hidden;width:" + str2 + ";";
     }
     else
     {
         str = "word-wrap:break-word;width:" + str2 + ";";
     }
     Utils.WriteStyleAttribute(writer, base.get_Style(), str);
     if (alignment != null)
     {
         writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
     }
     writer.Write(">");
     writer.WriteText(base.get_Control().get_HeaderText(), true);
     writer.WriteFullBeginTag("ul");
     for (int i = 1; i <= 2; i++)
     {
         writer.WriteFullBeginTag("li");
         writer.Write(Constants.ValidationSummaryErrorMessage, i.ToString());
         writer.WriteEndTag("li");
     }
     writer.WriteEndTag("ul");
     writer.WriteBeginTag("a");
     writer.WriteAttribute("href", "NavigationUrl");
     writer.Write(">");
     writer.WriteText((base.get_Control().get_BackLabel() == string.Empty) ? base.GetDefaultLabel(ControlAdapter.BackLabel) : base.get_Control().get_BackLabel(), true);
     writer.WriteEndTag("a");
     writer.WriteEndTag("div");
     writer.ExitLayout(base.get_Style());
     Utils.ExitZeroFontSizeTag(writer);
 }
        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");
            }
        }
Exemplo n.º 5
0
 public unsafe override void Render(HtmlMobileTextWriter writer)
 {
     Alignment alignment = *((Alignment*) base.get_Style().get_Item(Style.AlignmentKey, true));
     if (base.get_Control().get_ImageUrl().Length == 0)
     {
         Utils.EnterZeroFontSizeTag(writer);
         writer.WriteBeginTag("div");
         if (base.get_Control().get_Format() == null)
         {
             writer.WriteAttribute("style", "width:100%");
             if (alignment != null)
             {
                 writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
             }
             writer.Write(">");
             writer.EnterLayout(base.get_Style());
             writer.WriteBeginTag("input");
             Utils.WriteStyleAttribute(writer, base.get_Style(), null);
             writer.WriteAttribute("type", "submit");
             writer.Write(" value=\"");
             writer.WriteText(base.get_Control().get_Text(), true);
             writer.Write("\"/>");
             writer.ExitLayout(base.get_Style());
         }
         else
         {
             Wrapping wrapping = *((Wrapping*) base.get_Style().get_Item(Style.WrappingKey, true));
             if ((wrapping != 1) && (wrapping != 0))
             {
                 writer.WriteAttribute("style", "overflow-x:hidden;width:100%");
             }
             else
             {
                 writer.WriteAttribute("style", "word-wrap:break-word;width:100%");
             }
             if (alignment != null)
             {
                 writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
             }
             writer.Write(">");
             writer.WriteBeginTag("a");
             writer.WriteAttribute("href", "NavigationUrl");
             writer.Write(">");
             Utils.WriteCssStyleText(writer, base.get_Style(), null, base.get_Control().get_Text(), true);
             writer.WriteEndTag("a");
         }
         writer.WriteEndTag("div");
         Utils.ExitZeroFontSizeTag(writer);
     }
     else
     {
         writer.WriteBeginTag("div");
         if (alignment == 2)
         {
             writer.WriteAttribute("align", "center");
         }
         writer.WriteAttribute("style", "overflow-x:hidden;width:100%");
         writer.Write(">");
         writer.WriteBeginTag("img");
         Utils.WriteStyleAttribute(writer, base.get_Style(), null);
         writer.WriteAttribute("src", base.get_Control().get_ImageUrl(), true);
         if ((alignment == 3) || (alignment == 1))
         {
             writer.WriteAttribute("align", Enum.GetName(typeof(Alignment), alignment));
         }
         writer.WriteAttribute("border", "0");
         writer.Write(">");
         writer.WriteEndTag("div");
     }
 }
        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.IsNullOrEmpty((String) Style[Style.FontNameKey, true]))
            {
                // 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(CultureInfo.InvariantCulture, htmlFragment, size) : 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(CultureInfo.InvariantCulture, htmlFragment, fittingSize));
                }
                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 (!String.IsNullOrEmpty(Control.Text))
            {
                writer.Write(" value=\"");
                writer.WriteText(Control.Text, true);
                writer.Write("\" ");
            }
            if (fittingSize > 0)
            {
                writer.WriteAttribute("size", fittingSize.ToString(CultureInfo.InvariantCulture));
            }
            if (pwd)
            {
                writer.WriteAttribute("type", "password");
            }
            writer.Write("/>");

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