// now find the root HIView window
HRContentRoot = HIViewGetRoot(myWindow);
// find the HIView content window
from the nib
OSErr = HIViewFindByID(HRContentRoot,HRContentViewID,&HRContentView);
// get the state we need - MANUAL
VERSION
layoutInfo.version =
kHILayoutInfoVersionZero;
OSErr = HIViewGetLayoutInfo(HRContentView,&layoutInfo);
OSErr = HIViewGetFrame(HRContentView,&theRect);
// create the scroll view
MANUALLY
OSErr =
HIScrollViewCreate(kHIScrollViewOptionsVertScroll | kHIScrollViewOptionsHorizScroll,
&HRScrollView);
// put the scrolls in the view's
parent
OSErr = HIViewAddSubview(HIViewGetSuperview(HRContentView),HRScrollView);
// set the frame to match what we
originally wanted
OSErr = HIViewSetFrame(HRScrollView,&theRect);
// set the layout to what we
originally wanted
OSErr = HIViewSetLayoutInfo(HRScrollView,&layoutInfo);
// remove the content view from its
current owner and add it into the scroll view
OSErr =
HIViewRemoveFromSuperview(HRContentView);
OSErr = HIViewAddSubview(HRScrollView,HRContentView);
// Note - this code DOES correctly
set the bounds of the embedded HIView. This can
// be detected by checking the bounds
of the event contexts.
theRect.origin.x =
0.0;
theRect.origin.y =
0.0;
theRect.size.width =
BITMAPWIDTH+1;
theRect.size.height =
BITMAPHEIGHT+1;
OSErr = HIViewSetFrame(HRContentView,&theRect);
// request an update or the screen remains blank
HIViewSetVisible(HRScrollView,true);
HIViewSetNeedsDisplay(HRContentView,true);
// now add an event handler to handle
drawing into this window
OSErr =
InstallEventHandler(GetControlEventTarget(HRContentView),
NewEventHandlerUPP(myDrawEventHandler),
GetEventTypeCount(HRContentEvents),
HRContentEvents,
(void *)HRContentView,
NULL );
// now add an event handler to handle
scrolling
OSErr =
InstallEventHandler(GetControlEventTarget(HRScrollView),
NewEventHandlerUPP(myScrollEventHandler),
GetEventTypeCount(HRScrollEvents),
HRScrollEvents,
(void *)HRScrollView,
NULL );
// Now we've changed the size of the
content window, we need to send a kEventScrollableInfoChanged event
// to the scroll bars. We'll do that
after we've installed the event handler.
HIViewRef parentView = HIViewGetSuperview(HRContentView);
if(parentView)
{
EventRef theEvent;
OSErr =
CreateEvent(NULL,kEventClassScrollable,kEventScrollableInfoChanged,GetCurrentEventTime(),
kEventAttributeUserEvent,&theEvent);
OSErr =
SendEventToEventTarget(theEvent,GetControlEventTarget(parentView));
ReleaseEvent(theEvent);
}
Many
thanks,
Greg