Пример #1
0
        protected override HtmlElement CreateDOMElementForDisplayMode(string displayMode)
        {
            switch (displayMode)
            {
            case "Large":
            case "Menu":
                string alt = CUIUtility.SafeString(Properties.Alt);
                // Create elements
                _elmDefault = new Span();
                _elmDefault.SetAttribute("mscui:controltype", ControlType);
                _elmDefault.ClassName = "ms-cui-gallerybutton ms-cui-gallerybutton-" + Utility.GalleryElementDimensionsToSizeString[(int)ElementDimensions];

                _elmDefaultA           = new Anchor();
                _elmDefaultA.Title     = alt;
                _elmDefaultA.ClassName = "ms-cui-gallerybutton-a";
                Utility.NoOpLink(_elmDefaultA);
                Utility.SetAriaTooltipProperties(Properties, _elmDefaultA);
                _elmDefault.AppendChild(_elmDefaultA);

                if (!string.IsNullOrEmpty(Properties.InnerHTML))
                {
                    _elmDefaultA.InnerHtml = Properties.InnerHTML;
                    Utility.SetUnselectable(_elmDefaultA, true, true);
                }
                else
                {
                    if (string.IsNullOrEmpty(Properties.Image))
                    {
                        throw new ArgumentNullException("InnerHTML or Image must be defined for this GalleryButton");
                    }

                    ImgContainerSize size = ImgContainerSize.Size32by32;
                    switch (ElementDimensions)
                    {
                    case GalleryElementDimensions.Size16by16:
                        size = ImgContainerSize.Size16by16;
                        break;

                    case GalleryElementDimensions.Size32by32:
                        size = ImgContainerSize.Size32by32;
                        break;

                    case GalleryElementDimensions.Size48by48:
                        size = ImgContainerSize.Size48by48;
                        break;

                    case GalleryElementDimensions.Size64by48:
                        size = ImgContainerSize.Size64by48;
                        break;

                    case GalleryElementDimensions.Size72by96:
                        size = ImgContainerSize.Size72by96;
                        break;

                    case GalleryElementDimensions.Size96by72:
                        size = ImgContainerSize.Size96by72;
                        break;

                    case GalleryElementDimensions.Size96by96:
                        size = ImgContainerSize.Size96by96;
                        break;
                    }

                    _elmDefaultImage     = new Image();
                    _elmDefaultImageCont = Utility.CreateClusteredImageContainerNew(
                        size,
                        Properties.Image,
                        Properties.ImageClass,
                        _elmDefaultImage,
                        true,
                        false,
                        Properties.ImageTop,
                        Properties.ImageLeft);
                    _elmDefaultImage.Alt = alt;
                    _elmDefaultA.AppendChild(_elmDefaultImageCont);
                }

                // Setup event handlers
                AttachEventsForDisplayMode(displayMode);

                return(_elmDefault);

            default:
                EnsureValidDisplayMode(displayMode);
                return(null);
            }
        }
