Welcome to MacBoardz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Mouse event handling (Carbon)

 
   Macintosh computer (Home) -> Programmer Help RSS
Next:  NSTableColumn 101 Questions  
Author Message
H

External


Since: Sep 16, 2006
Posts: 11



(Msg. 1) Posted: Wed Jan 30, 2008 10:51 pm
Post subject: Mouse event handling (Carbon)
Archived from groups: comp>sys>mac>programmer>help (more info?)

I am trying to catch mouse events in a control. I can catch control
events but no mouse events. Attached is a simple sample:

// a list of all catchable events:
static EventTypeSpec const eventList[] =
{
{kEventClassControl, kEventControlDraw},
{kEventClassControl, kEventControlHit},
};

static EventTypeSpec const mouseEventList[] =
{
{kEventClassMouse, kEventMouseDown}
};

static pascal OSStatus EventHandler(EventHandlerCallRef handler,
EventRef EventReference, void* Data);
static pascal OSStatus MouseEventHandler(EventHandlerCallRef handler,
EventRef EventReference, void* Data);

DEFINE_ONE_SHOT_HANDLER_GETTER(EventHandler)
DEFINE_ONE_SHOT_HANDLER_GETTER(MouseEventHandler)


During control initialization I install the handlers:


InstallControlEventHandler(MouseControlRef,GetMouseEventHandlerUPP(),GetE
ventTypeCount(mouseEventList),mouseEventList,NULL,NULL);

InstallControlEventHandler(ControlRef,GetEventHandlerUPP(),GetEventTypeCo
unt(eventList),eventList,NULL,NULL);


By doing so I get all control events but no mouse event. What do I have
to do to get the mouse events?

Hartwig

 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
Ben Artin

External


Since: Jun 20, 2005
Posts: 30



(Msg. 2) Posted: Thu Jan 31, 2008 5:34 pm
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , H wrote:

> I am trying to catch mouse events in a control.

Use kEventClassControl, kEventControlClick. kEventClassMouse events are not sent
to the control because the window receives the mouse event, traverses the
control hierarchy, finds the control affected by the click, and sends it a
kEventControlClick event.

hth

Ben

--
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
H

External


Since: Sep 16, 2006
Posts: 11



(Msg. 3) Posted: Fri Feb 01, 2008 5:35 pm
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Ben Artin wrote:

> In article , H wrote:
>
> > I am trying to catch mouse events in a control.
>
> Use kEventClassControl, kEventControlClick. kEventClassMouse events are not
> sent
> to the control because the window receives the mouse event, traverses the
> control hierarchy, finds the control affected by the click, and sends it a
> kEventControlClick event.
>
> hth
>
> Ben
Thanks for the answer but ....
The problem is that I am not looking for a mouse click event but a mouse
moved event. And there is no equivalent in kEventClassControl. So, how
can I catch this event?

Hartwig
 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 4) Posted: Fri Feb 01, 2008 8:20 pm
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , H
wrote:

> The problem is that I am not looking for a mouse click event but a mouse
> moved event. And there is no equivalent in kEventClassControl. So, how
> can I catch this event?

I think you'll have to poll the mouse periodically to see if it's moved.

--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.

JR
 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
James W. Walker

External


Since: Jul 01, 2003
Posts: 128



(Msg. 5) Posted: Sat Feb 02, 2008 12:03 am
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , wrote:

> In article ,
> Ben Artin wrote:
>
> > In article , H wrote:
> >
> > > I am trying to catch mouse events in a control.
> >
> > Use kEventClassControl, kEventControlClick. kEventClassMouse events are not
> > sent
> > to the control because the window receives the mouse event, traverses the
> > control hierarchy, finds the control affected by the click, and sends it a
> > kEventControlClick event.
> >
> > hth
> >
> > Ben
> Thanks for the answer but ....
> The problem is that I am not looking for a mouse click event but a mouse
> moved event. And there is no equivalent in kEventClassControl. So, how
> can I catch this event?
>
> Hartwig

Try installing the handler on the application event target, not on a
control. I don't think controls receive raw mouse events.
 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 6) Posted: Sat Feb 02, 2008 3:01 am
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
"James W. Walker" wrote:

> In article , wrote:
>
> > In article ,
> > Ben Artin wrote:
> >
> > The problem is that I am not looking for a mouse click event but a mouse
> > moved event. And there is no equivalent in kEventClassControl. So, how
> > can I catch this event?
>
> Try installing the handler on the application event target, not on a
> control. I don't think controls receive raw mouse events.

The closest thing you can have to a mouse moved event in Carbon is
described here:

<http://preview.tinyurl.com/28w9rt>

If you set the mouseRgn parameter to the WaitNextEvent function, when
the cursor moves outside of that region, WaitNextEvent will return a
mouseMovedMessage. At that point, you are expected to recalculate the
mouseRgn parameter. So you define a region, wait for the mouse to exit
that region, get a mouse moved event, then recalculate the region and
start over.

If you are looking for *continuous* tracking of the cursor in Carbon,
you will probably have to do periodic polling of the cursor position.

In Cocoa, in Mac OS X 10.5 and later, you can use the NSTrackingArea
class to receive notifications when the cursor enters, moves around in,
and leaves a specified area, as described here:

<http://preview.tinyurl.com/2b68yf>

--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.

JR
 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
H

External


Since: Sep 16, 2006
Posts: 11



(Msg. 7) Posted: Sat Feb 02, 2008 11:51 am
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
,
Jolly Roger wrote:

