Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Can't get mouse hit on custom view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't get mouse hit on custom view




On May 28, 2007, at 9:24 AM, Carlos Eduardo Mello wrote:

Hi,

I need to have different behaviours in my custom view for single click and double click. After reading headers and docs and sample code for carbon events, controls, hiviews, etc., I figured I would need to check for a mouse hit in my view and then check the click count parameter. So, I registered for kEventControlHitTest and kEventControlHit. I believe I am handling the HitTest correctly ( code below ),

Why do you believe this? Have you verified that CGRectContainsPoint is returning the expected result when you click the view and that BackViewHitTest is returning the expected error code?


but I never get the Hit event. [ OS 10.4.9, XCode 2.4, G4 ]

Then that would suggest you *aren't* handling the HitTest event correctly.


Larry


Could any body point out my mistakes/bad assumptions/etc.? Am I doing everything wrong?

// From custom-view event handler...

case kEventClassControl:
		{
			switch ( eventKind )
			{
				case kEventControlInitialize:
					err = noErr;
					break;
				case kEventControlDraw:
					err = theCustomView->BackViewDraw( inEvent );
					break;
				case kEventControlHitTest:
					err = theCustomView->BackViewHitTest( inEvent );
					break;
				case kEventControlGetPartRegion:
					err = theCustomView->BackViewGetRegion( inEvent );
					break;
				case kEventControlHit:
					err = theCustomView->ProcessMouseClick( inEvent );
					break;
			}
			break;
		}



OSStatus MyCustomView::BackViewHitTest( EventRef inEvent )
{
OSStatus err = eventNotHandledErr;
ControlPartCode partCode;
HIPoint mouseLoc;
HIRect hiBounds;

err = GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(mouseLoc), NULL, &mouseLoc );
if(!err)
{
// p.s.: back view is my internal reference to the custom view
err = HIViewGetBounds( backView, &hiBounds );
if(!err)
{
if( CGRectContainsPoint( hiBounds, mouseLoc ) )
partCode = kControlButtonPart;
else
partCode = kControlNoPart;
err = SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, sizeof(partCode), &partCode );
}
}
return err;
}




Dr. Carlos Eduardo Mello (email@hidden)
Music Technology Lab, Music Department
University of Brasília, Brazil
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Can't get mouse hit on custom view (From: Carlos Eduardo Mello <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.