1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008-2010 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the
11 * above copyright notice, this list of conditions
12 * and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the
18 * 3. The name of the author may not be used to endorse
19 * or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #define _trace() do { \
44 struct timeval _ctv; \
45 gettimeofday(&_ctv, NULL); \
50 fprintf(stderr, "%lu.%.6u[%f]:_trace()@%s:%u[%s]\n", \
51 _ctv.tv_sec, _ctv.tv_usec, \
52 (_ctv.tv_sec - _ltv.tv_sec) + (_ctv.tv_usec - _ltv.tv_usec) / 1000000.0, \
53 __FILE__, __LINE__, __FUNCTION__\
60 #import <CoreFoundation/CoreFoundation.h>
61 #import <Foundation/Foundation.h>
62 #import <CoreGraphics/CoreGraphics.h>
64 #import <Celestial/AVController.h>
65 #import <Celestial/AVItem.h>
66 #import <Celestial/AVQueue.h>
68 #include <substrate.h>
70 #import <UIKit/UIKit.h>
72 #import <SpringBoard/SBApplication.h>
73 #import <SpringBoard/SBApplicationIcon.h>
74 #import <SpringBoard/SBAppWindow.h>
75 #import <SpringBoard/SBAwayView.h>
76 #import <SpringBoard/SBBookmarkIcon.h>
77 #import <SpringBoard/SBButtonBar.h>
78 #import <SpringBoard/SBCalendarIconContentsView.h>
79 #import <SpringBoard/SBIconController.h>
80 #import <SpringBoard/SBIconLabel.h>
81 #import <SpringBoard/SBIconList.h>
82 #import <SpringBoard/SBIconModel.h>
83 #import <SpringBoard/SBImageCache.h>
84 // XXX: #import <SpringBoard/SBSearchView.h>
85 #import <SpringBoard/SBSearchTableViewCell.h>
86 #import <SpringBoard/SBStatusBarContentsView.h>
87 #import <SpringBoard/SBStatusBarController.h>
88 #import <SpringBoard/SBStatusBarOperatorNameView.h>
89 #import <SpringBoard/SBStatusBarTimeView.h>
90 #import <SpringBoard/SBUIController.h>
91 #import <SpringBoard/SBWidgetApplicationIcon.h>
93 #import <MobileSMS/mSMSMessageTranscriptController.h>
95 #import <MediaPlayer/MPMoviePlayerController.h>
96 #import <MediaPlayer/MPVideoView.h>
97 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
99 #import <CoreGraphics/CGGeometry.h>
101 #import <ChatKit/CKMessageCell.h>
103 extern "C" void __clear_cache (char *beg, char *end);
105 @protocol WinterBoard
109 Class $MPMoviePlayerController;
111 Class $WebCoreFrameBridge;
116 Class $UINavigationBar;
119 Class $CKMessageCell;
120 Class $CKTimestampView;
121 Class $CKTranscriptController;
122 Class $CKTranscriptTableView;
124 Class $SBApplication;
125 Class $SBApplicationIcon;
127 Class $SBBookmarkIcon;
129 Class $SBCalendarIconContentsView;
132 Class $SBIconController;
136 //Class $SBImageCache;
138 Class $SBSearchTableViewCell;
139 Class $SBStatusBarContentsView;
140 Class $SBStatusBarController;
141 Class $SBStatusBarOperatorNameView;
142 Class $SBStatusBarTimeView;
143 Class $SBUIController;
144 Class $SBWidgetApplicationIcon;
148 @interface NSDictionary (WinterBoard)
149 - (UIColor *) wb$colorForKey:(NSString *)key;
150 - (BOOL) wb$boolForKey:(NSString *)key;
153 @implementation NSDictionary (WinterBoard)
155 - (UIColor *) wb$colorForKey:(NSString *)key {
156 NSString *value = [self objectForKey:key];
163 - (BOOL) wb$boolForKey:(NSString *)key {
164 if (NSString *value = [self objectForKey:key])
165 return [value boolValue];
171 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
172 #define $GSFontGetUseLegacyFontMetrics() \
173 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
175 static bool Debug_ = false;
176 static bool Engineer_ = false;
177 static bool SummerBoard_ = true;
178 static bool SpringBoard_;
180 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
181 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
182 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
183 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
184 static NSBundle *(*_UIKitBundle)();
185 static int (*_UISharedImageNameGetIdentifier)(NSString *);
186 static UIImage *(*_UISharedImageWithIdentifier)(int);
188 static NSMutableDictionary *UIImages_;
189 static NSMutableDictionary *PathImages_;
190 static NSMutableDictionary *Cache_;
191 static NSMutableDictionary *Strings_;
192 static NSMutableDictionary *Themed_;
193 static NSMutableDictionary *Bundles_;
195 static NSFileManager *Manager_;
196 static NSDictionary *English_;
197 static NSMutableDictionary *Info_;
198 static NSMutableArray *themes_;
200 static NSString *$getTheme$(NSArray *files, bool parent = false) {
202 if (NSString *path = [Themed_ objectForKey:files])
203 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
206 NSLog(@"WB:Debug: %@", [files description]);
210 for (NSString *theme in themes_)
211 for (NSString *file in files) {
212 path = [NSString stringWithFormat:@"%@/%@", theme, file];
213 if ([Manager_ fileExistsAtPath:path]) {
214 path = parent ? theme : path;
222 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
226 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
227 NSString *identifier = [bundle bundleIdentifier];
228 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
230 if (identifier != nil)
231 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
232 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
233 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
235 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
237 #define remapResourceName(oldname, newname) \
238 else if ([file isEqualToString:oldname]) \
239 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
241 bool summer(SpringBoard_ && SummerBoard_);
243 if (identifier == nil);
244 else if ([identifier isEqualToString:@"com.apple.chatkit"])
245 [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
246 else if ([identifier isEqualToString:@"com.apple.calculator"])
247 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
249 remapResourceName(@"FSO_BG.png", @"StatusBar")
250 remapResourceName(@"SBDockBG.png", @"Dock")
251 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
253 if (NSString *path = $getTheme$(names))
259 static NSString *$pathForIcon$(SBApplication *self, NSString *suffix = @"") {
260 NSString *identifier = [self bundleIdentifier];
261 NSString *path = [self path];
262 NSString *folder = [path lastPathComponent];
263 NSString *dname = [self displayName];
264 NSString *didentifier = [self displayIdentifier];
267 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
269 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
271 /* XXX: I might need to keep this for backwards compatibility
272 if (identifier != nil)
273 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
275 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */
277 #define testForIcon(Name) \
278 if (NSString *name = Name) \
279 [names addObject:[NSString stringWithFormat:@"Icons%@/%@.png", suffix, name]];
281 if (![didentifier isEqualToString:identifier])
282 testForIcon(didentifier);
284 testForIcon(identifier);
287 if ([identifier isEqualToString:@"com.apple.MobileSMS"])
290 if (didentifier != nil) {
291 testForIcon([English_ objectForKey:didentifier]);
293 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
294 if ([parts count] != 1)
295 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
296 testForIcon([english objectForKey:[parts lastObject]]);
299 if (NSString *path = $getTheme$(names))
305 @interface NSBundle (WinterBoard)
306 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
309 @implementation NSBundle (WinterBoard)
311 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
312 path = [path stringByDeletingLastPathComponent];
313 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
316 NSBundle *bundle([Bundles_ objectForKey:path]);
317 if (reinterpret_cast<id>(bundle) == [NSNull null])
319 else if (bundle == nil) {
320 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
321 bundle = [NSBundle bundleWithPath:path];
323 bundle = [NSBundle wb$bundleWithFile:path];
325 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
326 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
334 @interface NSString (WinterBoard)
335 - (NSString *) wb$themedPath;
338 @implementation NSString (WinterBoard)
340 - (NSString *) wb$themedPath {
342 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
344 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
345 NSString *file([self stringByResolvingSymlinksInPath]);
346 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
347 if ([file hasPrefix:prefix]) {
348 NSUInteger length([prefix length]);
349 if (length != [file length])
350 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
360 void WBLogRect(const char *tag, struct CGRect rect) {
361 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
364 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
365 CGRect frame([view frame]);
366 NSLog(@"%*s|%2d:%p:%s : {%f,%f+%f,%f} (%@)", indent * 3, "", index, view, class_getName([view class]), frame.origin.x, frame.origin.y, frame.size.width, frame.size.height, [view backgroundColor]);
368 for (UIView *child in [view subviews])
369 WBLogHierarchy(child, index++, indent + 1);
372 UIImage *$cacheForImage$(UIImage *image) {
373 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
374 CGRect rect = {CGPointMake(1, 1), [image size]};
375 CGSize size = {rect.size.width + 2, rect.size.height + 2};
377 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
378 CGColorSpaceRelease(space);
380 CGContextDrawImage(context, rect, [image CGImage]);
381 CGImageRef ref(CGBitmapContextCreateImage(context));
382 CGContextRelease(context);
384 UIImage *cache([UIImage imageWithCGImage:ref]);
390 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
391 //if ([name isEqualToString:@"icons"]) return nil;
392 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
395 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
396 NSString *key([icon displayIdentifier]);
398 if (UIImage *image = [icon icon]) {
399 CGSize size = [image size];
400 if (size.width != 59 || size.height != 60) {
401 UIImage *cache($cacheForImage$(image));
402 [Cache_ setObject:cache forKey:key];
407 _SBIconModel$cacheImageForIcon$(self, sel, icon);
410 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
411 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
412 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
414 NSString *key([icon displayIdentifier]);
416 if (UIImage *image = [icon icon]) {
417 CGSize size = [image size];
418 if (size.width != 59 || size.height != 60) {
419 UIImage *cache($cacheForImage$(image));
420 [Cache_ setObject:cache forKey:key];
426 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
427 NSString *key([icon displayIdentifier]);
428 if (UIImage *image = [Cache_ objectForKey:key])
431 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
434 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
436 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
437 NSString *key([icon displayIdentifier]);
438 if (UIImage *image = [Cache_ objectForKey:key])
441 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
444 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
445 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
446 [self setBackgroundColor:[UIColor clearColor]];
447 for (UIView *child in [self subviews])
448 [child setBackgroundColor:[UIColor clearColor]];
452 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
453 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
454 [self setBackgroundColor:[UIColor clearColor]];
458 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
459 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
460 float inset([self edgeInset]);
461 [[UIColor clearColor] set];
462 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
463 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
466 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
467 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
468 if (NSString *path = $pathForIcon$([self application]))
469 return [UIImage imageWithContentsOfFile:path];
470 return _SBApplicationIcon$icon(self, sel);
473 MSHook(UIImage *, SBApplicationIcon$generateIconImage$, SBApplicationIcon *self, SEL sel, int type) {
475 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"]) {
476 if (NSString *path72 = $pathForIcon$([self application], @"-72"))
477 return [UIImage imageWithContentsOfFile:path];
478 else if (NSString *path = $pathForIcon$([self application]))
479 if (UIImage *image = [UIImage imageWithContentsOfFile:path])
480 return [image _imageScaledToProportion:1.2 interpolationQuality:5];
482 return _SBApplicationIcon$generateIconImage$(self, sel, type);
485 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
487 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
488 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
489 return [UIImage imageWithContentsOfFile:path];
490 return _SBWidgetApplicationIcon$icon(self, sel);
493 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
495 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
496 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
497 return [UIImage imageWithContentsOfFile:path];
498 return _SBBookmarkIcon$icon(self, sel);
501 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
502 if (NSString *path = $pathForIcon$(self))
504 return _SBApplication$pathForIcon(self, sel);
507 static UIImage *CachedImageAtPath(NSString *path) {
508 path = [path stringByResolvingSymlinksInPath];
509 UIImage *image = [PathImages_ objectForKey:path];
511 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
512 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
514 image = [image autorelease];
515 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
519 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
521 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
523 NSString *themed([name wb$themedPath]);
525 if (false && SpringBoard_ && SummerBoard_ && themed == name) {
526 if ([name isEqualToString:@"/System/Library/CoreServices/SpringBoard.app/SBDockBGT-Portrait.png"])
527 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Dock.png"])) {
528 UIImage *image([UIImage imageWithContentsOfFile:path]);
529 CGImageRef ref([[image _imageScaledToProportion:2.4 interpolationQuality:5] imageRef]);
535 return __UIImageRefAtPath(themed, cache, orientation);
538 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
540 return __UIImageAtPath(name, nil);
542 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
543 UIImage *image = [PathImages_ objectForKey:key];
545 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
547 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
548 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
549 image = CachedImageAtPath(path);
551 image = __UIImageAtPath(name, bundle);
552 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
557 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
558 NSBundle *bundle = [NSBundle mainBundle];
560 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
561 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
562 return CachedImageAtPath(path);
563 return __UIApplicationImageWithName(name);
566 #define WBDelegate(delegate) \
567 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
569 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
570 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
572 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
576 - (void) forwardInvocation:(NSInvocation*)inv { \
577 SEL sel = [inv selector]; \
578 if ([delegate respondsToSelector:sel]) \
579 [inv invokeWithTarget:delegate]; \
581 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
584 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
585 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
587 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
588 if (NSString *path = $pathForFile$inBundle$(file, self, false))
590 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
593 void $setBarStyle$_(NSString *name, int &style) {
595 NSLog(@"WB:Debug:%@Style:%d", name, style);
596 NSNumber *number = nil;
598 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
600 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
602 style = [number intValue];
604 NSLog(@"WB:Debug:%@Style=%d", name, style);
608 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
609 NSBundle *bundle([NSBundle mainBundle]);
611 CFLocaleRef locale(CFLocaleCopyCurrent());
612 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
615 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
617 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
618 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
619 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
620 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
624 CFRelease(formatter);
626 NSString *datestyle([@""
627 "font-family: Helvetica; "
628 "font-weight: bold; "
631 "" stringByAppendingString:(IsWild_
632 ? @"font-size: 54px; "
633 : @"font-size: 39px; "
636 NSString *daystyle([@""
637 "font-family: Helvetica; "
638 "font-weight: bold; "
640 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
641 "" stringByAppendingString:(IsWild_
642 ? @"font-size: 11px; "
643 : @"font-size: 9px; "
646 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
647 datestyle = [datestyle stringByAppendingString:style];
648 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
649 daystyle = [daystyle stringByAppendingString:style];
651 float width([self bounds].size.width);
653 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
654 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
656 unsigned base(IsWild_ ? 89 : 70);
657 if ($GSFontGetUseLegacyFontMetrics())
660 [(NSString *)date drawAtPoint:CGPointMake(
661 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
662 ) withStyle:datestyle];
664 [(NSString *)day drawAtPoint:CGPointMake(
665 (width + 1 - daysize.width) / 2, ((IsWild_ ? 18 : 16) - daysize.height) / 2
666 ) withStyle:daystyle];
672 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
675 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
676 style = [number intValue];
678 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
681 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
684 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
685 self = [self wb$initWithCoder:coder];
688 UINavigationBar$setBarStyle$_(self);
692 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
693 self = [self wb$initWithFrame:frame];
696 UINavigationBar$setBarStyle$_(self);
700 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
701 $setBarStyle$_(@"Toolbar", style);
702 return _UIToolbar$setBarStyle$(self, sel, style);
705 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
706 $setBarStyle$_(@"NavigationBar", style);
707 return _UINavigationBar$setBarStyle$(self, sel, style);
710 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
711 [[self superview] setBackgroundColor:[UIColor clearColor]];
712 _SBButtonBar$didMoveToSuperview(self, sel);
715 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
716 [[self superview] setBackgroundColor:[UIColor clearColor]];
717 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
720 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
722 NSLog(@"WB:Debug:DefaultDesktopImage");
723 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
724 return [UIImage imageWithContentsOfFile:path];
725 return _UIImage$defaultDesktopImage(self, sel);
728 static NSArray *Wallpapers_;
729 static bool Papered_;
730 static NSString *WallpaperFile_;
731 static UIImageView *WallpaperImage_;
732 static UIWebDocumentView *WallpaperPage_;
733 static NSURL *WallpaperURL_;
735 #define _release(object) \
736 do if (object != nil) { \
741 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
742 self = _SBUIController$init(self, sel);
746 UIDevice *device([UIDevice currentDevice]);
747 IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
750 UIWindow *&_wallpaperView(MSHookIvar<UIWindow *>(self, "_wallpaperView"));
751 if (&_wallpaperView != NULL) {
752 [_wallpaperView removeFromSuperview];
753 [_wallpaperView release];
754 _wallpaperView = nil;
758 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
759 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
760 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
763 if (&_contentLayer != NULL)
764 layer = _contentLayer;
765 else if (&_contentView != NULL)
766 layer = _contentView;
770 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
772 [content setBackgroundColor:[layer backgroundColor]];
773 [layer setBackgroundColor:[UIColor clearColor]];
774 [layer setFrame:[content bounds]];
775 [_window setContentView:content];
778 if (!SummerBoard_ || !IsWild_)
781 CGRect bounds([content bounds]);
782 bounds.origin.y = -30;
783 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
784 [content addSubview:indirect];
785 [indirect zoomToScale:2.4];
788 _release(WallpaperFile_);
789 _release(WallpaperImage_);
790 _release(WallpaperPage_);
791 _release(WallpaperURL_);
793 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
794 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
795 if ([Manager_ fileExistsAtPath:mp4]) {
799 static AVController *controller_(nil);
800 if (controller_ == nil) {
801 AVQueue *queue([AVQueue avQueue]);
802 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
805 AVQueue *queue([controller_ queue]);
807 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
808 [controller_ setLayer:[video _layer]];
810 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
811 [queue appendItem:item error:&error];
813 [controller_ play:&error];
814 #elif UseMPMoviePlayerController
815 NSURL *url([NSURL fileURLWithPath:mp4]);
816 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
817 controller.movieControlMode = MPMovieControlModeHidden;
820 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
821 [video setMovieWithPath:mp4];
822 [video setRepeatMode:1];
823 [video setRepeatGap:-1];
824 [video playFromBeginning];;
827 [indirect addSubview:video];
830 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
831 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
834 if ([Manager_ fileExistsAtPath:png])
836 else if ([Manager_ fileExistsAtPath:jpg])
842 image = [[UIImage alloc] initWithContentsOfFile:path];
844 image = [image autorelease];
848 WallpaperFile_ = [path retain];
849 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
850 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
851 [WallpaperImage_ setAlpha:[number floatValue]];
852 [indirect addSubview:WallpaperImage_];
855 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
856 if ([Manager_ fileExistsAtPath:html]) {
857 CGRect bounds = [indirect bounds];
859 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
860 [view setAutoresizes:true];
862 WallpaperPage_ = [view retain];
863 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
865 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
867 [view setBackgroundColor:[UIColor clearColor]];
868 if ([view respondsToSelector:@selector(setDrawsBackground:)])
869 [view setDrawsBackground:NO];
870 [[view webView] setDrawsBackground:NO];
872 [indirect addSubview:view];
876 for (size_t i(0), e([themes_ count]); i != e; ++i) {
877 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
878 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
879 if ([Manager_ fileExistsAtPath:html]) {
880 CGRect bounds = [indirect bounds];
882 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
883 [view setAutoresizes:true];
885 NSURL *url = [NSURL fileURLWithPath:html];
886 [view loadRequest:[NSURLRequest requestWithURL:url]];
888 [view setBackgroundColor:[UIColor clearColor]];
889 if ([view respondsToSelector:@selector(setDrawsBackground:)])
890 [view setDrawsBackground:NO];
891 [[view webView] setDrawsBackground:NO];
893 [indirect addSubview:view];
897 [content addSubview:layer];
902 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
903 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
904 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
906 if (path != nil && _backgroundView != nil)
909 _SBAwayView$updateDesktopImage$(self, sel, image);
912 CGRect bounds = [self bounds];
914 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
915 [view setAutoresizes:true];
917 if (WallpaperPage_ != nil)
918 [WallpaperPage_ release];
919 WallpaperPage_ = [view retain];
921 if (WallpaperURL_ != nil)
922 [WallpaperURL_ release];
923 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
925 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
927 [[view webView] setDrawsBackground:false];
928 [view setBackgroundColor:[UIColor clearColor]];
930 [self insertSubview:view aboveSubview:_backgroundView];
934 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
935 extern "C" CGColorRef CGGStateGetFillColor(void *);
936 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
937 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
939 /* WBTimeLabel {{{ */
940 @interface WBTimeLabel : NSProxy {
942 _transient SBStatusBarTimeView *view_;
945 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
949 @implementation WBTimeLabel
956 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
957 time_ = [time retain];
962 - (NSString *) description {
968 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
969 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
970 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
972 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
973 "font-family: Helvetica; "
974 "font-weight: bold; "
977 "%@", _mode ? @"white" : @"black", custom]];
982 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
987 /* WBBadgeLabel {{{ */
988 @interface WBBadgeLabel : NSProxy {
992 - (id) initWithBadge:(NSString *)badge;
993 - (NSString *) description;
997 @implementation WBBadgeLabel
1004 - (id) initWithBadge:(NSString *)badge {
1005 badge_ = [badge retain];
1009 - (NSString *) description {
1010 return [badge_ description];
1015 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
1016 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
1017 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
1018 "font-family: Helvetica; "
1019 "font-weight: bold; "
1027 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1033 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1034 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1035 alpha = [number floatValue];
1036 return _SBIcon$setAlpha$(self, sel, alpha);
1039 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1040 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
1041 id &_badge(MSHookIvar<id>(self, "_badge"));
1043 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1048 void SBStatusBarController$setStatusBarMode(int &mode) {
1050 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
1051 if (mode < 100) // 104:hidden 105:glowing
1052 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1053 mode = [number intValue];
1056 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1057 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1058 SBStatusBarController$setStatusBarMode(mode);
1059 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1062 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
1063 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
1064 SBStatusBarController$setStatusBarMode(mode);
1065 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1068 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int fenceID, int animation, double startTime) {
1069 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1070 SBStatusBarController$setStatusBarMode(mode);
1071 //NSLog(@"mode=%u", mode);
1072 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1075 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1076 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1077 mode = [number intValue];
1078 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1081 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1082 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1084 NSLog(@"operatorNameStyle= %@", style);
1085 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1086 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1090 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1092 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1093 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1096 // XXX: replace this with [SBStatusBarTimeView tile]
1097 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1098 id &_time(MSHookIvar<id>(self, "_time"));
1099 if (_time != nil && [_time class] != [WBTimeLabel class])
1100 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1101 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1104 @interface UIView (WinterBoard)
1105 - (bool) wb$isWBImageView;
1106 - (void) wb$logHierarchy;
1109 @implementation UIView (WinterBoard)
1111 - (bool) wb$isWBImageView {
1115 - (void) wb$logHierarchy {
1116 WBLogHierarchy(self);
1121 @interface WBImageView : UIImageView {
1124 - (bool) wb$isWBImageView;
1125 - (void) wb$updateFrame;
1128 @implementation WBImageView
1130 - (bool) wb$isWBImageView {
1134 - (void) wb$updateFrame {
1135 CGRect frame([self frame]);
1138 for (UIView *view(self); ; ) {
1139 view = [view superview];
1142 frame.origin.y -= [view frame].origin.y;
1145 [self setFrame:frame];
1150 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1151 NSArray *subviews([self subviews]);
1152 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1153 if (view != nil && [view wb$isWBImageView])
1154 [view wb$updateFrame];
1155 _SBIconList$setFrame$(self, sel, frame);
1158 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1159 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1160 NSArray *lists([_iconModel iconLists]);
1162 for (unsigned i(0), e([lists count]); i != e; ++i)
1163 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1164 SBIconList *list([lists objectAtIndex:i]);
1165 NSArray *subviews([list subviews]);
1167 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1168 if (view == nil || ![view wb$isWBImageView]) {
1169 view = [[[WBImageView alloc] init] autorelease];
1170 [list insertSubview:view atIndex:0];
1173 UIImage *image([UIImage imageWithContentsOfFile:path]);
1175 CGRect frame([view frame]);
1176 frame.size = [image size];
1177 [view setFrame:frame];
1179 [view setImage:image];
1180 [view wb$updateFrame];
1183 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1186 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1187 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1189 [self setClipsToBounds:NO];
1193 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1194 id &_label(MSHookIvar<id>(self, "_label"));
1195 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1197 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1198 [_label setInDock:docked];
1199 return _SBIconLabel$setInDock$(self, sel, docked);
1202 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1203 NSString *identifier = [self bundleIdentifier];
1204 NSLocale *locale = [NSLocale currentLocale];
1205 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1207 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1208 NSString *file = table == nil ? @"Localizable" : table;
1209 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1210 NSDictionary *strings;
1211 if ((strings = [Strings_ objectForKey:name]) != nil) {
1212 if (static_cast<id>(strings) != [NSNull null]) strings:
1213 if (NSString *value = [strings objectForKey:key])
1215 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1218 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1219 [Strings_ setObject:[strings autorelease] forKey:name];
1223 [Strings_ setObject:[NSNull null] forKey:name];
1224 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1227 @class WebCoreFrameBridge;
1228 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1231 void **core(reinterpret_cast<void **>([node _node]));
1232 if (core == NULL || core[6] == NULL)
1234 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1237 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1238 CGRect bounds = [self bounds];
1240 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1243 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1244 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1246 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1248 NSString *style = [NSString stringWithFormat:@""
1249 "font-family: Helvetica; "
1250 "font-weight: bold; "
1252 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
1253 ? @"font-size: 12px; "
1254 : @"font-size: 11px; "
1258 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1260 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1262 bool ellipsis(false);
1263 float max = 75, width;
1265 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1268 size_t length([label length]);
1269 float spacing((width - max) / (length - 1));
1271 if (spacing > 1.25) {
1273 label = [label substringToIndex:(length - 1)];
1277 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1281 label = [label stringByAppendingString:@"..."];
1283 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1284 style = [style stringByAppendingString:custom];
1286 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1287 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1290 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1291 _CKMessageCell$addBalloonView$(self, sel, balloon);
1292 [balloon setBackgroundColor:[UIColor clearColor]];
1295 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1296 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1297 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1301 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1302 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1303 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1304 [_label setBackgroundColor:[UIColor clearColor]];
1308 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1309 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1312 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1314 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1315 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1319 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1320 _TranscriptController$loadView(self, sel);
1322 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1323 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1324 [image autorelease];
1326 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1327 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1329 if (&_transcriptTable != NULL)
1330 table = _transcriptTable;
1331 else if (&_transcriptLayer != NULL)
1332 table = _transcriptLayer;
1336 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1337 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1340 [placard insertSubview:background atIndex:0];
1342 [table setBackgroundColor:[UIColor clearColor]];
1343 [placard insertSubview:background belowSubview:table];
1348 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1349 int id(_UISharedImageNameGetIdentifier(name));
1351 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1354 return _UIImageAtPath(name, _UIKitBundle());
1356 NSNumber *key([NSNumber numberWithInt:id]);
1357 UIImage *image = [UIImages_ objectForKey:key];
1359 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1360 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1361 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1363 [image autorelease];
1365 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1366 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1370 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1371 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1372 UIImage *image([PathImages_ objectForKey:key]);
1374 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1376 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1377 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1378 image = [[UIImage alloc] initWithContentsOfFile:path];
1380 [image autorelease];
1382 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1383 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1386 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1388 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1389 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1390 name = [font UTF8String];
1391 //if (NSString *scale = [Info_ objectForKey:[NSString stringWithFormat:@"FontScale-%s", name]])
1392 // size *= [scale floatValue];
1393 return _GSFontCreateWithName(name, traits, size);
1396 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1397 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1399 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1401 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1403 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1404 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1406 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1409 NSString *path = [NSString stringWithUTF8String:a1];
1410 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1411 NSString *file = [path substringFromIndex:31];
1412 for (NSString *theme in themes_) {
1413 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1414 if ([Manager_ fileExistsAtPath:path]) {
1415 strcpy(a1, [path UTF8String]);
1424 static void ChangeWallpaper(
1425 CFNotificationCenterRef center,
1429 CFDictionaryRef info
1432 NSLog(@"WB:Debug:ChangeWallpaper!");
1435 if (WallpaperFile_ != nil) {
1436 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1438 image = [image autorelease];
1441 if (WallpaperImage_ != nil)
1442 [WallpaperImage_ setImage:image];
1443 if (WallpaperPage_ != nil)
1444 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1448 #define WBRename(name, sel, imp) \
1449 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1451 template <typename Type_>
1452 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1453 struct nlist &name(nl[index]);
1454 uintptr_t value(name.n_value);
1455 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1456 value |= 0x00000001;
1457 function = reinterpret_cast<Type_>(value);
1460 template <typename Type_>
1461 static void dlset(Type_ &function, const char *name) {
1462 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1465 extern "C" void WBInitialize() {
1466 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1468 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1470 NSLog(@"WB:Notice: WinterBoard");
1472 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1476 memset(nl, 0, sizeof(nl));
1477 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1478 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1479 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1480 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1481 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1482 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1483 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1486 nlset(_UIApplicationImageWithName, nl, 0);
1487 nlset(_UIImageAtPath, nl, 1);
1488 nlset(_UIImageRefAtPath, nl, 2);
1489 nlset(_UIImageWithNameInDomain, nl, 3);
1490 nlset(_UIKitBundle, nl, 4);
1491 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1492 nlset(_UISharedImageWithIdentifier, nl, 6);
1494 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1495 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1496 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1497 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1499 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1501 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1503 memset(nl, 0, sizeof(nl));
1504 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1505 nlist(AudioToolbox, nl);
1506 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1507 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1510 $NSBundle = objc_getClass("NSBundle");
1512 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1513 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1515 $UIImage = objc_getClass("UIImage");
1516 $UINavigationBar = objc_getClass("UINavigationBar");
1517 $UIToolbar = objc_getClass("UIToolbar");
1519 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1521 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1522 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1524 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1525 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1527 Manager_ = [[NSFileManager defaultManager] retain];
1528 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1529 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1530 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1531 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1532 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1534 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1536 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1537 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1538 SummerBoard_ = [value boolValue];
1539 if (NSNumber *value = [settings objectForKey:@"Debug"])
1540 Debug_ = [value boolValue];
1542 NSArray *themes([settings objectForKey:@"Themes"]);
1544 if (NSString *theme = [settings objectForKey:@"Theme"])
1545 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1547 [NSNumber numberWithBool:true], @"Active",
1551 for (NSDictionary *theme in themes) {
1552 NSNumber *active([theme objectForKey:@"Active"]);
1553 if (![active boolValue])
1556 NSString *name([theme objectForKey:@"Name"]);
1560 NSString *theme(nil);
1562 #define testForTheme(format...) \
1563 if (theme == nil) { \
1564 NSString *path = [NSString stringWithFormat:format]; \
1565 if ([Manager_ fileExistsAtPath:path]) { \
1566 [themes_ addObject:path]; \
1571 testForTheme(@"/Library/Themes/%@.theme", name)
1572 testForTheme(@"/Library/Themes/%@", name)
1573 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1578 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1580 for (NSString *theme in themes_)
1581 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1582 for (NSString *key in [info allKeys])
1583 if ([Info_ objectForKey:key] == nil)
1584 [Info_ setObject:[info objectForKey:key] forKey:key];
1586 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1588 SpringBoard_ = [identifier isEqualToString:@"com.apple.springboard"];
1590 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1592 $CKMessageCell = objc_getClass("CKMessageCell");
1593 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1594 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1596 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1597 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1598 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1600 $CKTimestampView = objc_getClass("CKTimestampView");
1601 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1603 $CKTranscriptController = objc_getClass("CKTranscriptController");
1604 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1607 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1609 if (_TranscriptController$loadView == NULL) {
1610 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1611 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1614 } else if (SpringBoard_) {
1615 CFNotificationCenterAddObserver(
1616 CFNotificationCenterGetDarwinNotifyCenter(),
1617 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1620 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
1621 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1622 if (MediaPlayer != nil)
1625 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1626 $MPVideoView = objc_getClass("MPVideoView");
1629 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1631 $SBApplication = objc_getClass("SBApplication");
1632 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1633 $SBAwayView = objc_getClass("SBAwayView");
1634 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1635 $SBButtonBar = objc_getClass("SBButtonBar");
1636 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1637 $SBIcon = objc_getClass("SBIcon");
1638 $SBIconBadge = objc_getClass("SBIconBadge");
1639 $SBIconController = objc_getClass("SBIconController");
1640 $SBIconLabel = objc_getClass("SBIconLabel");
1641 $SBIconList = objc_getClass("SBIconList");
1642 $SBIconModel = objc_getClass("SBIconModel");
1643 //$SBImageCache = objc_getClass("SBImageCache");
1644 $SBSearchView = objc_getClass("SBSearchView");
1645 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1646 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1647 $SBStatusBarController = objc_getClass("SBStatusBarController");
1648 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1649 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1650 $SBUIController = objc_getClass("SBUIController");
1651 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1653 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1656 WBRename(SBApplication, pathForIcon, pathForIcon);
1657 WBRename(SBApplicationIcon, icon, icon);
1658 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
1661 WBRename(SBBookmarkIcon, icon, icon);
1662 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1663 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1664 WBRename(SBIcon, setAlpha:, setAlpha$);
1665 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1666 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1667 WBRename(SBUIController, init, init);
1668 WBRename(SBWidgetApplicationIcon, icon, icon);
1670 WBRename(SBIconLabel, drawRect:, drawRect$);
1671 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1672 WBRename(SBIconLabel, setInDock:, setInDock$);
1674 WBRename(SBIconList, setFrame:, setFrame$);
1676 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1677 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1678 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1679 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1681 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1682 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1683 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1685 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1687 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1688 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1689 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1690 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1691 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1692 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1693 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1694 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1695 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1698 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1700 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1703 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1704 Papered_ = $getTheme$(Wallpapers_) != nil;
1706 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1707 [Info_ setObject:[NSNumber numberWithBool:(
1709 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1710 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1711 )] forKey:@"UndockedIconLabels"];
1714 NSLog(@"WB:Debug:Info = %@", [Info_ description]);