> In article ,
> "James W. Walker" wrote:
>
> > In article , wrote:
> >
> > > In article ,
> > > Ben Artin wrote:
> > >
> > > The problem is that I am not looking for a mouse click event but a mouse
> > > moved event. And there is no equivalent in kEventClassControl. So, how
> > > can I catch this event?
> >
> > Try installing the handler on the application event target, not on a
> > control. I don't think controls receive raw mouse events.
>
> The closest thing you can have to a mouse moved event in Carbon is
> described here:
>
> <http://preview.tinyurl.com/28w9rt>
>
> If you set the mouseRgn parameter to the WaitNextEvent function, when
> the cursor moves outside of that region, WaitNextEvent will return a
> mouseMovedMessage. At that point, you are expected to recalculate the
> mouseRgn parameter. So you define a region, wait for the mouse to exit
> that region, get a mouse moved event, then recalculate the region and
> start over.
>
> If you are looking for *continuous* tracking of the cursor in Carbon,
> you will probably have to do periodic polling of the cursor position.
>
> In Cocoa, in Mac OS X 10.5 and later, you can use the NSTrackingArea
> class to receive notifications when the cursor enters, moves around in,
> and leaves a specified area, as described here:
>
> <http://preview.tinyurl.com/2b68yf>

Thanks for the links and description. It works!

Hartwig
 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
Ben Artin

External


Since: Jun 20, 2005
Posts: 30



(Msg. 8) Posted: Sat Feb 02, 2008 7:39 pm
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , H wrote:

> The problem is that I am not looking for a mouse click event but a mouse
> moved event. And there is no equivalent in kEventClassControl. So, how
> can I catch this event?

Please ignore the incorrect advice given to you elsewhere in this thread,
regarding having to poll and call WaitNextEvent.

If you want to track mouse movement in Carbon, you should use mouse tracking
regions. They are documented at
<http://developer.apple.com/documentation/Carbon/Conceptual/Carbon_Event_Manager/
Tasks/chapter_3_section_10.html#//apple_ref/doc/uid/TP30000989-CH203-TPXREF109>,
in section "Mouse Tracking Regions".

Long story short, you create a mouse tracking region for your window, and then
you install a kEventMouseEntered/Exited on your application target.

If you can rely on 10.4 or later, please use HIView-based tracking regions,
described on the same page.

If mouse tracking regions are not sufficient for what you are trying to
accomplish, please describe your goal.

hth

Ben

--
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>
 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
James W. Walker

External


Since: Jul 01, 2003
Posts: 128



(Msg. 9) Posted: Sun Feb 03, 2008 12:32 am
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
,
Jolly Roger wrote:

> In article ,
> "James W. Walker" wrote:
>
> > In article , wrote:
> >
> > > In article ,
> > > Ben Artin wrote:
> > >
> > > The problem is that I am not looking for a mouse click event but a mouse
> > > moved event. And there is no equivalent in kEventClassControl. So, how
> > > can I catch this event?
> >
> > Try installing the handler on the application event target, not on a
> > control. I don't think controls receive raw mouse events.
>
> The closest thing you can have to a mouse moved event in Carbon is
> described here:
>
> <http://preview.tinyurl.com/28w9rt>

No, that's obsolete information. It is quite possible to receive
kEventClassMouse/kEventMouseMoved Carbon Events, just not at the
control level like the OP was trying. There are also tracking regions,
which are often more appropriate.
 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 10) Posted: Sun Feb 03, 2008 12:21 pm
Post subject: Re: Mouse event handling (Carbon) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
"James W. Walker" wrote:

> In article
> ,
> Jolly Roger wrote:
>
> > In article ,
> > "James W. Walker" wrote:
> >
> > > In article , wrote:
> > >
> > > > In article ,
> > > > Ben Artin wrote:
> > > >
> > > > The problem is that I am not looking for a mouse click event but a
> > > > mouse
> > > > moved event. And there is no equivalent in kEventClassControl. So, how
> > > > can I catch this event?
> > >
> > > Try installing the handler on the application event target, not on a
> > > control. I don't think controls receive raw mouse events.
> >
> > The closest thing you can have to a mouse moved event in Carbon is
> > described here:
> >
> > <http://preview.tinyurl.com/28w9rt>
>
> No, that's obsolete information. It is quite possible to receive
> kEventClassMouse/kEventMouseMoved Carbon Events, just not at the
> control level like the OP was trying. There are also tracking regions,
> which are often more appropriate.

Thanks for the correction.

--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.

JR
 >> Stay informed about: Mouse event handling (Carbon) 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Implementing cocoa like mouse handling in Carbon - I'd like to be able to handle mouse down, move, drag, and up events just like I can in Cocoa, using Carbon. I'd like to get notified of this for *each* control. Currently with the kEventClassMouse events you only get notified of these on a window, and..

Help required - Checkbox Control Event Handling - Hi, buddies i am new to this forum and Carbon programming. I need your help On Checkbox control event handling. I am working on one application in which i already using 5-6 checkbox controls and I want to put one more checkbox control which....

Startup code and event handling in windowless Cocoa app - Hi, This is such a basic question I'm kind of embarrassed to ask it, but I'm new to Cocoa, and haven't managed to find the answer in any documentation. I'm writing a Cocoa app that runs a local web server. It has no main window, but may eventually have...

Handling Events in Dock Menu in Carbon. - I am writing an application in Mac OS X using Carbon. I have a standalone menu created from a NIB . I have attached that menu to the Dock by calling the function // Code snip MenuRef menuDockRef; CreateMenuFromNib(sNibRef , CFSTR("D_Menu") ...

Handling mouse events in a view - Hi, What is the best way to handle mouse events inside of a view? For example, I have an array of objects of various shape, size and location which I draw in a view. I'll need to assign actions for mouse-overs and clicks inside of the various objects....
   Macintosh computer (Home) -> Programmer Help All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]