Cocoa Plugin - drawOffscreenFunction

I’ve more or less finished a Cocoa plugin and I’ve just started adding some functionality for dealing with the control in the layout editor in the IDE. I’m implementing a drawOffscreenFunction to be called via the control’s REALcontrolBehaviour structure:

static void SplitView_DrawOffscreenFunction(REALcontrolInstance control, REALgraphics graphics) { ... }
One thing that surprises me, is that the rectangle from the “graphics” argument is not the rectangle of the control in the IDE, but the rectangle of the layout editor. Is that correct? I just want to be sure before I invest time in calculating my drawing in the control.

[quote=28842:@Lukas Joerg]I’ve more or less finished a Cocoa plugin and I’ve just started adding some functionality for dealing with the control in the layout editor in the IDE. I’m implementing a drawOffscreenFunction to be called via the control’s REALcontrolBehaviour structure:

static void SplitView_DrawOffscreenFunction(REALcontrolInstance control, REALgraphics graphics) { ... }
One thing that surprises me, is that the rectangle from the “graphics” argument is not the rectangle of the control in the IDE, but the rectangle of the layout editor. Is that correct? I just want to be sure before I invest time in calculating my drawing in the control.[/quote]

Can you paste your control behavior definition? The answer somewhat depends on how your plugin is structured.

n/a is just a reminder for myself that an implementation wouldn’t be called, because I return an NSView in RBControlBehaviour.controlHandleGetter:

[code]static REALcontrolBehaviour SplitView_ControlBehaviour = {
/* constructorFunction / SplitView_ControlConstructor,
/
destructorFunction / SplitView_ControlDestructor,
/
redrawFunction n/a / NULL,
/
clickFunction n/a / NULL,
/
mouseDragFunction n/a / NULL,
/
mouseUpFunction n/a / NULL,
/
gainedFocusFunction n/a / NULL,
/
lostFocusFunction n/a / NULL,
/
keyDownFunction n/a / NULL,
/
openFunction / SplitView_OpenFunction,
/
closeFunction / SplitView_CloseFunction,
/
backgroundIdleFunction n/a / NULL,
/
drawOffscreenFunction / SplitView_DrawOffscreenFunction,
/
setSpecialBackground n/a / NULL,
/
constantChanging n/a / NULL,
/
droppedNewInstance n/a / NULL,
/
mouseEnterFunction n/a / NULL,
/
mouseExitFunction n/a / NULL,
/
mouseMoveFunction n/a / NULL,
/
stateChangedFunction / NULL,
/
actionEventFunction n/a / NULL,
/
controlHandleGetter / SplitView_ControlHandleGetter,
/
mouseWheelFunction n/a / NULL,
/
enableMenuItemsFunction / NULL,
/
menuItemActionFunction / NULL,
/
controlAcceptFocus n/a / NULL,
/
keyUpFunction n/a / NULL,
/
redrawWithRectsFunction n/a */ NULL
};

static REALcontrol SplitView_ControlDefinition = {
/* version / kCurrentREALControlVersion,
/
name / “NSSplitView”,
/
dataSize / sizeof(SplitView_ControlData),
/
flags / REALcontrolAcceptFocus,
/
toolbarPICT / 0,
/
toolbarDownPICT / 0,
/
defaultWidth / 300,
/
defaultHeight / 200,
/
properties / SplitView_ControlProperties,
/
propertyCount / sizeof(SplitView_ControlProperties) / sizeof(REALproperty),
/
methods / SplitView_ControlMethods,
/
methodCount / sizeof(SplitView_ControlMethods) / sizeof(REALmethodDefinition),
/
events / SplitView_ControlEvents,
/
eventCount / sizeof(SplitView_ControlEvents) / sizeof(REALevent),
/
behaviour / &SplitView_ControlBehaviour,
/
forSystemUse / 0,
/
eventInstances / SplitView_ControlEventInstances,
/
eventInstanceCount / sizeof(SplitView_ControlEventInstances) / sizeof(REALeventInstance),
/
interfaces / “”,
/
obsolete1 / NULL,
/
obsolete2 / 0,
/
constants / SplitView_ControlConstants,
/
constantCount */ sizeof(SplitView_ControlConstants) / sizeof(REALconstant)
};[/code]

[quote=28851:@Lukas Joerg] /* controlHandleGetter */ SplitView_ControlHandleGetter,
[/quote]

If you return a valid handle from this, the IDE will draw the NSView for you in the form editor. Is that what you’re after or do you want to draw some sort of placeholder instead?

NSSplitView doesn’t have a border, but in the IDE I would like to show one. What I do now is:

static void SplitView_DrawOffscreenFunction(REALcontrolInstance control, REALgraphics graphics) { void (*fpDrawRect)(REALobject, long, long, long, long) = NULL; fpDrawRect = (void (*)(REALobject, long, long, long, long))REALLoadObjectMethod((REALobject)graphics, "DrawRect(x As Integer, y As Integer, width As Integer, height As Integer)"); if (fpDrawRect) { long color = (127 << 16) | (127 << 8) | (127); REALSetPropValue((REALobject)graphics, "ForeColor", color); long left = REALGetControlPosition(control, 0); long top = REALGetControlPosition(control, 1); long width = REALGetControlPosition(control, 2); long height = REALGetControlPosition(control, 3); fpDrawRect((REALobject)graphics, left, top, width, height); } }
It works well, but I just wanted to be sure that this is indeed the correct way to draw something in the IDE.

You should also call REALGetGraphicsOrigin and add the x and y values to your left and top values. From a style perspective, I’d either use REALGetControlBounds or at least pass the kREALLeft, kREALTop, kREALWidth, kREALHeight constants in.

Perfect. Thank you very much.