/*
		 * EditValue
		 */

		/// <summary>
		/// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"></see> method.
		/// </summary>
		/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that can be used to gain additional context information.</param>
		/// <param name="provider">An <see cref="T:System.IServiceProvider"></see> that this editor can use to obtain services.</param>
		/// <param name="value">The object to edit.</param>
		/// <returns>
		/// The new value of the object. If the value of the object has not changed, this should return the same object it was passed.
		/// </returns>
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			if (context != null && context.Instance != null && provider != null)
			{
				IWindowsFormsEditorService editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
				NuGenToolTipInfo tooltipInfo = value as NuGenToolTipInfo;

				if (tooltipInfo == null)
				{
					tooltipInfo = new NuGenToolTipInfo();
				}

				if (editorService != null)
				{
					using (NuGenToolTipInfoEditorUI editorUI = new NuGenToolTipInfoEditorUI(
						this.ServiceProvider,
						tooltipInfo,
						new NuGenCustomTypeEditorServiceContext(context.Container, provider))
						)
					{
						if (editorService.ShowDialog(editorUI) == DialogResult.OK)
						{
							tooltipInfo = editorUI.GetTooltipInfoFromState();
						}
					}
					
					return tooltipInfo;
				}
			}

			return value;
		}
Exemplo n.º 2
0
        /*
         * EditValue
         */

        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"></see> method.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that can be used to gain additional context information.</param>
        /// <param name="provider">An <see cref="T:System.IServiceProvider"></see> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>
        /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed.
        /// </returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
                NuGenToolTipInfo           tooltipInfo   = value as NuGenToolTipInfo;

                if (tooltipInfo == null)
                {
                    tooltipInfo = new NuGenToolTipInfo();
                }

                if (editorService != null)
                {
                    using (NuGenToolTipInfoEditorUI editorUI = new NuGenToolTipInfoEditorUI(
                               this.ServiceProvider,
                               tooltipInfo,
                               new NuGenCustomTypeEditorServiceContext(context.Container, provider))
                           )
                    {
                        if (editorService.ShowDialog(editorUI) == DialogResult.OK)
                        {
                            tooltipInfo = editorUI.GetTooltipInfoFromState();
                        }
                    }

                    return(tooltipInfo);
                }
            }

            return(value);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NuGenToolTipInfoEditorUI"/> class.
        /// </summary>
        /// <param name="serviceContext"></param>
        /// <param name="serviceProvider">
        /// <para>Requires:</para>
        /// <para><see cref="INuGenToolTipLayoutManager"/></para>
        /// <para><see cref="INuGenToolTipRenderer"/></para>
        /// </param>
        /// <param name="initialTooltipInfo"></param>
        /// <exception cref="ArgumentNullException">
        /// <para>
        ///		<paramref name="serviceProvider"/> is <see langword="null"/>.
        /// </para>
        /// -or-
        /// <para>
        ///		<paramref name="serviceContext"/> is <see langword="null"/>.
        /// </para>
        /// </exception>
        public NuGenToolTipInfoEditorUI(
            INuGenServiceProvider serviceProvider,
            NuGenToolTipInfo initialTooltipInfo,
            NuGenCustomTypeEditorServiceContext serviceContext
            )
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            _serviceProvider = serviceProvider;

            this.SuspendLayout();

            _mainBlock        = new MainBlock(serviceContext);
            _mainBlock.Parent = this;

            _remarksBlock        = new RemarksBlock(serviceContext);
            _remarksBlock.Height = 100;
            _remarksBlock.Parent = this;

            _okButton = new Button();
            _okButton.DialogResult = DialogResult.OK;
            _okButton.TabIndex     = 0;
            _okButton.Text         = Resources.Text_ToolTipInfoEditor_okButton;

            _cancelButton = new Button();
            _cancelButton.DialogResult = DialogResult.Cancel;
            _cancelButton.TabIndex     = 1;
            _cancelButton.Text         = Resources.Text_ToolTipInfoEditor_cancelButton;

            _sizeBlock        = new SizeBlock();
            _sizeBlock.Parent = this;

            _dialogLayoutPanel = new DialogFlowLayoutPanel();
            _dialogLayoutPanel.Controls.Add(_cancelButton);
            _dialogLayoutPanel.Controls.Add(_okButton);
            _dialogLayoutPanel.Parent = this;

            this.CancelButton    = _cancelButton;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox     = false;
            this.MinimizeBox     = false;
            this.Padding         = new Padding(3);
            this.ShowIcon        = false;
            this.ShowInTaskbar   = false;
            this.Size            = new Size(350, 400);
            this.StartPosition   = FormStartPosition.CenterParent;
            this.Text            = Resources.Text_ToolTipInfoEditor_EditorForm;

            this.SetStateFromTooltipInfo(initialTooltipInfo);
            this.ResumeLayout(false);
        }
