/// <include file='doc\HtmlImageAdapter.uex' path='docs/doc[@for="HtmlImageAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            String target = Control.NavigateUrl;

            writer.EnterLayout(Style);
            if (!String.IsNullOrEmpty(target))
            {
                RenderBeginLink(writer, target);
            }

            if (String.IsNullOrEmpty(Control.ImageUrl))
            {
                // Just write the alternate as text
                writer.EnsureStyle();
                writer.MarkStyleContext();
                writer.EnterFormat(Style);
                writer.WriteText(Control.AlternateText, true);
                writer.ExitFormat(Style);
                writer.UnMarkStyleContext();
            }
            else
            {
                RenderImage(writer);
            }

            if (!String.IsNullOrEmpty(target))
            {
                RenderEndLink(writer);
            }
            writer.ExitLayout(Style, Control.BreakAfter);
        }
        /// <include file='doc\HtmlImageAdapter.uex' path='docs/doc[@for="HtmlImageAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            String target = Control.NavigateUrl;

            writer.EnterLayout(Style);
            if (!String.IsNullOrEmpty(target))
            {
                RenderBeginLink(writer, target);
            }

            if (String.IsNullOrEmpty(Control.ImageUrl))
            {
                // Just write the alternate as text
                writer.EnsureStyle();
                writer.MarkStyleContext();
                writer.EnterFormat(Style);
                writer.WriteText(Control.AlternateText, true);
                writer.ExitFormat(Style);
                writer.UnMarkStyleContext();
            }
            else
            {
                RenderImage(writer);
            }

            if (!String.IsNullOrEmpty(target))
            {
                RenderEndLink(writer);
            }
            writer.ExitLayout(Style, Control.BreakAfter);
        }
Пример #3
0
 private void RenderPostBackEventAsAnchor(HtmlMobileTextWriter writer, string argument, string linkText, Style style)
 {
     writer.EnterFormat(style);
     writer.WriteBeginTag("a");
     base.RenderPostBackEventAsAttribute(writer, "href", argument);
     writer.Write(">");
     writer.WriteText(linkText, true);
     writer.WriteEndTag("a");
     writer.ExitFormat(style);
 }
