Exemple #1
0
        /// <summary>
        /// Launch this MenuLauncher's Menu.
        /// </summary>
        /// <param name="evt">The DomEvent that triggered the launch(usually a mouse click)</param>
        protected bool LaunchMenu(HtmlElement elmHadFocus, Action onDelayedLoadSucceeded)
        {
            // If the menu is already launched, don't launch it twice
            // This happens when the menu is launched using the enter
            // key or the space bar since the browser sends two events:
            // one for the keypress and one for the associated click
            // when enter or space is pressed on an anchor element.
            if (MenuLaunched)
            {
                return(false);
            }

            _elmHadFocus = elmHadFocus;

            // If there is no Menu, then we check if this menu polls to get initialized.
            // If so, we poll for the menu XML, otherwise we exit.
            if (Utility.IsTrue(Properties.PopulateDynamically))
            {
                PollForDynamicMenu(true, onDelayedLoadSucceeded);
            }

            // If there is no Menu to launch then we can't launch the Menu
            // This is not necessarily a bug.  There is an asynchronous callback
            // available to create menus that are populated dynamically.  This
            // is handled in PollForDynamicMenu() above.
            if (CUIUtility.IsNullOrUndefined(_menu))
            {
                return(false);
            }

            // If we got this far and the member delayed load variable is not null, this was a delayed
            // load that succeeded, so we need to run the callback and clear the variable
            if (!CUIUtility.IsNullOrUndefined(_onDelayLoadSucceeded))
            {
                _onDelayLoadSucceeded();
                _onDelayLoadSucceeded = null;
            }

            _menu.EnsureRefreshed();

            if (!_menu.HasItems())
            {
                return(false);
            }

            ControlComponent comp = DisplayedComponent;

            comp.EnsureChildren();
            comp.IgnoreDirtyingEvents = true;
            comp.AddChild(_menu);
            comp.IgnoreDirtyingEvents = false;

            _menu.PollIfRootPolledSinceLastPoll();
            _menu.InvalidatePositionAndSizeData();

#if !CUI_NORIBBON
            // Adding the menu may cause window resize events which then immediately close the menu.
            // To fix this, we remove the onresize handler on Window until the menu is done launching.
            bool     isInRibbon = Root is SPRibbon;
            SPRibbon ribbon     = null;
            bool     oldWindowResizedHandlerEnabled = false;
            if (isInRibbon)
            {
                ribbon = (SPRibbon)Root;
                oldWindowResizedHandlerEnabled     = ribbon.WindowResizedHandlerEnabled;
                ribbon.WindowResizedHandlerEnabled = false;
            }
#endif

            HtmlElement menuElement = _menu.ElementInternal;

            // Hide menu while positioning
            menuElement.Style.Visibility = "hidden";
            menuElement.Style.Position   = "absolute";
            menuElement.Style.Top        = "0px";
            menuElement.Style.Left       = "0px";

            // Place menu directly on top of modal div (z-index:1000)
            menuElement.Style.ZIndex = 1001;

            // Add menu to DOM
            Browser.Document.Body.AppendChild(menuElement);

            if (BrowserUtility.InternetExplorer7 && Root.TextDirection == Direction.RTL)
            {
                int menuWidth = menuElement.OffsetWidth;

                // The menu items have 12px of padding, 2px of borders, and 2px of margins,
                // and the menu itself has 2px of borders too, so we need to remove that first
                menuWidth = menuWidth >= 18 ? menuWidth - 18 : 0;
                string strMenuWidth = menuWidth + "px";

                List <Component> sections = _menu.Children;
                foreach (MenuSection section in sections)
                {
                    List <Component> items = section.Children;
                    foreach (Component c in items)
                    {
                        if (c is MenuItem)
                        {
                            c.ElementInternal.Style.Width = strMenuWidth;
                        }
                    }
                }
            }

            PositionMenu(menuElement, comp.ElementInternal);

            // For IE, we need a backframe IFrame in order for the menu to show up over
            // ActiveX controls
            if (BrowserUtility.InternetExplorer)
            {
                AddAndPositionBackFrame();
            }

            // Show menu once it is positioned
            Root.BeginModal(this, _elmHadFocus);
            Root.AddMenuLauncherToStack(this);
            menuElement.Style.Visibility = "visible";

            _menuLaunched  = true;
            _menu.Launched = true;

            FocusOnAppropriateMenuItem(null);

#if !CUI_NORIBBON
            if (isInRibbon)
            {
                ribbon.WindowResizedHandlerEnabled = oldWindowResizedHandlerEnabled;
            }
#endif

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Launch this Control's ToolTip.
        /// </summary>
        /// <owner alias="HillaryM" />
        protected void LaunchToolTip()
        {
            if (CUIUtility.IsNullOrUndefined(Root))
            {
                return;
            }

            // clear the tooltip launching timer
            Browser.Window.ClearInterval(Root.TooltipLauncherTimer);

            // If the tooltip is already launched, don't launch it twice
            if (_toolTipLaunched)
            {
                return;
            }

            // if there is currently an open tooltip and it was not launched by this control, close it
            if ((!CUIUtility.IsNullOrUndefined(Root.TooltipLauncher)) &&
                (Root.TooltipLauncher.Id != this.Id))
            {
                Root.CloseOpenTootips();
            }

            // If there is no ToolTip title, we don't launch the ToolTip
            if (string.IsNullOrEmpty(_properties.ToolTipTitle))
            {
                return;
            }

            _toolTip = new ToolTip(Root, Id + "_ToolTip", _properties.ToolTipTitle, _properties.ToolTipDescription, _properties);

            if (!Enabled)
            {
                // Show message indicating that the control is disabled and give reason.
                DisabledCommandInfoProperties disabledInfo = new DisabledCommandInfoProperties();
                disabledInfo.Icon            = Root.Properties.ToolTipDisabledCommandImage16by16;
                disabledInfo.IconClass       = Root.Properties.ToolTipDisabledCommandImage16by16Class;
                disabledInfo.IconTop         = Root.Properties.ToolTipDisabledCommandImage16by16Top;
                disabledInfo.IconLeft        = Root.Properties.ToolTipDisabledCommandImage16by16Left;
                disabledInfo.Title           = Root.Properties.ToolTipDisabledCommandTitle;
                disabledInfo.Description     = Root.Properties.ToolTipDisabledCommandDescription;
                disabledInfo.HelpKeyWord     = Root.Properties.ToolTipDisabledCommandHelpKey;
                _toolTip.DisabledCommandInfo = disabledInfo;
            }

            ControlComponent comp = DisplayedComponent;

            if (!CUIUtility.IsNullOrUndefined(comp))
            {
                comp.EnsureChildren();
                comp.AddChild(_toolTip);
                _toolTip.Display();
                _toolTipLaunched     = true;
                Root.TooltipLauncher = this;
                OnToolTipOpenned();
            }
            else
            {
                _toolTip = null;
            }
        }