Beispiel #1
0
static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
    OSStatus result = eventNotHandledErr ;

    wxMacCarbonEvent cEvent( event ) ;
    
    ControlRef controlRef ;

    cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;

    switch( GetEventKind( event ) )
    {
        case kEventControlHit :
            {
                wxToolBarTool* tbartool = (wxToolBarTool*)data ;
                if ( tbartool->CanBeToggled() )
                {
#ifdef __WXMAC_OSX__
                    ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), !tbartool->IsToggled() );
#else
                    ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle()));
#endif
                }
                ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ;
                result = noErr; 
            }
            break ;
#ifdef __WXMAC_OSX__
        case kEventControlHitTest :
            {
                HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation) ;
                HIRect rect ;
                HIViewGetBounds( controlRef , &rect ) ;
                
                ControlPartCode pc = kControlNoPart ;
                if ( CGRectContainsPoint( rect , pt ) )
                    pc = kControlIconPart ;
                cEvent.SetParameter( kEventParamControlPart , typeControlPartCode, pc ) ;
                result = noErr ;
            }
            break ;
#endif
        default :
            break ;
    }
    return result ;
}
Beispiel #2
0
OSStatus HIOpenGLViewEventControlHitTest (EventHandlerCallRef, EventRef inEvent, HIOpenGLViewData* inData)
{
    // Extract the mouse location
    HIPoint where;
    ControlPartCode part;
    OSStatus err = GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, nil, sizeof(HIPoint), nil, &where);
    require_noerr(err, ParameterMissing);

    // Is the mouse in the view?
    HIRect bounds;
    err = HIViewGetBounds(inData->mControl, &bounds);
    part = CGRectContainsPoint(bounds, where) ? 1 : kControlNoPart;

    // Send back the value of the hit part
    err = SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(ControlPartCode), &part); 

    ParameterMissing:
        return err;
}
Beispiel #3
0
CGWindowID CGWindowAtPosition(CGPoint position) {

    CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements,
                                                       kCGNullWindowID);
    if (windowList == NULL)
        return kCGNullWindowID;

    CGWindowID windowID = kCGNullWindowID;

    for (CFIndex i = 0; i < CFArrayGetCount(windowList); i++) {

        CFDictionaryRef window = CFArrayGetValueAtIndex(windowList, i);

        int layer;
        CFNumberGetValue(CFDictionaryGetValue(window, kCGWindowLayer),
                         kCFNumberIntType,
                         &layer);
        if (layer != 0)
            continue;

        CGRect windowBounds;
        CGRectMakeWithDictionaryRepresentation(CFDictionaryGetValue(window, kCGWindowBounds),
                                               &windowBounds);

        if (CGRectContainsPoint(windowBounds, position)) {
            CFNumberGetValue(CFDictionaryGetValue(window, kCGWindowNumber),
                             kCGWindowIDCFNumberType,
                             &windowID);
            break;
        }
    }

    CFRelease(windowList);

    return windowID;
}
Beispiel #4
0
// -----------------------------------------------------------------------------
//	HITestViewTrack
// -----------------------------------------------------------------------------
//	This is overkill, and probably #ifdef'd out, but is here as an example of
//	a custom tracking handler.
//
OSStatus HITestViewTrack(
	EventRef				inEvent,
	HITestViewData*			inData )
{
	OSStatus				err;
	HIRect					bounds;
	HIPoint					where;
	ControlPartCode			part;
	Boolean					inside;
	Boolean					wasInside;
	Point					qdPt;
	MouseTrackingResult		mouseResult;
	PixMapHandle			portPixMap;

	// Extract the mouse location
	err = GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint,
			NULL, sizeof( HIPoint ), NULL, &where );
	require_noerr( err, ParameterMissing );

	// Is the mouse location in the view?
	err = HIViewGetBounds( inData->view, &bounds );
	if ( CGRectContainsPoint( bounds, where ) )
		part = 1;
	else
		part = kControlNoPart;
	HiliteControl( inData->view, part );
	
	wasInside = true;
	
	// Need the port's pixMap's bounds to convert the mouse location
	portPixMap = GetPortPixMap( GetWindowPort( GetControlOwner( inData->view ) ) );

	// The tracking loop
	while ( true )
	{
		// Check again to see if the mouse is in the view
		if ( CGRectContainsPoint( bounds, where ) )
			part = 1;
		else
			part = kControlNoPart;
		inside = ( part != kControlNoPart );
		
		// If that changed, update
		if ( inside != wasInside )
			HiliteControl( inData->view, part );
		wasInside = inside;

		// Watch the mouse for change
		err = TrackMouseLocation( (GrafPtr)-1L, &qdPt, &mouseResult );

		// Need to convert from global
		QDGlobalToLocalPoint( GetWindowPort( GetControlOwner( inData->view ) ), &qdPt );
		where.x = qdPt.h - (**portPixMap).bounds.left;
		where.y = qdPt.v - (**portPixMap).bounds.top;
		HIViewConvertPoint( &where, NULL, inData->view );

		// Bail out when the mouse is released
		if ( mouseResult == kMouseTrackingMouseReleased )
			break;
	}
	
	// Restore the original highlight
	HiliteControl( inData->view, kControlNoPart );

	// Send back the part upon which the mouse was released
	err = SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode,
			sizeof( ControlPartCode ), &part ); 

