static PyObject *Icn_RegisterIconRefFromFSRef(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSStatus _err; OSType creator; OSType iconType; FSRef iconFile; IconRef theIconRef; #ifndef RegisterIconRefFromFSRef PyMac_PRECHECK(RegisterIconRefFromFSRef); #endif if (!PyArg_ParseTuple(_args, "O&O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &iconType, PyMac_GetFSRef, &iconFile)) return NULL; _err = RegisterIconRefFromFSRef(creator, iconType, &iconFile, &theIconRef); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("O&", ResObj_New, theIconRef); return _res; }
IconRef GetOperaDocumentIcon() { OpFile iconDocsFile; IconRef docIcon = 0; iconDocsFile.Construct(UNI_L("OperaDocs.icns"), OPFILE_RESOURCES_FOLDER); BOOL exists = FALSE; iconDocsFile.Exists(exists); if(exists) { FSRef fsref; if(OpFileUtils::ConvertUniPathToFSRef(iconDocsFile.GetFullPath(), fsref)) { if(noErr == RegisterIconRefFromFSRef('OPRA', 'HTML', &fsref, &docIcon)) { return docIcon; } } } return 0; }
IconRef GetOperaApplicationIcon() { OpFile iconFile; IconRef operaIcon = 0; iconFile.Construct(UNI_L("Opera.icns"), OPFILE_RESOURCES_FOLDER); BOOL exists = FALSE; iconFile.Exists(exists); if(exists) { FSRef fsref; if(OpFileUtils::ConvertUniPathToFSRef(iconFile.GetFullPath(), fsref)) { if(noErr == RegisterIconRefFromFSRef('OPRA', 'APPL', &fsref, &operaIcon)) { return operaIcon; } } } return 0; }
void MusicBoxDialog(void) { OSStatus err; IBNibRef nibRef; if (!cartOpen) return; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { CFURLRef iconURL; FSRef iconFSRef; IconRef actIcon; WindowRef tWindowRef; actIcon = nil; if (musicboxmode == kMBXSoundEmulation) iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledoff"), CFSTR("icns"), nil); else iconURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_ledon" ), CFSTR("icns"), nil); if (iconURL) { if (CFURLGetFSRef(iconURL, &iconFSRef)) err = RegisterIconRefFromFSRef('~9X~', 'micn', &iconFSRef, &actIcon); CFRelease(iconURL); } err = CreateWindowFromNib(nibRef, CFSTR("MusicBox"), &tWindowRef); if (err == noErr) { EventHandlerRef mboxRef, paneRef; EventHandlerUPP mboxUPP, paneUPP; EventLoopTimerRef timeRef; EventLoopTimerUPP timeUPP; EventTypeSpec mboxEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }, paneEvents[] = { { kEventClassControl, kEventControlDraw } }; CFStringRef sref; CGDataProviderRef prov; CGImageRef ipng; CFURLRef iurl; HIViewRef ctl, root, paneView, imageView, contentView; HIViewID cid; HIRect bounds; Rect windowRect, barRect; char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; mboxPause = false; mbxFinished = false; showIndicator = false; so.stereo_switch = ~0; for (int i = 0; i < MAC_MAX_PLAYERS; i++) controlPad[i] = 0; switch (drawingMethod) { case kDrawingOpenGL: Settings.OpenGLEnable = true; break; case kDrawingDirect: case kDrawingBlitGL: Settings.OpenGLEnable = false; } // 107's enhanced SPC player root = HIViewGetRoot(tWindowRef); cid.id = 0; if (musicboxmode == kMBXSoundEmulation) { cid.signature = 'HEAD'; HIViewFindByID(root, cid, &ctl); EnableControl(ctl); StoredAPU = new SAPU; StoredAPURegisters = new SAPURegisters; StoredSoundData = new SSoundData; StoredIAPURAM = new uint8 [0x10000]; SPCPlayFreeze(); } else MusicBoxForceFreeze(); cid.signature = 'Kart'; HIViewFindByID(root, cid, &ctl); SetStaticTextTrunc(ctl, truncEnd, false); _splitpath(Memory.ROMFilename, drive, dir, fname, ext); sref = CFStringCreateWithCString(kCFAllocatorDefault, fname, MAC_PATH_ENCODING); if (sref) { SetStaticTextCFString(ctl, sref, false); CFRelease(sref); } ipng = nil; iurl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("musicbox_indicator"), CFSTR("png"), nil); if (iurl) { prov = CGDataProviderCreateWithURL(iurl); if (prov) { ipng = CGImageCreateWithPNGDataProvider(prov, nil, false, kCGRenderingIntentDefault); CGDataProviderRelease(prov); } CFRelease(iurl); } imageView = nil; if (ipng) { HIViewFindByID(root, kHIViewWindowContentID, &contentView); err = HIImageViewCreate(ipng, &imageView); if (err == noErr) { bounds = CGRectMake(30, 64, CGImageGetWidth(ipng), CGImageGetHeight(ipng)); HIViewSetFrame(imageView, &bounds); HIImageViewSetOpaque(imageView, false); HIViewSetVisible(imageView, true); HIViewAddSubview(contentView, imageView); cid.signature = 'iMaG'; SetControlID(imageView, &cid); } CGImageRelease(ipng); } cid.signature = 'Pane'; HIViewFindByID(root, cid, &paneView); HIViewGetBounds(paneView, &bounds); mbxViewWidth = bounds.size.width; mbxViewHeight = bounds.size.height; mbxMarginY = (mbxViewHeight - mbxBarHeight) / 2.0; mbxMarginX = (mbxViewWidth - ((mbxBarWidth * 8.0 + mbxBarSpace * 7.0) * 2.0 + mbxLRSpace)) / 2.0; if (imageView) { HIViewSetZOrder(imageView, kHIViewZOrderBelow, paneView); HIViewAddSubview(imageView, paneView); } cid.signature = 'Tr_i'; HIViewFindByID(root, cid, &ctl); HIViewGetFrame(ctl, &bounds); GetWindowBounds(tWindowRef, kWindowTitleBarRgn, &barRect); mbxClosedHeight = (short) (bounds.origin.y + bounds.size.height + 7.0) + (barRect.bottom - barRect.top); GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); mbxOpenedHeight = windowRect.bottom - windowRect.top; windowRect.bottom = windowRect.top + mbxClosedHeight; SetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); paneUPP = NewEventHandlerUPP(IndicatorEventHandler); err = InstallControlEventHandler(paneView, paneUPP, GetEventTypeCount(paneEvents), paneEvents, (void *) paneView, &paneRef); mboxUPP = NewEventHandlerUPP(MusicBoxEventHandler); err = InstallWindowEventHandler(tWindowRef, mboxUPP, GetEventTypeCount(mboxEvents), mboxEvents, (void *) tWindowRef, &mboxRef); timeUPP = NewEventLoopTimerUPP(MusicBoxTimerHandler); err = InstallEventLoopTimer(GetCurrentEventLoop(), kEventDurationNoWait, kEventDurationSecond * 2.0 / (double) Memory.ROMFramesPerSecond, timeUPP, (void *) paneView, &timeRef); MusicBoxInitIndicator(); stopNow = false; MacStartSound(); pthread_create(&mbxThread, nil, SoundTask, nil); MoveWindowPosition(tWindowRef, kWindowMusicBox, true); GetWindowBounds(tWindowRef, kWindowStructureRgn, &windowRect); if (windowRect.bottom - windowRect.top > mbxClosedHeight) { showIndicator = true; SetControl32BitValue(ctl, 1); // Tr_i } ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowMusicBox); stopNow = true; pthread_join(mbxThread, nil); MacStopSound(); err = RemoveEventLoopTimer(timeRef); DisposeEventLoopTimerUPP(timeUPP); err = RemoveEventHandler(mboxRef); DisposeEventHandlerUPP(mboxUPP); err = RemoveEventHandler(paneRef); DisposeEventHandlerUPP(paneUPP); ReleaseWindow(tWindowRef); so.stereo_switch = ~0; mbxFinished = true; if (musicboxmode == kMBXSoundEmulation) { SPCPlayDefrost(); delete StoredAPU; delete StoredAPURegisters; delete StoredSoundData; delete [] StoredIAPURAM; } else MusicBoxForceDefrost(); Settings.OpenGLEnable = false; } if (actIcon) err = UnregisterIconRef('~9X~', 'micn'); DisposeNibReference(nibRef); } }
// -------------------------------------------------------------------------------------- static DataBrowserItemID addItemsToIconDB(ControlRef iconDataBrowser, ControlRef *userPanes) { IconDBItemDataRec *itemsData, *rowItemData; CFBundleRef mainBundle; CFIndex rowNumber; DataBrowserItemID items[kNumberOfRows]; CFStringRef catNameKeys[kNumberOfRows]; itemsData = CFAllocatorAllocate(kCFAllocatorDefault, kNumberOfRows * sizeof(IconDBItemDataRec), 0); mainBundle = CFBundleGetMainBundle(); if (!gIconsRegistered) // if we didn't register our icons already, we need to { CFArrayRef iconURLs; FSRef iconFile; FSSpec iconSpec; iconURLs = CFBundleCopyResourceURLsOfType(mainBundle, CFSTR("icns"), CFSTR("PrefCategories")); for (rowNumber = 0; rowNumber < kNumberOfRows; rowNumber++) { CFURLGetFSRef(CFArrayGetValueAtIndex(iconURLs, rowNumber), &iconFile); #if TARGET_API_MAC_OSX #pragma unused (iconSpec) RegisterIconRefFromFSRef(kAppSignature, 'Cat0' + rowNumber, &iconFile, &((itemsData + rowNumber)->icon)); #else FSGetCatalogInfo(&iconFile, kFSCatInfoNone, NULL, NULL, &iconSpec, NULL); RegisterIconRefFromIconFile(kAppSignature, 'Cat0' + rowNumber, &iconSpec, &((itemsData + rowNumber)->icon)); #endif } CFRelease(iconURLs); gIconsRegistered = true; } else // the icons are already registered so we just have to get them { for (rowNumber = 0; rowNumber < kNumberOfRows; rowNumber++) { GetIconRef(kOnSystemDisk, kAppSignature, 'Cat0' + rowNumber, &((itemsData + rowNumber)->icon)); } } catNameKeys[0] = CFSTR("Panel 1"); // this is necessary because you have to use catNameKeys[1] = CFSTR("Panel 2"); // constant strings with CFSTR catNameKeys[2] = CFSTR("Panel 3"); // if we didn't do this then we couldn't get catNameKeys[3] = CFSTR("Panel 4"); // the strings in a loop catNameKeys[4] = CFSTR("Panel 5"); catNameKeys[5] = CFSTR("Panel 6"); catNameKeys[6] = CFSTR("Panel 7"); catNameKeys[7] = CFSTR("Panel 8"); catNameKeys[8] = CFSTR("Panel 9"); catNameKeys[9] = CFSTR("Panel 10"); for (rowNumber = 0; rowNumber < kNumberOfRows; rowNumber++) // now get the names { // and set the user panes rowItemData = itemsData + rowNumber; items[rowNumber] = (DataBrowserItemID)rowItemData; /* We use CFCopyLocalilzedStringFromTableInBundle here instead of CFCopyLocalizedString to avoid a call to CFBundleGetMainBundle every trip around the loop. */ rowItemData->name = CFCopyLocalizedStringFromTableInBundle(catNameKeys[rowNumber], NULL, mainBundle, NULL); rowItemData->userPane = *(userPanes + rowNumber); } AddDataBrowserItems(iconDataBrowser, kDataBrowserNoItem, kNumberOfRows, items, kDataBrowserItemNoProperty); return *items; }
static void AddFolderIcon (FSRef *fref, const char *folderName) { OSStatus err; FSCatalogInfo fcat, icat; FSRef bref, iref; CFStringRef str; CFURLRef url; IconFamilyHandle family; IconRef icon; HFSUniStr255 fork; Boolean r; SInt16 resf; char name[64]; UniChar iconName[5] = { 'I', 'c', 'o', 'n', '\r' }; strcpy(name, "folder_"); strcat(name, folderName); str = CFStringCreateWithCString(kCFAllocatorDefault, name, CFStringGetSystemEncoding()); if (str) { url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), str, CFSTR("icns"), NULL); if (url) { r = CFURLGetFSRef(url, &bref); if (r) { err = RegisterIconRefFromFSRef('~9X~', 'TEMP', &bref, &icon); if (err == noErr) { err = FSGetResourceForkName(&fork); if (err == noErr) { err = FSCreateResourceFile(fref, 5, iconName, kFSCatInfoNone, NULL, fork.length, fork.unicode, &iref, NULL); if (err == noErr) { err = FSOpenResourceFile(&iref, fork.length, fork.unicode, fsWrPerm, &resf); if (err == noErr) { err = IconRefToIconFamily(icon, kSelectorAllAvailableData, &family); if (err == noErr) { AddResource((Handle) family, 'icns', -16455, "\p"); WriteResource((Handle) family); ReleaseResource((Handle) family); err = FSGetCatalogInfo(&iref, kFSCatInfoFinderInfo, &icat, NULL, NULL, NULL); ((FileInfo *) &icat.finderInfo)->finderFlags |= kIsInvisible; ((FileInfo *) &icat.finderInfo)->fileCreator = 'MACS'; ((FileInfo *) &icat.finderInfo)->fileType = 'icon'; err = FSSetCatalogInfo(&iref, kFSCatInfoFinderInfo, &icat); err = FSGetCatalogInfo(fref, kFSCatInfoFinderInfo, &fcat, NULL, NULL, NULL); ((FolderInfo *) &fcat.finderInfo)->finderFlags |= kHasCustomIcon; ((FolderInfo *) &fcat.finderInfo)->finderFlags &= ~kHasBeenInited; err = FSSetCatalogInfo(fref, kFSCatInfoFinderInfo, &fcat); } CloseResFile(resf); } } }