Beispiel #1
0
        /// <summary>
        /// Hides tooltip if it is visible.
        /// </summary>
        public void HideTooltip()
        {
			m_HoverCount=0;
            DestroyActiveWindowTimer();
            DisposeHideDelayedTimer();
            if (m_Tooltip != null)
            {
                m_Tooltip.Hide();
                m_Tooltip.Dispose();
                m_Tooltip = null;
                OnTooltipClosed(new EventArgs());
            }
            m_MouseOverSuperTooltip = false;
        }
Beispiel #2
0
        /// <summary>
        /// Shows SuperTooltip for given object that has been registered using SetSuperTooltip method.
        /// </summary>
        /// <param name="sender">Object to show tooltip for. Object must be registered using SetSuperTooltip method before tooltip is shown for it.</param>
        private void ShowTooltip(object sender, Point screenPosition, bool useScreenPosition)
        {
            if (sender is Control && ((Control)sender).Focused && !m_ShowTooltipForFocusedControl)
                return;

            Rectangle controlRect = Rectangle.Empty;
            Rectangle actualControlRect = Rectangle.Empty;
            bool rightToLeft = false;

            // Check whether form that is hosting the control for super-tooltip is active and if not exit
            if (!IsFormActive(sender)) return;

            if (sender is Controls.ComboBoxEx)
            {
                BaseItem combo = GetComboBoxItemFromComboBoxEx(sender as Controls.ComboBoxEx);
                if (combo != null) sender = combo;
            }

            if (sender is BaseItem)
            {
                BaseItem item = sender as BaseItem;
                Control containerControl = GetContainerControl(item);
                if (item is PopupItem && ((PopupItem)item).Expanded && (containerControl is RibbonBar || containerControl is RibbonStrip))
                    return;
                Control itemControl = containerControl;
                if (itemControl != null)
                {
                    if (m_PositionBelowControl && !(itemControl is RibbonStrip && ((RibbonStrip)itemControl).QuickToolbarItems.Contains(item) || !(itemControl is RibbonBar)))
                        controlRect = new Rectangle(itemControl.PointToScreen(Point.Empty), itemControl.Size);
                    else
                        controlRect = new Rectangle(itemControl.PointToScreen(item.DisplayRectangle.Location), item.DisplayRectangle.Size);
                    actualControlRect = new Rectangle(itemControl.PointToScreen(item.DisplayRectangle.Location), item.DisplayRectangle.Size);
                    rightToLeft = containerControl.RightToLeft == RightToLeft.Yes;
                }
            }
            else if (sender is Control)
            {
                Control c = sender as Control;
                controlRect = new Rectangle(c.PointToScreen(Point.Empty), c.Size);
                actualControlRect = controlRect;
                rightToLeft = (c.RightToLeft == RightToLeft.Yes);
            }
            else if (sender is TabItem)
            {
                TabItem tab = sender as TabItem;
                TabStrip strip = tab.Parent;
                controlRect = new Rectangle(strip.PointToScreen(Point.Empty), strip.Size);
                actualControlRect = controlRect;
                rightToLeft = (strip.RightToLeft == RightToLeft.Yes);
            }
            else if (sender is ISuperTooltipInfoProvider)
            {
                ISuperTooltipInfoProvider ip = sender as ISuperTooltipInfoProvider;
                controlRect = ip.ComponentRectangle;
                actualControlRect = controlRect;
            }
            else if (sender is AdvTree.Node || IsTreeGXType(sender.GetType()))
            {
                controlRect = (Rectangle)TypeDescriptor.GetProperties(sender)["CellsBounds"].GetValue(sender);
                Control c = TypeDescriptor.GetProperties(sender)["TreeControl"].GetValue(sender) as Control;
                if (c != null)
                {
                    if (m_PositionBelowControl)
                        controlRect = new Rectangle(c.PointToScreen(Point.Empty), c.Size);
                    else
                        controlRect = new Rectangle(c.PointToScreen(controlRect.Location), controlRect.Size);
                    rightToLeft = (c.RightToLeft == RightToLeft.Yes);
                }
                actualControlRect = controlRect;
            }
#if (FRAMEWORK20)
            else if (sender is ToolStripButton)
            {
                ToolStripButton toolButton = sender as ToolStripButton;
                controlRect = toolButton.Bounds;
                actualControlRect = toolButton.Bounds;
            }
#endif

            if (controlRect.IsEmpty)
                return;

            SuperTooltipInfo info = GetSuperTooltipInfo(sender);
            if (info == null && sender is BaseItem)
            {
                // Try to find it by name...
                foreach (object o in m_SuperTooltipInfo.Keys)
                {
                    if (o is BaseItem && ((BaseItem)o).Name == ((BaseItem)sender).Name)
                    {
                        info = m_SuperTooltipInfo[o] as SuperTooltipInfo;
                        break;
                    }
                }
            }
            if (info == null)
                return;

            HideTooltip();

            Point p=new Point(Control.MousePosition.X,Control.MousePosition.Y+(int)(SystemInformation.CursorSize.Height * .6f));
            if (m_PositionBelowControl)
            {
                p.Y = Math.Max(controlRect.Bottom + 1, p.Y);
            }

            // Set the position explicitly
            if (useScreenPosition)
                p = screenPosition;

            m_Tooltip = new SuperTooltipControl();
            m_Tooltip.ShowTooltipDescription = m_ShowTooltipDescription;
            m_Tooltip.MaximumWidth = m_MaximumWidth;
            m_Tooltip.MouseActivateEnabled = false;
            m_Tooltip.MouseEnter += new EventHandler(SuperTooltip_MouseEnter);
            m_Tooltip.MouseLeave += new EventHandler(SuperTooltip_MouseLeave);
            m_Tooltip.MarkupLinkClick += new MarkupLinkClickEventHandler(Tooltip_MarkupLinkClick);
			if(m_DefaultFont!=null)
				m_Tooltip.Font=m_DefaultFont;
            if (rightToLeft)
                m_Tooltip.RightToLeft = RightToLeft.Yes;
            m_Tooltip.MinimumTooltipSize = m_MinimumTooltipSize;
			m_Tooltip.AntiAlias = m_AntiAlias;

            Size tooltipSize = Size.Empty;
            if (m_CheckTooltipPosition || m_CheckOnScreenPosition)
            {
                if (!info.CustomSize.IsEmpty && info.CustomSize.Width > 0 && info.CustomSize.Height > 0)
                    tooltipSize = info.CustomSize;
                else
                {
                    m_Tooltip.UpdateWithSuperTooltipInfo(info);
                    m_Tooltip.UpdateSuperTooltipSize(info); // RecalcSize();
                    tooltipSize = m_Tooltip.Size;
                }
            }

            if (m_CheckOnScreenPosition)
            {
                ScreenInformation screen = BarFunctions.ScreenFromPoint(p);
                if (screen != null)
                {
                    Rectangle r = new Rectangle(p, tooltipSize);
                    System.Drawing.Size layoutArea = screen.WorkingArea.Size;

                    if (r.Right > screen.WorkingArea.Right)
                    {
                        r.X = r.X - (r.Right - screen.WorkingArea.Right);
                        //if (r.IntersectsWith(controlRect))
                        //{
                        //    r.X = controlRect.X - r.Width;
                        //}
                    }
                    if (r.Bottom > screen.Bounds.Bottom)
                    {
                        r.Y = screen.Bounds.Bottom - r.Height;
                        //if (r.IntersectsWith(controlRect))
                        //{
                        //    r.Y = controlRect.Y - r.Height;
                        //}
                    }

                    p = r.Location;
                }
            }

            if (m_CheckTooltipPosition && !actualControlRect.IsEmpty)
            {
                Rectangle r = new Rectangle(p, tooltipSize);

                if (r.IntersectsWith(actualControlRect))
                {
                    if (actualControlRect.Y - r.Height >= 0)
                        r.Y = actualControlRect.Y - r.Height;
                    else if (actualControlRect.X - r.Width >= 0)
                        r.Width = actualControlRect.X - r.Width;

                    p = r.Location;
                }
            }
            
            if (BeforeTooltipDisplay != null)
            {
                SuperTooltipEventArgs eventArgs = new SuperTooltipEventArgs(sender, info, p);
                BeforeTooltipDisplay(this, eventArgs);
                if (eventArgs.Cancel)
                {
                    m_Tooltip.Dispose();
                    m_Tooltip = null;
                    return;
                }
                p = eventArgs.Location;
            }

            m_Tooltip.ShowTooltip(info, p.X, p.Y, false);
            m_DurationDisplayed = 0;
            CreateActiveWindowTimer();
        }