// --------------------------------------------------------------------------------------
void ReleaseIconListIcons(ListHandle iconList)
{
	short dataLength;
	IconListCellDataRec cellData;
	Cell theCell;
	UInt16 referenceCount;
	Boolean needRelease = false;
	
	dataLength = sizeof(IconListCellDataRec);
	
	SetPt(&theCell, 0, 0);
	LGetCell(&cellData, &dataLength, theCell, iconList);
	GetIconRefOwners(cellData.icon, &referenceCount);
	
	if (referenceCount == 1)	// if this is the last instance of the 
	{							// IconRefs we should unregister them
		OSType iconType;
		
			/* UnregisterIconRef doesn't decrement the reference count on some versions 
			   of Mac OS X (it does on 10.1.5, doesn't on 10.2.8, and does on 10.3.4).  
			   To account for this we will retain/acquire the icon, unregister it, then 
			   check the reference/owner count.  If it's the same then we will also 
			   release the icons.  We can't release the icons first or UnregisterIconRef 
			   will return noSuchIconErr (because the icons will already be disposed).  
			   Likewise we can't just release the icons afterwards because they may get 
			   disposed of when they're unregistered. */
		AcquireIconRef(cellData.icon);
		
		for (iconType = 'LIc0'; iconType <= 'LIc9'; iconType++)
			UnregisterIconRef(kAppSignature, iconType);
		
		gIconsRegistered = false;
		
		GetIconRefOwners(cellData.icon, &referenceCount);
		if (referenceCount > 1)
			needRelease = true;
		
		ReleaseIconRef(cellData.icon);
	}
	else						// otherwise simply release the icons
		needRelease = true;
	
	if (needRelease)
	{
		short rowNumber;
		
		ReleaseIconRef(cellData.icon);
		
		for (rowNumber = 1; rowNumber < kNumberOfRows; rowNumber++)
		{
			dataLength = sizeof(IconListCellDataRec);
			SetPt(&theCell, 0, rowNumber);
			LGetCell(&cellData, &dataLength, theCell, iconList);
			ReleaseIconRef(cellData.icon);
		}
	}
}
Beispiel #2
0
static PyObject *Icn_UnregisterIconRef(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	OSType creator;
	OSType iconType;
#ifndef UnregisterIconRef
	PyMac_PRECHECK(UnregisterIconRef);
#endif
	if (!PyArg_ParseTuple(_args, "O&O&",
	                      PyMac_GetOSType, &creator,
	                      PyMac_GetOSType, &iconType))
		return NULL;
	_err = UnregisterIconRef(creator,
	                         iconType);
	if (_err != noErr) return PyMac_Error(_err);
	Py_INCREF(Py_None);
	_res = Py_None;
	return _res;
}
Beispiel #3
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);
	}
}
// --------------------------------------------------------------------------------------
void ReleaseIconDataBrowserItemData(ControlRef iconDataBrowser)
{
    Handle itemsHandle;
    DataBrowserItemID *items;
    int itemNumber;
    IconDBItemDataRec *itemsData[kNumberOfRows];
    UInt16 referenceCount;
    Boolean needRelease = false;

    itemsHandle = NewHandle(0);		// GetDataBrowserItems will resize this for us
    GetDataBrowserItems(iconDataBrowser, kDataBrowserNoItem, false, kDataBrowserItemAnyState,
                        itemsHandle);

    /* At this point we have the following:
       Handle -> Pointer -> DataBrowserItemID[]
       In our icon data browser, DataBrowserItemID = IconDBItemDataRec pointer
       So that means we have:
       Handle -> Pointer -> IconDBItemDataRec pointer -> IconDBItemDataRec */

    HLockHi(itemsHandle);	// since we're about to dereference this, we need it to stay put
    items = (DataBrowserItemID *)*itemsHandle;

    /* While this is technically unnecessary, it will save us a lot of awkward
       multiple dereferencings and generally make things much easier to read. */
    for (itemNumber = 0; itemNumber < kNumberOfRows; itemNumber++)
        itemsData[itemNumber] = (IconDBItemDataRec *)*(items + itemNumber);

    GetIconRefOwners((itemsData[0])->icon, &referenceCount);

    // first, unregister and/or release the icons
    if (referenceCount == 1)	// if this is the last instance of the
    {   // IconRefs we should unregister them
        OSType iconType;

        /* UnregisterIconRef doesn't decrement the reference count on some versions
           of Mac OS X (it does on 10.1.5, doesn't on 10.2.8, and does on 10.3.4).
           To account for this we will retain/acquire the icon, unregister it, then
           check the reference/owner count.  If it's the same then we will also
           release the icons.  We can't release the icons first or UnregisterIconRef
           will return noSuchIconErr (because the icons will already be disposed).
           Likewise we can't just release the icons afterwards because they may get
           disposed of when they're unregistered. */
        AcquireIconRef((itemsData[0])->icon);

        for (iconType = 'Cat0'; iconType <= 'Cat9'; iconType++)
            UnregisterIconRef(kAppSignature, iconType);

        gIconsRegistered = false;

        GetIconRefOwners((itemsData[0])->icon, &referenceCount);
        if (referenceCount > 1)
            needRelease = true;

        ReleaseIconRef((itemsData[0])->icon);
    }
    else						// otherwise simply release the icons
        needRelease = true;

    if (needRelease)
    {
        for (itemNumber = 0; itemNumber < kNumberOfRows; itemNumber++)
            ReleaseIconRef((itemsData[itemNumber])->icon);
    }

    // second, release the strings
    for (itemNumber = 0; itemNumber < kNumberOfRows; itemNumber++)
        CFRelease((itemsData[itemNumber])->name);

    DisposeHandle(itemsHandle);

    // finally, release our callbacks
    gCallbackRefCount--;
    if (gCallbackRefCount == 0)
    {
        DisposeDataBrowserItemNotificationUPP(gIconDBCallbacks.u.v1.itemNotificationCallback);
        DisposeDataBrowserDrawItemUPP(gIconDBCustomCallbacks.u.v1.drawItemCallback);
    }
}
Beispiel #5
0
									((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);
							}
						}
					}

					err = UnregisterIconRef('~9X~', 'TEMP');
				}
			}

			CFRelease(url);
		}

		CFRelease(str);
	}
}

const char * S9xGetFilename (const char *inExt, enum s9x_getdirtype dirtype)
{
	static int	index = 0;
	static char	filePath[4][PATH_MAX + 1];