PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/TeamTalk/IOSDuoduo/ThridFramework/AQ/AQGridViewCell.m

https://gitlab.com/lisit1003/TTiOSClient
Objective C | 706 lines | 539 code | 122 blank | 45 comment | 115 complexity | 1c1e12e1ae22d15e081c40c74f46d678 MD5 | raw file
  1. /*
  2. * AQGridViewCell.m
  3. * AQGridView
  4. *
  5. * Created by Jim Dovey on 25/2/2010.
  6. * Copyright (c) 2010 Kobo Inc. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * Neither the name of the project's author nor the names of its
  20. * contributors may be used to endorse or promote products derived from
  21. * this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  29. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #import "AQGridViewCell.h"
  37. #import "AQGridViewCell+AQGridViewCellPrivate.h"
  38. #import "UIColor+AQGridView.h"
  39. #import <QuartzCore/QuartzCore.h>
  40. #import <objc/runtime.h>
  41. #ifdef BUILTIN_IMAGES
  42. #import "AQGridViewCell_png.h"
  43. #endif
  44. @interface AQGridViewCell ()
  45. @property (nonatomic, retain) UIView * contentView;
  46. @property (nonatomic, copy) NSString * reuseIdentifier;
  47. - (void) flipHighlightTimerFired: (NSTimer *) timer;
  48. @end
  49. @implementation AQGridViewCell
  50. @synthesize contentView=_contentView, backgroundView=_backgroundView, selectedBackgroundView=_selectedBackgroundView;
  51. @synthesize reuseIdentifier=_reuseIdentifier, selectionGlowColor=_selectionGlowColor;
  52. @synthesize selectionGlowShadowRadius=_selectionGlowShadowRadius;
  53. - (id) initWithFrame: (CGRect) frame reuseIdentifier: (NSString *) reuseIdentifier
  54. {
  55. self = [super initWithFrame: frame];
  56. if ( self == nil )
  57. return ( nil );
  58. self.reuseIdentifier = reuseIdentifier;
  59. _cellFlags.usingDefaultSelectedBackgroundView = 1;
  60. _cellFlags.separatorStyle = AQGridViewCellSeparatorStyleEmptySpace;
  61. if ( [CALayer instancesRespondToSelector: @selector(shadowPath)] )
  62. _cellFlags.selectionStyle = AQGridViewCellSelectionStyleGlow;
  63. else
  64. _cellFlags.selectionStyle = AQGridViewCellSelectionStyleGray;
  65. _cellFlags.setShadowPath = 0;
  66. _selectionColorInfo = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
  67. self.backgroundColor = [UIColor whiteColor];
  68. _selectionGlowShadowRadius = 12.0f;
  69. return ( self );
  70. }
  71. - (void) awakeFromNib
  72. {
  73. _cellFlags.usingDefaultSelectedBackgroundView = 1;
  74. _cellFlags.separatorStyle = AQGridViewCellSeparatorStyleEmptySpace;
  75. if ( [CALayer instancesRespondToSelector: @selector(shadowPath)] )
  76. _cellFlags.selectionStyle = AQGridViewCellSelectionStyleGlow;
  77. else
  78. _cellFlags.selectionStyle = AQGridViewCellSelectionStyleGray;
  79. _selectionColorInfo = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
  80. self.backgroundColor = [UIColor whiteColor];
  81. [super awakeFromNib];
  82. }
  83. - (void) dealloc
  84. {
  85. if ( _selectionColorInfo != NULL )
  86. CFRelease( _selectionColorInfo );
  87. }
  88. - (NSComparisonResult) compareOriginAgainstCell: (AQGridViewCell *) otherCell
  89. {
  90. CGPoint myOrigin = self.frame.origin;
  91. CGPoint theirOrigin = otherCell.frame.origin;
  92. if ( myOrigin.y > theirOrigin.y )
  93. return ( NSOrderedDescending );
  94. else if ( myOrigin.y < theirOrigin.y )
  95. return ( NSOrderedAscending );
  96. if ( myOrigin.x > theirOrigin.x )
  97. return ( NSOrderedDescending );
  98. else if ( myOrigin.x < theirOrigin.x )
  99. return ( NSOrderedAscending );
  100. return ( NSOrderedSame );
  101. }
  102. - (UIView *) contentView
  103. {
  104. if ( _contentView == nil )
  105. {
  106. _contentView = [[UIView alloc] initWithFrame: self.bounds];
  107. _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  108. _contentView.autoresizesSubviews = YES;
  109. self.autoresizesSubviews = YES;
  110. _contentView.backgroundColor = [UIColor whiteColor];
  111. [_contentView.layer setValue: [NSNumber numberWithBool: YES] forKey: @"KoboHackInterestingLayer"];
  112. [self addSubview: _contentView];
  113. }
  114. return ( _contentView );
  115. }
  116. - (CALayer *) glowSelectionLayer
  117. {
  118. return ( _contentView.layer );
  119. }
  120. - (AQGridViewCellSelectionStyle) selectionStyle
  121. {
  122. return ( _cellFlags.selectionStyle );
  123. }
  124. - (void) setSelectionStyle: (AQGridViewCellSelectionStyle) style
  125. {
  126. if ( (style == AQGridViewCellSelectionStyleGlow) && ([CALayer instancesRespondToSelector: @selector(shadowPath)] == NO) )
  127. style = AQGridViewCellSelectionStyleGray;
  128. _cellFlags.selectionStyle = style;
  129. }
  130. - (AQGridViewCellSeparatorEdge) separatorEdge
  131. {
  132. return ( _cellFlags.separatorEdge );
  133. }
  134. - (void) setSeparatorEdge: (AQGridViewCellSeparatorEdge) value
  135. {
  136. if ( _cellFlags.separatorEdge == value )
  137. return;
  138. _cellFlags.separatorEdge = value;
  139. [self setNeedsLayout];
  140. }
  141. - (BOOL) isSelected
  142. {
  143. return ( _cellFlags.selected );
  144. }
  145. - (void) setSelected: (BOOL) value
  146. {
  147. [self setSelected: value animated: NO];
  148. }
  149. - (void) setSelected: (BOOL) value animated: (BOOL) animated
  150. {
  151. _cellFlags.selected = (value ? 1 : 0);
  152. [self setHighlighted: value animated: animated];
  153. }
  154. - (BOOL) isHighlighted
  155. {
  156. return ( _cellFlags.highlighted );
  157. }
  158. - (void) setHighlighted: (BOOL) value
  159. {
  160. [self setHighlighted: value animated: NO];
  161. }
  162. - (void) makeSubviewsOfView: (UIView *) aView nonOpaqueWithBackgroundColor: (UIColor *) color
  163. {
  164. for ( UIView * view in aView.subviews )
  165. {
  166. if ( view.opaque )
  167. {
  168. NSMutableDictionary * info = (NSMutableDictionary *) objc_unretainedObject(CFDictionaryGetValue( _selectionColorInfo, objc_unretainedPointer(view) ));
  169. if ( info == nil )
  170. {
  171. info = [NSMutableDictionary dictionaryWithCapacity: 2];
  172. CFDictionarySetValue( _selectionColorInfo, objc_unretainedPointer(view), objc_unretainedPointer(info) );
  173. }
  174. id value = view.backgroundColor;
  175. if ( value == nil )
  176. value = [NSNull null];
  177. [info setObject: value forKey: @"backgroundColor"];
  178. view.opaque = NO;
  179. view.backgroundColor = color;
  180. }
  181. [self makeSubviewsOfView: view nonOpaqueWithBackgroundColor: color];
  182. }
  183. }
  184. - (void) makeSubviewsOfViewOpaqueAgain: (UIView *) aView
  185. {
  186. for ( UIView * view in aView.subviews )
  187. {
  188. NSMutableDictionary * info = (NSMutableDictionary *) objc_unretainedObject(CFDictionaryGetValue( _selectionColorInfo, objc_unretainedPointer(view) ));
  189. if ( info != nil )
  190. {
  191. id value = [info objectForKey: @"backgroundColor"];
  192. if ( value == nil )
  193. continue;
  194. if ( value == [NSNull null] )
  195. value = nil;
  196. view.opaque = YES;
  197. view.backgroundColor = value;
  198. }
  199. [self makeSubviewsOfViewOpaqueAgain: view];
  200. }
  201. }
  202. //- (void) setTextColor: (UIColor *) color forSubviewsOfView: (UIView *) aView
  203. - (void) highlightSubviewsOfView: (UIView *) aView
  204. {
  205. for ( UIView * view in aView.subviews )
  206. {
  207. if ( [view respondsToSelector: @selector(setHighlighted:)] )
  208. {
  209. NSMutableDictionary * info = (NSMutableDictionary *) objc_unretainedObject(CFDictionaryGetValue( _selectionColorInfo, objc_unretainedPointer(view) ));
  210. if ( info == nil )
  211. {
  212. info = [NSMutableDictionary dictionaryWithCapacity: 2];
  213. CFDictionarySetValue( _selectionColorInfo, objc_unretainedPointer(view), objc_unretainedPointer(info) );
  214. }
  215. // don't overwrite any prior cache of a view's original highlighted state.
  216. // this is because 'highlighted' will be set, then 'selected', which can perform 'highlight' again before the animation completes
  217. if ( [info objectForKey: @"highlighted"] == nil )
  218. {
  219. id value = [view valueForKey: @"highlighted"];
  220. if ( value == nil )
  221. value = [NSNumber numberWithBool: NO];
  222. [info setObject: value forKey: @"highlighted"];
  223. }
  224. [view setValue: [NSNumber numberWithBool: YES]
  225. forKey: @"highlighted"];
  226. }
  227. [self highlightSubviewsOfView: view];
  228. }
  229. }
  230. - (void) resetHighlightForSubviewsOfView: (UIView *) aView
  231. {
  232. for ( UIView * view in aView.subviews )
  233. {
  234. if ([view respondsToSelector:@selector(setHighlighted:)]) {
  235. NSMutableDictionary * info = (NSMutableDictionary *) objc_unretainedObject(CFDictionaryGetValue( _selectionColorInfo, objc_unretainedPointer(view) ));
  236. if ( info != nil )
  237. {
  238. id value = [info objectForKey: @"highlighted"];
  239. [view setValue: value forKey: @"highlighted"];
  240. }
  241. }
  242. [self resetHighlightForSubviewsOfView: view];
  243. }
  244. }
  245. - (void) _beginBackgroundHighlight: (BOOL) highlightOn animated: (BOOL) animated
  246. {
  247. if ( (_cellFlags.usingDefaultSelectedBackgroundView == 1) && (_selectedBackgroundView == nil) )
  248. {
  249. NSString *imageName = nil;
  250. #ifdef BUILTIN_IMAGES
  251. unsigned char * pngBytes = AQGridSelection_png;
  252. NSUInteger pngLength = AQGridSelection_png_len;
  253. switch ( _cellFlags.selectionStyle )
  254. {
  255. case AQGridViewCellSelectionStyleBlue:
  256. default:
  257. break;
  258. case AQGridViewCellSelectionStyleGray:
  259. imageName = @"AQGridSelectionGray.png";
  260. break;
  261. case AQGridViewCellSelectionStyleBlueGray:
  262. imageName = @"AQGridSelectionGrayBlue.png";
  263. break;
  264. case AQGridViewCellSelectionStyleGreen:
  265. imageName = @"AQGridSelectionGreen.png";
  266. break;
  267. case AQGridViewCellSelectionStyleRed:
  268. imageName = @"AQGridSelectionRed.png";
  269. break;
  270. }
  271. NSData *pngData = [NSData dataWithBytesNoCopy: pngBytes length: pngLength freeWhenDone: NO];
  272. _selectedBackgroundView = [[UIImageView alloc] initWithImage: [UIImage imageWithData: pngData]];
  273. #else
  274. imageName = @"AQGridSelection.png";
  275. switch ( _cellFlags.selectionStyle )
  276. {
  277. case AQGridViewCellSelectionStyleBlue:
  278. default:
  279. break;
  280. case AQGridViewCellSelectionStyleGray:
  281. imageName = @"AQGridSelectionGray.png";
  282. break;
  283. case AQGridViewCellSelectionStyleBlueGray:
  284. imageName = @"AQGridSelectionGrayBlue.png";
  285. break;
  286. case AQGridViewCellSelectionStyleGreen:
  287. imageName = @"AQGridSelectionGreen.png";
  288. break;
  289. case AQGridViewCellSelectionStyleRed:
  290. imageName = @"AQGridSelectionRed.png";
  291. break;
  292. }
  293. _selectedBackgroundView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: imageName]];
  294. #endif
  295. _selectedBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  296. _selectedBackgroundView.contentMode = UIViewContentModeScaleToFill;
  297. }
  298. // we'll set the text color to something here
  299. if ( highlightOn )
  300. {
  301. // start it invisible
  302. [UIView setAnimationsEnabled: NO];
  303. _selectedBackgroundView.alpha = 0.0;
  304. // find all opaque subviews and make non-opaque with clear backgrounds
  305. [self makeSubviewsOfView: self nonOpaqueWithBackgroundColor: [UIColor clearColor]];
  306. if ( _backgroundView != nil )
  307. [self insertSubview: _selectedBackgroundView aboveSubview: _backgroundView];
  308. else
  309. [self insertSubview: _selectedBackgroundView atIndex: 0];
  310. _selectedBackgroundView.frame = self.bounds;
  311. [UIView setAnimationsEnabled: YES];
  312. // now the animating bit -- make the selection fade in
  313. _selectedBackgroundView.alpha = 1.0;
  314. }
  315. else
  316. {
  317. _selectedBackgroundView.alpha = 0.0;
  318. }
  319. if ( animated )
  320. {
  321. if ( _fadeTimer != nil )
  322. {
  323. [_fadeTimer invalidate];
  324. }
  325. _fadeTimer = [[NSTimer alloc] initWithFireDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]
  326. interval: 0.1
  327. target: self
  328. selector: @selector(flipHighlightTimerFired:)
  329. userInfo: [NSNumber numberWithBool: highlightOn]
  330. repeats: NO];
  331. [[NSRunLoop currentRunLoop] addTimer: _fadeTimer forMode: NSDefaultRunLoopMode];
  332. }
  333. else
  334. {
  335. if ( highlightOn )
  336. [self highlightSubviewsOfView: self];
  337. else
  338. [self resetHighlightForSubviewsOfView: self];
  339. }
  340. }
  341. - (void) flipHighlightTimerFired: (NSTimer *) timer
  342. {
  343. if ( [[timer userInfo] boolValue] )
  344. [self highlightSubviewsOfView: self];
  345. else
  346. [self resetHighlightForSubviewsOfView: self];
  347. }
  348. - (void) highlightAnimationStopped: (NSString * __unused) animationID context: (void * __unused) context
  349. {
  350. BOOL isHighlighting = (_cellFlags.becomingHighlighted ? YES : NO);
  351. if ( isHighlighting )
  352. {
  353. _cellFlags.highlighted = 1;
  354. }
  355. else
  356. {
  357. [UIView setAnimationsEnabled: NO];
  358. // find all non-opaque subviews and make opaque again, with original background colors
  359. [self makeSubviewsOfViewOpaqueAgain: self];
  360. [UIView setAnimationsEnabled: YES];
  361. _cellFlags.highlighted = 0;
  362. [_selectedBackgroundView removeFromSuperview];
  363. CFDictionaryRemoveAllValues( _selectionColorInfo );
  364. }
  365. _cellFlags.animatingSelection = 0;
  366. }
  367. - (void) setHighlighted: (BOOL) value animated: (BOOL) animated
  368. {
  369. if ( _cellFlags.selectionStyle == AQGridViewCellSelectionStyleNone )
  370. {
  371. _cellFlags.highlighted = (value ? 1 : 0);
  372. return;
  373. }
  374. _cellFlags.becomingHighlighted = (value ? 1 : 0);
  375. if ( (animated) && ([UIView areAnimationsEnabled]) )
  376. {
  377. [UIView beginAnimations: @"AQGridCellViewHighlightAnimation" context: NULL];
  378. [UIView setAnimationCurve: UIViewAnimationCurveLinear];
  379. [UIView setAnimationBeginsFromCurrentState: YES];
  380. [UIView setAnimationDidStopSelector: @selector(highlightAnimationStopped:context:)];
  381. _cellFlags.animatingSelection = 1;
  382. }
  383. switch ( _cellFlags.selectionStyle )
  384. {
  385. case AQGridViewCellSelectionStyleNone:
  386. default:
  387. break;
  388. case AQGridViewCellSelectionStyleBlue:
  389. case AQGridViewCellSelectionStyleGray:
  390. case AQGridViewCellSelectionStyleBlueGray:
  391. case AQGridViewCellSelectionStyleGreen:
  392. case AQGridViewCellSelectionStyleRed:
  393. {
  394. [self _beginBackgroundHighlight: value animated: animated];
  395. break;
  396. }
  397. case AQGridViewCellSelectionStyleGlow:
  398. {
  399. CALayer * theLayer = self.glowSelectionLayer;
  400. if ([theLayer respondsToSelector: @selector(setShadowPath:)] && [theLayer respondsToSelector: @selector(shadowPath)])
  401. {
  402. if ( _cellFlags.setShadowPath == 0 )
  403. {
  404. CGMutablePathRef path = CGPathCreateMutable();
  405. CGPathAddRect( path, NULL, theLayer.bounds );
  406. theLayer.shadowPath = path;
  407. CGPathRelease( path );
  408. _cellFlags.setShadowPath = 1;
  409. }
  410. theLayer.shadowOffset = CGSizeZero;
  411. if ( _cellFlags.selectionGlowColorSet == 1 )
  412. theLayer.shadowColor = self.selectionGlowColor.CGColor;
  413. else
  414. theLayer.shadowColor = [[UIColor darkGrayColor] CGColor];
  415. theLayer.shadowRadius = self.selectionGlowShadowRadius;
  416. // add or remove the 'shadow' as appropriate
  417. if ( value )
  418. theLayer.shadowOpacity = 1.0;
  419. else
  420. theLayer.shadowOpacity = 0.0;
  421. }
  422. break;
  423. }
  424. }
  425. if ( (animated) && ([UIView areAnimationsEnabled]) )
  426. [UIView commitAnimations];
  427. else
  428. [self highlightAnimationStopped: @"" context: NULL];
  429. }
  430. - (void) setBackgroundView: (UIView *) aView
  431. {
  432. if ( aView == _backgroundView )
  433. return;
  434. if ( _backgroundView.superview == self )
  435. [_backgroundView removeFromSuperview];
  436. _backgroundView = aView;
  437. _backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  438. CGRect bgFrame = self.bounds;
  439. if ( _cellFlags.separatorStyle == AQGridViewCellSeparatorStyleSingleLine )
  440. {
  441. if ( _cellFlags.separatorEdge & AQGridViewCellSeparatorEdgeBottom )
  442. bgFrame.size.height -= 1.0;
  443. if ( _cellFlags.separatorEdge & AQGridViewCellSeparatorEdgeRight )
  444. bgFrame.size.width -= 1.0;
  445. }
  446. _backgroundView.frame = bgFrame;
  447. [self insertSubview: _backgroundView atIndex: 0];
  448. }
  449. - (void) layoutSubviews
  450. {
  451. [super layoutSubviews];
  452. _cellFlags.setShadowPath = 0;
  453. CGRect cFrame = self.bounds;
  454. if ( _cellFlags.separatorStyle == AQGridViewCellSeparatorStyleSingleLine )
  455. {
  456. if ( _cellFlags.separatorEdge & AQGridViewCellSeparatorEdgeBottom )
  457. {
  458. if ( _bottomSeparatorView == nil )
  459. {
  460. _bottomSeparatorView = [[UIView alloc] initWithFrame: CGRectMake(0.0, self.bounds.size.height - 1.0, self.bounds.size.width, 1.0)];
  461. _bottomSeparatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;
  462. [self insertSubview: _bottomSeparatorView atIndex: 0];
  463. }
  464. _bottomSeparatorView.backgroundColor = (_separatorColor == nil ? [UIColor AQDefaultGridCellSeparatorColor] : _separatorColor);
  465. cFrame.size.height -= 1.0;
  466. }
  467. else if ( _bottomSeparatorView != nil )
  468. {
  469. [_bottomSeparatorView removeFromSuperview];
  470. _bottomSeparatorView = nil;
  471. }
  472. if ( _cellFlags.separatorEdge & AQGridViewCellSeparatorEdgeRight )
  473. {
  474. if ( _rightSeparatorView == nil )
  475. {
  476. _rightSeparatorView = [[UIView alloc] initWithFrame: CGRectMake(self.bounds.size.width - 1.0, 0.0, 1.0, self.bounds.size.height)];
  477. _rightSeparatorView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleLeftMargin;
  478. [self insertSubview: _rightSeparatorView atIndex: 0];
  479. }
  480. _rightSeparatorView.backgroundColor = (_separatorColor == nil ? [UIColor AQDefaultGridCellSeparatorColor] : _separatorColor);
  481. cFrame.size.width -= 1.0;
  482. }
  483. else if ( _rightSeparatorView != nil )
  484. {
  485. [_rightSeparatorView removeFromSuperview];
  486. _rightSeparatorView = nil;
  487. }
  488. }
  489. self.contentView.frame = cFrame;
  490. self.backgroundView.frame = cFrame;
  491. self.selectedBackgroundView.frame = cFrame;
  492. }
  493. - (void) setSelectionGlowColor: (UIColor *) aColor
  494. {
  495. _selectionGlowColor = aColor;
  496. _cellFlags.selectionGlowColorSet = (aColor == nil ? 0 : 1);
  497. }
  498. - (void) setSelectedBackgroundView: (UIView *) aView
  499. {
  500. if ( aView == _selectedBackgroundView )
  501. return;
  502. if ( _selectedBackgroundView.superview == self )
  503. [_selectedBackgroundView removeFromSuperview];
  504. _selectedBackgroundView = aView;
  505. _selectedBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  506. CGRect bgFrame = self.bounds;
  507. if ( _cellFlags.separatorStyle == AQGridViewCellSeparatorStyleSingleLine )
  508. {
  509. if ( _cellFlags.separatorEdge & AQGridViewCellSeparatorEdgeBottom )
  510. bgFrame.size.height -= 1.0;
  511. if ( _cellFlags.separatorEdge & AQGridViewCellSeparatorEdgeRight )
  512. bgFrame.size.width -= 1.0;
  513. }
  514. _selectedBackgroundView.frame = bgFrame;
  515. [self insertSubview: _selectedBackgroundView atIndex: 0];
  516. _cellFlags.usingDefaultSelectedBackgroundView = (aView == nil ? 1 : 0);
  517. }
  518. - (void) prepareForReuse
  519. {
  520. _cellFlags.setShadowPath = 0;
  521. }
  522. - (BOOL) isEditing
  523. {
  524. return ( _cellFlags.editing == 1 );
  525. }
  526. - (void) setEditing: (BOOL) value
  527. {
  528. [self setEditing:value animated:NO];
  529. }
  530. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  531. {
  532. _cellFlags.editing = (editing ? 1 : 0);
  533. }
  534. @end
  535. @implementation AQGridViewCell (AQGridViewCellPrivate)
  536. - (UIColor *) separatorColor
  537. {
  538. return ( _separatorColor );
  539. }
  540. - (void) setSeparatorColor: (UIColor *) color
  541. {
  542. if ( _separatorColor == color )
  543. return;
  544. _separatorColor = color;
  545. _bottomSeparatorView.backgroundColor = _separatorColor;
  546. _rightSeparatorView.backgroundColor = _separatorColor;
  547. }
  548. - (AQGridViewCellSeparatorStyle) separatorStyle
  549. {
  550. return ( _cellFlags.separatorStyle );
  551. }
  552. - (void) setSeparatorStyle: (AQGridViewCellSeparatorStyle) style
  553. {
  554. if ( style == _cellFlags.separatorStyle )
  555. return;
  556. _cellFlags.separatorStyle = style;
  557. [self setNeedsLayout];
  558. }
  559. - (NSUInteger) displayIndex
  560. {
  561. return ( _displayIndex );
  562. }
  563. - (void) setDisplayIndex: (NSUInteger) index
  564. {
  565. _displayIndex = index;
  566. }
  567. - (BOOL) hiddenForAnimation
  568. {
  569. return ( _cellFlags.hiddenForAnimation == 1 );
  570. }
  571. - (void) setHiddenForAnimation: (BOOL) value
  572. {
  573. if ( value )
  574. {
  575. self.hidden = YES;
  576. _cellFlags.hiddenForAnimation = 1;
  577. }
  578. else
  579. {
  580. // don't make visible here-- might still be hidden by something else. Caller should un-hide if appropriate
  581. _cellFlags.hiddenForAnimation = 0;
  582. }
  583. }
  584. @end