WinWorkstation.st
changeset 4281 e22c313e9ff8
parent 4280 52421b26c983
child 4284 5efcb512f038
--- a/WinWorkstation.st	Tue Sep 21 14:05:29 2004 +0200
+++ b/WinWorkstation.st	Tue Sep 21 21:33:19 2004 +0200
@@ -8305,6 +8305,302 @@
     ^ rootWin
 ! !
 
+!WinWorkstation methodsFor:'clipboard'!
+
+getClipboardData
+    "caveat: for now, only Text is supported"
+
+%{
+    HANDLE hClip;
+    HANDLE hData;
+    OBJ s;
+    unsigned char *src, *p;
+    WIDECHAR *w_src, *w_p;
+
+    /* Unicode */
+    if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
+	int nRemain, len, realLen;
+
+	hClip = OpenClipboard(NULL);
+	if (hClip) {
+	    int needUnicode = 0;
+
+	    hData = GetClipboardData(CF_UNICODETEXT);
+	    w_src = GlobalLock(hData);
+	    len = w_src ? wcslen(w_src) : 0;
+	    /*
+	     * see how much we really need (when CRLF is replaced by LF)
+	     * and if result is really Unicode ...
+	     */
+	    for (realLen=nRemain=len, w_p=w_src; nRemain; ) {
+		WIDECHAR w_ch;
+
+		w_ch = *w_p++; nRemain--;
+		if ((unsigned) w_ch > 0xFF) {
+		    needUnicode = 1;
+		}
+		if (w_ch == 0x0D) {
+		    if (nRemain && (*w_p == 0x0A)) {
+			w_p++; nRemain--;realLen--;
+		    }
+		}
+	    }
+	    if (! needUnicode) {
+		s = __MKEMPTYSTRING(realLen);
+		if (s != nil) {
+		    for (p = __stringVal(s); len; ) {
+			unsigned char ch;
+
+			*p = ch = *w_src++;
+			len--;
+			if (len && (ch == 0x0D) && (*w_src == 0x0A)) {
+			    *p = 0x0A;
+			    w_src++;
+			    len--;
+			}
+			p++;
+		    }
+		}
+	    } else {
+		s = __BYTEARRAY_NEW_INT(realLen * 2);
+		if (s != nil) {
+		    __qClass(s) = @global(UnicodeString);
+		    for (w_p = (WIDECHAR *)__stringVal(s); len; ) {
+			WIDECHAR w_ch;
+
+			*w_p = w_ch = *w_src++;
+			len--;
+			if (len && (w_ch == 0x0D) && (*w_src == 0x0A)) {
+			    *w_p = 0x0A;
+			    w_src++;
+			    len--;
+			}
+			w_p++;
+		    }
+		}
+	    }
+	    GlobalUnlock(hData);
+	    CloseClipboard();
+	    RETURN(s);
+	}
+    }
+
+    /* check for format CF_TEXT */
+    if (IsClipboardFormatAvailable(CF_TEXT)) {
+	int nRemain, len, realLen;
+
+	hClip = OpenClipboard(NULL);
+	if (hClip) {
+	    hData = GetClipboardData(CF_TEXT);
+	    src = GlobalLock(hData);
+	    len = src ? strlen(src) : 0;
+
+	    /* see how much we really need (when CRLF is replaced by LF) */
+	    for (realLen=nRemain=len, p=src; nRemain; ) {
+		unsigned char ch;
+
+		ch = *p++; nRemain--;
+		if (ch == 0x0D) {
+		    if (nRemain && (*p == 0x0A)) {
+			p++; nRemain--;realLen--;
+		    }
+		}
+	    }
+	    s = __MKEMPTYSTRING(realLen);
+	    if (s != nil) {
+		for (p=__stringVal(s); len; ) {
+		    unsigned char ch;
+
+		    *p = ch = *src++;
+		    len--;
+		    if (len && (ch == 0x0D) && (*src == 0x0A)) {
+			*p = 0x0A;
+			src++;
+			len--;
+		    }
+		    p++;
+		}
+	    }
+	    GlobalUnlock(hData);
+	    CloseClipboard();
+	    DDPRINTF((stderr, "WinWorkstation [info]: clipBoard data is <%s>\n", (char *)hData));
+	    RETURN(s);
+	}
+    }
+    RETURN(nil);
+%}
+!
+
+getClipboardObjectFor:drawableId
+    ^ ClipBoardObject
+
+    "Modified: / 30.1.2000 / 02:26:47 / cg"
+!
+
+getClipboardText:selectionBufferSymbol for:drawableId
+    ^ self getCopyBuffer.
+!
+
+getCopyBuffer
+    "return the copyBuffers contents."
+
+    |clip|
+
+    ClipBoardObject notNil ifTrue:[
+        ^ ClipBoardObject
+    ].
+
+    (clip := (self getClipboardData)) notNil ifTrue:[
+        ^ clip
+    ].
+    ^ copyBuffer
+
+    "Created: / 13.7.1999 / 13:15:35 / cg"
+    "Modified: / 30.1.2000 / 12:01:13 / cg"
+!
+
+setClipboardData:aString
+    "caveat: for now, only Text is supported"
+
+%{
+    HANDLE hClip;
+    HANDLE hData;
+
+    if (__isString(aString)) {
+	char *s, *p, *src, *dst;
+	int n, len, realLen;
+
+	hClip = OpenClipboard(NULL);
+	if (hClip) {
+	    s = __stringVal(aString);
+	    /* must replace CR by CRLF */
+	    len = realLen = __stringSize(aString);
+	    for (src=s, n=len; n; n--) {
+		if ((src[0] == 0x0A) && ((src == s) || (src[-1] != 0x0D))) {
+		    realLen++;
+		}
+		src++;
+	    }
+
+	    hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, realLen+1);
+	    if (hData) {
+		char *t = GlobalLock(hData);
+
+		if (t) {
+		    for (src=s, dst=t, n=len; n;) {
+			unsigned char ch;
+
+			ch = src[0]; n--;
+			if ((ch == 0x0A) && ((src == s) || (src[-1] != 0x0D))) {
+			    *dst++ = 0x0D;
+			    *dst++ = 0x0A;
+			} else {
+			    *dst++ = ch;
+			}
+			src++;
+		    }
+		    *dst = 0;
+
+		    EmptyClipboard();
+		    if (SetClipboardData(CF_TEXT, hData) != 0) {
+			/* Note: After setting clipboard data,
+			 * the memory block previously allocated belongs to
+			 * the clipboard - not to the app.
+			 */
+			CloseClipboard();
+			RETURN (true);
+		    }
+		    DPRINTF(("SetClipboardData error:%d\n", GetLastError()));
+		    GlobalUnlock(hData);
+		}
+	    }
+	    CloseClipboard();
+	}
+	RETURN(false);
+    }
+
+    /* Unicode */
+    if (__isWords(aString)) {
+	WIDECHAR *w_s, *w_p, *w_src, *w_dst;
+	int n, len, realLen;
+
+	hClip = OpenClipboard(NULL);
+	if (hClip) {
+	    OBJ cls;
+	    int nInstBytes;
+
+	    cls = __qClass(aString);
+	    nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+	    w_s = (WIDECHAR *)(__stringVal(aString) + nInstBytes);
+
+	    /* must replace CR by CRLF */
+	    len = realLen = (__byteArraySize(aString) - nInstBytes) / 2;
+	    for (w_src=w_s, n=len; n; n--) {
+		if ((w_src[0] == 0x0A) && ((w_src == w_s) || (w_src[-1] != 0x0D))) {
+		    realLen++;
+		}
+		w_src++;
+	    }
+
+	    hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (realLen+1)*sizeof(WIDECHAR));
+	    if (hData) {
+		char *t = GlobalLock(hData);
+
+		if (t) {
+		    for (w_src=w_s, w_dst=t, n=len; n;) {
+			WIDECHAR w_ch;
+
+			w_ch = w_src[0]; n--;
+			if ((w_ch == 0x0A) && ((w_src == w_s) || (w_src[-1] != 0x0D))) {
+			    *w_dst++ = 0x0D;
+			    *w_dst++ = 0x0A;
+			} else {
+			    *w_dst++ = w_ch;
+			}
+			w_src++;
+		    }
+		    *w_dst = 0;
+
+		    EmptyClipboard();
+		    if (SetClipboardData(CF_UNICODETEXT, hData) != 0) {
+			/* Note: After setting clipboard data,
+			 * the memory block previously allocated belongs to
+			 * the clipboard - not to the app.
+			 */
+			CloseClipboard();
+			RETURN (true);
+		    }
+		    DPRINTF(("SetClipboardData error:%d\n", GetLastError()));
+		    GlobalUnlock(hData);
+		}
+	    }
+	    CloseClipboard();
+	}
+	RETURN(false);
+    }
+%}.
+    self primitiveFailed.
+!
+
+setClipboardObject:something owner:drawableId
+    something isString ifTrue:[
+        self setClipboardText:something owner:drawableId.
+        ^ self
+    ].
+    ClipBoardObject := something.
+
+    "Created: / 13.7.1999 / 13:30:37 / cg"
+    "Modified: / 30.1.2000 / 11:59:41 / cg"
+!
+
+setClipboardText:something owner:drawableId
+    ClipBoardObject := nil.
+    ^ self setClipboardData:something
+
+    "Created: / 13.7.1999 / 13:36:43 / cg"
+    "Modified: / 30.1.2000 / 12:12:57 / cg"
+! !
+
 !WinWorkstation methodsFor:'color stuff'!
 
 colorRed:redVal green:greenVal blue:blueVal
