Esempio n. 1
0
        protected override async Task OnMouseAction(Point point, MouseClickActions action)
        {
            // Find out where the text was clicked
            int posInLine = 0;
            var lastUp    = this.lastMouseUp;

            if (action == MouseClickActions.MouseUp)
            {
                this.lastMouseUp = null;
            }
            foreach (var part in textParts)
            {
                if (part.Rectangle.Contains(point))
                {
                    posInLine += Math.Min(part.Text.Length - 1, (int)((point.X - part.Rectangle.X) / Math.Max(1, this.lastCalculatedFontWidth) + 0.5));

                    // Check if it was doubleclick
                    if (action == MouseClickActions.MouseUp)
                    {
                        this.lastMouseUp = new LastMouseUp
                        {
                            Time = DateTime.UtcNow,
                            Pos  = point
                        };

                        if (lastUp != null && (DateTime.UtcNow - lastUp.Time) < TimeSpan.FromMilliseconds(500) && Math.Abs(point.X - lastUp.Pos.X) + Math.Abs(point.Y - lastUp.Pos.Y) < 10)
                        {
                            // Double-click -> select word under mouse
                            posInLine = Math.Min(posInLine, Math.Max(0, part.Text.Length - 1));
                            var startPos = posInLine;
                            while (startPos > 0 && IsWordPart(part.Text[startPos - 1]))
                            {
                                startPos--;
                            }
                            var endPos = posInLine;
                            while (endPos < part.Text.Length && IsWordPart(part.Text[endPos]))
                            {
                                endPos++;
                            }

                            await EditorState.CursorRaw.SetPositions(
                                startNode : this.XmlNode, posAtStartNode : XmlCursorPositions.CursorInsideTextNode, textPosInStartNode : startPos,
                                endNode : this.XmlNode, posAtEndNode : XmlCursorPositions.CursorInsideTextNode, textPosInEndNode : endPos,
                                throwChangedEventWhenValuesChanged : false
                                );

                            return;
                        }
                    }

                    await EditorState.CursorRaw.SetCursorByMouseAction(this.XmlNode, XmlCursorPositions.CursorInsideTextNode, posInLine, action);

                    return;
                }
                else
                {
                    posInLine += part.Text.Length;
                }
            }
        }
Esempio n. 2
0
        protected override async Task OnMouseAction(Point point, MouseClickActions mouseAction)
        {
            if (this.startTag.AreaArrow?.Contains(point) == true) // clicked on the left, opening arrow
            {
                if (this.XmlNode.ChildNodes.Count > 0)            // Children available
                {
                    // put in front of the first child
                    await EditorState.CursorRaw.SetCursorByMouseAction(this.XmlNode.FirstChild, XmlCursorPositions.CursorInFrontOfNode, mouseAction);

                    EditorState.CursorBlink.ResetBlinkPhase();
                    return;
                }
                else // No child available
                {
                    // Put into the node itself
                    await EditorState.CursorRaw.SetCursorByMouseAction(this.XmlNode, XmlCursorPositions.CursorInsideTheEmptyNode, mouseAction);

                    EditorState.CursorBlink.ResetBlinkPhase();
                    return;
                }
            }

            if (this.endTag?.AreaArrow?.Contains(point) == true) // the right, closing arrow was clicked
            {
                if (this.XmlNode.ChildNodes.Count > 0)           // Children available
                {
                    //  put behind the last child
                    await EditorState.CursorRaw.SetCursorByMouseAction(this.XmlNode.LastChild, XmlCursorPositions.CursorBehindTheNode, mouseAction);

                    EditorState.CursorBlink.ResetBlinkPhase();
                    return;
                }
                else // No child available
                {
                    // Put into the node itself
                    await EditorState.CursorRaw.SetCursorByMouseAction(this.XmlNode, XmlCursorPositions.CursorInsideTheEmptyNode, mouseAction);

                    EditorState.CursorBlink.ResetBlinkPhase();
                    return;
                }
            }

            if (this.startTag.AreaTag?.Contains(point) == true) // clicked on the left tag
            {
                await EditorState.CursorRaw.SetCursorByMouseAction(this.XmlNode, XmlCursorPositions.CursorOnNodeStartTag, mouseAction);

                EditorState.CursorBlink.ResetBlinkPhase();
                return;
            }

            if (this.endTag?.AreaTag?.Contains(point) == true) // clicked on the right day
            {
                await EditorState.CursorRaw.SetCursorByMouseAction(this.XmlNode, XmlCursorPositions.CursorOnNodeEndTag, mouseAction);

                EditorState.CursorBlink.ResetBlinkPhase();
                return;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Sets the cursor positions for corresponding mouse actions: For MausDown StartUndEndpos, for Move and Up only the endpos
 /// </summary>
 public async Task SetCursorByMouseAction(XmlNode xmlNode, XmlCursorPositions cursorPos, MouseClickActions action)
 {
     await SetCursorByMouseAction(xmlNode, cursorPos, 0, action);
 }
Esempio n. 4
0
        /// <summary>
        /// Sets the cursor positions for corresponding mouse actions: For MouseDown StartAndEndpos, for Move and Up only the endpos
        /// </summary>
        public async Task SetCursorByMouseAction(XmlNode xmlNode, XmlCursorPositions cursorPos, int posInLine, MouseClickActions action)
        {
            switch (action)
            {
            case MouseClickActions.MouseDown:
                // move the cursor to the new position
                await SetPositions(xmlNode, cursorPos, posInLine, throwChangedEventWhenValuesChanged : true);

                break;

            case MouseClickActions.MouseDownMove:
            case MouseClickActions.MouseUp:
                // Set end of the select cursor
                if (EndPos.SetPos(xmlNode, cursorPos, posInLine))
                {
                    await this.ForceChangedEvent();
                }
                break;
            }
        }
Esempio n. 5
0
 protected abstract Task OnMouseAction(Point point, MouseClickActions mouseAction);