file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
Example/Pods/Nimbus/src/core/src/NIError.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> /** * For defining various error types used throughout the Nimbus framework. * * @ingroup NimbusCore * @defgroup Errors Errors * @{ */ /** The Nimbus error domain. */ extern NSString* const NINimbusErrorDomain; /** The key used for images in the error's userInfo. */ extern NSString* const NIImageErrorKey; /** NSError codes in NINimbusErrorDomain. */ typedef enum { /** The image is too small to be used. */ NIImageTooSmall = 1, } NINimbusErrorDomainCode; /**@}*/// End of Errors /////////////////////////////////////////////////////////////////////////// /** * <h3>Example</h3> * * @code * error = [NSError errorWithDomain: NINimbusErrorDomain * code: NIImageTooSmall * userInfo: [NSDictionary dictionaryWithObject: image * forKey: NIImageErrorKey]]; * @endcode * * @enum NINimbusErrorDomainCode */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIError.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIError.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NSString* const NINimbusErrorDomain = @"com.nimbus.error"; NSString* const NIImageErrorKey = @"image";
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIFoundationMethods.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NIPreprocessorMacros.h" #if defined __cplusplus extern "C" { #endif /** * For filling in gaps in Apple's Foundation framework. * * @ingroup NimbusCore * @defgroup Foundation-Methods Foundation Methods * @{ * * Utility methods save time and headache. You've probably written dozens of your own. Nimbus * hopes to provide an ever-growing set of convenience methods that compliment the Foundation * framework's functionality. */ #pragma mark - NSInvocation Methods /** * Construct an NSInvocation with an instance of an object and a selector * * @return an NSInvocation that will call the given selector on the given target */ NSInvocation* NIInvocationWithInstanceTarget(NSObject* target, SEL selector); /** * Construct an NSInvocation for a class method given a class object and a selector * * @return an NSInvocation that will call the given class method/selector. */ NSInvocation* NIInvocationWithClassTarget(Class targetClass, SEL selector); #pragma mark - CGRect Methods /** * For manipulating CGRects. * * @defgroup CGRect-Methods CGRect Methods * @{ * * These methods provide additional means of modifying the edges of CGRects beyond the basics * included in CoreGraphics. */ /** * Modifies only the right and bottom edges of a CGRect. * * @return a CGRect with dx and dy subtracted from the width and height. * * Example result: CGRectMake(x, y, w - dx, h - dy) */ CGRect NIRectContract(CGRect rect, CGFloat dx, CGFloat dy); /** * Modifies only the right and bottom edges of a CGRect. * * @return a CGRect with dx and dy added to the width and height. * * Example result: CGRectMake(x, y, w + dx, h + dy) */ CGRect NIRectExpand(CGRect rect, CGFloat dx, CGFloat dy); /** * Modifies only the top and left edges of a CGRect. * * @return a CGRect whose origin has been offset by dx, dy, and whose size has been * contracted by dx, dy. * * Example result: CGRectMake(x + dx, y + dy, w - dx, h - dy) */ CGRect NIRectShift(CGRect rect, CGFloat dx, CGFloat dy); /** * Inverse of UIEdgeInsetsInsetRect. * * Example result: CGRectMake(x - left, y - top, * w + left + right, h + top + bottom) */ CGRect NIEdgeInsetsOutsetRect(CGRect rect, UIEdgeInsets outsets); /** * Returns the x position that will center size within containerSize. * * Example result: floorf((containerSize.width - size.width) / 2.f) */ CGFloat NICenterX(CGSize containerSize, CGSize size); /** * Returns the y position that will center size within containerSize. * * Example result: floorf((containerSize.height - size.height) / 2.f) */ CGFloat NICenterY(CGSize containerSize, CGSize size); /** * Returns a rect that will center viewToCenter within containerView. * * @return a CGPoint that will center viewToCenter within containerView. */ CGRect NIFrameOfCenteredViewWithinView(UIView* viewToCenter, UIView* containerView); /** * Returns the size of the string with given UILabel properties. */ CGSize NISizeOfStringWithLabelProperties(NSString *string, CGSize constrainedToSize, UIFont *font, NSLineBreakMode lineBreakMode, NSInteger numberOfLines); /**@}*/ #pragma mark - NSRange Methods /** * For manipulating NSRange. * * @defgroup NSRange-Methods NSRange Methods * @{ */ /** * Create an NSRange object from a CFRange object. * * @return an NSRange object with the same values as the CFRange object. * * @attention This has the potential to behave unexpectedly because it converts the * CFRange's long values to unsigned integers. Nimbus will fire off a debug * assertion at runtime if the value will be chopped or the sign will change. * Even though the assertion will fire, the method will still chop or change * the sign of the values so you should take care to fix this. */ NSRange NIMakeNSRangeFromCFRange(CFRange range); /**@}*/ #pragma mark - NSData Methods /** * For manipulating NSData. * * @defgroup NSData-Methods NSData Methods * @{ */ /** * Calculates an md5 hash of the data using CC_MD5. */ NSString* NIMD5HashFromData(NSData* data); /** * Calculates a sha1 hash of the data using CC_SHA1. */ NSString* NISHA1HashFromData(NSData* data); /**@}*/ #pragma mark - NSString Methods /** * For manipulating NSStrings. * * @defgroup NSString-Methods NSString Methods * @{ */ /** * Calculates an md5 hash of the string using CC_MD5. * * Treats the string as UTF8. */ NSString* NIMD5HashFromString(NSString* string); /** * Calculates a sha1 hash of the string using CC_SHA1. * * Treats the string as UTF8. */ NSString* NISHA1HashFromString(NSString* string); /** * Returns a Boolean value indicating whether the string is a NSString object that contains only * whitespace and newlines. */ BOOL NIIsStringWithWhitespaceAndNewlines(NSString* string); /** * Compares two strings expressing software versions. * * The comparison is (except for the development version provisions noted below) lexicographic * string comparison. So as long as the strings being compared use consistent version formats, * a variety of schemes are supported. For example "3.02" < "3.03" and "3.0.2" < "3.0.3". If you * mix such schemes, like trying to compare "3.02" and "3.0.3", the result may not be what you * expect. * * Development versions are also supported by adding an "a" character and more version info after * it. For example "3.0a1" or "3.01a4". The way these are handled is as follows: if the parts * before the "a" are different, the parts after the "a" are ignored. If the parts before the "a" * are identical, the result of the comparison is the result of NUMERICALLY comparing the parts * after the "a". If the part after the "a" is empty, it is treated as if it were "0". If one * string has an "a" and the other does not (e.g. "3.0" and "3.0a1") the one without the "a" * is newer. * * Examples (?? means undefined): * @htmlonly * <pre> * "3.0" = "3.0" * "3.0a2" = "3.0a2" * "3.0" > "2.5" * "3.1" > "3.0" * "3.0a1" < "3.0" * "3.0a1" < "3.0a4" * "3.0a2" < "3.0a19" <-- numeric, not lexicographic * "3.0a" < "3.0a1" * "3.02" < "3.03" * "3.0.2" < "3.0.3" * "3.00" ?? "3.0" * "3.02" ?? "3.0.3" * "3.02" ?? "3.0.2" * </pre> * @endhtmlonly */ NSComparisonResult NICompareVersionStrings(NSString* string1, NSString* string2); /** * Parses a URL query string into a dictionary where the values are arrays. * * A query string is one that looks like &param1=value1&param2=value2... * * The resulting NSDictionary will contain keys for each parameter name present in the query. * The value for each key will be an NSArray which may be empty if the key is simply present * in the query. Otherwise each object in the array with be an NSString corresponding to a value * in the query for that parameter. */ NSDictionary* NIQueryDictionaryFromStringUsingEncoding(NSString* string, NSStringEncoding encoding); /** * Returns a string that has been escaped for use as a URL parameter. */ NSString* NIStringByAddingPercentEscapesForURLParameterString(NSString* parameter); /** * Appends a dictionary of query parameters to a string, adding the ? character if necessary. */ NSString* NIStringByAddingQueryDictionaryToString(NSString* string, NSDictionary* query); /**@}*/ #pragma mark - CGFloat Methods /** * For manipulating CGFloat. * * @defgroup CGFloat-Methods CGFloat Methods * @{ * * These methods provide math functions on CGFloats. They could easily be replaced with <tgmath.h> * but that is currently (Xcode 5.0) incompatible with CLANG_ENABLE_MODULES (on by default for * many projects/targets). We'll use CG_INLINE because this really should be completely inline. */ #if CGFLOAT_IS_DOUBLE #define NI_CGFLOAT_EPSILON DBL_EPSILON #else #define NI_CGFLOAT_EPSILON FLT_EPSILON #endif /** * fabs()/fabsf() sized for CGFloat */ CG_INLINE CGFloat NICGFloatAbs(CGFloat x) { #if CGFLOAT_IS_DOUBLE return (CGFloat)fabs(x); #else return (CGFloat)fabsf(x); #endif } /** * floor()/floorf() sized for CGFloat */ CG_INLINE CGFloat NICGFloatFloor(CGFloat x) { #if CGFLOAT_IS_DOUBLE return (CGFloat)floor(x); #else return (CGFloat)floorf(x); #endif } /** * ceil()/ceilf() sized for CGFloat */ CG_INLINE CGFloat NICGFloatCeil(CGFloat x) { #if CGFLOAT_IS_DOUBLE return (CGFloat)ceil(x); #else return (CGFloat)ceilf(x); #endif } /** * round()/roundf() sized for CGFloat */ CG_INLINE CGFloat NICGFloatRound(CGFloat x) { #if CGFLOAT_IS_DOUBLE return (CGFloat)round(x); #else return (CGFloat)roundf(x); #endif } /** * sqrt()/sqrtf() sized for CGFloat */ CG_INLINE CGFloat NICGFloatSqRt(CGFloat x) { #if CGFLOAT_IS_DOUBLE return (CGFloat)sqrt(x); #else return (CGFloat)sqrtf(x); #endif } /** * copysign()/copysignf() sized for CGFloat */ CG_INLINE CGFloat NICGFloatCopySign(CGFloat x, CGFloat y) { #if CGFLOAT_IS_DOUBLE return (CGFloat)copysign(x, y); #else return (CGFloat)copysignf(x, y); #endif } /** * pow()/powf() sized for CGFloat */ CG_INLINE CGFloat NICGFloatPow(CGFloat x, CGFloat y) { #if CGFLOAT_IS_DOUBLE return (CGFloat)pow(x, y); #else return (CGFloat)powf(x, y); #endif } /** * cos()/cosf() sized for CGFloat */ CG_INLINE CGFloat NICGFloatCos(CGFloat x) { #if CGFLOAT_IS_DOUBLE return (CGFloat)cos(x); #else return (CGFloat)cosf(x); #endif } /**@}*/ #pragma mark - General Purpose Methods /** * For general purpose foundation type manipulation. * * @defgroup General-Purpose-Methods General Purpose Methods * @{ */ /** * Deprecated method. Use NIBoundf instead. */ CGFloat boundf(CGFloat value, CGFloat min, CGFloat max) __NI_DEPRECATED_METHOD; // Use NIBoundf instead. MAINTENANCE: Remove by Feb 28, 2014. /** * Deprecated method. Use NIBoundi instead. */ NSInteger boundi(NSInteger value, NSInteger min, NSInteger max) __NI_DEPRECATED_METHOD; // Use NIBoundi instead. MAINTENANCE: Remove by Feb 28, 2014. /** * Bounds a given value within the min and max values. * * If max < min then value will be min. * * @returns min <= result <= max */ CGFloat NIBoundf(CGFloat value, CGFloat min, CGFloat max); /** * Bounds a given value within the min and max values. * * If max < min then value will be min. * * @returns min <= result <= max */ NSInteger NIBoundi(NSInteger value, NSInteger min, NSInteger max); /**@}*/ #if defined __cplusplus }; #endif /**@}*/// End of Foundation Methods ///////////////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIFoundationMethods.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIFoundationMethods.h" #import "NIDebuggingTools.h" #import <CommonCrypto/CommonDigest.h> #import <objc/runtime.h> #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif #pragma mark - NSInvocation NSInvocation* NIInvocationWithInstanceTarget(NSObject *targetObject, SEL selector) { NSMethodSignature* sig = [targetObject methodSignatureForSelector:selector]; NSInvocation* inv = [NSInvocation invocationWithMethodSignature:sig]; [inv setTarget:targetObject]; [inv setSelector:selector]; return inv; } NSInvocation* NIInvocationWithClassTarget(Class targetClass, SEL selector) { Method method = class_getInstanceMethod(targetClass, selector); struct objc_method_description* desc = method_getDescription(method); if (desc == NULL || desc->name == NULL) return nil; NSMethodSignature* sig = [NSMethodSignature signatureWithObjCTypes:desc->types]; NSInvocation* inv = [NSInvocation invocationWithMethodSignature:sig]; [inv setSelector:selector]; return inv; } #pragma mark - CGRect CGRect NIRectContract(CGRect rect, CGFloat dx, CGFloat dy) { return CGRectMake(rect.origin.x, rect.origin.y, rect.size.width - dx, rect.size.height - dy); } CGRect NIRectExpand(CGRect rect, CGFloat dx, CGFloat dy) { return CGRectMake(rect.origin.x, rect.origin.y, rect.size.width + dx, rect.size.height + dy); } CGRect NIRectShift(CGRect rect, CGFloat dx, CGFloat dy) { return CGRectOffset(NIRectContract(rect, dx, dy), dx, dy); } CGRect NIEdgeInsetsOutsetRect(CGRect rect, UIEdgeInsets outsets) { return CGRectMake(rect.origin.x - outsets.left, rect.origin.y - outsets.top, rect.size.width + outsets.left + outsets.right, rect.size.height + outsets.top + outsets.bottom); } CGFloat NICenterX(CGSize containerSize, CGSize size) { return NICGFloatFloor((containerSize.width - size.width) / 2.f); } CGFloat NICenterY(CGSize containerSize, CGSize size) { return NICGFloatFloor((containerSize.height - size.height) / 2.f); } CGRect NIFrameOfCenteredViewWithinView(UIView* viewToCenter, UIView* containerView) { CGPoint origin; CGSize containerViewSize = containerView.bounds.size; CGSize viewSize = viewToCenter.frame.size; origin.x = NICenterX(containerViewSize, viewSize); origin.y = NICenterY(containerViewSize, viewSize); return CGRectMake(origin.x, origin.y, viewSize.width, viewSize.height); } CGSize NISizeOfStringWithLabelProperties(NSString *string, CGSize constrainedToSize, UIFont *font, NSLineBreakMode lineBreakMode, NSInteger numberOfLines) { if (string.length == 0) { return CGSizeZero; } CGFloat lineHeight = font.lineHeight; CGSize size = CGSizeZero; if (numberOfLines == 1) { size = [string sizeWithFont:font forWidth:constrainedToSize.width lineBreakMode:lineBreakMode]; } else { size = [string sizeWithFont:font constrainedToSize:constrainedToSize lineBreakMode:lineBreakMode]; if (numberOfLines > 0) { size.height = MIN(size.height, numberOfLines * lineHeight); } } return size; } #pragma mark - NSRange NSRange NIMakeNSRangeFromCFRange(CFRange range) { // CFRange stores its values in signed longs, but we're about to copy the values into // unsigned integers, let's check whether we're about to lose any information. NIDASSERT(range.location >= 0 && range.location <= NSIntegerMax); NIDASSERT(range.length >= 0 && range.length <= NSIntegerMax); return NSMakeRange(range.location, range.length); } #pragma mark - NSData NSString* NIMD5HashFromData(NSData* data) { unsigned char result[CC_MD5_DIGEST_LENGTH]; bzero(result, sizeof(result)); CC_MD5_CTX md5Context; CC_MD5_Init(&md5Context); size_t bytesHashed = 0; while (bytesHashed < [data length]) { CC_LONG updateSize = 1024 * 1024; if (([data length] - bytesHashed) < (size_t)updateSize) { updateSize = (CC_LONG)([data length] - bytesHashed); } CC_MD5_Update(&md5Context, (char *)[data bytes] + bytesHashed, updateSize); bytesHashed += updateSize; } CC_MD5_Final(result, &md5Context); return [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15] ]; } NSString* NISHA1HashFromData(NSData* data) { unsigned char result[CC_SHA1_DIGEST_LENGTH]; bzero(result, sizeof(result)); CC_SHA1_CTX sha1Context; CC_SHA1_Init(&sha1Context); size_t bytesHashed = 0; while (bytesHashed < [data length]) { CC_LONG updateSize = 1024 * 1024; if (([data length] - bytesHashed) < (size_t)updateSize) { updateSize = (CC_LONG)([data length] - bytesHashed); } CC_SHA1_Update(&sha1Context, (char *)[data bytes] + bytesHashed, updateSize); bytesHashed += updateSize; } CC_SHA1_Final(result, &sha1Context); return [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15], result[16], result[17], result[18], result[19] ]; } #pragma mark - NSString NSString* NIMD5HashFromString(NSString* string) { return NIMD5HashFromData([string dataUsingEncoding:NSUTF8StringEncoding]); } NSString* NISHA1HashFromString(NSString* string) { return NISHA1HashFromData([string dataUsingEncoding:NSUTF8StringEncoding]); } BOOL NIIsStringWithWhitespaceAndNewlines(NSString* string) { NSCharacterSet* notWhitespaceAndNewlines = [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet]; return [string isKindOfClass:[NSString class]] && [string rangeOfCharacterFromSet:notWhitespaceAndNewlines].length == 0; } NSComparisonResult NICompareVersionStrings(NSString* string1, NSString* string2) { NSArray *oneComponents = [string1 componentsSeparatedByString:@"a"]; NSArray *twoComponents = [string2 componentsSeparatedByString:@"a"]; // The parts before the "a" NSString *oneMain = [oneComponents objectAtIndex:0]; NSString *twoMain = [twoComponents objectAtIndex:0]; // If main parts are different, return that result, regardless of alpha part NSComparisonResult mainDiff; if ((mainDiff = [oneMain compare:twoMain]) != NSOrderedSame) { return mainDiff; } // At this point the main parts are the same; just deal with alpha stuff // If one has an alpha part and the other doesn't, the one without is newer if ([oneComponents count] < [twoComponents count]) { return NSOrderedDescending; } else if ([oneComponents count] > [twoComponents count]) { return NSOrderedAscending; } else if ([oneComponents count] == 1) { // Neither has an alpha part, and we know the main parts are the same return NSOrderedSame; } // At this point the main parts are the same and both have alpha parts. Compare the alpha parts // numerically. If it's not a valid number (including empty string) it's treated as zero. NSNumber *oneAlpha = [NSNumber numberWithInt:[[oneComponents objectAtIndex:1] intValue]]; NSNumber *twoAlpha = [NSNumber numberWithInt:[[twoComponents objectAtIndex:1] intValue]]; return [oneAlpha compare:twoAlpha]; } NSDictionary* NIQueryDictionaryFromStringUsingEncoding(NSString* string, NSStringEncoding encoding) { NSCharacterSet* delimiterSet = [NSCharacterSet characterSetWithCharactersInString:@"&;"]; NSMutableDictionary* pairs = [NSMutableDictionary dictionary]; NSScanner* scanner = [[NSScanner alloc] initWithString:string]; while (![scanner isAtEnd]) { NSString* pairString = nil; [scanner scanUpToCharactersFromSet:delimiterSet intoString:&pairString]; [scanner scanCharactersFromSet:delimiterSet intoString:NULL]; NSArray* kvPair = [pairString componentsSeparatedByString:@"="]; if (kvPair.count == 1 || kvPair.count == 2) { NSString* key = [kvPair[0] stringByReplacingPercentEscapesUsingEncoding:encoding]; NSMutableArray* values = pairs[key]; if (nil == values) { values = [NSMutableArray array]; pairs[key] = values; } if (kvPair.count == 1) { [values addObject:[NSNull null]]; } else if (kvPair.count == 2) { NSString* value = [kvPair[1] stringByReplacingPercentEscapesUsingEncoding:encoding]; [values addObject:value]; } } } return [pairs copy]; } NSString* NIStringByAddingPercentEscapesForURLParameterString(NSString* parameter) { CFStringRef buffer = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)parameter, NULL, (__bridge CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); NSString* result = [NSString stringWithString:(__bridge NSString *)buffer]; CFRelease(buffer); return result; } NSString* NIStringByAddingQueryDictionaryToString(NSString* string, NSDictionary* query) { NSMutableArray* pairs = [NSMutableArray array]; for (NSString* key in [query keyEnumerator]) { NSString* value = NIStringByAddingPercentEscapesForURLParameterString([query objectForKey:key]); NSString* pair = [NSString stringWithFormat:@"%@=%@", key, value]; [pairs addObject:pair]; } NSString* params = [pairs componentsJoinedByString:@"&"]; if ([string rangeOfString:@"?"].location == NSNotFound) { return [string stringByAppendingFormat:@"?%@", params]; } else { return [string stringByAppendingFormat:@"&%@", params]; } } #pragma mark - General Purpose // Deprecated. CGFloat boundf(CGFloat value, CGFloat min, CGFloat max) { return NIBoundf(value, min, max); } // Deprecated. NSInteger boundi(NSInteger value, NSInteger min, NSInteger max) { return NIBoundi(value, min, max); } CGFloat NIBoundf(CGFloat value, CGFloat min, CGFloat max) { if (max < min) { max = min; } CGFloat bounded = value; if (bounded > max) { bounded = max; } if (bounded < min) { bounded = min; } return bounded; } NSInteger NIBoundi(NSInteger value, NSInteger min, NSInteger max) { if (max < min) { max = min; } NSInteger bounded = value; if (bounded > max) { bounded = max; } if (bounded < min) { bounded = min; } return bounded; }
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIImageUtilities.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #if defined __cplusplus extern "C" { #endif /** * For manipulating UIImage objects. * * @ingroup NimbusCore * @defgroup Image-Utilities Image Utilities * @{ */ /** * Returns an image that is stretchable from the center. * * A common use of this method is to create an image that has rounded corners for a button * and then assign a stretchable version of that image to a UIButton. * * This stretches the middle vertical and horizontal line of pixels, so use care when * stretching images that have gradients. For example, an image with a vertical gradient * can be stretched horizontally, but will look odd if stretched vertically. */ UIImage* NIStretchableImageFromImage(UIImage* image); /**@}*/// End of Image Utilities ////////////////////////////////////////////////////////////////// #if defined __cplusplus }; #endif
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIImageUtilities.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIImageUtilities.h" UIImage* NIStretchableImageFromImage(UIImage* image) { const CGSize size = image.size; NSInteger midX = (NSInteger)(size.width / 2.f); NSInteger midY = (NSInteger)(size.height / 2.f); return [image stretchableImageWithLeftCapWidth:midX topCapHeight:midY]; }
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIInMemoryCache.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import "NIPreprocessorMacros.h" /** * For storing and accessing objects in memory. * * The base class, NIMemoryCache, is a generic object store that may be used for anything that * requires support for expiration. * * @ingroup NimbusCore * @defgroup In-Memory-Caches In-Memory Caches * @{ */ /** * An in-memory cache for storing objects with expiration support. * * The Nimbus in-memory object cache allows you to store objects in memory with an expiration * date attached. Objects with expiration dates drop out of the cache when they have expired. */ @interface NIMemoryCache : NSObject // Designated initializer. - (id)initWithCapacity:(NSUInteger)capacity; - (NSUInteger)count; - (void)storeObject:(id)object withName:(NSString *)name; - (void)storeObject:(id)object withName:(NSString *)name expiresAfter:(NSDate *)expirationDate; - (void)removeObjectWithName:(NSString *)name; - (void)removeAllObjectsWithPrefix:(NSString *)prefix; - (void)removeAllObjects; - (id)objectWithName:(NSString *)name; - (BOOL)containsObjectWithName:(NSString *)name; - (NSDate *)dateOfLastAccessWithName:(NSString *)name; - (NSString *)nameOfLeastRecentlyUsedObject; - (NSString *)nameOfMostRecentlyUsedObject; - (void)reduceMemoryUsage; // Subclassing - (BOOL)shouldSetObject:(id)object withName:(NSString *)name previousObject:(id)previousObject; - (void)didSetObject:(id)object withName:(NSString *)name; - (void)willRemoveObject:(id)object withName:(NSString *)name; // Deprecated method. Use shouldSetObject:withName:previousObject: instead. - (BOOL)willSetObject:(id)object withName:(NSString *)name previousObject:(id)previousObject __NI_DEPRECATED_METHOD; @end /** * An in-memory cache for storing images with caps on the total number of pixels. * * When reduceMemoryUsage is called, the least recently used images are removed from the cache * until the numberOfPixels is below maxNumberOfPixelsUnderStress. * * When an image is added to the cache that causes the memory usage to pass the max, the * least recently used images are removed from the cache until the numberOfPixels is below * maxNumberOfPixels. * * By default the image memory cache has no limit to its pixel count. You must explicitly * set this value in your application. * * @attention If the cache is too small to fit the newly added image, then all images * will end up being removed including the one being added. * * @see Nimbus::imageMemoryCache * @see Nimbus::setImageMemoryCache: */ @interface NIImageMemoryCache : NIMemoryCache @property (nonatomic, readonly) unsigned long long numberOfPixels; @property (nonatomic) unsigned long long maxNumberOfPixels; // Default: 0 (unlimited) @property (nonatomic) unsigned long long maxNumberOfPixelsUnderStress; // Default: 0 (unlimited) @end /**@}*/// End of In-Memory Cache ////////////////////////////////////////////////////////////////// /** @name Creating an In-Memory Cache */ /** * Initializes a newly allocated cache with the given capacity. * * @returns An in-memory cache initialized with the given capacity. * @fn NIMemoryCache::initWithCapacity: */ /** @name Storing Objects in the Cache */ /** * Stores an object in the cache. * * The object will be stored without an expiration date. The object will stay in the cache until * it's bumped out due to the cache's memory limit. * * @param object The object being stored in the cache. * @param name The name used as a key to store this object. * @fn NIMemoryCache::storeObject:withName: */ /** * Stores an object in the cache with an expiration date. * * If an object is stored with an expiration date that has already passed then the object will * not be stored in the cache and any existing object will be removed. The rationale behind this * is that the object would be removed from the cache the next time it was accessed anyway. * * @param object The object being stored in the cache. * @param name The name used as a key to store this object. * @param expirationDate A date after which this object is no longer valid in the cache. * @fn NIMemoryCache::storeObject:withName:expiresAfter: */ /** @name Removing Objects from the Cache */ /** * Removes an object from the cache with the given name. * * @param name The name used as a key to store this object. * @fn NIMemoryCache::removeObjectWithName: */ /** * Removes all objects from the cache with a given prefix. * * This method requires a scan of the cache entries. * * @param prefix Any object name that has this prefix will be removed from the cache. * @fn NIMemoryCache::removeAllObjectsWithPrefix: */ /** * Removes all objects from the cache, regardless of expiration dates. * * This will completely clear out the cache and all objects in the cache will be released. * * @fn NIMemoryCache::removeAllObjects */ /** @name Accessing Objects in the Cache */ /** * Retrieves an object from the cache. * * If the object has expired then the object will be removed from the cache and nil will be * returned. * * @returns The object stored in the cache. The object is retained and autoreleased to * ensure that it survives this run loop if you then remove it from the cache. * @fn NIMemoryCache::objectWithName: */ /** * Returns a Boolean value that indicates whether an object with the given name is present * in the cache. * * Does not update the access time of the object. * * If the object has expired then the object will be removed from the cache and NO will be * returned. * * @returns YES if an object with the given name is present in the cache and has not expired, * otherwise NO. * @fn NIMemoryCache::containsObjectWithName: */ /** * Returns the date that the object with the given name was last accessed. * * Does not update the access time of the object. * * If the object has expired then the object will be removed from the cache and nil will be * returned. * * @returns The last access date of the object if it exists and has not expired, nil * otherwise. * @fn NIMemoryCache::dateOfLastAccessWithName: */ /** * Retrieve the name of the object that was least recently used. * * This will not update the access time of the object. * * If the cache is empty, returns nil. * * @fn NIMemoryCache::nameOfLeastRecentlyUsedObject */ /** * Retrieve the key with the most fresh access. * * This will not update the access time of the object. * * If the cache is empty, returns nil. * * @fn NIMemoryCache::nameOfMostRecentlyUsedObject */ /** @name Reducing Memory Usage Explicitly */ /** * Removes all expired objects from the cache. * * Subclasses may add additional functionality to this implementation. * Subclasses should call super in order to prune expired objects. * * This will be called when <code>UIApplicationDidReceiveMemoryWarningNotification</code> * is posted. * * @fn NIMemoryCache::reduceMemoryUsage */ /** @name Querying an In-Memory Cache */ /** * Returns the number of objects currently in the cache. * * @returns The number of objects currently in the cache. * @fn NIMemoryCache::count */ /** * @name Subclassing * * The following methods are provided to aid in subclassing and are not meant to be * used externally. */ /** * An object is about to be stored in the cache. * * @param object The object that is about to be stored in the cache. * @param name The cache name for the object. * @param previousObject The object previously stored in the cache. This may be the * same as object. * @returns YES If object is allowed to be stored in the cache. * @fn NIMemoryCache::shouldSetObject:withName:previousObject: */ /** * This method is deprecated. Please use shouldSetObject:withName:previousObject: instead. * * @fn NIMemoryCache::willSetObject:withName:previousObject: */ /** * An object has been stored in the cache. * * @param object The object that was stored in the cache. * @param name The cache name for the object. * @fn NIMemoryCache::didSetObject:withName: */ /** * An object is about to be removed from the cache. * * @param object The object about to removed from the cache. * @param name The cache name for the object about to be removed. * @fn NIMemoryCache::willRemoveObject:withName: */ // NIImageMemoryCache /** @name Querying an In-Memory Image Cache */ /** * Returns the total number of pixels being stored in the cache. * * @returns The total number of pixels being stored in the cache. * @fn NIImageMemoryCache::numberOfPixels */ /** @name Setting the Maximum Number of Pixels */ /** * The maximum number of pixels this cache may ever store. * * Defaults to 0, which is special cased to represent an unlimited number of pixels. * * @returns The maximum number of pixels this cache may ever store. * @fn NIImageMemoryCache::maxNumberOfPixels */ /** * The maximum number of pixels this cache may store after a call to reduceMemoryUsage. * * Defaults to 0, which is special cased to represent an unlimited number of pixels. * * @returns The maximum number of pixels this cache may store after a call * to reduceMemoryUsage. * @fn NIImageMemoryCache::maxNumberOfPixelsUnderStress */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIInMemoryCache.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIInMemoryCache.h" #import "NIDebuggingTools.h" #import "NIPreprocessorMacros.h" #import <UIKit/UIKit.h> #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @interface NIMemoryCache() // Mapping from a name (usually a URL) to an internal object. @property (nonatomic, strong) NSMutableDictionary* cacheMap; // A linked list of least recently used cache objects. Most recently used is the tail. @property (nonatomic, strong) NSMutableOrderedSet* lruCacheObjects; @end /** * @brief A single cache item's information. * * Used in expiration calculations and for storing the actual cache object. */ @interface NIMemoryCacheInfo : NSObject /** * @brief The name used to store this object in the cache. */ @property (nonatomic, copy) NSString* name; /** * @brief The object stored in the cache. */ @property (nonatomic, strong) id object; /** * @brief The date after which the image is no longer valid and should be removed from the cache. */ @property (nonatomic, strong) NSDate* expirationDate; /** * @brief The last time this image was accessed. * * This property is updated every time the image is fetched from or stored into the cache. It * is used when the memory peak has been reached as a fast means of removing least-recently-used * images. When the memory limit is reached, we sort the cache based on the last access times and * then prune images until we're under the memory limit again. */ @property (nonatomic, strong) NSDate* lastAccessTime; /** * @brief Determine whether this cache entry has past its expiration date. * * @returns YES if an expiration date has been specified and the expiration date has been passed. * NO in all other cases. Notably if there is no expiration date then this object will * never expire. */ - (BOOL)hasExpired; @end @implementation NIMemoryCache - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (id)init { return [self initWithCapacity:0]; } - (id)initWithCapacity:(NSUInteger)capacity { if ((self = [super init])) { _cacheMap = [[NSMutableDictionary alloc] initWithCapacity:capacity]; _lruCacheObjects = [NSMutableOrderedSet orderedSet]; // Automatically reduce memory usage when we get a memory warning. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reduceMemoryUsage) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; } return self; } - (NSString *)description { return [NSString stringWithFormat: @"<%@" @" lruObjects: %@" @" cache map: %@" @">", [super description], self.lruCacheObjects, self.cacheMap]; } #pragma mark - Internal - (void)updateAccessTimeForInfo:(NIMemoryCacheInfo *)info { @synchronized(self) { NIDASSERT(nil != info); if (nil == info) { return; // COV_NF_LINE } info.lastAccessTime = [NSDate date]; [self.lruCacheObjects removeObject:info]; [self.lruCacheObjects addObject:info]; } } - (NIMemoryCacheInfo *)cacheInfoForName:(NSString *)name { NIMemoryCacheInfo* info; @synchronized(self) { info = self.cacheMap[name]; } return info; } - (void)setCacheInfo:(NIMemoryCacheInfo *)info forName:(NSString *)name { @synchronized(self) { NIDASSERT(nil != name); if (nil == name) { return; } // Storing in the cache counts as an access of the object, so we update the access time. [self updateAccessTimeForInfo:info]; id previousObject = [self cacheInfoForName:name].object; if ([self shouldSetObject:info.object withName:name previousObject:previousObject]) { self.cacheMap[name] = info; [self didSetObject:info.object withName:name]; } } } - (void)removeCacheInfoForName:(NSString *)name { @synchronized(self) { NIDASSERT(nil != name); if (nil == name) { return; } NIMemoryCacheInfo* cacheInfo = [self cacheInfoForName:name]; [self willRemoveObject:cacheInfo.object withName:name]; [self.lruCacheObjects removeObject:cacheInfo]; [self.cacheMap removeObjectForKey:name]; } } #pragma mark - Subclassing // Deprecated method. - (BOOL)willSetObject:(id)object withName:(NSString *)name previousObject:(id)previousObject { return [self shouldSetObject:object withName:name previousObject:previousObject]; } - (BOOL)shouldSetObject:(id)object withName:(NSString *)name previousObject:(id)previousObject { // Allow anything to be stored. return YES; } - (void)didSetObject:(id)object withName:(NSString *)name { // No-op } - (void)willRemoveObject:(id)object withName:(NSString *)name { // No-op } #pragma mark - Public - (void)storeObject:(id)object withName:(NSString *)name { @synchronized(self) { [self storeObject:object withName:name expiresAfter:nil]; } } - (void)storeObject:(id)object withName:(NSString *)name expiresAfter:(NSDate *)expirationDate { @synchronized(self) { // Don't store nil objects in the cache. if (nil == object) { return; } if (nil != expirationDate && [[NSDate date] timeIntervalSinceDate:expirationDate] >= 0) { // The object being stored is already expired so remove the object from the cache altogether. [self removeObjectWithName:name]; // We're done here. return; } NIMemoryCacheInfo* info = [self cacheInfoForName:name]; // Create a new cache entry. if (nil == info) { info = [[NIMemoryCacheInfo alloc] init]; info.name = name; } // Store the object in the cache item. info.object = object; // Override any existing expiration date. info.expirationDate = expirationDate; // Commit the changes to the cache. [self setCacheInfo:info forName:name]; } } - (id)objectWithName:(NSString *)name { @synchronized(self) { NIMemoryCacheInfo* info = [self cacheInfoForName:name]; id object = nil; if (nil != info) { if ([info hasExpired]) { [self removeObjectWithName:name]; } else { // Update the access time whenever we fetch an object from the cache. [self updateAccessTimeForInfo:info]; object = info.object; } } return object; } } - (BOOL)containsObjectWithName:(NSString *)name { @synchronized(self) { NIMemoryCacheInfo* info = [self cacheInfoForName:name]; if ([info hasExpired]) { [self removeObjectWithName:name]; return NO; } return (nil != info); } } - (NSDate *)dateOfLastAccessWithName:(NSString *)name { @synchronized(self) { NIMemoryCacheInfo* info = [self cacheInfoForName:name]; if ([info hasExpired]) { [self removeObjectWithName:name]; return nil; } return [info lastAccessTime]; } } - (NSString *)nameOfLeastRecentlyUsedObject { @synchronized(self) { NIMemoryCacheInfo* info = [self.lruCacheObjects firstObject]; if ([info hasExpired]) { [self removeObjectWithName:info.name]; return nil; } return info.name; } } - (NSString *)nameOfMostRecentlyUsedObject { @synchronized(self) { NIMemoryCacheInfo* info = [self.lruCacheObjects lastObject]; if ([info hasExpired]) { [self removeObjectWithName:info.name]; return nil; } return info.name; } } - (void)removeObjectWithName:(NSString *)name { @synchronized(self) { [self removeCacheInfoForName:name]; } } - (void)removeAllObjectsWithPrefix:(NSString *)prefix { @synchronized(self) { // Assertions fire if you try to modify the object you're iterating over, so we make a copy. for (NSString* name in [self.cacheMap copy]) { if ([name hasPrefix:prefix]) { [self removeObjectWithName:name]; } } } } - (void)removeAllObjects { @synchronized(self) { [self.cacheMap removeAllObjects]; [self.lruCacheObjects removeAllObjects]; } } - (void)reduceMemoryUsage { @synchronized(self) { // Assertions fire if you try to modify the object you're iterating over, so we make a copy. for (id name in [self.cacheMap copy]) { NIMemoryCacheInfo* info = [self cacheInfoForName:name]; if ([info hasExpired]) { [self removeCacheInfoForName:name]; } } } } - (NSUInteger)count { @synchronized(self) { return self.cacheMap.count; } } @end @implementation NIMemoryCacheInfo - (BOOL)hasExpired { return (nil != _expirationDate && [[NSDate date] timeIntervalSinceDate:_expirationDate] >= 0); } - (NSString *)description { return [NSString stringWithFormat: @"<%@" @" name: %@" @" object: %@" @" expiration date: %@" @" last access time: %@" @">", [super description], self.name, self.object, self.expirationDate, self.lastAccessTime]; } @end @interface NIImageMemoryCache() @property (nonatomic, assign) unsigned long long numberOfPixels; @end @implementation NIImageMemoryCache - (unsigned long long)numberOfPixelsUsedByImage:(UIImage *)image { @synchronized(self) { if (nil == image) { return 0; } return (unsigned long long)(image.size.width * image.size.height * [image scale] * [image scale]); } } - (void)removeAllObjects { @synchronized(self) { [super removeAllObjects]; self.numberOfPixels = 0; } } - (void)reduceMemoryUsage { @synchronized(self) { // Remove all expired images first. [super reduceMemoryUsage]; if (self.maxNumberOfPixelsUnderStress > 0) { // Remove the least recently used images by iterating over the linked list. while (self.numberOfPixels > self.maxNumberOfPixelsUnderStress) { NIMemoryCacheInfo* info = [self.lruCacheObjects firstObject]; [self removeCacheInfoForName:info.name]; } } } } - (BOOL)shouldSetObject:(id)object withName:(NSString *)name previousObject:(id)previousObject { @synchronized(self) { NIDASSERT(nil == object || [object isKindOfClass:[UIImage class]]); if (![object isKindOfClass:[UIImage class]]) { return NO; } _numberOfPixels -= [self numberOfPixelsUsedByImage:previousObject]; _numberOfPixels += [self numberOfPixelsUsedByImage:object]; return YES; } } - (void)didSetObject:(id)object withName:(NSString *)name { @synchronized(self) { // Reduce the cache size after the object has been set in case the cache size is smaller // than the object that's being added and we need to remove this object right away. if (self.maxNumberOfPixels > 0) { // Remove least recently used images until we satisfy our memory constraints. while (self.numberOfPixels > self.maxNumberOfPixels) { NIMemoryCacheInfo* info = [self.lruCacheObjects firstObject]; [self removeCacheInfoForName:info.name]; } } } } - (void)willRemoveObject:(id)object withName:(NSString *)name { @synchronized(self) { NIDASSERT(nil == object || [object isKindOfClass:[UIImage class]]); if (nil == object || ![object isKindOfClass:[UIImage class]]) { return; } self.numberOfPixels -= [self numberOfPixelsUsedByImage:object]; } } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NINavigationAppearance.h
C/C++ Header
// // Copyright 2011 Basil Shkara // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NIPreprocessorMacros.h" @class NINavigationAppearanceSnapshot; /** * The NINavigationAppearance provides support for saving and restoring the navigation appearance * state. * * This class is now deprecated due to the ease with which it may cause more problems than it * solves. It is recommended that instead of obfuscating navigation appearance by using this class * that you define and follow a standard practice of modifying navigation appearance throughout your * app that is more explicit. * * Use this when you are about to mutate the navigation bar style and/or status * bar style, and you want to be able to restore these bar styles sometime in the * future. * * An example of usage for this pattern is in NIToolbarPhotoViewController which * changes the navigation bar style to UIBarStyleBlack and the status bar style to * UIStatusBarStyleBlack* in viewWillAppear:. * * @code * [NINavigationAppearance pushAppearanceForNavigationController:self.navigationController] * * UINavigationBar* navBar = self.navigationController.navigationBar; * navBar.barStyle = UIBarStyleBlack; * navBar.translucent = YES; * @endcode * * Note that the call to NINavigationAppearance must occur before mutating any bar * states so that it is able to capture the original state correctly. * * Then when NIToolbarPhotoViewController is ready to restore the original navigation * appearance state, (in viewWillDisappear:), it calls the following: * * @code * [NINavigationAppearance popAppearanceForNavigationController:self.navigationController] * @endcode * * which pops the last snapshot of the stack and applies it, restoring the original * navigation appearance state. * * @ingroup NimbusCore */ __NI_DEPRECATED_METHOD @interface NINavigationAppearance : NSObject + (void)pushAppearanceForNavigationController:(UINavigationController *)navigationController; + (void)popAppearanceForNavigationController:(UINavigationController *)navigationController animated:(BOOL)animated; + (NSInteger)count; + (void)clear; @end /** * Take a snapshot of the current navigation appearance. * * Call this method before mutating the nav bar style or status bar style. * * @fn NINavigationAppearance::pushAppearanceForNavigationController: */ /** * Restore the last navigation appearance snapshot. * * Pops the last appearance values off the stack and applies them. * * @fn NINavigationAppearance::popAppearanceForNavigationController:animated: */ /** * Returns the number of items in the appearance stack. * * @fn NINavigationAppearance::count */ /** * Remove all navigation appearance snapshots from the stack. * * @fn NINavigationAppearance::clear */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NINavigationAppearance.m
Objective-C
// // Copyright 2011 Basil Shkara // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NINavigationAppearance.h" #import "NIDebuggingTools.h" #import "NISDKAvailability.h" #import "NIPreprocessorMacros.h" /* for weak */ #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static NSMutableArray* sAppearanceStack = nil; /** * @internal * Model class which captures and stores navigation appearance. * * Used in conjunction with NINavigationAppearance. * * @ingroup NimbusCore */ @interface NINavigationAppearanceSnapshot : NSObject { @private BOOL _navBarTranslucent; UIBarStyle _navBarStyle; UIStatusBarStyle _statusBarStyle; UIColor* _navBarTintColor; UIImage* _navBarDefaultImage; UIImage* _navBarLandscapePhoneImage; } /** * Holds value of UINavigationBar's translucent property. */ @property (nonatomic, readonly, assign) BOOL navBarTranslucent; /** * Holds value of UINavigationBar's barStyle property. */ @property (nonatomic, readonly, assign) UIBarStyle navBarStyle; /** * Holds value of UIApplication's statusBarStyle property. */ @property (nonatomic, readonly, assign) UIStatusBarStyle statusBarStyle; /** * Holds value of UINavigationBar's tintColor property. */ @property (nonatomic, readonly, strong) UIColor* navBarTintColor; /** * Holds value of UINavigationBar's UIBarMetricsDefault backgroundImage property. */ @property (nonatomic, readonly, strong) UIImage* navBarDefaultImage; /** * Holds value of UINavigationBar's UIBarMetricsLandscapePhone backgroundImage property. */ @property (nonatomic, readonly, strong) UIImage* navBarLandscapePhoneImage; /** * Create a new snapshot. */ - (id)initForNavigationController:(UINavigationController *)navigationController; /** * Apply the previously captured state. */ - (void)restoreForNavigationController:(UINavigationController *)navigationController animated:(BOOL)animated; @end @implementation NINavigationAppearance + (void)pushAppearanceForNavigationController:(UINavigationController *)navigationController { if (!sAppearanceStack) { sAppearanceStack = [[NSMutableArray alloc] init]; } NINavigationAppearanceSnapshot *snapshot = [[NINavigationAppearanceSnapshot alloc] initForNavigationController:navigationController]; [sAppearanceStack addObject:snapshot]; } + (void)popAppearanceForNavigationController:(UINavigationController *)navigationController animated:(BOOL)animated { NIDASSERT([sAppearanceStack count] > 0); if ([sAppearanceStack count]) { NINavigationAppearanceSnapshot *snapshot = [sAppearanceStack objectAtIndex:0]; [snapshot restoreForNavigationController:navigationController animated:animated]; [sAppearanceStack removeObject:snapshot]; } if (![sAppearanceStack count]) { sAppearanceStack = nil; } } + (NSInteger)count { return [sAppearanceStack count]; } + (void)clear { [sAppearanceStack removeAllObjects]; sAppearanceStack = nil; } @end @implementation NINavigationAppearanceSnapshot - (id)initForNavigationController:(UINavigationController *)navigationController { self = [super init]; if (self) { _statusBarStyle = [[UIApplication sharedApplication] statusBarStyle]; _navBarStyle = navigationController.navigationBar.barStyle; _navBarTranslucent = navigationController.navigationBar.translucent; _navBarTintColor = navigationController.navigationBar.tintColor; if ([navigationController.navigationBar respondsToSelector:@selector(backgroundImageForBarMetrics:)]) { _navBarDefaultImage = [navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault]; _navBarLandscapePhoneImage = [navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsLandscapePhone]; } } return self; } - (void)restoreForNavigationController:(UINavigationController *)navigationController animated:(BOOL)animated { [[UIApplication sharedApplication] setStatusBarStyle:self.statusBarStyle animated:animated]; navigationController.navigationBar.barStyle = self.navBarStyle; navigationController.navigationBar.translucent = self.navBarTranslucent; navigationController.navigationBar.tintColor = self.navBarTintColor; if ([navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) { [navigationController.navigationBar setBackgroundImage:self.navBarDefaultImage forBarMetrics:UIBarMetricsDefault]; [navigationController.navigationBar setBackgroundImage:self.navBarLandscapePhoneImage forBarMetrics:UIBarMetricsLandscapePhone]; } } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NINetworkActivity.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 July 2, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #if defined __cplusplus extern "C" { #endif /** * For showing network activity in the device's status bar. * * @ingroup NimbusCore * @defgroup Network-Activity Network Activity * @{ * * Two methods for keeping track of all active network tasks. These methods are threadsafe * and act as a simple counter. When the counter is positive, the network activity indicator * is displayed. */ /** * Increment the number of active network tasks. * * The status bar activity indicator will be spinning while there are active tasks. * * This method is threadsafe. */ void NINetworkActivityTaskDidStart(void); /** * Decrement the number of active network tasks. * * The status bar activity indicator will be spinning while there are active tasks. * * This method is threadsafe. */ void NINetworkActivityTaskDidFinish(void); /** * @name For Debugging Only * @{ * * Methods that will only do anything interesting if the DEBUG preprocessor macro is defined. */ /** * Enable network activity debugging. * * @attention This won't do anything unless the DEBUG preprocessor macro is defined. * * The Nimbus network activity methods will only work correctly if they are the only methods to * touch networkActivityIndicatorVisible. If you are using another library that touches * networkActivityIndicatorVisible then the network activity indicator might not accurately * represent its state. * * When enabled, the networkActivityIndicatorVisible method on UIApplication will be swizzled * with a debugging method that checks the global network task count and verifies that state * is maintained correctly. If it is found that networkActivityIndicatorVisible is being accessed * directly, then an assertion will be fired. * * If debugging was previously enabled, this does nothing. */ void NIEnableNetworkActivityDebugging(void); /** * Disable network activity debugging. * * @attention This won't do anything unless the DEBUG preprocessor macro is defined. * * When disabled, the networkActivityIndicatorVisible will be restored if this was previously * enabled, otherwise this method does nothing. * * If debugging wasn't previously enabled, this does nothing. */ void NIDisableNetworkActivityDebugging(void); /**@}*/// End of For Debugging Only #if defined __cplusplus }; #endif /**@}*/// End of Network Activity /////////////////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NINetworkActivity.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NINetworkActivity.h" #import "NIDebuggingTools.h" #if defined(DEBUG) || defined(NI_DEBUG) #import "NIRuntimeClassModifications.h" #endif #import <pthread.h> #import <UIKit/UIKit.h> #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static int gNetworkTaskCount = 0; static pthread_mutex_t gMutex = PTHREAD_MUTEX_INITIALIZER; static const NSTimeInterval kDelayBeforeDisablingActivity = 0.1; static NSTimer* gScheduledDelayTimer = nil; @interface NINetworkActivity : NSObject @end @implementation NINetworkActivity // Called after a certain amount of time has passed since all network activity has stopped. // By delaying the turnoff of the network activity we avoid "flickering" effects when network // activity is starting and stopping rapidly. + (void)disableNetworkActivity { pthread_mutex_lock(&gMutex); if (nil != gScheduledDelayTimer) { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; gScheduledDelayTimer = nil; } pthread_mutex_unlock(&gMutex); } @end void NINetworkActivityTaskDidStart(void) { pthread_mutex_lock(&gMutex); BOOL enableNetworkActivityIndicator = (0 == gNetworkTaskCount); ++gNetworkTaskCount; [gScheduledDelayTimer invalidate]; gScheduledDelayTimer = nil; if (enableNetworkActivityIndicator) { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; } pthread_mutex_unlock(&gMutex); } void NINetworkActivityTaskDidFinish(void) { pthread_mutex_lock(&gMutex); --gNetworkTaskCount; // If this asserts, you don't have enough stop requests to match your start requests. NIDASSERT(gNetworkTaskCount >= 0); gNetworkTaskCount = MAX(0, gNetworkTaskCount); if (gNetworkTaskCount == 0) { [gScheduledDelayTimer invalidate]; gScheduledDelayTimer = nil; // Ensure that the timer is scheduled on the main loop, otherwise it will die when the thread // dies. dispatch_async(dispatch_get_main_queue(), ^{ pthread_mutex_lock(&gMutex); gScheduledDelayTimer = [NSTimer scheduledTimerWithTimeInterval:kDelayBeforeDisablingActivity target:[NINetworkActivity class] selector:@selector(disableNetworkActivity) userInfo:nil repeats:NO]; pthread_mutex_unlock(&gMutex); }); } pthread_mutex_unlock(&gMutex); } #pragma mark - Network Activity Debugging #if defined(DEBUG) || defined(NI_DEBUG) static BOOL gNetworkActivityDebuggingEnabled = NO; void NISwizzleMethodsForNetworkActivityDebugging(void); @implementation UIApplication (NimbusNetworkActivityDebugging) - (void)nimbusDebugSetNetworkActivityIndicatorVisible:(BOOL)visible { // This method will only be used when swizzled, so this will actually call // setNetworkActivityIndicatorVisible: [self nimbusDebugSetNetworkActivityIndicatorVisible:visible]; // Sanity check that this method isn't being called directly when debugging isn't enabled. NIDASSERT(gNetworkActivityDebuggingEnabled); // If either of the following assertions fail then you should look at the call stack to // determine what code is erroneously calling setNetworkActivityIndicatorVisible: directly. if (visible) { // The only time we should be enabling the network activity indicator is when the task // count is one. NIDASSERT(1 == gNetworkTaskCount); } else { // The only time we should be disabling the network activity indicator is when the task // count is zero. NIDASSERT(0 == gNetworkTaskCount); } } @end void NISwizzleMethodsForNetworkActivityDebugging(void) { NISwapInstanceMethods([UIApplication class], @selector(setNetworkActivityIndicatorVisible:), @selector(nimbusDebugSetNetworkActivityIndicatorVisible:)); } void NIEnableNetworkActivityDebugging(void) { if (!gNetworkActivityDebuggingEnabled) { gNetworkActivityDebuggingEnabled = YES; NISwizzleMethodsForNetworkActivityDebugging(); } } void NIDisableNetworkActivityDebugging(void) { if (gNetworkActivityDebuggingEnabled) { gNetworkActivityDebuggingEnabled = NO; NISwizzleMethodsForNetworkActivityDebugging(); } } #else // #ifndef DEBUG void NIEnableNetworkActivityDebugging(void) { // No-op } void NIDisableNetworkActivityDebugging(void) { // No-op } #endif // #if defined(DEBUG) || defined(NI_DEBUG)
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NINonEmptyCollectionTesting.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #if defined __cplusplus extern "C" { #endif /** * For testing whether a collection is of a certain type and is non-empty. * * @ingroup NimbusCore * @defgroup Non-Empty-Collection-Testing Non-Empty Collection Testing * @{ * * Simply calling -count on an object may not yield the expected results when enumerating it if * certain assumptions are also made about the object's type. For example, if a JSON response * returns a dictionary when you expected an array, casting the result to an NSArray and * calling count will yield a positive value, but objectAtIndex: will crash the application. * These methods provide a safer check for non-emptiness of collections. */ /** * Tests if an object is a non-nil array which is not empty. */ BOOL NIIsArrayWithObjects(id object); /** * Tests if an object is a non-nil set which is not empty. */ BOOL NIIsSetWithObjects(id object); /** * Tests if an object is a non-nil string which is not empty. */ BOOL NIIsStringWithAnyText(id object); #if defined __cplusplus }; #endif /**@}*/// End of Non-Empty Collection Testing /////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NINonEmptyCollectionTesting.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NINonEmptyCollectionTesting.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif BOOL NIIsArrayWithObjects(id object) { return [object isKindOfClass:[NSArray class]] && [(NSArray*)object count] > 0; } BOOL NIIsSetWithObjects(id object) { return [object isKindOfClass:[NSSet class]] && [(NSSet*)object count] > 0; } BOOL NIIsStringWithAnyText(id object) { return [object isKindOfClass:[NSString class]] && [(NSString*)object length] > 0; }
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NINonRetainingCollections.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #if defined __cplusplus extern "C" { #endif /** * For collections that don't retain their objects. * * @ingroup NimbusCore * @defgroup Non-Retaining-Collections Non-Retaining Collections * @{ * * Non-retaining collections have historically been used when we needed more than one delegate * in an object. However, NSNotificationCenter is a much better solution for n > 1 delegates. * Using a non-retaining collection is dangerous, so if you must use one, use it with extreme care. * The danger primarily lies in the fact that by all appearances the collection should still * operate like a regular collection, so this might lead to a lot of developer error if the * developer assumes that the collection does, in fact, retain the object. */ /** * Creates a mutable array which does not retain references to the objects it contains. * * Typically used with arrays of delegates. */ NSMutableArray* NICreateNonRetainingMutableArray(void); /** * Creates a mutable dictionary which does not retain references to the values it contains. * * Typically used with dictionaries of delegates. */ NSMutableDictionary* NICreateNonRetainingMutableDictionary(void); /** * Creates a mutable set which does not retain references to the values it contains. * * Typically used with sets of delegates. */ NSMutableSet* NICreateNonRetainingMutableSet(void); #if defined __cplusplus }; #endif /**@}*/// End of Non-Retaining Collections ////////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NINonRetainingCollections.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 9, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NINonRetainingCollections.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NSMutableArray* NICreateNonRetainingMutableArray(void) { return (__bridge_transfer NSMutableArray *)CFArrayCreateMutable(nil, 0, nil); } NSMutableDictionary* NICreateNonRetainingMutableDictionary(void) { return (__bridge_transfer NSMutableDictionary *)CFDictionaryCreateMutable(nil, 0, nil, nil); } NSMutableSet* NICreateNonRetainingMutableSet(void) { return (__bridge_transfer NSMutableSet *)CFSetCreateMutable(nil, 0, nil); }
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIOperations+Subclassing.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // @interface NIOperation() @property (strong) NSError* lastError; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIOperations.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NIPreprocessorMacros.h" /* for weak */ @class NIOperation; typedef void (^NIOperationBlock)(NIOperation* operation); typedef void (^NIOperationDidFailBlock)(NIOperation* operation, NSError* error); /** * For writing code that runs concurrently. * * @ingroup NimbusCore * @defgroup Operations Operations * * This collection of NSOperation implementations is meant to provide a set of common * operations that might be used in an application to offload complex processing to a separate * thread. */ @protocol NIOperationDelegate; /** * A base implementation of an NSOperation that supports traditional delegation and blocks. * * <h2>Subclassing</h2> * * A subclass should call the operationDid* methods to notify the delegate on the main thread * of changes in the operation's state. Calling these methods will notify the delegate and the * blocks if provided. * * @ingroup Operations */ @interface NIOperation : NSOperation @property (weak) id<NIOperationDelegate> delegate; @property (readonly, strong) NSError* lastError; @property (assign) NSInteger tag; @property (copy) NIOperationBlock didStartBlock; @property (copy) NIOperationBlock didFinishBlock; @property (copy) NIOperationDidFailBlock didFailWithErrorBlock; @property (copy) NIOperationBlock willFinishBlock; - (void)didStart; - (void)didFinish; - (void)didFailWithError:(NSError *)error; - (void)willFinish; @end /** * The delegate protocol for an NIOperation. * * @ingroup Operations */ @protocol NIOperationDelegate <NSObject> @optional /** @name [NIOperationDelegate] State Changes */ /** The operation has started executing. */ - (void)nimbusOperationDidStart:(NIOperation *)operation; /** * The operation is about to complete successfully. * * This will not be called if the operation fails. * * This will be called from within the operation's runloop and must be thread safe. */ - (void)nimbusOperationWillFinish:(NIOperation *)operation; /** * The operation has completed successfully. * * This will not be called if the operation fails. */ - (void)nimbusOperationDidFinish:(NIOperation *)operation; /** * The operation failed in some way and has completed. * * operationDidFinish: will not be called. */ - (void)nimbusOperationDidFail:(NIOperation *)operation withError:(NSError *)error; @end // NIOperation /** @name Delegation */ /** * The delegate through which changes are notified for this operation. * * All delegate methods are performed on the main thread. * * @fn NIOperation::delegate */ /** @name Post-Operation Properties */ /** * The error last passed to the didFailWithError notification. * * @fn NIOperation::lastError */ /** @name Identification */ /** * A simple tagging mechanism for identifying operations. * * @fn NIOperation::tag */ /** @name Blocks */ /** * The operation has started executing. * * Performed on the main thread. * * @fn NIOperation::didStartBlock */ /** * The operation has completed successfully. * * This will not be called if the operation fails. * * Performed on the main thread. * * @fn NIOperation::didFinishBlock */ /** * The operation failed in some way and has completed. * * didFinishBlock will not be executed. * * Performed on the main thread. * * @fn NIOperation::didFailWithErrorBlock */ /** * The operation is about to complete successfully. * * This will not be called if the operation fails. * * Performed in the operation's thread. * * @fn NIOperation::willFinishBlock */ /** * @name Subclassing * * The following methods are provided to aid in subclassing and are not meant to be * used externally. */ /** * On the main thread, notify the delegate that the operation has begun. * * @fn NIOperation::didStart */ /** * On the main thread, notify the delegate that the operation has finished. * * @fn NIOperation::didFinish */ /** * On the main thread, notify the delegate that the operation has failed. * * @fn NIOperation::didFailWithError: */ /** * In the operation's thread, notify the delegate that the operation will finish successfully. * * @fn NIOperation::willFinish */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIOperations.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIOperations.h" #import "NIDebuggingTools.h" #import "NIPreprocessorMacros.h" #import "NIOperations+Subclassing.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @implementation NIOperation - (void)dealloc { // For an unknown reason these block objects are not released when the NIOperation is deallocated // with ARC enabled. _didStartBlock = nil; _didFinishBlock = nil; _didFailWithErrorBlock = nil; _willFinishBlock = nil; } #pragma mark - Initiate delegate notification from the NSOperation - (void)didStart { [self performSelectorOnMainThread:@selector(onMainThreadOperationDidStart) withObject:nil waitUntilDone:[NSThread isMainThread]]; } - (void)didFinish { [self performSelectorOnMainThread:@selector(onMainThreadOperationDidFinish) withObject:nil waitUntilDone:[NSThread isMainThread]]; } - (void)didFailWithError:(NSError *)error { self.lastError = error; [self performSelectorOnMainThread:@selector(onMainThreadOperationDidFailWithError:) withObject:error waitUntilDone:[NSThread isMainThread]]; } - (void)willFinish { if ([self.delegate respondsToSelector:@selector(nimbusOperationWillFinish:)]) { [self.delegate nimbusOperationWillFinish:self]; } if (nil != self.willFinishBlock) { self.willFinishBlock(self); } } #pragma mark - Main Thread - (void)onMainThreadOperationDidStart { // This method should only be called on the main thread. NIDASSERT([NSThread isMainThread]); if ([self.delegate respondsToSelector:@selector(nimbusOperationDidStart:)]) { [self.delegate nimbusOperationDidStart:self]; } if (nil != self.didStartBlock) { self.didStartBlock(self); } } - (void)onMainThreadOperationDidFinish { // This method should only be called on the main thread. NIDASSERT([NSThread isMainThread]); if ([self.delegate respondsToSelector:@selector(nimbusOperationDidFinish:)]) { [self.delegate nimbusOperationDidFinish:self]; } if (nil != self.didFinishBlock) { self.didFinishBlock(self); } } - (void)onMainThreadOperationDidFailWithError:(NSError *)error { // This method should only be called on the main thread. NIDASSERT([NSThread isMainThread]); if ([self.delegate respondsToSelector:@selector(nimbusOperationDidFail:withError:)]) { [self.delegate nimbusOperationDidFail:self withError:error]; } if (nil != self.didFailWithErrorBlock) { self.didFailWithErrorBlock(self, error); } } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIPaths.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #if defined __cplusplus extern "C" { #endif /** * For creating standard system paths. * * @ingroup NimbusCore * @defgroup Paths Paths * @{ */ /** * Create a path with the given bundle and the relative path appended. * * @param bundle The bundle to append relativePath to. If nil, [NSBundle mainBundle] * will be used. * @param relativePath The relative path to append to the bundle's path. * * @returns The bundle path concatenated with the given relative path. */ NSString* NIPathForBundleResource(NSBundle* bundle, NSString* relativePath); /** * Create a path with the documents directory and the relative path appended. * * @returns The documents path concatenated with the given relative path. */ NSString* NIPathForDocumentsResource(NSString* relativePath); /** * Create a path with the Library directory and the relative path appended. * * @returns The Library path concatenated with the given relative path. */ NSString* NIPathForLibraryResource(NSString* relativePath); /** * Create a path with the caches directory and the relative path appended. * * @returns The caches path concatenated with the given relative path. */ NSString* NIPathForCachesResource(NSString* relativePath); #if defined __cplusplus }; #endif /**@}*/// End of Paths ////////////////////////////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIPaths.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIPaths.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NSString* NIPathForBundleResource(NSBundle* bundle, NSString* relativePath) { NSString* resourcePath = [(nil == bundle ? [NSBundle mainBundle] : bundle) resourcePath]; return [resourcePath stringByAppendingPathComponent:relativePath]; } NSString* NIPathForDocumentsResource(NSString* relativePath) { static NSString* documentsPath = nil; if (nil == documentsPath) { NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); documentsPath = [dirs objectAtIndex:0]; } return [documentsPath stringByAppendingPathComponent:relativePath]; } NSString* NIPathForLibraryResource(NSString* relativePath) { static NSString* libraryPath = nil; if (nil == libraryPath) { NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); libraryPath = [dirs objectAtIndex:0]; } return [libraryPath stringByAppendingPathComponent:relativePath]; } NSString* NIPathForCachesResource(NSString* relativePath) { static NSString* cachesPath = nil; if (nil == cachesPath) { NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); cachesPath = [dirs objectAtIndex:0]; } return [cachesPath stringByAppendingPathComponent:relativePath]; }
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIPreprocessorMacros.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #pragma mark - Preprocessor Macros /** * Preprocessor macros are added to Nimbus with care. Macros hide functionality and are difficult * to debug, so most macros found in Nimbus are one-liners or compiler utilities. * * <h2>Creating Byte- and Hex-based Colors</h2> * * Nimbus provides the RGBCOLOR and RGBACOLOR macros for easily creating UIColor objects * with byte and hex values. * * <h3>Examples</h3> * @code UIColor* color = RGBCOLOR(255, 128, 64); // Fully opaque orange UIColor* color = RGBACOLOR(255, 128, 64, 0.5); // Orange with 50% transparency UIColor* color = RGBCOLOR(0xFF, 0x7A, 0x64); // Hexadecimal color @endcode * * <h3>Why it exists</h3> * * There is no easy way to create UIColor objects using 0 - 255 range values or hexadecimal. This * leads to code like this being written: * @code UIColor* color = [UIColor colorWithRed:128.f/255.0f green:64.f/255.0f blue:32.f/255.0f alpha:1] @endcode * * <h2>Avoid requiring the -all_load and -force_load flags</h2> * * Categories can introduce the need for the -all_load and -force_load because of the fact that * the application will not load these categories on startup without them. This is due to the way * Xcode deals with .m files that only contain categories: it doesn't load them without the * -all_load or -force_load flag specified. * * There is, however, a way to force Xcode into loading the category .m file. If you provide an * empty class implementation in the .m file then your app will pick up the category * implementation. * * Example in plain UIKit: * @code @interface BogusClass @end @implementation BogusClass @end @implementation UIViewController (MyCustomCategory) ... @end @endcode * * NI_FIX_CATEGORY_BUG is a Nimbus macro that you include in your category `.m` file to save you * the trouble of having to write a bogus class for every category. Just be sure that the name you * provide to the macro is unique across your project or you will encounter duplicate symbol errors * when linking. * @code NI_FIX_CATEGORY_BUG(UIViewController_MyCustomCategory); @implementation UIViewController (MyCustomCategory) ... @end @endcode * * @ingroup NimbusCore * @defgroup Preprocessor-Macros Preprocessor Macros * @{ */ /** * Mark a method or property as deprecated to the compiler. * * Any use of a deprecated method or property will flag a warning when compiling. * * Borrowed from Apple's AvailabiltyInternal.h header. * * @htmlonly * <pre> * __AVAILABILITY_INTERNAL_DEPRECATED __attribute__((deprecated)) * </pre> * @endhtmlonly */ #define __NI_DEPRECATED_METHOD __attribute__((deprecated)) /** * Force a category to be loaded when an app starts up. * * Add this macro before each category implementation, so we don't have to use * -all_load or -force_load to load object files from static libraries that only contain * categories and no classes. * See http://developer.apple.com/library/mac/#qa/qa2006/qa1490.html for more info. */ #define NI_FIX_CATEGORY_BUG(name) @interface NI_FIX_CATEGORY_BUG_##name : NSObject @end \ @implementation NI_FIX_CATEGORY_BUG_##name @end /** * Creates an opaque UIColor object from a byte-value color definition. */ #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1] /** * Creates a UIColor object from a byte-value color definition and alpha transparency. */ #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)] /**@}*/// End of Preprocessor Macros //////////////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIRuntimeClassModifications.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #if defined __cplusplus extern "C" { #endif /** * For modifying class implementations at runtime. * * @ingroup NimbusCore * @defgroup Runtime-Class-Modifications Runtime Class Modifications * @{ * * @attention Please use caution when modifying class implementations at runtime. * Apple is prone to rejecting apps for gratuitous use of method swapping. * In particular, avoid swapping any NSObject methods such as dealloc, init, * and retain/release on UIKit classes. * * See example: @link ExampleRuntimeDebugging.m Runtime Debugging with Method Swizzling@endlink */ /** * Swap two class instance method implementations. * * Use this method when you would like to replace an existing method implementation in a class * with your own implementation at runtime. In practice this is often used to replace the * implementations of UIKit classes where subclassing isn't an adequate solution. * * This will only work for methods declared with a -. * * After calling this method, any calls to originalSel will actually call newSel and vice versa. * * Uses method_exchangeImplementations to accomplish this. */ void NISwapInstanceMethods(Class cls, SEL originalSel, SEL newSel); /** * Swap two class method implementations. * * Use this method when you would like to replace an existing method implementation in a class * with your own implementation at runtime. In practice this is often used to replace the * implementations of UIKit classes where subclassing isn't an adequate solution. * * This will only work for methods declared with a +. * * After calling this method, any calls to originalSel will actually call newSel and vice versa. * * Uses method_exchangeImplementations to accomplish this. */ void NISwapClassMethods(Class cls, SEL originalSel, SEL newSel); #if defined __cplusplus }; #endif /**@}*/// End of Runtime Class Modifications //////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIRuntimeClassModifications.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIRuntimeClassModifications.h" #import <objc/runtime.h> #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif void NISwapInstanceMethods(Class cls, SEL originalSel, SEL newSel) { Method originalMethod = class_getInstanceMethod(cls, originalSel); Method newMethod = class_getInstanceMethod(cls, newSel); method_exchangeImplementations(originalMethod, newMethod); } void NISwapClassMethods(Class cls, SEL originalSel, SEL newSel) { Method originalMethod = class_getClassMethod(cls, originalSel); Method newMethod = class_getClassMethod(cls, newSel); method_exchangeImplementations(originalMethod, newMethod); }
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NISDKAvailability.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NIPreprocessorMacros.h" /** * For checking SDK feature availibility. * * @ingroup NimbusCore * @defgroup SDK-Availability SDK Availability * @{ * * NIIOS macros are defined in parallel to their __IPHONE_ counterparts as a consistently-defined * means of checking __IPHONE_OS_VERSION_MAX_ALLOWED. * * For example: * * @htmlonly * <pre> * #if __IPHONE_OS_VERSION_MAX_ALLOWED >= NIIOS_3_2 * // This code will only compile on versions >= iOS 3.2 * #endif * </pre> * @endhtmlonly */ /** * Released on July 11, 2008 */ #define NIIOS_2_0 20000 /** * Released on September 9, 2008 */ #define NIIOS_2_1 20100 /** * Released on November 21, 2008 */ #define NIIOS_2_2 20200 /** * Released on June 17, 2009 */ #define NIIOS_3_0 30000 /** * Released on September 9, 2009 */ #define NIIOS_3_1 30100 /** * Released on April 3, 2010 */ #define NIIOS_3_2 30200 /** * Released on June 21, 2010 */ #define NIIOS_4_0 40000 /** * Released on September 8, 2010 */ #define NIIOS_4_1 40100 /** * Released on November 22, 2010 */ #define NIIOS_4_2 40200 /** * Released on March 9, 2011 */ #define NIIOS_4_3 40300 /** * Released on October 12, 2011. */ #define NIIOS_5_0 50000 /** * Released on March 7, 2012. */ #define NIIOS_5_1 50100 /** * Released on September 19, 2012. */ #define NIIOS_6_0 60000 /** * Released on January 28, 2013. */ #define NIIOS_6_1 60100 /** * Released on September 18, 2013 */ #define NIIOS_7_0 70000 #ifndef kCFCoreFoundationVersionNumber_iPhoneOS_2_0 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_0 478.23 #endif #ifndef kCFCoreFoundationVersionNumber_iPhoneOS_2_1 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_1 478.26 #endif #ifndef kCFCoreFoundationVersionNumber_iPhoneOS_2_2 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_2 478.29 #endif #ifndef kCFCoreFoundationVersionNumber_iPhoneOS_3_0 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_0 478.47 #endif #ifndef kCFCoreFoundationVersionNumber_iPhoneOS_3_1 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_1 478.52 #endif #ifndef kCFCoreFoundationVersionNumber_iPhoneOS_3_2 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_2 478.61 #endif #ifndef kCFCoreFoundationVersionNumber_iOS_4_0 #define kCFCoreFoundationVersionNumber_iOS_4_0 550.32 #endif #ifndef kCFCoreFoundationVersionNumber_iOS_4_1 #define kCFCoreFoundationVersionNumber_iOS_4_1 550.38 #endif #ifndef kCFCoreFoundationVersionNumber_iOS_4_2 #define kCFCoreFoundationVersionNumber_iOS_4_2 550.52 #endif #ifndef kCFCoreFoundationVersionNumber_iOS_4_3 #define kCFCoreFoundationVersionNumber_iOS_4_3 550.52 #endif #ifndef kCFCoreFoundationVersionNumber_iOS_5_0 #define kCFCoreFoundationVersionNumber_iOS_5_0 675.00 #endif #ifndef kCFCoreFoundationVersionNumber_iOS_5_1 #define kCFCoreFoundationVersionNumber_iOS_5_1 690.10 #endif #ifndef kCFCoreFoundationVersionNumber_iOS_6_0 #define kCFCoreFoundationVersionNumber_iOS_6_0 793.00 #endif #ifndef kCFCoreFoundationVersionNumber_iOS_6_1 #define kCFCoreFoundationVersionNumber_iOS_6_1 793.00 #endif #if __cplusplus extern "C" { #endif /** * Checks whether the device the app is currently running on is an iPad or not. * * @returns YES if the device is an iPad. */ BOOL NIIsPad(void); /** * Checks whether the device the app is currently running on is an * iPhone/iPod touch or not. * * @returns YES if the device is an iPhone or iPod touch. */ BOOL NIIsPhone(void); /** * Checks whether the device supports tint colors on all UIViews. * * @returns YES if all UIView instances on the device respond to tintColor. */ BOOL NIIsTintColorGloballySupported(void); /** * Checks whether the device's OS version is at least the given version number. * * Useful for runtime checks of the device's version number. * * @param versionNumber Any value of kCFCoreFoundationVersionNumber. * * @attention Apple recommends using respondsToSelector where possible to check for * feature support. Use this method as a last resort. */ BOOL NIDeviceOSVersionIsAtLeast(double versionNumber); /** * Fetch the screen's scale. */ CGFloat NIScreenScale(void); /** * Returns YES if the screen is a retina display, NO otherwise. */ BOOL NIIsRetina(void); /** * This method is now deprecated. Use [UIPopoverController class] instead. * * MAINTENANCE: Remove by Feb 28, 2014. */ Class NIUIPopoverControllerClass(void) __NI_DEPRECATED_METHOD; /** * This method is now deprecated. Use [UITapGestureRecognizer class] instead. * * MAINTENANCE: Remove by Feb 28, 2014. */ Class NIUITapGestureRecognizerClass(void) __NI_DEPRECATED_METHOD; #if __cplusplus } // extern "C" #endif #pragma mark Building with Old SDKs // Define methods that were introduced in iOS 7.0. #if __IPHONE_OS_VERSION_MAX_ALLOWED < NIIOS_7_0 @interface UIViewController (Nimbus7SDKAvailability) @property (nonatomic, assign) UIRectEdge edgesForExtendedLayout; - (void)setNeedsStatusBarAppearanceUpdate; @end #endif /**@}*/// End of SDK Availability /////////////////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NISDKAvailability.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif #if __IPHONE_OS_VERSION_MAX_ALLOWED < NIIOS_6_0 const UIImageResizingMode UIImageResizingModeStretch = -1; #endif BOOL NIIsPad(void) { static NSInteger isPad = -1; if (isPad < 0) { isPad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) ? 1 : 0; } return isPad > 0; } BOOL NIIsPhone(void) { static NSInteger isPhone = -1; if (isPhone < 0) { isPhone = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) ? 1 : 0; } return isPhone > 0; } BOOL NIIsTintColorGloballySupported(void) { static NSInteger isTintColorGloballySupported = -1; if (isTintColorGloballySupported < 0) { UIView* view = [[UIView alloc] init]; isTintColorGloballySupported = [view respondsToSelector:@selector(tintColor)]; } return isTintColorGloballySupported > 0; } BOOL NIDeviceOSVersionIsAtLeast(double versionNumber) { return kCFCoreFoundationVersionNumber >= versionNumber; } CGFloat NIScreenScale(void) { return [[UIScreen mainScreen] scale]; } BOOL NIIsRetina(void) { return NIScreenScale() == 2.f; } Class NIUIPopoverControllerClass(void) { return [UIPopoverController class]; } Class NIUITapGestureRecognizerClass(void) { return [UITapGestureRecognizer class]; }
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NISnapshotRotation.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> /** * An object designed to easily implement snapshot rotation. * * Snapshot rotation involves taking two screenshots of a UIView: the "before" and the "after" * state of the rotation. These two images are then cross-faded during the rotation, creating an * animation that minimizes visual artifacts that would otherwise be noticed when rotation occurs. * * This feature will only function on iOS 6.0 and higher. On older iOS versions the view will rotate * just as it always has. * * This functionality has been adopted from WWDC 2012 session 240 "Polishing Your Interface * Rotations". * * @ingroup NimbusCore * @defgroup Snapshot-Rotation Snapshot Rotation * @{ */ @protocol NISnapshotRotationDelegate; /** * The NISnapshotRotation class provides support for implementing snapshot-based rotations on views. * * You must call this object's rotation methods from your controller in order for the rotation * object to implement the rotation animations correctly. */ @interface NISnapshotRotation : NSObject // Designated initializer. - (id)initWithDelegate:(id<NISnapshotRotationDelegate>)delegate; @property (nonatomic, weak) id<NISnapshotRotationDelegate> delegate; @property (nonatomic, readonly, assign) CGRect frameBeforeRotation; @property (nonatomic, readonly, assign) CGRect frameAfterRotation; - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; @end /** * The NITableViewSnapshotRotation class implements the fixedInsetsForSnapshotRotation: delegate * method and forwards all other delegate methods along. * * If you are rotating a UITableView you can instantiate a NITableViewSnapshotRotation object and * use it just like you would a snapshot rotation object. The NITableViewSnapshotRotation class * intercepts the fixedInsetsForSnapshotRotation: method and returns insets that map to the * dimensions of the content view for the first visible cell in the table view. * * The assigned delegate only needs to implement containerViewForSnapshotRotation: and * rotatingViewForSnapshotRotation:. */ @interface NITableViewSnapshotRotation : NISnapshotRotation @end /** * The methods declared by the NISnapshotRotation protocol allow the adopting delegate to respond to * messages from the NISnapshotRotation class and thus implement snapshot rotations. */ @protocol NISnapshotRotationDelegate <NSObject> @required /** @name Accessing Rotation Views */ /** * Tells the delegate to return the container view of the rotating view. * * This is often the controller's self.view. This view must not be the same as the rotatingView and * rotatingView must be in the subview tree of containerView. * * @sa NISnapshotRotation::rotatingViewForSnapshotRotation: */ - (UIView *)containerViewForSnapshotRotation:(NISnapshotRotation *)snapshotRotation; /** * Tells the delegate to return the rotating view. * * The rotating view is the view that will be snapshotted during the rotation. * * This view must not be the same as the containerView and must be in the subview tree of * containerView. * * @sa NISnapshotRotation::containerViewForSnapshotRotation: */ - (UIView *)rotatingViewForSnapshotRotation:(NISnapshotRotation *)snapshotRotation; @optional /** @name Configuring Fixed Insets */ /** * Asks the delegate to return the insets of the rotating view that should be fixed during rotation. * * This method will only be called on iOS 6.0 and higher. * * The returned insets will denote which parts of the snapshotted images will not stretch during * the rotation animation. */ - (UIEdgeInsets)fixedInsetsForSnapshotRotation:(NISnapshotRotation *)snapshotRotation; @end #if defined __cplusplus extern "C" { #endif /** * Returns an opaque UIImage snapshot of the given view. * * This method takes into account the offset of scrollable views and captures whatever is currently * in the frame of the view. * * @param view A snapshot will be taken of this view. * @returns A UIImage with the snapshot of @c view. */ UIImage* NISnapshotOfView(UIView* view); /** * Returns a UIImageView with an image snapshot of the given view. * * The frame of the returned view is set to match the frame of @c view. * * @param view A snapshot will be taken of this view. * @returns A UIImageView with the snapshot of @c view and matching frame. */ UIImageView* NISnapshotViewOfView(UIView* view); /** * Returns a UIImage snapshot of the given view with transparency. * * This method takes into account the offset of scrollable views and captures whatever is currently * in the frame of the view. * * @param view A snapshot will be taken of this view. * @returns A UIImage with the snapshot of @c view. */ UIImage* NISnapshotOfViewWithTransparency(UIView* view); /** * Returns a UIImageView with an image snapshot with transparency of the given view. * * The frame of the returned view is set to match the frame of @c view. * * @param view A snapshot will be taken of this view. * @returns A UIImageView with the snapshot of @c view and matching frame. */ UIImageView* NISnapshotViewOfViewWithTransparency(UIView* view); #if defined __cplusplus } #endif /** * @} */ /** @name Creating a Snapshot Rotation Object */ /** * Initializes a newly allocated rotation object with a given delegate. * * @param delegate A delegate that implements the NISnapshotRotation protocol. * @returns A NISnapshotRotation object initialized with @c delegate. * @fn NISnapshotRotation::initWithDelegate: */ /** @name Accessing the Delegate */ /** * The delegate of the snapshot rotation object. * * The delegate must adopt the NISnapshotRotation protocol. The NISnapshotRotation class, which does * not retain the delegate, invokes each protocol method the delegate implements. * * @fn NISnapshotRotation::delegate */ /** @name Implementing UIViewController Autorotation */ /** * Prepares the animation for a rotation by taking a snapshot of the rotatingView in its current * state. * * This method must be called from your UIViewController implementation. * * @fn NISnapshotRotation::willRotateToInterfaceOrientation:duration: */ /** * Crossfades between the initial and final snapshots. * * This method must be called from your UIViewController implementation. * * @fn NISnapshotRotation::willAnimateRotationToInterfaceOrientation:duration: */ /** * Finalizes the rotation animation by removing the snapshot views from the container view. * * This method must be called from your UIViewController implementation. * * @fn NISnapshotRotation::didRotateFromInterfaceOrientation: */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NISnapshotRotation.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // This code was originally found in Apple's WWDC Session 240 on // "Polishing Your Interface Rotations" and has been repurposed into a reusable class. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NISnapshotRotation.h" #import "NIDebuggingTools.h" #import "NISDKAvailability.h" #import <QuartzCore/QuartzCore.h> #import <objc/runtime.h> #if __IPHONE_OS_VERSION_MIN_REQUIRED < NIIOS_6_0 #error "Nimbus Snapshot Rotation requires iOS 6 or higher." #endif UIImage* NISnapshotOfViewWithTransparencyOption(UIView* view, BOOL transparency); UIImage* NISnapshotOfViewWithTransparencyOption(UIView* view, BOOL transparency) { // Passing 0 as the last argument ensures that the image context will match the current device's // scaling mode. UIGraphicsBeginImageContextWithOptions(view.bounds.size, !transparency, 0); CGContextRef cx = UIGraphicsGetCurrentContext(); // Views that can scroll do so by modifying their bounds. We want to capture the part of the view // that is currently in the frame, so we offset by the bounds of the view accordingly. CGContextTranslateCTM(cx, -view.bounds.origin.x, -view.bounds.origin.y); [view.layer renderInContext:cx]; UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } UIImage* NISnapshotOfView(UIView* view) { return NISnapshotOfViewWithTransparencyOption(view, NO); } UIImageView* NISnapshotViewOfView(UIView* view) { UIImage* image = NISnapshotOfView(view); UIImageView* snapshotView = [[UIImageView alloc] initWithImage:image]; snapshotView.frame = view.frame; return snapshotView; } UIImage* NISnapshotOfViewWithTransparency(UIView* view) { return NISnapshotOfViewWithTransparencyOption(view, YES); } UIImageView* NISnapshotViewOfViewWithTransparency(UIView* view) { UIImage* image = NISnapshotOfViewWithTransparency(view); UIImageView* snapshotView = [[UIImageView alloc] initWithImage:image]; snapshotView.frame = view.frame; return snapshotView; } @interface NISnapshotRotation() @property (nonatomic, assign) BOOL isSupportedOS; @property (nonatomic, assign) CGRect frameBeforeRotation; @property (nonatomic, assign) CGRect frameAfterRotation; @property (nonatomic, strong) UIImageView* snapshotViewBeforeRotation; @property (nonatomic, strong) UIImageView* snapshotViewAfterRotation; @end @implementation NISnapshotRotation - (id)initWithDelegate:(id<NISnapshotRotationDelegate>)delegate { if ((self = [super init])) { _delegate = delegate; // Check whether this feature is supported or not. UIImage* image = [[UIImage alloc] init]; _isSupportedOS = [image respondsToSelector:@selector(resizableImageWithCapInsets:resizingMode:)]; } return self; } - (id)init { return [self initWithDelegate:nil]; } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (!self.isSupportedOS) { return; } UIView* containerView = [self.delegate containerViewForSnapshotRotation:self]; UIView* rotationView = [self.delegate rotatingViewForSnapshotRotation:self]; // The container view must not be the same as the rotation view. NIDASSERT(containerView != rotationView); if (containerView == rotationView) { return; } self.frameBeforeRotation = rotationView.frame; self.snapshotViewBeforeRotation = NISnapshotViewOfView(rotationView); [containerView insertSubview:self.snapshotViewBeforeRotation aboveSubview:rotationView]; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (!self.isSupportedOS) { return; } UIView* containerView = [self.delegate containerViewForSnapshotRotation:self]; UIView* rotationView = [self.delegate rotatingViewForSnapshotRotation:self]; // The container view must not be the same as the rotation view. NIDASSERT(containerView != rotationView); if (containerView == rotationView) { return; } self.frameAfterRotation = rotationView.frame; [UIView setAnimationsEnabled:NO]; self.snapshotViewAfterRotation = NISnapshotViewOfView(rotationView); // Set the new frame while maintaining the old frame's height. self.snapshotViewAfterRotation.frame = CGRectMake(self.frameBeforeRotation.origin.x, self.frameBeforeRotation.origin.y, self.frameBeforeRotation.size.width, self.snapshotViewAfterRotation.frame.size.height); UIImage* imageBeforeRotation = self.snapshotViewBeforeRotation.image; UIImage* imageAfterRotation = self.snapshotViewAfterRotation.image; if ([self.delegate respondsToSelector:@selector(fixedInsetsForSnapshotRotation:)]) { UIEdgeInsets fixedInsets = [self.delegate fixedInsetsForSnapshotRotation:self]; imageBeforeRotation = [imageBeforeRotation resizableImageWithCapInsets:fixedInsets resizingMode:UIImageResizingModeStretch]; imageAfterRotation = [imageAfterRotation resizableImageWithCapInsets:fixedInsets resizingMode:UIImageResizingModeStretch]; } self.snapshotViewBeforeRotation.image = imageBeforeRotation; self.snapshotViewAfterRotation.image = imageAfterRotation; [UIView setAnimationsEnabled:YES]; if (imageAfterRotation.size.height < imageBeforeRotation.size.height) { self.snapshotViewAfterRotation.alpha = 0; [containerView insertSubview:self.snapshotViewAfterRotation aboveSubview:self.snapshotViewBeforeRotation]; self.snapshotViewAfterRotation.alpha = 1; } else { [containerView insertSubview:self.snapshotViewAfterRotation belowSubview:self.snapshotViewBeforeRotation]; self.snapshotViewBeforeRotation.alpha = 0; } self.snapshotViewAfterRotation.frame = self.frameAfterRotation; self.snapshotViewBeforeRotation.frame = CGRectMake(self.frameAfterRotation.origin.x, self.frameAfterRotation.origin.y, self.frameAfterRotation.size.width, self.snapshotViewBeforeRotation.frame.size.height); rotationView.hidden = YES; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { if (!self.isSupportedOS) { return; } UIView* containerView = [self.delegate containerViewForSnapshotRotation:self]; UIView* rotationView = [self.delegate rotatingViewForSnapshotRotation:self]; // The container view must not be the same as the rotation view. NIDASSERT(containerView != rotationView); if (containerView == rotationView) { return; } [self.snapshotViewBeforeRotation removeFromSuperview]; [self.snapshotViewAfterRotation removeFromSuperview]; self.snapshotViewBeforeRotation = nil; self.snapshotViewAfterRotation = nil; rotationView.hidden = NO; } @end @interface NITableViewSnapshotRotation() <NISnapshotRotationDelegate> @property (nonatomic, weak) id<NISnapshotRotationDelegate> forwardingDelegate; @end @implementation NITableViewSnapshotRotation - (void)setDelegate:(id<NISnapshotRotationDelegate>)delegate { if (delegate == self) { [super setDelegate:delegate]; } else { self.forwardingDelegate = delegate; } } - (id)init { if ((self = [super init])) { self.delegate = self; } return self; } #pragma mark - Forward Invocations - (BOOL)shouldForwardSelectorToDelegate:(SEL)selector { struct objc_method_description description; // Only forward the selector if it's part of the protocol. description = protocol_getMethodDescription(@protocol(NISnapshotRotationDelegate), selector, NO, YES); BOOL isSelectorInProtocol = (description.name != NULL && description.types != NULL); return (isSelectorInProtocol && [self.forwardingDelegate respondsToSelector:selector]); } - (BOOL)respondsToSelector:(SEL)selector { if ([super respondsToSelector:selector] == YES) { return YES; } else { return [self shouldForwardSelectorToDelegate:selector]; } } - (id)forwardingTargetForSelector:(SEL)selector { if ([self shouldForwardSelectorToDelegate:selector]) { return self.forwardingDelegate; } else { return nil; } } #pragma mark - NISnapshotRotation - (UIView *)containerViewForSnapshotRotation:(NISnapshotRotation *)snapshotRotation { return [self.forwardingDelegate containerViewForSnapshotRotation:snapshotRotation]; } - (UIView *)rotatingViewForSnapshotRotation:(NISnapshotRotation *)snapshotRotation { return [self.forwardingDelegate rotatingViewForSnapshotRotation:snapshotRotation]; } - (UIEdgeInsets)fixedInsetsForSnapshotRotation:(NISnapshotRotation *)snapshotRotation { UIEdgeInsets insets = UIEdgeInsetsZero; // Find the right edge of the content view in the coordinate space of the UITableView. UIView* rotatingView = [self.forwardingDelegate rotatingViewForSnapshotRotation:snapshotRotation]; NIDASSERT([rotatingView isKindOfClass:[UITableView class]]); if ([rotatingView isKindOfClass:[UITableView class]]) { UITableView* tableView = (UITableView *)rotatingView; NSArray* visibleCells = tableView.visibleCells; if (visibleCells.count > 0) { UIView* contentView = [[visibleCells objectAtIndex:0] contentView]; CGFloat contentViewRightEdge = [tableView convertPoint:CGPointMake(contentView.bounds.size.width, 0) fromView:contentView].x; CGFloat fixedRightWidth = tableView.bounds.size.width - contentViewRightEdge; CGFloat fixedLeftWidth = MIN(snapshotRotation.frameAfterRotation.size.width, snapshotRotation.frameBeforeRotation.size.width) - fixedRightWidth - 1; insets = UIEdgeInsetsMake(0, fixedLeftWidth, 0, fixedRightWidth); } } return insets; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIState.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> @class NIImageMemoryCache; /** * For modifying Nimbus state information. * * @ingroup NimbusCore * @defgroup Core-State State * @{ * * The Nimbus core provides a common layer of features used by nearly all of the libraries in * the Nimbus ecosystem. Here you will find methods for accessing and setting the global image * cache amongst other things. */ /** * The Nimbus state interface. * * @ingroup Core-State */ @interface Nimbus : NSObject #pragma mark Accessing Global State /** @name Accessing Global State */ /** * Access the global image memory cache. * * If a cache hasn't been assigned via Nimbus::setGlobalImageMemoryCache: then one will be created * automatically. * * @remarks The default image cache has no upper limit on its memory consumption. It is * up to you to specify an upper limit in your application. */ + (NIImageMemoryCache *)imageMemoryCache; /** * Access the global network operation queue. * * The global network operation queue exists to be used for asynchronous network requests if * you choose. By defining a global operation queue in the core of Nimbus, we can ensure that * all libraries that depend on core will use the same network operation queue unless configured * otherwise. * * If an operation queue hasn't been assigned via Nimbus::setGlobalNetworkOperationQueue: then * one will be created automatically with the default iOS settings. */ + (NSOperationQueue *)networkOperationQueue; #pragma mark Modifying Global State /** @name Modifying Global State */ /** * Set the global image memory cache. * * The cache will be retained and the old cache released. */ + (void)setImageMemoryCache:(NIImageMemoryCache *)imageMemoryCache; /** * Set the global network operation queue. * * The queue will be retained and the old queue released. */ + (void)setNetworkOperationQueue:(NSOperationQueue *)queue; @end /**@}*/// End of State ////////////////////////////////////////////////////////////////////////////
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIState.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIState.h" #import "NIInMemoryCache.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static NIImageMemoryCache* sNimbusGlobalMemoryCache = nil; static NSOperationQueue* sNimbusGlobalOperationQueue = nil; @implementation Nimbus + (void)setImageMemoryCache:(NIImageMemoryCache *)imageMemoryCache { if (sNimbusGlobalMemoryCache != imageMemoryCache) { sNimbusGlobalMemoryCache = nil; sNimbusGlobalMemoryCache = imageMemoryCache; } } + (NIImageMemoryCache *)imageMemoryCache { if (nil == sNimbusGlobalMemoryCache) { sNimbusGlobalMemoryCache = [[NIImageMemoryCache alloc] init]; } return sNimbusGlobalMemoryCache; } + (void)setNetworkOperationQueue:(NSOperationQueue *)queue { if (sNimbusGlobalOperationQueue != queue) { sNimbusGlobalOperationQueue = nil; sNimbusGlobalOperationQueue = queue; } } + (NSOperationQueue *)networkOperationQueue { if (nil == sNimbusGlobalOperationQueue) { sNimbusGlobalOperationQueue = [[NSOperationQueue alloc] init]; } return sNimbusGlobalOperationQueue; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIViewRecycler.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> /** * For recycling views in scroll views. * * @ingroup NimbusCore * @defgroup Core-View-Recycling View Recyling * @{ * * View recycling is an important aspect of iOS memory management and performance when building * scroll views. UITableView uses view recycling via the table cell dequeue mechanism. * NIViewRecycler implements this recycling functionality, allowing you to implement recycling * mechanisms in your own views and controllers. * * * <h2>Example Use</h2> * * Imagine building a UITableView. We'll assume that a viewRecycler object exists in the view. * * Views are usually recycled once they are no longer on screen, so within a did scroll event * we might have code like the following: * @code for (UIView<NIRecyclableView>* view in visibleViews) { if (![self isVisible:view]) { [viewRecycler recycleView:view]; [view removeFromSuperview]; } } @endcode * * This will take the views that are no longer visible and add them to the recycler. At a later * point in that same didScroll code we will check if there are any new views that are visible. * This is when we try to dequeue a recycled view from the recycler. * @code UIView<NIRecyclableView>* view = [viewRecycler dequeueReusableViewWithIdentifier:reuseIdentifier]; if (nil == view) { // Allocate a new view that conforms to the NIRecyclableView protocol. view = [[[...]] autorelease]; } [self addSubview:view]; @endcode * */ @protocol NIRecyclableView; /** * An object for efficiently reusing views by recycling and dequeuing them from a pool of views. * * This sort of object is likely what UITableView and NIPagingScrollView use to recycle their views. */ @interface NIViewRecycler : NSObject - (UIView<NIRecyclableView> *)dequeueReusableViewWithIdentifier:(NSString *)reuseIdentifier; - (void)recycleView:(UIView<NIRecyclableView> *)view; - (void)removeAllViews; @end /** * The NIRecyclableView protocol defines a set of optional methods that a view may implement to * handle being added to a NIViewRecycler. */ @protocol NIRecyclableView <NSObject> @optional /** * The identifier used to categorize views into buckets for reuse. * * Views will be reused when a new view is requested with a matching identifier. * * If the reuseIdentifier is nil then the class name will be used. */ @property (nonatomic, copy) NSString* reuseIdentifier; /** * Called immediately after the view has been dequeued from the recycled view pool. */ - (void)prepareForReuse; @end /** * A simple implementation of the NIRecyclableView protocol as a UIView. * * This class can be used as a base class for building recyclable views if specific reuse * identifiers are necessary, e.g. when the same class might have different implementations * depending on the reuse identifier. * * Assuming functionality is consistent for a given class it is simpler not to have a * reuseIdentifier, making the view recycler use the class name as the reuseIdentifier. In this case * subclassing this class is overkill. */ @interface NIRecyclableView : UIView <NIRecyclableView> // Designated initializer. - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier; @property (nonatomic, copy) NSString* reuseIdentifier; @end /**@}*/ // End of View Recyling /** * Dequeues a reusable view from the recycled views pool if one exists, otherwise returns nil. * * @fn NIViewRecycler::dequeueReusableViewWithIdentifier: * @param reuseIdentifier Often the name of the class of view you wish to fetch. */ /** * Adds a given view to the recycled views pool. * * @fn NIViewRecycler::recycleView: * @param view The view to recycle. The reuse identifier will be retrieved from the view * via the NIRecyclableView protocol. */ /** * Removes all of the views from the recycled views pool. * * @fn NIViewRecycler::removeAllViews */ /** * Initializes a newly allocated view with the given reuse identifier. * * This is the designated initializer. * * @fn NIRecyclableView::initWithReuseIdentifier: * @param reuseIdentifier The identifier that will be used to group this view in the view * recycler. */ /** * This view's reuse identifier. * * Used by NIViewRecycler to pool this view into a group of similar recycled views. * * @fn NIRecyclableView::reuseIdentifier */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NIViewRecycler.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIViewRecycler.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @interface NIViewRecycler() @property (nonatomic, strong) NSMutableDictionary* reuseIdentifiersToRecycledViews; @end @implementation NIViewRecycler - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (id)init { if ((self = [super init])) { _reuseIdentifiersToRecycledViews = [[NSMutableDictionary alloc] init]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(reduceMemoryUsage) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; } return self; } #pragma mark - Memory Warnings - (void)reduceMemoryUsage { [self removeAllViews]; } #pragma mark - Public - (UIView<NIRecyclableView> *)dequeueReusableViewWithIdentifier:(NSString *)reuseIdentifier { NSMutableArray* views = [_reuseIdentifiersToRecycledViews objectForKey:reuseIdentifier]; UIView<NIRecyclableView>* view = [views lastObject]; if (nil != view) { [views removeLastObject]; if ([view respondsToSelector:@selector(prepareForReuse)]) { [view prepareForReuse]; } } return view; } - (void)recycleView:(UIView<NIRecyclableView> *)view { NIDASSERT([view isKindOfClass:[UIView class]]); NSString* reuseIdentifier = nil; if ([view respondsToSelector:@selector(reuseIdentifier)]) { reuseIdentifier = [view reuseIdentifier];; } if (nil == reuseIdentifier) { reuseIdentifier = NSStringFromClass([view class]); } NIDASSERT(nil != reuseIdentifier); if (nil == reuseIdentifier) { return; } NSMutableArray* views = [_reuseIdentifiersToRecycledViews objectForKey:reuseIdentifier]; if (nil == views) { views = [[NSMutableArray alloc] init]; [_reuseIdentifiersToRecycledViews setObject:views forKey:reuseIdentifier]; } [views addObject:view]; } - (void)removeAllViews { [_reuseIdentifiersToRecycledViews removeAllObjects]; } @end @implementation NIRecyclableView - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithFrame:CGRectZero])) { _reuseIdentifier = reuseIdentifier; } return self; } - (id)initWithFrame:(CGRect)frame { return [self initWithReuseIdentifier:nil]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NimbusCore+Additions.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // All category documentation is found in the source files due to limitations of Doxygen. // Look for the documentation in the Classes tab of the documentation. #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NimbusCore.h" // Additions #import "UIResponder+NimbusCore.h"
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/NimbusCore.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @defgroup NimbusCore Nimbus Core * * <div id="github" feature="core"></div> * * Nimbus' Core defines the foundation upon which all other Nimbus features are built. * Within the core you will find common elements used to build iOS applications * including in-memory caches, path manipulation, and SDK availability. These features form * the foundation upon which all other Nimbus libraries are built. * * <h2>How Features are Added to the Core</h2> * * As a general rule of thumb, if something is used between multiple independent libraries or * applications with little variation, it likely qualifies to be added to the Core. * * <h3>Exceptions</h3> * * Standalone user interface components are <i>rarely</i> acceptable features to add to the Core. * For example: photo viewers, pull to refresh, launchers, attributed labels. * * Nimbus is not UIKit: we don't have the privilege of being an assumed cost on every iOS * device. Developers must carefully weigh whether it is worth adding a Nimbus feature - along * with its dependencies - over building the feature themselves or using another library. This * means that an incredible amount of care must be placed into deciding what gets added to the * Core. * * <h2>How Features are Removed from the Core</h2> * * It is inevitable that certain aspects of the Core will grow and develop over time. If a * feature gets to the point where the value of being a separate library is greater than the * overhead of managing such a library, then the feature should be considered for removal * from the Core. * * Great care must be taken to ensure that Nimbus doesn't become a framework composed of * hundreds of miniscule libraries. * * <h2>Common autoresizing masks</h2> * * Nimbus provides the following macros: UIViewAutoresizingFlexibleMargins, * UIViewAutoresizingFlexibleDimensions, UIViewAutoresizingNavigationBar, and * UIViewAutoresizingToolbarBar. * @code // Create a view that fills its superview's bounds. UIView* contentView = [[UIView alloc] initWithFrame:self.view.bounds]; contentView.autoresizingMask = UIViewAutoresizingFlexibleDimensions; [self.view addSubview:contentView]; // Create a view that is always centered in the superview's bounds. UIView* centeredView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; centeredView.autoresizingMask = UIViewAutoresizingFlexibleMargins; // Center the view within the superview however you choose. [self.view addSubview:centeredView]; // Create a navigation bar that stays fixed to the top. UINavigationBar* navBar = [[UINavigationBar alloc] initWithFrame:CGRectZero]; [navBar sizeToFit]; navBar.autoresizingMask = UIViewAutoresizingNavigationBar; [self.view addSubview:navBar]; // Create a toolbar that stays fixed to the bottom. UIToolbar* toolBar = [[UIToolbar alloc] initWithFrame:CGRectZero]; [toolBar sizeToFit]; toolBar.autoresizingMask = UIViewAutoresizingToolbarBar; [self.view addSubview:toolBar]; @endcode * * <h3>Why they exist</h3> * * Using the existing UIViewAutoresizing flags can be tedious for common flags. * * For example, to make a view have flexible margins you would need to write four flags: * @code view.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin); @endcode */ #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NIActions.h" #import "NIButtonUtilities.h" #import "NICommonMetrics.h" #import "NIDataStructures.h" // Deprecated. Will be removed after Feb 28, 2014 #import "NIDebuggingTools.h" #import "NIDeviceOrientation.h" #import "NIError.h" #import "NIFoundationMethods.h" #import "NIImageUtilities.h" #import "NIInMemoryCache.h" #import "NINavigationAppearance.h" // Deprecated. Will be removed after Feb 28, 2014 #import "NINetworkActivity.h" #import "NINonEmptyCollectionTesting.h" #import "NINonRetainingCollections.h" #import "NIOperations.h" #import "NIPaths.h" #import "NIPreprocessorMacros.h" #import "NIRuntimeClassModifications.h" #import "NISDKAvailability.h" #import "NISnapshotRotation.h" #import "NIState.h" #import "NIViewRecycler.h"
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/UIResponder+NimbusCore.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // +currentFirstResponder originally written by Jakob Egger, adapted by Jeff Verkoeyen. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> // Documentation for these additions is found in the .m file. @interface UIResponder (NimbusCore) + (instancetype)nimbus_currentFirstResponder; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/core/src/UIResponder+NimbusCore.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // +currentFirstResponder originally written by Jakob Egger, adapted by Jeff Verkoeyen. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UIResponder+NimbusCore.h" #import "NIPreprocessorMacros.h" // Adapted from http://stackoverflow.com/questions/5029267/is-there-any-way-of-asking-an-ios-view-which-of-its-children-has-first-responder/14135456#14135456 static __weak id sCurrentFirstResponder = nil; NI_FIX_CATEGORY_BUG(UIResponderNimbusCore) /** * For working with UIResponders. */ @implementation UIResponder (NimbusCore) /** * Returns the current first responder by sending an action from the UIApplication. * * The implementation was adapted from http://stackoverflow.com/questions/5029267/is-there-any-way-of-asking-an-ios-view-which-of-its-children-has-first-responder/14135456#14135456 */ + (instancetype)nimbus_currentFirstResponder { sCurrentFirstResponder = nil; [[UIApplication sharedApplication] sendAction:@selector(nimbus_findFirstResponder:) to:nil from:nil forEvent:nil]; return sCurrentFirstResponder; } - (void)nimbus_findFirstResponder:(id)sender { sCurrentFirstResponder = self; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/CSSTokenizer.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Autogenerated by flex using the Nimbus CSS grammar // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include "CssTokens.h" #line 3 "lex.css.c" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ #define yy_create_buffer css_create_buffer #define yy_delete_buffer css_delete_buffer #define yy_flex_debug css_flex_debug #define yy_init_buffer css_init_buffer #define yy_flush_buffer css_flush_buffer #define yy_load_buffer_state css_load_buffer_state #define yy_switch_to_buffer css_switch_to_buffer #define yyin cssin #define yyleng cssleng #define yylex csslex #define yylineno csslineno #define yyout cssout #define yyrestart cssrestart #define yytext csstext #define yywrap csswrap #define yyalloc cssalloc #define yyrealloc cssrealloc #define yyfree cssfree #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 #define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ #include <stdio.h> #include <string.h> #include <errno.h> #include <stdlib.h> /* end standard C headers. */ /* flex integer type definitions */ #ifndef FLEXINT_H #define FLEXINT_H /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 #endif #include <inttypes.h> typedef int8_t flex_int8_t; typedef uint8_t flex_uint8_t; typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; #endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN #define INT8_MIN (-128) #endif #ifndef INT16_MIN #define INT16_MIN (-32767-1) #endif #ifndef INT32_MIN #define INT32_MIN (-2147483647-1) #endif #ifndef INT8_MAX #define INT8_MAX (127) #endif #ifndef INT16_MAX #define INT16_MAX (32767) #endif #ifndef INT32_MAX #define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX #define UINT8_MAX (255U) #endif #ifndef UINT16_MAX #define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX #define UINT32_MAX (4294967295U) #endif #endif /* ! FLEXINT_H */ #ifdef __cplusplus /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST #else /* ! __cplusplus */ /* C99 requires __STDC__ to be defined as 1. */ #if defined (__STDC__) #define YY_USE_CONST #endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ #ifdef YY_USE_CONST #define yyconst const #else #define yyconst #endif /* Returned upon end-of-file. */ #define YY_NULL 0 /* Promotes a possibly negative, possibly signed char to an unsigned * integer for use as an array index. If the signed char is negative, * we want to instead treat it as an 8-bit unsigned char, hence the * double cast. */ #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ #define BEGIN (yy_start) = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ #define YY_START (((yy_start) - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ #define YY_NEW_FILE cssrestart(cssin ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ #ifndef YY_BUF_SIZE #define YY_BUF_SIZE 16384 #endif /* The state buf must be large enough to hold one state per character in the main buffer. */ #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T typedef size_t yy_size_t; #endif extern yy_size_t cssleng; extern FILE *cssin, *cssout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 #define YY_LESS_LINENO(n) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ do \ { \ /* Undo effects of setting up csstext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ *yy_cp = (yy_hold_char); \ YY_RESTORE_YY_MORE_OFFSET \ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up csstext again */ \ } \ while ( 0 ) #define unput(c) yyunput( c, (yytext_ptr) ) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state { FILE *yy_input_file; char *yy_ch_buf; /* input buffer */ char *yy_buf_pos; /* current position in input buffer */ /* Size of input buffer in bytes, not including room for EOB * characters. */ yy_size_t yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. */ yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to * delete it. */ int yy_is_our_buffer; /* Whether this is an "interactive" input source; if so, and * if we're using stdio for input, then we want to use getc() * instead of fread(), to make sure we stop fetching input after * each newline. */ int yy_is_interactive; /* Whether we're considered to be at the beginning of a line. * If so, '^' rules will be active on the next match, otherwise * not. */ int yy_at_bol; int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ /* Whether to try to fill the input buffer when we reach the * end of it. */ int yy_fill_buffer; int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 /* When an EOF's been seen but there's still some text to process * then we mark the buffer as YY_EOF_PENDING, to indicate that we * shouldn't try reading from the input source any more. We might * still have a bunch of tokens to match, though, because of * possible backing-up. * * When we actually see the EOF, we change the status to "new" * (via cssrestart()), so that the user can continue scanning by * just pointing cssin at a new input file. */ #define YY_BUFFER_EOF_PENDING 2 }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* Stack of input buffers. */ static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] /* yy_hold_char holds the character lost when csstext is formed. */ static char yy_hold_char; static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ yy_size_t cssleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; static int yy_init = 0; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ /* Flag which is used to allow csswrap()'s to do buffer switches * instead of setting up a fresh cssin. A bit of a hack ... */ static int yy_did_buffer_switch_on_eof; void cssrestart (FILE *input_file ); void css_switch_to_buffer (YY_BUFFER_STATE new_buffer ); YY_BUFFER_STATE css_create_buffer (FILE *file,int size ); void css_delete_buffer (YY_BUFFER_STATE b ); void css_flush_buffer (YY_BUFFER_STATE b ); void csspush_buffer_state (YY_BUFFER_STATE new_buffer ); void csspop_buffer_state (void ); static void cssensure_buffer_stack (void ); static void css_load_buffer_state (void ); static void css_init_buffer (YY_BUFFER_STATE b,FILE *file ); #define YY_FLUSH_BUFFER css_flush_buffer(YY_CURRENT_BUFFER ) YY_BUFFER_STATE css_scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE css_scan_string (yyconst char *yy_str ); YY_BUFFER_STATE css_scan_bytes (yyconst char *bytes,yy_size_t len ); void *cssalloc (yy_size_t ); void *cssrealloc (void *,yy_size_t ); void cssfree (void * ); #define yy_new_buffer css_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ cssensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ css_create_buffer(cssin,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ cssensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ css_create_buffer(cssin,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ typedef unsigned char YY_CHAR; FILE *cssin = (FILE *) 0, *cssout = (FILE *) 0; typedef int yy_state_type; extern int csslineno; int csslineno = 1; extern char *csstext; #define yytext_ptr csstext static yy_state_type yy_get_previous_state (void ); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); static int yy_get_next_buffer (void ); static void yy_fatal_error (yyconst char msg[] ); /* Done after the current pattern has been matched and before the * corresponding action - sets up csstext. */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ cssleng = (yy_size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; #define YY_NUM_RULES 41 #define YY_END_OF_BUFFER 42 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info { flex_int32_t yy_verify; flex_int32_t yy_nxt; }; static yyconst flex_int16_t yy_accept[370] = { 0, 0, 0, 42, 40, 1, 1, 40, 40, 40, 40, 40, 40, 40, 34, 40, 40, 8, 8, 40, 40, 40, 1, 0, 0, 7, 0, 9, 9, 8, 0, 0, 0, 0, 0, 34, 8, 0, 0, 34, 8, 0, 0, 33, 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 29, 0, 0, 0, 0, 0, 0, 0, 0, 37, 8, 0, 0, 0, 0, 8, 8, 8, 6, 5, 0, 0, 0, 7, 0, 0, 0, 8, 0, 8, 8, 0, 0, 7, 0, 0, 4, 8, 0, 8, 8, 0, 0, 32, 0, 20, 32, 17, 18, 32, 30, 22, 32, 21, 28, 24, 23, 19, 32, 32, 32, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 8, 0, 8, 8, 38, 38, 8, 8, 0, 0, 0, 9, 9, 8, 8, 8, 0, 0, 8, 8, 8, 0, 0, 2, 32, 32, 25, 32, 31, 26, 32, 3, 0, 0, 0, 0, 0, 0, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 38, 38, 38, 37, 8, 0, 0, 9, 8, 8, 0, 8, 8, 0, 0, 0, 0, 2, 32, 27, 32, 0, 0, 0, 0, 0, 11, 8, 8, 8, 8, 8, 8, 8, 39, 38, 38, 38, 38, 0, 0, 0, 0, 36, 0, 8, 0, 0, 9, 8, 8, 0, 8, 8, 0, 32, 32, 0, 0, 0, 12, 0, 8, 8, 8, 8, 8, 39, 38, 38, 38, 38, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 8, 0, 0, 9, 8, 8, 0, 8, 8, 32, 32, 0, 0, 10, 0, 8, 8, 8, 8, 8, 39, 38, 38, 38, 38, 38, 38, 0, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 9, 8, 8, 0, 8, 8, 32, 32, 14, 0, 0, 8, 8, 8, 8, 8, 39, 38, 38, 38, 38, 38, 38, 38, 0, 35, 0, 0, 0, 35, 0, 0, 0, 0, 9, 8, 8, 32, 0, 0, 8, 8, 8, 8, 39, 0, 0, 0, 0, 13, 15, 8, 8, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 } ; static yyconst flex_int32_t yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 7, 8, 9, 10, 11, 10, 12, 13, 14, 15, 16, 10, 17, 18, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 10, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 36, 43, 44, 45, 46, 36, 47, 48, 36, 49, 10, 50, 10, 10, 10, 10, 51, 28, 52, 53, 54, 55, 56, 57, 58, 36, 59, 60, 61, 62, 63, 64, 36, 65, 66, 67, 68, 36, 69, 70, 36, 71, 72, 73, 74, 75, 1, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76 } ; static yyconst flex_int32_t yy_meta[77] = { 0, 1, 2, 3, 4, 4, 5, 6, 7, 6, 6, 6, 7, 8, 6, 6, 6, 9, 10, 6, 11, 12, 6, 6, 6, 13, 6, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 6, 6, 6, 6, 15 } ; static yyconst flex_int16_t yy_base[448] = { 0, 0, 0, 882, 6624, 75, 80, 803, 79, 71, 77, 75, 80, 858, 120, 865, 168, 83, 188, 234, 831, 830, 103, 43, 86, 6624, 288, 82, 802, 92, 324, 91, 378, 827, 830, 0, 198, 414, 94, 97, 174, 450, 834, 6624, 798, 797, 84, 85, 186, 162, 144, 178, 164, 207, 230, 233, 796, 486, 828, 86, 83, 174, 168, 71, 190, 6624, 224, 222, 226, 522, 819, 285, 231, 576, 6624, 6624, 762, 296, 259, 261, 630, 684, 720, 284, 756, 307, 810, 298, 221, 282, 864, 918, 6624, 308, 954, 309, 1008, 820, 318, 784, 1044, 783, 314, 782, 779, 322, 777, 776, 313, 774, 773, 772, 771, 770, 335, 769, 1098, 801, 228, 274, 325, 338, 332, 336, 344, 397, 1134, 767, 756, 1170, 398, 1224, 101, 780, 399, 1278, 339, 262, 1332, 753, 1386, 403, 1440, 1494, 310, 1548, 404, 1602, 1656, 787, 380, 6624, 750, 1710, 744, 373, 743, 740, 1764, 6624, 370, 369, 396, 369, 407, 408, 434, 1800, 439, 1854, 732, 1890, 682, 1944, 1980, 0, 233, 705, 675, 517, 2034, 411, 2088, 2142, 2178, 2232, 2286, 2322, 2358, 683, 381, 638, 456, 636, 2394, 2448, 2502, 407, 630, 420, 280, 420, 6624, 474, 2556, 2610, 591, 2664, 2718, 2754, 0, 296, 612, 567, 511, 640, 691, 316, 390, 6624, 2808, 2862, 432, 2916, 2970, 3024, 3078, 3132, 3186, 3240, 468, 3276, 3312, 445, 456, 445, 6624, 466, 3348, 3384, 3420, 3456, 3492, 0, 509, 472, 468, 466, 376, 541, 448, 554, 3546, 482, 3600, 704, 717, 754, 775, 3654, 3708, 3762, 507, 3816, 3870, 3924, 3978, 4032, 4086, 4140, 4194, 4248, 516, 482, 6624, 535, 4284, 4320, 4356, 4392, 4428, 0, 510, 325, 270, 252, 177, 103, 596, 6624, 561, 450, 875, 4482, 4536, 516, 606, 929, 4590, 4644, 4698, 4734, 520, 617, 4788, 4842, 853, 667, 4896, 906, 4932, 4986, 6624, 536, 543, 5040, 5094, 5130, 5166, 610, 0, 102, 6624, 6624, 6624, 6624, 6624, 6624, 949, 616, 641, 5202, 1018, 652, 741, 5238, 5292, 526, 5328, 998, 1087, 672, 586, 670, 5364, 5400, 5436, 5472, 0, 5508, 5544, 5580, 612, 6624, 6624, 723, 759, 6624, 5616, 5652, 5688, 693, 5724, 5760, 1107, 725, 793, 1082, 6624, 6624, 5814, 5821, 5835, 5842, 5849, 5857, 5868, 5882, 5889, 5896, 5907, 5921, 5928, 5939, 5954, 372, 5961, 5972, 5979, 5986, 5997, 6002, 6012, 6023, 6034, 6049, 6060, 6067, 6078, 576, 6085, 6096, 6103, 6116, 6123, 6137, 6152, 6167, 6178, 6189, 496, 6196, 6209, 6223, 6237, 6252, 6267, 573, 6274, 6287, 6301, 6315, 6329, 6343, 6357, 6371, 6385, 6399, 6414, 654, 6421, 6434, 6448, 6462, 6476, 6490, 6504, 6518, 6532, 6546, 731, 6553, 6566, 6580, 6594, 6608, 732, 755 } ; static yyconst flex_int16_t yy_def[448] = { 0, 369, 1, 369, 369, 369, 369, 369, 370, 371, 372, 373, 374, 369, 369, 369, 369, 375, 375, 376, 369, 369, 369, 369, 370, 369, 377, 371, 378, 379, 380, 372, 381, 369, 369, 14, 375, 376, 374, 14, 382, 383, 384, 369, 385, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 387, 369, 369, 369, 369, 369, 369, 369, 369, 375, 388, 389, 390, 391, 375, 375, 375, 369, 369, 369, 370, 370, 370, 370, 377, 392, 379, 393, 379, 379, 372, 372, 372, 372, 381, 369, 382, 394, 382, 382, 384, 395, 386, 396, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 386, 369, 369, 369, 369, 369, 369, 369, 388, 397, 398, 399, 400, 401, 375, 375, 402, 369, 375, 131, 369, 403, 403, 404, 404, 379, 379, 142, 405, 405, 382, 96, 147, 406, 407, 369, 386, 116, 386, 386, 386, 386, 153, 369, 369, 369, 369, 369, 369, 369, 397, 408, 397, 397, 400, 409, 400, 400, 131, 410, 411, 369, 369, 412, 131, 369, 413, 414, 142, 142, 405, 147, 148, 406, 415, 406, 416, 406, 153, 153, 153, 369, 369, 369, 369, 369, 369, 397, 397, 204, 400, 400, 207, 131, 417, 418, 369, 369, 369, 419, 419, 420, 421, 369, 422, 131, 369, 423, 424, 425, 425, 426, 427, 427, 428, 153, 196, 369, 369, 369, 369, 369, 204, 205, 207, 208, 131, 429, 430, 369, 369, 369, 369, 369, 420, 369, 431, 421, 432, 433, 433, 433, 433, 433, 434, 131, 369, 435, 436, 437, 437, 438, 439, 439, 232, 270, 369, 369, 369, 369, 204, 239, 207, 241, 131, 440, 441, 369, 369, 369, 369, 369, 369, 369, 420, 420, 420, 420, 442, 443, 443, 443, 443, 444, 445, 261, 369, 435, 436, 266, 437, 438, 269, 439, 270, 270, 369, 369, 369, 277, 315, 207, 279, 301, 446, 369, 369, 369, 369, 369, 369, 369, 420, 420, 420, 293, 443, 443, 443, 298, 445, 369, 304, 437, 439, 311, 369, 369, 315, 316, 317, 318, 447, 293, 298, 336, 369, 369, 369, 345, 347, 369, 293, 298, 336, 369, 293, 298, 445, 369, 420, 443, 369, 0, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369 } ; static yyconst flex_int16_t yy_nxt[6701] = { 0, 4, 5, 6, 5, 5, 5, 7, 8, 9, 4, 4, 10, 4, 4, 4, 4, 11, 12, 13, 14, 4, 15, 4, 4, 4, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 17, 19, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 17, 4, 20, 4, 21, 17, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 25, 27, 25, 76, 28, 33, 34, 25, 35, 65, 38, 122, 28, 39, 67, 28, 25, 68, 22, 22, 22, 22, 22, 67, 369, 76, 68, 369, 369, 102, 39, 175, 175, 118, 30, 122, 101, 119, 37, 177, 32, 327, 26, 41, 43, 30, 69, 100, 100, 26, 44, 34, 102, 35, 32, 84, 118, 41, 101, 119, 45, 45, 46, 47, 48, 45, 49, 50, 51, 45, 52, 45, 53, 45, 45, 54, 55, 56, 45, 45, 45, 45, 45, 57, 45, 46, 47, 48, 45, 49, 50, 51, 52, 45, 53, 45, 45, 54, 55, 56, 45, 45, 45, 45, 45, 67, 106, 100, 68, 45, 59, 108, 121, 60, 65, 326, 61, 70, 105, 67, 62, 63, 68, 64, 65, 100, 120, 100, 106, 67, 123, 107, 68, 59, 108, 121, 60, 94, 103, 61, 105, 100, 62, 63, 71, 64, 25, 104, 120, 100, 65, 69, 124, 107, 123, 67, 127, 65, 68, 109, 103, 69, 67, 175, 110, 68, 71, 73, 160, 104, 100, 212, 111, 114, 73, 73, 73, 73, 73, 73, 25, 109, 25, 25, 32, 126, 110, 69, 112, 129, 325, 113, 160, 100, 69, 111, 100, 114, 73, 73, 73, 73, 73, 24, 24, 24, 77, 25, 324, 79, 112, 65, 24, 113, 31, 67, 67, 25, 68, 68, 236, 80, 26, 25, 26, 26, 175, 161, 80, 80, 80, 80, 80, 80, 245, 25, 134, 251, 67, 67, 67, 68, 68, 68, 236, 32, 150, 84, 69, 161, 151, 81, 80, 80, 80, 80, 80, 86, 134, 26, 154, 32, 155, 323, 86, 86, 86, 86, 86, 86, 84, 94, 94, 32, 369, 156, 100, 100, 157, 252, 162, 163, 165, 154, 164, 100, 155, 181, 86, 86, 86, 86, 86, 31, 31, 31, 87, 156, 100, 45, 45, 157, 162, 89, 163, 165, 164, 126, 192, 230, 181, 90, 193, 151, 287, 251, 195, 200, 90, 90, 90, 90, 90, 90, 65, 179, 197, 198, 67, 67, 67, 68, 68, 68, 67, 67, 100, 68, 68, 195, 200, 91, 90, 90, 90, 90, 90, 73, 197, 198, 199, 201, 202, 254, 73, 73, 73, 73, 73, 73, 167, 69, 69, 222, 233, 67, 84, 94, 68, 251, 67, 251, 199, 68, 201, 202, 235, 237, 73, 73, 73, 73, 73, 96, 192, 222, 233, 262, 193, 272, 96, 96, 96, 96, 96, 96, 230, 167, 235, 237, 193, 273, 167, 274, 286, 67, 285, 251, 68, 262, 284, 252, 272, 252, 96, 96, 96, 96, 96, 116, 210, 275, 313, 210, 273, 274, 116, 116, 116, 116, 116, 116, 215, 215, 215, 215, 215, 167, 217, 175, 175, 251, 218, 275, 219, 254, 313, 283, 322, 248, 116, 116, 116, 116, 116, 131, 249, 249, 249, 249, 249, 302, 131, 131, 131, 131, 131, 131, 219, 288, 288, 288, 288, 288, 312, 314, 337, 250, 342, 254, 220, 289, 251, 302, 352, 343, 131, 131, 131, 131, 131, 72, 72, 72, 72, 72, 312, 243, 337, 314, 243, 342, 65, 128, 128, 247, 352, 67, 343, 135, 68, 288, 288, 288, 288, 288, 135, 135, 135, 135, 135, 135, 369, 289, 252, 130, 130, 130, 130, 130, 353, 251, 78, 137, 137, 137, 78, 251, 25, 69, 135, 135, 135, 135, 135, 78, 137, 137, 137, 78, 246, 25, 361, 353, 171, 215, 215, 215, 215, 215, 234, 217, 251, 138, 190, 218, 190, 219, 369, 254, 138, 138, 138, 138, 138, 138, 361, 251, 281, 252, 26, 281, 88, 144, 144, 144, 88, 152, 152, 152, 152, 152, 25, 26, 138, 138, 138, 138, 138, 24, 24, 24, 77, 220, 252, 79, 249, 249, 249, 249, 249, 190, 369, 214, 354, 254, 369, 80, 219, 249, 249, 249, 249, 249, 80, 80, 80, 80, 80, 80, 32, 219, 249, 249, 249, 249, 249, 354, 203, 203, 203, 203, 203, 213, 219, 171, 365, 81, 80, 80, 80, 80, 80, 140, 220, 320, 348, 369, 320, 348, 140, 140, 140, 140, 140, 140, 251, 220, 365, 249, 249, 249, 249, 249, 206, 206, 206, 206, 206, 357, 220, 219, 357, 368, 140, 140, 140, 140, 140, 142, 249, 249, 249, 249, 249, 171, 142, 142, 142, 142, 142, 142, 219, 100, 254, 368, 100, 100, 291, 330, 330, 330, 291, 100, 251, 190, 82, 220, 178, 171, 142, 142, 142, 142, 142, 85, 85, 85, 85, 85, 129, 159, 100, 100, 100, 100, 100, 100, 220, 100, 100, 67, 100, 143, 68, 100, 100, 100, 98, 136, 143, 143, 143, 143, 143, 143, 252, 133, 117, 100, 100, 57, 98, 39, 92, 82, 75, 74, 85, 85, 85, 85, 85, 84, 143, 143, 143, 143, 143, 88, 144, 144, 144, 88, 67, 58, 42, 68, 23, 25, 328, 288, 288, 288, 328, 369, 251, 145, 369, 369, 369, 369, 329, 369, 145, 145, 145, 145, 145, 145, 369, 369, 369, 369, 369, 369, 84, 369, 369, 369, 369, 95, 95, 95, 95, 95, 369, 32, 145, 145, 145, 145, 145, 31, 31, 31, 87, 67, 252, 369, 68, 369, 369, 89, 332, 288, 288, 288, 332, 369, 369, 90, 369, 369, 251, 369, 333, 369, 90, 90, 90, 90, 90, 90, 328, 288, 288, 288, 328, 94, 251, 369, 369, 369, 369, 369, 329, 369, 369, 369, 369, 91, 90, 90, 90, 90, 90, 147, 369, 369, 369, 369, 254, 369, 147, 147, 147, 147, 147, 147, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 252, 141, 141, 141, 141, 141, 147, 147, 147, 147, 147, 95, 95, 95, 95, 95, 369, 67, 369, 369, 68, 332, 288, 288, 288, 332, 369, 67, 369, 148, 68, 251, 369, 333, 369, 369, 148, 148, 148, 148, 148, 148, 369, 369, 369, 369, 369, 369, 369, 84, 369, 369, 369, 369, 369, 369, 369, 369, 369, 94, 148, 148, 148, 148, 148, 153, 369, 369, 369, 254, 369, 369, 153, 153, 153, 153, 153, 153, 369, 369, 369, 369, 369, 369, 369, 296, 334, 334, 334, 296, 146, 146, 146, 146, 146, 251, 153, 153, 153, 153, 153, 115, 115, 115, 115, 115, 67, 369, 369, 68, 255, 255, 255, 255, 255, 369, 369, 369, 369, 158, 369, 369, 219, 369, 369, 369, 158, 158, 158, 158, 158, 158, 369, 254, 369, 369, 369, 369, 94, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 100, 158, 158, 158, 158, 158, 169, 369, 369, 220, 369, 369, 369, 169, 169, 169, 169, 169, 169, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 169, 169, 169, 169, 169, 173, 369, 369, 369, 369, 369, 369, 173, 173, 173, 173, 173, 173, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 173, 173, 173, 173, 173, 130, 130, 130, 130, 130, 369, 369, 369, 369, 369, 369, 65, 369, 369, 369, 369, 67, 369, 174, 68, 369, 369, 369, 369, 369, 174, 174, 174, 174, 174, 174, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 69, 174, 174, 174, 174, 174, 72, 72, 72, 72, 72, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 180, 369, 369, 369, 369, 369, 369, 180, 180, 180, 180, 180, 180, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 180, 180, 180, 180, 180, 78, 137, 137, 137, 78, 369, 25, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 182, 369, 369, 369, 369, 369, 369, 182, 182, 182, 182, 182, 182, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 26, 182, 182, 182, 182, 182, 139, 139, 139, 139, 139, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 183, 369, 369, 369, 369, 369, 369, 183, 183, 183, 183, 183, 183, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 82, 183, 183, 183, 183, 183, 141, 141, 141, 141, 141, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 184, 68, 369, 369, 369, 369, 369, 184, 184, 184, 184, 184, 184, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 84, 184, 184, 184, 184, 184, 85, 85, 85, 85, 85, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 185, 369, 369, 369, 369, 369, 369, 185, 185, 185, 185, 185, 185, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 185, 185, 185, 185, 185, 88, 144, 144, 144, 88, 369, 369, 369, 369, 369, 25, 369, 369, 369, 369, 369, 369, 369, 186, 369, 369, 369, 369, 369, 369, 186, 186, 186, 186, 186, 186, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 32, 186, 186, 186, 186, 186, 146, 146, 146, 146, 146, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 187, 369, 369, 369, 369, 369, 369, 187, 187, 187, 187, 187, 187, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 187, 187, 187, 187, 187, 95, 95, 95, 95, 95, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 188, 369, 369, 369, 369, 369, 369, 188, 188, 188, 188, 188, 188, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 188, 188, 188, 188, 188, 152, 152, 152, 152, 152, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 194, 369, 369, 369, 369, 369, 369, 194, 194, 194, 194, 194, 194, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 194, 194, 194, 194, 194, 115, 115, 115, 115, 115, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 196, 369, 369, 369, 369, 369, 369, 196, 196, 196, 196, 196, 196, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 196, 196, 196, 196, 196, 204, 369, 369, 369, 369, 369, 369, 204, 204, 204, 204, 204, 204, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 204, 204, 204, 204, 204, 168, 168, 168, 168, 168, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 205, 68, 369, 369, 369, 369, 369, 205, 205, 205, 205, 205, 205, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 167, 205, 205, 205, 205, 205, 207, 369, 369, 369, 369, 369, 369, 207, 207, 207, 207, 207, 207, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 207, 207, 207, 207, 207, 172, 172, 172, 172, 172, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 208, 369, 369, 369, 369, 369, 369, 208, 208, 208, 208, 208, 208, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 171, 208, 208, 208, 208, 208, 209, 369, 369, 369, 369, 369, 369, 209, 209, 209, 209, 209, 209, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 209, 209, 209, 209, 209, 72, 72, 72, 72, 72, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 221, 369, 369, 369, 369, 369, 369, 221, 221, 221, 221, 221, 221, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 221, 221, 221, 221, 221, 78, 137, 137, 137, 78, 369, 25, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 223, 369, 369, 369, 369, 369, 369, 223, 223, 223, 223, 223, 223, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 26, 223, 223, 223, 223, 223, 139, 139, 139, 139, 139, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 224, 369, 369, 369, 369, 369, 369, 224, 224, 224, 224, 224, 224, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 82, 224, 224, 224, 224, 224, 225, 369, 369, 369, 369, 369, 369, 225, 225, 225, 225, 225, 225, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 225, 225, 225, 225, 225, 85, 85, 85, 85, 85, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 226, 369, 369, 369, 369, 369, 369, 226, 226, 226, 226, 226, 226, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 226, 226, 226, 226, 226, 88, 144, 144, 144, 88, 369, 369, 369, 369, 369, 25, 369, 369, 369, 369, 369, 369, 369, 227, 369, 369, 369, 369, 369, 369, 227, 227, 227, 227, 227, 227, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 32, 227, 227, 227, 227, 227, 228, 369, 369, 369, 369, 369, 369, 228, 228, 228, 228, 228, 228, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 228, 228, 228, 228, 228, 229, 369, 369, 369, 369, 369, 369, 229, 229, 229, 229, 229, 229, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 229, 229, 229, 229, 229, 231, 369, 369, 369, 369, 369, 369, 231, 231, 231, 231, 231, 231, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 231, 231, 231, 231, 231, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 99, 369, 369, 369, 369, 369, 369, 99, 99, 99, 99, 99, 99, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 99, 99, 99, 99, 99, 115, 115, 115, 115, 115, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 232, 369, 369, 369, 369, 369, 369, 232, 232, 232, 232, 232, 232, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 232, 232, 232, 232, 232, 203, 203, 203, 203, 203, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 238, 68, 369, 369, 369, 369, 369, 238, 238, 238, 238, 238, 238, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 167, 238, 238, 238, 238, 238, 168, 168, 168, 168, 168, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 239, 369, 369, 369, 369, 369, 369, 239, 239, 239, 239, 239, 239, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 239, 239, 239, 239, 239, 206, 206, 206, 206, 206, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 240, 369, 369, 369, 369, 369, 369, 240, 240, 240, 240, 240, 240, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 171, 240, 240, 240, 240, 240, 172, 172, 172, 172, 172, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 241, 369, 369, 369, 369, 369, 369, 241, 241, 241, 241, 241, 241, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 241, 241, 241, 241, 241, 242, 369, 369, 369, 369, 369, 369, 242, 242, 242, 242, 242, 242, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 242, 242, 242, 242, 242, 249, 249, 249, 249, 255, 369, 257, 369, 369, 369, 257, 257, 258, 369, 369, 369, 369, 369, 259, 369, 369, 369, 369, 369, 369, 259, 259, 259, 259, 259, 259, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 260, 259, 259, 259, 259, 259, 72, 72, 72, 72, 72, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 261, 369, 369, 369, 369, 369, 369, 261, 261, 261, 261, 261, 261, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 261, 261, 261, 261, 261, 78, 137, 137, 137, 78, 369, 25, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 263, 369, 369, 369, 369, 369, 369, 263, 263, 263, 263, 263, 263, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 26, 263, 263, 263, 263, 263, 139, 139, 139, 139, 139, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 264, 369, 369, 369, 369, 369, 369, 264, 264, 264, 264, 264, 264, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 82, 264, 264, 264, 264, 264, 141, 141, 141, 141, 141, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 265, 68, 369, 369, 369, 369, 369, 265, 265, 265, 265, 265, 265, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 84, 265, 265, 265, 265, 265, 85, 85, 85, 85, 85, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 266, 68, 369, 369, 369, 369, 369, 266, 266, 266, 266, 266, 266, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 84, 266, 266, 266, 266, 266, 88, 144, 144, 144, 88, 369, 369, 369, 369, 369, 25, 369, 369, 369, 369, 369, 369, 369, 267, 369, 369, 369, 369, 369, 369, 267, 267, 267, 267, 267, 267, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 32, 267, 267, 267, 267, 267, 146, 146, 146, 146, 146, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 268, 68, 369, 369, 369, 369, 369, 268, 268, 268, 268, 268, 268, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 94, 268, 268, 268, 268, 268, 95, 95, 95, 95, 95, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 269, 68, 369, 369, 369, 369, 369, 269, 269, 269, 269, 269, 269, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 94, 269, 269, 269, 269, 269, 270, 369, 369, 369, 369, 369, 369, 270, 270, 270, 270, 270, 270, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 270, 270, 270, 270, 270, 271, 369, 369, 369, 369, 369, 369, 271, 271, 271, 271, 271, 271, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 271, 271, 271, 271, 271, 276, 369, 369, 369, 369, 369, 369, 276, 276, 276, 276, 276, 276, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 276, 276, 276, 276, 276, 277, 369, 369, 369, 369, 369, 369, 277, 277, 277, 277, 277, 277, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 277, 277, 277, 277, 277, 278, 369, 369, 369, 369, 369, 369, 278, 278, 278, 278, 278, 278, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 278, 278, 278, 278, 278, 279, 369, 369, 369, 369, 369, 369, 279, 279, 279, 279, 279, 279, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 279, 279, 279, 279, 279, 280, 369, 369, 369, 369, 369, 369, 280, 280, 280, 280, 280, 280, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 280, 280, 280, 280, 280, 250, 250, 250, 290, 369, 369, 292, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 293, 369, 369, 369, 369, 369, 369, 293, 293, 293, 293, 293, 293, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 294, 293, 293, 293, 293, 293, 253, 253, 253, 295, 369, 369, 369, 369, 369, 369, 297, 369, 369, 369, 369, 369, 369, 369, 298, 369, 369, 369, 369, 369, 369, 298, 298, 298, 298, 298, 298, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 299, 298, 298, 298, 298, 298, 255, 255, 255, 255, 255, 369, 369, 369, 369, 369, 369, 369, 219, 369, 369, 369, 369, 369, 300, 369, 369, 369, 369, 369, 369, 300, 300, 300, 300, 300, 300, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 220, 300, 300, 300, 300, 300, 249, 249, 249, 249, 255, 369, 257, 369, 369, 369, 257, 257, 258, 369, 369, 369, 369, 369, 259, 369, 369, 369, 369, 369, 369, 259, 259, 259, 259, 259, 259, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 260, 259, 259, 259, 259, 259, 72, 72, 72, 72, 72, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 301, 369, 369, 369, 369, 369, 369, 301, 301, 301, 301, 301, 301, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 301, 301, 301, 301, 301, 78, 137, 137, 137, 78, 369, 25, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 303, 369, 369, 369, 369, 369, 369, 303, 303, 303, 303, 303, 303, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 26, 303, 303, 303, 303, 303, 139, 139, 139, 139, 139, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 304, 369, 369, 369, 369, 369, 369, 304, 304, 304, 304, 304, 304, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 82, 304, 304, 304, 304, 304, 141, 141, 141, 141, 141, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 305, 68, 369, 369, 369, 369, 369, 305, 305, 305, 305, 305, 305, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 84, 305, 305, 305, 305, 305, 85, 85, 85, 85, 85, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 306, 68, 369, 369, 369, 369, 369, 306, 306, 306, 306, 306, 306, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 84, 306, 306, 306, 306, 306, 88, 144, 144, 144, 88, 369, 369, 369, 369, 369, 25, 369, 369, 369, 369, 369, 369, 369, 307, 369, 369, 369, 369, 369, 369, 307, 307, 307, 307, 307, 307, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 32, 307, 307, 307, 307, 307, 146, 146, 146, 146, 146, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 308, 68, 369, 369, 369, 369, 369, 308, 308, 308, 308, 308, 308, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 94, 308, 308, 308, 308, 308, 95, 95, 95, 95, 95, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 67, 369, 309, 68, 369, 369, 369, 369, 369, 309, 309, 309, 309, 309, 309, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 94, 309, 309, 309, 309, 309, 152, 152, 152, 152, 152, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 310, 369, 369, 369, 369, 369, 369, 310, 310, 310, 310, 310, 310, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 310, 310, 310, 310, 310, 115, 115, 115, 115, 115, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 311, 369, 369, 369, 369, 369, 369, 311, 311, 311, 311, 311, 311, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 311, 311, 311, 311, 311, 315, 369, 369, 369, 369, 369, 369, 315, 315, 315, 315, 315, 315, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 315, 315, 315, 315, 315, 316, 369, 369, 369, 369, 369, 369, 316, 316, 316, 316, 316, 316, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 316, 316, 316, 316, 316, 317, 369, 369, 369, 369, 369, 369, 317, 317, 317, 317, 317, 317, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 317, 317, 317, 317, 317, 318, 369, 369, 369, 369, 369, 369, 318, 318, 318, 318, 318, 318, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 318, 318, 318, 318, 318, 319, 369, 369, 369, 369, 369, 369, 319, 319, 319, 319, 319, 319, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 319, 319, 319, 319, 319, 291, 330, 330, 330, 291, 369, 251, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 331, 369, 369, 369, 369, 369, 369, 331, 331, 331, 331, 331, 331, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 252, 331, 331, 331, 331, 331, 250, 250, 250, 290, 369, 369, 292, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 293, 369, 369, 369, 369, 369, 369, 293, 293, 293, 293, 293, 293, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 294, 293, 293, 293, 293, 293, 296, 334, 334, 334, 296, 369, 369, 369, 369, 369, 251, 369, 369, 369, 369, 369, 369, 369, 335, 369, 369, 369, 369, 369, 369, 335, 335, 335, 335, 335, 335, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 254, 335, 335, 335, 335, 335, 253, 253, 253, 295, 369, 369, 369, 369, 369, 369, 297, 369, 369, 369, 369, 369, 369, 369, 298, 369, 369, 369, 369, 369, 369, 298, 298, 298, 298, 298, 298, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 299, 298, 298, 298, 298, 298, 255, 255, 255, 255, 255, 369, 369, 369, 369, 369, 369, 369, 219, 369, 369, 369, 369, 369, 336, 369, 369, 369, 369, 369, 369, 336, 336, 336, 336, 336, 336, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 220, 336, 336, 336, 336, 336, 66, 369, 369, 369, 369, 369, 369, 66, 66, 66, 66, 66, 66, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 66, 66, 66, 66, 66, 139, 139, 139, 139, 139, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 338, 369, 369, 369, 369, 369, 369, 338, 338, 338, 338, 338, 338, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 82, 338, 338, 338, 338, 338, 141, 141, 141, 141, 141, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 339, 369, 369, 369, 369, 369, 369, 339, 339, 339, 339, 339, 339, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 339, 339, 339, 339, 339, 146, 146, 146, 146, 146, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 340, 369, 369, 369, 369, 369, 369, 340, 340, 340, 340, 340, 340, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 340, 340, 340, 340, 340, 341, 369, 369, 369, 369, 369, 369, 341, 341, 341, 341, 341, 341, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 341, 341, 341, 341, 341, 115, 115, 115, 115, 115, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 99, 369, 369, 369, 369, 369, 369, 99, 99, 99, 99, 99, 99, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 99, 99, 99, 99, 99, 203, 203, 203, 203, 203, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 344, 369, 369, 369, 369, 369, 369, 344, 344, 344, 344, 344, 344, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 344, 344, 344, 344, 344, 168, 168, 168, 168, 168, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 345, 369, 369, 369, 369, 369, 369, 345, 345, 345, 345, 345, 345, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 345, 345, 345, 345, 345, 346, 369, 369, 369, 369, 369, 369, 346, 346, 346, 346, 346, 346, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 346, 346, 346, 346, 346, 347, 369, 369, 369, 369, 369, 369, 347, 347, 347, 347, 347, 347, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 347, 347, 347, 347, 347, 349, 369, 369, 369, 369, 369, 369, 349, 349, 349, 349, 349, 349, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 349, 349, 349, 349, 349, 350, 369, 369, 369, 369, 369, 369, 350, 350, 350, 350, 350, 350, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 350, 350, 350, 350, 350, 255, 255, 255, 255, 255, 369, 369, 369, 369, 369, 369, 369, 219, 369, 369, 369, 369, 369, 351, 369, 369, 369, 369, 369, 369, 351, 351, 351, 351, 351, 351, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 220, 351, 351, 351, 351, 351, 28, 369, 369, 369, 369, 369, 369, 28, 28, 28, 28, 28, 28, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 28, 28, 28, 28, 28, 355, 369, 369, 369, 369, 369, 369, 355, 355, 355, 355, 355, 355, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 355, 355, 355, 355, 355, 166, 369, 369, 369, 369, 369, 369, 166, 166, 166, 166, 166, 166, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 166, 166, 166, 166, 166, 356, 369, 369, 369, 369, 369, 369, 356, 356, 356, 356, 356, 356, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 356, 356, 356, 356, 356, 170, 369, 369, 369, 369, 369, 369, 170, 170, 170, 170, 170, 170, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 170, 170, 170, 170, 170, 358, 369, 369, 369, 369, 369, 369, 358, 358, 358, 358, 358, 358, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 358, 358, 358, 358, 358, 359, 369, 369, 369, 369, 369, 369, 359, 359, 359, 359, 359, 359, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 359, 359, 359, 359, 359, 360, 369, 369, 369, 369, 369, 369, 360, 360, 360, 360, 360, 360, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 360, 360, 360, 360, 360, 362, 369, 369, 369, 369, 369, 369, 362, 362, 362, 362, 362, 362, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 362, 362, 362, 362, 362, 363, 369, 369, 369, 369, 369, 369, 363, 363, 363, 363, 363, 363, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 363, 363, 363, 363, 363, 364, 369, 369, 369, 369, 369, 369, 364, 364, 364, 364, 364, 364, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 364, 364, 364, 364, 364, 366, 369, 369, 369, 369, 369, 369, 366, 366, 366, 366, 366, 366, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 366, 366, 366, 366, 366, 367, 369, 369, 369, 369, 369, 369, 367, 367, 367, 367, 367, 367, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 367, 367, 367, 367, 367, 24, 369, 369, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 29, 369, 29, 369, 369, 29, 29, 31, 369, 369, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 36, 36, 36, 369, 369, 36, 36, 40, 369, 40, 369, 369, 40, 40, 66, 66, 66, 66, 66, 369, 66, 66, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 28, 369, 28, 369, 369, 28, 28, 83, 83, 83, 83, 369, 83, 83, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 93, 93, 93, 93, 369, 93, 93, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 99, 369, 99, 369, 369, 99, 99, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 125, 369, 369, 369, 369, 125, 125, 128, 369, 369, 369, 369, 128, 128, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 132, 369, 132, 132, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 166, 166, 166, 166, 369, 166, 166, 168, 168, 168, 168, 168, 168, 168, 168, 168, 168, 168, 170, 369, 170, 369, 369, 170, 170, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 176, 369, 176, 369, 176, 176, 24, 369, 369, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 28, 369, 28, 369, 369, 28, 28, 31, 369, 369, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 211, 369, 211, 369, 211, 211, 216, 216, 216, 216, 216, 216, 369, 216, 216, 216, 216, 216, 216, 216, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 28, 28, 28, 28, 369, 369, 369, 28, 369, 28, 369, 369, 28, 28, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 244, 369, 244, 369, 244, 244, 216, 216, 216, 216, 216, 216, 369, 216, 216, 216, 216, 216, 216, 216, 250, 369, 369, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 253, 369, 369, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 28, 28, 28, 28, 369, 369, 369, 28, 369, 28, 369, 369, 28, 28, 83, 83, 83, 83, 369, 369, 369, 83, 83, 83, 83, 369, 83, 83, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 93, 93, 93, 93, 369, 369, 369, 93, 93, 93, 93, 369, 93, 93, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 282, 369, 282, 369, 282, 282, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 216, 216, 216, 216, 216, 369, 369, 216, 216, 216, 216, 216, 216, 216, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 28, 28, 28, 28, 369, 369, 369, 28, 369, 28, 369, 369, 28, 28, 83, 83, 83, 83, 369, 369, 369, 83, 83, 83, 83, 369, 83, 83, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 93, 93, 93, 93, 369, 369, 369, 93, 93, 93, 93, 369, 93, 93, 321, 369, 321, 369, 321, 321, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 291, 253, 253, 369, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 296, 216, 216, 216, 216, 216, 369, 369, 216, 216, 216, 216, 216, 216, 216, 3, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369 } ; static yyconst flex_int16_t yy_chk[6701] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 8, 9, 10, 23, 9, 11, 11, 24, 11, 17, 12, 63, 27, 12, 17, 27, 31, 17, 22, 22, 22, 22, 22, 29, 38, 23, 29, 38, 39, 47, 39, 132, 321, 59, 9, 63, 46, 60, 11, 132, 10, 287, 8, 12, 14, 27, 17, 46, 47, 24, 14, 14, 47, 14, 31, 29, 59, 38, 46, 60, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 40, 50, 50, 40, 14, 16, 52, 62, 16, 18, 286, 16, 18, 49, 18, 16, 16, 18, 16, 36, 49, 61, 52, 50, 36, 64, 51, 36, 16, 52, 62, 16, 40, 48, 16, 49, 51, 16, 16, 18, 16, 88, 48, 61, 48, 66, 18, 67, 51, 64, 66, 68, 72, 66, 53, 48, 36, 72, 176, 53, 72, 18, 19, 118, 48, 53, 176, 54, 55, 19, 19, 19, 19, 19, 19, 78, 53, 79, 137, 88, 67, 53, 66, 54, 68, 285, 54, 118, 54, 72, 54, 55, 55, 19, 19, 19, 19, 19, 26, 26, 26, 26, 89, 284, 26, 54, 71, 77, 54, 87, 83, 71, 77, 83, 71, 200, 26, 78, 87, 79, 137, 211, 119, 26, 26, 26, 26, 26, 26, 211, 144, 71, 217, 85, 93, 95, 85, 93, 95, 200, 89, 98, 83, 71, 119, 98, 26, 26, 26, 26, 26, 26, 30, 71, 77, 102, 87, 105, 283, 30, 30, 30, 30, 30, 30, 85, 93, 95, 144, 124, 108, 108, 102, 114, 217, 120, 121, 123, 102, 122, 105, 105, 136, 30, 30, 30, 30, 30, 32, 32, 32, 32, 108, 114, 385, 385, 114, 120, 32, 121, 123, 122, 124, 150, 190, 136, 32, 150, 190, 248, 218, 155, 163, 32, 32, 32, 32, 32, 32, 130, 134, 160, 161, 125, 130, 134, 125, 130, 134, 141, 146, 155, 141, 146, 155, 163, 32, 32, 32, 32, 32, 32, 37, 160, 161, 162, 164, 165, 218, 37, 37, 37, 37, 37, 37, 125, 130, 134, 181, 197, 166, 141, 146, 166, 250, 168, 291, 162, 168, 164, 165, 199, 201, 37, 37, 37, 37, 37, 41, 192, 181, 197, 222, 192, 233, 41, 41, 41, 41, 41, 41, 230, 166, 199, 201, 230, 234, 168, 235, 247, 203, 246, 253, 203, 222, 245, 250, 233, 291, 41, 41, 41, 41, 41, 57, 410, 237, 273, 410, 234, 235, 57, 57, 57, 57, 57, 57, 179, 179, 179, 179, 179, 203, 179, 244, 282, 295, 179, 237, 179, 253, 273, 244, 282, 214, 57, 57, 57, 57, 57, 69, 249, 249, 249, 249, 249, 262, 69, 69, 69, 69, 69, 69, 249, 251, 251, 251, 251, 251, 272, 275, 302, 290, 313, 295, 179, 251, 290, 262, 337, 314, 69, 69, 69, 69, 69, 73, 73, 73, 73, 73, 272, 417, 302, 275, 417, 313, 73, 399, 399, 213, 337, 73, 314, 73, 73, 288, 288, 288, 288, 288, 73, 73, 73, 73, 73, 73, 296, 288, 290, 319, 319, 319, 319, 319, 342, 296, 303, 303, 303, 303, 303, 329, 303, 73, 73, 73, 73, 73, 73, 80, 80, 80, 80, 80, 212, 80, 352, 342, 206, 215, 215, 215, 215, 215, 198, 215, 330, 80, 193, 215, 191, 215, 333, 296, 80, 80, 80, 80, 80, 80, 352, 333, 429, 329, 303, 429, 307, 307, 307, 307, 307, 341, 341, 341, 341, 341, 307, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 215, 330, 81, 216, 216, 216, 216, 216, 189, 216, 178, 343, 333, 216, 81, 216, 255, 255, 255, 255, 255, 81, 81, 81, 81, 81, 81, 307, 255, 256, 256, 256, 256, 256, 343, 355, 355, 355, 355, 355, 177, 256, 172, 361, 81, 81, 81, 81, 81, 81, 82, 216, 440, 446, 334, 440, 446, 82, 82, 82, 82, 82, 82, 334, 255, 361, 257, 257, 257, 257, 257, 356, 356, 356, 356, 356, 447, 256, 257, 447, 365, 82, 82, 82, 82, 82, 84, 258, 258, 258, 258, 258, 170, 84, 84, 84, 84, 84, 84, 258, 157, 334, 365, 156, 154, 366, 366, 366, 366, 366, 152, 366, 149, 139, 257, 133, 128, 84, 84, 84, 84, 84, 86, 86, 86, 86, 86, 127, 117, 115, 113, 112, 111, 110, 109, 258, 107, 106, 86, 104, 86, 86, 103, 101, 99, 97, 76, 86, 86, 86, 86, 86, 86, 366, 70, 58, 56, 45, 44, 42, 34, 33, 28, 21, 20, 306, 306, 306, 306, 306, 86, 86, 86, 86, 86, 86, 90, 90, 90, 90, 90, 306, 15, 13, 306, 7, 90, 292, 292, 292, 292, 292, 3, 292, 90, 0, 0, 0, 0, 292, 0, 90, 90, 90, 90, 90, 90, 0, 0, 0, 0, 0, 0, 306, 0, 0, 0, 0, 309, 309, 309, 309, 309, 0, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 309, 292, 0, 309, 0, 0, 91, 297, 297, 297, 297, 297, 0, 0, 91, 0, 0, 297, 0, 297, 0, 91, 91, 91, 91, 91, 91, 328, 328, 328, 328, 328, 309, 328, 0, 0, 0, 0, 0, 328, 0, 0, 0, 0, 91, 91, 91, 91, 91, 91, 94, 0, 0, 0, 0, 297, 0, 94, 94, 94, 94, 94, 94, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 328, 339, 339, 339, 339, 339, 94, 94, 94, 94, 94, 96, 96, 96, 96, 96, 0, 339, 0, 0, 339, 332, 332, 332, 332, 332, 0, 96, 0, 96, 96, 332, 0, 332, 0, 0, 96, 96, 96, 96, 96, 96, 0, 0, 0, 0, 0, 0, 0, 339, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 96, 96, 96, 96, 96, 100, 0, 0, 0, 332, 0, 0, 100, 100, 100, 100, 100, 100, 0, 0, 0, 0, 0, 0, 0, 367, 367, 367, 367, 367, 340, 340, 340, 340, 340, 367, 100, 100, 100, 100, 100, 116, 116, 116, 116, 116, 340, 0, 0, 340, 364, 364, 364, 364, 364, 0, 0, 0, 0, 116, 0, 0, 364, 0, 0, 0, 116, 116, 116, 116, 116, 116, 0, 367, 0, 0, 0, 0, 340, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116, 116, 116, 116, 116, 116, 126, 0, 0, 364, 0, 0, 0, 126, 126, 126, 126, 126, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126, 126, 126, 126, 126, 129, 0, 0, 0, 0, 0, 0, 129, 129, 129, 129, 129, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 129, 129, 129, 129, 129, 131, 131, 131, 131, 131, 0, 0, 0, 0, 0, 0, 131, 0, 0, 0, 0, 131, 0, 131, 131, 0, 0, 0, 0, 0, 131, 131, 131, 131, 131, 131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 131, 131, 131, 131, 131, 131, 135, 135, 135, 135, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 135, 135, 135, 135, 135, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 135, 135, 135, 135, 135, 138, 138, 138, 138, 138, 0, 138, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 0, 0, 0, 0, 0, 0, 138, 138, 138, 138, 138, 138, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 138, 138, 138, 138, 138, 140, 140, 140, 140, 140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 140, 0, 0, 0, 0, 0, 0, 140, 140, 140, 140, 140, 140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 140, 140, 140, 140, 140, 140, 142, 142, 142, 142, 142, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 142, 0, 142, 142, 0, 0, 0, 0, 0, 142, 142, 142, 142, 142, 142, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 142, 142, 142, 142, 142, 142, 143, 143, 143, 143, 143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 143, 0, 0, 0, 0, 0, 0, 143, 143, 143, 143, 143, 143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 143, 143, 143, 143, 143, 145, 145, 145, 145, 145, 0, 0, 0, 0, 0, 145, 0, 0, 0, 0, 0, 0, 0, 145, 0, 0, 0, 0, 0, 0, 145, 145, 145, 145, 145, 145, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 145, 145, 145, 145, 145, 145, 147, 147, 147, 147, 147, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 147, 0, 0, 0, 0, 0, 0, 147, 147, 147, 147, 147, 147, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 147, 147, 147, 147, 147, 148, 148, 148, 148, 148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 148, 0, 0, 0, 0, 0, 0, 148, 148, 148, 148, 148, 148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 148, 148, 148, 148, 148, 153, 153, 153, 153, 153, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 0, 0, 0, 0, 0, 0, 153, 153, 153, 153, 153, 153, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 153, 153, 153, 153, 158, 158, 158, 158, 158, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 158, 0, 0, 0, 0, 0, 0, 158, 158, 158, 158, 158, 158, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 158, 158, 158, 158, 158, 167, 0, 0, 0, 0, 0, 0, 167, 167, 167, 167, 167, 167, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 167, 167, 167, 167, 167, 169, 169, 169, 169, 169, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 169, 0, 169, 169, 0, 0, 0, 0, 0, 169, 169, 169, 169, 169, 169, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 169, 169, 169, 169, 169, 169, 171, 0, 0, 0, 0, 0, 0, 171, 171, 171, 171, 171, 171, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 171, 171, 171, 171, 173, 173, 173, 173, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 0, 0, 0, 0, 0, 0, 173, 173, 173, 173, 173, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 173, 173, 173, 173, 173, 174, 0, 0, 0, 0, 0, 0, 174, 174, 174, 174, 174, 174, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 174, 174, 174, 174, 174, 180, 180, 180, 180, 180, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 180, 0, 0, 0, 0, 0, 0, 180, 180, 180, 180, 180, 180, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 180, 180, 180, 180, 180, 182, 182, 182, 182, 182, 0, 182, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 182, 0, 0, 0, 0, 0, 0, 182, 182, 182, 182, 182, 182, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 183, 0, 0, 0, 0, 0, 0, 183, 183, 183, 183, 183, 183, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 183, 183, 183, 183, 183, 183, 184, 0, 0, 0, 0, 0, 0, 184, 184, 184, 184, 184, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 184, 184, 184, 184, 184, 185, 185, 185, 185, 185, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 185, 0, 0, 0, 0, 0, 0, 185, 185, 185, 185, 185, 185, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 185, 185, 185, 185, 185, 186, 186, 186, 186, 186, 0, 0, 0, 0, 0, 186, 0, 0, 0, 0, 0, 0, 0, 186, 0, 0, 0, 0, 0, 0, 186, 186, 186, 186, 186, 186, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 186, 186, 186, 186, 186, 186, 187, 0, 0, 0, 0, 0, 0, 187, 187, 187, 187, 187, 187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 187, 187, 187, 187, 187, 188, 0, 0, 0, 0, 0, 0, 188, 188, 188, 188, 188, 188, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 188, 188, 188, 188, 188, 194, 0, 0, 0, 0, 0, 0, 194, 194, 194, 194, 194, 194, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 194, 194, 194, 194, 194, 195, 195, 195, 195, 195, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 195, 0, 0, 0, 0, 0, 0, 195, 195, 195, 195, 195, 195, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 195, 195, 195, 195, 195, 196, 196, 196, 196, 196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 0, 0, 0, 0, 0, 0, 196, 196, 196, 196, 196, 196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 196, 196, 196, 196, 204, 204, 204, 204, 204, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 204, 0, 204, 204, 0, 0, 0, 0, 0, 204, 204, 204, 204, 204, 204, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 204, 204, 204, 204, 204, 204, 205, 205, 205, 205, 205, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 205, 0, 0, 0, 0, 0, 0, 205, 205, 205, 205, 205, 205, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 205, 205, 205, 205, 205, 207, 207, 207, 207, 207, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 207, 0, 0, 0, 0, 0, 0, 207, 207, 207, 207, 207, 207, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 207, 207, 207, 207, 207, 207, 208, 208, 208, 208, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 208, 0, 0, 0, 0, 0, 0, 208, 208, 208, 208, 208, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 208, 208, 208, 208, 208, 209, 0, 0, 0, 0, 0, 0, 209, 209, 209, 209, 209, 209, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 209, 209, 209, 209, 209, 220, 220, 220, 220, 220, 0, 220, 0, 0, 0, 220, 220, 220, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 220, 220, 220, 220, 220, 220, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 220, 220, 220, 220, 221, 221, 221, 221, 221, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 221, 0, 0, 0, 0, 0, 0, 221, 221, 221, 221, 221, 221, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 221, 221, 221, 221, 221, 223, 223, 223, 223, 223, 0, 223, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 223, 0, 0, 0, 0, 0, 0, 223, 223, 223, 223, 223, 223, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 223, 223, 223, 223, 223, 223, 224, 224, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 0, 0, 0, 0, 0, 0, 224, 224, 224, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 224, 224, 224, 225, 225, 225, 225, 225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 225, 0, 225, 225, 0, 0, 0, 0, 0, 225, 225, 225, 225, 225, 225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 225, 225, 225, 225, 225, 225, 226, 226, 226, 226, 226, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 226, 0, 226, 226, 0, 0, 0, 0, 0, 226, 226, 226, 226, 226, 226, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 226, 226, 226, 226, 226, 226, 227, 227, 227, 227, 227, 0, 0, 0, 0, 0, 227, 0, 0, 0, 0, 0, 0, 0, 227, 0, 0, 0, 0, 0, 0, 227, 227, 227, 227, 227, 227, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 227, 227, 227, 227, 227, 227, 228, 228, 228, 228, 228, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 0, 228, 228, 0, 0, 0, 0, 0, 228, 228, 228, 228, 228, 228, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 228, 228, 228, 228, 228, 229, 229, 229, 229, 229, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 0, 229, 229, 0, 0, 0, 0, 0, 229, 229, 229, 229, 229, 229, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 229, 229, 229, 229, 229, 231, 0, 0, 0, 0, 0, 0, 231, 231, 231, 231, 231, 231, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231, 231, 231, 231, 231, 232, 0, 0, 0, 0, 0, 0, 232, 232, 232, 232, 232, 232, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 232, 232, 232, 232, 232, 238, 0, 0, 0, 0, 0, 0, 238, 238, 238, 238, 238, 238, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 238, 238, 238, 238, 238, 239, 0, 0, 0, 0, 0, 0, 239, 239, 239, 239, 239, 239, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 239, 239, 239, 239, 239, 240, 0, 0, 0, 0, 0, 0, 240, 240, 240, 240, 240, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 240, 240, 240, 240, 241, 0, 0, 0, 0, 0, 0, 241, 241, 241, 241, 241, 241, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 241, 241, 241, 241, 241, 242, 0, 0, 0, 0, 0, 0, 242, 242, 242, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 242, 242, 242, 242, 242, 252, 252, 252, 252, 0, 0, 252, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252, 0, 0, 0, 0, 0, 0, 252, 252, 252, 252, 252, 252, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252, 252, 252, 252, 252, 252, 254, 254, 254, 254, 0, 0, 0, 0, 0, 0, 254, 0, 0, 0, 0, 0, 0, 0, 254, 0, 0, 0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 259, 259, 259, 259, 259, 0, 0, 0, 0, 0, 0, 0, 259, 0, 0, 0, 0, 0, 259, 0, 0, 0, 0, 0, 0, 259, 259, 259, 259, 259, 259, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 259, 259, 259, 259, 259, 259, 260, 260, 260, 260, 260, 0, 260, 0, 0, 0, 260, 260, 260, 0, 0, 0, 0, 0, 260, 0, 0, 0, 0, 0, 0, 260, 260, 260, 260, 260, 260, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 260, 260, 260, 260, 260, 260, 261, 261, 261, 261, 261, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 261, 0, 0, 0, 0, 0, 0, 261, 261, 261, 261, 261, 261, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 261, 261, 261, 261, 261, 263, 263, 263, 263, 263, 0, 263, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 263, 0, 0, 0, 0, 0, 0, 263, 263, 263, 263, 263, 263, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 263, 263, 263, 263, 263, 263, 264, 264, 264, 264, 264, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 264, 0, 0, 0, 0, 0, 0, 264, 264, 264, 264, 264, 264, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 264, 264, 264, 264, 264, 264, 265, 265, 265, 265, 265, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 265, 0, 265, 265, 0, 0, 0, 0, 0, 265, 265, 265, 265, 265, 265, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 265, 265, 265, 265, 265, 265, 266, 266, 266, 266, 266, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 266, 0, 266, 266, 0, 0, 0, 0, 0, 266, 266, 266, 266, 266, 266, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 266, 266, 266, 266, 266, 266, 267, 267, 267, 267, 267, 0, 0, 0, 0, 0, 267, 0, 0, 0, 0, 0, 0, 0, 267, 0, 0, 0, 0, 0, 0, 267, 267, 267, 267, 267, 267, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 267, 267, 267, 267, 267, 267, 268, 268, 268, 268, 268, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 268, 0, 268, 268, 0, 0, 0, 0, 0, 268, 268, 268, 268, 268, 268, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 268, 268, 268, 268, 268, 268, 269, 269, 269, 269, 269, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 269, 0, 269, 269, 0, 0, 0, 0, 0, 269, 269, 269, 269, 269, 269, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 269, 269, 269, 269, 269, 269, 270, 270, 270, 270, 270, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 270, 0, 0, 0, 0, 0, 0, 270, 270, 270, 270, 270, 270, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 270, 270, 270, 270, 270, 271, 271, 271, 271, 271, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 271, 0, 0, 0, 0, 0, 0, 271, 271, 271, 271, 271, 271, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 271, 271, 271, 271, 271, 276, 0, 0, 0, 0, 0, 0, 276, 276, 276, 276, 276, 276, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 276, 276, 276, 276, 276, 277, 0, 0, 0, 0, 0, 0, 277, 277, 277, 277, 277, 277, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 277, 277, 277, 277, 277, 278, 0, 0, 0, 0, 0, 0, 278, 278, 278, 278, 278, 278, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 278, 278, 278, 278, 278, 279, 0, 0, 0, 0, 0, 0, 279, 279, 279, 279, 279, 279, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 279, 279, 279, 279, 279, 280, 0, 0, 0, 0, 0, 0, 280, 280, 280, 280, 280, 280, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 280, 280, 280, 280, 280, 293, 293, 293, 293, 293, 0, 293, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 293, 0, 0, 0, 0, 0, 0, 293, 293, 293, 293, 293, 293, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 293, 293, 293, 293, 293, 293, 294, 294, 294, 294, 0, 0, 294, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 294, 0, 0, 0, 0, 0, 0, 294, 294, 294, 294, 294, 294, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 294, 294, 294, 294, 294, 294, 298, 298, 298, 298, 298, 0, 0, 0, 0, 0, 298, 0, 0, 0, 0, 0, 0, 0, 298, 0, 0, 0, 0, 0, 0, 298, 298, 298, 298, 298, 298, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 298, 298, 298, 298, 298, 298, 299, 299, 299, 299, 0, 0, 0, 0, 0, 0, 299, 0, 0, 0, 0, 0, 0, 0, 299, 0, 0, 0, 0, 0, 0, 299, 299, 299, 299, 299, 299, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 299, 299, 299, 299, 299, 299, 300, 300, 300, 300, 300, 0, 0, 0, 0, 0, 0, 0, 300, 0, 0, 0, 0, 0, 300, 0, 0, 0, 0, 0, 0, 300, 300, 300, 300, 300, 300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 300, 300, 300, 300, 300, 300, 301, 0, 0, 0, 0, 0, 0, 301, 301, 301, 301, 301, 301, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 301, 301, 301, 301, 301, 304, 304, 304, 304, 304, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 304, 0, 0, 0, 0, 0, 0, 304, 304, 304, 304, 304, 304, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 304, 304, 304, 304, 304, 304, 305, 305, 305, 305, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305, 0, 0, 0, 0, 0, 0, 305, 305, 305, 305, 305, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305, 305, 305, 305, 305, 308, 308, 308, 308, 308, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 308, 0, 0, 0, 0, 0, 0, 308, 308, 308, 308, 308, 308, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 308, 308, 308, 308, 308, 310, 0, 0, 0, 0, 0, 0, 310, 310, 310, 310, 310, 310, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 310, 310, 310, 310, 310, 311, 311, 311, 311, 311, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 311, 0, 0, 0, 0, 0, 0, 311, 311, 311, 311, 311, 311, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 311, 311, 311, 311, 311, 315, 315, 315, 315, 315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 315, 0, 0, 0, 0, 0, 0, 315, 315, 315, 315, 315, 315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 315, 315, 315, 315, 315, 316, 316, 316, 316, 316, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 316, 0, 0, 0, 0, 0, 0, 316, 316, 316, 316, 316, 316, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 316, 316, 316, 316, 316, 317, 0, 0, 0, 0, 0, 0, 317, 317, 317, 317, 317, 317, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 317, 317, 317, 317, 317, 318, 0, 0, 0, 0, 0, 0, 318, 318, 318, 318, 318, 318, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 318, 318, 318, 318, 318, 331, 0, 0, 0, 0, 0, 0, 331, 331, 331, 331, 331, 331, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 331, 331, 331, 331, 331, 335, 0, 0, 0, 0, 0, 0, 335, 335, 335, 335, 335, 335, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 335, 335, 335, 335, 335, 336, 336, 336, 336, 336, 0, 0, 0, 0, 0, 0, 0, 336, 0, 0, 0, 0, 0, 336, 0, 0, 0, 0, 0, 0, 336, 336, 336, 336, 336, 336, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 336, 336, 336, 336, 336, 336, 338, 0, 0, 0, 0, 0, 0, 338, 338, 338, 338, 338, 338, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 338, 338, 338, 338, 338, 344, 0, 0, 0, 0, 0, 0, 344, 344, 344, 344, 344, 344, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 344, 344, 344, 344, 344, 345, 0, 0, 0, 0, 0, 0, 345, 345, 345, 345, 345, 345, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 345, 345, 345, 345, 345, 346, 0, 0, 0, 0, 0, 0, 346, 346, 346, 346, 346, 346, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 346, 346, 346, 346, 346, 347, 0, 0, 0, 0, 0, 0, 347, 347, 347, 347, 347, 347, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 347, 347, 347, 347, 347, 349, 0, 0, 0, 0, 0, 0, 349, 349, 349, 349, 349, 349, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 349, 349, 349, 349, 349, 350, 0, 0, 0, 0, 0, 0, 350, 350, 350, 350, 350, 350, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 350, 350, 350, 350, 350, 351, 0, 0, 0, 0, 0, 0, 351, 351, 351, 351, 351, 351, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 351, 351, 351, 351, 351, 358, 0, 0, 0, 0, 0, 0, 358, 358, 358, 358, 358, 358, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 358, 358, 358, 358, 358, 359, 0, 0, 0, 0, 0, 0, 359, 359, 359, 359, 359, 359, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 359, 359, 359, 359, 359, 360, 0, 0, 0, 0, 0, 0, 360, 360, 360, 360, 360, 360, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 360, 360, 360, 360, 360, 362, 0, 0, 0, 0, 0, 0, 362, 362, 362, 362, 362, 362, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 362, 362, 362, 362, 362, 363, 0, 0, 0, 0, 0, 0, 363, 363, 363, 363, 363, 363, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 363, 363, 363, 363, 363, 370, 0, 0, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 371, 0, 371, 0, 0, 371, 371, 372, 0, 0, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 373, 373, 373, 0, 0, 373, 373, 374, 0, 374, 0, 0, 374, 374, 375, 375, 375, 375, 375, 0, 375, 375, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 378, 0, 378, 0, 0, 378, 378, 379, 379, 379, 379, 0, 379, 379, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 381, 381, 381, 381, 381, 381, 381, 381, 381, 381, 381, 381, 381, 381, 382, 382, 382, 382, 0, 382, 382, 383, 383, 383, 383, 383, 383, 383, 383, 383, 383, 383, 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, 386, 0, 386, 0, 0, 386, 386, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 388, 0, 0, 0, 0, 388, 388, 389, 0, 0, 0, 0, 389, 389, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 391, 0, 391, 391, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 393, 393, 393, 393, 393, 393, 393, 393, 393, 393, 393, 394, 394, 394, 394, 394, 394, 394, 394, 394, 394, 394, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 396, 396, 396, 396, 396, 396, 396, 396, 396, 396, 396, 397, 397, 397, 397, 0, 397, 397, 398, 398, 398, 398, 398, 398, 398, 398, 398, 398, 398, 400, 0, 400, 0, 0, 400, 400, 401, 401, 401, 401, 401, 401, 401, 401, 401, 401, 401, 402, 0, 402, 0, 402, 402, 403, 0, 0, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 404, 0, 404, 0, 0, 404, 404, 405, 0, 0, 405, 405, 405, 405, 405, 405, 405, 405, 405, 405, 405, 406, 406, 406, 406, 406, 406, 406, 406, 406, 406, 406, 406, 406, 406, 406, 407, 407, 407, 407, 407, 407, 407, 407, 407, 407, 407, 407, 407, 407, 407, 408, 408, 408, 408, 408, 408, 408, 408, 408, 408, 408, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 409, 411, 0, 411, 0, 411, 411, 412, 412, 412, 412, 412, 412, 0, 412, 412, 412, 412, 412, 412, 412, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 414, 414, 414, 414, 0, 0, 0, 414, 0, 414, 0, 0, 414, 414, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 418, 0, 418, 0, 418, 418, 419, 419, 419, 419, 419, 419, 0, 419, 419, 419, 419, 419, 419, 419, 420, 0, 0, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 421, 0, 0, 421, 421, 421, 421, 421, 421, 421, 421, 421, 421, 421, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 422, 423, 423, 423, 423, 423, 423, 423, 423, 423, 423, 423, 423, 423, 423, 424, 424, 424, 424, 0, 0, 0, 424, 0, 424, 0, 0, 424, 424, 425, 425, 425, 425, 0, 0, 0, 425, 425, 425, 425, 0, 425, 425, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 427, 427, 427, 427, 0, 0, 0, 427, 427, 427, 427, 0, 427, 427, 428, 428, 428, 428, 428, 428, 428, 428, 428, 428, 428, 428, 428, 428, 428, 430, 0, 430, 0, 430, 430, 431, 431, 431, 431, 431, 431, 431, 431, 431, 431, 431, 431, 431, 431, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 433, 433, 433, 433, 433, 0, 0, 433, 433, 433, 433, 433, 433, 433, 434, 434, 434, 434, 434, 434, 434, 434, 434, 434, 434, 434, 434, 434, 435, 435, 435, 435, 435, 435, 435, 435, 435, 435, 435, 435, 435, 435, 436, 436, 436, 436, 0, 0, 0, 436, 0, 436, 0, 0, 436, 436, 437, 437, 437, 437, 0, 0, 0, 437, 437, 437, 437, 0, 437, 437, 438, 438, 438, 438, 438, 438, 438, 438, 438, 438, 438, 438, 438, 438, 439, 439, 439, 439, 0, 0, 0, 439, 439, 439, 439, 0, 439, 439, 441, 0, 441, 0, 441, 441, 442, 442, 442, 442, 442, 442, 442, 442, 442, 442, 442, 442, 442, 442, 443, 443, 0, 443, 443, 443, 443, 443, 443, 443, 443, 443, 443, 443, 444, 444, 444, 444, 444, 444, 444, 444, 444, 444, 444, 444, 444, 444, 445, 445, 445, 445, 445, 0, 0, 445, 445, 445, 445, 445, 445, 445, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369 } ; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; extern int css_flex_debug; int css_flex_debug = 0; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ #define REJECT reject_used_but_not_detected #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *csstext; #line 1 "css.grammar" #line 2083 "lex.css.c" #define INITIAL 0 #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way * down here because we want the user's section 1 to have been scanned first. * The user has a chance to override it with an option. */ #include <unistd.h> #endif #ifndef YY_EXTRA_TYPE #define YY_EXTRA_TYPE void * #endif static int yy_init_globals (void ); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ int csslex_destroy (void ); int cssget_debug (void ); void cssset_debug (int debug_flag ); YY_EXTRA_TYPE cssget_extra (void ); void cssset_extra (YY_EXTRA_TYPE user_defined ); FILE *cssget_in (void ); void cssset_in (FILE * in_str ); FILE *cssget_out (void ); void cssset_out (FILE * out_str ); yy_size_t cssget_leng (void ); char *cssget_text (void ); int cssget_lineno (void ); void cssset_lineno (int line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. */ #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus extern "C" int csswrap (void ); #else extern int csswrap (void ); #endif #endif #ifndef yytext_ptr static void yy_flex_strncpy (char *,yyconst char *,int ); #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * ); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void ); #else static int input (void ); #endif #endif /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE #define YY_READ_BUF_SIZE 8192 #endif /* Copy whatever the last rule matched to the standard output. */ #ifndef ECHO /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ #define ECHO fwrite( csstext, cssleng, 1, cssout ) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT #define YY_INPUT(buf,result,max_size) \ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ yy_size_t n; \ for ( n = 0; n < max_size && \ (c = getc( cssin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ if ( c == '\n' ) \ buf[n++] = (char) c; \ if ( c == EOF && ferror( cssin ) ) \ YY_FATAL_ERROR( "input in flex scanner failed" ); \ result = n; \ } \ else \ { \ errno=0; \ while ( (result = fread(buf, 1, max_size, cssin))==0 && ferror(cssin)) \ { \ if( errno != EINTR) \ { \ YY_FATAL_ERROR( "input in flex scanner failed" ); \ break; \ } \ errno=0; \ clearerr(cssin); \ } \ }\ \ #endif /* No semi-colon after return; correct usage is to write "yyterminate();" - * we don't want an extra ';' after the "return" because that will cause * some compilers to complain about unreachable statements. */ #ifndef yyterminate #define yyterminate() return YY_NULL #endif /* Number of entries by which start-condition stack grows. */ #ifndef YY_START_STACK_INCR #define YY_START_STACK_INCR 25 #endif /* Report a fatal error. */ #ifndef YY_FATAL_ERROR #define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) #endif /* end tables serialization structures and prototypes */ /* Default declaration of generated scanner - a define so the user can * easily add parameters. */ #ifndef YY_DECL #define YY_DECL_IS_OURS 1 extern int csslex (void); #define YY_DECL int csslex (void) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after csstext and cssleng * have been set up. */ #ifndef YY_USER_ACTION #define YY_USER_ACTION #endif /* Code executed at the end of each rule. */ #ifndef YY_BREAK #define YY_BREAK break; #endif #define YY_RULE_SETUP \ YY_USER_ACTION /** The main scanner function which does all the work. */ YY_DECL { register yy_state_type yy_current_state; register char *yy_cp, *yy_bp; register int yy_act; #line 21 "css.grammar" #line 2266 "lex.css.c" if ( !(yy_init) ) { (yy_init) = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif if ( ! (yy_start) ) (yy_start) = 1; /* first start state */ if ( ! cssin ) cssin = stdin; if ( ! cssout ) cssout = stdout; if ( ! YY_CURRENT_BUFFER ) { cssensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = css_create_buffer(cssin,YY_BUF_SIZE ); } css_load_buffer_state( ); } while ( 1 ) /* loops until end-of-file is reached */ { yy_cp = (yy_c_buf_p); /* Support of csstext. */ *yy_cp = (yy_hold_char); /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; yy_current_state = (yy_start); yy_match: do { register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 370 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } while ( yy_base[yy_current_state] != 6624 ); yy_find_action: yy_act = yy_accept[yy_current_state]; if ( yy_act == 0 ) { /* have to back up */ yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); yy_act = yy_accept[yy_current_state]; } YY_DO_BEFORE_ACTION; do_action: /* This label is used only to access EOF actions. */ switch ( yy_act ) { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ *yy_cp = (yy_hold_char); yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); goto yy_find_action; case 1: /* rule 1 can match eol */ YY_RULE_SETUP #line 23 "css.grammar" YY_BREAK case 2: /* rule 2 can match eol */ YY_RULE_SETUP #line 25 "css.grammar" /* ignore comments */ YY_BREAK case 3: YY_RULE_SETUP #line 27 "css.grammar" YY_BREAK case 4: YY_RULE_SETUP #line 28 "css.grammar" YY_BREAK case 5: YY_RULE_SETUP #line 29 "css.grammar" YY_BREAK case 6: YY_RULE_SETUP #line 30 "css.grammar" YY_BREAK case 7: /* rule 7 can match eol */ YY_RULE_SETUP #line 32 "css.grammar" {cssConsume(csstext, CSSSTRING);} YY_BREAK case 8: /* rule 8 can match eol */ YY_RULE_SETUP #line 34 "css.grammar" {cssConsume(csstext, CSSIDENT);} YY_BREAK case 9: /* rule 9 can match eol */ YY_RULE_SETUP #line 36 "css.grammar" {cssConsume(csstext, CSSHASH);} YY_BREAK case 10: YY_RULE_SETUP #line 38 "css.grammar" {cssConsume(csstext, CSSIMPORT);} YY_BREAK case 11: YY_RULE_SETUP #line 39 "css.grammar" YY_BREAK case 12: YY_RULE_SETUP #line 40 "css.grammar" {cssConsume(csstext, CSSMEDIA);} YY_BREAK case 13: YY_RULE_SETUP #line 41 "css.grammar" YY_BREAK case 14: YY_RULE_SETUP #line 42 "css.grammar" YY_BREAK case 15: YY_RULE_SETUP #line 43 "css.grammar" YY_BREAK case 16: YY_RULE_SETUP #line 45 "css.grammar" YY_BREAK case 17: YY_RULE_SETUP #line 47 "css.grammar" {cssConsume(csstext, CSSEMS);} YY_BREAK case 18: YY_RULE_SETUP #line 48 "css.grammar" {cssConsume(csstext, CSSEXS);} YY_BREAK case 19: YY_RULE_SETUP #line 49 "css.grammar" {cssConsume(csstext, CSSLENGTH);} YY_BREAK case 20: YY_RULE_SETUP #line 50 "css.grammar" {cssConsume(csstext, CSSLENGTH);} YY_BREAK case 21: YY_RULE_SETUP #line 51 "css.grammar" {cssConsume(csstext, CSSLENGTH);} YY_BREAK case 22: YY_RULE_SETUP #line 52 "css.grammar" {cssConsume(csstext, CSSLENGTH);} YY_BREAK case 23: YY_RULE_SETUP #line 53 "css.grammar" {cssConsume(csstext, CSSLENGTH);} YY_BREAK case 24: YY_RULE_SETUP #line 54 "css.grammar" {cssConsume(csstext, CSSLENGTH);} YY_BREAK case 25: YY_RULE_SETUP #line 55 "css.grammar" {cssConsume(csstext, CSSANGLE);} YY_BREAK case 26: YY_RULE_SETUP #line 56 "css.grammar" {cssConsume(csstext, CSSANGLE);} YY_BREAK case 27: YY_RULE_SETUP #line 57 "css.grammar" {cssConsume(csstext, CSSANGLE);} YY_BREAK case 28: YY_RULE_SETUP #line 58 "css.grammar" {cssConsume(csstext, CSSTIME);} YY_BREAK case 29: YY_RULE_SETUP #line 59 "css.grammar" {cssConsume(csstext, CSSTIME);} YY_BREAK case 30: YY_RULE_SETUP #line 60 "css.grammar" {cssConsume(csstext, CSSFREQ);} YY_BREAK case 31: YY_RULE_SETUP #line 61 "css.grammar" {cssConsume(csstext, CSSFREQ);} YY_BREAK case 32: /* rule 32 can match eol */ YY_RULE_SETUP #line 62 "css.grammar" {cssConsume(csstext, CSSDIMEN);} YY_BREAK case 33: YY_RULE_SETUP #line 63 "css.grammar" {cssConsume(csstext, CSSPERCENTAGE);} YY_BREAK case 34: YY_RULE_SETUP #line 64 "css.grammar" {cssConsume(csstext, CSSNUMBER);} YY_BREAK case 35: /* rule 35 can match eol */ YY_RULE_SETUP #line 66 "css.grammar" {cssConsume(csstext, CSSURI);} YY_BREAK case 36: /* rule 36 can match eol */ YY_RULE_SETUP #line 67 "css.grammar" {cssConsume(csstext, CSSURI);} YY_BREAK case 37: /* rule 37 can match eol */ YY_RULE_SETUP #line 68 "css.grammar" {cssConsume(csstext, CSSFUNCTION);} YY_BREAK case 38: YY_RULE_SETUP #line 70 "css.grammar" {cssConsume(csstext, CSSUNICODERANGE);} YY_BREAK case 39: YY_RULE_SETUP #line 71 "css.grammar" {cssConsume(csstext, CSSUNICODERANGE);} YY_BREAK case 40: YY_RULE_SETUP #line 73 "css.grammar" {cssConsume(csstext, CSSUNKNOWN);} YY_BREAK case 41: YY_RULE_SETUP #line 75 "css.grammar" ECHO; YY_BREAK #line 2563 "lex.css.c" case YY_STATE_EOF(INITIAL): yyterminate(); case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ *yy_cp = (yy_hold_char); YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) { /* We're scanning a new file or input source. It's * possible that this happened because the user * just pointed cssin at a new source and called * csslex(). If so, then we have to assure * consistency between YY_CURRENT_BUFFER and our * globals. Here is the right place to do so, because * this is the first action (other than possibly a * back-up) that will match for the new input source. */ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = cssin; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } /* Note that here we test for yy_c_buf_p "<=" to the position * of the first EOB in the buffer, since yy_c_buf_p will * already have been incremented past the NUL character * (since all states make transitions on EOB to the * end-of-buffer state). Contrast this with the test * in input(). */ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) { /* This was really a NUL. */ yy_state_type yy_next_state; (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state( ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have * yy_get_previous_state() go ahead and do it * for us because it doesn't know how to deal * with the possibility of jamming (and we don't * want to build jamming into it because then it * will run more slowly). */ yy_next_state = yy_try_NUL_trans( yy_current_state ); yy_bp = (yytext_ptr) + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ yy_cp = ++(yy_c_buf_p); yy_current_state = yy_next_state; goto yy_match; } else { yy_cp = (yy_c_buf_p); goto yy_find_action; } } else switch ( yy_get_next_buffer( ) ) { case EOB_ACT_END_OF_FILE: { (yy_did_buffer_switch_on_eof) = 0; if ( csswrap( ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up * csstext, we can now set up * yy_c_buf_p so that if some total * hoser (like flex itself) wants to * call the scanner after we return the * YY_NULL, it'll still work - another * YY_NULL will get returned. */ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; } else { if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state( ); yy_cp = (yy_c_buf_p); yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: (yy_c_buf_p) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; yy_current_state = yy_get_previous_state( ); yy_cp = (yy_c_buf_p); yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_find_action; } break; } default: YY_FATAL_ERROR( "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ } /* end of csslex */ /* yy_get_next_buffer - try to read in a new buffer * * Returns a code representing an action: * EOB_ACT_LAST_MATCH - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ static int yy_get_next_buffer (void) { register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; register char *source = (yytext_ptr); register int number_to_move, i; int ret_val; if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. */ return EOB_ACT_END_OF_FILE; } else { /* We matched some text prior to the EOB, first * process it. */ return EOB_ACT_LAST_MATCH; } } /* Try to read more data. */ /* First move last chars to start of buffer. */ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; else { yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ YY_BUFFER_STATE b = YY_CURRENT_BUFFER; int yy_c_buf_p_offset = (int) ((yy_c_buf_p) - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { yy_size_t new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; else b->yy_buf_size *= 2; b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ cssrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); } else /* Can't grow it, we don't own it. */ b->yy_ch_buf = 0; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; } if ( num_to_read > YY_READ_BUF_SIZE ) num_to_read = YY_READ_BUF_SIZE; /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), (yy_n_chars), num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } if ( (yy_n_chars) == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; cssrestart(cssin ); } else { ret_val = EOB_ACT_LAST_MATCH; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; } } else ret_val = EOB_ACT_CONTINUE_SCAN; if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cssrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } (yy_n_chars) += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ static yy_state_type yy_get_previous_state (void) { register yy_state_type yy_current_state; register char *yy_cp; yy_current_state = (yy_start); for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 370 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; } return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character * * synopsis * next_state = yy_try_NUL_trans( current_state ); */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { register int yy_is_jam; register char *yy_cp = (yy_c_buf_p); register YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 370 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_is_jam = (yy_current_state == 369); return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void) #else static int input (void) #endif { int c; *(yy_c_buf_p) = (yy_hold_char); if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) /* This was really a NUL. */ *(yy_c_buf_p) = '\0'; else { /* need more input */ yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() * sees that we've accumulated a * token and flags that we need to * try matching the token before * proceeding. But for input(), * there's no matching to consider. * So convert the EOB_ACT_LAST_MATCH * to EOB_ACT_END_OF_FILE. */ /* Reset buffer status. */ cssrestart(cssin ); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { if ( csswrap( ) ) return 0; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; #ifdef __cplusplus return yyinput(); #else return input(); #endif } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + offset; break; } } } c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ *(yy_c_buf_p) = '\0'; /* preserve csstext */ (yy_hold_char) = *++(yy_c_buf_p); return c; } #endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. * * @note This function does not reset the start condition to @c INITIAL . */ void cssrestart (FILE * input_file ) { if ( ! YY_CURRENT_BUFFER ){ cssensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = css_create_buffer(cssin,YY_BUF_SIZE ); } css_init_buffer(YY_CURRENT_BUFFER,input_file ); css_load_buffer_state( ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. * */ void css_switch_to_buffer (YY_BUFFER_STATE new_buffer ) { /* TODO. We should be able to replace this entire function body * with * csspop_buffer_state(); * csspush_buffer_state(new_buffer); */ cssensure_buffer_stack (); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } // This line looks to be a manual fix from flex output... Restore if you regenerate the file. if (yy_buffer_stack) { YY_CURRENT_BUFFER_LVALUE = new_buffer; } css_load_buffer_state( ); /* We don't actually know whether we did this switch during * EOF (csswrap()) processing, but the only time this flag * is looked at is after csswrap() is called, so it's safe * to go ahead and always set it. */ (yy_did_buffer_switch_on_eof) = 1; } static void css_load_buffer_state (void) { (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; cssin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; (yy_hold_char) = *(yy_c_buf_p); } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. * * @return the allocated buffer state. */ YY_BUFFER_STATE css_create_buffer (FILE * file, int size ) { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) cssalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in css_create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) cssalloc(b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in css_create_buffer()" ); b->yy_is_our_buffer = 1; css_init_buffer(b,file ); return b; } /** Destroy the buffer. * @param b a buffer created with css_create_buffer() * */ void css_delete_buffer (YY_BUFFER_STATE b ) { if ( ! b ) return; if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) cssfree((void *) b->yy_ch_buf ); cssfree((void *) b ); } #ifndef __cplusplus extern int isatty (int ); #endif /* __cplusplus */ /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a cssrestart() or at EOF. */ static void css_init_buffer (YY_BUFFER_STATE b, FILE * file ) { int oerrno = errno; css_flush_buffer(b ); b->yy_input_file = file; b->yy_fill_buffer = 1; /* If b is the current buffer, then css_init_buffer was _probably_ * called from cssrestart() or through yy_get_next_buffer. * In that case, we don't want to reset the lineno or column. */ if (b != YY_CURRENT_BUFFER){ b->yy_bs_lineno = 1; b->yy_bs_column = 0; } b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * */ void css_flush_buffer (YY_BUFFER_STATE b ) { if ( ! b ) return; b->yy_n_chars = 0; /* We always need two end-of-buffer characters. The first causes * a transition to the end-of-buffer state. The second causes * a jam in that state. */ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; b->yy_buf_pos = &b->yy_ch_buf[0]; b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) css_load_buffer_state( ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. * */ void csspush_buffer_state (YY_BUFFER_STATE new_buffer ) { if (new_buffer == NULL) return; cssensure_buffer_stack(); /* This block is copied from css_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) (yy_buffer_stack_top)++; // This line looks to be a manual fix from flex output... Restore if you regenerate the file. if (yy_buffer_stack) { YY_CURRENT_BUFFER_LVALUE = new_buffer; } /* copied from css_switch_to_buffer. */ css_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * */ void csspop_buffer_state (void) { if (!YY_CURRENT_BUFFER) return; css_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; if ((yy_buffer_stack_top) > 0) --(yy_buffer_stack_top); if (YY_CURRENT_BUFFER) { css_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ static void cssensure_buffer_stack (void) { yy_size_t num_to_alloc; if (!(yy_buffer_stack)) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; const yy_size_t ptr_size = sizeof(struct yy_buffer_state*); const yy_size_t size_to_alloc = ptr_size /* * num_to_alloc */; (yy_buffer_stack) = (struct yy_buffer_state**)cssalloc(size_to_alloc); /* flex generates this, but the above 4 lines were here before, so I'm keeping them as is. * it would sure seem like num_to_alloc isn't getting set as it should in the above (yy_buffer_stack) = (struct yy_buffer_state**)cssalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); */ if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in cssensure_buffer_stack()" ); memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; } if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)cssrealloc ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in cssensure_buffer_stack()" ); /* zero only the new slots.*/ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE css_scan_buffer (char * base, yy_size_t size ) { YY_BUFFER_STATE b; if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; b = (YY_BUFFER_STATE) cssalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in css_scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; b->yy_input_file = 0; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; css_switch_to_buffer(b ); return b; } /** Setup the input buffer state to scan a string. The next call to csslex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * css_scan_bytes() instead. */ YY_BUFFER_STATE css_scan_string (yyconst char * yystr ) { return css_scan_bytes(yystr,strlen(yystr) ); } /** Setup the input buffer state to scan the given bytes. The next call to csslex() will * scan from a @e copy of @a bytes. * @param bytes the byte buffer to scan * @param len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE css_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n, i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; buf = (char *) cssalloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in css_scan_bytes()" ); for ( i = 0; i < _yybytes_len; ++i ) buf[i] = yybytes[i]; buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = css_scan_buffer(buf,n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in css_scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. */ b->yy_is_our_buffer = 1; return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif static void yy_fatal_error (yyconst char* msg ) { (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless #define yyless(n) \ do \ { \ /* Undo effects of setting up csstext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ csstext[cssleng] = (yy_hold_char); \ (yy_c_buf_p) = csstext + yyless_macro_arg; \ (yy_hold_char) = *(yy_c_buf_p); \ *(yy_c_buf_p) = '\0'; \ cssleng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ /** Get the current line number. * */ int cssget_lineno (void) { return csslineno; } /** Get the input stream. * */ FILE *cssget_in (void) { return cssin; } /** Get the output stream. * */ FILE *cssget_out (void) { return cssout; } /** Get the length of the current token. * */ yy_size_t cssget_leng (void) { return cssleng; } /** Get the current token. * */ char *cssget_text (void) { return csstext; } /** Set the current line number. * @param line_number * */ void cssset_lineno (int line_number ) { csslineno = line_number; } /** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. * * @see css_switch_to_buffer */ void cssset_in (FILE * in_str ) { cssin = in_str ; } void cssset_out (FILE * out_str ) { cssout = out_str ; } int cssget_debug (void) { return css_flex_debug; } void cssset_debug (int bdebug ) { css_flex_debug = bdebug ; } static int yy_init_globals (void) { /* Initialization is the same as for the non-reentrant scanner. * This function is called from csslex_destroy(), so don't allocate here. */ (yy_buffer_stack) = 0; (yy_buffer_stack_top) = 0; (yy_buffer_stack_max) = 0; (yy_c_buf_p) = (char *) 0; (yy_init) = 0; (yy_start) = 0; /* Defined in main.c */ #ifdef YY_STDINIT cssin = stdin; cssout = stdout; #else cssin = (FILE *) 0; cssout = (FILE *) 0; #endif /* For future reference: Set errno on error, since we are called by * csslex_init() */ return 0; } /* csslex_destroy is for both reentrant and non-reentrant scanners. */ int csslex_destroy (void) { /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ css_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; csspop_buffer_state(); } /* Destroy the stack itself. */ cssfree((yy_buffer_stack) ); (yy_buffer_stack) = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * csslex() is called, initialization will occur. */ yy_init_globals( ); return 0; } /* * Internal utility routines. */ #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) { register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * s ) { register int n; for ( n = 0; s[n]; ++n ) ; return n; } #endif void *cssalloc (yy_size_t size ) { return (void *) malloc( size ); } void *cssrealloc (void * ptr, yy_size_t size ) { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter * because both ANSI C and C++ allow castless assignment from * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size ); } void cssfree (void * ptr ) { free( (char *) ptr ); /* see cssrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" #line 75 "css.grammar" int csswrap(void){return 1;}
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/CSSTokens.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include <stdio.h> typedef enum { CSSFIRST_TOKEN = 0x100, CSSSTRING = CSSFIRST_TOKEN, CSSIDENT, CSSHASH, CSSEMS, CSSEXS, CSSLENGTH, CSSANGLE, CSSTIME, CSSFREQ, CSSDIMEN, CSSPERCENTAGE, CSSNUMBER, CSSURI, CSSFUNCTION, CSSUNICODERANGE, CSSIMPORT, CSSUNKNOWN, CSSMEDIA } CssParserCodes; extern const char* cssnames[]; #ifndef YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T typedef void* yyscan_t; #endif extern FILE *cssin; int csslex(void); int cssConsume(char* text, int token); int cssget_lineno(void);
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/CSSTokens.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif const char* cssnames[] = { "STRING", "IDENT", "HASH", "EMS", "EXS", "LENGTH", "ANGLE", "TIME", "FREQ", "DIMEN", "PERCENTAGE", "NUMBER", "URI", "FUNCTION", "UNICODERANGE", "CSSIMPORT", "UNKNOWN", };
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NICSSParser.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> extern NSString* const kPropertyOrderKey; extern NSString* const kDependenciesSelectorKey; @protocol NICSSParserDelegate; /** * An Objective-C wrapper for the flex CSS parser. * * @ingroup NimbusCSS * * Generates a dictionary of raw CSS rules from a given CSS file. * * It is recommended that you do NOT use this object directly. Use NIStylesheet instead. * * Terminology note: CSS selectors are referred to as "scopes" to avoid confusion with * Objective-C selectors. * * This object is not thread-safe. */ @interface NICSSParser : NSObject { @private // CSS state NSMutableDictionary* _mutatingRuleset; NSMutableDictionary* _rulesets; NSMutableArray* _mutatingScope; NSMutableArray* _scopesForActiveRuleset; NSString* _currentPropertyName; NSMutableArray* _importedFilenames; BOOL droppingCurrentRules; union { struct { int InsideRuleset : 1; // Within `ruleset {...}` int InsideProperty : 1; // Defining a `property: ...` int InsideFunction : 1; // Within a `function(...)` int InsideMedia : 1; // within `@media {}` int ReadingMedia : 1; // got @media start, waiting for rules and a brace } Flags; int _data; } _state; // Parser state NSString* _lastTokenText; int _lastToken; // Result state BOOL _didFailToParse; } - (NSDictionary *)dictionaryForPath:(NSString *)path pathPrefix:(NSString *)pathPrefix delegate:(id<NICSSParserDelegate>)delegate; - (NSDictionary *)dictionaryForPath:(NSString *)path pathPrefix:(NSString *)rootPath; - (NSDictionary *)dictionaryForPath:(NSString *)path; @property (nonatomic, readonly, assign) BOOL didFailToParse; @end /** * The delegate protocol for NICSSParser. */ @protocol NICSSParserDelegate <NSObject> @required /** * The implementor may use this method to change the filename that will be used to load * the CSS file from disk. * * If nil is returned then the given filename will be used. * * Example: * This is used by the Chameleon observer to hash filenames with md5, effectively flattening * the path structure so that the files can be accessed without creating subdirectories. */ - (NSString *)cssParser:(NICSSParser *)parser pathFromPath:(NSString *)path; @end /** * Reads a CSS file from a given path and returns a dictionary of raw CSS rule sets. * * If a pathPrefix is provided then all paths will be prefixed with this value. * * For example, if a path prefix of "/bundle/css" is given and a CSS file has the * statement "@import url('user/profile.css')", the loaded file will be * "/bundle/css/user/profile.css". * * @fn NICSSParser::dictionaryForPath:pathPrefix:delegate: * @param path The path of the file to be read. * @param pathPrefix [optional] A prefix path that will be prepended to the given path * as well as any imported files. * @param delegate [optional] A delegate that can reprocess paths. * @returns A dictionary mapping CSS scopes to dictionaries of property names to values. */ /** * @fn NICSSParser::dictionaryForPath:pathPrefix: * @sa NICSSParser::dictionaryForPath:pathPrefix:delegate: */ /** * @fn NICSSParser::dictionaryForPath: * @sa NICSSParser::dictionaryForPath:pathPrefix:delegate: */ /** * Will be YES after retrieving a dictionary if the parser failed to parse the file in any way. * * @fn NICSSParser::didFailToParse */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NICSSParser.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NICSSParser.h" #import "CSSTokens.h" #import "NimbusCore.h" #import <pthread.h> #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static pthread_mutex_t gMutex = PTHREAD_MUTEX_INITIALIZER; NSString* const kPropertyOrderKey = @"__kRuleSetOrder__"; NSString* const kDependenciesSelectorKey = @"__kDependencies__"; // Damn you, flex. Due to the nature of flex we can only have one active parser at any given time. NICSSParser* gActiveParser = nil; int cssConsume(char* text, int token); @interface NICSSParser() - (void)consumeToken:(int)token text:(char*)text; @end // The entry point of the flex css parser. // Flex is inherently designed to operate as a singleton. int cssConsume(char* text, int token) { [gActiveParser consumeToken:token text:text]; return 0; } @implementation NICSSParser - (void)shutdown { _rulesets = nil; _scopesForActiveRuleset = nil; _mutatingScope = nil; _mutatingRuleset = nil; _currentPropertyName = nil; _importedFilenames = nil; _lastTokenText = nil; } - (void)setFailFlag { if (!self.didFailToParse) { _didFailToParse = YES; [self shutdown]; } } - (void)commitCurrentSelector { [_scopesForActiveRuleset addObject:[_mutatingScope componentsJoinedByString:@" "]]; [_mutatingScope removeAllObjects]; } - (void)consumeToken:(int)token text:(char*)text { if (_didFailToParse) { return; } NSString* textAsString = [[NSString alloc] initWithCString:text encoding:NSUTF8StringEncoding]; NSString* lowercaseTextAsString = [textAsString lowercaseString]; switch (token) { case CSSMEDIA: // @media { } if (_state.Flags.InsideMedia || _state.Flags.ReadingMedia) { [self setFailFlag]; } _state.Flags.ReadingMedia = YES; droppingCurrentRules = YES; // at least one must match to undo this break; case CSSHASH: // #{name} case CSSIDENT: { // {ident}(:{ident})? if (_state.Flags.ReadingMedia) { if (!droppingCurrentRules) { // No point in running these checks if we've already decided break; } else if ([textAsString caseInsensitiveCompare:@"ipad"] == NSOrderedSame) { if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { droppingCurrentRules = NO; } break; } else if ([textAsString caseInsensitiveCompare:@"iphone"] == NSOrderedSame) { if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { droppingCurrentRules = NO; } break; } else if ([textAsString caseInsensitiveCompare:@"retina"] == NSOrderedSame) { if ([UIScreen mainScreen].scale != 1.0) { droppingCurrentRules = NO; } break; } else if ([textAsString caseInsensitiveCompare:@"nonretina"] == NSOrderedSame) { if ([UIScreen mainScreen].scale == 1.0) { droppingCurrentRules = NO; } break; } else if ([textAsString caseInsensitiveCompare:@"ipad-retina"] == NSOrderedSame) { if ([UIScreen mainScreen].scale != 1.0 && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { droppingCurrentRules = NO; } break; } else if ([textAsString caseInsensitiveCompare:@"ipad-nonretina"] == NSOrderedSame) { if ([UIScreen mainScreen].scale == 1.0 && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { droppingCurrentRules = NO; } break; } else if ([textAsString caseInsensitiveCompare:@"iphone-retina"] == NSOrderedSame) { if ([UIScreen mainScreen].scale != 1.0 && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { droppingCurrentRules = NO; } break; } else if ([textAsString caseInsensitiveCompare:@"iphone-nonretina"] == NSOrderedSame) { if ([UIScreen mainScreen].scale == 1.0 && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { droppingCurrentRules = NO; } break; } } else if (_state.Flags.InsideRuleset) { NIDASSERT(nil != _mutatingRuleset); if (nil == _mutatingRuleset) { [self setFailFlag]; } // Treat CSSIDENT as a new property if we're not already defining one. if (CSSIDENT == token && !_state.Flags.InsideProperty) { // Properties are case insensitive. _currentPropertyName = lowercaseTextAsString; NSMutableArray* ruleSetOrder = [_mutatingRuleset objectForKey:kPropertyOrderKey]; [ruleSetOrder addObject:_currentPropertyName]; // Clear any existing values for the given property. NSMutableArray* values = [[NSMutableArray alloc] init]; [_mutatingRuleset setObject:values forKey:_currentPropertyName]; } else { // This is a value for the active property; add it. NIDASSERT(nil != _currentPropertyName); if (nil != _currentPropertyName) { NSMutableArray* values = [_mutatingRuleset objectForKey:_currentPropertyName]; [values addObject:lowercaseTextAsString]; } else { [self setFailFlag]; } } } else { // if not inside a rule set... [_mutatingScope addObject:textAsString]; // Ensure that we're not modifying a property. _currentPropertyName = nil; } break; } case CSSFUNCTION: { // Functions can only exist within properties. if (_state.Flags.InsideProperty) { _state.Flags.InsideFunction = YES; NIDASSERT(nil != _currentPropertyName); if (nil != _currentPropertyName) { NSMutableArray* values = [_mutatingRuleset objectForKey:_currentPropertyName]; [values addObject:lowercaseTextAsString]; } else { [self setFailFlag]; } } break; } case CSSSTRING: case CSSEMS: case CSSEXS: case CSSLENGTH: case CSSANGLE: case CSSTIME: case CSSFREQ: case CSSDIMEN: case CSSPERCENTAGE: case CSSNUMBER: case CSSURI: { if (_lastToken == CSSIMPORT && token == CSSURI) { NSInteger prefixLength = @"url(\"".length; NSString* filename = [textAsString substringWithRange:NSMakeRange(prefixLength, textAsString.length - prefixLength - 2)]; [_importedFilenames addObject:filename]; } else { NIDASSERT(nil != _currentPropertyName); if (nil != _currentPropertyName) { NSMutableArray* values = [_mutatingRuleset objectForKey:_currentPropertyName]; [values addObject:textAsString]; } else { [self setFailFlag]; } } break; } // Parse individual characters. case CSSUNKNOWN: { switch (text[0]) { // Commit the current selector and start a new one. case ',': { if (_state.Flags.ReadingMedia) { // Ignore, more media coming } else if (!_state.Flags.InsideRuleset) { [self commitCurrentSelector]; } break; } // Start a new rule set. case '{': { if (_state.Flags.ReadingMedia) { _state.Flags.InsideMedia = YES; _state.Flags.ReadingMedia = NO; break; } NIDASSERT(nil != _mutatingScope); if ([_mutatingScope count] > 0 && !_state.Flags.InsideRuleset && !_state.Flags.InsideFunction) { [self commitCurrentSelector]; _state.Flags.InsideRuleset = YES; _state.Flags.InsideFunction = NO; _mutatingRuleset = [[NSMutableDictionary alloc] init]; [_mutatingRuleset setObject:[NSMutableArray array] forKey:kPropertyOrderKey]; } else { [self setFailFlag]; } break; } // Commit an existing rule set. case '}': { if (_state.Flags.InsideMedia && !_mutatingRuleset) { // End of a media tag _state.Flags.InsideMedia = NO; droppingCurrentRules = NO; } else { if (!droppingCurrentRules) { for (NSString* name in _scopesForActiveRuleset) { NSMutableDictionary* existingProperties = [_rulesets objectForKey:name]; if (nil == existingProperties) { NSMutableDictionary* ruleSet = [_mutatingRuleset mutableCopy]; [_rulesets setObject:ruleSet forKey:name]; } else { // Properties already exist, so overwrite them. // Merge the orders. { NSMutableArray* order = [existingProperties objectForKey:kPropertyOrderKey]; [order addObjectsFromArray:[_mutatingRuleset objectForKey:kPropertyOrderKey]]; [_mutatingRuleset setObject:order forKey:kPropertyOrderKey]; } for (NSString* key in _mutatingRuleset) { [existingProperties setObject:[_mutatingRuleset objectForKey:key] forKey:key]; } // Add the order of the new properties. NSMutableArray* order = [existingProperties objectForKey:kPropertyOrderKey]; [order addObjectsFromArray:[_mutatingRuleset objectForKey:kPropertyOrderKey]]; } } } _mutatingRuleset = nil; [_scopesForActiveRuleset removeAllObjects]; _state.Flags.InsideRuleset = NO; _state.Flags.InsideProperty = NO; _state.Flags.InsideFunction = NO; } break; } case ':': { // Defining a property value. if (_state.Flags.InsideRuleset) { _state.Flags.InsideProperty = YES; } break; } case ')': { if (_state.Flags.InsideFunction && nil != _currentPropertyName) { NSMutableArray* values = [_mutatingRuleset objectForKey:_currentPropertyName]; [values addObject:lowercaseTextAsString]; } _state.Flags.InsideFunction = NO; break; } case ';': { // Committing a property value. if (_state.Flags.InsideRuleset) { _state.Flags.InsideProperty = NO; } break; } } break; } } _lastTokenText = textAsString; _lastToken = token; } - (void)setup { [self shutdown]; _rulesets = [[NSMutableDictionary alloc] init]; _scopesForActiveRuleset = [[NSMutableArray alloc] init]; _mutatingScope = [[NSMutableArray alloc] init]; _importedFilenames = [[NSMutableArray alloc] init]; } - (void)parseFileAtPath:(NSString *)path { // flex is not thread-safe so we force it to be by creating a single-access lock here. pthread_mutex_lock(&gMutex); { cssin = fopen([path UTF8String], "r"); gActiveParser = self; csslex(); fclose(cssin); } pthread_mutex_unlock(&gMutex); } - (NSDictionary *)mergeCompositeRulesets:(NSMutableArray *)compositeRulesets dependencyFilenames:(NSSet *)dependencyFilenames { NIDASSERT([compositeRulesets count] > 0); if ([compositeRulesets count] == 0) { return nil; } NSDictionary* result = nil; if ([compositeRulesets count] == 1) { if ([dependencyFilenames count] > 0) { [[compositeRulesets objectAtIndex:0] setObject:dependencyFilenames forKey:kDependenciesSelectorKey]; } result = [[compositeRulesets objectAtIndex:0] copy]; } else { NSMutableDictionary* mergedResult = [compositeRulesets lastObject]; [compositeRulesets removeLastObject]; // Merge all of the rulesets into one. for (NSDictionary* ruleSet in [compositeRulesets reverseObjectEnumerator]) { for (NSString* scope in ruleSet) { if (![mergedResult objectForKey:scope]) { // New scope means we can just add it. [mergedResult setObject:[ruleSet objectForKey:scope] forKey:scope]; } else { // Existing scope means we need to overwrite existing properties. NSMutableDictionary* mergedScopeProperties = [mergedResult objectForKey:scope]; NSMutableDictionary* properties = [ruleSet objectForKey:scope]; for (NSString* propertyName in properties) { if (!(nil != [mergedScopeProperties objectForKey:propertyName] && [propertyName isEqualToString:kPropertyOrderKey])) { // Overwrite the existing property's value. [mergedScopeProperties setObject:[properties objectForKey:propertyName] forKey:propertyName]; } else { // Append the property order. NSMutableArray *order = [mergedScopeProperties objectForKey:kPropertyOrderKey]; [order addObjectsFromArray:[properties objectForKey:kPropertyOrderKey]]; } } } } } if ([dependencyFilenames count] > 0) { [mergedResult setObject:dependencyFilenames forKey:kDependenciesSelectorKey]; } result = [mergedResult copy]; } return result; } #pragma mark - Public - (NSDictionary *)dictionaryForPath:(NSString *)path { return [self dictionaryForPath:path pathPrefix:nil delegate:nil]; } - (NSDictionary *)dictionaryForPath:(NSString *)path pathPrefix:(NSString *)pathPrefix { return [self dictionaryForPath:path pathPrefix:pathPrefix delegate:nil]; } - (NSDictionary *)dictionaryForPath:(NSString *)aPath pathPrefix:(NSString *)pathPrefix delegate:(id<NICSSParserDelegate>)delegate { // Bail out early if there was no path given. if ([aPath length] == 0) { _didFailToParse = YES; return nil; } _didFailToParse = NO; NSMutableArray* compositeRulesets = [[NSMutableArray alloc] init]; // Maintain a set of filenames that we've looked at for two reasons: // 1) To avoid visiting the same CSS file twice. // 2) To collect a list of dependencies for this stylesheet. NSMutableSet* processedFilenames = [[NSMutableSet alloc] init]; // Imported CSS files will be added to the queue. NSMutableOrderedSet* filenameQueue = [NSMutableOrderedSet orderedSet]; [filenameQueue addObject:aPath]; while ([filenameQueue count] > 0) { // Om nom nom NSString* path = [filenameQueue firstObject]; [filenameQueue removeObjectAtIndex:0]; // Skip files that we've already processed in order to avoid infinite loops. if ([processedFilenames containsObject:path]) { continue; } [processedFilenames addObject:path]; // Allow the delegate to rename the file. if ([delegate respondsToSelector:@selector(cssParser:pathFromPath:)]) { NSString* reprocessedFilename = [delegate cssParser:self pathFromPath:path]; if (nil != reprocessedFilename) { path = reprocessedFilename; } } // Add the prefix, if it exists. if (pathPrefix.length > 0) { path = [pathPrefix stringByAppendingPathComponent:path]; } // Verify that the file exists. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { [self shutdown]; return nil; } [self setup]; [self parseFileAtPath:path]; if (self.didFailToParse) { break; } [filenameQueue addObjectsFromArray:_importedFilenames]; [_importedFilenames removeAllObjects]; [compositeRulesets addObject:_rulesets]; [self shutdown]; } NSDictionary* result = nil; if (!self.didFailToParse) { // processedFilenames will be the set of dependencies, so remove the initial path. [processedFilenames removeObject:aPath]; result = [self mergeCompositeRulesets:compositeRulesets dependencyFilenames:processedFilenames]; } [self shutdown]; return result; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NICSSRuleset.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> /** * Currently, for size units we only support pixels (resolution independent) * and percentage (of superview) */ typedef enum { CSS_PIXEL_UNIT, CSS_PERCENTAGE_UNIT, CSS_AUTO_UNIT } NICSSUnitType; /** * Width, height, top, left, right, bottom can be expressed in various units. */ typedef struct { NICSSUnitType type; CGFloat value; } NICSSUnit; typedef enum { NICSSButtonAdjustNone = 0, NICSSButtonAdjustHighlighted = 1, NICSSButtonAdjustDisabled = 2 } NICSSButtonAdjust; /** * A simple translator from raw CSS rulesets to Objective-C values. * * @ingroup NimbusCSS * * Objective-C values are created on-demand and cached. These ruleset objects are cached * by NIStylesheet for a given CSS scope. When a memory warning is received, all ruleset objects * are removed from every stylesheet. */ @interface NICSSRuleset : NSObject { @private NSMutableDictionary* _ruleset; UIColor* _textColor; UIColor* _highlightedTextColor; UITextAlignment _textAlignment; UIFont* _font; UIColor* _textShadowColor; CGSize _textShadowOffset; NSLineBreakMode _lineBreakMode; NSInteger _numberOfLines; CGFloat _minimumFontSize; BOOL _adjustsFontSize; UIBaselineAdjustment _baselineAdjustment; CGFloat _opacity; UIColor* _backgroundColor; NSString* _backgroundImage; UIEdgeInsets _backgroundStretchInsets; NSString* _image; CGFloat _borderRadius; UIColor *_borderColor; CGFloat _borderWidth; UIColor *_tintColor; UIActivityIndicatorViewStyle _activityIndicatorStyle; UIViewAutoresizing _autoresizing; UITableViewCellSeparatorStyle _tableViewCellSeparatorStyle; UIScrollViewIndicatorStyle _scrollViewIndicatorStyle; UITextAlignment _frameHorizontalAlign; UIViewContentMode _frameVerticalAlign; UIControlContentVerticalAlignment _verticalAlign; UIControlContentHorizontalAlignment _horizontalAlign; BOOL _visible; NICSSButtonAdjust _buttonAdjust; UIEdgeInsets _titleInsets; UIEdgeInsets _contentInsets; UIEdgeInsets _imageInsets; NSString *_textKey; NSString* _relativeToId; NICSSUnit _marginTop; NICSSUnit _marginLeft; NICSSUnit _marginRight; NICSSUnit _marginBottom; NICSSUnit _verticalPadding; NICSSUnit _horizontalPadding; NICSSUnit _width; NICSSUnit _height; NICSSUnit _top; NICSSUnit _bottom; NICSSUnit _left; NICSSUnit _right; NICSSUnit _minHeight; NICSSUnit _minWidth; NICSSUnit _maxHeight; NICSSUnit _maxWidth; union { struct { int TextColor : 1; int HighlightedTextColor: 1; int TextAlignment : 1; int Font : 1; int TextShadowColor : 1; int TextShadowOffset : 1; int LineBreakMode : 1; int NumberOfLines : 1; int MinimumFontSize : 1; int AdjustsFontSize : 1; int BaselineAdjustment : 1; int Opacity : 1; int BackgroundColor : 1; int BackgroundImage: 1; int BackgroundStretchInsets: 1; //16 int Image: 1; int BorderRadius : 1; int BorderColor : 1; int BorderWidth : 1; int TintColor : 1; int ActivityIndicatorStyle : 1; int Autoresizing : 1; int TableViewCellSeparatorStyle : 1; int ScrollViewIndicatorStyle : 1; int VerticalAlign: 1; int HorizontalAlign: 1; int Width : 1; int Height : 1; int Top : 1; int Bottom : 1; int Left : 1; // 32 int Right : 1; int FrameHorizontalAlign: 1; int FrameVerticalAlign: 1; int Visible: 1; int TitleInsets: 1; int ContentInsets: 1; int ImageInsets: 1; int RelativeToId: 1; int MarginTop: 1; int MarginLeft: 1; int MarginRight: 1; int MarginBottom: 1; int MinWidth: 1; int MinHeight: 1; int MaxWidth: 1; int MaxHeight: 1; // 48 int TextKey: 1; int ButtonAdjust: 1; int HorizontalPadding: 1; int VerticalPadding: 1; } cached; int64_t _data; } _is; } - (void)addEntriesFromDictionary:(NSDictionary *)dictionary; - (id)cssRuleForKey: (NSString*)key; - (BOOL)hasTextColor; - (UIColor *)textColor; // color - (BOOL)hasHighlightedTextColor; - (UIColor *)highlightedTextColor; - (BOOL)hasTextAlignment; - (UITextAlignment)textAlignment; // text-align - (BOOL)hasFont; - (UIFont *)font; // font, font-family, font-size, font-style, font-weight - (BOOL)hasTextShadowColor; - (UIColor *)textShadowColor; // text-shadow - (BOOL)hasTextShadowOffset; - (CGSize)textShadowOffset; // text-shadow - (BOOL)hasLineBreakMode; - (NSLineBreakMode)lineBreakMode; // -ios-line-break-mode - (BOOL)hasNumberOfLines; - (NSInteger)numberOfLines; // -ios-number-of-lines - (BOOL)hasMinimumFontSize; - (CGFloat)minimumFontSize; // -ios-minimum-font-size - (BOOL)hasAdjustsFontSize; - (BOOL)adjustsFontSize; // -ios-adjusts-font-size - (BOOL)hasBaselineAdjustment; - (UIBaselineAdjustment)baselineAdjustment; // -ios-baseline-adjustment - (BOOL)hasOpacity; - (CGFloat)opacity; // opacity - (BOOL)hasBackgroundColor; - (UIColor *)backgroundColor; // background-color - (BOOL)hasBackgroundImage; - (NSString*)backgroundImage; // background-image - (BOOL)hasBackgroundStretchInsets; - (UIEdgeInsets)backgroundStretchInsets; // -mobile-background-stretch - (BOOL)hasImage; - (NSString*)image; // -mobile-image - (BOOL)hasBorderRadius; - (CGFloat)borderRadius; // border-radius - (BOOL)hasBorderColor; - (UIColor *)borderColor; // border, border-color - (BOOL)hasBorderWidth; - (CGFloat)borderWidth; // border, border-width - (BOOL)hasWidth; - (NICSSUnit)width; // width - (BOOL)hasHeight; - (NICSSUnit)height; // height - (BOOL)hasTop; - (NICSSUnit)top; // top - (BOOL)hasBottom; - (NICSSUnit)bottom; // bottom - (BOOL)hasLeft; - (NICSSUnit)left; // left - (BOOL)hasRight; - (NICSSUnit)right; // right - (BOOL)hasMinWidth; - (NICSSUnit)minWidth; // min-width - (BOOL)hasMinHeight; - (NICSSUnit)minHeight; // min-height - (BOOL)hasMaxWidth; - (NICSSUnit)maxWidth; // max-width - (BOOL)hasMaxHeight; - (NICSSUnit)maxHeight; // max-height - (BOOL)hasVerticalAlign; - (UIControlContentVerticalAlignment)verticalAlign; // -mobile-content-valign - (BOOL)hasHorizontalAlign; - (UIControlContentHorizontalAlignment)horizontalAlign; // -mobile-content-halign - (BOOL)hasFrameHorizontalAlign; - (UITextAlignment)frameHorizontalAlign; // -mobile-halign - (BOOL)hasFrameVerticalAlign; - (UIViewContentMode)frameVerticalAlign; // -mobile-valign - (BOOL)hasTintColor; - (UIColor *)tintColor; // -ios-tint-color - (BOOL)hasActivityIndicatorStyle; - (UIActivityIndicatorViewStyle)activityIndicatorStyle; // -ios-activity-indicator-style - (BOOL)hasAutoresizing; - (UIViewAutoresizing)autoresizing; // -ios-autoresizing - (BOOL)hasTableViewCellSeparatorStyle; - (UITableViewCellSeparatorStyle)tableViewCellSeparatorStyle; // -ios-table-view-cell-separator-style - (BOOL)hasScrollViewIndicatorStyle; - (UIScrollViewIndicatorStyle)scrollViewIndicatorStyle; // -ios-scroll-view-indicator-style - (BOOL)hasVisible; - (BOOL)visible; // visibility - (BOOL)hasButtonAdjust; - (NICSSButtonAdjust)buttonAdjust; // -ios-button-adjust - (BOOL)hasTitleInsets; - (UIEdgeInsets)titleInsets; // -mobile-title-insets - (BOOL)hasContentInsets; - (UIEdgeInsets)contentInsets; // -mobile-content-insets - (BOOL)hasImageInsets; - (UIEdgeInsets)imageInsets; // -mobile-image-insets - (BOOL)hasRelativeToId; - (NSString*)relativeToId; // -mobile-relative - (BOOL)hasMarginTop; - (NICSSUnit)marginTop; // margin-top - (BOOL)hasMarginBottom; - (NICSSUnit)marginBottom; // margin-bottom - (BOOL)hasMarginLeft; - (NICSSUnit)marginLeft; // margin-left - (BOOL)hasMarginRight; - (NICSSUnit)marginRight; // margin-bottom - (BOOL)hasTextKey; - (NSString*)textKey; // -mobile-text-key - (BOOL) hasHorizontalPadding; - (NICSSUnit) horizontalPadding; // padding or -mobile-hPadding - (BOOL) hasVerticalPadding; - (NICSSUnit) verticalPadding; // padding or -mobile-vPadding @end /** * Adds a raw CSS ruleset to this ruleset object. * * @fn NICSSRuleset::addEntriesFromDictionary: */ /** * Returns YES if the ruleset has a 'color' property. * * @fn NICSSRuleset::hasTextColor */ /** * Returns the text color. * * @fn NICSSRuleset::textColor */ /** * Returns YES if the ruleset has a 'text-align' property. * * @fn NICSSRuleset::hasTextAlignment */ /** * Returns the text alignment. * * @fn NICSSRuleset::textAlignment */ /** * Returns YES if the ruleset has a value for any of the following properties: * font, font-family, font-size, font-style, font-weight. * * Note: You can't specify bold or italic with a font-family due to the way fonts are * constructed. You also can't specify a font that is both bold and italic. In order to do * either of these things you must specify the font-family that corresponds to the bold or italic * version of your font. * * @fn NICSSRuleset::hasFont */ /** * Returns the font. * * @fn NICSSRuleset::font */ /** * Returns YES if the ruleset has a 'text-shadow' property. * * @fn NICSSRuleset::hasTextShadowColor */ /** * Returns the text shadow color. * * @fn NICSSRuleset::textShadowColor */ /** * Returns YES if the ruleset has a 'text-shadow' property. * * @fn NICSSRuleset::hasTextShadowOffset */ /** * Returns the text shadow offset. * * @fn NICSSRuleset::textShadowOffset */ /** * Returns YES if the ruleset has an '-ios-line-break-mode' property. * * @fn NICSSRuleset::hasLineBreakMode */ /** * Returns the line break mode. * * @fn NICSSRuleset::lineBreakMode */ /** * Returns YES if the ruleset has an '-ios-number-of-lines' property. * * @fn NICSSRuleset::hasNumberOfLines */ /** * Returns the number of lines. * * @fn NICSSRuleset::numberOfLines */ /** * Returns YES if the ruleset has an '-ios-minimum-font-size' property. * * @fn NICSSRuleset::hasMinimumFontSize */ /** * Returns the minimum font size. * * @fn NICSSRuleset::minimumFontSize */ /** * Returns YES if the ruleset has an '-ios-adjusts-font-size' property. * * @fn NICSSRuleset::hasAdjustsFontSize */ /** * Returns the adjustsFontSize value. * * @fn NICSSRuleset::adjustsFontSize */ /** * Returns YES if the ruleset has an '-ios-baseline-adjustment' property. * * @fn NICSSRuleset::hasBaselineAdjustment */ /** * Returns the baseline adjustment. * * @fn NICSSRuleset::baselineAdjustment */ /** * Returns YES if the ruleset has an 'opacity' property. * * @fn NICSSRuleset::hasOpacity */ /** * Returns the opacity. * * @fn NICSSRuleset::opacity */ /** * Returns YES if the ruleset has a 'background-color' property. * * @fn NICSSRuleset::hasBackgroundColor */ /** * Returns the background color. * * @fn NICSSRuleset::backgroundColor */ /** * Returns YES if the ruleset has a 'border-radius' property. * * @fn NICSSRuleset::hasBorderRadius */ /** * Returns the border radius. * * @fn NICSSRuleset::borderRadius */ /** * Returns YES if the ruleset has a 'border' or 'border-color' property. * * @fn NICSSRuleset::hasBorderColor */ /** * Returns the border color. * * @fn NICSSRuleset::borderColor */ /** * Returns YES if the ruleset has a 'border' or 'border-width' property. * * @fn NICSSRuleset::hasBorderWidth */ /** * Returns the border width. * * @fn NICSSRuleset::borderWidth */ /** * Returns YES if the ruleset has an '-ios-tint-color' property. * * @fn NICSSRuleset::hasTintColor */ /** * Returns the tint color. * * @fn NICSSRuleset::tintColor */ /** * Returns YES if the ruleset has a 'width' property. * * @fn NICSSRuleset::hasWidth */ /** * Returns the width. * * @fn NICSSRuleset::width */ /** * When relativeToId is set, a view will be positioned using margin-* directives relative to the view * identified by relativeToId. You can use id notation, e.g. #MyButton, or a few selectors: * .next, .prev, .first and .last which find the obviously named siblings. Note that the mechanics or * margin are not the same as CSS, which is of course a flow layout. So you cannot, for example, * combine margin-top and margin-bottom as only margin-top will be executed. * * Relative positioning also requires that you're careful about the order in which you register views * in the engine (for now), since we will evaluate the rules immediately. TODO add some simple dependency * management to make sure we've run the right views first. * * @fn NICSSRuleset::relativeToId */ /** * In combination with relativeToId, the margin fields control how a view is positioned relative to another. * margin-top: 0 means the top of this view will be aligned to the bottom of the view identified by relativeToId. * A positive number will move this further down, and a negative number further up. A *percentage* will operate * off the height of relativeToId and modify the position relative to margin-top:0. So -100% means "align top". * A value of auto means we will align the center y of relativeToId with the center y of this view. * * @fn NICSSRuleset::margin-top */ /** * In combination with relativeToId, the margin fields control how a view is positioned relative to another. * margin-bottom: 0 means the bottom of this view will be aligned to the bottom of the view identified by relativeToId. * A positive number will move this further down, and a negative number further up. A *percentage* will operate * off the height of relativeToId and modify the position relative to margin-bottom:0. So -100% means line up the bottom * of this view with the top of relativeToId. * A value of auto means we will align the center y of relativeToId with the center y of this view. * * @fn NICSSRuleset::margin-bottom */ /** * In combination with relativeToId, the margin fields control how a view is positioned relative to another. * margin-left: 0 means the left of this view will be aligned to the right of the view identified by relativeToId. * A positive number will move this further right, and a negative number further left. A *percentage* will operate * off the width of relativeToId and modify the position relative to margin-left:0. So -100% means line up the left * of this view with the left of relativeToId. * A value of auto means we will align the center x of relativeToId with the center x of this view. * * @fn NICSSRuleset::margin-left */ /** * In combination with relativeToId, the margin fields control how a view is positioned relative to another. * margin-right: 0 means the right of this view will be aligned to the right of the view identified by relativeToId. * A positive number will move this further right, and a negative number further left. A *percentage* will operate * off the width of relativeToId and modify the position relative to margin-left:0. So -100% means line up the right * of this view with the left of relativeToId. * A value of auto means we will align the center x of relativeToId with the center x of this view. * * @fn NICSSRuleset::margin-right */ /** * Return the rule values for a particular key, such as margin-top or width. Exposing this allows you, among * other things, use the CSS to hold variable information that has an effect on the layout of the views that * cannot be expressed as a style - such as padding. * * @fn NICSSRuleset::cssRuleForKey */ /** * For views that support sizeToFit, padding will add a value to the computed size * * @fn NICSSRuleset::horizontalPadding */ /** * For views that support sizeToFit, padding will add a value to the computed size * * @fn NICSSRuleset::verticalPadding */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NICSSRuleset.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NICSSRuleset.h" #import "NICSSParser.h" #import "NimbusCore.h" // TODO selected/highlighted states for buttons #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static NSString* const kTextColorKey = @"color"; static NSString* const kHighlightedTextColorKey = @"-ios-highlighted-color"; static NSString* const kTextAlignmentKey = @"text-align"; static NSString* const kFontKey = @"font"; static NSString* const kFontSizeKey = @"font-size"; static NSString* const kFontStyleKey = @"font-style"; static NSString* const kFontWeightKey = @"font-weight"; static NSString* const kFontFamilyKey = @"font-family"; static NSString* const kTextShadowKey = @"text-shadow"; static NSString* const kLineBreakModeKey = @"-ios-line-break-mode"; static NSString* const kNumberOfLinesKey = @"-ios-number-of-lines"; static NSString* const kMinimumFontSizeKey = @"-ios-minimum-font-size"; static NSString* const kAdjustsFontSizeKey = @"-ios-adjusts-font-size"; static NSString* const kBaselineAdjustmentKey = @"-ios-baseline-adjustment"; static NSString* const kOpacityKey = @"opacity"; static NSString* const kBackgroundColorKey = @"background-color"; static NSString* const kBorderRadiusKey = @"border-radius"; static NSString* const kBorderKey = @"border"; static NSString* const kBorderColorKey = @"border-color"; static NSString* const kBorderWidthKey = @"border-width"; static NSString* const kTintColorKey = @"-ios-tint-color"; static NSString* const kActivityIndicatorStyleKey = @"-ios-activity-indicator-style"; static NSString* const kAutoresizingKey = @"-ios-autoresizing"; static NSString* const kTableViewCellSeparatorStyleKey = @"-ios-table-view-cell-separator-style"; static NSString* const kScrollViewIndicatorStyleKey = @"-ios-scroll-view-indicator-style"; static NSString* const kPaddingKey = @"padding"; static NSString* const kHPaddingKey = @"-mobile-hpadding"; static NSString* const kVPaddingKey = @"-mobile-vpadding"; // This color table is generated on-demand and is released when a memory warning is encountered. static NSDictionary* sColorTable = nil; @interface NICSSRuleset() // Instantiates the color table if it does not already exist. + (NSDictionary *)colorTable; + (UIColor *)colorFromCssValues:(NSArray *)cssValues numberOfConsumedTokens:(NSInteger *)pNumberOfConsumedTokens; + (UITextAlignment)textAlignmentFromCssValues:(NSArray *)cssValues; @end // Maintain sanity with a preprocessor macro for the common cases #define RULE_ELEMENT(name,Name,cssKey,type,converter) \ static NSString* const k ## Name ## Key = cssKey; \ -(BOOL)has ## Name { \ return nil != [_ruleset objectForKey: k ## Name ## Key]; \ } \ -(type)name { \ NIDASSERT([self has ## Name]); \ if (!_is.cached.Name) { \ _##name = [[self class] converter:[_ruleset objectForKey:k##Name##Key]]; \ _is.cached.Name = YES; \ } \ return _##name; \ } @implementation NICSSRuleset - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (id)init { if ((self = [super init])) { _ruleset = [[NSMutableDictionary alloc] init]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc addObserver: self selector: @selector(didReceiveMemoryWarning:) name: UIApplicationDidReceiveMemoryWarningNotification object: nil]; } return self; } #pragma mark - Public - (void)addEntriesFromDictionary:(NSDictionary *)dictionary { NSMutableArray* order = [_ruleset objectForKey:kPropertyOrderKey]; [_ruleset addEntriesFromDictionary:dictionary]; if (nil != order) { [order addObjectsFromArray:[dictionary objectForKey:kPropertyOrderKey]]; [_ruleset setObject:order forKey:kPropertyOrderKey]; } } -(id)cssRuleForKey:(NSString *)key { return [_ruleset objectForKey:key]; } - (BOOL)hasTextColor { return nil != [_ruleset objectForKey:kTextColorKey]; } - (UIColor *)textColor { NIDASSERT([self hasTextColor]); if (!_is.cached.TextColor) { _textColor = [[self class] colorFromCssValues:[_ruleset objectForKey:kTextColorKey] numberOfConsumedTokens:nil]; _is.cached.TextColor = YES; } return _textColor; } - (BOOL)hasHighlightedTextColor { return nil != [_ruleset objectForKey:kHighlightedTextColorKey]; } - (UIColor *)highlightedTextColor { NIDASSERT([self hasHighlightedTextColor]); if (!_is.cached.HighlightedTextColor) { _highlightedTextColor = [[self class] colorFromCssValues:[_ruleset objectForKey:kHighlightedTextColorKey] numberOfConsumedTokens:nil]; _is.cached.HighlightedTextColor = YES; } return _highlightedTextColor; } - (BOOL)hasTextAlignment { return nil != [_ruleset objectForKey:kTextAlignmentKey]; } - (UITextAlignment)textAlignment { NIDASSERT([self hasTextAlignment]); if (!_is.cached.TextAlignment) { _textAlignment = [[self class] textAlignmentFromCssValues:[_ruleset objectForKey:kTextAlignmentKey]]; _is.cached.TextAlignment = YES; } return _textAlignment; } -(BOOL)hasHorizontalPadding { return nil != [_ruleset objectForKey:kPaddingKey] || nil != [_ruleset objectForKey:kHPaddingKey]; } -(NICSSUnit)horizontalPadding { NIDASSERT([self hasHorizontalPadding]); NSArray *css = [_ruleset objectForKey:kHPaddingKey]; if (css && css.count > 0) { return [NICSSRuleset unitFromCssValues:css]; } css = [_ruleset objectForKey:kPaddingKey]; if (css && css.count > 1) { return [NICSSRuleset unitFromCssValues:css offset:1]; } if (css && css.count == 1) { return [NICSSRuleset unitFromCssValues:css]; } else { NICSSUnit unit; NIDASSERT([css count] > 0); unit.type = CSS_PIXEL_UNIT; unit.value = 0; return unit; } } -(BOOL)hasVerticalPadding { return nil != [_ruleset objectForKey:kPaddingKey] || nil != [_ruleset objectForKey:kVPaddingKey]; } -(NICSSUnit)verticalPadding { NIDASSERT([self hasVerticalPadding]); NSArray *css = [_ruleset objectForKey:kVPaddingKey]; if (css && css.count > 0) { return [NICSSRuleset unitFromCssValues:css]; } css = [_ruleset objectForKey:kPaddingKey]; if (css && css.count > 0) { return [NICSSRuleset unitFromCssValues:css]; } else { NICSSUnit unit; NIDASSERT([css count] > 0); unit.type = CSS_PIXEL_UNIT; unit.value = 0; return unit; } } - (BOOL)hasFont { return (nil != [_ruleset objectForKey:kFontKey] || nil != [_ruleset objectForKey:kFontSizeKey] || nil != [_ruleset objectForKey:kFontWeightKey] || nil != [_ruleset objectForKey:kFontStyleKey] || nil != [_ruleset objectForKey:kFontFamilyKey]); } - (UIFont *)font { NIDASSERT([self hasFont]); if (_is.cached.Font) { return _font; } NSString* fontName = nil; CGFloat fontSize = [UIFont systemFontSize]; BOOL fontIsBold = NO; BOOL fontIsItalic = NO; NSArray* values = [_ruleset objectForKey:kFontWeightKey]; if (nil != values) { NIDASSERT([values count] == 1); fontIsBold = [[values objectAtIndex:0] isEqualToString:@"bold"]; } values = [_ruleset objectForKey:kFontStyleKey]; if (nil != values) { NIDASSERT([values count] == 1); fontIsItalic = [[values objectAtIndex:0] isEqualToString:@"italic"]; } // There are two ways to set font size and family: font and font-size/font-family. // Newer definitions of these values should overwrite previous definitions so we must // respect ordering here. BOOL hasSetFontName = NO; BOOL hasSetFontSize = NO; NSArray* order = [_ruleset objectForKey:kPropertyOrderKey]; for (NSString* name in [order reverseObjectEnumerator]) { if (!hasSetFontName && [name isEqualToString:kFontFamilyKey]) { values = [_ruleset objectForKey:name]; NIDASSERT([values count] == 1); if ([values count] < 1) { continue; } fontName = [[values objectAtIndex:0] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"\""]]; hasSetFontName = YES; } else if (!hasSetFontSize && [name isEqualToString:kFontSizeKey]) { values = [_ruleset objectForKey:name]; NIDASSERT([values count] == 1); if ([values count] < 1) { continue; } NSString* value = [values objectAtIndex:0]; if ([value isEqualToString:@"default"]) { fontSize = [UIFont systemFontSize]; } else { fontSize = [value floatValue]; } hasSetFontSize = YES; } else if (!hasSetFontSize && !hasSetFontName && [name isEqualToString:kFontKey]) { values = [_ruleset objectForKey:name]; NIDASSERT([values count] <= 2); if ([values count] < 1) { continue; } if ([values count] >= 1) { // Font size fontSize = [[values objectAtIndex:0] floatValue]; hasSetFontSize = YES; } if ([values count] >= 2) { // Font name fontName = [[values objectAtIndex:1] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"\""]]; hasSetFontName = YES; } } if (hasSetFontName && hasSetFontSize) { // Once we've set all values then we can ignore any previous values. break; } } UIFont* font = nil; if (hasSetFontName) { // If you wish to set the weight and style for a non-standard font family then you will need // to set the font family to the given style manually. NIDASSERT(!fontIsItalic && !fontIsBold); font = [UIFont fontWithName:fontName size:fontSize]; } else if (fontIsItalic && fontIsBold) { // There is no easy way to create a bold italic font using the exposed UIFont methods. // Please consider using the exact font name instead. E.g. font-name: Helvetica-BoldObliquei NIDASSERT(!(fontIsItalic && fontIsBold)); font = [UIFont systemFontOfSize:fontSize]; } else if (fontIsItalic) { font = [UIFont italicSystemFontOfSize:fontSize]; } else if (fontIsBold) { font = [UIFont boldSystemFontOfSize:fontSize]; } else { font = [UIFont systemFontOfSize:fontSize]; } _font = font; _is.cached.Font = YES; return font; } - (BOOL)hasTextShadowColor { return nil != [_ruleset objectForKey:kTextShadowKey]; } - (UIColor *)textShadowColor { NIDASSERT([self hasTextShadowColor]); if (!_is.cached.TextShadowColor) { NSArray* values = [_ruleset objectForKey:kTextShadowKey]; _textShadowColor = [[self class] colorFromCssValues:values numberOfConsumedTokens:nil]; _is.cached.TextShadowColor = YES; } return _textShadowColor; } - (BOOL)hasTextShadowOffset { return nil != [_ruleset objectForKey:kTextShadowKey]; } - (CGSize)textShadowOffset { NIDASSERT([self hasTextShadowOffset]); if (!_is.cached.TextShadowOffset) { NSArray* values = [_ruleset objectForKey:kTextShadowKey]; NSInteger skipTokens = 0; [[self class] colorFromCssValues:values numberOfConsumedTokens:&skipTokens]; _textShadowOffset = CGSizeZero; if ([values count] - skipTokens >= 1) { _textShadowOffset.width = [[values objectAtIndex:skipTokens] floatValue]; } if ([values count] - skipTokens >= 2) { _textShadowOffset.height = [[values objectAtIndex:skipTokens + 1] floatValue]; } _is.cached.TextShadowOffset = YES; } return _textShadowOffset; } - (BOOL)hasLineBreakMode { return nil != [_ruleset objectForKey:kLineBreakModeKey]; } - (NSLineBreakMode)lineBreakMode { NIDASSERT([self hasLineBreakMode]); if (!_is.cached.LineBreakMode) { NSArray* values = [_ruleset objectForKey:kLineBreakModeKey]; NIDASSERT([values count] == 1); NSString* value = [values objectAtIndex:0]; if ([value isEqualToString:@"wrap"]) { _lineBreakMode = NSLineBreakByWordWrapping; } else if ([value isEqualToString:@"character-wrap"]) { _lineBreakMode = NSLineBreakByCharWrapping; } else if ([value isEqualToString:@"clip"]) { _lineBreakMode = NSLineBreakByClipping; } else if ([value isEqualToString:@"head-truncate"]) { _lineBreakMode = NSLineBreakByTruncatingHead; } else if ([value isEqualToString:@"tail-truncate"]) { _lineBreakMode = NSLineBreakByTruncatingTail; } else if ([value isEqualToString:@"middle-truncate"]) { _lineBreakMode = NSLineBreakByTruncatingMiddle; } else { _lineBreakMode = NSLineBreakByWordWrapping; } _is.cached.LineBreakMode = YES; } return _lineBreakMode; } - (BOOL)hasNumberOfLines { return nil != [_ruleset objectForKey:kNumberOfLinesKey]; } - (NSInteger)numberOfLines { NIDASSERT([self hasNumberOfLines]); if (!_is.cached.NumberOfLines) { NSArray* values = [_ruleset objectForKey:kNumberOfLinesKey]; NIDASSERT([values count] == 1); _numberOfLines = [[values objectAtIndex:0] intValue]; _is.cached.NumberOfLines = YES; } return _numberOfLines; } - (BOOL)hasMinimumFontSize { return nil != [_ruleset objectForKey:kMinimumFontSizeKey]; } - (CGFloat)minimumFontSize { NIDASSERT([self hasMinimumFontSize]); if (!_is.cached.MinimumFontSize) { NSArray* values = [_ruleset objectForKey:kMinimumFontSizeKey]; NIDASSERT([values count] == 1); _minimumFontSize = [[values objectAtIndex:0] floatValue]; _is.cached.MinimumFontSize = YES; } return _minimumFontSize; } - (BOOL)hasAdjustsFontSize { return nil != [_ruleset objectForKey:kAdjustsFontSizeKey]; } - (BOOL)adjustsFontSize { NIDASSERT([self hasAdjustsFontSize]); if (!_is.cached.AdjustsFontSize) { NSArray* values = [_ruleset objectForKey:kAdjustsFontSizeKey]; NIDASSERT([values count] == 1); _adjustsFontSize = [[values objectAtIndex:0] boolValue]; _is.cached.AdjustsFontSize = YES; } return _adjustsFontSize; } - (BOOL)hasBaselineAdjustment { return nil != [_ruleset objectForKey:kBaselineAdjustmentKey]; } - (UIBaselineAdjustment)baselineAdjustment { NIDASSERT([self hasBaselineAdjustment]); if (!_is.cached.BaselineAdjustment) { NSArray* values = [_ruleset objectForKey:kBaselineAdjustmentKey]; NIDASSERT([values count] == 1); NSString* value = [values objectAtIndex:0]; if ([value isEqualToString:@"align-baselines"]) { _baselineAdjustment = UIBaselineAdjustmentAlignBaselines; } else if ([value isEqualToString:@"align-centers"]) { _baselineAdjustment = UIBaselineAdjustmentAlignCenters; } else { _baselineAdjustment = UIBaselineAdjustmentNone; } _is.cached.BaselineAdjustment = YES; } return _baselineAdjustment; } - (BOOL)hasOpacity { return nil != [_ruleset objectForKey:kOpacityKey]; } - (CGFloat)opacity { NIDASSERT([self hasOpacity]); if (!_is.cached.Opacity) { NSArray* values = [_ruleset objectForKey:kOpacityKey]; NIDASSERT([values count] == 1); _opacity = [[values objectAtIndex:0] floatValue]; _is.cached.Opacity = YES; } return _opacity; } - (BOOL)hasBackgroundColor { return nil != [_ruleset objectForKey:kBackgroundColorKey]; } - (UIColor *)backgroundColor { NIDASSERT([self hasBackgroundColor]); if (!_is.cached.BackgroundColor) { _backgroundColor = [[self class] colorFromCssValues:[_ruleset objectForKey:kBackgroundColorKey] numberOfConsumedTokens:nil]; _is.cached.BackgroundColor = YES; } return _backgroundColor; } - (BOOL)hasBorderRadius { return nil != [_ruleset objectForKey:kBorderRadiusKey]; } - (CGFloat)borderRadius { NIDASSERT([self hasBorderRadius]); if (!_is.cached.BorderRadius) { NSArray* values = [_ruleset objectForKey:kBorderRadiusKey]; NIDASSERT([values count] == 1); _borderRadius = [[values objectAtIndex:0] floatValue]; _is.cached.BorderRadius = YES; } return _borderRadius; } - (BOOL)hasBorderColor { return (nil != [_ruleset objectForKey:kBorderColorKey] || nil != [_ruleset objectForKey:kBorderKey]); } - (void)cacheBorderValues { _borderWidth = 0; _borderColor = nil; NSArray* values = nil; // There are two ways to set border color and width: border and border-color/border-width. // Newer definitions of these values should overwrite previous definitions so we must // respect ordering here. BOOL hasSetBorderColor = NO; BOOL hasSetBorderWidth = NO; NSArray* order = [_ruleset objectForKey:kPropertyOrderKey]; for (NSString* name in [order reverseObjectEnumerator]) { if (!hasSetBorderColor && [name isEqualToString:kBorderColorKey]) { values = [_ruleset objectForKey:name]; _borderColor = [[self class] colorFromCssValues:values numberOfConsumedTokens:nil]; hasSetBorderColor = YES; } else if (!hasSetBorderWidth && [name isEqualToString:kBorderWidthKey]) { values = [_ruleset objectForKey:name]; NIDASSERT([values count] == 1); if ([values count] < 1) { continue; } _borderWidth = [[values objectAtIndex:0] floatValue]; hasSetBorderWidth = YES; } else if (!hasSetBorderColor && !hasSetBorderWidth && [name isEqualToString:kBorderKey]) { values = [_ruleset objectForKey:name]; if ([values count] >= 1) { // Border width _borderWidth = [[values objectAtIndex:0] floatValue]; hasSetBorderWidth = YES; } if ([values count] >= 3) { // Border color _borderColor = [[self class] colorFromCssValues:[values subarrayWithRange:NSMakeRange(2, [values count] - 2)] numberOfConsumedTokens:nil]; hasSetBorderColor = YES; } } if (hasSetBorderColor && hasSetBorderWidth) { // Once we've set all values then we can ignore any previous values. break; } } _is.cached.BorderColor = hasSetBorderColor; _is.cached.BorderWidth = hasSetBorderWidth; } - (UIColor *)borderColor { NIDASSERT([self hasBorderColor]); [self cacheBorderValues]; return _borderColor; } - (BOOL)hasBorderWidth { return (nil != [_ruleset objectForKey:kBorderWidthKey] || nil != [_ruleset objectForKey:kBorderKey]); } - (CGFloat)borderWidth { NIDASSERT([self hasBorderWidth]); [self cacheBorderValues]; return _borderWidth; } RULE_ELEMENT(width,Width,@"width",NICSSUnit,unitFromCssValues) RULE_ELEMENT(height,Height,@"height",NICSSUnit,unitFromCssValues) RULE_ELEMENT(top,Top,@"top",NICSSUnit,unitFromCssValues) RULE_ELEMENT(bottom,Bottom,@"bottom",NICSSUnit,unitFromCssValues) RULE_ELEMENT(right,Right,@"right",NICSSUnit,unitFromCssValues) RULE_ELEMENT(left,Left,@"left",NICSSUnit,unitFromCssValues) RULE_ELEMENT(minWidth, MinWidth, @"min-width", NICSSUnit, unitFromCssValues) RULE_ELEMENT(minHeight, MinHeight, @"min-height", NICSSUnit, unitFromCssValues) RULE_ELEMENT(maxWidth, MaxWidth, @"max-width", NICSSUnit, unitFromCssValues) RULE_ELEMENT(maxHeight, MaxHeight, @"max-height", NICSSUnit, unitFromCssValues) RULE_ELEMENT(frameHorizontalAlign,FrameHorizontalAlign,@"-mobile-halign",UITextAlignment,textAlignmentFromCssValues) RULE_ELEMENT(frameVerticalAlign,FrameVerticalAlign,@"-mobile-valign",UIViewContentMode,verticalAlignFromCssValues) RULE_ELEMENT(backgroundStretchInsets,BackgroundStretchInsets,@"-mobile-background-stretch",UIEdgeInsets,edgeInsetsFromCssValues) RULE_ELEMENT(backgroundImage,BackgroundImage,@"background-image", NSString*,imageStringFromCssValues) RULE_ELEMENT(image, Image, @"-mobile-image", NSString*, imageStringFromCssValues) RULE_ELEMENT(visible, Visible, @"visibility", BOOL, visibilityFromCssValues) RULE_ELEMENT(titleInsets, TitleInsets, @"-mobile-title-insets", UIEdgeInsets, edgeInsetsFromCssValues) RULE_ELEMENT(contentInsets, ContentInsets, @"-mobile-content-insets", UIEdgeInsets, edgeInsetsFromCssValues) RULE_ELEMENT(imageInsets, ImageInsets, @"-mobile-image-insets", UIEdgeInsets, edgeInsetsFromCssValues) RULE_ELEMENT(relativeToId, RelativeToId, @"-mobile-relative", NSString*, stringFromCssValue) RULE_ELEMENT(marginTop, MarginTop, @"margin-top", NICSSUnit, unitFromCssValues) RULE_ELEMENT(marginBottom, MarginBottom, @"margin-bottom", NICSSUnit, unitFromCssValues) RULE_ELEMENT(marginLeft, MarginLeft, @"margin-left", NICSSUnit, unitFromCssValues) RULE_ELEMENT(marginRight, MarginRight, @"margin-right", NICSSUnit, unitFromCssValues) RULE_ELEMENT(textKey, TextKey, @"-mobile-text-key", NSString*, stringFromCssValue) RULE_ELEMENT(buttonAdjust, ButtonAdjust, @"-ios-button-adjust", NICSSButtonAdjust, buttonAdjustFromCssValue) RULE_ELEMENT(verticalAlign, VerticalAlign, @"-mobile-content-valign", UIControlContentVerticalAlignment, controlVerticalAlignFromCssValues) RULE_ELEMENT(horizontalAlign, HorizontalAlign, @"-mobile-content-halign", UIControlContentHorizontalAlignment, controlHorizontalAlignFromCssValues) - (BOOL)hasTintColor { return nil != [_ruleset objectForKey:kTintColorKey]; } - (UIColor *)tintColor { NIDASSERT([self hasTintColor]); if (!_is.cached.TintColor) { _tintColor = [[self class] colorFromCssValues:[_ruleset objectForKey:kTintColorKey] numberOfConsumedTokens:nil]; _is.cached.TintColor = YES; } return _tintColor; } - (BOOL)hasActivityIndicatorStyle { return nil != [_ruleset objectForKey:kActivityIndicatorStyleKey]; } - (UIActivityIndicatorViewStyle)activityIndicatorStyle { NIDASSERT([self hasActivityIndicatorStyle]); if (!_is.cached.ActivityIndicatorStyle) { NSArray* values = [_ruleset objectForKey:kActivityIndicatorStyleKey]; NIDASSERT([values count] == 1); NSString* value = [values objectAtIndex:0]; if ([value isEqualToString:@"white"]) { _activityIndicatorStyle = UIActivityIndicatorViewStyleWhite; } else if ([value isEqualToString:@"gray"]) { _activityIndicatorStyle = UIActivityIndicatorViewStyleGray; } else { _activityIndicatorStyle = UIActivityIndicatorViewStyleWhiteLarge; } _is.cached.ActivityIndicatorStyle = YES; } return _activityIndicatorStyle; } - (BOOL)hasAutoresizing { return nil != [_ruleset objectForKey:kAutoresizingKey]; } - (UIViewAutoresizing)autoresizing { NIDASSERT([self hasAutoresizing]); if (!_is.cached.Autoresizing) { NSArray* values = [_ruleset objectForKey:kAutoresizingKey]; UIViewAutoresizing autoresizing = UIViewAutoresizingNone; for (NSString* value in values) { if ([value isEqualToString:@"left"]) { autoresizing |= UIViewAutoresizingFlexibleLeftMargin; } else if ([value isEqualToString:@"top"]) { autoresizing |= UIViewAutoresizingFlexibleTopMargin; } else if ([value isEqualToString:@"right"]) { autoresizing |= UIViewAutoresizingFlexibleRightMargin; } else if ([value isEqualToString:@"bottom"]) { autoresizing |= UIViewAutoresizingFlexibleBottomMargin; } else if ([value isEqualToString:@"width"]) { autoresizing |= UIViewAutoresizingFlexibleWidth; } else if ([value isEqualToString:@"height"]) { autoresizing |= UIViewAutoresizingFlexibleHeight; } else if ([value isEqualToString:@"all"]) { autoresizing |= UIViewAutoresizingFlexibleDimensions | UIViewAutoresizingFlexibleMargins; } else if ([value isEqualToString:@"margins"]) { autoresizing |= UIViewAutoresizingFlexibleMargins; } else if ([value isEqualToString:@"dimensions"]) { autoresizing |= UIViewAutoresizingFlexibleDimensions; } } _autoresizing = autoresizing; _is.cached.Autoresizing = YES; } return _autoresizing; } - (BOOL)hasTableViewCellSeparatorStyle { return nil != [_ruleset objectForKey:kTableViewCellSeparatorStyleKey]; } - (UITableViewCellSeparatorStyle)tableViewCellSeparatorStyle { NIDASSERT([self hasTableViewCellSeparatorStyle]); if (!_is.cached.TableViewCellSeparatorStyle) { NSArray* values = [_ruleset objectForKey:kTableViewCellSeparatorStyleKey]; NIDASSERT([values count] == 1); NSString* value = [values objectAtIndex:0]; UITableViewCellSeparatorStyle style = UITableViewCellSeparatorStyleSingleLine; if ([value isEqualToString:@"none"]) { style = UITableViewCellSeparatorStyleNone; } else if ([value isEqualToString:@"single-line-etched"]) { style = UITableViewCellSeparatorStyleSingleLineEtched; } _tableViewCellSeparatorStyle = style; _is.cached.TableViewCellSeparatorStyle = YES; } return _tableViewCellSeparatorStyle; } - (BOOL)hasScrollViewIndicatorStyle { return nil != [_ruleset objectForKey:kScrollViewIndicatorStyleKey]; } - (UIScrollViewIndicatorStyle)scrollViewIndicatorStyle { NIDASSERT([self hasScrollViewIndicatorStyle]); if (!_is.cached.ScrollViewIndicatorStyle) { NSArray* values = [_ruleset objectForKey:kScrollViewIndicatorStyleKey]; NIDASSERT([values count] == 1); NSString* value = [values objectAtIndex:0]; UIScrollViewIndicatorStyle style = UIScrollViewIndicatorStyleDefault; if ([value isEqualToString:@"black"]) { style = UIScrollViewIndicatorStyleBlack; } else if ([value isEqualToString:@"white"]) { style = UIScrollViewIndicatorStyleWhite; } _scrollViewIndicatorStyle = style; _is.cached.ScrollViewIndicatorStyle = YES; } return _scrollViewIndicatorStyle; } #pragma mark - NSNotifications - (void)reduceMemory { sColorTable = nil; _textColor = nil; _font = nil; _textShadowColor = nil; _backgroundColor = nil; _borderColor = nil; _tintColor = nil; memset(&_is, 0, sizeof(_is)); } - (void)didReceiveMemoryWarning:(void*)object { [self reduceMemory]; } #pragma mark - Color Tables + (NSDictionary *)colorTable { if (nil == sColorTable) { // This color table was generated from http://www.w3.org/TR/css3-color/ // // The output was sorted, // > pbpaste | sort | pbcopy // // reformatted using a regex, // ^(.+)\t(.+)\t(.+) => RGBCOLOR($3), @"$1", // // and then uniq'd // > pbpaste | uniq | pbcopy NSMutableDictionary* colorTable = [[NSMutableDictionary alloc] initWithObjectsAndKeys: RGBCOLOR(240,248,255), @"aliceblue", RGBCOLOR(250,235,215), @"antiquewhite", RGBCOLOR(0,255,255), @"aqua", RGBCOLOR(127,255,212), @"aquamarine", RGBCOLOR(240,255,255), @"azure", RGBCOLOR(245,245,220), @"beige", RGBCOLOR(255,228,196), @"bisque", RGBCOLOR(0,0,0), @"black", RGBCOLOR(255,235,205), @"blanchedalmond", RGBCOLOR(0,0,255), @"blue", RGBCOLOR(138,43,226), @"blueviolet", RGBCOLOR(165,42,42), @"brown", RGBCOLOR(222,184,135), @"burlywood", RGBCOLOR(95,158,160), @"cadetblue", RGBCOLOR(127,255,0), @"chartreuse", RGBCOLOR(210,105,30), @"chocolate", RGBCOLOR(255,127,80), @"coral", RGBCOLOR(100,149,237), @"cornflowerblue", RGBCOLOR(255,248,220), @"cornsilk", RGBCOLOR(220,20,60), @"crimson", RGBCOLOR(0,255,255), @"cyan", RGBCOLOR(0,0,139), @"darkblue", RGBCOLOR(0,139,139), @"darkcyan", RGBCOLOR(184,134,11), @"darkgoldenrod", RGBCOLOR(169,169,169), @"darkgray", RGBCOLOR(0,100,0), @"darkgreen", RGBCOLOR(169,169,169), @"darkgrey", RGBCOLOR(189,183,107), @"darkkhaki", RGBCOLOR(139,0,139), @"darkmagenta", RGBCOLOR(85,107,47), @"darkolivegreen", RGBCOLOR(255,140,0), @"darkorange", RGBCOLOR(153,50,204), @"darkorchid", RGBCOLOR(139,0,0), @"darkred", RGBCOLOR(233,150,122), @"darksalmon", RGBCOLOR(143,188,143), @"darkseagreen", RGBCOLOR(72,61,139), @"darkslateblue", RGBCOLOR(47,79,79), @"darkslategray", RGBCOLOR(47,79,79), @"darkslategrey", RGBCOLOR(0,206,209), @"darkturquoise", RGBCOLOR(148,0,211), @"darkviolet", RGBCOLOR(255,20,147), @"deeppink", RGBCOLOR(0,191,255), @"deepskyblue", RGBCOLOR(105,105,105), @"dimgray", RGBCOLOR(105,105,105), @"dimgrey", RGBCOLOR(30,144,255), @"dodgerblue", RGBCOLOR(178,34,34), @"firebrick", RGBCOLOR(255,250,240), @"floralwhite", RGBCOLOR(34,139,34), @"forestgreen", RGBCOLOR(255,0,255), @"fuchsia", RGBCOLOR(220,220,220), @"gainsboro", RGBCOLOR(248,248,255), @"ghostwhite", RGBCOLOR(255,215,0), @"gold", RGBCOLOR(218,165,32), @"goldenrod", RGBCOLOR(128,128,128), @"gray", RGBCOLOR(0,128,0), @"green", RGBCOLOR(173,255,47), @"greenyellow", RGBCOLOR(128,128,128), @"grey", RGBCOLOR(240,255,240), @"honeydew", RGBCOLOR(255,105,180), @"hotpink", RGBCOLOR(205,92,92), @"indianred", RGBCOLOR(75,0,130), @"indigo", RGBCOLOR(255,255,240), @"ivory", RGBCOLOR(240,230,140), @"khaki", RGBCOLOR(230,230,250), @"lavender", RGBCOLOR(255,240,245), @"lavenderblush", RGBCOLOR(124,252,0), @"lawngreen", RGBCOLOR(255,250,205), @"lemonchiffon", RGBCOLOR(173,216,230), @"lightblue", RGBCOLOR(240,128,128), @"lightcoral", RGBCOLOR(224,255,255), @"lightcyan", RGBCOLOR(250,250,210), @"lightgoldenrodyellow", RGBCOLOR(211,211,211), @"lightgray", RGBCOLOR(144,238,144), @"lightgreen", RGBCOLOR(211,211,211), @"lightgrey", RGBCOLOR(255,182,193), @"lightpink", RGBCOLOR(255,160,122), @"lightsalmon", RGBCOLOR(32,178,170), @"lightseagreen", RGBCOLOR(135,206,250), @"lightskyblue", RGBCOLOR(119,136,153), @"lightslategray", RGBCOLOR(119,136,153), @"lightslategrey", RGBCOLOR(176,196,222), @"lightsteelblue", RGBCOLOR(255,255,224), @"lightyellow", RGBCOLOR(0,255,0), @"lime", RGBCOLOR(50,205,50), @"limegreen", RGBCOLOR(250,240,230), @"linen", RGBCOLOR(255,0,255), @"magenta", RGBCOLOR(128,0,0), @"maroon", RGBCOLOR(102,205,170), @"mediumaquamarine", RGBCOLOR(0,0,205), @"mediumblue", RGBCOLOR(186,85,211), @"mediumorchid", RGBCOLOR(147,112,219), @"mediumpurple", RGBCOLOR(60,179,113), @"mediumseagreen", RGBCOLOR(123,104,238), @"mediumslateblue", RGBCOLOR(0,250,154), @"mediumspringgreen", RGBCOLOR(72,209,204), @"mediumturquoise", RGBCOLOR(199,21,133), @"mediumvioletred", RGBCOLOR(25,25,112), @"midnightblue", RGBCOLOR(245,255,250), @"mintcream", RGBCOLOR(255,228,225), @"mistyrose", RGBCOLOR(255,228,181), @"moccasin", RGBCOLOR(255,222,173), @"navajowhite", RGBCOLOR(0,0,128), @"navy", RGBCOLOR(253,245,230), @"oldlace", RGBCOLOR(128,128,0), @"olive", RGBCOLOR(107,142,35), @"olivedrab", RGBCOLOR(255,165,0), @"orange", RGBCOLOR(255,69,0), @"orangered", RGBCOLOR(218,112,214), @"orchid", RGBCOLOR(238,232,170), @"palegoldenrod", RGBCOLOR(152,251,152), @"palegreen", RGBCOLOR(175,238,238), @"paleturquoise", RGBCOLOR(219,112,147), @"palevioletred", RGBCOLOR(255,239,213), @"papayawhip", RGBCOLOR(255,218,185), @"peachpuff", RGBCOLOR(205,133,63), @"peru", RGBCOLOR(255,192,203), @"pink", RGBCOLOR(221,160,221), @"plum", RGBCOLOR(176,224,230), @"powderblue", RGBCOLOR(128,0,128), @"purple", RGBCOLOR(255,0,0), @"red", RGBCOLOR(188,143,143), @"rosybrown", RGBCOLOR(65,105,225), @"royalblue", RGBCOLOR(139,69,19), @"saddlebrown", RGBCOLOR(250,128,114), @"salmon", RGBCOLOR(244,164,96), @"sandybrown", RGBCOLOR(46,139,87), @"seagreen", RGBCOLOR(255,245,238), @"seashell", RGBCOLOR(160,82,45), @"sienna", RGBCOLOR(192,192,192), @"silver", RGBCOLOR(135,206,235), @"skyblue", RGBCOLOR(106,90,205), @"slateblue", RGBCOLOR(112,128,144), @"slategray", RGBCOLOR(112,128,144), @"slategrey", RGBCOLOR(255,250,250), @"snow", RGBCOLOR(0,255,127), @"springgreen", RGBCOLOR(70,130,180), @"steelblue", RGBCOLOR(210,180,140), @"tan", RGBCOLOR(0,128,128), @"teal", RGBCOLOR(216,191,216), @"thistle", RGBCOLOR(255,99,71), @"tomato", RGBCOLOR(64,224,208), @"turquoise", RGBCOLOR(238,130,238), @"violet", RGBCOLOR(245,222,179), @"wheat", RGBCOLOR(255,255,255), @"white", RGBCOLOR(245,245,245), @"whitesmoke", RGBCOLOR(255,255,0), @"yellow", RGBCOLOR(154,205,50), @"yellowgreen", // System colors [UIColor lightTextColor], @"lightTextColor", [UIColor darkTextColor], @"darkTextColor", [UIColor groupTableViewBackgroundColor], @"groupTableViewBackgroundColor", [UIColor viewFlipsideBackgroundColor], @"viewFlipsideBackgroundColor", nil]; if ([UIColor respondsToSelector:@selector(scrollViewTexturedBackgroundColor)]) { // 3.2 and up UIColor* color = [UIColor scrollViewTexturedBackgroundColor]; if (nil != color) { [colorTable setObject:color forKey:@"scrollViewTexturedBackgroundColor"]; } } if ([UIColor respondsToSelector:@selector(underPageBackgroundColor)]) { // 5.0 and up UIColor* color = [UIColor underPageBackgroundColor]; if (nil != color) { [colorTable setObject:color forKey:@"underPageBackgroundColor"]; } } // Replace the web colors with their system color equivalents. [colorTable setObject:[UIColor blackColor] forKey:@"black"]; [colorTable setObject:[UIColor darkGrayColor] forKey:@"darkGray"]; [colorTable setObject:[UIColor lightGrayColor] forKey:@"lightGray"]; [colorTable setObject:[UIColor whiteColor] forKey:@"white"]; [colorTable setObject:[UIColor grayColor] forKey:@"gray"]; [colorTable setObject:[UIColor redColor] forKey:@"red"]; [colorTable setObject:[UIColor greenColor] forKey:@"green"]; [colorTable setObject:[UIColor blueColor] forKey:@"blue"]; [colorTable setObject:[UIColor cyanColor] forKey:@"cyan"]; [colorTable setObject:[UIColor yellowColor] forKey:@"yellow"]; [colorTable setObject:[UIColor magentaColor] forKey:@"magenta"]; [colorTable setObject:[UIColor orangeColor] forKey:@"orange"]; [colorTable setObject:[UIColor purpleColor] forKey:@"purple"]; [colorTable setObject:[UIColor brownColor] forKey:@"brown"]; [colorTable setObject:[UIColor clearColor] forKey:@"clear"]; sColorTable = [colorTable copy]; } return sColorTable; } + (NICSSUnit)unitFromCssValues:(NSArray*)cssValues { return [self unitFromCssValues:cssValues offset: 0]; } + (NICSSUnit)unitFromCssValues:(NSArray*)cssValues offset: (int) offset { NICSSUnit returnUnits; NSString *unitValue = [cssValues objectAtIndex:offset]; if ([unitValue caseInsensitiveCompare:@"auto"] == NSOrderedSame) { returnUnits.type = CSS_AUTO_UNIT; returnUnits.value = 0; } else if ([unitValue hasSuffix:@"%"]) { returnUnits.type = CSS_PERCENTAGE_UNIT; NSDecimalNumber *nv = [NSDecimalNumber decimalNumberWithString: [unitValue substringToIndex:unitValue.length-1]]; returnUnits.value = [nv decimalNumberByDividingBy:[NSDecimalNumber decimalNumberWithMantissa:1 exponent:2 isNegative:NO]].floatValue; } else if ([unitValue hasSuffix:@"px"]) { returnUnits.type = CSS_PIXEL_UNIT; returnUnits.value = [NSDecimalNumber decimalNumberWithString: [unitValue substringToIndex:unitValue.length-1]].floatValue; } else if ([unitValue isEqualToString:@"0"]) { returnUnits.type = CSS_PIXEL_UNIT; returnUnits.value = 0; } else { NIDERROR(@"Unknown unit: %@", unitValue); } return returnUnits; } +(UIViewContentMode) verticalAlignFromCssValues:(NSArray*)cssValues { NSString *unitValue = [cssValues objectAtIndex:0]; if ([unitValue caseInsensitiveCompare:@"middle"] == NSOrderedSame) { return UIViewContentModeCenter; } else if ([unitValue caseInsensitiveCompare:@"top"] == NSOrderedSame) { return UIViewContentModeTop; } else if ([unitValue caseInsensitiveCompare:@"bottom"] == NSOrderedSame) { return UIViewContentModeBottom; } else { NIDERROR(@"Unknown vertical alignment: %@", unitValue); return UIViewContentModeCenter; } } +(UIControlContentVerticalAlignment) controlVerticalAlignFromCssValues:(NSArray*)cssValues { NSString *unitValue = [cssValues objectAtIndex:0]; if ([unitValue caseInsensitiveCompare:@"middle"] == NSOrderedSame) { return UIControlContentVerticalAlignmentCenter; } else if ([unitValue caseInsensitiveCompare:@"top"] == NSOrderedSame) { return UIControlContentVerticalAlignmentTop; } else if ([unitValue caseInsensitiveCompare:@"bottom"] == NSOrderedSame) { return UIControlContentVerticalAlignmentBottom; } else if ([unitValue caseInsensitiveCompare:@"fill"] == NSOrderedSame) { return UIControlContentVerticalAlignmentFill; } else { NIDERROR(@"Unknown content vertical alignment: %@", unitValue); return UIControlContentVerticalAlignmentCenter; } } +(UIControlContentHorizontalAlignment) controlHorizontalAlignFromCssValues:(NSArray*)cssValues { NSString *unitValue = [cssValues objectAtIndex:0]; if ([unitValue caseInsensitiveCompare:@"center"] == NSOrderedSame) { return UIControlContentHorizontalAlignmentCenter; } else if ([unitValue caseInsensitiveCompare:@"left"] == NSOrderedSame) { return UIControlContentHorizontalAlignmentLeft; } else if ([unitValue caseInsensitiveCompare:@"right"] == NSOrderedSame) { return UIControlContentHorizontalAlignmentRight; } else if ([unitValue caseInsensitiveCompare:@"fill"] == NSOrderedSame) { return UIControlContentHorizontalAlignmentFill; } else { NIDERROR(@"Unknown content horizontal alignment: %@", unitValue); return UIControlContentHorizontalAlignmentCenter; } } + (UIColor *)colorFromCssValues:(NSArray *)cssValues numberOfConsumedTokens:(NSInteger *)pNumberOfConsumedTokens { NSInteger bogus = 0; if (nil == pNumberOfConsumedTokens) { pNumberOfConsumedTokens = &bogus; } UIColor* color = nil; if ([cssValues count] >= 6 && [[cssValues objectAtIndex:0] isEqualToString:@"rgba("]) { // rgba( x x x x ) color = RGBACOLOR([[cssValues objectAtIndex:1] floatValue], [[cssValues objectAtIndex:2] floatValue], [[cssValues objectAtIndex:3] floatValue], [[cssValues objectAtIndex:4] floatValue]); *pNumberOfConsumedTokens = 6; } else if ([cssValues count] >= 5 && [[cssValues objectAtIndex:0] isEqualToString:@"rgb("]) { // rgb( x x x ) color = RGBCOLOR([[cssValues objectAtIndex:1] floatValue], [[cssValues objectAtIndex:2] floatValue], [[cssValues objectAtIndex:3] floatValue]); *pNumberOfConsumedTokens = 5; } else if ([cssValues count] == 1 && [[cssValues objectAtIndex:0] hasPrefix:@"url("]) { NSString *image = [cssValues objectAtIndex:0]; image = [image substringWithRange:NSMakeRange(4, image.length - 5)]; image = [image stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" '\""]]; color = [UIColor colorWithPatternImage:[UIImage imageNamed:image]]; } else if ([cssValues count] >= 1) { NSString* cssString = [cssValues objectAtIndex:0]; if ([cssString characterAtIndex:0] == '#') { unsigned long colorValue = 0; // #FFF if ([cssString length] == 4) { colorValue = strtol([cssString UTF8String] + 1, nil, 16); colorValue = ((colorValue & 0xF00) << 12) | ((colorValue & 0xF00) << 8) | ((colorValue & 0xF0) << 8) | ((colorValue & 0xF0) << 4) | ((colorValue & 0xF) << 4) | (colorValue & 0xF); // #FFFFFF } else if ([cssString length] == 7) { colorValue = strtol([cssString UTF8String] + 1, nil, 16); } color = RGBCOLOR(((colorValue & 0xFF0000) >> 16), ((colorValue & 0xFF00) >> 8), (colorValue & 0xFF)); } else if ([cssString caseInsensitiveCompare:@"none"] == NSOrderedSame) { // Special case to "undo" a color that was set by some other rule color = nil; } else { color = [[self colorTable] objectForKey:cssString]; } *pNumberOfConsumedTokens = 1; } return color; } +(BOOL)visibilityFromCssValues: (NSArray*) values { NSString *v = [values objectAtIndex:0]; if ([v caseInsensitiveCompare:@"hidden"] == NSOrderedSame) { return NO; } return YES; } +(NSString*)imageStringFromCssValues:(NSArray*) cssValues { NSString *bg = [cssValues objectAtIndex:0]; if ([bg hasPrefix:@"url("]) { bg = [bg substringWithRange: NSMakeRange(4, bg.length - 5)]; } if ([bg characterAtIndex:0] == '\'' || [bg characterAtIndex:0] == '"') { bg = [bg substringWithRange:NSMakeRange(1, bg.length-2)]; } return bg; } +(NSString*)stringFromCssValue:(NSArray*) cssValues { NSString *s = [cssValues objectAtIndex:0]; if ([s characterAtIndex:0] == '\"') { s = [s substringWithRange:NSMakeRange(1, s.length-2)]; } return s; } +(UIEdgeInsets)edgeInsetsFromCssValues: (NSArray*) cssValues { // top, left, bottom, right NSString *top = [cssValues objectAtIndex:0], *left, *right, *bottom; if (cssValues.count > 1) { left = [cssValues objectAtIndex:1]; if (cssValues.count > 2) { bottom = [cssValues objectAtIndex:2]; if (cssValues.count > 3) { right = [cssValues objectAtIndex:3]; } } else { bottom = top; right = left; } } else { left = right = bottom = top; } return UIEdgeInsetsMake( [NSDecimalNumber decimalNumberWithString:top].floatValue, [NSDecimalNumber decimalNumberWithString:left].floatValue, [NSDecimalNumber decimalNumberWithString:bottom].floatValue, [NSDecimalNumber decimalNumberWithString:right].floatValue ); } +(CGFloat)pixelsFromCssValue: (NSArray*) cssValues { return [[cssValues objectAtIndex:0] floatValue]; } +(NICSSButtonAdjust)buttonAdjustFromCssValue: (NSArray*) cssValues { NICSSButtonAdjust a = NICSSButtonAdjustNone; for (NSString* token in cssValues) { if ([token caseInsensitiveCompare:@"highlighted"] == NSOrderedSame) { a |= NICSSButtonAdjustHighlighted; } else if ([token caseInsensitiveCompare:@"disabled"] == NSOrderedSame) { a |= NICSSButtonAdjustDisabled; } } return a; } + (UITextAlignment)textAlignmentFromCssValues:(NSArray *)cssValues { NIDASSERT([cssValues count] == 1); if ([cssValues count] < 1) { return UITextAlignmentLeft; } NSString* value = [cssValues objectAtIndex:0]; UITextAlignment textAlignment = UITextAlignmentLeft; if ([value isEqualToString:@"center"]) { textAlignment = UITextAlignmentCenter; } else if ([value isEqualToString:@"right"]) { textAlignment = UITextAlignmentRight; } else if ([value isEqualToString:@"left"]) { textAlignment = UITextAlignmentLeft; } else { NIDERROR(@"Unknown horizontal alignment %@", value); } return textAlignment; } -(NSString *)description { return [_ruleset description]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIChameleonObserver.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import "NimbusCore.h" #import "NICSSParser.h" @class NIStylesheet; @class NIStylesheetCache; extern NSString* const NIJSONDidChangeNotification; extern NSString* const NIJSONDidChangeFilePathKey; extern NSString* const NIJSONDidChangeNameKey; /** * An observer for the Chameleon server. * * @ingroup NimbusCSS * * This observer connects to a Chameleon server and waits for changes in stylesheets. Once * a stylesheet change has been detected, the new stylesheet is retrieved from the server * and a notification is fired via NIStylesheetDidChangeNotification after the stylesheet * has been reloaded. * * Thanks to the use of NIOperations, the stylesheet loading and processing is accomplished * on a separate thread. This means that the UI will only be notified of stylesheet changes * once the request thread has successfully loaded and processed the changed stylesheet. */ @interface NIChameleonObserver : NSObject <NIOperationDelegate, NICSSParserDelegate> { @private NIStylesheetCache* _stylesheetCache; NSMutableArray* _stylesheetPaths; NSOperationQueue* _queue; NSString* _host; NSInteger _retryCount; } // Designated initializer. - (id)initWithStylesheetCache:(NIStylesheetCache *)stylesheetCache host:(NSString *)host; - (NIStylesheet *)stylesheetForPath:(NSString *)path; - (void)watchSkinChanges; - (void)enableBonjourDiscovery: (NSString*) serviceName; @end /** * Initializes a newly allocated Chameleon observer with a given stylesheet cache and host. * * @fn NIChameleonObserver::initWithStylesheetCache:host: */ /** * Returns a loaded stylesheet from the given path. * * @fn NIChameleonObserver::stylesheetForPath: */ /** * Begins listening to the Chameleon server for changes. * * When changes are detected the Chameleon observer downloads the new CSS files, reloads them, * and then fires the appropriate notifications. * * @fn NIChameleonObserver::watchSkinChanges */ /** * Browses Bonjour for services with the given name (e.g. your username) and sets the host * automatically. * * @fn NIChameleonObserver::enableBonjourDiscovery: */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIChameleonObserver.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIChameleonObserver.h" #import "NIStylesheet.h" #import "NIStylesheetCache.h" #import "NIUserInterfaceString.h" #import "NimbusCore+Additions.h" #import "AFNetworking.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static NSString* const kWatchFilenameKey = @"___watch___"; static const NSTimeInterval kTimeoutInterval = 1000; static const NSTimeInterval kRetryInterval = 10000; static const NSInteger kMaxNumberOfRetries = 3; NSString* const NIJSONDidChangeNotification = @"NIJSONDidChangeNotification"; NSString* const NIJSONDidChangeFilePathKey = @"NIJSONPathKey"; NSString* const NIJSONDidChangeNameKey = @"NIJSONNameKey"; @interface NIChameleonObserver() < NSNetServiceBrowserDelegate, NSNetServiceDelegate > - (NSString *)pathFromPath:(NSString *)path; @property (nonatomic,strong) NSNetServiceBrowser *netBrowser; @property (nonatomic,strong) NSNetService *netService; @end @implementation NIChameleonObserver - (void)dealloc { [_queue cancelAllOperations]; } - (id)initWithStylesheetCache:(NIStylesheetCache *)stylesheetCache host:(NSString *)host { if ((self = [super init])) { // You must provide a stylesheet cache. NIDASSERT(nil != stylesheetCache); _stylesheetCache = stylesheetCache; _stylesheetPaths = [[NSMutableArray alloc] init]; _queue = [[NSOperationQueue alloc] init]; if ([host hasSuffix:@"/"]) { _host = [host copy]; } else if (host) { _host = [[host stringByAppendingString:@"/"] copy]; } NSFileManager* fm = [NSFileManager defaultManager]; NSDirectoryEnumerator* de = [fm enumeratorAtPath:_stylesheetCache.pathPrefix]; NSString* filename; while ((filename = [de nextObject])) { BOOL isFolder = NO; NSString* path = [_stylesheetCache.pathPrefix stringByAppendingPathComponent:filename]; if ([fm fileExistsAtPath:path isDirectory:&isFolder] && !isFolder && [[filename pathExtension] isEqualToString:@"css"]) { [_stylesheetPaths addObject:filename]; NSString* cachePath = NIPathForDocumentsResource([self pathFromPath:filename]); NSError* error = nil; [fm removeItemAtPath:cachePath error:&error]; error = nil; [fm copyItemAtPath:path toPath:cachePath error:&error]; NIDASSERT(nil == error); } } } return self; } - (void)downloadStylesheetWithFilename:(NSString *)path { NSURL* url = [NSURL URLWithString:[_host stringByAppendingString:path]]; NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url]; AFHTTPRequestOperation* requestOp = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [requestOp setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSMutableArray* changedStylesheets = [NSMutableArray array]; NSArray* pathParts = [[operation.request.URL absoluteString] pathComponents]; NSString* resultPath = [[pathParts subarrayWithRange:NSMakeRange(2, [pathParts count] - 2)] componentsJoinedByString:@"/"]; NSString* rootPath = NIPathForDocumentsResource(nil); NSString* hashedPath = [self pathFromPath:resultPath]; NSString* diskPath = [rootPath stringByAppendingPathComponent:hashedPath]; [responseObject writeToFile:diskPath atomically:YES]; NIStylesheet* stylesheet = [_stylesheetCache stylesheetWithPath:resultPath loadFromDisk:NO]; if ([stylesheet loadFromPath:resultPath pathPrefix:rootPath delegate:self]) { [changedStylesheets addObject:stylesheet]; } for (NSString* iteratingPath in _stylesheetPaths) { stylesheet = [_stylesheetCache stylesheetWithPath:iteratingPath loadFromDisk:NO]; if ([stylesheet.dependencies containsObject:resultPath]) { // This stylesheet has the changed stylesheet as a dependency so let's refresh it. if ([stylesheet loadFromPath:iteratingPath pathPrefix:rootPath delegate:self]) { [changedStylesheets addObject:stylesheet]; } } } NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; for (NIStylesheet* changedStylesheet in changedStylesheets) { [nc postNotificationName:NIStylesheetDidChangeNotification object:changedStylesheet userInfo:nil]; } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; [_queue addOperation:requestOp]; } - (void)downloadStringsWithFilename:(NSString *)path { NSURL* url = [NSURL URLWithString:[_host stringByAppendingString:path]]; NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url]; AFHTTPRequestOperation* requestOp = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [requestOp setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSArray* pathParts = [[operation.request.URL absoluteString] pathComponents]; NSString* resultPath = [[pathParts subarrayWithRange:NSMakeRange(2, [pathParts count] - 2)] componentsJoinedByString:@"/"]; NSString* rootPath = NIPathForDocumentsResource(nil); NSString* hashedPath = [self pathFromPath:resultPath]; NSString* diskPath = [rootPath stringByAppendingPathComponent:hashedPath]; [responseObject writeToFile:diskPath atomically:YES]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc postNotificationName:NIStringsDidChangeNotification object:nil userInfo:@{ NIStringsDidChangeFilePathKey: diskPath }]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; [_queue addOperation:requestOp]; } - (void)downloadJSONWithFilename:(NSString *)path { NSURL* url = [NSURL URLWithString:[_host stringByAppendingString:path]]; NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url]; AFHTTPRequestOperation* requestOp = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [requestOp setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSArray* pathParts = [[operation.request.URL absoluteString] pathComponents]; NSString* resultPath = [[pathParts subarrayWithRange:NSMakeRange(2, [pathParts count] - 2)] componentsJoinedByString:@"/"]; NSString* rootPath = NIPathForDocumentsResource(nil); NSString* hashedPath = [self pathFromPath:resultPath]; NSString* diskPath = [rootPath stringByAppendingPathComponent:hashedPath]; [responseObject writeToFile:diskPath atomically:YES]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc postNotificationName:NIJSONDidChangeNotification object:nil userInfo:@{ NIJSONDidChangeFilePathKey: diskPath, NIJSONDidChangeNameKey: path }]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; [_queue addOperation:requestOp]; } - (NSString *)pathFromPath:(NSString *)path { return NIMD5HashFromString(path); } #pragma mark - NICSSParserDelegate - (NSString *)cssParser:(NICSSParser *)parser pathFromPath:(NSString *)path { return [self pathFromPath:path]; } #pragma mark - Public - (NIStylesheet *)stylesheetForPath:(NSString *)path { return [_stylesheetCache stylesheetWithPath:path]; } - (void)watchSkinChanges { NSURL* url = [NSURL URLWithString:[_host stringByAppendingString:@"watch"]]; NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url]; request.timeoutInterval = kTimeoutInterval; AFHTTPRequestOperation* requestOp = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [requestOp setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSString* stringData = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSArray* files = [stringData componentsSeparatedByString:@"\n"]; for (NSString* filename in files) { if ([[filename lowercaseString] hasSuffix:@".strings"]) { [self downloadStringsWithFilename: filename]; } else if ([[filename lowercaseString] hasSuffix:@".json"]) { [self downloadJSONWithFilename:filename]; } else { [self downloadStylesheetWithFilename:filename]; } } // Immediately start watching for more skin changes. _retryCount = 0; [self watchSkinChanges]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if (_retryCount < kMaxNumberOfRetries) { ++_retryCount; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kRetryInterval * NSEC_PER_MSEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self watchSkinChanges]; }); } }]; [_queue addOperation:requestOp]; } -(void)enableBonjourDiscovery:(NSString *)serviceName { self.netBrowser = [[NSNetServiceBrowser alloc] init]; self.netBrowser.delegate = self; [self.netBrowser searchForServicesOfType:[NSString stringWithFormat:@"_%@._tcp", serviceName] inDomain:@""]; } -(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing { [self.netBrowser stop]; self.netBrowser = nil; self.netService = aNetService; aNetService.delegate = self; [aNetService resolveWithTimeout:15.0]; } -(void)netServiceDidResolveAddress:(NSNetService *)sender { _host = [NSString stringWithFormat:@"http://%@:%d/", [sender hostName], [sender port]]; self.netService = nil; [self watchSkinChanges]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIDOM.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @class NIStylesheet; /** * A leight-weight DOM-like object to which you attach views and stylesheets. * * @ingroup NimbusCSS * * To be clear: this is not an HTML DOM, but its intent is the same. NIDOM is designed * to simplify the view <=> stylesheet relationship. Add a view to the DOM and it will * automatically apply any applicable styles from the attached stylesheet. If the stylesheet * changes you can refresh the DOM and all registered views will be updated accordingly. * * Because NimbusCSS supports positioning and sizing using percentages and relative units, * the order of view registration is important. Generally, you should register superviews * first, so that any size calculations on their children can occur after their own * size has been determined. It's not feasible (or at least advisable) to try and * untangle these dependencies automatically. * * <h2>Example Use</h2> * * NIDOM is most useful when you create a single NIDOM per view controller. * @code NIStylesheet* stylesheet = [stylesheetCache stylesheetWithPath:@"root/root.css"]; // Create a NIDOM object in your view controller. _dom = [[NIDOM alloc] initWithStylesheet:stylesheet]; @endcode * * You then register views in the DOM during loadView or viewDidLoad. * @code // Registers a view by itself such that only "UILabel" rulesets will apply. [_dom registerView:_label]; // Register a view with a specific CSS class. Any rulesets with the ".background" scope will // apply to this view. [_dom registerView:self.view withCSSClass:@"background"]; @endcode * * Once the view controller unloads its view you must unregister all of the views from your DOM. * @code - (void)viewDidUnload { [_dom unregisterAllViews]; } @endcode */ @interface NIDOM : NSObject // Designated initializer. - (id)initWithStylesheet:(NIStylesheet *)stylesheet; + (id)domWithStylesheet:(NIStylesheet *)stylesheet; + (id)domWithStylesheetWithPathPrefix:(NSString *)pathPrefix paths:(NSString *)path, ...; + (id)domWithStylesheet:(NIStylesheet *)stylesheet andParentStyles: (NIStylesheet*) parentStyles; - (void)registerView:(UIView *)view; - (void)registerView:(UIView *)view withCSSClass:(NSString *)cssClass; - (void)registerView:(UIView *)view withCSSClass:(NSString *)cssClass andId: (NSString*) viewId; - (void)addCssClass: (NSString *) cssClass toView: (UIView*) view; - (void)removeCssClass: (NSString*) cssClass fromView: (UIView*) view; - (void)unregisterView:(UIView *)view; - (void)unregisterAllViews; - (void)refresh; - (void)refreshView: (UIView*) view; -(UIView*)viewById: (NSString*) viewId; -(NSString*) descriptionForView: (UIView*) view withName: (NSString*) viewName; -(NSString*) descriptionForAllViews; @property (nonatomic,unsafe_unretained) id target; @end /** @name Creating NIDOMs */ /** * Initializes a newly allocated DOM with the given stylesheet. * * @fn NIDOM::initWithStylesheet: */ /** * Returns an autoreleased DOM initialized with the given stylesheet. * * @fn NIDOM::domWithStylesheet: */ /** * Returns an autoreleased DOM initialized with a nil-terminated list of file paths. * * @fn NIDOM::domWithStylesheetWithPathPrefix:paths: */ /** * Returns an autoreleased DOM initialized with the given stylesheet and a "parent" stylesheet * that runs first. Doing this rather than compositing stylesheets can save memory and improve * performance in the common case where you have a set of global styles and a bunch of view * or view controller specific style sheets. * * @fn NIDOM::domWithStylesheet:andParentStyles: */ /** @name Registering Views */ /** * Registers the given view with the DOM. * * The view's class will be used as the CSS selector when applying styles from the stylesheet. * * @fn NIDOM::registerView: */ /** * Registers the given view with the DOM. * * The view's class as well as the given CSS class string will be used as the CSS selectors * when applying styles from the stylesheet. * * @fn NIDOM::registerView:withCSSClass: */ /** * Removes the given view from from the DOM. * * Once a view has been removed from the DOM it will not be restyled when the DOM is refreshed. * * @fn NIDOM::unregisterView: */ /** * Removes all views from from the DOM. * * @fn NIDOM::unregisterAllViews */ /** @name Re-Applying All Styles */ /** * Reapplies the stylesheet to all views. Since there may be positioning involved, * you may need to reapply if layout or sizes change. * * @fn NIDOM::refresh */ /** * Reapplies the stylesheet to a single view. Since there may be positioning involved, * you may need to reapply if layout or sizes change. * * @fn NIDOM::refreshView: */ /** * Removes the association of a view with a CSS class. Note that this doesn't * "undo" the styles that the CSS class generated, it just stops applying them * in the future. * * @fn NIDOM::removeCssClass:fromView: */ /** * Create an association of a view with a CSS class and apply relevant styles * immediately. * * @fn NIDOM::addCssClass:toView: */ /** @name Dynamic View Construction */ /** * Using the [UIView buildSubviews:inDOM:] extension allows you to build view * hierarchies from JSON (or anything able to convert to NSDictionary/NSArray * of simple types) documents, mostly for prototyping. Those documents can * specify selectors, and those selectors need a target. This target property * will be the target for all selectors in a given DOM. Truth is it only matters * during buildSubviews, so in theory you could set and reset it across multiple * build calls if you wanted to. * * @fn NIDOM::target */ /** @name Debugging */ /** * Describe what would be done to view given the existing registrations for it. In other words, you * must call one of the register view variants first before asking for a description. The current * implementations return actual objective-c code, using viewName as the target. This allows you to * theoretically replace the CSS infrastructure with generated code, if you choose to. More importantly, * it allows you to debug what's happening with view styling. * * @fn NIDOM::descriptionForView:withName: */ /** * Call descriptionForView for all registered views, in the order they would be applied during refresh * * @fn NIDOM::descriptionForAllViews */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIDOM.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIDOM.h" #import "NIStylesheet.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @interface NIDOM () @property (nonatomic,strong) NIStylesheet* stylesheet; @property (nonatomic,strong) NSMutableArray* registeredViews; @property (nonatomic,strong) NSMutableDictionary* viewToSelectorsMap; @property (nonatomic,strong) NSMutableDictionary* idToViewMap; @property (nonatomic,strong) NIDOM *parent; @end @implementation NIDOM + (id)domWithStylesheet:(NIStylesheet *)stylesheet { return [[self alloc] initWithStylesheet:stylesheet]; } + (id)domWithStylesheetWithPathPrefix:(NSString *)pathPrefix paths:(NSString *)path, ... { va_list ap; va_start(ap, path); NIStylesheet* compositeStylesheet = [[NIStylesheet alloc] init]; while (nil != path) { NIDASSERT([path isKindOfClass:[NSString class]]); if ([path isKindOfClass:[NSString class]]) { NIStylesheet* stylesheet = [[NIStylesheet alloc] init]; if ([stylesheet loadFromPath:path pathPrefix:pathPrefix]) { [compositeStylesheet addStylesheet:stylesheet]; } } path = va_arg(ap, NSString*); } va_end(ap); return [[self alloc] initWithStylesheet:compositeStylesheet]; } +(id)domWithStylesheet:(NIStylesheet *)stylesheet andParentStyles:(NIStylesheet *)parentStyles { NIDOM *dom = [[self alloc] initWithStylesheet:stylesheet]; if (parentStyles) { dom.parent = [NIDOM domWithStylesheet:parentStyles andParentStyles:nil]; } return dom; } - (id)initWithStylesheet:(NIStylesheet *)stylesheet { if ((self = [super init])) { _stylesheet = stylesheet; _registeredViews = [[NSMutableArray alloc] init]; _viewToSelectorsMap = [[NSMutableDictionary alloc] init]; } return self; } #pragma mark - Styling Views - (void)refreshStyleForView:(UIView *)view withSelectorName:(NSString *)selectorName { if (self.parent) { [self.parent.stylesheet applyStyleToView:view withClassName:selectorName inDOM:self]; } [_stylesheet applyStyleToView:view withClassName:selectorName inDOM:self]; } #pragma mark - Public - (id)keyForView:(UIView *)view { return [NSNumber numberWithLong:(long)view]; } - (void)registerSelector:(NSString *)selector withView:(UIView *)view { id key = [self keyForView:view]; NSMutableArray* selectors = [_viewToSelectorsMap objectForKey:key]; if (nil == selectors) { selectors = [[NSMutableArray alloc] init]; [_viewToSelectorsMap setObject:selectors forKey:key]; } [selectors addObject:selector]; } - (void)registerView:(UIView *)view { if (self.parent) { [self.parent registerView:view]; } NSString* selector = NSStringFromClass([view class]); [self registerSelector:selector withView:view]; NSArray *pseudos = nil; if ([view respondsToSelector:@selector(pseudoClasses)]) { pseudos = (NSArray*) [view performSelector:@selector(pseudoClasses)]; if (pseudos) { for (NSString *ps in pseudos) { [self registerSelector:[selector stringByAppendingString:ps] withView:view]; } } } [_registeredViews addObject:view]; [self refreshStyleForView:view withSelectorName:selector]; if (pseudos) { for (NSString *ps in pseudos) { [self refreshStyleForView:view withSelectorName:[selector stringByAppendingString:ps]]; } } } - (void)registerView:(UIView *)view withCSSClass:(NSString *)cssClass andId:(NSString *)viewId { // These are basically the least specific selectors (by our simple rules), so this needs to get registered first [self registerView:view withCSSClass:cssClass]; NSArray *pseudos = nil; if (viewId) { if (![viewId hasPrefix:@"#"]) { viewId = [@"#" stringByAppendingString:viewId]; } if (self.parent) { [self.parent registerSelector:viewId withView:view]; } [self registerSelector:viewId withView:view]; if ([view respondsToSelector:@selector(pseudoClasses)]) { pseudos = (NSArray*) [view performSelector:@selector(pseudoClasses)]; if (pseudos) { for (NSString *ps in pseudos) { if (self.parent) { [self.parent registerSelector:[viewId stringByAppendingString:ps] withView:view]; } [self registerSelector:[viewId stringByAppendingString:ps] withView:view]; } } } if (!_idToViewMap) { _idToViewMap = [[NSMutableDictionary alloc] init]; } [_idToViewMap setObject:view forKey:viewId]; // Run the id selectors last so they take precedence [self refreshStyleForView:view withSelectorName:viewId]; if (pseudos) { for (NSString *ps in pseudos) { [self refreshStyleForView:view withSelectorName:[viewId stringByAppendingString:ps]]; } } } } - (void)registerView:(UIView *)view withCSSClass:(NSString *)cssClass registerMainView: (BOOL) registerMainView { if (registerMainView) { if (self.parent) { [self.parent registerView:view withCSSClass:cssClass registerMainView:NO]; } [self registerView:view]; } if (cssClass) { [self addCssClass:cssClass toView:view]; } } - (void)registerView:(UIView *)view withCSSClass:(NSString *)cssClass { [self registerView:view withCSSClass:cssClass registerMainView:YES]; } -(void)addCssClass:(NSString *)cssClass toView:(UIView *)view { NSString* selector = [@"." stringByAppendingString:cssClass]; [self registerSelector:selector withView:view]; // This registers both the UIKit class name and the css class name for this view // Now, we also want to register the 'state based' selectors. Fun. NSArray *pseudos = nil; if ([view respondsToSelector:@selector(pseudoClasses)]) { pseudos = (NSArray*) [view performSelector:@selector(pseudoClasses)]; if (pseudos) { for (NSString *ps in pseudos) { [self registerSelector:[selector stringByAppendingString:ps] withView:view]; } } } [self refreshStyleForView:view withSelectorName:selector]; if (pseudos) { for (NSString *ps in pseudos) { [self refreshStyleForView:view withSelectorName:[selector stringByAppendingString:ps]]; } } } -(void)removeCssClass:(NSString *)cssClass fromView:(UIView *)view { NSString* selector = [@"." stringByAppendingString:cssClass]; NSString* pseudoBase = [selector stringByAppendingString:@":"]; NSMutableArray *selectors = [_viewToSelectorsMap objectForKey:[self keyForView:view]]; if (selectors) { // Iterate over the selectors finding the id selector (if any) so we can // also remove it from the id map for (int i = selectors.count-1; i >= 0; i--) { NSString *s = [selectors objectAtIndex:i]; if ([s isEqualToString:selector] && [s hasPrefix:pseudoBase]) { [selectors removeObjectAtIndex:i]; } } } } - (void)unregisterView:(UIView *)view { [_registeredViews removeObject:view]; NSArray *selectors = [_viewToSelectorsMap objectForKey:[self keyForView:view]]; if (selectors) { // Iterate over the selectors finding the id selector (if any) so we can // also remove it from the id map for (NSString *s in selectors) { if ([s characterAtIndex:0] == '#') { [_idToViewMap removeObjectForKey:s]; } } } [_viewToSelectorsMap removeObjectForKey:[self keyForView:view]]; } - (void)unregisterAllViews { [_registeredViews removeAllObjects]; [_viewToSelectorsMap removeAllObjects]; [_idToViewMap removeAllObjects]; } - (void)refresh { for (UIView* view in _registeredViews) { for (NSString* selector in [_viewToSelectorsMap objectForKey:[self keyForView:view]]) { [self refreshStyleForView:view withSelectorName:selector]; } } } - (void)refreshView:(UIView *)view { for (NSString* selector in [_viewToSelectorsMap objectForKey:[self keyForView:view]]) { [self refreshStyleForView:view withSelectorName:selector]; } } -(UIView *)viewById:(NSString *)viewId { if (![viewId hasPrefix:@"#"]) { viewId = [@"#" stringByAppendingString:viewId]; } return [_idToViewMap objectForKey:viewId]; } -(NSString *)descriptionForView:(UIView *)view withName:(NSString *)viewName { NSMutableString *description = [[NSMutableString alloc] init]; BOOL appendedStyleInfo = NO; for (NSString *selector in [_viewToSelectorsMap objectForKey:[self keyForView:view]]) { BOOL appendedSelectorInfo = NO; NSString *additional = nil; if (self.parent) { additional = [self.parent.stylesheet descriptionForView: view withClassName: selector inDOM:self andViewName: viewName]; if (additional && additional.length) { if (!appendedStyleInfo) { appendedStyleInfo = YES; [description appendFormat:@"// Styles for %@\n", viewName]; } if (!appendedSelectorInfo) { appendedSelectorInfo = YES; [description appendFormat:@"// Selector %@\n", selector]; } [description appendString:additional]; } } additional = [_stylesheet descriptionForView:view withClassName: selector inDOM:self andViewName: viewName]; if (additional && additional.length) { if (!appendedStyleInfo) { appendedStyleInfo = YES; [description appendFormat:@"// Styles for %@\n", viewName]; } if (!appendedSelectorInfo) { [description appendFormat:@"// Selector %@\n", selector]; } [description appendString:additional]; } } return description; } -(NSString *)descriptionForAllViews { NSMutableString *description = [[NSMutableString alloc] init]; int viewCount = 0; for (UIView *view in _registeredViews) { [description appendString:@"\n///////////////////////////////////////////////////////////////////////////////////////////////////\n"]; viewCount++; // This is a little hokey - because we don't get individual view names we have to come up with some. __block NSString *vid = nil; [[_viewToSelectorsMap objectForKey:[self keyForView:view]] enumerateObjectsUsingBlock:^(NSString *selector, NSUInteger idx, BOOL *stop) { if ([selector hasPrefix:@"#"]) { vid = [selector substringFromIndex:1]; *stop = YES; } }]; if (vid) { [description appendFormat:@"UIView *%@_%d = [dom viewById: @\"#%@\"];\n", [view class], viewCount, vid]; } [description appendString:[self descriptionForView:view withName:[NSString stringWithFormat:@"%@_%d", [view class], viewCount]]]; } return description; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> @class NICSSRuleset; @class NIDOM; /** * The protocol used by the NIStylesheet to apply NICSSRuleSets to views. * * @ingroup NimbusCSS * * If you implement this protocol in a category it is recommended that you implement the * logic as a separate method and call that method from applyStyleWithRuleSet: so as to allow * subclasses to call super implementations. See UILabel+NIStyleable.h/m for an example. */ @protocol NIStyleable <NSObject> @required /** * Please implement applyStyleWithRuleSet:inDOM: instead to support relative positioning. The deprecated * warning will only catch calls to super rather than implementors, but not sure what else to do. */ - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet DEPRECATED_ATTRIBUTE; /** * The given ruleset should be applied to the view. The ruleset represents a composite of all * rulesets in the applicable stylesheet. */ - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; @optional /** * Tells the CSS engine a set of pseudo classes that apply to views of this class. * In the case of UIButton, for example, this includes :selected, :highlighted, and :disabled. * In CSS, you specify these with selectors like UIButton:active. If you implement this you need to respond * to applyStyleWithRuleSet:forPseudoClass: * * Make sure to include the leading colon. */ - (NSArray*) pseudoClasses; /** * Applies the given rule set to this view but for a pseudo class. Thus it only supports the subset of * properties that can be set on states of the view. (e.g. UIButton textColor or background) */ - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet forPseudoClass: (NSString*) pseudo inDOM: (NIDOM*) dom; /** * Return a string describing what would be done with the view. The current implementations return actual * Objective-C using the view name as the message target. The intent is to allow developers to debug * the logic, but also to be able to strip out the CSS infrastructure if desired and replace it with manual code. */ - (NSString*) descriptionWithRuleSet: (NICSSRuleset*) ruleSet forPseudoClass: (NSString*) pseudo inDOM: (NIDOM*) dom withViewName: (NSString*) name; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIStylesheet.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @protocol NICSSParserDelegate; @class NICSSRuleset; @class NIDOM; /** * The notification key for when a stylesheet has changed. * * @ingroup NimbusCSS * * This notification will be sent with the stylesheet as the object. Listeners should add * themselves using the stylesheet object that they are interested in. * * The NSNotification userInfo object will be nil. */ extern NSString* const NIStylesheetDidChangeNotification; /** * Loads and caches information regarding a specific stylesheet. * * @ingroup NimbusCSS * * Use this object to load and parse a CSS stylesheet from disk and then apply the stylesheet * to views. Rulesets are cached on demand and cleared when a memory warning is received. * * Stylesheets can be merged using the addStylesheet: method. * * Cached rulesets are released when a memory warning is received. */ @interface NIStylesheet : NSObject { @private NSDictionary* _rawRulesets; NSMutableDictionary* _ruleSets; NSDictionary* _significantScopeToScopes; } @property (nonatomic, readonly, copy) NSSet* dependencies; - (BOOL)loadFromPath:(NSString *)path pathPrefix:(NSString *)pathPrefix delegate:(id<NICSSParserDelegate>)delegate; - (BOOL)loadFromPath:(NSString *)path pathPrefix:(NSString *)path; - (BOOL)loadFromPath:(NSString *)path; - (void)addStylesheet:(NIStylesheet *)stylesheet; - (void)applyStyleToView:(UIView *)view withClassName:(NSString *)className inDOM: (NIDOM*)dom; - (NSString*)descriptionForView:(UIView *)view withClassName:(NSString *)className inDOM: (NIDOM*)dom andViewName: (NSString*) viewName; - (NICSSRuleset *)rulesetForClassName:(NSString *)className; /** * The class to create for rule sets. Default is NICSSRuleset */ +(Class)rulesetClass; /** * Set the class created to hold rule sets. Default is NICSSRuleset */ +(void)setRulesetClass: (Class) rulesetClass; @end /** @name Properties */ /** * A set of NSString filenames for the @htmlonly@imports@endhtmlonly in this stylesheet. * * @fn NIStylesheet::dependencies */ /** @name Loading Stylesheets */ /** * Loads and parses a CSS file from disk. * * @fn NIStylesheet::loadFromPath:pathPrefix:delegate: * @param path The path of the file to be read. * @param pathPrefix [optional] A prefix path that will be prepended to the given path * as well as any imported files. * @param delegate [optional] A delegate that can reprocess paths. * @returns YES if the CSS file was successfully loaded and parsed, NO otherwise. */ /** * @fn NIStylesheet::loadFromPath:pathPrefix: * @sa NIStylesheet::loadFromPath:pathPrefix:delegate: */ /** * @fn NIStylesheet::loadFromPath: * @sa NIStylesheet::loadFromPath:pathPrefix:delegate: */ /** @name Compositing Stylesheets */ /** * Merge another stylesheet with this one. * * All property values in the given stylesheet will overwrite values in this stylesheet. * Non-overlapping values will not be modified. * * @fn NIStylesheet::addStylesheet: */ /** @name Applying Stylesheets to Views */ /** * Apply any rulesets that match the className to the given view. * * @fn NIStylesheet::applyStyleToView:withClassName: * @param view The view for which styles should be applied. * @param className Either the view's class as a string using NSStringFromClass([view class]); * or a CSS class selector such as ".myClassSelector". * @param dom The DOM responsible for applying this style */ /** * Returns an autoreleased ruleset for the given class name. * * @fn NIStylesheet::rulesetForClassName: * @param className Either the view's class as a string using NSStringFromClass([view class]); * or a CSS class selector such as ".myClassSelector". */ /** @name Debugging */ /** * Build a string describing the rules that would be applied to the view given a css class name in a DOM. * Current implementations output Objective-C code that use viewName as the target. * * @fn NIStylesheet::descriptionForView:withClassName:inDOM:andViewName: */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIStylesheet.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIStylesheet.h" #import "NICSSParser.h" #import "NICSSRuleset.h" #import "NIStyleable.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NSString* const NIStylesheetDidChangeNotification = @"NIStylesheetDidChangeNotification"; static Class _rulesetClass; @interface NIStylesheet() @property (nonatomic, readonly, copy) NSDictionary* rawRulesets; @property (nonatomic, readonly, copy) NSDictionary* significantScopeToScopes; @end @implementation NIStylesheet - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (id)init { if ((self = [super init])) { _ruleSets = [[NSMutableDictionary alloc] init]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc addObserver: self selector: @selector(didReceiveMemoryWarning:) name: UIApplicationDidReceiveMemoryWarningNotification object: nil]; } return self; } #pragma mark - Rule Sets // Builds a map of significant scopes to full scopes. // // For example, consider the following rulesets: // // .root UIButton { // } // .apple UIButton { // } // UIButton UIView { // } // UIView { // } // // The generated scope map will look like: // // UIButton => (.root UIButton, .apple UIButton) // UIView => (UIButton UIView, UIView) // - (void)rebuildSignificantScopeToScopes { NSMutableDictionary* significantScopeToScopes = [[NSMutableDictionary alloc] initWithCapacity:[_rawRulesets count]]; for (NSString* scope in _rawRulesets) { NSArray* parts = [scope componentsSeparatedByString:@" "]; NSString* mostSignificantScopePart = [parts lastObject]; // TODO (jverkoey Oct 6, 2011): We should respect CSS specificity. Right now this will // give higher precedance to newer styles. Instead, we should prefer styles that have more // selectors. NSMutableArray* scopes = [significantScopeToScopes objectForKey:mostSignificantScopePart]; if (nil == scopes) { scopes = [[NSMutableArray alloc] initWithObjects:scope, nil]; [significantScopeToScopes setObject:scopes forKey:mostSignificantScopePart]; } else { [scopes addObject:scope]; } } _significantScopeToScopes = [significantScopeToScopes copy]; } - (void)ruleSetsDidChange { [self rebuildSignificantScopeToScopes]; } #pragma mark - NSNotifications - (void)reduceMemory { _ruleSets = [[NSMutableDictionary alloc] init]; } - (void)didReceiveMemoryWarning:(void*)object { [self reduceMemory]; } #pragma mark - Public - (BOOL)loadFromPath:(NSString *)path { return [self loadFromPath:path pathPrefix:nil delegate:nil]; } - (BOOL)loadFromPath:(NSString *)path pathPrefix:(NSString *)pathPrefix { return [self loadFromPath:path pathPrefix:pathPrefix delegate:nil]; } - (BOOL)loadFromPath:(NSString *)path pathPrefix:(NSString *)pathPrefix delegate:(id<NICSSParserDelegate>)delegate { BOOL loadDidSucceed = NO; @synchronized(self) { _rawRulesets = nil; _significantScopeToScopes = nil; _ruleSets = [[NSMutableDictionary alloc] init]; NICSSParser* parser = [[NICSSParser alloc] init]; NSDictionary* results = [parser dictionaryForPath:path pathPrefix:pathPrefix delegate:delegate]; if (nil != results && ![parser didFailToParse]) { _rawRulesets = results; loadDidSucceed = YES; } if (loadDidSucceed) { [self ruleSetsDidChange]; } } return loadDidSucceed; } - (void)addStylesheet:(NIStylesheet *)stylesheet { NIDASSERT(nil != stylesheet); if (nil == stylesheet) { return; } @synchronized(self) { NSMutableDictionary* compositeRuleSets = [self.rawRulesets mutableCopy]; BOOL ruleSetsDidChange = NO; for (NSString* selector in stylesheet.rawRulesets) { NSDictionary* incomingRuleSet = [stylesheet.rawRulesets objectForKey:selector]; NSDictionary* existingRuleSet = [self.rawRulesets objectForKey:selector]; // Don't bother adding empty rulesets. if ([incomingRuleSet count] > 0) { ruleSetsDidChange = YES; if (nil == existingRuleSet) { // There is no rule set of this selector - simply add the new one. [compositeRuleSets setObject:incomingRuleSet forKey:selector]; continue; } NSMutableDictionary* compositeRuleSet = [existingRuleSet mutableCopy]; // Add the incoming rule set entries, overwriting any existing ones. [compositeRuleSet addEntriesFromDictionary:incomingRuleSet]; [compositeRuleSets setObject:compositeRuleSet forKey:selector]; } } _rawRulesets = [compositeRuleSets copy]; if (ruleSetsDidChange) { [self ruleSetsDidChange]; } } } - (NSString*)descriptionForView:(UIView *)view withClassName:(NSString *)className inDOM:(NIDOM *)dom andViewName:(NSString *)viewName { NSMutableString *description = [[NSMutableString alloc] init]; NICSSRuleset *ruleset = [self rulesetForClassName:className]; if (nil != ruleset) { NSRange r = [className rangeOfString:@":"]; if ([view respondsToSelector:@selector(descriptionWithRuleSet:forPseudoClass:inDOM:withViewName:)]) { if (r.location != NSNotFound) { [description appendString:[(id<NIStyleable>)view descriptionWithRuleSet:ruleset forPseudoClass:[className substringFromIndex:r.location+1] inDOM:dom withViewName:viewName]]; } else { [description appendString:[(id<NIStyleable>)view descriptionWithRuleSet:ruleset forPseudoClass:nil inDOM:dom withViewName:viewName]]; } } else { [description appendFormat:@"// Description not supported for %@ with selector %@\n", view, className]; } } return description; } #pragma mark Applying Styles to Views - (void)applyRuleSet:(NICSSRuleset *)ruleSet toView:(UIView *)view inDOM: (NIDOM*)dom { if ([view respondsToSelector:@selector(applyStyleWithRuleSet:inDOM:)]) { [(id<NIStyleable>)view applyStyleWithRuleSet:ruleSet inDOM:dom]; } if ([view respondsToSelector:@selector(applyStyleWithRuleSet:)]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" [(id<NIStyleable>)view applyStyleWithRuleSet:ruleSet]; #pragma clang diagnostic pop } } - (void)applyStyleToView:(UIView *)view withClassName:(NSString *)className inDOM:(NIDOM *)dom { NICSSRuleset *ruleset = [self rulesetForClassName:className]; if (nil != ruleset) { NSRange r = [className rangeOfString:@":"]; if (r.location != NSNotFound && [view respondsToSelector:@selector(applyStyleWithRuleSet:forPseudoClass:inDOM:)]) { [(id<NIStyleable>)view applyStyleWithRuleSet:ruleset forPseudoClass: [className substringFromIndex:r.location+1] inDOM:dom]; } else { [self applyRuleSet:ruleset toView:view inDOM:dom]; } } } - (NICSSRuleset*) addSelectors: (NSArray*) selectors toRuleset: (NICSSRuleset*) ruleSet forClassName: (NSString*) className { if ([selectors count] > 0) { // Gather all of the rule sets for this view into a composite rule set. ruleSet = ruleSet ?: [_ruleSets objectForKey:className]; if (nil == ruleSet) { ruleSet = [[[NIStylesheet rulesetClass] alloc] init]; // Composite the rule sets into one. for (NSString* selector in selectors) { [ruleSet addEntriesFromDictionary:[_rawRulesets objectForKey:selector]]; } NIDASSERT(nil != _ruleSets); [_ruleSets setObject:ruleSet forKey:className]; } } return ruleSet; } - (NICSSRuleset *)rulesetForClassName:(NSString *)className { NSArray* selectors = [_significantScopeToScopes objectForKey:className]; return [self addSelectors:selectors toRuleset:nil forClassName:className]; } - (NSSet *)dependencies { return [_rawRulesets objectForKey:kDependenciesSelectorKey]; } +(Class)rulesetClass { return _rulesetClass ?: [NICSSRuleset class]; } +(void)setRulesetClass:(Class)rulesetClass { _rulesetClass = rulesetClass; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIStylesheetCache.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> @class NIStylesheet; /** * A simple in-memory cache for stylesheets. * * @ingroup NimbusCSS * * It is recommended that you use this object to store stylesheets in a centralized location. * Ideally you would have one stylesheet cache throughout the lifetime of your application. * * * <h2>Using a stylesheet cache with Chameleon</h2> * * A stylesheet cache must be used with the Chameleon observer so that changes can be sent * for a given stylesheet. This is because changes are sent using the stylesheet object as * the notification object, so a listener must register notifications with the stylesheet as * the object. * @code NIStylesheet* stylesheet = [stylesheetCache stylesheetWithPath:@"common.css"]; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(stylesheetDidChange) name:NIStylesheetDidChangeNotification object:stylesheet]; @endcode */ @interface NIStylesheetCache : NSObject { @private NSMutableDictionary* _pathToStylesheet; NSString* _pathPrefix; } @property (nonatomic, readonly, copy) NSString* pathPrefix; // Designated initializer. - (id)initWithPathPrefix:(NSString *)pathPrefix; - (NIStylesheet *)stylesheetWithPath:(NSString *)path loadFromDisk:(BOOL)loadFromDisk; - (NIStylesheet *)stylesheetWithPath:(NSString *)path; @end /** * The path prefix that will be used to load stylesheets. * * @fn NIStylesheetCache::pathPrefix */ /** * Initializes a newly allocated stylesheet cache with a given path prefix. * * @fn NIStylesheetCache::initWithPathPrefix: */ /** * Fetches a stylesheet from the in-memory cache if it exists or loads the stylesheet from disk if * loadFromDisk is YES. * * @fn NIStylesheetCache::stylesheetWithPath:loadFromDisk: */ /** * Fetches a stylesheet from the in-memory cache if it exists or loads the stylesheet from disk. * * Short form for calling [cache stylesheetWithPath:path loadFromDisk:YES] * * @fn NIStylesheetCache::stylesheetWithPath: */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIStylesheetCache.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIStylesheetCache.h" #import "NIStylesheet.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @implementation NIStylesheetCache - (id)initWithPathPrefix:(NSString *)pathPrefix { if ((self = [super init])) { _pathToStylesheet = [[NSMutableDictionary alloc] init]; _pathPrefix = [pathPrefix copy]; } return self; } - (id)init { // This method should not be called directly. NIDASSERT(NO); return [self initWithPathPrefix:nil]; } - (NIStylesheet *)stylesheetWithPath:(NSString *)path loadFromDisk:(BOOL)loadFromDisk { NIStylesheet* stylesheet = [_pathToStylesheet objectForKey:path]; if (nil == stylesheet) { stylesheet = [[NIStylesheet alloc] init]; if (loadFromDisk) { BOOL didSucceed = [stylesheet loadFromPath:path pathPrefix:_pathPrefix]; if (didSucceed) { [_pathToStylesheet setObject:stylesheet forKey:path]; } else { [_pathToStylesheet removeObjectForKey:path]; stylesheet = nil; } } else { [_pathToStylesheet setObject:stylesheet forKey:path]; } } return stylesheet; } - (NIStylesheet *)stylesheetWithPath:(NSString *)path { return [self stylesheetWithPath:path loadFromDisk:YES]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NITextField+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // Originally written by Max Metral // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NITextField.h" @class NICSSRuleset; @class NIDOM; @interface NITextField (NIStyleable) /** * Applies the given rule set to this text field. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyNITextFieldStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; /** * Applies the given rule set to this label. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. Since some of the view * styles (e.g. positioning) may rely on some label elements (like text), this is called * before the view styling is done. */ - (void)applyNITextFieldStyleBeforeViewWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; /** * Applies the given rule set to this text field but for a pseudo class. Thus it only supports the subset of * properties that can be set on states of the button. (There's no fancy stuff that applies the styles * manually on state transitions. * * Since UIView doesn't have psuedo's, we don't need the specific version for UIButton like we do with * applyButtonStyleWithRuleSet. */ - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet forPseudoClass: (NSString*) pseudo inDOM: (NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NITextField+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // Originally written by Max Metral // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NITextField+NIStyleable.h" #import "UITextField+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NIDOM.h" #import "NICSSRuleset.h" #import "NIUserInterfaceString.h" #import "NIPreprocessorMacros.h" NI_FIX_CATEGORY_BUG(NITextField_NIStyleable) @implementation NITextField (NIStyleable) - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyNITextFieldStyleBeforeViewWithRuleSet:ruleSet inDOM:dom]; [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyNITextFieldStyleWithRuleSet:ruleSet inDOM:dom]; } -(void)applyStyleWithRuleSet:(NICSSRuleset*)ruleSet forPseudoClass:(NSString *)pseudo inDOM:(NIDOM*)dom { if (ruleSet.hasFont) { self.placeholderFont = ruleSet.font; } if (ruleSet.hasTextColor) { self.placeholderTextColor = ruleSet.textColor; } if (ruleSet.hasTextKey) { NIUserInterfaceString *nis = [[NIUserInterfaceString alloc] initWithKey:ruleSet.textKey]; [nis attach:self withSelector:@selector(setPlaceholder:)]; } } -(void)applyNITextFieldStyleBeforeViewWithRuleSet:(NICSSRuleset*)ruleSet inDOM:(NIDOM*)dom { [self applyTextFieldStyleBeforeViewWithRuleSet:ruleSet inDOM:dom]; if (ruleSet.hasTitleInsets) { self.textInsets = ruleSet.titleInsets; } } -(void)applyNITextFieldStyleWithRuleSet:(NICSSRuleset*)ruleSet inDOM:(NIDOM*)dom { [self applyTextFieldStyleWithRuleSet:ruleSet inDOM:dom]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIUserInterfaceString.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // Originally written by Max Metral // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> /** * The notification key for when a strings file has changed. * * @ingroup NimbusCSS * * This notification will be sent globally at the moment. * * The NSNotification userInfo object will contain the local disk path of the strings file. */ extern NSString* const NIStringsDidChangeNotification; extern NSString* const NIStringsDidChangeFilePathKey; /** * A very thin derivative of NSString that will track what user interface * elements it has been assigned to and watch for updates via Chameleon */ @class NIUserInterfaceString; /** * A simple NSLocalizedString like macro to make it easier to use NIUserInterfaceStrings */ #define NILocalizedStringWithDefault(key,default) [[NIUserInterfaceString alloc] initWithKey: key defaultValue: default] #define NILocalizedStringWithKey(key) [[NIUserInterfaceString alloc] initWithKey: key]; @protocol NIUserInterfaceStringResolver @required /** * The default resolver will just call NSLocalizedString, but also watch the notification center * for incoming updates from Chameleon */ -(NSString*)stringForKey: (NSString*) key withDefaultValue: (NSString*) value; /** * Determine whether string change tracking is enabled or not. Since there * is some overhead to this, the default behavior is to return YES * if DEBUG is defined, and NO otherwise. */ -(BOOL)isChangeTrackingEnabled; @end /** * A very thin derivative of NSString that will track what user interface * elements it has been assigned to and watch for updates via Chameleon */ @interface NIUserInterfaceString : NSObject @property (nonatomic,strong) NSString *string; @property (nonatomic,strong) NSString *originalKey; /** * The global resolver for strings by key */ +(id<NIUserInterfaceStringResolver>)stringResolver; /** * Set the global resolver for strings by key */ +(void)setStringResolver:(id<NIUserInterfaceStringResolver>)stringResolver; /** * Create a string with the given key using the resolver. */ -(id)initWithKey: (NSString*) key; /** * Create a string with the given key using the resolver and a default value if * not found. */ -(id)initWithKey: (NSString*) key defaultValue: (NSString*) value; /** * Attach a string to a user interface element. Any changes to the string will * be sent to the view until the view is dealloced or the string is detached. * This method uses setText if available, else setTitle or asserts. */ -(void)attach: (UIView*) view; /** * Attach a string to an element via a selector. The selector must take * one argument. */ -(void)attach: (id) element withSelector: (SEL) selector; /** * Attach a string to a user interface element that supports control states. * Any changes to the string will be sent to the view until the view is * dealloced or the string is detached. */ -(void)attach: (UIView*) view withSelector: (SEL) selector forControlState: (UIControlState) state; /** * Detach a string from a user interface element. This does not "unset" * the string value itself but it essentially stops tracking changes * and frees internal structures. */ -(void)detach: (UIView*) view; /** * Attach a string to an element via a selector. The selector must take * one argument. */ -(void)detach: (id) element withSelector: (SEL) selector; /** * Attach a string to an element via a selector. The selector must take * one argument. */ -(void)detach: (UIView*) element withSelector: (SEL) selector forControlState: (UIControlState) state; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NIUserInterfaceString.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIUserInterfaceString.h" #import "NIDebuggingTools.h" #import <objc/runtime.h> static NSMutableDictionary* sStringToViewMap; static char sBaseStringAssocationKey; static id<NIUserInterfaceStringResolver> sResolver; NSString* const NIStringsDidChangeNotification = @"NIStringsDidChangeNotification"; NSString* const NIStringsDidChangeFilePathKey = @"NIStringsPathKey"; //////////////////////////////////////////////////////////////////////////////// /** * Information about an attachment */ @interface NIUserInterfaceStringAttachment : NSObject @property (unsafe_unretained,nonatomic) id element; @property (assign) SEL setter; @property (assign) UIControlState controlState; @property (assign) BOOL setterIsWithControlState; -(void)attach: (NSString*) value; @end //////////////////////////////////////////////////////////////////////////////// /** * This class exists solely to be attached to objects that strings have been * attached to so that we can easily detach them on dealloc */ @interface NIUserInterfaceStringDeallocTracker : NSObject +(void)attachString: (NIUserInterfaceString*) string withInfo: (NIUserInterfaceStringAttachment*) attachment; @property (strong, nonatomic) NIUserInterfaceStringAttachment *attachment; @property (strong, nonatomic) NIUserInterfaceString *string; @end //////////////////////////////////////////////////////////////////////////////// @interface NIUserInterfaceStringResolverDefault : NSObject < NIUserInterfaceStringResolver > // The path of a file that was loaded from Chameleon that should be checked first // before the built in bundle @property (nonatomic,strong) NSDictionary *overrides; // For dev/debug purposes, if we read "/* SHOW KEYS */" at the front of the file, we'll // just return all keys in the UI @property (nonatomic,assign) BOOL returnKeys; @end //////////////////////////////////////////////////////////////////////////////// @implementation NIUserInterfaceString +(void)setStringResolver:(id<NIUserInterfaceStringResolver>)stringResolver { sResolver = stringResolver; } +(id<NIUserInterfaceStringResolver>)stringResolver { return sResolver ?: (sResolver = [[NIUserInterfaceStringResolverDefault alloc] init]); } -(NSMutableDictionary*) viewMap { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sStringToViewMap = [[NSMutableDictionary alloc] init]; }); return sStringToViewMap; } //////////////////////////////////////////////////////////////////////////////// -(id)initWithKey:(NSString *)key { return [self initWithKey:key defaultValue:nil]; } -(id)initWithKey:(NSString *)key defaultValue: (NSString*) value { NSString *v =[[NIUserInterfaceString stringResolver] stringForKey:key withDefaultValue:value]; if (!v) { return nil; } self = [super init]; if (self) { _string = v; _originalKey = key; } return self; } //////////////////////////////////////////////////////////////////////////////// -(void)attach:(UIView *)view { if ([view respondsToSelector:@selector(setText:)]) { // UILabel [self attach: view withSelector:@selector(setText:)]; } else if ([view respondsToSelector:@selector(setTitle:forState:)]) { [self attach:view withSelector:@selector(setTitle:forState:) withControlState:UIControlStateNormal hasControlState:YES]; } else if ([view respondsToSelector:@selector(setTitle:)]) { [self attach: view withSelector:@selector(setTitle:)]; } else { NIDASSERT([view respondsToSelector:@selector(setText:)] || [view respondsToSelector:@selector(setTitle:)]); } } //////////////////////////////////////////////////////////////////////////////// -(void)attach:(id)element withSelector:(SEL)selector { [self attach:element withSelector:selector withControlState:UIControlStateNormal hasControlState:NO]; } //////////////////////////////////////////////////////////////////////////////// -(void)attach:(UIView *)view withSelector:(SEL)selector forControlState:(UIControlState)state { [self attach:view withSelector:selector withControlState:state hasControlState:YES]; } //////////////////////////////////////////////////////////////////////////////// -(void)attach:(id)element withSelector:(SEL)selector withControlState: (UIControlState) state hasControlState: (BOOL) hasControlState { NIUserInterfaceStringAttachment *attachment = [[NIUserInterfaceStringAttachment alloc] init]; attachment.element = element; attachment.controlState = state; attachment.setterIsWithControlState = hasControlState; attachment.setter = selector; // If we're keeping track of attachments, set all that up. Else just call the selector if ([[NIUserInterfaceString stringResolver] isChangeTrackingEnabled]) { NSMutableDictionary *viewMap = self.viewMap; @synchronized (viewMap) { // Call this first, because if there's an existing association, it will detach it in dealloc [NIUserInterfaceStringDeallocTracker attachString:self withInfo:attachment]; id existing = [viewMap objectForKey:_originalKey]; if (!existing) { // Simple, no map exists, make one [viewMap setObject:attachment forKey:_originalKey]; } else if ([existing isKindOfClass: [NIUserInterfaceStringAttachment class]]) { // An attachment exists, convert it to a list NSMutableArray *list = [[NSMutableArray alloc] initWithCapacity:2]; [list addObject:existing]; [list addObject:attachment]; [viewMap setObject:list forKey:_originalKey]; } else { // NSMutableArray* NSMutableArray *a = (NSMutableArray*) existing; [a addObject: attachment]; } } } [attachment attach: _string]; } //////////////////////////////////////////////////////////////////////////////// -(void)detach:(UIView *)view { if ([view respondsToSelector:@selector(setText:)]) { // UILabel [self detach: view withSelector:@selector(setText:) withControlState:UIControlStateNormal hasControlState:NO]; } else if ([view respondsToSelector:@selector(setTitle:)]) { [self detach: view withSelector:@selector(setTitle:) withControlState:UIControlStateNormal hasControlState:NO]; } else { NIDASSERT([view respondsToSelector:@selector(setText:)] || [view respondsToSelector:@selector(setTitle:)]); } } -(void)detach:(id)element withSelector:(SEL)selector { [self detach:element withSelector:selector withControlState:UIControlStateNormal hasControlState:NO]; } -(void)detach:(UIView *)element withSelector:(SEL)selector forControlState:(UIControlState)state { [self detach:element withSelector:selector withControlState:state hasControlState:YES]; } -(void)detach:(id)element withSelector:(SEL)selector withControlState: (UIControlState) state hasControlState: (BOOL) hasControlState { NSMutableDictionary *viewMap = self.viewMap; @synchronized (viewMap) { } } @end //////////////////////////////////////////////////////////////////////////////// @implementation NIUserInterfaceStringResolverDefault -(id)init { self = [super init]; if (self) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stringsDidChange:) name:NIStringsDidChangeNotification object:nil]; } return self; } -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } -(void)stringsDidChange: (NSNotification*) notification { NSString *path = [notification.userInfo objectForKey:NIStringsDidChangeFilePathKey]; NSString *content = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; if ([content hasPrefix:@"/* SHOW KEYS */"]) { self.returnKeys = YES; } else { self.returnKeys = NO; } self.overrides = [[NSDictionary alloc] initWithContentsOfFile:path]; if (sStringToViewMap && self.overrides.count > 0) { @synchronized (sStringToViewMap) { [sStringToViewMap enumerateKeysAndObjectsUsingBlock:^(NSString* key, id obj, BOOL *stop) { NSString *o = self.returnKeys ? key : [self.overrides objectForKey:key]; if (o) { if ([obj isKindOfClass:[NIUserInterfaceStringAttachment class]]) { [((NIUserInterfaceStringAttachment*)obj) attach: o]; } else { NSArray *attachments = (NSArray*) obj; for (NIUserInterfaceStringAttachment *a in attachments) { [a attach:o]; } } } }]; } } } -(NSString *)stringForKey:(NSString *)key withDefaultValue:(NSString *)value { if (self.returnKeys) { return key; // TODO should we maybe return } if (self.overrides) { NSString *overridden = [self.overrides objectForKey:key]; if (overridden) { return overridden; } } return NSLocalizedStringWithDefaultValue(key, nil, [NSBundle mainBundle], value, nil); } -(BOOL)isChangeTrackingEnabled { #ifdef DEBUG return YES; #else return NO; #endif } @end //////////////////////////////////////////////////////////////////////////////// @implementation NIUserInterfaceStringAttachment -(void)attach: (NSString*) value { if (self.setterIsWithControlState) { NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[_element methodSignatureForSelector:_setter]]; [inv setSelector:_setter]; [inv setTarget:_element]; [inv setArgument:&value atIndex:2]; //this is the string to set (0 and 1 are self and message respectively) [inv setArgument:&_controlState atIndex:3]; [inv invoke]; } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [_element performSelector:_setter withObject:value]; #pragma clang diagnostic pop } } @end //////////////////////////////////////////////////////////////////////////////// @implementation NIUserInterfaceStringDeallocTracker +(void)attachString:(NIUserInterfaceString *)string withInfo:(NIUserInterfaceStringAttachment *)attachment { NIUserInterfaceStringDeallocTracker *tracker = [[NIUserInterfaceStringDeallocTracker alloc] init]; tracker.attachment = attachment; tracker.string = string; char* key = &sBaseStringAssocationKey; if (attachment.setterIsWithControlState) { key += attachment.controlState; } objc_setAssociatedObject(attachment.element, key, tracker, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(void)dealloc { [self.string detach:self.attachment.element withSelector:self.attachment.setter withControlState:self.attachment.controlState hasControlState:self.attachment.setterIsWithControlState]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/NimbusCSS.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> /** * @defgroup NimbusCSS Nimbus CSS * @{ * * <div id="github" feature="css"></div> * * Nimbus CSS allows you to use cascading stylesheets to theme your native iOS application. * Stylesheets provide a number of advantages over Interface Builder and native code. * * - Diffing CSS files is much easier than diffing Interface Builder's xibs. * - CSS allows you to define cascading styles. Change one line and an entire class of views * throughout your application will change. * - CSS can be downloaded and swapped out post-App Store submission if you want to make any * minor stylistic changes in production. * - On that same note, CSS stylesheets can be swapped at runtime allowing you to easily change * the application's UI when the app state changes. A good example of this is the Rdio app * when you go into offline mode and the app's online components gray out. * - Chameleon - modify CSS files and watch the changes affect your app in real time. * * <h2>How to Create a Stylesheet</h2> * * Start by creating a .css file. Add it to your project, ensuring that you include it in * the copy resources phase. Place all of your CSS files in a subdirectory and add the folder * to your project by creating a folder reference. Creating a folder reference will ensure * that your subdirectories are maintained when the CSS files are copied to the device. * * You can then load the stylesheet: * @code // In this example all of the app's css files are in a "css" folder. The "css" folder would be // dragged into the Xcode project with the "Create folder reference" option selected. NSString* pathPrefix = NIPathForBundleResource(nil, @"css"); NIStylesheet* stylesheet = [[[NIStylesheet alloc] init] autorelease]; if ([stylesheet loadFromPath:"common.css" pathPrefix:pathPrefix]) { // Successfully loaded <bundlePath>/css/common.css } @endcode * * * <h2>Recommended Procedure for Storing Stylesheets</h2> * * Use a global NIStylesheetCache object to store your stylesheets in memory. Parsing a stylesheet * is fast but care should be taken to avoid loading a stylesheet more often than necessary. * By no means should you be allocating new stylesheets in tight loops. * Using a global NIStylesheetCache will make it easy to ensure that your stylesheets are * cached in memory and easily accessible. * * Another advantage to using a global NIStylesheetCache is that it allows you to easily use * Chameleon. Chameleon will post notifications on the stylesheet objects * registered in the NIStylesheetCache. Because the observer and you will use the same cache, * you can register for notifications on the same stylesheet objects. * * The above example would look like this if you used a stylesheet cache: * @code // In your app initialization code, create a global stylesheet cache: NSString* pathPrefix = NIPathForBundleResource(nil, @"resources/css"); _stylesheetCache = [[NIStylesheetCache alloc] initWithPathPrefix:pathPrefix]; @endcode * @code // Elsewhere in your app, when you need access to any stylesheet: NIStylesheetCache* stylesheetCache = [(AppDelegate *)[UIApplication sharedApplication].delegate stylesheetCache]; NIStylesheet* stylesheet = [stylesheetCache stylesheetWithPath:@"common.css"]; @endcode * * Reduce the dependencies on your application delegate by defining a global method somewhere: * @code NIStylesheetCache* StylesheetCache(void); @endcode * @code #import "AppDelegate.h" NIStylesheetCache* StylesheetCache(void) { return [(AppDelegate *)[UIApplication sharedApplication].delegate stylesheetCache]; } @endcode * * * <h2>Using a Stylesheet</h2> * * The easiest way to apply a stylesheet to a set of views is by using a NIDOM object. Once * you attach a stylesheet to an NIDOM object, the stylesheet will be applied to any views you * attach to the NIDOM object. * * * <h2>Linking to Other Stylesheets</h2> * * You can link to one stylesheet from another using @htmlonly @import url('url')@endhtmlonly * in the .css file. * * For example, let's say you have a common CSS file, common.css, and a CSS file for a specific * view controller, profile.css. You can import common.css in profile.css by adding the following * line: * * @htmlonly @import url('common.css')@endhtmlonly * * Files are imported relative to the pathPrefix given to NIStylesheet. * * <h3>CSS Import Ordering Gotcha</h3> * * One might expect that placing an @htmlonly @import@endhtmlonly in the middle of a CSS * file would import the file at that exact location. This is not currently the case, * i.e. the parser does not insert the imported CSS where the @htmlonly @import@endhtmlonly * is. Instead, all of the CSS within the imported stylesheet will be processed before * the importer's CSS. * * For example, even if @htmlonly @import url('common.css')@endhtmlonly is placed at * the bottom of the profile.css file, common.css will be processed first, followed by profile.css. * * This is a known limitation and will ideally be fixed in a later release. * * Relative ordering of @htmlonly @imports@endhtmlonly is respected. * * * <h2>Supported CSS Properties</h2> * @code UIView { border: <dimension> <ignored> <color> {view.layer.borderWidth view.layer.borderColor} border-color: <color> {view.layer.borderColor} border-width: <dimension> {view.layer.borderWidth} background-color: <color|image_name> {view.backgroundColor} border-radius: <dimension> {view.layer.cornerRadius} opacity: xx.xx {view.alpha} -ios-autoresizing: [left|top|right|bottom|width|height|all|margins|dimensions] {view.autoresizingMask} visibility: [hidden|visible] {view.hidden} width: [x%,xpx,auto] {view.frameWidth} height: [x%,xpx,auto] {view.frameHeight} padding: <vertical unit> <horizontal unit> {used in auto height and width calculations} -mobile-hpadding: <horizontal unit> {used in auto width} -mobile-vpadding: <vertical unit> {used in auto height} max-width: [x%,xpx] {view.frameWidth} max-height: [x%,xps] {view.frameHeight} min-width: [x%,xpx] {view.frameWidth} min-height: [x%,xps] {view.frameHeight} top: [x%,xpx] {view.frameMinY} left: [x%,xpx] {view.frameMinX} bottom: [x%,xpx] {view.frameMaxY} right: [x%,xpx] {view.frameMaxX} -mobile-halign: [left|right|center] {view.frameX} -mobile-valign: [top|bottom|middle] {view.frameY} -mobile-relative: [#id|.prev|.next|.first|.last] {controls the position of the view relative to another view} margin-top: [x%,xpx,auto] {distance from view.frameMinY to relative.frameMaxY - % is relative to size of relative element, px is absolute, auto aligns the vertical centers} margin-bottom: [x%,xpx,auto] {distance from view.frameMaxY to relative.frameMinY - % is relative to size of relative element, px is absolute, auto aligns the vertical centers} margin-left: [x%,xpx,auto] {distance from view.frameMinX to relative.frameMaxX - % is relative to size of relative element, px is absolute, auto aligns the horizontal centers} margin-right: [x%,xpx,auto] {distance from view.frameMaxX to relative.frameMinX - % is relative to size of relative element, px is absolute, auto aligns the horizontal centers} } UILabel { color: <color> {label.textColor} font: <font-size> <font-name> {label.font} font-size: <font-size> {label.font} font-family: <font-name> {label.font} Can not be used in conjunction with font/font-family properties. Use the italic/bold font name instead. font-style: [italic|normal] {label.font} font-weight: [bold|normal] {label.font} text-align: [left|right|center] {label.textAlignment} text-shadow: <color> <x-offset> <y-offset> {label.shadowColor label.shadowOffset} -ios-highlighted-color: <color> {label.highlightedTextColor} -ios-line-break-mode: [wrap|character-wrap|clip|head-truncate|tail-truncate|middle-truncate] [label.lineBreakMode] -ios-number-of-lines: xx {label.numberOfLines} -ios-minimum-font-size: <font-size> {label.minimumFontSize} -ios-adjusts-font-size: [true|false] {label.adjustsFontSizeToFitWidth} -ios-baseline-adjustment: [align-baselines|align-centers|none] {label.baselineAdjustment} -mobile-text-key: "Key Name" {attaches a localized string (or the key name if not found) to this label} } UIButton { -mobile-title-insets -mobile-content-insets -mobile-image-insets font: <font-size> <font-name> {button.font} Buttons also support pseudo selectors: :selected,:highlighted,:disabled with the following rules: color: <color> {[button titleColorForState:]} text-shadow: <color> {[button titleShadowColorForState:]} -mobile-image: url(image_name) -mobile-text-key: "Key Name" {attaches a localized string (or the key name if not found) to this button} background-image: url(image_name) -mobile-background-stretch: top left bottom right -ios-button-adjust } UINavigationBar { -ios-tint-color: <color> {navBar.tintColor} } UISearchBar { -ios-tint-color: <color> {searchBar.tintColor} } UIToolbar { -ios-tint-color: <color> {toolbar.tintColor} } @endcode * * * <h2>Chameleon</h2> * * Chameleon is a web server that serves changes to CSS files in real time. * * You start Chameleon from the command line using node.js and tell it to watch a specific * directory of CSS files for changes. This should ideally be the directory that contains * all of your project's CSS files. * * Note: ensure that when you add the css directory to your project that it is added as a folder * reference. This will ensure that the complete folder hierarchy is maintained when the files * are copied to the device. * * To learn more about how to start up a Chameleon server, view the README file within * nimbus/src/css/chameleon/. This README will walk you through the necessary steps to build * and install node.js. * * Once you've started the Chameleon server, you simply create a Chameleon observer in your * application, give it access to your global stylesheet cache, and then tell it to start * watching Chameleon for skin changes. This logic is summed up below: @code _chameleonObserver = [[NIChameleonObserver alloc] initWithStylesheetCache:_stylesheetCache host:host]; [_chameleonObserver watchSkinChanges]; @endcode * * You then simply register for NIStylesheetDidChangeNotification notifications on the stylesheets * that you are interested in. You will get a notification when the stylesheet has been modified, * at which point if you're using NIDOM you can tell the NIDOM object to refresh itself; * this will reapply the stylesheet to all of its attached views. */ /**@}*/ #import "NICSSRuleSet.h" #import "NICSSParser.h" #import "NIDOM.h" #import "NIStyleable.h" #import "NIStylesheet.h" #import "NIStylesheetCache.h" #import "NIChameleonObserver.h" // Styleable UIKit views #import "UIButton+NIStyleable.h" #import "UILabel+NIStyleable.h" #import "UINavigationBar+NIStyleable.h" #import "UISearchBar+NIStyleable.h" #import "UIToolbar+NIStyleable.h" #import "UIView+NIStyleable.h" // Dependencies #import "NimbusCore.h"
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIActivityIndicatorView+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NICSSRuleset; @class NIDOM; @interface UIActivityIndicatorView (NIStyleable) /** * Applies the given rule set to this acitivity indicator view. * Use applyActivityIndicatorStyleWithRuleSet:inDOM: instead. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyActivityIndicatorStyleWithRuleSet:(NICSSRuleset *)ruleSet DEPRECATED_ATTRIBUTE; /** * Applies the given rule set to this acitivity indicator view. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyActivityIndicatorStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIActivityIndicatorView+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UIActivityIndicatorView+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NI_FIX_CATEGORY_BUG(UIActivityIndicatorView_NIStyleable) @implementation UIActivityIndicatorView (NIStyleable) - (void)applyActivityIndicatorStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyActivityIndicatorStyleWithRuleSet:ruleSet inDOM:nil]; } - (void)applyActivityIndicatorStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { if ([ruleSet hasActivityIndicatorStyle]) { [self setActivityIndicatorViewStyle:ruleSet.activityIndicatorStyle]; } else { [self setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge]; } if ([ruleSet hasTextColor]) { [self setColor:ruleSet.textColor]; } } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyStyleWithRuleSet:ruleSet inDOM:nil]; } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyActivityIndicatorStyleWithRuleSet:ruleSet inDOM:dom]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIButton+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NICSSRuleset; @class NIDOM; @interface UIButton (NIStyleable) /** * Applies the given rule set to this button. Call applyButtonStyleWithRuleSet:inDOM: * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyButtonStyleWithRuleSet:(NICSSRuleset *)ruleSet DEPRECATED_ATTRIBUTE; /** * Applies the given rule set to this button. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyButtonStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; /** * Applies the given rule set to this label. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. Since some of the view * styles (e.g. positioning) may rely on some label elements (like text), this is called * before the view styling is done. */ - (void)applyButtonStyleBeforeViewWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; /** * Tells the CSS engine a set of pseudo classes that apply to views of this class. * In the case of UIButton, this includes :selected, :highlighted, and :disabled. * In CSS, you specify these with selectors like UIButton:active. If you implement this you need to respond * to applyStyleWithRuleSet:forPseudoClass:inDOM: * * Make sure to include the leading colon. */ - (NSArray*) pseudoClasses; /** * Applies the given rule set to this button but for a pseudo class. Thus it only supports the subset of * properties that can be set on states of the button. (There's no fancy stuff that applies the styles * manually on state transitions. * * Since UIView doesn't have psuedo's, we don't need the specific version for UIButton like we do with * applyButtonStyleWithRuleSet. */ - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet forPseudoClass: (NSString*) pseudo inDOM: (NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIButton+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UIButton+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #import "NIUserInterfaceString.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NI_FIX_CATEGORY_BUG(UIButton_NIStyleable) @implementation UIButton (NIStyleable) - (void)applyButtonStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyButtonStyleWithRuleSet:ruleSet inDOM:nil]; } -(void)applyButtonStyleBeforeViewWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { if (ruleSet.hasFont) { self.titleLabel.font = ruleSet.font; } if (ruleSet.hasTextKey) { NIUserInterfaceString *nis = [[NIUserInterfaceString alloc] initWithKey:ruleSet.textKey]; [nis attach:self withSelector:@selector(setTitle:forState:) forControlState:UIControlStateNormal]; } } - (void)applyButtonStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { if ([ruleSet hasTextColor]) { // If you want to reset this color, set none as the color [self setTitleColor:ruleSet.textColor forState:UIControlStateNormal]; } if ([ruleSet hasTextShadowColor]) { // If you want to reset this color, set none as the color [self setTitleShadowColor:ruleSet.textShadowColor forState:UIControlStateNormal]; } if (ruleSet.hasImage) { [self setImage:[UIImage imageNamed:ruleSet.image] forState:UIControlStateNormal]; } if (ruleSet.hasBackgroundImage) { UIImage *backImage = [UIImage imageNamed:ruleSet.backgroundImage]; if (ruleSet.hasBackgroundStretchInsets) { backImage = [backImage resizableImageWithCapInsets:ruleSet.backgroundStretchInsets]; } [self setBackgroundImage:backImage forState:UIControlStateNormal]; } if ([ruleSet hasTextShadowOffset]) { self.titleLabel.shadowOffset = ruleSet.textShadowOffset; } if ([ruleSet hasTitleInsets]) { self.titleEdgeInsets = ruleSet.titleInsets; } if ([ruleSet hasContentInsets]) { self.contentEdgeInsets = ruleSet.contentInsets; } if ([ruleSet hasImageInsets]) { self.imageEdgeInsets = ruleSet.imageInsets; } if ([ruleSet hasButtonAdjust]) { self.adjustsImageWhenDisabled = ((ruleSet.buttonAdjust & NICSSButtonAdjustDisabled) != 0); self.adjustsImageWhenHighlighted = ((ruleSet.buttonAdjust & NICSSButtonAdjustHighlighted) != 0); } } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyStyleWithRuleSet:ruleSet inDOM:nil]; } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyButtonStyleBeforeViewWithRuleSet:ruleSet inDOM:dom]; [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyButtonStyleWithRuleSet:ruleSet inDOM:dom]; } -(void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet forPseudoClass:(NSString *)pseudo inDOM:(NIDOM *)dom { UIControlState state = UIControlStateNormal; if ([pseudo caseInsensitiveCompare:@"selected"] == NSOrderedSame) { state = UIControlStateSelected; } else if ([pseudo caseInsensitiveCompare:@"highlighted"] == NSOrderedSame) { state = UIControlStateHighlighted; } else if ([pseudo caseInsensitiveCompare:@"disabled"] == NSOrderedSame) { state = UIControlStateDisabled; } if (ruleSet.hasTextKey) { NIUserInterfaceString *nis = [[NIUserInterfaceString alloc] initWithKey:ruleSet.textKey]; [nis attach:self withSelector:@selector(setTitle:forState:) forControlState:state]; } if (ruleSet.hasTextColor) { [self setTitleColor:ruleSet.textColor forState:state]; } if (ruleSet.hasTextShadowColor) { [self setTitleShadowColor:ruleSet.textShadowColor forState:state]; } if (ruleSet.hasImage) { [self setImage:[UIImage imageNamed:ruleSet.image] forState:state]; } if (ruleSet.hasBackgroundImage) { UIImage *backImage = [UIImage imageNamed:ruleSet.backgroundImage]; if (ruleSet.hasBackgroundStretchInsets) { backImage = [backImage resizableImageWithCapInsets:ruleSet.backgroundStretchInsets]; } [self setBackgroundImage:backImage forState:state]; } } -(NSArray *)pseudoClasses { static dispatch_once_t onceToken; static NSArray *buttonPseudos; dispatch_once(&onceToken, ^{ buttonPseudos = @[@":selected", @":highlighted", @":disabled"]; }); return buttonPseudos; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UILabel+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NICSSRuleset; @class NIDOM; @interface UILabel (NIStyleable) /** * Applies the given rule set to this label. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyLabelStyleWithRuleSet:(NICSSRuleset *)ruleSet DEPRECATED_ATTRIBUTE; /** * Applies the given rule set to this label. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyLabelStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; /** * Applies the given rule set to this label. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. Since some of the view * styles (e.g. positioning) may rely on some label elements (like text), this is called * before the view styling is done. */ - (void)applyLabelStyleBeforeViewWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UILabel+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UILabel+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #import "NIUserInterfaceString.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NI_FIX_CATEGORY_BUG(UILabel_NIStyleable) @implementation UILabel (NIStyleable) - (void)applyLabelStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyLabelStyleWithRuleSet:ruleSet inDOM:nil]; } - (void)applyLabelStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { if ([ruleSet hasTextColor]) { self.textColor = ruleSet.textColor; } if ([ruleSet hasHighlightedTextColor]) { self.highlightedTextColor = ruleSet.highlightedTextColor; } if ([ruleSet hasTextAlignment]) { self.textAlignment = ruleSet.textAlignment; } if ([ruleSet hasFont]) { self.font = ruleSet.font; } if ([ruleSet hasTextShadowColor]) { self.shadowColor = ruleSet.textShadowColor; } if ([ruleSet hasTextShadowOffset]) { self.shadowOffset = ruleSet.textShadowOffset; } if ([ruleSet hasLineBreakMode]) { self.lineBreakMode = ruleSet.lineBreakMode; } if ([ruleSet hasNumberOfLines]) { self.numberOfLines = ruleSet.numberOfLines; } if ([ruleSet hasMinimumFontSize]) { self.minimumFontSize = ruleSet.minimumFontSize; } if ([ruleSet hasAdjustsFontSize]) { self.adjustsFontSizeToFitWidth = ruleSet.adjustsFontSize; } if ([ruleSet hasBaselineAdjustment]) { self.baselineAdjustment = ruleSet.baselineAdjustment; } } -(void)applyLabelStyleBeforeViewWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { if (ruleSet.hasTextKey) { NIUserInterfaceString *nis = [[NIUserInterfaceString alloc] initWithKey:ruleSet.textKey]; [nis attach:self withSelector:@selector(setText:)]; } } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyStyleWithRuleSet:ruleSet inDOM:nil]; } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyLabelStyleBeforeViewWithRuleSet:ruleSet inDOM:dom]; [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyLabelStyleWithRuleSet:ruleSet inDOM:dom]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UINavigationBar+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NICSSRuleset; @class NIDOM; @interface UINavigationBar (NIStyleable) /** * Applies the given rule set to this navigation bar. Use applyNavigationBarStyleWithRuleSet:inDOM: instead * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyNavigationBarStyleWithRuleSet:(NICSSRuleset *)ruleSet DEPRECATED_ATTRIBUTE; /** * Applies the given rule set to this navigation bar. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyNavigationBarStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UINavigationBar+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UINavigationBar+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NI_FIX_CATEGORY_BUG(UINavigationBar_NIStyleable) @implementation UINavigationBar (NIStyleable) - (void)applyNavigationBarStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyNavigationBarStyleWithRuleSet:ruleSet inDOM:nil]; } - (void)applyNavigationBarStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { if ([ruleSet hasTintColor]) { self.tintColor = ruleSet.tintColor; } } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyNavigationBarStyleWithRuleSet:ruleSet inDOM:dom]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIScrollView+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NIDOM; @class NICSSRuleset; @interface UIScrollView (NIStyleable) /** * Applies the given rule set to this scroll view. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyScrollViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIScrollView+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UIScrollView+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NI_FIX_CATEGORY_BUG(UIScrollView_NIStyleable) @implementation UIScrollView (NIStyleable) - (void)applyScrollViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM*) dom { if ([ruleSet hasScrollViewIndicatorStyle]) { self.indicatorStyle = ruleSet.scrollViewIndicatorStyle; } } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyViewStyleWithRuleSet:ruleSet inDOM:nil]; } - (void)applyViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyScrollViewStyleWithRuleSet:ruleSet inDOM: dom]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UISearchBar+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NIDOM; @class NICSSRuleset; @interface UISearchBar (NIStyleable) /** * Applies the given rule set to this search bar. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applySearchBarStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UISearchBar+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UISearchBar+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NI_FIX_CATEGORY_BUG(UISearchBar_NIStyleable) @implementation UISearchBar (NIStyleable) - (void)applySearchBarStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM*) dom { if ([ruleSet hasTintColor]) { self.tintColor = ruleSet.tintColor; } } -(void)applyViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applySearchBarStyleWithRuleSet:ruleSet inDOM:dom]; } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet { } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UITableView+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NIDOM; @class NICSSRuleset; @interface UITableView (NIStyleable) /** * Applies the given rule set to this table view. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyTableViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UITableView+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UITableView+NIStyleable.h" #import "UIView+NIStyleable.h" #import "UIScrollView+NIStyleable.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NI_FIX_CATEGORY_BUG(UITableView_NIStyleable) @implementation UITableView (NIStyleable) - (void)applyTableViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom { if ([ruleSet hasTableViewCellSeparatorStyle]) { self.separatorStyle = ruleSet.tableViewCellSeparatorStyle; } } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyStyleWithRuleSet:ruleSet inDOM: nil]; } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyScrollViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyTableViewStyleWithRuleSet:ruleSet inDOM:dom]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UITextField+NIStyleable.h
C/C++ Header
// // UITextField+NIStyleable.h // Nimbus // // Created by Metral, Max on 2/22/13. // Copyright (c) 2013 Jeff Verkoeyen. All rights reserved. // #import <UIKit/UIKit.h> @class NICSSRuleset; @class NIDOM; @interface UITextField (NIStyleable) /** * Applies the given rule set to this text field. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyTextFieldStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; /** * Applies the given rule set to this label. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. Since some of the view * styles (e.g. positioning) may rely on some label elements (like text), this is called * before the view styling is done. */ - (void)applyTextFieldStyleBeforeViewWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; /** * Tells the CSS engine a set of pseudo classes that apply to views of this class. * In the case of UITextField, this is :empty. * In CSS, you specify these with selectors like UITextField:empty. * * Make sure to include the leading colon. */ - (NSArray*) pseudoClasses; /** * Applies the given rule set to this text field but for a pseudo class. Thus it only supports the subset of * properties that can be set on states of the button. (There's no fancy stuff that applies the styles * manually on state transitions. * * Since UIView doesn't have psuedo's, we don't need the specific version for UITextField like we do with * applyTextFieldStyleWithRuleSet. */ - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet forPseudoClass: (NSString*) pseudo inDOM: (NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UITextField+NIStyleable.m
Objective-C
// // UITextField+NIStyleable.m // Nimbus // // Created by Metral, Max on 2/22/13. // Copyright (c) 2013 Jeff Verkoeyen. All rights reserved. // #import "UITextField+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NICSSRuleset.h" #import "NIUserInterfaceString.h" #import "NIPreprocessorMacros.h" @class NIDOM; NI_FIX_CATEGORY_BUG(UITextField_NIStyleable) @implementation UITextField (NIStyleable) - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyTextFieldStyleBeforeViewWithRuleSet:ruleSet inDOM:dom]; [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyTextFieldStyleWithRuleSet:ruleSet inDOM:dom]; } -(void)applyStyleWithRuleSet:(NICSSRuleset*)ruleSet forPseudoClass:(NSString *)pseudo inDOM:(NIDOM*)dom { if (ruleSet.hasTextKey) { NIUserInterfaceString *nis = [[NIUserInterfaceString alloc] initWithKey:ruleSet.textKey]; [nis attach:self withSelector:@selector(setPlaceholder:)]; } } -(void)applyTextFieldStyleBeforeViewWithRuleSet:(NICSSRuleset*)ruleSet inDOM:(NIDOM*)dom { if (ruleSet.hasTextKey) { NIUserInterfaceString *nis = [[NIUserInterfaceString alloc] initWithKey:ruleSet.textKey]; [nis attach:self withSelector:@selector(setTitle:forState:) forControlState:UIControlStateNormal]; } } -(void)applyTextFieldStyleWithRuleSet:(NICSSRuleset*)ruleSet inDOM:(NIDOM*)dom { if ([ruleSet hasTextColor]) { self.textColor = ruleSet.textColor; } if ([ruleSet hasTextAlignment]) { self.textAlignment = ruleSet.textAlignment; } if ([ruleSet hasFont]) { self.font = ruleSet.font; } if ([ruleSet hasMinimumFontSize]) { self.minimumFontSize = ruleSet.minimumFontSize; } if ([ruleSet hasAdjustsFontSize]) { self.adjustsFontSizeToFitWidth = ruleSet.adjustsFontSize; } if ([ruleSet hasVerticalAlign]) { self.contentVerticalAlignment = ruleSet.verticalAlign; } } -(NSArray *)pseudoClasses { static dispatch_once_t onceToken; static NSArray *pseudos; dispatch_once(&onceToken, ^{ pseudos = @[@":empty"]; }); return pseudos; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIToolbar+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NIDOM; @class NICSSRuleset; @interface UIToolbar (NIStyleable) /** * Applies the given rule set to this toolbar. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyToolbarStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIToolbar+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UIToolbar+NIStyleable.h" #import "UIView+NIStyleable.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NI_FIX_CATEGORY_BUG(UIToolbar_NIStyleable) @implementation UIToolbar (NIStyleable) - (void)applyToolbarStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom { if ([ruleSet hasTintColor]) { self.tintColor = ruleSet.tintColor; } } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyStyleWithRuleSet:ruleSet inDOM:nil]; } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; [self applyToolbarStyleWithRuleSet:ruleSet inDOM:dom]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIView+NIStyleable.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> @class NICSSRuleset; @class NIDOM; extern NSString* const NICSSViewKey; extern NSString* const NICSSViewIdKey; extern NSString* const NICSSViewCssClassKey; extern NSString* const NICSSViewTextKey; extern NSString* const NICSSViewTagKey; extern NSString* const NICSSViewTargetSelectorKey; extern NSString* const NICSSViewSubviewsKey; extern NSString* const NICSSViewAccessibilityLabelKey; extern NSString* const NICSSViewBackgroundColorKey; @interface UIView (NIStyleable) /** * Applies the given rule set to this view. Call applyViewStyleWithRuleSet:inDOM: instead. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyViewStyleWithRuleSet:(NICSSRuleset *)ruleSet DEPRECATED_ATTRIBUTE; /** * Applies the given rule set to this view. * * This method is exposed primarily for subclasses to use when implementing the * applyStyleWithRuleSet: method from NIStyleable. */ - (void)applyViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom; /** * Describes the given rule set when applied to this view. * * This method is exposed primarily for subclasses to use when implementing the * descriptionWithRuleSetFor:forPseudoClass:inDOM:withViewName: method from NIStyleable. */ - (NSString*) descriptionWithRuleSetForView: (NICSSRuleset*) ruleSet forPseudoClass: (NSString*) pseudo inDOM: (NIDOM*) dom withViewName: (NSString*) name; /** * Build a view hierarchy. The array is a list of view specs, where viewSpec is a loosely formatted * sequence delineated by UIViews. After a UIView, the type of the next object determines what is done * with it: * UIView instance - following values will be applied to this UIView (other than Class, which "starts anew") * Class - a UIView subclass that will be alloc'ed and init'ed * NSString starting with a hash - view id (for style application) * NSString starting with a dot - CSS Class (for style application) (you can do this multiple times per view) * NSString - accessibility label for the view. * NIUserInterfaceString - .text or .title(normal) on a button. Asserts otherwise * NSNumber - tag * NSInvocation - selector for TouchUpInside (e.g. on a UIButton) * NSArray - passed to build on the active UIView and results added as subviews * NSDictionary - if you're squeamish about this whole Javascript duck typing auto detecting fancyness * you can pass a boring old dictionary with named values: * NICSSViewKey, NICSSViewIdKey, NICSSViewCssClassKey, NICSSViewTextKey, NICSSViewTagKey, * NICSSViewTargetSelectorKey, NICSSViewSubviewsKey, NICSSViewAccessibilityLabelKey * * Example (including inline setting of self properties): * [self.view buildSubviews: @[ * self.buttonContainer = UIView.alloc.init, @"#LoginContainer", @[ * self.myButton = UIButton.alloc.init, @"#Login", @".primary" * ] * ]]; */ - (NSArray*) buildSubviews: (NSArray*) viewSpecs inDOM: (NIDOM*) dom; /// View frame and bounds manipulation helpers @property (nonatomic) CGFloat frameWidth; @property (nonatomic) CGFloat frameHeight; @property (nonatomic) CGFloat frameMinX; @property (nonatomic) CGFloat frameMidX; @property (nonatomic) CGFloat frameMaxX; @property (nonatomic) CGFloat frameMinY; @property (nonatomic) CGFloat frameMidY; @property (nonatomic) CGFloat frameMaxY; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/css/src/UIView+NIStyleable.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "UIView+NIStyleable.h" #import "NIDOM.h" #import "NICSSRuleset.h" #import "NimbusCore.h" #import "NIUserInterfaceString.h" #import <QuartzCore/QuartzCore.h> #import <objc/runtime.h> #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif NSString* const NICSSViewKey = @"view"; NSString* const NICSSViewIdKey = @"id"; NSString* const NICSSViewCssClassKey = @"cssClass"; NSString* const NICSSViewTextKey = @"text"; NSString* const NICSSViewTagKey = @"tag"; NSString* const NICSSViewTargetSelectorKey = @"selector"; NSString* const NICSSViewSubviewsKey = @"subviews"; NSString* const NICSSViewAccessibilityLabelKey = @"label"; NSString* const NICSSViewBackgroundColorKey = @"bg"; /** * Private class for storing info during view creation */ @interface NIPrivateViewInfo : NSObject @property (nonatomic,strong) NSMutableArray *cssClasses; @property (nonatomic,strong) NSString *viewId; @property (nonatomic,strong) UIView *view; @end // We split this up because we want to add all the subviews to the DOM in the order they were created @interface UIView (NIStyleablePrivate) -(void)_buildSubviews:(NSArray *)viewSpecs inDOM:(NIDOM *)dom withViewArray: (NSMutableArray*) subviews; @end NI_FIX_CATEGORY_BUG(UIView_NIStyleable) NI_FIX_CATEGORY_BUG(UIView_NIStyleablePrivate) CGFloat NICSSUnitToPixels(NICSSUnit unit, CGFloat container); @implementation UIView (NIStyleable) - (void)applyViewStyleWithRuleSet:(NICSSRuleset *)ruleSet { [self applyViewStyleWithRuleSet:ruleSet inDOM:nil]; } -(NSString *)descriptionWithRuleSetForView:(NICSSRuleset *)ruleSet forPseudoClass:(NSString *)pseudo inDOM:(NIDOM *)dom withViewName:(NSString *)name { return [self applyOrDescribe:NO ruleSet:ruleSet inDOM:dom withViewName:name]; } -(NSString *)descriptionWithRuleSet:(NICSSRuleset *)ruleSet forPseudoClass:(NSString *)pseudo inDOM:(NIDOM *)dom withViewName:(NSString *)name { return [self descriptionWithRuleSetForView:ruleSet forPseudoClass:pseudo inDOM:dom withViewName:name]; } - (void)applyViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyOrDescribe:YES ruleSet:ruleSet inDOM:dom withViewName:nil]; } - (NSString*)applyOrDescribe: (BOOL) apply ruleSet: (NICSSRuleset*) ruleSet inDOM: (NIDOM*)dom withViewName: (NSString*) name { NSMutableString *desc = apply ? nil : [[NSMutableString alloc] init]; // [desc appendFormat:@"%@. = %f;\n"]; if ([ruleSet hasBackgroundColor]) { if (apply) { self.backgroundColor = ruleSet.backgroundColor; } else { CGFloat r,g,b,a; [ruleSet.backgroundColor getRed:&r green:&g blue:&b alpha:&a]; [desc appendFormat:@"%@.backgroundColor = [UIColor colorWithRed: %f green: %f blue: %f alpha: %f];\n", name, r, g, b, a]; } } if ([ruleSet hasOpacity]) { if (apply) { self.alpha = ruleSet.opacity; } else { [desc appendFormat:@"%@.alpha = %f;", name, ruleSet.opacity]; } } if ([ruleSet hasBorderRadius]) { if (apply) { self.layer.cornerRadius = ruleSet.borderRadius; } else { [desc appendFormat:@"%@.layer.cornerRadius = %f;\n", name, ruleSet.borderRadius]; } } if ([ruleSet hasBorderWidth]) { if (apply) { self.layer.borderWidth = ruleSet.borderWidth; } else { [desc appendFormat:@"%@.layer.borderWidth = %f;\n", name, ruleSet.borderWidth]; } } if ([ruleSet hasBorderColor]) { if (apply) { self.layer.borderColor = ruleSet.borderColor.CGColor; } else { CGFloat r,g,b,a; [ruleSet.borderColor getRed:&r green:&g blue:&b alpha:&a]; [desc appendFormat:@"%@.layer.borderColor = [UIColor colorWithRed: %f green: %f blue: %f alpha: %f].CGColor;\n", name, r, g, b, a]; } } if ([ruleSet hasAutoresizing]) { if (apply) { self.autoresizingMask = ruleSet.autoresizing; } else { [desc appendFormat:@"%@.autoresizingMask = (UIViewAutoresizing) %d;\n", name, ruleSet.autoresizing]; } } if ([ruleSet hasVisible]) { if (apply) { self.hidden = !ruleSet.visible; } else { [desc appendFormat:@"%@.hidden = %@;\n", name, ruleSet.visible ? @"NO" : @"YES"]; } } // View sizing // Special case auto/auto height and width if ([ruleSet hasWidth] && [ruleSet hasHeight] && ruleSet.width.type == CSS_AUTO_UNIT && ruleSet.height.type == CSS_AUTO_UNIT) { if (apply) { [self sizeToFit]; } else { [desc appendFormat:@"[%@ sizeToFit];\n", name]; } if (ruleSet.hasVerticalPadding) { NICSSUnit vPadding = ruleSet.verticalPadding; switch (vPadding.type) { case CSS_AUTO_UNIT: break; case CSS_PERCENTAGE_UNIT: if (apply) { self.frameHeight += (self.frameHeight * vPadding.value); } else { [desc appendFormat:@"%@.frameHeight += (%@.frameHeight * %f);", name, name, vPadding.value]; } break; case CSS_PIXEL_UNIT: if (apply) { self.frameHeight += vPadding.value; } else { [desc appendFormat:@"%@.frameHeight += %f;", name, vPadding.value]; } break; } } if (ruleSet.hasHorizontalPadding) { NICSSUnit hPadding = ruleSet.horizontalPadding; switch (hPadding.type) { case CSS_AUTO_UNIT: break; case CSS_PERCENTAGE_UNIT: if (apply) { self.frameWidth += (self.frameWidth * hPadding.value); } else { [desc appendFormat:@"%@.frameWidth += (%@.frameWidth * %f);", name, name, hPadding.value]; } break; case CSS_PIXEL_UNIT: if (apply) { self.frameWidth += hPadding.value; } else { [desc appendFormat:@"%@.frameWidth += %f;", name, hPadding.value]; } break; } } } else { if ([ruleSet hasWidth]) { NICSSUnit u = ruleSet.width; CGFloat startHeight = self.frameHeight; switch (u.type) { case CSS_AUTO_UNIT: if (apply) { [self sizeToFit]; // sizeToFit the width, but retain height. Behavior somewhat undefined... self.frameHeight = startHeight; } else { [desc appendFormat:@"[%@ sizeToFit];\n%@.frameHeight = %f;\n", name, name, startHeight]; } break; case CSS_PERCENTAGE_UNIT: if (apply) { self.frameWidth = self.superview.bounds.size.width * u.value; } else { [desc appendFormat:@"%@.frameWidth = %f;\n", name, self.superview.bounds.size.width * u.value]; } break; case CSS_PIXEL_UNIT: // Because padding and margin are (a) complicated to implement and (b) not relevant in a non-flow layout, // we use negative width values to mean "the superview dimension - the value." It's a little hokey, but // it's very useful. If someone wants to layer on padding primitives to deal with this in a more CSSy way, // go for it. if (u.value < 0) { if (apply) { self.frameWidth = self.superview.frameWidth + u.value; } else { [desc appendFormat:@"%@.frameWidth = %f;\n", name, self.superview.frameWidth + u.value]; } } else { if (apply) { self.frameWidth = u.value; } else { [desc appendFormat:@"%@.frameWidth = %f;\n", name, u.value]; } } break; } if (ruleSet.hasHorizontalPadding) { NICSSUnit hPadding = ruleSet.horizontalPadding; switch (hPadding.type) { case CSS_AUTO_UNIT: break; case CSS_PERCENTAGE_UNIT: if (apply) { self.frameWidth += (self.frameWidth * hPadding.value); } else { [desc appendFormat:@"%@.frameWidth += (%@.frameWidth * %f);", name, name, hPadding.value]; } break; case CSS_PIXEL_UNIT: if (apply) { self.frameWidth += hPadding.value; } else { [desc appendFormat:@"%@.frameWidth += %f;", name, hPadding.value]; } break; } } } if ([ruleSet hasHeight]) { NICSSUnit u = ruleSet.height; CGFloat startWidth = self.frameWidth; switch (u.type) { case CSS_AUTO_UNIT: if (apply) { [self sizeToFit]; self.frameWidth = startWidth; } else { [desc appendFormat:@"[%@ sizeToFit];\n%@.frameWidth = %f;\n", name, name, startWidth]; } break; case CSS_PERCENTAGE_UNIT: if (apply) { self.frameHeight = self.superview.bounds.size.height * u.value; } else { [desc appendFormat:@"%@.frameHeight = %f;\n", name, self.superview.bounds.size.height * u.value]; } break; case CSS_PIXEL_UNIT: // Because padding and margin are (a) complicated to implement and (b) not relevant in a non-flow layout, // we use negative width values to mean "the superview dimension - the value." It's a little hokey, but // it's very useful. If someone wants to layer on padding primitives to deal with this in a more CSSy way, // go for it. if (u.value < 0) { if (apply) { self.frameHeight = self.superview.frameHeight + u.value; } else { [desc appendFormat:@"%@.frameHeight = %f;\n", name, self.superview.frameHeight + u.value]; } } else { if (apply) { self.frameHeight = u.value; } else { [desc appendFormat:@"%@.frameHeight = %f;\n", name, u.value]; } } break; } if (ruleSet.hasVerticalPadding) { NICSSUnit vPadding = ruleSet.verticalPadding; switch (vPadding.type) { case CSS_AUTO_UNIT: break; case CSS_PERCENTAGE_UNIT: if (apply) { self.frameHeight += (self.frameHeight * vPadding.value); } else { [desc appendFormat:@"%@.frameHeight += (%@.frameHeight * %f);", name, name, vPadding.value]; } break; case CSS_PIXEL_UNIT: if (apply) { self.frameHeight += vPadding.value; } else { [desc appendFormat:@"%@.frameHeight += %f;", name, vPadding.value]; } break; } } } } // Min/Max width/height enforcement if ([ruleSet hasMaxWidth]) { CGFloat max = NICSSUnitToPixels(ruleSet.maxWidth,self.frameWidth); if (self.frameWidth > max) { if (apply) { self.frameWidth = max; } else { [desc appendFormat:@"%@.frameWidth = %f;\n", name, max]; } } } if ([ruleSet hasMaxHeight]) { CGFloat max = NICSSUnitToPixels(ruleSet.maxHeight,self.frameHeight); if (self.frameHeight > max) { if (apply) { self.frameHeight = max; } else { [desc appendFormat:@"%@.frameHeight = %f;\n", name, max]; } } } if ([ruleSet hasMinWidth]) { CGFloat min = NICSSUnitToPixels(ruleSet.minWidth,self.frameWidth); if (self.frameWidth < min) { if (apply) { self.frameWidth = min; } else { [desc appendFormat:@"%@.frameWidth = %f;\n", name, min]; } } } if ([ruleSet hasMinHeight]) { CGFloat min = NICSSUnitToPixels(ruleSet.minHeight,self.frameHeight); if (self.frameHeight < min) { if (apply) { self.frameHeight = min; } else { [desc appendFormat:@"%@.frameHeight = %f;\n", name, min]; } } } // "Absolute" position in superview if ([ruleSet hasTop]) { NICSSUnit u = ruleSet.top; switch (u.type) { case CSS_PERCENTAGE_UNIT: if (apply) { self.frameMinY = self.superview.bounds.size.height * u.value; } else { [desc appendFormat:@"%@.frameMinY = %f;\n", name, self.superview.bounds.size.height * u.value]; } break; case CSS_PIXEL_UNIT: if (apply) { self.frameMinY = u.value; } else { [desc appendFormat:@"%@.frameMinY = %f;\n", name, u.value]; } break; default: NIDASSERT(u.type == CSS_PERCENTAGE_UNIT || u.type == CSS_PIXEL_UNIT); break; } } if ([ruleSet hasLeft]) { NICSSUnit u = ruleSet.left; switch (u.type) { case CSS_PERCENTAGE_UNIT: if (apply) { self.frameMinX = self.superview.bounds.size.width * u.value; } else { [desc appendFormat:@"%@.frameMinX = %f;\n", name, self.superview.bounds.size.width * u.value]; } break; case CSS_PIXEL_UNIT: if (apply) { self.frameMinX = u.value; } else { [desc appendFormat:@"%@.frameMinX = %f;\n", name, u.value]; } break; default: NIDASSERT(u.type == CSS_PERCENTAGE_UNIT || u.type == CSS_PIXEL_UNIT); break; } } // TODO - should specifying both left/right or top/bottom set the width instead? // TODO - how does left/right/top/bottom interact with relative positioning if at all? if ([ruleSet hasRight]) { NICSSUnit u = ruleSet.right; switch (u.type) { case CSS_PERCENTAGE_UNIT: if (apply) { self.frameMaxX = self.superview.bounds.size.width * u.value; } else { [desc appendFormat:@"%@.frameMaxX = %f;\n", name, self.superview.bounds.size.width * u.value]; } break; case CSS_PIXEL_UNIT: if (apply) { self.frameMaxX = self.superview.bounds.size.width - u.value; } else { [desc appendFormat:@"%@.frameMaxX = %f;\n", name, self.superview.bounds.size.width - u.value]; } break; default: NIDASSERT(u.type == CSS_PERCENTAGE_UNIT || u.type == CSS_PIXEL_UNIT); break; } } if ([ruleSet hasBottom]) { NICSSUnit u = ruleSet.bottom; switch (u.type) { case CSS_PERCENTAGE_UNIT: if (apply) { self.frameMaxY = self.superview.bounds.size.height * u.value; } else { [desc appendFormat:@"%@.frameMaxY = %f;\n", name, self.superview.bounds.size.height * u.value]; } break; case CSS_PIXEL_UNIT: if (apply) { self.frameMaxY = self.superview.bounds.size.height - u.value; } else { [desc appendFormat:@"%@.frameMaxY = %f;\n", name, self.superview.bounds.size.height - u.value]; } break; default: NIDASSERT(u.type == CSS_PERCENTAGE_UNIT || u.type == CSS_PIXEL_UNIT); break; } } if ([ruleSet hasFrameHorizontalAlign]) { switch (ruleSet.frameHorizontalAlign) { case UITextAlignmentCenter: if (apply) { self.frameMidX = self.superview.bounds.size.width / 2.0; } else { [desc appendFormat:@"%@.frameMidX = %f;\n", name, self.superview.bounds.size.width / 2.0]; } break; case UITextAlignmentLeft: if (apply) { self.frameMinX = 0; } else { [desc appendFormat:@"%@.frameMinX = 0;\n", name]; } break; case UITextAlignmentRight: self.frameMaxX = self.superview.bounds.size.width; break; default: NIDASSERT(NO); break; } } if ([ruleSet hasFrameVerticalAlign]) { switch (ruleSet.frameVerticalAlign) { case UIViewContentModeCenter: if (apply) { self.frameMidY = self.superview.bounds.size.height / 2.0; } else { [desc appendFormat:@"%@.frameMidY = %f;\n", name, self.superview.bounds.size.height / 2.0]; } break; case UIViewContentModeTop: if (apply) { self.frameMinY = 0; } else { [desc appendFormat:@"%@.frameMinY = 0;\n", name]; } break; case UIViewContentModeBottom: if (apply) { self.frameMaxY = self.superview.bounds.size.height; } else { [desc appendFormat:@"%@.frameMaxY = %f;\n", name, self.superview.bounds.size.height]; } break; default: NIDASSERT(NO); break; } } // Relative positioning to other identified views if (ruleSet.hasRelativeToId) { NSString *viewSpec = ruleSet.relativeToId; UIView* relative = nil; if ([viewSpec characterAtIndex:0] == '.') { if ([viewSpec caseInsensitiveCompare:@".next"] == NSOrderedSame) { NSInteger ix = [self.superview.subviews indexOfObject:self]; if (++ix < self.superview.subviews.count) { relative = [self.superview.subviews objectAtIndex:ix]; } } else if ([viewSpec caseInsensitiveCompare:@".prev"] == NSOrderedSame) { NSInteger ix = [self.superview.subviews indexOfObject:self]; if (ix > 0) { relative = [self.superview.subviews objectAtIndex:ix-1]; } } else if ([viewSpec caseInsensitiveCompare:@".first"] == NSOrderedSame) { relative = [self.superview.subviews objectAtIndex:0]; if (relative == self) { relative = nil; } } else if ([viewSpec caseInsensitiveCompare:@".last"] == NSOrderedSame) { relative = [self.superview.subviews lastObject]; if (relative == self) { relative = nil; } } } else { // For performance, I'm not going to try and fix up your bad selectors. Start with a # or it will fail. relative = [dom viewById:ruleSet.relativeToId]; } if (relative) { CGPoint anchor; if (ruleSet.hasMarginTop) { NICSSUnit top = ruleSet.marginTop; switch (top.type) { case CSS_AUTO_UNIT: // Align y center anchor = CGPointMake(0, relative.frameMidY); if (self.superview != relative.superview) { anchor = [self convertPoint:anchor fromView:relative.superview]; } if (apply) { self.frameMidY = anchor.y; } else { [desc appendFormat:@"%@.frameMidY = %f;\n", name, anchor.y]; } break; case CSS_PERCENTAGE_UNIT: case CSS_PIXEL_UNIT: // relative.frameMaxY + relative.frameHeight * unit anchor = CGPointMake(0, relative.frameMaxY); if (self.superview != relative.superview) { anchor = [self convertPoint:anchor fromView:relative.superview]; } if (apply) { self.frameMinY = anchor.y + NICSSUnitToPixels(top, relative.frameHeight); } else { [desc appendFormat:@"%@.frameMinY = %f;\n", name, anchor.y + NICSSUnitToPixels(top, relative.frameHeight)]; } break; } } else if (ruleSet.hasMarginBottom) { NICSSUnit bottom = ruleSet.marginBottom; switch (bottom.type) { case CSS_AUTO_UNIT: // Align y center anchor = CGPointMake(0, relative.frameMidY); if (self.superview != relative.superview) { anchor = [self convertPoint:anchor fromView:relative.superview]; } if (apply) { self.frameMidY = anchor.y; } else { [desc appendFormat:@"%@.frameMidY = %f;\n", name, anchor.y]; } break; case CSS_PERCENTAGE_UNIT: case CSS_PIXEL_UNIT: // relative.frameMinY - (relative.frameHeight * unit) anchor = CGPointMake(0, relative.frameMinY); if (self.superview != relative.superview) { anchor = [self convertPoint:anchor fromView:relative.superview]; } if (apply) { self.frameMaxY = anchor.y - NICSSUnitToPixels(bottom, relative.frameHeight); } else { [desc appendFormat:@"%@.frameMaxY = %f;", name, anchor.y - NICSSUnitToPixels(bottom, relative.frameHeight)]; } break; } } if (ruleSet.hasMarginLeft) { NICSSUnit left = ruleSet.marginLeft; switch (left.type) { case CSS_AUTO_UNIT: // Align x center anchor = CGPointMake(relative.frameMidX, 0); if (self.superview != relative.superview) { anchor = [self convertPoint:anchor fromView:relative.superview]; } if (apply) { self.frameMidX = anchor.x; } else { [desc appendFormat:@"%@.frameMidX = %f;\n", name, anchor.x]; } break; case CSS_PERCENTAGE_UNIT: case CSS_PIXEL_UNIT: // relative.frameMaxX + (relative.frameHeight * unit) anchor = CGPointMake(relative.frameMaxX, 0); if (self.superview != relative.superview) { anchor = [self convertPoint:anchor fromView:relative.superview]; } if (apply) { self.frameMinX = anchor.x + NICSSUnitToPixels(left, relative.frameWidth); } else { [desc appendFormat:@"%@.frameMinX = %f;\n", name, anchor.x + NICSSUnitToPixels(left, relative.frameWidth)]; } break; } } else if (ruleSet.hasMarginRight) { NICSSUnit right = ruleSet.marginRight; switch (right.type) { case CSS_AUTO_UNIT: // Align x center anchor = CGPointMake(relative.frameMidX, 0); if (self.superview != relative.superview) { anchor = [self convertPoint:anchor fromView:relative.superview]; } if (apply) { self.frameMidX = anchor.x; } else { [desc appendFormat:@"%@.frameMidX = %f;\n", name, anchor.x]; } break; case CSS_PERCENTAGE_UNIT: case CSS_PIXEL_UNIT: // relative.frameMinX - (relative.frameHeight * unit) anchor = CGPointMake(relative.frameMinX, 0); if (self.superview != relative.superview) { anchor = [self convertPoint:anchor fromView:relative.superview]; } if (apply) { self.frameMaxX = anchor.x - NICSSUnitToPixels(right, relative.frameWidth); } else { [desc appendFormat:@"%@.frameMaxX = %f;", name, anchor.x - NICSSUnitToPixels(right, relative.frameWidth)]; } break; } } } } return desc; } -(NSArray *)buildSubviews:(NSArray *)viewSpecs inDOM:(NIDOM *)dom { NSMutableArray *subviews = [[NSMutableArray alloc] init]; [self _buildSubviews:viewSpecs inDOM:dom withViewArray:subviews]; for (int ix = 0, ct = subviews.count; ix < ct; ix++) { NIPrivateViewInfo *viewInfo = [subviews objectAtIndex:ix]; NSString *firstClass = [viewInfo.cssClasses count] ? [viewInfo.cssClasses objectAtIndex:0] : nil; [dom registerView:viewInfo.view withCSSClass:firstClass andId:viewInfo.viewId]; if (viewInfo.viewId && dom.target) { NSString *selectorName = [NSString stringWithFormat:@"set%@%@:", [[viewInfo.viewId substringWithRange:NSMakeRange(1, 1)] uppercaseString], [viewInfo.viewId substringFromIndex:2]]; SEL selector = NSSelectorFromString(selectorName); if ([dom.target respondsToSelector:selector]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [dom.target performSelector:selector withObject:viewInfo.view]; #pragma clang diagnostic pop } } if (viewInfo.cssClasses.count > 1) { for (int i = 1, cct = viewInfo.cssClasses.count; i < cct; i++) { [dom addCssClass:[viewInfo.cssClasses objectAtIndex:i] toView:viewInfo.view]; } } [subviews replaceObjectAtIndex:ix withObject:viewInfo.view]; } return subviews; } - (void)applyStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom { [self applyViewStyleWithRuleSet:ruleSet inDOM:dom]; } - (CGFloat)frameWidth { return self.frame.size.width; } - (void)setFrameWidth:(CGFloat)frameWidth { CGRect frame = self.frame; frame.size.width = frameWidth; self.frame = frame; } - (CGFloat)frameHeight { return self.frame.size.height; } - (void)setFrameHeight:(CGFloat)frameHeight { CGRect frame = self.frame; frame.size.height = frameHeight; self.frame = frame; } - (CGFloat)frameMinX { return CGRectGetMinX(self.frame); } - (void)setFrameMinX:(CGFloat)frameMinX { CGRect frame = self.frame; frame.origin.x = frameMinX; self.frame = frame; } - (CGFloat)frameMidX { return CGRectGetMidX(self.frame); } - (void)setFrameMidX:(CGFloat)frameMidX { self.frameMinX = (frameMidX - (self.frameWidth / 2.0f)); } - (CGFloat)frameMaxX { return CGRectGetMaxX(self.frame); } - (void)setFrameMaxX:(CGFloat)frameMaxX { self.frameMinX = (frameMaxX - self.frameWidth); } - (CGFloat)frameMinY { return CGRectGetMinY(self.frame); } - (void)setFrameMinY:(CGFloat)frameMinY { CGRect frame = self.frame; frame.origin.y = frameMinY; self.frame = frame; } - (CGFloat)frameMidY { return CGRectGetMidY(self.frame); } - (void)setFrameMidY:(CGFloat)frameMidY { self.frameMinY = (frameMidY - (self.frameHeight / 2.0f)); } - (CGFloat)frameMaxY { return CGRectGetMaxY(self.frame); } - (void)setFrameMaxY:(CGFloat)frameMaxY { self.frameMinY = (frameMaxY - self.frameHeight); } @end CGFloat NICSSUnitToPixels(NICSSUnit unit, CGFloat container) { if (unit.type == CSS_PERCENTAGE_UNIT) { return unit.value * container; } return unit.value; } @implementation UIView (NIStyleablePrivate) -(void)_buildSubviews:(NSArray *)viewSpecs inDOM:(NIDOM *)dom withViewArray:(NSMutableArray *)subviews { NIPrivateViewInfo *active = nil; for (id directive in viewSpecs) { if ([directive isKindOfClass:[NSDictionary class]]) { // Process the key value pairs rather than trying to determine intent // from the type NSDictionary *kv = (NSDictionary*) directive; if (!active) { NSAssert([kv objectForKey:NICSSViewKey], @"The first NSDictionary passed to build subviews must contain the NICSSViewKey"); } id directiveValue = [kv objectForKey:NICSSViewKey]; if (directiveValue) { #ifdef NI_DYNAMIC_VIEWS // I have a dream that you can instantiate this whole thing from JSON. // So the dictionary version endeavors to make NSString/NSNumber work for every directive if ([directiveValue isKindOfClass:[NSString class]]) { directiveValue = [[NSClassFromString(directiveValue) alloc] init]; } #endif if ([directiveValue isKindOfClass:[UIView class]]) { active = [[NIPrivateViewInfo alloc] init]; active.view = (UIView*) directiveValue; [self addSubview:active.view]; [subviews addObject: active]; } else if (class_isMetaClass(object_getClass(directiveValue))) { active = [[NIPrivateViewInfo alloc] init]; active.view = [[directive alloc] init]; NSAssert([active.view isKindOfClass:[UIView class]], @"View must inherit from UIView. %@ does not.", NSStringFromClass([active class])); [self addSubview:active.view]; [subviews addObject: active]; } else { NSAssert(NO, @"NICSSViewKey directive does not identify a UIView or UIView class."); } } directiveValue = [kv objectForKey:NICSSViewIdKey]; if (directiveValue) { NSAssert([directiveValue isKindOfClass:[NSString class]], @"The value of NICSSViewIdKey must be an NSString*"); if (![directiveValue hasPrefix:@"#"]) { directiveValue = [@"#" stringByAppendingString:directiveValue]; } active.viewId = directiveValue; } directiveValue = [kv objectForKey:NICSSViewCssClassKey]; if (directiveValue) { NSAssert([directiveValue isKindOfClass:[NSString class]] || [directiveValue isKindOfClass:[NSArray class]], @"The value of NICSSViewCssClassKey must be an NSString* or NSArray*"); active.cssClasses = active.cssClasses ?: [[NSMutableArray alloc] init]; if ([directiveValue isKindOfClass:[NSString class]]) { [active.cssClasses addObject:directiveValue]; } else { [active.cssClasses addObjectsFromArray:directiveValue]; } } directiveValue = [kv objectForKey:NICSSViewTextKey]; if (directiveValue) { NSAssert([directiveValue isKindOfClass:[NSString class]] || [directiveValue isKindOfClass:[NIUserInterfaceString class]], @"The value of NICSSViewCssClassKey must be an NSString* or NIUserInterfaceString*"); if ([directiveValue isKindOfClass:[NSString class]]) { directiveValue = [[NIUserInterfaceString alloc] initWithKey:directiveValue defaultValue:directiveValue]; } if ([directiveValue isKindOfClass:[NIUserInterfaceString class]]) { [((NIUserInterfaceString*)directiveValue) attach:active.view]; } } directiveValue = [kv objectForKey:NICSSViewBackgroundColorKey]; if (directiveValue) { NSAssert([directiveValue isKindOfClass:[UIColor class]] || [directiveValue isKindOfClass:[NSNumber class]], @"The value of NICSSViewBackgroundColorKey must be NSNumber* or UIColor*"); if ([directiveValue isKindOfClass:[NSNumber class]]) { long rgbValue = [directiveValue longValue]; directiveValue = [UIColor colorWithRed:((float)((rgbValue & 0xFF000000) >> 24))/255.0 green:((float)((rgbValue & 0xFF0000) >> 16))/255.0 blue:((float)((rgbValue & 0xFF00) >> 8))/255.0 alpha:((float)(rgbValue & 0xFF))/255.0]; } self.backgroundColor = directiveValue; } directiveValue = [kv objectForKey:NICSSViewTagKey]; if (directiveValue) { NSAssert([directiveValue isKindOfClass:[NSNumber class]], @"The value of NICSSViewTagKey must be an NSNumber*"); active.view.tag = [directiveValue integerValue]; } directiveValue = [kv objectForKey:NICSSViewTargetSelectorKey]; if (directiveValue) { NSAssert([directiveValue isKindOfClass:[NSInvocation class]] || [directiveValue isKindOfClass:[NSString class]], @"NICSSViewTargetSelectorKey must be an NSInvocation*, or an NSString* if you're adventurous and NI_DYNAMIC_VIEWS is defined."); #ifdef NI_DYNAMIC_VIEWS // NSSelectorFromString has Apple rejection written all over it, even though it's documented. Since its intended // use is primarily rapid development right now, use the #ifdef to turn it on. if ([directiveValue isKindOfClass:[NSString class]]) { // Let's make an invocation out of this puppy. @try { SEL selector = NSSelectorFromString(directiveValue); directiveValue = NIInvocationWithInstanceTarget(dom.target, selector); } @catch (NSException *exception) { #ifdef DEBUG NIDPRINT(@"Unknown selector %@ specified on %@.", directiveValue, dom.target); #endif } } #endif if ([directiveValue isKindOfClass:[NSInvocation class]]) { NSInvocation *n = (NSInvocation*) directiveValue; if ([active.view respondsToSelector:@selector(addTarget:action:forControlEvents:)]) { [((id)active.view) addTarget: n.target action: n.selector forControlEvents: UIControlEventTouchUpInside]; } else { NSString *error = [NSString stringWithFormat:@"Cannot apply NSInvocation to class %@", NSStringFromClass(active.class)]; NSAssert(NO, error); } } } directiveValue = [kv objectForKey:NICSSViewSubviewsKey]; if (directiveValue) { NSAssert([directiveValue isKindOfClass: [NSArray class]], @"NICSSViewSubviewsKey must be an NSArray*"); [active.view _buildSubviews:directiveValue inDOM:dom withViewArray:subviews]; } else if (directiveValue) directiveValue = [kv objectForKey:NICSSViewAccessibilityLabelKey]; if (directiveValue) { NSAssert([directiveValue isKindOfClass:[NSString class]], @"NICSSViewAccessibilityLabelKey must be an NSString*"); active.view.accessibilityLabel = directiveValue; } continue; } // This first element in a "segment" of the array must be a view or a class object that we will make into a view // You can do things like UIView.alloc.init, UIView.class, [[UIView alloc] init]... if ([directive isKindOfClass: [UIView class]]) { active = [[NIPrivateViewInfo alloc] init]; active.view = (UIView*) directive; [self addSubview:active.view]; [subviews addObject: active]; continue; } else if (class_isMetaClass(object_getClass(directive))) { active = [[NIPrivateViewInfo alloc] init]; active.view = [[directive alloc] init]; [self addSubview:active.view]; [subviews addObject: active]; continue; } else if (!active) { NSAssert(NO, @"UIView::buildSubviews expected UIView or Class to start a directive."); continue; } if ([directive isKindOfClass:[NIUserInterfaceString class]]) { [((NIUserInterfaceString*)directive) attach:active.view]; } else if ([directive isKindOfClass:[NSString class]]) { // Strings are either a cssClass or an accessibility label NSString *d = (NSString*) directive; if ([d hasPrefix:@"."]) { active.cssClasses = active.cssClasses ?: [[NSMutableArray alloc] init]; [active.cssClasses addObject: [d substringFromIndex:1]]; } else if ([d hasPrefix:@"#"]) { active.viewId = d; } else { active.view.accessibilityLabel = d; } } else if ([directive isKindOfClass:[NSNumber class]]) { // NSNumber means tag active.view.tag = [directive integerValue]; } else if ([directive isKindOfClass:[NSArray class]]) { // NSArray means recursive call to build [active.view _buildSubviews:directive inDOM:dom withViewArray:subviews]; } else if ([directive isKindOfClass:[UIColor class]]) { active.view.backgroundColor = directive; } else if ([directive isKindOfClass:[NSInvocation class]]) { NSInvocation *n = (NSInvocation*) directive; if ([active.view respondsToSelector:@selector(addTarget:action:forControlEvents:)]) { [((id)active.view) addTarget: n.target action: n.selector forControlEvents: UIControlEventTouchUpInside]; } else { NSString *error = [NSString stringWithFormat:@"Cannot apply NSInvocation to class %@", NSStringFromClass(active.class)]; NSAssert(NO, error); } } else { NSAssert(NO, @"Unknown directive in build specifier"); } } } @end @implementation NIPrivateViewInfo @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/interapp/src/NIInterapp.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <CoreLocation/CoreLocation.h> @class NIMailAppInvocation; /** * An interface for interacting with other apps installed on the device. * * @ingroup NimbusInterapp */ @interface NIInterapp : NSObject #pragma mark Chrome vs Safari + (void)setPreferGoogleChrome:(BOOL)preferGoogleChromeOverSafari; + (BOOL)preferGoogleChrome; + (BOOL)openPreferredBrowserWithURL:(NSURL *)url; #pragma mark Safari + (BOOL)safariWithURL:(NSURL *)url; #pragma mark Google Chrome + (BOOL)googleChromeIsInstalled; + (BOOL)googleChromeWithURL:(NSURL *)url; + (NSString *)googleChromeAppStoreId; #pragma mark Google Maps + (BOOL)googleMapsIsInstalled; + (BOOL)googleMaps; + (NSString *)googleMapsAppStoreId; + (BOOL)googleMapAtLocation:(CLLocationCoordinate2D)location; + (BOOL)googleMapAtLocation:(CLLocationCoordinate2D)location title:(NSString *)title; + (BOOL)googleMapDirectionsFromLocation:(CLLocationCoordinate2D)fromLocation toLocation:(CLLocationCoordinate2D)toLocation; // directionsMode can be nil. @"driving", @"transit", or @"walking". + (BOOL)googleMapDirectionsFromLocation:(CLLocationCoordinate2D)fromLocation toLocation:(CLLocationCoordinate2D)toLocation withMode:(NSString*)directionsMode; + (BOOL)googleMapDirectionsFromSourceAddress:(NSString *)srcAddr toDestAddress:(NSString *)destAddr withMode:(NSString *)directionsMode; // these just use the user's current location (even if your application doesn't have locations services on, the google maps site/app MIGHT + (BOOL)googleMapDirectionsToDestAddress:(NSString *)destAddr withMode:(NSString *)directionsMode; + (BOOL)googleMapDirectionsToLocation:(CLLocationCoordinate2D)toLocation withMode:(NSString *)directionsMode; + (BOOL)googleMapWithQuery:(NSString *)query; #pragma mark Phone + (BOOL)phone; + (BOOL)phoneWithNumber:(NSString *)phoneNumber; #pragma mark SMS + (BOOL)sms; + (BOOL)smsWithNumber:(NSString *)phoneNumber; #pragma mark Mail + (BOOL)mailWithInvocation:(NIMailAppInvocation *)invocation; #pragma mark YouTube + (BOOL)youTubeWithVideoId:(NSString *)videoId; #pragma mark App Store + (BOOL)appStoreWithAppId:(NSString *)appId; + (BOOL)appStoreGiftWithAppId:(NSString *)appId; + (BOOL)appStoreReviewWithAppId:(NSString *)appId; #pragma mark iBooks + (BOOL)iBooksIsInstalled; + (BOOL)iBooks; + (NSString *)iBooksAppStoreId; #pragma mark Facebook + (BOOL)facebookIsInstalled; + (BOOL)facebook; + (BOOL)facebookProfileWithId:(NSString *)profileId; + (NSString *)facebookAppStoreId; #pragma mark Twitter + (BOOL)twitterIsInstalled; + (BOOL)twitter; + (BOOL)twitterWithMessage:(NSString *)message; + (BOOL)twitterProfileForUsername:(NSString *)username; + (NSString *)twitterAppStoreId; #pragma mark Instagram + (BOOL)instagramIsInstalled; + (BOOL)instagram; + (BOOL)instagramCamera; + (BOOL)instagramProfileForUsername:(NSString *)username; + (NSURL *)urlForInstagramImageAtFilePath:(NSString *)filePath error:(NSError **)error; + (NSString *)instagramAppStoreId; #pragma mark Custom Application + (BOOL)applicationIsInstalledWithScheme:(NSString *)applicationScheme; + (BOOL)applicationWithScheme:(NSString *)applicationScheme; + (BOOL)applicationWithScheme:(NSString *)applicationScheme andAppStoreId:(NSString *)appStoreId; + (BOOL)applicationWithScheme:(NSString *)applicationScheme andPath:(NSString *)path; + (BOOL)applicationWithScheme:(NSString *)applicationScheme appStoreId:(NSString *)appStoreId andPath:(NSString *)path; @end @interface NIMailAppInvocation : NSObject { @private NSString* _recipient; NSString* _cc; NSString* _bcc; NSString* _subject; NSString* _body; } @property (nonatomic, copy) NSString* recipient; @property (nonatomic, copy) NSString* cc; @property (nonatomic, copy) NSString* bcc; @property (nonatomic, copy) NSString* subject; @property (nonatomic, copy) NSString* body; /** * Returns an autoreleased invocation object. */ + (id)invocation; @end /** @name Safari **/ /** * Opens the given URL in Safari. * * @fn NIInterapp::safariWithURL: */ /** @name Google Chrome **/ /** * Returns YES if the Google Chrome application is installed. * * @fn NIInterapp::googleChromeIsInstalled */ /** * Opens the given URL in Google Chrome if installed on the device. * * @fn NIINterapp::googleChromeWithURL: */ /** * The Google Chrome App Store ID. * * @fn NIInterapp::googleChromeAppStoreId */ /** @name Google Maps **/ /** * Opens Google Maps at the given location. * * @fn NIInterapp::googleMapAtLocation: */ /** * Opens Google Maps at the given location with a title. * * @fn NIInterapp::googleMapAtLocation:title: */ /** * Opens Google Maps with directions from one location to another. * * @fn NIInterapp::googleMapDirectionsFromLocation:toLocation: */ /** * Opens Google Maps with a generic query. * * @fn NIInterapp::googleMapWithQuery: */ /** @name Phone **/ /** * Opens the phone app. * * @fn NIInterapp::phone */ /** * Make a phone call with the given number. * * @fn NIInterapp::phoneWithNumber: */ /** @name SMS **/ /** * Opens the phone app. * * @fn NIInterapp::sms */ /** * Start texting the given number. * * @fn NIInterapp::smsWithNumber: */ /** @name Mail **/ /** * Opens mail with the given invocation properties. * * @fn NIInterapp::mailWithInvocation: */ /** @name YouTube **/ /** * Opens the YouTube video with the given video id. * * @fn NIInterapp::youTubeWithVideoId: */ /** @name iBooks **/ /** * Returns YES if the iBooks application is installed. * * @fn NIInterapp::iBooksIsInstalled */ /** * Opens the iBooks application. If the iBooks application is not installed, will open the * App Store to the iBooks download page. * * @fn NIInterapp::iBooks */ /** * The iBooks App Store ID. * * @fn NIInterapp::iBooksAppStoreId */ /** @name Facebook **/ /** * Returns YES if the Facebook application is installed. * * @fn NIInterapp::facebookIsInstalled */ /** * Opens the Facebook application. If the Facebook application is not installed, will open the * App Store to the Facebook download page. * * @fn NIInterapp::facebook */ /** * Opens the Facebook profile with the given id. * * @fn NIInterapp::facebookProfileWithId: */ /** * The Facebook App Store ID. * * @fn NIInterapp::facebookAppStoreId */ /** @name Twitter **/ /** * Returns YES if the Twitter application is installed. * * @fn NIInterapp::twitterIsInstalled */ /** * Opens the Twitter application. If the Twitter application is not installed, will open the * App Store to the Twitter download page. * * @fn NIInterapp::twitter */ /** * Begins composing a message. * * @fn NIInterapp::twitterWithMessage: */ /** * Opens the profile for the given username. * * @fn NIInterapp::twitterProfileForUsername: */ /** * The Twitter App Store ID. * * @fn NIInterapp::twitterAppStoreId */ /** @name Custom Application **/ /** * Returns YES if the supplied application is installed. * * @fn NIInterapp::applicationIsInstalledWithScheme: */ /** * Opens the supplied application. * * @fn NIInterapp::applicationWithScheme */ /** * Opens the supplied application. If the supplied application is not installed, will open the * App Store to the specified ID download page. * * @fn NIInterapp::applicationWithScheme:andAppStoreId: */ /** * Opens the supplied application. * * @fn NIInterapp::applicationWithScheme:andPath: */ /** * Opens the supplied application, to the specified path. If the supplied application is not installed, will open the * App Store to the download page for the specified AppStoreId. * * @fn NIInterapp::applicationWithScheme:appStoreId:andPath: */ /** * Opens the application with the supplied custom URL. * * @fn NIInterapp::applicationWithUrl: */ /** @name Instagram **/ // http://instagram.com/developer/iphone-hooks/ /** * Returns YES if the Instagram application is installed. * * @fn NIInterapp::instagramIsInstalled */ /** * Opens the Instagram application. If the Instagram application is not installed, will open the * App Store to the Instagram download page. * * @fn NIInterapp::instagram */ /** * Opens the Instagram camera. * * @fn NIInterapp::instagramCamera */ /** * Opens the profile for the given username. * * @fn NIInterapp::instagramProfileForUsername: */ /** * Copies an image to a temporary path suitable for use with a UIDocumentInteractionController in * order to open the image in Instagram. * * The image at filePath must be at least 612x612 and preferably square. If the image * is smaller than 612x612 then this method will fail. * * @fn NIInterapp::urlForInstagramImageAtFilePath:error: */ /** * The Instagram App Store ID. * * @fn NIInterapp::instagramAppStoreId */ /** @name App Store **/ /** * Opens the App Store page for the app with the given ID. * * @fn NIInterapp::appStoreWithAppId: */ /** * Opens the "Gift this app" App Store page for the app with the given ID. * * @fn NIInterapp::appStoreGiftWithAppId: */ /** * Opens the "Write a review" App Store page for the app with the given ID. * * @fn NIInterapp::appStoreReviewWithAppId: */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/interapp/src/NIInterapp.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NIInterapp.h" #import "NimbusCore+Additions.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif // TODO: Make this a user default. static BOOL sPreferGoogleChrome = NO; @implementation NIInterapp + (NSString *)sanitizedPhoneNumberFromString:(NSString *)string { if (nil == string) { return nil; } NSCharacterSet* validCharacters = [NSCharacterSet characterSetWithCharactersInString:@"1234567890-+"]; return [[string componentsSeparatedByCharactersInSet:[validCharacters invertedSet]] componentsJoinedByString:@""]; } #pragma mark Chrome vs Safari + (void)setPreferGoogleChrome:(BOOL)preferGoogleChrome { sPreferGoogleChrome = preferGoogleChrome; } + (BOOL)preferGoogleChrome { return sPreferGoogleChrome; } + (BOOL)openPreferredBrowserWithURL:(NSURL *)url { if (sPreferGoogleChrome && [NIInterapp googleChromeIsInstalled]) { return [NIInterapp googleChromeWithURL:url]; } else { return [NIInterapp safariWithURL:url]; } } #pragma mark - Safari + (BOOL)safariWithURL:(NSURL *)url { return [[UIApplication sharedApplication] openURL:url]; } #pragma mark - Google Chrome /** * Based on https://developers.google.com/chrome/mobile/docs/ios-links */ static NSString* const sGoogleChromeHttpScheme = @"googlechrome:"; static NSString* const sGoogleChromeHttpsScheme = @"googlechromes:"; + (BOOL)googleChromeIsInstalled { return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sGoogleChromeHttpScheme]]; } + (BOOL)googleChromeWithURL:(NSURL *)url { NSString *chromeScheme = nil; if ([url.scheme isEqualToString:@"http"]) { chromeScheme = sGoogleChromeHttpScheme; } else if ([url.scheme isEqualToString:@"https"]) { chromeScheme = sGoogleChromeHttpsScheme; } if (chromeScheme) { NSRange rangeForScheme = [[url absoluteString] rangeOfString:@":"]; NSString* urlNoScheme = [[url absoluteString] substringFromIndex:rangeForScheme.location + 1]; NSString* chromeUrlString = [chromeScheme stringByAppendingString:urlNoScheme]; NSURL* chromeUrl = [NSURL URLWithString:chromeUrlString]; BOOL didOpen = [[UIApplication sharedApplication] openURL:chromeUrl]; if (!didOpen) { didOpen = [self appStoreWithAppId:[self googleChromeAppStoreId]]; } return didOpen; } return NO; } + (NSString *)googleChromeAppStoreId { return @"535886823"; } #pragma mark - Google Maps /** * Source for URL information: http://mapki.com/wiki/Google_Map_Parameters */ static NSString* const sGoogleMapsScheme = @"comgooglemaps:"; + (BOOL)googleMapsIsInstalled { return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sGoogleMapsScheme]]; } + (BOOL)googleMaps { BOOL didOpen = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sGoogleMapsScheme]]; if (!didOpen) { didOpen = [self appStoreWithAppId:[self googleMapsAppStoreId]]; } return didOpen; } + (NSString *)googleMapsAppStoreId { return @"585027354"; } + (BOOL)openBestGoogleMapUrl:(NSString*)urlString{ if ([NIInterapp googleMapsIsInstalled]) { NSURL* url = [NSURL URLWithString:[@"comgooglemaps://" stringByAppendingString:urlString]]; return [[UIApplication sharedApplication] openURL:url]; } else { NSURL* url = [NSURL URLWithString:[@"http://maps.google.com/maps" stringByAppendingString:urlString]]; return [NIInterapp openPreferredBrowserWithURL:url]; } } + (BOOL)googleMapAtLocation:(CLLocationCoordinate2D)location { NSString* urlPath = [NSString stringWithFormat:@"?q=%f,%f", location.latitude, location.longitude]; return [NIInterapp openBestGoogleMapUrl:urlPath]; } + (BOOL)googleMapAtLocation:(CLLocationCoordinate2D)location title:(NSString *)title { NSString* urlPath = [NSString stringWithFormat:@"?q=%@@%f,%f", NIStringByAddingPercentEscapesForURLParameterString(title), location.latitude, location.longitude]; return [NIInterapp openBestGoogleMapUrl:urlPath]; } + (BOOL)googleMapDirectionsFromLocation:(CLLocationCoordinate2D)fromLocation toLocation:(CLLocationCoordinate2D)toLocation { return [NIInterapp googleMapDirectionsFromLocation:fromLocation toLocation:toLocation withMode:nil]; } + (BOOL)googleMapDirectionsFromLocation:(CLLocationCoordinate2D)fromLocation toLocation:(CLLocationCoordinate2D)toLocation withMode:(NSString *)directionsMode { NSString* saddr = [NSString stringWithFormat:@"%f,%f", fromLocation.latitude, fromLocation.longitude]; NSString* daddr = [NSString stringWithFormat:@"%f,%f", toLocation.latitude, toLocation.longitude]; return [NIInterapp googleMapDirectionsFromSourceAddress:saddr toDestAddress:daddr withMode:directionsMode]; } + (BOOL)googleMapDirectionsToLocation:(CLLocationCoordinate2D)toLocation withMode:(NSString *)directionsMode { NSString* daddr = [NSString stringWithFormat:@"%f,%f", toLocation.latitude, toLocation.longitude]; return [NIInterapp googleMapDirectionsFromSourceAddress:nil toDestAddress:daddr withMode:directionsMode]; } + (BOOL)googleMapDirectionsToDestAddress:(NSString *)destAddr withMode:(NSString *)directionsMode { return [NIInterapp googleMapDirectionsFromSourceAddress:nil toDestAddress:destAddr withMode:directionsMode]; } + (BOOL)googleMapDirectionsFromSourceAddress:(NSString *)srcAddr toDestAddress:(NSString *)destAddr withMode:(NSString *)directionsMode { NSString* urlPath; // source can be left blank == get current users location if (srcAddr.length > 0) { urlPath = [NSString stringWithFormat:@"?saddr=%@&daddr=%@", srcAddr, destAddr]; } else { urlPath = [NSString stringWithFormat:@"?daddr=%@", destAddr]; } if (directionsMode.length > 0) { urlPath = [NSString stringWithFormat:@"%@&directionsmode=%@", urlPath, directionsMode]; } return [NIInterapp openBestGoogleMapUrl:urlPath]; } + (BOOL)googleMapWithQuery:(NSString *)query { NSString* urlPath = [NSString stringWithFormat:@"?q=%@", NIStringByAddingPercentEscapesForURLParameterString(query)]; return [NIInterapp openBestGoogleMapUrl:urlPath]; } #pragma mark - Phone + (BOOL)phone { return [self phoneWithNumber:nil]; } + (BOOL)phoneWithNumber:(NSString *)phoneNumber { phoneNumber = [self sanitizedPhoneNumberFromString:phoneNumber]; if (nil == phoneNumber) { phoneNumber = @""; } NSString* urlPath = [@"tel:" stringByAppendingString:phoneNumber]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } #pragma mark - Texting + (BOOL)sms { return [self smsWithNumber:nil]; } + (BOOL)smsWithNumber:(NSString *)phoneNumber { phoneNumber = [self sanitizedPhoneNumberFromString:phoneNumber]; if (nil == phoneNumber) { phoneNumber = @""; } NSString* urlPath = [@"sms:" stringByAppendingString:phoneNumber]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } #pragma mark - Mail static NSString* const sMailScheme = @"mailto:"; + (BOOL)mailWithInvocation:(NIMailAppInvocation *)invocation { NSMutableDictionary* parameters = [NSMutableDictionary dictionary]; NSString* urlPath = sMailScheme; if (NIIsStringWithAnyText(invocation.recipient)) { urlPath = [urlPath stringByAppendingString:NIStringByAddingPercentEscapesForURLParameterString(invocation.recipient)]; } if (NIIsStringWithAnyText(invocation.cc)) { [parameters setObject:invocation.cc forKey:@"cc"]; } if (NIIsStringWithAnyText(invocation.bcc)) { [parameters setObject:invocation.bcc forKey:@"bcc"]; } if (NIIsStringWithAnyText(invocation.subject)) { [parameters setObject:invocation.subject forKey:@"subject"]; } if (NIIsStringWithAnyText(invocation.body)) { [parameters setObject:invocation.body forKey:@"body"]; } urlPath = NIStringByAddingQueryDictionaryToString(urlPath, parameters); return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } #pragma mark - YouTube + (BOOL)youTubeWithVideoId:(NSString *)videoId { NSString* urlPath = [@"http://www.youtube.com/watch?v=" stringByAppendingString:videoId]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } #pragma mark - iBooks static NSString* const sIBooksScheme = @"itms-books:"; + (BOOL)iBooksIsInstalled { return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sIBooksScheme]]; } + (BOOL)iBooks { BOOL didOpen = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sIBooksScheme]]; if (!didOpen) { didOpen = [self appStoreWithAppId:[self iBooksAppStoreId]]; } return didOpen; } + (NSString *)iBooksAppStoreId { return @"364709193"; } #pragma mark - Facebook static NSString* const sFacebookScheme = @"fb:"; + (BOOL)facebookIsInstalled { return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sFacebookScheme]]; } + (BOOL)facebook { BOOL didOpen = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sFacebookScheme]]; if (!didOpen) { didOpen = [self appStoreWithAppId:[self facebookAppStoreId]]; } return didOpen; } + (BOOL)facebookProfileWithId:(NSString *)profileId { NSString* urlPath = [sFacebookScheme stringByAppendingFormat:@"//profile/%@", profileId]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } + (NSString *)facebookAppStoreId { return @"284882215"; } #pragma mark - Twitter static NSString* const sTwitterScheme = @"twitter:"; + (BOOL)twitterIsInstalled { return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sTwitterScheme]]; } + (BOOL)twitter { BOOL didOpen = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sTwitterScheme]]; if (!didOpen) { didOpen = [self appStoreWithAppId:[self twitterAppStoreId]]; } return didOpen; } + (BOOL)twitterWithMessage:(NSString *)message { NSString* urlPath = [sTwitterScheme stringByAppendingFormat:@"//post?message=%@", NIStringByAddingPercentEscapesForURLParameterString(message)]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } + (BOOL)twitterProfileForUsername:(NSString *)username { NSString* urlPath = [sTwitterScheme stringByAppendingFormat:@"//user?screen_name=%@", NIStringByAddingPercentEscapesForURLParameterString(username)]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } + (NSString *)twitterAppStoreId { return @"333903271"; } #pragma mark - Application + (BOOL)applicationIsInstalledWithScheme:(NSString *)applicationScheme { return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:applicationScheme]]; } + (BOOL)applicationWithScheme:(NSString *)applicationScheme { return [self applicationWithScheme:applicationScheme appStoreId:nil andPath:nil]; } + (BOOL)applicationWithScheme:(NSString *)applicationScheme andAppStoreId:(NSString *)appStoreId { return [self applicationWithScheme:applicationScheme appStoreId:appStoreId andPath:nil]; } + (BOOL)applicationWithScheme:(NSString *)applicationScheme andPath:(NSString *)path { return [self applicationWithScheme:applicationScheme appStoreId:nil andPath:path]; } + (BOOL)applicationWithScheme:(NSString *)applicationScheme appStoreId:(NSString *)appStoreId andPath:(NSString *)path { BOOL didOpen = false; NSString* urlPath = applicationScheme; // Were we passed a path? if (path != nil) { // Generate the full application URL urlPath = [urlPath stringByAppendingFormat:@"%@", path]; } // Try to open the application URL didOpen = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; // Didn't open and we have an appStoreId if (!didOpen && appStoreId != nil) { // Open the app store instead didOpen = [self appStoreWithAppId:appStoreId]; } return didOpen; } #pragma mark - Instagram static NSString* const sInstagramScheme = @"instagram:"; + (BOOL)instagramIsInstalled { return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sInstagramScheme]]; } + (BOOL)instagram { BOOL didOpen = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sInstagramScheme]]; if (!didOpen) { didOpen = [self appStoreWithAppId:[self instagramAppStoreId]]; } return didOpen; } + (BOOL)instagramCamera { NSString* urlPath = [sInstagramScheme stringByAppendingString:@"//camera"]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } + (BOOL)instagramProfileForUsername:(NSString *)username { NSString* urlPath = [sInstagramScheme stringByAppendingFormat:@"//user?username=%@", NIStringByAddingPercentEscapesForURLParameterString(username)]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } + (NSURL *)urlForInstagramImageAtFilePath:(NSString *)filePath error:(NSError **)error { if (![self instagramIsInstalled]) { return nil; } UIImage* image = [[UIImage alloc] initWithContentsOfFile:filePath]; // Unable to read the image. if (nil == image) { if (nil != error) { *error = [NSError errorWithDomain: NSCocoaErrorDomain code: NSFileReadUnknownError userInfo: [NSDictionary dictionaryWithObject: filePath forKey: NSFilePathErrorKey]]; } return nil; } // Instagram requires that images are at least 612x612 and preferably square. if (image.size.width < 612 || image.size.height < 612) { if (nil != error) { *error = [NSError errorWithDomain: NINimbusErrorDomain code: NIImageTooSmall userInfo: [NSDictionary dictionaryWithObject: image forKey: NIImageErrorKey]]; } return nil; } NSFileManager* fm = [NSFileManager defaultManager]; NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NIDASSERT(NIIsArrayWithObjects(paths)); if (!NIIsArrayWithObjects(paths)) { return nil; } NSString* documentsPath = [paths objectAtIndex:0]; NSString* destinationPath = [documentsPath stringByAppendingPathComponent: [NSString stringWithFormat:@"nimbus-instagram-image-%.0f.ig", [NSDate timeIntervalSinceReferenceDate]]]; [fm copyItemAtPath: filePath toPath: destinationPath error: error]; NIDASSERT(nil == error || nil == *error); if (nil == error || nil == *error) { return [NSURL URLWithString:[@"file:" stringByAppendingString:destinationPath]]; } else { return nil; } } + (NSString *)instagramAppStoreId { return @"389801252"; } #pragma mark - App Store + (BOOL)appStoreWithAppId:(NSString *)appId { NSString* urlPath = [@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=" stringByAppendingString:appId]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } + (BOOL)appStoreGiftWithAppId:(NSString *)appId { NSString* urlPath = [NSString stringWithFormat:@"itms-appss://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/giftSongsWizard?gift=1&salableAdamId=%@&productType=C&pricingParameter=STDQ&mt=8&ign-mscache=1", appId]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } + (BOOL)appStoreReviewWithAppId:(NSString *)appId { NSString* urlPath = [@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=" stringByAppendingString:appId]; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlPath]]; } @end @implementation NIMailAppInvocation + (id)invocation { return [[[self class] alloc] init]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/interapp/src/NimbusInterapp.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> /** * @defgroup NimbusInterapp Nimbus Interapp * * <div id="github" feature="interapp"></div> * * Nimbus' inter-application communication feature for interacting with other applications * installed on the device. * * Applications may define schemes that make it possible to open them from your own application * using <code>[[UIApplication sharedApplication] openURL:]</code>. There is no way to * ask an application which URLs it implements, so Interapp strives to provide a growing * set of implementations for known application interfaces. * * <h2>Minimum Requirements</h2> * * Required frameworks: * * - Foundation.framework * - UIKit.framework * - CoreLocation.framework * * Minimum Operating System: <b>iOS 4.0</b> * * Source located in <code>src/interapp/src</code> * * * <h2>When to Use Interapp</h2> * * Interapp is particularly useful if you would like to reuse functionality provided by other * applications. For example, imagine building an app for a client that would optionally * support tweeting messages. Instead of building Oath into your application, you * can simply check to see whether the Twitter app is installed and then launch it with a * pre-populated message. If the app is not installed, Interapp also makes it easy to launch * the App Store directly to the page where the app can be downloaded. * * Choosing to use Interapp over building functionality into your application is a definite * tradeoff. Keeping the user within the context of your application may be worth the extra * effort to communicate with the API or implement the functionality yourself. In this case * you may find it useful to use Interapp as a quick means of prototyping the eventual * functionality. * * * <h2>Examples</h2> * * <h3>Composing a Message in the Twitter App</h3> * * @code * // Check whether the Twitter app is installed. * if ([NIInterapp twitterIsInstalled]) { * // Opens the Twitter app with the composer prepopulated with the following message. * [NIInterapp twitterWithMessage:@"Playing with the Nimbus Interapp feature!"]; * * } else { * // Optionally, we can open the App Store to the twitter page to download the app. * [NIInterapp twitter]; * } * @endcode * * * <h3>Opening a Photo in Instagram</h3> * * @code * NSString* filePath = ...; * NSError* error = nil; * * // Copies the image at filePath to a suitable location for being opened by Instagram. * NSURL* fileUrl = [NIInterapp urlForInstagramImageAtFilePath:filePath error:&error]; * * // It's possible that copying the file might fail (if the image dimensions are * // less than 612x612, for example). * if (nil != fileUrl && nil == error) { * * // Note: You must retain docController at some point here. Generally you would retain * // a local copy of docController in your containing controller and then release the * // docController as necessary. * UIDocumentInteractionController* docController = * [UIDocumentInteractionController interactionControllerWithURL:_fileUrl]; * * // Use the delegate methods to release the doc controller when the menu is dismissed. * docController.delegate = self; * * // Use any of the presentOpenIn* methods to present the menu from the correct location. * [docController presentOpenInMenuFromRect: bounds * inView: view * animated: YES]; * } * @endcode */ #import "NimbusCore.h" #import "NIInterapp.h"
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherButtonView.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> #import "NILauncherView.h" #import "NILauncherViewModel.h" /** * A launcher button view that displays an image and and a label beneath it. * * This view shows the icon anchored to the top middle of the view and the label anchored to the * bottom middle. By default the label is a single line label with NSLineBreakByTruncatingTail. * * @image html NILauncherButtonExample1.png "Example of an NILauncherButton" * * @ingroup NimbusLauncher */ @interface NILauncherButtonView : NIRecyclableView <NILauncherButtonView, NILauncherViewObjectView> @property (nonatomic, strong) UIButton* button; @property (nonatomic, copy) UILabel* label; @property (nonatomic, assign) UIEdgeInsets contentInset; @end /** @name Accessing Subviews */ /** * The button view that should be used to display the launcher icon. * * @fn NILauncherButtonView::button */ /** * The label view that should show the title of the launcher item. * * @fn NILauncherButtonView::label */ /** @name Configuring Display Attributes */ /** * The distance that the button and label are inset from the enclosing view. * * The unit of size is points. The default value is 5 points on all sides. * * @fn NILauncherButtonView::contentInset */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherButtonView.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <QuartzCore/QuartzCore.h> #import "NILauncherButtonView.h" #import "NILauncherViewObject.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif // The contentInset around the entire button on the top, left, bottom, and right sides. static const CGFloat kDefaultContentInset = 0; @implementation NILauncherButtonView - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithReuseIdentifier:reuseIdentifier])) { _contentInset = UIEdgeInsetsMake(kDefaultContentInset, kDefaultContentInset, kDefaultContentInset, kDefaultContentInset); _button = [UIButton buttonWithType:UIButtonTypeCustom]; _button.imageView.contentMode = UIViewContentModeCenter; _label = [[UILabel alloc] init]; _label.backgroundColor = [UIColor clearColor]; _label.numberOfLines = 1; #if __IPHONE_OS_VERSION_MIN_REQUIRED < NIIOS_6_0 _label.textAlignment = UITextAlignmentCenter; _label.lineBreakMode = NSLineBreakByTruncatingTail; #else _label.textAlignment = NSTextAlignmentCenter; _label.lineBreakMode = NSLineBreakByTruncatingTail; #endif _label.font = [UIFont boldSystemFontOfSize:12]; _label.textColor = [UIColor whiteColor]; self.layer.rasterizationScale = NIScreenScale(); [self.layer setShouldRasterize:YES]; [self addSubview:_button]; [self addSubview:_label]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; CGRect contentBounds = UIEdgeInsetsInsetRect(self.bounds, self.contentInset); self.label.frame = CGRectMake(CGRectGetMinX(contentBounds), CGRectGetMaxY(contentBounds) - self.label.font.lineHeight, CGRectGetWidth(contentBounds), self.label.font.lineHeight); self.button.frame = NIRectContract(contentBounds, 0, self.label.bounds.size.height); } #pragma mark - NIRecyclableView - (void)prepareForReuse { self.label.text = nil; [self.button setImage:nil forState:UIControlStateNormal]; } #pragma mark - NILauncherModelObjectView - (void)shouldUpdateViewWithObject:(NILauncherViewObject *)object { self.label.text = object.title; [self.button setImage:object.image forState:UIControlStateNormal]; [self setNeedsLayout]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherPageView.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <UIKit/UIKit.h> #import "NimbusPagingScrollView.h" /** * A single page in a launcher view. * * This is a recyclable page view that can be used with NIPagingScrollView. * * Each launcher page contains a set of views. The page lays out each of the views in a grid based * on the given display attributes. * * Views will be laid out from left to right and then from top to bottom. * * @ingroup NimbusLauncher */ @interface NILauncherPageView : NIPagingScrollViewPage @property (nonatomic, strong) NIViewRecycler* viewRecycler; - (void)addRecyclableView:(UIView<NIRecyclableView> *)view; @property (nonatomic, readonly, strong) NSArray* recyclableViews; @property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, assign) CGSize viewSize; @property (nonatomic, assign) CGSize viewMargins; @end /** @name Recyclable Views */ /** * A shared view recycler for this page's recyclable views. * * When this page view is preparing for reuse it will add each of its button views to the recycler. * This recycler should be the same recycler used by all pages in the launcher view. * * @fn NILauncherPageView::viewRecycler */ /** * Add a recyclable view to this page. * * @param view A recyclable view. * @fn NILauncherPageView::addRecyclableView: */ /** * All of the recyclable views that have been added to this page. * * @returns An array of recyclable views in the same order in which they were added. * @fn NILauncherPageView::recyclableViews */ /** @name Configuring Display Attributes */ /** * The distance that the recyclable views are inset from the enclosing view. * * Use this property to add to the area around the content. The unit of size is points. * The default value is UIEdgeInsetsZero. * * @fn NILauncherPageView::contentInset */ /** * The size of each recyclable view. * * The unit of size is points. The default value is CGSizeZero. * * @fn NILauncherPageView::viewSize */ /** * The recommended horizontal and vertical distance between each recyclable view. * * This property is only a recommended value because the page view does its best to distribute the * views in a way that visually balances them. * * Width is the horizontal distance between each view. Height is the vertical distance between each * view. The unit of size is points. The default value is CGSizeZero. * * @fn NILauncherPageView::viewMargins */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherPageView.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NILauncherPageView.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @interface NILauncherPageView() @property (nonatomic, strong) NSMutableArray* mutableRecyclableViews; @end @implementation NILauncherPageView - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithReuseIdentifier:reuseIdentifier])) { _mutableRecyclableViews = [NSMutableArray array]; // The view frames are calculated manually in layoutSubviews. self.autoresizesSubviews = NO; } return self; } - (void)layoutSubviews { [super layoutSubviews]; const CGFloat leftEdge = self.contentInset.left; const CGFloat topEdge = self.contentInset.top; const CGFloat rightEdge = self.bounds.size.width - self.contentInset.right; const CGSize viewSize = self.viewSize; const CGSize viewMargins = self.viewMargins; CGFloat contentWidth = (self.bounds.size.width - self.contentInset.left - self.contentInset.right); NSInteger numberOfColumns = floorf((contentWidth + viewMargins.width) / (viewSize.width + viewMargins.width)); CGFloat viewWidth = numberOfColumns * viewSize.width; CGFloat distributedHorizontalMargin = floorf((contentWidth - viewWidth) / (CGFloat)(numberOfColumns + 1)); const CGFloat horizontalDelta = viewSize.width + distributedHorizontalMargin; const CGFloat verticalDelta = viewSize.height + viewMargins.height; CGFloat x = leftEdge + distributedHorizontalMargin; CGFloat y = topEdge; for (UIView* view in self.mutableRecyclableViews) { view.frame = CGRectMake(x, y, viewSize.width, viewSize.height); x += horizontalDelta; if (x + viewSize.width > rightEdge) { x = leftEdge + distributedHorizontalMargin; y += verticalDelta; } } } #pragma mark - NIRecyclableView - (void)prepareForReuse { // You forgot to provide a view recycler. NIDASSERT(nil != self.viewRecycler); for (UIView<NIRecyclableView>* view in self.mutableRecyclableViews) { [view removeFromSuperview]; [self.viewRecycler recycleView:view]; } [self.mutableRecyclableViews removeAllObjects]; } #pragma mark - Public - (void)addRecyclableView:(UIView<NIRecyclableView> *)view { [self addSubview:view]; [self.mutableRecyclableViews addObject:view]; [self setNeedsLayout]; } - (NSArray *)recyclableViews { return [self.mutableRecyclableViews copy]; } - (void)setContentInset:(UIEdgeInsets)contentInset { _contentInset = contentInset; [self setNeedsLayout]; } - (void)setviewSize:(CGSize)viewSize { _viewSize = viewSize; [self setNeedsLayout]; } - (void)setviewMargins:(CGSize)viewMargins { _viewMargins = viewMargins; [self setNeedsLayout]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherView.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NimbusCore.h" @protocol NILauncherDelegate; @protocol NILauncherDataSource; @protocol NILauncherButtonView; /** * Calculate the given field dynamically given the view and button dimensions. */ extern const NSInteger NILauncherViewGridBasedOnButtonSize; /** * A launcher view that simulates iOS' home screen launcher functionality. * * @ingroup NimbusLauncher */ @interface NILauncherView : UIView @property (nonatomic, assign) NSInteger maxNumberOfButtonsPerPage; // Default: NSIntegerMax @property (nonatomic, assign) UIEdgeInsets contentInsetForPages; // Default: 10px on all sides @property (nonatomic, assign) CGSize buttonSize; // Default: 80x80 @property (nonatomic, assign) NSInteger numberOfRows; // Default: NILauncherViewGridBasedOnButtonSize @property (nonatomic, assign) NSInteger numberOfColumns; // Default: NILauncherViewGridBasedOnButtonSize - (void)reloadData; @property (nonatomic, weak) id<NILauncherDelegate> delegate; @property (nonatomic, weak) id<NILauncherDataSource> dataSource; - (UIView<NILauncherButtonView> *)dequeueReusableViewWithIdentifier:(NSString *)identifier; - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; @end /** * The launcher data source used to populate the view. * * @ingroup NimbusLauncher */ @protocol NILauncherDataSource <NSObject> @required /** @name Configuring a Launcher View */ /** * Tells the receiver to return the number of rows in a given section of a table view (required). * * @param launcherView The launcher-view object requesting this information. * @param page The index locating a page in @c launcherView. * @returns The number of buttons in @c page. */ - (NSInteger)launcherView:(NILauncherView *)launcherView numberOfButtonsInPage:(NSInteger)page; /** * Tells the receiver to return a button view for inserting into a particular location of a given * page in the launcher view (required). * * @param launcherView The launcher-view object requesting this information. * @param page The index locating a page in @c launcherView. * @param index The index locating a button in a page. * @returns A UIView that conforms to NILauncherButtonView that the launcher will display on the given page. An assertion is raised if you return nil. */ - (UIView<NILauncherButtonView> *)launcherView:(NILauncherView *)launcherView buttonViewForPage:(NSInteger)page atIndex:(NSInteger)index; @optional /** * Asks the receiver to return the number of pages in the launcher view. * * It is assumed that the launcher view has one page if this method is not implemented. * * @param launcherView The launcher-view object requesting this information. * @returns The number of pages in @c launcherView. The default value is 1. * @sa NILauncherDataSource::launcherView:numberOfButtonsInPage: */ - (NSInteger)numberOfPagesInLauncherView:(NILauncherView *)launcherView; /** * Asks the receiver to return the number of rows of buttons each page can display in the * launcher view. * * This method will be called each time the frame of the launcher view changes. Notably, this will * be called when the launcher view has been rotated as a result of a device rotation. * * @param launcherView The launcher-view object requesting this information. * @returns The number of rows of buttons each page can display. * @sa NILauncherDataSource::numberOfColumnsPerPageInLauncherView: */ - (NSInteger)numberOfRowsPerPageInLauncherView:(NILauncherView *)launcherView; /** * Asks the receiver to return the number of columns of buttons each page can display in the * launcher view. * * This method will be called each time the frame of the launcher view changes. Notably, this will * be called when the launcher view has been rotated as a result of a device rotation. * * @param launcherView The launcher-view object requesting this information. * @returns The number of columns of buttons each page can display. * @sa NILauncherDataSource::numberOfRowsPerPageInLauncherView: */ - (NSInteger)numberOfColumnsPerPageInLauncherView:(NILauncherView *)launcherView; @end /** * The launcher delegate used to inform of state changes and user interactions. * * @ingroup NimbusLauncher */ @protocol NILauncherDelegate <NSObject> @optional /** @name Managing Selections */ /** * Informs the receiver that the specified item on the specified page has been selected. * * @param launcherView A launcher-view object informing the delegate about the new item * selection. * @param page A page index locating the selected item in @c launcher. * @param index An index locating the selected item in the given page. */ - (void)launcherView:(NILauncherView *)launcherView didSelectItemOnPage:(NSInteger)page atIndex:(NSInteger)index; @end /** * The launcher delegate used to inform of state changes and user interactions. * * @ingroup NimbusLauncher */ @protocol NILauncherButtonView <NIRecyclableView> @required /** * Requires the view to contain a button subview. */ @property (nonatomic, strong) UIButton* button; @end /** @name Configuring a Launcher View */ /** * The maximum number of buttons allowed on a given page. * * By default this value is NSIntegerMax. * * @fn NILauncherView::maxNumberOfButtonsPerPage */ /** * The distance that each page view insets its contents. * * Use this property to add to the area around the content of each page. The unit of size is points. * The default value is 10 points on all sides. * * @fn NILauncherView::contentInsetForPages */ /** * The size of each launcher button. * * @fn NILauncherView::buttonSize */ /** * The number of rows to display on each page. * * @fn NILauncherView::numberOfRows */ /** * The number of columns to display on each page. * * @fn NILauncherView::numberOfColumns */ /** * Returns a reusable launcher button view object located by its identifier. * * @param identifier A string identifying the launcher button view object to be reused. By * default, a reusable view's identifier is its class name, but you can * change it to any arbitrary value. * @returns A UIView object with the associated identifier that conforms to the * NILauncherButtonView protocol, or nil if no such object exists in the reusable-cell * queue. * @fn NILauncherView::dequeueReusableViewWithIdentifier: */ /** @name Managing the Delegate and the Data Source */ /** * The object that acts as the delegate of the receiving launcher view. * * The delegate must adopt the NILauncherDelegate protocol. The delegate is not retained. * * @fn NILauncherView::delegate */ /** * The object that acts as the data source of the receiving table view. * * The data source must adopt the NILauncherDataSource protocol. The data source is not retained. * * @fn NILauncherView::dataSource */ /** @name Reloading the Table View */ /** * Reloads the pages of the receiver. * * Call this method to reload all the data that is used to construct the launcher, including pages * and buttons. For efficiency, the launcher redisplays only those pages that are visible or nearly * visible. * * @fn NILauncherView::reloadData */ /** @name Rotating the Launcher View */ /** * Stores the current state of the launcher view in preparation for rotation. * * This must be called in conjunction with willAnimateRotationToInterfaceOrientation:duration: * in the methods by the same name from the view controller containing this view. * * @fn NILauncherView::willRotateToInterfaceOrientation:duration: */ /** * Updates the frame of the launcher view while maintaining the current visible page's state. * * @fn NILauncherView::willAnimateRotationToInterfaceOrientation:duration: */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherView.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NILauncherView.h" #import "NILauncherPageView.h" #import "NimbusPagingScrollView.h" #import "NIPagingScrollView+Subclassing.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static NSString* const kPageReuseIdentifier = @"page"; const NSInteger NILauncherViewGridBasedOnButtonSize = -1; static const CGFloat kDefaultButtonDimensions = 80; static const CGFloat kDefaultPadding = 10; @interface NILauncherView() <NIPagingScrollViewDataSource, NIPagingScrollViewDelegate> @property (nonatomic, strong) NIPagingScrollView* pagingScrollView; @property (nonatomic, strong) UIPageControl* pager; @property (nonatomic, assign) NSInteger numberOfPages; @property (nonatomic, strong) NIViewRecycler* viewRecycler; - (void)updateLayoutForPage:(NILauncherPageView *)page; @end @implementation NILauncherView - (void)_configureDefaults { // We handle autoresizing ourselves. [self setAutoresizesSubviews:NO]; _viewRecycler = [[NIViewRecycler alloc] init]; _buttonSize = CGSizeMake(kDefaultButtonDimensions, kDefaultButtonDimensions); _numberOfColumns = NILauncherViewGridBasedOnButtonSize; _numberOfRows = NILauncherViewGridBasedOnButtonSize; _maxNumberOfButtonsPerPage = NSIntegerMax; _contentInsetForPages = UIEdgeInsetsMake(kDefaultPadding, kDefaultPadding, kDefaultPadding, kDefaultPadding); // The paging scroll view. _pagingScrollView = [[NIPagingScrollView alloc] initWithFrame:self.bounds]; _pagingScrollView.dataSource = self; _pagingScrollView.delegate = self; [self addSubview:_pagingScrollView]; // The pager displayed below the paging scroll view. _pager = [[UIPageControl alloc] init]; _pager.hidesForSinglePage = YES; // So, this is weird. Apparently if you don't set a background color on the pager control // then taps won't be handled anywhere but within the dot area. If you do set a background // color, however, then taps outside of the dot area DO change the selected page. // \(o.o)/ _pager.backgroundColor = [UIColor blackColor]; // Similarly for the scroll view anywhere there isn't a subview. // We update these background colors when the launcher view's own background color is set. _pagingScrollView.backgroundColor = [UIColor blackColor]; // Don't update the pager when the user taps until we've animated to the new page. // This allows us to reset the page index forcefully if necessary without flickering the // pager's current selection. _pager.defersCurrentPageDisplay = YES; // When the user taps the pager control it fires a UIControlEventValueChanged notification. [_pager addTarget:self action:@selector(pagerDidChangePage:) forControlEvents:UIControlEventValueChanged]; [self addSubview:_pager]; } - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { [self _configureDefaults]; } return self; } - (id)initWithCoder:(NSCoder *)aDecoder { if ((self = [super initWithCoder:aDecoder])) { [self _configureDefaults]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; [_pager sizeToFit]; _pagingScrollView.frame = NIRectContract(self.bounds, 0, _pager.frame.size.height); _pager.frame = NIRectShift(self.bounds, 0, _pagingScrollView.frame.size.height); for (NILauncherPageView* pageView in self.pagingScrollView.visiblePages) { [self updateLayoutForPage:pageView]; } } - (void)setBackgroundColor:(UIColor *)backgroundColor { [super setBackgroundColor:backgroundColor]; self.pagingScrollView.backgroundColor = backgroundColor; self.pager.backgroundColor = backgroundColor; } - (void)calculateLayoutForFrame:(CGRect)frame buttonDimensions:(CGSize *)pButtonDimensions numberOfRows:(NSInteger *)pNumberOfRows numberOfColumns:(NSInteger *)pNumberOfColumns buttonMargins:(CGSize *)pButtonMargins { NIDASSERT(nil != pButtonDimensions); NIDASSERT(nil != pNumberOfRows); NIDASSERT(nil != pNumberOfColumns); NIDASSERT(nil != pButtonMargins); if (nil == pButtonDimensions || nil == pNumberOfRows || nil == pNumberOfColumns || nil == pButtonMargins) { return; } CGFloat pageWidth = frame.size.width - self.contentInsetForPages.left - self.contentInsetForPages.right; CGFloat pageHeight = frame.size.height - self.contentInsetForPages.top - self.contentInsetForPages.bottom; CGSize buttonDimensions = self.buttonSize; NSInteger numberOfColumns = self.numberOfColumns; NSInteger numberOfRows = self.numberOfRows; // Override point if ([self.dataSource respondsToSelector:@selector(numberOfRowsPerPageInLauncherView:)]) { numberOfRows = [self.dataSource numberOfRowsPerPageInLauncherView:self]; } if ([self.dataSource respondsToSelector:@selector(numberOfColumnsPerPageInLauncherView:)]) { numberOfColumns = [self.dataSource numberOfColumnsPerPageInLauncherView:self]; } if (NILauncherViewGridBasedOnButtonSize == numberOfColumns) { numberOfColumns = floorf(pageWidth / buttonDimensions.width); } if (NILauncherViewGridBasedOnButtonSize == numberOfRows) { numberOfRows = floorf(pageHeight / buttonDimensions.height); } NIDASSERT(numberOfRows > 0); NIDASSERT(numberOfColumns > 0); numberOfRows = MAX(1, numberOfRows); numberOfColumns = MAX(1, numberOfColumns); CGFloat totalButtonWidth = numberOfColumns * buttonDimensions.width; CGFloat buttonHorizontalSpacing = 0; if (numberOfColumns > 1) { buttonHorizontalSpacing = floorf((pageWidth - totalButtonWidth) / (numberOfColumns - 1)); } CGFloat totalButtonHeight = numberOfRows * buttonDimensions.height; CGFloat buttonVerticalSpacing = 0; if (numberOfRows > 1) { buttonVerticalSpacing = floorf((pageHeight - totalButtonHeight) / (numberOfRows - 1)); } *pButtonDimensions = buttonDimensions; *pNumberOfRows = numberOfRows; *pNumberOfColumns = numberOfColumns; pButtonMargins->width = buttonHorizontalSpacing; pButtonMargins->height = buttonVerticalSpacing; } - (void)updateLayoutForPage:(NILauncherPageView *)page { CGSize buttonDimensions = CGSizeZero; NSInteger numberOfRows = 0; NSInteger numberOfColumns = 0; CGSize buttonMargins = CGSizeZero; [self calculateLayoutForFrame:self.pagingScrollView.frame buttonDimensions:&buttonDimensions numberOfRows:&numberOfRows numberOfColumns:&numberOfColumns buttonMargins:&buttonMargins]; page.contentInset = self.contentInsetForPages; page.viewSize = buttonDimensions; page.viewMargins = buttonMargins; } #pragma mark - UIPageControl Change Notifications - (void)pagerDidChangePage:(UIPageControl*)pager { if ([self.pagingScrollView moveToPageAtIndex:pager.currentPage animated:YES]) { // Once we've handled the page change notification, notify the pager that it's ok to update // the page display. [self.pager updateCurrentPageDisplay]; } } #pragma mark - Actions /** * Find a button in the pages and retrieve its page and index. * * @param[in] searchButton The button you are looking for. * @param[out] pPage The resulting page, if found. * @param[out] pIndex The resulting index, if found. * @returns YES if the button was found. NO otherwise. */ - (BOOL)pageAndIndexOfButton:(UIButton *)searchButton page:(NSInteger *)pPage index:(NSInteger *)pIndex { NIDASSERT(nil != pPage); NIDASSERT(nil != pIndex); if (nil == pPage || nil == pIndex) { return NO; } for (NILauncherPageView* pageView in self.pagingScrollView.visiblePages) { for (NSInteger buttonIndex = 0; buttonIndex < pageView.recyclableViews.count; ++buttonIndex) { UIView<NILauncherButtonView>* buttonView = [pageView.recyclableViews objectAtIndex:buttonIndex]; if (buttonView.button == searchButton) { *pPage = pageView.pageIndex; *pIndex = buttonIndex; return YES; } } } return NO; } - (void)didTapButton:(UIButton *)tappedButton { NSInteger page = -1; NSInteger buttonIndex = 0; if ([self pageAndIndexOfButton:tappedButton page:&page index:&buttonIndex]) { if ([self.delegate respondsToSelector:@selector(launcherView:didSelectItemOnPage:atIndex:)]) { [self.delegate launcherView:self didSelectItemOnPage:page atIndex:buttonIndex]; } } else { // How exactly did we tap a button that wasn't a part of the launcher view? NIDASSERT(NO); } } #pragma mark - NIPagingScrollViewDataSource - (NSInteger)numberOfPagesInPagingScrollView:(NIPagingScrollView *)pagingScrollView { return self.numberOfPages; } - (UIView<NIPagingScrollViewPage> *)pagingScrollView:(NIPagingScrollView *)pagingScrollView pageViewForIndex:(NSInteger)pageIndex { NILauncherPageView* page = (NILauncherPageView *)[self.pagingScrollView dequeueReusablePageWithIdentifier:kPageReuseIdentifier]; if (nil == page) { page = [[NILauncherPageView alloc] initWithReuseIdentifier:kPageReuseIdentifier]; page.viewRecycler = self.viewRecycler; } [self updateLayoutForPage:page]; NSInteger numberOfButtons = [self.dataSource launcherView:self numberOfButtonsInPage:pageIndex]; numberOfButtons = MIN(numberOfButtons, self.maxNumberOfButtonsPerPage); for (NSInteger buttonIndex = 0 ; buttonIndex < numberOfButtons; ++buttonIndex) { UIView<NILauncherButtonView>* buttonView = [self.dataSource launcherView:self buttonViewForPage:pageIndex atIndex:buttonIndex]; NSAssert(nil != buttonView, @"A non-nil UIView must be returned."); [buttonView.button addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside]; [page addRecyclableView:(UIView<NIRecyclableView> *)buttonView]; } return page; } #pragma mark - NIPagingScrollViewDelegate - (void)pagingScrollViewDidChangePages:(NIPagingScrollView *)pagingScrollView { self.pager.currentPage = pagingScrollView.centerPageIndex; } #pragma mark - Public - (void)reloadData { if ([self.dataSource respondsToSelector:@selector(numberOfPagesInLauncherView:)]) { _numberOfPages = [self.dataSource numberOfPagesInLauncherView:self]; } else { _numberOfPages = 1; } self.pager.numberOfPages = _numberOfPages; [self.pagingScrollView reloadData]; [self setNeedsLayout]; } - (UIView<NILauncherButtonView> *)dequeueReusableViewWithIdentifier:(NSString *)identifier { NIDASSERT(nil != identifier); if (nil == identifier) { return nil; } return (UIView<NILauncherButtonView> *)[self.viewRecycler dequeueReusableViewWithIdentifier:identifier]; } - (void)setcontentInsetForPages:(UIEdgeInsets)contentInsetForPages { _contentInsetForPages = contentInsetForPages; for (NILauncherPageView* pageView in self.pagingScrollView.visiblePages) { pageView.contentInset = contentInsetForPages; } } - (void)setButtonSize:(CGSize)buttonSize { _buttonSize = buttonSize; for (NILauncherPageView* pageView in self.pagingScrollView.visiblePages) { pageView.viewSize = buttonSize; } } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self.pagingScrollView willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self.pagingScrollView willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherViewController.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NILauncherView.h" /** * The NILauncherViewController class creates a controller object that manages a launcher view. * It implements the following behavior: * * - It creates an unconfigured NILauncherView object with the correct dimensions and autoresize * mask. You can access this view through the launcherView property. * - NILauncherViewController sets the data source and the delegate of the launcher view to self. * - When the launcher view is about to appear the first time it’s loaded, the launcher-view * controller reloads the launcher view’s data. * * @image html NILauncherViewControllerExample1.png "Example of an NILauncherViewController." * * @ingroup NimbusLauncher */ @interface NILauncherViewController : UIViewController <NILauncherDelegate, NILauncherDataSource> @property (nonatomic, strong) NILauncherView* launcherView; @end /** @name Accessing the Launcher View */ /** * Returns the launcher view managed by the controller object. * * @fn NILauncherViewController::launcherView */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherViewController.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NILauncherViewController.h" #import "NILauncherView.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @interface NILauncherViewController() @property (nonatomic, assign) BOOL shouldReloadData; @end @implementation NILauncherViewController - (void)loadView { [super loadView]; self.launcherView = [[NILauncherView alloc] initWithFrame:self.view.bounds]; self.launcherView.autoresizingMask = UIViewAutoresizingFlexibleDimensions; self.launcherView.dataSource = self; self.launcherView.delegate = self; self.view = self.launcherView; self.shouldReloadData = YES; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (self.view && self.shouldReloadData) { [self.launcherView reloadData]; self.shouldReloadData = NO; } } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; [self.launcherView willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; [self.launcherView willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; } #pragma mark - NILauncherDataSource - (NSInteger)launcherView:(NILauncherView *)launcherView numberOfButtonsInPage:(NSInteger)page { return 0; } - (UIView<NILauncherButtonView> *)launcherView:(NILauncherView *)launcherView buttonViewForPage:(NSInteger)page atIndex:(NSInteger)buttonIndex { return nil; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherViewModel.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NILauncherView.h" @protocol NILauncherViewObject; @protocol NILauncherViewModelDelegate; /** * A launcher view model that complies to the NILauncherDataSource protocol. * * This model object allows you to keep all of your launcher view data together in one object. * It also conforms to the NSCoding protocol, allowing you to read and write your model to disk * so that you can store the state of your launcher. * * @ingroup NimbusLauncherModel */ @interface NILauncherViewModel : NSObject <NILauncherDataSource, NSCoding> // Designated initializer. - (id)initWithArrayOfPages:(NSArray *)pages delegate:(id<NILauncherViewModelDelegate>)delegate; - (void)appendPage:(NSArray *)page; - (void)appendObject:(id<NILauncherViewObject>)object toPage:(NSInteger)pageIndex; - (id<NILauncherViewObject>)objectAtIndex:(NSInteger)index pageIndex:(NSInteger)pageIndex; @property (nonatomic, weak) id<NILauncherViewModelDelegate> delegate; @end /** * The delegate for NILauncherViewModel. * * This delegate allows you to configure the launcher button views before they are displayed. * * @ingroup NimbusLauncherModel */ @protocol NILauncherViewModelDelegate <NSObject> @required /** * Tells the delegate to configure a button view in a given page. * * @param launcherViewModel The launcher-view model requesting this configuration. * @param buttonView The button view that should be configured. * @param launcherView The launcher-view object that will displaly this button view. * @param pageIndex The index of the page where this button view will be displayed. * @param buttonIndex The index of the button in the page. * @param object The object that will likely be used to configure this button view. */ - (void)launcherViewModel:(NILauncherViewModel *)launcherViewModel configureButtonView:(UIView<NILauncherButtonView> *)buttonView forLauncherView:(NILauncherView *)launcherView pageIndex:(NSInteger)pageIndex buttonIndex:(NSInteger)buttonIndex object:(id<NILauncherViewObject>)object; @end /** * The minimal amount of information required to configure a button view. * * @ingroup NimbusLauncherModel */ @protocol NILauncherViewObject <NSObject> @required /** @name Accessing the Object Attributes */ /** * The title that will be displayed on the launcher view button. */ @property (nonatomic, copy) NSString* title; /** * The image that will be displayed on the launcher view button. */ @property (nonatomic, strong) UIImage* image; /** * The class of button view that should be used to display this object. * * This class must conform to the NILauncherButtonView protocol. */ - (Class)buttonViewClass; @end /** * A protocol that a launcher button view can implement to allow itself to be configured. * * @ingroup NimbusLauncherModel */ @protocol NILauncherViewObjectView <NSObject> @required /** @name Updating a Launcher Button View */ /** * Informs the receiver that a new object should be used to configure the view. */ - (void)shouldUpdateViewWithObject:(id)object; @end /** @name Creating Launcher View Models */ /** * Initializes a newly allocated launcher view model with an array of pages and a given delegate. * * This is the designated initializer. * * @param pages An array of arrays of objects that conform to the NILauncherViewObject protocol. * @param delegate An object that conforms to the NILauncherViewModelDelegate protocol. * @returns An initialized launcher view model. * @fn NILauncherViewModel::initWithArrayOfPages:delegate: */ /** @name Accessing Objects */ /** * Appends a page of launcher view objects. * * @param page An array of launcher view objects to add. * @fn NILauncherViewModel::appendPage: */ /** * Appends a launcher view object to a given page. * * @param object The object to add to the page. * @param pageIndex The index of the page to add this object to. * @fn NILauncherViewModel::appendObject:toPage: */ /** * Returns the object at the given index in the page at the given page index. * * Throws an assertion if the object index or page index are out of bounds. * * @param index The index within the page of the object to return. * @param pageIndex The index of the page to retrieve the object from. * @returns An object from a specific page. * @fn NILauncherViewModel::objectAtIndex:pageIndex: */ /** @name Managing the Delegate */ /** * The delegate for this launcher view model. */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherViewModel.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NILauncherViewModel.h" #import "NILauncherView.h" #import "NILauncherViewObject.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @interface NILauncherViewModel() @property (nonatomic, strong) NSMutableArray* pages; @end @implementation NILauncherViewModel - (id)initWithArrayOfPages:(NSArray *)pages delegate:(id<NILauncherViewModelDelegate>)delegate { if ((self = [super init])) { // Make the entire pages array mutable. NSMutableArray* mutablePages = [NSMutableArray arrayWithCapacity:pages.count]; for (NSArray* subArray in pages) { // You must add an array of arrays. NIDASSERT([subArray isKindOfClass:[NSArray class]]); [mutablePages addObject:[subArray mutableCopy]]; } self.pages = mutablePages; _delegate = delegate; } return self; } - (NSMutableArray *)_pageAtIndex:(NSInteger)pageIndex { NIDASSERT(self.pages.count > pageIndex && pageIndex >= 0); return [self.pages objectAtIndex:pageIndex]; } - (void)appendPage:(NSArray *)page { [self.pages addObject:[page mutableCopy]]; } - (void)appendObject:(id<NILauncherViewObject>)object toPage:(NSInteger)pageIndex { NSAssert(self.pages.count > pageIndex && pageIndex >= 0, @"Page index is out of bounds."); [[self _pageAtIndex:pageIndex] addObject:object]; } - (id<NILauncherViewObject>)objectAtIndex:(NSInteger)index pageIndex:(NSInteger)pageIndex { NSAssert(self.pages.count > pageIndex && pageIndex >= 0, @"Page index is out of bounds."); NSArray* objects = [self _pageAtIndex:pageIndex]; NSAssert(objects.count > index && index >= 0, @"Index is out of bounds."); return [objects objectAtIndex:index]; } #pragma mark NSCoding - (void)encodeWithCoder:(NSCoder *)coder { NSUInteger numberOfPages = self.pages.count; [coder encodeValueOfObjCType:@encode(NSUInteger) at:&numberOfPages]; for (NSArray* page in self.pages) { NSUInteger numberOfObjects = page.count; [coder encodeValueOfObjCType:@encode(NSUInteger) at:&numberOfObjects]; for (id object in page) { // The object must conform to NSCoding in order to be encoded. NIDASSERT([object conformsToProtocol:@protocol(NSCoding)]); [coder encodeObject:object]; } } } - (id)initWithCoder:(NSCoder *)decoder { if ((self = [super init])) { NSUInteger numberOfPages = 0; [decoder decodeValueOfObjCType:@encode(NSUInteger) at:&numberOfPages]; NSMutableArray* pages = [NSMutableArray arrayWithCapacity:numberOfPages]; for (NSUInteger ixPage = 0; ixPage < numberOfPages; ++ixPage) { NSUInteger numberOfObjects = 0; [decoder decodeValueOfObjCType:@encode(NSUInteger) at:&numberOfObjects]; NSMutableArray* objects = [NSMutableArray arrayWithCapacity:numberOfObjects]; for (NSUInteger ixObject = 0; ixObject < numberOfObjects; ++ixObject) { [objects addObject:[decoder decodeObject]]; } [pages addObject:objects]; } _pages = pages; } return self; } #pragma mark - NILauncherDataSource - (NSInteger)numberOfPagesInLauncherView:(NILauncherView *)launcherView { return self.pages.count; } - (NSInteger)launcherView:(NILauncherView *)launcherView numberOfButtonsInPage:(NSInteger)page { return [[self.pages objectAtIndex:page] count]; } - (UIView<NILauncherButtonView> *)launcherView:(NILauncherView *)launcherView buttonViewForPage:(NSInteger)page atIndex:(NSInteger)index { id<NILauncherViewObject> object = [self objectAtIndex:index pageIndex:page]; Class buttonViewClass = object.buttonViewClass; // You must provide a button view class. NIDASSERT(nil != buttonViewClass); NSString* reuseIdentifier = NSStringFromClass(buttonViewClass); UIView<NILauncherButtonView>* buttonView = [launcherView dequeueReusableViewWithIdentifier:reuseIdentifier]; if (nil == buttonView) { buttonView = [[buttonViewClass alloc] initWithReuseIdentifier:reuseIdentifier]; } // Give the button view a chance to update itself. if ([buttonView respondsToSelector:@selector(shouldUpdateViewWithObject:)]) { [buttonView performSelector:@selector(shouldUpdateViewWithObject:) withObject:object]; } // Give the delegate a chance to customize this button. [self.delegate launcherViewModel:self configureButtonView:buttonView forLauncherView:launcherView pageIndex:page buttonIndex:index object:object]; return buttonView; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherViewObject.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NILauncherViewModel.h" /** * An implementation of the NILauncherViewObject protocol. * * @ingroup NimbusLauncherModel */ @interface NILauncherViewObject : NSObject <NILauncherViewObject, NSCoding> // Designated initializer. - (id)initWithTitle:(NSString *)title image:(UIImage *)image; + (id)objectWithTitle:(NSString *)title image:(UIImage *)image; @end /** * Initializes a newly allocated launcher view object with a given title and image. * * This is the designated initializer. * * @fn NILauncherViewObject::initWithTitle:image: */ /** * Allocates and returns an autoreleased instance of a launcher view object. * * @fn NILauncherViewObject::objectWithTitle:image: */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NILauncherViewObject.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NILauncherViewObject.h" #import "NILauncherButtonView.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static NSString* const kTitleCodingKey = @"title"; static NSString* const kImageCodingKey = @"image"; @implementation NILauncherViewObject @synthesize title = _title; @synthesize image = _image; - (id)initWithTitle:(NSString *)title image:(UIImage *)image { if ((self = [super init])) { _title = title; _image = image; } return self; } + (id)objectWithTitle:(NSString *)title image:(UIImage *)image { return [[self alloc] initWithTitle:title image:image]; } - (Class)buttonViewClass { return [NILauncherButtonView class]; } #pragma mark NSCoding - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:self.title forKey:kTitleCodingKey]; [coder encodeObject:self.image forKey:kImageCodingKey]; } - (id)initWithCoder:(NSCoder *)decoder { if ((self = [super init])) { _title = [decoder decodeObjectForKey:kTitleCodingKey]; _image = [decoder decodeObjectForKey:kImageCodingKey]; } return self; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/launcher/src/NimbusLauncher.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @defgroup NimbusLauncher Nimbus Launcher * @{ * * <div id="github" feature="launcher"></div> * * A launcher view is best exemplified in Apple's home screen interface. It consists of a set * of pages that each contain a set of buttons that the user may tap to access a consistent, * focused aspect of the application or operating system. The user may swipe the screen to the * left or right or tap the pager control at the bottom of the screen to change pages. * * @image html NILauncherViewControllerExample1.png "Example of an NILauncherViewController as seen in the BasicLauncher demo application." * * <h2>Minimum Requirements</h2> * * Required frameworks: * * - Foundation.framework * - UIKit.framework * * Minimum Operating System: <b>iOS 4.0</b> * * Source located in <code>src/launcher/src</code> */ /** * @defgroup NimbusLauncherModel Nimbus Launcher Model * * The Nimbus Launcher provides a model object that can store all of the launcher data. This model * object works similarly to NITableViewModel. * * Presented below is an example of subclassing a NILauncherViewController and using a * NILauncherViewModel to supply the data source information. * @code @implementation CustomLauncherViewController() @property (nonatomic, retain) NILauncherViewModel* model; @end @interface CustomLauncherViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { NSArray* contents = [NSArray arrayWithObjects: [NSArray arrayWithObjects: [NILauncherViewObject objectWithTitle:@"Nimbus" image:image], [NILauncherViewObject objectWithTitle:@"Nimbus 2" image:image], [NILauncherViewObject objectWithTitle:@"Nimbus 3" image:image], [NILauncherViewObject objectWithTitle:@"Nimbus 5" image:image], [NILauncherViewObject objectWithTitle:@"Nimbus 6" image:image], nil], [NSArray arrayWithObjects: [NILauncherViewObject objectWithTitle:@"Page 2" image:image], nil], [NSArray arrayWithObjects: [NILauncherViewObject objectWithTitle:@"Page 3" image:image], nil], nil]; _model = [[NILauncherViewModel alloc] initWithArrayOfPages:contents delegate:nil]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.launcherView.dataSource = self.model; } @end @endcode */ #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> // Dependencies #import "NimbusCore.h" #import "NimbusPagingScrollView.h" #import "NILauncherButtonView.h" #import "NILauncherViewModel.h" #import "NILauncherViewObject.h" #import "NILauncherViewController.h" #import "NILauncherView.h" /**@}*/
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/models/src/NICellBackgrounds.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NIPreprocessorMacros.h" /* for weak */ /** * The NIGroupedCellAppearance protocol provides support for each cell to adjust their appearance. * * @ingroup TableCellBackgrounds */ @protocol NIGroupedCellAppearance <NSObject> @optional /** * Determines whether or not to draw a divider between cells. * * If the cell does not implement this method, a cell divider will be provided. */ - (BOOL)drawsCellDivider; @end // Flags set on the cell's backgroundView's tag property. typedef enum { NIGroupedCellBackgroundFlagIsLast = (1 << 0), NIGroupedCellBackgroundFlagIsFirst = (1 << 1), NIGroupedCellBackgroundFlagInitialized = (1 << 2), NIGroupedCellBackgroundFlagNoDivider = (1 << 3), } NIGroupedCellBackgroundFlag; /** * The NIGroupedCellBackground class provides support for generating grouped UITableView cell * backgrounds. * * @ingroup TableCellBackgrounds */ @interface NIGroupedCellBackground : NSObject - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath; - (UIImage *)imageForFirst:(BOOL)first last:(BOOL)last highlighted:(BOOL)highlighted; // Default: drawDivider: True - (UIImage *)imageForFirst:(BOOL)first last:(BOOL)last highlighted:(BOOL)highlighted drawDivider:(BOOL)drawDivider; @property (nonatomic, strong) UIColor* innerBackgroundColor; // Default: [UIColor whiteColor] @property (nonatomic, strong) NSMutableArray* highlightedInnerGradientColors; // Default: RGBCOLOR(53, 141, 245), RGBCOLOR(16, 93, 230) @property (nonatomic, assign) CGFloat shadowWidth; // Default: 4 @property (nonatomic, assign) CGSize shadowOffset; // Default: CGSizeMake(0, 1) @property (nonatomic, strong) UIColor* shadowColor; // Default: RGBACOLOR(0, 0, 0, 0.3) @property (nonatomic, strong) UIColor* borderColor; // Default: RGBACOLOR(0, 0, 0, 0.07) @property (nonatomic, strong) UIColor* dividerColor; // Default: RGBCOLOR(230, 230, 230) @property (nonatomic, assign) CGFloat borderRadius; // Default: 5 @end /** * Returns an image for use with the given cell configuration. * * The returned image is cached internally after the first request. Changing any of the display * properties will invalidate the cached images. * * @param first YES will round the top corners. * @param last YES will round the bottom corners. * @param highlighed YES will fill the contents with the highlightedInnerGradientColors. * @returns A UIImage representing the given configuration. * @fn NIGroupedCellBackground::imageForFirst:last:highlighted: */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/models/src/NICellBackgrounds.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NICellBackgrounds.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif static const CGFloat kBorderSize = 1; static const CGSize kCellImageSize = {44, 44}; @interface NIGroupedCellBackground() @property (nonatomic, strong) NSMutableDictionary* cachedImages; @end @implementation NIGroupedCellBackground - (id)init { if ((self = [super init])) { _innerBackgroundColor = [UIColor whiteColor]; _highlightedInnerGradientColors = [NSMutableArray arrayWithObjects: (id)RGBCOLOR(53, 141, 245).CGColor, (id)RGBCOLOR(16, 93, 230).CGColor, nil]; _shadowWidth = 4; _shadowOffset = CGSizeMake(0, 1); _shadowColor = RGBACOLOR(0, 0, 0, 0.3f); _borderColor = RGBACOLOR(0, 0, 0, 0.07f); _dividerColor = RGBCOLOR(230, 230, 230); _borderRadius = 5; _cachedImages = [NSMutableDictionary dictionary]; } return self; } // We want to draw the borders and shadows on single retina-pixel boundaries if possible, but // we need to avoid doing this on non-retina devices because it'll look blurry. + (CGFloat)minPixelOffset { if (NIIsRetina()) { return 0.5f; } else { return 1.f; } } - (void)_applySinglePathToContext:(CGContextRef)c rect:(CGRect)rect { CGFloat minPixelOffset = [[self class] minPixelOffset]; CGFloat minx = CGRectGetMinX(rect) + minPixelOffset; CGFloat midx = CGRectGetMidX(rect) + minPixelOffset; CGFloat maxx = CGRectGetMaxX(rect) - minPixelOffset; CGFloat miny = CGRectGetMinY(rect) - minPixelOffset; CGFloat midy = CGRectGetMidY(rect) - minPixelOffset; CGFloat maxy = CGRectGetMaxY(rect) + minPixelOffset; CGContextBeginPath(c); CGContextMoveToPoint(c, minx, midy); CGContextAddArcToPoint(c, minx, miny + 1, midx, miny + 1, self.borderRadius); CGContextAddArcToPoint(c, maxx, miny + 1, maxx, midy, self.borderRadius); CGContextAddLineToPoint(c, maxx, midy); CGContextAddArcToPoint(c, maxx, maxy - 1, midx, maxy - 1, self.borderRadius); CGContextAddArcToPoint(c, minx, maxy - 1, minx, midy, self.borderRadius); CGContextAddLineToPoint(c, minx, midy); CGContextClosePath(c); } - (void)_applyTopPathToContext:(CGContextRef)c rect:(CGRect)rect { CGFloat minPixelOffset = [[self class] minPixelOffset]; CGFloat minx = CGRectGetMinX(rect) + minPixelOffset; CGFloat midx = CGRectGetMidX(rect) + minPixelOffset; CGFloat maxx = CGRectGetMaxX(rect) - minPixelOffset; CGFloat miny = CGRectGetMinY(rect) - minPixelOffset; CGFloat midy = CGRectGetMidY(rect) - minPixelOffset; CGFloat maxy = CGRectGetMaxY(rect) + minPixelOffset; CGContextBeginPath(c); CGContextMoveToPoint(c, minx, maxy); CGContextAddLineToPoint(c, minx, midy); CGContextAddArcToPoint(c, minx, miny + 1, midx, miny + 1, self.borderRadius); CGContextAddArcToPoint(c, maxx, miny + 1, maxx, midy, self.borderRadius); CGContextAddLineToPoint(c, maxx, maxy); CGContextClosePath(c); } - (void)_applyBottomPathToContext:(CGContextRef)c rect:(CGRect)rect { CGFloat minPixelOffset = [[self class] minPixelOffset]; CGFloat minx = CGRectGetMinX(rect) + minPixelOffset; CGFloat midx = CGRectGetMidX(rect) + minPixelOffset; CGFloat maxx = CGRectGetMaxX(rect) - minPixelOffset; CGFloat miny = CGRectGetMinY(rect) - minPixelOffset; CGFloat midy = CGRectGetMidY(rect) - minPixelOffset; CGFloat maxy = CGRectGetMaxY(rect) + minPixelOffset; CGContextBeginPath(c); CGContextMoveToPoint(c, maxx, miny); CGContextAddLineToPoint(c, maxx, midy); CGContextAddArcToPoint(c, maxx, maxy - 1, midx, maxy - 1, self.borderRadius); CGContextAddArcToPoint(c, minx, maxy - 1, minx, midy, self.borderRadius); CGContextAddLineToPoint(c, minx, miny); CGContextClosePath(c); } - (void)_applyDividerPathToContext:(CGContextRef)c rect:(CGRect)rect { CGFloat minPixelOffset = [[self class] minPixelOffset]; CGFloat minx = CGRectGetMinX(rect) + minPixelOffset; CGFloat maxx = CGRectGetMaxX(rect) - minPixelOffset; CGFloat maxy = CGRectGetMaxY(rect) + minPixelOffset; CGContextBeginPath(c); CGContextMoveToPoint(c, minx, maxy); CGContextAddLineToPoint(c, maxx, maxy); CGContextClosePath(c); } - (void)_applyLeftPathToContext:(CGContextRef)c rect:(CGRect)rect { CGFloat minPixelOffset = [[self class] minPixelOffset]; CGFloat minx = CGRectGetMinX(rect) + minPixelOffset; CGFloat miny = CGRectGetMinY(rect) - minPixelOffset; CGFloat maxy = CGRectGetMaxY(rect) + minPixelOffset; CGContextBeginPath(c); CGContextMoveToPoint(c, minx, miny); CGContextAddLineToPoint(c, minx, maxy); CGContextClosePath(c); } - (void)_applyRightPathToContext:(CGContextRef)c rect:(CGRect)rect { CGFloat minPixelOffset = [[self class] minPixelOffset]; CGFloat maxx = CGRectGetMaxX(rect) - minPixelOffset; CGFloat miny = CGRectGetMinY(rect) - minPixelOffset; CGFloat maxy = CGRectGetMaxY(rect) + minPixelOffset; CGContextBeginPath(c); CGContextMoveToPoint(c, maxx, miny); CGContextAddLineToPoint(c, maxx, maxy); CGContextClosePath(c); } - (void)_applyPathToContext:(CGContextRef)c rect:(CGRect)rect isFirst:(BOOL)isFirst isLast:(BOOL)isLast { CGFloat minPixelOffset = [[self class] minPixelOffset]; CGFloat minx = CGRectGetMinX(rect) + minPixelOffset; CGFloat midx = CGRectGetMidX(rect) + minPixelOffset; CGFloat maxx = CGRectGetMaxX(rect) - minPixelOffset; CGFloat miny = CGRectGetMinY(rect) - minPixelOffset; CGFloat midy = CGRectGetMidY(rect) - minPixelOffset; CGFloat maxy = CGRectGetMaxY(rect) + minPixelOffset; CGContextBeginPath(c); // // x-> | // CGContextMoveToPoint(c, minx, midy); if (isFirst) { // arc // >/ // | // CGContextAddArcToPoint(c, minx, miny + 1, midx, miny + 1, self.borderRadius); // ______ line and then arc // / \ < // | // CGContextAddArcToPoint(c, maxx, miny + 1, maxx, midy, self.borderRadius); } else { // line // >| // | // CGContextAddLineToPoint(c, minx, miny); // ______ <- line to here // | // | // CGContextAddLineToPoint(c, maxx, miny); } // isSolid? // vv // ______ // | | - // | | -\< right edge line // CGContextAddLineToPoint(c, maxx, midy); if (isLast) { CGContextAddArcToPoint(c, maxx, maxy - 1, midx, maxy - 1, self.borderRadius); CGContextAddArcToPoint(c, minx, maxy - 1, minx, midy, self.borderRadius); } else { // | | // | | // -------- <- line to here // CGContextAddLineToPoint(c, maxx, maxy); // | | // | | // -------- // ^ then to here CGContextAddLineToPoint(c, minx, maxy); } // x-> | | // | | // -------- CGContextAddLineToPoint(c, minx, midy); CGContextClosePath(c); } - (UIImage *)_imageForHighlight { CGRect imageRect = CGRectMake(0, 0, 1, kCellImageSize.height); UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, 0); CGContextRef cx = UIGraphicsGetCurrentContext(); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)self.highlightedInnerGradientColors, nil); CGColorSpaceRelease(colorSpace); colorSpace = nil; CGContextDrawLinearGradient(cx, gradient, CGPointZero, CGPointMake(imageRect.size.width, imageRect.size.height), 0); CGGradientRelease(gradient); gradient = nil; UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } - (UIImage *)_imageForFirst:(BOOL)first last:(BOOL)last highlighted:(BOOL)highlighted drawDivider:(BOOL)drawDivider { CGRect imageRect = CGRectMake(0, 0, kCellImageSize.width, kCellImageSize.height); UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, 0); CGContextRef cx = UIGraphicsGetCurrentContext(); // Create a transparent background. CGContextClearRect(cx, imageRect); if (highlighted) { CGContextSetFillColorWithColor(cx, [UIColor colorWithPatternImage:self._imageForHighlight].CGColor); } else { CGContextSetFillColorWithColor(cx, self.innerBackgroundColor.CGColor); } CGRect contentFrame = CGRectInset(imageRect, self.shadowWidth, 0); if (first) { contentFrame = NIRectShift(contentFrame, 0, self.shadowWidth); } if (last) { contentFrame = NIRectContract(contentFrame, 0, self.shadowWidth); } if (self.shadowWidth > 0 && !highlighted) { // Draw the shadow CGContextSaveGState(cx); CGRect shadowFrame = contentFrame; // We want the shadow to clip to the top and bottom edges of the image so that when two cells // are next to each other their shadows line up perfectly. if (!first) { shadowFrame = NIRectShift(shadowFrame, 0, -self.borderRadius); } if (!last) { shadowFrame = NIRectContract(shadowFrame, 0, -self.borderRadius); } [self _applyPathToContext:cx rect:shadowFrame isFirst:first isLast:last]; CGContextSetShadowWithColor(cx, self.shadowOffset, self.shadowWidth, self.shadowColor.CGColor); CGContextDrawPath(cx, kCGPathFill); CGContextRestoreGState(cx); } CGContextSaveGState(cx); [self _applyPathToContext:cx rect:contentFrame isFirst:first isLast:last]; CGContextFillPath(cx); CGContextRestoreGState(cx); // We want the cell border to overlap the shadow and the content. CGFloat minPixelOffset = [[self class] minPixelOffset]; CGRect borderFrame = CGRectInset(contentFrame, -minPixelOffset, -minPixelOffset); if (!highlighted) { // Draw the cell border. CGContextSaveGState(cx); CGContextSetLineWidth(cx, kBorderSize); CGContextSetStrokeColorWithColor(cx, self.borderColor.CGColor); if (first && last) { [self _applySinglePathToContext:cx rect:borderFrame]; CGContextStrokePath(cx); } else if (first) { [self _applyTopPathToContext:cx rect:borderFrame]; CGContextStrokePath(cx); } else if (last) { [self _applyBottomPathToContext:cx rect:borderFrame]; CGContextStrokePath(cx); } else { [self _applyLeftPathToContext:cx rect:borderFrame]; CGContextStrokePath(cx); [self _applyRightPathToContext:cx rect:borderFrame]; CGContextStrokePath(cx); } CGContextRestoreGState(cx); } // Draw the cell divider. if (!last && drawDivider) { CGContextSaveGState(cx); CGContextSetLineWidth(cx, kBorderSize); CGContextSetStrokeColorWithColor(cx, self.dividerColor.CGColor); [self _applyDividerPathToContext:cx rect:NIRectContract(contentFrame, 0, 1)]; CGContextStrokePath(cx); CGContextRestoreGState(cx); } UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); CGFloat capWidth = NICGFloatFloor(image.size.width / 2); CGFloat capHeight = NICGFloatFloor(image.size.height / 2); return [image resizableImageWithCapInsets:UIEdgeInsetsMake(capHeight, capWidth, capHeight, capWidth)]; } - (id)_cacheKeyForFirst:(BOOL)first last:(BOOL)last highlighted:(BOOL)highlighted drawDivider:(BOOL)drawDivider { NSInteger flags = ((first ? 0x01 : 0) | (last ? 0x02 : 0) | (highlighted ? 0x04 : 0) | (drawDivider ? 0x08 : 0)); return [NSNumber numberWithInteger:flags]; } - (void)_invalidateCache { [self.cachedImages removeAllObjects]; } #pragma mark - Public - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger numberOfRowsInSection = [tableView.dataSource tableView:tableView numberOfRowsInSection:indexPath.section]; BOOL isFirst = (0 == indexPath.row); BOOL isLast = (indexPath.row == numberOfRowsInSection - 1); BOOL drawDivider = YES; if ([cell conformsToProtocol:@protocol(NIGroupedCellAppearance)] && [cell respondsToSelector:@selector(drawsCellDivider)]) { id<NIGroupedCellAppearance> groupedCell = (id<NIGroupedCellAppearance>)cell; drawDivider = [groupedCell drawsCellDivider]; } NSInteger backgroundTag = ((isFirst ? NIGroupedCellBackgroundFlagIsFirst : 0) | (isLast ? NIGroupedCellBackgroundFlagIsLast : 0) | NIGroupedCellBackgroundFlagInitialized | (drawDivider ? 0 : NIGroupedCellBackgroundFlagNoDivider)); if (cell.backgroundView.tag != backgroundTag) { cell.backgroundView = [[UIImageView alloc] initWithImage:[self imageForFirst:isFirst last:isLast highlighted:NO drawDivider:drawDivider]]; cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[self imageForFirst:isFirst last:isLast highlighted:YES drawDivider:drawDivider]]; cell.backgroundView.tag = backgroundTag; } } - (UIImage *)imageForFirst:(BOOL)first last:(BOOL)last highlighted:(BOOL)highlighted { return [self imageForFirst:first last:last highlighted:highlighted drawDivider:YES]; } - (UIImage *)imageForFirst:(BOOL)first last:(BOOL)last highlighted:(BOOL)highlighted drawDivider:(BOOL)drawDivider { id cacheKey = [self _cacheKeyForFirst:first last:last highlighted:highlighted drawDivider:drawDivider]; UIImage* image = [self.cachedImages objectForKey:cacheKey]; if (nil == image) { image = [self _imageForFirst:first last:last highlighted:highlighted drawDivider:drawDivider]; [self.cachedImages setObject:image forKey:cacheKey]; } return image; } - (void)setInnerBackgroundColor:(UIColor *)innerBackgroundColor { if (_innerBackgroundColor != innerBackgroundColor) { _innerBackgroundColor = innerBackgroundColor; [self _invalidateCache]; } } - (void)setHighlightedInnerGradientColors:(NSMutableArray *)highlightedInnerGradientColors { if (_highlightedInnerGradientColors != highlightedInnerGradientColors) { _highlightedInnerGradientColors = highlightedInnerGradientColors; [self _invalidateCache]; } } - (void)setShadowWidth:(CGFloat)shadowWidth { if (_shadowWidth != shadowWidth) { _shadowWidth = shadowWidth; [self _invalidateCache]; } } - (void)setShadowColor:(UIColor *)shadowColor { if (_shadowColor != shadowColor) { _shadowColor = shadowColor; [self _invalidateCache]; } } - (void)setBorderColor:(UIColor *)borderColor { if (_borderColor != borderColor) { _borderColor = borderColor; [self _invalidateCache]; } } - (void)setDividerColor:(UIColor *)dividerColor { if (_dividerColor != dividerColor) { _dividerColor = dividerColor; [self _invalidateCache]; } } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/models/src/NICellCatalog.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NICellFactory.h" typedef CGFloat (^NICellDrawRectBlock)(CGRect rect, id object, UITableViewCell* cell); /** * An object that will draw the contents of the cell using a provided block. * * @ingroup TableCellCatalog */ @interface NIDrawRectBlockCellObject : NICellObject // Designated initializer. - (id)initWithBlock:(NICellDrawRectBlock)block object:(id)object; + (id)objectWithBlock:(NICellDrawRectBlock)block object:(id)object; @property (nonatomic, copy) NICellDrawRectBlock block; @property (nonatomic, strong) id object; @end /** * An object for displaying a single-line title in a table view cell. * * This object maps by default to a NITextCell and displays the title with a * UITableViewCellStyleDefault cell. You can customize the cell class using the * NICellObject methods. * * @ingroup TableCellCatalog */ @interface NITitleCellObject : NICellObject // Designated initializer. - (id)initWithTitle:(NSString *)title image:(UIImage *)image cellClass:(Class)cellClass userInfo:(id)userInfo; - (id)initWithTitle:(NSString *)title image:(UIImage *)image; - (id)initWithTitle:(NSString *)title; + (id)objectWithTitle:(NSString *)title image:(UIImage *)image; + (id)objectWithTitle:(NSString *)title; @property (nonatomic, copy) NSString* title; @property (nonatomic, strong) UIImage* image; @end /** * An object for displaying two lines of text in a table view cell. * * This object maps by default to a NITextCell and displays the title with a * UITableViewCellStyleSubtitle cell. You can customize the cell class using the * NICellObject methods. * * @ingroup TableCellCatalog */ @interface NISubtitleCellObject : NITitleCellObject // Designated initializer. - (id)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image cellClass:(Class)cellClass userInfo:(id)userInfo; - (id)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image; + (id)objectWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image; - (id)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle; + (id)objectWithTitle:(NSString *)title subtitle:(NSString *)subtitle; @property (nonatomic, copy) NSString* subtitle; @property (nonatomic, assign) UITableViewCellStyle cellStyle; @end /** * A general-purpose cell for displaying text. * * When given a NITitleCellObject, will set the textLabel's text with the title. * When given a NISubtitleCellObject, will also set the detailTextLabel's text with the subtitle. * * @ingroup TableCellCatalog */ @interface NITextCell : UITableViewCell <NICell> @end /** * A cell that renders its contents using a block. * * @ingroup TableCellCatalog */ @interface NIDrawRectBlockCell : UITableViewCell <NICell> @property (nonatomic, strong) UIView* blockView; @end /** * Initializes the NITitleCellObject with the given title, image, cellClass, and userInfo. * * This is the designated initializer. Use of this initializer allows for customization of the * associated cell class for this object. * * @fn NITitleCellObject::initWithTitle:image:cellClass:userInfo: */ /** * Initializes the NITitleCellObject with NITextCell as the cell class and the given title text and * image. * * @fn NITitleCellObject::initWithTitle:image: */ /** * Initializes the NITitleCellObject with NITextCell as the cell class and the given title text. * * @fn NITitleCellObject::initWithTitle: */ /** * Convenience method for initWithTitle:image:. * * @fn NITitleCellObject::objectWithTitle:image: * @returns Autoreleased instance of NITitleCellObject. */ /** * Convenience method for initWithTitle:. * * @fn NITitleCellObject::objectWithTitle: * @returns Autoreleased instance of NITitleCellObject. */ /** * The text to be displayed in the cell. * * @fn NITitleCellObject::title */ /** * Initializes the NISubtitleCellObject with the given title, subtitle, image, cellClass, and * userInfo. * * This is the designated initializer. Use of this initializer allows for customization of the * associated cell class for this object. * * @fn NISubtitleCellObject::initWithTitle:subtitle:image:cellClass:userInfo: */ /** * Initializes the NICellObject with NITextCell as the cell class and the given title and subtitle * text. * * @fn NISubtitleCellObject::initWithTitle:subtitle: */ /** * Convenience method for initWithTitle:subtitle:. * * @fn NISubtitleCellObject::objectWithTitle:subtitle: * @returns Autoreleased instance of NISubtitleCellObject. */ /** * The text to be displayed in the subtitle portion of the cell. * * @fn NISubtitleCellObject::subtitle */ /** * The type of UITableViewCell to instantiate. * * By default this is UITableViewCellStyleSubtitle. * * @fn NISubtitleCellObject::cellStyle */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/models/src/NICellCatalog.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NICellCatalog.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @implementation NIDrawRectBlockCellObject - (id)initWithBlock:(NICellDrawRectBlock)block object:(id)object { if ((self = [super initWithCellClass:[NIDrawRectBlockCell class]])) { _block = block; _object = object; } return self; } + (id)objectWithBlock:(NICellDrawRectBlock)block object:(id)object { return [[self alloc] initWithBlock:block object:object]; } @end @implementation NITitleCellObject - (id)initWithTitle:(NSString *)title image:(UIImage *)image cellClass:(Class)cellClass userInfo:(id)userInfo { if ((self = [super initWithCellClass:cellClass userInfo:userInfo])) { _title = [title copy]; _image = image; } return self; } - (id)initWithCellClass:(Class)cellClass userInfo:(id)userInfo { return [self initWithTitle:nil image:nil cellClass:cellClass userInfo:userInfo]; } - (id)initWithTitle:(NSString *)title image:(UIImage *)image { return [self initWithTitle:title image:image cellClass:[NITextCell class] userInfo:nil]; } - (id)initWithTitle:(NSString *)title { return [self initWithTitle:title image:nil cellClass:[NITextCell class] userInfo:nil]; } - (id)init { return [self initWithTitle:nil image:nil cellClass:[NITextCell class] userInfo:nil]; } + (id)objectWithTitle:(NSString *)title image:(UIImage *)image { return [[self alloc] initWithTitle:title image:image]; } + (id)objectWithTitle:(NSString *)title { return [[self alloc] initWithTitle:title image:nil]; } @end @implementation NISubtitleCellObject - (id)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image cellClass:(Class)cellClass userInfo:(id)userInfo { if ((self = [super initWithTitle:title image:image cellClass:cellClass userInfo:userInfo])) { _subtitle = [subtitle copy]; _cellStyle = UITableViewCellStyleSubtitle; } return self; } - (id)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image { return [self initWithTitle:title subtitle:subtitle image:image cellClass:[NITextCell class] userInfo:nil]; } - (id)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle { return [self initWithTitle:title subtitle:subtitle image:nil cellClass:[NITextCell class] userInfo:nil]; } - (id)initWithTitle:(NSString *)title image:(UIImage *)image { return [self initWithTitle:title subtitle:nil image:image cellClass:[NITextCell class] userInfo:nil]; } - (id)init { return [self initWithTitle:nil subtitle:nil image:nil cellClass:[NITextCell class] userInfo:nil]; } + (id)objectWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image { return [[self alloc] initWithTitle:title subtitle:subtitle image:image]; } + (id)objectWithTitle:(NSString *)title subtitle:(NSString *)subtitle { return [[self alloc] initWithTitle:title subtitle:subtitle image:nil]; } @end @implementation NITextCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { self.selectionStyle = UITableViewCellSelectionStyleNone; } return self; } - (void)prepareForReuse { [super prepareForReuse]; self.imageView.image = nil; self.textLabel.text = nil; self.detailTextLabel.text = nil; } - (BOOL)shouldUpdateCellWithObject:(id)object { if ([object isKindOfClass:[NITitleCellObject class]]) { NITitleCellObject* titleObject = object; self.textLabel.text = titleObject.title; self.imageView.image = titleObject.image; } if ([object isKindOfClass:[NISubtitleCellObject class]]) { NISubtitleCellObject* subtitleObject = object; self.detailTextLabel.text = subtitleObject.subtitle; } return YES; } @end @interface NIDrawRectBlockView : UIView @property (nonatomic, copy) NICellDrawRectBlock block; @property (nonatomic, strong) id object; @property (nonatomic, assign) UITableViewCell* cell; @end @implementation NIDrawRectBlockView - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { self.backgroundColor = [UIColor clearColor]; } return self; } - (void)drawRect:(CGRect)rect { if (nil != self.block) { self.block(rect, self.object, self.cell); } } @end @implementation NIDrawRectBlockCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier])) { self.selectionStyle = UITableViewCellSelectionStyleNone; _blockView = [[NIDrawRectBlockView alloc] initWithFrame:self.contentView.bounds]; _blockView.autoresizingMask = UIViewAutoresizingFlexibleDimensions; _blockView.contentMode = UIViewContentModeRedraw; [self.contentView addSubview:_blockView]; [self.textLabel removeFromSuperview]; [self.imageView removeFromSuperview]; [self.detailTextLabel removeFromSuperview]; } return self; } - (BOOL)shouldUpdateCellWithObject:(NIDrawRectBlockCellObject *)object { NIDrawRectBlockView* blockView = (NIDrawRectBlockView *)self.blockView; blockView.block = object.block; blockView.object = object.object; blockView.cell = self; [blockView setNeedsDisplay]; return YES; } + (CGFloat)heightForObject:(NIDrawRectBlockCellObject *)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView { return object.block(tableView.bounds, object.object, nil); } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/models/src/NICellFactory.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "NITableViewModel.h" /** * A simple factory for creating table view cells from objects. * * This factory provides a single method that accepts an object and returns a UITableViewCell * for use in a UITableView. A cell will only be returned if the object passed to the factory * conforms to the NICellObject protocol. The created cell should ideally conform to * the NICell protocol. If it does, the object will be passed to it via * @link NICell::shouldUpdateCellWithObject: shouldUpdateCellWithObject:@endlink before the * factory method returns. * * This factory is designed to be used with NITableViewModels, though one could easily use * it with other table view data source implementations simply by providing nil for the table * view model. * * If you instantiate an NICellFactory then you can provide explicit mappings from objects * to cells. This is helpful if the effort required to implement the NICell protocol on * an object outweighs the benefit of using the factory, i.e. when you want to map * simple types such as NSString to cells. * * @ingroup TableCellFactory */ @interface NICellFactory : NSObject <NITableViewModelDelegate> /** * Creates a cell from a given object if and only if the object conforms to the NICellObject * protocol. * * This method signature matches the NITableViewModelDelegate method so that you can * set this factory as the model's delegate: * * @code // Must cast to id to avoid compiler warnings. _model.delegate = (id)[NICellFactory class]; * @endcode * * If you would like to customize the factory's output, implement the model's delegate method * and call the factory method. Remember that if the factory doesn't know how to map * the object to a cell it will return nil. * * @code - (UITableViewCell *)tableViewModel:(NITableViewModel *)tableViewModel cellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { UITableViewCell* cell = [NICellFactory tableViewModel:tableViewModel cellForTableView:tableView atIndexPath:indexPath withObject:object]; if (nil == cell) { // Custom cell creation here. } return cell; } * @endcode */ + (UITableViewCell *)tableViewModel:(NITableViewModel *)tableViewModel cellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath withObject:(id)object; /** * Map an object's class to a cell's class. * * If an object implements the NICell protocol AND is found in this factory * mapping, the factory mapping will take precedence. This allows you to * explicitly override the mapping on a case-by-case basis. */ - (void)mapObjectClass:(Class)objectClass toCellClass:(Class)cellClass; /** * Returns the height for a row at a given index path. * * Uses the heightForObject:atIndexPath:tableView: selector from the NICell protocol to ask the * object at indexPath in the model what its height should be. If a class mapping has been made for * the given object in this factory then that class mapping will be used over the result of * cellClass from the NICellObject protocol. * * If the cell returns a height of zero then tableView.rowHeight will be used. * * Example implementation: * @code - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [self.cellFactory tableView:tableView heightForRowAtIndexPath:indexPath model:self.model]; } @endcode * * @param tableView The table view within which the cell exists. * @param indexPath The location of the cell in the table view. * @param model The backing model being used by the table view. * @returns The height of the cell mapped to the object at indexPath, if it implements * heightForObject:atIndexPath:tableView:; otherwise, returns tableView.rowHeight. */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath model:(NITableViewModel *)model; /** * Returns the height for a row at a given index path. * * Uses the heightForObject:atIndexPath:tableView: selector from the NICell protocol to ask the * object at indexPath in the model what its height should be. Only implicit mappings will be * checked with this static implementation. If you would like to provide explicit mappings you must * create an instance of NICellFactory. * * If the cell returns a height of zero then tableView.rowHeight will be used. * * Example implementation: * @code - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [NICellFactory tableView:tableView heightForRowAtIndexPath:indexPath model:self.model]; } @endcode * * @param tableView The table view within which the cell exists. * @param indexPath The location of the cell in the table view. * @param model The backing model being used by the table view. * @returns The height of the cell mapped to the object at indexPath, if it implements * heightForObject:atIndexPath:tableView:; otherwise, returns tableView.rowHeight. */ + (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath model:(NITableViewModel *)model; @end /** * The protocol for an object that can be used in the NICellFactory. * * @ingroup TableCellFactory */ @protocol NICellObject <NSObject> @required /** The class of cell to be created when this object is passed to the cell factory. */ - (Class)cellClass; @optional /** The style of UITableViewCell to be used when initializing the cell for the first time. */ - (UITableViewCellStyle)cellStyle; @end /** * The protocol for an object that can be used in the NICellFactory with Interface Builder nibs. * * @ingroup TableCellFactory */ @protocol NINibCellObject <NSObject> @required /** A nib that contains a table view cell to display this object's contents. */ - (UINib *)cellNib; @end /** * The protocol for a cell created in the NICellFactory. * * Cells that implement this protocol are given the object that implemented the NICellObject * protocol and returned this cell's class name in @link NICellObject::cellClass cellClass@endlink. * * @ingroup TableCellFactory */ @protocol NICell <NSObject> @required /** * Called when a cell is created and reused. * * Implement this method to customize the cell's properties for display using the given object. */ - (BOOL)shouldUpdateCellWithObject:(id)object; @optional /** * Asks the receiver whether the mapped object class should be appended to the reuse identifier * in order to create a unique cell.object identifier key. * * This is useful when you have a cell that is intended to be used by a variety of different * objects. */ + (BOOL)shouldAppendObjectClassToReuseIdentifier; /** * Asks the receiver to calculate its height. * * The following is an appropiate implementation in your tableView's delegate: * @code -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGFloat height = tableView.rowHeight; id object = [(NITableViewModel *)tableView.dataSource objectAtIndexPath:indexPath]; id class = [object cellClass]; if ([class respondsToSelector:@selector(heightForObject:atIndexPath:tableView:)]) { height = [class heightForObject:object atIndexPath:indexPath tableView:tableView]; } return height; } @endcode * * You may also use the * @link NICellFactory::tableView:heightForRowAtIndexPath:model: tableView:heightForRowAtIndexPath:model:@endlink * methods on NICellFactory to achieve the same result. Using the above example allows you to * customize the logic according to your specific needs. */ + (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView; @end /** * A light-weight implementation of the NICellObject protocol. * * Use this object in cases where you can't set up a hard binding between an object and a cell, * or when you simply don't want to. * * For example, let's say that you want to show a cell that shows a loading indicator. * Rather than create a new interface, LoadMoreObject, simply for the cell and binding it * to the cell view, you can create an NICellObject and pass the class name of the cell. * @code [tableContents addObject:[NICellObject objectWithCellClass:[LoadMoreCell class]]]; @endcode */ @interface NICellObject : NSObject <NICellObject> // Designated initializer. - (id)initWithCellClass:(Class)cellClass userInfo:(id)userInfo; - (id)initWithCellClass:(Class)cellClass; + (id)objectWithCellClass:(Class)cellClass userInfo:(id)userInfo; + (id)objectWithCellClass:(Class)cellClass; @property (nonatomic, strong) id userInfo; @end /** * An object that can be used to populate information in the cell. * * @fn NICellObject::userInfo */
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/models/src/NICellFactory.m
Objective-C
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NICellFactory.h" #import "NimbusCore.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "Nimbus requires ARC support." #endif @interface NICellFactory() @property (nonatomic, copy) NSMutableDictionary* objectToCellMap; @end @implementation NICellFactory - (id)init { if ((self = [super init])) { _objectToCellMap = [[NSMutableDictionary alloc] init]; } return self; } + (UITableViewCell *)cellWithClass:(Class)cellClass tableView:(UITableView *)tableView object:(id)object { UITableViewCell* cell = nil; NSString* identifier = NSStringFromClass(cellClass); if ([cellClass respondsToSelector:@selector(shouldAppendObjectClassToReuseIdentifier)] && [cellClass shouldAppendObjectClassToReuseIdentifier]) { identifier = [identifier stringByAppendingFormat:@".%@", NSStringFromClass([object class])]; } cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (nil == cell) { UITableViewCellStyle style = UITableViewCellStyleDefault; if ([object respondsToSelector:@selector(cellStyle)]) { style = [object cellStyle]; } cell = [[cellClass alloc] initWithStyle:style reuseIdentifier:identifier]; } // Allow the cell to configure itself with the object's information. if ([cell respondsToSelector:@selector(shouldUpdateCellWithObject:)]) { [(id<NICell>)cell shouldUpdateCellWithObject:object]; } return cell; } + (UITableViewCell *)cellWithNib:(UINib *)cellNib tableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath object:(id)object { UITableViewCell* cell = nil; NSString* identifier = NSStringFromClass([object class]); [tableView registerNib:cellNib forCellReuseIdentifier:identifier]; cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; // Allow the cell to configure itself with the object's information. if ([cell respondsToSelector:@selector(shouldUpdateCellWithObject:)]) { [(id<NICell>)cell shouldUpdateCellWithObject:object]; } return cell; } + (UITableViewCell *)tableViewModel:(NITableViewModel *)tableViewModel cellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { UITableViewCell* cell = nil; // Only NICellObject-conformant objects may pass. if ([object respondsToSelector:@selector(cellClass)]) { Class cellClass = [object cellClass]; cell = [self cellWithClass:cellClass tableView:tableView object:object]; } else if ([object respondsToSelector:@selector(cellNib)]) { UINib* nib = [object cellNib]; cell = [self cellWithNib:nib tableView:tableView indexPath:indexPath object:object]; } // If this assertion fires then your app is about to crash. You need to either add an explicit // binding in a NICellFactory object or implement the NICellObject protocol on this object and // return a cell class. NIDASSERT(nil != cell); return cell; } - (Class)cellClassFromObject:(id)object { if (nil == object) { return nil; } Class objectClass = [object class]; Class cellClass = [self.objectToCellMap objectForKey:objectClass]; BOOL hasExplicitMapping = (nil != cellClass && cellClass != [NSNull class]); if (!hasExplicitMapping && [object respondsToSelector:@selector(cellClass)]) { cellClass = [object cellClass]; } if (nil == cellClass) { cellClass = [NIActions objectFromKeyClass:objectClass map:self.objectToCellMap]; } return cellClass; } - (UITableViewCell *)tableViewModel:(NITableViewModel *)tableViewModel cellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { UITableViewCell* cell = nil; Class cellClass = [self cellClassFromObject:object]; if (nil != cellClass) { cell = [[self class] cellWithClass:cellClass tableView:tableView object:object]; } else if ([object respondsToSelector:@selector(cellNib)]) { UINib* nib = [object cellNib]; cell = [[self class] cellWithNib:nib tableView:tableView indexPath:indexPath object:object]; } // If this assertion fires then your app is about to crash. You need to either add an explicit // binding in a NICellFactory object or implement the NICellObject protocol on this object and // return a cell class. NIDASSERT(nil != cell); return cell; } - (void)mapObjectClass:(Class)objectClass toCellClass:(Class)cellClass { [self.objectToCellMap setObject:cellClass forKey:(id<NSCopying>)objectClass]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath model:(NITableViewModel *)model { CGFloat height = tableView.rowHeight; id object = [model objectAtIndexPath:indexPath]; Class cellClass = [self cellClassFromObject:object]; if ([cellClass respondsToSelector:@selector(heightForObject:atIndexPath:tableView:)]) { CGFloat cellHeight = [cellClass heightForObject:object atIndexPath:indexPath tableView:tableView]; if (cellHeight > 0) { height = cellHeight; } } return height; } + (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath model:(NITableViewModel *)model { CGFloat height = tableView.rowHeight; id object = [model objectAtIndexPath:indexPath]; Class cellClass = nil; if ([object respondsToSelector:@selector(cellClass)]) { cellClass = [object cellClass]; } if ([cellClass respondsToSelector:@selector(heightForObject:atIndexPath:tableView:)]) { CGFloat cellHeight = [cellClass heightForObject:object atIndexPath:indexPath tableView:tableView]; if (cellHeight > 0) { height = cellHeight; } } return height; } @end @interface NICellObject() @property (nonatomic, assign) Class cellClass; @end @implementation NICellObject - (id)initWithCellClass:(Class)cellClass userInfo:(id)userInfo { if ((self = [super init])) { _cellClass = cellClass; _userInfo = userInfo; } return self; } - (id)initWithCellClass:(Class)cellClass { return [self initWithCellClass:cellClass userInfo:nil]; } + (id)objectWithCellClass:(Class)cellClass userInfo:(id)userInfo { return [[self alloc] initWithCellClass:cellClass userInfo:userInfo]; } + (id)objectWithCellClass:(Class)cellClass { return [[self alloc] initWithCellClass:cellClass userInfo:nil]; } @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay
Example/Pods/Nimbus/src/models/src/NIFormCellCatalog.h
C/C++ Header
// // Copyright 2011-2014 NimbusKit // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #import "NICellFactory.h" #pragma mark Form Elements /** * A single element of a form with an ID property. * * Each form element has, at the very least, an element ID property which can be used to * differentiate the form elements when change notifications are received. Each element cell * will assign the element ID to the tag property of its views. * * @ingroup TableCellCatalog */ @interface NIFormElement : NSObject <NICellObject> // Designated initializer + (id)elementWithID:(NSInteger)elementID; @property (nonatomic, assign) NSInteger elementID; @end /** * A text input form element. * * This element is similar to HTML's &lt;input type="text">. It presents a simple text field * control with optional placeholder text. You can assign a delegate to this object that will * be assigned to the text field, allowing you to receive text field delegate notifications. * * Bound to NITextInputFormElementCell when using the @link TableCellFactory Nimbus cell factory@endlink. * * @ingroup TableCellCatalog */ @interface NITextInputFormElement : NIFormElement // Designated initializer + (id)textInputElementWithID:(NSInteger)elementID placeholderText:(NSString *)placeholderText value:(NSString *)value delegate:(id<UITextFieldDelegate>)delegate; + (id)textInputElementWithID:(NSInteger)elementID placeholderText:(NSString *)placeholderText value:(NSString *)value; + (id)passwordInputElementWithID:(NSInteger)elementID placeholderText:(NSString *)placeholderText value:(NSString *)value delegate:(id<UITextFieldDelegate>)delegate; + (id)passwordInputElementWithID:(NSInteger)elementID placeholderText:(NSString *)placeholderText value:(NSString *)value; @property (nonatomic, copy) NSString* placeholderText; @property (nonatomic, copy) NSString* value; @property (nonatomic, assign) BOOL isPassword; @property (nonatomic, assign) id<UITextFieldDelegate> delegate; @end /** * A switch form element. * * This element is similar to the Settings app's switch fields. It shows a label with a switch * align to the right edge of the row. * * Bound to NISwitchFormElementCell when using the @link TableCellFactory Nimbus cell factory@endlink. * * @ingroup TableCellCatalog */ @interface NISwitchFormElement : NIFormElement // Designated initializer + (id)switchElementWithID:(NSInteger)elementID labelText:(NSString *)labelText value:(BOOL)value didChangeTarget:(id)target didChangeSelector:(SEL)selector; + (id)switchElementWithID:(NSInteger)elementID labelText:(NSString *)labelText value:(BOOL)value; @property (nonatomic, copy) NSString* labelText; @property (nonatomic, assign) BOOL value; @property (nonatomic, assign) id didChangeTarget; @property (nonatomic, assign) SEL didChangeSelector; @end /** * A slider form element. * * This element is a slider that can be embedded in a form. It shows a label with a switch * align to the right edge of the row. * * Bound to NISliderFormElementCell when using the @link TableCellFactory Nimbus cell factory@endlink. * * @ingroup TableCellCatalog */ @interface NISliderFormElement : NIFormElement // Designated initializer + (id)sliderElementWithID:(NSInteger)elementID labelText:(NSString *)labelText value:(float)value minimumValue:(float)minimumValue maximumValue:(float)maximumValue didChangeTarget:(id)target didChangeSelector:(SEL)selector; + (id)sliderElementWithID:(NSInteger)elementID labelText:(NSString *)labelText value:(float)value minimumValue:(float)minimumValue maximumValue:(float)maximumValue; @property (nonatomic, copy) NSString* labelText; @property (nonatomic, assign) float value; @property (nonatomic, assign) float minimumValue; @property (nonatomic, assign) float maximumValue; @property (nonatomic, weak) id didChangeTarget; @property (nonatomic, assign) SEL didChangeSelector; @end /** * A segmented control form element. * * This element presents a segmented control. You can initialize it with a label for the cell, an * array of NSString or UIImage objects acting as segments for the segmented control and a * selectedIndex. The selectedIndex can be -1 if you don't want to preselect a segment. * * A delegate method (didChangeSelector) will be called on the didChangeTarget once a different * segment is selected. The segmented control will be passed as an argument to this method. * * @ingroup TableCellCatalog */ @interface NISegmentedControlFormElement : NIFormElement /** * Initializes a segmented control form cell with callback method for value change events. * * @param elementID An ID for this element. * @param labelText Text to show on the left side of the form cell. * @param segments An array containing NSString or UIImage objects that will be used as * segments of the control. The order in the array is used as order of the * segments. * @param selectedIndex Index of the selected segment. -1 if no segment is selected. * @param target Receiver for didChangeSelector calls. * @param selector Method that is called when a segment is selected. */ + (id)segmentedControlElementWithID:(NSInteger)elementID labelText:(NSString *)labelText segments:(NSArray *)segments selectedIndex:(NSInteger)selectedIndex didChangeTarget:(id)target didChangeSelector:(SEL)selector ; /** * Initializes a segmented control form cell. * * @param elementID An ID for this element. * @param labelText Text to show on the left side of the form cell. * @param segments An array containing NSString or UIImage objects that will be used as * segments of the control. The order in the array is used as order of the * segments. * @param selectedIndex Index of the selected segment. -1 if no segment is selected. */ + (id)segmentedControlElementWithID:(NSInteger)elementID labelText:(NSString *)labelText segments:(NSArray *)segments selectedIndex:(NSInteger)selectedIndex; @property (nonatomic, copy) NSString *labelText; @property (nonatomic, assign) NSInteger selectedIndex; @property (nonatomic, strong) NSArray *segments; @property (nonatomic, weak) id didChangeTarget; @property (nonatomic, assign) SEL didChangeSelector; @end /** * A date picker form element. * * This element shows a date that can be modified. * * You can initialize it with a labelText showing on the left in the table cell, a date that will * be used to initialize the date picker and a delegate target and method that gets called when a * different date is selected. * * To change the date picker format you can access the datePicker property of the * NIDatePickerFormElementCell sibling object. * * @ingroup TableCellCatalog */ @interface NIDatePickerFormElement : NIFormElement /** * Initializes a date picker form element with callback method for value changed events. * * @param elementID An ID for this element. * @param labelText Text to show on the left side of the form cell. * @param date Initial date to show in the picker * @param datePickerMode UIDatePickerMode to user for the date picker * @param target Receiver for didChangeSelector calls. * @param selector Method that is called when a segment is selected. */ + (id)datePickerElementWithID:(NSInteger)elementID labelText:(NSString *)labelText date:(NSDate *)date datePickerMode:(UIDatePickerMode)datePickerMode didChangeTarget:(id)target didChangeSelector:(SEL)selector; /** * Initializes a date picker form element with callback method for value changed events. * * @param elementID An ID for this element. * @param labelText Text to show on the left side of the form cell. * @param date Initial date to show in the picker * @param datePickerMode UIDatePickerMode to user for the date picker */ + (id)datePickerElementWithID:(NSInteger)elementID labelText:(NSString *)labelText date:(NSDate *)date datePickerMode:(UIDatePickerMode)datePickerMode; @property (nonatomic, copy) NSString *labelText; @property (nonatomic, strong) NSDate *date; @property (nonatomic, assign) UIDatePickerMode datePickerMode; @property (nonatomic, weak) id didChangeTarget; @property (nonatomic, assign) SEL didChangeSelector; @end #pragma mark - Form Element Cells /** * The base class for form element cells. * * Doesn't do anything particularly interesting other than retaining the element. * * @ingroup TableCellCatalog */ @interface NIFormElementCell : UITableViewCell <NICell> @property (nonatomic, readonly, strong) NIFormElement* element; @end /** * The cell sibling to NITextInputFormElement. * * Displays a simple text field that fills the entire content view. * * @image html NITextInputCellExample1.png "Example of a NITextInputFormElementCell." * * @ingroup TableCellCatalog */ @interface NITextInputFormElementCell : NIFormElementCell <UITextFieldDelegate> @property (nonatomic, readonly, strong) UITextField* textField; @end /** * The cell sibling to NISwitchFormElement. * * Displays a left-aligned label and a right-aligned switch. * * @image html NISwitchFormElementCellExample1.png "Example of a NISwitchFormElementCell." * * @ingroup TableCellCatalog */ @interface NISwitchFormElementCell : NIFormElementCell <UITextFieldDelegate> @property (nonatomic, readonly, strong) UISwitch* switchControl; @end /** * The cell sibling to NISliderFormElement. * * Displays a left-aligned label and a right-aligned slider. * * @image html NISliderFormElementCellExample1.png "Example of a NISliderFormElementCell." * * @ingroup TableCellCatalog */ @interface NISliderFormElementCell : NIFormElementCell <UITextFieldDelegate> @property (nonatomic, readonly, strong) UISlider* sliderControl; @end @interface NITableViewModel (NIFormElementSearch) // Finds an element in the static table view model with the given element id. - (id)elementWithID:(NSInteger)elementID; @end /** * The cell sibling to NISegmentedControlFormElement. * * Displays a left-aligned label and a right-aligned segmented control. * * @ingroup TableCellCatalog */ @interface NISegmentedControlFormElementCell : NIFormElementCell @property (nonatomic, readonly, strong) UISegmentedControl *segmentedControl; @end /** * The cell sibling to NIDatePickerFormElement * * Displays a left-aligned label and a right-aligned date. * * @ingroup TableCellCatalog */ @interface NIDatePickerFormElementCell : NIFormElementCell <UITextFieldDelegate> @property (nonatomic, readonly, strong) UITextField *dateField; @property (nonatomic, readonly, strong) UIDatePicker *datePicker; @end
xiekw2010/DXPhotoBrowser
2
A photo browser for displaying a bunch of images one by one
Objective-C
xiekw2010
David Tse
Alipay