KeyboardForwarder.st
author Claus Gittinger <cg@exept.de>
Wed, 22 Aug 2018 12:58:11 +0200
changeset 8451 6eafe0433763
parent 8362 573b5a8cc1c5
permissions -rw-r--r--
#QUALITY by cg class: WindowSensor comment/format in: #basicAddDamage:view:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
     1
"{ Encoding: utf8 }"
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
     2
128
9c2378152500 Initial revision
claus
parents:
diff changeset
     3
"
9c2378152500 Initial revision
claus
parents:
diff changeset
     4
 COPYRIGHT (c) 1995 by Claus Gittinger
9c2378152500 Initial revision
claus
parents:
diff changeset
     5
	      All Rights Reserved
9c2378152500 Initial revision
claus
parents:
diff changeset
     6
9c2378152500 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
9c2378152500 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
9c2378152500 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
9c2378152500 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
9c2378152500 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
9c2378152500 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
9c2378152500 Initial revision
claus
parents:
diff changeset
    13
"
3682
d756fdb95712 evenTypes - private to windowEvent
ca
parents: 3094
diff changeset
    14
"{ Package: 'stx:libview' }"
d756fdb95712 evenTypes - private to windowEvent
ca
parents: 3094
diff changeset
    15
7660
7541edd3ab40 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 6352
diff changeset
    16
"{ NameSpace: Smalltalk }"
7541edd3ab40 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 6352
diff changeset
    17
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    18
Object subclass:#KeyboardForwarder
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
    19
	instanceVariableNames:'sourceView destinationView destination condition filter'
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
    20
	classVariableNames:''
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
    21
	poolDictionaries:''
5277
27d26caa8086 category change
Claus Gittinger <cg@exept.de>
parents: 3682
diff changeset
    22
	category:'Interface-Support-UI'
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    23
!
9c2378152500 Initial revision
claus
parents:
diff changeset
    24
9c2378152500 Initial revision
claus
parents:
diff changeset
    25
!KeyboardForwarder class methodsFor:'documentation'!
9c2378152500 Initial revision
claus
parents:
diff changeset
    26
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    27
copyright
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    28
"
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    29
 COPYRIGHT (c) 1995 by Claus Gittinger
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    30
	      All Rights Reserved
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    31
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    32
 This software is furnished under a license and may be used
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    33
 only in accordance with the terms of that license and with the
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    35
 be provided or otherwise made available to, or used by, any
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    36
 other person.  No title to or ownership of the software is
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    37
 hereby transferred.
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    38
"
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    39
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    40
!
9c2378152500 Initial revision
claus
parents:
diff changeset
    41
9c2378152500 Initial revision
claus
parents:
diff changeset
    42
documentation
9c2378152500 Initial revision
claus
parents:
diff changeset
    43
"
144
claus
parents: 142
diff changeset
    44
    Instances of this class can be used to forward keyboard
claus
parents: 142
diff changeset
    45
    events to some object or other view (install them via aView delegate:).
claus
parents: 142
diff changeset
    46
    Event delegation allows to add additional keyboard functions to views
claus
parents: 142
diff changeset
    47
    WITHOUT modifying their code or changing controllers.
claus
parents: 142
diff changeset
    48
    Also, it allows to catch certain individual keys to ignore them or
claus
parents: 142
diff changeset
    49
    perform different functions.
claus
parents: 142
diff changeset
    50
7660
7541edd3ab40 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 6352
diff changeset
    51
    Notice, that delegates don't have to be instances of
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    52
    myself; any object with a protocol similar to mine can be used as
9c2378152500 Initial revision
claus
parents:
diff changeset
    53
    a delegate. 
142
claus
parents: 140
diff changeset
    54
    (i.e. any object that responds to 
claus
parents: 140
diff changeset
    55
     handlesKeyPress:view: / keyPress:x:y:view: / delegatesTo: etc.)
139
claus
parents: 134
diff changeset
    56
claus
parents: 134
diff changeset
    57
    However, I provide the most common functions required for conditional
claus
parents: 134
diff changeset
    58
    event delegation and instances of myself are for example used to forward 
