XWorkstation.st
changeset 5033 27bc058343f0
parent 4928 4e457b74f5d2
child 5034 c2e7d8a07da8
equal deleted inserted replaced
5032:93bc49567a43 5033:27bc058343f0
  2806     |msgType dropColl dropCollSize anyFile anyDir anyText anyOther
  2806     |msgType dropColl dropCollSize anyFile anyDir anyText anyOther
  2807      dropType dropTypeCode strings sz idx val|
  2807      dropType dropTypeCode strings sz idx val|
  2808 
  2808 
  2809     (msgType := self atomIDOf:#DndProtocol) notNil ifTrue:[
  2809     (msgType := self atomIDOf:#DndProtocol) notNil ifTrue:[
  2810 
  2810 
  2811 	"/ DND can drop files, file, dir, links, dirLink and text
  2811         "/ DND can drop files, file, dir, links, dirLink and text
  2812 	"/ check for this.
  2812         "/ check for this.
  2813 
  2813 
  2814 	dropObjects isCollection ifFalse:[
  2814         dropObjects isCollection ifFalse:[
  2815 	    dropColl := Array with:dropObjects
  2815             dropColl := Array with:dropObjects
  2816 	] ifTrue:[
  2816         ] ifTrue:[
  2817 	    dropColl := dropObjects
  2817             dropColl := dropObjects
  2818 	].
  2818         ].
  2819 	anyFile := anyDir := anyText := anyOther := false.
  2819         anyFile := anyDir := anyText := anyOther := false.
  2820 	dropColl do:[:aDropObject |
  2820         dropColl do:[:aDropObject |
  2821 	    aDropObject isFileObject ifTrue:[
  2821             aDropObject isFileObject ifTrue:[
  2822 		aDropObject theObject isDirectory ifTrue:[
  2822                 aDropObject theObject isDirectory ifTrue:[
  2823 		    anyDir := true
  2823                     anyDir := true
  2824 		] ifFalse:[
  2824                 ] ifFalse:[
  2825 		    anyFile := true
  2825                     anyFile := true
  2826 		]
  2826                 ]
  2827 	    ] ifFalse:[
  2827             ] ifFalse:[
  2828 		aDropObject isTextObject ifTrue:[
  2828                 aDropObject isTextObject ifTrue:[
  2829 		    anyText := true
  2829                     anyText := true
  2830 		] ifFalse:[
  2830                 ] ifFalse:[
  2831 		    anyOther := true
  2831                     anyOther := true
  2832 		]
  2832                 ]
  2833 	    ]
  2833             ]
  2834 	].
  2834         ].
  2835 
  2835 
  2836 	anyOther ifTrue:[
  2836         anyOther ifTrue:[
  2837 	    "/ DND does not support this ...
  2837             "/ DND does not support this ...
  2838 	    'XWorkstation [info]: DND can only drop files or text' infoPrintCR.
  2838             'XWorkstation [info]: DND can only drop files or text' infoPrintCR.
  2839 	    ^ false
  2839             ^ false
  2840 	].
  2840         ].
  2841 	anyText ifTrue:[
  2841         anyText ifTrue:[
  2842 	    (anyFile or:[anyDir]) ifTrue:[
  2842             (anyFile or:[anyDir]) ifTrue:[
  2843 		"/ DND does not support mixed types
  2843                 "/ DND does not support mixed types
  2844 		'XWorkstation [info]: DND cannot drop both files and text' infoPrintCR.
  2844                 'XWorkstation [info]: DND cannot drop both files and text' infoPrintCR.
  2845 		^ false
  2845                 ^ false
  2846 	    ]
  2846             ]
  2847 	].
  2847         ].
  2848 
  2848 
  2849 	dropCollSize := dropColl size.
  2849         dropCollSize := dropColl size.
  2850 	anyFile ifTrue:[
  2850         anyFile ifTrue:[
  2851 	    dropType := #DndFiles.
  2851             dropType := #DndFiles.
  2852 	    dropCollSize == 1 ifTrue:[
  2852             dropCollSize == 1 ifTrue:[
  2853 		dropType := #DndFile
  2853                 dropType := #DndFile
  2854 	    ]
  2854             ]
  2855 	] ifFalse:[
  2855         ] ifFalse:[
  2856 	    anyDir ifTrue:[
  2856             anyDir ifTrue:[
  2857 		dropType := #DndFiles.
  2857                 dropType := #DndFiles.
  2858 		dropCollSize == 1 ifTrue:[
  2858                 dropCollSize == 1 ifTrue:[
  2859 		    dropType := #DndDir
  2859                     dropType := #DndDir
  2860 		]
  2860                 ]
  2861 	    ] ifFalse:[
  2861             ] ifFalse:[
  2862 		anyText ifTrue:[
  2862                 anyText ifTrue:[
  2863 		    dropCollSize == 1 ifTrue:[
  2863                     dropCollSize == 1 ifTrue:[
  2864 			dropType := #DndText
  2864                         dropType := #DndText
  2865 		    ] ifFalse:[
  2865                     ] ifFalse:[
  2866 			"/ can only drop a single text object
  2866                         "/ can only drop a single text object
  2867 			'XWorkstation [info]: DND can only drop a single text' infoPrintCR.
  2867                         'XWorkstation [info]: DND can only drop a single text' infoPrintCR.
  2868 			^ false
  2868                         ^ false
  2869 		    ]
  2869                     ]
  2870 		] ifFalse:[
  2870                 ] ifFalse:[
  2871 		    "/ mhmh ...
  2871                     "/ mhmh ...
  2872 		    'XWorkstation [info]: DND cannot drop this' infoPrintCR.
  2872                     'XWorkstation [info]: DND cannot drop this' infoPrintCR.
  2873 		    ^ false
  2873                     ^ false
  2874 		]
  2874                 ]
  2875 	    ]
  2875             ]
  2876 	].
  2876         ].
  2877 
  2877 
  2878 	dropTypeCode := self dndDropTypes indexOf:dropType.
  2878         dropTypeCode := self dndDropTypes indexOf:dropType.
  2879 	dropTypeCode == 0 ifTrue:[
  2879         dropTypeCode == 0 ifTrue:[
  2880 	    'XWorkstation [info]: DND cannot drop this' infoPrintCR.
  2880             'XWorkstation [info]: DND cannot drop this' infoPrintCR.
  2881 	    ^ false
  2881             ^ false
  2882 	].
  2882         ].
  2883 	dropTypeCode := dropTypeCode - 1.
  2883         dropTypeCode := dropTypeCode - 1.
  2884 
  2884 
  2885 
  2885 
  2886 	"/ place the selection inTo the DndSelection property
  2886         "/ place the selection inTo the DndSelection property
  2887 	"/ of the rootView ...
  2887         "/ of the rootView ...
  2888 	"/ ... need a single string, with 0-terminated parts.
  2888         "/ ... need a single string, with 0-terminated parts.
  2889 
  2889 
  2890 	strings := OrderedCollection new.
  2890         strings := OrderedCollection new.
  2891 	sz := 0.
  2891         sz := 0.
  2892 	dropColl do:[:anObject |
  2892         dropColl do:[:anObject |
  2893 	    |s o|
  2893             |s o|
  2894 
  2894 
  2895 	    o := anObject theObject.
  2895             o := anObject theObject.
  2896 	    anObject isFileObject ifTrue:[
  2896             anObject isFileObject ifTrue:[
  2897 		o := o pathName
  2897                 o := o pathName
  2898 	    ].
  2898             ].
  2899 	    s := o asString.
  2899             s := o asString.
  2900 	    strings add:s.
  2900             strings add:s.
  2901 	    sz := sz + (s size) + 1.
  2901             sz := sz + (s size) + 1.
  2902 	].
  2902         ].
  2903 	val := String new:sz.
  2903         val := String new:sz.
  2904 	idx := 1.
  2904         idx := 1.
  2905 	strings do:[:aString |
  2905         strings do:[:aString |
  2906 	    |sz|
  2906             |sz|
  2907 
  2907 
  2908 	    sz := aString size.
  2908             sz := aString size.
  2909 	    val replaceFrom:idx to:(idx + sz - 1) with:aString startingAt:1.
  2909             val replaceFrom:idx to:(idx + sz - 1) with:aString startingAt:1.
  2910 	    idx := idx + sz.
  2910             idx := idx + sz.
  2911 	    val at:idx put:(Character value:0).
  2911             val at:idx put:(Character value:0).
  2912 	    idx := idx + 1
  2912             idx := idx + 1
  2913 	].
  2913         ].
  2914 
  2914 
  2915 	self
  2915         self
  2916 	    setProperty:(self atomIDOf:#DndSelection)
  2916             setProperty:(self atomIDOf:#DndSelection)
  2917 	    type:(self atomIDOf:#STRING)
  2917             type:(self atomIDOf:#STRING)
  2918 	    value:val
  2918             value:val
  2919 	    for:rootId.
  2919             for:rootId.
  2920 
  2920 
  2921 	^ self
  2921         ^ self
  2922 	    sendClientEvent:msgType
  2922             sendClientEvent:msgType
  2923 	    format:32
  2923             format:32
  2924 	    to:destinationId
  2924             to:destinationId
  2925 	    data1:dropTypeCode
  2925             propagate:true
  2926 	    data2:0
  2926             eventMask:nil
  2927 	    data3:destinationId
  2927             window:destinationId
  2928 	    data4:nil
  2928             data1:dropTypeCode
  2929 	    data5:nil.
  2929             data2:0
       
  2930             data3:destinationId
       
  2931             data4:nil
       
  2932             data5:nil.
  2930     ].
  2933     ].
  2931 
  2934 
  2932     ^ false
  2935     ^ false
  2933 
  2936 
  2934     "Created: 6.4.1997 / 13:39:37 / cg"
  2937     "Created: 6.4.1997 / 13:39:37 / cg"
  5019     else if (anEventSymbol == @symbol(visibilityChange)) m = VisibilityChangeMask;
  5022     else if (anEventSymbol == @symbol(visibilityChange)) m = VisibilityChangeMask;
  5020     else if (anEventSymbol == @symbol(structureNotify)) m = StructureNotifyMask;
  5023     else if (anEventSymbol == @symbol(structureNotify)) m = StructureNotifyMask;
  5021     else if (anEventSymbol == @symbol(resizeRedirect)) m = ResizeRedirectMask;
  5024     else if (anEventSymbol == @symbol(resizeRedirect)) m = ResizeRedirectMask;
  5022     else if (anEventSymbol == @symbol(propertyChange)) m = PropertyChangeMask;
  5025     else if (anEventSymbol == @symbol(propertyChange)) m = PropertyChangeMask;
  5023     else if (anEventSymbol == @symbol(colormapChange)) m = ColormapChangeMask;
  5026     else if (anEventSymbol == @symbol(colormapChange)) m = ColormapChangeMask;
       
  5027     else if (anEventSymbol == @symbol(substructureNotify)) m = SubstructureNotifyMask;
       
  5028     else if (anEventSymbol == @symbol(substructureRedirect)) m = SubstructureRedirectMask;
  5024     RETURN (__MKSMALLINT(m));
  5029     RETURN (__MKSMALLINT(m));
  5025 %}
  5030 %}
  5026 !
  5031 !
  5027 
  5032 
  5028 eventPending
  5033 eventPending
  5750 
  5755 
  5751 ! !
  5756 ! !
  5752 
  5757 
  5753 !XWorkstation methodsFor:'event sending'!
  5758 !XWorkstation methodsFor:'event sending'!
  5754 
  5759 
  5755 sendClientEvent:msgType format:msgFormat to:targetWindowID data1:d1 data2:d2 data3:d3 data4:d4 data5:d5
  5760 sendClientEvent:msgType format:msgFormat to:targetWindowID propagate:propagate eventMask:eventMask window:windowID data1:d1 data2:d2 data3:d3 data4:d4 data5:d5
  5756     "send a ClientMessage to some other (possibly: non-ST/X) view.
  5761     "send a ClientMessage to some other (possibly: non-ST/X) view.
  5757      The client message gets message_type and msgFormat as specified by
  5762      The client message gets message_type and msgFormat as specified by
  5758      the arguments. The additional data arguments specify up to
  5763      the arguments. The additional data arguments specify up to
  5759      5 longWords of user data; each may be an integer or nil.
  5764      5 longWords of user data; each may be an integer or nil.
  5760      It is passed transparently in the events data field.
  5765      It is passed transparently in the events data field.
  5762 
  5767 
  5763     "/ Event.xclient.type              = ClientMessage;
  5768     "/ Event.xclient.type              = ClientMessage;
  5764     "/ Event.xclient.display           = dpy;
  5769     "/ Event.xclient.display           = dpy;
  5765     "/ Event.xclient.message_type      = msgType;
  5770     "/ Event.xclient.message_type      = msgType;
  5766     "/ Event.xclient.format            = msgFormat;
  5771     "/ Event.xclient.format            = msgFormat;
  5767     "/ Event.xclient.window            = targetWindowID;
  5772     "/ Event.xclient.window            = windowID;
  5768     "/ Event.xclient.data.l[0]         = d1
  5773     "/ Event.xclient.data.l[0]         = d1
  5769     "/ Event.xclient.data.l[1]         = d2
  5774     "/ Event.xclient.data.l[1]         = d2
  5770     "/ Event.xclient.data.l[2]         = d3
  5775     "/ Event.xclient.data.l[2]         = d3
  5771     "/ Event.xclient.data.l[3]         = d4
  5776     "/ Event.xclient.data.l[3]         = d4
  5772     "/ Event.xclient.data.l[4]         = d5
  5777     "/ Event.xclient.data.l[4]         = d5
  5773     "/
  5778     "/
  5774     "/ XSendEvent(dpy,DispatchWindow,True,NoEventMask,&Event);
  5779     "/ XSendEvent(dpy, targetWindowID, propagate, eventMask, &Event);
  5775 
  5780 
  5776     <context: #return>
  5781     <context: #return>
  5777 %{
  5782 %{
  5778     int type;
  5783     int type;
  5779     int state;
  5784     int state;
       
  5785     int __eventMask;
  5780 
  5786 
  5781     if (ISCONNECTED
  5787     if (ISCONNECTED
  5782      && __isInteger(msgType)
  5788      && __isInteger(msgType)
  5783      && __isInteger(msgFormat)
  5789      && __isInteger(msgFormat)
       
  5790      && (eventMask == nil || __isInteger(eventMask))
       
  5791      && (__isExternalAddress(windowID) || __isInteger(windowID))
  5784      && (__isExternalAddress(targetWindowID) || __isInteger(targetWindowID))) {
  5792      && (__isExternalAddress(targetWindowID) || __isInteger(targetWindowID))) {
  5785 	Display *dpy = myDpy;
  5793         Display *dpy = myDpy;
  5786 	XEvent ev;
  5794         XEvent ev;
  5787 	Status result;
  5795         Status result;
  5788 
  5796         Window targetWindow;
  5789 	if (__isInteger(d1)) {
  5797 
  5790 	    ev.xclient.data.l[0] = __longIntVal(d1);
  5798         if (__isInteger(d1)) {
  5791 	} else {
  5799             ev.xclient.data.l[0] = __longIntVal(d1);
  5792 	    if (__isExternalAddress(d1)) {
  5800         } else {
  5793 		ev.xclient.data.l[0] = (INT)__externalAddressVal(d1);
  5801             if (__isExternalAddress(d1)) {
  5794 	    } else {
  5802                 ev.xclient.data.l[0] = (INT)__externalAddressVal(d1);
  5795 		ev.xclient.data.l[0] = 0;
  5803             } else {
  5796 	    }
  5804                 ev.xclient.data.l[0] = 0;
  5797 	}
  5805             }
  5798 	if (__isInteger(d2)) {
  5806         }
  5799 	    ev.xclient.data.l[1] = __longIntVal(d2);
  5807         if (__isInteger(d2)) {
  5800 	} else {
  5808             ev.xclient.data.l[1] = __longIntVal(d2);
  5801 	    if (__isExternalAddress(d2)) {
  5809         } else {
  5802 		ev.xclient.data.l[1] = (INT)__externalAddressVal(d2);
  5810             if (__isExternalAddress(d2)) {
  5803 	    } else {
  5811                 ev.xclient.data.l[1] = (INT)__externalAddressVal(d2);
  5804 		ev.xclient.data.l[1] = 0;
  5812             } else {
  5805 	    }
  5813                 ev.xclient.data.l[1] = 0;
  5806 	}
  5814             }
  5807 	if (__isInteger(d3)) {
  5815         }
  5808 	    ev.xclient.data.l[2] = __longIntVal(d3);
  5816         if (__isInteger(d3)) {
  5809 	} else {
  5817             ev.xclient.data.l[2] = __longIntVal(d3);
  5810 	    if (__isExternalAddress(d3)) {
  5818         } else {
  5811 		ev.xclient.data.l[2] = (INT)__externalAddressVal(d3);
  5819             if (__isExternalAddress(d3)) {
  5812 	    } else {
  5820                 ev.xclient.data.l[2] = (INT)__externalAddressVal(d3);
  5813 		ev.xclient.data.l[2] = 0;
  5821             } else {
  5814 	    }
  5822                 ev.xclient.data.l[2] = 0;
  5815 	}
  5823             }
  5816 	if (__isInteger(d4)) {
  5824         }
  5817 	    ev.xclient.data.l[3] = __longIntVal(d4);
  5825         if (__isInteger(d4)) {
  5818 	} else {
  5826             ev.xclient.data.l[3] = __longIntVal(d4);
  5819 	    if (__isExternalAddress(d4)) {
  5827         } else {
  5820 		ev.xclient.data.l[3] = (INT)__externalAddressVal(d4);
  5828             if (__isExternalAddress(d4)) {
  5821 	    } else {
  5829                 ev.xclient.data.l[3] = (INT)__externalAddressVal(d4);
  5822 		ev.xclient.data.l[3] = 0;
  5830             } else {
  5823 	    }
  5831                 ev.xclient.data.l[3] = 0;
  5824 	}
  5832             }
  5825 	if (__isInteger(d5)) {
  5833         }
  5826 	    ev.xclient.data.l[4] = __longIntVal(d5);
  5834         if (__isInteger(d5)) {
  5827 	} else {
  5835             ev.xclient.data.l[4] = __longIntVal(d5);
  5828 	    if (__isExternalAddress(d5)) {
  5836         } else {
  5829 		ev.xclient.data.l[4] = (INT)__externalAddressVal(d5);
  5837             if (__isExternalAddress(d5)) {
  5830 	    } else {
  5838                 ev.xclient.data.l[4] = (INT)__externalAddressVal(d5);
  5831 		ev.xclient.data.l[4] = 0;
  5839             } else {
  5832 	    }
  5840                 ev.xclient.data.l[4] = 0;
  5833 	}
  5841             }
  5834 
  5842         }
  5835 	if (__isExternalAddress(targetWindowID)) {
  5843 
  5836 	    ev.xclient.window = __WindowVal(targetWindowID);
  5844         if (__isExternalAddress(windowID)) {
  5837 	} else {
  5845             ev.xclient.window = __WindowVal(windowID);
  5838 	    ev.xclient.window = (Window)__longIntVal(targetWindowID);
  5846         } else {
  5839 	}
  5847             ev.xclient.window = (Window)__longIntVal(windowID);
  5840 
  5848         }
  5841 	ev.xclient.type              = ClientMessage;
  5849 
  5842 	ev.xclient.display           = dpy;
  5850         if (__isExternalAddress(targetWindowID)) {
  5843 	ev.xclient.message_type      = __longIntVal(msgType);
  5851             targetWindow = __WindowVal(targetWindowID);
  5844 	ev.xclient.format            = __longIntVal(msgFormat);
  5852         } else {
  5845 
  5853             targetWindow = (Window)__longIntVal(targetWindowID);
  5846 	ENTER_XLIB();
  5854         }
  5847 	result = XSendEvent(dpy, ev.xclient.window, True, NoEventMask , &ev);
  5855 
  5848 	LEAVE_XLIB();
  5856         ev.xclient.type              = ClientMessage;
  5849 
  5857         ev.xclient.display           = dpy;
  5850 	if ((result == BadValue) || (result == BadWindow)) {
  5858         ev.xclient.message_type      = __longIntVal(msgType);
  5851 	    DPRINTF(("bad status in sendClientEvent\n"));
  5859         ev.xclient.format            = __longIntVal(msgFormat);
  5852 	    RETURN ( false )
  5860 
  5853 	}
  5861         if (eventMask == nil) {
  5854 	RETURN (true)
  5862             __eventMask = NoEventMask;
       
  5863         } else {
       
  5864             __eventMask = __longIntVal(eventMask);
       
  5865         }
       
  5866 
       
  5867         ENTER_XLIB();
       
  5868         result = XSendEvent(dpy, targetWindow, (propagate == true ? True : False), __eventMask , &ev);
       
  5869         LEAVE_XLIB();
       
  5870 
       
  5871         if ((result == BadValue) || (result == BadWindow)) {
       
  5872             DPRINTF(("bad status in sendClientEvent\n"));
       
  5873             RETURN ( false )
       
  5874         }
       
  5875         RETURN (true)
  5855     }
  5876     }
  5856 %}.
  5877 %}.
  5857     self primitiveFailedOrClosedConnection.
  5878     self primitiveFailedOrClosedConnection.
  5858     ^ false
  5879     ^ false
  5859 !
  5880 !
  9532 ! !
  9553 ! !
  9533 
  9554 
  9534 !XWorkstation methodsFor:'resources'!
  9555 !XWorkstation methodsFor:'resources'!
  9535 
  9556 
  9536 atomIDOf:aStringOrSymbol
  9557 atomIDOf:aStringOrSymbol
  9537     "return an X11 atoms ID; dont create if not already present.
  9558     "return an X11 atoms ID.
  9538      This is highly X specific and only for local use (with selections).
  9559      This is highly X specific and only for local use (with selections).
  9539      The default is to create the atom, if it does not exist, in order to
  9560      The default is to create the atom, if it does not exist, in order to
  9540      speed up future lookups"
  9561      speed up future lookups"
  9541 
  9562 
  9542     ^ self atomIDOf:aStringOrSymbol create:true
  9563     ^ self atomIDOf:aStringOrSymbol create:true
 11194     }
 11215     }
 11195 %}.
 11216 %}.
 11196     self primitiveFailedOrClosedConnection
 11217     self primitiveFailedOrClosedConnection
 11197 !
 11218 !
 11198 
 11219 
       
 11220 setForegroundWindow:aWindowId
       
 11221     "bring a window to front.
       
 11222      Send a specific message to the WindowManager"
       
 11223 
       
 11224     |activeWindowAtom|
       
 11225 
       
 11226     self raiseWindow:aWindowId.
       
 11227 
       
 11228     activeWindowAtom := self atomIDOf:#'_NET_ACTIVE_WINDOW'.
       
 11229     activeWindowAtom notNil ifTrue:[
       
 11230         self
       
 11231             sendClientEvent:activeWindowAtom
       
 11232             format:32
       
 11233             to:(self rootWindowId)
       
 11234             propagate:false
       
 11235             eventMask:((self eventMaskFor:#substructureNotify) bitOr:(self eventMaskFor:#substructureRedirect))
       
 11236             window:aWindowId
       
 11237             data1:2                 "activate request from pager. This is a trick: kwm ignores requests from applications (1)"
       
 11238             data2:nil
       
 11239             data3:nil
       
 11240             data4:nil
       
 11241             data5:nil.
       
 11242     ].
       
 11243 !
       
 11244 
 11199 setIconName:aString in:aWindowId
 11245 setIconName:aString in:aWindowId
 11200     "define a windows iconname"
 11246     "define a windows iconname"
 11201 
 11247 
 11202     <context: #return>
 11248     <context: #return>
 11203 %{
 11249 %{
 11925 ! !
 11971 ! !
 11926 
 11972 
 11927 !XWorkstation class methodsFor:'documentation'!
 11973 !XWorkstation class methodsFor:'documentation'!
 11928 
 11974 
 11929 version
 11975 version
 11930     ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.496 2008-03-15 17:17:21 stefan Exp $'
 11976     ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.497 2008-09-12 18:42:11 stefan Exp $'
 11931 ! !
 11977 ! !
 11932 
 11978 
 11933 XWorkstation initialize!
 11979 XWorkstation initialize!