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 18:02:25 UTC
svn commit: r830672 - in /incubator/pivot/trunk/wtk:
src/org/apache/pivot/wtk/skin/TextAreaSkin.java
src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
test/org/apache/pivot/wtk/text/test/document.wtkx
Author: gbrown
Date: Wed Oct 28 17:02:24 2009
New Revision: 830672
URL: http://svn.apache.org/viewvc?rev=830672&view=rev
Log:
Add auto-scrolling support to 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
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/text/test/document.wtkx
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=830672&r1=830671&r2=830672&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 17:02:24 2009
@@ -747,7 +747,7 @@
for (int i = 0, n = rows.getLength(); i < n; i++) {
Row row = rows.get(i);
- if (y > row.y
+ if (y >= row.y
&& y < row.y + row.height) {
if (x < row.x) {
NodeView firstNodeView = row.nodeViews.get(0);
@@ -1290,8 +1290,40 @@
private class ScrollSelectionCallback implements Runnable {
@Override
public void run() {
- // TODO Add the next or previous row to the selection based on the
- // current location of the mouse
+ TextArea textArea = (TextArea)getComponent();
+ int selectionStart = textArea.getSelectionStart();
+ int selectionLength = textArea.getSelectionLength();
+ int selectionEnd = selectionStart + selectionLength - 1;
+
+ switch (scrollDirection) {
+ case FORWARD: {
+ // Get next offset
+ int offset = getNextInsertionPoint(caretX, selectionEnd, scrollDirection);
+ if (offset != -1) {
+ textArea.setSelection(selectionStart, offset - selectionStart + 1);
+ Bounds characterBounds = getCharacterBounds(offset);
+ textArea.scrollAreaToVisible(characterBounds);
+ }
+
+ break;
+ }
+
+ case BACKWARD: {
+ // Get previous offset
+ int offset = getNextInsertionPoint(caretX, selectionStart, scrollDirection);
+ if (offset != -1) {
+ textArea.setSelection(offset, selectionEnd - offset + 1);
+ Bounds characterBounds = getCharacterBounds(offset);
+ textArea.scrollAreaToVisible(characterBounds);
+ }
+
+ break;
+ }
+
+ default: {
+ throw new RuntimeException();
+ }
+ }
}
}
@@ -1304,6 +1336,8 @@
private boolean caretOn = false;
+ private Direction scrollDirection = null;
+
private BlinkCaretCallback blinkCaretCallback = new BlinkCaretCallback();
private ApplicationContext.ScheduledCallback scheduledBlinkCaretCallback = null;
@@ -1322,7 +1356,7 @@
private static final int PARAGRAPH_TERMINATOR_WIDTH = 4;
private static final FontRenderContext FONT_RENDER_CONTEXT = new FontRenderContext(null, true, true);
- private static final int SCROLL_RATE = 50;
+ private static final int SCROLL_RATE = 30;
public TextAreaSkin() {
Theme theme = Theme.getTheme();
@@ -1722,6 +1756,8 @@
scheduledScrollSelectionCallback = null;
}
+ scrollDirection = null;
+
int offset = getInsertionPoint(x, y);
if (offset != -1) {
@@ -1733,9 +1769,9 @@
}
}
} else {
- // TODO Initialize the scroll callback state?
-
if (scheduledScrollSelectionCallback == null) {
+ scrollDirection = (y < visibleArea.y) ? Direction.BACKWARD : Direction.FORWARD;
+
scheduledScrollSelectionCallback =
ApplicationContext.scheduleRecurringCallback(scrollSelectionCallback,
SCROLL_RATE);
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=830672&r1=830671&r2=830672&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 Wed Oct 28 17:02:24 2009
@@ -79,8 +79,6 @@
}
private class ScrollSelectionCallback implements Runnable {
- private int x = 0;
-
@Override
public void run() {
TextInput textInput = (TextInput)getComponent();
@@ -89,7 +87,7 @@
int selectionStart = textInput.getSelectionStart();
int selectionLength = textInput.getSelectionLength();
- if (x < 0) {
+ if (scrollX < 0) {
// Add the previous character to the selection
if (selectionStart > 0) {
selectionStart--;
@@ -111,6 +109,7 @@
private Shape logicalHighlightShape = null;
private int scrollLeft = 0;
+ private int scrollX = 0;
private BlinkCaretCallback blinkCaretCallback = new BlinkCaretCallback();
private ApplicationContext.ScheduledCallback scheduledBlinkCaretCallback = null;
@@ -862,7 +861,7 @@
textInput.setSelection(selectionStart, selectionLength);
} else {
- scrollSelectionCallback.x = x;
+ scrollX = x;
if (scheduledScrollSelectionCallback == null) {
scheduledScrollSelectionCallback =
Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/text/test/document.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/text/test/document.wtkx?rev=830672&r1=830671&r2=830672&view=diff
==============================================================================
Binary files - no diff available.