Пример #2
0
        static protected Anchor CreateStandardControlDOMElementCore(
            Control control,
            Root root,
            string displayMode,
            string id,
            string image32by32,
            string image32by32Class,
            string image32by32Top,
            string image32by32Left,
            string image16by16,
            string image16by16Class,
            string image16by16Top,
            string image16by16Left,
            string labelText,
            string labelCss,
            string alt,
            string description,
            string tooltipTitle,
            bool menu,
            bool arrow)
        {
            // O14:503464 - Missing label text should be empty instead of "undefined"
            if (string.IsNullOrEmpty(labelText))
            {
                labelText = "";
            }

            bool   isMenu           = false;
            bool   needsHiddenLabel = true;
            Anchor elm = Utility.CreateNoOpLink();

            string outerStyle = null;

            if (displayMode == "Large")
            {
                outerStyle = "ms-cui-ctl-large";
            }
            else if (displayMode == "Medium")
            {
                outerStyle = "ms-cui-ctl-medium";
            }
            else if (displayMode == "Menu16" || displayMode == "Menu")
            {
                outerStyle = "ms-cui-ctl-menu";
                isMenu     = true;
            }
            else if (displayMode == "Menu32")
            {
                outerStyle = "ms-cui-ctl-menu ms-cui-ctl-menu32";
                isMenu     = true;
            }
            else
            {
                outerStyle = "ms-cui-ctl";
            }

            Utility.EnsureCSSClassOnElement(elm, outerStyle);

            if (displayMode == "Menu")
            {
                Utility.EnsureCSSClassOnElement(elm, "ms-cui-textmenuitem");
            }

            if (!string.IsNullOrEmpty(tooltipTitle))
            {
                elm.SetAttribute("aria-describedby", id + "_ToolTip");
            }

            elm.SetAttribute("mscui:controltype", control.ControlType);

            // Create the image
            Image elmImage = new Image();

            string           imageUrl   = null;
            string           imageClass = null;
            string           imageTop   = null;
            string           imageLeft  = null;
            ImgContainerSize imgSize    = ImgContainerSize.None;

            elmImage.Alt = "";
            alt          = string.IsNullOrEmpty(alt) ? labelText : alt;
            elm.SetAttribute("role", control.AriaRole);
            if (control is FlyoutAnchor)
            {
                elm.SetAttribute("aria-haspopup", "true");
            }

            if (string.IsNullOrEmpty(tooltipTitle))
            {
                elm.Title        = alt;
                elmImage.Alt     = alt;
                needsHiddenLabel = false;
            }

            if (displayMode == "Large" || displayMode == "Menu32")
            {
                imageUrl   = image32by32;
                imageClass = image32by32Class;
                imageTop   = image32by32Top;
                imageLeft  = image32by32Left;
                imgSize    = ImgContainerSize.Size32by32;
            }
            else
            {
                imageUrl   = image16by16;
                imageClass = image16by16Class;
                imageTop   = image16by16Top;
                imageLeft  = image16by16Left;
                imgSize    = ImgContainerSize.Size16by16;
            }

            Span elmImageCont = Utility.CreateClusteredImageContainerNew(
                imgSize,
                imageUrl,
                imageClass,
                elmImage,
                true,
                false,
                imageTop,
                imageLeft);
            Span elmIconContainer = new Span();

            elmIconContainer.ClassName = displayMode == "Large" ? "ms-cui-ctl-largeIconContainer" : "ms-cui-ctl-iconContainer";
            elmIconContainer.AppendChild(elmImageCont);

            // Create the label
            // The small display mode of controls does not have label text
            // However, controls with arrows like FlyoutAnchor still need
            // this element.
            SPLabel     hiddenLabel = null;
            HtmlElement elmLabel    = null;

            if (needsHiddenLabel)
            {
                hiddenLabel = Utility.CreateHiddenLabel(alt);
            }
            if (displayMode != "Small" || arrow)
            {
                elmLabel = new Span();
                if (displayMode != "Small")
                {
                    if (displayMode == "Large")
                    {
                        Utility.EnsureCSSClassOnElement(elmLabel, "ms-cui-ctl-largelabel");
                        elmLabel.InnerHtml = Utility.FixLargeControlText(labelText, arrow);
                    }
                    else
                    {
                        string text = labelText;
                        if (arrow)
                        {
                            text = text + " ";
                        }

                        Utility.EnsureCSSClassOnElement(elmLabel, "ms-cui-ctl-mediumlabel");
                        UIUtility.SetInnerText(elmLabel, text);
                    }
                    if (!string.IsNullOrEmpty(labelCss))
                    {
                        elmLabel.Style.CssText = labelCss;
                    }
                }
                else
                {
                    // If the displaymode is Small and there is an arrow
                    Utility.EnsureCSSClassOnElement(elmLabel, "ms-cui-ctl-smalllabel");
                    UIUtility.SetInnerText(elmLabel, " ");
                }
            }
            else if (needsHiddenLabel)
            {
                elmLabel = Utility.CreateHiddenLabel(alt);
            }

            // Create the arrow image if one was specified
            Span elmArrowCont = null;

            if (arrow)
            {
                Image elmArrowImage = new Image();
                elmArrowImage.Alt = "";
                if (string.IsNullOrEmpty(tooltipTitle))
                {
                    elmArrowImage.Alt = alt;
                }
                elmArrowCont = Utility.CreateClusteredImageContainerNew(
                    ImgContainerSize.Size5by3,
                    root.Properties.ImageDownArrow,
                    root.Properties.ImageDownArrowClass,
                    elmArrowImage,
                    true,
                    false,
                    root.Properties.ImageDownArrowTop,
                    root.Properties.ImageDownArrowLeft);
            }

            // This is used for Menu32.  It can have a description under the label text.
            Span elmTextContainer   = null;
            Span elmDescriptionText = null;
            Span elmMenu32Clear     = null;

            if (displayMode == "Menu32")
            {
                elmTextContainer           = new Span();
                elmTextContainer.ClassName = "ms-cui-ctl-menulabel";
                Utility.EnsureCSSClassOnElement(elmLabel, "ms-cui-btn-title");
                elmTextContainer.AppendChild(elmLabel);
                if (!string.IsNullOrEmpty(description))
                {
                    elmDescriptionText = new Span();
                    Utility.EnsureCSSClassOnElement(elmDescriptionText, "ms-cui-btn-menu-description");
                    UIUtility.SetInnerText(elmDescriptionText, description);
                    elmDescriptionText.Style.Display = "block";
                    elmTextContainer.AppendChild(elmDescriptionText);
                }
                elmMenu32Clear           = new Span();
                elmMenu32Clear.ClassName = "ms-cui-ctl-menu32clear";
                elmMenu32Clear.InnerHtml = " ";
            }

            elm.AppendChild(elmIconContainer);

            if (!CUIUtility.IsNullOrUndefined(elmLabel))
            {
                if (!CUIUtility.IsNullOrUndefined(elmTextContainer))
                {
                    elm.AppendChild(elmTextContainer);
                    elm.AppendChild(elmMenu32Clear);
                }
                else
                {
                    elm.AppendChild(elmLabel);
                    if (displayMode == "Small" && arrow && needsHiddenLabel) // if no alt is present add a hidden label for MSAA
                    {
                        elm.AppendChild(hiddenLabel);
                    }
                }
                if (!CUIUtility.IsNullOrUndefined(elmArrowCont))
                {
                    elmLabel.AppendChild(elmArrowCont);
                }
            }

            if (isMenu)
            {
                Span elmMenuGlass = Utility.CreateGlassElement();
                elm.AppendChild(elmMenuGlass);
            }

            return(elm);
        }