claus
parents: 134
diff changeset
    59
    events from elements of some dialogBoxes to the enterfield/fieldGroup - 
144
claus
parents: 142
diff changeset
    60
    (which allows keyboard input to be forwarded to the active text-field even 
claus
parents: 142
diff changeset
    61
     while the mouse pointer is somewhere else)
139
claus
parents: 134
diff changeset
    62
claus
parents: 134
diff changeset
    63
    Another application of delegation is to catch keyboard input to some standard
claus
parents: 134
diff changeset
    64
    widget, optionally processing and resending the key-event.
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    65
144
claus
parents: 142
diff changeset
    66
    I can either forward the key event to another view, or to some general
claus
parents: 142
diff changeset
    67
    object - the difference is that views are sent a #keyXXX:x:y: message,
claus
parents: 142
diff changeset
    68
    while general destinations get a #keyXXX:x:y:view: message, with the original
claus
parents: 142
diff changeset
    69
    view (the one in which the event occurred) as additional argument.
claus
parents: 142
diff changeset
    70
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    71
    [Instance Variables:]
139
claus
parents: 134
diff changeset
    72
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    73
        destinationView         <View>          the view which shall receive
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    74
                                                the forwarded keyboard events.
134
claus
parents: 128
diff changeset
    75
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    76
        destination             <Object>        the object which shall receive
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    77
                                                the forwarded keyboard events.
139
claus
parents: 134
diff changeset
    78
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    79
        sourceView              <ViewOrNil>     if non-nil, only events from this
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    80
                                                view are forwarded.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    81
                                                (currently nowhere used)
134
claus
parents: 128
diff changeset
    82
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    83
        condition               <Symbol>        an additional condition for forwarding
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    84
                                                currently only #noFocus is implemented.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    85
                                                The #noFocus condition will only forward
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    86
                                                events if no explicit focus has been
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    87
                                                set in the windowGroup.
144
claus
parents: 142
diff changeset
    88
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    89
                                <Block>         condition block - event is forwarded,
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    90
                                                if it evaluates to true.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    91
                                                The block gets 3 arguments:
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    92
                                                    eventType   #keyPress or #keyRelease
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    93
                                                    key         the key
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    94
                                                    view        the originating view
144
claus
parents: 142
diff changeset
    95
claus
parents: 142
diff changeset
    96
    For more info on event handling/forwarding, see the documentation in
claus
parents: 142
diff changeset
    97
    WindowSensor, WindowGroup and especially in WindowEvent.
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    98
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    99
    [see also:]
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
   100
        WindowEvent WindowSensor WindowGroup
612
8758d0c9933e documentation
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
   101
8758d0c9933e documentation
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
   102
    [author:]
8758d0c9933e documentation
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
   103
        Claus Gittinger
144
claus
parents: 142
diff changeset
   104
"
claus
parents: 142
diff changeset
   105
!
claus
parents: 142
diff changeset
   106
claus
parents: 142
diff changeset
   107
examples
claus
parents: 142
diff changeset
   108
"
claus
parents: 142
diff changeset
   109
    catch an enterfields input:
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   110
                                                                        [exBegin]
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   111
        |top field forwarder catcher|
144
claus
parents: 142
diff changeset
   112
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   113
        catcher := Plug new.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   114
        catcher respondTo:#keyPress:x:y:view:
1752
Claus Gittinger <cg@exept.de>
parents: 1693
diff changeset
   115
                    with:[:key :x :y :view | Transcript showCR:'caught keyPress: ' , key printString.].
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   116
        catcher respondTo:#keyRelease:x:y:view:
1752
Claus Gittinger <cg@exept.de>
parents: 1693
diff changeset
   117
                    with:[:key :x :y :view | Transcript showCR:'caught keyRelease: ' , key printString.].
144
claus
parents: 142
diff changeset
   118
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   119
        top := StandardSystemView new.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   120
        top extent:200@200.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   121
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   122
        field := EditField in:top.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   123
        field origin:0.0@0.0; width:1.0.
144
claus
parents: 142
diff changeset
   124
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   125
        forwarder := KeyboardForwarder to:catcher. 
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   126
        field delegate:forwarder.
