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/30 16:44:30 UTC

svn commit: r831342 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin: TextAreaSkin.java terra/TerraTextInputSkin.java

Author: gbrown
Date: Fri Oct 30 15:44:29 2009
New Revision: 831342

URL: http://svn.apache.org/viewvc?rev=831342&view=rev
Log:
Fix some scrolling issues in TextInput and TextArea.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java

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=831342&r1=831341&r2=831342&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 Fri Oct 30 15:44:29 2009
@@ -1934,6 +1934,7 @@
                     }
 
                     textArea.setSelection(selectionStart, selectionLength);
+                    scrollCharacterToVisible(selectionStart);
 
                     if (caret != null) {
                         caretX = caret.x;
@@ -1967,6 +1968,7 @@
                     }
 
                     textArea.setSelection(selectionStart, selectionLength);
+                    scrollCharacterToVisible(selectionStart + selectionLength);
 
                     if (caret != null) {
                         caretX = caret.x;

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=831342&r1=831341&r2=831342&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Fri Oct 30 15:44:29 2009
@@ -86,12 +86,15 @@
 
     private GlyphVector glyphVector = null;
 
-    private boolean caretOn = true;
+    // TODO
+    // private int anchor = -1;
     private Rectangle caret = new Rectangle();
     private Rectangle selection = null;
 
     private int scrollLeft = 0;
 
+    private boolean caretOn = true;
+
     private BlinkCaretCallback blinkCaretCallback = new BlinkCaretCallback();
     private ApplicationContext.ScheduledCallback scheduledBlinkCaretCallback = null;
 
@@ -224,6 +227,12 @@
         updateSelection();
         showCaret(textInput.isFocused()
             && textInput.getSelectionLength() == 0);
+
+        if (textNode.getCharacterCount() > 0) {
+            scrollCharacterToVisible(textInput.getSelectionStart());
+        } else {
+            scrollLeft = 0;
+        }
     }
 
     @Override
@@ -271,6 +280,15 @@
         graphics.setColor(borderColor);
         GraphicsUtilities.drawRect(graphics, 0, 0, width, height);
 
+        // TODO Remove
+        /*
+        // Paint the padding border
+        graphics.setColor(Color.RED);
+        graphics.drawRect(padding.left + 1, padding.top + 1,
+            width - (padding.left + padding.right + 2),
+            height - (padding.top + padding.bottom + 2));
+        */
+
         // Paint the content
         if (FONT_RENDER_CONTEXT.isAntiAliased()) {
             graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
@@ -408,6 +426,20 @@
         return new Bounds(x, y, width, height);
     }
 
+    private void scrollCharacterToVisible(int offset) {
+        int width = getWidth();
+        Bounds characterBounds = getCharacterBounds(offset);
+        int glyphX = characterBounds.x - (padding.left + 1) + scrollLeft;
+
+        if (characterBounds.x < padding.left + 1) {
+            scrollLeft = glyphX;
+        } else if (characterBounds.x + characterBounds.width > width - (padding.right + 1)) {
+            scrollLeft = glyphX + (padding.left + padding.right + 2) + characterBounds.width - width;
+        }
+
+        repaintComponent();
+    }
+
     public Font getFont() {
         return font;
     }
@@ -996,8 +1028,6 @@
             Keyboard.Modifier commandModifier = Platform.getCommandModifier();
             if (keyCode == Keyboard.KeyCode.DELETE
                 || keyCode == Keyboard.KeyCode.BACKSPACE) {
-                consumed = true;
-
                 Direction direction = (keyCode == Keyboard.KeyCode.DELETE ?
                     Direction.FORWARD : Direction.BACKWARD);
 
@@ -1030,9 +1060,9 @@
                 } else {
                     textInput.delete(direction);
                 }
-            } else if (keyCode == Keyboard.KeyCode.LEFT) {
-                consumed = true;
 
+                consumed = true;
+            } else if (keyCode == Keyboard.KeyCode.LEFT) {
                 int selectionStart = textInput.getSelectionStart();
                 int selectionLength = textInput.getSelectionLength();
 
@@ -1067,9 +1097,15 @@
                 }
 
                 textInput.setSelection(selectionStart, selectionLength);
-            } else if (keyCode == Keyboard.KeyCode.RIGHT) {
-                consumed = true;
 
+                if (textNode.getCharacterCount() > 0) {
+                    scrollCharacterToVisible(selectionStart);
+                } else {
+                    scrollLeft = 0;
+                }
+
+                consumed = true;
+            } else if (keyCode == Keyboard.KeyCode.RIGHT) {
                 int selectionStart = textInput.getSelectionStart();
                 int selectionLength = textInput.getSelectionLength();
 
@@ -1104,6 +1140,14 @@
                 }
 
                 textInput.setSelection(selectionStart, selectionLength);
+
+                if (textNode.getCharacterCount() > 0) {
+                    scrollCharacterToVisible(selectionStart + selectionLength - 1);
+                } else {
+                    scrollLeft = 0;
+                }
+
+                consumed = true;
             } else if (keyCode == Keyboard.KeyCode.HOME) {
                 // Move the caret to the beginning of the text
                 if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
@@ -1126,33 +1170,31 @@
                 consumed = true;
             } else if (keyCode == Keyboard.KeyCode.A
                 && Keyboard.isPressed(commandModifier)) {
-                consumed = true;
-
                 // Select all
                 textInput.setSelection(0, textNode.getCharacterCount());
+                consumed = true;
             } else if (keyCode == Keyboard.KeyCode.X
                 && Keyboard.isPressed(commandModifier)) {
-                consumed = true;
-
                 if (textInput.isPassword()) {
                     Toolkit.getDefaultToolkit().beep();
                 } else {
                     textInput.cut();
                 }
+
+                consumed = true;
             } else if (keyCode == Keyboard.KeyCode.C
                 && Keyboard.isPressed(commandModifier)) {
-                consumed = true;
-
                 if (textInput.isPassword()) {
                     Toolkit.getDefaultToolkit().beep();
                 } else {
                     textInput.copy();
                 }
+
+                consumed = true;
             } else if (keyCode == Keyboard.KeyCode.V
                 && Keyboard.isPressed(commandModifier)) {
-                consumed = true;
-
                 textInput.paste();
+                consumed = true;
             } else {
                 consumed = super.keyPressed(component, keyCode, keyLocation);
             }