@@ -14875,302 +15171,6 @@
     ^ false
 ! !
 
-!WinWorkstation methodsFor:'selections'!
-
-getClipboardData
-    "caveat: for now, only Text is supported"
-
-%{
-    HANDLE hClip;
-    HANDLE hData;
-    OBJ s;
-    unsigned char *src, *p;
-    WIDECHAR *w_src, *w_p;
-
-    /* Unicode */
-    if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
-	int nRemain, len, realLen;
-
-	hClip = OpenClipboard(NULL);
-	if (hClip) {
-	    int needUnicode = 0;
-
-	    hData = GetClipboardData(CF_UNICODETEXT);
-	    w_src = GlobalLock(hData);
-	    len = w_src ? wcslen(w_src) : 0;
-	    /*
-	     * see how much we really need (when CRLF is replaced by LF)
-	     * and if result is really Unicode ...
-	     */
-	    for (realLen=nRemain=len, w_p=w_src; nRemain; ) {
-		WIDECHAR w_ch;
-
-		w_ch = *w_p++; nRemain--;
-		if ((unsigned) w_ch > 0xFF) {
-		    needUnicode = 1;
-		}
-		if (w_ch == 0x0D) {
-		    if (nRemain && (*w_p == 0x0A)) {
-			w_p++; nRemain--;realLen--;
-		    }
-		}
-	    }
-	    if (! needUnicode) {
-		s = __MKEMPTYSTRING(realLen);
-		if (s != nil) {
-		    for (p = __stringVal(s); len; ) {
-			unsigned char ch;
-
-			*p = ch = *w_src++;
-			len--;
-			if (len && (ch == 0x0D) && (*w_src == 0x0A)) {
-			    *p = 0x0A;
-			    w_src++;
-			    len--;
-			}
-			p++;
-		    }
-		}
-	    } else {
-		s = __BYTEARRAY_NEW_INT(realLen * 2);
-		if (s != nil) {
-		    __qClass(s) = @global(UnicodeString);
-		    for (w_p = (WIDECHAR *)__stringVal(s); len; ) {
-			WIDECHAR w_ch;
-
-			*w_p = w_ch = *w_src++;
-			len--;
-			if (len && (w_ch == 0x0D) && (*w_src == 0x0A)) {
-			    *w_p = 0x0A;
-			    w_src++;
-			    len--;
-			}
-			w_p++;
-		    }
-		}
-	    }
-	    GlobalUnlock(hData);
-	    CloseClipboard();
-	    RETURN(s);
-	}
-    }
-
-    /* check for format CF_TEXT */
-    if (IsClipboardFormatAvailable(CF_TEXT)) {
-	int nRemain, len, realLen;
-
-	hClip = OpenClipboard(NULL);
-	if (hClip) {
-	    hData = GetClipboardData(CF_TEXT);
-	    src = GlobalLock(hData);
-	    len = src ? strlen(src) : 0;
-
-	    /* see how much we really need (when CRLF is replaced by LF) */
-	    for (realLen=nRemain=len, p=src; nRemain; ) {
-		unsigned char ch;
-
-		ch = *p++; nRemain--;
-		if (ch == 0x0D) {
-		    if (nRemain && (*p == 0x0A)) {
-			p++; nRemain--;realLen--;
-		    }
-		}
-	    }
-	    s = __MKEMPTYSTRING(realLen);
-	    if (s != nil) {
-		for (p=__stringVal(s); len; ) {
-		    unsigned char ch;
-
-		    *p = ch = *src++;
-		    len--;
-		    if (len && (ch == 0x0D) && (*src == 0x0A)) {
-			*p = 0x0A;
-			src++;
-			len--;
-		    }
-		    p++;
-		}
-	    }
-	    GlobalUnlock(hData);
-	    CloseClipboard();
-	    DDPRINTF((stderr, "WinWorkstation [info]: clipBoard data is <%s>\n", (char *)hData));
-	    RETURN(s);
-	}
-    }
-    RETURN(nil);
-%}
-!
-
-getClipboardObjectFor:drawableId
-    ^ ClipBoardObject
-
-    "Modified: / 30.1.2000 / 02:26:47 / cg"
-!
-
-getClipboardText:selectionBufferSymbol for:drawableId
-    ^ self getCopyBuffer.
-!
-
-getCopyBuffer
-    "return the copyBuffers contents."
-
-    |clip|
-
-    ClipBoardObject notNil ifTrue:[
-        ^ ClipBoardObject
-    ].
-
-    (clip := (self getClipboardData)) notNil ifTrue:[
-        ^ clip
-    ].
-    ^ copyBuffer
-
-    "Created: / 13.7.1999 / 13:15:35 / cg"
-    "Modified: / 30.1.2000 / 12:01:13 / cg"
-!
-
-setClipboardData:aString
-    "caveat: for now, only Text is supported"
-
-%{
-    HANDLE hClip;
-    HANDLE hData;
-
-    if (__isString(aString)) {
-	char *s, *p, *src, *dst;
-	int n, len, realLen;
-
-	hClip = OpenClipboard(NULL);
-	if (hClip) {
-	    s = __stringVal(aString);
-	    /* must replace CR by CRLF */
-	    len = realLen = __stringSize(aString);
-	    for (src=s, n=len; n; n--) {
-		if ((src[0] == 0x0A) && ((src == s) || (src[-1] != 0x0D))) {
-		    realLen++;
-		}
-		src++;
-	    }
-
-	    hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, realLen+1);
-	    if (hData) {
-		char *t = GlobalLock(hData);
-
-		if (t) {
-		    for (src=s, dst=t, n=len; n;) {
-			unsigned char ch;
-
-			ch = src[0]; n--;
-			if ((ch == 0x0A) && ((src == s) || (src[-1] != 0x0D))) {
-			    *dst++ = 0x0D;
-			    *dst++ = 0x0A;
-			} else {
-			    *dst++ = ch;
-			}
-			src++;
-		    }
-		    *dst = 0;
-
-		    EmptyClipboard();
-		    if (SetClipboardData(CF_TEXT, hData) != 0) {
-			/* Note: After setting clipboard data,
-			 * the memory block previously allocated belongs to
-			 * the clipboard - not to the app.
-			 */
-			CloseClipboard();
-			RETURN (true);
-		    }
-		    DPRINTF(("SetClipboardData error:%d\n", GetLastError()));
-		    GlobalUnlock(hData);
-		}
-	    }
-	    CloseClipboard();
-	}
-	RETURN(false);
-    }
-
-    /* Unicode */
-    if (__isWords(aString)) {
-	WIDECHAR *w_s, *w_p, *w_src, *w_dst;
-	int n, len, realLen;
-
-	hClip = OpenClipboard(NULL);
-	if (hClip) {
-	    OBJ cls;
-	    int nInstBytes;
-
-	    cls = __qClass(aString);
-	    nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    w_s = (WIDECHAR *)(__stringVal(aString) + nInstBytes);
-
-	    /* must replace CR by CRLF */
-	    len = realLen = (__byteArraySize(aString) - nInstBytes) / 2;
-	    for (w_src=w_s, n=len; n; n--) {
-		if ((w_src[0] == 0x0A) && ((w_src == w_s) || (w_src[-1] != 0x0D))) {
-		    realLen++;
-		}
-		w_src++;
-	    }
-
-	    hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (realLen+1)*sizeof(WIDECHAR));
-	    if (hData) {
-		char *t = GlobalLock(hData);
-
-		if (t) {
-		    for (w_src=w_s, w_dst=t, n=len; n;) {
-			WIDECHAR w_ch;
-
-			w_ch = w_src[0]; n--;
-			if ((w_ch == 0x0A) && ((w_src == w_s) || (w_src[-1] != 0x0D))) {
-			    *w_dst++ = 0x0D;
-			    *w_dst++ = 0x0A;
-			} else {
-			    *w_dst++ = w_ch;
-			}
-			w_src++;
-		    }
-		    *w_dst = 0;
-
-		    EmptyClipboard();
-		    if (SetClipboardData(CF_UNICODETEXT, hData) != 0) {
-			/* Note: After setting clipboard data,
-			 * the memory block previously allocated belongs to
-			 * the clipboard - not to the app.
-			 */
-			CloseClipboard();
-			RETURN (true);
-		    }
-		    DPRINTF(("SetClipboardData error:%d\n", GetLastError()));
-		    GlobalUnlock(hData);
-		}
-	    }
-	    CloseClipboard();
-	}
-	RETURN(false);
-    }
-%}.
-    self primitiveFailed.
-!
-
-setClipboardObject:something owner:drawableId
-    something isString ifTrue:[
-        self setClipboardText:something owner:drawableId.
-        ^ self
-    ].
-    ClipBoardObject := something.
-
-    "Created: / 13.7.1999 / 13:30:37 / cg"
-    "Modified: / 30.1.2000 / 11:59:41 / cg"
-!
-
-setClipboardText:something owner:drawableId
-    ClipBoardObject := nil.
-    ^ self setClipboardData:something
-
-    "Created: / 13.7.1999 / 13:36:43 / cg"
-    "Modified: / 30.1.2000 / 12:12:57 / cg"
-! !
-
 !WinWorkstation methodsFor:'style defaults'!
 
 defaultStyleValueFor:aKey
@@ -16361,7 +16361,7 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.291 2004-09-21 12:04:27 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.292 2004-09-21 19:33:19 stefan Exp $'
 ! !
 
 WinWorkstation initialize!