Trapping a key press event 
Author Message
 Trapping a key press event

Hi,

I want to trap the keystrokes going to an instance of
AbtContainerDetailsColumn but it doesn't understand
#addEventHandler:receiver:selector:clientData: so I can't add the event
handler.

Is there an event handler already set up for this control?  if so what
message is triggered on the event?  The documentation is next to useless on
this subject.

I know I could use a converter to do any checking I need done but I only
want to accept numerics in the column and it seems a bit petty to allow the
user to type in what they want then say "Sorry numerics only" after they
tab out.

Any help would be appriciated!

TIA,
Gary



Wed, 18 Jun 1902 08:00:00 GMT  
 Trapping a key press event



Quote:

> I want to trap the keystrokes going to an instance of
> AbtContainerDetailsColumn but it doesn't understand
> #addEventHandler:receiver:selector:clientData: so I can't add the event
> handler.

Very true. Table columns are not widgets, so that message has no meaning.
The widget that actually accepts the keys strokes is the *cell editor*
managed by the edit policy setup for the column.

Quote:
> Is there an event handler already set up for this control?  if so what
> message is triggered on the event?  The documentation is next to useless
on
> this subject.

There is lots of documentation within the image in the form of class and
method comments. Review the class comment for EwTableList and take a look
at the subclasses of EwTextEditPolicy.

Quote:
> I know I could use a converter to do any checking I need done but I only
> want to accept numerics in the column and it seems a bit petty to allow
the
> user to type in what they want then say "Sorry numerics only" after they
> tab out.

