diff options
author | Silenio Quarti | 2007-05-17 21:30:12 +0000 |
---|---|---|
committer | Silenio Quarti | 2007-05-17 21:30:12 +0000 |
commit | bc9956a6f967a96697e77f5ed7831350af3db840 (patch) | |
tree | 7b310919d291c5fdc4ae6d037d06ff3ff0a31891 | |
parent | 3f47a755266664610448138701a2636b542036e6 (diff) | |
download | eclipse.platform.swt-bc9956a6f967a96697e77f5ed7831350af3db840.tar.gz eclipse.platform.swt-bc9956a6f967a96697e77f5ed7831350af3db840.tar.xz eclipse.platform.swt-bc9956a6f967a96697e77f5ed7831350af3db840.zip |
185607 - Can't copy and paste into dialog text fields from some applicationsv3344c
4 files changed, 52 insertions, 57 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java index e4e210012b..15c460252a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java @@ -438,15 +438,7 @@ public void copy () { checkWidget (); Point selection = getSelection (); if (selection.x == selection.y) return; - copy (getText (selection.x, selection.y)); -} - -void copy (char [] buffer) { - if (buffer.length == 0) return; - OS.ClearCurrentScrap (); - int [] scrap = new int [1]; - OS.GetCurrentScrap (scrap); - OS.PutScrapFlavor (scrap [0], OS.kScrapFlavorTypeUnicode, 0, buffer.length * 2, buffer); + copyToClipboard (getText (selection.x, selection.y)); } void createHandle () { @@ -517,7 +509,7 @@ public void cut () { } char [] buffer = new char [newText.length ()]; newText.getChars (0, buffer.length, buffer, 0); - copy (buffer); + copyToClipboard (buffer); setText (leftText + newText + rightText, false); start += newText.length (); setSelection (new Point (start, start)); @@ -934,16 +926,6 @@ public int indexOf (String string, int start) { return -1; } -String getClipboardText () { - int [] scrap = new int [1]; - OS.GetCurrentScrap (scrap); - int [] size = new int [1]; - if (OS.GetScrapFlavorSize (scrap [0], OS.kScrapFlavorTypeUnicode, size) != OS.noErr || size [0] == 0) return ""; - char [] buffer = new char [size [0] / 2]; - if (OS.GetScrapFlavorData (scrap [0], OS.kScrapFlavorTypeUnicode, size, buffer) != OS.noErr) return ""; - return new String (buffer); -} - int getCharCount () { // checkWidget (); int [] ptr = new int [1]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Spinner.java index 81094a705f..e2b54f95a0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Spinner.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Spinner.java @@ -273,15 +273,7 @@ public void copy () { char [] buffer= new char [range.length]; OS.CFStringGetCharacters (ptr [0], range, buffer); OS.CFRelease (ptr [0]); - copy (buffer); -} - -void copy (char [] buffer) { - if (buffer.length == 0) return; - OS.ClearCurrentScrap (); - int [] scrap = new int [1]; - OS.GetCurrentScrap (scrap); - OS.PutScrapFlavor (scrap [0], OS.kScrapFlavorTypeUnicode, 0, buffer.length * 2, buffer); + copyToClipboard (buffer); } void createHandle () { @@ -328,7 +320,7 @@ public void cut () { if (selection [0] == selection [1]) return; char [] buffer = setText ("", selection [0], selection [1], true); if (buffer != null) { - copy (buffer); + copyToClipboard (buffer); } } @@ -610,15 +602,10 @@ int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) { public void paste () { checkWidget (); if ((style & SWT.READ_ONLY) != 0) return; - int [] scrap = new int [1]; - OS.GetCurrentScrap (scrap); - int [] size = new int [1]; - if (OS.GetScrapFlavorSize (scrap [0], OS.kScrapFlavorTypeUnicode, size) != OS.noErr || size [0] == 0) return; - char [] buffer = new char [size [0] / 2]; - if (OS.GetScrapFlavorData (scrap [0], OS.kScrapFlavorTypeUnicode, size, buffer) != OS.noErr) return; + String text = getClipboardText (); short [] selection = new short [2]; if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) != OS.noErr) return; - setText (new String (buffer), selection [0], selection [1], true); + setText (text, selection [0], selection [1], true); } public void redraw () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java index f53c4fd4af..46151b7db5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java @@ -457,20 +457,12 @@ public void copy () { if (txnObject == 0) { Point selection = getSelection (); if (selection.x == selection.y) return; - copy (getEditText (selection.x, selection.y - 1)); + copyToClipboard (getEditText (selection.x, selection.y - 1)); } else { OS.TXNCopy (txnObject); } } -void copy (char [] buffer) { - if (buffer.length == 0) return; - OS.ClearCurrentScrap (); - int [] scrap = new int [1]; - OS.GetCurrentScrap (scrap); - OS.PutScrapFlavor (scrap [0], OS.kScrapFlavorTypeUnicode, 0, buffer.length * 2, buffer); -} - void createHandle () { int [] outControl = new int [1]; if ((style & SWT.MULTI) != 0 || (style & (SWT.BORDER | SWT.SEARCH)) == 0) { @@ -598,7 +590,7 @@ public void cut () { if (cut) { if (txnObject == 0) { if (oldText == null) oldText = getEditText (oldSelection.x, oldSelection.y - 1); - copy (oldText); + copyToClipboard (oldText); insertEditText (""); } else { OS.TXNCut (txnObject); @@ -743,16 +735,6 @@ public int getCharCount () { return OS.TXNDataSize (txnObject) / 2; } -String getClipboardText () { - int [] scrap = new int [1]; - OS.GetCurrentScrap (scrap); - int [] size = new int [1]; - if (OS.GetScrapFlavorSize (scrap [0], OS.kScrapFlavorTypeUnicode, size) != OS.noErr || size [0] == 0) return ""; - char [] buffer = new char [size [0] / 2]; - if (OS.GetScrapFlavorData (scrap [0], OS.kScrapFlavorTypeUnicode, size, buffer) != OS.noErr) return ""; - return new String (buffer); -} - /** * Returns the double click enabled flag. * <p> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java index a7a9fc66ee..75055c0220 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java @@ -12,6 +12,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.carbon.CFRange; import org.eclipse.swt.internal.carbon.CGRect; import org.eclipse.swt.internal.carbon.OS; import org.eclipse.swt.internal.carbon.RGBColor; @@ -381,6 +382,14 @@ int accessibilityProc (int nextHandler, int theEvent, int userData) { return OS.eventNotHandledErr; } +void copyToClipboard (char [] buffer) { + if (buffer.length == 0) return; + OS.ClearCurrentScrap (); + int [] scrap = new int [1]; + OS.GetCurrentScrap (scrap); + OS.PutScrapFlavor (scrap [0], OS.kScrapFlavorTypeUnicode, 0, buffer.length * 2, buffer); +} + int createCIcon (Image image) { int imageHandle = image.handle; int width = OS.CGImageGetWidth(imageHandle); @@ -679,6 +688,41 @@ int fixMnemonic (char [] buffer) { return j; } +String getClipboardText () { + String result = ""; + int [] scrap = new int [1]; + OS.GetCurrentScrap (scrap); + int [] size = new int [1]; + if (OS.GetScrapFlavorSize (scrap [0], OS.kScrapFlavorTypeUnicode, size) == OS.noErr) { + if (size [0] != 0) { + char [] buffer = new char [size [0] / 2]; + if (OS.GetScrapFlavorData (scrap [0], OS.kScrapFlavorTypeUnicode, size, buffer) == OS.noErr) { + result = new String (buffer); + } + } + } else if (OS.GetScrapFlavorSize (scrap [0], OS.kScrapFlavorTypeText, size) == OS.noErr) { + if (size [0] != 0) { + byte [] buffer = new byte [size [0]]; + if (OS.GetScrapFlavorData (scrap [0], OS.kScrapFlavorTypeText, size, buffer) == OS.noErr) { + int encoding = OS.CFStringGetSystemEncoding(); + int cfstring = OS.CFStringCreateWithBytes(OS.kCFAllocatorDefault, buffer, buffer.length, encoding, true); + if (cfstring != 0) { + int length = OS.CFStringGetLength(cfstring); + if (length != 0) { + char[] chars = new char[length]; + CFRange range = new CFRange(); + range.length = length; + OS.CFStringGetCharacters(cfstring, range, chars); + result = new String(chars); + } + OS.CFRelease(cfstring); + } + } + } + } + return result; +} + Rectangle getControlBounds (int control) { CGRect rect = new CGRect (); OS.HIViewGetFrame (control, rect); |