Faculty of Information Technology
Software Engineering Group

Ticket #134: libview_fix_1_of_1_rev_57888ed51447_Issue__134__Added_generic_implementation_of___sendKeyOrButtonEvent_____to__DeviceWorkstation_.patch

File libview_fix_1_of_1_rev_57888ed51447_Issue__134__Added_generic_implementation_of___sendKeyOrButtonEvent_____to__DeviceWorkstation_.patch, 6.7 KB (added by Jan Vrany, 3 years ago)
  • DeviceWorkstation.st

    # HG changeset patch
    # User Jan Vrany <jan.vrany@fit.cvut.cz>
    # Date 1494066393 -3600
    #      Sat May 06 11:26:33 2017 +0100
    # Branch jv
    # Node ID 57888ed51447bc974694e0b6b2543d59661a6978
    # Parent  653376a94c8f90590160b75eeb2a0943f3d46ed0
    Issue #134: Added generic implementation of `#sendKeyOrButtonEvent:..` to `DeviceWorkstation`
    
    ...as a fallback. This implementation works purely on a
    Smalltalk level by directly injecting (St/X) events in
    (St/X) window group's event queue, completely bypassing
    windowing system.
    
    The implementation is icomplete and is designed and tested
    only with UI testing framework (stx:goodies/sunit/ext/ui)
    to allow UI testing on systems with no specific implementation
    of `#sendKeyOrButtonEvent...` - e.g. Windows at the time.
    
    https://swing.fit.cvut.cz/projects/stx-jv/ticket/134
    
    diff -r 653376a94c8f -r 57888ed51447 DeviceWorkstation.st
    a b  
    51685168     The non-nil case is the lowlevel entry, where state must include any shift/ctrl information
    51695169     (not very user friendly)"
    51705170
    5171     self subclassResponsibility
     5171    "/ WARNING: this is a generic implementation that completely bypasses underlaying
     5172    "/ system event queue. It may not be complete - it has been written as a quick hack
     5173    "/ to make UI testing framework kind-of working on systems where there's no proper
     5174    "/ implementation of this method (e.g., Windows at the time)
     5175
     5176    | view shiftWasDown ctrlWasDown altWasDown metaWasDown |
     5177
     5178    view := self viewFromId: targetId.
     5179
     5180    [
     5181        shiftWasDown := shiftDown.
     5182        altWasDown := altDown.
     5183        metaWasDown := metaDown.
     5184        ctrlWasDown := ctrlDown.
     5185        stateMask notNil ifTrue:[
     5186            shiftDown := (stateMask bitAnd: self shiftModifierMask) ~~ 0.
     5187            altDown := (stateMask bitAnd: self altModifierMask) ~~ 0.
     5188            metaDown := (stateMask bitAnd: self metaModifierMask) ~~ 0.
     5189            ctrlDown := (stateMask bitAnd: self ctrlModifierMask) ~~ 0.
     5190        ].
     5191        (typeSymbol == #keyPress or:[ typeSymbol == #keyRelease ]) ifTrue:[
     5192            | key |
     5193
     5194            key := keySymCodeOrButtonNr.
     5195            (#(Left Right Up Down) includes: key) ifTrue:[
     5196                key := (#Cursor , key) asSymbol.
     5197            ].
     5198            typeSymbol == #keyPress ifTrue:[
     5199                self keyPress:key x:1 y:1 view:view.
     5200            ] ifFalse:[
     5201                self keyRelease:key x:1 y:1 view:view.
     5202            ]
     5203        ] ifFalse:[ 
     5204            self notYetImplemented.
     5205        ].
     5206    ] ensure:[
     5207        shiftDown := shiftWasDown.
     5208        altDown := altWasDown.
     5209        metaDown := metaWasDown.
     5210        ctrlDown := ctrlWasDown.
     5211    ].
     5212
     5213    "Modified (comment): / 06-05-2017 / 11:15:25 / jv"
    51725214!
    51735215
    51745216simulateKeyboardInput:aCharacterOrString inViewId:viewId
  • WinWorkstation.st

    diff -r 653376a94c8f -r 57888ed51447 WinWorkstation.st
    a b  
    1919        classVariableNames:'BeepDuration NativeDialogs NativeFileDialogs NativeWidgets
    2020                NativeWidgetClassTable StandardColorValues IgnoreSysColorChanges
    2121                IgnoreFontChanges SystemColorValues CanEndSession
    22                 VerboseNativeDialogs '
     22                VerboseNativeDialogs'
    2323        poolDictionaries:''
    2424        category:'Interface-Graphics'
    2525!
     
    64956495    '                   Peak User Objects = ' errorPrint. counts second errorPrintCR.
    64966496    '                   # GDI Objects     = ' errorPrint. counts third errorPrintCR.
    64976497    '                   Peak GDI Objects  = ' errorPrint. counts fourth errorPrintCR.
    6498 !   
     6498!
    64996499
    65006500printHandleCounts
    65016501   "show prim values"
     
    80908090    "Modified: / 28-01-2012 / 10:20:30 / cg"
    80918091!
    80928092
    8093 destroyGC:aGCId
    8094 %{
    8095     if (__isExternalAddress(aGCId)) {
    8096         struct gcData *gcData = _GCDATA(aGCId);
    8097 
    8098         if (gcData == NULL) {
    8099             console_fprintf(stderr, "WinWorkstation [warning]: trying to destroy GC twice\n");
    8100             RETURN(self);
    8101         }
    8102 
    8103 #ifdef COUNT_RESOURCES
    8104          __cnt_gcData--;
    8105         RESPRINTF(("DestroyGcData %d\n",__cnt_gcData));
    8106 #endif
    8107 
    8108 #ifdef CACHE_LAST_DC
    8109         if (lastGcData == gcData) {
    8110             _releaseDC(gcData);
    8111         }
    8112 #endif
    8113         __ExternalAddressInstPtr(aGCId)->e_address = NULL;
    8114 
    8115         freeGcData(gcData);
    8116     }
    8117 %}
    8118 !
    8119 
    8120 destroyPixmap:aDrawableId
    8121 
    8122 %{  /* NOCONTEXT */
    8123     if (__isExternalAddress(aDrawableId) && ISCONNECTED) {
    8124         HANDLE bitmapHandle = _HANDLEVal(aDrawableId);
    8125 
    8126         if (bitmapHandle) {
    8127 #ifdef COUNT_BMP_RESOURCES
    8128             __cnt_bitmap--;
    8129             RES_BMP_PRINTF(("DestroyPixmap %x %d\n", bitmapHandle, __cnt_bitmap));
    8130 #endif
    8131             _DeleteObject(bitmapHandle, __LINE__);
    8132         }
    8133     }
    8134 %}
    8135 !
    8136 
    8137 destroyView:aView withId:aWindowId
    8138     self primDestroyView:aView withId:aWindowId.
    8139     self removeKnownView:aView withId:aWindowId
    8140 !
    8141 
    81428093dcGetClipBoxForGC: gcId
    81438094        "Return clipping box for given device context (as  #(left top right bottom) ). "
    81448095
     
    82018152    err:;
    82028153%}.
    82038154    ^ self primitiveFailed: error
    8204 !     
     8155!
    82058156
    82068157dcUnlockForGC:gcId
    82078158    "Unlocks and __destroy__ a device context for given GC previously
     
    82248175    err:;
    82258176%}.
    82268177    ^ self primitiveFailed: error
    8227 !     
     8178!
     8179
     8180destroyGC:aGCId
     8181%{
     8182    if (__isExternalAddress(aGCId)) {
     8183        struct gcData *gcData = _GCDATA(aGCId);
     8184
     8185        if (gcData == NULL) {
     8186            console_fprintf(stderr, "WinWorkstation [warning]: trying to destroy GC twice\n");
     8187            RETURN(self);
     8188        }
     8189
     8190#ifdef COUNT_RESOURCES
     8191         __cnt_gcData--;
     8192        RESPRINTF(("DestroyGcData %d\n",__cnt_gcData));
     8193#endif
     8194
     8195#ifdef CACHE_LAST_DC
     8196        if (lastGcData == gcData) {
     8197            _releaseDC(gcData);
     8198        }
     8199#endif
     8200        __ExternalAddressInstPtr(aGCId)->e_address = NULL;
     8201
     8202        freeGcData(gcData);
     8203    }
     8204%}
     8205!
     8206
     8207destroyPixmap:aDrawableId
     8208
     8209%{  /* NOCONTEXT */
     8210    if (__isExternalAddress(aDrawableId) && ISCONNECTED) {
     8211        HANDLE bitmapHandle = _HANDLEVal(aDrawableId);
     8212
     8213        if (bitmapHandle) {
     8214#ifdef COUNT_BMP_RESOURCES
     8215            __cnt_bitmap--;
     8216            RES_BMP_PRINTF(("DestroyPixmap %x %d\n", bitmapHandle, __cnt_bitmap));
     8217#endif
     8218            _DeleteObject(bitmapHandle, __LINE__);
     8219        }
     8220    }
     8221%}
     8222!
     8223
     8224destroyView:aView withId:aWindowId
     8225    self primDestroyView:aView withId:aWindowId.
     8226    self removeKnownView:aView withId:aWindowId
     8227!
    82288228
    82298229gcFor:aDrawableId
    82308230
     
    1317113171     The non-nil case is the lowlevel entry, where state must include any shift/ctrl information
    1317213172     (not very user friendly)"
    1317313173
    13174     'WinWorkstation [warning]: sendKeyOrButtonEvent unimplemented' infoPrintCR.
    13175     ^ false
     13174    super sendKeyOrButtonEvent:typeSymbol x:xPos y:yPos keyOrButton:keySymCodeOrButtonNr state:stateMask toViewId:targetId
     13175
     13176    "Modified: / 06-05-2017 / 11:19:03 / jv"
    1317613177! !
    1317713178
    1317813179!WinWorkstation methodsFor:'font stuff'!
     
    1961219613
    1961319614version_CVS
    1961419615    ^ '$Header$'
     19616!
     19617
     19618version_HG
     19619
     19620    ^ '$Changeset: <not expanded> $'
    1961519621! !
    1961619622
    1961719623