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 bounds.origin.y = -30;
760 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
761 [content addSubview:indirect];
762 [indirect zoomToScale:2.4];
765 _release(WallpaperFile_);
766 _release(WallpaperImage_);
767 _release(WallpaperPage_);
768 _release(WallpaperURL_);
770 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
771 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
772 if ([Manager_ fileExistsAtPath:mp4]) {
776 static AVController *controller_(nil);
777 if (controller_ == nil) {
778 AVQueue *queue([AVQueue avQueue]);
779 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
782 AVQueue *queue([controller_ queue]);
784 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
785 [controller_ setLayer:[video _layer]];
787 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
788 [queue appendItem:item error:&error];
790 [controller_ play:&error];
791 #elif UseMPMoviePlayerController
792 NSURL *url([NSURL fileURLWithPath:mp4]);
793 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
794 controller.movieControlMode = MPMovieControlModeHidden;
797 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
798 [video setMovieWithPath:mp4];
799 [video setRepeatMode:1];
800 [video setRepeatGap:-1];
801 [video playFromBeginning];;
804 [indirect addSubview:video];
807 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
808 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
811 if ([Manager_ fileExistsAtPath:png])
813 else if ([Manager_ fileExistsAtPath:jpg])
819 image = [[UIImage alloc] initWithContentsOfFile:path];
821 image = [image autorelease];
825 WallpaperFile_ = [path retain];
826 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
827 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
828 [WallpaperImage_ setAlpha:[number floatValue]];
829 [indirect addSubview:WallpaperImage_];
832 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
833 if ([Manager_ fileExistsAtPath:html]) {
834 CGRect bounds = [indirect bounds];
836 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
837 [view setAutoresizes:true];
839 WallpaperPage_ = [view retain];
840 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
842 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
844 [view setBackgroundColor:[UIColor clearColor]];
845 if ([view respondsToSelector:@selector(setDrawsBackground:)])
846 [view setDrawsBackground:NO];
847 [[view webView] setDrawsBackground:NO];
849 [indirect addSubview:view];
853 for (size_t i(0), e([themes_ count]); i != e; ++i) {
854 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
855 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
856 if ([Manager_ fileExistsAtPath:html]) {
857 CGRect bounds = [indirect bounds];
859 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
860 [view setAutoresizes:true];
862 NSURL *url = [NSURL fileURLWithPath:html];
863 [view loadRequest:[NSURLRequest requestWithURL:url]];
865 [view setBackgroundColor:[UIColor clearColor]];
866 if ([view respondsToSelector:@selector(setDrawsBackground:)])
867 [view setDrawsBackground:NO];
868 [[view webView] setDrawsBackground:NO];
870 [indirect addSubview:view];
874 [content addSubview:layer];
879 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
880 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
881 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
883 if (path != nil && _backgroundView != nil)
886 _SBAwayView$updateDesktopImage$(self, sel, image);
889 CGRect bounds = [self bounds];
891 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
892 [view setAutoresizes:true];
894 if (WallpaperPage_ != nil)
895 [WallpaperPage_ release];
896 WallpaperPage_ = [view retain];
898 if (WallpaperURL_ != nil)
899 [WallpaperURL_ release];
900 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
902 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
904 [[view webView] setDrawsBackground:false];
905 [view setBackgroundColor:[UIColor clearColor]];
907 [self insertSubview:view aboveSubview:_backgroundView];
911 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
912 extern "C" CGColorRef CGGStateGetFillColor(void *);
913 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
914 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
916 /* WBTimeLabel {{{ */
917 @interface WBTimeLabel : NSProxy {
919 _transient SBStatusBarTimeView *view_;
922 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
926 @implementation WBTimeLabel
933 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
934 time_ = [time retain];
939 - (NSString *) description {
945 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
946 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
947 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
949 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
950 "font-family: Helvetica; "
951 "font-weight: bold; "
954 "%@", _mode ? @"white" : @"black", custom]];
959 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
964 /* WBBadgeLabel {{{ */
965 @interface WBBadgeLabel : NSProxy {
969 - (id) initWithBadge:(NSString *)badge;
970 - (NSString *) description;
974 @implementation WBBadgeLabel
981 - (id) initWithBadge:(NSString *)badge {
982 badge_ = [badge retain];
986 - (NSString *) description {
987 return [badge_ description];
992 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
993 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
994 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
995 "font-family: Helvetica; "
996 "font-weight: bold; "
1004 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1010 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1011 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1012 alpha = [number floatValue];
1013 return _SBIcon$setAlpha$(self, sel, alpha);
1016 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1017 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
1018 id &_badge(MSHookIvar<id>(self, "_badge"));
1020 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1025 void SBStatusBarController$setStatusBarMode(int &mode) {
1027 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
1028 if (mode < 100) // 104:hidden 105:glowing
1029 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1030 mode = [number intValue];
1033 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1034 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1035 SBStatusBarController$setStatusBarMode(mode);
1036 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1039 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
1040 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
1041 SBStatusBarController$setStatusBarMode(mode);
1042 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1045 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) {
1046 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1047 SBStatusBarController$setStatusBarMode(mode);
1048 //NSLog(@"mode=%u", mode);
1049 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1052 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1053 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1054 mode = [number intValue];
1055 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1058 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1059 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1061 NSLog(@"operatorNameStyle= %@", style);
1062 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1063 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1067 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1069 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1070 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1073 // XXX: replace this with [SBStatusBarTimeView tile]
1074 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1075 id &_time(MSHookIvar<id>(self, "_time"));
1076 if (_time != nil && [_time class] != [WBTimeLabel class])
1077 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1078 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1081 @interface UIView (WinterBoard)
1082 - (bool) wb$isWBImageView;
1083 - (void) wb$logHierarchy;
1086 @implementation UIView (WinterBoard)
1088 - (bool) wb$isWBImageView {
1092 - (void) wb$logHierarchy {
1093 WBLogHierarchy(self);
1098 @interface WBImageView : UIImageView {
1101 - (bool) wb$isWBImageView;
1102 - (void) wb$updateFrame;
1105 @implementation WBImageView
1107 - (bool) wb$isWBImageView {
1111 - (void) wb$updateFrame {
1112 CGRect frame([self frame]);
1115 for (UIView *view(self); ; ) {
1116 view = [view superview];
1119 frame.origin.y -= [view frame].origin.y;
1122 [self setFrame:frame];
1127 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1128 NSArray *subviews([self subviews]);
1129 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1130 if (view != nil && [view wb$isWBImageView])
1131 [view wb$updateFrame];
1132 _SBIconList$setFrame$(self, sel, frame);
1135 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1136 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1137 NSArray *lists([_iconModel iconLists]);
1139 for (unsigned i(0), e([lists count]); i != e; ++i)
1140 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1141 SBIconList *list([lists objectAtIndex:i]);
1142 NSArray *subviews([list subviews]);
1144 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1145 if (view == nil || ![view wb$isWBImageView]) {
1146 view = [[[WBImageView alloc] init] autorelease];
1147 [list insertSubview:view atIndex:0];
1150 UIImage *image([UIImage imageWithContentsOfFile:path]);
1152 CGRect frame([view frame]);
1153 frame.size = [image size];
1154 [view setFrame:frame];
1156 [view setImage:image];
1157 [view wb$updateFrame];
1160 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1163 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1164 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1166 [self setClipsToBounds:NO];
1170 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1171 id &_label(MSHookIvar<id>(self, "_label"));
1172 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1174 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1175 [_label setInDock:docked];
1176 return _SBIconLabel$setInDock$(self, sel, docked);
1179 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1180 NSString *identifier = [self bundleIdentifier];
1181 NSLocale *locale = [NSLocale currentLocale];
1182 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1184 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1185 NSString *file = table == nil ? @"Localizable" : table;
1186 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1187 NSDictionary *strings;
1188 if ((strings = [Strings_ objectForKey:name]) != nil) {
1189 if (static_cast<id>(strings) != [NSNull null]) strings:
1190 if (NSString *value = [strings objectForKey:key])
1192 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1195 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1196 [Strings_ setObject:[strings autorelease] forKey:name];
1200 [Strings_ setObject:[NSNull null] forKey:name];
1201 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1204 @class WebCoreFrameBridge;
1205 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1208 void **core(reinterpret_cast<void **>([node _node]));
1209 if (core == NULL || core[6] == NULL)
1211 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1214 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1215 CGRect bounds = [self bounds];
1217 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1220 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1221 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1223 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1225 NSString *style = [NSString stringWithFormat:@""
1226 "font-family: Helvetica; "
1227 "font-weight: bold; "
1229 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
1230 ? @"font-size: 12px; "
1231 : @"font-size: 11px; "
1235 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1237 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1239 bool ellipsis(false);
1240 float max = 75, width;
1242 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1245 size_t length([label length]);
1246 float spacing((width - max) / (length - 1));
1248 if (spacing > 1.25) {
1250 label = [label substringToIndex:(length - 1)];
1254 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1258 label = [label stringByAppendingString:@"..."];
1260 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1261 style = [style stringByAppendingString:custom];
1263 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1264 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1267 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1268 _CKMessageCell$addBalloonView$(self, sel, balloon);
1269 [balloon setBackgroundColor:[UIColor clearColor]];
1272 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1273 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1274 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1278 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1279 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1280 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1281 [_label setBackgroundColor:[UIColor clearColor]];
1285 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1286 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1289 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1291 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1292 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1296 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1297 _TranscriptController$loadView(self, sel);
1299 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1300 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1301 [image autorelease];
1303 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1304 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1306 if (&_transcriptTable != NULL)
1307 table = _transcriptTable;
1308 else if (&_transcriptLayer != NULL)
1309 table = _transcriptLayer;
1313 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1314 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1317 [placard insertSubview:background atIndex:0];
1319 [table setBackgroundColor:[UIColor clearColor]];
1320 [placard insertSubview:background belowSubview:table];
1325 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1326 int id(_UISharedImageNameGetIdentifier(name));
1328 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1331 return _UIImageAtPath(name, _UIKitBundle());
1333 NSNumber *key([NSNumber numberWithInt:id]);
1334 UIImage *image = [UIImages_ objectForKey:key];
1336 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1337 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1338 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1340 [image autorelease];
1342 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1343 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1347 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1348 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1349 UIImage *image([PathImages_ objectForKey:key]);
1351 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1353 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1354 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1355 image = [[UIImage alloc] initWithContentsOfFile:path];
1357 [image autorelease];
1359 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1360 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1363 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1365 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1366 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1367 name = [font UTF8String];
1368 return _GSFontCreateWithName(name, traits, size);
1371 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1372 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1374 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1376 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1378 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1379 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1381 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1384 NSString *path = [NSString stringWithUTF8String:a1];
1385 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1386 NSString *file = [path substringFromIndex:31];
1387 for (NSString *theme in themes_) {
1388 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1389 if ([Manager_ fileExistsAtPath:path]) {
1390 strcpy(a1, [path UTF8String]);
1399 static void ChangeWallpaper(
1400 CFNotificationCenterRef center,
1404 CFDictionaryRef info
1407 NSLog(@"WB:Debug:ChangeWallpaper!");
1410 if (WallpaperFile_ != nil) {
1411 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1413 image = [image autorelease];
1416 if (WallpaperImage_ != nil)
1417 [WallpaperImage_ setImage:image];
1418 if (WallpaperPage_ != nil)
1419 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1423 #define WBRename(name, sel, imp) \
1424 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1426 template <typename Type_>
1427 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1428 struct nlist &name(nl[index]);
1429 uintptr_t value(name.n_value);
1430 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1431 value |= 0x00000001;
1432 function = reinterpret_cast<Type_>(value);
1435 template <typename Type_>
1436 static void dlset(Type_ &function, const char *name) {
1437 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1440 extern "C" void WBInitialize() {
1441 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1443 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1445 NSLog(@"WB:Notice: WinterBoard");
1447 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1451 memset(nl, 0, sizeof(nl));
1452 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1453 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1454 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1455 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1456 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1457 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1458 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1461 nlset(_UIApplicationImageWithName, nl, 0);
1462 nlset(_UIImageAtPath, nl, 1);
1463 nlset(_UIImageRefAtPath, nl, 2);
1464 nlset(_UIImageWithNameInDomain, nl, 3);
1465 nlset(_UIKitBundle, nl, 4);
1466 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1467 nlset(_UISharedImageWithIdentifier, nl, 6);
1469 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1470 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1471 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1472 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1474 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1476 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1478 memset(nl, 0, sizeof(nl));
1479 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1480 nlist(AudioToolbox, nl);
1481 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1482 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1485 $NSBundle = objc_getClass("NSBundle");
1487 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1488 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1490 $UIImage = objc_getClass("UIImage");
1491 $UINavigationBar = objc_getClass("UINavigationBar");
1492 $UIToolbar = objc_getClass("UIToolbar");
1494 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1496 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1497 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1499 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1500 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1502 Manager_ = [[NSFileManager defaultManager] retain];
1503 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1504 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1505 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1506 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1507 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1509 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1511 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1512 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1513 SummerBoard_ = [value boolValue];
1514 if (NSNumber *value = [settings objectForKey:@"Debug"])
1515 Debug_ = [value boolValue];
1517 NSArray *themes([settings objectForKey:@"Themes"]);
1519 if (NSString *theme = [settings objectForKey:@"Theme"])
1520 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1522 [NSNumber numberWithBool:true], @"Active",
1526 for (NSDictionary *theme in themes) {
1527 NSNumber *active([theme objectForKey:@"Active"]);
1528 if (![active boolValue])
1531 NSString *name([theme objectForKey:@"Name"]);
1535 NSString *theme(nil);
1537 #define testForTheme(format...) \
1538 if (theme == nil) { \
1539 NSString *path = [NSString stringWithFormat:format]; \
1540 if ([Manager_ fileExistsAtPath:path]) { \
1541 [themes_ addObject:path]; \
1546 testForTheme(@"/Library/Themes/%@.theme", name)
1547 testForTheme(@"/Library/Themes/%@", name)
1548 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1553 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1555 for (NSString *theme in themes_)
1556 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1557 for (NSString *key in [info allKeys])
1558 if ([Info_ objectForKey:key] == nil)
1559 [Info_ setObject:[info objectForKey:key] forKey:key];
1561 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1563 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1565 $CKMessageCell = objc_getClass("CKMessageCell");
1566 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1567 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1569 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1570 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1571 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1573 $CKTimestampView = objc_getClass("CKTimestampView");
1574 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1576 $CKTranscriptController = objc_getClass("CKTranscriptController");
1577 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1580 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1582 if (_TranscriptController$loadView == NULL) {
1583 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1584 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1587 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1588 CFNotificationCenterAddObserver(
1589 CFNotificationCenterGetDarwinNotifyCenter(),
1590 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1593 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
1594 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1595 if (MediaPlayer != nil)
1598 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1599 $MPVideoView = objc_getClass("MPVideoView");
1602 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1604 $SBApplication = objc_getClass("SBApplication");
1605 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1606 $SBAwayView = objc_getClass("SBAwayView");
1607 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1608 $SBButtonBar = objc_getClass("SBButtonBar");
1609 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1610 $SBIcon = objc_getClass("SBIcon");
1611 $SBIconBadge = objc_getClass("SBIconBadge");
1612 $SBIconController = objc_getClass("SBIconController");
1613 $SBIconLabel = objc_getClass("SBIconLabel");
1614 $SBIconList = objc_getClass("SBIconList");
1615 $SBIconModel = objc_getClass("SBIconModel");
1616 //$SBImageCache = objc_getClass("SBImageCache");
1617 $SBSearchView = objc_getClass("SBSearchView");
1618 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1619 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1620 $SBStatusBarController = objc_getClass("SBStatusBarController");
1621 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1622 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1623 $SBUIController = objc_getClass("SBUIController");
1624 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1626 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1629 WBRename(SBApplication, pathForIcon, pathForIcon);
1630 WBRename(SBApplicationIcon, icon, icon);
1631 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
1634 WBRename(SBBookmarkIcon, icon, icon);
1635 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1636 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1637 WBRename(SBIcon, setAlpha:, setAlpha$);
1638 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1639 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1640 WBRename(SBUIController, init, init);
1641 WBRename(SBWidgetApplicationIcon, icon, icon);
1643 WBRename(SBIconLabel, drawRect:, drawRect$);
1644 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1645 WBRename(SBIconLabel, setInDock:, setInDock$);
1647 WBRename(SBIconList, setFrame:, setFrame$);
1649 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1650 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1651 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1652 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1654 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1655 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1656 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1658 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1660 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1661 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1662 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1663 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1664 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1665 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1666 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1667 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1668 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1671 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1673 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1676 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1677 Papered_ = $getTheme$(Wallpapers_) != nil;
1679 UIDevice *device([UIDevice currentDevice]);
1680 IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
1682 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1683 [Info_ setObject:[NSNumber numberWithBool:(
1685 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1686 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1687 )] forKey:@"UndockedIconLabels"];
1690 NSLog(@"WB:Debug:Info = %@", [Info_ description]);