Пример #4
0
        /// <include file='doc\ChtmlFormAdapter.uex' path='docs/doc[@for="ChtmlFormAdapter.RenderPagerTag"]/*' />
        protected internal override void RenderPagerTag(
            HtmlMobileTextWriter writer,
            int pageToNavigate,
            String text)
        {
            writer.EnterLayout(Style);
            writer.EnterFormat(Style);
            writer.WriteBeginTag("input");

            // Specially encode the page number with the control id.
            // The corresponding code that handles postback should know how
            // to extract the page number correctly.
            writer.Write(" name=\"");
            writer.Write(Control.UniqueID);
            writer.Write(Constants.PagePrefix);
            writer.Write(pageToNavigate.ToString(CultureInfo.InvariantCulture));
            writer.Write("\"");

            writer.WriteAttribute("type", "submit");
            writer.WriteAttribute("value", text, true);
            writer.Write("/>");
            writer.ExitFormat(Style);
            writer.ExitLayout(Style);
        }
        private void RenderItemsListWithoutTableTags(HtmlMobileTextWriter writer)
        {
            int startIndex = Control.FirstVisibleItemIndex;
            int pageSize   = Control.VisibleItemCount;
            ObjectListItemCollection   items     = Control.Items;
            IObjectListFieldCollection allFields = Control.AllFields;
            int count = allFields.Count;

            int nextStartIndex  = startIndex + pageSize;
            int labelFieldIndex = Control.LabelFieldIndex;


            Style style      = this.Style;
            Style labelStyle = Control.LabelStyle;

            writer.EnterStyle(labelStyle);
            writer.WriteText(Control.AllFields[labelFieldIndex].Title, true);
            writer.ExitStyle(labelStyle, true);

            bool hasDefaultCommand     = HasDefaultCommand();
            bool onlyHasDefaultCommand = OnlyHasDefaultCommand();
            bool requiresDetailsScreen = !onlyHasDefaultCommand && HasCommands();

            // if there is > 1 visible field, need a details screen
            for (int visibleFields = 0, i = 0; !requiresDetailsScreen && i < count; i++)
            {
                visibleFields        += allFields[i].Visible ? 1 : 0;
                requiresDetailsScreen =
                    requiresDetailsScreen || visibleFields > 1;
            }
            bool itemRequiresHyperlink  = requiresDetailsScreen || hasDefaultCommand;
            bool itemRequiresMoreButton = requiresDetailsScreen && hasDefaultCommand;


            Style subCommandStyle = Control.CommandStyle;

            subCommandStyle.Alignment = style.Alignment;
            subCommandStyle.Wrapping  = style.Wrapping;

            writer.EnterStyle(style);
            for (int i = startIndex; i < nextStartIndex; i++)
            {
                ObjectListItem item = items[i];

                if (itemRequiresHyperlink)
                {
                    RenderPostBackEventAsAnchor(writer,
                                                hasDefaultCommand ?
                                                item.Index.ToString(CultureInfo.InvariantCulture) :
                                                String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index),
                                                item[labelFieldIndex]);
                }
                else
                {
                    writer.WriteText(item[labelFieldIndex], true);
                }

                if (itemRequiresMoreButton)
                {
                    BooleanOption cachedItalic = subCommandStyle.Font.Italic;
                    subCommandStyle.Font.Italic = BooleanOption.False;
                    writer.EnterFormat(subCommandStyle);
                    writer.Write(" [");
                    writer.ExitFormat(subCommandStyle);
                    subCommandStyle.Font.Italic = cachedItalic;
                    writer.EnterFormat(subCommandStyle);
                    String moreText = Control.MoreText.Length == 0 ?
                                      GetDefaultLabel(MoreLabel) :
                                      Control.MoreText;
                    writer.WriteBeginTag("a");
                    RenderPostBackEventAsAttribute(writer, "href", String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index));
                    writer.Write(">");
                    writer.WriteText(moreText, true);
                    writer.WriteEndTag("a");
                    writer.ExitFormat(subCommandStyle);
                    subCommandStyle.Font.Italic = BooleanOption.False;
                    writer.EnterFormat(subCommandStyle);
                    writer.Write("]");
                    writer.ExitFormat(subCommandStyle);
                    subCommandStyle.Font.Italic = cachedItalic;
                }

                if (i < (nextStartIndex - 1))
                {
                    writer.WriteBreak();
                }
            }
            writer.ExitStyle(style, Control.BreakAfter);
        }
        private void RenderItemsListWithTableTags(HtmlMobileTextWriter writer)
        {
            int pageStart = Control.FirstVisibleItemIndex;
            int pageSize  = Control.VisibleItemCount;
            ObjectListItemCollection items = Control.Items;

            // Determine how to render.
            bool shouldRenderAsTable    = ShouldRenderAsTable();
            bool hasDefaultCommand      = HasDefaultCommand();
            bool onlyHasDefaultCommand  = OnlyHasDefaultCommand();
            bool requiresDetailsScreen  = HasItemDetails() || (!onlyHasDefaultCommand && HasCommands());
            bool itemRequiresHyperlink  = requiresDetailsScreen || hasDefaultCommand;
            bool itemRequiresMoreButton = requiresDetailsScreen && hasDefaultCommand;

            int fieldCount;

            int[] fieldIndices = new int[] {};
            if (shouldRenderAsTable)
            {
                fieldIndices = Control.TableFieldIndices;
            }
            Debug.Assert(fieldIndices != null, "fieldIndices is null");
            fieldCount = fieldIndices.Length;

            if (fieldCount == 0)
            {
                fieldIndices    = new int[1];
                fieldIndices[0] = Control.LabelFieldIndex;
                fieldCount      = 1;
            }

            Style style           = this.Style;
            Style subCommandStyle = Control.CommandStyle;
            Style labelStyle      = Control.LabelStyle;
            Color foreColor       = (Color)style[Style.ForeColorKey, true];

            writer.BeginStyleContext();
            writer.WriteLine("<table border=0 width=\"100%\">\r\n<tr>");
            for (int field = 0; field < fieldCount; field++)
            {
                writer.Write("<td>");
                writer.BeginStyleContext();
                writer.EnterStyle(labelStyle);
                writer.WriteText(Control.AllFields[fieldIndices[field]].Title, true);
                writer.ExitStyle(labelStyle);
                writer.EndStyleContext();
                writer.Write("</td>");
            }
            if (itemRequiresMoreButton)
            {
                writer.WriteLine("<td/>");
            }
            writer.WriteLine("\r\n</tr>");
            RenderRule(writer, foreColor, fieldCount + 1);

            for (int i = 0; i < pageSize; i++)
            {
                ObjectListItem item = items[pageStart + i];
                writer.WriteLine("<tr>");
                for (int field = 0; field < fieldCount; field++)
                {
                    writer.Write("<td>");
                    if (field == 0 && itemRequiresHyperlink)
                    {
                        writer.BeginStyleContext();
                        writer.EnterStyle(style);
                        String eventArgument =
                            hasDefaultCommand ?
                            item.Index.ToString(CultureInfo.InvariantCulture) :
                            String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index.ToString(CultureInfo.InvariantCulture));
                        RenderPostBackEventAsAnchor(writer,
                                                    eventArgument,
                                                    item[fieldIndices[0]]);
                        writer.ExitStyle(style);
                        writer.EndStyleContext();
                    }
                    else
                    {
                        writer.BeginStyleContext();
                        writer.EnterStyle(style);
                        writer.WriteText(item[fieldIndices[field]], true);
                        writer.ExitStyle(style);
                        writer.EndStyleContext();
                    }
                    writer.WriteLine("</td>");
                }

                if (itemRequiresMoreButton)
                {
                    writer.Write("<td align=right>");
                    writer.BeginStyleContext();
                    writer.EnterFormat(subCommandStyle);
                    String moreText = Control.MoreText.Length == 0 ?
                                      GetDefaultLabel(MoreLabel) :
                                      Control.MoreText;
                    RenderPostBackEventAsAnchor(writer,
                                                String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index),
                                                moreText,
                                                subCommandStyle);
                    writer.ExitFormat(subCommandStyle);
                    writer.EndStyleContext();
                    writer.Write("</td>\r\n");
                }

                writer.WriteLine("</tr>");
            }

            RenderRule(writer, foreColor, fieldCount + 1);

            writer.Write("</table>\r\n");
            writer.EndStyleContext();
        }
