// --------------------------------------------------------------------------------------
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);
		}
	}
}
// --------------------------------------------------------------------------------------
pascal void IconListDef(short message, Boolean selected, Rect *cellRect, Cell theCell, 
						short dataOffset, short dataLen, ListHandle theList)
{
#pragma unused (dataOffset)

	switch(message)
	{
		case lDrawMsg:
		case lHiliteMsg:
				/* Drawing and highlighting are put together because of text smoothing 
				   (anti-aliasing).  Simply using the QuickDraw hilitetransfermode to 
				   paint the cell doesn't work because the text will be smoothed 
				   according to the background color which would still be white.  So 
				   instead we'll need to set the background color according to whether 
				   or not the cell is highlighted, erase the cell, then draw its 
				   contents for both highlight and draw messages.  An alternative would 
				   be, for lHilite messages, to set the background color, erase only the 
				   region around the icon, then draw only the text but messing with all 
				   the Regions would probably end up taking more time so we're just 
				   going to go ahead and erase the entire cell. */
			if (dataLen == sizeof(IconListCellDataRec))		// this should always be true 
			{												// but check it just in case
				IconListCellDataRec cellData;
				
				LGetCell(&cellData, &dataLen, theCell, theList);
				drawIconListCell(theList, cellRect, &cellData, selected);
			}
			break;
	}
}
Beispiel #3
0
int DoHostListDialog()
	{
		short itemHit,okay=FALSE,keepGoing=TRUE;
		DialogPtr dlog=NIL; GrafPtr oldPort;
		ModalFilterUPP MyFilterUPP;

		GetPort(&oldPort);

		/* On PowerPC, need a RoutineDescriptor from heap; on 68K, no allocation */
		
		MyFilterUPP = NewModalFilterProc(MyFilterHD);
		if (MyFilterUPP == NIL) goto cleanUp;

		/* Build dialog window and install its item values */
		
		OpenPrefsFile();
		
		dlog = OpenThisDialog();
		if (dlog == NIL) goto cleanUp;

		/* Entertain filtered user events until dialog is dismissed */
		
		while (keepGoing) {
			ModalDialog(MyFilterUPP,&itemHit);
			keepGoing = DoDialogItem(dlog,itemHit);
			}
		
		/*
		 *	Do final processing of item values, such as exporting them to caller.
		 *	DoDialogItem() has already called AnyBadValues().
		 */
		
		if (itemHit == OK_ITEM) {
			Point	theCell;
			short	dataLen;
			OSErr	anErr;
			Handle	aHand;
			
			//	get the current selection and store it in a global which can be accessed
			//	from the application
			
			theCell.h = 0;
			theCell.v = list4.currentRow;
			
			dataLen = 255;
			LGetCell(&gSavedSelection[1], &dataLen, theCell, list4.hndl);
			gSavedSelection[0] = dataLen;

			//	we save the current selection for the next time we use this transport
			
			//	remove the current resource
			
			aHand = Get1Resource('mw2H', 1000);
			if (aHand != nil) {
				RemoveResource(aHand);
				DisposeHandle(aHand);
				aHand = nil;
			}
			
			//	create a handle and add this resource to the resource file
			
			anErr = PtrToHand(&gSavedSelection[0], &aHand, gSavedSelection[0] + 1);		//	name and length byte
			if ( (anErr == noErr) && (aHand != nil) ) {
				AddResource(aHand, 'mw2H', 1000, "\pDefault Host");
				WriteResource(aHand);
			}