Mac OS X Implementing HIView
Contributors
Eric Bachard[ericb]
Sébastien Plisson [plipli]
Introduction
[DRAFT] : means, not yet working, work in progress ...
The main idea behind HIView is to superpose plans, to create any view, using compositing possibilities of Quartz Graphical Engine. The final result is the superposition of all plans, following simple rules like :
- The last plan is always drawn on the previous one ; - Some plans can be declared visible, or not, very easely.
This page is part of [Native Controls Implementation] and the objective is to use HIView for HIComboboxes or other HI* controls.
Our objective is to bind vcl controls with HI* controls, from Carbon API.
e.g. : implement HICombobox as one control only.
The generic implementation, under tests (and not fully working), uses :
HI* events definitions in aquavclevents.hxx
Event handler implementation in HandleHIViewEvent()
The use of HandleHIViewEvent() in AquaSalFrame::CreateNewSystemWindow()
The use of HI* controls, in vcl, when ::CreateNewSystemWindow() is used, calling HandleHIViewEvent(), when HI* events are detected in the frame.
Note : we "or"- ed kWindowCompositingAttribute in nWindowAttributes, to see compositing effects.
[FIXME] : investigate, because use this attribute causes refresh issues
Current code implementation
Events for HIView
Two sorts of events are needed:
- for objects (ClasskEventClassHIObject ) :
kEventHIObjectConstruct kEventHIObjectInitialize kEventHIObjectDestruct
- for controls themselves ( Class kEventClassControl ) :
kEventControlDraw kEventControlInitialize kEventControlHitTest kEventControlGetPartRegion kEventControlBoundsChanged
Current implementation : see vcl/aqua/aquavclevents.hxx for more informations about the syntax.
Install Event Handler
Now we have to install event Handler, inside AquaSalFrame::CreateNewSystemWindow() :
InstallEventHandler ( GetControlEventTarget (mhView), NewEventHandlerUPP (HandleHIViewEvent), GetEventTypeCount (cHIViewEvent), cHIViewEvent, (void*)mhView, // note the use of the pointer NULL );
The HI* Event Handler
The Handler is OSStatus type, and is used when events are detected.
e.g. : we created HandleHIViewEvent()
using GetEventParameter, itself using the parameters described in Apple documentation.
Code sample :
OSStatus HandleHIViewEvent(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void* inUserData) { //lock ImplSalYieldMutexAcquire(); OSStatus status = noErr; // we use mrContext, global and seen from everywhere CGContextRef mrContext; // create HIRect, contianing the control bounds ( in local coordinates) HIRect bounds; status = GetEventParameter (inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof (CGContextRef), NULL, &mrContext); // not used, but usefull //require_noerr(status, CantGetGraphicsContext); // 2 // We need to know the bounds containing the current control HIViewGetBounds ((HIViewRef) inUserData, &bounds); // not used, but usefull //require_noerr(status, CantGetBoundingRectangle); // unlock ImplSalYieldMutexRelease(); return status; }
HIView use in AquaSalFrame::CreateNewSystemWindow()
Code sample :
// TEST HIVIew part // Set mhView with HIView Content ViewRef HIRect myViewRect; myViewRect.origin.x = aContentRect.left; myViewRect.origin.y = aContentRect.right; myViewRect.size.width = aContentRect.right-aContentRect.left; myViewRect.size.height = aContentRect.bottom-aContentRect.top; OSStatus errval; errval = HIViewFindByID(HIViewGetRoot(mrWindow), kHIViewWindowContentID, &mhView); // make the view visible HIViewSetVisible (mhView, true); // set the frame HIViewSetFrame (mhView, &myViewRect);
Controls
[FIXME]
Example : HICombobox
-> code located in vcl/aqua/source/gdi/salnativewidgets.cxx , where all NWF are defined
1) declare CTRL_COMBOBOX control as "true" in isNativeControlSupported()
2) get the control region in getNativeControlRegion()
3) add CTRL_COMBOBOX case in drawNativeControl()
Code sample for the last part (Warning : not yet working !! ) :
switch( nType ) { case CTRL_COMBOBOX: if ( ( nPart==PART_BUTTON_DOWN) || (nPart==PART_SUB_EDIT) || (nPart==PART_ENTIRE_CONTROL) || (nPart==HAS_BACKGROUND_TEXTURE)) .... (other code ) if( BeginGraphics() ) { HIViewRef myCombo; HIRect aBoundRect; HIViewGetBounds ( myCombo, &aBoundRect); HIComboBoxCreate ( &aBoundRect, NULL, NULL, NULL, kHIComboBoxStandardAttributes, &myCombo); HIViewSetVisible ( myCombo, true); HIViewAddSubview (mrView, myCombo); HIViewSetNeedsDisplay (myCombo, true); EndGraphics(); return true; } ..... (other code )
Usefull Links
Reference
OverView : [HIToolbox]
HIVIew : [reference] [or .pdf format]
Code sample
High Level Toolbox, HIServices Release Notes : http://developer.apple.com/releasenotes/Carbon/RN-HIToolbox/