Пример #7
0
        /// <include file='doc\HtmlListAdapter.uex' path='docs/doc[@for="HtmlListAdapter.RenderList"]/*' />
        protected virtual void RenderList(HtmlMobileTextWriter writer)
        {
            MobileListItemCollection items = Control.Items;
            Wrapping wrap = Style.Wrapping; // used for tables, no decoration case.

            if (items.Count == 0)
            {
                return;
            }

            int pageStart = Control.FirstVisibleItemIndex;
            int pageSize  = Control.VisibleItemCount;

            // Determine what markup to use.

            String         listSuffix, itemPrefix, itemSuffix;
            ListDecoration decoration  = Control.Decoration;
            bool           insideStyle = true;

            // We know that for table tag, outer style doesn't carry over
            // into inside tags so style state needs to be reset.
            // For other cases, we enter the style here once and exit at the
            // end once.
            if (decoration != ListDecoration.None || !Device.Tables)
            {
                writer.EnterStyle(Style);
                insideStyle = false;
            }

            switch (decoration)
            {
            case ListDecoration.Bulleted:
                writer.WriteLine("<ul>");
                listSuffix = "</ul>";
                itemPrefix = "<li>";
                itemSuffix = "</li>";

                if (!Device.RendersBreaksAfterHtmlLists)
                {
                    listSuffix += "<br>";
                }
                break;

            case ListDecoration.Numbered:
                if (pageStart == 0)
                {
                    writer.WriteLine("<ol>");
                }
                else
                {
                    writer.Write("<ol start=\"");
                    writer.Write(pageStart + 1);
                    writer.WriteLine("\">");
                }
                listSuffix = "</ol>";
                itemPrefix = "<li>";
                itemSuffix = "</li>";

                if (!Device.RendersBreaksAfterHtmlLists)
                {
                    listSuffix += "<br>";
                }
                break;

            default:
                if (Device.Tables)
                {
                    listSuffix     = "</table>";
                    Style.Wrapping = Wrapping.NotSet;
                    writer.EnterLayout(Style);
                    writer.WriteLine("<table>");
                    if (wrap == Wrapping.NoWrap)
                    {
                        itemPrefix = "<tr nowrap><td>";
                    }
                    else
                    {
                        itemPrefix = "<tr><td>";
                    }
                    itemSuffix = "</td></tr>";
                }
                else
                {
                    listSuffix = String.Empty;
                    itemPrefix = String.Empty;
                    itemSuffix = "<br>";
                }
                break;
            }

            bool hasCmdHandler = Control.HasItemCommandHandler;

            for (int i = 0; i < pageSize; i++)
            {
                MobileListItem item = items[pageStart + i];
                writer.Write(itemPrefix);

                if (insideStyle)
                {
                    writer.BeginStyleContext();
                    writer.EnterFormat(Style);
                }

                if (Control.ItemsAsLinks)
                {
                    RenderBeginLink(writer, item.Value);
                }
                else if (hasCmdHandler)
                {
                    writer.WriteBeginTag("a");
                    RenderPostBackEventAsAttribute(writer, "href", item.Index.ToString(CultureInfo.InvariantCulture));
                    writer.Write(">");
                }
                writer.WriteEncodedText(item.Text);

                if (hasCmdHandler || Control.ItemsAsLinks)
                {
                    RenderEndLink(writer);
                }

                if (insideStyle)
                {
                    writer.ExitFormat(Style);
                    writer.EndStyleContext();
                }
                writer.WriteLine(itemSuffix);
            }

            if (listSuffix == null || listSuffix.Length > 0)
            {
                writer.WriteLine(listSuffix);
            }

            if (decoration != ListDecoration.None || !Device.Tables)
            {
                writer.ExitStyle(Style);
            }
            else
            {
                writer.ExitLayout(Style);
                Style.Wrapping = wrap;
            }
        }
        /// <include file='doc\HtmlSelectionListAdapter.uex' path='docs/doc[@for="HtmlSelectionListAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            MobileListItemCollection items      = Control.Items;
            ListSelectType           selectType = Control.SelectType;

            if (items.Count == 0 &&
                selectType != ListSelectType.ListBox &&
                selectType != ListSelectType.MultiSelectListBox)
            {
                return;
            }

            int    selectedIndex = Control.SelectedIndex;
            String renderName;

            if (Device.RequiresAttributeColonSubstitution)
            {
                renderName = Control.UniqueID.Replace(':', ',');
            }
            else
            {
                renderName = Control.UniqueID;
            }

            switch (selectType)
            {
            case ListSelectType.DropDown:
            case ListSelectType.ListBox:
            case ListSelectType.MultiSelectListBox:

                if (items.Count == 0 && !Device.CanRenderEmptySelects)
                {
                    break;
                }

                writer.EnterLayout(Style);
                writer.WriteBeginTag("select");

                if (selectType == ListSelectType.MultiSelectListBox)
                {
                    writer.Write(" multiple");
                }

                if (selectType == ListSelectType.ListBox || selectType == ListSelectType.MultiSelectListBox)
                {
                    writer.WriteAttribute("size", Control.Rows.ToString(CultureInfo.InvariantCulture));
                }

                writer.WriteAttribute("name", renderName);
                writer.Write(">");

                for (int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                {
                    MobileListItem item = items[itemIndex];
                    writer.WriteBeginTag("option");
                    WriteItemValueAttribute(writer, itemIndex, item.Value);
                    if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex))
                    {
                        writer.Write(" selected>");
                    }
                    else
                    {
                        writer.Write(">");
                    }
                    writer.WriteEncodedText(item.Text);
                    writer.WriteLine("");
                }
                writer.Write("</select>");

                if (Device.HidesRightAlignedMultiselectScrollbars &&
                    selectType == ListSelectType.MultiSelectListBox)
                {
                    // nested if for perf
                    if ((Alignment)Style[Style.AlignmentKey, true] == Alignment.Right)
                    {
                        writer.Write("&nbsp;&nbsp;&nbsp;&nbsp;");
                    }
                }
                writer.WriteLine("");

                if (!Page.DesignMode)
                {
                    writer.ExitLayout(Style, Control.BreakAfter);
                }
                else
                {
                    writer.ExitLayout(Style, false);
                }
                break;

            case ListSelectType.Radio:
            case ListSelectType.CheckBox:

                String selectTypeString =
                    (selectType == ListSelectType.Radio) ?
                    "radio" :
                    "checkbox";
                Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
                if (!Device.Tables || alignment == Alignment.Left || alignment == Alignment.NotSet)
                {
                    writer.EnterStyle(Style);
                    bool breakAfter = false;
                    for (int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                    {
                        if (breakAfter)
                        {
                            writer.WriteBreak();
                        }
                        MobileListItem item = items[itemIndex];

                        writer.WriteBeginTag("input");
                        writer.WriteAttribute("type", selectTypeString);
                        writer.WriteAttribute("name", renderName);
                        WriteItemValueAttribute(writer, itemIndex, item.Value);
                        if (item.Selected &&
                            (Control.IsMultiSelect || itemIndex == selectedIndex) &&
                            Device.SupportsUncheck)
                        {
                            writer.Write(" checked>");
                        }
                        else
                        {
                            writer.Write(">");
                        }
                        writer.WriteEncodedText(item.Text);
                        breakAfter = true;
                    }
                    writer.ExitStyle(Style, Control.BreakAfter);
                }
                else     // Device supports tables and alignment is non default.
                {
                    Wrapping wrapping = (Wrapping)Style[Style.WrappingKey, true];
                    bool     nowrap   = (wrapping == Wrapping.NoWrap);

                    writer.EnterLayout(Style);
                    writer.WriteFullBeginTag("table");
                    writer.BeginStyleContext();
                    for (int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                    {
                        MobileListItem item = items[itemIndex];
                        writer.WriteFullBeginTag("tr");
                        writer.WriteBeginTag("td");
                        if (nowrap)
                        {
                            writer.WriteAttribute("nowrap", "true");
                        }
                        writer.Write(">");

                        writer.WriteBeginTag("input");
                        writer.WriteAttribute("type", selectTypeString);
                        writer.WriteAttribute("name", renderName);
                        WriteItemValueAttribute(writer, itemIndex, item.Value);
                        if (item.Selected &&
                            (Control.IsMultiSelect || itemIndex == selectedIndex) &&
                            Device.SupportsUncheck)
                        {
                            writer.Write(" checked>");
                        }
                        else
                        {
                            writer.Write(">");
                        }

                        writer.MarkStyleContext();
                        writer.EnterFormat(Style);
                        writer.WriteEncodedText(item.Text);
                        writer.ExitFormat(Style);
                        writer.UnMarkStyleContext();
                        writer.WriteEndTag("td");
                        writer.WriteEndTag("tr");
                    }
                    writer.WriteEndTag("table");
                    writer.EndStyleContext();
                    writer.ExitFormat(Style, Control.BreakAfter);
                }
                break;
            }
        }
        /// <include file='doc\ChtmlFormAdapter.uex' path='docs/doc[@for="ChtmlFormAdapter.RenderPagerTag"]/*' />
        protected internal override void RenderPagerTag(
            HtmlMobileTextWriter writer,
            int pageToNavigate,
            String text)
        {
            writer.EnterLayout(Style);
            writer.EnterFormat(Style);
            writer.WriteBeginTag("input");

            // Specially encode the page number with the control id.
            // The corresponding code that handles postback should know how
            // to extract the page number correctly.
            writer.Write(" name=\"");
            writer.Write(Control.UniqueID);
            writer.Write(Constants.PagePrefix);
            writer.Write(pageToNavigate.ToString(CultureInfo.InvariantCulture));
            writer.Write("\"");

            writer.WriteAttribute("type", "submit");
            writer.WriteAttribute("value", text, true);
            writer.Write("/>");
            writer.ExitFormat(Style);
            writer.ExitLayout(Style);
        }
 // Private overload for use with subcommands.
 // Style, Enter/ExitFormat included only for completeness because style
 // is already set for subcommands.
 private void RenderPostBackEventAsAnchor(
     HtmlMobileTextWriter writer,
     String argument,
     String linkText,
     Style style)
 {
     writer.EnterFormat(style);
     writer.WriteBeginTag("a");
     RenderPostBackEventAsAttribute(writer, "href", argument);
     writer.Write(">");
     writer.WriteText(linkText, true);
     writer.WriteEndTag("a");
     writer.ExitFormat(style);
 }
        private void RenderItemsListWithoutTableTags(HtmlMobileTextWriter writer)
        {
            int startIndex = Control.FirstVisibleItemIndex;
            int pageSize = Control.VisibleItemCount;
            ObjectListItemCollection items = Control.Items;
            IObjectListFieldCollection allFields = Control.AllFields;
            int count = allFields.Count;
            
            int nextStartIndex =  startIndex + pageSize;
            int labelFieldIndex = Control.LabelFieldIndex;

             
            Style style = this.Style;
            Style labelStyle = Control.LabelStyle;
            writer.EnterStyle(labelStyle);
            writer.WriteText(Control.AllFields[labelFieldIndex].Title, true);
            writer.ExitStyle(labelStyle, true);

            bool hasDefaultCommand = HasDefaultCommand();
            bool onlyHasDefaultCommand = OnlyHasDefaultCommand();
            bool requiresDetailsScreen = !onlyHasDefaultCommand && HasCommands();
            // if there is > 1 visible field, need a details screen
            for (int visibleFields = 0, i = 0; !requiresDetailsScreen && i < count; i++)
            {
                visibleFields += allFields[i].Visible ? 1 : 0;
                requiresDetailsScreen = 
                    requiresDetailsScreen || visibleFields > 1;
            }   
            bool itemRequiresHyperlink = requiresDetailsScreen || hasDefaultCommand;
            bool itemRequiresMoreButton = requiresDetailsScreen && hasDefaultCommand;
            

            Style subCommandStyle = Control.CommandStyle;
            subCommandStyle.Alignment = style.Alignment;
            subCommandStyle.Wrapping = style.Wrapping;

            writer.EnterStyle(style);
            for (int i = startIndex; i < nextStartIndex; i++)
            {
                ObjectListItem item = items[i];

                if (itemRequiresHyperlink)
                {
                    RenderPostBackEventAsAnchor(writer,
                        hasDefaultCommand ?
                        item.Index.ToString(CultureInfo.InvariantCulture) :
                        String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index),
                        item[labelFieldIndex]);
                }
                else
                {
                    writer.WriteText(item[labelFieldIndex], true);
                }

                if (itemRequiresMoreButton)
                {
                    BooleanOption cachedItalic = subCommandStyle.Font.Italic;
                    subCommandStyle.Font.Italic = BooleanOption.False;
                    writer.EnterFormat(subCommandStyle);
                    writer.Write(" [");
                    writer.ExitFormat(subCommandStyle);
                    subCommandStyle.Font.Italic = cachedItalic;
                    writer.EnterFormat(subCommandStyle);
                    String moreText = Control.MoreText.Length == 0 ?
                        GetDefaultLabel(MoreLabel) :
                        Control.MoreText;
                    writer.WriteBeginTag("a");
                    RenderPostBackEventAsAttribute(writer, "href", String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index));
                    writer.Write(">");
                    writer.WriteText(moreText, true);
                    writer.WriteEndTag("a");                  
                    writer.ExitFormat(subCommandStyle);
                    subCommandStyle.Font.Italic = BooleanOption.False;
                    writer.EnterFormat(subCommandStyle);
                    writer.Write("]");
                    writer.ExitFormat(subCommandStyle);
                    subCommandStyle.Font.Italic = cachedItalic;
                }
                
                if(i < (nextStartIndex - 1))
                {
                    writer.WriteBreak();            
                }
            }
            writer.ExitStyle(style, Control.BreakAfter);
        }
        private void RenderItemsListWithTableTags(HtmlMobileTextWriter writer)
        {
            int pageStart = Control.FirstVisibleItemIndex;
            int pageSize = Control.VisibleItemCount;
            ObjectListItemCollection items = Control.Items;

            // Determine how to render.
            bool shouldRenderAsTable = ShouldRenderAsTable();
            bool hasDefaultCommand = HasDefaultCommand();
            bool onlyHasDefaultCommand = OnlyHasDefaultCommand();
            bool requiresDetailsScreen = HasItemDetails() || (!onlyHasDefaultCommand && HasCommands());
            bool itemRequiresHyperlink = requiresDetailsScreen || hasDefaultCommand;
            bool itemRequiresMoreButton = requiresDetailsScreen && hasDefaultCommand;

            int fieldCount;
            int[] fieldIndices = new int[]{};
            if (shouldRenderAsTable)
            {
                fieldIndices = Control.TableFieldIndices;
            }
            Debug.Assert(fieldIndices != null, "fieldIndices is null");
            fieldCount = fieldIndices.Length;

            if(fieldCount == 0)
            {
                fieldIndices = new int[1];
                fieldIndices[0] = Control.LabelFieldIndex;
                fieldCount = 1;
            }

            Style style = this.Style;
            Style subCommandStyle = Control.CommandStyle;
            Style labelStyle = Control.LabelStyle;
            Color foreColor = (Color)style[Style.ForeColorKey, true];

            writer.BeginStyleContext();
            writer.WriteLine("<table border=0 width=\"100%\">\r\n<tr>");
            for (int field = 0; field < fieldCount; field++)
            {
                writer.Write("<td>");
                writer.BeginStyleContext();
                writer.EnterStyle(labelStyle);
                writer.WriteText(Control.AllFields[fieldIndices[field]].Title, true);
                writer.ExitStyle(labelStyle);
                writer.EndStyleContext();
                writer.Write("</td>");
            }
            if (itemRequiresMoreButton)
            {
                writer.WriteLine("<td/>");
            }
            writer.WriteLine("\r\n</tr>");
            RenderRule(writer, foreColor, fieldCount + 1);

            for (int i = 0; i < pageSize; i++)
            {
                ObjectListItem item = items[pageStart + i];
                writer.WriteLine("<tr>");
                for (int field = 0; field < fieldCount; field++)
                {
                    writer.Write("<td>");
                    if (field == 0 && itemRequiresHyperlink)
                    {
                        writer.BeginStyleContext();
                        writer.EnterStyle(style);
                        String eventArgument =
                            hasDefaultCommand ?
                                item.Index.ToString(CultureInfo.InvariantCulture) :
                                String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index.ToString(CultureInfo.InvariantCulture));
                        RenderPostBackEventAsAnchor(writer,
                            eventArgument,
                            item[fieldIndices[0]]);
                        writer.ExitStyle(style);
                        writer.EndStyleContext();
                    }
                    else
                    {
                        writer.BeginStyleContext();
                        writer.EnterStyle(style);
                        writer.WriteText(item[fieldIndices[field]], true);
                        writer.ExitStyle(style);
                        writer.EndStyleContext();
                    }
                    writer.WriteLine("</td>");
                }

                if (itemRequiresMoreButton)
                {
                    writer.Write("<td align=right>");
                    writer.BeginStyleContext();
                    writer.EnterFormat(subCommandStyle);
                    String moreText = Control.MoreText.Length == 0 ?
                        GetDefaultLabel(MoreLabel) :
                        Control.MoreText;
                    RenderPostBackEventAsAnchor(writer,
                        String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index), 
                        moreText,
                        subCommandStyle);
                    writer.ExitFormat(subCommandStyle);
                    writer.EndStyleContext();
                    writer.Write("</td>\r\n");
                }

                writer.WriteLine("</tr>");
            }

            RenderRule(writer, foreColor, fieldCount + 1);

            writer.Write("</table>\r\n");
            writer.EndStyleContext();
        }
        /// <include file='doc\HtmlListAdapter.uex' path='docs/doc[@for="HtmlListAdapter.RenderList"]/*' />
        protected virtual void RenderList(HtmlMobileTextWriter writer)
        {
            MobileListItemCollection items = Control.Items;
            Wrapping wrap = Style.Wrapping; // used for tables, no decoration case.
            if (items.Count == 0)
            {
                return;
            }

            int pageStart = Control.FirstVisibleItemIndex;
            int pageSize = Control.VisibleItemCount;

            // Determine what markup to use.

            String listSuffix, itemPrefix, itemSuffix;
            ListDecoration decoration = Control.Decoration;
            bool insideStyle = true;

            // We know that for table tag, outer style doesn't carry over
            // into inside tags so style state needs to be reset.
            // For other cases, we enter the style here once and exit at the
            // end once.
            if (decoration != ListDecoration.None || !Device.Tables)
            {
                writer.EnterStyle(Style);
                insideStyle = false;
            }

            switch (decoration)
            {
                case ListDecoration.Bulleted:
                    writer.WriteLine("<ul>");
                    listSuffix = "</ul>";
                    itemPrefix = "<li>";
                    itemSuffix = "</li>";

                    if (!Device.RendersBreaksAfterHtmlLists)
                    {
                        listSuffix += "<br>";
                    }
                    break;
                case ListDecoration.Numbered:
                    if (pageStart == 0)
                    {
                        writer.WriteLine("<ol>");
                    }
                    else
                    {
                        writer.Write("<ol start=\"");
                        writer.Write(pageStart + 1);
                        writer.WriteLine("\">");
                    }
                    listSuffix = "</ol>";
                    itemPrefix = "<li>";
                    itemSuffix = "</li>";

                    if (!Device.RendersBreaksAfterHtmlLists)
                    {
                        listSuffix += "<br>";
                    }
                    break;
                default:
                    if (Device.Tables)
                    {
                        listSuffix = "</table>";
                        Style.Wrapping = Wrapping.NotSet;
                        writer.EnterLayout(Style);
                        writer.WriteLine("<table>");
                        if(wrap == Wrapping.NoWrap)
                        {
                            itemPrefix = "<tr nowrap><td>";
                        }
                        else
                        {
                            itemPrefix = "<tr><td>";
                        }
                        itemSuffix = "</td></tr>";
                    }
                    else
                    {
                        listSuffix = String.Empty;
                        itemPrefix = String.Empty;
                        itemSuffix = "<br>";
                    }
                    break;
            }

            bool hasCmdHandler = Control.HasItemCommandHandler;

            for (int i = 0; i < pageSize; i++)
            {
                MobileListItem item = items[pageStart + i];
                writer.Write(itemPrefix);

                if(insideStyle)
                {
                    writer.BeginStyleContext();
                    writer.EnterFormat(Style);
                }

                if(Control.ItemsAsLinks)
                {
                    RenderBeginLink(writer, item.Value);
                }
                else if(hasCmdHandler) 
                {
                    writer.WriteBeginTag("a");
                    RenderPostBackEventAsAttribute(writer, "href", item.Index.ToString(CultureInfo.InvariantCulture));
                    writer.Write(">");
                } 
                writer.WriteEncodedText(item.Text);
                
                if (hasCmdHandler || Control.ItemsAsLinks)
                {
                    RenderEndLink(writer);
                }

                if(insideStyle)
                {
                    writer.ExitFormat(Style);
                    writer.EndStyleContext();
                }
                writer.WriteLine(itemSuffix);
            }

            if (listSuffix == null || listSuffix.Length > 0)
            {
                writer.WriteLine(listSuffix);
            }

            if (decoration != ListDecoration.None || !Device.Tables)
            {
                writer.ExitStyle(Style);
            }
            else
            {
                writer.ExitLayout(Style);
                Style.Wrapping = wrap;
            }
        }
        /// <include file='doc\HtmlSelectionListAdapter.uex' path='docs/doc[@for="HtmlSelectionListAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            MobileListItemCollection items = Control.Items;
            ListSelectType selectType = Control.SelectType;

            if (items.Count == 0 && 
                selectType != ListSelectType.ListBox && 
                selectType != ListSelectType.MultiSelectListBox)
            {
                return;
            }
            
            int selectedIndex = Control.SelectedIndex;
            String renderName;
            if(Device.RequiresAttributeColonSubstitution)
            {
                renderName = Control.UniqueID.Replace(':', ',');
            }
            else
            {
                renderName = Control.UniqueID;
            }

            switch(selectType)
            {
                case ListSelectType.DropDown:
                case ListSelectType.ListBox:
                case ListSelectType.MultiSelectListBox:

                    if (items.Count == 0 && !Device.CanRenderEmptySelects)
                    {
                        break;
                    }

                    writer.EnterLayout(Style);
                    writer.WriteBeginTag("select");

                    if (selectType == ListSelectType.MultiSelectListBox)
                    {
                        writer.Write(" multiple");
                    }

                    if (selectType == ListSelectType.ListBox || selectType == ListSelectType.MultiSelectListBox)
                    {
                        writer.WriteAttribute("size", Control.Rows.ToString(CultureInfo.InvariantCulture));
                    }

                    writer.WriteAttribute("name", renderName);
                    writer.Write(">");

                    for(int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                    {
                        MobileListItem item = items[itemIndex];
                        writer.WriteBeginTag("option");
                        WriteItemValueAttribute(writer, itemIndex, item.Value);
                        if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex))
                        {
                            writer.Write(" selected>");
                        }
                        else
                        {
                            writer.Write(">");
                        }
                        writer.WriteEncodedText(item.Text);
                        writer.WriteLine("");
                    }
                    writer.Write("</select>");
            
                    if(Device.HidesRightAlignedMultiselectScrollbars &&
                        selectType == ListSelectType.MultiSelectListBox)
                    {
                        // nested if for perf
                        if((Alignment)Style[Style.AlignmentKey, true] == Alignment.Right)
                        {                                                
                            writer.Write("&nbsp;&nbsp;&nbsp;&nbsp;");
                        }
                    }
                    writer.WriteLine("");
                    
                    if (!Page.DesignMode)
                    {
                        writer.ExitLayout(Style, Control.BreakAfter);
                    }
                    else
                    {
                        writer.ExitLayout(Style, false);
                    }
                    break;

                case ListSelectType.Radio:
                case ListSelectType.CheckBox:

                    String selectTypeString =
                        (selectType == ListSelectType.Radio) ?
                        "radio" :
                        "checkbox";
                    Alignment alignment = (Alignment)Style[Style.AlignmentKey, true];
                    if(!Device.Tables || alignment == Alignment.Left || alignment == Alignment.NotSet)
                    {
                        writer.EnterStyle(Style);
                        bool breakAfter = false;
                        for(int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                        {
                            if(breakAfter)
                            {
                                writer.WriteBreak();
                            }
                            MobileListItem item = items[itemIndex];

                            writer.WriteBeginTag("input");
                            writer.WriteAttribute("type", selectTypeString);
                            writer.WriteAttribute("name", renderName);
                            WriteItemValueAttribute(writer, itemIndex, item.Value);
                            if (item.Selected && 
                                (Control.IsMultiSelect || itemIndex == selectedIndex) &&
                                Device.SupportsUncheck)
                            {
                                writer.Write(" checked>");
                            }
                            else
                            {
                                writer.Write(">");
                            }
                            writer.WriteEncodedText(item.Text);
                            breakAfter = true;
                        }
                        writer.ExitStyle(Style, Control.BreakAfter);
                    }
                    else // Device supports tables and alignment is non default.
                    {
                        Wrapping  wrapping  = (Wrapping) Style[Style.WrappingKey , true];
                        bool nowrap = (wrapping == Wrapping.NoWrap);

                        writer.EnterLayout(Style);
                        writer.WriteFullBeginTag("table");
                        writer.BeginStyleContext();
                        for(int itemIndex = 0; itemIndex < items.Count; itemIndex++)
                        {
                            MobileListItem item = items[itemIndex];
                            writer.WriteFullBeginTag("tr");
                            writer.WriteBeginTag("td");
                            if(nowrap)
                            {
                                writer.WriteAttribute("nowrap","true");
                            }
                            writer.Write(">");

                            writer.WriteBeginTag("input");
                            writer.WriteAttribute("type", selectTypeString);
                            writer.WriteAttribute("name", renderName);
                            WriteItemValueAttribute(writer, itemIndex, item.Value);
                            if (item.Selected && 
                                (Control.IsMultiSelect || itemIndex == selectedIndex) &&
                                Device.SupportsUncheck)
                            {
                                writer.Write(" checked>");
                            }
                            else
                            {
                                writer.Write(">");
                            }

                            writer.MarkStyleContext();
                            writer.EnterFormat(Style);
                            writer.WriteEncodedText(item.Text);
                            writer.ExitFormat(Style);
                            writer.UnMarkStyleContext();
                            writer.WriteEndTag("td");
                            writer.WriteEndTag("tr");
                        }
                        writer.WriteEndTag("table");
                        writer.EndStyleContext();
                        writer.ExitFormat(Style, Control.BreakAfter);
                    }
                break;
            }
        }