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);
743 UIDevice *device([UIDevice currentDevice]);
744 IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
747 UIWindow *&_wallpaperView(MSHookIvar<UIWindow *>(self, "_wallpaperView"));
748 if (&_wallpaperView != NULL) {
749 [_wallpaperView removeFromSuperview];
750 [_wallpaperView release];
751 _wallpaperView = nil;
755 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
756 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
757 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
760 if (&_contentLayer != NULL)
761 layer = _contentLayer;
762 else if (&_contentView != NULL)
763 layer = _contentView;
767 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
769 [content setBackgroundColor:[layer backgroundColor]];
770 [layer setBackgroundColor:[UIColor clearColor]];
771 [layer setFrame:[content bounds]];
772 [_window setContentView:content];
775 if (!SummerBoard_ || !IsWild_)
778 CGRect bounds([content bounds]);
779 bounds.origin.y = -30;
780 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
781 [content addSubview:indirect];
782 [indirect zoomToScale:2.4];
785 _release(WallpaperFile_);
786 _release(WallpaperImage_);
787 _release(WallpaperPage_);
788 _release(WallpaperURL_);
790 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
791 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
792 if ([Manager_ fileExistsAtPath:mp4]) {
796 static AVController *controller_(nil);
797 if (controller_ == nil) {
798 AVQueue *queue([AVQueue avQueue]);
799 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
802 AVQueue *queue([controller_ queue]);
804 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
805 [controller_ setLayer:[video _layer]];
807 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
808 [queue appendItem:item error:&error];
810 [controller_ play:&error];
811 #elif UseMPMoviePlayerController
812 NSURL *url([NSURL fileURLWithPath:mp4]);
813 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
814 controller.movieControlMode = MPMovieControlModeHidden;
817 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
818 [video setMovieWithPath:mp4];
819 [video setRepeatMode:1];
820 [video setRepeatGap:-1];
821 [video playFromBeginning];;
824 [indirect addSubview:video];
827 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
828 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
831 if ([Manager_ fileExistsAtPath:png])
833 else if ([Manager_ fileExistsAtPath:jpg])
839 image = [[UIImage alloc] initWithContentsOfFile:path];
841 image = [image autorelease];
845 WallpaperFile_ = [path retain];
846 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
847 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
848 [WallpaperImage_ setAlpha:[number floatValue]];
849 [indirect addSubview:WallpaperImage_];
852 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
853 if ([Manager_ fileExistsAtPath:html]) {
854 CGRect bounds = [indirect bounds];
856 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
857 [view setAutoresizes:true];
859 WallpaperPage_ = [view retain];
860 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
862 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
864 [view setBackgroundColor:[UIColor clearColor]];
865 if ([view respondsToSelector:@selector(setDrawsBackground:)])
866 [view setDrawsBackground:NO];
867 [[view webView] setDrawsBackground:NO];
869 [indirect addSubview:view];
873 for (size_t i(0), e([themes_ count]); i != e; ++i) {
874 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
875 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
876 if ([Manager_ fileExistsAtPath:html]) {
877 CGRect bounds = [indirect bounds];
879 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
880 [view setAutoresizes:true];
882 NSURL *url = [NSURL fileURLWithPath:html];
883 [view loadRequest:[NSURLRequest requestWithURL:url]];
885 [view setBackgroundColor:[UIColor clearColor]];
886 if ([view respondsToSelector:@selector(setDrawsBackground:)])
887 [view setDrawsBackground:NO];
888 [[view webView] setDrawsBackground:NO];
890 [indirect addSubview:view];
894 [content addSubview:layer];
899 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
900 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
901 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
903 if (path != nil && _backgroundView != nil)
906 _SBAwayView$updateDesktopImage$(self, sel, image);
909 CGRect bounds = [self bounds];
911 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
912 [view setAutoresizes:true];
914 if (WallpaperPage_ != nil)
915 [WallpaperPage_ release];
916 WallpaperPage_ = [view retain];
918 if (WallpaperURL_ != nil)
919 [WallpaperURL_ release];
920 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
922 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
924 [[view webView] setDrawsBackground:false];
925 [view setBackgroundColor:[UIColor clearColor]];
927 [self insertSubview:view aboveSubview:_backgroundView];
931 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
932 extern "C" CGColorRef CGGStateGetFillColor(void *);
933 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
934 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
936 /* WBTimeLabel {{{ */
937 @interface WBTimeLabel : NSProxy {
939 _transient SBStatusBarTimeView *view_;
942 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
946 @implementation WBTimeLabel
953 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
954 time_ = [time retain];
959 - (NSString *) description {
965 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
966 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
967 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
969 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
970 "font-family: Helvetica; "
971 "font-weight: bold; "
974 "%@", _mode ? @"white" : @"black", custom]];
979 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
984 /* WBBadgeLabel {{{ */
985 @interface WBBadgeLabel : NSProxy {
989 - (id) initWithBadge:(NSString *)badge;
990 - (NSString *) description;
994 @implementation WBBadgeLabel
1001 - (id) initWithBadge:(NSString *)badge {
1002 badge_ = [badge retain];
1006 - (NSString *) description {
1007 return [badge_ description];
1012 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
1013 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
1014 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
1015 "font-family: Helvetica; "
1016 "font-weight: bold; "
1024 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1030 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1031 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1032 alpha = [number floatValue];
1033 return _SBIcon$setAlpha$(self, sel, alpha);
1036 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1037 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
1038 id &_badge(MSHookIvar<id>(self, "_badge"));
1040 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1045 void SBStatusBarController$setStatusBarMode(int &mode) {
1047 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
1048 if (mode < 100) // 104:hidden 105:glowing
1049 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1050 mode = [number intValue];
1053 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1054 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1055 SBStatusBarController$setStatusBarMode(mode);
1056 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1059 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
1060 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
1061 SBStatusBarController$setStatusBarMode(mode);
1062 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1065 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) {
1066 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1067 SBStatusBarController$setStatusBarMode(mode);
1068 //NSLog(@"mode=%u", mode);
1069 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1072 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1073 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1074 mode = [number intValue];
1075 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1078 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1079 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1081 NSLog(@"operatorNameStyle= %@", style);
1082 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1083 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1087 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1089 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1090 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1093 // XXX: replace this with [SBStatusBarTimeView tile]
1094 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1095 id &_time(MSHookIvar<id>(self, "_time"));
1096 if (_time != nil && [_time class] != [WBTimeLabel class])
1097 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1098 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1101 @interface UIView (WinterBoard)
1102 - (bool) wb$isWBImageView;
1103 - (void) wb$logHierarchy;
1106 @implementation UIView (WinterBoard)
1108 - (bool) wb$isWBImageView {
1112 - (void) wb$logHierarchy {
1113 WBLogHierarchy(self);
1118 @interface WBImageView : UIImageView {
1121 - (bool) wb$isWBImageView;
1122 - (void) wb$updateFrame;
1125 @implementation WBImageView
1127 - (bool) wb$isWBImageView {
1131 - (void) wb$updateFrame {
1132 CGRect frame([self frame]);
1135 for (UIView *view(self); ; ) {
1136 view = [view superview];
1139 frame.origin.y -= [view frame].origin.y;
1142 [self setFrame:frame];
1147 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1148 NSArray *subviews([self subviews]);
1149 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1150 if (view != nil && [view wb$isWBImageView])
1151 [view wb$updateFrame];
1152 _SBIconList$setFrame$(self, sel, frame);
1155 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1156 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1157 NSArray *lists([_iconModel iconLists]);
1159 for (unsigned i(0), e([lists count]); i != e; ++i)
1160 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1161 SBIconList *list([lists objectAtIndex:i]);
1162 NSArray *subviews([list subviews]);
1164 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1165 if (view == nil || ![view wb$isWBImageView]) {
1166 view = [[[WBImageView alloc] init] autorelease];
1167 [list insertSubview:view atIndex:0];
1170 UIImage *image([UIImage imageWithContentsOfFile:path]);
1172 CGRect frame([view frame]);
1173 frame.size = [image size];
1174 [view setFrame:frame];
1176 [view setImage:image];
1177 [view wb$updateFrame];
1180 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1183 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1184 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1186 [self setClipsToBounds:NO];
1190 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1191 id &_label(MSHookIvar<id>(self, "_label"));
1192 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1194 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1195 [_label setInDock:docked];
1196 return _SBIconLabel$setInDock$(self, sel, docked);
1199 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1200 NSString *identifier = [self bundleIdentifier];
1201 NSLocale *locale = [NSLocale currentLocale];
1202 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1204 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1205 NSString *file = table == nil ? @"Localizable" : table;
1206 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1207 NSDictionary *strings;
1208 if ((strings = [Strings_ objectForKey:name]) != nil) {
1209 if (static_cast<id>(strings) != [NSNull null]) strings:
1210 if (NSString *value = [strings objectForKey:key])
1212 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1215 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1216 [Strings_ setObject:[strings autorelease] forKey:name];
1220 [Strings_ setObject:[NSNull null] forKey:name];
1221 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1224 @class WebCoreFrameBridge;
1225 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1228 void **core(reinterpret_cast<void **>([node _node]));
1229 if (core == NULL || core[6] == NULL)
1231 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1234 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1235 CGRect bounds = [self bounds];
1237 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1240 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1241 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1243 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1245 NSString *style = [NSString stringWithFormat:@""
1246 "font-family: Helvetica; "
1247 "font-weight: bold; "
1249 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
1250 ? @"font-size: 12px; "
1251 : @"font-size: 11px; "
1255 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1257 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1259 bool ellipsis(false);
1260 float max = 75, width;
1262 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1265 size_t length([label length]);
1266 float spacing((width - max) / (length - 1));
1268 if (spacing > 1.25) {
1270 label = [label substringToIndex:(length - 1)];
1274 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1278 label = [label stringByAppendingString:@"..."];
1280 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1281 style = [style stringByAppendingString:custom];
1283 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1284 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1287 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1288 _CKMessageCell$addBalloonView$(self, sel, balloon);
1289 [balloon setBackgroundColor:[UIColor clearColor]];
1292 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1293 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1294 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1298 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1299 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1300 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1301 [_label setBackgroundColor:[UIColor clearColor]];
1305 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1306 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1309 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1311 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1312 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1316 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1317 _TranscriptController$loadView(self, sel);
1319 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1320 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1321 [image autorelease];
1323 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1324 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1326 if (&_transcriptTable != NULL)
1327 table = _transcriptTable;
1328 else if (&_transcriptLayer != NULL)
1329 table = _transcriptLayer;
1333 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1334 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1337 [placard insertSubview:background atIndex:0];
1339 [table setBackgroundColor:[UIColor clearColor]];
1340 [placard insertSubview:background belowSubview:table];
1345 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1346 int id(_UISharedImageNameGetIdentifier(name));
1348 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1351 return _UIImageAtPath(name, _UIKitBundle());
1353 NSNumber *key([NSNumber numberWithInt:id]);
1354 UIImage *image = [UIImages_ objectForKey:key];
1356 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1357 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1358 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1360 [image autorelease];
1362 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1363 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1367 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1368 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1369 UIImage *image([PathImages_ objectForKey:key]);
1371 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1373 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1374 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1375 image = [[UIImage alloc] initWithContentsOfFile:path];
1377 [image autorelease];
1379 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1380 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1383 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1385 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1386 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1387 name = [font UTF8String];
1388 //if (NSString *scale = [Info_ objectForKey:[NSString stringWithFormat:@"FontScale-%s", name]])
1389 // size *= [scale floatValue];
1390 return _GSFontCreateWithName(name, traits, size);
1393 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1394 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1396 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1398 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1400 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1401 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1403 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1406 NSString *path = [NSString stringWithUTF8String:a1];
1407 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1408 NSString *file = [path substringFromIndex:31];
1409 for (NSString *theme in themes_) {
1410 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1411 if ([Manager_ fileExistsAtPath:path]) {
1412 strcpy(a1, [path UTF8String]);
1421 static void ChangeWallpaper(
1422 CFNotificationCenterRef center,
1426 CFDictionaryRef info
1429 NSLog(@"WB:Debug:ChangeWallpaper!");
1432 if (WallpaperFile_ != nil) {
1433 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1435 image = [image autorelease];
1438 if (WallpaperImage_ != nil)
1439 [WallpaperImage_ setImage:image];
1440 if (WallpaperPage_ != nil)
1441 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1445 #define WBRename(name, sel, imp) \
1446 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1448 template <typename Type_>
1449 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1450 struct nlist &name(nl[index]);
1451 uintptr_t value(name.n_value);
1452 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1453 value |= 0x00000001;
1454 function = reinterpret_cast<Type_>(value);
1457 template <typename Type_>
1458 static void dlset(Type_ &function, const char *name) {
1459 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1462 extern "C" void WBInitialize() {
1463 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1465 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1467 NSLog(@"WB:Notice: WinterBoard");
1469 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1473 memset(nl, 0, sizeof(nl));
1474 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1475 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1476 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1477 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1478 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1479 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1480 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1483 nlset(_UIApplicationImageWithName, nl, 0);
1484 nlset(_UIImageAtPath, nl, 1);
1485 nlset(_UIImageRefAtPath, nl, 2);
1486 nlset(_UIImageWithNameInDomain, nl, 3);
1487 nlset(_UIKitBundle, nl, 4);
1488 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1489 nlset(_UISharedImageWithIdentifier, nl, 6);
1491 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1492 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1493 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1494 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1496 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1498 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1500 memset(nl, 0, sizeof(nl));
1501 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1502 nlist(AudioToolbox, nl);
1503 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1504 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1507 $NSBundle = objc_getClass("NSBundle");
1509 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1510 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1512 $UIImage = objc_getClass("UIImage");
1513 $UINavigationBar = objc_getClass("UINavigationBar");
1514 $UIToolbar = objc_getClass("UIToolbar");
1516 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1518 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1519 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1521 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1522 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1524 Manager_ = [[NSFileManager defaultManager] retain];
1525 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1526 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1527 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1528 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1529 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1531 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1533 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1534 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1535 SummerBoard_ = [value boolValue];
1536 if (NSNumber *value = [settings objectForKey:@"Debug"])
1537 Debug_ = [value boolValue];
1539 NSArray *themes([settings objectForKey:@"Themes"]);
1541 if (NSString *theme = [settings objectForKey:@"Theme"])
1542 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1544 [NSNumber numberWithBool:true], @"Active",
1548 for (NSDictionary *theme in themes) {
1549 NSNumber *active([theme objectForKey:@"Active"]);
1550 if (![active boolValue])
1553 NSString *name([theme objectForKey:@"Name"]);
1557 NSString *theme(nil);
1559 #define testForTheme(format...) \
1560 if (theme == nil) { \
1561 NSString *path = [NSString stringWithFormat:format]; \
1562 if ([Manager_ fileExistsAtPath:path]) { \
1563 [themes_ addObject:path]; \
1568 testForTheme(@"/Library/Themes/%@.theme", name)
1569 testForTheme(@"/Library/Themes/%@", name)
1570 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1575 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1577 for (NSString *theme in themes_)
1578 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1579 for (NSString *key in [info allKeys])
1580 if ([Info_ objectForKey:key] == nil)
1581 [Info_ setObject:[info objectForKey:key] forKey:key];
1583 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1585 SpringBoard_ = [identifier isEqualToString:@"com.apple.springboard"];
1587 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"])
1589 $CKMessageCell = objc_getClass("CKMessageCell");
1590 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1591 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1593 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1594 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1595 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1597 $CKTimestampView = objc_getClass("CKTimestampView");
1598 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1600 $CKTranscriptController = objc_getClass("CKTranscriptController");
1601 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1604 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1606 if (_TranscriptController$loadView == NULL) {
1607 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1608 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1611 } else if (SpringBoard_) {
1612 CFNotificationCenterAddObserver(
1613 CFNotificationCenterGetDarwinNotifyCenter(),
1614 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1617 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
1618 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1619 if (MediaPlayer != nil)
1622 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1623 $MPVideoView = objc_getClass("MPVideoView");
1626 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1628 $SBApplication = objc_getClass("SBApplication");
1629 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1630 $SBAwayView = objc_getClass("SBAwayView");
1631 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1632 $SBButtonBar = objc_getClass("SBButtonBar");
1633 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1634 $SBIcon = objc_getClass("SBIcon");
1635 $SBIconBadge = objc_getClass("SBIconBadge");
1636 $SBIconController = objc_getClass("SBIconController");
1637 $SBIconLabel = objc_getClass("SBIconLabel");
1638 $SBIconList = objc_getClass("SBIconList");
1639 $SBIconModel = objc_getClass("SBIconModel");
1640 //$SBImageCache = objc_getClass("SBImageCache");
1641 $SBSearchView = objc_getClass("SBSearchView");
1642 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1643 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1644 $SBStatusBarController = objc_getClass("SBStatusBarController");
1645 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1646 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1647 $SBUIController = objc_getClass("SBUIController");
1648 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1650 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1653 WBRename(SBApplication, pathForIcon, pathForIcon);
1654 WBRename(SBApplicationIcon, icon, icon);
1655 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
1658 WBRename(SBBookmarkIcon, icon, icon);
1659 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1660 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1661 WBRename(SBIcon, setAlpha:, setAlpha$);
1662 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1663 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1664 WBRename(SBUIController, init, init);
1665 WBRename(SBWidgetApplicationIcon, icon, icon);
1667 WBRename(SBIconLabel, drawRect:, drawRect$);
1668 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1669 WBRename(SBIconLabel, setInDock:, setInDock$);
1671 WBRename(SBIconList, setFrame:, setFrame$);
1673 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1674 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1675 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1676 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1678 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1679 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1680 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1682 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1684 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1685 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1686 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1687 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1688 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1689 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1690 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1691 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1692 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1695 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1697 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1700 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1701 Papered_ = $getTheme$(Wallpapers_) != nil;
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]);