Exemplo n.º 4
0
        private static Padding GetTextPadding(NuGenToolTipInfo tooltipInfo)
        {
            Debug.Assert(tooltipInfo != null, "tooltipInfo != null");

            if (!tooltipInfo.IsHeaderVisible && !tooltipInfo.IsRemarksHeaderVisible)
            {
                return(new Padding(1));
            }

            return(new Padding(14, 6, 4, 4));
        }
        public void GetConstructorInfoTest()
        {
            _tooltipInfo = new NuGenToolTipInfo();
            object[]   values;
            MemberInfo ctorInfo = this.GetConstructorInfo(out values);

            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(0, values.Length);

            _tooltipInfo.Header = _sampleStr;
            this.GetConstructorInfo(out values);
            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(3, values.Length);

            _tooltipInfo.Remarks = _sampleStr;
            this.GetConstructorInfo(out values);
            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(7, values.Length);

            _tooltipInfo       = new NuGenToolTipInfo();
            _tooltipInfo.Image = _sampleImg;
            this.GetConstructorInfo(out values);
            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(3, values.Length);

            _tooltipInfo = new NuGenToolTipInfo();
            _tooltipInfo.RemarksImage = _sampleImg;
            this.GetConstructorInfo(out values);
            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(7, values.Length);

            _tooltipInfo      = new NuGenToolTipInfo();
            _tooltipInfo.Text = _sampleStr;
            this.GetConstructorInfo(out values);
            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(3, values.Length);

            _tooltipInfo.RemarksHeader = _sampleStr;
            this.GetConstructorInfo(out values);
            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(7, values.Length);

            _tooltipInfo            = new NuGenToolTipInfo();
            _tooltipInfo.CustomSize = Size.Empty;
            this.GetConstructorInfo(out values);
            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(0, values.Length);
            _tooltipInfo.CustomSize = new Size(1, 1);
            this.GetConstructorInfo(out values);
            Assert.IsNotNull(ctorInfo);
            Assert.AreEqual(7, values.Length);
        }
		public void SetStateFromTooltipInfo(NuGenToolTipInfo tooltipInfo)
		{
			if (tooltipInfo != null)
			{
				_mainBlock.Header = tooltipInfo.Header;
				_mainBlock.Image = tooltipInfo.Image;
				_mainBlock.Text = tooltipInfo.Text;

				_remarksBlock.RemarksHeader = tooltipInfo.RemarksHeader;
				_remarksBlock.RemarksImage = tooltipInfo.RemarksImage;
				_remarksBlock.Remarks = tooltipInfo.Remarks;

				_sizeBlock.CustomSize = tooltipInfo.CustomSize;
			}
		}
        public void SetStateFromTooltipInfo(NuGenToolTipInfo tooltipInfo)
        {
            if (tooltipInfo != null)
            {
                _mainBlock.Header = tooltipInfo.Header;
                _mainBlock.Image  = tooltipInfo.Image;
                _mainBlock.Text   = tooltipInfo.Text;

                _remarksBlock.RemarksHeader = tooltipInfo.RemarksHeader;
                _remarksBlock.RemarksImage  = tooltipInfo.RemarksImage;
                _remarksBlock.Remarks       = tooltipInfo.Remarks;

                _sizeBlock.CustomSize = tooltipInfo.CustomSize;
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="NuGenToolTipInfoEditorUI"/> class.
		/// </summary>
		/// <param name="serviceContext"></param>
		/// <param name="serviceProvider">
		/// <para>Requires:</para>
		/// <para><see cref="INuGenToolTipLayoutManager"/></para>
		/// <para><see cref="INuGenToolTipRenderer"/></para>
		/// </param>
		/// <param name="initialTooltipInfo"></param>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="serviceProvider"/> is <see langword="null"/>.
		/// </para>
		/// -or-
		/// <para>
		///		<paramref name="serviceContext"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public NuGenToolTipInfoEditorUI(
			INuGenServiceProvider serviceProvider,
			NuGenToolTipInfo initialTooltipInfo,
			NuGenCustomTypeEditorServiceContext serviceContext
			)
		{
			if (serviceProvider == null)
			{
				throw new ArgumentNullException("serviceProvider");
			}

			if (serviceContext == null)
			{
				throw new ArgumentNullException("serviceContext");
			}

			_serviceProvider = serviceProvider;

			this.SuspendLayout();

			_mainBlock = new MainBlock(serviceContext);
			_mainBlock.Parent = this;

			_remarksBlock = new RemarksBlock(serviceContext);
			_remarksBlock.Height = 100;
			_remarksBlock.Parent = this;

			_okButton = new Button();
			_okButton.DialogResult = DialogResult.OK;
			_okButton.TabIndex = 0;
			_okButton.Text = Resources.Text_ToolTipInfoEditor_okButton;

			_cancelButton = new Button();
			_cancelButton.DialogResult = DialogResult.Cancel;
			_cancelButton.TabIndex = 1;
			_cancelButton.Text = Resources.Text_ToolTipInfoEditor_cancelButton;

			_sizeBlock = new SizeBlock();
			_sizeBlock.Parent = this;

			_dialogLayoutPanel = new DialogFlowLayoutPanel();
			_dialogLayoutPanel.Controls.Add(_cancelButton);
			_dialogLayoutPanel.Controls.Add(_okButton);
			_dialogLayoutPanel.Parent = this;

			this.CancelButton = _cancelButton;
			this.FormBorderStyle = FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Padding = new Padding(3);
			this.ShowIcon = false;
			this.ShowInTaskbar = false;
			this.Size = new Size(350, 400);
			this.StartPosition = FormStartPosition.CenterParent;
			this.Text = Resources.Text_ToolTipInfoEditor_EditorForm;
			
			this.SetStateFromTooltipInfo(initialTooltipInfo);
			this.ResumeLayout(false);
		}
		public void SetUp()
		{
			_tooltipInfo = new NuGenToolTipInfo();
		}
		private static Padding GetTextPadding(NuGenToolTipInfo tooltipInfo)
		{
			Debug.Assert(tooltipInfo != null, "tooltipInfo != null");

			if (!tooltipInfo.IsHeaderVisible && !tooltipInfo.IsRemarksHeaderVisible)
			{
				return new Padding(1);
			}

			return new Padding(14, 6, 4, 4);
		}
		/// <summary>
		/// </summary>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="g"/> is <see langword="null"/>.</para>
		/// -or-
		/// <para><paramref name="tooltipInfo"/> is <see langword="null"/>.</para>
		/// -or-
		/// <para><paramref name="headerFont"/> is <see langword="null"/>.</para>
		/// -or-
		/// <para><paramref name="textFont"/> is <see langword="null"/>.</para>
		/// </exception>
		public NuGenToolTipLayoutDescriptor BuildLayoutDescriptor(
			Graphics g,
			NuGenToolTipInfo tooltipInfo,
			Font headerFont,
			Font textFont
			)
		{
			if (g == null)
			{
				throw new ArgumentNullException("g");
			}

			if (tooltipInfo == null)
			{
				throw new ArgumentNullException("tooltipInfo");
			}

			if (headerFont == null)
			{
				throw new ArgumentNullException("headerFont");
			}

			if (textFont == null)
			{
				throw new ArgumentNullException("textFont");
			}

			NuGenToolTipLayoutDescriptor descriptor = new NuGenToolTipLayoutDescriptor();

			Size tooltipSize = tooltipInfo.IsCustomSize
				? tooltipInfo.CustomSize
				: this.GetAutoSize(g, tooltipInfo, headerFont, textFont)
				;

			Rectangle rect = new Rectangle(new Point(0, 0), tooltipSize);

			Padding headerPadding = _headerPadding;
			Padding remarksHeaderPadding = _remarksHeaderPadding;
			Padding textPadding = NuGenToolTipLayoutManager.GetTextPadding(tooltipInfo);
			Padding imagePadding = _imagePadding;

			/* Header */

			if (tooltipInfo.IsHeaderVisible)
			{
				Rectangle headerRect = new Rectangle(
					rect.X + headerPadding.Left,
					rect.Y + headerPadding.Top,
					rect.Width - headerPadding.Horizontal,
					rect.Height - headerPadding.Vertical
				);

				descriptor.HeaderBounds = headerRect;
				Size headerSize = g.MeasureString(tooltipInfo.Header, headerFont, headerRect.Width).ToSize();
				headerSize.Width += headerPadding.Horizontal;
				headerSize.Height += headerPadding.Vertical;
				rect.Y += headerSize.Height;
				rect.Height -= headerSize.Height;
			}

			/* Remarks */

			if (tooltipInfo.IsRemarksHeaderVisible && rect.Width > 0 && rect.Height > 0)
			{
				if (tooltipInfo.IsRemarksVisible)
				{
					int offset = remarksHeaderPadding.Left;

					if (tooltipInfo.IsRemarksImageVisible)
					{
						offset += tooltipInfo.RemarksImage.Width + imagePadding.Horizontal;
					}

					int remarksTextWidth = rect.Width - offset;
					Size remarksSize = g.MeasureString(tooltipInfo.Remarks, textFont, remarksTextWidth).ToSize();

					Rectangle remarksRect = new Rectangle(
						rect.X + offset,
						rect.Bottom - remarksSize.Height - textPadding.Vertical,
						remarksTextWidth,
						remarksSize.Height
					);

					descriptor.RemarksBounds = remarksRect;
					rect.Height -= (remarksRect.Height + textPadding.Vertical);
				}

				Size remarksHeaderSize = g.MeasureString(tooltipInfo.RemarksHeader, headerFont, rect.Width - remarksHeaderPadding.Horizontal).ToSize();
				Image remarksImage = tooltipInfo.RemarksImage;

				if (tooltipInfo.IsRemarksImageVisible && remarksImage.Height > remarksHeaderSize.Height)
				{
					remarksHeaderSize.Height = remarksImage.Height;
				}

				Rectangle remarksHeaderRect = new Rectangle(
					rect.X + remarksHeaderPadding.Left,
					rect.Bottom - remarksHeaderSize.Height - remarksHeaderPadding.Bottom,
					rect.Width - remarksHeaderPadding.Horizontal,
					remarksHeaderSize.Height
				);

				int bevelTop = remarksHeaderRect.Y - remarksHeaderPadding.Top - 1;
				descriptor.BevelBounds = new Rectangle(headerPadding.Horizontal, bevelTop, tooltipSize.Width - headerPadding.Horizontal, bevelTop);

				if (remarksImage != null)
				{
					descriptor.RemarksImageBounds = new Rectangle(
						remarksHeaderRect.X,
						remarksHeaderRect.Y + (remarksHeaderRect.Height - remarksImage.Height) / 2,
						remarksImage.Width,
						remarksImage.Height
					);

					remarksHeaderRect.X += (remarksImage.Width + _remarksImageOffset);
					remarksHeaderRect.Width -= (remarksImage.Width + _remarksImageOffset);
				}

				descriptor.RemarksHeaderBounds = remarksHeaderRect;

				remarksHeaderSize.Width += remarksHeaderPadding.Horizontal;
				remarksHeaderSize.Height += remarksHeaderPadding.Vertical;

				rect.Height -= remarksHeaderSize.Height;
			}

			/* Image */

			Image image = tooltipInfo.Image;

			if (tooltipInfo.IsImageVisible)
			{
				Rectangle imageRect = new Rectangle(
					rect.X + imagePadding.Left,
					rect.Y + imagePadding.Top,
					image.Width,
					image.Width
				);

				descriptor.ImageBounds = imageRect;

				rect.X += (imagePadding.Horizontal + image.Width);
				rect.Width -= (imagePadding.Horizontal + image.Width);
			}

			/* Text */

			if (tooltipInfo.IsTextVisible && rect.Width > 0 && rect.Height > 0)
			{
				Rectangle textRect = new Rectangle(
					rect.X + textPadding.Left,
					rect.Y + textPadding.Top,
					rect.Width - textPadding.Horizontal,
					rect.Height - textPadding.Vertical
				);

				descriptor.TextBounds = textRect;
			}

			Size shadowSize = this.GetShadowSize();
			descriptor.TooltipSize = new Size(tooltipSize.Width + shadowSize.Width, tooltipSize.Height + shadowSize.Height);

			return descriptor;
		}
		/*
		 * GetAutoSize
		 */

		private Size GetAutoSize(Graphics g, NuGenToolTipInfo tooltipInfo, Font headerFont, Font textFont)
		{
			Debug.Assert(tooltipInfo != null, "tooltipInfo != null");

			Padding headerPadding = _headerPadding;
			Padding remarksPadding = _remarksHeaderPadding;
			Padding textPadding = NuGenToolTipLayoutManager.GetTextPadding(tooltipInfo);
			Padding imagePadding = _imagePadding;

			Size minimumTooltipSize = this.GetMinimumTooltipSize();
			Size size = Size.Empty;

			if (tooltipInfo.IsHeaderVisible)
			{
				Size headerSize = g.MeasureString(tooltipInfo.Header, headerFont).ToSize();

				headerSize.Width += (headerPadding.Horizontal * 2);
				headerSize.Height += (headerPadding.Vertical + headerPadding.Top);

				if (headerSize.Width > size.Width)
				{
					size.Width = headerSize.Width;
				}

				size.Height += headerSize.Height;
			}

			if (tooltipInfo.IsRemarksHeaderVisible)
			{
				Size remarksHeaderSize = g.MeasureString(tooltipInfo.RemarksHeader, headerFont).ToSize();

				remarksHeaderSize.Width += 2;
				remarksHeaderSize.Height += 2;

				Image remarksImage = tooltipInfo.RemarksImage;

				if (tooltipInfo.IsRemarksImageVisible)
				{
					remarksHeaderSize.Width += (remarksImage.Width + _remarksImageOffset);

					if (remarksImage.Height > remarksHeaderSize.Height)
					{
						remarksHeaderSize.Height = remarksImage.Height;
					}
				}

				remarksHeaderSize.Width += remarksPadding.Horizontal;
				remarksHeaderSize.Height += remarksPadding.Vertical;

				if (remarksHeaderSize.Width > size.Width)
				{
					size.Width = remarksHeaderSize.Width;
				}

				size.Height += remarksHeaderSize.Height;

				if (tooltipInfo.IsRemarksVisible)
				{
					int textArea = size.Width;

					if (textArea < minimumTooltipSize.Width)
					{
						textArea = minimumTooltipSize.Width;
					}

					if (remarksImage != null)
					{
						textArea -= remarksImage.Width;
					}

					Size textSize = g.MeasureString(tooltipInfo.Remarks, textFont, textArea).ToSize();

					if (textSize.Height > textSize.Width * 1.75)
					{
						textArea = (int)(textSize.Height * 0.75);
						textSize = g.MeasureString(tooltipInfo.Remarks, textFont, textArea).ToSize();
					}

					textSize.Width += textPadding.Horizontal;
					textSize.Height += textPadding.Vertical;

					if (textSize.Width > size.Width)
					{
						size.Width = textSize.Width;
					}

					size.Height += textSize.Height;
				}
			}

			if (tooltipInfo.IsTextVisible)
			{
				int textArea = size.Width;

				if (textArea < minimumTooltipSize.Width)
				{
					textArea = minimumTooltipSize.Width;
				}

				Size textSize = g.MeasureString(tooltipInfo.Text, textFont, textArea).ToSize();

				textSize.Width += (textPadding.Horizontal + textPadding.Right);
				textSize.Height += (textPadding.Vertical);

				if (tooltipInfo.IsImageVisible)
				{
					Image image = tooltipInfo.Image;
					Debug.Assert(image != null, "image != null");

					textSize.Width += image.Width + imagePadding.Horizontal;

					if (image.Height + imagePadding.Vertical > textSize.Height)
					{
						textSize.Height = image.Height + imagePadding.Vertical;
					}
				}

				if (textSize.Width > size.Width)
				{
					size.Width = textSize.Width;
				}

				size.Height += textSize.Height;
			}
			else
			{
				if (tooltipInfo.IsImageVisible)
				{
					Image image = tooltipInfo.Image;
					Debug.Assert(image != null, "image != null");

					if (image.Width + imagePadding.Horizontal > size.Width)
					{
						size.Width = image.Width + imagePadding.Horizontal;
					}

					size.Height += image.Height + imagePadding.Vertical;
				}
			}

			if (size.Width < minimumTooltipSize.Width)
			{
				size.Width = minimumTooltipSize.Width;
			}

			if (size.Height < minimumTooltipSize.Height)
			{
				size.Height = minimumTooltipSize.Height;
			}

			return size;
		}
Exemplo n.º 13
0
        /// <summary>
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="g"/> is <see langword="null"/>.</para>
        /// -or-
        /// <para><paramref name="tooltipInfo"/> is <see langword="null"/>.</para>
        /// -or-
        /// <para><paramref name="headerFont"/> is <see langword="null"/>.</para>
        /// -or-
        /// <para><paramref name="textFont"/> is <see langword="null"/>.</para>
        /// </exception>
        public NuGenToolTipLayoutDescriptor BuildLayoutDescriptor(
            Graphics g,
            NuGenToolTipInfo tooltipInfo,
            Font headerFont,
            Font textFont
            )
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            if (tooltipInfo == null)
            {
                throw new ArgumentNullException("tooltipInfo");
            }

            if (headerFont == null)
            {
                throw new ArgumentNullException("headerFont");
            }

            if (textFont == null)
            {
                throw new ArgumentNullException("textFont");
            }

            NuGenToolTipLayoutDescriptor descriptor = new NuGenToolTipLayoutDescriptor();

            Size tooltipSize = tooltipInfo.IsCustomSize
                                ? tooltipInfo.CustomSize
                                : this.GetAutoSize(g, tooltipInfo, headerFont, textFont)
            ;

            Rectangle rect = new Rectangle(new Point(0, 0), tooltipSize);

            Padding headerPadding        = _headerPadding;
            Padding remarksHeaderPadding = _remarksHeaderPadding;
            Padding textPadding          = NuGenToolTipLayoutManager.GetTextPadding(tooltipInfo);
            Padding imagePadding         = _imagePadding;

            /* Header */

            if (tooltipInfo.IsHeaderVisible)
            {
                Rectangle headerRect = new Rectangle(
                    rect.X + headerPadding.Left,
                    rect.Y + headerPadding.Top,
                    rect.Width - headerPadding.Horizontal,
                    rect.Height - headerPadding.Vertical
                    );

                descriptor.HeaderBounds = headerRect;
                Size headerSize = g.MeasureString(tooltipInfo.Header, headerFont, headerRect.Width).ToSize();
                headerSize.Width  += headerPadding.Horizontal;
                headerSize.Height += headerPadding.Vertical;
                rect.Y            += headerSize.Height;
                rect.Height       -= headerSize.Height;
            }

            /* Remarks */

            if (tooltipInfo.IsRemarksHeaderVisible && rect.Width > 0 && rect.Height > 0)
            {
                if (tooltipInfo.IsRemarksVisible)
                {
                    int offset = remarksHeaderPadding.Left;

                    if (tooltipInfo.IsRemarksImageVisible)
                    {
                        offset += tooltipInfo.RemarksImage.Width + imagePadding.Horizontal;
                    }

                    int  remarksTextWidth = rect.Width - offset;
                    Size remarksSize      = g.MeasureString(tooltipInfo.Remarks, textFont, remarksTextWidth).ToSize();

                    Rectangle remarksRect = new Rectangle(
                        rect.X + offset,
                        rect.Bottom - remarksSize.Height - textPadding.Vertical,
                        remarksTextWidth,
                        remarksSize.Height
                        );

                    descriptor.RemarksBounds = remarksRect;
                    rect.Height -= (remarksRect.Height + textPadding.Vertical);
                }

                Size  remarksHeaderSize = g.MeasureString(tooltipInfo.RemarksHeader, headerFont, rect.Width - remarksHeaderPadding.Horizontal).ToSize();
                Image remarksImage      = tooltipInfo.RemarksImage;

                if (tooltipInfo.IsRemarksImageVisible && remarksImage.Height > remarksHeaderSize.Height)
                {
                    remarksHeaderSize.Height = remarksImage.Height;
                }

                Rectangle remarksHeaderRect = new Rectangle(
                    rect.X + remarksHeaderPadding.Left,
                    rect.Bottom - remarksHeaderSize.Height - remarksHeaderPadding.Bottom,
                    rect.Width - remarksHeaderPadding.Horizontal,
                    remarksHeaderSize.Height
                    );

                int bevelTop = remarksHeaderRect.Y - remarksHeaderPadding.Top - 1;
                descriptor.BevelBounds = new Rectangle(headerPadding.Horizontal, bevelTop, tooltipSize.Width - headerPadding.Horizontal, bevelTop);

                if (remarksImage != null)
                {
                    descriptor.RemarksImageBounds = new Rectangle(
                        remarksHeaderRect.X,
                        remarksHeaderRect.Y + (remarksHeaderRect.Height - remarksImage.Height) / 2,
                        remarksImage.Width,
                        remarksImage.Height
                        );

                    remarksHeaderRect.X     += (remarksImage.Width + _remarksImageOffset);
                    remarksHeaderRect.Width -= (remarksImage.Width + _remarksImageOffset);
                }

                descriptor.RemarksHeaderBounds = remarksHeaderRect;

                remarksHeaderSize.Width  += remarksHeaderPadding.Horizontal;
                remarksHeaderSize.Height += remarksHeaderPadding.Vertical;

                rect.Height -= remarksHeaderSize.Height;
            }

            /* Image */

            Image image = tooltipInfo.Image;

            if (tooltipInfo.IsImageVisible)
            {
                Rectangle imageRect = new Rectangle(
                    rect.X + imagePadding.Left,
                    rect.Y + imagePadding.Top,
                    image.Width,
                    image.Width
                    );

                descriptor.ImageBounds = imageRect;

                rect.X     += (imagePadding.Horizontal + image.Width);
                rect.Width -= (imagePadding.Horizontal + image.Width);
            }

            /* Text */

            if (tooltipInfo.IsTextVisible && rect.Width > 0 && rect.Height > 0)
            {
                Rectangle textRect = new Rectangle(
                    rect.X + textPadding.Left,
                    rect.Y + textPadding.Top,
                    rect.Width - textPadding.Horizontal,
                    rect.Height - textPadding.Vertical
                    );

                descriptor.TextBounds = textRect;
            }

            Size shadowSize = this.GetShadowSize();

            descriptor.TooltipSize = new Size(tooltipSize.Width + shadowSize.Width, tooltipSize.Height + shadowSize.Height);

            return(descriptor);
        }
