From 8fc465b63a9e5244575248472df551a5962d4ccf Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Wed, 13 Oct 2010 13:37:28 +0200 Subject: [PATCH 1/5] fix: CPTabView not resizable fix: delegate problem with uninitialized variable --- AppKit/CPTabView.j | 47 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/AppKit/CPTabView.j b/AppKit/CPTabView.j index 7a9f86697..2d8265411 100644 --- a/AppKit/CPTabView.j +++ b/AppKit/CPTabView.j @@ -77,6 +77,46 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; return self; } +/*! + Override CPView message to allow to set the autoresizing mask + of the tabview and it's subview + + @param unsigned aMask the autoresizing mask +*/ +- (void)setAutoresizingMask:(unsigned)aMask +{ + [box setAutoresizingMask:aMask]; + + [super setAutoresizingMask:aMask]; +} + + +/*! + Override the CPView method in order + to allow to reposition the segmented control + + @param aFrame the new frame +*/ +- (void)setFrame:(CGRect)aFrame +{ + [super setFrame:aFrame]; + + [self _repositionTabs]; +} + +/*! + Override the CPView method in order + to allow to reposition the segmented control + + @param someBounds the new bounds +*/ +- (void)setBounds:(CGRect)someBounds +{ + [super setBounds:someBounds]; + + [self _repositionTabs]; +} + // Adding and Removing Tabs /*! Adds a CPTabViewItem to the tab view. @@ -251,9 +291,11 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; if (anIndex === selectedIndex) return; + var aTabViewItem = [self tabViewItemAtIndex:anIndex]; + if ((delegateSelectors & CPTabViewShouldSelectTabViewItemSelector) && ![delegate tabView:self shouldSelectTabViewItem:aTabViewItem]) return; - + if (delegateSelectors & CPTabViewWillSelectTabViewItemSelector) [delegate tabView:self willSelectTabViewItem:aTabViewItem]; @@ -292,7 +334,8 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; type = aTabViewType; - switch (type) { + switch (type) + { case CPTopTabsBezelBorder: case CPBottomTabsBezelBorder: case CPNoTabsBezelBorder: From 560c971aeb12a5d293c877785b4bf02feef9f275 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Wed, 13 Oct 2010 13:41:35 +0200 Subject: [PATCH 2/5] capp_lint --- AppKit/CPTabView.j | 79 +++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/AppKit/CPTabView.j b/AppKit/CPTabView.j index 2d8265411..46cf5b4cd 100644 --- a/AppKit/CPTabView.j +++ b/AppKit/CPTabView.j @@ -48,7 +48,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; CPNumber selectedIndex; CPTabViewType type; - + id delegate; unsigned delegateSelectors; } @@ -59,61 +59,61 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; if (self) { items = [CPArray array]; - + tabs = [[CPSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 0, HEIGHT_OF_SEGMENTED_CONTROL)]; [tabs setHitTests:NO]; - + box = [[CPBox alloc] initWithFrame:CGRectMake(0, HEIGHT_OF_SEGMENTED_CONTROL / 2, CGRectGetWidth(aFrame), CGRectGetHeight(aFrame) - HEIGHT_OF_SEGMENTED_CONTROL)]; - + selectedIndex = CPNotFound; - + [self setTabViewType:CPTopTabsBezelBorder]; [self setBackgroundColor:[CPColor colorWithCalibratedWhite:0.95 alpha:1.0]]; - + [self addSubview:box]; [self addSubview:tabs]; } return self; } -/*! - Override CPView message to allow to set the autoresizing mask +/*! + Override CPView message to allow to set the autoresizing mask of the tabview and it's subview - + @param unsigned aMask the autoresizing mask */ - (void)setAutoresizingMask:(unsigned)aMask { [box setAutoresizingMask:aMask]; - + [super setAutoresizingMask:aMask]; } -/*! +/*! Override the CPView method in order to allow to reposition the segmented control - + @param aFrame the new frame */ - (void)setFrame:(CGRect)aFrame { [super setFrame:aFrame]; - + [self _repositionTabs]; } -/*! +/*! Override the CPView method in order to allow to reposition the segmented control - + @param someBounds the new bounds */ - (void)setBounds:(CGRect)someBounds { [super setBounds:someBounds]; - + [self _repositionTabs]; } @@ -136,7 +136,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; - (void)insertTabViewItem:(CPTabViewItem)aTabViewItem atIndex:(unsigned)anIndex { [items insertObject:aTabViewItem atIndex:anIndex]; - + [self _updateItems]; [self _repositionTabs]; @@ -160,7 +160,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; [self _updateItems]; [self _repositionTabs]; - + if (delegateSelectors & CPTabViewDidChangeNumberOfTabViewItemsSelector) [delegate tabViewDidChangeNumberOfTabViewItems:self]; } @@ -221,7 +221,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; { if ([items count] === 0) return; // throw? - + [self selectTabViewItemAtIndex:0]; } @@ -233,7 +233,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; { if ([items count] === 0) return; // throw? - + [self selectTabViewItemAtIndex:[items count] - 1]; } @@ -245,12 +245,13 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; { if (selectedIndex === CPNotFound) return; - + var nextIndex = selectedIndex + 1; - + if (nextIndex === [items count]) - return; // does nothing. According to spec at (http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSTabView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSTabView/selectNextTabViewItem:) - + // does nothing. According to spec at (http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSTabView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSTabView/selectNextTabViewItem:) + return; + [self selectTabViewItemAtIndex:nextIndex]; } @@ -262,12 +263,12 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; { if (selectedIndex === CPNotFound) return; - + var previousIndex = selectedIndex - 1; if (previousIndex < 0) return; // does nothing. See above. - + [self selectTabViewItemAtIndex:previousIndex]; } @@ -290,18 +291,18 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; if (anIndex === selectedIndex) return; - + var aTabViewItem = [self tabViewItemAtIndex:anIndex]; - + if ((delegateSelectors & CPTabViewShouldSelectTabViewItemSelector) && ![delegate tabView:self shouldSelectTabViewItem:aTabViewItem]) return; - + if (delegateSelectors & CPTabViewWillSelectTabViewItemSelector) [delegate tabView:self willSelectTabViewItem:aTabViewItem]; - + [tabs selectSegmentWithTag:anIndex]; [self _setSelectedIndex:anIndex]; - + if (delegateSelectors & CPTabViewDidSelectTabViewItemSelector) [delegate tabView:self didSelectTabViewItem:aTabViewItem]; } @@ -323,17 +324,17 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; { if (type === aTabViewType) return; - + if ((type === CPTopTabsBezelBorder || type === CPBottomTabsBezelBorder) && (aTabViewType !== CPTopTabsBezelBorder && aTabViewType !== CPBottomTabsBezelBorder)) [tabs removeFromSuperview]; - + if ((type === CPNoTabsBezelBorder || type === CPNoTabsLineBorder || type === CPNoTabsNoBorder) && (aTabViewType !== CPNoTabsBezelBorder && aTabViewType !== CPNoTabsBezelBorder && aTabViewType !== CPNoTabsNoBorder)) [self addSubview:tabs]; - + type = aTabViewType; - + switch (type) { case CPTopTabsBezelBorder: @@ -400,7 +401,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; - (void)mouseDown:(CPEvent)anEvent { var segmentIndex = [tabs testSegment:[tabs convertPoint:[anEvent locationInWindow] fromView:nil]]; - + if (segmentIndex != CPNotFound) { [self selectTabViewItemAtIndex:segmentIndex]; @@ -412,7 +413,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; { var horizontalCenterOfSelf = CGRectGetWidth([self bounds]) / 2, verticalCenterOfTabs = CGRectGetHeight([tabs bounds]) / 2; - + if (type === CPBottomTabsBezelBorder) [tabs setCenter:CGPointMake(horizontalCenterOfSelf, CGRectGetHeight([self bounds]) - verticalCenterOfTabs)]; else @@ -422,7 +423,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; - (void)_setSelectedIndex:(CPNumber)index { selectedIndex = index; - + [box setContentView:[[items objectAtIndex:selectedIndex] view]]; } @@ -475,7 +476,7 @@ var CPTabViewItemsKey = "CPTabViewItemsKey", - (void)encodeWithCoder:(CPCoder)aCoder { [super encodeWithCoder:aCoder]; - + [aCoder encodeObject:items forKey:CPTabViewItemsKey];; [aCoder encodeObject:[self selectedTabViewItem] forKey:CPTabViewSelectedItemKey]; From 3d82203893b3eaa2b196101a4ba6f1a144f62cd7 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Tue, 19 Oct 2010 22:53:52 +0200 Subject: [PATCH 3/5] remove 'drunk' code and simply use resizing masks --- AppKit/CPTabView.j | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/AppKit/CPTabView.j b/AppKit/CPTabView.j index 46cf5b4cd..31c6d1c51 100644 --- a/AppKit/CPTabView.j +++ b/AppKit/CPTabView.j @@ -73,50 +73,13 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24; [self addSubview:box]; [self addSubview:tabs]; + + [box setAutoresizingMask:CPViewWidthSizable]; + [tabs setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin]; } return self; } -/*! - Override CPView message to allow to set the autoresizing mask - of the tabview and it's subview - - @param unsigned aMask the autoresizing mask -*/ -- (void)setAutoresizingMask:(unsigned)aMask -{ - [box setAutoresizingMask:aMask]; - - [super setAutoresizingMask:aMask]; -} - - -/*! - Override the CPView method in order - to allow to reposition the segmented control - - @param aFrame the new frame -*/ -- (void)setFrame:(CGRect)aFrame -{ - [super setFrame:aFrame]; - - [self _repositionTabs]; -} - -/*! - Override the CPView method in order - to allow to reposition the segmented control - - @param someBounds the new bounds -*/ -- (void)setBounds:(CGRect)someBounds -{ - [super setBounds:someBounds]; - - [self _repositionTabs]; -} - // Adding and Removing Tabs /*! Adds a CPTabViewItem to the tab view. From 48ebd2e954e79c142ff203c70d6c01dda3ea065b Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Tue, 19 Oct 2010 23:46:03 +0200 Subject: [PATCH 4/5] add tests for CPTabView --- Tests/AppKit/CPTabViewTest.j | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Tests/AppKit/CPTabViewTest.j diff --git a/Tests/AppKit/CPTabViewTest.j b/Tests/AppKit/CPTabViewTest.j new file mode 100644 index 000000000..3496bf6c0 --- /dev/null +++ b/Tests/AppKit/CPTabViewTest.j @@ -0,0 +1,65 @@ +@import +@import + + + +@implementation CPTabView (TEST) + +- (CPSegmentedControl)tabs +{ + return tabs; +} + +@end + + +@implementation CPTabViewTest : OJTestCase +{ + CPTabView _tableView; + CPTabViewItem _tabItem1; + CPTabViewItem _tabItem2; +} + +- (void)setUp +{ + _tabView = [[CPTabView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]; + + _tabItem1 = [[CPTabViewItem alloc] initWithIdentifier:@"id1"]; + [_tabItem1 setLabel:@"Item A"]; + [_tabItem1 setView:[[CPView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]] + + _tabItem2 = [[CPTabViewItem alloc] initWithIdentifier:@"id2"]; + [_tabItem2 setLabel:@"Item B"]; + [_tabItem2 setView:[[CPView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]] + + [_tabView addTabViewItem:_tabItem1]; + [_tabView addTabViewItem:_tabItem2]; +} + +- (void)testCreate +{ + [self assertNotNull:_tabView]; + +} + +- (void)testMiddle +{ + var tabs = [_tabView tabs]; + [self assert:([_tabView frameSize].width / 2) equals:CPRectGetMidX([tabs frame])]; +} + +- (void)testMiddleAfterMoveFrame +{ + var tabs = [_tabView tabs]; + [_tabView setFrame:CPRectMake(10, 100, 1000, 200)]; + [self assert:([_tabView frameSize].width / 2) equals:CPRectGetMidX([tabs frame])]; +} + +- (void)testMiddleAfterMoveBound +{ + var tabs = [_tabView tabs]; + [_tabView setBounds:CPRectMake(12, 13, 20, 300)]; + [self assert:([_tabView boundsSize].width / 2) equals:CPRectGetMidX([tabs frame])]; +} + +@end \ No newline at end of file From 8ead5f63dadd135fc8818845a3d2f57b31febd99 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Thu, 28 Oct 2010 11:01:38 +0200 Subject: [PATCH 5/5] fix CPtabViewTest --- Tests/AppKit/CPTabViewTest.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/AppKit/CPTabViewTest.j b/Tests/AppKit/CPTabViewTest.j index 3496bf6c0..9bba62b40 100644 --- a/Tests/AppKit/CPTabViewTest.j +++ b/Tests/AppKit/CPTabViewTest.j @@ -58,8 +58,8 @@ - (void)testMiddleAfterMoveBound { var tabs = [_tabView tabs]; - [_tabView setBounds:CPRectMake(12, 13, 20, 300)]; - [self assert:([_tabView boundsSize].width / 2) equals:CPRectGetMidX([tabs frame])]; + [_tabView setBounds:CPRectMake(100, 100, 20, 300)]; + [self assert:([tabs boundsSize].width / 2) equals:CPRectGetMidX([tabs bounds])]; } @end \ No newline at end of file