ParameterMissing:
	return err;
}
Beispiel #5
0
static pascal OSStatus CustomSpotViewHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon)
{
	OSStatus result = eventNotHandledErr;
	CustomSpotViewData* myData = (CustomSpotViewData*)inRefcon;
	
	switch (GetEventClass(inEvent))
	{
		case kEventClassHIObject:
			switch (GetEventKind(inEvent))
			{
				case kEventHIObjectConstruct:
				{
					myData = (CustomSpotViewData*) calloc(1, sizeof(CustomSpotViewData));
					GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(myData->view), NULL, &myData->view);
					result = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(myData), &myData);
					break;
				}
					
				case kEventHIObjectInitialize:
				{
					HIRect bounds;
					GetEventParameter(inEvent, kEventParamBounds, typeHIRect, NULL, sizeof(bounds), NULL, &bounds);
					myData->spot.x = CGRectGetMidX(bounds) - CGRectGetMinX(bounds);
					myData->spot.y = CGRectGetMidY(bounds) - CGRectGetMinY(bounds);
					HIViewSetVisible(myData->view, true);
					break;
				}
					
				case kEventHIObjectDestruct:
				{
					free(myData);
					result = noErr;
					break;
				}
					
				default:
					break;
			}
			break;
			
		case kEventClassControl:
			switch (GetEventKind(inEvent))
			{
				case kEventControlDraw:
				{
					CGContextRef	context;
					HIRect			bounds;
					result = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(context), NULL, &context);
					HIViewGetBounds(myData->view, &bounds);
					
					if (!IsControlActive(myData->view))
					{
						CGContextSetGrayStrokeColor(context, 0.5, 0.3);
						CGContextSetGrayFillColor(context, 0.5, 0.3);
					}
					else
					{
						CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.7);
						CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.7);
					}
					
					CGContextSetLineWidth(context, 3.0);
					CGContextStrokeRect(context, bounds);
					
					HIRect spot = { {myData->spot.x - 4.0, myData->spot.y - 4.0}, {8.0, 8.0} };
					CGContextFillRect(context, spot);
					
					result = noErr;
					break;
				}
					
				case kEventControlBoundsChanged:
				{
					HIRect newHIBounds;
					GetEventParameter(inEvent, kEventParamCurrentBounds, typeHIRect, NULL, sizeof(newHIBounds), NULL, &newHIBounds);
					myData->spot.x = CGRectGetMidX(newHIBounds) - CGRectGetMinX(newHIBounds);
					myData->spot.y = CGRectGetMidY(newHIBounds) - CGRectGetMinY(newHIBounds);
					break;
				}
					
				case kEventControlHitTest:
				{
					HIPoint	pt;
					HIRect	bounds;
					GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(pt), NULL, &pt);
					HIViewGetBounds(myData->view, &bounds);
					ControlPartCode part = (CGRectContainsPoint(bounds, pt))?kControlButtonPart:kControlNoPart;
					result = SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part);
					break;
				}
					
				case kEventControlTrack:
				{
					Point qdPoint;
					Rect qdWindowBounds;
					HIPoint hiPoint;
					HIRect hiViewBounds;
					MouseTrackingResult mouseStatus = kMouseTrackingMouseDown;
					
					HIViewGetBounds(myData->view, &hiViewBounds);
					GetWindowBounds(GetControlOwner(myData->view), kWindowStructureRgn, &qdWindowBounds);
					
					// handle the first mouseDown before moving
					GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(hiPoint), NULL, &hiPoint);
					
					while (mouseStatus != kMouseTrackingMouseUp)
					{
						if (CGRectContainsPoint(hiViewBounds, hiPoint))
						{
							if (hiPoint.x < hiViewBounds.origin.x+4) hiPoint.x = hiViewBounds.origin.x+4;
							if (hiPoint.x > hiViewBounds.origin.x+hiViewBounds.size.width-4) hiPoint.x = hiViewBounds.origin.x+hiViewBounds.size.width-4;
							if (hiPoint.y < hiViewBounds.origin.y+4) hiPoint.y = hiViewBounds.origin.y+4;
							if (hiPoint.y > hiViewBounds.origin.y+hiViewBounds.size.height-4) hiPoint.y = hiViewBounds.origin.y+hiViewBounds.size.height-4;
							myData->spot = hiPoint;
							HIViewSetNeedsDisplay(myData->view, true);
						}
						
						// a -1 GrafPtr to TrackMouseLocation yields global coordinates
						TrackMouseLocation((GrafPtr)-1L, &qdPoint, &mouseStatus);						
						
						// convert to window-relative coordinates
						hiPoint.x = qdPoint.h - qdWindowBounds.left;
						hiPoint.y = qdPoint.v - qdWindowBounds.top;
						
						// convert to view-relative coordinates
						HIViewConvertPoint(&hiPoint, NULL, myData->view);
					}
					break;
				}
					
					
				default:
					break;
			}
			break;
			
		default:
			break;
	}
	
	return result;
}
Beispiel #6
0
bool NDUITableLayer::TouchMoved(NDTouch* touch)
{
    NDUILayer::TouchMoved(touch);

    if (m_sectionTitleVisibled)
    {
        for (unsigned int i = 0; i < m_sectionTitles.size(); i++)
        {
            NDUISectionTitle* sectionTitle = m_sectionTitles.at(i);
            CGRect rect = sectionTitle->GetScreenRect();
            if (CGRectContainsPoint(rect, m_beginTouch))
                return false;
        }
    }

    //this->SetFocusOnCell(m_curSection->GetFocusCellIndex());

    if (m_curSection)
    {
        CGPoint prePos = touch->GetPreviousLocation();
        CGPoint curPos = touch->GetLocation();
        CGFloat subValue = curPos.y - prePos.y;

        if (m_sectionTitles.size() > m_curSectionIndex)
        {
            NDUISectionTitle* sectionTitle = m_sectionTitles.at(m_curSectionIndex);
            CGRect sectionTitleRect = sectionTitle->GetFrameRect();

            if (m_curSection->Count() > 0)
            {
                if (subValue > 0)
                {
                    NDUINode* firstCell = m_curSection->Cell(0);
                    if (m_sectionTitleVisibled)
                    {
                        if (firstCell->GetFrameRect().origin.y + subValue  > sectionTitle->GetFrameRect().origin.y + sectionTitle->GetFrameRect().size.height)
                        {
                            subValue = sectionTitle->GetFrameRect().origin.y + sectionTitle->GetFrameRect().size.height - firstCell->GetFrameRect().origin.y + m_cellsInterval;
                        }
                    }
                    else
                    {
                        if (firstCell->GetFrameRect().origin.y + subValue  > sectionTitle->GetFrameRect().origin.y)
                        {
                            subValue = sectionTitle->GetFrameRect().origin.y  - firstCell->GetFrameRect().origin.y + m_cellsInterval;
                        }
                    }

                    if (subValue <= 0)
                        return false;
                }
                else
                {
                    NDUINode* lastCell = m_curSection->Cell(m_curSection->Count() - 1);
                    CGFloat sectionBottom = this->GetFrameRect().size.height;
                    if (m_curSectionIndex + 1 < m_dataSource->Count())
                    {
                        NDUISectionTitle* nextSectionTitle = m_sectionTitles.at(m_curSectionIndex + 1);
                        sectionBottom = nextSectionTitle->GetFrameRect().origin.y - m_cellsInterval;
                    }
                    if (lastCell->GetFrameRect().origin.y + lastCell->GetFrameRect().size.height + subValue < sectionBottom)
                    {
                        subValue = sectionBottom - lastCell->GetFrameRect().origin.y - lastCell->GetFrameRect().size.height - m_cellsInterval;
                    }

                    if (subValue >= 0)
                        return false;
                }
            }
        }

        if (m_backgrounds.size() > m_curSectionIndex)
        {
            NDUIRecttangle* cellBackground = m_backgrounds.at(m_curSectionIndex);
            for (unsigned int i = 0; i < m_curSection->Count(); i++)
            {
                NDUINode* uiNode = m_curSection->Cell(i);
                CGRect nodeRect = uiNode->GetFrameRect();
                uiNode->SetFrameRect(CGRectMake(nodeRect.origin.x, nodeRect.origin.y + subValue, nodeRect.size.width, nodeRect.size.height));
                bool bDraw = CGRectIntersectsRect(cellBackground->GetFrameRect(), uiNode->GetFrameRect());
                uiNode->EnableDraw(bDraw);
            }
        }


        if (m_scrollBars.size() > m_curSectionIndex)
        {
            if (m_scrollBarVisibled)
            {
                NDUIVerticalScrollBar* scrollBar = m_scrollBars.at(m_curSectionIndex);
                scrollBar->SetCurrentContentY(scrollBar->GetCurrentContentY() - subValue);
            }
        }

    }

    return true;
}