Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

finished moving over the last bits of the original View Controller cl…

…ass involving layout
  • Loading branch information...
commit 60f855cc66e741236bc871ae37bd6dccffde7aa2 1 parent 5ab1a05
Colin Wheeler authored

Showing 1 changed file with 62 additions and 17 deletions. Show diff stats Hide diff stats

  1. +62 17 Rebel/NSView+RBLViewControllerAdditions.m
79 Rebel/NSView+RBLViewControllerAdditions.m
@@ -12,18 +12,23 @@
12 12 #import <objc/runtime.h>
13 13
14 14 void *kRBLViewControllerKey = &kRBLViewControllerKey;
  15 +void *KRBLViewNeedsLayoutKey = &KRBLViewNeedsLayoutKey;
15 16
16 17 @implementation NSView (NSView_RBLViewControllerAdditions)
17 18
  19 ++ (void)initialize {
  20 + if(self == [NSView class]) {
  21 + [self loadSupportForLayoutSubviews];
  22 + }
  23 +}
  24 +
18 25 #pragma mark - ViewController
19 26
20   --(id)viewController
21   -{
  27 +-(id)viewController {
22 28 return objc_getAssociatedObject(self, kRBLViewControllerKey);
23 29 }
24 30
25   --(void)setViewController:(id)newViewController
26   -{
  31 +-(void)setViewController:(id)newViewController {
27 32 if (self.viewController) {
28 33 NSResponder *controllerNextResponder = [self.viewController nextResponder];
29 34 [self setNextResponder:controllerNextResponder];
@@ -39,10 +44,55 @@ -(void)setViewController:(id)newViewController
39 44 }
40 45 }
41 46
42   -#pragma mark - Custom Methods
  47 +#pragma mark - Layout Subviews
  48 +
  49 ++ (void)loadSupportForLayoutSubviews {
  50 + [self swapMethod:@selector(setBounds:) with:@selector(custom_setBounds:)];
  51 + [self swapMethod:@selector(setFrame:) with:@selector(custom_setFrame:)];
  52 + [self swapMethod:@selector(viewWillDraw) with:@selector(custom_viewWillDraw)];
  53 +}
  54 +
  55 +- (void)custom_setBounds:(NSRect)newBounds {
  56 + [self custom_setBounds:newBounds];
  57 +
  58 + [self setNeedsLayout];
  59 +}
  60 +
  61 +- (void)custom_setFrame:(NSRect)newFrame {
  62 + [self custom_setFrame:newFrame];
  63 +
  64 + [self setNeedsLayout];
  65 +}
  66 +
  67 +- (void)custom_viewWillDraw {
  68 + [self layoutIfNeeded];
  69 +
  70 + [self custom_viewWillDraw];
  71 +}
  72 +
  73 +- (void)layoutIfNeeded {
  74 + if([self needsLayout]) {
  75 + [self layoutSubviews];
  76 + }
  77 +}
  78 +
  79 +- (void)layoutSubviews {
  80 + objc_setAssociatedObject(self, KRBLViewNeedsLayoutKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  81 +}
  82 +
  83 +- (void)setNeedsLayout {
  84 + objc_setAssociatedObject(self, KRBLViewNeedsLayoutKey, [NSNull null], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  85 +
  86 + [self setNeedsDisplay:YES];
  87 +}
  88 +
  89 +- (BOOL)needsLayout {
  90 + return objc_getAssociatedObject(self, KRBLViewNeedsLayoutKey) != nil;
  91 +}
  92 +
  93 +#pragma mark - View Methods
43 94
44   -+(void)loadSupportForRBLViewControllers
45   -{
  95 ++(void)loadSupportForRBLViewControllers {
46 96 static dispatch_once_t onceToken;
47 97 dispatch_once(&onceToken, ^{
48 98 //swizzle swizzle...
@@ -56,8 +106,7 @@ +(void)loadSupportForRBLViewControllers
56 106 });
57 107 }
58 108
59   -- (void)custom_viewWillMoveToSuperview:(NSView *)newSuperview
60   -{
  109 +- (void)custom_viewWillMoveToSuperview:(NSView *)newSuperview {
61 110 [self custom_viewWillMoveToSuperview:newSuperview];
62 111
63 112 if ([self.viewController isKindOfClass:[RBLViewController class]]) {
@@ -77,8 +126,7 @@ - (void)custom_viewWillMoveToSuperview:(NSView *)newSuperview
77 126 }
78 127 }
79 128
80   -- (void)custom_viewDidMoveToSuperview
81   -{
  129 +- (void)custom_viewDidMoveToSuperview {
82 130 [self custom_viewDidMoveToSuperview];
83 131
84 132 if ([self.viewController isKindOfClass:[RBLViewController class]]) {
@@ -98,8 +146,7 @@ - (void)custom_viewDidMoveToSuperview
98 146 }
99 147 }
100 148
101   -- (void)custom_viewWillMoveToWindow:(NSWindow *)newWindow
102   -{
  149 +- (void)custom_viewWillMoveToWindow:(NSWindow *)newWindow {
103 150 [self custom_viewWillMoveToWindow:newWindow];
104 151
105 152 if ([self.viewController isKindOfClass:[RBLViewController class]]) {
@@ -119,8 +166,7 @@ - (void)custom_viewWillMoveToWindow:(NSWindow *)newWindow
119 166 }
120 167 }
121 168
122   -- (void)custom_viewDidMoveToWindow
123   -{
  169 +- (void)custom_viewDidMoveToWindow {
124 170 [self custom_viewDidMoveToWindow];
125 171
126 172 if ([self.viewController isKindOfClass:[RBLViewController class]]) {
@@ -140,8 +186,7 @@ - (void)custom_viewDidMoveToWindow
140 186 }
141 187 }
142 188
143   -- (void)custom_setNextResponder:(NSResponder *)newNextResponder
144   -{
  189 +- (void)custom_setNextResponder:(NSResponder *)newNextResponder {
145 190 if (self.viewController != nil) {
146 191 [self.viewController setNextResponder:newNextResponder];
147 192 return;

0 comments on commit 60f855c

Please sign in to comment.
Something went wrong with that request. Please try again.