]>
Commit | Line | Data |
---|---|---|
d5168fd6 JF |
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 | ||
889cb4f2 | 38 | #define _trace() NSLog(@"WB:_trace(%u)", __LINE__); |
ca13798d | 39 | #define _transient |
62b2dbad | 40 | |
e6f0817b | 41 | #include <substrate.h> |
95a5777b | 42 | |
e6f0817b | 43 | #import <CoreFoundation/CoreFoundation.h> |
d5168fd6 | 44 | #import <Foundation/Foundation.h> |
2435118f | 45 | #import <CoreGraphics/CoreGraphics.h> |
d5168fd6 JF |
46 | |
47 | #import <UIKit/UIColor.h> | |
889cb4f2 | 48 | #import <UIKit/UIFont.h> |
d5168fd6 JF |
49 | #import <UIKit/UIImage.h> |
50 | #import <UIKit/UIImageView.h> | |
95a5777b | 51 | #import <UIKit/UINavigationBar.h> |
26c43b47 | 52 | #import <UIKit/UINavigationBarBackground.h> |
95a5777b | 53 | #import <UIKit/UIToolbar.h> |
394d1eb5 | 54 | #import <UIKit/UIWebDocumentView.h> |
62b2dbad | 55 | |
889cb4f2 JF |
56 | #import <UIKit/NSString-UIStringDrawing.h> |
57 | #import <UIKit/NSString-UIStringDrawingDeprecated.h> | |
58 | ||
2435118f JF |
59 | #import <UIKit/UIImage-UIImageDeprecated.h> |
60 | ||
62b2dbad | 61 | #import <UIKit/UIView-Geometry.h> |
d5168fd6 | 62 | #import <UIKit/UIView-Hierarchy.h> |
62b2dbad | 63 | #import <UIKit/UIView-Rendering.h> |
d5168fd6 JF |
64 | |
65 | #import <SpringBoard/SBApplication.h> | |
394d1eb5 | 66 | #import <SpringBoard/SBApplicationIcon.h> |
d5168fd6 | 67 | #import <SpringBoard/SBAppWindow.h> |
502d350e | 68 | #import <SpringBoard/SBBookmarkIcon.h> |
62b2dbad | 69 | #import <SpringBoard/SBButtonBar.h> |
e6f0817b | 70 | #import <SpringBoard/SBCalendarIconContentsView.h> |
d5168fd6 | 71 | #import <SpringBoard/SBContentLayer.h> |
95a5777b | 72 | #import <SpringBoard/SBIconController.h> |
889cb4f2 | 73 | #import <SpringBoard/SBIconLabel.h> |
502d350e | 74 | #import <SpringBoard/SBSlidingAlertDisplay.h> |
08454e3a | 75 | #import <SpringBoard/SBStatusBarContentsView.h> |
d5fb6e01 | 76 | #import <SpringBoard/SBStatusBarController.h> |
08454e3a | 77 | #import <SpringBoard/SBStatusBarTimeView.h> |
d5168fd6 JF |
78 | #import <SpringBoard/SBUIController.h> |
79 | ||
d5fb6e01 JF |
80 | #import <MediaPlayer/MPVideoView.h> |
81 | #import <MediaPlayer/MPVideoView-PlaybackControl.h> | |
82 | ||
d5168fd6 JF |
83 | #import <CoreGraphics/CGGeometry.h> |
84 | ||
95a5777b JF |
85 | extern "C" void __clear_cache (char *beg, char *end); |
86 | ||
87 | Class $MPVideoView; | |
88 | ||
89 | Class $UIColor; | |
90 | Class $UIImage; | |
91 | Class $UIImageView; | |
92 | Class $UIWebDocumentView; | |
93 | ||
26c43b47 JF |
94 | @interface NSDictionary (WinterBoard) |
95 | - (UIColor *) colorForKey:(NSString *)key; | |
889cb4f2 | 96 | - (BOOL) boolForKey:(NSString *)key; |
26c43b47 JF |
97 | @end |
98 | ||
99 | @implementation NSDictionary (WinterBoard) | |
100 | ||
101 | - (UIColor *) colorForKey:(NSString *)key { | |
102 | NSString *value = [self objectForKey:key]; | |
103 | if (value == nil) | |
104 | return nil; | |
105 | /* XXX: incorrect */ | |
106 | return nil; | |
107 | } | |
108 | ||
889cb4f2 JF |
109 | - (BOOL) boolForKey:(NSString *)key { |
110 | if (NSString *value = [self objectForKey:key]) | |
111 | return [value boolValue]; | |
95a5777b | 112 | return false; |
889cb4f2 JF |
113 | } |
114 | ||
26c43b47 JF |
115 | @end |
116 | ||
f22a8989 | 117 | bool Debug_ = false; |
e6f0817b | 118 | bool Engineer_ = false; |
889cb4f2 | 119 | |
d5168fd6 | 120 | /* WinterBoard Backend {{{ */ |
d5168fd6 JF |
121 | void WBInject(const char *classname, const char *oldname, IMP newimp, const char *type) { |
122 | Class _class = objc_getClass(classname); | |
123 | if (_class == nil) | |
124 | return; | |
125 | if (!class_addMethod(_class, sel_registerName(oldname), newimp, type)) | |
2435118f | 126 | NSLog(@"WB:Error: failed to inject [%s %s]", classname, oldname); |
d5168fd6 JF |
127 | } |
128 | ||
d5168fd6 JF |
129 | /* }}} */ |
130 | ||
131 | @protocol WinterBoard | |
7ff778ee JF |
132 | - (CGSize) wb_renderedSizeOfNode:(id)node constrainedToWidth:(float)width; |
133 | - (void *) _node; | |
502d350e JF |
134 | - (void) wb_updateDesktopImage:(UIImage *)image; |
135 | - (UIImage *) wb_defaultDesktopImage; | |
136 | - (NSString *) wb_bundlePath; | |
d5168fd6 JF |
137 | - (NSString *) wb_pathForIcon; |
138 | - (NSString *) wb_pathForResource:(NSString *)resource ofType:(NSString *)type; | |
08454e3a JF |
139 | - (id) wb_init; |
140 | - (id) wb_layer; | |
d5168fd6 | 141 | - (id) wb_initWithSize:(CGSize)size; |
889cb4f2 | 142 | - (id) wb_initWithSize:(CGSize)size label:(NSString *)label; |
62b2dbad | 143 | - (id) wb_initWithFrame:(CGRect)frame; |
26c43b47 | 144 | - (id) wb_initWithCoder:(NSCoder *)coder; |
62b2dbad | 145 | - (void) wb_setFrame:(CGRect)frame; |
ca13798d | 146 | - (void) wb_drawRect:(CGRect)rect; |
d5168fd6 | 147 | - (void) wb_setBackgroundColor:(id)color; |
62b2dbad | 148 | - (void) wb_setAlpha:(float)value; |
26c43b47 JF |
149 | - (void) wb_setBarStyle:(int)style; |
150 | - (id) wb_initWithFrame:(CGRect)frame withBarStyle:(int)style withTintColor:(UIColor *)color; | |
08454e3a | 151 | - (void) wb_setOpaque:(BOOL)opaque; |
889cb4f2 | 152 | - (void) wb_setInDock:(BOOL)docked; |
08454e3a | 153 | - (void) wb_didMoveToSuperview; |
889cb4f2 | 154 | + (UIImage *) wb_imageNamed:(NSString *)name inBundle:(NSBundle *)bundle; |
d5fb6e01 | 155 | + (UIImage *) wb_applicationImageNamed:(NSString *)name; |
394d1eb5 JF |
156 | - (NSDictionary *) wb_infoDictionary; |
157 | - (UIImage *) wb_icon; | |
95a5777b | 158 | - (void) wb_appendIconList:(SBIconList *)list; |
d5fb6e01 JF |
159 | - (id) wb_initWithStatusBar:(id)bar mode:(int)mode; |
160 | - (id) wb_initWithMode:(int)mode orientation:(int)orientation; | |
502d350e JF |
161 | - (id) wb_imageAtPath:(NSString *)path; |
162 | - (id) wb_initWithContentsOfFile:(NSString *)file; | |
163 | - (id) wb_initWithContentsOfFile:(NSString *)file cache:(BOOL)cache; | |
d5fb6e01 | 164 | - (void) wb_setStatusBarMode:(int)mode orientation:(int)orientation duration:(float)duration fenceID:(int)id animation:(int)animation; |
d5168fd6 JF |
165 | @end |
166 | ||
502d350e JF |
167 | static NSMutableDictionary **__mappedImages; |
168 | static NSMutableDictionary *UIImages_; | |
169 | static NSMutableDictionary *PathImages_; | |
2435118f | 170 | |
502d350e JF |
171 | static NSFileManager *Manager_; |
172 | static NSDictionary *English_; | |
173 | static NSMutableDictionary *Info_; | |
174 | static NSMutableArray *themes_; | |
d5168fd6 | 175 | |
502d350e JF |
176 | static NSString *$getTheme$(NSArray *files) { |
177 | for (NSString *theme in themes_) | |
178 | for (NSString *file in files) { | |
179 | NSString *path([NSString stringWithFormat:@"%@/%@", theme, file]); | |
180 | if ([Manager_ fileExistsAtPath:path]) | |
181 | return path; | |
182 | } | |
183 | ||
184 | return nil; | |
185 | } | |
186 | ||
187 | static NSString *$pathForIcon$(SBApplication<WinterBoard> *self) { | |
d5fb6e01 JF |
188 | for (NSString *theme in themes_) { |
189 | NSString *identifier = [self bundleIdentifier]; | |
190 | NSString *folder = [[self path] lastPathComponent]; | |
191 | NSString *dname = [self displayName]; | |
192 | NSString *didentifier = [self displayIdentifier]; | |
193 | ||
95a5777b | 194 | if (Debug_) |
d5fb6e01 | 195 | NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier); |
62b2dbad | 196 | |
d5fb6e01 JF |
197 | #define testForIcon(Name) \ |
198 | if (NSString *name = Name) { \ | |
199 | NSString *path = [NSString stringWithFormat:@"%@/Icons/%@.png", theme, name]; \ | |
200 | if ([Manager_ fileExistsAtPath:path]) \ | |
201 | return path; \ | |
202 | } | |
203 | ||
204 | if (identifier != nil) { | |
205 | NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/icon.png", theme, identifier]; | |
206 | if ([Manager_ fileExistsAtPath:path]) | |
207 | return path; | |
26c43b47 | 208 | } |
889cb4f2 | 209 | |
d5fb6e01 JF |
210 | if (folder != nil) { |
211 | NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/icon.png", theme, folder]; | |
212 | if ([Manager_ fileExistsAtPath:path]) | |
213 | return path; | |
214 | } | |
ca13798d | 215 | |
d5fb6e01 JF |
216 | testForIcon(identifier); |
217 | testForIcon(dname); | |
889cb4f2 | 218 | |
d5fb6e01 JF |
219 | if (didentifier != nil) { |
220 | testForIcon([English_ objectForKey:didentifier]); | |
889cb4f2 | 221 | |
d5fb6e01 JF |
222 | NSArray *parts = [didentifier componentsSeparatedByString:@"-"]; |
223 | if ([parts count] != 1) | |
224 | if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[[self path] stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease]) | |
225 | testForIcon([english objectForKey:[parts lastObject]]); | |
226 | } | |
227 | } | |
889cb4f2 | 228 | |
394d1eb5 JF |
229 | return nil; |
230 | } | |
231 | ||
232 | static UIImage *SBApplicationIcon$icon(SBApplicationIcon<WinterBoard> *self, SEL sel) { | |
d5fb6e01 | 233 | if (![Info_ boolForKey:@"ComposeStoreIcons"]) |
56539693 | 234 | if (NSString *path = $pathForIcon$([self application])) |
95a5777b | 235 | return [$UIImage imageWithContentsOfFile:path]; |
394d1eb5 JF |
236 | return [self wb_icon]; |
237 | } | |
238 | ||
502d350e JF |
239 | static UIImage *SBBookmarkIcon$icon(SBBookmarkIcon<WinterBoard> *self, SEL sel) { |
240 | if (Debug_) | |
241 | NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]); | |
242 | if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]])) | |
243 | return [$UIImage imageWithContentsOfFile:path]; | |
244 | return [self wb_icon]; | |
245 | } | |
246 | ||
394d1eb5 | 247 | static NSString *SBApplication$pathForIcon(SBApplication<WinterBoard> *self, SEL sel) { |
d5fb6e01 JF |
248 | if (NSString *path = $pathForIcon$(self)) |
249 | return path; | |
d5168fd6 JF |
250 | return [self wb_pathForIcon]; |
251 | } | |
252 | ||
502d350e | 253 | static NSString *$pathForFile$inBundle$(NSString *file, NSBundle<WinterBoard> *bundle, bool ui) { |
d5fb6e01 | 254 | for (NSString *theme in themes_) { |
ca13798d JF |
255 | NSString *identifier = [bundle bundleIdentifier]; |
256 | ||
257 | if (identifier != nil) { | |
d5fb6e01 | 258 | NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/%@", theme, identifier, file]; |
ca13798d JF |
259 | if ([Manager_ fileExistsAtPath:path]) |
260 | return path; | |
261 | } | |
262 | ||
502d350e | 263 | if (NSString *folder = [[bundle wb_bundlePath] lastPathComponent]) { |
d5fb6e01 | 264 | NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/%@", theme, folder, file]; |
ca13798d JF |
265 | if ([Manager_ fileExistsAtPath:path]) |
266 | return path; | |
267 | } | |
26c43b47 | 268 | |
889cb4f2 JF |
269 | #define remapResourceName(oldname, newname) \ |
270 | else if ([file isEqualToString:oldname]) { \ | |
d5fb6e01 | 271 | NSString *path = [NSString stringWithFormat:@"%@/%@.png", theme, newname]; \ |
889cb4f2 JF |
272 | if ([Manager_ fileExistsAtPath:path]) \ |
273 | return path; \ | |
274 | } | |
26c43b47 | 275 | |
ca13798d | 276 | if (identifier == nil || ![identifier isEqualToString:@"com.apple.springboard"]); |
8e65ed9f JF |
277 | remapResourceName(@"FSO_BG.png", @"StatusBar") |
278 | remapResourceName(@"SBDockBG.png", @"Dock") | |
279 | remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather") | |
95a5777b JF |
280 | |
281 | if (ui) { | |
282 | NSString *path = [NSString stringWithFormat:@"%@/UIImages/%@", theme, file]; | |
283 | if ([Manager_ fileExistsAtPath:path]) | |
284 | return path; | |
285 | } | |
d5168fd6 JF |
286 | } |
287 | ||
889cb4f2 JF |
288 | return nil; |
289 | } | |
290 | ||
95a5777b JF |
291 | static UIImage *CachedImageAtPath(NSString *path) { |
292 | UIImage *image = [PathImages_ objectForKey:path]; | |
293 | if (image != nil) | |
294 | return reinterpret_cast<id>(image) == [NSNull null] ? nil : image; | |
502d350e | 295 | image = [[$UIImage alloc] wb_initWithContentsOfFile:path cache:true]; |
95a5777b JF |
296 | if (image != nil) |
297 | image = [image autorelease]; | |
298 | [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path]; | |
299 | return image; | |
300 | } | |
301 | ||
394d1eb5 | 302 | static UIImage *UIImage$imageNamed$inBundle$(Class<WinterBoard> self, SEL sel, NSString *name, NSBundle *bundle) { |
e6f0817b | 303 | NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name]; |
95a5777b JF |
304 | UIImage *image = [PathImages_ objectForKey:key]; |
305 | if (image != nil) | |
306 | return reinterpret_cast<id>(image) == [NSNull null] ? nil : image; | |
889cb4f2 JF |
307 | if (Debug_) |
308 | NSLog(@"WB:Debug: [UIImage(%@) imageNamed:\"%@\"]", [bundle bundleIdentifier], name); | |
95a5777b JF |
309 | if (NSString *path = $pathForFile$inBundle$(name, bundle, false)) |
310 | image = CachedImageAtPath(path); | |
311 | if (image == nil) | |
312 | image = [self wb_imageNamed:name inBundle:bundle]; | |
313 | [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key]; | |
314 | return image; | |
889cb4f2 JF |
315 | } |
316 | ||
394d1eb5 | 317 | static UIImage *UIImage$imageNamed$(Class<WinterBoard> self, SEL sel, NSString *name) { |
889cb4f2 JF |
318 | return UIImage$imageNamed$inBundle$(self, sel, name, [NSBundle mainBundle]); |
319 | } | |
320 | ||
d5fb6e01 JF |
321 | static UIImage *UIImage$applicationImageNamed$(Class<WinterBoard> self, SEL sel, NSString *name) { |
322 | NSBundle *bundle = [NSBundle mainBundle]; | |
323 | if (Debug_) | |
324 | NSLog(@"WB:Debug: [UIImage(%@) applicationImageNamed:\"%@\"]", [bundle bundleIdentifier], name); | |
95a5777b JF |
325 | if (NSString *path = $pathForFile$inBundle$(name, bundle, false)) |
326 | return CachedImageAtPath(path); | |
d5fb6e01 JF |
327 | return [self wb_applicationImageNamed:name]; |
328 | } | |
329 | ||
502d350e JF |
330 | @interface NSString (WinterBoard) |
331 | - (NSString *) wb_themedPath; | |
332 | @end | |
333 | ||
334 | @implementation NSString (WinterBoard) | |
335 | ||
336 | - (NSString *) wb_themedPath { | |
e6f0817b JF |
337 | if (Debug_) |
338 | NSLog(@"WB:Debug:Bypass(\"%@\")", self); | |
502d350e JF |
339 | return self; |
340 | } | |
341 | ||
342 | @end | |
343 | ||
344 | static NSMutableDictionary *Files_; | |
345 | ||
346 | #define WBDelegate(delegate) \ | |
347 | - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \ | |
348 | if (Engineer_) \ | |
349 | NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \ | |
350 | if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \ | |
351 | return sig; \ | |
352 | NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \ | |
353 | return nil; \ | |
354 | } \ | |
355 | \ | |
356 | - (void) forwardInvocation:(NSInvocation*)inv { \ | |
357 | SEL sel = [inv selector]; \ | |
358 | if ([delegate respondsToSelector:sel]) \ | |
359 | [inv invokeWithTarget:delegate]; \ | |
360 | else \ | |
361 | NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \ | |
362 | } | |
363 | ||
364 | /*@interface WBBundlePath : NSProxy { | |
365 | NSBundle<WinterBoard> *bundle_; | |
366 | NSString *path_; | |
367 | } | |
368 | ||
369 | - (id) initWithBundle:(NSBundle *)bundle path:(NSString *)path; | |
370 | ||
371 | - (NSString *) wb_themedPath; | |
372 | ||
373 | @end | |
374 | ||
375 | @implementation WBBundlePath | |
376 | ||
377 | - (void) dealloc { | |
378 | [bundle_ release]; | |
379 | [path_ release]; | |
380 | [super dealloc]; | |
381 | } | |
382 | ||
383 | - (id) initWithBundle:(NSBundle *)bundle path:(NSString *)path { | |
384 | bundle_ = [bundle retain]; | |
385 | path_ = [path retain]; | |
386 | return self; | |
387 | } | |
388 | ||
389 | WBDelegate(path_) | |
390 | ||
391 | - (NSString *) stringByAppendingPathComponent:(NSString *)component { | |
392 | NSLog(@"WB:Debug:app:%@:%@", path_, component); | |
393 | return [[[WBBundlePath alloc] initWithBundle:bundle_ path:[path_ stringByAppendingPathComponent:component]] autorelease]; | |
394 | } | |
395 | ||
396 | - (NSString *) stringByAppendingPathExtension:(NSString *)extension { | |
397 | return [[[WBBundlePath alloc] initWithBundle:bundle_ path:[path_ stringByAppendingPathExtension:extension]] autorelease]; | |
398 | } | |
399 | ||
400 | - (const char *) UTF8String { | |
401 | const char *string = [path_ UTF8String]; | |
402 | NSLog(@"WB:Debug:UTF=%s", string); | |
403 | return string; | |
404 | } | |
405 | ||
406 | - (NSString *) description { | |
407 | return [path_ description]; | |
408 | } | |
409 | ||
410 | - (NSString *) wb_themedPath { | |
411 | return path_; | |
412 | NSString *path = [Files_ objectForKey:path_]; | |
413 | if (path == nil) { | |
414 | NSString *path = [bundle_ wb_bundlePath]; | |
415 | if (![path_ hasPrefix:path]) { | |
416 | NSLog(@"WB:Error:![@\"%@\" hasPrefix:@\"%@\"]", path_, path); | |
417 | return path_; | |
418 | } | |
419 | path = [path_ substringFromIndex:([path length] + 1)]; | |
420 | path = $pathForFile$inBundle$(path, bundle_, false); | |
421 | if (path == nil) | |
422 | path = reinterpret_cast<NSString *>([NSNull null]); | |
423 | [Files_ setObject:path forKey:path_]; | |
424 | if (Debug_) | |
425 | NSLog(@"WB:Debug:ThemePath(\"%@\")->\"%@\"", path_, path); | |
426 | } | |
427 | if (reinterpret_cast<id>(path) == [NSNull null]) | |
428 | path = path_; | |
429 | NSLog(@"WB:Debug:ThemePath=%@", path); | |
430 | return path; | |
431 | } | |
432 | ||
433 | @end*/ | |
434 | ||
435 | static NSString *NSBundle$bundlePath$(NSBundle<WinterBoard> *self, SEL sel) { | |
436 | //return [[WBBundlePath alloc] initWithBundle:self path:[self wb_bundlePath]]; | |
437 | return [self wb_bundlePath]; | |
438 | } | |
439 | ||
394d1eb5 | 440 | static NSString *NSBundle$pathForResource$ofType$(NSBundle<WinterBoard> *self, SEL sel, NSString *resource, NSString *type) { |
889cb4f2 JF |
441 | NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type]; |
442 | if (Debug_) | |
443 | NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file); | |
95a5777b | 444 | if (NSString *path = $pathForFile$inBundle$(file, self, false)) |
ca13798d | 445 | return path; |
d5168fd6 JF |
446 | return [self wb_pathForResource:resource ofType:type]; |
447 | } | |
448 | ||
502d350e | 449 | static bool $setBarStyle$_(NSString *name, UIView<WinterBoard> *self, int style) { |
95a5777b JF |
450 | if (Debug_) |
451 | NSLog(@"WB:Debug:%@Style:%d", name, style); | |
452 | NSNumber *number = nil; | |
453 | if (number == nil) | |
454 | number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]]; | |
455 | if (number == nil) | |
456 | number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]]; | |
457 | if (number == nil) | |
458 | return false; | |
459 | else { | |
460 | style = [number intValue]; | |
461 | if (Debug_) | |
462 | NSLog(@"WB:Debug:%@Style=%d", name, style); | |
463 | [self wb_setBarStyle:style]; | |
d5fb6e01 | 464 | return true; |
26c43b47 | 465 | } |
26c43b47 JF |
466 | } |
467 | ||
e6f0817b JF |
468 | static void SBCalendarIconContentsView$drawRect$(SBCalendarIconContentsView<WinterBoard> *self, SEL sel, CGRect rect) { |
469 | CFLocaleRef locale(CFLocaleCopyCurrent()); | |
470 | CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle)); | |
471 | CFRelease(locale); | |
472 | ||
473 | CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent())); | |
474 | ||
475 | CFDateFormatterSetFormat(formatter, CFSTR("d")); | |
476 | CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now)); | |
477 | CFDateFormatterSetFormat(formatter, CFSTR("EEEE")); | |
478 | CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now)); | |
479 | ||
480 | CFRelease(now); | |
481 | ||
482 | CFRelease(formatter); | |
483 | ||
484 | NSString *datestyle(@"" | |
485 | "font-family: Helvetica; " | |
486 | "font-weight: bold; " | |
487 | "font-size: 39px; " | |
488 | "color: #333333; " | |
489 | "alpha: 1.0; " | |
490 | ""); | |
491 | ||
492 | NSString *daystyle(@"" | |
493 | "font-family: Helvetica; " | |
494 | "font-weight: bold; " | |
495 | "font-size: 9px; " | |
496 | "color: white; " | |
497 | "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; " | |
498 | ""); | |
499 | ||
500 | if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"]) | |
501 | datestyle = [datestyle stringByAppendingString:style]; | |
502 | if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"]) | |
503 | daystyle = [daystyle stringByAppendingString:style]; | |
504 | ||
cf31d246 | 505 | float width([self bounds].size.width); |
e6f0817b JF |
506 | CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:width]; |
507 | CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:width]; | |
508 | ||
509 | [(NSString *)date drawAtPoint:CGPointMake( | |
cf31d246 | 510 | (width + 4 - datesize.width) / 2, (71 - datesize.height) / 2 |
e6f0817b JF |
511 | ) withStyle:datestyle]; |
512 | ||
513 | [(NSString *)day drawAtPoint:CGPointMake( | |
514 | (width - daysize.width) / 2, (16 - daysize.height) / 2 | |
515 | ) withStyle:daystyle]; | |
516 | ||
517 | CFRelease(date); | |
518 | CFRelease(day); | |
519 | } | |
520 | ||
502d350e | 521 | /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) { |
26c43b47 JF |
522 | _trace(); |
523 | ||
d5fb6e01 JF |
524 | if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"]) |
525 | style = [number intValue]; | |
26c43b47 | 526 | |
d5fb6e01 JF |
527 | if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"]) |
528 | tint = color; | |
26c43b47 JF |
529 | |
530 | return [self wb_initWithFrame:frame withBarStyle:style withTintColor:tint]; | |
531 | }*/ | |
532 | ||
502d350e | 533 | /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) { |
26c43b47 JF |
534 | self = [self wb_initWithCoder:coder]; |
535 | if (self == nil) | |
536 | return nil; | |
537 | UINavigationBar$setBarStyle$_(self); | |
538 | return self; | |
539 | } | |
540 | ||
502d350e | 541 | static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) { |
26c43b47 JF |
542 | self = [self wb_initWithFrame:frame]; |
543 | if (self == nil) | |
544 | return nil; | |
545 | UINavigationBar$setBarStyle$_(self); | |
546 | return self; | |
547 | }*/ | |
548 | ||
95a5777b JF |
549 | static void UIToolbar$setBarStyle$(UIToolbar<WinterBoard> *self, SEL sel, int style) { |
550 | if ($setBarStyle$_(@"Toolbar", self, style)) | |
551 | return; | |
552 | return [self wb_setBarStyle:style]; | |
553 | } | |
554 | ||
555 | static void UINavigationBar$setBarStyle$(UINavigationBar<WinterBoard> *self, SEL sel, int style) { | |
556 | if ($setBarStyle$_(@"NavigationBar", self, style)) | |
26c43b47 JF |
557 | return; |
558 | return [self wb_setBarStyle:style]; | |
559 | } | |
560 | ||
394d1eb5 | 561 | static void $didMoveToSuperview(SBButtonBar<WinterBoard> *self, SEL sel) { |
95a5777b | 562 | [[self superview] setBackgroundColor:[$UIColor clearColor]]; |
08454e3a JF |
563 | [self wb_didMoveToSuperview]; |
564 | } | |
62b2dbad | 565 | |
502d350e JF |
566 | static id UIImage$imageAtPath$(NSObject<WinterBoard> *self, SEL sel, NSString *path) { |
567 | return [self wb_imageAtPath:[path wb_themedPath]]; | |
568 | } | |
d5fb6e01 | 569 | |
502d350e JF |
570 | static id $initWithContentsOfFile$(NSObject<WinterBoard> *self, SEL sel, NSString *file) { |
571 | return [self wb_initWithContentsOfFile:[file wb_themedPath]]; | |
394d1eb5 JF |
572 | } |
573 | ||
502d350e JF |
574 | static id UIImage$initWithContentsOfFile$cache$(UIImage<WinterBoard> *self, SEL sel, NSString *file, BOOL cache) { |
575 | return [self wb_initWithContentsOfFile:[file wb_themedPath] cache:cache]; | |
576 | } | |
577 | ||
578 | static UIImage *UIImage$defaultDesktopImage$(UIImage<WinterBoard> *self, SEL sel) { | |
579 | if (Debug_) | |
580 | NSLog(@"WB:Debug:DefaultDesktopImage"); | |
581 | if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil])) | |
582 | return [$UIImage imageWithContentsOfFile:path]; | |
583 | return [self wb_defaultDesktopImage]; | |
584 | } | |
585 | ||
586 | static UIImageView *WallpaperImage_; | |
587 | static UIWebDocumentView *WallpaperPage_; | |
588 | static NSURL *WallpaperURL_; | |
95a5777b | 589 | |
394d1eb5 | 590 | static id SBContentLayer$initWithSize$(SBContentLayer<WinterBoard> *self, SEL sel, CGSize size) { |
d5168fd6 JF |
591 | self = [self wb_initWithSize:size]; |
592 | if (self == nil) | |
593 | return nil; | |
594 | ||
d5fb6e01 | 595 | if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"])) { |
95a5777b | 596 | MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease]; |
d5fb6e01 JF |
597 | [video setMovieWithPath:path]; |
598 | [video setRepeatMode:1]; | |
599 | [video setRepeatGap:0]; | |
600 | [self addSubview:video]; | |
601 | [video playFromBeginning];; | |
602 | } | |
603 | ||
95a5777b JF |
604 | UIImage *image; |
605 | if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil])) { | |
502d350e | 606 | image = [[$UIImage alloc] wb_initWithContentsOfFile:path]; |
95a5777b JF |
607 | if (image != nil) |
608 | image = [image autorelease]; | |
609 | } else image = nil; | |
610 | ||
502d350e JF |
611 | if (WallpaperImage_ != nil) |
612 | [WallpaperImage_ release]; | |
613 | WallpaperImage_ = [[$UIImageView alloc] initWithImage:image]; | |
614 | [self addSubview:WallpaperImage_]; | |
d5fb6e01 JF |
615 | |
616 | if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.html"])) { | |
394d1eb5 JF |
617 | CGRect bounds = [self bounds]; |
618 | ||
95a5777b JF |
619 | UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]); |
620 | [view setAutoresizes:true]; | |
394d1eb5 | 621 | |
502d350e JF |
622 | if (WallpaperPage_ != nil) |
623 | [WallpaperPage_ release]; | |
624 | WallpaperPage_ = [view retain]; | |
625 | ||
626 | if (WallpaperURL_ != nil) | |
627 | [WallpaperURL_ release]; | |
628 | WallpaperURL_ = [[NSURL fileURLWithPath:path] retain]; | |
629 | ||
630 | [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]]; | |
394d1eb5 | 631 | |
95a5777b JF |
632 | [[view webView] setDrawsBackground:false]; |
633 | [view setBackgroundColor:[$UIColor clearColor]]; | |
394d1eb5 JF |
634 | |
635 | [self addSubview:view]; | |
08454e3a | 636 | } |
d5168fd6 JF |
637 | |
638 | return self; | |
639 | } | |
640 | ||
502d350e JF |
641 | static void SBSlidingAlertDisplay$updateDesktopImage$(SBSlidingAlertDisplay<WinterBoard> *self, SEL sel, UIImage *image) { |
642 | NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]); | |
643 | ||
644 | if (path) { | |
645 | UIView *background; | |
646 | object_getInstanceVariable(self, "_backgroundView", reinterpret_cast<void **>(&background)); | |
647 | if (background != nil) | |
648 | path = nil; | |
649 | } | |
650 | ||
651 | [self wb_updateDesktopImage:image]; | |
652 | ||
653 | if (path != nil) { | |
654 | CGRect bounds = [self bounds]; | |
655 | ||
656 | UIWebDocumentView *view([[[$UIWebDocumentView alloc] initWithFrame:bounds] autorelease]); | |
657 | [view setAutoresizes:true]; | |
658 | ||
659 | if (WallpaperPage_ != nil) | |
660 | [WallpaperPage_ release]; | |
661 | WallpaperPage_ = [view retain]; | |
662 | ||
663 | if (WallpaperURL_ != nil) | |
664 | [WallpaperURL_ release]; | |
665 | WallpaperURL_ = [[NSURL fileURLWithPath:path] retain]; | |
666 | ||
667 | [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]]; | |
668 | ||
669 | [[view webView] setDrawsBackground:false]; | |
670 | [view setBackgroundColor:[$UIColor clearColor]]; | |
671 | ||
672 | UIView *background; | |
673 | object_getInstanceVariable(self, "_backgroundView", reinterpret_cast<void **>(&background)); | |
674 | NSLog(@"back:%@", background); | |
675 | ||
676 | [self insertSubview:view aboveSubview:background]; | |
ca13798d | 677 | } |
502d350e | 678 | } |
ca13798d | 679 | |
95a5777b JF |
680 | static unsigned *__currentContextCount; |
681 | static void ***__currentContextStack; | |
ca13798d | 682 | |
95a5777b | 683 | /*extern "C" CGColorRef CGGStateGetSystemColor(void *); |
ca13798d JF |
684 | extern "C" CGColorRef CGGStateGetFillColor(void *); |
685 | extern "C" CGColorRef CGGStateGetStrokeColor(void *); | |
95a5777b | 686 | extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/ |
ca13798d JF |
687 | |
688 | @interface WBTime : NSProxy { | |
689 | NSString *time_; | |
690 | _transient SBStatusBarTimeView *view_; | |
889cb4f2 JF |
691 | } |
692 | ||
ca13798d | 693 | - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view; |
889cb4f2 JF |
694 | |
695 | @end | |
696 | ||
ca13798d | 697 | @implementation WBTime |
889cb4f2 JF |
698 | |
699 | - (void) dealloc { | |
ca13798d | 700 | [time_ release]; |
889cb4f2 JF |
701 | [super dealloc]; |
702 | } | |
703 | ||
ca13798d JF |
704 | - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view { |
705 | time_ = [time retain]; | |
706 | view_ = view; | |
889cb4f2 JF |
707 | return self; |
708 | } | |
709 | ||
ca13798d JF |
710 | WBDelegate(time_) |
711 | ||
712 | - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode { | |
d5fb6e01 JF |
713 | if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) { |
714 | BOOL mode; | |
95a5777b | 715 | object_getInstanceVariable(view_, "_mode", reinterpret_cast<void **>(&mode)); |
d5fb6e01 JF |
716 | |
717 | [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@"" | |
718 | "font-family: Helvetica; " | |
719 | "font-weight: bold; " | |
720 | "font-size: 14px; " | |
721 | "color: %@; " | |
722 | "%@", mode ? @"white" : @"black", custom]]; | |
723 | ||
724 | return CGSizeZero; | |
725 | } | |
ca13798d JF |
726 | |
727 | return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode]; | |
889cb4f2 JF |
728 | } |
729 | ||
ca13798d JF |
730 | @end |
731 | ||
732 | @interface WBIconLabel : NSProxy { | |
733 | NSString *string_; | |
734 | BOOL docked_; | |
889cb4f2 JF |
735 | } |
736 | ||
ca13798d JF |
737 | - (id) initWithString:(NSString *)string; |
738 | ||
739 | @end | |
740 | ||
d5fb6e01 | 741 | static void SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(SBStatusBarController<WinterBoard> *self, SEL sel, int mode, int orientation, float duration, int id, int animation) { |
95a5777b JF |
742 | if (Debug_) |
743 | NSLog(@"WB:Debug:setStatusBarMode:%d", mode); | |
502d350e | 744 | if (mode < 100) // 104:hidden 105:glowing |
95a5777b JF |
745 | if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"]) |
746 | mode = [number intValue]; | |
d5fb6e01 JF |
747 | return [self wb_setStatusBarMode:mode orientation:orientation duration:duration fenceID:id animation:animation]; |
748 | } | |
749 | ||
750 | /*static id SBStatusBar$initWithMode$orientation$(SBStatusBar<WinterBoard> *self, SEL sel, int mode, int orientation) { | |
751 | return [self wb_initWithMode:mode orientation:orientation]; | |
752 | }*/ | |
753 | ||
754 | static id SBStatusBarContentsView$initWithStatusBar$mode$(SBStatusBarContentsView<WinterBoard> *self, SEL sel, id bar, int mode) { | |
755 | if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"]) | |
756 | mode = [number intValue]; | |
757 | return [self wb_initWithStatusBar:bar mode:mode]; | |
758 | } | |
759 | ||
394d1eb5 | 760 | static void SBStatusBarTimeView$drawRect$(SBStatusBarTimeView<WinterBoard> *self, SEL sel, CGRect rect) { |
ca13798d | 761 | id time; |
95a5777b | 762 | object_getInstanceVariable(self, "_time", reinterpret_cast<void **>(&time)); |
ca13798d | 763 | if (time != nil && [time class] != [WBTime class]) |
95a5777b | 764 | object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTime alloc] initWithTime:[time autorelease] view:self])); |
ca13798d JF |
765 | return [self wb_drawRect:rect]; |
766 | } | |
767 | ||
95a5777b JF |
768 | static void SBIconController$appendIconList$(SBIconController<WinterBoard> *self, SEL sel, SBIconList *list) { |
769 | if (Debug_) | |
770 | NSLog(@"appendIconList:%@", list); | |
771 | return [self wb_appendIconList:list]; | |
772 | } | |
773 | ||
cf31d246 JF |
774 | static id SBIconLabel$initWithSize$label$(SBIconLabel<WinterBoard> *self, SEL sel, CGSize size, NSString *label) { |
775 | self = [self wb_initWithSize:size label:label]; | |
776 | if (self != nil) | |
777 | [self setClipsToBounds:NO]; | |
778 | return self; | |
779 | } | |
780 | ||
394d1eb5 | 781 | static void SBIconLabel$setInDock$(SBIconLabel<WinterBoard> *self, SEL sel, BOOL docked) { |
889cb4f2 | 782 | id label; |
95a5777b | 783 | object_getInstanceVariable(self, "_label", reinterpret_cast<void **>(&label)); |
d5fb6e01 | 784 | if (![Info_ boolForKey:@"UndockedIconLabels"]) |
95a5777b | 785 | docked = true; |
889cb4f2 JF |
786 | if (label != nil && [label respondsToSelector:@selector(setInDock:)]) |
787 | [label setInDock:docked]; | |
788 | return [self wb_setInDock:docked]; | |
789 | } | |
790 | ||
7ff778ee JF |
791 | @class WebCoreFrameBridge; |
792 | static CGSize WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(WebCoreFrameBridge<WinterBoard> *self, SEL sel, id node, float width) { | |
793 | if (node == nil) | |
794 | return CGSizeZero; | |
795 | void **core(reinterpret_cast<void **>([node _node])); | |
796 | if (core == NULL || core[6] == NULL) | |
797 | return CGSizeZero; | |
798 | return [self wb_renderedSizeOfNode:node constrainedToWidth:width]; | |
799 | } | |
800 | ||
cf31d246 JF |
801 | static void SBIconLabel$drawRect$(SBIconLabel<WinterBoard> *self, SEL sel, CGRect rect) { |
802 | CGRect bounds = [self bounds]; | |
e6f0817b | 803 | |
a3fa54a5 JF |
804 | static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL); |
805 | ||
cf31d246 | 806 | BOOL docked; |
a3fa54a5 JF |
807 | Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked)); |
808 | docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0; | |
cf31d246 JF |
809 | |
810 | NSString *label; | |
811 | object_getInstanceVariable(self, "_label", reinterpret_cast<void **>(&label)); | |
812 | ||
813 | NSString *style = [NSString stringWithFormat:@"" | |
814 | "font-family: Helvetica; " | |
815 | "font-weight: bold; " | |
816 | "font-size: 11px; " | |
817 | "color: %@; " | |
818 | "", docked ? @"white" : @"#b3b3b3"]; | |
819 | ||
820 | if (docked) | |
821 | style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "]; | |
822 | float max = 75, width = [label sizeWithStyle:style forWidth:320].width; | |
823 | if (width > max) | |
824 | style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", ((width - max) / ([label length] - 1))]]; | |
825 | if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")]) | |
826 | style = [style stringByAppendingString:custom]; | |
827 | ||
828 | CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width]; | |
829 | [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style]; | |
889cb4f2 JF |
830 | } |
831 | ||
2435118f JF |
832 | extern "C" void FindMappedImages(void); |
833 | extern "C" NSData *UIImagePNGRepresentation(UIImage *); | |
834 | ||
95a5777b JF |
835 | static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path); |
836 | static CGImageRef *(*_UIImageRefAtPath)(NSString *path, bool cache, UIImageOrientation *orientation); | |
837 | static UIImage *(*_UIImageWithName)(NSString *name); | |
e6f0817b | 838 | static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain); |
95a5777b JF |
839 | static NSBundle *(*_UIKitBundle)(); |
840 | static void (*_UISharedImageInitialize)(bool); | |
841 | static int (*_UISharedImageNameGetIdentifier)(NSString *); | |
842 | static UIImage *(*_UISharedImageWithIdentifier)(int); | |
843 | ||
844 | static UIImage *$_UIImageWithName(NSString *name) { | |
845 | int id(_UISharedImageNameGetIdentifier(name)); | |
846 | if (Debug_) | |
847 | NSLog(@"WB:Debug: UIImageWithName(\"%@\", %d)", name, id); | |
848 | ||
849 | if (id == -1) | |
850 | return _UIImageAtPath(name, _UIKitBundle()); | |
851 | else { | |
852 | NSNumber *key([NSNumber numberWithInt:id]); | |
853 | UIImage *image = [UIImages_ objectForKey:key]; | |
854 | if (image != nil) | |
855 | return reinterpret_cast<id>(image) == [NSNull null] ? nil : image; | |
856 | if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) { | |
502d350e | 857 | image = [[$UIImage alloc] wb_initWithContentsOfFile:path]; |
95a5777b JF |
858 | if (image != nil) |
859 | [image autorelease]; | |
860 | } | |
861 | if (image == nil) | |
862 | image = _UISharedImageWithIdentifier(id); | |
863 | [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key]; | |
864 | return image; | |
865 | } | |
866 | } | |
867 | ||
e6f0817b JF |
868 | static UIImage *$_UIImageWithNameInDomain(NSString *name, NSString *domain) { |
869 | NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]; | |
870 | UIImage *image = [PathImages_ objectForKey:key]; | |
871 | if (image != nil) | |
872 | return reinterpret_cast<id>(image) == [NSNull null] ? nil : image; | |
95a5777b | 873 | if (Debug_) |
e6f0817b JF |
874 | NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain); |
875 | if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) { | |
876 | image = [[$UIImage alloc] wb_initWithContentsOfFile:path]; | |
877 | if (image != nil) | |
878 | [image autorelease]; | |
95a5777b | 879 | } |
e6f0817b JF |
880 | if (image == nil) |
881 | image = _UIImageWithNameInDomain(name, domain); | |
882 | [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key]; | |
883 | return image; | |
95a5777b JF |
884 | } |
885 | ||
886 | template <typename Type_> | |
887 | static void WBReplace(Type_ *symbol, Type_ *replace) { | |
888 | return WBReplace(symbol, replace, static_cast<Type_ **>(NULL)); | |
889 | } | |
890 | ||
891 | #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox" | |
892 | #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit" | |
893 | ||
894 | /*static void UIWebDocumentView$setViewportSize$forDocumentTypes$(UIWebDocumentView *self, SEL sel, CGSize size, int type) { | |
895 | NSLog(@"WB:Examine: %f:%f:%u", size.width, size.height, type); | |
896 | }*/ | |
897 | ||
898 | static bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long, char *, bool &); | |
899 | ||
900 | static bool $_Z24GetFileNameForThisActionmPcRb(unsigned long a0, char *a1, bool &a2) { | |
901 | bool value = _Z24GetFileNameForThisActionmPcRb(a0, a1, a2); | |
902 | if (Debug_) | |
903 | NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value); | |
904 | ||
905 | if (value) { | |
906 | NSString *path = [NSString stringWithUTF8String:a1]; | |
907 | if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) { | |
908 | NSString *file = [path substringFromIndex:31]; | |
909 | NSLog(@"%@", file); | |
910 | for (NSString *theme in themes_) { | |
911 | NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]); | |
912 | if ([Manager_ fileExistsAtPath:path]) { | |
913 | strcpy(a1, [path UTF8String]); | |
914 | continue; | |
915 | } | |
916 | } | |
917 | } | |
918 | } | |
919 | return value; | |
920 | } | |
921 | ||
922 | static void ChangeWallpaper( | |
923 | CFNotificationCenterRef center, | |
924 | void *observer, | |
925 | CFStringRef name, | |
926 | const void *object, | |
927 | CFDictionaryRef info | |
928 | ) { | |
929 | if (Debug_) | |
930 | NSLog(@"WB:Debug:ChangeWallpaper!"); | |
502d350e | 931 | |
95a5777b JF |
932 | UIImage *image; |
933 | if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil])) { | |
502d350e | 934 | image = [[$UIImage alloc] wb_initWithContentsOfFile:path]; |
95a5777b JF |
935 | if (image != nil) |
936 | image = [image autorelease]; | |
937 | } else image = nil; | |
502d350e JF |
938 | |
939 | if (WallpaperImage_ != nil) | |
940 | [WallpaperImage_ setImage:image]; | |
941 | if (WallpaperPage_ != nil) | |
942 | [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]]; | |
943 | ||
95a5777b | 944 | } |
394d1eb5 | 945 | |
e6f0817b JF |
946 | void WBRename(bool instance, const char *name, SEL sel, IMP imp) { |
947 | Class _class = objc_getClass(name); | |
948 | if (_class == nil) { | |
949 | if (Debug_) | |
950 | NSLog(@"WB:Warning: cannot find class [%s]", name); | |
951 | return; | |
952 | } | |
953 | if (!instance) | |
954 | _class = object_getClass(_class); | |
955 | MSHookMessage(_class, sel, imp, "wb_"); | |
956 | } | |
957 | ||
d5168fd6 | 958 | extern "C" void WBInitialize() { |
95a5777b JF |
959 | if (dlopen(UIKit, RTLD_LAZY | RTLD_NOLOAD) == NULL) |
960 | return; | |
2435118f | 961 | NSLog(@"WB:Notice: Installing WinterBoard..."); |
d5168fd6 JF |
962 | |
963 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
964 | ||
95a5777b JF |
965 | NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]; |
966 | if (MediaPlayer != nil) | |
967 | [MediaPlayer load]; | |
394d1eb5 | 968 | |
95a5777b | 969 | $MPVideoView = objc_getClass("MPVideoView"); |
394d1eb5 | 970 | |
95a5777b JF |
971 | $UIColor = objc_getClass("UIColor"); |
972 | $UIImage = objc_getClass("UIImage"); | |
973 | $UIImageView = objc_getClass("UIImageView"); | |
974 | $UIWebDocumentView = objc_getClass("UIWebDocumentView"); | |
975 | ||
e6f0817b | 976 | struct nlist nl[12]; |
95a5777b | 977 | memset(nl, 0, sizeof(nl)); |
394d1eb5 | 978 | |
95a5777b JF |
979 | nl[0].n_un.n_name = (char *) "___currentContextCount"; |
980 | nl[1].n_un.n_name = (char *) "___currentContextStack"; | |
981 | nl[2].n_un.n_name = (char *) "___mappedImages"; | |
982 | nl[3].n_un.n_name = (char *) "__UIImageAtPath"; | |
983 | nl[4].n_un.n_name = (char *) "__UIImageRefAtPath"; | |
984 | nl[5].n_un.n_name = (char *) "__UIImageWithName"; | |
e6f0817b JF |
985 | nl[6].n_un.n_name = (char *) "__UIImageWithNameInDomain"; |
986 | nl[7].n_un.n_name = (char *) "__UIKitBundle"; | |
987 | nl[8].n_un.n_name = (char *) "__UISharedImageInitialize"; | |
988 | nl[9].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier"; | |
989 | nl[10].n_un.n_name = (char *) "__UISharedImageWithIdentifier"; | |
95a5777b JF |
990 | |
991 | nlist(UIKit, nl); | |
992 | ||
993 | __currentContextCount = (unsigned *) nl[0].n_value; | |
994 | __currentContextStack = (void ***) nl[1].n_value; | |
995 | __mappedImages = (id *) nl[2].n_value; | |
996 | _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[3].n_value; | |
997 | _UIImageRefAtPath = (CGImageRef *(*)(NSString *, bool, UIImageOrientation *)) nl[4].n_value; | |
998 | _UIImageWithName = (UIImage *(*)(NSString *)) nl[5].n_value; | |
e6f0817b JF |
999 | _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[6].n_value; |
1000 | _UIKitBundle = (NSBundle *(*)()) nl[7].n_value; | |
1001 | _UISharedImageInitialize = (void (*)(bool)) nl[8].n_value; | |
1002 | _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[9].n_value; | |
1003 | _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[10].n_value; | |
95a5777b | 1004 | |
e6f0817b JF |
1005 | MSHookFunction(_UIImageWithName, &$_UIImageWithName, &_UIImageWithName); |
1006 | MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &_UIImageWithNameInDomain); | |
95a5777b JF |
1007 | |
1008 | if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) { | |
1009 | struct nlist nl[2]; | |
1010 | memset(nl, 0, sizeof(nl)); | |
1011 | nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb"; | |
1012 | nlist(AudioToolbox, nl); | |
1013 | _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value; | |
e6f0817b | 1014 | MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &_Z24GetFileNameForThisActionmPcRb); |
95a5777b | 1015 | } |
2435118f | 1016 | |
e6f0817b JF |
1017 | WBRename(false, "UIImage", @selector(applicationImageNamed:), (IMP) &UIImage$applicationImageNamed$); |
1018 | WBRename(false, "UIImage", @selector(defaultDesktopImage), (IMP) &UIImage$defaultDesktopImage$); | |
1019 | WBRename(false, "UIImage", @selector(imageAtPath:), (IMP) &UIImage$imageAtPath$); | |
1020 | WBRename(false, "UIImage", @selector(imageNamed:), (IMP) &UIImage$imageNamed$); | |
1021 | WBRename(false, "UIImage", @selector(imageNamed:inBundle:), (IMP) &UIImage$imageNamed$inBundle$); | |
1022 | ||
1023 | //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$); | |
1024 | //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$); | |
1025 | //WBRename(true, "SBStatusBar", @selector(initWithMode:orientation:", (IMP) &SBStatusBar$initWithMode$orientation$); | |
1026 | //WBRename(true, "UIWebDocumentView", @selector(setViewportSize:forDocumentTypes:", (IMP) &UIWebDocumentView$setViewportSize$forDocumentTypes$); | |
1027 | ||
1028 | WBRename(true, "NSBundle", @selector(bundlePath), (IMP) &NSBundle$bundlePath$); | |
1029 | WBRename(true, "NSBundle", @selector(pathForResource:ofType:), (IMP) &NSBundle$pathForResource$ofType$); | |
1030 | ||
1031 | WBRename(true, "UIImage", @selector(initWithContentsOfFile:), (IMP) &$initWithContentsOfFile$); | |
1032 | WBRename(true, "UIImage", @selector(initWithContentsOfFile:cache:), (IMP) &UIImage$initWithContentsOfFile$cache$); | |
1033 | WBRename(true, "UINavigationBar", @selector(setBarStyle:), (IMP) &UINavigationBar$setBarStyle$); | |
1034 | WBRename(true, "UIToolbar", @selector(setBarStyle:), (IMP) &UIToolbar$setBarStyle$); | |
1035 | ||
7ff778ee JF |
1036 | WBRename(true, "WebCoreFrameBridge", @selector(renderedSizeOfNode:constrainedToWidth:), (IMP) &WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$); |
1037 | ||
e6f0817b JF |
1038 | WBRename(true, "SBApplication", @selector(pathForIcon), (IMP) &SBApplication$pathForIcon); |
1039 | WBRename(true, "SBApplicationIcon", @selector(icon), (IMP) &SBApplicationIcon$icon); | |
1040 | WBRename(true, "SBBookmarkIcon", @selector(icon), (IMP) &SBBookmarkIcon$icon); | |
1041 | WBRename(true, "SBButtonBar", @selector(didMoveToSuperview), (IMP) &$didMoveToSuperview); | |
1042 | WBRename(true, "SBCalendarIconContentsView", @selector(drawRect:), (IMP) &SBCalendarIconContentsView$drawRect$); | |
1043 | WBRename(true, "SBContentLayer", @selector(initWithSize:), (IMP) &SBContentLayer$initWithSize$); | |
e6f0817b | 1044 | WBRename(true, "SBIconLabel", @selector(initWithSize:label:), (IMP) &SBIconLabel$initWithSize$label$); |
cf31d246 JF |
1045 | WBRename(true, "SBIconLabel", @selector(setInDock:), (IMP) &SBIconLabel$setInDock$); |
1046 | WBRename(true, "SBIconLabel", @selector(drawRect:), (IMP) &SBIconLabel$drawRect$); | |
e6f0817b JF |
1047 | WBRename(true, "SBSlidingAlertDisplay", @selector(updateDesktopImage:), (IMP) &SBSlidingAlertDisplay$updateDesktopImage$); |
1048 | WBRename(true, "SBStatusBarContentsView", @selector(didMoveToSuperview), (IMP) &$didMoveToSuperview); | |
1049 | WBRename(true, "SBStatusBarContentsView", @selector(initWithStatusBar:mode:), (IMP) &SBStatusBarContentsView$initWithStatusBar$mode$); | |
1050 | WBRename(true, "SBStatusBarController", @selector(setStatusBarMode:orientation:duration:fenceID:animation:), (IMP) &SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$); | |
1051 | WBRename(true, "SBStatusBarTimeView", @selector(drawRect:), (IMP) &SBStatusBarTimeView$drawRect$); | |
1052 | WBRename(true, "SBIconController", @selector(appendIconList:), (IMP) &SBIconController$appendIconList$); | |
d5fb6e01 | 1053 | |
502d350e JF |
1054 | _UISharedImageInitialize(false); |
1055 | ||
1056 | English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"]; | |
1057 | if (English_ != nil) | |
1058 | English_ = [English_ retain]; | |
1059 | ||
1060 | Manager_ = [[NSFileManager defaultManager] retain]; | |
1061 | UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16]; | |
1062 | PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16]; | |
1063 | Files_ = [[NSMutableDictionary alloc] initWithCapacity:16]; | |
1064 | ||
d5fb6e01 | 1065 | themes_ = [[NSMutableArray alloc] initWithCapacity:8]; |
26c43b47 | 1066 | |
d5fb6e01 | 1067 | if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) { |
62b2dbad | 1068 | [settings autorelease]; |
62b2dbad | 1069 | |
95a5777b JF |
1070 | if (NSNumber *debug = [settings objectForKey:@"Debug"]) |
1071 | Debug_ = [debug boolValue]; | |
1072 | ||
d5fb6e01 JF |
1073 | NSArray *themes = [settings objectForKey:@"Themes"]; |
1074 | if (themes == nil) | |
1075 | if (NSString *theme = [settings objectForKey:@"Theme"]) | |
1076 | themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys: | |
1077 | theme, @"Name", | |
95a5777b | 1078 | [NSNumber numberWithBool:true], @"Active", |
d5fb6e01 JF |
1079 | nil]]; |
1080 | if (themes != nil) | |
1081 | for (NSDictionary *theme in themes) { | |
1082 | NSNumber *active = [theme objectForKey:@"Active"]; | |
1083 | if (![active boolValue]) | |
1084 | continue; | |
26c43b47 | 1085 | |
d5fb6e01 JF |
1086 | NSString *name = [theme objectForKey:@"Name"]; |
1087 | if (name == nil) | |
1088 | continue; | |
1089 | ||
1090 | NSString *theme = nil; | |
1091 | ||
95a5777b JF |
1092 | #define testForTheme(format...) \ |
1093 | if (theme == nil) { \ | |
1094 | NSString *path = [NSString stringWithFormat:format]; \ | |
1095 | if ([Manager_ fileExistsAtPath:path]) { \ | |
1096 | [themes_ addObject:path]; \ | |
1097 | continue; \ | |
1098 | } \ | |
d5fb6e01 | 1099 | } |
d5fb6e01 | 1100 | |
95a5777b JF |
1101 | testForTheme(@"/Library/Themes/%@.theme", name) |
1102 | testForTheme(@"/Library/Themes/%@", name) | |
1103 | testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name) | |
d5fb6e01 | 1104 | } |
26c43b47 JF |
1105 | } |
1106 | ||
d5fb6e01 JF |
1107 | Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain]; |
1108 | ||
95a5777b | 1109 | for (NSString *theme in themes_) |
d5fb6e01 JF |
1110 | if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) |
1111 | for (NSString *key in [info allKeys]) | |
1112 | if ([Info_ objectForKey:key] == nil) | |
1113 | [Info_ setObject:[info objectForKey:key] forKey:key]; | |
95a5777b JF |
1114 | |
1115 | if (objc_getClass("SpringBoard") != nil) | |
1116 | CFNotificationCenterAddObserver( | |
1117 | CFNotificationCenterGetDarwinNotifyCenter(), | |
1118 | NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0 | |
1119 | ); | |
62b2dbad | 1120 | |
f22a8989 JF |
1121 | if ([Info_ objectForKey:@"UndockedIconLabels"] == nil) |
1122 | [Info_ setObject:[NSNumber numberWithBool:( | |
1123 | [Info_ objectForKey:@"DockedIconLabelStyle"] != nil || | |
1124 | [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil | |
1125 | )] forKey:@"UndockedIconLabels"]; | |
1126 | ||
1127 | if (![Info_ boolForKey:@"UndockedIconLabels"]) | |
d5fb6e01 JF |
1128 | if (Debug_) |
1129 | NSLog(@"WB:Debug:Info = %@", [Info_ description]); | |
1130 | ||
d5168fd6 JF |
1131 | [pool release]; |
1132 | } |