KeyboardProcessor.st
author Claus Gittinger <cg@exept.de>
Thu, 11 Mar 1999 01:02:58 +0100
changeset 1134 758151d73aac
parent 1133 48fe25214e65
child 1135 ee997fc311e2
permissions -rw-r--r--
only do autoAccept, if there is no focus view.

"
 COPYRIGHT (c) 1997 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"





Object subclass:#KeyboardProcessor
	instanceVariableNames:'returnIsOKInDialog escapeIsCancelInDialog menuBar
		autoAcceptListeners'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Support-UI'
!

!KeyboardProcessor class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"




!

documentation
"
    ST80 compatibility (mimicry) class.

    The class is not completed yet and certainly not bug free.
    Also, it is not guaranteed that all winSpecs are understood.

    Notice: 
        this class was implemented using protocol information
        from alpha testers, literature and by reading public domain code
        - it may not be complete or compatible to
        the corresponding ST-80 class. 
        If you encounter any incompatibilities, please forward a note 
        describing the incompatibility verbal (i.e. no code) to the ST/X team.

    [author:]
        Claus Atzkern
"




! !

!KeyboardProcessor methodsFor:'ST80 - mimicri'!

keyboardConsumers
    ^ #()

    "Created: 6.3.1997 / 15:16:32 / cg"
!

removeKeyboardReceiver:aController

    "Created: / 31.10.1997 / 01:56:54 / cg"
!

sendKeyboardTo:aController

    "Created: / 31.10.1997 / 01:57:15 / cg"
!

setActive:aWidget

    "Created: 3.3.1997 / 18:31:09 / cg"
! !

!KeyboardProcessor methodsFor:'accessing'!

escapeIsCancelInDialog:aBoolean
    "set the escapeIsCancel flag.
     If off, Escape is NOT handled as cancel (however, the default is true)"

    escapeIsCancelInDialog := aBoolean
!

menuBar
    "return the value of the instance variable 'menuBar' (automatically generated)"

    ^ menuBar!

menuBar:something
    "set the value of the instance variable 'menuBar' (automatically generated)"

    menuBar := something.!

returnIsOKInDialog:aBoolean
    "set the returnIsOK flag.
     If off, Return is NOT handled as accept (however, the default is true)"

    returnIsOKInDialog := aBoolean

! !

!KeyboardProcessor methodsFor:'event handling'!

processEvent:event
    "process a key-event; return true, if handled & eaten; false if not.
     Here, Return and Escape are intercepted and lead to Accept & Cancel resp.
     Also, in the future, menu-shortcuts will be handled here (does not work yet)"

    |key topView app view|

    view := event view.

    event isKeyPressEvent ifTrue:[
        key := event key.
        topView := view topView.
        app := topView application.

        topView isModal ifTrue:[
            topView windowGroup focusView isNil ifTrue:[
                (returnIsOKInDialog and:[key == #Return]) ifTrue:[
                    self requestGlobalAutoAccept ifFalse:[^ true].
                    app doAccept.
                    ^ true
                ].
            ].

            (escapeIsCancelInDialog and:[key == #Escape]) ifTrue:[
                app doCancel.
                ^ true
            ].
        ].

        "/ how about menu-shortkeys ?
        (menuBar notNil and:[(menuBar processShortcutKeyEventInMenuBar:event)]) ifTrue:[
            ^ true
        ]
    ].

    ^ false

    "/ let view dispatch it.



!

requestForWindowClose
     "about to close the window."

     ^ true
!

requestGlobalAutoAccept
     "about to close the window via return ok accept.
      Ask all acceptListeners to accept their value and return true, if all of those fields
      did."

    autoAcceptListeners notNil ifTrue:[
        autoAcceptListeners do:[:aListener |
            (aListener requestAutoAccept) ifFalse:[^ false].
        ].
        ^ true
    ].
    ^ false

! !

!KeyboardProcessor methodsFor:'setup'!

addAutoAcceptListener:aListener
    "add a aListener to my autoAcceptListeners.
     Typically, inputFields add themself, to be notified (via requestForAutoAccept)
     when the dialog is about to be closed with returnIsOK or accept.
     (of course, other listeners are also invited ;-)"

    autoAcceptListeners isNil ifTrue:[
        autoAcceptListeners := IdentitySet new.
    ].
    autoAcceptListeners add:aListener
! !

!KeyboardProcessor class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.5 1999-03-11 00:02:58 cg Exp $'
! !