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;
175 bool SummerBoard_ = true;
177 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
178 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
179 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
180 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
181 static NSBundle *(*_UIKitBundle)();
182 static int (*_UISharedImageNameGetIdentifier)(NSString *);
183 static UIImage *(*_UISharedImageWithIdentifier)(int);
185 static NSMutableDictionary *UIImages_;
186 static NSMutableDictionary *PathImages_;
187 static NSMutableDictionary *Cache_;
188 static NSMutableDictionary *Strings_;
189 static NSMutableDictionary *Themed_;
190 static NSMutableDictionary *Bundles_;
192 static NSFileManager *Manager_;
193 static NSDictionary *English_;
194 static NSMutableDictionary *Info_;
195 static NSMutableArray *themes_;
197 static NSString *$getTheme$(NSArray *files, bool parent = false) {
199 if (NSString *path = [Themed_ objectForKey:files])
200 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
203 NSLog(@"WB:Debug: %@", [files description]);
207 for (NSString *theme in themes_)
208 for (NSString *file in files) {
209 path = [NSString stringWithFormat:@"%@/%@", theme, file];
210 if ([Manager_ fileExistsAtPath:path]) {
211 path = parent ? theme : path;
219 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
223 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
224 NSString *identifier = [bundle bundleIdentifier];
225 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
227 if (identifier != nil)
228 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
229 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
230 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
232 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
234 #define remapResourceName(oldname, newname) \
235 else if ([file isEqualToString:oldname]) \
236 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
238 if (identifier == nil);
239 else if ([identifier isEqualToString:@"com.apple.chatkit"])
240 [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
241 else if ([identifier isEqualToString:@"com.apple.calculator"])
242 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
243 else if (![identifier isEqualToString:@"com.apple.springboard"] || !SummerBoard_);
244 remapResourceName(@"FSO_BG.png", @"StatusBar")
245 remapResourceName(@"SBDockBG.png", @"Dock")
246 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
248 if (NSString *path = $getTheme$(names))
253 static NSString *$pathForIcon$(SBApplication *self) {
254 NSString *identifier = [self bundleIdentifier];
255 NSString *path = [self path];
256 NSString *folder = [path lastPathComponent];
257 NSString *dname = [self displayName];
258 NSString *didentifier = [self displayIdentifier];
261 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
263 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
265 /* XXX: I might need to keep this for backwards compatibility
266 if (identifier != nil)
267 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
269 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */
271 #define testForIcon(Name) \
272 if (NSString *name = Name) \
273 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
275 if (![didentifier isEqualToString:identifier])
276 testForIcon(didentifier);
277 testForIcon(identifier);
280 if (didentifier != nil) {
281 testForIcon([English_ objectForKey:didentifier]);
283 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
284 if ([parts count] != 1)
285 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
286 testForIcon([english objectForKey:[parts lastObject]]);
289 if (NSString *path = $getTheme$(names))
294 @interface NSBundle (WinterBoard)
295 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
298 @implementation NSBundle (WinterBoard)
300 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
301 path = [path stringByDeletingLastPathComponent];
302 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
305 NSBundle *bundle([Bundles_ objectForKey:path]);
306 if (reinterpret_cast<id>(bundle) == [NSNull null])
308 else if (bundle == nil) {
309 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
310 bundle = [NSBundle bundleWithPath:path];
312 bundle = [NSBundle wb$bundleWithFile:path];
314 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
315 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
323 @interface NSString (WinterBoard)
324 - (NSString *) wb$themedPath;
327 @implementation NSString (WinterBoard)
329 - (NSString *) wb$themedPath {
331 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
333 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
334 NSString *file([self stringByResolvingSymlinksInPath]);
335 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
336 if ([file hasPrefix:prefix]) {
337 NSUInteger length([prefix length]);
338 if (length != [file length])
339 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
349 void WBLogRect(const char *tag, struct CGRect rect) {
350 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
353 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
354 CGRect frame([view frame]);
355 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]);
357 for (UIView *child in [view subviews])
358 WBLogHierarchy(child, index++, indent + 1);
361 UIImage *$cacheForImage$(UIImage *image) {
362 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
363 CGRect rect = {CGPointMake(1, 1), [image size]};
364 CGSize size = {rect.size.width + 2, rect.size.height + 2};
366 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
367 CGColorSpaceRelease(space);
369 CGContextDrawImage(context, rect, [image CGImage]);
370 CGImageRef ref(CGBitmapContextCreateImage(context));
371 CGContextRelease(context);
373 UIImage *cache([UIImage imageWithCGImage:ref]);
379 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
380 //if ([name isEqualToString:@"icons"]) return nil;
381 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
384 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
385 NSString *key([icon displayIdentifier]);
387 if (UIImage *image = [icon icon]) {
388 CGSize size = [image size];
389 if (size.width != 59 || size.height != 60) {
390 UIImage *cache($cacheForImage$(image));
391 [Cache_ setObject:cache forKey:key];
396 _SBIconModel$cacheImageForIcon$(self, sel, icon);
399 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
400 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
401 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
403 NSString *key([icon displayIdentifier]);
405 if (UIImage *image = [icon icon]) {
406 CGSize size = [image size];
407 if (size.width != 59 || size.height != 60) {
408 UIImage *cache($cacheForImage$(image));
409 [Cache_ setObject:cache forKey:key];
415 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
416 NSString *key([icon displayIdentifier]);
417 if (UIImage *image = [Cache_ objectForKey:key])
420 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
423 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
425 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
426 NSString *key([icon displayIdentifier]);
427 if (UIImage *image = [Cache_ objectForKey:key])
430 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
433 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
434 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
435 [self setBackgroundColor:[UIColor clearColor]];
436 for (UIView *child in [self subviews])
437 [child setBackgroundColor:[UIColor clearColor]];
441 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
442 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
443 [self setBackgroundColor:[UIColor clearColor]];
447 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
448 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
449 float inset([self edgeInset]);
450 [[UIColor clearColor] set];
451 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
452 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
455 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
456 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
457 if (NSString *path = $pathForIcon$([self application]))
458 return [UIImage imageWithContentsOfFile:path];
459 return _SBApplicationIcon$icon(self, sel);
462 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
464 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
465 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
466 return [UIImage imageWithContentsOfFile:path];
467 return _SBWidgetApplicationIcon$icon(self, sel);
470 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
472 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
473 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
474 return [UIImage imageWithContentsOfFile:path];
475 return _SBBookmarkIcon$icon(self, sel);
478 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
479 if (NSString *path = $pathForIcon$(self))
481 return _SBApplication$pathForIcon(self, sel);
484 static UIImage *CachedImageAtPath(NSString *path) {
485 path = [path stringByResolvingSymlinksInPath];
486 UIImage *image = [PathImages_ objectForKey:path];
488 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
489 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
491 image = [image autorelease];
492 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
496 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
498 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
499 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
502 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
504 return __UIImageAtPath(name, nil);
506 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
507 UIImage *image = [PathImages_ objectForKey:key];
509 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
511 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
512 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
513 image = CachedImageAtPath(path);
515 image = __UIImageAtPath(name, bundle);
516 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
521 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
522 NSBundle *bundle = [NSBundle mainBundle];
524 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
525 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
526 return CachedImageAtPath(path);
527 return __UIApplicationImageWithName(name);
530 #define WBDelegate(delegate) \
531 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
533 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
534 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
536 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
540 - (void) forwardInvocation:(NSInvocation*)inv { \
541 SEL sel = [inv selector]; \
542 if ([delegate respondsToSelector:sel]) \
543 [inv invokeWithTarget:delegate]; \
545 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
548 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
549 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
551 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
552 if (NSString *path = $pathForFile$inBundle$(file, self, false))
554 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
557 void $setBarStyle$_(NSString *name, int &style) {
559 NSLog(@"WB:Debug:%@Style:%d", name, style);
560 NSNumber *number = nil;
562 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
564 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
566 style = [number intValue];
568 NSLog(@"WB:Debug:%@Style=%d", name, style);
572 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
573 NSBundle *bundle([NSBundle mainBundle]);
575 CFLocaleRef locale(CFLocaleCopyCurrent());
576 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
579 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
581 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
582 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
583 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
584 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
588 CFRelease(formatter);
590 NSString *datestyle(@""
591 "font-family: Helvetica; "
592 "font-weight: bold; "
598 NSString *daystyle(@""
599 "font-family: Helvetica; "
600 "font-weight: bold; "
603 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
606 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
607 datestyle = [datestyle stringByAppendingString:style];
608 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
609 daystyle = [daystyle stringByAppendingString:style];
611 float width([self bounds].size.width);
613 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
614 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
616 unsigned base($GSFontGetUseLegacyFontMetrics() ? 71 : 70);
618 [(NSString *)date drawAtPoint:CGPointMake(
619 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
620 ) withStyle:datestyle];
622 [(NSString *)day drawAtPoint:CGPointMake(
623 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
624 ) withStyle:daystyle];
630 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
633 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
634 style = [number intValue];
636 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
639 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
642 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
643 self = [self wb$initWithCoder:coder];
646 UINavigationBar$setBarStyle$_(self);
650 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
651 self = [self wb$initWithFrame:frame];
654 UINavigationBar$setBarStyle$_(self);
658 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
659 $setBarStyle$_(@"Toolbar", style);
660 return _UIToolbar$setBarStyle$(self, sel, style);
663 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
664 $setBarStyle$_(@"NavigationBar", style);
665 return _UINavigationBar$setBarStyle$(self, sel, style);
668 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
669 [[self superview] setBackgroundColor:[UIColor clearColor]];
670 _SBButtonBar$didMoveToSuperview(self, sel);
673 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
674 [[self superview] setBackgroundColor:[UIColor clearColor]];
675 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
678 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
680 NSLog(@"WB:Debug:DefaultDesktopImage");
681 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
682 return [UIImage imageWithContentsOfFile:path];
683 return _UIImage$defaultDesktopImage(self, sel);
686 static NSArray *Wallpapers_;
687 static NSString *WallpaperFile_;
688 static UIImageView *WallpaperImage_;
689 static UIWebDocumentView *WallpaperPage_;
690 static NSURL *WallpaperURL_;
692 #define _release(object) \
693 do if (object != nil) { \
698 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
699 self = _SBUIController$init(self, sel);
703 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
704 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
705 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
708 if (&_contentLayer != NULL)
709 layer = _contentLayer;
710 else if (&_contentView != NULL)
711 layer = _contentView;
715 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
716 [content setBackgroundColor:[layer backgroundColor]];
717 [layer setBackgroundColor:[UIColor clearColor]];
718 [layer setFrame:[content bounds]];
719 [_window setContentView:content];
721 _release(WallpaperFile_);
722 _release(WallpaperImage_);
723 _release(WallpaperPage_);
724 _release(WallpaperURL_);
726 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
727 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
728 if ([Manager_ fileExistsAtPath:mp4]) {
732 static AVController *controller_(nil);
733 if (controller_ == nil) {
734 AVQueue *queue([AVQueue avQueue]);
735 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
738 AVQueue *queue([controller_ queue]);
740 UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
741 [controller_ setLayer:[video _layer]];
743 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
744 [queue appendItem:item error:&error];
746 [controller_ play:&error];
747 #elif UseMPMoviePlayerController
748 NSURL *url([NSURL fileURLWithPath:mp4]);
749 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
750 controller.movieControlMode = MPMovieControlModeHidden;
753 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
754 [video setMovieWithPath:mp4];
755 [video setRepeatMode:1];
756 [video setRepeatGap:-1];
757 [video playFromBeginning];;
760 [content addSubview:video];
763 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
764 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
767 if ([Manager_ fileExistsAtPath:png])
769 else if ([Manager_ fileExistsAtPath:jpg])
775 image = [[UIImage alloc] initWithContentsOfFile:path];
777 image = [image autorelease];
781 WallpaperFile_ = [path retain];
782 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
783 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
784 [WallpaperImage_ setAlpha:[number floatValue]];
785 [content addSubview:WallpaperImage_];
788 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
789 if ([Manager_ fileExistsAtPath:html]) {
790 CGRect bounds = [content bounds];
792 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
793 [view setAutoresizes:true];
795 WallpaperPage_ = [view retain];
796 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
798 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
800 [view setBackgroundColor:[UIColor clearColor]];
801 if ([view respondsToSelector:@selector(setDrawsBackground:)])
802 [view setDrawsBackground:NO];
803 [[view webView] setDrawsBackground:NO];
805 [content addSubview:view];
809 for (size_t i(0), e([themes_ count]); i != e; ++i) {
810 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
811 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
812 if ([Manager_ fileExistsAtPath:html]) {
813 CGRect bounds = [content bounds];
815 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
816 [view setAutoresizes:true];
818 NSURL *url = [NSURL fileURLWithPath:html];
819 [view loadRequest:[NSURLRequest requestWithURL:url]];
821 [view setBackgroundColor:[UIColor clearColor]];
822 if ([view respondsToSelector:@selector(setDrawsBackground:)])
823 [view setDrawsBackground:NO];
824 [[view webView] setDrawsBackground:NO];
826 [content addSubview:view];
830 [content addSubview:layer];
835 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
836 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
837 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
839 if (path != nil && _backgroundView != nil)
842 _SBAwayView$updateDesktopImage$(self, sel, image);
845 CGRect bounds = [self bounds];
847 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
848 [view setAutoresizes:true];
850 if (WallpaperPage_ != nil)
851 [WallpaperPage_ release];
852 WallpaperPage_ = [view retain];
854 if (WallpaperURL_ != nil)
855 [WallpaperURL_ release];
856 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
858 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
860 [[view webView] setDrawsBackground:false];
861 [view setBackgroundColor:[UIColor clearColor]];
863 [self insertSubview:view aboveSubview:_backgroundView];
867 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
868 extern "C" CGColorRef CGGStateGetFillColor(void *);
869 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
870 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
872 /* WBTimeLabel {{{ */
873 @interface WBTimeLabel : NSProxy {
875 _transient SBStatusBarTimeView *view_;
878 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
882 @implementation WBTimeLabel
889 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
890 time_ = [time retain];
895 - (NSString *) description {
901 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
902 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
903 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
905 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
906 "font-family: Helvetica; "
907 "font-weight: bold; "
910 "%@", _mode ? @"white" : @"black", custom]];
915 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
920 /* WBBadgeLabel {{{ */
921 @interface WBBadgeLabel : NSProxy {
925 - (id) initWithBadge:(NSString *)badge;
926 - (NSString *) description;
930 @implementation WBBadgeLabel
937 - (id) initWithBadge:(NSString *)badge {
938 badge_ = [badge retain];
942 - (NSString *) description {
943 return [badge_ description];
948 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
949 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
950 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
951 "font-family: Helvetica; "
952 "font-weight: bold; "
960 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
966 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
967 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
968 alpha = [number floatValue];
969 return _SBIcon$setAlpha$(self, sel, alpha);
972 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
973 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
974 id &_badge(MSHookIvar<id>(self, "_badge"));
976 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
981 void SBStatusBarController$setStatusBarMode(int &mode) {
983 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
984 if (mode < 100) // 104:hidden 105:glowing
985 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
986 mode = [number intValue];
989 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
990 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
991 SBStatusBarController$setStatusBarMode(mode);
992 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
995 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
996 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
997 SBStatusBarController$setStatusBarMode(mode);
998 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1001 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) {
1002 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1003 SBStatusBarController$setStatusBarMode(mode);
1004 //NSLog(@"mode=%u", mode);
1005 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1008 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1009 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1010 mode = [number intValue];
1011 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1014 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1015 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1017 NSLog(@"operatorNameStyle= %@", style);
1018 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1019 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1023 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1025 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1026 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1029 // XXX: replace this with [SBStatusBarTimeView tile]
1030 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1031 id &_time(MSHookIvar<id>(self, "_time"));
1032 if (_time != nil && [_time class] != [WBTimeLabel class])
1033 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1034 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1037 @interface UIView (WinterBoard)
1038 - (bool) wb$isWBImageView;
1039 - (void) wb$logHierarchy;
1042 @implementation UIView (WinterBoard)
1044 - (bool) wb$isWBImageView {
1048 - (void) wb$logHierarchy {
1049 WBLogHierarchy(self);
1054 @interface WBImageView : UIImageView {
1057 - (bool) wb$isWBImageView;
1058 - (void) wb$updateFrame;
1061 @implementation WBImageView
1063 - (bool) wb$isWBImageView {
1067 - (void) wb$updateFrame {
1068 CGRect frame([self frame]);
1071 for (UIView *view(self); ; ) {
1072 view = [view superview];
1075 frame.origin.y -= [view frame].origin.y;
1078 [self setFrame:frame];
1083 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1084 NSArray *subviews([self subviews]);
1085 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1086 if (view != nil && [view wb$isWBImageView])
1087 [view wb$updateFrame];
1088 _SBIconList$setFrame$(self, sel, frame);
1091 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1092 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1093 NSArray *lists([_iconModel iconLists]);
1095 for (unsigned i(0), e([lists count]); i != e; ++i)
1096 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1097 SBIconList *list([lists objectAtIndex:i]);
1098 NSArray *subviews([list subviews]);
1100 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1101 if (view == nil || ![view wb$isWBImageView]) {
1102 view = [[[WBImageView alloc] init] autorelease];
1103 [list insertSubview:view atIndex:0];
1106 UIImage *image([UIImage imageWithContentsOfFile:path]);
1108 CGRect frame([view frame]);
1109 frame.size = [image size];
1110 [view setFrame:frame];
1112 [view setImage:image];
1113 [view wb$updateFrame];
1116 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1119 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1120 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1122 [self setClipsToBounds:NO];
1126 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1127 id &_label(MSHookIvar<id>(self, "_label"));
1128 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1130 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1131 [_label setInDock:docked];
1132 return _SBIconLabel$setInDock$(self, sel, docked);
1135 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1136 NSString *identifier = [self bundleIdentifier];
1137 NSLocale *locale = [NSLocale currentLocale];
1138 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1140 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1141 NSString *file = table == nil ? @"Localizable" : table;
1142 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1143 NSDictionary *strings;
1144 if ((strings = [Strings_ objectForKey:name]) != nil) {
1145 if (static_cast<id>(strings) != [NSNull null]) strings:
1146 if (NSString *value = [strings objectForKey:key])
1148 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1151 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1152 [Strings_ setObject:[strings autorelease] forKey:name];
1156 [Strings_ setObject:[NSNull null] forKey:name];
1157 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1160 @class WebCoreFrameBridge;
1161 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1164 void **core(reinterpret_cast<void **>([node _node]));
1165 if (core == NULL || core[6] == NULL)
1167 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1170 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1171 CGRect bounds = [self bounds];
1173 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1176 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1177 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1179 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1181 NSString *style = [NSString stringWithFormat:@""
1182 "font-family: Helvetica; "
1183 "font-weight: bold; "
1186 "", docked ? @"white" : @"#b3b3b3"];
1189 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1191 bool ellipsis(false);
1192 float max = 75, width;
1194 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1197 size_t length([label length]);
1198 float spacing((width - max) / (length - 1));
1200 if (spacing > 1.25) {
1202 label = [label substringToIndex:(length - 1)];
1206 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1210 label = [label stringByAppendingString:@"..."];
1212 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1213 style = [style stringByAppendingString:custom];
1215 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1216 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1219 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1220 _CKMessageCell$addBalloonView$(self, sel, balloon);
1221 [balloon setBackgroundColor:[UIColor clearColor]];
1224 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1225 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1226 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1230 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1231 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1232 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1233 [_label setBackgroundColor:[UIColor clearColor]];
1237 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1238 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1241 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1243 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1244 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1248 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1249 _TranscriptController$loadView(self, sel);
1251 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1252 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1253 [image autorelease];
1255 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1256 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1258 if (&_transcriptTable != NULL)
1259 table = _transcriptTable;
1260 else if (&_transcriptLayer != NULL)
1261 table = _transcriptLayer;
1265 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1266 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1269 [placard insertSubview:background atIndex:0];
1271 [table setBackgroundColor:[UIColor clearColor]];
1272 [placard insertSubview:background belowSubview:table];
1277 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1278 int id(_UISharedImageNameGetIdentifier(name));
1280 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1283 return _UIImageAtPath(name, _UIKitBundle());
1285 NSNumber *key([NSNumber numberWithInt:id]);
1286 UIImage *image = [UIImages_ objectForKey:key];
1288 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1289 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1290 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1292 [image autorelease];
1294 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1295 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1299 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1300 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1301 UIImage *image([PathImages_ objectForKey:key]);
1303 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1305 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1306 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1307 image = [[UIImage alloc] initWithContentsOfFile:path];
1309 [image autorelease];
1311 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1312 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1315 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1317 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1318 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1319 name = [font UTF8String];
1320 return _GSFontCreateWithName(name, traits, size);
1323 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1324 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1326 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1328 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1330 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1331 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1333 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1336 NSString *path = [NSString stringWithUTF8String:a1];
1337 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1338 NSString *file = [path substringFromIndex:31];
1339 for (NSString *theme in themes_) {
1340 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1341 if ([Manager_ fileExistsAtPath:path]) {
1342 strcpy(a1, [path UTF8String]);
1351 static void ChangeWallpaper(
1352 CFNotificationCenterRef center,
1356 CFDictionaryRef info
1359 NSLog(@"WB:Debug:ChangeWallpaper!");
1362 if (WallpaperFile_ != nil) {
1363 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1365 image = [image autorelease];
1368 if (WallpaperImage_ != nil)
1369 [WallpaperImage_ setImage:image];
1370 if (WallpaperPage_ != nil)
1371 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1375 #define WBRename(name, sel, imp) \
1376 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1378 template <typename Type_>
1379 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1380 struct nlist &name(nl[index]);
1381 uintptr_t value(name.n_value);
1382 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1383 value |= 0x00000001;
1384 function = reinterpret_cast<Type_>(value);
1387 template <typename Type_>
1388 static void dlset(Type_ &function, const char *name) {
1389 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1392 extern "C" void WBInitialize() {
1393 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1395 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1397 NSLog(@"WB:Notice: WinterBoard");
1399 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1403 memset(nl, 0, sizeof(nl));
1404 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1405 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1406 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1407 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1408 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1409 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1410 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1413 nlset(_UIApplicationImageWithName, nl, 0);
1414 nlset(_UIImageAtPath, nl, 1);
1415 nlset(_UIImageRefAtPath, nl, 2);
1416 nlset(_UIImageWithNameInDomain, nl, 3);
1417 nlset(_UIKitBundle, nl, 4);
1418 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1419 nlset(_UISharedImageWithIdentifier, nl, 6);
1421 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1422 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1423 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1424 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1426 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1428 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1430 memset(nl, 0, sizeof(nl));
1431 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1432 nlist(AudioToolbox, nl);
1433 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1434 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1437 $NSBundle = objc_getClass("NSBundle");
1439 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1440 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1442 $UIImage = objc_getClass("UIImage");
1443 $UINavigationBar = objc_getClass("UINavigationBar");
1444 $UIToolbar = objc_getClass("UIToolbar");
1446 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1448 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1449 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1451 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1452 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1454 Manager_ = [[NSFileManager defaultManager] retain];
1455 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1456 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1457 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1458 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1459 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1461 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1463 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1464 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1465 SummerBoard_ = [value boolValue];
1466 if (NSNumber *value = [settings objectForKey:@"Debug"])
1467 Debug_ = [value boolValue];
1469 NSArray *themes([settings objectForKey:@"Themes"]);
1471 if (NSString *theme = [settings objectForKey:@"Theme"])
1472 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1474 [NSNumber numberWithBool:true], @"Active",
1478 for (NSDictionary *theme in themes) {
1479 NSNumber *active([theme objectForKey:@"Active"]);
1480 if (![active boolValue])
1483 NSString *name([theme objectForKey:@"Name"]);
1487 NSString *theme(nil);
1489 #define testForTheme(format...) \
1490 if (theme == nil) { \
1491 NSString *path = [NSString stringWithFormat:format]; \
1492 if ([Manager_ fileExistsAtPath:path]) { \
1493 [themes_ addObject:path]; \
1498 testForTheme(@"/Library/Themes/%@.theme", name)
1499 testForTheme(@"/Library/Themes/%@", name)
1500 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1505 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1507 for (NSString *theme in themes_)
1508 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1509 for (NSString *key in [info allKeys])
1510 if ([Info_ objectForKey:key] == nil)
1511 [Info_ setObject:[info objectForKey:key] forKey:key];
1513 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1515 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1517 $CKMessageCell = objc_getClass("CKMessageCell");
1518 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1519 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1521 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1522 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1523 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1525 $CKTimestampView = objc_getClass("CKTimestampView");
1526 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1528 $CKTranscriptController = objc_getClass("CKTranscriptController");
1529 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1532 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1534 if (_TranscriptController$loadView == NULL) {
1535 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1536 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1539 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1540 CFNotificationCenterAddObserver(
1541 CFNotificationCenterGetDarwinNotifyCenter(),
1542 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1546 if ($getTheme$([NSArray arrayWithObjects:@"Wallpaper.mp4"]) != nil) {
1547 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1548 if (MediaPlayer != nil)
1551 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1552 $MPVideoView = objc_getClass("MPVideoView");
1555 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1557 $SBApplication = objc_getClass("SBApplication");
1558 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1559 $SBAwayView = objc_getClass("SBAwayView");
1560 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1561 $SBButtonBar = objc_getClass("SBButtonBar");
1562 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1563 $SBIcon = objc_getClass("SBIcon");
1564 $SBIconBadge = objc_getClass("SBIconBadge");
1565 $SBIconController = objc_getClass("SBIconController");
1566 $SBIconLabel = objc_getClass("SBIconLabel");
1567 $SBIconList = objc_getClass("SBIconList");
1568 $SBIconModel = objc_getClass("SBIconModel");
1569 //$SBImageCache = objc_getClass("SBImageCache");
1570 $SBSearchView = objc_getClass("SBSearchView");
1571 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1572 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1573 $SBStatusBarController = objc_getClass("SBStatusBarController");
1574 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1575 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1576 $SBUIController = objc_getClass("SBUIController");
1577 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1579 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1582 WBRename(SBApplication, pathForIcon, pathForIcon);
1583 WBRename(SBApplicationIcon, icon, icon);
1586 WBRename(SBBookmarkIcon, icon, icon);
1587 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1588 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1589 WBRename(SBIcon, setAlpha:, setAlpha$);
1590 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1591 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1592 WBRename(SBUIController, init, init);
1593 WBRename(SBWidgetApplicationIcon, icon, icon);
1595 WBRename(SBIconLabel, drawRect:, drawRect$);
1596 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1597 WBRename(SBIconLabel, setInDock:, setInDock$);
1599 WBRename(SBIconList, setFrame:, setFrame$);
1601 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1602 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1603 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1604 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1606 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1607 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1608 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1610 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1612 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1613 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1614 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1615 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1616 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1617 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1618 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1619 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1620 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1622 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1623 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1626 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1628 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1629 [Info_ setObject:[NSNumber numberWithBool:(
1630 $getTheme$(Wallpapers_) == nil ||
1631 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1632 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1633 )] forKey:@"UndockedIconLabels"];
1636 NSLog(@"WB:Debug:Info = %@", [Info_ description]);