Пример #3
0
        internal static Span CreateClusteredImageContainerNew(ImgContainerSize size,
                                                                     string imageSource,
                                                                     string imageClass,
                                                                     Image elmImage,
                                                                     bool inlineBlockDisplay,
                                                                     bool blockDisplay,
                                                                     string imageTop,
                                                                     string imageLeft)
        {
            Span cont = new Span();
            if (blockDisplay)
                Utility.EnsureCSSClassOnElement(cont, "ms-cui-block");

            string cssClass = ImageSizeToClass[(int)size];

            // Cluster mode detection
            bool hasTop = !string.IsNullOrEmpty(imageTop);
            bool hasLeft = !string.IsNullOrEmpty(imageLeft);
            bool hasClass = !string.IsNullOrEmpty(imageClass);

            // These classes are needed for unclustered ribbon icon disabling.
            if (inlineBlockDisplay)
                cssClass += " ms-cui-img-cont-float";
            else
                cssClass += " ms-cui-img-container";

            // Revisit this.  Right now we dont' append here to help on performance
            if (hasClass)
                elmImage.ClassName = imageClass;

            cont.ClassName += " " + cssClass;
            if (!string.IsNullOrEmpty(imageSource))
            {
                cont.AppendChild(elmImage);
                elmImage.Src = imageSource;
                if (hasTop)
                    elmImage.Style.Top = imageTop + "px";
                if (hasLeft)
                    elmImage.Style.Left = imageLeft + "px";
            }
            return cont;
        }
