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