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