Ejemplo n.º 1
0
/*
	Position the contentView (presumed to be a subview of the frameView) by
	asking the content view for its metrics and positioning it appropriately.
*/
OSStatus PositionContentViewWithMetrics(HIViewRef frameView, HIViewRef contentView)
{
	HIViewFrameMetrics metrics = { 0, 0, 0, 0 };
	EventRef getMetricsEvent = NULL;

	// First we check the frame metrics of the content view by asking it (politely) for the
	// metrics it wants
	verify_noerr(CreateEvent(NULL, kEventClassControl, kEventControlGetFrameMetrics, GetCurrentEventTime(), 0, &getMetricsEvent));
	if(NULL != getMetricsEvent) {
		SetEventParameter(getMetricsEvent, kEventParamDirectObject, typeControlRef, sizeof(contentView), &contentView);
		SetEventParameter(getMetricsEvent, kEventParamControlFrameMetrics, typeControlFrameMetrics, sizeof(metrics), &metrics);

		OSStatus result = SendEventToEventTarget(getMetricsEvent, HIObjectGetEventTarget((HIObjectRef)contentView));
		if(result == noErr) {
			verify_noerr(GetEventParameter(getMetricsEvent, kEventParamControlFrameMetrics, typeControlFrameMetrics, NULL, sizeof(metrics), NULL, &metrics));
		}

		ReleaseEvent(getMetricsEvent);
		getMetricsEvent = NULL;
	}

	// Now we reposition the content view based on the metrics we got from it.
	HIRect bounds, contentRect;
	HIViewGetBounds(frameView, &bounds);

	contentRect.origin.x = metrics.left;
	contentRect.origin.y = metrics.top;
	contentRect.size.width = bounds.size.width - (metrics.left + metrics.right);
	contentRect.size.height = bounds.size.height - (metrics.top + metrics.bottom);

	HIViewSetFrame(contentView, &contentRect);

	return noErr;
}
Ejemplo n.º 2
0
QSize FilterWidget::sizeHint (void) const
{
	HIRect optimalBounds;
	EventRef event;
	CreateEvent(0, kEventClassControl, kEventControlGetOptimalBounds,
		GetCurrentEventTime(), kEventAttributeUserEvent, &event);
	SendEventToEventTargetWithOptions(event,
		HIObjectGetEventTarget(HIObjectRef(winId())),
		kEventTargetDontPropagate);
	GetEventParameter(event, kEventParamControlOptimalBounds, typeHIRect,
		0, sizeof(HIRect), 0, &optimalBounds);
	ReleaseEvent(event);
	return QSize(optimalBounds.size.width + 200, optimalBounds.size.height - 4);
}