00001 00002 @import <AppKit/CPTheme.j> 00003 @import <AppKit/CPView.j> 00004 00005 @import "BKUtilities.j" 00006 00007 00008 @implementation BKShowcaseController : CPObject 00009 { 00010 } 00011 00012 - (void)applicationDidFinishLaunching:(CPNotification)aNotification 00013 { 00014 var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], 00015 contentView = [theWindow contentView], 00016 bounds = [contentView bounds], 00017 themeDescriptorClasses = BKThemeDescriptorClasses(); 00018 00019 var tabView = [[CPTabView alloc] initWithFrame:bounds]; 00020 00021 [tabView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; 00022 00023 [contentView addSubview:tabView]; 00024 00025 var index = 0, 00026 count = [themeDescriptorClasses count]; 00027 00028 for (; index < count; ++index) 00029 { 00030 var theClass = themeDescriptorClasses[index], 00031 item = [[CPTabViewItem alloc] initWithIdentifier:[theClass themeName]], 00032 templates = BKThemeObjectTemplatesForClass(theClass), 00033 templatesCount = [templates count], 00034 viewTemplates = [], 00035 itemSize = CGSizeMake(0.0, 0.0); 00036 00037 while (templatesCount--) 00038 { 00039 var template = templates[templatesCount], 00040 object = [template valueForKey:@"themedObject"]; 00041 00042 if ([object isKindOfClass:[CPView class]]) 00043 { 00044 var size = [object frame].size, 00045 labelWidth = [[template valueForKey:@"label"] sizeWithFont:[CPFont boldSystemFontOfSize:12.0]].width + 20.0; 00046 00047 if (size.width > itemSize.width) 00048 itemSize.width = size.width; 00049 00050 if (labelWidth > itemSize.width) 00051 itemSize.width = labelWidth; 00052 00053 if (size.height > itemSize.height) 00054 itemSize.height = size.height; 00055 00056 [viewTemplates addObject:template]; 00057 } 00058 } 00059 00060 itemSize.width += 20.0; 00061 itemSize.height += 30.0; 00062 00063 var collectionView = [[CPCollectionView alloc] initWithFrame:CGRectMakeZero()], 00064 collectionViewItem = [[CPCollectionViewItem alloc] init]; 00065 00066 var backgroundColor = nil; 00067 00068 if ([theClass respondsToSelector:@selector(themeShowcaseBackgroundColor)]) 00069 backgroundColor = [theClass themeShowcaseBackgroundColor]; 00070 00071 [collectionViewItem setView:[[BKShowcaseCell alloc] initWithShowcaseBackgroundColor:backgroundColor]]; 00072 00073 [collectionView setItemPrototype:collectionViewItem]; 00074 [collectionView setMinItemSize:itemSize]; 00075 [collectionView setMaxItemSize:itemSize]; 00076 [collectionView setVerticalMargin:5.0]; 00077 [collectionView setContent:viewTemplates]; 00078 00079 [item setLabel:[theClass themeName]]; 00080 [item setView:collectionView]; 00081 00082 [tabView addTabViewItem:item]; 00083 } 00084 00085 [theWindow orderFront:self]; 00086 } 00087 00088 @end 00089 00090 00091 @implementation BKShowcaseCell : CPView 00092 { 00093 CPColor _showcaseBackgroundColor; 00094 CPView _backgroundView; 00095 00096 CPView _view; 00097 CPTextField _label; 00098 } 00099 00100 - (id)initWithShowcaseBackgroundColor:(CPColor)aColor 00101 { 00102 self = [super init]; 00103 00104 if (self) 00105 _showcaseBackgroundColor = aColor; 00106 00107 return self; 00108 } 00109 00110 - (void)setSelected:(BOOL)isSelected 00111 { 00112 } 00113 00114 - (void)setRepresentedObject:(id)anObject 00115 { 00116 if (!_label) 00117 { 00118 _label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; 00119 00120 [_label setAlignment:CPCenterTextAlignment]; 00121 [_label setAutoresizingMask:CPViewMinYMargin | CPViewWidthSizable]; 00122 [_label setFont:[CPFont boldSystemFontOfSize:12.0]]; 00123 00124 [self addSubview:_label]; 00125 } 00126 00127 [_label setStringValue:[anObject valueForKey:@"label"]]; 00128 [_label sizeToFit]; 00129 00130 [_label setFrame:CGRectMake(0.0, CGRectGetHeight([self bounds]) - CGRectGetHeight([_label frame]), 00131 CGRectGetWidth([self bounds]), CGRectGetHeight([_label frame]))]; 00132 00133 if (!_backgroundView) 00134 { 00135 _backgroundView = [[CPView alloc] init]; 00136 00137 [_backgroundView setBackgroundColor:_showcaseBackgroundColor]; 00138 00139 [self addSubview:_backgroundView]; 00140 } 00141 00142 [_backgroundView setFrame:CGRectMake(0.0, 0.0, CGRectGetWidth([self bounds]), CGRectGetMinY([_label frame]))]; 00143 [_backgroundView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; 00144 00145 if (_view) 00146 [_view removeFromSuperview]; 00147 00148 _view = [anObject valueForKey:@"themedObject"]; 00149 00150 [_view setTheme:nil]; 00151 [_view setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; 00152 [_view setFrameOrigin:CGPointMake((CGRectGetWidth([_backgroundView bounds]) - CGRectGetWidth([_view frame])) / 2.0, 00153 (CGRectGetHeight([_backgroundView bounds]) - CGRectGetHeight([_view frame])) / 2.0)]; 00154 00155 [_backgroundView addSubview:_view]; 00156 } 00157 00158 - (id)initWithCoder:(CPCoder)aCoder 00159 { 00160 self = [super initWithCoder:aCoder]; 00161 00162 if (self) 00163 _showcaseBackgroundColor = [aCoder decodeObjectForKey:@"showcase-background-color"]; 00164 00165 return self 00166 } 00167 00168 - (void)encodeWithCoder:(CPCoder)aCoder 00169 { 00170 [super encodeWithCoder:aCoder]; 00171 00172 [aCoder encodeObject:_showcaseBackgroundColor forKey:@"showcase-background-color"]; 00173 } 00174 00175 @end