Widget Cursor 
Author Message
 Widget Cursor

I would like the cursor (mouse pointer) to change when it is over
a specific widget.  For example, when the mouse pointer is over a hot
spot, I would like it to change from a arrow to a hand (like one sees on
HTML links).

I have been able to do this for an entire Window, but I haven't found a
way to do this for a specific widget within the window.

Does anyone have any tips?



Sat, 02 Oct 1999 03:00:00 GMT  
 Widget Cursor

Quote:

> I would like the cursor (mouse pointer) to change when it is over
> a specific widget.  For example, when the mouse pointer is over a hot
> spot, I would like it to change from a arrow to a hand (like one sees on
> HTML links).

> I have been able to do this for an entire Window, but I haven't found a
> way to do this for a specific widget within the window.

> Does anyone have any tips?

Hello,
You will have to modify this widget's controller to handle this event.
Every component has a method called "defaultControllerClass".
This will return the default controller for the widget. You can make
your own subclass of the default class in the "defaultControllerClass"
which handles mouse events as you described them. Also, instead of
modifying the base class you can dynamicaly substitute widget default
controller with your own controller at runtime in your "postBuildWith:"
method. This may look something like:

postBuildWith: aBldr
        super postBuildWith: aBldr.
        (aBldr componentAt: #componentID) widget controller: MyController new

I think that should do it.
--
Vladimir Tokarskiy
350 West Erie
2nd Floor
Chicago, IL 60610
http://www.objsoft.com



Sun, 03 Oct 1999 03:00:00 GMT  
 Widget Cursor

Quote:

> I would like the cursor (mouse pointer) to change when it is over
> a specific widget.  For example, when the mouse pointer is over a hot
> spot, I would like it to change from a arrow to a hand (like one sees on
> HTML links).

> I have been able to do this for an entire Window, but I haven't found a
> way to do this for a specific widget within the window.

> Does anyone have any tips?

Todd:
You didn't mention which Smalltalk you are using so I'll take the optomistic approach that you are
using IBM Smalltalk :-)

There are two possible scenarios. The first is where you are interested in changing the cursor for
particular widgets, the second, where you want to change the cursor for particular regions for a
given widget.

For the first case you'll have to set up an observation on the widget that you want the cursor to
change over like this:
        aWidget addEventHandler: PointerMotionMask
                        receiver: self
                        selector: #pointerOver:clientData:callData:
                        clientData: nil;

In #pointerOver:clientData:callData: change the cursor to the hand or foot or whatever, as you have
already done.

To reset the cursor when the pointer leaves the widget, set up an observation on the widget's parent
in the same way and free the cursor in that callback.

For the second case, just set up an observation on the widget as above but set/reset the cursor
depending on whether the pointer is within the hotspot. Assuming you know where the hotspot is, just
detect whether the pointer point is contained within the hotspot region and adjust the cursor
accordingly. There's a sort of goofy example of this in the VisualAge Help Example feature that comes
with the product. Just load that and look at AbtHelpBrowserView>>#mouseMoved:clientData:callData: in
AbtExamplesHelpBrowserSubApp. Cut, paste and enjoy.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mike Silverstein, Lead Architect        voice: (919) 363-3946
SilverMark, Inc.                          fax: (919) 362-0772

Raleigh, NC                         http://www.silvermark.com



Sun, 03 Oct 1999 03:00:00 GMT  
 Widget Cursor

What's worked for me in Visualage (and I assume IBM Smalltalk/Windows)..

Given aCwWidget that's been mapped/managed...

exampleSetHandCursorFor: aCwWidget

        | window cursor |

        window := aCwWidget window.
        cursor := window display createFontCursor: XCHand2.
        window defineCursor: cursor

Whenever the mouse passes over aCwWidget, it will change to XCHand2 (which
is one of the many predefined cursors accessible via a pool dictionary).
I'm not sure, but you may be responsible for freeing the cursor when you
destroy aCwWidget.

Regards,
Bob Manjoney



Quote:

> > I would like the cursor (mouse pointer) to change when it is over
> > a specific widget.  
> >... stuff deleted...
> For the first case you'll have to set up an observation on the widget

that you want the cursor to
Quote:
> change over like this:
>    aWidget addEventHandler: PointerMotionMask
>                    receiver: self
>                    selector: #pointerOver:clientData:callData:
>                    clientData: nil;

> In #pointerOver:clientData:callData: change the cursor to the hand or

foot or whatever, as you have
Quote:
> already done.

> To reset the cursor when the pointer leaves the widget, set up an

observation on the widget's parent
Quote:
> in the same way and free the cursor in that callback.

> For the second case, just set up an observation on the widget as above

but set/reset the cursor
Quote:
> depending on whether the pointer is within the hotspot. Assuming you know

where the hotspot is, just
Quote:
> detect whether the pointer point is contained within the hotspot region

and adjust the cursor
Quote:
> accordingly. There's a sort of goofy example of this in the VisualAge

Help Example feature that comes
Quote:
> with the product. Just load that and look at

AbtHelpBrowserView>>#mouseMoved:clientData:callData: in
Quote:
> AbtExamplesHelpBrowserSubApp. Cut, paste and enjoy.



Sun, 03 Oct 1999 03:00:00 GMT  
 Widget Cursor

Quote:

> I would like the cursor (mouse pointer) to change when it is over
> a specific widget.  For example, when the mouse pointer is over a hot
> spot, I would like it to change from a arrow to a hand (like one sees on
> HTML links).

> I have been able to do this for an entire Window, but I haven't found a
> way to do this for a specific widget within the window.

> Does anyone have any tips?

Todd,

You can try to "abuse" the drag and drop feature of VW 2.5.x
You have to set up the widget as a drop target and write the necessary
methods. Compare the description in the VW Cook Book in the chapter drag
and drop.

HTH,
Frank

--
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Frank Derichsweiler                                     |

| I speak for myself and not for my employer.             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+



Thu, 07 Oct 1999 03:00:00 GMT  
 Widget Cursor

Quote:

>You will have to modify this widget's controller to handle this event.
>Every component has a method called "defaultControllerClass".
>This will return the default controller for the widget. You can make
>your own subclass of the default class in the "defaultControllerClass"
>which handles mouse events as you described them.

Todd,

If you choose the above approach to implement your hypertext example,
the new Controller subclass may look like this:

        cursor
                ^self isHyperlinkUnderCursor
                        ifTrue: [HyperlinkCursor]
                        ifFalse: [Cursor normal]

        isControlWanted
                | cursor |
                cursor := self cursor.
                Cursor currentCursor == cursor
                        ifFalse: [cursor show].
                ^super isControlWanted

        controlTerminate
                Cursor normal show.
                ^super controlTerminate

Of course, you must implement method isHyperlinkUnderCursor. You can
create a new cursor with

        HyperlinkCursor := (Cursor
                imageArray: #( ... )
                maskArray: #( ... )
                hotSpot: aPoint
                name: 'hyperlink')

Hope this helps,
Kai

--



Thu, 07 Oct 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. When enabling and disabling text widget cursor behaves unpredictable

2. Fatal Bug in Tcl/Tk 8.2 (W'95/Solaris 2.6) Scale widget -cursor hand2

3. widget cursor

4. text widget cursor controls?

5. Problem setting entry widget cursor position under trace

6. Problem with entry widget cursor

7. Menus & entry widget cursors

8. Moving cursor in tk widget

9. tkdnd within a text widget with blinking cursor

10. Change cursor for all widgets

11. TIP #197: Text Widget Persistant Cursor

12. Problems with two cursors in text widgets

 

 
Powered by phpBB® Forum Software