1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008-2009 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 testForIcon(identifier);
276 if (didentifier != nil) {
277 testForIcon([English_ objectForKey:didentifier]);
279 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
280 if ([parts count] != 1)
281 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
282 testForIcon([english objectForKey:[parts lastObject]]);
285 if (NSString *path = $getTheme$(names))
290 @interface NSBundle (WinterBoard)
291 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
294 @implementation NSBundle (WinterBoard)
296 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
297 path = [path stringByDeletingLastPathComponent];
298 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
301 NSBundle *bundle([Bundles_ objectForKey:path]);
302 if (reinterpret_cast<id>(bundle) == [NSNull null])
304 else if (bundle == nil) {
305 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
306 bundle = [NSBundle bundleWithPath:path];
308 bundle = [NSBundle wb$bundleWithFile:path];
310 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
311 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
319 @interface NSString (WinterBoard)
320 - (NSString *) wb$themedPath;
323 @implementation NSString (WinterBoard)
325 - (NSString *) wb$themedPath {
327 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
329 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
330 NSString *file([self stringByResolvingSymlinksInPath]);
331 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
332 if ([file hasPrefix:prefix]) {
333 NSUInteger length([prefix length]);
334 if (length != [file length])
335 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
345 void WBLogRect(const char *tag, struct CGRect rect) {
346 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
349 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
350 CGRect frame([view frame]);
351 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]);
353 for (UIView *child in [view subviews])
354 WBLogHierarchy(child, index++, indent + 1);
357 UIImage *$cacheForImage$(UIImage *image) {
358 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
359 CGRect rect = {CGPointMake(1, 1), [image size]};
360 CGSize size = {rect.size.width + 2, rect.size.height + 2};
362 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
363 CGColorSpaceRelease(space);
365 CGContextDrawImage(context, rect, [image CGImage]);
366 CGImageRef ref(CGBitmapContextCreateImage(context));
367 CGContextRelease(context);
369 UIImage *cache([UIImage imageWithCGImage:ref]);
375 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
376 //if ([name isEqualToString:@"icons"]) return nil;
377 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
380 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
381 NSString *key([icon displayIdentifier]);
383 if (UIImage *image = [icon icon]) {
384 CGSize size = [image size];
385 if (size.width != 59 || size.height != 60) {
386 UIImage *cache($cacheForImage$(image));
387 [Cache_ setObject:cache forKey:key];
392 _SBIconModel$cacheImageForIcon$(self, sel, icon);
395 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
396 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
397 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
399 NSString *key([icon displayIdentifier]);
401 if (UIImage *image = [icon icon]) {
402 CGSize size = [image size];
403 if (size.width != 59 || size.height != 60) {
404 UIImage *cache($cacheForImage$(image));
405 [Cache_ setObject:cache forKey:key];
411 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
412 NSString *key([icon displayIdentifier]);
413 if (UIImage *image = [Cache_ objectForKey:key])
416 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
419 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
421 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
422 NSString *key([icon displayIdentifier]);
423 if (UIImage *image = [Cache_ objectForKey:key])
426 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
429 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
430 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
431 [self setBackgroundColor:[UIColor clearColor]];
432 for (UIView *child in [self subviews])
433 [child setBackgroundColor:[UIColor clearColor]];
437 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
438 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
439 [self setBackgroundColor:[UIColor clearColor]];
443 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
444 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
445 float inset([self edgeInset]);
446 [[UIColor clearColor] set];
447 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
448 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
451 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
452 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
453 if (NSString *path = $pathForIcon$([self application]))
454 return [UIImage imageWithContentsOfFile:path];
455 return _SBApplicationIcon$icon(self, sel);
458 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
460 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
461 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
462 return [UIImage imageWithContentsOfFile:path];
463 return _SBWidgetApplicationIcon$icon(self, sel);
466 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
468 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
469 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
470 return [UIImage imageWithContentsOfFile:path];
471 return _SBBookmarkIcon$icon(self, sel);
474 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
475 if (NSString *path = $pathForIcon$(self))
477 return _SBApplication$pathForIcon(self, sel);
480 static UIImage *CachedImageAtPath(NSString *path) {
481 path = [path stringByResolvingSymlinksInPath];
482 UIImage *image = [PathImages_ objectForKey:path];
484 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
485 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
487 image = [image autorelease];
488 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
492 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
494 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
495 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
498 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
500 return __UIImageAtPath(name, nil);
502 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
503 UIImage *image = [PathImages_ objectForKey:key];
505 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
507 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
508 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
509 image = CachedImageAtPath(path);
511 image = __UIImageAtPath(name, bundle);
512 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
517 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
518 NSBundle *bundle = [NSBundle mainBundle];
520 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
521 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
522 return CachedImageAtPath(path);
523 return __UIApplicationImageWithName(name);
526 #define WBDelegate(delegate) \
527 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
529 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
530 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
532 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
536 - (void) forwardInvocation:(NSInvocation*)inv { \
537 SEL sel = [inv selector]; \
538 if ([delegate respondsToSelector:sel]) \
539 [inv invokeWithTarget:delegate]; \
541 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
544 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
545 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
547 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
548 if (NSString *path = $pathForFile$inBundle$(file, self, false))
550 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
553 void $setBarStyle$_(NSString *name, int &style) {
555 NSLog(@"WB:Debug:%@Style:%d", name, style);
556 NSNumber *number = nil;
558 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
560 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
562 style = [number intValue];
564 NSLog(@"WB:Debug:%@Style=%d", name, style);
568 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
569 NSBundle *bundle([NSBundle mainBundle]);
571 CFLocaleRef locale(CFLocaleCopyCurrent());
572 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
575 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
577 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
578 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
579 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
580 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
584 CFRelease(formatter);
586 NSString *datestyle(@""
587 "font-family: Helvetica; "
588 "font-weight: bold; "
594 NSString *daystyle(@""
595 "font-family: Helvetica; "
596 "font-weight: bold; "
599 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
602 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
603 datestyle = [datestyle stringByAppendingString:style];
604 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
605 daystyle = [daystyle stringByAppendingString:style];
607 float width([self bounds].size.width);
609 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
610 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
612 unsigned base($GSFontGetUseLegacyFontMetrics() ? 71 : 70);
614 [(NSString *)date drawAtPoint:CGPointMake(
615 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
616 ) withStyle:datestyle];
618 [(NSString *)day drawAtPoint:CGPointMake(
619 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
620 ) withStyle:daystyle];
626 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
629 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
630 style = [number intValue];
632 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
635 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
638 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
639 self = [self wb$initWithCoder:coder];
642 UINavigationBar$setBarStyle$_(self);
646 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
647 self = [self wb$initWithFrame:frame];
650 UINavigationBar$setBarStyle$_(self);
654 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
655 $setBarStyle$_(@"Toolbar", style);
656 return _UIToolbar$setBarStyle$(self, sel, style);
659 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
660 $setBarStyle$_(@"NavigationBar", style);
661 return _UINavigationBar$setBarStyle$(self, sel, style);
664 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
665 [[self superview] setBackgroundColor:[UIColor clearColor]];
666 _SBButtonBar$didMoveToSuperview(self, sel);
669 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
670 [[self superview] setBackgroundColor:[UIColor clearColor]];
671 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
674 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
676 NSLog(@"WB:Debug:DefaultDesktopImage");
677 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
678 return [UIImage imageWithContentsOfFile:path];
679 return _UIImage$defaultDesktopImage(self, sel);
682 static NSArray *Wallpapers_;
683 static NSString *WallpaperFile_;
684 static UIImageView *WallpaperImage_;
685 static UIWebDocumentView *WallpaperPage_;
686 static NSURL *WallpaperURL_;
688 #define _release(object) \
689 do if (object != nil) { \
694 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
695 self = _SBUIController$init(self, sel);
699 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
700 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
701 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
704 if (&_contentLayer != NULL)
705 layer = _contentLayer;
706 else if (&_contentView != NULL)
707 layer = _contentView;
711 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
712 [content setBackgroundColor:[layer backgroundColor]];
713 [layer setBackgroundColor:[UIColor clearColor]];
714 [layer setFrame:[content bounds]];
715 [_window setContentView:content];
717 _release(WallpaperFile_);
718 _release(WallpaperImage_);
719 _release(WallpaperPage_);
720 _release(WallpaperURL_);
722 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
723 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
724 if ([Manager_ fileExistsAtPath:mp4]) {
728 static AVController *controller_(nil);
729 if (controller_ == nil) {
730 AVQueue *queue([AVQueue avQueue]);
731 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
734 AVQueue *queue([controller_ queue]);
736 UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
737 [controller_ setLayer:[video _layer]];
739 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
740 [queue appendItem:item error:&error];
742 [controller_ play:&error];
743 #elif UseMPMoviePlayerController
744 NSURL *url([NSURL fileURLWithPath:mp4]);
745 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
746 controller.movieControlMode = MPMovieControlModeHidden;
749 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
750 [video setMovieWithPath:mp4];
751 [video setRepeatMode:1];
752 [video setRepeatGap:-1];
753 [video playFromBeginning];;
756 [content addSubview:video];
759 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
760 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
763 if ([Manager_ fileExistsAtPath:png])
765 else if ([Manager_ fileExistsAtPath:jpg])
771 image = [[UIImage alloc] initWithContentsOfFile:path];
773 image = [image autorelease];
777 WallpaperFile_ = [path retain];
778 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
779 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
780 [WallpaperImage_ setAlpha:[number floatValue]];
781 [content addSubview:WallpaperImage_];
784 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
785 if ([Manager_ fileExistsAtPath:html]) {
786 CGRect bounds = [content bounds];
788 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
789 [view setAutoresizes:true];
791 WallpaperPage_ = [view retain];
792 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
794 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
796 [view setBackgroundColor:[UIColor clearColor]];
797 if ([view respondsToSelector:@selector(setDrawsBackground:)])
798 [view setDrawsBackground:NO];
799 [[view webView] setDrawsBackground:NO];
801 [content addSubview:view];
805 for (size_t i(0), e([themes_ count]); i != e; ++i) {
806 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
807 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
808 if ([Manager_ fileExistsAtPath:html]) {
809 CGRect bounds = [content bounds];
811 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
812 [view setAutoresizes:true];
814 NSURL *url = [NSURL fileURLWithPath:html];
815 [view loadRequest:[NSURLRequest requestWithURL:url]];
817 [view setBackgroundColor:[UIColor clearColor]];
818 if ([view respondsToSelector:@selector(setDrawsBackground:)])
819 [view setDrawsBackground:NO];
820 [[view webView] setDrawsBackground:NO];
822 [content addSubview:view];
826 [content addSubview:layer];
831 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
832 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
833 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
835 if (path != nil && _backgroundView != nil)
838 _SBAwayView$updateDesktopImage$(self, sel, image);
841 CGRect bounds = [self bounds];
843 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
844 [view setAutoresizes:true];
846 if (WallpaperPage_ != nil)
847 [WallpaperPage_ release];
848 WallpaperPage_ = [view retain];
850 if (WallpaperURL_ != nil)
851 [WallpaperURL_ release];
852 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
854 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
856 [[view webView] setDrawsBackground:false];
857 [view setBackgroundColor:[UIColor clearColor]];
859 [self insertSubview:view aboveSubview:_backgroundView];
863 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
864 extern "C" CGColorRef CGGStateGetFillColor(void *);
865 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
866 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
868 /* WBTimeLabel {{{ */
869 @interface WBTimeLabel : NSProxy {
871 _transient SBStatusBarTimeView *view_;
874 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
878 @implementation WBTimeLabel
885 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
886 time_ = [time retain];
891 - (NSString *) description {
897 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
898 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
899 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
901 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
902 "font-family: Helvetica; "
903 "font-weight: bold; "
906 "%@", _mode ? @"white" : @"black", custom]];
911 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
916 /* WBBadgeLabel {{{ */
917 @interface WBBadgeLabel : NSProxy {
921 - (id) initWithBadge:(NSString *)badge;
922 - (NSString *) description;
926 @implementation WBBadgeLabel
933 - (id) initWithBadge:(NSString *)badge {
934 badge_ = [badge retain];
938 - (NSString *) description {
939 return [badge_ description];
944 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
945 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
946 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
947 "font-family: Helvetica; "
948 "font-weight: bold; "
956 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
962 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
963 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
964 alpha = [number floatValue];
965 return _SBIcon$setAlpha$(self, sel, alpha);
968 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
969 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
970 id &_badge(MSHookIvar<id>(self, "_badge"));
972 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
977 void SBStatusBarController$setStatusBarMode(int &mode) {
979 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
980 if (mode < 100) // 104:hidden 105:glowing
981 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
982 mode = [number intValue];
985 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
986 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
987 SBStatusBarController$setStatusBarMode(mode);
988 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
991 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
992 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
993 SBStatusBarController$setStatusBarMode(mode);
994 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
997 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) {
998 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
999 SBStatusBarController$setStatusBarMode(mode);
1000 //NSLog(@"mode=%u", mode);
1001 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1004 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1005 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1006 mode = [number intValue];
1007 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1010 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1011 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1013 NSLog(@"operatorNameStyle= %@", style);
1014 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1015 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1019 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1021 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1022 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1025 // XXX: replace this with [SBStatusBarTimeView tile]
1026 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1027 id &_time(MSHookIvar<id>(self, "_time"));
1028 if (_time != nil && [_time class] != [WBTimeLabel class])
1029 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1030 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1033 @interface UIView (WinterBoard)
1034 - (bool) wb$isWBImageView;
1035 - (void) wb$logHierarchy;
1038 @implementation UIView (WinterBoard)
1040 - (bool) wb$isWBImageView {
1044 - (void) wb$logHierarchy {
1045 WBLogHierarchy(self);
1050 @interface WBImageView : UIImageView {
1053 - (bool) wb$isWBImageView;
1054 - (void) wb$updateFrame;
1057 @implementation WBImageView
1059 - (bool) wb$isWBImageView {
1063 - (void) wb$updateFrame {
1064 CGRect frame([self frame]);
1067 for (UIView *view(self); ; ) {
1068 view = [view superview];
1071 frame.origin.y -= [view frame].origin.y;
1074 [self setFrame:frame];
1079 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1080 NSArray *subviews([self subviews]);
1081 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1082 if (view != nil && [view wb$isWBImageView])
1083 [view wb$updateFrame];
1084 _SBIconList$setFrame$(self, sel, frame);
1087 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1088 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1089 NSArray *lists([_iconModel iconLists]);
1091 for (unsigned i(0), e([lists count]); i != e; ++i)
1092 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1093 SBIconList *list([lists objectAtIndex:i]);
1094 NSArray *subviews([list subviews]);
1096 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1097 if (view == nil || ![view wb$isWBImageView]) {
1098 view = [[[WBImageView alloc] init] autorelease];
1099 [list insertSubview:view atIndex:0];
1102 UIImage *image([UIImage imageWithContentsOfFile:path]);
1104 CGRect frame([view frame]);
1105 frame.size = [image size];
1106 [view setFrame:frame];
1108 [view setImage:image];
1109 [view wb$updateFrame];
1112 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1115 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1116 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1118 [self setClipsToBounds:NO];
1122 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1123 id &_label(MSHookIvar<id>(self, "_label"));
1124 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1126 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1127 [_label setInDock:docked];
1128 return _SBIconLabel$setInDock$(self, sel, docked);
1131 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1132 NSString *identifier = [self bundleIdentifier];
1133 NSLocale *locale = [NSLocale currentLocale];
1134 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1136 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1137 NSString *file = table == nil ? @"Localizable" : table;
1138 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1139 NSDictionary *strings;
1140 if ((strings = [Strings_ objectForKey:name]) != nil) {
1141 if (static_cast<id>(strings) != [NSNull null]) strings:
1142 if (NSString *value = [strings objectForKey:key])
1144 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1147 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1148 [Strings_ setObject:[strings autorelease] forKey:name];
1152 [Strings_ setObject:[NSNull null] forKey:name];
1153 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1156 @class WebCoreFrameBridge;
1157 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1160 void **core(reinterpret_cast<void **>([node _node]));
1161 if (core == NULL || core[6] == NULL)
1163 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1166 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1167 CGRect bounds = [self bounds];
1169 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1172 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1173 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1175 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1177 NSString *style = [NSString stringWithFormat:@""
1178 "font-family: Helvetica; "
1179 "font-weight: bold; "
1182 "", docked ? @"white" : @"#b3b3b3"];
1185 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1187 bool ellipsis(false);
1188 float max = 75, width;
1190 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1193 size_t length([label length]);
1194 float spacing((width - max) / (length - 1));
1196 if (spacing > 1.25) {
1198 label = [label substringToIndex:(length - 1)];
1202 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1206 label = [label stringByAppendingString:@"..."];
1208 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1209 style = [style stringByAppendingString:custom];
1211 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1212 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1215 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1216 _CKMessageCell$addBalloonView$(self, sel, balloon);
1217 [balloon setBackgroundColor:[UIColor clearColor]];
1220 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1221 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1222 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1226 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1227 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1228 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1229 [_label setBackgroundColor:[UIColor clearColor]];
1233 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1234 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1237 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1239 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1240 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1244 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1245 _TranscriptController$loadView(self, sel);
1247 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1248 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1249 [image autorelease];
1251 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1252 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1254 if (&_transcriptTable != NULL)
1255 table = _transcriptTable;
1256 else if (&_transcriptLayer != NULL)
1257 table = _transcriptLayer;
1261 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1262 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1265 [placard insertSubview:background atIndex:0];
1267 [table setBackgroundColor:[UIColor clearColor]];
1268 [placard insertSubview:background belowSubview:table];
1273 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1274 int id(_UISharedImageNameGetIdentifier(name));
1276 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1279 return _UIImageAtPath(name, _UIKitBundle());
1281 NSNumber *key([NSNumber numberWithInt:id]);
1282 UIImage *image = [UIImages_ objectForKey:key];
1284 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1285 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1286 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1288 [image autorelease];
1290 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1291 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1295 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1296 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1297 UIImage *image([PathImages_ objectForKey:key]);
1299 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1301 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1302 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1303 image = [[UIImage alloc] initWithContentsOfFile:path];
1305 [image autorelease];
1307 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1308 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1311 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1313 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1314 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1315 name = [font UTF8String];
1316 return _GSFontCreateWithName(name, traits, size);
1319 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1320 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1322 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1324 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1326 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1327 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1329 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1332 NSString *path = [NSString stringWithUTF8String:a1];
1333 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1334 NSString *file = [path substringFromIndex:31];
1335 for (NSString *theme in themes_) {
1336 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1337 if ([Manager_ fileExistsAtPath:path]) {
1338 strcpy(a1, [path UTF8String]);
1347 static void ChangeWallpaper(
1348 CFNotificationCenterRef center,
1352 CFDictionaryRef info
1355 NSLog(@"WB:Debug:ChangeWallpaper!");
1358 if (WallpaperFile_ != nil) {
1359 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1361 image = [image autorelease];
1364 if (WallpaperImage_ != nil)
1365 [WallpaperImage_ setImage:image];
1366 if (WallpaperPage_ != nil)
1367 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1371 #define WBRename(name, sel, imp) \
1372 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1374 template <typename Type_>
1375 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1376 struct nlist &name(nl[index]);
1377 uintptr_t value(name.n_value);
1378 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1379 value |= 0x00000001;
1380 function = reinterpret_cast<Type_>(value);
1383 template <typename Type_>
1384 static void dlset(Type_ &function, const char *name) {
1385 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1388 extern "C" void WBInitialize() {
1389 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1391 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1393 NSLog(@"WB:Notice: WinterBoard");
1395 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1399 memset(nl, 0, sizeof(nl));
1400 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1401 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1402 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1403 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1404 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1405 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1406 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1409 nlset(_UIApplicationImageWithName, nl, 0);
1410 nlset(_UIImageAtPath, nl, 1);
1411 nlset(_UIImageRefAtPath, nl, 2);
1412 nlset(_UIImageWithNameInDomain, nl, 3);
1413 nlset(_UIKitBundle, nl, 4);
1414 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1415 nlset(_UISharedImageWithIdentifier, nl, 6);
1417 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1418 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1419 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1420 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1422 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1424 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1426 memset(nl, 0, sizeof(nl));
1427 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1428 nlist(AudioToolbox, nl);
1429 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1430 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1433 $NSBundle = objc_getClass("NSBundle");
1435 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1436 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1438 $UIImage = objc_getClass("UIImage");
1439 $UINavigationBar = objc_getClass("UINavigationBar");
1440 $UIToolbar = objc_getClass("UIToolbar");
1442 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1444 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1445 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1447 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1448 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1450 Manager_ = [[NSFileManager defaultManager] retain];
1451 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1452 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1453 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1454 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1455 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1457 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1459 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1460 [settings autorelease];
1462 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1463 Debug_ = [debug boolValue];
1465 NSArray *themes = [settings objectForKey:@"Themes"];
1467 if (NSString *theme = [settings objectForKey:@"Theme"])
1468 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1470 [NSNumber numberWithBool:true], @"Active",
1473 for (NSDictionary *theme in themes) {
1474 NSNumber *active = [theme objectForKey:@"Active"];
1475 if (![active boolValue])
1478 NSString *name = [theme objectForKey:@"Name"];
1482 NSString *theme = nil;
1484 #define testForTheme(format...) \
1485 if (theme == nil) { \
1486 NSString *path = [NSString stringWithFormat:format]; \
1487 if ([Manager_ fileExistsAtPath:path]) { \
1488 [themes_ addObject:path]; \
1493 testForTheme(@"/Library/Themes/%@.theme", name)
1494 testForTheme(@"/Library/Themes/%@", name)
1495 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1499 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1501 for (NSString *theme in themes_)
1502 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
1504 for (NSString *key in [info allKeys])
1505 if ([Info_ objectForKey:key] == nil)
1506 [Info_ setObject:[info objectForKey:key] forKey:key];
1509 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1511 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1513 $CKMessageCell = objc_getClass("CKMessageCell");
1514 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1515 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1517 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1518 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1519 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1521 $CKTimestampView = objc_getClass("CKTimestampView");
1522 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1524 $CKTranscriptController = objc_getClass("CKTranscriptController");
1525 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1528 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1530 if (_TranscriptController$loadView == NULL) {
1531 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1532 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1535 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1536 CFNotificationCenterAddObserver(
1537 CFNotificationCenterGetDarwinNotifyCenter(),
1538 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1541 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1542 if (MediaPlayer != nil)
1545 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1546 $MPVideoView = objc_getClass("MPVideoView");
1547 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1549 $SBApplication = objc_getClass("SBApplication");
1550 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1551 $SBAwayView = objc_getClass("SBAwayView");
1552 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1553 $SBButtonBar = objc_getClass("SBButtonBar");
1554 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1555 $SBIcon = objc_getClass("SBIcon");
1556 $SBIconBadge = objc_getClass("SBIconBadge");
1557 $SBIconController = objc_getClass("SBIconController");
1558 $SBIconLabel = objc_getClass("SBIconLabel");
1559 $SBIconList = objc_getClass("SBIconList");
1560 $SBIconModel = objc_getClass("SBIconModel");
1561 //$SBImageCache = objc_getClass("SBImageCache");
1562 $SBSearchView = objc_getClass("SBSearchView");
1563 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1564 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1565 $SBStatusBarController = objc_getClass("SBStatusBarController");
1566 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1567 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1568 $SBUIController = objc_getClass("SBUIController");
1569 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1571 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1573 WBRename(SBApplication, pathForIcon, pathForIcon);
1574 WBRename(SBApplicationIcon, icon, icon);
1575 WBRename(SBBookmarkIcon, icon, icon);
1576 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1577 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1578 WBRename(SBIcon, setAlpha:, setAlpha$);
1579 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1580 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1581 WBRename(SBUIController, init, init);
1582 WBRename(SBWidgetApplicationIcon, icon, icon);
1584 WBRename(SBIconLabel, drawRect:, drawRect$);
1585 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1586 WBRename(SBIconLabel, setInDock:, setInDock$);
1588 WBRename(SBIconList, setFrame:, setFrame$);
1590 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1591 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1592 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1593 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1595 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1596 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1597 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1599 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1601 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1602 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1603 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1604 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1605 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1606 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1607 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1608 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1609 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1611 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1612 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1615 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1617 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1618 [Info_ setObject:[NSNumber numberWithBool:(
1619 $getTheme$(Wallpapers_) == nil ||
1620 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1621 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1622 )] forKey:@"UndockedIconLabels"];
1625 NSLog(@"WB:Debug:Info = %@", [Info_ description]);