WinWorkstation.st
changeset 4811 9b04f5e8a01b
parent 4810 b4be19d40fa8
child 4816 114cf20ad4ed
equal deleted inserted replaced
4810:b4be19d40fa8 4811:9b04f5e8a01b
   673 static HBRUSH __whiteBrush = 0;
   673 static HBRUSH __whiteBrush = 0;
   674 
   674 
   675 static HPEN __bgPen = 0;
   675 static HPEN __bgPen = 0;
   676 static int __bgPenColor = 0;
   676 static int __bgPenColor = 0;
   677 
   677 
   678 #define WM_THREAD_CREATEWINDOW   WM_USER + 0x101
   678 #define WM_THREAD_CREATEWINDOW   (WM_USER + 0x101)
   679 #define WM_THREAD_DESTROYWINDOW  WM_USER + 0x102
   679 #define WM_THREAD_DESTROYWINDOW  (WM_USER + 0x102)
   680 #define WM_THREAD_SETFOCUS       WM_USER + 0x103
   680 #define WM_THREAD_SETFOCUS       (WM_USER + 0x103)
   681 #define WM_THREAD_SETCAPTURE     WM_USER + 0x104
   681 #define WM_THREAD_SETCAPTURE     (WM_USER + 0x104)
   682 #define WM_THREAD_SETCURSOR      WM_USER + 0x105
   682 #define WM_THREAD_SETCURSOR      (WM_USER + 0x105)
   683 #define WM_THREAD_BEEP           WM_USER + 0x106
   683 #define WM_THREAD_BEEP           (WM_USER + 0x106)
       
   684 
       
   685 #define WM_TRAY_MESSAGE          (WM_USER + 0x200)
   684 
   686 
   685 #define hasEventQueued() (eventQueueHead != NULL)
   687 #define hasEventQueued() (eventQueueHead != NULL)
   686 #define EVENT_THREAD_STACKSIZE  (4096*10)
   688 #define EVENT_THREAD_STACKSIZE  (4096*10)
   687 
   689 
   688 typedef int (*intf)(int);
   690 typedef int (*intf)(int);
  7990 	  style:wStyle inputOnly:winputOnly
  7992 	  style:wStyle inputOnly:winputOnly
  7991 	  label:wlabel owner:wowner
  7993 	  label:wlabel owner:wowner
  7992 	  icon:wicon iconMask:wiconMask
  7994 	  icon:wicon iconMask:wiconMask
  7993 	  moreArgs:moreArgs
  7995 	  moreArgs:moreArgs
  7994 
  7996 
  7995 %{
  7997 %{  /* STACK: 16000 */
  7996 
  7998 
  7997     WNDCLASS wc;
  7999     WNDCLASS wc;
  7998     long bg, bd, bw;
  8000     long bg, bd, bw;
  7999     int winStyleBits, winEXStyleBits;
  8001     int winStyleBits, winEXStyleBits;
  8000     int w, h, x, y;
  8002     int w, h, x, y;
  8698 
  8700 
  8699     |currentSequenceNumber|
  8701     |currentSequenceNumber|
  8700 
  8702 
  8701     currentSequenceNumber := self getClipboardSequenceNumber.
  8703     currentSequenceNumber := self getClipboardSequenceNumber.
  8702     lastClipboardSequenceNumber ~= currentSequenceNumber ifTrue:[
  8704     lastClipboardSequenceNumber ~= currentSequenceNumber ifTrue:[
  8703         "copyBuffer is invalid, fill it from the windows clipboard.
  8705 	"copyBuffer is invalid, fill it from the windows clipboard.
  8704          Even if we could not decode the windows clipboard,
  8706 	 Even if we could not decode the windows clipboard,
  8705          we intentionally set the copyBuffer to nil to get a consistent
  8707 	 we intentionally set the copyBuffer to nil to get a consistent
  8706          behavior."
  8708 	 behavior."
  8707         copyBuffer := self getClipboardData.
  8709 	copyBuffer := self getClipboardData.
  8708         lastClipboardSequenceNumber := currentSequenceNumber.
  8710 	lastClipboardSequenceNumber := currentSequenceNumber.
  8709     ].
  8711     ].
  8710     ^ self copyBufferAsString
  8712     ^ self copyBufferAsString
  8711 
  8713 
  8712     "
  8714     "
  8713      Screen current getClipboardText:#clipboard for:nil
  8715      Screen current getClipboardText:#clipboard for:nil
  8783     unsigned char *src, *p;
  8785     unsigned char *src, *p;
  8784     WIDECHAR *w_src, *w_p;
  8786     WIDECHAR *w_src, *w_p;
  8785     int fmt;
  8787     int fmt;
  8786 
  8788 
  8787     if (format == @symbol(CF_TIFF)) {
  8789     if (format == @symbol(CF_TIFF)) {
  8788         fmt = CF_TIFF;
  8790 	fmt = CF_TIFF;
  8789     } else if (format == @symbol(CF_BITMAP)) {
  8791     } else if (format == @symbol(CF_BITMAP)) {
  8790         fmt = CF_BITMAP;
  8792 	fmt = CF_BITMAP;
  8791     } else if (format == @symbol(CF_DIB)) {
  8793     } else if (format == @symbol(CF_DIB)) {
  8792         fmt = CF_DIB;
  8794 	fmt = CF_DIB;
  8793     } else 
  8795     } else
  8794         goto badFormat;
  8796 	goto badFormat;
  8795 
  8797 
  8796     if (IsClipboardFormatAvailable(fmt)) {
  8798     if (IsClipboardFormatAvailable(fmt)) {
  8797         int len;
  8799 	int len;
  8798 
  8800 
  8799         hClip = OpenClipboard(NULL);
  8801 	hClip = OpenClipboard(NULL);
  8800         if (hClip) {
  8802 	if (hClip) {
  8801             hData = GetClipboardData(fmt);
  8803 	    hData = GetClipboardData(fmt);
  8802             if (hData) {
  8804 	    if (hData) {
  8803                 len = GlobalSize(hData);
  8805 		len = GlobalSize(hData);
  8804                 src = GlobalLock(hData);
  8806 		src = GlobalLock(hData);
  8805                 if (src) {
  8807 		if (src) {
  8806                     bytes = __MKBYTEARRAY(src, len);
  8808 		    bytes = __MKBYTEARRAY(src, len);
  8807                 }
  8809 		}
  8808                 GlobalUnlock(hData);
  8810 		GlobalUnlock(hData);
  8809                 CloseClipboard();
  8811 		CloseClipboard();
  8810                 DDPRINTF((stderr, "WinWorkstation [info]: clipBoard data size is <%d>\n", len));
  8812 		DDPRINTF((stderr, "WinWorkstation [info]: clipBoard data size is <%d>\n", len));
  8811                 RETURN(bytes);
  8813 		RETURN(bytes);
  8812             }
  8814 	    }
  8813         }
  8815 	}
  8814     }
  8816     }
  8815 badFormat: ;
  8817 badFormat: ;
  8816 %}.
  8818 %}.
  8817     ^ nil
  8819     ^ nil
  8818 
  8820 
  8819     "
  8821     "
  8820      Screen current getClipboardDataBytes:#CF_TIFF   
  8822      Screen current getClipboardDataBytes:#CF_TIFF
  8821      Screen current getClipboardDataBytes:#CF_BITMAP   
  8823      Screen current getClipboardDataBytes:#CF_BITMAP
  8822      Screen current getClipboardDataBytes:#CF_DIB   
  8824      Screen current getClipboardDataBytes:#CF_DIB
  8823     "
  8825     "
  8824 
  8826 
  8825     "Created: / 09-10-2007 / 13:11:12 / cg"
  8827     "Created: / 09-10-2007 / 13:11:12 / cg"
  8826     "Modified: / 09-10-2007 / 14:18:26 / cg"
  8828     "Modified: / 09-10-2007 / 14:18:26 / cg"
  8827 !
  8829 !
  8862      Answer an image on success or nil otherwise."
  8864      Answer an image on success or nil otherwise."
  8863 
  8865 
  8864     |data|
  8866     |data|
  8865 
  8867 
  8866     (data := self getClipboardDataBytes:#CF_TIFF) notNil ifTrue:[
  8868     (data := self getClipboardDataBytes:#CF_TIFF) notNil ifTrue:[
  8867         "/ tiff image in data...
  8869 	"/ tiff image in data...
  8868         ^ "TIFFReader fromBytes:data" nil
  8870 	^ "TIFFReader fromBytes:data" nil
  8869     ].
  8871     ].
  8870     (data := self getClipboardDataBytes:#CF_DIB) notNil ifTrue:[
  8872     (data := self getClipboardDataBytes:#CF_DIB) notNil ifTrue:[
  8871         "/ device independent bitmap image in data...
  8873 	"/ device independent bitmap image in data...
  8872         ^ "TIFFReader fromBytes:data" nil
  8874 	^ "TIFFReader fromBytes:data" nil
  8873     ].
  8875     ].
  8874     ^ nil
  8876     ^ nil
  8875 
  8877 
  8876     "Created: / 09-10-2007 / 14:19:53 / cg"
  8878     "Created: / 09-10-2007 / 14:19:53 / cg"
  8877 !
  8879 !
  8888     unsigned char *src, *p;
  8890     unsigned char *src, *p;
  8889     WIDECHAR *w_src, *w_p;
  8891     WIDECHAR *w_src, *w_p;
  8890 
  8892 
  8891     /* check for format CF_TEXT */
  8893     /* check for format CF_TEXT */
  8892     if (IsClipboardFormatAvailable(CF_TEXT)) {
  8894     if (IsClipboardFormatAvailable(CF_TEXT)) {
  8893         int nRemain, len, realLen;
  8895 	int nRemain, len, realLen;
  8894 
  8896 
  8895         hClip = OpenClipboard(NULL);
  8897 	hClip = OpenClipboard(NULL);
  8896         if (hClip) {
  8898 	if (hClip) {
  8897             hData = GetClipboardData(CF_TEXT);
  8899 	    hData = GetClipboardData(CF_TEXT);
  8898             src = GlobalLock(hData);
  8900 	    src = GlobalLock(hData);
  8899             len = src ? strlen(src) : 0;
  8901 	    len = src ? strlen(src) : 0;
  8900 
  8902 
  8901             /* see how much we really need (when CRLF is replaced by LF) */
  8903 	    /* see how much we really need (when CRLF is replaced by LF) */
  8902             for (realLen=nRemain=len, p=src; nRemain; ) {
  8904 	    for (realLen=nRemain=len, p=src; nRemain; ) {
  8903                 unsigned char ch;
  8905 		unsigned char ch;
  8904 
  8906 
  8905                 ch = *p++; nRemain--;
  8907 		ch = *p++; nRemain--;
  8906                 if (ch == 0x0D) {
  8908 		if (ch == 0x0D) {
  8907                     if (nRemain && (*p == 0x0A)) {
  8909 		    if (nRemain && (*p == 0x0A)) {
  8908                         p++; nRemain--;realLen--;
  8910 			p++; nRemain--;realLen--;
  8909                     }
  8911 		    }
  8910                 }
  8912 		}
  8911             }
  8913 	    }
  8912             s = __MKEMPTYSTRING(realLen);
  8914 	    s = __MKEMPTYSTRING(realLen);
  8913             if (s != nil) {
  8915 	    if (s != nil) {
  8914                 for (p=__stringVal(s); len; ) {
  8916 		for (p=__stringVal(s); len; ) {
  8915                     unsigned char ch;
  8917 		    unsigned char ch;
  8916 
  8918 
  8917                     *p = ch = *src++;
  8919 		    *p = ch = *src++;
  8918                     len--;
  8920 		    len--;
  8919                     if (len && (ch == 0x0D) && (*src == 0x0A)) {
  8921 		    if (len && (ch == 0x0D) && (*src == 0x0A)) {
  8920                         *p = 0x0A;
  8922 			*p = 0x0A;
  8921                         src++;
  8923 			src++;
  8922                         len--;
  8924 			len--;
  8923                     }
  8925 		    }
  8924                     p++;
  8926 		    p++;
  8925                 }
  8927 		}
  8926             }
  8928 	    }
  8927             GlobalUnlock(hData);
  8929 	    GlobalUnlock(hData);
  8928             CloseClipboard();
  8930 	    CloseClipboard();
  8929             DDPRINTF((stderr, "WinWorkstation [info]: clipBoard data is <%s>\n", (char *)hData));
  8931 	    DDPRINTF((stderr, "WinWorkstation [info]: clipBoard data is <%s>\n", (char *)hData));
  8930             RETURN(s);
  8932 	    RETURN(s);
  8931         }
  8933 	}
  8932     }
  8934     }
  8933 %}.
  8935 %}.
  8934     ^ nil
  8936     ^ nil
  8935 
  8937 
  8936     "Created: / 09-10-2007 / 12:46:00 / cg"
  8938     "Created: / 09-10-2007 / 12:46:00 / cg"
  8948     unsigned char *src, *p;
  8950     unsigned char *src, *p;
  8949     WIDECHAR *w_src, *w_p;
  8951     WIDECHAR *w_src, *w_p;
  8950 
  8952 
  8951     /* Unicode */
  8953     /* Unicode */
  8952     if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
  8954     if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
  8953         int nRemain, len, realLen;
  8955 	int nRemain, len, realLen;
  8954 
  8956 
  8955         hClip = OpenClipboard(NULL);
  8957 	hClip = OpenClipboard(NULL);
  8956         if (hClip) {
  8958 	if (hClip) {
  8957             int needUnicode = 0;
  8959 	    int needUnicode = 0;
  8958 
  8960 
  8959             hData = GetClipboardData(CF_UNICODETEXT);
  8961 	    hData = GetClipboardData(CF_UNICODETEXT);
  8960             w_src = GlobalLock(hData);
  8962 	    w_src = GlobalLock(hData);
  8961             len = w_src ? wcslen(w_src) : 0;
  8963 	    len = w_src ? wcslen(w_src) : 0;
  8962             /*
  8964 	    /*
  8963              * see how much we really need (when CRLF is replaced by LF)
  8965 	     * see how much we really need (when CRLF is replaced by LF)
  8964              * and if result is really Unicode ...
  8966 	     * and if result is really Unicode ...
  8965              */
  8967 	     */
  8966             for (realLen=nRemain=len, w_p=w_src; nRemain; ) {
  8968 	    for (realLen=nRemain=len, w_p=w_src; nRemain; ) {
  8967                 WIDECHAR w_ch;
  8969 		WIDECHAR w_ch;
  8968 
  8970 
  8969                 w_ch = *w_p++; nRemain--;
  8971 		w_ch = *w_p++; nRemain--;
  8970                 if ((unsigned) w_ch > 0xFF) {
  8972 		if ((unsigned) w_ch > 0xFF) {
  8971                     needUnicode = 1;
  8973 		    needUnicode = 1;
  8972                 }
  8974 		}
  8973                 if (w_ch == 0x0D) {
  8975 		if (w_ch == 0x0D) {
  8974                     if (nRemain && (*w_p == 0x0A)) {
  8976 		    if (nRemain && (*w_p == 0x0A)) {
  8975                         w_p++; nRemain--;realLen--;
  8977 			w_p++; nRemain--;realLen--;
  8976                     }
  8978 		    }
  8977                 }
  8979 		}
  8978             }
  8980 	    }
  8979             if (! needUnicode) {
  8981 	    if (! needUnicode) {
  8980                 s = __MKEMPTYSTRING(realLen);
  8982 		s = __MKEMPTYSTRING(realLen);
  8981                 if (s != nil) {
  8983 		if (s != nil) {
  8982                     for (p = __stringVal(s); len; ) {
  8984 		    for (p = __stringVal(s); len; ) {
  8983                         unsigned char ch;
  8985 			unsigned char ch;
  8984 
  8986 
  8985                         *p = ch = *w_src++;
  8987 			*p = ch = *w_src++;
  8986                         len--;
  8988 			len--;
  8987                         if (len && (ch == 0x0D) && (*w_src == 0x0A)) {
  8989 			if (len && (ch == 0x0D) && (*w_src == 0x0A)) {
  8988                             *p = 0x0A;
  8990 			    *p = 0x0A;
  8989                             w_src++;
  8991 			    w_src++;
  8990                             len--;
  8992 			    len--;
  8991                         }
  8993 			}
  8992                         p++;
  8994 			p++;
  8993                     }
  8995 		    }
  8994                 }
  8996 		}
  8995             } else {
  8997 	    } else {
  8996                 s = __BYTEARRAY_NEW_INT(realLen * 2);
  8998 		s = __BYTEARRAY_NEW_INT(realLen * 2);
  8997                 if (s != nil) {
  8999 		if (s != nil) {
  8998                     __qClass(s) = @global(UnicodeString);
  9000 		    __qClass(s) = @global(UnicodeString);
  8999                     for (w_p = (WIDECHAR *)__stringVal(s); len; ) {
  9001 		    for (w_p = (WIDECHAR *)__stringVal(s); len; ) {
  9000                         WIDECHAR w_ch;
  9002 			WIDECHAR w_ch;
  9001 
  9003 
  9002                         *w_p = w_ch = *w_src++;
  9004 			*w_p = w_ch = *w_src++;
  9003                         len--;
  9005 			len--;
  9004                         if (len && (w_ch == 0x0D) && (*w_src == 0x0A)) {
  9006 			if (len && (w_ch == 0x0D) && (*w_src == 0x0A)) {
  9005                             *w_p = 0x0A;
  9007 			    *w_p = 0x0A;
  9006                             w_src++;
  9008 			    w_src++;
  9007                             len--;
  9009 			    len--;
  9008                         }
  9010 			}
  9009                         w_p++;
  9011 			w_p++;
  9010                     }
  9012 		    }
  9011                 }
  9013 		}
  9012             }
  9014 	    }
  9013             GlobalUnlock(hData);
  9015 	    GlobalUnlock(hData);
  9014             CloseClipboard();
  9016 	    CloseClipboard();
  9015             RETURN(s);
  9017 	    RETURN(s);
  9016         }
  9018 	}
  9017     }
  9019     }
  9018 %}.
  9020 %}.
  9019     ^ nil
  9021     ^ nil
  9020 
  9022 
  9021     "Created: / 09-10-2007 / 12:45:26 / cg"
  9023     "Created: / 09-10-2007 / 12:45:26 / cg"
 17382 ! !
 17384 ! !
 17383 
 17385 
 17384 !WinWorkstation class methodsFor:'documentation'!
 17386 !WinWorkstation class methodsFor:'documentation'!
 17385 
 17387 
 17386 version
 17388 version
 17387     ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.347 2007-10-30 15:52:03 cg Exp $'
 17389     ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.348 2007-10-30 15:54:44 cg Exp $'
 17388 ! !
 17390 ! !
 17389 
 17391 
 17390 WinWorkstation initialize!
 17392 WinWorkstation initialize!