XWorkstation.st
changeset 440 e959b8e18453
parent 404 0db38d8283a4
child 447 9a58924e921b
--- a/XWorkstation.st	Fri Feb 23 03:23:19 1996 +0100
+++ b/XWorkstation.st	Fri Feb 23 03:24:18 1996 +0100
@@ -2890,151 +2890,6 @@
     ^ false
 ! !
 
-!XWorkstation methodsFor:'event sending'!
-
-simulateKeyboardInput:aCharacterOrString inViewId:viewId
-    "send input to some other view, by simulating keyPress/keyRelease
-     events. Notice: not all alien views allow this kind of synthetic input;
-     some simply ignore it."
-
-    |shifted control code state|
-
-    aCharacterOrString isString ifTrue:[
-	aCharacterOrString do:[:char |
-	    self simulateKeyboardInput:char inViewId:viewId
-	].
-	^ self
-    ].
-
-    shifted := false.
-    control := false.
-    code := aCharacterOrString asciiValue.
-
-    (aCharacterOrString == Character cr) ifTrue:[
-	code := #Return
-    ] ifFalse:[
-	(aCharacterOrString between:$A and:$Z) ifTrue:[
-	    "/ shifted
-	    shifted := true
-	] ifFalse:[
-	    (aCharacterOrString between:$a and:$z) ifTrue:[
-		"/ unshifted alpha
-		code := code - $a asciiValue + $A asciiValue
-	    ]
-	]
-    ].
-
-    shifted ifTrue:[
-	state := self shiftMask
-    ] ifFalse:[
-	state := 0
-    ].
-    control ifTrue:[
-	state := state bitOr:(self controlMask)
-    ].
-
-    self sendKeyOrButtonEvent:#keyPress x:0 y:0 keyOrButton:code state:state toViewId:viewId.
-    self sendKeyOrButtonEvent:#keyRelease x:0 y:0 keyOrButton:code state:state toViewId:viewId
-
-    "
-      sending input to some (possibly alien) view:
-
-      |point id|
-
-      point :=  Display pointFromUser.
-      id := Display viewIdFromPoint:point.
-      Display simulateKeyboardInput:'hello' inViewId:id
-    "
-!
-
-sendKeyOrButtonEvent:typeSymbol x:xPos y:yPos keyOrButton:keySymCodeOrButtonNr state:stateMask toViewId:targetId
-    "send a keyPress/Release or buttonPress/Release event to some (possibly alien) view.
-     TypeSymbol must be one of: #keyPress, #keyRelease, #buttonPress , #buttonRelease.
-     For buttonEvents, the keySymCodeOrButtonNr must be the buttons number (1, 2 ...);
-     for key events, it can be either a symbol (as listen in X's keySyms)
-     or a numeric keysym code.
-     This is the lowlevel entry, where state must include any shift/ctrl information
-     (not very user friendly)"
-
-%{  /* NOCONTEXT */
-    Display *dpy = myDpy;
-    int type;
-
-    if (ISCONNECTED
-     && __isSmallInteger(xPos) && __isSmallInteger(yPos)
-     && (__isSmallInteger(keySymCodeOrButtonNr) || __isSymbol(keySymCodeOrButtonNr) || __isString(keySymCodeOrButtonNr))
-     && __isSmallInteger(stateMask)
-     && (__isExternalAddress(targetId) || __isInteger(targetId))) {
-	XEvent ev;
-	Window target;
-	Status result;
-	KeySym keySym;
-	int screen = _intVal(_INST(screen));
-	char s[2];
-
-	if ((typeSymbol == @symbol(keyPress))
-	 || (typeSymbol == @symbol(keyRelease))) {
-	    if (__isSymbol(keySymCodeOrButtonNr) || __isString(keySymCodeOrButtonNr)) {
-		keySym = XStringToKeysym(__stringVal(keySymCodeOrButtonNr));
-	    } else {
-		if (__isCharacter(keySymCodeOrButtonNr)) {
-		    s[0] = __intVal(__characterVal(keySymCodeOrButtonNr));
-		    s[1] = '\0';
-		    keySym = XStringToKeysym(s);
-		} else {
-		    keySym = (KeySym) __intVal(keySymCodeOrButtonNr);
-		}
-	    }
-	    ev.xkey.keycode = XKeysymToKeycode(dpy, keySym);
-	} else {
-	    if ((typeSymbol == @symbol(buttonPress))
-	     || (typeSymbol == @symbol(buttonRelease))) {
-		if (__isSmallInteger(keySymCodeOrButtonNr)) {
-		    ev.xbutton.button = __intVal(keySymCodeOrButtonNr);
-		} else {
-		    ev.xbutton.button = 1;
-		}
-	    } else {
-		DPRINTF(("invalid sendEvent typeSymbol\n"));
-		RETURN (false);
-	    }
-	}
-
-	if (typeSymbol == @symbol(keyPress))
-	    ev.xany.type = KeyPress;
-	else if (typeSymbol == @symbol(keyRelease))
-	    ev.xany.type = KeyRelease;
-	else if (typeSymbol == @symbol(buttonPress))
-	    ev.xany.type = ButtonPress;
-	else if (typeSymbol == @symbol(buttonRelease))
-	    ev.xany.type = ButtonRelease;
-
-	if (__isExternalAddress(targetId)) {
-	    target = _WindowVal(targetId);
-	} else {
-	    target = (Window) __longIntVal(targetId);
-	}
-	ev.xkey.window = target;
-	ev.xkey.same_screen = 1;
-	ev.xkey.subwindow = 0;
-	ev.xkey.root = RootWindow(myDpy, screen);
-	ev.xkey.x = __intVal(xPos);
-	ev.xkey.y = __intVal(yPos);
-	ev.xkey.state = __intVal(stateMask);
-	ev.xkey.time = CurrentTime;
-
-	result = XSendEvent(dpy, target, False, 0 , &ev);
-	if ((result == BadValue) || (result == BadWindow)) {
-	    DPRINTF(("bad status\n"));
-	    RETURN ( false )
-	}
-	RETURN (true)
-    }
-%}.
-    self primitiveFailed.
-    ^ false
-! !
-
 !XWorkstation methodsFor:'event handling'!
 
 dispatchEventFor:aViewIdOrNil withMask:eventMask
@@ -3948,6 +3803,151 @@
     super startDispatch
 ! !
 
+!XWorkstation methodsFor:'event sending'!
+
+sendKeyOrButtonEvent:typeSymbol x:xPos y:yPos keyOrButton:keySymCodeOrButtonNr state:stateMask toViewId:targetId
+    "send a keyPress/Release or buttonPress/Release event to some (possibly alien) view.
+     TypeSymbol must be one of: #keyPress, #keyRelease, #buttonPress , #buttonRelease.
+     For buttonEvents, the keySymCodeOrButtonNr must be the buttons number (1, 2 ...);
+     for key events, it can be either a symbol (as listen in X's keySyms)
+     or a numeric keysym code.
+     This is the lowlevel entry, where state must include any shift/ctrl information
+     (not very user friendly)"
+
+%{  /* NOCONTEXT */
+    Display *dpy = myDpy;
+    int type;
+
+    if (ISCONNECTED
+     && __isSmallInteger(xPos) && __isSmallInteger(yPos)
+     && (__isSmallInteger(keySymCodeOrButtonNr) || __isSymbol(keySymCodeOrButtonNr) || __isString(keySymCodeOrButtonNr))
+     && __isSmallInteger(stateMask)
+     && (__isExternalAddress(targetId) || __isInteger(targetId))) {
+	XEvent ev;
+	Window target;
+	Status result;
+	KeySym keySym;
+	int screen = _intVal(_INST(screen));
+	char s[2];
+
+	if ((typeSymbol == @symbol(keyPress))
+	 || (typeSymbol == @symbol(keyRelease))) {
+	    if (__isSymbol(keySymCodeOrButtonNr) || __isString(keySymCodeOrButtonNr)) {
+		keySym = XStringToKeysym(__stringVal(keySymCodeOrButtonNr));
+	    } else {
+		if (__isCharacter(keySymCodeOrButtonNr)) {
+		    s[0] = __intVal(__characterVal(keySymCodeOrButtonNr));
+		    s[1] = '\0';
+		    keySym = XStringToKeysym(s);
+		} else {
+		    keySym = (KeySym) __intVal(keySymCodeOrButtonNr);
+		}
+	    }
+	    ev.xkey.keycode = XKeysymToKeycode(dpy, keySym);
+	} else {
+	    if ((typeSymbol == @symbol(buttonPress))
+	     || (typeSymbol == @symbol(buttonRelease))) {
+		if (__isSmallInteger(keySymCodeOrButtonNr)) {
+		    ev.xbutton.button = __intVal(keySymCodeOrButtonNr);
+		} else {
+		    ev.xbutton.button = 1;
+		}
+	    } else {
+		DPRINTF(("invalid sendEvent typeSymbol\n"));
+		RETURN (false);
+	    }
+	}
+
+	if (typeSymbol == @symbol(keyPress))
+	    ev.xany.type = KeyPress;
+	else if (typeSymbol == @symbol(keyRelease))
+	    ev.xany.type = KeyRelease;
+	else if (typeSymbol == @symbol(buttonPress))
+	    ev.xany.type = ButtonPress;
+	else if (typeSymbol == @symbol(buttonRelease))
+	    ev.xany.type = ButtonRelease;
+
+	if (__isExternalAddress(targetId)) {
+	    target = _WindowVal(targetId);
+	} else {
+	    target = (Window) __longIntVal(targetId);
+	}
+	ev.xkey.window = target;
+	ev.xkey.same_screen = 1;
+	ev.xkey.subwindow = 0;
+	ev.xkey.root = RootWindow(myDpy, screen);
+	ev.xkey.x = __intVal(xPos);
+	ev.xkey.y = __intVal(yPos);
+	ev.xkey.state = __intVal(stateMask);
+	ev.xkey.time = CurrentTime;
+
+	result = XSendEvent(dpy, target, False, 0 , &ev);
+	if ((result == BadValue) || (result == BadWindow)) {
+	    DPRINTF(("bad status\n"));
+	    RETURN ( false )
+	}
+	RETURN (true)
+    }
+%}.
+    self primitiveFailed.
+    ^ false
+!
+
+simulateKeyboardInput:aCharacterOrString inViewId:viewId
+    "send input to some other view, by simulating keyPress/keyRelease
+     events. Notice: not all alien views allow this kind of synthetic input;
+     some simply ignore it."
+
+    |shifted control code state|
+
+    aCharacterOrString isString ifTrue:[
+	aCharacterOrString do:[:char |
+	    self simulateKeyboardInput:char inViewId:viewId
+	].
+	^ self
+    ].
+
+    shifted := false.
+    control := false.
+    code := aCharacterOrString asciiValue.
+
+    (aCharacterOrString == Character cr) ifTrue:[
+	code := #Return
+    ] ifFalse:[
+	(aCharacterOrString between:$A and:$Z) ifTrue:[
+	    "/ shifted
+	    shifted := true
+	] ifFalse:[
+	    (aCharacterOrString between:$a and:$z) ifTrue:[
+		"/ unshifted alpha
+		code := code - $a asciiValue + $A asciiValue
+	    ]
+	]
+    ].
+
+    shifted ifTrue:[
+	state := self shiftMask
+    ] ifFalse:[
+	state := 0
+    ].
+    control ifTrue:[
+	state := state bitOr:(self controlMask)
+    ].
+
+    self sendKeyOrButtonEvent:#keyPress x:0 y:0 keyOrButton:code state:state toViewId:viewId.
+    self sendKeyOrButtonEvent:#keyRelease x:0 y:0 keyOrButton:code state:state toViewId:viewId
+
+    "
+      sending input to some (possibly alien) view:
+
+      |point id|
+
+      point :=  Display pointFromUser.
+      id := Display viewIdFromPoint:point.
+      Display simulateKeyboardInput:'hello' inViewId:id
+    "
+! !
+
 !XWorkstation methodsFor:'font stuff'!
 
 ascentOf:aFontId
@@ -4133,6 +4133,196 @@
     ^ nil
 !
 
+encodingOf:aFontId
+    "the fonts encoding - if the font does not provide that info,
+     return nil (and assume ASCII, which is a subset of ISO8859-1)."
+
+    |enc fullName fontName registry encoding charSetCollections|
+
+%{ 
+    XFontStruct *f;
+    XFontProp *prop;
+    int n;
+    char *cp;
+    Atom fontAtom, registryAtom, encodingAtom, charSetCollAtom;
+
+    registryAtom = XInternAtom(myDpy, "CHARSET_REGISTRY", True);
+    encodingAtom = XInternAtom(myDpy, "CHARSET_ENCODING", True);
+    charSetCollAtom = XInternAtom(myDpy, "CHARSET_COLLECTIONS", True);
+    fontAtom = XInternAtom(myDpy, "FONT", True);
+
+    if (ISCONNECTED) {
+        if (__isExternalAddress(aFontId)) {
+        
+            f = _FontVal(aFontId);
+            if (f) {
+                n = f->n_properties;
+                prop = f->properties;
+                if (prop) {
+                    while (n--) {
+                        cp = XGetAtomName(myDpy, prop->name);
+#ifdef SUPERDEBUG
+                        printf("%s (%d) -> %d\n", cp, prop->name, prop->card32);
+#endif
+                        if (prop->name == XA_FULL_NAME) {
+                            cp = XGetAtomName(myDpy, prop->card32);
+                            if (cp) {
+                                fullName = __MKSTRING(cp COMMA_CON);
+#ifdef SUPERDEBUG
+                                printf("   FULL_NAME -> %s\n", cp);
+#endif
+                            }
+                        }
+                        if (prop->name == fontAtom) {
+                            cp = XGetAtomName(myDpy, prop->card32);
+                            if (cp) {
+                                fontName = __MKSTRING(cp COMMA_CON);
+#ifdef SUPERDEBUG
+                                printf("   FONT -> %s\n", cp);
+#endif
+                            }
+                        }
+                        if (prop->name == encodingAtom) {
+                            cp = XGetAtomName(myDpy, prop->card32);
+                            if (cp) {
+                                encoding = __MKSTRING(cp COMMA_CON);
+#ifdef SUPERDEBUG
+                                printf("   ENCODING -> %s\n", cp);
+#endif
+                            }
+                        }
+                        if (prop->name == registryAtom) {
+                            cp = XGetAtomName(myDpy, prop->card32);
+                            if (cp) {
+                                registry = __MKSTRING(cp COMMA_CON);
+#ifdef SUPERDEBUG
+                                printf("   REGISTRY -> %s\n", cp);
+#endif
+                            }
+                        }
+                        if (prop->name == charSetCollAtom) {
+                            cp = XGetAtomName(myDpy, prop->card32);
+                            if (cp) {
+                                charSetCollections = __MKSTRING(cp COMMA_CON);
+#ifdef SUPERDEBUG
+                                printf("   CHARSET_COLLECTIONS -> %s\n", cp);
+#endif
+                            }
+                        }
+                        prop++;
+                    }
+                }
+            }
+        }
+    }
+%}.
+    (registry notNil and:[registry notEmpty]) ifTrue:[
+        enc := registry asUppercase.
+        (encoding notNil and:[encoding notEmpty]) ifTrue:[
+            enc := enc , '-' , encoding asUppercase
+        ]
+    ] ifFalse:[
+        (encoding notNil and:[encoding notEmpty]) ifTrue:[
+            enc := encoding asUppercase
+        ] ifFalse:[
+            (charSetCollections notNil and:[charSetCollections notEmpty]) ifTrue:[
+                charSetCollections := charSetCollections asUppercase asCollectionOfWords.
+                (charSetCollections includes:'ISO8859-1') ifTrue:[
+                    enc := 'ISO8859-1'
+                ] ifFalse:[
+                    (charSetCollections includes:'ISO8859') ifTrue:[
+                        enc := 'ISO8859-1'
+                    ] ifFalse:[
+                        (charSetCollections includes:'ASCII') ifTrue:[
+                            enc := 'ASCII'
+                        ] ifFalse:[
+                            (charSetCollections includes:'ADOBE-STANDARD') ifTrue:[
+                                enc := 'ISO8859-1'
+                            ]
+                        ]
+                    ]
+                ]
+            ] 
+        ]
+    ].
+    ^  enc
+!
+
+flushListOfAvailableFonts
+    "flush the cached list of all available fonts on this display.
+     Required if new fonts have been added on the display server."
+
+    listOfXFonts := nil
+
+    "
+     Display flushListOfAvailableFonts.
+     Display listOfAvailableFonts
+    "
+
+    "Modified: 27.9.1995 / 10:54:47 / stefan"
+    "Created: 20.2.1996 / 22:55:52 / cg"
+!
+
+fullNameOf:aFontId
+    "the fonts fullName - this is very device specific and should only be
+     used for user feed-back (for example: in the fontPanel).
+     If the display/font do not provide that info, return nil."
+
+    |fullName fontName|
+
+%{ 
+    XFontStruct *f;
+    XFontProp *prop;
+    int n;
+    char *cp;
+    Atom fontAtom;
+
+    fontAtom = XInternAtom(myDpy, "FONT", True);
+
+    if (ISCONNECTED) {
+        if (__isExternalAddress(aFontId)) {
+        
+            f = _FontVal(aFontId);
+            if (f) {
+                n = f->n_properties;
+                prop = f->properties;
+                if (prop) {
+                    while (n--) {
+                        cp = XGetAtomName(myDpy, prop->name);
+#ifdef SUPERDEBUG
+                        printf("%s (%d) -> %d\n", cp, prop->name, prop->card32);
+#endif
+                        if (prop->name == XA_FULL_NAME) {
+                            cp = XGetAtomName(myDpy, prop->card32);
+                            if (cp) {
+                                fullName = __MKSTRING(cp COMMA_CON);
+#ifdef SUPERDEBUG
+                                printf("   FULL_NAME -> %s\n", cp);
+#endif
+                            }
+                        }
+                        if (prop->name == fontAtom) {
+                            cp = XGetAtomName(myDpy, prop->card32);
+                            if (cp) {
+                                fontName = __MKSTRING(cp COMMA_CON);
+#ifdef SUPERDEBUG
+                                printf("   FONT -> %s\n", cp);
+#endif
+                            }
+                        }
+                        prop++;
+                    }
+                }
+            }
+        }
+    }
+%}.
+    (fullName notNil and:[fullName notEmpty]) ifTrue:[
+        ^ fullName
+    ].
+    ^ fontName
+!
+
 getAvailableFontsMatching:pattern
     "return an Array filled with font names matching aPattern"
 
@@ -6182,6 +6372,13 @@
     "return an Atoms ID; dont create if not already present"
 
     ^ self atomIDOf:aStringOrSymbol create:false
+
+    "
+     Display atomIDOf:'FACE_NAME'      
+     Display atomIDOf:'FULL_NAME' 
+    "
+
+    "Modified: 22.2.1996 / 23:29:32 / cg"
 !
 
 atomIDOf:aStringOrSymbol create:create
@@ -6240,22 +6437,29 @@
     char *name;
 
     if (ISCONNECTED) {
-	if (__isAtomID(anAtomID)) {
-	    name = XGetAtomName(myDpy, _AtomVal(anAtomID));
-	    if (name == 0) {
-		RETURN (nil);
-	    }
-	    str = __MKSTRING(name COMMA_CON);
-	    XFree(name);
-	    RETURN ( str );
-	}
+        if (__isAtomID(anAtomID)) {
+            name = XGetAtomName(myDpy, _AtomVal(anAtomID));
+            if (name == 0) {
+                RETURN (nil);
+            }
+            str = __MKSTRING(name COMMA_CON);
+            XFree(name);
+            RETURN ( str );
+        }
     }
 %}.
     self primitiveFailed.
     ^ nil
 
     "
-     Display atomName:1
+     Display atomName:1 
+     Display atomName:130  '_DEC_DEVICE_FONTNAMES'
+     Display atomName:132  'FONTNAME_REGISTRY'
+     Display atomName:135 'FOUNDRY' 
+     Display atomName:150  'CHARSET_REGISTRY'
+     Display atomName:151  'ISO8859'
+     Display atomName:152 'CHARSET_ENCODING'
+     Display atomName:154 
     "
 !
 
@@ -7296,6 +7500,6 @@
 !XWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.109 1996-02-06 00:25:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.110 1996-02-23 02:24:18 cg Exp $'
 ! !
 XWorkstation initialize!