package com.sun.glass.ui.win;
import static javafx.scene.AccessibleAttribute.*;
import java.text.BreakIterator;
import javafx.geometry.Bounds;
import javafx.scene.AccessibleAction;
import javafx.scene.AccessibleAttribute;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
class {
private native static void ();
static {
_initIDs();
}
private static final int = 0;
private static final int = 1;
private static final int = 0;
private static final int = 1;
private static final int = 2;
private static final int = 3;
private static final int = 4;
private static final int = 5;
private static final int = 6;
private static final int = 40005;
private static final int = 40006;
private static final int = 40007;
private static final int = 40013;
private static final int = 40014;
private static final int = 40015;
private static int = 1;
private int ;
private int , ;
private WinAccessible ;
private long ;
private native long (long accessible);
private native void (long textRangeProvider);
(WinAccessible accessible) {
this.accessible = accessible;
peer = _createTextRangeProvider(accessible.getNativeAccessible());
id = idCount++;
}
long () {
return peer;
}
void () {
_destroyTextRangeProvider(peer);
peer = 0L;
}
void (int start, int end) {
this.start = start;
this.end = end;
}
int () {
return start;
}
int () {
return end;
}
@Override public String () {
return "Range(start: "+start+", end: "+end+", id: " + id + ")";
}
private Object (AccessibleAttribute attribute, Object... parameters) {
return accessible.getAttribute(attribute, parameters);
}
private boolean (BreakIterator bi, String text, int offset) {
if (offset == 0) return true;
if (offset == text.length()) return true;
if (offset == BreakIterator.DONE) return true;
return bi.isBoundary(offset) && Character.isLetterOrDigit(text.charAt(offset));
}
private long () {
WinTextRangeProvider clone = new WinTextRangeProvider(accessible);
clone.setRange(start, end);
return clone.getNativeProvider();
}
private boolean (WinTextRangeProvider range) {
if (range == null) return false;
return accessible == range.accessible && start == range.start && end == range.end;
}
private int (int endpoint, WinTextRangeProvider targetRange, int targetEndpoint) {
int offset = endpoint == TextPatternRangeEndpoint_Start ? start : end;
int targetOffset = targetEndpoint == TextPatternRangeEndpoint_Start ? targetRange.start : targetRange.end;
return offset - targetOffset;
}
private void ExpandToEnclosingUnit(int unit) {
String text = (String)getAttribute(TEXT);
if (text == null) return;
int length = text.length();
if (length == 0) return;
switch (unit) {
case TextUnit_Character: {
if (start == length) start--;
end = start + 1;
break;
}
case TextUnit_Format:
case TextUnit_Word: {
BreakIterator bi = BreakIterator.getWordInstance();
bi.setText(text);
if (!isWordStart(bi, text, start)) {
int offset = bi.preceding(start);
while (!isWordStart(bi, text, offset)) {
offset = bi.previous();
}
start = offset != BreakIterator.DONE ? offset : 0;
}
if (!isWordStart(bi, text, end)) {
int offset = bi.following(end);
while (!isWordStart(bi, text, offset)) {
offset = bi.next();
}
end = offset != BreakIterator.DONE ? offset : length;
}
break;
}
case TextUnit_Line: {
Integer lineIndex = (Integer)getAttribute(LINE_FOR_OFFSET, start);
Integer lineStart = (Integer)getAttribute(LINE_START, lineIndex);
Integer lineEnd = (Integer)getAttribute(LINE_END, lineIndex);
if (lineIndex == null || lineEnd == null || lineStart == null) {
start = 0;
end = length;
} else {
start = lineStart;
end = lineEnd;
}
break;
}
case TextUnit_Paragraph: {
Integer lineIndex = (Integer)getAttribute(LINE_FOR_OFFSET, start);
if (lineIndex == null) {
start = 0;
end = length;
} else {
BreakIterator bi = BreakIterator.getSentenceInstance();
bi.setText(text);
if (!bi.isBoundary(start)) {
int offset = bi.preceding(start);
start = offset != BreakIterator.DONE ? offset : 0;
}
int offset = bi.following(start);
end = offset != BreakIterator.DONE ? offset : length;
}
break;
}
case TextUnit_Page:
case TextUnit_Document: {
start = 0;
end = length;
break;
}
}
start = Math.max(0, Math.min(start, length));
end = Math.max(start, Math.min(end, length));
}
private long (int attributeId, WinVariant val, boolean backward) {
System.err.println("FindAttribute NOT IMPLEMENTED");
return 0;
}
private long (String text, boolean backward, boolean ignoreCase) {
if (text == null) return 0;
String documentText = (String)getAttribute(TEXT);
if (documentText == null) return 0;
String rangeText = documentText.substring(start, end);
if (ignoreCase) {
rangeText = rangeText.toLowerCase();
text = text.toLowerCase();
}
int index = -1;
if (backward) {
index = rangeText.lastIndexOf(text);
} else {
index = rangeText.indexOf(text);
}
if (index == -1) return 0;
WinTextRangeProvider result = new WinTextRangeProvider(accessible);
result.setRange(start + index, start + index + text.length());
return result.getNativeProvider();
}
private WinVariant (int attributeId) {
WinVariant variant = null;
switch (attributeId) {
case UIA_FontNameAttributeId: {
Font font = (Font)getAttribute(FONT);
if (font != null) {
variant = new WinVariant();
variant.vt = WinVariant.VT_BSTR;
variant.bstrVal = font.getName();
}
break;
}
case UIA_FontSizeAttributeId: {
Font font = (Font)getAttribute(FONT);
if (font != null) {
variant = new WinVariant();
variant.vt = WinVariant.VT_R8;
variant.dblVal = font.getSize();
}
break;
}
case UIA_FontWeightAttributeId: {
Font font = (Font)getAttribute(FONT);
if (font != null) {
boolean bold = font.getStyle().toLowerCase().contains("bold");
variant = new WinVariant();
variant.vt = WinVariant.VT_I4;
variant.lVal = bold ? FontWeight.BOLD.getWeight() : FontWeight.NORMAL.getWeight();
}
break;
}
case UIA_IsHiddenAttributeId:
case UIA_IsReadOnlyAttributeId:
variant = new WinVariant();
variant.vt = WinVariant.VT_BOOL;
variant.boolVal = false;
break;
case UIA_IsItalicAttributeId: {
Font font = (Font)getAttribute(FONT);
if (font != null) {
boolean italic = font.getStyle().toLowerCase().contains("italic");
variant = new WinVariant();
variant.vt = WinVariant.VT_BOOL;
variant.boolVal = italic;
}
break;
}
default:
}
return variant;
}
private double[] () {
String text = (String)getAttribute(TEXT);
if (text == null) return null;
int length = text.length();
if (length == 0) return new double[0];
int endOffset = end;
if (endOffset > 0 && endOffset > start && text.charAt(endOffset - 1) == '\n') {
endOffset--;
}
if (endOffset > 0 && endOffset > start && text.charAt(endOffset - 1) == '\r') {
endOffset--;
}
if (endOffset > 0 && endOffset > start && endOffset == length) {
endOffset--;
}
Bounds[] bounds = (Bounds[])getAttribute(BOUNDS_FOR_RANGE, start, endOffset);
if (bounds != null) {
double[] result = new double[bounds.length * 4];
int index = 0;
for (int i = 0; i < bounds.length; i++) {
Bounds b = bounds[i];
result[index++] = b.getMinX();
result[index++] = b.getMinY();
result[index++] = b.getWidth();
result[index++] = b.getHeight();
}
return result;
}
return null;
}
private long () {
return accessible.getNativeAccessible();
}
private String (int maxLength) {
String text = (String)getAttribute(TEXT);
if (text == null) return null;
int endOffset = maxLength != -1 ? Math.min(end, start + maxLength) : end;
return text.substring(start, endOffset);
}
private int (int unit, final int requestedCount) {
if (requestedCount == 0) return 0;
String text = (String)getAttribute(TEXT);
if (text == null) return 0;
int length = text.length();
if (length == 0) return 0;
int actualCount = 0;
switch (unit) {
case TextUnit_Character: {
int oldStart = start;
start = Math.max(0, Math.min(start + requestedCount, length - 1));
end = start + 1;
actualCount = start - oldStart;
break;
}
case TextUnit_Format:
case TextUnit_Word: {
BreakIterator bi = BreakIterator.getWordInstance();
bi.setText(text);
int offset = start;
while (!isWordStart(bi, text, offset)) {
offset = bi.preceding(start);
}
while (offset != BreakIterator.DONE && actualCount != requestedCount) {
if (requestedCount > 0) {
offset = bi.following(offset);
while (!isWordStart(bi, text, offset)) {
offset = bi.next();
}
actualCount++;
} else {
offset = bi.preceding(offset);
while (!isWordStart(bi, text, offset)) {
offset = bi.previous();
}
actualCount--;
}
}
if (actualCount != 0) {
if (offset != BreakIterator.DONE) {
start = offset;
} else {
start = requestedCount > 0 ? length : 0;
}
offset = bi.following(start);
while (!isWordStart(bi, text, offset)) {
offset = bi.next();
}
end = offset != BreakIterator.DONE ? offset : length;
}
break;
}
case TextUnit_Line: {
Integer lineIndex = (Integer)getAttribute(LINE_FOR_OFFSET, start);
if (lineIndex == null) return 0;
int step = requestedCount > 0 ? + 1 : -1;
while (requestedCount != actualCount) {
if (getAttribute(LINE_START, lineIndex + step) == null) break;
lineIndex += step;
actualCount += step;
}
if (actualCount != 0) {
Integer lineStart = (Integer)getAttribute(LINE_START, lineIndex);
Integer lineEnd = (Integer)getAttribute(LINE_END, lineIndex);
if (lineStart == null || lineEnd == null) return 0;
start = lineStart;
end = lineEnd;
}
break;
}
case TextUnit_Paragraph: {
BreakIterator bi = BreakIterator.getSentenceInstance();
bi.setText(text);
int offset = bi.isBoundary(start) ? start : bi.preceding(start);
while (offset != BreakIterator.DONE && actualCount != requestedCount) {
if (requestedCount > 0) {
offset = bi.following(offset);
actualCount++;
} else {
offset = bi.preceding(offset);
actualCount--;
}
}
if (actualCount != 0) {
start = offset != BreakIterator.DONE ? offset : 0;
offset = bi.following(start);
end = offset != BreakIterator.DONE ? offset : length;
}
break;
}
case TextUnit_Page:
case TextUnit_Document: {
return 0;
}
}
start = Math.max(0, Math.min(start, length));
end = Math.max(start, Math.min(end, length));
return actualCount;
}
private int (int endpoint, int unit, final int requestedCount) {
if (requestedCount == 0) return 0;
String text = (String)getAttribute(TEXT);
if (text == null) return 0;
int length = text.length();
int actualCount = 0;
int offset = endpoint == TextPatternRangeEndpoint_Start ? start : end;
switch (unit) {
case TextUnit_Character: {
int oldOffset = offset;
offset = Math.max(0, Math.min(offset + requestedCount, length));
actualCount = offset - oldOffset;
break;
}
case TextUnit_Format:
case TextUnit_Word: {
BreakIterator bi = BreakIterator.getWordInstance();
bi.setText(text);
while (offset != BreakIterator.DONE && actualCount != requestedCount) {
if (requestedCount > 0) {
offset = bi.following(offset);
while (!isWordStart(bi, text, offset)) {
offset = bi.next();
}
actualCount++;
} else {
offset = bi.preceding(offset);
while (!isWordStart(bi, text, offset)) {
offset = bi.previous();
}
actualCount--;
}
}
if (offset == BreakIterator.DONE) {
offset = requestedCount > 0 ? length : 0;
}
break;
}
case TextUnit_Line: {
Integer lineIndex = (Integer)getAttribute(LINE_FOR_OFFSET, offset);
Integer lineStart = (Integer)getAttribute(LINE_START, lineIndex);
Integer lineEnd = (Integer)getAttribute(LINE_END, lineIndex);
if (lineIndex == null || lineStart == null || lineEnd == null) {
offset = requestedCount > 0 ? length : 0;
break;
}
int step = requestedCount > 0 ? + 1 : -1;
int endOffset = requestedCount > 0 ? lineEnd : lineStart;
if (offset != endOffset) {
actualCount += step;
}
while (requestedCount != actualCount) {
if (getAttribute(LINE_START, lineIndex + step) == null) break;
lineIndex += step;
actualCount += step;
}
if (actualCount != 0) {
lineStart = (Integer)getAttribute(LINE_START, lineIndex);
lineEnd = (Integer)getAttribute(LINE_END, lineIndex);
if (lineStart == null || lineEnd == null) return 0;
offset = requestedCount > 0 ? lineEnd : lineStart;
}
break;
}
case TextUnit_Paragraph: {
BreakIterator bi = BreakIterator.getSentenceInstance();
bi.setText(text);
while (offset != BreakIterator.DONE && actualCount != requestedCount) {
if (requestedCount > 0) {
offset = bi.following(offset);
actualCount++;
} else {
offset = bi.preceding(offset);
actualCount--;
}
}
if (offset == BreakIterator.DONE) {
offset = requestedCount > 0 ? length : 0;
}
break;
}
case TextUnit_Page:
case TextUnit_Document: {
return 0;
}
}
if (endpoint == TextPatternRangeEndpoint_Start) {
start = offset;
} else {
end = offset;
}
if (start > end) {
start = end = offset;
}
start = Math.max(0, Math.min(start, length));
end = Math.max(start, Math.min(end, length));
return actualCount;
}
private void (int endpoint, WinTextRangeProvider targetRange, int targetEndpoint) {
String text = (String)getAttribute(TEXT);
if (text == null) return;
int length = text.length();
int offset = targetEndpoint == TextPatternRangeEndpoint_Start ? targetRange.start : targetRange.end;
if (endpoint == TextPatternRangeEndpoint_Start) {
start = offset;
} else {
end = offset;
}
if (start > end) {
start = end = offset;
}
start = Math.max(0, Math.min(start, length));
end = Math.max(start, Math.min(end, length));
}
private void () {
accessible.executeAction(AccessibleAction.SET_TEXT_SELECTION, start, end);
}
private void () {
}
private void () {
}
private void (boolean alignToTop) {
accessible.executeAction(AccessibleAction.SHOW_TEXT_RANGE, start, end);
}
private long[] () {
return new long[0];
}
}