Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Can I get mouse position inside widget
Can I get mouse position inside widget [message #446123] Wed, 17 November 2004 14:56 Go to next message
Andy Doddington is currently offline Andy DoddingtonFriend
Messages: 17
Registered: July 2009
Junior Member
I am writing a DropTargetListener for a Tree control and wish to find out
where the mouse is relative to each TreeItem widget. THis is to that I can
distinguihs between sibling-type inserts and child-type inserts, which are
otherwise indistinguishable - as far as I can work out.

I can get the display position from the event, along with the widget
itself, but there does not appear to be any way of obtaining the location
of the widget in any form that relates to the mouse position.

The event coordinates are relative to the display, which is fine, but all
of the widget details are relative to the widget itself - e.g. its
location is always set to (0,0).

Does anyone have any ideas as to how I can get the location of the widget
relative to the display (or any other common reference point)?

Note that since the widget is not a Control, I cannot use methods like
toDisplay or toControl to re-map the mouse coordinates.

Any info most appreciated.

Regards,

Andy D
Re: Can I get mouse position inside widget [message #446129 is a reply to message #446123] Wed, 17 November 2004 16:05 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
See Display.map():

/**
* Maps a point from one coordinate system to another.
* When the control is null, coordinates are mapped to
* the display.
* <p>
* NOTE: On right-to-left platforms where the coordinate
* systems are mirrored, special care needs to be taken
* when mapping coordinates from one control to another
* to ensure the result is correctly mirrored.
*
* Mapping a point that is the origin of a rectangle and
* then adding the width and height is not equivalent to
* mapping the rectangle. When one control is mirrored
* and the other is not, adding the width and height to a
* point that was mapped causes the rectangle to extend
* in the wrong direction. Mapping the entire rectangle
* instead of just one point causes both the origin and
* the corner of the rectangle to be mapped.
* </p>
*
* @param from the source <code>Control</code> or <code>null</code>
* @param to the destination <code>Control</code> or <code>null</code>
* @param x coordinates to be mapped
* @param y coordinates to be mapped
* @return point with mapped coordinates
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have
been disposed</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that
created the receiver</li>
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*
* @since 2.1.2
*/
public Point map (Control from, Control to, int x, int y) {


See also:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet91.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup


"Andy Doddington" <andy@doddington.net> wrote in message
news:cnfore$l3j$1@www.eclipse.org...
>I am writing a DropTargetListener for a Tree control and wish to find out
>where the mouse is relative to each TreeItem widget. THis is to that I can
>distinguihs between sibling-type inserts and child-type inserts, which are
>otherwise indistinguishable - as far as I can work out.
>
> I can get the display position from the event, along with the widget
> itself, but there does not appear to be any way of obtaining the location
> of the widget in any form that relates to the mouse position.
> The event coordinates are relative to the display, which is fine, but all
> of the widget details are relative to the widget itself - e.g. its
> location is always set to (0,0).
>
> Does anyone have any ideas as to how I can get the location of the widget
> relative to the display (or any other common reference point)?
>
> Note that since the widget is not a Control, I cannot use methods like
> toDisplay or toControl to re-map the mouse coordinates.
>
> Any info most appreciated.
>
> Regards,
>
> Andy D
>
Re: Can I get mouse position inside widget [message #446135 is a reply to message #446129] Wed, 17 November 2004 17:11 Go to previous message
Andy Doddington is currently offline Andy DoddingtonFriend
Messages: 17
Registered: July 2009
Junior Member
Many thanks Veronica - that has solved my problem!

Cheers,

Andy D

Veronika Irvine wrote:

> See Display.map():

> /**
> * Maps a point from one coordinate system to another.
> * When the control is null, coordinates are mapped to
> * the display.
> * <p>
> * NOTE: On right-to-left platforms where the coordinate
> * systems are mirrored, special care needs to be taken
> * when mapping coordinates from one control to another
> * to ensure the result is correctly mirrored.
> *
> * Mapping a point that is the origin of a rectangle and
> * then adding the width and height is not equivalent to
> * mapping the rectangle. When one control is mirrored
> * and the other is not, adding the width and height to a
> * point that was mapped causes the rectangle to extend
> * in the wrong direction. Mapping the entire rectangle
> * instead of just one point causes both the origin and
> * the corner of the rectangle to be mapped.
> * </p>
> *
> * @param from the source <code>Control</code> or <code>null</code>
> * @param to the destination <code>Control</code> or <code>null</code>
> * @param x coordinates to be mapped
> * @param y coordinates to be mapped
> * @return point with mapped coordinates
> *
> * @exception IllegalArgumentException <ul>
> * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have
> been disposed</li>
> * </ul>
> * @exception SWTException <ul>
> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that
> created the receiver</li>
> * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
> * </ul>
> *
> * @since 2.1.2
> */
> public Point map (Control from, Control to, int x, int y) {


> See also:
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet91.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup


> "Andy Doddington" <andy@doddington.net> wrote in message
> news:cnfore$l3j$1@www.eclipse.org...
>>I am writing a DropTargetListener for a Tree control and wish to find out
>>where the mouse is relative to each TreeItem widget. THis is to that I can
>>distinguihs between sibling-type inserts and child-type inserts, which are
>>otherwise indistinguishable - as far as I can work out.
>>
>> I can get the display position from the event, along with the widget
>> itself, but there does not appear to be any way of obtaining the location
>> of the widget in any form that relates to the mouse position.
>> The event coordinates are relative to the display, which is fine, but all
>> of the widget details are relative to the widget itself - e.g. its
>> location is always set to (0,0).
>>
>> Does anyone have any ideas as to how I can get the location of the widget
>> relative to the display (or any other common reference point)?
>>
>> Note that since the widget is not a Control, I cannot use methods like
>> toDisplay or toControl to re-map the mouse coordinates.
>>
>> Any info most appreciated.
>>
>> Regards,
>>
>> Andy D
>>
Previous Topic:DirectoryFieldEditorQuestion
Next Topic:Z-Order of child widgets of a canvas
Goto Forum:
  


Current Time: Tue Apr 23 10:31:05 GMT 2024

Powered by FUDForum. Page generated in 0.02859 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top