summaryrefslogtreecommitdiffstats
path: root/bundles
diff options
context:
space:
mode:
authorGrant Gayed <ggayed>2008-07-15 18:59:28 +0000
committerGrant Gayed <ggayed>2008-07-15 18:59:28 +0000
commitf5f68fabf893d045dff7842a39ab757567d0bd9c (patch)
treed69d01a67b1285494ffc18b59d3aa39e5d5a1e4c /bundles
parent5ee76f68731beca27e439535faff552a72b10741 (diff)
downloadeclipse.platform.swt-f5f68fabf893d045dff7842a39ab757567d0bd9c.tar.gz
eclipse.platform.swt-f5f68fabf893d045dff7842a39ab757567d0bd9c.tar.xz
eclipse.platform.swt-f5f68fabf893d045dff7842a39ab757567d0bd9c.zip
preserve selection after focus loss
Diffstat (limited to 'bundles')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c17
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java1
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java17
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java38
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java7
5 files changed, 74 insertions, 6 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c
index 7a9317d96d..8fa35ddb62 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c
@@ -534,3 +534,20 @@ JNIEXPORT SWT_PTR JNICALL OS_NATIVE(attributedSubstringFromRange_1CALLBACK)
return (SWT_PTR)attributedSubstringFromRangeProc;
}
#endif
+
+#ifndef NO_textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1CALLBACK
+static SWT_PTR textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1CALLBACK;
+static NSRange textView_1willChangeSelectionFromCharacterRange_1toCharacterRange(id obj, SEL sel, NSTextView *aTextView, NSRange oldSelectedCharRange, NSRange newSelectedCharRange)
+{
+ NSRange* ptr = ((NSRange* (*)(id, SEL, NSTextView*, NSRange*, NSRange*))textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1CALLBACK)(obj, sel, aTextView, &oldSelectedCharRange, &newSelectedCharRange);
+ NSRange result = *ptr;
+ free(ptr);
+ return result;
+}
+JNIEXPORT SWT_PTR JNICALL OS_NATIVE(textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1CALLBACK)
+ (JNIEnv *env, jclass that, SWT_PTR func)
+{
+ textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1CALLBACK = func;
+ return (SWT_PTR)textView_1willChangeSelectionFromCharacterRange_1toCharacterRange;
+}
+#endif
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
index 7d5f4a0d36..139c96cdc7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
@@ -372,6 +372,7 @@ public static final native int attributedSubstringFromRange_CALLBACK(int func);
public static final native int setMarkedText_selectedRange_CALLBACK(int func);
public static final native int characterIndexForPoint_CALLBACK(int func);
public static final native int firstRectForCharacterRange_CALLBACK(int func);
+public static final native int textView_willChangeSelectionFromCharacterRange_toCharacterRange_CALLBACK(int func);
public static final native int objc_msgSendSuper(objc_super superId, int sel);
public static final native int objc_msgSendSuper(objc_super superId, int sel, NSRect arg0);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
index b4dca00c9f..bfee7df197 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
@@ -1694,7 +1694,8 @@ void initClasses () {
int attributedSubstringFromRangeProc = OS.attributedSubstringFromRange_CALLBACK(proc3);
int characterIndexForPointProc = OS.characterIndexForPoint_CALLBACK(proc3);
int firstRectForCharacterRangeProc = OS.firstRectForCharacterRange_CALLBACK(proc3);
-
+ int textWillChangeSelectionProc = OS.textView_willChangeSelectionFromCharacterRange_toCharacterRange_CALLBACK(proc5);
+
String className = "SWTWindowDelegate";
int cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0);
OS.class_addIvar(cls, SWT_OBJECT, OS.PTR_SIZEOF, (byte)(Math.log(OS.PTR_SIZEOF) / Math.log(2)), "i");
@@ -1916,6 +1917,8 @@ void initClasses () {
OS.class_addMethod(cls, OS.sel_drawRect_1, drawRectProc, "@:i");
addEventMethods(cls, proc2, proc3);
addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
+ OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_1, proc3, "@:@");
+ OS.class_addMethod(cls, OS.sel_textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
OS.objc_registerClassPair(cls);
className = "SWTSearchField";
@@ -1924,6 +1927,8 @@ void initClasses () {
OS.class_addMethod(cls, OS.sel_drawRect_1, drawRectProc, "@:i");
addEventMethods(cls, proc2, proc3);
addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
+ OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_1, proc3, "@:@");
+ OS.class_addMethod(cls, OS.sel_textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
OS.objc_registerClassPair(cls);
className = "SWTSecureTextField";
@@ -1932,6 +1937,8 @@ void initClasses () {
OS.class_addMethod(cls, OS.sel_drawRect_1, drawRectProc, "@:i");
addEventMethods(cls, proc2, proc3);
addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
+ OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_1, proc3, "@:@");
+ OS.class_addMethod(cls, OS.sel_textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
OS.objc_registerClassPair(cls);
className = "SWTWindow";
@@ -3598,6 +3605,8 @@ int windowDelegateProc(int id, int sel, int arg0) {
widget.pageDown(id, sel, arg0);
} else if (sel == OS.sel_pageUp_1) {
widget.pageUp(id, sel, arg0);
+ } else if (sel == OS.sel_textViewDidChangeSelection_1) {
+ widget.textViewDidChangeSelection(arg0);
} else if (sel == OS.sel_attributedSubstringFromRange_1) {
return widget.attributedSubstringFromRange (id, sel, arg0);
} else if (sel == OS.sel_characterIndexForPoint_1) {
@@ -3651,6 +3660,12 @@ int windowDelegateProc(int delegate, int sel, int arg0, int arg1, int arg2) {
return widget.outlineView_child_ofItem(arg0, arg1, arg2);
} else if (sel == OS.sel_outlineView_1objectValueForTableColumn_1byItem_1) {
return widget.outlineView_objectValueForTableColumn_byItem(arg0, arg1, arg2);
+ } else if (sel == OS.sel_textView_1willChangeSelectionFromCharacterRange_1toCharacterRange_1) {
+ NSRange range = widget.textView_willChangeSelectionFromCharacterRange_toCharacterRange(arg0, arg1, arg2);
+ /* NOTE that this is freed in C */
+ int /*long*/ result = OS.malloc (NSRange.sizeof);
+ OS.memmove (result, range, NSRange.sizeof);
+ return result;
}
return 0;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java
index 33139fee30..973743651c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java
@@ -47,8 +47,9 @@ import org.eclipse.swt.graphics.*;
public class Text extends Scrollable {
int textLimit = LIMIT, tabs = 8;
char echoCharacter;
- boolean doubleClick;
+ boolean doubleClick, receivingFocus;
String hiddenText, message;
+ NSRange selection;
/**
* The maximum number of characters that can be entered
@@ -250,6 +251,13 @@ public void append (String string) {
if (string.length () != 0) sendEvent (SWT.Modify);
}
+boolean becomeFirstResponder (int id, int sel) {
+ receivingFocus = true;
+ boolean result = super.becomeFirstResponder (id, sel);
+ receivingFocus = false;
+ return result;
+}
+
static int checkStyle (int style) {
if ((style & SWT.SEARCH) != 0) {
style |= SWT.SINGLE | SWT.BORDER;
@@ -755,8 +763,8 @@ int getPosition (int x, int y) {
public Point getSelection () {
checkWidget();
if ((style & SWT.SINGLE) != 0) {
-// new NSTextFieldCell(((NSTextField)view).cell()).title().
- return new Point(0, 0);
+ if (selection == null) return new Point(0, 0);
+ return new Point(selection.location, selection.location + selection.length);
} else {
NSTextView widget = (NSTextView)view;
NSRange range = widget.selectedRange();
@@ -777,8 +785,7 @@ public Point getSelection () {
public int getSelectionCount () {
checkWidget();
if ((style & SWT.SINGLE) != 0) {
-// new NSTextFieldCell(((NSTextField)view).cell()).title().
- return -1;
+ return selection != null ? selection.length : 0;
} else {
NSTextView widget = (NSTextView)view;
NSRange range = widget.selectedRange();
@@ -1051,6 +1058,7 @@ public void paste () {
void releaseWidget () {
super.releaseWidget ();
hiddenText = message = null;
+ selection = null;
}
/**
@@ -1628,6 +1636,26 @@ public void showSelection () {
}
}
+void textViewDidChangeSelection(int aNotification) {
+ NSNotification notification = new NSNotification(aNotification);
+ NSText editor = new NSText(notification.object().id);
+ selection = editor.selectedRange();
+}
+
+NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange(int aTextView, int oldSelectedCharRange, int newSelectedCharRange) {
+ /*
+ * If the selection is changing as a result of the receiver getting focus
+ * then return the receiver's last selection range, otherwise the full
+ * text will be automatically selected.
+ */
+ if (receivingFocus && selection != null) return selection;
+
+ /* allow the selection change to proceed */
+ NSRange result = new NSRange();
+ OS.memmove(result, newSelectedCharRange, NSRange.sizeof);
+ return result;
+}
+
int traversalCode (int key, NSEvent theEvent) {
int bits = super.traversalCode (key, theEvent);
if ((style & SWT.READ_ONLY) != 0) return bits;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
index 4d10de8ffd..7b844eeff6 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
@@ -1242,6 +1242,13 @@ boolean tableView_shouldEditTableColumn_row(int aTableView, int aTableColumn, in
void tableView_willDisplayCell_forTableColumn_row(int aTableView, int aCell, int aTableColumn, int rowIndex) {
}
+void textViewDidChangeSelection(int aNotification) {
+}
+
+NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange(int aTextView, int oldSelectedCharRange, int newSelectedCharRange) {
+ return new NSRange();
+}
+
/**
* Returns a string containing a concise, human-readable
* description of the receiver.