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;
146 @interface NSDictionary (WinterBoard)
147 - (UIColor *) wb$colorForKey:(NSString *)key;
148 - (BOOL) wb$boolForKey:(NSString *)key;
151 @implementation NSDictionary (WinterBoard)
153 - (UIColor *) wb$colorForKey:(NSString *)key {
154 NSString *value = [self objectForKey:key];
161 - (BOOL) wb$boolForKey:(NSString *)key {
162 if (NSString *value = [self objectForKey:key])
163 return [value boolValue];
169 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
170 #define $GSFontGetUseLegacyFontMetrics() \
171 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
174 bool Engineer_ = false;
176 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
177 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
178 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
179 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
180 static NSBundle *(*_UIKitBundle)();
181 static int (*_UISharedImageNameGetIdentifier)(NSString *);
182 static UIImage *(*_UISharedImageWithIdentifier)(int);
184 static NSMutableDictionary *UIImages_;
185 static NSMutableDictionary *PathImages_;
186 static NSMutableDictionary *Cache_;
187 static NSMutableDictionary *Strings_;
188 static NSMutableDictionary *Themed_;
189 static NSMutableDictionary *Bundles_;
191 static NSFileManager *Manager_;
192 static NSDictionary *English_;
193 static NSMutableDictionary *Info_;
194 static NSMutableArray *themes_;
196 static NSString *$getTheme$(NSArray *files, bool parent = false) {
198 if (NSString *path = [Themed_ objectForKey:files])
199 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
202 NSLog(@"WB:Debug: %@", [files description]);
206 for (NSString *theme in themes_)
207 for (NSString *file in files) {
208 path = [NSString stringWithFormat:@"%@/%@", theme, file];
209 if ([Manager_ fileExistsAtPath:path]) {
210 path = parent ? theme : path;
218 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
222 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
223 NSString *identifier = [bundle bundleIdentifier];
224 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
226 if (identifier != nil)
227 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
228 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
229 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
231 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
233 #define remapResourceName(oldname, newname) \
234 else if ([file isEqualToString:oldname]) \
235 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
237 if (identifier == nil);
238 else if ([identifier isEqualToString:@"com.apple.chatkit"])
239 [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
240 else if ([identifier isEqualToString:@"com.apple.calculator"])
241 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
242 else if (![identifier isEqualToString:@"com.apple.springboard"]);
243 remapResourceName(@"FSO_BG.png", @"StatusBar")
244 remapResourceName(@"SBDockBG.png", @"Dock")
245 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
247 if (NSString *path = $getTheme$(names))
252 static NSString *$pathForIcon$(SBApplication *self) {
253 NSString *identifier = [self bundleIdentifier];
254 NSString *path = [self path];
255 NSString *folder = [path lastPathComponent];
256 NSString *dname = [self displayName];
257 NSString *didentifier = [self displayIdentifier];
260 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
262 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
264 if (identifier != nil)
265 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
267 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
269 #define testForIcon(Name) \
270 if (NSString *name = Name) \
271 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
273 if (![didentifier isEqualToString:identifier])
274 testForIcon(didentifier);
275 testForIcon(identifier);
278 if (didentifier != nil) {
279 testForIcon([English_ objectForKey:didentifier]);
281 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
282 if ([parts count] != 1)
283 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
284 testForIcon([english objectForKey:[parts lastObject]]);
287 if (NSString *path = $getTheme$(names))
292 @interface NSBundle (WinterBoard)
293 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
296 @implementation NSBundle (WinterBoard)
298 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
299 path = [path stringByDeletingLastPathComponent];
300 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
303 NSBundle *bundle([Bundles_ objectForKey:path]);
304 if (reinterpret_cast<id>(bundle) == [NSNull null])
306 else if (bundle == nil) {
307 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
308 bundle = [NSBundle bundleWithPath:path];
310 bundle = [NSBundle wb$bundleWithFile:path];
312 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
313 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
321 @interface NSString (WinterBoard)
322 - (NSString *) wb$themedPath;
325 @implementation NSString (WinterBoard)
327 - (NSString *) wb$themedPath {
329 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
331 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
332 NSString *file([self stringByResolvingSymlinksInPath]);
333 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
334 if ([file hasPrefix:prefix]) {
335 NSUInteger length([prefix length]);
336 if (length != [file length])
337 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
347 void WBLogRect(const char *tag, struct CGRect rect) {
348 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
351 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
352 CGRect frame([view frame]);
353 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]);
355 for (UIView *child in [view subviews])
356 WBLogHierarchy(child, index++, indent + 1);
359 UIImage *$cacheForImage$(UIImage *image) {
360 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
361 CGRect rect = {CGPointMake(1, 1), [image size]};
362 CGSize size = {rect.size.width + 2, rect.size.height + 2};
364 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
365 CGColorSpaceRelease(space);
367 CGContextDrawImage(context, rect, [image CGImage]);
368 CGImageRef ref(CGBitmapContextCreateImage(context));
369 CGContextRelease(context);
371 UIImage *cache([UIImage imageWithCGImage:ref]);
377 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
378 //if ([name isEqualToString:@"icons"]) return nil;
379 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
382 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
383 NSString *key([icon displayIdentifier]);
385 if (UIImage *image = [icon icon]) {
386 CGSize size = [image size];
387 if (size.width != 59 || size.height != 60) {
388 UIImage *cache($cacheForImage$(image));
389 [Cache_ setObject:cache forKey:key];
394 _SBIconModel$cacheImageForIcon$(self, sel, icon);
397 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
398 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
399 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
401 NSString *key([icon displayIdentifier]);
403 if (UIImage *image = [icon icon]) {
404 CGSize size = [image size];
405 if (size.width != 59 || size.height != 60) {
406 UIImage *cache($cacheForImage$(image));
407 [Cache_ setObject:cache forKey:key];
413 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
414 NSString *key([icon displayIdentifier]);
415 if (UIImage *image = [Cache_ objectForKey:key])
418 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
421 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
423 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
424 NSString *key([icon displayIdentifier]);
425 if (UIImage *image = [Cache_ objectForKey:key])
428 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
431 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
432 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
433 [self setBackgroundColor:[UIColor clearColor]];
434 for (UIView *child in [self subviews])
435 [child setBackgroundColor:[UIColor clearColor]];
439 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
440 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
441 [self setBackgroundColor:[UIColor clearColor]];
445 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
446 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
447 float inset([self edgeInset]);
448 [[UIColor clearColor] set];
449 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
450 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
453 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
454 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
455 if (NSString *path = $pathForIcon$([self application]))
456 return [UIImage imageWithContentsOfFile:path];
457 return _SBApplicationIcon$icon(self, sel);
460 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
462 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
463 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
464 return [UIImage imageWithContentsOfFile:path];
465 return _SBWidgetApplicationIcon$icon(self, sel);
468 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
470 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
471 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
472 return [UIImage imageWithContentsOfFile:path];
473 return _SBBookmarkIcon$icon(self, sel);
476 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
477 if (NSString *path = $pathForIcon$(self))
479 return _SBApplication$pathForIcon(self, sel);
482 static UIImage *CachedImageAtPath(NSString *path) {
483 path = [path stringByResolvingSymlinksInPath];
484 UIImage *image = [PathImages_ objectForKey:path];
486 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
487 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
489 image = [image autorelease];
490 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
494 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
496 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
497 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
500 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
502 return __UIImageAtPath(name, nil);
504 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
505 UIImage *image = [PathImages_ objectForKey:key];
507 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
509 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
510 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
511 image = CachedImageAtPath(path);
513 image = __UIImageAtPath(name, bundle);
514 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
519 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
520 NSBundle *bundle = [NSBundle mainBundle];
522 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
523 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
524 return CachedImageAtPath(path);
525 return __UIApplicationImageWithName(name);
528 #define WBDelegate(delegate) \
529 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
531 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
532 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
534 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
538 - (void) forwardInvocation:(NSInvocation*)inv { \
539 SEL sel = [inv selector]; \
540 if ([delegate respondsToSelector:sel]) \
541 [inv invokeWithTarget:delegate]; \
543 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
546 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
547 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
549 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
550 if (NSString *path = $pathForFile$inBundle$(file, self, false))
552 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
555 void $setBarStyle$_(NSString *name, int &style) {
557 NSLog(@"WB:Debug:%@Style:%d", name, style);
558 NSNumber *number = nil;
560 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
562 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
564 style = [number intValue];
566 NSLog(@"WB:Debug:%@Style=%d", name, style);
570 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
571 NSBundle *bundle([NSBundle mainBundle]);
573 CFLocaleRef locale(CFLocaleCopyCurrent());
574 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
577 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
579 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
580 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
581 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
582 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
586 CFRelease(formatter);
588 NSString *datestyle(@""
589 "font-family: Helvetica; "
590 "font-weight: bold; "
596 NSString *daystyle(@""
597 "font-family: Helvetica; "
598 "font-weight: bold; "
601 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
604 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
605 datestyle = [datestyle stringByAppendingString:style];
606 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
607 daystyle = [daystyle stringByAppendingString:style];
609 float width([self bounds].size.width);
611 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
612 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
614 unsigned base($GSFontGetUseLegacyFontMetrics() ? 71 : 70);
616 [(NSString *)date drawAtPoint:CGPointMake(
617 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
618 ) withStyle:datestyle];
620 [(NSString *)day drawAtPoint:CGPointMake(
621 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
622 ) withStyle:daystyle];
628 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
631 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
632 style = [number intValue];
634 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
637 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
640 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
641 self = [self wb$initWithCoder:coder];
644 UINavigationBar$setBarStyle$_(self);
648 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
649 self = [self wb$initWithFrame:frame];
652 UINavigationBar$setBarStyle$_(self);
656 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
657 $setBarStyle$_(@"Toolbar", style);
658 return _UIToolbar$setBarStyle$(self, sel, style);
661 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
662 $setBarStyle$_(@"NavigationBar", style);
663 return _UINavigationBar$setBarStyle$(self, sel, style);
666 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
667 [[self superview] setBackgroundColor:[UIColor clearColor]];
668 _SBButtonBar$didMoveToSuperview(self, sel);
671 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
672 [[self superview] setBackgroundColor:[UIColor clearColor]];
673 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
676 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
678 NSLog(@"WB:Debug:DefaultDesktopImage");
679 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
680 return [UIImage imageWithContentsOfFile:path];
681 return _UIImage$defaultDesktopImage(self, sel);
684 static NSArray *Wallpapers_;
685 static NSString *WallpaperFile_;
686 static UIImageView *WallpaperImage_;
687 static UIWebDocumentView *WallpaperPage_;
688 static NSURL *WallpaperURL_;
690 #define _release(object) \
691 do if (object != nil) { \
696 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
697 self = _SBUIController$init(self, sel);
701 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
702 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
703 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
706 if (&_contentLayer != NULL)
707 layer = _contentLayer;
708 else if (&_contentView != NULL)
709 layer = _contentView;
713 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
714 [content setBackgroundColor:[layer backgroundColor]];
715 [layer setBackgroundColor:[UIColor clearColor]];
716 [layer setFrame:[content bounds]];
717 [_window setContentView:content];
719 _release(WallpaperFile_);
720 _release(WallpaperImage_);
721 _release(WallpaperPage_);
722 _release(WallpaperURL_);
724 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
725 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
726 if ([Manager_ fileExistsAtPath:mp4]) {
730 static AVController *controller_(nil);
731 if (controller_ == nil) {
732 AVQueue *queue([AVQueue avQueue]);
733 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
736 AVQueue *queue([controller_ queue]);
738 UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
739 [controller_ setLayer:[video _layer]];
741 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
742 [queue appendItem:item error:&error];
744 [controller_ play:&error];
745 #elif UseMPMoviePlayerController
746 NSURL *url([NSURL fileURLWithPath:mp4]);
747 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
748 controller.movieControlMode = MPMovieControlModeHidden;
751 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
752 [video setMovieWithPath:mp4];
753 [video setRepeatMode:1];
754 [video setRepeatGap:-1];
755 [video playFromBeginning];;
758 [content addSubview:video];
761 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
762 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
765 if ([Manager_ fileExistsAtPath:png])
767 else if ([Manager_ fileExistsAtPath:jpg])
773 image = [[UIImage alloc] initWithContentsOfFile:path];
775 image = [image autorelease];
779 WallpaperFile_ = [path retain];
780 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
781 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
782 [WallpaperImage_ setAlpha:[number floatValue]];
783 [content addSubview:WallpaperImage_];
786 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
787 if ([Manager_ fileExistsAtPath:html]) {
788 CGRect bounds = [content bounds];
790 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
791 [view setAutoresizes:true];
793 WallpaperPage_ = [view retain];
794 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
796 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
798 [view setBackgroundColor:[UIColor clearColor]];
799 if ([view respondsToSelector:@selector(setDrawsBackground:)])
800 [view setDrawsBackground:NO];
801 [[view webView] setDrawsBackground:NO];
803 [content addSubview:view];
807 for (size_t i(0), e([themes_ count]); i != e; ++i) {
808 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
809 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
810 if ([Manager_ fileExistsAtPath:html]) {
811 CGRect bounds = [content bounds];
813 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
814 [view setAutoresizes:true];
816 NSURL *url = [NSURL fileURLWithPath:html];
817 [view loadRequest:[NSURLRequest requestWithURL:url]];
819 [view setBackgroundColor:[UIColor clearColor]];
820 if ([view respondsToSelector:@selector(setDrawsBackground:)])
821 [view setDrawsBackground:NO];
822 [[view webView] setDrawsBackground:NO];
824 [content addSubview:view];
828 [content addSubview:layer];
833 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
834 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
835 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
837 if (path != nil && _backgroundView != nil)
840 _SBAwayView$updateDesktopImage$(self, sel, image);
843 CGRect bounds = [self bounds];
845 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
846 [view setAutoresizes:true];
848 if (WallpaperPage_ != nil)
849 [WallpaperPage_ release];
850 WallpaperPage_ = [view retain];
852 if (WallpaperURL_ != nil)
853 [WallpaperURL_ release];
854 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
856 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
858 [[view webView] setDrawsBackground:false];
859 [view setBackgroundColor:[UIColor clearColor]];
861 [self insertSubview:view aboveSubview:_backgroundView];
865 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
866 extern "C" CGColorRef CGGStateGetFillColor(void *);
867 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
868 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
870 /* WBTimeLabel {{{ */
871 @interface WBTimeLabel : NSProxy {
873 _transient SBStatusBarTimeView *view_;
876 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
880 @implementation WBTimeLabel
887 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
888 time_ = [time retain];
893 - (NSString *) description {
899 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
900 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
901 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
903 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
904 "font-family: Helvetica; "
905 "font-weight: bold; "
908 "%@", _mode ? @"white" : @"black", custom]];
913 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
918 /* WBBadgeLabel {{{ */
919 @interface WBBadgeLabel : NSProxy {
923 - (id) initWithBadge:(NSString *)badge;
924 - (NSString *) description;
928 @implementation WBBadgeLabel
935 - (id) initWithBadge:(NSString *)badge {
936 badge_ = [badge retain];
940 - (NSString *) description {
941 return [badge_ description];
946 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
947 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
948 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
949 "font-family: Helvetica; "
950 "font-weight: bold; "
958 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
964 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
965 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
966 alpha = [number floatValue];
967 return _SBIcon$setAlpha$(self, sel, alpha);
970 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
971 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
972 id &_badge(MSHookIvar<id>(self, "_badge"));
974 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
979 void SBStatusBarController$setStatusBarMode(int &mode) {
981 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
982 if (mode < 100) // 104:hidden 105:glowing
983 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
984 mode = [number intValue];
987 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
988 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
989 SBStatusBarController$setStatusBarMode(mode);
990 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
993 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
994 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
995 SBStatusBarController$setStatusBarMode(mode);
996 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
999 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) {
1000 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1001 SBStatusBarController$setStatusBarMode(mode);
1002 //NSLog(@"mode=%u", mode);
1003 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1006 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1007 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1008 mode = [number intValue];
1009 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1012 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1013 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1015 NSLog(@"operatorNameStyle= %@", style);
1016 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1017 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1021 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1023 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1024 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1027 // XXX: replace this with [SBStatusBarTimeView tile]
1028 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1029 id &_time(MSHookIvar<id>(self, "_time"));
1030 if (_time != nil && [_time class] != [WBTimeLabel class])
1031 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1032 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1035 @interface UIView (WinterBoard)
1036 - (bool) wb$isWBImageView;
1037 - (void) wb$logHierarchy;
1040 @implementation UIView (WinterBoard)
1042 - (bool) wb$isWBImageView {
1046 - (void) wb$logHierarchy {
1047 WBLogHierarchy(self);
1052 @interface WBImageView : UIImageView {
1055 - (bool) wb$isWBImageView;
1056 - (void) wb$updateFrame;
1059 @implementation WBImageView
1061 - (bool) wb$isWBImageView {
1065 - (void) wb$updateFrame {
1066 CGRect frame([self frame]);
1069 for (UIView *view(self); ; ) {
1070 view = [view superview];
1073 frame.origin.y -= [view frame].origin.y;
1076 [self setFrame:frame];
1081 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1082 NSArray *subviews([self subviews]);
1083 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1084 if (view != nil && [view wb$isWBImageView])
1085 [view wb$updateFrame];
1086 _SBIconList$setFrame$(self, sel, frame);
1089 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1090 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1091 NSArray *lists([_iconModel iconLists]);
1093 for (unsigned i(0), e([lists count]); i != e; ++i)
1094 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1095 SBIconList *list([lists objectAtIndex:i]);
1096 NSArray *subviews([list subviews]);
1098 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1099 if (view == nil || ![view wb$isWBImageView]) {
1100 view = [[[WBImageView alloc] init] autorelease];
1101 [list insertSubview:view atIndex:0];
1104 UIImage *image([UIImage imageWithContentsOfFile:path]);
1106 CGRect frame([view frame]);
1107 frame.size = [image size];
1108 [view setFrame:frame];
1110 [view setImage:image];
1111 [view wb$updateFrame];
1114 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1117 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1118 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1120 [self setClipsToBounds:NO];
1124 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1125 id &_label(MSHookIvar<id>(self, "_label"));
1126 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1128 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1129 [_label setInDock:docked];
1130 return _SBIconLabel$setInDock$(self, sel, docked);
1133 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1134 NSString *identifier = [self bundleIdentifier];
1135 NSLocale *locale = [NSLocale currentLocale];
1136 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1138 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1139 NSString *file = table == nil ? @"Localizable" : table;
1140 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1141 NSDictionary *strings;
1142 if ((strings = [Strings_ objectForKey:name]) != nil) {
1143 if (static_cast<id>(strings) != [NSNull null]) strings:
1144 if (NSString *value = [strings objectForKey:key])
1146 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1149 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1150 [Strings_ setObject:[strings autorelease] forKey:name];
1154 [Strings_ setObject:[NSNull null] forKey:name];
1155 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1158 @class WebCoreFrameBridge;
1159 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1162 void **core(reinterpret_cast<void **>([node _node]));
1163 if (core == NULL || core[6] == NULL)
1165 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1168 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1169 CGRect bounds = [self bounds];
1171 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1174 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1175 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1177 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1179 NSString *style = [NSString stringWithFormat:@""
1180 "font-family: Helvetica; "
1181 "font-weight: bold; "
1184 "", docked ? @"white" : @"#b3b3b3"];
1187 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1189 bool ellipsis(false);
1190 float max = 75, width;
1192 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1195 size_t length([label length]);
1196 float spacing((width - max) / (length - 1));
1198 if (spacing > 1.25) {
1200 label = [label substringToIndex:(length - 1)];
1204 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1208 label = [label stringByAppendingString:@"..."];
1210 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1211 style = [style stringByAppendingString:custom];
1213 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1214 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1217 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1218 _CKMessageCell$addBalloonView$(self, sel, balloon);
1219 [balloon setBackgroundColor:[UIColor clearColor]];
1222 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1223 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1224 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1228 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1229 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1230 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1231 [_label setBackgroundColor:[UIColor clearColor]];
1235 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1236 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1239 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1241 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1242 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1246 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1247 _TranscriptController$loadView(self, sel);
1249 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1250 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1251 [image autorelease];
1253 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1254 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1256 if (&_transcriptTable != NULL)
1257 table = _transcriptTable;
1258 else if (&_transcriptLayer != NULL)
1259 table = _transcriptLayer;
1263 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1264 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1267 [placard insertSubview:background atIndex:0];
1269 [table setBackgroundColor:[UIColor clearColor]];
1270 [placard insertSubview:background belowSubview:table];
1275 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1276 int id(_UISharedImageNameGetIdentifier(name));
1278 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1281 return _UIImageAtPath(name, _UIKitBundle());
1283 NSNumber *key([NSNumber numberWithInt:id]);
1284 UIImage *image = [UIImages_ objectForKey:key];
1286 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1287 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1288 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1290 [image autorelease];
1292 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1293 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1297 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1298 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1299 UIImage *image([PathImages_ objectForKey:key]);
1301 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1303 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1304 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1305 image = [[UIImage alloc] initWithContentsOfFile:path];
1307 [image autorelease];
1309 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1310 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1313 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1315 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1316 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1317 name = [font UTF8String];
1318 return _GSFontCreateWithName(name, traits, size);
1321 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1322 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1324 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1326 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1328 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1329 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1331 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1334 NSString *path = [NSString stringWithUTF8String:a1];
1335 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1336 NSString *file = [path substringFromIndex:31];
1337 for (NSString *theme in themes_) {
1338 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1339 if ([Manager_ fileExistsAtPath:path]) {
1340 strcpy(a1, [path UTF8String]);
1349 static void ChangeWallpaper(
1350 CFNotificationCenterRef center,
1354 CFDictionaryRef info
1357 NSLog(@"WB:Debug:ChangeWallpaper!");
1360 if (WallpaperFile_ != nil) {
1361 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1363 image = [image autorelease];
1366 if (WallpaperImage_ != nil)
1367 [WallpaperImage_ setImage:image];
1368 if (WallpaperPage_ != nil)
1369 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1373 #define WBRename(name, sel, imp) \
1374 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1376 template <typename Type_>
1377 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1378 struct nlist &name(nl[index]);
1379 uintptr_t value(name.n_value);
1380 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1381 value |= 0x00000001;
1382 function = reinterpret_cast<Type_>(value);
1385 template <typename Type_>
1386 static void dlset(Type_ &function, const char *name) {
1387 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1390 extern "C" void WBInitialize() {
1391 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1393 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1395 NSLog(@"WB:Notice: WinterBoard");
1397 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1401 memset(nl, 0, sizeof(nl));
1402 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1403 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1404 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1405 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1406 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1407 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1408 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1411 nlset(_UIApplicationImageWithName, nl, 0);
1412 nlset(_UIImageAtPath, nl, 1);
1413 nlset(_UIImageRefAtPath, nl, 2);
1414 nlset(_UIImageWithNameInDomain, nl, 3);
1415 nlset(_UIKitBundle, nl, 4);
1416 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1417 nlset(_UISharedImageWithIdentifier, nl, 6);
1419 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1420 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1421 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1422 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1424 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1426 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1428 memset(nl, 0, sizeof(nl));
1429 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1430 nlist(AudioToolbox, nl);
1431 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1432 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1435 $NSBundle = objc_getClass("NSBundle");
1437 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1438 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1440 $UIImage = objc_getClass("UIImage");
1441 $UINavigationBar = objc_getClass("UINavigationBar");
1442 $UIToolbar = objc_getClass("UIToolbar");
1444 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1446 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1447 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1449 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1450 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1452 Manager_ = [[NSFileManager defaultManager] retain];
1453 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1454 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1455 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1456 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1457 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1459 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1461 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1462 [settings autorelease];
1464 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1465 Debug_ = [debug boolValue];
1467 NSArray *themes = [settings objectForKey:@"Themes"];
1469 if (NSString *theme = [settings objectForKey:@"Theme"])
1470 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1472 [NSNumber numberWithBool:true], @"Active",
1475 for (NSDictionary *theme in themes) {
1476 NSNumber *active = [theme objectForKey:@"Active"];
1477 if (![active boolValue])
1480 NSString *name = [theme objectForKey:@"Name"];
1484 NSString *theme = nil;
1486 #define testForTheme(format...) \
1487 if (theme == nil) { \
1488 NSString *path = [NSString stringWithFormat:format]; \
1489 if ([Manager_ fileExistsAtPath:path]) { \
1490 [themes_ addObject:path]; \
1495 testForTheme(@"/Library/Themes/%@.theme", name)
1496 testForTheme(@"/Library/Themes/%@", name)
1497 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1501 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1503 for (NSString *theme in themes_)
1504 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
1506 for (NSString *key in [info allKeys])
1507 if ([Info_ objectForKey:key] == nil)
1508 [Info_ setObject:[info objectForKey:key] forKey:key];
1511 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1513 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1515 $CKMessageCell = objc_getClass("CKMessageCell");
1516 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1517 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1519 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1520 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1521 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1523 $CKTimestampView = objc_getClass("CKTimestampView");
1524 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1526 $CKTranscriptController = objc_getClass("CKTranscriptController");
1527 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1530 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1532 if (_TranscriptController$loadView == NULL) {
1533 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1534 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1537 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1538 CFNotificationCenterAddObserver(
1539 CFNotificationCenterGetDarwinNotifyCenter(),
1540 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1543 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1544 if (MediaPlayer != nil)
1547 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1548 $MPVideoView = objc_getClass("MPVideoView");
1549 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1551 $SBApplication = objc_getClass("SBApplication");
1552 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1553 $SBAwayView = objc_getClass("SBAwayView");
1554 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1555 $SBButtonBar = objc_getClass("SBButtonBar");
1556 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1557 $SBIcon = objc_getClass("SBIcon");
1558 $SBIconBadge = objc_getClass("SBIconBadge");
1559 $SBIconController = objc_getClass("SBIconController");
1560 $SBIconLabel = objc_getClass("SBIconLabel");
1561 $SBIconList = objc_getClass("SBIconList");
1562 $SBIconModel = objc_getClass("SBIconModel");
1563 //$SBImageCache = objc_getClass("SBImageCache");
1564 $SBSearchView = objc_getClass("SBSearchView");
1565 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1566 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1567 $SBStatusBarController = objc_getClass("SBStatusBarController");
1568 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1569 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1570 $SBUIController = objc_getClass("SBUIController");
1571 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1573 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1575 WBRename(SBApplication, pathForIcon, pathForIcon);
1576 WBRename(SBApplicationIcon, icon, icon);
1577 WBRename(SBBookmarkIcon, icon, icon);
1578 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1579 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1580 WBRename(SBIcon, setAlpha:, setAlpha$);
1581 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1582 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1583 WBRename(SBUIController, init, init);
1584 WBRename(SBWidgetApplicationIcon, icon, icon);
1586 WBRename(SBIconLabel, drawRect:, drawRect$);
1587 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1588 WBRename(SBIconLabel, setInDock:, setInDock$);
1590 WBRename(SBIconList, setFrame:, setFrame$);
1592 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1593 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1594 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1595 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1597 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1598 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1599 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1601 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1603 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1604 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1605 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1606 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1607 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1608 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1609 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1610 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1611 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1613 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1614 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1617 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1619 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1620 [Info_ setObject:[NSNumber numberWithBool:(
1621 $getTheme$(Wallpapers_) == nil ||
1622 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1623 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1624 )] forKey:@"UndockedIconLabels"];
1627 NSLog(@"WB:Debug:Info = %@", [Info_ description]);