-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathUIStatusBarCustomItem.mm
191 lines (151 loc) · 5.8 KB
/
UIStatusBarCustomItem.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//#define TESTING
#import "common.h"
#import "defines.h"
#import "classes.h"
#import "UIStatusBarCustomItem.h"
#import "LSStatusBarItem.h"
//Class $UIStatusBarCustomItem;
int UIStatusBarCustomItem$type(UIStatusBarCustomItem* self, SEL sel)
{
return 0;
}
int UIStatusBarCustomItem$leftOrder(UIStatusBarCustomItem* self, SEL sel)
{
if(NSDictionary* properties = [self properties])
{
NSNumber* nsalign = [properties objectForKey: @"alignment"];
StatusBarAlignment alignment = nsalign ? (StatusBarAlignment) [nsalign intValue] : StatusBarAlignmentRight;
if(alignment & StatusBarAlignmentLeft)
{
return 15;
}
}
return 0;
}
Class UIStatusBarCustomItem$viewClass(UIStatusBarCustomItem* self, SEL sel)
{
NSString* customViewClass = [[self properties] objectForKey: @"customViewClass"];
if(customViewClass)
{
Class ret = NSClassFromString(customViewClass);
if(ret)
return ret;
}
return $UIStatusBarCustomItemView;
// return objc_getClass("UIStatusBarCustomItemView");
// return objc_getClass("UIStatusBarIndicatorItemView");
}
int UIStatusBarCustomItem$rightOrder(UIStatusBarCustomItem* self, SEL sel)
{
if(NSDictionary* properties = [self properties])
{
NSNumber* nsalign = [properties objectForKey: @"alignment"];
StatusBarAlignment alignment = nsalign ? (StatusBarAlignment) [nsalign intValue] : StatusBarAlignmentRight;
if(alignment & StatusBarAlignmentRight)
{
return 15;
}
else
{
return 0;
}
}
else
{
return 15;
}
}
int UIStatusBarCustomItem$priority(UIStatusBarCustomItem* self, SEL sel)
{
return 0;
}
NSString* UIStatusBarCustomItem$description(UIStatusBarCustomItem* self, SEL sel)
{
return [NSString stringWithFormat: @"UIStatusBarCustomItem [%@]", [self indicatorName]];
}
NSString* UIStatusBarCustomItem$indicatorName(UIStatusBarCustomItem* self, SEL sel)
{
if(NSDictionary* properties = [self properties])
{
NSString* name = [properties objectForKey: @"imageName"];
if(name)
return name;
}
NSString* &_indicatorName(MSHookIvar<NSString*>(self, "_indicatorName"));
return _indicatorName;
}
void UIStatusBarCustomItem$setIndicatorName$(UIStatusBarCustomItem* self, SEL sel, NSString* name)
{
NSString* &_indicatorName(MSHookIvar<NSString*>(self, "_indicatorName"));
[_indicatorName release];
_indicatorName = [name retain];
}
NSDictionary* UIStatusBarCustomItem$properties(UIStatusBarCustomItem* self, SEL sel)
{
NSDictionary* &_properties(MSHookIvar<NSDictionary*>(self, "_properties"));
return _properties;
}
void UIStatusBarCustomItem$setProperties$(UIStatusBarCustomItem* self, SEL sel, NSDictionary* properties)
{
NSDictionary* &_properties(MSHookIvar<NSDictionary*>(self, "_properties"));
[_properties release];
_properties = [properties retain];
}
UIStatusBarItemView* UIStatusBarCustomItem$viewForManager$(id self, SEL sel, id manager)
{
CFMutableDictionaryRef &_views(MSHookIvar<CFMutableDictionaryRef>(self, "_views"));
if(_views)
{
return (UIStatusBarItemView*) CFDictionaryGetValue(_views, (void*) manager);
}
else
{
return nil;
}
}
void UIStatusBarCustomItem$setView$forManager$(id self, SEL sel, id view, id manager)
{
CFMutableDictionaryRef &_views(MSHookIvar<CFMutableDictionaryRef>(self, "_views"));
if(!_views)
{
_views = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
CFDictionarySetValue(_views, (void*) manager, view);
}
void UIStatusBarCustomItem$removeFromSuperview(id key, UIView* view)
{
if(view)
[view removeFromSuperview];
}
void UIStatusBarCustomItem$removeAllViews(id self, SEL sel)
{
CFMutableDictionaryRef &_views(MSHookIvar<CFMutableDictionaryRef>(self, "_views"));
if(_views)
{
CFDictionaryApplyFunction(_views, (CFDictionaryApplierFunction) UIStatusBarCustomItem$removeFromSuperview, NULL);
}
}
void ClassCreate_UIStatusBarCustomItem()
{
GETCLASS(UIStatusBarItem);
$UIStatusBarCustomItem = objc_allocateClassPair($UIStatusBarItem, "UIStatusBarCustomItem", 0);
class_addMethod($UIStatusBarCustomItem, @selector(type), (IMP) UIStatusBarCustomItem$type, "i@:");
class_addMethod($UIStatusBarCustomItem, @selector(leftOrder), (IMP) UIStatusBarCustomItem$leftOrder, "i@:");
class_addMethod($UIStatusBarCustomItem, @selector(viewClass), (IMP) UIStatusBarCustomItem$viewClass, "#@:");
//class_addIvar($UIStatusBarCustomItem, "_properties", sizeof(id), 0x4, "@");
class_addMethod($UIStatusBarCustomItem, @selector(rightOrder), (IMP) UIStatusBarCustomItem$rightOrder, "i@:");
class_addMethod($UIStatusBarCustomItem, @selector(priority), (IMP) UIStatusBarCustomItem$priority, "i@:");
class_addMethod($UIStatusBarCustomItem, @selector(description), (IMP) UIStatusBarCustomItem$description, "@@:");
class_addIvar($UIStatusBarCustomItem, "_views", sizeof(id), 0x4, "@");
class_addMethod($UIStatusBarCustomItem, @selector(viewForManager:), (IMP) UIStatusBarCustomItem$viewForManager$, "@@:@");
class_addMethod($UIStatusBarCustomItem, @selector(setView:forManager:), (IMP) UIStatusBarCustomItem$setView$forManager$, "v@:@@");
class_addMethod($UIStatusBarCustomItem, @selector(removeAllViews), (IMP) UIStatusBarCustomItem$removeAllViews, "v@:");
class_addIvar($UIStatusBarCustomItem, "_properties", sizeof(id), 0x4, "@");
class_addIvar($UIStatusBarCustomItem, "_indicatorName", sizeof(id), 0x4, "@");
class_addMethod($UIStatusBarCustomItem, @selector(indicatorName), (IMP) UIStatusBarCustomItem$indicatorName, "@@:");
class_addMethod($UIStatusBarCustomItem, @selector(setIndicatorName:), (IMP) UIStatusBarCustomItem$setIndicatorName$, "v@:@");
class_addMethod($UIStatusBarCustomItem, @selector(properties), (IMP) UIStatusBarCustomItem$properties, "@@:");
class_addMethod($UIStatusBarCustomItem, @selector(setProperties:), (IMP) UIStatusBarCustomItem$setProperties$, "v@:@");
objc_registerClassPair($UIStatusBarCustomItem);
CommonLog("Class created")
}