]> git.saurik.com Git - winterboard.git/blame - Library.mm
Add an IconAlpha fix from NickF.
[winterboard.git] / Library.mm
CommitLineData
d5168fd6 1/* WinterBoard - Theme Manager for the iPhone
9e42420f 2 * Copyright (C) 2008-2010 Jay Freeman (saurik)
d5168fd6
JF
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
69550bfb
JF
38#include <sys/time.h>
39
40struct timeval _ltv;
41bool _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
ca13798d 58#define _transient
62b2dbad 59
e6f0817b 60#import <CoreFoundation/CoreFoundation.h>
d5168fd6 61#import <Foundation/Foundation.h>
2435118f 62#import <CoreGraphics/CoreGraphics.h>
f64efe8d 63#import <ImageIO/CGImageSource.h>
d5168fd6 64
d806256e
JF
65#import <Celestial/AVController.h>
66#import <Celestial/AVItem.h>
67#import <Celestial/AVQueue.h>
68
2acbe5b8
JF
69#include <substrate.h>
70
4668cd8e 71#import <UIKit/UIKit.h>
d5168fd6
JF
72
73#import <SpringBoard/SBApplication.h>
394d1eb5 74#import <SpringBoard/SBApplicationIcon.h>
d5168fd6 75#import <SpringBoard/SBAppWindow.h>
9cfe3924 76#import <SpringBoard/SBAwayView.h>
502d350e 77#import <SpringBoard/SBBookmarkIcon.h>
62b2dbad 78#import <SpringBoard/SBButtonBar.h>
e6f0817b 79#import <SpringBoard/SBCalendarIconContentsView.h>
95a5777b 80#import <SpringBoard/SBIconController.h>
889cb4f2 81#import <SpringBoard/SBIconLabel.h>
a8d008e4 82#import <SpringBoard/SBIconList.h>
98fe8d52 83#import <SpringBoard/SBIconModel.h>
82b4a0bd 84#import <SpringBoard/SBImageCache.h>
1a4ffdf8 85// XXX: #import <SpringBoard/SBSearchView.h>
9c64bab2 86#import <SpringBoard/SBSearchTableViewCell.h>
08454e3a 87#import <SpringBoard/SBStatusBarContentsView.h>
d5fb6e01 88#import <SpringBoard/SBStatusBarController.h>
4668cd8e 89#import <SpringBoard/SBStatusBarOperatorNameView.h>
08454e3a 90#import <SpringBoard/SBStatusBarTimeView.h>
d5168fd6 91#import <SpringBoard/SBUIController.h>
4f1b7acd 92#import <SpringBoard/SBWidgetApplicationIcon.h>
d5168fd6 93
4668cd8e
JF
94#import <MobileSMS/mSMSMessageTranscriptController.h>
95
d806256e 96#import <MediaPlayer/MPMoviePlayerController.h>
d5fb6e01
JF
97#import <MediaPlayer/MPVideoView.h>
98#import <MediaPlayer/MPVideoView-PlaybackControl.h>
99
d5168fd6
JF
100#import <CoreGraphics/CGGeometry.h>
101
198eb03b
JF
102#import <ChatKit/CKMessageCell.h>
103
609e1cd8
JF
104#include <sys/sysctl.h>
105
95a5777b
JF
106extern "C" void __clear_cache (char *beg, char *end);
107
0316ebc4
JF
108@protocol WinterBoard
109- (void *) _node;
110@end
111
d806256e 112Class $MPMoviePlayerController;
95a5777b 113Class $MPVideoView;
0316ebc4
JF
114Class $WebCoreFrameBridge;
115
116Class $NSBundle;
117
118Class $UIImage;
119Class $UINavigationBar;
120Class $UIToolbar;
121
198eb03b
JF
122Class $CKMessageCell;
123Class $CKTimestampView;
8b94f6b0 124Class $CKTranscriptController;
198eb03b 125Class $CKTranscriptTableView;
8b94f6b0 126
0316ebc4
JF
127Class $SBApplication;
128Class $SBApplicationIcon;
9cfe3924 129Class $SBAwayView;
0316ebc4
JF
130Class $SBBookmarkIcon;
131Class $SBButtonBar;
132Class $SBCalendarIconContentsView;
77d89d52 133Class $SBDockIconListView;
b0d0c73f 134Class $SBIcon;
0316ebc4
JF
135Class $SBIconBadge;
136Class $SBIconController;
137Class $SBIconLabel;
a8d008e4 138Class $SBIconList;
0316ebc4 139Class $SBIconModel;
8e4d2f42 140Class $SBIconView;
82b4a0bd 141//Class $SBImageCache;
1a4ffdf8 142Class $SBSearchView;
9c64bab2 143Class $SBSearchTableViewCell;
0316ebc4
JF
144Class $SBStatusBarContentsView;
145Class $SBStatusBarController;
146Class $SBStatusBarOperatorNameView;
147Class $SBStatusBarTimeView;
69550bfb 148Class $SBUIController;
4f1b7acd 149Class $SBWidgetApplicationIcon;
95a5777b 150
8e4d2f42
JF
151#define SBIconView SBIcon
152
1d3b613f 153static bool IsWild_;
77d89d52 154static bool Four_;
1d3b613f 155
26c43b47 156@interface NSDictionary (WinterBoard)
37351a17
JF
157- (UIColor *) wb$colorForKey:(NSString *)key;
158- (BOOL) wb$boolForKey:(NSString *)key;
26c43b47
JF
159@end
160
161@implementation NSDictionary (WinterBoard)
162
37351a17 163- (UIColor *) wb$colorForKey:(NSString *)key {
26c43b47
JF
164 NSString *value = [self objectForKey:key];
165 if (value == nil)
166 return nil;
167 /* XXX: incorrect */
168 return nil;
169}
170
37351a17 171- (BOOL) wb$boolForKey:(NSString *)key {
889cb4f2
JF
172 if (NSString *value = [self objectForKey:key])
173 return [value boolValue];
95a5777b 174 return false;
889cb4f2
JF
175}
176
26c43b47
JF
177@end
178
81decb42
JF
179static BOOL (*_GSFontGetUseLegacyFontMetrics)();
180#define $GSFontGetUseLegacyFontMetrics() \
181 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
182
bae02419
JF
183static bool Debug_ = false;
184static bool Engineer_ = false;
185static bool SummerBoard_ = true;
186static bool SpringBoard_;
889cb4f2 187
4df9352e
JF
188static UIImage *(*_UIApplicationImageWithName)(NSString *name);
189static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
77d89d52 190static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation, float *scale);
4df9352e
JF
191static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
192static NSBundle *(*_UIKitBundle)();
77d89d52 193static bool (*_UIPackedImageTableGetIdentifierForName)(NSString *, int *);
4df9352e 194static int (*_UISharedImageNameGetIdentifier)(NSString *);
4df9352e 195
502d350e
JF
196static NSMutableDictionary *UIImages_;
197static NSMutableDictionary *PathImages_;
4668cd8e
JF
198static NSMutableDictionary *Cache_;
199static NSMutableDictionary *Strings_;
0316ebc4 200static NSMutableDictionary *Themed_;
4df9352e 201static NSMutableDictionary *Bundles_;
2435118f 202
502d350e
JF
203static NSFileManager *Manager_;
204static NSDictionary *English_;
205static NSMutableDictionary *Info_;
206static NSMutableArray *themes_;
d5168fd6 207
0316ebc4 208static NSString *$getTheme$(NSArray *files, bool parent = false) {
e839c3fe
JF
209 if (!parent)
210 if (NSString *path = [Themed_ objectForKey:files])
211 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
212
2acbe5b8
JF
213 if (Debug_)
214 NSLog(@"WB:Debug: %@", [files description]);
215
e839c3fe
JF
216 NSString *path;
217
502d350e
JF
218 for (NSString *theme in themes_)
219 for (NSString *file in files) {
e839c3fe
JF
220 path = [NSString stringWithFormat:@"%@/%@", theme, file];
221 if ([Manager_ fileExistsAtPath:path]) {
222 path = parent ? theme : path;
223 goto set;
224 }
502d350e
JF
225 }
226
e839c3fe
JF
227 path = nil;
228 set:
229 if (!parent)
230 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
231 return path;
502d350e
JF
232}
233
0316ebc4 234static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
4df9352e
JF
235 NSString *identifier = [bundle bundleIdentifier];
236 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
237
238 if (identifier != nil)
239 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
240 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
241 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
242 if (ui)
243 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
244
245 #define remapResourceName(oldname, newname) \
77d89d52 246 else if ([file isEqualToString:(oldname)]) \
4df9352e
JF
247 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
248
bae02419
JF
249 bool summer(SpringBoard_ && SummerBoard_);
250
4df9352e 251 if (identifier == nil);
198eb03b
JF
252 else if ([identifier isEqualToString:@"com.apple.chatkit"])
253 [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
4df9352e
JF
254 else if ([identifier isEqualToString:@"com.apple.calculator"])
255 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
bae02419 256 else if (!summer);
4df9352e 257 remapResourceName(@"FSO_BG.png", @"StatusBar")
77d89d52 258 remapResourceName(Four_ ? @"SBDockBG-old.png" : @"SBDockBG.png", @"Dock")
4df9352e
JF
259 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
260
261 if (NSString *path = $getTheme$(names))
262 return path;
bae02419 263
4df9352e
JF
264 return nil;
265}
266
ab3ce88d 267static NSString *$pathForIcon$(SBApplication *self, NSString *suffix = @"") {
2acbe5b8
JF
268 NSString *identifier = [self bundleIdentifier];
269 NSString *path = [self path];
270 NSString *folder = [path lastPathComponent];
271 NSString *dname = [self displayName];
272 NSString *didentifier = [self displayIdentifier];
d5fb6e01 273
2acbe5b8
JF
274 if (Debug_)
275 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
62b2dbad 276
2acbe5b8 277 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
d5fb6e01 278
265e19b2 279 /* XXX: I might need to keep this for backwards compatibility
2acbe5b8
JF
280 if (identifier != nil)
281 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
282 if (folder != nil)
265e19b2 283 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */
889cb4f2 284
2acbe5b8
JF
285 #define testForIcon(Name) \
286 if (NSString *name = Name) \
ab3ce88d 287 [names addObject:[NSString stringWithFormat:@"Icons%@/%@.png", suffix, name]];
ca13798d 288
9e42420f
JF
289 if (![didentifier isEqualToString:identifier])
290 testForIcon(didentifier);
24ba43ee 291
2acbe5b8
JF
292 testForIcon(identifier);
293 testForIcon(dname);
889cb4f2 294
24ba43ee
JF
295 if ([identifier isEqualToString:@"com.apple.MobileSMS"])
296 testForIcon(@"SMS");
297
2acbe5b8
JF
298 if (didentifier != nil) {
299 testForIcon([English_ objectForKey:didentifier]);
889cb4f2 300
2acbe5b8
JF
301 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
302 if ([parts count] != 1)
303 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
304 testForIcon([english objectForKey:[parts lastObject]]);
d5fb6e01 305 }
889cb4f2 306
2acbe5b8
JF
307 if (NSString *path = $getTheme$(names))
308 return path;
24ba43ee 309
394d1eb5
JF
310 return nil;
311}
312
4df9352e
JF
313@interface NSBundle (WinterBoard)
314+ (NSBundle *) wb$bundleWithFile:(NSString *)path;
315@end
316
317@implementation NSBundle (WinterBoard)
318
319+ (NSBundle *) wb$bundleWithFile:(NSString *)path {
320 path = [path stringByDeletingLastPathComponent];
321 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
322 return nil;
323
324 NSBundle *bundle([Bundles_ objectForKey:path]);
325 if (reinterpret_cast<id>(bundle) == [NSNull null])
326 return nil;
327 else if (bundle == nil) {
0316ebc4
JF
328 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
329 bundle = [NSBundle bundleWithPath:path];
4df9352e
JF
330 if (bundle == nil)
331 bundle = [NSBundle wb$bundleWithFile:path];
332 if (Debug_)
333 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
44aa4549 334 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
4df9352e
JF
335 }
336
337 return bundle;
338}
339
340@end
341
342@interface NSString (WinterBoard)
343- (NSString *) wb$themedPath;
344@end
345
346@implementation NSString (WinterBoard)
347
348- (NSString *) wb$themedPath {
349 if (Debug_)
350 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
351
352 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
353 NSString *file([self stringByResolvingSymlinksInPath]);
354 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
355 if ([file hasPrefix:prefix]) {
356 NSUInteger length([prefix length]);
357 if (length != [file length])
358 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
359 return path;
360 }
361 }
362
363 return self;
364}
365
366@end
367
9c64bab2
JF
368void WBLogRect(const char *tag, struct CGRect rect) {
369 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
370}
371
372void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
373 CGRect frame([view frame]);
198eb03b 374 NSLog(@"%*s|%2d:%p:%s : {%f,%f+%f,%f} (%@)", indent * 3, "", index, view, class_getName([view class]), frame.origin.x, frame.origin.y, frame.size.width, frame.size.height, [view backgroundColor]);
1a4ffdf8
JF
375 index = 0;
376 for (UIView *child in [view subviews])
9c64bab2 377 WBLogHierarchy(child, index++, indent + 1);
1a4ffdf8
JF
378}
379
82b4a0bd
JF
380UIImage *$cacheForImage$(UIImage *image) {
381 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
382 CGRect rect = {CGPointMake(1, 1), [image size]};
383 CGSize size = {rect.size.width + 2, rect.size.height + 2};
2acbe5b8 384
82b4a0bd
JF
385 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
386 CGColorSpaceRelease(space);
2acbe5b8 387
82b4a0bd
JF
388 CGContextDrawImage(context, rect, [image CGImage]);
389 CGImageRef ref(CGBitmapContextCreateImage(context));
390 CGContextRelease(context);
2acbe5b8 391
82b4a0bd
JF
392 UIImage *cache([UIImage imageWithCGImage:ref]);
393 CGImageRelease(ref);
2acbe5b8 394
82b4a0bd
JF
395 return cache;
396}
397
398/*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
399 //if ([name isEqualToString:@"icons"]) return nil;
400 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
401}*/
402
403MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
404 NSString *key([icon displayIdentifier]);
2acbe5b8 405
82b4a0bd
JF
406 if (UIImage *image = [icon icon]) {
407 CGSize size = [image size];
b0d0c73f 408 if (size.width != 59 || size.height != 60) {
82b4a0bd
JF
409 UIImage *cache($cacheForImage$(image));
410 [Cache_ setObject:cache forKey:key];
411 return;
412 }
2acbe5b8 413 }
82b4a0bd
JF
414
415 _SBIconModel$cacheImageForIcon$(self, sel, icon);
4e0efa01
JF
416}
417
1a4ffdf8
JF
418MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
419 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
420 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
421
422 NSString *key([icon displayIdentifier]);
423
424 if (UIImage *image = [icon icon]) {
425 CGSize size = [image size];
426 if (size.width != 59 || size.height != 60) {
427 UIImage *cache($cacheForImage$(image));
428 [Cache_ setObject:cache forKey:key];
429 return;
430 }
431 }
432}
433
0316ebc4 434MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
4e0efa01
JF
435 NSString *key([icon displayIdentifier]);
436 if (UIImage *image = [Cache_ objectForKey:key])
437 return image;
438 else
0316ebc4 439 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
4e0efa01
JF
440}
441
1a4ffdf8
JF
442MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
443 if (small)
444 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
445 NSString *key([icon displayIdentifier]);
446 if (UIImage *image = [Cache_ objectForKey:key])
447 return image;
448 else
449 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
450}
451
452MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
453 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
454 [self setBackgroundColor:[UIColor clearColor]];
455 for (UIView *child in [self subviews])
456 [child setBackgroundColor:[UIColor clearColor]];
457 } return self;
458}
459
9c64bab2
JF
460MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
461 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
462 [self setBackgroundColor:[UIColor clearColor]];
463 } return self;
464}
465
466MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
467 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
468 float inset([self edgeInset]);
469 [[UIColor clearColor] set];
470 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
471 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
472}
473
0316ebc4 474MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
37351a17 475 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
56539693 476 if (NSString *path = $pathForIcon$([self application]))
2acbe5b8 477 return [UIImage imageWithContentsOfFile:path];
0316ebc4 478 return _SBApplicationIcon$icon(self, sel);
394d1eb5
JF
479}
480
1d3b613f
JF
481MSHook(UIImage *, SBApplicationIcon$generateIconImage$, SBApplicationIcon *self, SEL sel, int type) {
482 if (type == 2)
ab3ce88d 483 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"]) {
f53378dc 484 if (IsWild_ && false) // XXX: delete this code, it should not be supported
77d89d52
JF
485 if (NSString *path72 = $pathForIcon$([self application], @"-72"))
486 return [UIImage imageWithContentsOfFile:path72];
487 if (NSString *path = $pathForIcon$([self application]))
488 if (UIImage *image = [UIImage imageWithContentsOfFile:path]) {
489 float width;
490 if ([$SBIcon respondsToSelector:@selector(defaultIconImageSize)])
491 width = [$SBIcon defaultIconImageSize].width;
492 else
493 width = 59;
494 return width == 59 ? image : [image _imageScaledToProportion:(width / 59.0) interpolationQuality:5];
495 }
ab3ce88d 496 }
1d3b613f
JF
497 return _SBApplicationIcon$generateIconImage$(self, sel, type);
498}
499
4f1b7acd 500MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
d806256e
JF
501 if (Debug_)
502 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
503 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
4f1b7acd 504 return [UIImage imageWithContentsOfFile:path];
d806256e 505 return _SBWidgetApplicationIcon$icon(self, sel);
4f1b7acd
JF
506}
507
0316ebc4 508MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
502d350e
JF
509 if (Debug_)
510 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
511 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
2acbe5b8 512 return [UIImage imageWithContentsOfFile:path];
0316ebc4 513 return _SBBookmarkIcon$icon(self, sel);
502d350e
JF
514}
515
0316ebc4 516MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
d5fb6e01
JF
517 if (NSString *path = $pathForIcon$(self))
518 return path;
0316ebc4 519 return _SBApplication$pathForIcon(self, sel);
d5168fd6
JF
520}
521
95a5777b 522static UIImage *CachedImageAtPath(NSString *path) {
4df9352e 523 path = [path stringByResolvingSymlinksInPath];
95a5777b
JF
524 UIImage *image = [PathImages_ objectForKey:path];
525 if (image != nil)
526 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
4df9352e 527 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
95a5777b
JF
528 if (image != nil)
529 image = [image autorelease];
530 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
531 return image;
532}
533
f64efe8d
JF
534MSHook(CGImageSourceRef, CGImageSourceCreateWithURL, CFURLRef url, CFDictionaryRef options) {
535 if (Debug_)
536 NSLog(@"WB:Debug: CGImageSourceCreateWithURL(\"%@\", %s)", url, options);
537 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
538 if (NSString *path = (NSString *) CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle))
539 if (NSString *themed = [path wb$themedPath])
540 if (themed != path)
541 url = (CFURLRef) [NSURL fileURLWithPath:themed];
542 CGImageSourceRef source(_CGImageSourceCreateWithURL(url, options));
543 [pool release];
544 return source;
545}
546
77d89d52 547MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation, float *scale) {
889cb4f2 548 if (Debug_)
77d89d52 549 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\")", name);
bae02419
JF
550
551 NSString *themed([name wb$themedPath]);
552
553 if (false && SpringBoard_ && SummerBoard_ && themed == name) {
554 if ([name isEqualToString:@"/System/Library/CoreServices/SpringBoard.app/SBDockBGT-Portrait.png"])
555 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Dock.png"])) {
556 UIImage *image([UIImage imageWithContentsOfFile:path]);
557 CGImageRef ref([[image _imageScaledToProportion:2.4 interpolationQuality:5] imageRef]);
558 CGImageRetain(ref);
559 return ref;
560 }
561 }
562
77d89d52 563 return __UIImageRefAtPath(themed, cache, orientation, scale);
889cb4f2
JF
564}
565
4df9352e
JF
566/*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
567 if (bundle == nil)
568 return __UIImageAtPath(name, nil);
569 else {
570 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
571 UIImage *image = [PathImages_ objectForKey:key];
572 if (image != nil)
573 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
574 if (Debug_)
575 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
576 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
577 image = CachedImageAtPath(path);
578 if (image == nil)
579 image = __UIImageAtPath(name, bundle);
580 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
581 return image;
582 }
583}*/
889cb4f2 584
4df9352e 585MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
d5fb6e01
JF
586 NSBundle *bundle = [NSBundle mainBundle];
587 if (Debug_)
4df9352e 588 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
95a5777b
JF
589 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
590 return CachedImageAtPath(path);
4df9352e 591 return __UIApplicationImageWithName(name);
502d350e
JF
592}
593
502d350e
JF
594#define WBDelegate(delegate) \
595 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
596 if (Engineer_) \
597 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
598 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
599 return sig; \
600 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
601 return nil; \
602 } \
603\
604 - (void) forwardInvocation:(NSInvocation*)inv { \
605 SEL sel = [inv selector]; \
606 if ([delegate respondsToSelector:sel]) \
607 [inv invokeWithTarget:delegate]; \
608 else \
609 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
610 }
611
0316ebc4 612MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
889cb4f2
JF
613 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
614 if (Debug_)
615 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
95a5777b 616 if (NSString *path = $pathForFile$inBundle$(file, self, false))
ca13798d 617 return path;
0316ebc4 618 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
d5168fd6
JF
619}
620
0316ebc4 621void $setBarStyle$_(NSString *name, int &style) {
95a5777b
JF
622 if (Debug_)
623 NSLog(@"WB:Debug:%@Style:%d", name, style);
624 NSNumber *number = nil;
625 if (number == nil)
626 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
627 if (number == nil)
628 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
0316ebc4 629 if (number != nil) {
95a5777b
JF
630 style = [number intValue];
631 if (Debug_)
632 NSLog(@"WB:Debug:%@Style=%d", name, style);
26c43b47 633 }
26c43b47
JF
634}
635
0316ebc4 636MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
4668cd8e
JF
637 NSBundle *bundle([NSBundle mainBundle]);
638
e6f0817b
JF
639 CFLocaleRef locale(CFLocaleCopyCurrent());
640 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
641 CFRelease(locale);
642
643 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
644
77d89d52 645 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"d" table:@"SpringBoard"]);
e6f0817b 646 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
44aa4549 647 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
e6f0817b
JF
648 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
649
650 CFRelease(now);
651
652 CFRelease(formatter);
653
c79980f5 654 NSString *datestyle([@""
e6f0817b
JF
655 "font-family: Helvetica; "
656 "font-weight: bold; "
e6f0817b
JF
657 "color: #333333; "
658 "alpha: 1.0; "
1d3b613f 659 "" stringByAppendingString:(IsWild_
c79980f5
JF
660 ? @"font-size: 54px; "
661 : @"font-size: 39px; "
662 )]);
e6f0817b 663
c79980f5 664 NSString *daystyle([@""
e6f0817b
JF
665 "font-family: Helvetica; "
666 "font-weight: bold; "
e6f0817b
JF
667 "color: white; "
668 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
1d3b613f 669 "" stringByAppendingString:(IsWild_
c79980f5
JF
670 ? @"font-size: 11px; "
671 : @"font-size: 9px; "
672 )]);
e6f0817b
JF
673
674 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
675 datestyle = [datestyle stringByAppendingString:style];
676 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
677 daystyle = [daystyle stringByAppendingString:style];
678
cf31d246 679 float width([self bounds].size.width);
4668cd8e
JF
680 float leeway(10);
681 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
682 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
e6f0817b 683
77d89d52 684 unsigned base0(IsWild_ ? 89 : 70);
c79980f5 685 if ($GSFontGetUseLegacyFontMetrics())
77d89d52
JF
686 base0 = base0 + 1;
687 unsigned base1(IsWild_ ? 18 : 16);
688
689 if (Four_) {
690 ++base0;
691 ++base1;
692 }
81decb42 693
e6f0817b 694 [(NSString *)date drawAtPoint:CGPointMake(
77d89d52 695 (width + 1 - datesize.width) / 2, (base0 - datesize.height) / 2
e6f0817b
JF
696 ) withStyle:datestyle];
697
698 [(NSString *)day drawAtPoint:CGPointMake(
77d89d52 699 (width + 1 - daysize.width) / 2, (base1 - daysize.height) / 2
e6f0817b
JF
700 ) withStyle:daystyle];
701
702 CFRelease(date);
703 CFRelease(day);
704}
705
502d350e 706/*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
69550bfb 707_trace();
26c43b47 708
d5fb6e01
JF
709 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
710 style = [number intValue];
26c43b47 711
37351a17 712 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
d5fb6e01 713 tint = color;
26c43b47 714
2acbe5b8 715 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
26c43b47
JF
716}*/
717
502d350e 718/*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
2acbe5b8 719 self = [self wb$initWithCoder:coder];
26c43b47
JF
720 if (self == nil)
721 return nil;
722 UINavigationBar$setBarStyle$_(self);
723 return self;
724}
725
502d350e 726static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
2acbe5b8 727 self = [self wb$initWithFrame:frame];
26c43b47
JF
728 if (self == nil)
729 return nil;
730 UINavigationBar$setBarStyle$_(self);
731 return self;
732}*/
733
0316ebc4
JF
734MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
735 $setBarStyle$_(@"Toolbar", style);
736 return _UIToolbar$setBarStyle$(self, sel, style);
95a5777b
JF
737}
738
0316ebc4
JF
739MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
740 $setBarStyle$_(@"NavigationBar", style);
741 return _UINavigationBar$setBarStyle$(self, sel, style);
26c43b47
JF
742}
743
0316ebc4 744MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
2acbe5b8 745 [[self superview] setBackgroundColor:[UIColor clearColor]];
0316ebc4 746 _SBButtonBar$didMoveToSuperview(self, sel);
08454e3a 747}
62b2dbad 748
0316ebc4
JF
749MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
750 [[self superview] setBackgroundColor:[UIColor clearColor]];
751 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
752}
753
754MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
502d350e
JF
755 if (Debug_)
756 NSLog(@"WB:Debug:DefaultDesktopImage");
757 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
2acbe5b8 758 return [UIImage imageWithContentsOfFile:path];
0316ebc4 759 return _UIImage$defaultDesktopImage(self, sel);
502d350e
JF
760}
761
4668cd8e 762static NSArray *Wallpapers_;
1d3b613f 763static bool Papered_;
77d89d52 764static bool Docked_;
4668cd8e 765static NSString *WallpaperFile_;
502d350e
JF
766static UIImageView *WallpaperImage_;
767static UIWebDocumentView *WallpaperPage_;
768static NSURL *WallpaperURL_;
95a5777b 769
4668cd8e
JF
770#define _release(object) \
771 do if (object != nil) { \
772 [object release]; \
773 object = nil; \
774 } while (false)
775
69550bfb
JF
776MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
777 self = _SBUIController$init(self, sel);
d5168fd6
JF
778 if (self == nil)
779 return nil;
780
609e1cd8
JF
781 {
782 size_t size;
783 sysctlbyname("hw.machine", NULL, &size, NULL, 0);
784 char *machine = new char[size];
785
786 if (sysctlbyname("hw.machine", machine, &size, NULL, 0) == -1) {
787 perror("sysctlbyname(\"hw.machine\", ?)");
788 delete [] machine;
789 machine = NULL;
790 }
791
792 IsWild_ = machine != NULL && strncmp(machine, "iPad", 4) == 0;
793 }
226d2af9 794
3135f5ed
JF
795 BOOL (*GSSystemHasCapability)(CFStringRef) = reinterpret_cast<BOOL (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemHasCapability"));
796
0137e6de
JF
797 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
798 [Info_ setObject:[NSNumber numberWithBool:(
3135f5ed 799 !(Papered_ || GSSystemHasCapability != NULL && GSSystemHasCapability(CFSTR("homescreen-wallpaper"))) ||
0137e6de
JF
800 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
801 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
802 )] forKey:@"UndockedIconLabels"];
803
804 if (Debug_)
805 NSLog(@"WB:Debug:Info = %@", [Info_ description]);
806
1d3b613f 807 if (Papered_) {
55e82d74 808 UIImageView *&_wallpaperView(MSHookIvar<UIImageView *>(self, "_wallpaperView"));
1d3b613f
JF
809 if (&_wallpaperView != NULL) {
810 [_wallpaperView removeFromSuperview];
811 [_wallpaperView release];
812 _wallpaperView = nil;
813 }
814 }
815
44aa4549 816 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
69550bfb
JF
817 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
818
77d89d52 819 UIView **player;
44aa4549 820 if (&_contentLayer != NULL)
77d89d52 821 player = &_contentLayer;
44aa4549 822 else if (&_contentView != NULL)
77d89d52 823 player = &_contentView;
44aa4549 824 else
77d89d52 825 player = NULL;
77d89d52 826 UIView *layer(player == NULL ? nil : *player);
44aa4549 827
55e82d74
JF
828 UIWindow *window([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
829 UIView *content([[[UIView alloc] initWithFrame:[window frame]] autorelease]);
830 [window setContentView:content];
831
832 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
833 [window setBackgroundColor:[_window backgroundColor]];
834 [_window setBackgroundColor:[UIColor clearColor]];
835
836 [window setLevel:-1000];
837 [window setHidden:NO];
1d3b613f 838
77d89d52
JF
839 /*if (player != NULL)
840 *player = content;*/
841
44aa4549
JF
842 [content setBackgroundColor:[layer backgroundColor]];
843 [layer setBackgroundColor:[UIColor clearColor]];
69550bfb 844
1d3b613f
JF
845 UIView *indirect;
846 if (!SummerBoard_ || !IsWild_)
847 indirect = content;
848 else {
849 CGRect bounds([content bounds]);
c8fbf228 850 bounds.origin.y = -30;
1d3b613f
JF
851 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
852 [content addSubview:indirect];
853 [indirect zoomToScale:2.4];
854 }
855
4668cd8e
JF
856 _release(WallpaperFile_);
857 _release(WallpaperImage_);
858 _release(WallpaperPage_);
859 _release(WallpaperURL_);
860
861 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
862 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
863 if ([Manager_ fileExistsAtPath:mp4]) {
d806256e
JF
864#if UseAVController
865 NSError *error;
866
867 static AVController *controller_(nil);
868 if (controller_ == nil) {
869 AVQueue *queue([AVQueue avQueue]);
870 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
871 }
872
873 AVQueue *queue([controller_ queue]);
874
1d3b613f 875 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
d806256e
JF
876 [controller_ setLayer:[video _layer]];
877
878 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
879 [queue appendItem:item error:&error];
880
881 [controller_ play:&error];
882#elif UseMPMoviePlayerController
883 NSURL *url([NSURL fileURLWithPath:mp4]);
265e19b2 884 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
d806256e
JF
885 controller.movieControlMode = MPMovieControlModeHidden;
886 [controller play];
887#else
1d3b613f 888 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
4668cd8e
JF
889 [video setMovieWithPath:mp4];
890 [video setRepeatMode:1];
d806256e 891 [video setRepeatGap:-1];
4668cd8e 892 [video playFromBeginning];;
d806256e
JF
893#endif
894
1d3b613f 895 [indirect addSubview:video];
4668cd8e 896 }
d5fb6e01 897
4668cd8e
JF
898 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
899 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
95a5777b 900
4668cd8e
JF
901 NSString *path;
902 if ([Manager_ fileExistsAtPath:png])
903 path = png;
904 else if ([Manager_ fileExistsAtPath:jpg])
905 path = jpg;
906 else path = nil;
d5fb6e01 907
4668cd8e
JF
908 UIImage *image;
909 if (path != nil) {
4df9352e 910 image = [[UIImage alloc] initWithContentsOfFile:path];
4668cd8e
JF
911 if (image != nil)
912 image = [image autorelease];
913 } else image = nil;
394d1eb5 914
4668cd8e
JF
915 if (image != nil) {
916 WallpaperFile_ = [path retain];
917 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
9c64bab2
JF
918 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
919 [WallpaperImage_ setAlpha:[number floatValue]];
1d3b613f 920 [indirect addSubview:WallpaperImage_];
4668cd8e 921 }
394d1eb5 922
4668cd8e
JF
923 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
924 if ([Manager_ fileExistsAtPath:html]) {
1d3b613f 925 CGRect bounds = [indirect bounds];
502d350e 926
4668cd8e
JF
927 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
928 [view setAutoresizes:true];
502d350e 929
4668cd8e
JF
930 WallpaperPage_ = [view retain];
931 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
394d1eb5 932
4668cd8e
JF
933 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
934
4668cd8e 935 [view setBackgroundColor:[UIColor clearColor]];
1a4ffdf8
JF
936 if ([view respondsToSelector:@selector(setDrawsBackground:)])
937 [view setDrawsBackground:NO];
938 [[view webView] setDrawsBackground:NO];
394d1eb5 939
1d3b613f 940 [indirect addSubview:view];
4668cd8e 941 }
08454e3a 942 }
d5168fd6 943
5e5c7190
JF
944 for (size_t i(0), e([themes_ count]); i != e; ++i) {
945 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
946 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
947 if ([Manager_ fileExistsAtPath:html]) {
1d3b613f 948 CGRect bounds = [indirect bounds];
5e5c7190
JF
949
950 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
951 [view setAutoresizes:true];
952
953 NSURL *url = [NSURL fileURLWithPath:html];
954 [view loadRequest:[NSURLRequest requestWithURL:url]];
955
5e5c7190 956 [view setBackgroundColor:[UIColor clearColor]];
1a4ffdf8
JF
957 if ([view respondsToSelector:@selector(setDrawsBackground:)])
958 [view setDrawsBackground:NO];
959 [[view webView] setDrawsBackground:NO];
5e5c7190 960
1d3b613f 961 [indirect addSubview:view];
5e5c7190
JF
962 }
963 }
964
d5168fd6
JF
965 return self;
966}
967
9cfe3924 968MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
502d350e 969 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
2acbe5b8 970 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
502d350e 971
2acbe5b8
JF
972 if (path != nil && _backgroundView != nil)
973 path = nil;
502d350e 974
9cfe3924 975 _SBAwayView$updateDesktopImage$(self, sel, image);
502d350e
JF
976
977 if (path != nil) {
978 CGRect bounds = [self bounds];
979
2acbe5b8 980 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
502d350e
JF
981 [view setAutoresizes:true];
982
983 if (WallpaperPage_ != nil)
984 [WallpaperPage_ release];
985 WallpaperPage_ = [view retain];
986
987 if (WallpaperURL_ != nil)
988 [WallpaperURL_ release];
989 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
990
991 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
992
993 [[view webView] setDrawsBackground:false];
2acbe5b8 994 [view setBackgroundColor:[UIColor clearColor]];
502d350e 995
2acbe5b8 996 [self insertSubview:view aboveSubview:_backgroundView];
ca13798d 997 }
502d350e 998}
ca13798d 999
95a5777b 1000/*extern "C" CGColorRef CGGStateGetSystemColor(void *);
ca13798d
JF
1001extern "C" CGColorRef CGGStateGetFillColor(void *);
1002extern "C" CGColorRef CGGStateGetStrokeColor(void *);
95a5777b 1003extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
ca13798d 1004
cd6ad593
JF
1005/* WBTimeLabel {{{ */
1006@interface WBTimeLabel : NSProxy {
ca13798d
JF
1007 NSString *time_;
1008 _transient SBStatusBarTimeView *view_;
889cb4f2
JF
1009}
1010
ca13798d 1011- (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
889cb4f2
JF
1012
1013@end
1014
cd6ad593 1015@implementation WBTimeLabel
889cb4f2
JF
1016
1017- (void) dealloc {
ca13798d 1018 [time_ release];
889cb4f2
JF
1019 [super dealloc];
1020}
1021
ca13798d
JF
1022- (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
1023 time_ = [time retain];
1024 view_ = view;
889cb4f2
JF
1025 return self;
1026}
1027
44aa4549
JF
1028- (NSString *) description {
1029 return time_;
1030}
1031
ca13798d
JF
1032WBDelegate(time_)
1033
1034- (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
d5fb6e01 1035 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
2acbe5b8 1036 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
d5fb6e01
JF
1037
1038 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
1039 "font-family: Helvetica; "
1040 "font-weight: bold; "
1041 "font-size: 14px; "
1042 "color: %@; "
2acbe5b8 1043 "%@", _mode ? @"white" : @"black", custom]];
d5fb6e01
JF
1044
1045 return CGSizeZero;
1046 }
ca13798d
JF
1047
1048 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
889cb4f2
JF
1049}
1050
cd6ad593
JF
1051@end
1052/* }}} */
1053/* WBBadgeLabel {{{ */
1054@interface WBBadgeLabel : NSProxy {
1055 NSString *badge_;
1056}
1057
1058- (id) initWithBadge:(NSString *)badge;
29155933 1059- (NSString *) description;
cd6ad593 1060
ca13798d
JF
1061@end
1062
cd6ad593
JF
1063@implementation WBBadgeLabel
1064
1065- (void) dealloc {
1066 [badge_ release];
1067 [super dealloc];
889cb4f2
JF
1068}
1069
cd6ad593
JF
1070- (id) initWithBadge:(NSString *)badge {
1071 badge_ = [badge retain];
1072 return self;
1073}
1074
29155933
JF
1075- (NSString *) description {
1076 return [badge_ description];
1077}
1078
cd6ad593
JF
1079WBDelegate(badge_)
1080
1081- (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
1082 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
1083 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
1084 "font-family: Helvetica; "
1085 "font-weight: bold; "
1086 "font-size: 17px; "
1087 "color: white; "
1088 "%@", custom]];
1089
1090 return CGSizeZero;
1091 }
1092
1093 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1094}
ca13798d
JF
1095
1096@end
cd6ad593
JF
1097/* }}} */
1098
8e4d2f42
JF
1099MSHook(void, SBIconView$setIconImageAlpha$, SBIconView *self, SEL sel, float alpha) {
1100 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1101 alpha = [number floatValue];
1102 return _SBIconView$setIconImageAlpha$(self, sel, alpha);
1103}
1104
1105MSHook(void, SBIconView$setIconLabelAlpha$, SBIconView *self, SEL sel, float alpha) {
1106 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1107 alpha = [number floatValue];
1108 return _SBIconView$setIconLabelAlpha$(self, sel, alpha);
1109}
1110
1111MSHook(id, SBIconView$initWithDefaultSize, SBIconView *self, SEL sel) {
1112 if ((self = _SBIconView$initWithDefaultSize(self, sel)) != nil) {
1113 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"]) {
1114 // XXX: note: this is overridden above, which is silly
1115 float alpha([number floatValue]);
1116 [self setIconImageAlpha:alpha];
1117 [self setIconLabelAlpha:alpha];
1118 }
1119 } return self;
1120}
1121
b0d0c73f
JF
1122MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1123 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1124 alpha = [number floatValue];
1125 return _SBIcon$setAlpha$(self, sel, alpha);
1126}
1127
0316ebc4
JF
1128MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1129 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
2acbe5b8
JF
1130 id &_badge(MSHookIvar<id>(self, "_badge"));
1131 if (_badge != nil)
1132 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1133 _badge = label;
cd6ad593
JF
1134 } return self;
1135}
ca13798d 1136
69550bfb 1137void SBStatusBarController$setStatusBarMode(int &mode) {
95a5777b
JF
1138 if (Debug_)
1139 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
502d350e 1140 if (mode < 100) // 104:hidden 105:glowing
95a5777b
JF
1141 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1142 mode = [number intValue];
d5fb6e01
JF
1143}
1144
69550bfb
JF
1145/*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1146 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1147 SBStatusBarController$setStatusBarMode(mode);
1148 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1149}*/
1150
1151MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
8b94f6b0 1152 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
69550bfb
JF
1153 SBStatusBarController$setStatusBarMode(mode);
1154 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1155}
1156
1157MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int fenceID, int animation, double startTime) {
8b94f6b0 1158 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
69550bfb 1159 SBStatusBarController$setStatusBarMode(mode);
8b94f6b0 1160 //NSLog(@"mode=%u", mode);
69550bfb
JF
1161 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1162}
1163
1164/*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
d5fb6e01
JF
1165 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1166 mode = [number intValue];
0316ebc4 1167 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
69550bfb 1168}*/
d5fb6e01 1169
0316ebc4
JF
1170MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1171 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
4668cd8e
JF
1172 if (Debug_)
1173 NSLog(@"operatorNameStyle= %@", style);
1174 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1175 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1176 return style;
1177}
1178
0316ebc4 1179MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
4668cd8e
JF
1180 if (Debug_)
1181 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
0316ebc4 1182 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
4668cd8e
JF
1183}
1184
0316ebc4
JF
1185// XXX: replace this with [SBStatusBarTimeView tile]
1186MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
2acbe5b8
JF
1187 id &_time(MSHookIvar<id>(self, "_time"));
1188 if (_time != nil && [_time class] != [WBTimeLabel class])
1189 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
0316ebc4 1190 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
ca13798d
JF
1191}
1192
98fe8d52 1193@interface UIView (WinterBoard)
a8d008e4 1194- (bool) wb$isWBImageView;
198eb03b 1195- (void) wb$logHierarchy;
98fe8d52
JF
1196@end
1197
1198@implementation UIView (WinterBoard)
1199
a8d008e4 1200- (bool) wb$isWBImageView {
98fe8d52
JF
1201 return false;
1202}
1203
198eb03b
JF
1204- (void) wb$logHierarchy {
1205 WBLogHierarchy(self);
1206}
1207
98fe8d52
JF
1208@end
1209
a8d008e4
JF
1210@interface WBImageView : UIImageView {
1211}
1212
1213- (bool) wb$isWBImageView;
1214- (void) wb$updateFrame;
98fe8d52
JF
1215@end
1216
a8d008e4 1217@implementation WBImageView
98fe8d52 1218
a8d008e4 1219- (bool) wb$isWBImageView {
98fe8d52
JF
1220 return true;
1221}
1222
a8d008e4
JF
1223- (void) wb$updateFrame {
1224 CGRect frame([self frame]);
1225 frame.origin.y = 0;
1226
1227 for (UIView *view(self); ; ) {
1228 view = [view superview];
1229 if (view == nil)
1230 break;
1231 frame.origin.y -= [view frame].origin.y;
1232 }
1233
1234 [self setFrame:frame];
1235}
1236
98fe8d52
JF
1237@end
1238
a8d008e4
JF
1239MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1240 NSArray *subviews([self subviews]);
1241 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1242 if (view != nil && [view wb$isWBImageView])
1243 [view wb$updateFrame];
1244 _SBIconList$setFrame$(self, sel, frame);
1245}
1246
98fe8d52
JF
1247MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1248 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1249 NSArray *lists([_iconModel iconLists]);
1250
1251 for (unsigned i(0), e([lists count]); i != e; ++i)
1252 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1253 SBIconList *list([lists objectAtIndex:i]);
1254 NSArray *subviews([list subviews]);
a8d008e4
JF
1255
1256 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1257 if (view == nil || ![view wb$isWBImageView]) {
1258 view = [[[WBImageView alloc] init] autorelease];
98fe8d52
JF
1259 [list insertSubview:view atIndex:0];
1260 }
a8d008e4 1261
98fe8d52 1262 UIImage *image([UIImage imageWithContentsOfFile:path]);
1a4ffdf8
JF
1263
1264 CGRect frame([view frame]);
1265 frame.size = [image size];
1266 [view setFrame:frame];
1267
98fe8d52 1268 [view setImage:image];
a8d008e4 1269 [view wb$updateFrame];
98fe8d52
JF
1270 }
1271
1272 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
95a5777b
JF
1273}
1274
e542b0ca
JF
1275MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1276 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
cf31d246
JF
1277 if (self != nil)
1278 [self setClipsToBounds:NO];
1279 return self;
1280}
1281
e542b0ca 1282MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
2acbe5b8 1283 id &_label(MSHookIvar<id>(self, "_label"));
37351a17 1284 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
95a5777b 1285 docked = true;
2acbe5b8
JF
1286 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1287 [_label setInDock:docked];
e542b0ca 1288 return _SBIconLabel$setInDock$(self, sel, docked);
889cb4f2
JF
1289}
1290
77d89d52
JF
1291MSHook(BOOL, SBDockIconListView$shouldShowNewDock, id self, SEL sel) {
1292 return SummerBoard_ && Docked_ ? NO : _SBDockIconListView$shouldShowNewDock(self, sel);
1293}
1294
1295MSHook(void, SBDockIconListView$setFrame$, id self, SEL sel, CGRect frame) {
1296 _SBDockIconListView$setFrame$(self, sel, frame);
1297}
1298
0316ebc4 1299MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
4fa950df
JF
1300 NSString *identifier = [self bundleIdentifier];
1301 NSLocale *locale = [NSLocale currentLocale];
1302 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
2acbe5b8 1303 if (Debug_)
4fa950df
JF
1304 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1305 NSString *file = table == nil ? @"Localizable" : table;
1306 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1307 NSDictionary *strings;
1308 if ((strings = [Strings_ objectForKey:name]) != nil) {
1309 if (static_cast<id>(strings) != [NSNull null]) strings:
1310 if (NSString *value = [strings objectForKey:key])
1311 return value;
1312 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1313 language, file
1314 ], self, false)) {
1315 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1316 [Strings_ setObject:[strings autorelease] forKey:name];
1317 goto strings;
1318 } else goto null;
1319 } else null:
1320 [Strings_ setObject:[NSNull null] forKey:name];
0316ebc4 1321 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
4fa950df
JF
1322}
1323
7ff778ee 1324@class WebCoreFrameBridge;
0316ebc4 1325MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
7ff778ee
JF
1326 if (node == nil)
1327 return CGSizeZero;
1328 void **core(reinterpret_cast<void **>([node _node]));
1329 if (core == NULL || core[6] == NULL)
1330 return CGSizeZero;
0316ebc4 1331 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
7ff778ee
JF
1332}
1333
e542b0ca 1334MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
cf31d246 1335 CGRect bounds = [self bounds];
e6f0817b 1336
a3fa54a5
JF
1337 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1338
aa6529f2 1339 int docked;
a3fa54a5
JF
1340 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1341 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
cf31d246 1342
6134e674 1343 NSString *label(MSHookIvar<NSString *>(self, "_label"));
cf31d246
JF
1344
1345 NSString *style = [NSString stringWithFormat:@""
1346 "font-family: Helvetica; "
1347 "font-weight: bold; "
ac1be56e 1348 "color: %@; %@"
1d3b613f 1349 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
ac1be56e
JF
1350 ? @"font-size: 12px; "
1351 : @"font-size: 11px; "
1352 )];
1353
1d3b613f 1354 if (IsWild_)
ac1be56e
JF
1355 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1356 else if (docked)
cf31d246 1357 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
d806256e
JF
1358
1359 bool ellipsis(false);
1360 float max = 75, width;
1361 width:
1362 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1363
1364 if (width > max) {
1365 size_t length([label length]);
1366 float spacing((width - max) / (length - 1));
1367
1368 if (spacing > 1.25) {
1369 ellipsis = true;
1370 label = [label substringToIndex:(length - 1)];
1371 goto width;
1372 }
1373
1374 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1375 }
1376
1377 if (ellipsis)
1378 label = [label stringByAppendingString:@"..."];
1379
cf31d246
JF
1380 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1381 style = [style stringByAppendingString:custom];
1382
1383 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1384 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
889cb4f2
JF
1385}
1386
198eb03b
JF
1387MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1388 _CKMessageCell$addBalloonView$(self, sel, balloon);
1389 [balloon setBackgroundColor:[UIColor clearColor]];
1390}
1391
1392MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1393 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1394 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1395 } return self;
1396}
1397
1398MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1399 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1400 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1401 [_label setBackgroundColor:[UIColor clearColor]];
1402 } return self;
1403}
1404
1405MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1406 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1407}
1408
1409MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1410 _trace();
1411 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1412 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1413 } return self;
1414}
1415
8b94f6b0
JF
1416MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1417 _TranscriptController$loadView(self, sel);
e542b0ca 1418
4668cd8e 1419 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
4df9352e 1420 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
4668cd8e 1421 [image autorelease];
8b94f6b0
JF
1422
1423 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
4668cd8e 1424 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
8b94f6b0
JF
1425 UIView *table;
1426 if (&_transcriptTable != NULL)
1427 table = _transcriptTable;
1428 else if (&_transcriptLayer != NULL)
1429 table = _transcriptLayer;
1430 else
1431 table = nil;
1432
1433 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
4668cd8e 1434 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
8b94f6b0
JF
1435
1436 if (table == nil)
1437 [placard insertSubview:background atIndex:0];
1438 else {
1439 [table setBackgroundColor:[UIColor clearColor]];
1440 [placard insertSubview:background belowSubview:table];
1441 }
4668cd8e
JF
1442 }
1443}
1444
4df9352e 1445MSHook(UIImage *, _UIImageWithName, NSString *name) {
95a5777b 1446 if (Debug_)
77d89d52 1447 NSLog(@"WB:Debug: _UIImageWithName(\"%@\")", name);
2c2082b3
JF
1448 if (name == nil)
1449 return nil;
77d89d52
JF
1450
1451 int identifier;
1452 bool packed;
1453
1454 if (_UIPackedImageTableGetIdentifierForName != NULL)
1455 packed = _UIPackedImageTableGetIdentifierForName(name, &identifier);
1456 else if (_UISharedImageNameGetIdentifier != NULL) {
1457 identifier = _UISharedImageNameGetIdentifier(name);
1458 packed = identifier != -1;
1459 } else {
1460 identifier = -1;
1461 packed = false;
1462 }
1463
1464 if (Debug_)
1465 NSLog(@"WB:Debug: _UISharedImageNameGetIdentifier(\"%@\") = %d", name, identifier);
95a5777b 1466
77d89d52
JF
1467 if (!packed)
1468 return __UIImageWithName(name);
95a5777b 1469 else {
77d89d52
JF
1470 NSNumber *key([NSNumber numberWithInt:identifier]);
1471 UIImage *image([UIImages_ objectForKey:key]);
95a5777b 1472 if (image != nil)
77d89d52 1473 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithName(name) : image;
95a5777b 1474 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
4f1b7acd 1475 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
95a5777b
JF
1476 if (image != nil)
1477 [image autorelease];
1478 }
95a5777b 1479 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
77d89d52 1480 return image == nil ? __UIImageWithName(name) : image;
95a5777b
JF
1481 }
1482}
1483
4df9352e 1484MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
96442a01
JF
1485 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1486 UIImage *image([PathImages_ objectForKey:key]);
e6f0817b 1487 if (image != nil)
96442a01 1488 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
95a5777b 1489 if (Debug_)
e6f0817b
JF
1490 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1491 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
4df9352e 1492 image = [[UIImage alloc] initWithContentsOfFile:path];
e6f0817b
JF
1493 if (image != nil)
1494 [image autorelease];
95a5777b 1495 }
e6f0817b 1496 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
96442a01 1497 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
95a5777b
JF
1498}
1499
d806256e 1500MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
9c64bab2
JF
1501 if (Debug_)
1502 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
d806256e
JF
1503 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1504 name = [font UTF8String];
bae02419
JF
1505 //if (NSString *scale = [Info_ objectForKey:[NSString stringWithFormat:@"FontScale-%s", name]])
1506 // size *= [scale floatValue];
d806256e
JF
1507 return _GSFontCreateWithName(name, traits, size);
1508}
1509
95a5777b
JF
1510#define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1511#define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1512
e542b0ca 1513bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
95a5777b 1514
e542b0ca 1515MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
9c64bab2
JF
1516 if (Debug_)
1517 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
e542b0ca 1518 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
95a5777b
JF
1519 if (Debug_)
1520 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1521
1522 if (value) {
1523 NSString *path = [NSString stringWithUTF8String:a1];
1524 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1525 NSString *file = [path substringFromIndex:31];
95a5777b
JF
1526 for (NSString *theme in themes_) {
1527 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1528 if ([Manager_ fileExistsAtPath:path]) {
1529 strcpy(a1, [path UTF8String]);
1530 continue;
1531 }
1532 }
1533 }
1534 }
1535 return value;
1536}
1537
1538static void ChangeWallpaper(
1539 CFNotificationCenterRef center,
1540 void *observer,
1541 CFStringRef name,
1542 const void *object,
1543 CFDictionaryRef info
1544) {
1545 if (Debug_)
1546 NSLog(@"WB:Debug:ChangeWallpaper!");
502d350e 1547
95a5777b 1548 UIImage *image;
4668cd8e 1549 if (WallpaperFile_ != nil) {
4df9352e 1550 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
95a5777b
JF
1551 if (image != nil)
1552 image = [image autorelease];
1553 } else image = nil;
502d350e
JF
1554
1555 if (WallpaperImage_ != nil)
1556 [WallpaperImage_ setImage:image];
1557 if (WallpaperPage_ != nil)
1558 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1559
95a5777b 1560}
394d1eb5 1561
0316ebc4
JF
1562#define WBRename(name, sel, imp) \
1563 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
e6f0817b 1564
9c64bab2
JF
1565template <typename Type_>
1566static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1567 struct nlist &name(nl[index]);
1568 uintptr_t value(name.n_value);
1569 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1570 value |= 0x00000001;
1571 function = reinterpret_cast<Type_>(value);
1572}
1573
1574template <typename Type_>
1575static void dlset(Type_ &function, const char *name) {
8b94f6b0 1576 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
9c64bab2
JF
1577}
1578
f64efe8d
JF
1579/*static void WBImage(const struct mach_header* mh, intptr_t vmaddr_slide) {
1580 uint32_t count(_dyld_image_count());
1581 for (uint32_t index(0); index != count; ++index)
1582 if (_dyld_get_image_header(index) == mh) {
1583 CGImageSourceRef (*CGImageSourceCreateWithURL)(CFURLRef url, CFDictionaryRef options);
1584 dlset(CGImageSourceCreateWithURL, "CGImageSourceCreateWithURL");
1585 MSHookFunction(&CGImageSourceCreateWithURL, &$CGImageSourceCreateWithURL, &_CGImageSourceCreateWithURL);
1586 }
1587}*/
1588
d5168fd6 1589extern "C" void WBInitialize() {
265e19b2 1590 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
d5168fd6 1591
2acbe5b8 1592 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
394d1eb5 1593
2acbe5b8 1594 NSLog(@"WB:Notice: WinterBoard");
95a5777b 1595
9c64bab2 1596 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
81decb42 1597
f64efe8d
JF
1598 //if ([NSBundle bundleWithIdentifier:@"com.apple.ImageIO.framework"] != nil)
1599 MSHookFunction(&CGImageSourceCreateWithURL, &$CGImageSourceCreateWithURL, &_CGImageSourceCreateWithURL);
1600 //else
1601 // _dyld_register_func_for_add_image(&WBImage);
1602
69550bfb 1603 struct nlist nl[8];
394d1eb5 1604
f64efe8d
JF
1605 if ([NSBundle bundleWithIdentifier:@"com.apple.UIKit"] != nil) {
1606// UIKit {{{
1607 memset(nl, 0, sizeof(nl));
1608 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1609 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1610 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1611 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1612 nl[4].n_un.n_name = (char *) "__UIKitBundle";
77d89d52
JF
1613 nl[5].n_un.n_name = (char *) "__UIPackedImageTableGetIdentifierForName";
1614 nl[6].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
f64efe8d
JF
1615 nlist(UIKit, nl);
1616
1617 nlset(_UIApplicationImageWithName, nl, 0);
1618 nlset(_UIImageAtPath, nl, 1);
1619 nlset(_UIImageRefAtPath, nl, 2);
1620 nlset(_UIImageWithNameInDomain, nl, 3);
1621 nlset(_UIKitBundle, nl, 4);
77d89d52
JF
1622 nlset(_UIPackedImageTableGetIdentifierForName, nl, 5);
1623 nlset(_UISharedImageNameGetIdentifier, nl, 6);
f64efe8d
JF
1624
1625 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1626 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1627 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1628 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1629// }}}
1630 }
95a5777b 1631
d806256e
JF
1632 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1633
95a5777b 1634 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
f64efe8d 1635// AudioToolbox {{{
95a5777b
JF
1636 struct nlist nl[2];
1637 memset(nl, 0, sizeof(nl));
1638 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1639 nlist(AudioToolbox, nl);
9c64bab2 1640 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
e542b0ca 1641 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
f64efe8d 1642// }}}
95a5777b 1643 }
2435118f 1644
0316ebc4
JF
1645 $NSBundle = objc_getClass("NSBundle");
1646
1647 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1648 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1649
1650 $UIImage = objc_getClass("UIImage");
1651 $UINavigationBar = objc_getClass("UINavigationBar");
1652 $UIToolbar = objc_getClass("UIToolbar");
1653
1654 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
e6f0817b 1655
265e19b2
JF
1656 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1657 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
e6f0817b 1658
0316ebc4
JF
1659 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1660 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
e6f0817b 1661
502d350e
JF
1662 Manager_ = [[NSFileManager defaultManager] retain];
1663 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1664 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
4fa950df 1665 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
4df9352e 1666 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
e839c3fe 1667 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
502d350e 1668
d5fb6e01 1669 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
26c43b47 1670
265e19b2 1671 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
f64efe8d 1672// Load Settings {{{
265e19b2
JF
1673 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1674 SummerBoard_ = [value boolValue];
1675 if (NSNumber *value = [settings objectForKey:@"Debug"])
1676 Debug_ = [value boolValue];
62b2dbad 1677
265e19b2 1678 NSArray *themes([settings objectForKey:@"Themes"]);
d5fb6e01
JF
1679 if (themes == nil)
1680 if (NSString *theme = [settings objectForKey:@"Theme"])
1681 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1682 theme, @"Name",
95a5777b 1683 [NSNumber numberWithBool:true], @"Active",
d5fb6e01 1684 nil]];
265e19b2 1685
d5fb6e01
JF
1686 if (themes != nil)
1687 for (NSDictionary *theme in themes) {
265e19b2 1688 NSNumber *active([theme objectForKey:@"Active"]);
d5fb6e01
JF
1689 if (![active boolValue])
1690 continue;
26c43b47 1691
265e19b2 1692 NSString *name([theme objectForKey:@"Name"]);
d5fb6e01
JF
1693 if (name == nil)
1694 continue;
1695
265e19b2 1696 NSString *theme(nil);
d5fb6e01 1697
95a5777b
JF
1698 #define testForTheme(format...) \
1699 if (theme == nil) { \
1700 NSString *path = [NSString stringWithFormat:format]; \
1701 if ([Manager_ fileExistsAtPath:path]) { \
1702 [themes_ addObject:path]; \
1703 continue; \
1704 } \
d5fb6e01 1705 }
d5fb6e01 1706
95a5777b
JF
1707 testForTheme(@"/Library/Themes/%@.theme", name)
1708 testForTheme(@"/Library/Themes/%@", name)
1709 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
265e19b2 1710
d5fb6e01 1711 }
f64efe8d 1712// }}}
26c43b47
JF
1713 }
1714
d5fb6e01
JF
1715 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1716
95a5777b 1717 for (NSString *theme in themes_)
265e19b2 1718 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
d5fb6e01
JF
1719 for (NSString *key in [info allKeys])
1720 if ([Info_ objectForKey:key] == nil)
1721 [Info_ setObject:[info objectForKey:key] forKey:key];
95a5777b 1722
198eb03b
JF
1723 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1724
bae02419
JF
1725 SpringBoard_ = [identifier isEqualToString:@"com.apple.springboard"];
1726
f64efe8d
JF
1727 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"] != nil)
1728// ChatKit {{{
198eb03b
JF
1729 if (sms) {
1730 $CKMessageCell = objc_getClass("CKMessageCell");
1731 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1732 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1733
1734 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1735 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1736 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1737
1738 $CKTimestampView = objc_getClass("CKTimestampView");
1739 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1740
1741 $CKTranscriptController = objc_getClass("CKTranscriptController");
1742 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1743 }
f64efe8d 1744// }}}
8b94f6b0 1745
4668cd8e 1746 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
f64efe8d 1747// MobileSMS {{{
198eb03b
JF
1748 if (sms) {
1749 if (_TranscriptController$loadView == NULL) {
1750 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1751 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1752 }
8b94f6b0 1753 }
f64efe8d 1754// }}}
bae02419 1755 } else if (SpringBoard_) {
f64efe8d 1756// SpringBoard {{{
95a5777b
JF
1757 CFNotificationCenterAddObserver(
1758 CFNotificationCenterGetDarwinNotifyCenter(),
1759 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1760 );
62b2dbad 1761
cc46954c 1762 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
265e19b2
JF
1763 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1764 if (MediaPlayer != nil)
1765 [MediaPlayer load];
1766
1767 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1768 $MPVideoView = objc_getClass("MPVideoView");
cc46954c 1769 }
2acbe5b8 1770
0316ebc4
JF
1771 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1772
9741cf15
JF
1773 bool olden(dlsym(RTLD_DEFAULT, "GSLibraryCopyGenerationInfoValueForKey") == NULL);
1774
1775 if (olden)
1776 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1777
0316ebc4
JF
1778 $SBApplication = objc_getClass("SBApplication");
1779 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
9cfe3924 1780 $SBAwayView = objc_getClass("SBAwayView");
0316ebc4
JF
1781 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1782 $SBButtonBar = objc_getClass("SBButtonBar");
77d89d52 1783 $SBDockIconListView = objc_getClass("SBDockIconListView");
b0d0c73f 1784 $SBIcon = objc_getClass("SBIcon");
0316ebc4
JF
1785 $SBIconBadge = objc_getClass("SBIconBadge");
1786 $SBIconController = objc_getClass("SBIconController");
1787 $SBIconLabel = objc_getClass("SBIconLabel");
a8d008e4 1788 $SBIconList = objc_getClass("SBIconList");
0316ebc4 1789 $SBIconModel = objc_getClass("SBIconModel");
8e4d2f42 1790 $SBIconView = objc_getClass("SBIconView");
82b4a0bd 1791 //$SBImageCache = objc_getClass("SBImageCache");
1a4ffdf8 1792 $SBSearchView = objc_getClass("SBSearchView");
9c64bab2 1793 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
0316ebc4
JF
1794 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1795 $SBStatusBarController = objc_getClass("SBStatusBarController");
1796 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1797 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
69550bfb 1798 $SBUIController = objc_getClass("SBUIController");
4f1b7acd 1799 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
0316ebc4 1800
8e4d2f42
JF
1801 if ($SBIconView == nil)
1802 $SBIconView = $SBIcon;
1803
77d89d52
JF
1804 Four_ = $SBDockIconListView != nil;
1805
0316ebc4
JF
1806 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1807
265e19b2
JF
1808 if (SummerBoard_) {
1809 WBRename(SBApplication, pathForIcon, pathForIcon);
1810 WBRename(SBApplicationIcon, icon, icon);
1d3b613f 1811 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
265e19b2
JF
1812 }
1813
0316ebc4
JF
1814 WBRename(SBBookmarkIcon, icon, icon);
1815 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1816 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
b0d0c73f 1817 WBRename(SBIcon, setAlpha:, setAlpha$);
0316ebc4 1818 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
98fe8d52 1819 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
8e4d2f42
JF
1820 WBRename(SBIconView, initWithDefaultSize, initWithDefaultSize);
1821 WBRename(SBIconView, setIconImageAlpha:, setIconImageAlpha$);
1822 WBRename(SBIconView, setIconLabelAlpha:, setIconLabelAlpha$);
69550bfb 1823 WBRename(SBUIController, init, init);
4f1b7acd 1824 WBRename(SBWidgetApplicationIcon, icon, icon);
0316ebc4 1825
77d89d52
JF
1826 WBRename(SBDockIconListView, setFrame:, setFrame$);
1827 MSHookMessage(object_getClass($SBDockIconListView), @selector(shouldShowNewDock), &$SBDockIconListView$shouldShowNewDock, &_SBDockIconListView$shouldShowNewDock);
1828
9741cf15
JF
1829 if (olden)
1830 WBRename(SBIconLabel, drawRect:, drawRect$);
1831
0316ebc4
JF
1832 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1833 WBRename(SBIconLabel, setInDock:, setInDock$);
1834
a8d008e4
JF
1835 WBRename(SBIconList, setFrame:, setFrame$);
1836
0316ebc4 1837 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1a4ffdf8 1838 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
0316ebc4 1839 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1a4ffdf8
JF
1840 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1841
1842 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
9c64bab2
JF
1843 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1844 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
0316ebc4 1845
82b4a0bd
JF
1846 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1847
9cfe3924 1848 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
0316ebc4 1849 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
69550bfb
JF
1850 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1851 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
0316ebc4 1852 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
69550bfb 1853 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
0316ebc4
JF
1854 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1855 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1856 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
2acbe5b8 1857
24ba43ee
JF
1858 if (SummerBoard_)
1859 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1860
2acbe5b8 1861 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
f64efe8d 1862// }}}
2acbe5b8
JF
1863 }
1864
4668cd8e 1865 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1d3b613f
JF
1866 Papered_ = $getTheme$(Wallpapers_) != nil;
1867
77d89d52
JF
1868 Docked_ = $getTheme$([NSArray arrayWithObjects:@"Dock.png", nil]);
1869
d5168fd6
JF
1870 [pool release];
1871}