You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/10/28 16:37:33 UTC

svn commit: r830616 - in /incubator/pivot/trunk/wtk: src/org/apache/pivot/wtk/Container.java src/org/apache/pivot/wtk/TextArea.java src/org/apache/pivot/wtk/skin/TextAreaSkin.java test/org/apache/pivot/wtk/test/SheetTest.java

Author: gbrown
Date: Wed Oct 28 15:37:33 2009
New Revision: 830616

URL: http://svn.apache.org/viewvc?rev=830616&view=rev
Log:
Ensure that mouseOut() is fired when container mouse move events are consumed; various TextArea fixes.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java?rev=830616&r1=830615&r2=830616&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java Wed Oct 28 15:37:33 2009
@@ -688,32 +688,35 @@
     protected boolean mouseMove(int x, int y) {
         boolean consumed = false;
 
+        // Clear the mouse over component if its mouse-over state has
+        // changed (e.g. if its enabled or visible properties have
+        // changed)
+        if (mouseOverComponent != null
+            && !mouseOverComponent.isMouseOver()) {
+            mouseOverComponent = null;
+        }
+
         if (isEnabled()) {
-            // Notify container listeners
-            consumed = containerMouseListeners.mouseMove(this, x, y);
+            // Synthesize mouse over/out events
+            Component component = getComponentAt(x, y);
 
-            if (!consumed) {
-                // Clear the mouse over component if its mouse-over state has
-                // changed (e.g. if its enabled or visible properties have
-                // changed)
-                if (mouseOverComponent != null
-                    && !mouseOverComponent.isMouseOver()) {
-                    mouseOverComponent = null;
+            if (mouseOverComponent != component) {
+                if (mouseOverComponent != null) {
+                    mouseOverComponent.mouseOut();
                 }
 
-                // Synthesize mouse over/out events
-                Component component = getComponentAt(x, y);
+                mouseOverComponent = null;
+                Mouse.setCursor(this);
+            }
 
-                if (mouseOverComponent != component) {
-                    if (mouseOverComponent != null) {
-                        mouseOverComponent.mouseOut();
-                    }
+            // Notify container listeners
+            consumed = containerMouseListeners.mouseMove(this, x, y);
 
+            if (!consumed) {
+                if (mouseOverComponent != component) {
                     mouseOverComponent = component;
 
-                    if (mouseOverComponent == null) {
-                        Mouse.setCursor(this);
-                    } else {
+                    if (mouseOverComponent != null) {
                         mouseOverComponent.mouseOver();
                         Mouse.setCursor(mouseOverComponent);
                     }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java?rev=830616&r1=830615&r2=830616&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java Wed Oct 28 15:37:33 2009
@@ -462,7 +462,7 @@
                 if (node instanceof TextNode) {
                     // Insert the text into the existing node
                     TextNode textNode = (TextNode)node;
-                    textNode.insertText(text, offset);
+                    textNode.insertText(text, offset - textNode.getOffset());
                 } else {
                     // Append a new text node
                     paragraph.add(new TextNode(text));
@@ -543,43 +543,44 @@
             throw new IllegalStateException();
         }
 
+        int offset = selectionStart;
+
+        int characterCount;
         if (selectionLength > 0) {
-            // TODO Need to merge paragraphs here if we delete the terminator character;
-            // see below
-            document.removeRange(selectionStart, selectionLength);
+            characterCount = selectionLength;
         } else {
-            int offset = selectionStart;
-
             if (direction == Direction.BACKWARD) {
                 offset--;
             }
 
-            if (offset >= 0
-                && offset < document.getCharacterCount()) {
-                Node descendant = document.getDescendantAt(offset);
-
-                if (descendant instanceof Paragraph) {
-                    // We are deleting a paragraph terminator
-                    Paragraph paragraph = (Paragraph)descendant;
-
-                    Element parent = paragraph.getParent();
-                    int index = parent.indexOf(paragraph);
-
-                    // Attempt to merge any successive content into the paragraph
-                    if (index < parent.getLength() - 1) {
-                        // TODO This won't always be a paragraph - we'll need to
-                        // find the next paragraph by walking the tree, then
-                        // remove any empty nodes
-                        Sequence<Node> removed = parent.remove(index + 1, 1);
-                        Paragraph nextParagraph = (Paragraph)removed.get(0);
-                        paragraph.insertRange(nextParagraph, paragraph.getCharacterCount() - 1);
-
-                        // Move the caret to the merge point
-                        setSelection(offset, 0);
-                    }
-                } else {
-                    document.removeRange(offset, 1);
+            characterCount = 1;
+        }
+
+        if (offset >= 0
+            && offset < document.getCharacterCount()) {
+            Node descendant = document.getDescendantAt(offset);
+
+            if (descendant instanceof Paragraph) {
+                // We are deleting a paragraph terminator
+                Paragraph paragraph = (Paragraph)descendant;
+
+                Element parent = paragraph.getParent();
+                int index = parent.indexOf(paragraph);
+
+                // Attempt to merge any successive content into the paragraph
+                if (index < parent.getLength() - 1) {
+                    // TODO This won't always be a paragraph - we'll need to
+                    // find the next paragraph by walking the tree, then
+                    // remove any empty nodes
+                    Sequence<Node> removed = parent.remove(index + 1, 1);
+                    Paragraph nextParagraph = (Paragraph)removed.get(0);
+                    paragraph.insertRange(nextParagraph, paragraph.getCharacterCount() - 1);
                 }
+
+                // Move the caret to the merge point
+                setSelection(offset, 0);
+            } else {
+                document.removeRange(offset, characterCount);
             }
         }
 
@@ -587,9 +588,6 @@
         if (document.getCharacterCount() == 0) {
             document.add(new Paragraph(""));
         }
-
-        // Clear the selection length
-        selectionLength = 0;
     }
 
     public void cut() {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=830616&r1=830615&r2=830616&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Wed Oct 28 15:37:33 2009
@@ -1019,21 +1019,22 @@
                     int selectionStart = textArea.getSelectionStart();
                     Span selectionRange = new Span(selectionStart, selectionStart + selectionLength - 1);
 
-                    int absoluteOffset = getOffset();
+                    // TODO Move this to a method?
+                    int documentOffset = getOffset();
                     ElementView parent = getParent();
                     while (parent != null) {
-                        absoluteOffset += parent.getOffset();
+                        documentOffset += parent.getOffset();
                         parent = parent.getParent();
                     }
 
-                    Span characterRange = new Span(absoluteOffset, absoluteOffset + getCharacterCount() - 1);
+                    Span characterRange = new Span(documentOffset, documentOffset + getCharacterCount() - 1);
                     if (characterRange.intersects(selectionRange)) {
                         int width = getWidth();
                         int height = getHeight();
 
                         int x0;
                         if (selectionRange.start > characterRange.start) {
-                            Bounds leadingSelectionBounds = getCharacterBounds(selectionRange.start - absoluteOffset);
+                            Bounds leadingSelectionBounds = getCharacterBounds(selectionRange.start - documentOffset);
                             x0 = leadingSelectionBounds.x;
                         } else {
                             x0 = 0;
@@ -1041,7 +1042,7 @@
 
                         int x1;
                         if (selectionRange.end < characterRange.end) {
-                            Bounds trailingSelectionBounds = getCharacterBounds(selectionRange.end - absoluteOffset);
+                            Bounds trailingSelectionBounds = getCharacterBounds(selectionRange.end - documentOffset);
                             x1 = trailingSelectionBounds.x + trailingSelectionBounds.width;
                         } else {
                             x1 = width;
@@ -1400,7 +1401,8 @@
             documentView.validate();
 
             updateSelection();
-            showCaret(textArea.getSelectionLength() == 0);
+            showCaret(textArea.isFocused()
+                && textArea.getSelectionLength() == 0);
         }
     }
 

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java?rev=830616&r1=830615&r2=830616&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java (original)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SheetTest.java Wed Oct 28 15:37:33 2009
@@ -22,6 +22,8 @@
 import org.apache.pivot.wtk.Application;
 import org.apache.pivot.wtk.Button;
 import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.ComponentMouseListener;
 import org.apache.pivot.wtk.DesktopApplicationContext;
 import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.BoxPane;
@@ -79,6 +81,18 @@
         final Prompt prompt = new Prompt(MessageType.INFO, "Prompt", new ArrayList<String>("OK"), promptBody);
         prompt.setTitle("Prompt");
 
+        prompt.getComponentMouseListeners().add(new ComponentMouseListener.Adapter() {
+            @Override
+            public void mouseOver(Component component) {
+                System.out.println("Mouse Over");
+            }
+
+            @Override
+            public void mouseOut(Component component) {
+                System.out.println("Mouse out");
+            }
+        });
+
         Label alertBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
         alertBody.getStyles().put("wrapText", true);