Exemple #1
0
        private void Construct(IDiagramPresenter owner, ICaptionedShape shape, int captionIndex, string currentText,
                               string newText)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }
            if (captionIndex < 0 || captionIndex >= shape.CaptionCount)
            {
                throw new ArgumentOutOfRangeException("captionIndex");
            }
            // Set control styles
            SetStyle(ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
            UpdateStyles();

            // Set caption / style specific properties
            this.owner        = owner;
            this.shape        = shape;
            this.captionIndex = captionIndex;

            // Set general properties
            this.BackColor        = Color.Transparent;      // Does not matter - see CreateParams()
            this.AutoScrollOffset = Point.Empty;
            this.ScrollBars       = RichTextBoxScrollBars.None;
            this.BorderStyle      = BorderStyle.None;
            // Set Styles here because the ParagraphStyle is needed for resizing
            characterStyle = shape.GetCaptionCharacterStyle(captionIndex);
            paragraphStyle = shape.GetCaptionParagraphStyle(captionIndex);


            // Set base' members
            SuspendLayout();
            try {
                this.WordWrap   = paragraphStyle.WordWrap;
                this.Font       = ToolCache.GetFont(characterStyle);
                this.ZoomFactor = owner.ZoomLevel / 100f;

                // Get line height
                Size textSize = TextRenderer.MeasureText(((IDisplayService)owner).InfoGraphics, "Iq", Font);
                owner.DiagramToControl(textSize, out textSize);
                lineHeight = textSize.Height;

                DoUpdateBounds();

                SelectAll();
                SelectionAlignment = ConvertToHorizontalAlignment(paragraphStyle.Alignment);
                DeselectAll();
            }
            finally {
                ResumeLayout();
            }
            OnPaddingChanged(EventArgs.Empty);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="T:Dataweb.NShape.WinFormsUI.TextUITypeEditorDialog" />.
 /// </summary>
 public TextEditorDialog(string text, ICharacterStyle characterStyle)
     : this(text) {
     if (characterStyle == null)
     {
         throw new ArgumentNullException("characterStyle");
     }
     Font font = ToolCache.GetFont(characterStyle);
     textBox.Font = (Font)font.Clone();
     font         = null;
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of <see cref="T:Dataweb.NShape.WinFormsUI.TextUITypeEditorDialog" />.
 /// </summary>
 public TextEditorDialog(IEnumerable <string> lines, CharacterStyle characterStyle)
     : this(lines) {
     if (characterStyle == null)
     {
         throw new ArgumentNullException("characterStyle");
     }
     Font font = ToolCache.GetFont(characterStyle);
     textBox.Font = (Font)font.Clone();
     font         = null;
 }
        /// <override></override>
        protected override void OnMeasureItem(MeasureItemEventArgs e)
        {
            if (Items.Count > 0)
            {
                UpdateMaxItemWidth(e.Graphics, e.Index);

                e.ItemWidth = Width;
                if (Items[e.Index] is IStyle)
                {
                    switch (styleCategory)
                    {
                    case StyleCategory.CapStyle:
                        e.ItemHeight = ((ICapStyle)Items[e.Index]).CapSize;
                        break;

                    case StyleCategory.ColorStyle:
                    case StyleCategory.FillStyle:
                        e.ItemHeight = stdItemHeight;
                        break;

                    case StyleCategory.CharacterStyle:
                        ICharacterStyle characterStyle = (ICharacterStyle)Items[e.Index];
                        Font            font           = ToolCache.GetFont(characterStyle);
                        e.ItemHeight = (int)Math.Ceiling(font.GetHeight(e.Graphics));
                        break;

                    case StyleCategory.LineStyle:
                        e.ItemHeight = ((ILineStyle)Items[e.Index]).LineWidth + 4;
                        break;

                    case StyleCategory.ParagraphStyle:
                        e.ItemHeight = dblItemHeight + dblItemHeight;
                        break;

                    default:
                        throw new NShapeException(string.Format("Unexpected enum value '{0}'.", styleCategory));
                    }
                }
                // correct calculated Height by the Height of the label's font
                float fontSizeInPixels = Font.GetHeight(e.Graphics);
                if (fontSizeInPixels > e.ItemHeight)
                {
                    e.ItemHeight = (int)Math.Round(fontSizeInPixels);
                }
                e.ItemHeight += 4;
                if (e.ItemHeight < stdItemHeight)
                {
                    e.ItemHeight = 20;
                }
            }
        }
		private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ICharacterStyle charStyle) {
			Brush fontBrush = ToolCache.GetBrush(charStyle.ColorStyle);
			Font font = ToolCache.GetFont(charStyle);
			int height = Geometry.PointToPixel(charStyle.SizeInPoints, gfx.DpiY);
			float scale = Geometry.CalcScaleFactor(height, height, previewBounds.Width, previewBounds.Height);
			gfx.ScaleTransform(scale, scale);
			RectangleF layoutRect = RectangleF.Empty;
			layoutRect.X = 0;
			layoutRect.Y = 0;
			layoutRect.Width = (float)previewBounds.Width / scale;
			layoutRect.Height = (float)previewBounds.Height / scale;
			gfx.DrawString(string.Format("{0} {1} pt", charStyle.FontName, charStyle.SizeInPoints), 
				font, fontBrush, layoutRect, formatter);
		}
Exemple #6
0
        /// <override></override>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (maxItemTextWidth < 0)
            {
                UpdateMaxItemWidth(e.Graphics);
            }
            const int txtMargin = 4;

            itemBounds.X      = e.Bounds.X + 3;
            itemBounds.Y      = e.Bounds.Y + 1;
            itemBounds.Width  = (e.Bounds.Right - 3) - (e.Bounds.X + 3);
            itemBounds.Height = (e.Bounds.Bottom - 1) - (e.Bounds.Y + 1);

            previewRect.X      = itemBounds.X + margin;
            previewRect.Y      = itemBounds.Y + margin;
            previewRect.Width  = itemBounds.Width - Math.Max(maxItemTextWidth, itemBounds.Width / 4) - (2 * margin) - (2 * txtMargin);
            previewRect.Height = (itemBounds.Bottom - margin) - (itemBounds.Y + margin);

            labelLayoutRect.X      = previewRect.Right + txtMargin;
            labelLayoutRect.Y      = previewRect.Y;
            labelLayoutRect.Width  = maxItemTextWidth;
            labelLayoutRect.Height = previewRect.Height;

            // Draw Item Background and Border
            e.Graphics.FillRectangle(ItemBackgroundBrush, itemBounds);
            if (itemBorderColor != Color.Transparent)
            {
                e.Graphics.DrawRectangle(ItemBorderPen, itemBounds);
            }

            // Draw Selection and/or Focus markers
            if ((e.State & DrawItemState.Selected) != 0)
            {
                e.Graphics.FillRectangle(ItemSelectedBrush, itemBounds);
            }
            if ((e.State & DrawItemState.Focus) != 0)
            {
                if (itemFocusedColor != Color.Transparent)
                {
                    e.Graphics.FillRectangle(ItemFocusedBrush, itemBounds);
                }
                if (FocusBorderColor != Color.Transparent)
                {
                    e.Graphics.DrawRectangle(FocusBorderPen, itemBounds);
                }
            }
            else if (HighlightItems && (e.State & DrawItemState.HotLight) != 0)
            {
                if (ItemHighlightedColor != Color.Transparent)
                {
                    e.Graphics.FillRectangle(ItemHighlightedBrush, itemBounds);
                }
            }

            e.Graphics.SmoothingMode     = SmoothingMode.HighQuality;
            e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            if (Items.Count > 0 && e.Index >= 0)
            {
                if (Items[e.Index] is IStyle)
                {
                    switch (StyleCategory)
                    {
                    case StyleCategory.CapStyle:
                        DrawCapStyleItem((CapStyle)Items[e.Index], e);
                        break;

                    case StyleCategory.ColorStyle:
                        ColorStyle colorStyle = (ColorStyle)Items[e.Index];
                        Brush      colorBrush = ToolCache.GetBrush(colorStyle);
                        e.Graphics.FillRectangle(colorBrush, previewRect);
                        e.Graphics.DrawRectangle(ItemBorderPen, previewRect);
                        e.Graphics.DrawRectangle(Pens.Black, previewRect);
                        e.Graphics.DrawString(colorStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.FillStyle:
                        DrawFillStyleItem((FillStyle)Items[e.Index], e);
                        break;

                    case StyleCategory.CharacterStyle:
                        CharacterStyle charStyle = (CharacterStyle)Items[e.Index];
                        Font           font      = ToolCache.GetFont(charStyle);
                        Brush          fontBrush = ToolCache.GetBrush(charStyle.ColorStyle);
                        e.Graphics.DrawString(string.Format("{0} {1} pt", font.FontFamily.Name, font.SizeInPoints), font, fontBrush, previewRect, styleItemFormatter);
                        e.Graphics.DrawString(charStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.LineStyle:
                        LineStyle lineStyle = (LineStyle)Items[e.Index];
                        Pen       linePen   = ToolCache.GetPen(lineStyle, null, null);
                        e.Graphics.DrawLine(linePen, previewRect.X, previewRect.Y + (previewRect.Height / 2), previewRect.Right, previewRect.Y + (previewRect.Height / 2));
                        e.Graphics.DrawString(lineStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.ParagraphStyle:
                        ParagraphStyle paragraphStyle = (ParagraphStyle)Items[e.Index];
                        StringFormat   stringFormat   = ToolCache.GetStringFormat(paragraphStyle);
                        Rectangle      r = Rectangle.Empty;
                        r.X      = previewRect.Left + paragraphStyle.Padding.Left;
                        r.Y      = previewRect.Top + paragraphStyle.Padding.Top;
                        r.Width  = previewRect.Width - (paragraphStyle.Padding.Left + paragraphStyle.Padding.Right);
                        r.Height = previewRect.Height - (paragraphStyle.Padding.Top + paragraphStyle.Padding.Bottom);
                        e.Graphics.DrawString(previewText, e.Font, TextBrush, r, stringFormat);
                        e.Graphics.DrawRectangle(Pens.Black, previewRect);
                        e.Graphics.DrawString(paragraphStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    default:
                        throw new NShapeException(string.Format("Unexpected enum value '{0}'.", styleCategory));
                    }
                }
                else
                {
                    e.Graphics.DrawString(Items[e.Index].ToString().Trim(), e.Font, TextBrush, e.Bounds, specialItemFormatter);
                }
            }
        }