]> git.saurik.com Git - winterboard.git/blobdiff - Library.mm
I got the final Breaks: line from ashikase for Folder Enhancer.
[winterboard.git] / Library.mm
index d45c023e8acb54b2195de4be1528dca480da9bc1..676a2572e1eac05c8e267837bd52b6f7054b380d 100644 (file)
@@ -200,7 +200,7 @@ static BOOL (*_GSFontGetUseLegacyFontMetrics)();
 static bool Debug_ = false;
 static bool UIDebug_ = false;
 static bool Engineer_ = false;
 static bool Debug_ = false;
 static bool UIDebug_ = false;
 static bool Engineer_ = false;
-static bool SummerBoard_ = true;
+static bool SummerBoard_ = false;
 static bool SpringBoard_;
 
 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
 static bool SpringBoard_;
 
 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
@@ -676,6 +676,35 @@ MSInstanceMessageHook2(NSString *, NSBundle, pathForResource,ofType, NSString *,
 }
 // }}}
 
 }
 // }}}
 
+static void $drawLabel$(NSString *label, CGRect rect, NSString *style, NSString *custom) {
+    bool ellipsis(false);
+    float max = rect.size.width - 11, width;
+  width:
+    width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
+
+    if (width > max) {
+        size_t length([label length]);
+        float spacing((width - max) / (length - 1));
+
+        if (spacing > 1.25) {
+            ellipsis = true;
+            label = [label substringToIndex:(length - 1)];
+            goto width;
+        }
+
+        style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
+    }
+
+    if (ellipsis)
+        label = [label stringByAppendingString:@"..."];
+
+    if (custom != nil)
+        style = [style stringByAppendingString:custom];
+
+    CGSize size = [label sizeWithStyle:style forWidth:rect.size.width];
+    [label drawAtPoint:CGPointMake((rect.size.width - size.width) / 2 + rect.origin.x, rect.origin.y) withStyle:style];
+}
+
 static struct WBStringDrawingState {
     WBStringDrawingState *next_;
     unsigned count_;
 static struct WBStringDrawingState {
     WBStringDrawingState *next_;
     unsigned count_;
@@ -683,7 +712,9 @@ static struct WBStringDrawingState {
     NSString *info_;
 } *stringDrawingState_;
 
     NSString *info_;
 } *stringDrawingState_;
 
-MSInstanceMessageHook6(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreakMode,letterSpacing,includeEmoji, CGPoint, point, float, width, UIFont *, font, int, mode, float, spacing, BOOL, emoji) {
+MSInstanceMessageHook6(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreakMode,letterSpacing,includeEmoji, CGPoint, point, float, width, UIFont *, font, UILineBreakMode, mode, float, spacing, BOOL, emoji) {
+    //NSLog(@"XXX: @\"%@\" %g", self, spacing);
+
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(point, width, font, mode, spacing, emoji);
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(point, width, font, mode, spacing, emoji);
@@ -703,27 +734,52 @@ MSInstanceMessageHook6(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreak
     return CGSizeZero;
 }
 
     return CGSizeZero;
 }
 
-MSInstanceMessageHook6(CGSize, NSString, drawInRect,withFont,lineBreakMode,alignment,lineSpacing,includeEmoji, CGRect, rect, UIFont *, font, int, mode, int, alignment, float, spacing, BOOL, emoji) {
+extern "C" NSString *NSStringFromCGRect(CGRect rect);
+
+MSInstanceMessageHook7(CGSize, NSString, _drawInRect,withFont,lineBreakMode,alignment,lineSpacing,includeEmoji,truncationRect, CGRect, rect, UIFont *, font, UILineBreakMode, mode, UITextAlignment, alignment, float, spacing, BOOL, emoji, CGRect, truncation) {
+    //NSLog(@"XXX: &\"%@\" %@ \"%@\" %u %u %g %u %@", self, NSStringFromCGRect(rect), font, mode, alignment, spacing, emoji, NSStringFromCGRect(truncation));
+
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
-        return MSOldCall(rect, font, mode, alignment, spacing, emoji);
+        return MSOldCall(rect, font, mode, alignment, spacing, emoji, truncation);
 
     if (--state->count_ == 0)
         stringDrawingState_ = state->next_;
     if (state->info_ == nil)
 
     if (--state->count_ == 0)
         stringDrawingState_ = state->next_;
     if (state->info_ == nil)
-        return MSOldCall(rect, font, mode, alignment, spacing, emoji);
+        return MSOldCall(rect, font, mode, alignment, spacing, emoji, truncation);
 
     NSString *info([Info_ objectForKey:state->info_]);
     if (info == nil)
 
     NSString *info([Info_ objectForKey:state->info_]);
     if (info == nil)
-        return MSOldCall(rect, font, mode, alignment, spacing, emoji);
+        return MSOldCall(rect, font, mode, alignment, spacing, emoji, truncation);
+
+    NSString *textAlign;
+    switch (alignment) {
+        default:
+        case UITextAlignmentLeft:
+            textAlign = @"left";
+            break;
+        case UITextAlignmentCenter:
+            textAlign = @"center";
+            break;
+        case UITextAlignmentRight:
+            textAlign = @"right";
+            break;
+    }
 
     NSString *base(state->base_ ?: @"");
 
     NSString *base(state->base_ ?: @"");
-    NSString *align(@"text-align: center");
-    [self drawInRect:rect withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], align, base, info]];
+    NSString *extra([NSString stringWithFormat:@"text-align: %@", textAlign]);
+
+    if (true)
+        $drawLabel$(self, rect, [NSString stringWithFormat:@"%@;%@", [font markupDescription], base], info);
+    else
+        [self drawInRect:rect withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], extra, base, info]];
+
     return CGSizeZero;
 }
 
     return CGSizeZero;
 }
 
