/*tkmacicon: implements a simple Cocoa-based mechanism for retrieving file icons in a Tk application on OS X. (c) 2009 WordTech Communications LLC. License: standard Tcl license, http://www.tcl.tk/software/tcltk/license.html.*/ #import "macicon.h" #import "tkmacicon.h" // Tcl command to get a file icon int GetMacIcon (ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) { NSString *iconpath; NSString *iconfile; double iconwidth; double iconheight; double tclwidth; double tclheight; //cast double vars to float for Cocoa method args float outputheight; float outputwidth; //set up memory pool NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //need proper number of args if(objc != 5) { Tcl_WrongNumArgs(ip, 1, objv, "icon width height outputfile"); return TCL_ERROR; } //initialize the instance of tkmacicon MacIcon *tkmacicon = [[MacIcon alloc ] init]; //convert args to usable Cocoa objects iconpath = [NSString stringWithUTF8String:Tcl_GetString(objv[1])]; iconwidth = Tcl_GetDoubleFromObj(ip, objv[2], &tclwidth); iconheight = Tcl_GetDoubleFromObj(ip, objv[3], &tclheight); outputwidth = (float) tclwidth; outputheight = (float) tclheight; iconfile = [NSString stringWithUTF8String:Tcl_GetString(objv[4])]; //retrieve the icon and write it to file [tkmacicon makeIcon:iconpath imagewidth:outputwidth imageheight:outputheight outputfile:iconfile]; //release the memory [pool release]; return TCL_OK; } //initalize the package in the tcl interpreter, create tcl commands int Tkmacicon_Init (Tcl_Interp *ip) { //set up an autorelease pool NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; if (Tcl_InitStubs(ip, "8.5", 0) == NULL) { return TCL_ERROR; } Tcl_CreateObjCommand(ip, "::tkmacicon::getIcon", GetMacIcon,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); if (Tcl_PkgProvide(ip, "tkmacicon", "1.0") != TCL_OK) { return TCL_ERROR; } //release memory [pool release]; return TCL_OK; } int Tkmacicon_SafeInit(Tcl_Interp *ip) { return Tkmacicon_Init(ip); }