Exemplo n.º 14
0
        /*
         * GetAutoSize
         */

        private Size GetAutoSize(Graphics g, NuGenToolTipInfo tooltipInfo, Font headerFont, Font textFont)
        {
            Debug.Assert(tooltipInfo != null, "tooltipInfo != null");

            Padding headerPadding  = _headerPadding;
            Padding remarksPadding = _remarksHeaderPadding;
            Padding textPadding    = NuGenToolTipLayoutManager.GetTextPadding(tooltipInfo);
            Padding imagePadding   = _imagePadding;

            Size minimumTooltipSize = this.GetMinimumTooltipSize();
            Size size = Size.Empty;

            if (tooltipInfo.IsHeaderVisible)
            {
                Size headerSize = g.MeasureString(tooltipInfo.Header, headerFont).ToSize();

                headerSize.Width  += (headerPadding.Horizontal * 2);
                headerSize.Height += (headerPadding.Vertical + headerPadding.Top);

                if (headerSize.Width > size.Width)
                {
                    size.Width = headerSize.Width;
                }

                size.Height += headerSize.Height;
            }

            if (tooltipInfo.IsRemarksHeaderVisible)
            {
                Size remarksHeaderSize = g.MeasureString(tooltipInfo.RemarksHeader, headerFont).ToSize();

                remarksHeaderSize.Width  += 2;
                remarksHeaderSize.Height += 2;

                Image remarksImage = tooltipInfo.RemarksImage;

                if (tooltipInfo.IsRemarksImageVisible)
                {
                    remarksHeaderSize.Width += (remarksImage.Width + _remarksImageOffset);

                    if (remarksImage.Height > remarksHeaderSize.Height)
                    {
                        remarksHeaderSize.Height = remarksImage.Height;
                    }
                }

                remarksHeaderSize.Width  += remarksPadding.Horizontal;
                remarksHeaderSize.Height += remarksPadding.Vertical;

                if (remarksHeaderSize.Width > size.Width)
                {
                    size.Width = remarksHeaderSize.Width;
                }

                size.Height += remarksHeaderSize.Height;

                if (tooltipInfo.IsRemarksVisible)
                {
                    int textArea = size.Width;

                    if (textArea < minimumTooltipSize.Width)
                    {
                        textArea = minimumTooltipSize.Width;
                    }

                    if (remarksImage != null)
                    {
                        textArea -= remarksImage.Width;
                    }

                    Size textSize = g.MeasureString(tooltipInfo.Remarks, textFont, textArea).ToSize();

                    if (textSize.Height > textSize.Width * 1.75)
                    {
                        textArea = (int)(textSize.Height * 0.75);
                        textSize = g.MeasureString(tooltipInfo.Remarks, textFont, textArea).ToSize();
                    }

                    textSize.Width  += textPadding.Horizontal;
                    textSize.Height += textPadding.Vertical;

                    if (textSize.Width > size.Width)
                    {
                        size.Width = textSize.Width;
                    }

                    size.Height += textSize.Height;
                }
            }

            if (tooltipInfo.IsTextVisible)
            {
                int textArea = size.Width;

                if (textArea < minimumTooltipSize.Width)
                {
                    textArea = minimumTooltipSize.Width;
                }

                Size textSize = g.MeasureString(tooltipInfo.Text, textFont, textArea).ToSize();

                textSize.Width  += (textPadding.Horizontal + textPadding.Right);
                textSize.Height += (textPadding.Vertical);

                if (tooltipInfo.IsImageVisible)
                {
                    Image image = tooltipInfo.Image;
                    Debug.Assert(image != null, "image != null");

                    textSize.Width += image.Width + imagePadding.Horizontal;

                    if (image.Height + imagePadding.Vertical > textSize.Height)
                    {
                        textSize.Height = image.Height + imagePadding.Vertical;
                    }
                }

                if (textSize.Width > size.Width)
                {
                    size.Width = textSize.Width;
                }

                size.Height += textSize.Height;
            }
            else
            {
                if (tooltipInfo.IsImageVisible)
                {
                    Image image = tooltipInfo.Image;
                    Debug.Assert(image != null, "image != null");

                    if (image.Width + imagePadding.Horizontal > size.Width)
                    {
                        size.Width = image.Width + imagePadding.Horizontal;
                    }

                    size.Height += image.Height + imagePadding.Vertical;
                }
            }

            if (size.Width < minimumTooltipSize.Width)
            {
                size.Width = minimumTooltipSize.Width;
            }

            if (size.Height < minimumTooltipSize.Height)
            {
                size.Height = minimumTooltipSize.Height;
            }

            return(size);
        }
Exemplo n.º 15
0
 public void SetUp()
 {
     _tooltipInfo = new NuGenToolTipInfo();
 }