Exemplo n.º 1
0
        // Recursive method to check if there is any descendant control
        // requires the form tag.  For unknown cases, the method returns true
        // in case the unknown rendering requires the form tag.
        private bool IsFormTagNeeded(Control control)
        {
            // Check itself first
            if (!control.Visible)
            {
                return(false);
            }

            MobileControl mobileControl = control as MobileControl;

            if (mobileControl != null)
            {
                // Since we don't have control over what content is included
                // in the template, to be safe we just generate the form tag.
                if (mobileControl.IsTemplated)
                {
                    return(true);
                }

                HtmlControlAdapter adapter = mobileControl.Adapter as HtmlControlAdapter;
                if (adapter != null && adapter.RequiresFormTag)
                {
                    return(true);
                }
            }
            else if (!(control is UserControl) &&
                     !(control is LiteralControl))
            {
                // UserControl simply acts as a container, so the checking
                // should be delegated to its children below.
                // LiteralControl is a plain text control.  Also, it is
                // generated for the spaces in between mobile control tags so
                // we don't want to consider it as a form required control.
                // For other cases, we should generate form tag as we don't
                // know the content that will be generated.
                return(true);
            }

            // No problem with the current control so far, now recursively
            // check its children.
            if (control.HasControls())
            {
                foreach (Control child in control.Controls)
                {
                    if (IsFormTagNeeded(child))
                    {
                        // This is to get out of recursive loop without
                        // further checking on other controls.
                        return(true);
                    }
                }
            }

            return(false);
        }
        // Renders hidden variables for IPostBackDataHandlers which are
        // not displayed due to pagination or secondary UI.
        internal void RenderOffPageVariables(HtmlMobileTextWriter writer, Control ctl, int page)
        {
            if (ctl.HasControls())
            {
                foreach (Control child in ctl.Controls)
                {
                    // Note: Control.Form != null.
                    if (!child.Visible || child == Control.Form.Header || child == Control.Form.Footer)
                    {
                        continue;
                    }

                    MobileControl mobileCtl = child as MobileControl;

                    if (mobileCtl != null)
                    {
                        if (mobileCtl.IsVisibleOnPage(page) &&
                            (mobileCtl == ((HtmlFormAdapter)mobileCtl.Form.Adapter).SecondaryUIControl ||
                             null == ((HtmlFormAdapter)mobileCtl.Form.Adapter).SecondaryUIControl))
                        {
                            if (mobileCtl.FirstPage == mobileCtl.LastPage)
                            {
                                // Entire control is visible on this page, so no need to look
                                // into children.
                                continue;
                            }

                            // Control takes up more than one page, so it may be possible that
                            // its children are on a different page, so we'll continue to
                            // fall through into children.
                        }
                        else if (mobileCtl is IPostBackDataHandler)
                        {
                            HtmlControlAdapter adapter = mobileCtl.Adapter as HtmlControlAdapter;
                            if (adapter != null)
                            {
                                adapter.RenderAsHiddenInputField(writer);
                            }
                        }
                    }

                    RenderOffPageVariables(writer, child, page);
                }
            }
        }
Exemplo n.º 3
0
        public override void Render(HtmlMobileTextWriter writer)
        {
            System.Web.UI.WebControls.WebControl webCalendar = Control.WebCalendar;

            Style.ApplyTo(webCalendar);

            // Delegate the rendering effort to the child Web Calendar
            // control for HTML browser
            webCalendar.Visible = true;

            // There is no explicit property for alignment on WebForms
            // Calendar, so we need some special code to set it.
            writer.EnterLayout(Style);
            writer.EnsureStyle();
            Alignment align = (Alignment)Style[Style.AlignmentKey, true];

            if (!Device.SupportsDivAlign)
            {
                webCalendar.Attributes["align"] = align.ToString();
            }

            if (Device.SupportsCss)
            {
                // Target device supports CSS - simply delegate the rendering
                // to the underlying Web Calendar control
                webCalendar.RenderControl(writer);
            }
            else
            {
                // Insert bgcolor attributes in cells that correspond to selected dates
                StringWriter   sw        = new StringWriter();
                HtmlTextWriter tmpWriter = new HtmlTextWriter(sw);
                webCalendar.RenderControl(tmpWriter);
                String webCalendarHtml = sw.ToString();
                int    index = 0, indexLastTable = 0;
                // Search for offset of last <table> tag in the Web Calendar HTML.
                // That table contains the various days.
                do
                {
                    index = webCalendarHtml.IndexOf(_selectedDateSearchTableTag, index);
                    if (index >= 0)
                    {
                        indexLastTable = index;
                        index         += 5;
                    }
                }while (index >= 0);
                index = LocateNextSelectedDate(webCalendarHtml, indexLastTable);
                if (index >= 0)
                {
                    // Determine the background color of the containing Form control
                    HtmlControlAdapter formAdapter = (HtmlControlAdapter)Control.Form.Adapter;
                    Color backColor = (Color)formAdapter.Style[Style.BackColorKey, true];
                    int   deltaR    = System.Math.Abs(backColor.R - 0xC0);
                    int   deltaG    = System.Math.Abs(backColor.G - 0xC0);
                    int   deltaB    = System.Math.Abs(backColor.B - 0xC0);
                    // Determine the distance between Silver and the Form's background color
                    int bgColorDistance = deltaR * deltaR + deltaG * deltaG + deltaB * deltaB;
                    // Choose Silver or White depending on that distance
                    String selectedDateBGColor =
                        String.Format("bgcolor=\"{0}\" ", bgColorDistance < _bgColorDistanceTreshold ? "White" : "Silver");
                    while (index >= 0)
                    {
                        // Insert the bgcolor attribute for each selected date cell
                        webCalendarHtml = webCalendarHtml.Insert(index + _bgColorInsertionPointInPattern, selectedDateBGColor);
                        index           = LocateNextSelectedDate(webCalendarHtml, index + _bgColorInsertionPointInPattern);
                    }
                }
                // Use the HTML after insertions
                writer.Write(webCalendarHtml);
            }

            if (Control.BreakAfter)
            {
                writer.WriteBreak();
            }
            writer.ExitLayout(Style);
        }