Пример #4
0
        static protected Span CreateTwoAnchorControlDOMElementCore(
            Control control,
            Root root,
            string displayMode,
            string id,
            string image32by32,
            string image32by32Class,
            string image32by32Top,
            string image32by32Left,
            string image16by16,
            string image16by16Class,
            string image16by16Top,
            string image16by16Left,
            string labelText,
            string alt,
            string tooltipTitle,
            bool arrow)
        {
            bool needsHiddenLabel = true;

            labelText = CUIUtility.SafeString(labelText);

            // Create the outer <span> element for this two anchor control
            Span elm = new Span();

            if (displayMode == "Large")
            {
                elm.ClassName = "ms-cui-ctl-large";
            }
            else if (displayMode == "Medium")
            {
                elm.ClassName = "ms-cui-ctl ms-cui-ctl-medium";
            }
            else
            {
                elm.ClassName = "ms-cui-ctl ms-cui-ctl-small";
            }

            if (!string.IsNullOrEmpty(tooltipTitle))
            {
                elm.SetAttribute("aria-describedby", id + "_ToolTip");
            }

            elm.SetAttribute("mscui:controltype", control.ControlType);

            Anchor elmA1 = Utility.CreateNoOpLink();
            Anchor elmA2 = Utility.CreateNoOpLink();

            elmA1.ClassName = "ms-cui-ctl-a1";
            elmA2.ClassName = "ms-cui-ctl-a2";
            alt             = string.IsNullOrEmpty(alt) ? labelText : alt;

            // Setting aria properties for screen readers
            elmA1.SetAttribute("role", control.AriaRole);
            elmA2.SetAttribute("role", control.AriaRole);
            elmA2.SetAttribute("aria-haspopup", "true");

            Span elmA1Internal = new Span();

            elmA1Internal.ClassName = "ms-cui-ctl-a1Internal";

            // Create the image
            Image            elmImage   = new Image();
            string           imageUrl   = null;
            string           imageClass = null;
            string           imageTop   = null;
            string           imageLeft  = null;
            ImgContainerSize imgSize    = ImgContainerSize.None;

            elmImage.Alt = "";

            // Display alt only if no supertooltip is present
            if (string.IsNullOrEmpty(tooltipTitle))
            {
                elmA1.Title      = alt;
                elmA2.Title      = alt;
                elmImage.Alt     = alt;
                needsHiddenLabel = false;
            }

            if (displayMode == "Large" || displayMode == "Menu32")
            {
                imageUrl   = image32by32;
                imageClass = image32by32Class;
                imageTop   = image32by32Top;
                imageLeft  = image32by32Left;
                imgSize    = ImgContainerSize.Size32by32;
            }
            else
            {
                imageUrl   = image16by16;
                imageClass = image16by16Class;
                imageTop   = image16by16Top;
                imageLeft  = image16by16Left;
                imgSize    = ImgContainerSize.Size16by16;
            }

            Span elmImageCont = Utility.CreateClusteredImageContainerNew(
                imgSize,
                imageUrl,
                imageClass,
                elmImage,
                true,
                false,
                imageTop,
                imageLeft);

            // Controls lacking a label and with supertooltips need hidden labels
            SPLabel elmHiddenBtnLabel   = null;
            SPLabel elmHiddenArrowLabel = null;

            if (needsHiddenLabel)
            {
                elmHiddenBtnLabel   = Utility.CreateHiddenLabel(alt);
                elmHiddenArrowLabel = Utility.CreateHiddenLabel(alt);
            }

            // Create the label
            // The small display mode of controls does not have label text
            // However, controls with arrows like FlyoutAnchor still need
            // this element.
            Span elmLabel = null;

            if (displayMode != "Small" || arrow)
            {
                elmLabel = new Span();
                if (displayMode != "Small")
                {
                    if (displayMode == "Large")
                    {
                        Utility.EnsureCSSClassOnElement(elmLabel, "ms-cui-ctl-largelabel");
                        elmLabel.InnerHtml = Utility.FixLargeControlText(labelText, arrow);
                    }
                    else if (displayMode == "Medium")
                    {
                        Utility.EnsureCSSClassOnElement(elmLabel, "ms-cui-ctl-mediumlabel");
                        UIUtility.SetInnerText(elmLabel, labelText);
                    }
                }
            }

            Span elmArrowCont = null;

            if (arrow)
            {
                Image elmArrowImage = new Image();
                if (string.IsNullOrEmpty(tooltipTitle))
                {
                    elmArrowImage.Alt = alt;
                }
                elmArrowCont = Utility.CreateClusteredImageContainerNew(
                    ImgContainerSize.Size5by3,
                    root.Properties.ImageDownArrow,
                    root.Properties.ImageDownArrowClass,
                    elmArrowImage,
                    true,
                    false,
                    root.Properties.ImageDownArrowTop,
                    root.Properties.ImageDownArrowLeft);
            }

            elm.AppendChild(elmA1);
            elm.AppendChild(elmA2);
            elmA1.AppendChild(elmA1Internal);
            elmA1Internal.AppendChild(elmImageCont);

            if (!CUIUtility.IsNullOrUndefined(elmLabel))
            {
                if (displayMode == "Large")
                {
                    elmA2.AppendChild(elmLabel);
                    if (needsHiddenLabel)
                    {
                        elmA1.AppendChild(elmHiddenBtnLabel);
                    }
                }
                else
                {
                    elmA1Internal.AppendChild(elmLabel);
                    if (needsHiddenLabel)
                    {
                        elmA2.AppendChild(elmHiddenArrowLabel);
                    }
                }

                if (displayMode == "Small" && needsHiddenLabel)
                {
                    elmA1.AppendChild(elmHiddenBtnLabel);
                }
            }
            if (!CUIUtility.IsNullOrUndefined(elmArrowCont))
            {
                if (displayMode == "Large")
                {
                    elmLabel.AppendChild(elmArrowCont);
                }
                else
                {
                    elmA2.AppendChild(elmArrowCont);
                }
            }

            return(elm);
        }