144
claus
parents: 142
diff changeset
   127
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   128
        top open
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   129
                                                                        [exEnd]
144
claus
parents: 142
diff changeset
   130
claus
parents: 142
diff changeset
   131
claus
parents: 142
diff changeset
   132
    catch an enterfields return-key only:
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   133
                                                                        [exBegin]
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   134
        |top field forwarder catcher|
144
claus
parents: 142
diff changeset
   135
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   136
        catcher := Plug new.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   137
        catcher respondTo:#keyPress:x:y:view:
1752
Claus Gittinger <cg@exept.de>
parents: 1693
diff changeset
   138
                    with:[:key :x :y :view | Transcript showCR:'caught return'].
144
claus
parents: 142
diff changeset
   139
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   140
        top := StandardSystemView new.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   141
        top extent:200@200.
144
claus
parents: 142
diff changeset
   142
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   143
        field := EditField in:top.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   144
        field origin:0.0@0.0; width:1.0.
144
claus
parents: 142
diff changeset
   145
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   146
        forwarder := KeyboardForwarder 
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   147
                        to:catcher 
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   148
                        condition:[:type :key :view | (type == #keyPress) & (key == #Return)].
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   149
        field delegate:forwarder.
144
claus
parents: 142
diff changeset
   150
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   151
        top open
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   152
                                                                        [exEnd]
144
claus
parents: 142
diff changeset
   153
claus
parents: 142
diff changeset
   154
claus
parents: 142
diff changeset
   155
    catch all of an enterfields input and ignore it:
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   156
                                                                        [exBegin]
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   157
        |top field forwarder|
144
claus
parents: 142
diff changeset
   158
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   159
        top := StandardSystemView new.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   160
        top extent:200@200.
144
claus
parents: 142
diff changeset
   161
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   162
        field := EditField in:top.
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   163
        field origin:0.0@0.0; width:1.0.
144
claus
parents: 142
diff changeset
   164
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   165
        forwarder := KeyboardForwarder to:nil. 
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   166
        field delegate:forwarder.
144
claus
parents: 142
diff changeset
   167
620
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   168
        top open
c840b7106a64 examples
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
   169
                                                                        [exEnd]
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   170
"
9c2378152500 Initial revision
claus
parents:
diff changeset
   171
! !
9c2378152500 Initial revision
claus
parents:
diff changeset
   172
9c2378152500 Initial revision
claus
parents:
diff changeset
   173
!KeyboardForwarder class methodsFor:'instance creation'!
9c2378152500 Initial revision
claus
parents:
diff changeset
   174
139
claus
parents: 134
diff changeset
   175
from:sourceView to:destination
claus
parents: 134
diff changeset
   176
    "create and return a new KeyboardForwarder to redirect key events
claus
parents: 134
diff changeset
   177
     for sourceView to destination. Events from other than the sourceView
claus
parents: 134
diff changeset
   178
     will not be forwarded. The forwarded event will be reported including
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   179
     the original view as argument (i.e. as #keyPress:x:y:view:).
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   180
139
claus
parents: 134
diff changeset
   181
     Use this, if the destination is not a view."
claus
parents: 134
diff changeset
   182
claus
parents: 134
diff changeset
   183
    ^ self new sourceView:sourceView; destination:destination
claus
parents: 134
diff changeset
   184
!
claus
parents: 134
diff changeset
   185
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   186
from:sourceView toView:destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   187
    "create and return a new KeyboardForwarder to redirect key events
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   188
     for sourceView to destinationView. Events from other than the sourceView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   189
     will not be forwarded. The forwarded event will be reported excluding
139
claus
parents: 134
diff changeset
   190
     the original view as argument (i.e. as #keyPress:x:y:). 
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   191
139
claus
parents: 134
diff changeset
   192
     Use this, if the destination is a view."
claus
parents: 134
diff changeset
   193
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   194
    ^ self new sourceView:sourceView; destinationView:destinationView
134
claus
parents: 128
diff changeset
   195
!
claus
parents: 128
diff changeset
   196
139
claus
parents: 134
diff changeset
   197
to:destination
claus
parents: 134
diff changeset
   198
    "create and return a new KeyboardForwarder to redirect any key event
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   199
     to destination (independent of the view in which the event originally
139
claus
parents: 134
diff changeset
   200
     occurred). The forwarded event will be reported including
claus
parents: 134
diff changeset
   201
     the original view as argument (i.e. as #keyPress:x:y:view:). 
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   202
139
claus
parents: 134
diff changeset
   203
     Use this, if the destination is not a view."
claus
parents: 134
diff changeset
   204
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   205
    ^ self to:destination condition:nil filter:nil 
139
claus
parents: 134
diff changeset
   206
!
claus
parents: 134
diff changeset
   207
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   208
to:destination condition:aCondition
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   209
    "create and return a new KeyboardForwarder to redirect any key event
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   210
     to destination 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   211
     (independent of the view in which the event originally occurred) 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   212
     but only, if some condition as specified by aCondition
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   213
     is met. The forwarded event will be reported including
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   214
     the original view as argument (i.e. as #keyPress:x:y:view:).
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   215
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   216
     Use this, if the destination is not a view."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   217
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   218
    ^ self to:destination condition:aCondition filter:nil 
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   219
!
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   220
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   221
to:destination condition:aCondition filter:aFilterBlock
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   222
    "create and return a new KeyboardForwarder to redirect any key event
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   223
     to destination
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   224
     (independent of the view in which the event originally occurred) 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   225
     but only, if some condition as specified by aCondition
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   226
     is met and aFilterBlock returns true for that key.
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   227
     The forwarded event will be reported including
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   228
     the original view as argument (i.e. as #keyPress:x:y:view:). 
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   229
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   230
     Use this, if the destination is not a view."
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   231
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   232
    ^ self new destination:destination; condition:aCondition; filter:aFilterBlock
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   233
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   234
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   235
toView:destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   236
    "create and return a new KeyboardForwarder to redirect any key event
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   237
     to destinationView 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   238
     (independent of the view in which the event originally occurred). 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   239
     The forwarded event will be reported excluding
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   240
     the original view as argument (i.e. as #keyPress:x:y:).
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   241
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   242
     Use this, if the destination is a view."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   243
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   244
    ^ self toView:destinationView condition:nil filter:nil 
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   245
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   246
144
claus
parents: 142
diff changeset
   247
toView:destinationView condition:aCondition
139
claus
parents: 134
diff changeset
   248
    "create and return a new KeyboardForwarder to redirect any key event
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   249
     to destinationView 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   250
     (independent of the view in which the event originally occurred) but only, 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   251
     if some condition as specified by aCondition
139
claus
parents: 134
diff changeset
   252
     is met. The forwarded event will be reported excluding
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   253
     the original view as argument (i.e. as #keyPress:x:y:).
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   254
139
claus
parents: 134
diff changeset
   255
     Use this, if the destination is a view."
claus
parents: 134
diff changeset
   256
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   257
    ^ self toView:destinationView condition:aCondition filter:nil 
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   258
!
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   259
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   260
toView:destinationView condition:aCondition filter:aFilterBlock
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   261
    "create and return a new KeyboardForwarder to redirect any key event
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   262
     to destinationView 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   263
     (independent of the view in which the event originally occurred) 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   264
     but only, if some condition as specified by aCondition
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   265
     is met and aFilterBlock returns true for that key.
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   266
     The forwarded event will be reported excluding
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   267
     the original view as argument (i.e. as #keyPress:x:y:). 
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   268
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   269
     Use this, if the destination is a view."
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   270
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   271
    ^ self new destinationView:destinationView; condition:aCondition; filter:aFilterBlock
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   272
! !
9c2378152500 Initial revision
claus
parents:
diff changeset
   273
144
claus
parents: 142
diff changeset
   274
!KeyboardForwarder methodsFor:'accessing'!
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   275
134
claus
parents: 128
diff changeset
   276
condition:aCondition
144
claus
parents: 142
diff changeset
   277
    "set the condition - typically a block"
claus
parents: 142
diff changeset
   278
134
claus
parents: 128
diff changeset
   279
    condition := aCondition
claus
parents: 128
diff changeset
   280
!
claus
parents: 128
diff changeset
   281
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   282
destination
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   283
    "return the destination"
144
claus
parents: 142
diff changeset
   284
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   285
    ^ destination
139
claus
parents: 134
diff changeset
   286
!
claus
parents: 134
diff changeset
   287
claus
parents: 134
diff changeset
   288
destination:anObject 
144
claus
parents: 142
diff changeset
   289
    "set the destination 
claus
parents: 142
diff changeset
   290
     - that one will get the event with an additional view arg."
claus
parents: 142
diff changeset
   291
139
claus
parents: 134
diff changeset
   292
    destination := anObject
claus
parents: 134
diff changeset
   293
!
claus
parents: 134
diff changeset
   294
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   295
destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   296
    "return the destination view"
144
claus
parents: 142
diff changeset
   297
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   298
    ^ destinationView
139
claus
parents: 134
diff changeset
   299
!
claus
parents: 134
diff changeset
   300
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   301
destinationView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   302
    "set the destination view"
144
claus
parents: 142
diff changeset
   303
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   304
    destinationView := aView
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   305
!
9c2378152500 Initial revision
claus
parents:
diff changeset
   306
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   307
filter:aOneArgBlock
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   308
    "set the filter - if non-nil, only keys for which it returns true are forwarded"
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   309
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   310
     filter := aOneArgBlock
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   311
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   312
    "Created: 4.2.1996 / 20:35:15 / cg"
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   313
!
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   314
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   315
sourceView
144
claus
parents: 142
diff changeset
   316
    "get the sourceView - if nonNil, only events from this view will be forwarded"
claus
parents: 142
diff changeset
   317
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   318
    ^ sourceView
142
claus
parents: 140
diff changeset
   319
!
claus
parents: 140
diff changeset
   320
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   321
sourceView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   322
    "set the sourceView - if nonNil, only events from this view will be forwarded"
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   323
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   324
    sourceView := aView
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   325
! !
9c2378152500 Initial revision
claus
parents:
diff changeset
   326
9c2378152500 Initial revision
claus
parents:
diff changeset
   327
!KeyboardForwarder methodsFor:'event forwarding'!
9c2378152500 Initial revision
claus
parents:
diff changeset
   328
9c2378152500 Initial revision
claus
parents:
diff changeset
   329
keyPress:key x:x y:y view:aView
139
claus
parents: 134
diff changeset
   330
    "handle a delegated event - this is sent by the sensor to actually
claus
parents: 134
diff changeset
   331
     forward the event (i.e. after I returned true on handlesKeyPress:.
claus
parents: 134
diff changeset
   332
     Take care of cyclic delegation (via a kludge-test for negative coordinate)."
claus
parents: 134
diff changeset
   333
3094
7ef0f53288bc always use the new #dispatchEvent methods
ca
parents: 2506
diff changeset
   334
    |xDel yDel forwardedEvent|
1967
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   335
490
1d2ed059a063 delegated keyboardMessages get nil as x/y
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   336
    x isNil ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   337
        "
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   338
         already delegated ... ignore
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   339
        "
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   340
        ^ self
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   341
    ].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   342
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   343
    filter notNil ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   344
        (filter value:key) ifFalse:[^ self].
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   345
    ].
9c2378152500 Initial revision
claus
parents:
diff changeset
   346
1967
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   347
    xDel := x.
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   348
    yDel := y.
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   349
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   350
    x == 0 ifTrue:[
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   351
        "
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   352
         already delegated ... care to not delegate twice
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   353
        "
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   354
        xDel := nil.
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   355
        yDel := nil.
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   356
    ].
4aea1cea284e care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents: 1941
diff changeset
   357
139
claus
parents: 134
diff changeset
   358
    destination notNil ifTrue:[
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   359
        "delegating to an app (or anything else)"
490
1d2ed059a063 delegated keyboardMessages get nil as x/y
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   360
        destination keyPress:key x:nil y:nil view:aView.
139
claus
parents: 134
diff changeset
   361
    ] ifFalse:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   362
        destinationView notNil ifTrue:[
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   363
            "delegating to another view"
3682
d756fdb95712 evenTypes - private to windowEvent
ca
parents: 3094
diff changeset
   364
            forwardedEvent := WindowEvent keyPress:key x:xDel y:yDel view:destinationView.
2126
1f108c76dfdb moved event dispatching code to view (where it belongs)
Claus Gittinger <cg@exept.de>
parents: 1967
diff changeset
   365
            destinationView
3094
7ef0f53288bc always use the new #dispatchEvent methods
ca
parents: 2506
diff changeset
   366
                dispatchEvent:forwardedEvent
693
ed557e02b378 dont redelegate delegated messages
Claus Gittinger <cg@exept.de>
parents: 620
diff changeset
   367
                withFocusOn:nil 
ed557e02b378 dont redelegate delegated messages
Claus Gittinger <cg@exept.de>
parents: 620
diff changeset
   368
                delegate:false
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   369
        ]
139
claus
parents: 134
diff changeset
   370
    ]
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   371
2126
1f108c76dfdb moved event dispatching code to view (where it belongs)
Claus Gittinger <cg@exept.de>
parents: 1967
diff changeset
   372
    "Modified: / 20.5.1998 / 22:54:05 / cg"
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   373
!
9c2378152500 Initial revision
claus
parents:
diff changeset
   374
9c2378152500 Initial revision
claus
parents:
diff changeset
   375
keyRelease:key x:x y:y view:aView
139
claus
parents: 134
diff changeset
   376
    "handle a delegated event - this is sent by the sensor to actually
claus
parents: 134
diff changeset
   377
     forward the event (i.e. after I returned true on handlesKeyRelease:.
claus
parents: 134
diff changeset
   378
     Take care of cyclic delegation (via a kludge-test for negative coordinate)."
claus
parents: 134
diff changeset
   379
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   380
    |forwardedEvent xDel yDel|
3094
7ef0f53288bc always use the new #dispatchEvent methods
ca
parents: 2506
diff changeset
   381
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   382
    (x isNil or:[x < 0]) ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   383
        "
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   384
         already delegated ... ignore
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   385
        "
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   386
        ^ self
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   387
    ].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   388
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   389
    filter notNil ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   390
        (filter value:key) ifFalse:[^ self].
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   391
    ].
9c2378152500 Initial revision
claus
parents:
diff changeset
   392
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   393
    xDel := x.
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   394
    yDel := y.
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   395
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   396
    x == 0 ifTrue:[
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   397
        "
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   398
         already delegated ... care to not delegate twice
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   399
        "
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   400
        xDel := nil.
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   401
        yDel := nil.
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   402
    ].
139
claus
parents: 134
diff changeset
   403
    destination notNil ifTrue:[
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   404
        "delegating to an app (or anything else)"
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   405
        destination keyRelease:key x:-1 y:-1 view:aView
139
claus
parents: 134
diff changeset
   406
    ] ifFalse:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   407
        destinationView notNil ifTrue:[
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   408
            "delegating to another view"
3682
d756fdb95712 evenTypes - private to windowEvent
ca
parents: 3094
diff changeset
   409
            forwardedEvent := WindowEvent keyRelease:key x:-1 y:-1 view:destinationView.
d756fdb95712 evenTypes - private to windowEvent
ca
parents: 3094
diff changeset
   410
            destinationView dispatchEvent:forwardedEvent withFocusOn:nil delegate:false
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   411
        ]
139
claus
parents: 134
diff changeset
   412
    ]
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   413
2126
1f108c76dfdb moved event dispatching code to view (where it belongs)
Claus Gittinger <cg@exept.de>
parents: 1967
diff changeset
   414
    "Modified: / 20.5.1998 / 22:54:32 / cg"
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   415
! !
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   416
385
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   417
!KeyboardForwarder methodsFor:'focus forwarding'!
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   418
2506
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   419
hasKeyboardFocus:aBoolean
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   420
    "forward focus information to my destination"
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   421
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   422
    destinationView notNil ifTrue:[
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   423
        destinationView hasKeyboardFocus:aBoolean
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   424
    ].
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   425
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   426
    "Modified: 25.2.1997 / 23:16:35 / cg"
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   427
!
221b75206a75 focus handling changed.
Claus Gittinger <cg@exept.de>
parents: 2126
diff changeset
   428
385
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   429
showFocus:explicit
1380
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   430
    "forward focus information to my destination"
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   431
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   432
    |d|
385
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   433
1380
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   434
    destinationView notNil ifTrue:[
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   435
        d := destinationView
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   436
    ] ifFalse:[
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   437
        d := destination
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   438
    ].
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   439
    d notNil ifTrue:[
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   440
        d showFocus:explicit
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   441
    ]
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   442
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   443
    "Modified: 25.2.1997 / 23:16:35 / cg"
385
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   444
!
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   445
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   446
showNoFocus:explicit
1380
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   447
    "forward focus information to my destination"
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   448
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   449
    |d|
385
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   450
1380
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   451
    destinationView notNil ifTrue:[
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   452
        d := destinationView
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   453
    ] ifFalse:[
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   454
        d := destination
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   455
    ].
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   456
    d notNil ifTrue:[
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   457
        d showNoFocus:explicit
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   458
    ]
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   459
febf152d630f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 697
diff changeset
   460
    "Modified: 25.2.1997 / 23:16:40 / cg"
385
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   461
! !
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   462
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   463
!KeyboardForwarder methodsFor:'queries'!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   464
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   465
checkCondition:typeOfEvent key:key view:aView
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   466
    "return true, if I am interested in an event with type 
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   467
     (#keyPress or #keyRelease) and key for aView."
1941
0141f373c69c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
   468
1693
66ca1549dd82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1380
diff changeset
   469
    |wg|
66ca1549dd82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1380
diff changeset
   470
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   471
    filter notNil ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   472
        (filter value:key) ifFalse:[^ false].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   473
    ].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   474
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   475
    condition notNil ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   476
        condition == #noFocus ifTrue:[
1941
0141f373c69c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
   477
            wg := aView windowGroup.
0141f373c69c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
   478
            (wg isNil or:[wg focusView notNil]) ifTrue:[^ false]
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   479
        ].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   480
        condition isBlock ifTrue:[
8362
573b5a8cc1c5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7660
diff changeset
   481
            (condition value:typeOfEvent value:key value:aView) ifFalse:[^ false]
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   482
        ]
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   483
    ].
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   484
    sourceView notNil ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   485
        ^ aView == sourceView
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   486
    ].
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   487
    ^ true
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   488
1941
0141f373c69c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
   489
    "Modified: / 31.10.1997 / 20:24:42 / cg"
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   490
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   491
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   492
delegatesTo:someone
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   493
    "return true, if I delegate events to someone"
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   494
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   495
    ^ destination == someone or:[destinationView == someone]
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   496
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   497
6352
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   498
handlesButtonMotion:something inView:aView
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   499
    "I am not interested in button events"
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   500
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   501
    ^ false
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   502
!
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   503
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   504
handlesButtonPress:something inView:aView
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   505
    "I am not interested in button events"
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   506
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   507
    ^ false
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   508
!
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   509
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   510
handlesKeyPress:key inView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   511
    "this is the query from the sensor to ask me if I would like to
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   512
     get a keyPress event for key from aView. Return true, if I want so,
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   513
     false otherwise."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   514
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   515
    ^ self checkCondition:#keyPress key:key view:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   516
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   517
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   518
handlesKeyRelease:key inView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   519
    "this is the query from the sensor to ask me if I would like to
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   520
     get a keyRelease event for key from aView. Return true, if I want so,
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   521
     false otherwise."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   522
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   523
    ^ self checkCondition:#keyRelease key:key view:aView
6352
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   524
!
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   525
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   526
handlesPointerEnter:something inView:aView
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   527
    "I am not interested in pointer events"
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   528
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   529
    ^ false
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   530
!
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   531
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   532
handlesPointerLeave:something inView:aView
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   533
    "I am not interested in pointer events"
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   534
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   535
    ^ false
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   536
! !
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   537
251
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   538
!KeyboardForwarder class methodsFor:'documentation'!
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   539
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   540
version
7660
7541edd3ab40 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 6352
diff changeset
   541
    ^ '$Header$'
251
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   542
! !
6352
7db661989259 class: KeyboardForwarder
Stefan Vogel <sv@exept.de>
parents: 5277
diff changeset
   543