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())
175 static bool Debug_ = false;
176 static bool Engineer_ = false;
177 static bool SummerBoard_ = true;
178 static bool SpringBoard_;
180 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
181 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
182 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
183 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
184 static NSBundle *(*_UIKitBundle)();
185 static int (*_UISharedImageNameGetIdentifier)(NSString *);
186 static UIImage *(*_UISharedImageWithIdentifier)(int);
188 static NSMutableDictionary *UIImages_;
189 static NSMutableDictionary *PathImages_;
190 static NSMutableDictionary *Cache_;
191 static NSMutableDictionary *Strings_;
192 static NSMutableDictionary *Themed_;
193 static NSMutableDictionary *Bundles_;
195 static NSFileManager *Manager_;
196 static NSDictionary *English_;
197 static NSMutableDictionary *Info_;
198 static NSMutableArray *themes_;
200 static NSString *$getTheme$(NSArray *files, bool parent = false) {
202 if (NSString *path = [Themed_ objectForKey:files])
203 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
206 NSLog(@"WB:Debug: %@", [files description]);
210 for (NSString *theme in themes_)
211 for (NSString *file in files) {
212 path = [NSString stringWithFormat:@"%@/%@", theme, file];
213 if ([Manager_ fileExistsAtPath:path]) {
214 path = parent ? theme : path;
222 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
226 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
227 NSString *identifier = [bundle bundleIdentifier];
228 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
230 if (identifier != nil)
231 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
232 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
233 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
235 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
237 #define remapResourceName(oldname, newname) \
238 else if ([file isEqualToString:oldname]) \
239 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
241 bool summer(SpringBoard_ && SummerBoard_);
243 if (identifier == nil);
244 else if ([identifier isEqualToString:@"com.apple.chatkit"])
245 [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
246 else if ([identifier isEqualToString:@"com.apple.calculator"])
247 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
249 remapResourceName(@"FSO_BG.png", @"StatusBar")
250 remapResourceName(@"SBDockBG.png", @"Dock")
251 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
253 if (NSString *path = $getTheme$(names))
259 static NSString *$pathForIcon$(SBApplication *self) {
260 NSString *identifier = [self bundleIdentifier];
261 NSString *path = [self path];
262 NSString *folder = [path lastPathComponent];
263 NSString *dname = [self displayName];
264 NSString *didentifier = [self displayIdentifier];
267 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
269 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
271 /* XXX: I might need to keep this for backwards compatibility
272 if (identifier != nil)
273 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
275 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */
277 #define testForIcon(Name) \
278 if (NSString *name = Name) \
279 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
281 if (![didentifier isEqualToString:identifier])
282 testForIcon(didentifier);
284 testForIcon(identifier);
287 if ([identifier isEqualToString:@"com.apple.MobileSMS"])
290 if (didentifier != nil) {
291 testForIcon([English_ objectForKey:didentifier]);
293 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
294 if ([parts count] != 1)
295 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
296 testForIcon([english objectForKey:[parts lastObject]]);
299 if (NSString *path = $getTheme$(names))
305 @interface NSBundle (WinterBoard)
306 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
309 @implementation NSBundle (WinterBoard)
311 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
312 path = [path stringByDeletingLastPathComponent];
313 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
316 NSBundle *bundle([Bundles_ objectForKey:path]);
317 if (reinterpret_cast<id>(bundle) == [NSNull null])
319 else if (bundle == nil) {
320 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
321 bundle = [NSBundle bundleWithPath:path];
323 bundle = [NSBundle wb$bundleWithFile:path];
325 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
326 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
334 @interface NSString (WinterBoard)
335 - (NSString *) wb$themedPath;
338 @implementation NSString (WinterBoard)
340 - (NSString *) wb$themedPath {
342 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
344 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
345 NSString *file([self stringByResolvingSymlinksInPath]);
346 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
347 if ([file hasPrefix:prefix]) {
348 NSUInteger length([prefix length]);
349 if (length != [file length])
350 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
360 void WBLogRect(const char *tag, struct CGRect rect) {
361 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
364 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
365 CGRect frame([view frame]);
366 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]);
368 for (UIView *child in [view subviews])
369 WBLogHierarchy(child, index++, indent + 1);
372 UIImage *$cacheForImage$(UIImage *image) {
373 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
374 CGRect rect = {CGPointMake(1, 1), [image size]};
375 CGSize size = {rect.size.width + 2, rect.size.height + 2};
377 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
378 CGColorSpaceRelease(space);
380 CGContextDrawImage(context, rect, [image CGImage]);
381 CGImageRef ref(CGBitmapContextCreateImage(context));
382 CGContextRelease(context);
384 UIImage *cache([UIImage imageWithCGImage:ref]);
390 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
391 //if ([name isEqualToString:@"icons"]) return nil;
392 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
395 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
396 NSString *key([icon displayIdentifier]);
398 if (UIImage *image = [icon icon]) {
399 CGSize size = [image size];
400 if (size.width != 59 || size.height != 60) {
401 UIImage *cache($cacheForImage$(image));
402 [Cache_ setObject:cache forKey:key];
407 _SBIconModel$cacheImageForIcon$(self, sel, icon);
410 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
411 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
412 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
414 NSString *key([icon displayIdentifier]);
416 if (UIImage *image = [icon icon]) {
417 CGSize size = [image size];
418 if (size.width != 59 || size.height != 60) {
419 UIImage *cache($cacheForImage$(image));
420 [Cache_ setObject:cache forKey:key];
426 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
427 NSString *key([icon displayIdentifier]);
428 if (UIImage *image = [Cache_ objectForKey:key])
431 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
434 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
436 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
437 NSString *key([icon displayIdentifier]);
438 if (UIImage *image = [Cache_ objectForKey:key])
441 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
444 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
445 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
446 [self setBackgroundColor:[UIColor clearColor]];
447 for (UIView *child in [self subviews])
448 [child setBackgroundColor:[UIColor clearColor]];
452 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
453 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
454 [self setBackgroundColor:[UIColor clearColor]];
458 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
459 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
460 float inset([self edgeInset]);
461 [[UIColor clearColor] set];
462 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
463 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
466 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
467 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
468 if (NSString *path = $pathForIcon$([self application]))
469 return [UIImage imageWithContentsOfFile:path];
470 return _SBApplicationIcon$icon(self, sel);
473 MSHook(UIImage *, SBApplicationIcon$generateIconImage$, SBApplicationIcon *self, SEL sel, int type) {
475 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
476 if (NSString *path = $pathForIcon$([self application]))
477 if (UIImage *image = [UIImage imageWithContentsOfFile:path])
478 return [image _imageScaledToProportion:1.2 interpolationQuality:5];
479 return _SBApplicationIcon$generateIconImage$(self, sel, type);
482 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
484 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
485 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
486 return [UIImage imageWithContentsOfFile:path];
487 return _SBWidgetApplicationIcon$icon(self, sel);
490 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
492 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
493 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
494 return [UIImage imageWithContentsOfFile:path];
495 return _SBBookmarkIcon$icon(self, sel);
498 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
499 if (NSString *path = $pathForIcon$(self))
501 return _SBApplication$pathForIcon(self, sel);
504 static UIImage *CachedImageAtPath(NSString *path) {
505 path = [path stringByResolvingSymlinksInPath];
506 UIImage *image = [PathImages_ objectForKey:path];
508 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
509 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
511 image = [image autorelease];
512 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
516 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
518 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
520 NSString *themed([name wb$themedPath]);
522 if (false && SpringBoard_ && SummerBoard_ && themed == name) {
523 if ([name isEqualToString:@"/System/Library/CoreServices/SpringBoard.app/SBDockBGT-Portrait.png"])
524 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Dock.png"])) {
525 UIImage *image([UIImage imageWithContentsOfFile:path]);
526 CGImageRef ref([[image _imageScaledToProportion:2.4 interpolationQuality:5] imageRef]);
532 return __UIImageRefAtPath(themed, cache, orientation);
535 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
537 return __UIImageAtPath(name, nil);
539 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
540 UIImage *image = [PathImages_ objectForKey:key];
542 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
544 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
545 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
546 image = CachedImageAtPath(path);
548 image = __UIImageAtPath(name, bundle);
549 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
554 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
555 NSBundle *bundle = [NSBundle mainBundle];
557 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
558 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
559 return CachedImageAtPath(path);
560 return __UIApplicationImageWithName(name);
563 #define WBDelegate(delegate) \
564 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
566 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
567 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
569 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
573 - (void) forwardInvocation:(NSInvocation*)inv { \
574 SEL sel = [inv selector]; \
575 if ([delegate respondsToSelector:sel]) \
576 [inv invokeWithTarget:delegate]; \
578 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
581 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
582 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
584 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
585 if (NSString *path = $pathForFile$inBundle$(file, self, false))
587 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
590 void $setBarStyle$_(NSString *name, int &style) {
592 NSLog(@"WB:Debug:%@Style:%d", name, style);
593 NSNumber *number = nil;
595 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
597 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
599 style = [number intValue];
601 NSLog(@"WB:Debug:%@Style=%d", name, style);
605 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
606 NSBundle *bundle([NSBundle mainBundle]);
608 CFLocaleRef locale(CFLocaleCopyCurrent());
609 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
612 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
614 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
615 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
616 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
617 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
621 CFRelease(formatter);
623 NSString *datestyle([@""
624 "font-family: Helvetica; "
625 "font-weight: bold; "
628 "" stringByAppendingString:(IsWild_
629 ? @"font-size: 54px; "
630 : @"font-size: 39px; "
633 NSString *daystyle([@""
634 "font-family: Helvetica; "
635 "font-weight: bold; "
637 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
638 "" stringByAppendingString:(IsWild_
639 ? @"font-size: 11px; "
640 : @"font-size: 9px; "
643 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
644 datestyle = [datestyle stringByAppendingString:style];
645 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
646 daystyle = [daystyle stringByAppendingString:style];
648 float width([self bounds].size.width);
650 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
651 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
653 unsigned base(IsWild_ ? 89 : 70);
654 if ($GSFontGetUseLegacyFontMetrics())
657 [(NSString *)date drawAtPoint:CGPointMake(
658 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
659 ) withStyle:datestyle];
661 [(NSString *)day drawAtPoint:CGPointMake(
662 (width + 1 - daysize.width) / 2, ((IsWild_ ? 18 : 16) - daysize.height) / 2
663 ) withStyle:daystyle];
669 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
672 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
673 style = [number intValue];
675 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
678 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
681 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
682 self = [self wb$initWithCoder:coder];
685 UINavigationBar$setBarStyle$_(self);
689 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
690 self = [self wb$initWithFrame:frame];
693 UINavigationBar$setBarStyle$_(self);
697 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
698 $setBarStyle$_(@"Toolbar", style);
699 return _UIToolbar$setBarStyle$(self, sel, style);
702 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
703 $setBarStyle$_(@"NavigationBar", style);
704 return _UINavigationBar$setBarStyle$(self, sel, style);
707 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
708 [[self superview] setBackgroundColor:[UIColor clearColor]];
709 _SBButtonBar$didMoveToSuperview(self, sel);
712 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
713 [[self superview] setBackgroundColor:[UIColor clearColor]];
714 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
717 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
719 NSLog(@"WB:Debug:DefaultDesktopImage");
720 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
721 return [UIImage imageWithContentsOfFile:path];
722 return _UIImage$defaultDesktopImage(self, sel);
725 static NSArray *Wallpapers_;
726 static bool Papered_;
727 static NSString *WallpaperFile_;
728 static UIImageView *WallpaperImage_;
729 static UIWebDocumentView *WallpaperPage_;
730 static NSURL *WallpaperURL_;
732 #define _release(object) \
733 do if (object != nil) { \
738 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
739 self = _SBUIController$init(self, sel);
744 UIWindow *&_wallpaperView(MSHookIvar<UIWindow *>(self, "_wallpaperView"));
745 if (&_wallpaperView != NULL) {
746 [_wallpaperView removeFromSuperview];
747 [_wallpaperView release];
748 _wallpaperView = nil;
752 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
753 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
754 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
757 if (&_contentLayer != NULL)
758 layer = _contentLayer;
759 else if (&_contentView != NULL)
760 layer = _contentView;
764 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
766 [content setBackgroundColor:[layer backgroundColor]];
767 [layer setBackgroundColor:[UIColor clearColor]];
768 [layer setFrame:[content bounds]];
769 [_window setContentView:content];
772 if (!SummerBoard_ || !IsWild_)
775 CGRect bounds([content bounds]);
776 bounds.origin.y = -30;
777 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
778 [content addSubview:indirect];
779 [indirect zoomToScale:2.4];
782 _release(WallpaperFile_);
783 _release(WallpaperImage_);
784 _release(WallpaperPage_);
785 _release(WallpaperURL_);
787 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
788 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
789 if ([Manager_ fileExistsAtPath:mp4]) {
793 static AVController *controller_(nil);
794 if (controller_ == nil) {
795 AVQueue *queue([AVQueue avQueue]);
796 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
799 AVQueue *queue([controller_ queue]);
801 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
802 [controller_ setLayer:[video _layer]];
804 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
805 [queue appendItem:item error:&error];
807 [controller_ play:&error];
808 #elif UseMPMoviePlayerController
809 NSURL *url([NSURL fileURLWithPath:mp4]);
810 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
811 controller.movieControlMode = MPMovieControlModeHidden;
814 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
815 [video setMovieWithPath:mp4];
816 [video setRepeatMode:1];
817 [video setRepeatGap:-1];
818 [video playFromBeginning];;
821 [indirect addSubview:video];
824 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
825 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
828 if ([Manager_ fileExistsAtPath:png])
830 else if ([Manager_ fileExistsAtPath:jpg])
836 image = [[UIImage alloc] initWithContentsOfFile:path];
838 image = [image autorelease];
842 WallpaperFile_ = [path retain];
843 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
844 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
845 [WallpaperImage_ setAlpha:[number floatValue]];
846 [indirect addSubview:WallpaperImage_];
849 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
850 if ([Manager_ fileExistsAtPath:html]) {
851 CGRect bounds = [indirect bounds];
853 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
854 [view setAutoresizes:true];
856 WallpaperPage_ = [view retain];
857 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
859 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
861 [view setBackgroundColor:[UIColor clearColor]];
862 if ([view respondsToSelector:@selector(setDrawsBackground:)])
863 [view setDrawsBackground:NO];
864 [[view webView] setDrawsBackground:NO];
866 [indirect addSubview:view];
870 for (size_t i(0), e([themes_ count]); i != e; ++i) {
871 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
872 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
873 if ([Manager_ fileExistsAtPath:html]) {
874 CGRect bounds = [indirect bounds];
876 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
877 [view setAutoresizes:true];
879 NSURL *url = [NSURL fileURLWithPath:html];
880 [view loadRequest:[NSURLRequest requestWithURL:url]];
882 [view setBackgroundColor:[UIColor clearColor]];
883 if ([view respondsToSelector:@selector(setDrawsBackground:)])
884 [view setDrawsBackground:NO];
885 [[view webView] setDrawsBackground:NO];
887 [indirect addSubview:view];
891 [content addSubview:layer];
896 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
897 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
898 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
900 if (path != nil && _backgroundView != nil)
903 _SBAwayView$updateDesktopImage$(self, sel, image);
906 CGRect bounds = [self bounds];
908 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
909 [view setAutoresizes:true];
911 if (WallpaperPage_ != nil)
912 [WallpaperPage_ release];
913 WallpaperPage_ = [view retain];
915 if (WallpaperURL_ != nil)
916 [WallpaperURL_ release];
917 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
919 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
921 [[view webView] setDrawsBackground:false];
922 [view setBackgroundColor:[UIColor clearColor]];
924 [self insertSubview:view aboveSubview:_backgroundView];
928 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
929 extern "C" CGColorRef CGGStateGetFillColor(void *);
930 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
931 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
933 /* WBTimeLabel {{{ */
934 @interface WBTimeLabel : NSProxy {
936 _transient SBStatusBarTimeView *view_;
939 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
943 @implementation WBTimeLabel
950 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
951 time_ = [time retain];
956 - (NSString *) description {
962 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
963 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
964 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
966 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
967 "font-family: Helvetica; "
968 "font-weight: bold; "
971 "%@", _mode ? @"white" : @"black", custom]];
976 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
981 /* WBBadgeLabel {{{ */
982 @interface WBBadgeLabel : NSProxy {
986 - (id) initWithBadge:(NSString *)badge;
987 - (NSString *) description;
991 @implementation WBBadgeLabel
998 - (id) initWithBadge:(NSString *)badge {
999 badge_ = [badge retain];
1003 - (NSString *) description {
1004 return [badge_ description];
1009 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
1010 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
1011 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
1012 "font-family: Helvetica; "
1013 "font-weight: bold; "
1021 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1027 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1028 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1029 alpha = [number floatValue];
1030 return _SBIcon$setAlpha$(self, sel, alpha);
1033 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1034 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
1035 id &_badge(MSHookIvar<id>(self, "_badge"));
1037 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1042 void SBStatusBarController$setStatusBarMode(int &mode) {
1044 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
1045 if (mode < 100) // 104:hidden 105:glowing
1046 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1047 mode = [number intValue];
1050 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1051 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1052 SBStatusBarController$setStatusBarMode(mode);
1053 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1056 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
1057 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
1058 SBStatusBarController$setStatusBarMode(mode);
1059 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1062 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) {
1063 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1064 SBStatusBarController$setStatusBarMode(mode);
1065 //NSLog(@"mode=%u", mode);
1066 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1069 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1070 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1071 mode = [number intValue];
1072 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1075 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1076 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1078 NSLog(@"operatorNameStyle= %@", style);
1079 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1080 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1084 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1086 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1087 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1090 // XXX: replace this with [SBStatusBarTimeView tile]
1091 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1092 id &_time(MSHookIvar<id>(self, "_time"));
1093 if (_time != nil && [_time class] != [WBTimeLabel class])
1094 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1095 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1098 @interface UIView (WinterBoard)
1099 - (bool) wb$isWBImageView;
1100 - (void) wb$logHierarchy;
1103 @implementation UIView (WinterBoard)
1105 - (bool) wb$isWBImageView {
1109 - (void) wb$logHierarchy {
1110 WBLogHierarchy(self);
1115 @interface WBImageView : UIImageView {
1118 - (bool) wb$isWBImageView;
1119 - (void) wb$updateFrame;
1122 @implementation WBImageView
1124 - (bool) wb$isWBImageView {
1128 - (void) wb$updateFrame {
1129 CGRect frame([self frame]);
1132 for (UIView *view(self); ; ) {
1133 view = [view superview];
1136 frame.origin.y -= [view frame].origin.y;
1139 [self setFrame:frame];
1144 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1145 NSArray *subviews([self subviews]);
1146 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1147 if (view != nil && [view wb$isWBImageView])
1148 [view wb$updateFrame];
1149 _SBIconList$setFrame$(self, sel, frame);
1152 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1153 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1154 NSArray *lists([_iconModel iconLists]);
1156 for (unsigned i(0), e([lists count]); i != e; ++i)
1157 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1158 SBIconList *list([lists objectAtIndex:i]);
1159 NSArray *subviews([list subviews]);
1161 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1162 if (view == nil || ![view wb$isWBImageView]) {
1163 view = [[[WBImageView alloc] init] autorelease];
1164 [list insertSubview:view atIndex:0];
1167 UIImage *image([UIImage imageWithContentsOfFile:path]);
1169 CGRect frame([view frame]);
1170 frame.size = [image size];
1171 [view setFrame:frame];
1173 [view setImage:image];
1174 [view wb$updateFrame];
1177 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1180 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1181 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1183 [self setClipsToBounds:NO];
1187 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1188 id &_label(MSHookIvar<id>(self, "_label"));
1189 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1191 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1192 [_label setInDock:docked];
1193 return _SBIconLabel$setInDock$(self, sel, docked);
1196 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1197 NSString *identifier = [self bundleIdentifier];
1198 NSLocale *locale = [NSLocale currentLocale];
1199 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1201 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1202 NSString *file = table == nil ? @"Localizable" : table;
1203 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1204 NSDictionary *strings;
1205 if ((strings = [Strings_ objectForKey:name]) != nil) {
1206 if (static_cast<id>(strings) != [NSNull null]) strings:
1207 if (NSString *value = [strings objectForKey:key])
1209 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1212 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1213 [Strings_ setObject:[strings autorelease] forKey:name];
1217 [Strings_ setObject:[NSNull null] forKey:name];
1218 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1221 @class WebCoreFrameBridge;
1222 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1225 void **core(reinterpret_cast<void **>([node _node]));
1226 if (core == NULL || core[6] == NULL)
1228 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1231 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1232 CGRect bounds = [self bounds];
1234 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1237 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1238 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1240 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1242 NSString *style = [NSString stringWithFormat:@""
1243 "font-family: Helvetica; "
1244 "font-weight: bold; "
1246 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
1247 ? @"font-size: 12px; "
1248 : @"font-size: 11px; "
1252 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1254 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1256 bool ellipsis(false);
1257 float max = 75, width;
1259 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1262 size_t length([label length]);
1263 float spacing((width - max) / (length - 1));
1265 if (spacing > 1.25) {
1267 label = [label substringToIndex:(length - 1)];
1271 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1275 label = [label stringByAppendingString:@"..."];
1277 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1278 style = [style stringByAppendingString:custom];
1280 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1281 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1284 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1285 _CKMessageCell$addBalloonView$(self, sel, balloon);
1286 [balloon setBackgroundColor:[UIColor clearColor]];
1289 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1290 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1291 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1295 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1296 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1297 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1298 [_label setBackgroundColor:[UIColor clearColor]];
1302 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1303 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1306 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1308 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1309 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1313 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1314 _TranscriptController$loadView(self, sel);
1316 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1317 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1318 [image autorelease];
1320 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1321 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1323 if (&_transcriptTable != NULL)
1324 table = _transcriptTable;
1325 else if (&_transcriptLayer != NULL)
1326 table = _transcriptLayer;
1330 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1331 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1334 [placard insertSubview:background atIndex:0];
1336 [table setBackgroundColor:[UIColor clearColor]];
1337 [placard insertSubview:background belowSubview:table];
1342 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1343 int id(_UISharedImageNameGetIdentifier(name));
1345 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1348 return _UIImageAtPath(name, _UIKitBundle());
1350 NSNumber *key([NSNumber numberWithInt:id]);
1351 UIImage *image = [UIImages_ objectForKey:key];
1353 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1354 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1355 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1357 [image autorelease];
1359 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1360 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1364 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1365 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1366 UIImage *image([PathImages_ objectForKey:key]);
1368 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1370 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1371 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1372 image = [[UIImage alloc] initWithContentsOfFile:path];
1374 [image autorelease];
1376 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1377 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1380 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1382 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1383 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1384 name = [font UTF8String];
1385 //if (NSString *scale = [Info_ objectForKey:[NSString stringWithFormat:@"FontScale-%s", name]])
1386 // size *= [scale floatValue];
1387 return _GSFontCreateWithName(name, traits, size);
1390 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1391 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1393 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1395 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1397 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1398 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1400 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1403 NSString *path = [NSString stringWithUTF8String:a1];
1404 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1405 NSString *file = [path substringFromIndex:31];
1406 for (NSString *theme in themes_) {
1407 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1408 if ([Manager_ fileExistsAtPath:path]) {
1409 strcpy(a1, [path UTF8String]);
1418 static void ChangeWallpaper(
1419 CFNotificationCenterRef center,
1423 CFDictionaryRef info
1426 NSLog(@"WB:Debug:ChangeWallpaper!");
1429 if (WallpaperFile_ != nil) {
1430 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1432 image = [image autorelease];
1435 if (WallpaperImage_ != nil)
1436 [WallpaperImage_ setImage:image];
1437 if (WallpaperPage_ != nil)
1438 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1442 #define WBRename(name, sel, imp) \
1443 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1445 template <typename Type_>
1446 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1447 struct nlist &name(nl[index]);
1448 uintptr_t value(name.n_value);
1449 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1450 value |= 0x00000001;
1451 function = reinterpret_cast<Type_>(value);
1454 template <typename Type_>
1455 static void dlset(Type_ &function, const char *name) {
1456 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1459 extern "C" void WBInitialize() {
1460 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1462 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1464 NSLog(@"WB:Notice: WinterBoard");
1466 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1470 memset(nl, 0, sizeof(nl));
1471 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1472 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1473 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1474 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1475 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1476 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1477 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1480 nlset(_UIApplicationImageWithName, nl, 0);
1481 nlset(_UIImageAtPath, nl, 1);
1482 nlset(_UIImageRefAtPath, nl, 2);
1483 nlset(_UIImageWithNameInDomain, nl, 3);
1484 nlset(_UIKitBundle, nl, 4);
1485 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1486 nlset(_UISharedImageWithIdentifier, nl, 6);
1488 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1489 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1490 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1491 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1493 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1495 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1497 memset(nl, 0, sizeof(nl));
1498 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1499 nlist(AudioToolbox, nl);
1500 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1501 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1504 $NSBundle = objc_getClass("NSBundle");
1506 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1507 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1509 $UIImage = objc_getClass("UIImage");
1510 $UINavigationBar = objc_getClass("UINavigationBar");
1511 $UIToolbar = objc_getClass("UIToolbar");
1513 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1515 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1516 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1518 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1519 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1521 Manager_ = [[NSFileManager defaultManager] retain];
1522 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1523 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1524 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1525 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1526 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1528 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1530 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1531 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1532 SummerBoard_ = [value boolValue];
1533 if (NSNumber *value = [settings objectForKey:@"Debug"])
1534 Debug_ = [value boolValue];
1536 NSArray *themes([settings objectForKey:@"Themes"]);
1538 if (NSString *theme = [settings objectForKey:@"Theme"])
1539 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1541 [NSNumber numberWithBool:true], @"Active",
1545 for (NSDictionary *theme in themes) {
1546 NSNumber *active([theme objectForKey:@"Active"]);
1547 if (![active boolValue])
1550 NSString *name([theme objectForKey:@"Name"]);
1554 NSString *theme(nil);
1556 #define testForTheme(format...) \
1557 if (theme == nil) { \
1558 NSString *path = [NSString stringWithFormat:format]; \
1559 if ([Manager_ fileExistsAtPath:path]) { \
1560 [themes_ addObject:path]; \
1565 testForTheme(@"/Library/Themes/%@.theme", name)
1566 testForTheme(@"/Library/Themes/%@", name)
1567 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1572 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1574 for (NSString *theme in themes_)
1575 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1576 for (NSString *key in [info allKeys])
1577 if ([Info_ objectForKey:key] == nil)
1578 [Info_ setObject:[info objectForKey:key] forKey:key];
1580 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1582 SpringBoard_ = [identifier isEqualToString:@"com.apple.springboard"];
1584 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1586 $CKMessageCell = objc_getClass("CKMessageCell");
1587 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1588 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1590 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1591 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1592 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1594 $CKTimestampView = objc_getClass("CKTimestampView");
1595 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1597 $CKTranscriptController = objc_getClass("CKTranscriptController");
1598 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1601 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1603 if (_TranscriptController$loadView == NULL) {
1604 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1605 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1608 } else if (SpringBoard_) {
1609 CFNotificationCenterAddObserver(
1610 CFNotificationCenterGetDarwinNotifyCenter(),
1611 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1614 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
1615 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1616 if (MediaPlayer != nil)
1619 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1620 $MPVideoView = objc_getClass("MPVideoView");
1623 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1625 $SBApplication = objc_getClass("SBApplication");
1626 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1627 $SBAwayView = objc_getClass("SBAwayView");
1628 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1629 $SBButtonBar = objc_getClass("SBButtonBar");
1630 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1631 $SBIcon = objc_getClass("SBIcon");
1632 $SBIconBadge = objc_getClass("SBIconBadge");
1633 $SBIconController = objc_getClass("SBIconController");
1634 $SBIconLabel = objc_getClass("SBIconLabel");
1635 $SBIconList = objc_getClass("SBIconList");
1636 $SBIconModel = objc_getClass("SBIconModel");
1637 //$SBImageCache = objc_getClass("SBImageCache");
1638 $SBSearchView = objc_getClass("SBSearchView");
1639 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1640 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1641 $SBStatusBarController = objc_getClass("SBStatusBarController");
1642 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1643 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1644 $SBUIController = objc_getClass("SBUIController");
1645 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1647 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1650 WBRename(SBApplication, pathForIcon, pathForIcon);
1651 WBRename(SBApplicationIcon, icon, icon);
1652 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
1655 WBRename(SBBookmarkIcon, icon, icon);
1656 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1657 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1658 WBRename(SBIcon, setAlpha:, setAlpha$);
1659 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1660 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1661 WBRename(SBUIController, init, init);
1662 WBRename(SBWidgetApplicationIcon, icon, icon);
1664 WBRename(SBIconLabel, drawRect:, drawRect$);
1665 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1666 WBRename(SBIconLabel, setInDock:, setInDock$);
1668 WBRename(SBIconList, setFrame:, setFrame$);
1670 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1671 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1672 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1673 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1675 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1676 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1677 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1679 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1681 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1682 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1683 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1684 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1685 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1686 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1687 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1688 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1689 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1692 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1694 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1697 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1698 Papered_ = $getTheme$(Wallpapers_) != nil;
1700 UIDevice *device([UIDevice currentDevice]);
1701 IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
1703 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1704 [Info_ setObject:[NSNumber numberWithBool:(
1706 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1707 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1708 )] forKey:@"UndockedIconLabels"];
1711 NSLog(@"WB:Debug:Info = %@", [Info_ description]);