File:  [mozdev] / chimera / PreferencePanes / MVPreferencesGroupedIconView.m
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Feb 26 11:49:02 2002 UTC (17 years, 9 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
Checking in the underlying prefs structure, and a prefPane, also fir structural integrity.  Also including a couple categories to extend a couple Cocoa objects, and some project changes to support building with the bundled prefPanes.  Also, added a contrib directory to house user contributed artifacts.  To come soon: more prefPanes, and the colorized icon store, with pref-generated notifications to be picked up by toolbars.

    1: #import "MVPreferencesGroupedIconView.h"
    2: #import "MVPreferencesMultipleIconView.h"
    3: #import "MVPreferencesController.h"
    4: 
    5: @interface MVPreferencesMultipleIconView (MVPreferencesMultipleIconViewPrivate)
    6: - (unsigned int) _numberOfRows;
    7: @end
    8: 
    9: @interface MVPreferencesGroupedIconView (MVPreferencesGroupedIconViewPrivate)
   10: - (unsigned int) _numberOfGroups;
   11: - (void) _sizeToFit;
   12: - (NSRect) _rectForGroupAtIndex:(unsigned int) index;
   13: - (NSRect) _rectForGroupSeparatorAtIndex:(unsigned int) index;
   14: - (void) _generateGroupViews;
   15: - (void) _generateGroupViewAtIndex:(unsigned int) index;
   16: @end
   17: 
   18: @implementation MVPreferencesGroupedIconView
   19: const unsigned int groupViewHeight = 95;
   20: const unsigned int multiIconViewYOffset = 18;
   21: const unsigned int sideGutterWidths = 15;
   22: const unsigned int extraRowHeight = 69;
   23: 
   24: - (id) initWithFrame:(NSRect) frame {
   25:     if( ( self = [super initWithFrame:frame] ) ) {
   26: 		groupMultiIconViews = [[NSMutableArray array] retain];
   27:     }
   28:     return self;
   29: }
   30: 
   31: - (void) drawRect:(NSRect) rect {
   32: 	[self _generateGroupViews];
   33: }
   34: 
   35: - (void) setPreferencesController:(MVPreferencesController *) newPreferencesController {
   36: 	[preferencesController autorelease];
   37: 	preferencesController = [newPreferencesController retain];
   38: 	[self _sizeToFit];
   39: 	[self setNeedsDisplay:YES];
   40: }
   41: 
   42: - (void) setPreferencePanes:(NSArray *) newPreferencePanes {
   43: 	[preferencePanes autorelease];
   44: 	preferencePanes = [newPreferencePanes retain];
   45: 	[self _sizeToFit];
   46: 	[self setNeedsDisplay:YES];
   47: }
   48: 
   49: - (NSArray *) preferencePanes {
   50: 	return preferencePanes;
   51: }
   52: 
   53: - (void) setPreferencePaneGroups:(NSArray *) newPreferencePaneGroups {
   54: 	[preferencePaneGroups autorelease];
   55: 	preferencePaneGroups = [newPreferencePaneGroups retain];
   56: 	[self _sizeToFit];
   57: 	[self setNeedsDisplay:YES];
   58: }
   59: 
   60: - (NSArray *) preferencePaneGroups {
   61: 	return preferencePaneGroups;
   62: }
   63: 
   64: - (BOOL) acceptsFirstResponder {
   65: 	return YES;
   66: }
   67: 
   68: - (BOOL) becomeFirstResponder {
   69: 	[[self window] makeFirstResponder:[self viewWithTag:0]];
   70: 	return YES;
   71: }
   72: 
   73: - (BOOL) resignFirstResponder {
   74: 	return YES;
   75: }
   76: 
   77: - (BOOL) isFlipped {
   78: 	return YES;
   79: }
   80: 
   81: - (BOOL) isOpaque {
   82: 	return NO;
   83: }
   84: @end
   85: 
   86: @implementation MVPreferencesGroupedIconView (MVPreferencesGroupedIconViewPrivate)
   87: - (unsigned int) _numberOfGroups {
   88: 	return [[self preferencePaneGroups] count];
   89: }
   90: 
   91: - (void) _sizeToFit {
   92: 	if( ! [self _numberOfGroups] ) return;
   93: 	[self _generateGroupViews];
   94: 	[self setFrameSize:NSMakeSize( NSWidth( _bounds ), NSMaxY( [self _rectForGroupAtIndex:[self _numberOfGroups] - 1] ) ) ];
   95: }
   96: 
   97: - (NSRect) _rectForGroupAtIndex:(unsigned int) index {
   98: 	unsigned int extra = 0, groupIndex;
   99: 	for( groupIndex = 0; groupIndex < index; groupIndex++ )
  100: 		extra += [[self viewWithTag:groupIndex] _numberOfRows] * extraRowHeight;
  101: 	return NSMakeRect( 0., (index * groupViewHeight ) + multiIconViewYOffset + index + extra, NSWidth( [self frame] ), groupViewHeight );
  102: }
  103: 
  104: - (NSRect) _rectForGroupSeparatorAtIndex:(unsigned int) index {
  105: 	unsigned int extra = 0, groupIndex;
  106: 	if( ! index ) return NSZeroRect;
  107: 	for( groupIndex = 0; groupIndex < index; groupIndex++ )
  108: 		extra += [[self viewWithTag:groupIndex] _numberOfRows] * extraRowHeight;
  109: 	return NSMakeRect( sideGutterWidths, ((index + 1) * groupViewHeight) - groupViewHeight + index + extra, NSWidth( [self frame] ) - (sideGutterWidths * 2), 1 );
  110: }
  111: 
  112: - (void) _generateGroupViews {
  113: 	unsigned int groupIndex, groupCount;
  114: 
  115: 	groupCount = [self _numberOfGroups];
  116: 	for( groupIndex = 0; groupIndex < groupCount; groupIndex++ )
  117: 		[self _generateGroupViewAtIndex:groupIndex];
  118: }
  119: 
  120: - (void) _generateGroupViewAtIndex:(unsigned int) index {
  121: 	MVPreferencesMultipleIconView *multiIconView = nil;
  122: 	NSString *identifier = [[preferencePaneGroups objectAtIndex:index] objectForKey:@"identifier"];
  123: 	NSString *name = NSLocalizedStringFromTable( identifier, @"MVPreferencePaneGroups", nil );
  124: 	NSDictionary *attributesDictionary;
  125: 	unsigned nameHeight = 0;
  126: 
  127: 	if( ! ( multiIconView = [self viewWithTag:index] ) ) {
  128: 		NSMutableArray *panes = [NSMutableArray array];
  129: 		NSBox *sep = [[[NSBox alloc] initWithFrame:[self _rectForGroupSeparatorAtIndex:index]] autorelease];
  130: 		NSEnumerator *enumerator = [[[preferencePaneGroups objectAtIndex:index] objectForKey:@"panes"] objectEnumerator];
  131: 		id pane = nil, bundle = 0;
  132: 
  133: 		multiIconView = [[[MVPreferencesMultipleIconView alloc] initWithFrame:[self _rectForGroupAtIndex:index]] autorelease];
  134: 		while( ( pane = [enumerator nextObject] ) ) {
  135: 			bundle = [NSBundle bundleWithIdentifier:pane];
  136: 			if( bundle ) [panes addObject:bundle];
  137: 		}
  138: 
  139: 		[multiIconView setPreferencesController:preferencesController];
  140: 		[multiIconView setPreferencePanes:panes];
  141: 		[multiIconView setTag:index];
  142: 
  143: 		[sep setBoxType:NSBoxSeparator];
  144: 		[sep setBorderType:NSBezelBorder];
  145: 	
  146: 		[self addSubview:multiIconView];
  147: 		[self addSubview:sep];
  148: //		if( ! index ) [[self window] makeFirstResponder:multiIconView];
  149: 		if( index - 1 >= 0 ) [[self viewWithTag:index - 1] setNextKeyView:multiIconView];
  150: 		if( index == [self _numberOfGroups] - 1 ) [multiIconView setNextKeyView:[self viewWithTag:0]];
  151: 	}
  152: 
  153: 	attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont boldSystemFontOfSize:13.], NSFontAttributeName, nil];
  154: 	nameHeight = [[NSFont boldSystemFontOfSize:13.] ascender];
  155: 	[name drawAtPoint:NSMakePoint( sideGutterWidths - 1, NSMinY( [multiIconView frame] ) - nameHeight - 1 ) withAttributes:attributesDictionary];
  156: }
  157: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>