Carbon envents urgent help needed!

Discussion in 'Mac Programming' started by ZiggyH, Mar 12, 2012.

  1. macrumors newbie

    Joined:
    Mar 12, 2012
    #1
    Hi all.

    I'm working on a VST plugin, which have to support both cocoa and carbon.
    The cocoa version is ready, but i still have some troubles with carbon.

    I really need help on this...

    My main problem is to catch the kEventTextInputUnicodeForKeyEvent from the kEventClassTextInput class.

    The host provide me a WindowRef. Then i create an HIView, i Register envent handlers, then add the HIView to the window.

    I'm like this :

    Code:
    // ============================================================================
    // Control Creation
    // ============================================================================
    UInt32 features =	  kControlSupportsDragAndDrop
    				| kControlSupportsFocus
    				| kControlHandlesTracking
    				| kControlSupportsEmbedding
    				| kHIViewIsOpaque
    				| kHIViewFeatureDoesNotUseSpecialParts
    				| kHIViewFeatureGetsFocusOnClick;
    	
    	
    Rect r = {(short)rcSize.top, (short)rcSize.left, (short)rcSize.bottom, (short)rcSize.right};
    	
    OSStatus status = CreateUserPaneControl (0, &r, features, &m_ControlRef);
    if (status != noErr)
    {
    	ASSERT(0);
    }
    
    Then the events handlers:

    Code:
    //============================================================================
    // Control Event Handler
    //============================================================================
    const EventTypeSpec controlEventTypes[] = {	
    		{ kEventClassControl,	kEventControlDraw},
    		{ kEventClassControl,	kEventControlHitTest},
    		{ kEventClassControl,	kEventControlClick},
    		{ kEventClassMouse,		kEventMouseWheelMoved},
    		{ kEventClassControl,	kEventControlDragEnter},
    		{ kEventClassControl,	kEventControlDragWithin},
    		{ kEventClassControl,	kEventControlDragLeave},
    		{ kEventClassControl,	kEventControlDragReceive},
    		{ kEventClassControl,	kEventControlInitialize},
    		{ kEventClassControl,	kEventControlGetClickActivation},
    		{ kEventClassControl,	kEventControlGetOptimalBounds},
    		{ kEventClassScrollable,kEventScrollableGetInfo},
    		{ kEventClassScrollable,kEventScrollableScrollTo},
    		{ kEventClassControl,	kEventControlSetFocusPart},
    		{ kEventClassControl,	kEventControlGetFocusPart},
    		{ kEventClassControl,	kEventControlTrackingAreaExited}
    	};
    	
    InstallControlEventHandler(m_ControlRef, carbonEventHandler, GetEventTypeCount(controlEventTypes), controlEventTypes, this, NULL);
    
    //============================================================================
    // Input Event Handler
    //============================================================================
    const EventTypeSpec keyInputEvents[] = {
    		{ kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
    		{ kEventClassWindow,	kEventWindowFocusAcquired },
    		{ kEventClassWindow,	kEventWindowFocusRelinquish },
    		{ kEventClassWindow,	kEventTextInputUpdateActiveInputArea},
    		{ kEventClassKeyboard,	kEventRawKeyDown},
    		{ kEventClassKeyboard,	kEventRawKeyUp},
    		{ kEventClassKeyboard,	kEventRawKeyRepeat}
    	};
    	
    InstallWindowEventHandler (HostWindowRef, carbonEventHandler, GetEventTypeCount(keyInputEvents), keyInputEvents, this, &m_KeyboardEventHandler);
    
    //============================================================================
    // Window Mouse Event Handler
    //============================================================================
    	const EventTypeSpec mouseEvents[] = {
    		{ kEventClassMouse, kEventMouseDown },
    		{ kEventClassMouse, kEventMouseUp },
    		{ kEventClassMouse, kEventMouseMoved },
    		{ kEventClassMouse, kEventMouseDragged }
    	};
    	
    InstallWindowEventHandler(HostWindowRef, carbonMouseEventHandler, GetEventTypeCount(mouseEvents), mouseEvents, this, &m_MouseEventHandler);
    
    then i add the control to the window :

    Code:
    //============================================================================
    // Add control to window
    //============================================================================
    if (isWindowComposited(HostWindowRef))
    {
    	HIViewRef contentView;
    	HIViewRef rootView = HIViewGetRoot(HostWindowRef);
    		
    	if (HIViewFindByID(rootView, kHIViewWindowContentID, &contentView) != noErr)
    	{
    		contentView = rootView;
    	}
    		
    	HIViewAddSubview (contentView, m_ControlRef);
    }
    else
    {
    	ControlRef rootControl;
    	GetRootControl(HostWindowRef, &rootControl);
    		
    	if (rootControl == NULL)
    	{
    		CreateRootControl(HostWindowRef, &rootControl);
    	}
    	EmbedControl(m_ControlRef, rootControl);
    }
    
    //============================================================================
    // Add Tracking area
    //============================================================================
    	
    HIViewTrackingAreaRef trackingAreaRef;	// will automatically removed if view is destroyed
    HIViewNewTrackingArea (m_ControlRef, 0, 0, &trackingAreaRef);
    
    I received the raw keys events, and others, but never kEventTextInputUnicodeForKeyEvent.

    I can't figure what i'm doing wrong with this event.

    Any help will be appreciated.

    Thanks.
     
  2. macrumors member

    Joined:
    May 21, 2011
    Location:
    Spain
    #2
    If I remember correctly, you cannot use InstallWindowEventHandler with kEventClassTextInput events, it works only with raw key events. Instead, you should install a separate handler:

    Code:
    const EventTypeSpec textInputEvents[] = {
    		{ kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }
    };
    InstallEventHandler(GetUserFocusEventTarget(), carbonEventHandler, GetEventTypeCount(textInputEvents), textInputEvents, this, &m_TextInputEventHandler);
    
    (I haven't checked for syntax errors, but that's the idea).
     

Share This Page