You can set this up pretty easily by using a custom edit policy. All you
need to do is hook the XmNmodifyVerifyCallback callback for the cell
editor. The callData object returned by the callback includes the text that
was entered and gives you the opportunity (via the #doit: message) to
cancel the entry (this callback is triggered after the user types the
character but *before* it appears within the widget). A sample handler that
would allow only integer input might look like:

        modifyVerify: aWidget clientData: clientData callData: callData
                callData doit: (callData text conform: [:aChar |
                        aChar isDigit or: [aChar == $-]])

Setting it up for arbitrary numeric input would be only slightly harder.

-Eric Clayberg
President                      
Smalltalk Systems (StS), a division of Instantiations, Inc.



   Web: http://www.smalltalksystems.com
        http://www.instantiations.com

GO SMALLTALK!



Wed, 18 Jun 1902 08:00:00 GMT  
 Trapping a key press event



Quote:

> > I want to trap the keystrokes going to an instance of
> > AbtContainerDetailsColumn but it doesn't understand
> > #addEventHandler:receiver:selector:clientData: so I can't add the event
> > handler.

> correct.  I tried

>    self table widget
>            addEventHandler:  KeyPressMask
>            receiver: self
>            selector: #keyPressedInTable:clientData:callData:
>            clientData: nil.

> but #keyPressedInTable:clientData:callData: is never called.

...because the table itself does not accept key strokes. Rather, the
current cell editor the user is typing into is the widget that accepts the
key strokes. You could, for example, hook the KeyPressMask event on the
cell editor if you wished.

Quote:
> > I know I could use a converter to do any checking I need done but I
only
> > want to accept numerics in the column and it seems a bit petty to allow
the
> > user to type in what they want then say "Sorry numerics only" after
they
> > tab out.

> unfortunately, I think that's the only choice.  I looked into it at the
time,
> and validation on a table cell value can only be performed when the
> #aboutToEndEdit event is triggered by the AbtContainerDetailsColumn part.

No. You could also hook the XmNmodifyVerifyCallback callback of the cell
editor (via a custom edit policy) and validate the input on a character by
character basis.

-Eric Clayberg
President                      
Smalltalk Systems (StS), a division of Instantiations, Inc.



   Web: http://www.smalltalksystems.com
        http://www.instantiations.com

GO SMALLTALK!



Wed, 18 Jun 1902 08:00:00 GMT  
 Trapping a key press event

Hi Eric,

Thanks for your help with this problem but I'm not quite there yet...

Quote:
> You can set this up pretty easily by using a custom edit policy. All you
> need to do is hook the XmNmodifyVerifyCallback callback for the cell
> editor.

How do I get hold of this cell editor object?  I'm using an
EwTextEditPolicy object, as the edit policy for the
AbtContainerDetailsColumn, which says it will use a text widget, (CwText?),
to edit the cell.  This is great because CwText responds to
addCallback:receiver:selector:cllientData: so I could hook up the
XmNmodifyVerifyCallback.  Unfortunatly, when I inspect the editPolicy for
the column and look at the widget IV it says it's an
AbtContainerDetailsColumn, which does not respond to
addCallback:receiver:selector:cllientData:

I can't seem to find an accessor which will give me access to the *cell
editor*.  What am I missing?

TIA
Gary

The callData object returned by the callback includes the text that

Quote:
> was entered and gives you the opportunity (via the #doit: message) to
> cancel the entry (this callback is triggered after the user types the
> character but *before* it appears within the widget). A sample handler
that
> would allow only integer input might look like:

>    modifyVerify: aWidget clientData: clientData callData: callData
>            callData doit: (callData text conform: [:aChar |
>                    aChar isDigit or: [aChar == $-]])

> Setting it up for arbitrary numeric input would be only slightly harder.

> -Eric Clayberg
> President                      
> Smalltalk Systems (StS), a division of Instantiations, Inc.



>    Web: http://www.smalltalksystems.com
>         http://www.instantiations.com

> GO SMALLTALK!



Wed, 18 Jun 1902 08:00:00 GMT  
 Trapping a key press event



Quote:

> Thanks for your help with this problem but I'm not quite there yet...

> > You can set this up pretty easily by using a custom edit policy. All
you
> > need to do is hook the XmNmodifyVerifyCallback callback for the cell
> > editor.

> How do I get hold of this cell editor object?  I'm using an
> EwTextEditPolicy object, as the edit policy for the
> AbtContainerDetailsColumn, which says it will use a text widget,
(CwText?),
> to edit the cell.  This is great because CwText responds to
> addCallback:receiver:selector:cllientData: so I could hook up the
> XmNmodifyVerifyCallback.  Unfortunatly, when I inspect the editPolicy for
> the column and look at the widget IV it says it's an
> AbtContainerDetailsColumn, which does not respond to
> addCallback:receiver:selector:cllientData:

> I can't seem to find an accessor which will give me access to the *cell
> editor*.  What am I missing?

All you need to do is subclass EwTextEditPolicy and override the
#beginEditOn: method. See the comment in the EwTextEditPolicy>>beginEditOn:
method for a further explanation. Also examine other implementors of
#beginEditOn: to get an idea of the things you can do with it. In your
case, it should look something like this:

        beginEditOn: aWidget
                super beginEditOn: aWidget.
                aWidget
                        addCallback: XmNmodifyVerifyCallback
                                receiver: self
                                selector: #modifyVerify:clientData:callData:
                                clientData: nil.

"aWidget" in this context is the actual cell editor. "self widget" in this
context refers back to the owner of the edit policy (in this case the table
column).

The #modifyVerify:clientData:callData: method I proposed yesterday should
also go in this subclass. To clean up after the editing is complete, you
should also implement the following:

        endEditOn: aWidget
                super endEditOn: aWidget.
                aWidget
                        removeCallback: XmNmodifyVerifyCallback
                                receiver: self
                                selector: #modifyVerify:clientData:callData:
                                clientData: nil.

If you want to see an example of a fancy, "plugable" edit policy, look at
AbtEwObjectTextEditPolicy for some ideas (don't use
AbtEwObjectTextEditPolicy in your app as it is part of VA's development
support, not runtime).

-Eric Clayberg
President                      
Smalltalk Systems (StS), a division of Instantiations, Inc.



   Web: http://www.smalltalksystems.com
        http://www.instantiations.com

GO SMALLTALK!



Wed, 18 Jun 1902 08:00:00 GMT  
 Trapping a key press event

Hi Eric,

Problem solved!!  Thanks a lot for your time.

Gary



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. IBM VA close window upon key pressed event

2. Key press events on a window

3. How to capture key-presses (keyboard-presses)???

4. Only One Tkinter Entry can receive key event event in Linux RH8.0

5. Tracking key presses, mouse clicks and mouse movements?

6. many keys pressed at the same time

7. Command-key presses

8. Changing the cursor when control key pressed.

9. Selecting TAB sheet by pressing TAB key

10. Keycode() - Getting a response to a key press

11. pressing ESC key in source procedure

12. KEY PRESSED DETECT(@@@@ Help Please @@@@)

 

 
Powered by phpBB® Forum Software