-MSInstanceMessageHook4(CGSize, NSString, sizeWithFont,forWidth,lineBreakMode,letterSpacing, UIFont *, font, float, width, int, mode, float, spacing) {
+MSInstanceMessageHook4(CGSize, NSString, sizeWithFont,forWidth,lineBreakMode,letterSpacing, UIFont *, font, float, width, UILineBreakMode, mode, float, spacing) {
+    //NSLog(@"XXX: #\"%@\" \"%@\" %g %u %g", self, font, width, mode, spacing);
+
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(font, width, mode, spacing);
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(font, width, mode, spacing);
@@ -743,6 +799,8 @@ MSInstanceMessageHook4(CGSize, NSString, sizeWithFont,forWidth,lineBreakMode,let
 }
 
 MSInstanceMessageHook1(CGSize, NSString, sizeWithFont, UIFont *, font) {
 }
 
 MSInstanceMessageHook1(CGSize, NSString, sizeWithFont, UIFont *, font) {
+    //NSLog(@"XXX: ?\"%@\"", self);
+
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(font);
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(font);
@@ -1194,7 +1252,7 @@ extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
 
 WBDelegate(time_)
 
 
 WBDelegate(time_)
 
-- (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
+- (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)mode {
     if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
         BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
 
     if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
         BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
 
@@ -1241,7 +1299,7 @@ WBDelegate(time_)
 
 WBDelegate(badge_)
 
 
 WBDelegate(badge_)
 
-- (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
+- (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)mode {
     if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
         [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
             "font-family: Helvetica; "
     if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
         [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
             "font-family: Helvetica; "
@@ -1525,8 +1583,6 @@ MSInstanceMessageHook2(CGSize, WebCoreFrameBridge, renderedSizeOfNode,constraine
 // }}}
 
 MSInstanceMessage1(void, SBIconLabel, drawRect, CGRect, rect) {
 // }}}
 
 MSInstanceMessage1(void, SBIconLabel, drawRect, CGRect, rect) {
-    CGRect bounds = [self bounds];
-
     static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
 
     int docked;
     static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
 
     int docked;
@@ -1549,46 +1605,23 @@ MSInstanceMessage1(void, SBIconLabel, drawRect, CGRect, rect) {
     else if (docked)
         style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
 
     else if (docked)
         style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
 
-    bool ellipsis(false);
-    float max = [self frame].size.width - 11, width;
-  width:
-    width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
-
-    if (width > max) {
-        size_t length([label length]);
-        float spacing((width - max) / (length - 1));
+    NSString *custom([Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")]);
 
 
-        if (spacing > 1.25) {
-            ellipsis = true;
-            label = [label substringToIndex:(length - 1)];
-            goto width;
-        }
-
-        style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
-    }
-
-    if (ellipsis)
-        label = [label stringByAppendingString:@"..."];
-
-    if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
-        style = [style stringByAppendingString:custom];
-
-    CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
-    [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
+    $drawLabel$(label, [self bounds], style, custom);
 }
 
 MSInstanceMessage0(CGImageRef, SBIconLabel, buildLabelImage) {
     bool docked((MSHookIvar<unsigned>(self, "_inDock") & 0x2) != 0);
 
 }
 
 MSInstanceMessage0(CGImageRef, SBIconLabel, buildLabelImage) {
     bool docked((MSHookIvar<unsigned>(self, "_inDock") & 0x2) != 0);
 
-    WBStringDrawingState labelState = {NULL, 0, [NSString stringWithFormat:@""
-        "color: %@;"
-    ,
-        (docked || !SummerBoard_ ? @"white" : @"#b3b3b3")
-    ], docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle"};
+    WBStringDrawingState labelState = {NULL, 0, @""
+        "color: white;"
+    , docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle"};
 
     stringDrawingState_ = &labelState;
 
 
     stringDrawingState_ = &labelState;
 
+    //NSLog(@"XXX: +");
     CGImageRef image(MSOldCall());
     CGImageRef image(MSOldCall());
+    //NSLog(@"XXX: -");
 
     stringDrawingState_ = NULL;
     return image;
 
     stringDrawingState_ = NULL;
     return image;
@@ -1778,7 +1811,7 @@ MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool
                 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
                 if ([Manager_ fileExistsAtPath:path]) {
                     strcpy(a1, [path UTF8String]);
                 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
                 if ([Manager_ fileExistsAtPath:path]) {
                     strcpy(a1, [path UTF8String]);
-                    continue;
+                    break;
                 }
             }
         }
                 }
             }
         }
@@ -1847,6 +1880,7 @@ static void NSString$drawAtPoint$withStyle$(NSString *self, SEL _cmd, CGPoint po
     WKSetCurrentGraphicsContext(UIGraphicsGetCurrentContext());
     if (style == nil || [style length] == 0)
         style = @"font-family: Helvetica; font-size: 12px";
     WKSetCurrentGraphicsContext(UIGraphicsGetCurrentContext());
     if (style == nil || [style length] == 0)
         style = @"font-family: Helvetica; font-size: 12px";
+    //NSLog(@"XXX:draw(%@)", [style stringByReplacingOccurrencesOfString:@"\n" withString:@" "]);
     return [[WBMarkup sharedMarkup] drawString:self atPoint:point withStyle:style];
 }
 
     return [[WBMarkup sharedMarkup] drawString:self atPoint:point withStyle:style];
 }
 
@@ -1860,6 +1894,7 @@ static void NSString$drawInRect$withStyle$(NSString *self, SEL _cmd, CGRect rect
 static CGSize NSString$sizeWithStyle$forWidth$(NSString *self, SEL _cmd, NSString *style, float width) {
     if (style == nil || [style length] == 0)
         style = @"font-family: Helvetica; font-size: 12px";
 static CGSize NSString$sizeWithStyle$forWidth$(NSString *self, SEL _cmd, NSString *style, float width) {
     if (style == nil || [style length] == 0)
         style = @"font-family: Helvetica; font-size: 12px";
+    //NSLog(@"XXX:size(%@)", [style stringByReplacingOccurrencesOfString:@"\n" withString:@" "]);
     return [[WBMarkup sharedMarkup] sizeOfString:self withStyle:style forWidth:width];
 }
 
     return [[WBMarkup sharedMarkup] sizeOfString:self withStyle:style forWidth:width];
 }
 
@@ -1885,7 +1920,7 @@ static void SBInitialize() {
     WBRename(SBDockIconListView, setFrame:, setFrame$);
     MSHookMessage(object_getClass($SBDockIconListView), @selector(shouldShowNewDock), &$SBDockIconListView$shouldShowNewDock, &_SBDockIconListView$shouldShowNewDock);
 
     WBRename(SBDockIconListView, setFrame:, setFrame$);
     MSHookMessage(object_getClass($SBDockIconListView), @selector(shouldShowNewDock), &$SBDockIconListView$shouldShowNewDock, &_SBDockIconListView$shouldShowNewDock);
 
-    if (kCFCoreFoundationVersionNumber < 600)
+    if (kCFCoreFoundationVersionNumber < 600 || SummerBoard_)
         WBRename(SBIconLabel, drawRect:, drawRect$);
     else
         WBRename(SBIconLabel, buildLabelImage, buildLabelImage);
         WBRename(SBIconLabel, drawRect:, drawRect$);
     else
         WBRename(SBIconLabel, buildLabelImage, buildLabelImage);
@@ -1935,6 +1970,9 @@ MSInitialize {
     if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
         if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
             SummerBoard_ = [value boolValue];
     if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
         if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
             SummerBoard_ = [value boolValue];
+        else
+            SummerBoard_ = true;
+
         if (NSNumber *value = [settings objectForKey:@"Debug"])
             Debug_ = [value boolValue];
         if (NSNumber *value = [settings objectForKey:@"RecordUI"])
         if (NSNumber *value = [settings objectForKey:@"Debug"])
             Debug_ = [value boolValue];
         if (NSNumber *value = [settings objectForKey:@"RecordUI"])