#include"Initalisation.h"globalsg;/*** INITALISE NEW EDITOR INSTANCE ***/OSStatusPlug_InitInstance(Plug_PlugInRefplug,Plug_ResourceRefresource){// get system version
OSStatuserror=Gestalt(gestaltSystemVersion,&g.systemVersion);if(error)returnerror;// create window
RectcreationBounds;WindowRefwindow;SetRect(&creationBounds,0,0,kDefaultWindowWidth,kDefaultWindowHeight);OffsetRect(&creationBounds,8,48);WindowAttributesattributes=kWindowCloseBoxAttribute|kWindowCollapseBoxAttribute|kWindowStandardHandlerAttribute|kWindowInWindowMenuAttribute;if(g.systemVersion>=kMacOSX)attributes|=kWindowLiveResizeAttribute;error=CreateNewWindow(kDocumentWindowClass,attributes,&creationBounds,&window);// register mac window with host and retrieve plug window
Plug_WindowRefplugWindow=Host_RegisterWindow(plug,resource,window);// cerate new pict window class
PictWindowPtrpictWindow=newPictWindow(window);// set window refCon to my class
Host_SetWindowRefCon(plugWindow,(UInt32)pictWindow);// set the window pic to the data handle
PicHandlepicture=(PicHandle)Host_GetResourceData(resource);if(picture==null)Host_DisplayError("\pNo picture could be obtained.","\p",0);// get pict rect
PictInfopictInfo;GetPictInfo(picture,&pictInfo,0,0,0,0);RectpictRect;pictRect.top=0;pictRect.left=0;pictRect.right=pictInfo.sourceRect.right-pictInfo.sourceRect.left;pictRect.bottom=pictInfo.sourceRect.bottom-pictInfo.sourceRect.top;SizeWindow(window,pictRect.right,pictRect.bottom,false);#if TARGET_API_MAC_CARBONControlRefpicControl;// this is better than SetWindowPic() in Carbon
ControlButtonContentInfocontent;content.contentType=kControlContentPictHandle;content.u.picture=picture;// bug: if handle dissapears, control is fucked
CreatePictureControl(window,&pictRect,&content,true,&picControl);// DrawOneControl( picControl ); // bug: work around for bug in ControlManager
/* HLockHi( picture );
SetControlData( picControl, kControlPicturePart, kControlPictureHandleTag, sizeof(picture), *picture ); */#elseSetWindowPic(window,picture);// this doesn't work properly on X
#endif// show window
ShowWindow(window);SelectWindow(window);returnerror;}