static PyObject *Icn_RegisterIconRefFromResource(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSErr _err; OSType creator; OSType iconType; FSSpec resourceFile; SInt16 resourceID; IconRef theIconRef; #ifndef RegisterIconRefFromResource PyMac_PRECHECK(RegisterIconRefFromResource); #endif if (!PyArg_ParseTuple(_args, "O&O&O&h", PyMac_GetOSType, &creator, PyMac_GetOSType, &iconType, PyMac_GetFSSpec, &resourceFile, &resourceID)) return NULL; _err = RegisterIconRefFromResource(creator, iconType, &resourceFile, resourceID, &theIconRef); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("O&", ResObj_New, theIconRef); return _res; }
// -------------------------------------------------------------------------------------- void AddRowsAndDataToIconList(ListHandle iconList, SInt16 iconFamilyBaseID) { short dataLength, rowNumber; IconListCellDataRec cellData; Cell theCell; if (!gIconsRegistered) // if we didn't register our icons already, we need to { OSErr error; FSSpec iconResFile; /* The first thing we need to do to register an IconRef is to get the FSSpec for the file containing the icon resources. This could be the application file itself or a flattened resource file in a bundle. Either way, in this program it's the "current" resource file so we call our utility function that converts the file reference number returned by CurResFile to an FSSpec. */ error = getCurrentResourceFSSpec(&iconResFile); if (error != noErr) // if we can't get our icons, this program is kind of useless ExitToShell(); // we've got the FSSpec, now get the icons out of it dataLength = sizeof(IconListCellDataRec); for (rowNumber = 0; rowNumber < kNumberOfRows; rowNumber++) { RegisterIconRefFromResource(kAppSignature, 'LIc0' + rowNumber, &iconResFile, iconFamilyBaseID + rowNumber, &cellData.icon); GetIndString(cellData.name, rIconListStrings, rowNumber + 1); rowNumber = LAddRow(1, rowNumber, iconList); // add each row to the SetPt(&theCell, 0, rowNumber); // bottom of the List LSetCell(&cellData, dataLength, theCell, iconList); } gIconsRegistered = true; } else // the icons are already registered so we just have to get them { dataLength = sizeof(IconListCellDataRec); for (rowNumber = 0; rowNumber < kNumberOfRows; rowNumber++) { GetIconRef(kOnSystemDisk, kAppSignature, 'LIc0' + rowNumber, &cellData.icon); GetIndString(cellData.name, rIconListStrings, rowNumber + 1); rowNumber = LAddRow(1, rowNumber, iconList); // add each row to the SetPt(&theCell, 0, rowNumber); // bottom of the List LSetCell(&cellData, dataLength, theCell, iconList); } } }