/// <summary>
        /// Apply new font size
        /// </summary>
        public static bool ApplyFontSize(DrawingCanvas drawingCanvas, double value, bool addToHistory)
        {
            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange             = false;

            foreach (GraphicsBase g in drawingCanvas.Selection)
            {
                GraphicsText gt = g as GraphicsText;

                if (gt != null)
                {
                    if (gt.TextFontSize != value)
                    {
                        gt.TextFontSize = value;
                        wasChange       = true;
                    }
                }
            }

            if (wasChange && addToHistory)
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }

            return(wasChange);
        }
Example #2
0
        public PropertiesGraphicsText(GraphicsText graphicsText)
        {
            if (graphicsText == null)
            {
                throw new ArgumentNullException("graphicsText");
            }

            this.text               = graphicsText.Text;
            this.left               = graphicsText.Left;
            this.top                = graphicsText.Top;
            this.right              = graphicsText.Right;
            this.bottom             = graphicsText.Bottom;
            this.objectColor        = graphicsText.ObjectColor;
            this.textFontSize       = graphicsText.TextFontSize;
            this.textFontFamilyName = graphicsText.TextFontFamilyName;
            this.textFontStyle      = FontConversions.FontStyleToString(graphicsText.TextFontStyle);
            this.textFontWeight     = FontConversions.FontWeightToString(graphicsText.TextFontWeight);
            this.textFontStretch    = FontConversions.FontStretchToString(graphicsText.TextFontStretch);
            this.actualScale        = graphicsText.ActualScale;
            this.ID       = graphicsText.Id;
            this.selected = graphicsText.IsSelected;

            this.layer = graphicsText.Layer;
            this.page  = graphicsText.Page;

            this.reportContent = graphicsText.ReportContent;
            this.reporter      = graphicsText.Reporter;
            this.reportDate    = graphicsText.ReportDate;
        }
        /// <summary>
        /// Return true if currently active properties (line width, color etc.)
        /// can be applied to selected items.
        ///
        /// If at least one selected object has property different from currently
        /// active property value, properties can be applied.
        /// </summary>
        public static bool CanApplyProperties(DrawingCanvas drawingCanvas)
        {
            foreach (GraphicsBase graphicsBase in drawingCanvas.GraphicsList)
            {
                if (!graphicsBase.IsSelected)
                {
                    continue;
                }

                // ObjectColor - used in all graphics objects
                if (graphicsBase.ObjectColor != drawingCanvas.ObjectColor)
                {
                    return(true);
                }

                GraphicsText graphicsText = graphicsBase as GraphicsText;

                if (graphicsText == null)
                {
                    // LineWidth - used in all objects except of GraphicsText
                    if (graphicsBase.LineWidth != drawingCanvas.LineWidth)
                    {
                        return(true);
                    }
                }
                else
                {
                    // Font - for GraphicsText

                    if (graphicsText.TextFontFamilyName != drawingCanvas.TextFontFamilyName)
                    {
                        return(true);
                    }

                    if (graphicsText.TextFontSize != drawingCanvas.TextFontSize)
                    {
                        return(true);
                    }

                    if (graphicsText.TextFontStretch != drawingCanvas.TextFontStretch)
                    {
                        return(true);
                    }

                    if (graphicsText.TextFontStyle != drawingCanvas.TextFontStyle)
                    {
                        return(true);
                    }

                    if (graphicsText.TextFontWeight != drawingCanvas.TextFontWeight)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #4
0
        /// <summary>
        /// Create textbox for in-place editing
        /// </summary>
        public void CreateTextBox(GraphicsText graphicsText, DrawingCanvas drawingCanvas)
        {
            graphicsText.IsSelected = false;  // selection marks don't look good with textbox

            // Keep old text in the case Esc is pressed while editing
            oldText = graphicsText.Text;

            // Keep reference to edited object
            editedGraphicsText = graphicsText;


            textBox = new TextBox();

            textBox.Width       = graphicsText.Rectangle.Width;
            textBox.Height      = graphicsText.Rectangle.Height;
            textBox.FontFamily  = new FontFamily(graphicsText.TextFontFamilyName);
            textBox.FontSize    = graphicsText.TextFontSize;
            textBox.FontStretch = graphicsText.TextFontStretch;
            textBox.FontStyle   = graphicsText.TextFontStyle;
            textBox.FontWeight  = graphicsText.TextFontWeight;
            textBox.Text        = graphicsText.Text;

            textBox.AcceptsReturn = true;
            textBox.TextWrapping  = TextWrapping.Wrap;

            drawingCanvas.Children.Add(textBox);

            Canvas.SetLeft(textBox, graphicsText.Rectangle.Left);
            Canvas.SetTop(textBox, graphicsText.Rectangle.Top);
            textBox.Width  = textBox.Width;
            textBox.Height = textBox.Height;

            textBox.Focus();

            textBox.LostFocus         += new RoutedEventHandler(textBox_LostFocus);
            textBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(textBox_LostKeyboardFocus);
            textBox.PreviewKeyDown    += new KeyEventHandler(textBox_PreviewKeyDown);
            textBox.ContextMenu        = null; // see notes in textBox_LostKeyboardFocus

            // Initially textbox is set to the same rectangle as graphicsText.
            // After textbox loading its template is available, and we can
            // correct textbox position - see details in the textBox_Loaded function.
            textBox.Loaded += new RoutedEventHandler(textBox_Loaded);
        }
        /// <summary>
        /// Open in-place edit box if GraphicsText is clicked
        /// </summary>
        void HandleDoubleClick(MouseButtonEventArgs e)
        {
            Point point = e.GetPosition(this);

            // Enumerate all text objects
            for (int i = graphicsList.Count - 1; i >= 0; i--)
            {
                GraphicsText t = graphicsList[i] as GraphicsText;

                if (t != null)
                {
                    if (t.Contains(point))
                    {
                        toolText.CreateTextBox(t, this);
                        return;
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Left mouse is released.
        /// New object is created and resized.
        /// </summary>
        public override void OnMouseUp(DrawingCanvas drawingCanvas, MouseButtonEventArgs e)
        {
            drawingCanvas.Tool   = ToolType.Pointer;
            drawingCanvas.Cursor = HelperFunctions.DefaultCursor;
            drawingCanvas.ReleaseMouseCapture();

            if (drawingCanvas.Count > 0)
            {
                drawingCanvas[drawingCanvas.Count - 1].Normalize();

                GraphicsText t = drawingCanvas[drawingCanvas.Count - 1] as GraphicsText;

                if (t != null)
                {
                    // Create textbox for editing of graphics object which is just created
                    CreateTextBox(t, drawingCanvas);
                }
            }

            // Commnnd will be added to History later, after closing
            // in-place textbox.
        }
Example #7
0
        public override GraphicsBase CreateGraphics()
        {
            GraphicsBase b = new GraphicsText(
                text,
                left,
                top,
                right,
                bottom,
                objectColor,
                textFontSize,
                textFontFamilyName,
                FontConversions.FontStyleFromString(textFontStyle),
                FontConversions.FontWeightFromString(textFontWeight),
                FontConversions.FontStretchFromString(textFontStretch),
                actualScale, reportContent, reporter, reportDate);

            if (this.ID != 0)
            {
                b.Id         = this.ID;
                b.IsSelected = this.selected;
            }

            return(b);
        }
        /// <summary>
        /// Hide in-place editing textbox.
        /// Called from TextTool, when user pressed Enter or Esc,
        /// or from this class, when user clicks on the canvas.
        ///
        /// graphicsText passed to this function can be new text added by
        /// ToolText, or existing text opened for editing.
        /// If ToolText.OldText is empty, this is new object.
        /// If not, this is existing object.
        /// </summary>
        internal void HideTextbox(GraphicsText graphicsText)
        {
            if (toolText.TextBox == null)
            {
                return;
            }

            graphicsText.IsSelected = true;   // restore selection which was removed for better textbox appearance


            if (toolText.TextBox.Text.Trim().Length == 0)
            {
                // Textbox is empty: remove text object.

                if (!String.IsNullOrEmpty(toolText.OldText))     // existing text was edited
                {
                    // Since text object is removed now,
                    // Add Delete command to the history
                    undoManager.AddCommandToHistory(new CommandDelete(this));
                }

                // Remove empty text object
                graphicsList.Remove(graphicsText);
            }
            else
            {
                if (!String.IsNullOrEmpty(toolText.OldText))              // existing text was edited
                {
                    if (toolText.TextBox.Text.Trim() != toolText.OldText) // text was really changed
                    {
                        // Create command
                        CommandChangeState command = new CommandChangeState(this);

                        // Make change in the text object
                        graphicsText.Text = toolText.TextBox.Text.Trim();
                        graphicsText.UpdateRectangle();

                        // Keep state after change and add command to the history
                        command.NewState(this);
                        undoManager.AddCommandToHistory(command);
                    }
                }
                else                                          // new text was added
                {
                    // Make change in the text object
                    graphicsText.Text = toolText.TextBox.Text.Trim();
                    graphicsText.UpdateRectangle();

                    // Add command to the history
                    undoManager.AddCommandToHistory(new CommandAdd(graphicsText));
                }
            }

            // Remove textbox and set it to null.
            this.Children.Remove(toolText.TextBox);
            toolText.TextBox = null;

            // This enables back all ApplicationCommands,
            // which are disabled while textbox is active.
            this.Focus();
        }