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