]>
Commit | Line | Data |
---|---|---|
b6ceaaff JF |
1 | #include <substrate.h> |
2 | ||
3 | #import <Foundation/NSArray.h> | |
81572520 | 4 | #import <Foundation/NSAutoreleasePool.h> |
b6ceaaff | 5 | #import <Foundation/NSNull.h> |
81572520 | 6 | |
b6ceaaff | 7 | #import <CoreGraphics/CGGeometry.h> |
ece3fb52 | 8 | |
b6ceaaff JF |
9 | #import <SpringBoard/SBButtonBar.h> |
10 | #import <SpringBoard/SBIcon.h> | |
8021a3ca | 11 | #import <SpringBoard/SBIconModel.h> |
b6ceaaff | 12 | |
81572520 JF |
13 | @interface ISIconSupport : NSObject { |
14 | } | |
15 | ||
16 | + (ISIconSupport *) sharedInstance; | |
17 | - (void) addExtension:(NSString *)name; | |
18 | ||
19 | @end | |
20 | ||
ece3fb52 JF |
21 | @interface SBDockIconListView : NSObject { |
22 | } | |
23 | - (NSArray *) icons; | |
24 | @end | |
25 | ||
b52a08b0 | 26 | MSClassHook(SBButtonBar) |
ece3fb52 | 27 | MSClassHook(SBDockIconListView) |
b52a08b0 JF |
28 | MSClassHook(SBIcon) |
29 | MSClassHook(SBIconModel) | |
e8dc11fb | 30 | |
ece3fb52 | 31 | MSMetaClassHook(SBDockIconListView) |
b52a08b0 | 32 | MSMetaClassHook(SBIconModel) |
e8dc11fb | 33 | |
81572520 JF |
34 | __attribute__((__constructor__)) |
35 | static void MSFixClass() { | |
36 | if ($SBIcon == nil) | |
37 | $SBIcon = objc_getClass("SBIconView"); | |
38 | } | |
39 | ||
b52a08b0 | 40 | MSInstanceMessageHook1(float, SBButtonBar, leftMarginForIconRowArray, NSArray *, row) { |
d0510745 | 41 | return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : MSOldCall(row); |
b6ceaaff JF |
42 | } |
43 | ||
b52a08b0 | 44 | MSInstanceMessageHook0(int, SBButtonBar, maxIconColumns) { |
1714f15a | 45 | return 5; |
b6ceaaff JF |
46 | } |
47 | ||
ece3fb52 JF |
48 | MSClassMessageHook1(int, SBDockIconListView, iconColumnsForInterfaceOrientation, int, orientation) { |
49 | return 5; | |
50 | } | |
51 | ||
56a24300 | 52 | static unsigned $SBButtonBar$count(SBButtonBar *self) { |
b52a08b0 | 53 | MSIvarHook(NSArray *, _iconMatrix); |
56a24300 JF |
54 | NSArray *row([_iconMatrix objectAtIndex:0]); |
55 | unsigned count(0); | |
56 | for (id icon in row) | |
57 | if (icon != [NSNull null]) | |
58 | ++count; | |
59 | return count; | |
b6ceaaff JF |
60 | } |
61 | ||
b52a08b0 | 62 | MSInstanceMessageHook0(float, SBButtonBar, topIconPadding) { |
bddf654d | 63 | return 313370 + $SBButtonBar$count(self); |
b6ceaaff JF |
64 | } |
65 | ||
b52a08b0 | 66 | MSInstanceMessageHook1(void, SBIcon, setOrigin, CGPoint, origin) { |
56a24300 | 67 | unsigned count(origin.y); |
bddf654d JF |
68 | if (count < 313370) |
69 | goto set; | |
70 | count -= 313370; | |
56a24300 | 71 | |
bddf654d | 72 | if (count > 40) |
b6ceaaff | 73 | origin.x = 256; |
56a24300 JF |
74 | else if (count > 10 || count < 0) |
75 | goto set; | |
76 | else if (count == 5) | |
77 | origin.x = (origin.x - 4) / 76 * 63 + 4; | |
78 | ||
79 | origin.y = 11; | |
b6ceaaff | 80 | set: |
d0510745 | 81 | MSOldCall(origin); |
b6ceaaff JF |
82 | } |
83 | ||
b52a08b0 | 84 | MSInstanceMessageHook2(CGPoint, SBButtonBar, originForIconAtX,Y, int, x, int, y) { |
d0510745 | 85 | CGPoint origin;//(MSOldCall(x, y, )); |
56a24300 JF |
86 | //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y); |
87 | origin.y = 11; | |
88 | ||
89 | unsigned count($SBButtonBar$count(self)), gap; | |
90 | unsigned space(320 - 60 * count); | |
91 | ||
92 | if (count >= 4) | |
93 | gap = space / (count + 1); | |
94 | else // I hate people who love Apple. | |
95 | gap = 16; | |
96 | ||
97 | origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x; | |
b6ceaaff | 98 | |
56a24300 JF |
99 | return origin; |
100 | } | |
101 | ||
ece3fb52 JF |
102 | // XXX: merge with previous function if possible, but not until after iPhone 4 |
103 | MSInstanceMessageHook2(CGPoint, SBDockIconListView, originForIconAtX,Y, int, x, int, y) { | |
104 | CGPoint origin;//(MSOldCall(x, y, )); | |
105 | //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y); | |
106 | origin.y = 11; | |
107 | ||
108 | unsigned count([[self icons] count]), gap; | |
109 | unsigned space(320 - 60 * count); | |
110 | ||
111 | if (count >= 4) | |
112 | gap = space / (count + 1); | |
113 | else // I hate people who love Apple. | |
114 | gap = 16; | |
115 | ||
116 | origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x; | |
117 | ||
118 | return origin; | |
119 | } | |
120 | ||
2538a727 | 121 | /*MSClassMessageHook0(int, SBIconModel, maxIconListCount) { |
8021a3ca | 122 | return 16; |
2538a727 | 123 | }*/ |
81572520 JF |
124 | |
125 | MSInitialize { | |
126 | NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); | |
127 | ||
128 | if (dlopen("/Library/MobileSubstrate/DynamicLibraries/IconSupport.dylib", RTLD_GLOBAL | RTLD_LAZY) != NULL) | |
129 | if (Class $ISIconSupport = objc_getClass("ISIconSupport")) | |
130 | [[$ISIconSupport sharedInstance] addExtension:@"com.saurik.iphone.fid"]; | |
131 | ||
132 | [pool release]; | |
133 | } |