#include"Initalisation.h"#include"HexWindow.h"#include"Events.h"#include"HexUtility.h"globalsg;prefsp;/************************//* EDITOR INITALIZATION *//************************//*** INITALISE GLOBALS ***/OSStatusInitGlobals(void){// get system version
OSStatuserror=Gestalt(gestaltSystemVersion,&g.systemVersion);if(error)returnerror;// set up colours
SetColour(&g.white,0xFFFF,0xFFFF,0xFFFF);SetColour(&g.bgColour,0xEEEE,0xEEEE,0xEEEE);SetColour(&g.sortColour,0xDDDD,0xDDDD,0xDDDD);SetColour(&g.bevelColour,0xAAAA,0xAAAA,0xAAAA);SetColour(&g.textColour,0x7777,0x7777,0x7777);SetColour(&g.frameColour,0x5555,0x5555,0x5555);SetColour(&g.black,0x0000,0x0000,0x0000);// check appearance availablilty
#if TARGET_API_MAC_CARBONg.useAppearance=true;#elseProcessSerialNumberpsn;error=GetCurrentProcess(&psn);if(error)g.useAppearance=false;elseg.useAppearance=IsAppearanceClient(&psn);#endif// initalise preferences
p.version=kHexEditorCurrentVersion;p.lowChar=0x20;p.highChar=0x7F;p.GWorldDepth=8;returnerror;}/*** INITALISE NEW EDITOR INSTANCE ***/OSStatusPlug_InitInstance(Plug_PlugInRefplug,Plug_ResourceRefresource){WindowRefwindow;OSStatuserror=InitGlobals();if(error)returnerror;#if USE_NIBS// create a nib reference (only searches the application bundle)
IBNibRefnibRef=null;error=CreateNibReference(CFSTR("Hex Editor"),&nibRef);if(error!=noErr||nibRef==null){// Host_DisplayError( "\pThe nib file reference could not be obtained.", "\p", 0 );
returnerror;}// create window
error=CreateWindowFromNib(nibRef,CFSTR("Hex Window"),&window);if(error!=noErr||window==null){// Host_DisplayError( "\pA file window could not be obtained from the nib file.", "\p", 0 );
returnerror;}// dispose of nib ref
DisposeNibReference(nibRef);#elif TARGET_API_MAC_CARBON// create window
RectcreationBounds;SetRect(&creationBounds,0,0,kDefaultWindowWidth,kDefaultWindowHeight);OffsetRect(&creationBounds,8,48);WindowAttributesattributes=kWindowStandardDocumentAttributes|kWindowStandardHandlerAttribute|kWindowInWindowMenuAttribute;if(g.systemVersion>=kMacOSX)attributes|=kWindowLiveResizeAttribute;error=CreateNewWindow(kDocumentWindowClass,attributes,&creationBounds,&window);#else/* if( g.useAppearance && g.systemVersion >= kMacOSEight )
{
window = GetNewCWindow( kFileWindow8, null, kFirstWindowOfClass );
themeSavvy = true;
}
else
{
*/window=GetNewCWindow(kFileWindow7,null,kFirstWindowOfClass);DrawGrowIcon(window);/* themeSavvy = false;
} */SizeWindow(window,kDefaultWindowWidth,kDefaultWindowHeight,false);#endif// register mac window with host and retreive plug window
Plug_WindowRefplugWindow=Host_RegisterWindow(plug,resource,window);// cerate new hex window class
HexWindowPtrhexWindow=newHexWindow(window);// set window refCon to my class
Host_SetWindowRefCon(plugWindow,(UInt32)hexWindow);// load resource data into handle
hexWindow->data=Host_GetResourceData(resource);// handle disposed of by calling Host_ReleaseResData()
// window is not yet active, will receive activate event soon
hexWindow->activeWindow=false;// set window's background to default for theme
if(g.useAppearance)SetThemeWindowBackground(window,kThemeBrushModelessDialogBackgroundActive,false);#if TARGET_API_MAC_CARBON// install window event handler
EventHandlerRefref=null;EventHandlerUPPhandler=NewEventHandlerUPP(CarbonWindowEventHandler);EventTypeSpecevents[]={{kEventClassWindow,kEventWindowClose},{kEventClassWindow,kEventWindowActivated},{kEventClassWindow,kEventWindowDeactivated},{kEventClassWindow,kEventWindowBoundsChanging},{kEventClassWindow,kEventWindowBoundsChanged},{kEventClassWindow,kEventWindowHandleContentClick},