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); }
/// <summary> /// Creates a new instance of Dataweb.NShape.WinFormsUI.InPlaceTextBox. /// </summary> public InPlaceTextBox(IDiagramPresenter owner, ICaptionedShape shape, int captionIndex, string currentText, string newText) { Construct(owner, shape, captionIndex, currentText, newText); // Set Text originalText = currentText; if (string.IsNullOrEmpty(newText)) { // Preselect the whole text if the user has not started typing yet base.Text = currentText; SelectAll(); } else { // Set the types text and place the cursor at the end of the text base.Text = newText; SelectionStart = Text.Length; } }
private static void Compare(ICaptionedShape savedShape, ICaptionedShape loadedShape, int version) { Assert.AreEqual <bool>(savedShape != null, loadedShape != null); if (savedShape != null && loadedShape != null) { Assert.AreEqual <int>(savedShape.CaptionCount, loadedShape.CaptionCount); for (int i = savedShape.CaptionCount - 1; i >= 0; --i) { Compare(savedShape.GetCaptionCharacterStyle(i), loadedShape.GetCaptionCharacterStyle(i), version); Compare(savedShape.GetCaptionParagraphStyle(i), loadedShape.GetCaptionParagraphStyle(i), version); CompareString(savedShape.GetCaptionText(i), loadedShape.GetCaptionText(i), false); } } }
private static void Compare(ICaptionedShape shapeA, ICaptionedShape shapeB, int version) { Assert.AreEqual <bool>(shapeA != null, shapeB != null); if (shapeA != null && shapeB != null) { Assert.AreEqual <int>(shapeA.CaptionCount, shapeB.CaptionCount); for (int i = shapeA.CaptionCount - 1; i >= 0; --i) { Compare(shapeA.GetCaptionCharacterStyle(i), shapeB.GetCaptionCharacterStyle(i), version); Compare(shapeA.GetCaptionParagraphStyle(i), shapeB.GetCaptionParagraphStyle(i), version); CompareString(shapeA.GetCaptionText(i), shapeB.GetCaptionText(i), false); } } }
/// <override></override> public override void CopyFrom(Shape source) { base.CopyFrom(source); if (source is ICaptionedShape) { ICaptionedShape src = (ICaptionedShape)source; // Copy first caption ICharacterStyle charStyle = src.GetCaptionCharacterStyle(0); privateCharacterStyle = (Template != null && charStyle == ((ICaptionedShape)Template.Shape).GetCaptionCharacterStyle(0)) ? null : charStyle; IParagraphStyle paragraphStyle = src.GetCaptionParagraphStyle(0); privateParagraphStyle = (Template != null && paragraphStyle == ((ICaptionedShape)Template.Shape).GetCaptionParagraphStyle(0)) ? null : paragraphStyle; string txt = src.GetCaptionText(0); if (!string.IsNullOrEmpty(txt)) { if (caption == null) { caption = new Caption(txt); } else { caption.Text = txt; } } else { caption = null; } // Copy remaining captions int cnt = Math.Min(CaptionCount, src.CaptionCount); for (int i = 1; i < cnt; ++i) { SetCaptionCharacterStyle(i, src.GetCaptionCharacterStyle(i)); SetCaptionParagraphStyle(i, GetCaptionParagraphStyle(i)); SetCaptionText(i, GetCaptionText(i)); } } }
/// <summary> /// Creates a new instance of Dataweb.NShape.WinFormsUI.InPlaceTextBox. /// </summary> public InPlaceTextBox(IDiagramPresenter owner, ICaptionedShape shape, int captionIndex, string currentText) : this(owner, shape, captionIndex, currentText, null) { }
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 general properties this.BackColor = Color.Transparent; // Does not matter - see CreateParams() this.AutoScrollOffset = Point.Empty; this.ScrollBars = RichTextBoxScrollBars.None; this.BorderStyle = BorderStyle.None; // Set caption / style specific properties this.owner = owner; this.shape = shape; this.captionIndex = captionIndex; // 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(); } }