]> git.saurik.com Git - winterboard.git/blob - Library.mm
Fixed a number of 2.x reported issues.
[winterboard.git] / Library.mm
1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008 Jay Freeman (saurik)
3 */
4
5 /*
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
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
17 * distribution.
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.
21 *
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.
36 */
37
38 #include <sys/time.h>
39
40 struct timeval _ltv;
41 bool _itv;
42
43 #define _trace() do { \
44 struct timeval _ctv; \
45 gettimeofday(&_ctv, NULL); \
46 if (!_itv) { \
47 _itv = true; \
48 _ltv = _ctv; \
49 } \
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__\
54 ); \
55 _ltv = _ctv; \
56 } while (false)
57
58 #define _transient
59
60 #import <CoreFoundation/CoreFoundation.h>
61 #import <Foundation/Foundation.h>
62 #import <CoreGraphics/CoreGraphics.h>
63
64 #import <Celestial/AVController.h>
65 #import <Celestial/AVItem.h>
66 #import <Celestial/AVQueue.h>
67
68 #include <substrate.h>
69
70 #import <UIKit/UIKit.h>
71
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/SBStatusBarContentsView.h>
86 #import <SpringBoard/SBStatusBarController.h>
87 #import <SpringBoard/SBStatusBarOperatorNameView.h>
88 #import <SpringBoard/SBStatusBarTimeView.h>
89 #import <SpringBoard/SBUIController.h>
90 #import <SpringBoard/SBWidgetApplicationIcon.h>
91
92 #import <MobileSMS/mSMSMessageTranscriptController.h>
93
94 #import <MediaPlayer/MPMoviePlayerController.h>
95 #import <MediaPlayer/MPVideoView.h>
96 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
97
98 #import <CoreGraphics/CGGeometry.h>
99
100 extern "C" void __clear_cache (char *beg, char *end);
101
102 @protocol WinterBoard
103 - (void *) _node;
104 @end
105
106 Class $MPMoviePlayerController;
107 Class $MPVideoView;
108 Class $WebCoreFrameBridge;
109
110 Class $NSBundle;
111
112 Class $UIImage;
113 Class $UINavigationBar;
114 Class $UIToolbar;
115
116 Class $SBApplication;
117 Class $SBApplicationIcon;
118 Class $SBAwayView;
119 Class $SBBookmarkIcon;
120 Class $SBButtonBar;
121 Class $SBCalendarIconContentsView;
122 Class $SBIcon;
123 Class $SBIconBadge;
124 Class $SBIconController;
125 Class $SBIconLabel;
126 Class $SBIconList;
127 Class $SBIconModel;
128 //Class $SBImageCache;
129 Class $SBSearchView;
130 Class $SBStatusBarContentsView;
131 Class $SBStatusBarController;
132 Class $SBStatusBarOperatorNameView;
133 Class $SBStatusBarTimeView;
134 Class $SBUIController;
135 Class $SBWidgetApplicationIcon;
136
137 @interface NSDictionary (WinterBoard)
138 - (UIColor *) wb$colorForKey:(NSString *)key;
139 - (BOOL) wb$boolForKey:(NSString *)key;
140 @end
141
142 @implementation NSDictionary (WinterBoard)
143
144 - (UIColor *) wb$colorForKey:(NSString *)key {
145 NSString *value = [self objectForKey:key];
146 if (value == nil)
147 return nil;
148 /* XXX: incorrect */
149 return nil;
150 }
151
152 - (BOOL) wb$boolForKey:(NSString *)key {
153 if (NSString *value = [self objectForKey:key])
154 return [value boolValue];
155 return false;
156 }
157
158 @end
159
160 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
161 #define $GSFontGetUseLegacyFontMetrics() \
162 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
163
164 bool Debug_ = false;
165 bool Engineer_ = false;
166
167 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
168 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
169 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
170 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
171 static NSBundle *(*_UIKitBundle)();
172 static int (*_UISharedImageNameGetIdentifier)(NSString *);
173 static UIImage *(*_UISharedImageWithIdentifier)(int);
174
175 static NSMutableDictionary *UIImages_;
176 static NSMutableDictionary *PathImages_;
177 static NSMutableDictionary *Cache_;
178 static NSMutableDictionary *Strings_;
179 static NSMutableDictionary *Themed_;
180 static NSMutableDictionary *Bundles_;
181
182 static NSFileManager *Manager_;
183 static NSDictionary *English_;
184 static NSMutableDictionary *Info_;
185 static NSMutableArray *themes_;
186
187 static NSString *$getTheme$(NSArray *files, bool parent = false) {
188 if (!parent)
189 if (NSString *path = [Themed_ objectForKey:files])
190 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
191
192 if (Debug_)
193 NSLog(@"WB:Debug: %@", [files description]);
194
195 NSString *path;
196
197 for (NSString *theme in themes_)
198 for (NSString *file in files) {
199 path = [NSString stringWithFormat:@"%@/%@", theme, file];
200 if ([Manager_ fileExistsAtPath:path]) {
201 path = parent ? theme : path;
202 goto set;
203 }
204 }
205
206 path = nil;
207 set:
208 if (!parent)
209 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
210 return path;
211 }
212
213 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
214 NSString *identifier = [bundle bundleIdentifier];
215 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
216
217 if (identifier != nil)
218 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
219 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
220 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
221 if (ui)
222 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
223
224 #define remapResourceName(oldname, newname) \
225 else if ([file isEqualToString:oldname]) \
226 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
227
228 if (identifier == nil);
229 else if ([identifier isEqualToString:@"com.apple.calculator"])
230 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
231 else if (![identifier isEqualToString:@"com.apple.springboard"]);
232 remapResourceName(@"FSO_BG.png", @"StatusBar")
233 remapResourceName(@"SBDockBG.png", @"Dock")
234 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
235
236 if (NSString *path = $getTheme$(names))
237 return path;
238 return nil;
239 }
240
241 static NSString *$pathForIcon$(SBApplication *self) {
242 NSString *identifier = [self bundleIdentifier];
243 NSString *path = [self path];
244 NSString *folder = [path lastPathComponent];
245 NSString *dname = [self displayName];
246 NSString *didentifier = [self displayIdentifier];
247
248 if (Debug_)
249 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
250
251 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
252
253 if (identifier != nil)
254 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
255 if (folder != nil)
256 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
257
258 #define testForIcon(Name) \
259 if (NSString *name = Name) \
260 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
261
262 testForIcon(identifier);
263 testForIcon(dname);
264
265 if (didentifier != nil) {
266 testForIcon([English_ objectForKey:didentifier]);
267
268 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
269 if ([parts count] != 1)
270 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
271 testForIcon([english objectForKey:[parts lastObject]]);
272 }
273
274 if (NSString *path = $getTheme$(names))
275 return path;
276 return nil;
277 }
278
279 @interface NSBundle (WinterBoard)
280 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
281 @end
282
283 @implementation NSBundle (WinterBoard)
284
285 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
286 path = [path stringByDeletingLastPathComponent];
287 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
288 return nil;
289
290 NSBundle *bundle([Bundles_ objectForKey:path]);
291 if (reinterpret_cast<id>(bundle) == [NSNull null])
292 return nil;
293 else if (bundle == nil) {
294 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
295 bundle = [NSBundle bundleWithPath:path];
296 if (bundle == nil)
297 bundle = [NSBundle wb$bundleWithFile:path];
298 if (Debug_)
299 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
300 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
301 }
302
303 return bundle;
304 }
305
306 @end
307
308 @interface NSString (WinterBoard)
309 - (NSString *) wb$themedPath;
310 @end
311
312 @implementation NSString (WinterBoard)
313
314 - (NSString *) wb$themedPath {
315 if (Debug_)
316 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
317
318 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
319 NSString *file([self stringByResolvingSymlinksInPath]);
320 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
321 if ([file hasPrefix:prefix]) {
322 NSUInteger length([prefix length]);
323 if (length != [file length])
324 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
325 return path;
326 }
327 }
328
329 return self;
330 }
331
332 @end
333
334 void DumpHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
335 NSLog(@"%*s|%2d:%s", indent * 3, "", index, class_getName([view class]));
336 index = 0;
337 for (UIView *child in [view subviews])
338 DumpHierarchy(child, index++, indent + 1);
339 }
340
341 UIImage *$cacheForImage$(UIImage *image) {
342 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
343 CGRect rect = {CGPointMake(1, 1), [image size]};
344 CGSize size = {rect.size.width + 2, rect.size.height + 2};
345
346 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
347 CGColorSpaceRelease(space);
348
349 CGContextDrawImage(context, rect, [image CGImage]);
350 CGImageRef ref(CGBitmapContextCreateImage(context));
351 CGContextRelease(context);
352
353 UIImage *cache([UIImage imageWithCGImage:ref]);
354 CGImageRelease(ref);
355
356 return cache;
357 }
358
359 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
360 //if ([name isEqualToString:@"icons"]) return nil;
361 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
362 }*/
363
364 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
365 NSString *key([icon displayIdentifier]);
366
367 if (UIImage *image = [icon icon]) {
368 CGSize size = [image size];
369 if (size.width != 59 || size.height != 60) {
370 UIImage *cache($cacheForImage$(image));
371 [Cache_ setObject:cache forKey:key];
372 return;
373 }
374 }
375
376 _SBIconModel$cacheImageForIcon$(self, sel, icon);
377 }
378
379 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
380 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
381 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
382
383 NSString *key([icon displayIdentifier]);
384
385 if (UIImage *image = [icon icon]) {
386 CGSize size = [image size];
387 if (size.width != 59 || size.height != 60) {
388 UIImage *cache($cacheForImage$(image));
389 [Cache_ setObject:cache forKey:key];
390 return;
391 }
392 }
393 }
394
395 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
396 NSString *key([icon displayIdentifier]);
397 if (UIImage *image = [Cache_ objectForKey:key])
398 return image;
399 else
400 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
401 }
402
403 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
404 if (small)
405 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
406 NSString *key([icon displayIdentifier]);
407 if (UIImage *image = [Cache_ objectForKey:key])
408 return image;
409 else
410 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
411 }
412
413 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
414 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
415 [self setBackgroundColor:[UIColor clearColor]];
416 for (UIView *child in [self subviews])
417 [child setBackgroundColor:[UIColor clearColor]];
418 } return self;
419 }
420
421 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
422 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
423 if (NSString *path = $pathForIcon$([self application]))
424 return [UIImage imageWithContentsOfFile:path];
425 return _SBApplicationIcon$icon(self, sel);
426 }
427
428 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
429 if (Debug_)
430 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
431 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
432 return [UIImage imageWithContentsOfFile:path];
433 return _SBWidgetApplicationIcon$icon(self, sel);
434 }
435
436 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
437 if (Debug_)
438 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
439 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
440 return [UIImage imageWithContentsOfFile:path];
441 return _SBBookmarkIcon$icon(self, sel);
442 }
443
444 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
445 if (NSString *path = $pathForIcon$(self))
446 return path;
447 return _SBApplication$pathForIcon(self, sel);
448 }
449
450 static UIImage *CachedImageAtPath(NSString *path) {
451 path = [path stringByResolvingSymlinksInPath];
452 UIImage *image = [PathImages_ objectForKey:path];
453 if (image != nil)
454 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
455 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
456 if (image != nil)
457 image = [image autorelease];
458 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
459 return image;
460 }
461
462 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
463 if (Debug_)
464 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
465 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
466 }
467
468 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
469 if (bundle == nil)
470 return __UIImageAtPath(name, nil);
471 else {
472 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
473 UIImage *image = [PathImages_ objectForKey:key];
474 if (image != nil)
475 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
476 if (Debug_)
477 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
478 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
479 image = CachedImageAtPath(path);
480 if (image == nil)
481 image = __UIImageAtPath(name, bundle);
482 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
483 return image;
484 }
485 }*/
486
487 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
488 NSBundle *bundle = [NSBundle mainBundle];
489 if (Debug_)
490 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
491 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
492 return CachedImageAtPath(path);
493 return __UIApplicationImageWithName(name);
494 }
495
496 #define WBDelegate(delegate) \
497 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
498 if (Engineer_) \
499 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
500 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
501 return sig; \
502 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
503 return nil; \
504 } \
505 \
506 - (void) forwardInvocation:(NSInvocation*)inv { \
507 SEL sel = [inv selector]; \
508 if ([delegate respondsToSelector:sel]) \
509 [inv invokeWithTarget:delegate]; \
510 else \
511 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
512 }
513
514 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
515 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
516 if (Debug_)
517 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
518 if (NSString *path = $pathForFile$inBundle$(file, self, false))
519 return path;
520 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
521 }
522
523 void $setBarStyle$_(NSString *name, int &style) {
524 if (Debug_)
525 NSLog(@"WB:Debug:%@Style:%d", name, style);
526 NSNumber *number = nil;
527 if (number == nil)
528 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
529 if (number == nil)
530 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
531 if (number != nil) {
532 style = [number intValue];
533 if (Debug_)
534 NSLog(@"WB:Debug:%@Style=%d", name, style);
535 }
536 }
537
538 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
539 NSBundle *bundle([NSBundle mainBundle]);
540
541 CFLocaleRef locale(CFLocaleCopyCurrent());
542 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
543 CFRelease(locale);
544
545 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
546
547 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
548 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
549 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
550 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
551
552 CFRelease(now);
553
554 CFRelease(formatter);
555
556 NSString *datestyle(@""
557 "font-family: Helvetica; "
558 "font-weight: bold; "
559 "font-size: 39px; "
560 "color: #333333; "
561 "alpha: 1.0; "
562 "");
563
564 NSString *daystyle(@""
565 "font-family: Helvetica; "
566 "font-weight: bold; "
567 "font-size: 9px; "
568 "color: white; "
569 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
570 "");
571
572 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
573 datestyle = [datestyle stringByAppendingString:style];
574 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
575 daystyle = [daystyle stringByAppendingString:style];
576
577 float width([self bounds].size.width);
578 float leeway(10);
579 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
580 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
581
582 unsigned base($GSFontGetUseLegacyFontMetrics() ? 71 : 70);
583
584 [(NSString *)date drawAtPoint:CGPointMake(
585 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
586 ) withStyle:datestyle];
587
588 [(NSString *)day drawAtPoint:CGPointMake(
589 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
590 ) withStyle:daystyle];
591
592 CFRelease(date);
593 CFRelease(day);
594 }
595
596 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
597 _trace();
598
599 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
600 style = [number intValue];
601
602 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
603 tint = color;
604
605 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
606 }*/
607
608 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
609 self = [self wb$initWithCoder:coder];
610 if (self == nil)
611 return nil;
612 UINavigationBar$setBarStyle$_(self);
613 return self;
614 }
615
616 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
617 self = [self wb$initWithFrame:frame];
618 if (self == nil)
619 return nil;
620 UINavigationBar$setBarStyle$_(self);
621 return self;
622 }*/
623
624 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
625 $setBarStyle$_(@"Toolbar", style);
626 return _UIToolbar$setBarStyle$(self, sel, style);
627 }
628
629 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
630 $setBarStyle$_(@"NavigationBar", style);
631 return _UINavigationBar$setBarStyle$(self, sel, style);
632 }
633
634 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
635 [[self superview] setBackgroundColor:[UIColor clearColor]];
636 _SBButtonBar$didMoveToSuperview(self, sel);
637 }
638
639 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
640 [[self superview] setBackgroundColor:[UIColor clearColor]];
641 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
642 }
643
644 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
645 if (Debug_)
646 NSLog(@"WB:Debug:DefaultDesktopImage");
647 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
648 return [UIImage imageWithContentsOfFile:path];
649 return _UIImage$defaultDesktopImage(self, sel);
650 }
651
652 static NSArray *Wallpapers_;
653 static NSString *WallpaperFile_;
654 static UIImageView *WallpaperImage_;
655 static UIWebDocumentView *WallpaperPage_;
656 static NSURL *WallpaperURL_;
657
658 #define _release(object) \
659 do if (object != nil) { \
660 [object release]; \
661 object = nil; \
662 } while (false)
663
664 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
665 self = _SBUIController$init(self, sel);
666 if (self == nil)
667 return nil;
668
669 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
670 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
671 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
672
673 UIView *layer;
674 if (&_contentLayer != NULL)
675 layer = _contentLayer;
676 else if (&_contentView != NULL)
677 layer = _contentView;
678 else
679 layer = nil;
680
681 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
682 [content setBackgroundColor:[layer backgroundColor]];
683 [layer setBackgroundColor:[UIColor clearColor]];
684 [layer setFrame:[content bounds]];
685 [_window setContentView:content];
686
687 _release(WallpaperFile_);
688 _release(WallpaperImage_);
689 _release(WallpaperPage_);
690 _release(WallpaperURL_);
691
692 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
693 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
694 if ([Manager_ fileExistsAtPath:mp4]) {
695 #if UseAVController
696 NSError *error;
697
698 static AVController *controller_(nil);
699 if (controller_ == nil) {
700 AVQueue *queue([AVQueue avQueue]);
701 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
702 }
703
704 AVQueue *queue([controller_ queue]);
705
706 UIView *video([[[UIView alloc] initWithFrame:[content bounds]] autorelease]);
707 [controller_ setLayer:[video _layer]];
708
709 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
710 [queue appendItem:item error:&error];
711
712 [controller_ play:&error];
713 #elif UseMPMoviePlayerController
714 NSURL *url([NSURL fileURLWithPath:mp4]);
715 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
716 controller.movieControlMode = MPMovieControlModeHidden;
717 [controller play];
718 #else
719 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[content bounds]] autorelease];
720 [video setMovieWithPath:mp4];
721 [video setRepeatMode:1];
722 [video setRepeatGap:-1];
723 [video playFromBeginning];;
724 #endif
725
726 [content addSubview:video];
727 }
728
729 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
730 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
731
732 NSString *path;
733 if ([Manager_ fileExistsAtPath:png])
734 path = png;
735 else if ([Manager_ fileExistsAtPath:jpg])
736 path = jpg;
737 else path = nil;
738
739 UIImage *image;
740 if (path != nil) {
741 image = [[UIImage alloc] initWithContentsOfFile:path];
742 if (image != nil)
743 image = [image autorelease];
744 } else image = nil;
745
746 if (image != nil) {
747 WallpaperFile_ = [path retain];
748 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
749 [content addSubview:WallpaperImage_];
750 }
751
752 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
753 if ([Manager_ fileExistsAtPath:html]) {
754 CGRect bounds = [content bounds];
755
756 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
757 [view setAutoresizes:true];
758
759 WallpaperPage_ = [view retain];
760 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
761
762 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
763
764 [view setBackgroundColor:[UIColor clearColor]];
765 if ([view respondsToSelector:@selector(setDrawsBackground:)])
766 [view setDrawsBackground:NO];
767 [[view webView] setDrawsBackground:NO];
768
769 [content addSubview:view];
770 }
771 }
772
773 for (size_t i(0), e([themes_ count]); i != e; ++i) {
774 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
775 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
776 if ([Manager_ fileExistsAtPath:html]) {
777 CGRect bounds = [content bounds];
778
779 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
780 [view setAutoresizes:true];
781
782 NSURL *url = [NSURL fileURLWithPath:html];
783 [view loadRequest:[NSURLRequest requestWithURL:url]];
784
785 [view setBackgroundColor:[UIColor clearColor]];
786 if ([view respondsToSelector:@selector(setDrawsBackground:)])
787 [view setDrawsBackground:NO];
788 [[view webView] setDrawsBackground:NO];
789
790 [content addSubview:view];
791 }
792 }
793
794 [content addSubview:layer];
795 DumpHierarchy(_window);
796
797 return self;
798 }
799
800 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
801 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
802 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
803
804 if (path != nil && _backgroundView != nil)
805 path = nil;
806
807 _SBAwayView$updateDesktopImage$(self, sel, image);
808
809 if (path != nil) {
810 CGRect bounds = [self bounds];
811
812 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
813 [view setAutoresizes:true];
814
815 if (WallpaperPage_ != nil)
816 [WallpaperPage_ release];
817 WallpaperPage_ = [view retain];
818
819 if (WallpaperURL_ != nil)
820 [WallpaperURL_ release];
821 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
822
823 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
824
825 [[view webView] setDrawsBackground:false];
826 [view setBackgroundColor:[UIColor clearColor]];
827
828 [self insertSubview:view aboveSubview:_backgroundView];
829 }
830 }
831
832 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
833 extern "C" CGColorRef CGGStateGetFillColor(void *);
834 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
835 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
836
837 /* WBTimeLabel {{{ */
838 @interface WBTimeLabel : NSProxy {
839 NSString *time_;
840 _transient SBStatusBarTimeView *view_;
841 }
842
843 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
844
845 @end
846
847 @implementation WBTimeLabel
848
849 - (void) dealloc {
850 [time_ release];
851 [super dealloc];
852 }
853
854 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
855 time_ = [time retain];
856 view_ = view;
857 return self;
858 }
859
860 - (NSString *) description {
861 return time_;
862 }
863
864 WBDelegate(time_)
865
866 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
867 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
868 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
869
870 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
871 "font-family: Helvetica; "
872 "font-weight: bold; "
873 "font-size: 14px; "
874 "color: %@; "
875 "%@", _mode ? @"white" : @"black", custom]];
876
877 return CGSizeZero;
878 }
879
880 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
881 }
882
883 @end
884 /* }}} */
885 /* WBBadgeLabel {{{ */
886 @interface WBBadgeLabel : NSProxy {
887 NSString *badge_;
888 }
889
890 - (id) initWithBadge:(NSString *)badge;
891
892 @end
893
894 @implementation WBBadgeLabel
895
896 - (void) dealloc {
897 [badge_ release];
898 [super dealloc];
899 }
900
901 - (id) initWithBadge:(NSString *)badge {
902 badge_ = [badge retain];
903 return self;
904 }
905
906 WBDelegate(badge_)
907
908 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
909 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
910 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
911 "font-family: Helvetica; "
912 "font-weight: bold; "
913 "font-size: 17px; "
914 "color: white; "
915 "%@", custom]];
916
917 return CGSizeZero;
918 }
919
920 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
921 }
922
923 @end
924 /* }}} */
925
926 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
927 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
928 alpha = [number floatValue];
929 return _SBIcon$setAlpha$(self, sel, alpha);
930 }
931
932 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
933 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
934 id &_badge(MSHookIvar<id>(self, "_badge"));
935 if (_badge != nil)
936 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
937 _badge = label;
938 } return self;
939 }
940
941 void SBStatusBarController$setStatusBarMode(int &mode) {
942 if (Debug_)
943 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
944 if (mode < 100) // 104:hidden 105:glowing
945 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
946 mode = [number intValue];
947 }
948
949 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
950 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
951 SBStatusBarController$setStatusBarMode(mode);
952 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
953 }*/
954
955 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
956 NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
957 SBStatusBarController$setStatusBarMode(mode);
958 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
959 }
960
961 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) {
962 NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
963 SBStatusBarController$setStatusBarMode(mode);
964 NSLog(@"mode=%u", mode);
965 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
966 }
967
968 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
969 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
970 mode = [number intValue];
971 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
972 }*/
973
974 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
975 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
976 if (Debug_)
977 NSLog(@"operatorNameStyle= %@", style);
978 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
979 style = [NSString stringWithFormat:@"%@; %@", style, custom];
980 return style;
981 }
982
983 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
984 if (Debug_)
985 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
986 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
987 }
988
989 // XXX: replace this with [SBStatusBarTimeView tile]
990 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
991 id &_time(MSHookIvar<id>(self, "_time"));
992 if (_time != nil && [_time class] != [WBTimeLabel class])
993 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
994 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
995 }
996
997 @interface UIView (WinterBoard)
998 - (bool) wb$isWBImageView;
999 @end
1000
1001 @implementation UIView (WinterBoard)
1002
1003 - (bool) wb$isWBImageView {
1004 return false;
1005 }
1006
1007 @end
1008
1009 @interface WBImageView : UIImageView {
1010 }
1011
1012 - (bool) wb$isWBImageView;
1013 - (void) wb$updateFrame;
1014 @end
1015
1016 @implementation WBImageView
1017
1018 - (bool) wb$isWBImageView {
1019 return true;
1020 }
1021
1022 - (void) wb$updateFrame {
1023 CGRect frame([self frame]);
1024 frame.origin.y = 0;
1025
1026 for (UIView *view(self); ; ) {
1027 view = [view superview];
1028 if (view == nil)
1029 break;
1030 frame.origin.y -= [view frame].origin.y;
1031 }
1032
1033 [self setFrame:frame];
1034 }
1035
1036 @end
1037
1038 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1039 NSArray *subviews([self subviews]);
1040 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1041 if (view != nil && [view wb$isWBImageView])
1042 [view wb$updateFrame];
1043 _SBIconList$setFrame$(self, sel, frame);
1044 }
1045
1046 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1047 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1048 NSArray *lists([_iconModel iconLists]);
1049
1050 for (unsigned i(0), e([lists count]); i != e; ++i)
1051 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1052 SBIconList *list([lists objectAtIndex:i]);
1053 NSArray *subviews([list subviews]);
1054
1055 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1056 if (view == nil || ![view wb$isWBImageView]) {
1057 view = [[[WBImageView alloc] init] autorelease];
1058 [list insertSubview:view atIndex:0];
1059 }
1060
1061 UIImage *image([UIImage imageWithContentsOfFile:path]);
1062
1063 CGRect frame([view frame]);
1064 frame.size = [image size];
1065 [view setFrame:frame];
1066
1067 [view setImage:image];
1068 [view wb$updateFrame];
1069 }
1070
1071 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1072 }
1073
1074 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1075 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1076 if (self != nil)
1077 [self setClipsToBounds:NO];
1078 return self;
1079 }
1080
1081 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1082 id &_label(MSHookIvar<id>(self, "_label"));
1083 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1084 docked = true;
1085 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1086 [_label setInDock:docked];
1087 return _SBIconLabel$setInDock$(self, sel, docked);
1088 }
1089
1090 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1091 NSString *identifier = [self bundleIdentifier];
1092 NSLocale *locale = [NSLocale currentLocale];
1093 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1094 if (Debug_)
1095 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1096 NSString *file = table == nil ? @"Localizable" : table;
1097 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1098 NSDictionary *strings;
1099 if ((strings = [Strings_ objectForKey:name]) != nil) {
1100 if (static_cast<id>(strings) != [NSNull null]) strings:
1101 if (NSString *value = [strings objectForKey:key])
1102 return value;
1103 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1104 language, file
1105 ], self, false)) {
1106 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1107 [Strings_ setObject:[strings autorelease] forKey:name];
1108 goto strings;
1109 } else goto null;
1110 } else null:
1111 [Strings_ setObject:[NSNull null] forKey:name];
1112 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1113 }
1114
1115 @class WebCoreFrameBridge;
1116 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1117 if (node == nil)
1118 return CGSizeZero;
1119 void **core(reinterpret_cast<void **>([node _node]));
1120 if (core == NULL || core[6] == NULL)
1121 return CGSizeZero;
1122 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1123 }
1124
1125 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1126 CGRect bounds = [self bounds];
1127
1128 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1129
1130 BOOL docked;
1131 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1132 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1133
1134 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1135
1136 NSString *style = [NSString stringWithFormat:@""
1137 "font-family: Helvetica; "
1138 "font-weight: bold; "
1139 "font-size: 11px; "
1140 "color: %@; "
1141 "", docked ? @"white" : @"#b3b3b3"];
1142
1143 if (docked)
1144 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1145
1146 bool ellipsis(false);
1147 float max = 75, width;
1148 width:
1149 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1150
1151 if (width > max) {
1152 size_t length([label length]);
1153 float spacing((width - max) / (length - 1));
1154
1155 if (spacing > 1.25) {
1156 ellipsis = true;
1157 label = [label substringToIndex:(length - 1)];
1158 goto width;
1159 }
1160
1161 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1162 }
1163
1164 if (ellipsis)
1165 label = [label stringByAppendingString:@"..."];
1166
1167 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1168 style = [style stringByAppendingString:custom];
1169
1170 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1171 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1172 }
1173
1174 MSHook(void, mSMSMessageTranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1175 _mSMSMessageTranscriptController$loadView(self, sel);
1176
1177 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1178 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1179 [image autorelease];
1180 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1181 UIView *parent([_transcriptLayer superview]);
1182 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1183 [parent insertSubview:background belowSubview:_transcriptLayer];
1184 [_transcriptLayer setBackgroundColor:[UIColor clearColor]];
1185 }
1186 }
1187
1188 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1189 int id(_UISharedImageNameGetIdentifier(name));
1190 if (Debug_)
1191 NSLog(@"WB:Debug: _UIImageWithName(\"%@\", %d)", name, id);
1192
1193 if (id == -1)
1194 return _UIImageAtPath(name, _UIKitBundle());
1195 else {
1196 NSNumber *key([NSNumber numberWithInt:id]);
1197 UIImage *image = [UIImages_ objectForKey:key];
1198 if (image != nil)
1199 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1200 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1201 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1202 if (image != nil)
1203 [image autorelease];
1204 }
1205 if (image == nil)
1206 image = _UISharedImageWithIdentifier(id);
1207 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1208 return image;
1209 }
1210 }
1211
1212 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1213 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
1214 UIImage *image = [PathImages_ objectForKey:key];
1215 if (image != nil)
1216 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1217 if (Debug_)
1218 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1219 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1220 image = [[UIImage alloc] initWithContentsOfFile:path];
1221 if (image != nil)
1222 [image autorelease];
1223 }
1224 if (image == nil)
1225 image = __UIImageWithNameInDomain(name, domain);
1226 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1227 return image;
1228 }
1229
1230 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1231 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1232 name = [font UTF8String];
1233 return _GSFontCreateWithName(name, traits, size);
1234 }
1235
1236 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1237 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1238
1239 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1240
1241 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1242 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1243 if (Debug_)
1244 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1245
1246 if (value) {
1247 NSString *path = [NSString stringWithUTF8String:a1];
1248 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1249 NSString *file = [path substringFromIndex:31];
1250 for (NSString *theme in themes_) {
1251 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1252 if ([Manager_ fileExistsAtPath:path]) {
1253 strcpy(a1, [path UTF8String]);
1254 continue;
1255 }
1256 }
1257 }
1258 }
1259 return value;
1260 }
1261
1262 static void ChangeWallpaper(
1263 CFNotificationCenterRef center,
1264 void *observer,
1265 CFStringRef name,
1266 const void *object,
1267 CFDictionaryRef info
1268 ) {
1269 if (Debug_)
1270 NSLog(@"WB:Debug:ChangeWallpaper!");
1271
1272 UIImage *image;
1273 if (WallpaperFile_ != nil) {
1274 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1275 if (image != nil)
1276 image = [image autorelease];
1277 } else image = nil;
1278
1279 if (WallpaperImage_ != nil)
1280 [WallpaperImage_ setImage:image];
1281 if (WallpaperPage_ != nil)
1282 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1283
1284 }
1285
1286 #define WBRename(name, sel, imp) \
1287 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1288
1289 extern "C" void WBInitialize() {
1290 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1291
1292 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1293
1294 NSLog(@"WB:Notice: WinterBoard");
1295
1296 _GSFontGetUseLegacyFontMetrics = reinterpret_cast<BOOL (*)()>(dlsym(RTLD_DEFAULT, "GSFontGetUseLegacyFontMetrics"));
1297
1298 struct nlist nl[8];
1299 memset(nl, 0, sizeof(nl));
1300
1301 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1302 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1303 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1304 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1305 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1306 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1307 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1308
1309 nlist(UIKit, nl);
1310
1311 _UIApplicationImageWithName = (UIImage *(*)(NSString *)) nl[0].n_value;
1312 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[1].n_value;
1313 _UIImageRefAtPath = (CGImageRef (*)(NSString *, bool, UIImageOrientation *)) nl[2].n_value;
1314 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[3].n_value;
1315 _UIKitBundle = (NSBundle *(*)()) nl[4].n_value;
1316 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[5].n_value;
1317 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[6].n_value;
1318
1319 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1320 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1321 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1322 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1323
1324 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1325
1326 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1327 struct nlist nl[2];
1328 memset(nl, 0, sizeof(nl));
1329 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1330 nlist(AudioToolbox, nl);
1331 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1332 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1333 }
1334
1335 $NSBundle = objc_getClass("NSBundle");
1336
1337 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1338 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1339
1340 $UIImage = objc_getClass("UIImage");
1341 $UINavigationBar = objc_getClass("UINavigationBar");
1342 $UIToolbar = objc_getClass("UIToolbar");
1343
1344 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1345
1346 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1347 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1348
1349 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1350 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1351
1352 Manager_ = [[NSFileManager defaultManager] retain];
1353 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1354 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1355 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1356 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1357 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1358
1359 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1360
1361 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1362 [settings autorelease];
1363
1364 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1365 Debug_ = [debug boolValue];
1366
1367 NSArray *themes = [settings objectForKey:@"Themes"];
1368 if (themes == nil)
1369 if (NSString *theme = [settings objectForKey:@"Theme"])
1370 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1371 theme, @"Name",
1372 [NSNumber numberWithBool:true], @"Active",
1373 nil]];
1374 if (themes != nil)
1375 for (NSDictionary *theme in themes) {
1376 NSNumber *active = [theme objectForKey:@"Active"];
1377 if (![active boolValue])
1378 continue;
1379
1380 NSString *name = [theme objectForKey:@"Name"];
1381 if (name == nil)
1382 continue;
1383
1384 NSString *theme = nil;
1385
1386 #define testForTheme(format...) \
1387 if (theme == nil) { \
1388 NSString *path = [NSString stringWithFormat:format]; \
1389 if ([Manager_ fileExistsAtPath:path]) { \
1390 [themes_ addObject:path]; \
1391 continue; \
1392 } \
1393 }
1394
1395 testForTheme(@"/Library/Themes/%@.theme", name)
1396 testForTheme(@"/Library/Themes/%@", name)
1397 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1398 }
1399 }
1400
1401 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1402
1403 for (NSString *theme in themes_)
1404 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
1405 [info autorelease];
1406 for (NSString *key in [info allKeys])
1407 if ([Info_ objectForKey:key] == nil)
1408 [Info_ setObject:[info objectForKey:key] forKey:key];
1409 }
1410
1411 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1412 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1413 _mSMSMessageTranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$mSMSMessageTranscriptController$loadView);
1414 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1415 CFNotificationCenterAddObserver(
1416 CFNotificationCenterGetDarwinNotifyCenter(),
1417 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1418 );
1419
1420 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1421 if (MediaPlayer != nil)
1422 [MediaPlayer load];
1423
1424 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1425 $MPVideoView = objc_getClass("MPVideoView");
1426 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1427
1428 $SBApplication = objc_getClass("SBApplication");
1429 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1430 $SBAwayView = objc_getClass("SBAwayView");
1431 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1432 $SBButtonBar = objc_getClass("SBButtonBar");
1433 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1434 $SBIcon = objc_getClass("SBIcon");
1435 $SBIconBadge = objc_getClass("SBIconBadge");
1436 $SBIconController = objc_getClass("SBIconController");
1437 $SBIconLabel = objc_getClass("SBIconLabel");
1438 $SBIconList = objc_getClass("SBIconList");
1439 $SBIconModel = objc_getClass("SBIconModel");
1440 //$SBImageCache = objc_getClass("SBImageCache");
1441 $SBSearchView = objc_getClass("SBSearchView");
1442 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1443 $SBStatusBarController = objc_getClass("SBStatusBarController");
1444 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1445 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1446 $SBUIController = objc_getClass("SBUIController");
1447 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1448
1449 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1450
1451 WBRename(SBApplication, pathForIcon, pathForIcon);
1452 WBRename(SBApplicationIcon, icon, icon);
1453 WBRename(SBBookmarkIcon, icon, icon);
1454 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1455 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1456 WBRename(SBIcon, setAlpha:, setAlpha$);
1457 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1458 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1459 WBRename(SBUIController, init, init);
1460 WBRename(SBWidgetApplicationIcon, icon, icon);
1461
1462 WBRename(SBIconLabel, drawRect:, drawRect$);
1463 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1464 WBRename(SBIconLabel, setInDock:, setInDock$);
1465
1466 WBRename(SBIconList, setFrame:, setFrame$);
1467
1468 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1469 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1470 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1471 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1472
1473 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1474
1475 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1476
1477 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1478 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1479 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1480 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1481 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1482 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1483 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1484 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1485 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1486
1487 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1488 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1489 }
1490
1491 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1492
1493 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1494 [Info_ setObject:[NSNumber numberWithBool:(
1495 $getTheme$(Wallpapers_) == nil ||
1496 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1497 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1498 )] forKey:@"UndockedIconLabels"];
1499
1500 if (Debug_)
1501 NSLog(@"WB:Debug:Info = %@", [Info_ description]);
1502
1503 [pool release];
1504 }