1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008 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.
38 #define _trace() NSLog(@"WB:_trace(%u)", __LINE__);
41 #include <substrate.h>
43 #import <CoreFoundation/CoreFoundation.h>
44 #import <Foundation/Foundation.h>
45 #import <CoreGraphics/CoreGraphics.h>
47 #import <UIKit/UIColor.h>
48 #import <UIKit/UIFont.h>
49 #import <UIKit/UIImage.h>
50 #import <UIKit/UIImageView.h>
51 #import <UIKit/UINavigationBar.h>
52 #import <UIKit/UINavigationBarBackground.h>
53 #import <UIKit/UIToolbar.h>
54 #import <UIKit/UIWebDocumentView.h>
56 #import <UIKit/NSString-UIStringDrawing.h>
57 #import <UIKit/NSString-UIStringDrawingDeprecated.h>
59 #import <UIKit/UIImage-UIImageDeprecated.h>
61 #import <UIKit/UIView-Geometry.h>
62 #import <UIKit/UIView-Hierarchy.h>
63 #import <UIKit/UIView-Rendering.h>
65 #import <SpringBoard/SBApplication.h>
66 #import <SpringBoard/SBApplicationIcon.h>
67 #import <SpringBoard/SBAppWindow.h>
68 #import <SpringBoard/SBBookmarkIcon.h>
69 #import <SpringBoard/SBButtonBar.h>
70 #import <SpringBoard/SBCalendarIconContentsView.h>
71 #import <SpringBoard/SBContentLayer.h>
72 #import <SpringBoard/SBIconController.h>
73 #import <SpringBoard/SBIconLabel.h>
74 #import <SpringBoard/SBSlidingAlertDisplay.h>
75 #import <SpringBoard/SBStatusBarContentsView.h>
76 #import <SpringBoard/SBStatusBarController.h>
77 #import <SpringBoard/SBStatusBarTimeView.h>
78 #import <SpringBoard/SBUIController.h>
80 #import <MediaPlayer/MPVideoView.h>
81 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
83 #import <CoreGraphics/CGGeometry.h>
85 extern "C" void __clear_cache (char *beg, char *end);
92 Class $UIWebDocumentView;
94 @interface NSDictionary (WinterBoard)
95 - (UIColor *) colorForKey:(NSString *)key;
96 - (BOOL) boolForKey:(NSString *)key;
99 @implementation NSDictionary (WinterBoard)
101 - (UIColor *) colorForKey:(NSString *)key {
102 NSString *value = [self objectForKey:key];
109 - (BOOL) boolForKey:(NSString *)key {
110 if (NSString *value = [self objectForKey:key])
111 return [value boolValue];
118 bool Engineer_ = false;
120 /* WinterBoard Backend {{{ */
121 void WBInject(const char *classname, const char *oldname, IMP newimp, const char *type) {
122 Class _class = objc_getClass(classname);
125 if (!class_addMethod(_class, sel_registerName(oldname), newimp, type))
126 NSLog(@"WB:Error: failed to inject [%s %s]", classname, oldname);
131 @protocol WinterBoard
132 - (CGSize) wb_renderedSizeOfNode:(id)node constrainedToWidth:(float)width;
134 - (void) wb_updateDesktopImage:(UIImage *)image;
135 - (UIImage *) wb_defaultDesktopImage;
136 - (NSString *) wb_bundlePath;
137 - (NSString *) wb_pathForIcon;
138 - (NSString *) wb_pathForResource:(NSString *)resource ofType:(NSString *)type;
141 - (id) wb_initWithSize:(CGSize)size;
142 - (id) wb_initWithSize:(CGSize)size label:(NSString *)label;
143 - (id) wb_initWithFrame:(CGRect)frame;
144 - (id) wb_initWithCoder:(NSCoder *)coder;
145 - (void) wb_setFrame:(CGRect)frame;
146 - (void) wb_drawRect:(CGRect)rect;
147 - (void) wb_setBackgroundColor:(id)color;
148 - (void) wb_setAlpha:(float)value;
149 - (void) wb_setBarStyle:(int)style;
150 - (id) wb_initWithFrame:(CGRect)frame withBarStyle:(int)style withTintColor:(UIColor *)color;
151 - (void) wb_setOpaque:(BOOL)opaque;
152 - (void) wb_setInDock:(BOOL)docked;
153 - (void) wb_didMoveToSuperview;
154 + (UIImage *) wb_imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;
155 + (UIImage *) wb_applicationImageNamed:(NSString *)name;
156 - (NSDictionary *) wb_infoDictionary;
157 - (UIImage *) wb_icon;
158 - (void) wb_appendIconList:(SBIconList *)list;
159 - (id) wb_initWithStatusBar:(id)bar mode:(int)mode;
160 - (id) wb_initWithMode:(int)mode orientation:(int)orientation;
161 - (id) wb_imageAtPath:(NSString *)path;
162 - (id) wb_initWithContentsOfFile:(NSString *)file;
163 - (id) wb_initWithContentsOfFile:(NSString *)file cache:(BOOL)cache;
164 - (void) wb_setStatusBarMode:(int)mode orientation:(int)orientation duration:(float)duration fenceID:(int)id animation:(int)animation;
167 static NSMutableDictionary **__mappedImages;
168 static NSMutableDictionary *UIImages_;
169 static NSMutableDictionary *PathImages_;
171 static NSFileManager *Manager_;
172 static NSDictionary *English_;
173 static NSMutableDictionary *Info_;
174 static NSMutableArray *themes_;
176 static NSString *$getTheme$(NSArray *files) {
177 for (NSString *theme in themes_)
178 for (NSString *file in files) {
179 NSString *path([NSString stringWithFormat:@"%@/%@", theme, file]);
180 if ([Manager_ fileExistsAtPath:path])
187 static NSString *$pathForIcon$(SBApplication<WinterBoard> *self) {
188 for (NSString *theme in themes_) {
189 NSString *identifier = [self bundleIdentifier];
190 NSString *folder = [[self path] lastPathComponent];
191 NSString *dname = [self displayName];
192 NSString *didentifier = [self displayIdentifier];
195 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
197 #define testForIcon(Name) \
198 if (NSString *name = Name) { \
199 NSString *path = [NSString stringWithFormat:@"%@/Icons/%@.png", theme, name]; \
200 if ([Manager_ fileExistsAtPath:path]) \
204 if (identifier != nil) {
205 NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/icon.png", theme, identifier];
206 if ([Manager_ fileExistsAtPath:path])
211 NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/icon.png", theme, folder];
212 if ([Manager_ fileExistsAtPath:path])
216 testForIcon(identifier);
219 if (didentifier != nil) {
220 testForIcon([English_ objectForKey:didentifier]);
222 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
223 if ([parts count] != 1)
224 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[[self path] stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
225 testForIcon([english objectForKey:[parts lastObject]]);
232 static UIImage *SBApplicationIcon$icon(SBApplicationIcon<WinterBoard> *self, SEL sel) {
233 if (![Info_ boolForKey:@"ComposeStoreIcons"])
234 if (NSString *path = $pathForIcon$([self application]))
235 return [$UIImage imageWithContentsOfFile:path];
236 return [self wb_icon];
239 static UIImage *SBBookmarkIcon$icon(SBBookmarkIcon<WinterBoard> *self, SEL sel) {
241 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
242 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
243 return [$UIImage imageWithContentsOfFile:path];
244 return [self wb_icon];
247 static NSString *SBApplication$pathForIcon(SBApplication<WinterBoard> *self, SEL sel) {
248 if (NSString *path = $pathForIcon$(self))
250 return [self wb_pathForIcon];
253 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle<WinterBoard> *bundle, bool ui) {
254 for (NSString *theme in themes_) {
255 NSString *identifier = [bundle bundleIdentifier];
257 if (identifier != nil) {
258 NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/%@", theme, identifier, file];
259 if ([Manager_ fileExistsAtPath:path])
263 if (NSString *folder = [[bundle wb_bundlePath] lastPathComponent]) {
264 NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/%@", theme, folder, file];
265 if ([Manager_ fileExistsAtPath:path])
269 #define remapResourceName(oldname, newname) \
270 else if ([file isEqualToString:oldname]) { \
271 NSString *path = [NSString stringWithFormat:@"%@/%@.png", theme, newname]; \
272 if ([Manager_ fileExistsAtPath:path]) \
276 if (identifier == nil || ![identifier isEqualToString:@"com.apple.springboard"]);
277 remapResourceName(@"FSO_BG.png", @"StatusBar")
278 remapResourceName(@"SBDockBG.png", @"Dock")
279 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
282 NSString *path = [NSString stringWithFormat:@"%@/UIImages/%@", theme, file];
283 if ([Manager_ fileExistsAtPath:path])
291 static UIImage *CachedImageAtPath(NSString *path) {
292 UIImage *image = [PathImages_ objectForKey:path];
294 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
295 image = [[$UIImage alloc] wb_initWithContentsOfFile:path cache:true];
297 image = [image autorelease];
298 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
302 static UIImage *UIImage$imageNamed$inBundle$(Class<WinterBoard> self, SEL sel, NSString *name, NSBundle *bundle) {
303 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
304 UIImage *image = [PathImages_ objectForKey:key];
306 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
308 NSLog(@"WB:Debug: [UIImage(%@) imageNamed:\"%@\"]", [bundle bundleIdentifier], name);
309 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
310 image = CachedImageAtPath(path);
312 image = [self wb_imageNamed:name inBundle:bundle];
313 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
317 static UIImage *UIImage$imageNamed$(Class<WinterBoard> self, SEL sel, NSString *name) {
318 return UIImage$imageNamed$inBundle$(self, sel, name, [NSBundle mainBundle]);
321 static UIImage *UIImage$applicationImageNamed$(Class<WinterBoard> self, SEL sel, NSString *name) {
322 NSBundle *bundle = [NSBundle mainBundle];
324 NSLog(@"WB:Debug: [UIImage(%@) applicationImageNamed:\"%@\"]", [bundle bundleIdentifier], name);
325 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
326 return CachedImageAtPath(path);
327 return [self wb_applicationImageNamed:name];
330 @interface NSString (WinterBoard)
331 - (NSString *) wb_themedPath;
334 @implementation NSString (WinterBoard)
336 - (NSString *) wb_themedPath {
338 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
344 static NSMutableDictionary *Files_;
346 #define WBDelegate(delegate) \
347 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
349 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
350 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
352 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
356 - (void) forwardInvocation:(NSInvocation*)inv { \
357 SEL sel = [inv selector]; \
358 if ([delegate respondsToSelector:sel]) \
359 [inv invokeWithTarget:delegate]; \
361 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
364 /*@interface WBBundlePath : NSProxy {
365 NSBundle<WinterBoard> *bundle_;
369 - (id) initWithBundle:(NSBundle *)bundle path:(NSString *)path;
371 - (NSString *) wb_themedPath;
375 @implementation WBBundlePath
383 - (id) initWithBundle:(NSBundle *)bundle path:(NSString *)path {
384 bundle_ = [bundle retain];
385 path_ = [path retain];
391 - (NSString *) stringByAppendingPathComponent:(NSString *)component {
392 NSLog(@"WB:Debug:app:%@:%@", path_, component);
393 return [[[WBBundlePath alloc] initWithBundle:bundle_ path:[path_ stringByAppendingPathComponent:component]] autorelease];
396 - (NSString *) stringByAppendingPathExtension:(NSString *)extension {
397 return [[[WBBundlePath alloc] initWithBundle:bundle_ path:[path_ stringByAppendingPathExtension:extension]] autorelease];
400 - (const char *) UTF8String {
401 const char *string = [path_ UTF8String];
402 NSLog(@"WB:Debug:UTF=%s", string);
406 - (NSString *) description {
407 return [path_ description];
410 - (NSString *) wb_themedPath {
412 NSString *path = [Files_ objectForKey:path_];
414 NSString *path = [bundle_ wb_bundlePath];
415 if (![path_ hasPrefix:path]) {
416 NSLog(@"WB:Error:![@\"%@\" hasPrefix:@\"%@\"]", path_, path);
419 path = [path_ substringFromIndex:([path length] + 1)];
420 path = $pathForFile$inBundle$(path, bundle_, false);
422 path = reinterpret_cast<NSString *>([NSNull null]);
423 [Files_ setObject:path forKey:path_];
425 NSLog(@"WB:Debug:ThemePath(\"%@\")->\"%@\"", path_, path);
427 if (reinterpret_cast<id>(path) == [NSNull null])
429 NSLog(@"WB:Debug:ThemePath=%@", path);
435 static NSString *NSBundle$bundlePath$(NSBundle<WinterBoard> *self, SEL sel) {
436 //return [[WBBundlePath alloc] initWithBundle:self path:[self wb_bundlePath]];
437 return [self wb_bundlePath];
440 static NSString *NSBundle$pathForResource$ofType$(NSBundle<WinterBoard> *self, SEL sel, NSString *resource, NSString *type) {
441 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
443 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
444 if (NSString *path = $pathForFile$inBundle$(file, self, false))
446 return [self wb_pathForResource:resource ofType:type];
449 static bool $setBarStyle$_(NSString *name, UIView<WinterBoard> *self, int style) {
451 NSLog(@"WB:Debug:%@Style:%d", name, style);
452 NSNumber *number = nil;
454 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
456 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
460 style = [number intValue];
462 NSLog(@"WB:Debug:%@Style=%d", name, style);
463 [self wb_setBarStyle:style];
468 static void SBCalendarIconContentsView$drawRect$(SBCalendarIconContentsView<WinterBoard> *self, SEL sel, CGRect rect) {
469 CFLocaleRef locale(CFLocaleCopyCurrent());
470 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
473 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
475 CFDateFormatterSetFormat(formatter, CFSTR("d"));
476 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
477 CFDateFormatterSetFormat(formatter, CFSTR("EEEE"));
478 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
482 CFRelease(formatter);
484 NSString *datestyle(@""
485 "font-family: Helvetica; "
486 "font-weight: bold; "
492 NSString *daystyle(@""
493 "font-family: Helvetica; "
494 "font-weight: bold; "
497 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
500 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
501 datestyle = [datestyle stringByAppendingString:style];
502 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
503 daystyle = [daystyle stringByAppendingString:style];
505 float width([self bounds].size.width);
506 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:width];
507 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:width];
509 [(NSString *)date drawAtPoint:CGPointMake(
510 (width + 4 - datesize.width) / 2, (71 - datesize.height) / 2
511 ) withStyle:datestyle];
513 [(NSString *)day drawAtPoint:CGPointMake(
514 (width - daysize.width) / 2, (16 - daysize.height) / 2
515 ) withStyle:daystyle];
521 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
524 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
525 style = [number intValue];
527 if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"])
530 return [self wb_initWithFrame:frame withBarStyle:style withTintColor:tint];
533 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
534 self = [self wb_initWithCoder:coder];
537 UINavigationBar$setBarStyle$_(self);
541 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
542 self = [self wb_initWithFrame:frame];
545 UINavigationBar$setBarStyle$_(self);
549 static void UIToolbar$setBarStyle$(UIToolbar<WinterBoard> *self, SEL sel, int style) {
550 if ($setBarStyle$_(@"Toolbar", self, style))
552 return [self wb_setBarStyle:style];
555 static void UINavigationBar$setBarStyle$(UINavigationBar<WinterBoard> *self, SEL sel, int style) {
556 if ($setBarStyle$_(@"NavigationBar", self, style))
558 return [self wb_setBarStyle:style];
561 static void $didMoveToSuperview(SBButtonBar<WinterBoard> *self, SEL sel) {
562 [[self superview] setBackgroundColor:[$UIColor clearColor]];
563 [self wb_didMoveToSuperview];
566 static id UIImage$imageAtPath$(NSObject<WinterBoard> *self, SEL sel, NSString *path) {
567 return [self wb_imageAtPath:[path wb_themedPath]];
570 static id $initWithContentsOfFile$(NSObject<WinterBoard> *self, SEL sel, NSString *file) {
571 return [self wb_initWithContentsOfFile:[file wb_themedPath]];
574 static id UIImage$initWithContentsOfFile$cache$(UIImage<WinterBoard> *self, SEL sel, NSString *file, BOOL cache) {
575 return [self wb_initWithContentsOfFile:[file wb_themedPath] cache:cache];
578 static UIImage *UIImage$defaultDesktopImage$(UIImage<WinterBoard> *self, SEL sel) {
580 NSLog(@"WB:Debug:DefaultDesktopImage");
581 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
582 return [$UIImage imageWithContentsOfFile:path];
583 return [self wb_defaultDesktopImage];
586 static UIImageView *WallpaperImage_;
587 static UIWebDocumentView *WallpaperPage_;
588 static NSURL *WallpaperURL_;
590 static id SBContentLayer$initWithSize$(SBContentLayer<WinterBoard> *self, SEL sel, CGSize size) {
591 self = [self wb_initWithSize:size];
595 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"])) {
596 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
597 [video setMovieWithPath:path];
598 [video setRepeatMode:1];
599 [video setRepeatGap:0];
600 [self addSubview:video];
601 [video playFromBeginning];;
605 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil])) {
606 image = [[$UIImage alloc] wb_initWithContentsOfFile:path];
608 image = [image autorelease];
611 if (WallpaperImage_ != nil)
612 [WallpaperImage_ release];
613 WallpaperImage_ = [[$UIImageView alloc] initWithImage:image];
614 [self addSubview:WallpaperImage_];
616 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.html"])) {
617 CGRect bounds = [self bounds];
619 UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
620 [view setAutoresizes:true];
622 if (WallpaperPage_ != nil)
623 [WallpaperPage_ release];
624 WallpaperPage_ = [view retain];
626 if (WallpaperURL_ != nil)
627 [WallpaperURL_ release];
628 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
630 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
632 [[view webView] setDrawsBackground:false];
633 [view setBackgroundColor:[$UIColor clearColor]];
635 [self addSubview:view];
641 static void SBSlidingAlertDisplay$updateDesktopImage$(SBSlidingAlertDisplay<WinterBoard> *self, SEL sel, UIImage *image) {
642 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
646 object_getInstanceVariable(self, "_backgroundView", reinterpret_cast<void **>(&background));
647 if (background != nil)
651 [self wb_updateDesktopImage:image];
654 CGRect bounds = [self bounds];
656 UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
657 [view setAutoresizes:true];
659 if (WallpaperPage_ != nil)
660 [WallpaperPage_ release];
661 WallpaperPage_ = [view retain];
663 if (WallpaperURL_ != nil)
664 [WallpaperURL_ release];
665 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
667 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
669 [[view webView] setDrawsBackground:false];
670 [view setBackgroundColor:[$UIColor clearColor]];
673 object_getInstanceVariable(self, "_backgroundView", reinterpret_cast<void **>(&background));
674 NSLog(@"back:%@", background);
676 [self insertSubview:view aboveSubview:background];
680 static unsigned *__currentContextCount;
681 static void ***__currentContextStack;
683 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
684 extern "C" CGColorRef CGGStateGetFillColor(void *);
685 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
686 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
688 @interface WBTime : NSProxy {
690 _transient SBStatusBarTimeView *view_;
693 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
697 @implementation WBTime
704 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
705 time_ = [time retain];
712 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
713 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
715 object_getInstanceVariable(view_, "_mode", reinterpret_cast<void **>(&mode));
717 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
718 "font-family: Helvetica; "
719 "font-weight: bold; "
722 "%@", mode ? @"white" : @"black", custom]];
727 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
732 @interface WBIconLabel : NSProxy {
737 - (id) initWithString:(NSString *)string;
741 static void SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(SBStatusBarController<WinterBoard> *self, SEL sel, int mode, int orientation, float duration, int id, int animation) {
743 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
744 if (mode < 100) // 104:hidden 105:glowing
745 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
746 mode = [number intValue];
747 return [self wb_setStatusBarMode:mode orientation:orientation duration:duration fenceID:id animation:animation];
750 /*static id SBStatusBar$initWithMode$orientation$(SBStatusBar<WinterBoard> *self, SEL sel, int mode, int orientation) {
751 return [self wb_initWithMode:mode orientation:orientation];
754 static id SBStatusBarContentsView$initWithStatusBar$mode$(SBStatusBarContentsView<WinterBoard> *self, SEL sel, id bar, int mode) {
755 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
756 mode = [number intValue];
757 return [self wb_initWithStatusBar:bar mode:mode];
760 static void SBStatusBarTimeView$drawRect$(SBStatusBarTimeView<WinterBoard> *self, SEL sel, CGRect rect) {
762 object_getInstanceVariable(self, "_time", reinterpret_cast<void **>(&time));
763 if (time != nil && [time class] != [WBTime class])
764 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTime alloc] initWithTime:[time autorelease] view:self]));
765 return [self wb_drawRect:rect];
768 static void SBIconController$appendIconList$(SBIconController<WinterBoard> *self, SEL sel, SBIconList *list) {
770 NSLog(@"appendIconList:%@", list);
771 return [self wb_appendIconList:list];
774 static id SBIconLabel$initWithSize$label$(SBIconLabel<WinterBoard> *self, SEL sel, CGSize size, NSString *label) {
775 self = [self wb_initWithSize:size label:label];
777 [self setClipsToBounds:NO];
781 static void SBIconLabel$setInDock$(SBIconLabel<WinterBoard> *self, SEL sel, BOOL docked) {
783 object_getInstanceVariable(self, "_label", reinterpret_cast<void **>(&label));
784 if (![Info_ boolForKey:@"UndockedIconLabels"])
786 if (label != nil && [label respondsToSelector:@selector(setInDock:)])
787 [label setInDock:docked];
788 return [self wb_setInDock:docked];
791 @class WebCoreFrameBridge;
792 static CGSize WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(WebCoreFrameBridge<WinterBoard> *self, SEL sel, id node, float width) {
795 void **core(reinterpret_cast<void **>([node _node]));
796 if (core == NULL || core[6] == NULL)
798 return [self wb_renderedSizeOfNode:node constrainedToWidth:width];
801 static void SBIconLabel$drawRect$(SBIconLabel<WinterBoard> *self, SEL sel, CGRect rect) {
802 CGRect bounds = [self bounds];
804 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
807 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
808 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
811 object_getInstanceVariable(self, "_label", reinterpret_cast<void **>(&label));
813 NSString *style = [NSString stringWithFormat:@""
814 "font-family: Helvetica; "
815 "font-weight: bold; "
818 "", docked ? @"white" : @"#b3b3b3"];
821 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
822 float max = 75, width = [label sizeWithStyle:style forWidth:320].width;
824 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", ((width - max) / ([label length] - 1))]];
825 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
826 style = [style stringByAppendingString:custom];
828 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
829 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
832 extern "C" void FindMappedImages(void);
833 extern "C" NSData *UIImagePNGRepresentation(UIImage *);
835 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
836 static CGImageRef *(*_UIImageRefAtPath)(NSString *path, bool cache, UIImageOrientation *orientation);
837 static UIImage *(*_UIImageWithName)(NSString *name);
838 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
839 static NSBundle *(*_UIKitBundle)();
840 static void (*_UISharedImageInitialize)(bool);
841 static int (*_UISharedImageNameGetIdentifier)(NSString *);
842 static UIImage *(*_UISharedImageWithIdentifier)(int);
844 static UIImage *$_UIImageWithName(NSString *name) {
845 int id(_UISharedImageNameGetIdentifier(name));
847 NSLog(@"WB:Debug: UIImageWithName(\"%@\", %d)", name, id);
850 return _UIImageAtPath(name, _UIKitBundle());
852 NSNumber *key([NSNumber numberWithInt:id]);
853 UIImage *image = [UIImages_ objectForKey:key];
855 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
856 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
857 image = [[$UIImage alloc] wb_initWithContentsOfFile:path];
862 image = _UISharedImageWithIdentifier(id);
863 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
868 static UIImage *$_UIImageWithNameInDomain(NSString *name, NSString *domain) {
869 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
870 UIImage *image = [PathImages_ objectForKey:key];
872 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
874 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
875 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
876 image = [[$UIImage alloc] wb_initWithContentsOfFile:path];
881 image = _UIImageWithNameInDomain(name, domain);
882 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
886 template <typename Type_>
887 static void WBReplace(Type_ *symbol, Type_ *replace) {
888 return WBReplace(symbol, replace, static_cast<Type_ **>(NULL));
891 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
892 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
894 /*static void UIWebDocumentView$setViewportSize$forDocumentTypes$(UIWebDocumentView *self, SEL sel, CGSize size, int type) {
895 NSLog(@"WB:Examine: %f:%f:%u", size.width, size.height, type);
898 static bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long, char *, bool &);
900 static bool $_Z24GetFileNameForThisActionmPcRb(unsigned long a0, char *a1, bool &a2) {
901 bool value = _Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
903 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
906 NSString *path = [NSString stringWithUTF8String:a1];
907 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
908 NSString *file = [path substringFromIndex:31];
910 for (NSString *theme in themes_) {
911 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
912 if ([Manager_ fileExistsAtPath:path]) {
913 strcpy(a1, [path UTF8String]);
922 static void ChangeWallpaper(
923 CFNotificationCenterRef center,
930 NSLog(@"WB:Debug:ChangeWallpaper!");
933 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil])) {
934 image = [[$UIImage alloc] wb_initWithContentsOfFile:path];
936 image = [image autorelease];
939 if (WallpaperImage_ != nil)
940 [WallpaperImage_ setImage:image];
941 if (WallpaperPage_ != nil)
942 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
946 void WBRename(bool instance, const char *name, SEL sel, IMP imp) {
947 Class _class = objc_getClass(name);
950 NSLog(@"WB:Warning: cannot find class [%s]", name);
954 _class = object_getClass(_class);
955 MSHookMessage(_class, sel, imp, "wb_");
958 extern "C" void WBInitialize() {
959 if (dlopen(UIKit, RTLD_LAZY | RTLD_NOLOAD) == NULL)
961 NSLog(@"WB:Notice: Installing WinterBoard...");
963 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
965 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
966 if (MediaPlayer != nil)
969 $MPVideoView = objc_getClass("MPVideoView");
971 $UIColor = objc_getClass("UIColor");
972 $UIImage = objc_getClass("UIImage");
973 $UIImageView = objc_getClass("UIImageView");
974 $UIWebDocumentView = objc_getClass("UIWebDocumentView");
977 memset(nl, 0, sizeof(nl));
979 nl[0].n_un.n_name = (char *) "___currentContextCount";
980 nl[1].n_un.n_name = (char *) "___currentContextStack";
981 nl[2].n_un.n_name = (char *) "___mappedImages";
982 nl[3].n_un.n_name = (char *) "__UIImageAtPath";
983 nl[4].n_un.n_name = (char *) "__UIImageRefAtPath";
984 nl[5].n_un.n_name = (char *) "__UIImageWithName";
985 nl[6].n_un.n_name = (char *) "__UIImageWithNameInDomain";
986 nl[7].n_un.n_name = (char *) "__UIKitBundle";
987 nl[8].n_un.n_name = (char *) "__UISharedImageInitialize";
988 nl[9].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
989 nl[10].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
993 __currentContextCount = (unsigned *) nl[0].n_value;
994 __currentContextStack = (void ***) nl[1].n_value;
995 __mappedImages = (id *) nl[2].n_value;
996 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[3].n_value;
997 _UIImageRefAtPath = (CGImageRef *(*)(NSString *, bool, UIImageOrientation *)) nl[4].n_value;
998 _UIImageWithName = (UIImage *(*)(NSString *)) nl[5].n_value;
999 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[6].n_value;
1000 _UIKitBundle = (NSBundle *(*)()) nl[7].n_value;
1001 _UISharedImageInitialize = (void (*)(bool)) nl[8].n_value;
1002 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[9].n_value;
1003 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[10].n_value;
1005 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &_UIImageWithName);
1006 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &_UIImageWithNameInDomain);
1008 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1010 memset(nl, 0, sizeof(nl));
1011 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1012 nlist(AudioToolbox, nl);
1013 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1014 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &_Z24GetFileNameForThisActionmPcRb);
1017 WBRename(false, "UIImage", @selector(applicationImageNamed:), (IMP) &UIImage$applicationImageNamed$);
1018 WBRename(false, "UIImage", @selector(defaultDesktopImage), (IMP) &UIImage$defaultDesktopImage$);
1019 WBRename(false, "UIImage", @selector(imageAtPath:), (IMP) &UIImage$imageAtPath$);
1020 WBRename(false, "UIImage", @selector(imageNamed:), (IMP) &UIImage$imageNamed$);
1021 WBRename(false, "UIImage", @selector(imageNamed:inBundle:), (IMP) &UIImage$imageNamed$inBundle$);
1023 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1024 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1025 //WBRename(true, "SBStatusBar", @selector(initWithMode:orientation:", (IMP) &SBStatusBar$initWithMode$orientation$);
1026 //WBRename(true, "UIWebDocumentView", @selector(setViewportSize:forDocumentTypes:", (IMP) &UIWebDocumentView$setViewportSize$forDocumentTypes$);
1028 WBRename(true, "NSBundle", @selector(bundlePath), (IMP) &NSBundle$bundlePath$);
1029 WBRename(true, "NSBundle", @selector(pathForResource:ofType:), (IMP) &NSBundle$pathForResource$ofType$);
1031 WBRename(true, "UIImage", @selector(initWithContentsOfFile:), (IMP) &$initWithContentsOfFile$);
1032 WBRename(true, "UIImage", @selector(initWithContentsOfFile:cache:), (IMP) &UIImage$initWithContentsOfFile$cache$);
1033 WBRename(true, "UINavigationBar", @selector(setBarStyle:), (IMP) &UINavigationBar$setBarStyle$);
1034 WBRename(true, "UIToolbar", @selector(setBarStyle:), (IMP) &UIToolbar$setBarStyle$);
1036 WBRename(true, "WebCoreFrameBridge", @selector(renderedSizeOfNode:constrainedToWidth:), (IMP) &WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$);
1038 WBRename(true, "SBApplication", @selector(pathForIcon), (IMP) &SBApplication$pathForIcon);
1039 WBRename(true, "SBApplicationIcon", @selector(icon), (IMP) &SBApplicationIcon$icon);
1040 WBRename(true, "SBBookmarkIcon", @selector(icon), (IMP) &SBBookmarkIcon$icon);
1041 WBRename(true, "SBButtonBar", @selector(didMoveToSuperview), (IMP) &$didMoveToSuperview);
1042 WBRename(true, "SBCalendarIconContentsView", @selector(drawRect:), (IMP) &SBCalendarIconContentsView$drawRect$);
1043 WBRename(true, "SBContentLayer", @selector(initWithSize:), (IMP) &SBContentLayer$initWithSize$);
1044 WBRename(true, "SBIconLabel", @selector(initWithSize:label:), (IMP) &SBIconLabel$initWithSize$label$);
1045 WBRename(true, "SBIconLabel", @selector(setInDock:), (IMP) &SBIconLabel$setInDock$);
1046 WBRename(true, "SBIconLabel", @selector(drawRect:), (IMP) &SBIconLabel$drawRect$);
1047 WBRename(true, "SBSlidingAlertDisplay", @selector(updateDesktopImage:), (IMP) &SBSlidingAlertDisplay$updateDesktopImage$);
1048 WBRename(true, "SBStatusBarContentsView", @selector(didMoveToSuperview), (IMP) &$didMoveToSuperview);
1049 WBRename(true, "SBStatusBarContentsView", @selector(initWithStatusBar:mode:), (IMP) &SBStatusBarContentsView$initWithStatusBar$mode$);
1050 WBRename(true, "SBStatusBarController", @selector(setStatusBarMode:orientation:duration:fenceID:animation:), (IMP) &SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$);
1051 WBRename(true, "SBStatusBarTimeView", @selector(drawRect:), (IMP) &SBStatusBarTimeView$drawRect$);
1052 WBRename(true, "SBIconController", @selector(appendIconList:), (IMP) &SBIconController$appendIconList$);
1054 _UISharedImageInitialize(false);
1056 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1057 if (English_ != nil)
1058 English_ = [English_ retain];
1060 Manager_ = [[NSFileManager defaultManager] retain];
1061 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1062 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1063 Files_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1065 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1067 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1068 [settings autorelease];
1070 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1071 Debug_ = [debug boolValue];
1073 NSArray *themes = [settings objectForKey:@"Themes"];
1075 if (NSString *theme = [settings objectForKey:@"Theme"])
1076 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1078 [NSNumber numberWithBool:true], @"Active",
1081 for (NSDictionary *theme in themes) {
1082 NSNumber *active = [theme objectForKey:@"Active"];
1083 if (![active boolValue])
1086 NSString *name = [theme objectForKey:@"Name"];
1090 NSString *theme = nil;
1092 #define testForTheme(format...) \
1093 if (theme == nil) { \
1094 NSString *path = [NSString stringWithFormat:format]; \
1095 if ([Manager_ fileExistsAtPath:path]) { \
1096 [themes_ addObject:path]; \
1101 testForTheme(@"/Library/Themes/%@.theme", name)
1102 testForTheme(@"/Library/Themes/%@", name)
1103 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1107 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1109 for (NSString *theme in themes_)
1110 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1111 for (NSString *key in [info allKeys])
1112 if ([Info_ objectForKey:key] == nil)
1113 [Info_ setObject:[info objectForKey:key] forKey:key];
1115 if (objc_getClass("SpringBoard") != nil)
1116 CFNotificationCenterAddObserver(
1117 CFNotificationCenterGetDarwinNotifyCenter(),
1118 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1121 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1122 [Info_ setObject:[NSNumber numberWithBool:(
1123 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1124 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1125 )] forKey:@"UndockedIconLabels"];
1127 if (![Info_ boolForKey:@"UndockedIconLabels"])
1129 NSLog(@"WB:Debug:Info = %@", [Info_ description]);