1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008-2010 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the
11 * above copyright notice, this list of conditions
12 * and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the
18 * 3. The name of the author may not be used to endorse
19 * or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #define _trace() do { \
44 struct timeval _ctv; \
45 gettimeofday(&_ctv, NULL); \
50 fprintf(stderr, "%lu.%.6u[%f]:_trace()@%s:%u[%s]\n", \
51 _ctv.tv_sec, _ctv.tv_usec, \
52 (_ctv.tv_sec - _ltv.tv_sec) + (_ctv.tv_usec - _ltv.tv_usec) / 1000000.0, \
53 __FILE__, __LINE__, __FUNCTION__\
60 #import <CoreFoundation/CoreFoundation.h>
61 #import <Foundation/Foundation.h>
62 #import <CoreGraphics/CoreGraphics.h>
64 #import <Celestial/AVController.h>
65 #import <Celestial/AVItem.h>
66 #import <Celestial/AVQueue.h>
68 #include <substrate.h>
70 #import <UIKit/UIKit.h>
72 #import <SpringBoard/SBApplication.h>
73 #import <SpringBoard/SBApplicationIcon.h>
74 #import <SpringBoard/SBAppWindow.h>
75 #import <SpringBoard/SBAwayView.h>
76 #import <SpringBoard/SBBookmarkIcon.h>
77 #import <SpringBoard/SBButtonBar.h>
78 #import <SpringBoard/SBCalendarIconContentsView.h>
79 #import <SpringBoard/SBIconController.h>
80 #import <SpringBoard/SBIconLabel.h>
81 #import <SpringBoard/SBIconList.h>
82 #import <SpringBoard/SBIconModel.h>
83 #import <SpringBoard/SBImageCache.h>
84 // XXX: #import <SpringBoard/SBSearchView.h>
85 #import <SpringBoard/SBSearchTableViewCell.h>
86 #import <SpringBoard/SBStatusBarContentsView.h>
87 #import <SpringBoard/SBStatusBarController.h>
88 #import <SpringBoard/SBStatusBarOperatorNameView.h>
89 #import <SpringBoard/SBStatusBarTimeView.h>
90 #import <SpringBoard/SBUIController.h>
91 #import <SpringBoard/SBWidgetApplicationIcon.h>
93 #import <MobileSMS/mSMSMessageTranscriptController.h>
95 #import <MediaPlayer/MPMoviePlayerController.h>
96 #import <MediaPlayer/MPVideoView.h>
97 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
99 #import <CoreGraphics/CGGeometry.h>
101 #import <ChatKit/CKMessageCell.h>
103 extern "C" void __clear_cache (char *beg, char *end);
105 @protocol WinterBoard
109 Class $MPMoviePlayerController;
111 Class $WebCoreFrameBridge;
116 Class $UINavigationBar;
119 Class $CKMessageCell;
120 Class $CKTimestampView;
121 Class $CKTranscriptController;
122 Class $CKTranscriptTableView;
124 Class $SBApplication;
125 Class $SBApplicationIcon;
127 Class $SBBookmarkIcon;
129 Class $SBCalendarIconContentsView;
132 Class $SBIconController;
136 //Class $SBImageCache;
138 Class $SBSearchTableViewCell;
139 Class $SBStatusBarContentsView;
140 Class $SBStatusBarController;
141 Class $SBStatusBarOperatorNameView;
142 Class $SBStatusBarTimeView;
143 Class $SBUIController;
144 Class $SBWidgetApplicationIcon;
148 @interface NSDictionary (WinterBoard)
149 - (UIColor *) wb$colorForKey:(NSString *)key;
150 - (BOOL) wb$boolForKey:(NSString *)key;
153 @implementation NSDictionary (WinterBoard)
155 - (UIColor *) wb$colorForKey:(NSString *)key {
156 NSString *value = [self objectForKey:key];
163 - (BOOL) wb$boolForKey:(NSString *)key {
164 if (NSString *value = [self objectForKey:key])
165 return [value boolValue];
171 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
172 #define $GSFontGetUseLegacyFontMetrics() \
173 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
176 bool Engineer_ = false;
177 bool SummerBoard_ = true;
179 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
180 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
181 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
182 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
183 static NSBundle *(*_UIKitBundle)();
184 static int (*_UISharedImageNameGetIdentifier)(NSString *);
185 static UIImage *(*_UISharedImageWithIdentifier)(int);
187 static NSMutableDictionary *UIImages_;
188 static NSMutableDictionary *PathImages_;
189 static NSMutableDictionary *Cache_;
190 static NSMutableDictionary *Strings_;
191 static NSMutableDictionary *Themed_;
192 static NSMutableDictionary *Bundles_;
194 static NSFileManager *Manager_;
195 static NSDictionary *English_;
196 static NSMutableDictionary *Info_;
197 static NSMutableArray *themes_;
199 static NSString *$getTheme$(NSArray *files, bool parent = false) {
201 if (NSString *path = [Themed_ objectForKey:files])
202 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
205 NSLog(@"WB:Debug: %@", [files description]);
209 for (NSString *theme in themes_)
210 for (NSString *file in files) {
211 path = [NSString stringWithFormat:@"%@/%@", theme, file];
212 if ([Manager_ fileExistsAtPath:path]) {
213 path = parent ? theme : path;
221 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
225 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
226 NSString *identifier = [bundle bundleIdentifier];
227 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
229 if (identifier != nil)
230 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
231 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
232 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
234 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
236 #define remapResourceName(oldname, newname) \
237 else if ([file isEqualToString:oldname]) \
238 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
240 if (identifier == nil);
241 else if ([identifier isEqualToString:@"com.apple.chatkit"])
242 [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
243 else if ([identifier isEqualToString:@"com.apple.calculator"])
244 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
245 else if (![identifier isEqualToString:@"com.apple.springboard"] || !SummerBoard_);
246 remapResourceName(@"FSO_BG.png", @"StatusBar")
247 remapResourceName(@"SBDockBG.png", @"Dock")
248 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
250 if (NSString *path = $getTheme$(names))
255 static NSString *$pathForIcon$(SBApplication *self) {
256 NSString *identifier = [self bundleIdentifier];
257 NSString *path = [self path];
258 NSString *folder = [path lastPathComponent];
259 NSString *dname = [self displayName];
260 NSString *didentifier = [self displayIdentifier];
263 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
265 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
267 /* XXX: I might need to keep this for backwards compatibility
268 if (identifier != nil)
269 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
271 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */
273 #define testForIcon(Name) \
274 if (NSString *name = Name) \
275 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
277 if (![didentifier isEqualToString:identifier])
278 testForIcon(didentifier);
280 testForIcon(identifier);
283 if ([identifier isEqualToString:@"com.apple.MobileSMS"])
286 if (didentifier != nil) {
287 testForIcon([English_ objectForKey:didentifier]);
289 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
290 if ([parts count] != 1)
291 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
292 testForIcon([english objectForKey:[parts lastObject]]);
295 if (NSString *path = $getTheme$(names))
301 @interface NSBundle (WinterBoard)
302 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
305 @implementation NSBundle (WinterBoard)
307 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
308 path = [path stringByDeletingLastPathComponent];
309 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
312 NSBundle *bundle([Bundles_ objectForKey:path]);
313 if (reinterpret_cast<id>(bundle) == [NSNull null])
315 else if (bundle == nil) {
316 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
317 bundle = [NSBundle bundleWithPath:path];
319 bundle = [NSBundle wb$bundleWithFile:path];
321 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
322 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
330 @interface NSString (WinterBoard)
331 - (NSString *) wb$themedPath;
334 @implementation NSString (WinterBoard)
336 - (NSString *) wb$themedPath {
338 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
340 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
341 NSString *file([self stringByResolvingSymlinksInPath]);
342 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
343 if ([file hasPrefix:prefix]) {
344 NSUInteger length([prefix length]);
345 if (length != [file length])
346 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
356 void WBLogRect(const char *tag, struct CGRect rect) {
357 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
360 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
361 CGRect frame([view frame]);
362 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]);
364 for (UIView *child in [view subviews])
365 WBLogHierarchy(child, index++, indent + 1);
368 UIImage *$cacheForImage$(UIImage *image) {
369 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
370 CGRect rect = {CGPointMake(1, 1), [image size]};
371 CGSize size = {rect.size.width + 2, rect.size.height + 2};
373 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
374 CGColorSpaceRelease(space);
376 CGContextDrawImage(context, rect, [image CGImage]);
377 CGImageRef ref(CGBitmapContextCreateImage(context));
378 CGContextRelease(context);
380 UIImage *cache([UIImage imageWithCGImage:ref]);
386 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
387 //if ([name isEqualToString:@"icons"]) return nil;
388 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
391 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
392 NSString *key([icon displayIdentifier]);
394 if (UIImage *image = [icon icon]) {
395 CGSize size = [image size];
396 if (size.width != 59 || size.height != 60) {
397 UIImage *cache($cacheForImage$(image));
398 [Cache_ setObject:cache forKey:key];
403 _SBIconModel$cacheImageForIcon$(self, sel, icon);
406 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
407 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
408 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
410 NSString *key([icon displayIdentifier]);
412 if (UIImage *image = [icon icon]) {
413 CGSize size = [image size];
414 if (size.width != 59 || size.height != 60) {
415 UIImage *cache($cacheForImage$(image));
416 [Cache_ setObject:cache forKey:key];
422 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
423 NSString *key([icon displayIdentifier]);
424 if (UIImage *image = [Cache_ objectForKey:key])
427 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
430 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
432 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
433 NSString *key([icon displayIdentifier]);
434 if (UIImage *image = [Cache_ objectForKey:key])
437 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
440 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
441 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
442 [self setBackgroundColor:[UIColor clearColor]];
443 for (UIView *child in [self subviews])
444 [child setBackgroundColor:[UIColor clearColor]];
448 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
449 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
450 [self setBackgroundColor:[UIColor clearColor]];
454 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
455 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
456 float inset([self edgeInset]);
457 [[UIColor clearColor] set];
458 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
459 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
462 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
463 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
464 if (NSString *path = $pathForIcon$([self application]))
465 return [UIImage imageWithContentsOfFile:path];
466 return _SBApplicationIcon$icon(self, sel);
469 MSHook(UIImage *, SBApplicationIcon$generateIconImage$, SBApplicationIcon *self, SEL sel, int type) {
471 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
472 if (NSString *path = $pathForIcon$([self application]))
473 if (UIImage *image = [UIImage imageWithContentsOfFile:path])
474 return [image _imageScaledToProportion:1.2 interpolationQuality:5];
475 return _SBApplicationIcon$generateIconImage$(self, sel, type);
478 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
480 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
481 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
482 return [UIImage imageWithContentsOfFile:path];
483 return _SBWidgetApplicationIcon$icon(self, sel);
486 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
488 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
489 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
490 return [UIImage imageWithContentsOfFile:path];
491 return _SBBookmarkIcon$icon(self, sel);
494 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
495 if (NSString *path = $pathForIcon$(self))
497 return _SBApplication$pathForIcon(self, sel);
500 static UIImage *CachedImageAtPath(NSString *path) {
501 path = [path stringByResolvingSymlinksInPath];
502 UIImage *image = [PathImages_ objectForKey:path];
504 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
505 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
507 image = [image autorelease];
508 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
512 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
514 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
515 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
518 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
520 return __UIImageAtPath(name, nil);
522 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
523 UIImage *image = [PathImages_ objectForKey:key];
525 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
527 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
528 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
529 image = CachedImageAtPath(path);
531 image = __UIImageAtPath(name, bundle);
532 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
537 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
538 NSBundle *bundle = [NSBundle mainBundle];
540 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
541 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
542 return CachedImageAtPath(path);
543 return __UIApplicationImageWithName(name);
546 #define WBDelegate(delegate) \
547 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
549 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
550 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
552 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
556 - (void) forwardInvocation:(NSInvocation*)inv { \
557 SEL sel = [inv selector]; \
558 if ([delegate respondsToSelector:sel]) \
559 [inv invokeWithTarget:delegate]; \
561 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
564 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
565 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
567 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
568 if (NSString *path = $pathForFile$inBundle$(file, self, false))
570 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
573 void $setBarStyle$_(NSString *name, int &style) {
575 NSLog(@"WB:Debug:%@Style:%d", name, style);
576 NSNumber *number = nil;
578 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
580 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
582 style = [number intValue];
584 NSLog(@"WB:Debug:%@Style=%d", name, style);
588 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
589 NSBundle *bundle([NSBundle mainBundle]);
591 CFLocaleRef locale(CFLocaleCopyCurrent());
592 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
595 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
597 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
598 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
599 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
600 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
604 CFRelease(formatter);
606 NSString *datestyle([@""
607 "font-family: Helvetica; "
608 "font-weight: bold; "
611 "" stringByAppendingString:(IsWild_
612 ? @"font-size: 54px; "
613 : @"font-size: 39px; "
616 NSString *daystyle([@""
617 "font-family: Helvetica; "
618 "font-weight: bold; "
620 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
621 "" stringByAppendingString:(IsWild_
622 ? @"font-size: 11px; "
623 : @"font-size: 9px; "
626 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
627 datestyle = [datestyle stringByAppendingString:style];
628 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
629 daystyle = [daystyle stringByAppendingString:style];
631 float width([self bounds].size.width);
633 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
634 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
636 unsigned base(IsWild_ ? 89 : 70);
637 if ($GSFontGetUseLegacyFontMetrics())
640 [(NSString *)date drawAtPoint:CGPointMake(
641 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
642 ) withStyle:datestyle];
644 [(NSString *)day drawAtPoint:CGPointMake(
645 (width + 1 - daysize.width) / 2, ((IsWild_ ? 18 : 16) - daysize.height) / 2
646 ) withStyle:daystyle];
652 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
655 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
656 style = [number intValue];
658 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
661 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
664 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
665 self = [self wb$initWithCoder:coder];
668 UINavigationBar$setBarStyle$_(self);
672 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
673 self = [self wb$initWithFrame:frame];
676 UINavigationBar$setBarStyle$_(self);
680 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
681 $setBarStyle$_(@"Toolbar", style);
682 return _UIToolbar$setBarStyle$(self, sel, style);
685 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
686 $setBarStyle$_(@"NavigationBar", style);
687 return _UINavigationBar$setBarStyle$(self, sel, style);
690 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
691 [[self superview] setBackgroundColor:[UIColor clearColor]];
692 _SBButtonBar$didMoveToSuperview(self, sel);
695 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
696 [[self superview] setBackgroundColor:[UIColor clearColor]];
697 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
700 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
702 NSLog(@"WB:Debug:DefaultDesktopImage");
703 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
704 return [UIImage imageWithContentsOfFile:path];
705 return _UIImage$defaultDesktopImage(self, sel);
708 static NSArray *Wallpapers_;
709 static bool Papered_;
710 static NSString *WallpaperFile_;
711 static UIImageView *WallpaperImage_;
712 static UIWebDocumentView *WallpaperPage_;
713 static NSURL *WallpaperURL_;
715 #define _release(object) \
716 do if (object != nil) { \
721 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
722 self = _SBUIController$init(self, sel);
727 UIWindow *&_wallpaperView(MSHookIvar<UIWindow *>(self, "_wallpaperView"));
728 if (&_wallpaperView != NULL) {
729 [_wallpaperView removeFromSuperview];
730 [_wallpaperView release];
731 _wallpaperView = nil;
735 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
736 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
737 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
740 if (&_contentLayer != NULL)
741 layer = _contentLayer;
742 else if (&_contentView != NULL)
743 layer = _contentView;
747 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
749 [content setBackgroundColor:[layer backgroundColor]];
750 [layer setBackgroundColor:[UIColor clearColor]];
751 [layer setFrame:[content bounds]];
752 [_window setContentView:content];
755 if (!SummerBoard_ || !IsWild_)
758 CGRect bounds([content bounds]);
759 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
760 [content addSubview:indirect];
761 [indirect zoomToScale:2.4];
764 _release(WallpaperFile_);
765 _release(WallpaperImage_);
766 _release(WallpaperPage_);
767 _release(WallpaperURL_);
769 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
770 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
771 if ([Manager_ fileExistsAtPath:mp4]) {
775 static AVController *controller_(nil);
776 if (controller_ == nil) {
777 AVQueue *queue([AVQueue avQueue]);
778 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
781 AVQueue *queue([controller_ queue]);
783 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
784 [controller_ setLayer:[video _layer]];
786 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
787 [queue appendItem:item error:&error];
789 [controller_ play:&error];
790 #elif UseMPMoviePlayerController
791 NSURL *url([NSURL fileURLWithPath:mp4]);
792 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
793 controller.movieControlMode = MPMovieControlModeHidden;
796 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
797 [video setMovieWithPath:mp4];
798 [video setRepeatMode:1];
799 [video setRepeatGap:-1];
800 [video playFromBeginning];;
803 [indirect addSubview:video];
806 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
807 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
810 if ([Manager_ fileExistsAtPath:png])
812 else if ([Manager_ fileExistsAtPath:jpg])
818 image = [[UIImage alloc] initWithContentsOfFile:path];
820 image = [image autorelease];
824 WallpaperFile_ = [path retain];
825 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
826 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
827 [WallpaperImage_ setAlpha:[number floatValue]];
828 [indirect addSubview:WallpaperImage_];
831 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
832 if ([Manager_ fileExistsAtPath:html]) {
833 CGRect bounds = [indirect bounds];
835 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
836 [view setAutoresizes:true];
838 WallpaperPage_ = [view retain];
839 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
841 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
843 [view setBackgroundColor:[UIColor clearColor]];
844 if ([view respondsToSelector:@selector(setDrawsBackground:)])
845 [view setDrawsBackground:NO];
846 [[view webView] setDrawsBackground:NO];
848 [indirect addSubview:view];
852 for (size_t i(0), e([themes_ count]); i != e; ++i) {
853 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
854 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
855 if ([Manager_ fileExistsAtPath:html]) {
856 CGRect bounds = [indirect bounds];
858 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
859 [view setAutoresizes:true];
861 NSURL *url = [NSURL fileURLWithPath:html];
862 [view loadRequest:[NSURLRequest requestWithURL:url]];
864 [view setBackgroundColor:[UIColor clearColor]];
865 if ([view respondsToSelector:@selector(setDrawsBackground:)])
866 [view setDrawsBackground:NO];
867 [[view webView] setDrawsBackground:NO];
869 [indirect addSubview:view];
873 [content addSubview:layer];
878 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
879 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
880 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
882 if (path != nil && _backgroundView != nil)
885 _SBAwayView$updateDesktopImage$(self, sel, image);
888 CGRect bounds = [self bounds];
890 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
891 [view setAutoresizes:true];
893 if (WallpaperPage_ != nil)
894 [WallpaperPage_ release];
895 WallpaperPage_ = [view retain];
897 if (WallpaperURL_ != nil)
898 [WallpaperURL_ release];
899 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
901 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
903 [[view webView] setDrawsBackground:false];
904 [view setBackgroundColor:[UIColor clearColor]];
906 [self insertSubview:view aboveSubview:_backgroundView];
910 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
911 extern "C" CGColorRef CGGStateGetFillColor(void *);
912 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
913 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
915 /* WBTimeLabel {{{ */
916 @interface WBTimeLabel : NSProxy {
918 _transient SBStatusBarTimeView *view_;
921 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
925 @implementation WBTimeLabel
932 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
933 time_ = [time retain];
938 - (NSString *) description {
944 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
945 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
946 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
948 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
949 "font-family: Helvetica; "
950 "font-weight: bold; "
953 "%@", _mode ? @"white" : @"black", custom]];
958 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
963 /* WBBadgeLabel {{{ */
964 @interface WBBadgeLabel : NSProxy {
968 - (id) initWithBadge:(NSString *)badge;
969 - (NSString *) description;
973 @implementation WBBadgeLabel
980 - (id) initWithBadge:(NSString *)badge {
981 badge_ = [badge retain];
985 - (NSString *) description {
986 return [badge_ description];
991 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
992 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
993 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
994 "font-family: Helvetica; "
995 "font-weight: bold; "
1003 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1009 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1010 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1011 alpha = [number floatValue];
1012 return _SBIcon$setAlpha$(self, sel, alpha);
1015 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1016 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
1017 id &_badge(MSHookIvar<id>(self, "_badge"));
1019 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1024 void SBStatusBarController$setStatusBarMode(int &mode) {
1026 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
1027 if (mode < 100) // 104:hidden 105:glowing
1028 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1029 mode = [number intValue];
1032 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1033 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1034 SBStatusBarController$setStatusBarMode(mode);
1035 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1038 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
1039 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
1040 SBStatusBarController$setStatusBarMode(mode);
1041 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1044 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) {
1045 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1046 SBStatusBarController$setStatusBarMode(mode);
1047 //NSLog(@"mode=%u", mode);
1048 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1051 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1052 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1053 mode = [number intValue];
1054 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1057 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1058 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1060 NSLog(@"operatorNameStyle= %@", style);
1061 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1062 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1066 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1068 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1069 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1072 // XXX: replace this with [SBStatusBarTimeView tile]
1073 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1074 id &_time(MSHookIvar<id>(self, "_time"));
1075 if (_time != nil && [_time class] != [WBTimeLabel class])
1076 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1077 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1080 @interface UIView (WinterBoard)
1081 - (bool) wb$isWBImageView;
1082 - (void) wb$logHierarchy;
1085 @implementation UIView (WinterBoard)
1087 - (bool) wb$isWBImageView {
1091 - (void) wb$logHierarchy {
1092 WBLogHierarchy(self);
1097 @interface WBImageView : UIImageView {
1100 - (bool) wb$isWBImageView;
1101 - (void) wb$updateFrame;
1104 @implementation WBImageView
1106 - (bool) wb$isWBImageView {
1110 - (void) wb$updateFrame {
1111 CGRect frame([self frame]);
1114 for (UIView *view(self); ; ) {
1115 view = [view superview];
1118 frame.origin.y -= [view frame].origin.y;
1121 [self setFrame:frame];
1126 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1127 NSArray *subviews([self subviews]);
1128 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1129 if (view != nil && [view wb$isWBImageView])
1130 [view wb$updateFrame];
1131 _SBIconList$setFrame$(self, sel, frame);
1134 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1135 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1136 NSArray *lists([_iconModel iconLists]);
1138 for (unsigned i(0), e([lists count]); i != e; ++i)
1139 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1140 SBIconList *list([lists objectAtIndex:i]);
1141 NSArray *subviews([list subviews]);
1143 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1144 if (view == nil || ![view wb$isWBImageView]) {
1145 view = [[[WBImageView alloc] init] autorelease];
1146 [list insertSubview:view atIndex:0];
1149 UIImage *image([UIImage imageWithContentsOfFile:path]);
1151 CGRect frame([view frame]);
1152 frame.size = [image size];
1153 [view setFrame:frame];
1155 [view setImage:image];
1156 [view wb$updateFrame];
1159 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1162 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1163 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1165 [self setClipsToBounds:NO];
1169 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1170 id &_label(MSHookIvar<id>(self, "_label"));
1171 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1173 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1174 [_label setInDock:docked];
1175 return _SBIconLabel$setInDock$(self, sel, docked);
1178 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1179 NSString *identifier = [self bundleIdentifier];
1180 NSLocale *locale = [NSLocale currentLocale];
1181 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1183 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1184 NSString *file = table == nil ? @"Localizable" : table;
1185 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1186 NSDictionary *strings;
1187 if ((strings = [Strings_ objectForKey:name]) != nil) {
1188 if (static_cast<id>(strings) != [NSNull null]) strings:
1189 if (NSString *value = [strings objectForKey:key])
1191 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1194 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1195 [Strings_ setObject:[strings autorelease] forKey:name];
1199 [Strings_ setObject:[NSNull null] forKey:name];
1200 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1203 @class WebCoreFrameBridge;
1204 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1207 void **core(reinterpret_cast<void **>([node _node]));
1208 if (core == NULL || core[6] == NULL)
1210 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1213 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1214 CGRect bounds = [self bounds];
1216 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1219 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1220 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1222 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1224 NSString *style = [NSString stringWithFormat:@""
1225 "font-family: Helvetica; "
1226 "font-weight: bold; "
1228 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
1229 ? @"font-size: 12px; "
1230 : @"font-size: 11px; "
1234 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1236 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1238 bool ellipsis(false);
1239 float max = 75, width;
1241 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1244 size_t length([label length]);
1245 float spacing((width - max) / (length - 1));
1247 if (spacing > 1.25) {
1249 label = [label substringToIndex:(length - 1)];
1253 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1257 label = [label stringByAppendingString:@"..."];
1259 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1260 style = [style stringByAppendingString:custom];
1262 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1263 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1266 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1267 _CKMessageCell$addBalloonView$(self, sel, balloon);
1268 [balloon setBackgroundColor:[UIColor clearColor]];
1271 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1272 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1273 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1277 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1278 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1279 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1280 [_label setBackgroundColor:[UIColor clearColor]];
1284 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1285 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1288 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1290 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1291 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1295 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1296 _TranscriptController$loadView(self, sel);
1298 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1299 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1300 [image autorelease];
1302 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1303 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1305 if (&_transcriptTable != NULL)
1306 table = _transcriptTable;
1307 else if (&_transcriptLayer != NULL)
1308 table = _transcriptLayer;
1312 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1313 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1316 [placard insertSubview:background atIndex:0];
1318 [table setBackgroundColor:[UIColor clearColor]];
1319 [placard insertSubview:background belowSubview:table];
1324 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1325 int id(_UISharedImageNameGetIdentifier(name));
1327 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1330 return _UIImageAtPath(name, _UIKitBundle());
1332 NSNumber *key([NSNumber numberWithInt:id]);
1333 UIImage *image = [UIImages_ objectForKey:key];
1335 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1336 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1337 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1339 [image autorelease];
1341 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1342 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1346 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1347 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1348 UIImage *image([PathImages_ objectForKey:key]);
1350 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1352 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1353 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1354 image = [[UIImage alloc] initWithContentsOfFile:path];
1356 [image autorelease];
1358 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1359 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1362 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1364 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1365 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1366 name = [font UTF8String];
1367 return _GSFontCreateWithName(name, traits, size);
1370 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1371 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1373 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1375 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1377 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1378 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1380 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1383 NSString *path = [NSString stringWithUTF8String:a1];
1384 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1385 NSString *file = [path substringFromIndex:31];
1386 for (NSString *theme in themes_) {
1387 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1388 if ([Manager_ fileExistsAtPath:path]) {
1389 strcpy(a1, [path UTF8String]);
1398 static void ChangeWallpaper(
1399 CFNotificationCenterRef center,
1403 CFDictionaryRef info
1406 NSLog(@"WB:Debug:ChangeWallpaper!");
1409 if (WallpaperFile_ != nil) {
1410 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1412 image = [image autorelease];
1415 if (WallpaperImage_ != nil)
1416 [WallpaperImage_ setImage:image];
1417 if (WallpaperPage_ != nil)
1418 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1422 #define WBRename(name, sel, imp) \
1423 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1425 template <typename Type_>
1426 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1427 struct nlist &name(nl[index]);
1428 uintptr_t value(name.n_value);
1429 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1430 value |= 0x00000001;
1431 function = reinterpret_cast<Type_>(value);
1434 template <typename Type_>
1435 static void dlset(Type_ &function, const char *name) {
1436 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1439 extern "C" void WBInitialize() {
1440 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1442 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1444 NSLog(@"WB:Notice: WinterBoard");
1446 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1450 memset(nl, 0, sizeof(nl));
1451 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1452 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1453 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1454 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1455 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1456 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1457 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1460 nlset(_UIApplicationImageWithName, nl, 0);
1461 nlset(_UIImageAtPath, nl, 1);
1462 nlset(_UIImageRefAtPath, nl, 2);
1463 nlset(_UIImageWithNameInDomain, nl, 3);
1464 nlset(_UIKitBundle, nl, 4);
1465 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1466 nlset(_UISharedImageWithIdentifier, nl, 6);
1468 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1469 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1470 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1471 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1473 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1475 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1477 memset(nl, 0, sizeof(nl));
1478 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1479 nlist(AudioToolbox, nl);
1480 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1481 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1484 $NSBundle = objc_getClass("NSBundle");
1486 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1487 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1489 $UIImage = objc_getClass("UIImage");
1490 $UINavigationBar = objc_getClass("UINavigationBar");
1491 $UIToolbar = objc_getClass("UIToolbar");
1493 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1495 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1496 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1498 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1499 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1501 Manager_ = [[NSFileManager defaultManager] retain];
1502 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1503 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1504 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1505 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1506 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1508 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1510 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1511 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1512 SummerBoard_ = [value boolValue];
1513 if (NSNumber *value = [settings objectForKey:@"Debug"])
1514 Debug_ = [value boolValue];
1516 NSArray *themes([settings objectForKey:@"Themes"]);
1518 if (NSString *theme = [settings objectForKey:@"Theme"])
1519 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1521 [NSNumber numberWithBool:true], @"Active",
1525 for (NSDictionary *theme in themes) {
1526 NSNumber *active([theme objectForKey:@"Active"]);
1527 if (![active boolValue])
1530 NSString *name([theme objectForKey:@"Name"]);
1534 NSString *theme(nil);
1536 #define testForTheme(format...) \
1537 if (theme == nil) { \
1538 NSString *path = [NSString stringWithFormat:format]; \
1539 if ([Manager_ fileExistsAtPath:path]) { \
1540 [themes_ addObject:path]; \
1545 testForTheme(@"/Library/Themes/%@.theme", name)
1546 testForTheme(@"/Library/Themes/%@", name)
1547 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1552 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1554 for (NSString *theme in themes_)
1555 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1556 for (NSString *key in [info allKeys])
1557 if ([Info_ objectForKey:key] == nil)
1558 [Info_ setObject:[info objectForKey:key] forKey:key];
1560 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1562 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1564 $CKMessageCell = objc_getClass("CKMessageCell");
1565 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1566 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1568 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1569 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1570 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1572 $CKTimestampView = objc_getClass("CKTimestampView");
1573 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1575 $CKTranscriptController = objc_getClass("CKTranscriptController");
1576 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1579 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1581 if (_TranscriptController$loadView == NULL) {
1582 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1583 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1586 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1587 CFNotificationCenterAddObserver(
1588 CFNotificationCenterGetDarwinNotifyCenter(),
1589 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1592 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
1593 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1594 if (MediaPlayer != nil)
1597 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1598 $MPVideoView = objc_getClass("MPVideoView");
1601 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1603 $SBApplication = objc_getClass("SBApplication");
1604 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1605 $SBAwayView = objc_getClass("SBAwayView");
1606 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1607 $SBButtonBar = objc_getClass("SBButtonBar");
1608 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1609 $SBIcon = objc_getClass("SBIcon");
1610 $SBIconBadge = objc_getClass("SBIconBadge");
1611 $SBIconController = objc_getClass("SBIconController");
1612 $SBIconLabel = objc_getClass("SBIconLabel");
1613 $SBIconList = objc_getClass("SBIconList");
1614 $SBIconModel = objc_getClass("SBIconModel");
1615 //$SBImageCache = objc_getClass("SBImageCache");
1616 $SBSearchView = objc_getClass("SBSearchView");
1617 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1618 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1619 $SBStatusBarController = objc_getClass("SBStatusBarController");
1620 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1621 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1622 $SBUIController = objc_getClass("SBUIController");
1623 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1625 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1628 WBRename(SBApplication, pathForIcon, pathForIcon);
1629 WBRename(SBApplicationIcon, icon, icon);
1630 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
1633 WBRename(SBBookmarkIcon, icon, icon);
1634 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1635 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1636 WBRename(SBIcon, setAlpha:, setAlpha$);
1637 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1638 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1639 WBRename(SBUIController, init, init);
1640 WBRename(SBWidgetApplicationIcon, icon, icon);
1642 WBRename(SBIconLabel, drawRect:, drawRect$);
1643 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1644 WBRename(SBIconLabel, setInDock:, setInDock$);
1646 WBRename(SBIconList, setFrame:, setFrame$);
1648 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1649 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1650 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1651 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1653 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1654 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1655 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1657 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1659 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1660 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1661 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1662 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1663 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1664 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1665 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1666 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1667 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1670 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1672 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1675 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1676 Papered_ = $getTheme$(Wallpapers_) != nil;
1678 UIDevice *device([UIDevice currentDevice]);
1679 IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
1681 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1682 [Info_ setObject:[NSNumber numberWithBool:(
1684 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1685 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1686 )] forKey:@"UndockedIconLabels"];
1689 NSLog(@"WB:Debug:Info = %@", [Info_ description]);