File: programming/cocoa/UKFontMenuController.zip/UKFontMenuController.m


/* =============================================================================
	PROJECT:	UKFontMenu
	CLASS:		UKFontMenuController
				
	COPYRIGHT:  (c) 2004 by M. Uli Kusterer, all rights reserved.
   ========================================================================== */
 
// -----------------------------------------------------------------------------
//  Headers:
// -----------------------------------------------------------------------------
 
#import "UKFontMenuController.h"
 
 
// -----------------------------------------------------------------------------
//  UKFontMenuController:
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  awakeFromNib:
///		NIB has been loaded, set up font menu.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  dealloc:
//		Clean up by getting rid of ssociated objects.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  rebuildMenu:
///		Remove any old items we added to the menu and append new, updated and
///		more current ones.
//
//  REVISIONS:
//		2004-09-02  UK  Fixed bug in deleting items that would miss submenus.
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
// Remove any old items:
// All items we create have us as the target, even separator lines.
// Look for UKFontMenuCollectionName in user defaults:
"UKFontMenuCollectionName"// No user defaults? Maybe a collection with app's name?
"CFBundleName""Font Menu",@"""Font Menu",@""// Add a separator item if there is none yet:
// Put a separator in there to put it apart from the "Favorites".
"com.apple.Favorites""Favorites",@""// Add 'Favorites' submenu.
"com.apple.Recents""Recently Used",@""// Add 'Recently used' submenu.
	//[fontMenu setDelegate: self];
// Have UKFontMenuCollectionName or app-specific collection? List it!
// Put a separator in there to put it apart from the "Favorites".
// Otherwise, create submenus for *all* collections:
// -----------------------------------------------------------------------------
//  collectionsMayHaveChangedNotification:
///		We got one of the notifications that *may* indicate the collections
///		have changed. Rebuild the menu to make sure it's halfway current.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//  addFavoritesCollectionToMenu:
///		Build the "Favorites" menu.
///		Favorites need to be handled specially, as they include a size, and
///		don't preview their font.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
""// Somehow we can get invalid names.
""// -----------------------------------------------------------------------------
//  addAllFontCollectionsToMenu:
///		Loop over all available font collections (except favorites and recently
///		used), create submenus and call addFontCollection:toMenu: for them.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
"com.apple.Favorites"] )  // Skip favorites.
"com.apple.Recents"] )	// Skip recents.
""// -----------------------------------------------------------------------------
//  addFontCollection:toMenu:
///		Add a list of the font families in the specified collection to a menu.
///		This will make each item display in its own font, if the charset for
///		name and font don't differ (they usually only do for dingbat-style
///		fonts).
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
// Here we keep track of families so we don't list them twice (the different styles show up in the collection as well).
// Don't already have that family name?
		{
			// Add menu item for it:
""// Now make the title a live preview of the font:
// Remember font family so we don't add another item for it.
		}
	}
	[pool release];
}
 
 
// -----------------------------------------------------------------------------
//  menuChoiceChangeFont:
///		Menu action for regular font menu items.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
// Keep new font family name in our member variable so convertAttributes can access it:
// just being paranoid...
	newFontFamily = [[sender title] retain];
	newFontSize = 0;	// 0 = don't change size.
	
	// Send change message:
// Causes call to changeAttributes.
}
 
 
// -----------------------------------------------------------------------------
//  menuChoiceChangeFavoriteFont:
///		Menu action for 'favorites' menu items.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
// just being paranoid...
"com.apple.Favorites"// Send change message:
// Causes call to changeAttributes.
}
 
 
// -----------------------------------------------------------------------------
//  convertAttributes:
///		Called for each style run affected by the changeAttributes call we make
///		in our menu item actions.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
/*-(int)  numberOfItemsInMenu: (NSMenu*)menu
{
	return [menu numberOfItems];
}
 
 
-(BOOL) menu:(NSMenu*)menu updateItem:(NSMenuItem*)item atIndex:(int)index shouldCancel:(BOOL)shouldCancel
{
	if( [item action] == @selector(menuChoiceChangeFont:) )
	{
		if( [item attributedTitle] == nil )
		{
			NSString*			nme = [item title];
			NSFont*				theFont = [[NSFontManager sharedFontManager] convertFont: [NSFont systemFontOfSize: [NSFont systemFontSize]] toFamily: nme];
			NSAttributedString*	astr = [[[NSAttributedString alloc] initWithString: nme attributes: [NSDictionary dictionaryWithObjectsAndKeys: theFont, NSFontAttributeName, nil]] autorelease];
			[item setAttributedTitle: astr];
		}
	}
	
	return !shouldCancel;
}*/
 
 
 
// -----------------------------------------------------------------------------
//  validateMenuItem:
//		Enable/disable menu items we created and checkmark current font in
//		menu.
//
//  REVISIONS:
//		2004-09-01  UK  Created.
// -----------------------------------------------------------------------------
// create a fake "Bigger" menu item and ask the responder whether we can enable it:
"Bigger (Fake)"""// ----------------------------------------------------------
// - fontMenu:
// ----------------------------------------------------------
// ----------------------------------------------------------
// - setFontMenu:
// ----------------------------------------------------------
 

This code uses the PclZip Zip File reading code, which is subject to the GNU LGPL. It also uses the GeSHi syntax highlighter, subject to the GPL. Ask if you want this for your own web site, it's free.