summaryrefslogtreecommitdiff
path: root/frontends/cocoa/PSMTabBarControl/PSMTabBarControl.m
diff options
context:
space:
mode:
authorSven Weidauer <sven@5sw.de>2017-06-05 10:47:34 +0200
committerSven Weidauer <sven@5sw.de>2017-06-05 10:51:19 +0200
commit3ee40a10b123c36be3e29602767840a7a71aaafa (patch)
tree64123d0bf6a6cf5a5a4c1fd8349756db68e09483 /frontends/cocoa/PSMTabBarControl/PSMTabBarControl.m
parentce4e059ea67cee7f35b4b810a4387f343fa74650 (diff)
downloadnetsurf-3ee40a10b123c36be3e29602767840a7a71aaafa.tar.gz
netsurf-3ee40a10b123c36be3e29602767840a7a71aaafa.tar.bz2
Fix up cocoa frontend.
- Convert to ARC - Fix crash due to endless responder chain recursion - Update makefile to find openssl installed via home-brew - Fix most compiler warnings
Diffstat (limited to 'frontends/cocoa/PSMTabBarControl/PSMTabBarControl.m')
-rw-r--r--frontends/cocoa/PSMTabBarControl/PSMTabBarControl.m145
1 files changed, 36 insertions, 109 deletions
diff --git a/frontends/cocoa/PSMTabBarControl/PSMTabBarControl.m b/frontends/cocoa/PSMTabBarControl/PSMTabBarControl.m
index cb0e0342c..01df769f1 100644
--- a/frontends/cocoa/PSMTabBarControl/PSMTabBarControl.m
+++ b/frontends/cocoa/PSMTabBarControl/PSMTabBarControl.m
@@ -17,52 +17,15 @@
#import "PSMTabDragAssistant.h"
#import "PSMTabBarController.h"
-@interface PSMTabBarControl (Private)
-
-// constructor/destructor
-- (void)initAddedProperties;
-
-// accessors
-- (NSEvent *)lastMouseDownEvent;
-- (void)setLastMouseDownEvent:(NSEvent *)event;
-
-// contents
-- (void)addTabViewItem:(NSTabViewItem *)item;
-- (void)removeTabForCell:(PSMTabBarCell *)cell;
-
-// draw
-- (void)update;
-- (void)update:(BOOL)animate;
-- (void)_setupTrackingRectsForCell:(PSMTabBarCell *)cell;
-- (void)_positionOverflowMenu;
-- (void)_checkWindowFrame;
-
-// actions
-- (void)overflowMenuAction:(id)sender;
-- (void)closeTabClick:(id)sender;
-- (void)tabClick:(id)sender;
-- (void)tabNothing:(id)sender;
-
-// notification handlers
-- (void)frameDidChange:(NSNotification *)notification;
-- (void)windowDidMove:(NSNotification *)aNotification;
-- (void)windowDidUpdate:(NSNotification *)notification;
-
-// NSTabView delegate
-- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
-- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem;
-- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem;
-- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)tabView;
-
-// archiving
-- (void)encodeWithCoder:(NSCoder *)aCoder;
-- (id)initWithCoder:(NSCoder *)aDecoder;
-
-// convenience
-- (void)_bindPropertiesForCell:(PSMTabBarCell *)cell andTabViewItem:(NSTabViewItem *)item;
-- (id)cellForPoint:(NSPoint)point cellFrame:(NSRectPointer)outFrame;
-
-- (void)_animateCells:(NSTimer *)timer;
+#import "PSMTabBarControl+Private.h"
+
+@protocol PSMTabBarItem
+@optional
+- (BOOL)isProcessing;
+
+@optional
+- (int)objectCount;
+
@end
@implementation PSMTabBarControl
@@ -202,36 +165,22 @@
//stop any animations that may be running
[_animationTimer invalidate];
- [_animationTimer release]; _animationTimer = nil;
[_showHideAnimationTimer invalidate];
- [_showHideAnimationTimer release]; _showHideAnimationTimer = nil;
//Also unwind the spring, if it's wound.
[_springTimer invalidate];
- [_springTimer release]; _springTimer = nil;
//unbind all the items to prevent crashing
//not sure if this is necessary or not
// http://code.google.com/p/maccode/issues/detail?id=35
- NSEnumerator *enumerator = [[[_cells copy] autorelease] objectEnumerator];
+ NSEnumerator *enumerator = [[_cells copy] objectEnumerator];
PSMTabBarCell *nextCell;
while((nextCell = [enumerator nextObject])) {
[self removeTabForCell:nextCell];
}
- [_overflowPopUpButton release];
- [_cells release];
- [_controller release];
- [tabView release];
- [_addTabButton release];
- [partnerView release];
- [_lastMouseDownEvent release];
- [style release];
-
[self unregisterDraggedTypes];
-
- [super dealloc];
}
- (void)awakeFromNib {
@@ -256,7 +205,7 @@
if(_showHideAnimationTimer) {
[_showHideAnimationTimer invalidate];
- [_showHideAnimationTimer release]; _showHideAnimationTimer = nil;
+ _showHideAnimationTimer = nil;
}
if(aWindow) {
@@ -283,8 +232,6 @@
}
- (void)setLastMouseDownEvent:(NSEvent *)event {
- [event retain];
- [_lastMouseDownEvent release];
_lastMouseDownEvent = event;
}
@@ -310,8 +257,6 @@
}
- (void)setTabView:(NSTabView *)view {
- [view retain];
- [tabView release];
tabView = view;
}
@@ -325,8 +270,6 @@
- (void)setStyle:(id <PSMTabStyle>)newStyle {
if(style != newStyle) {
- [style autorelease];
- style = [newStyle retain];
// restyle add tab button
if(_addTabButton) {
@@ -359,7 +302,6 @@
id <PSMTabStyle> newStyle = [[styleClass alloc] init];
[self setStyle:newStyle];
- [newStyle release];
}
- (PSMTabBarOrientation)orientation {
@@ -568,7 +510,6 @@
// add to collection
[_cells addObject:cell];
- [cell release];
if([_cells count] == (NSUInteger)[tabView numberOfTabViewItems]) {
[self update]; // don't update unless all are accounted for!
}
@@ -822,9 +763,8 @@
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithDouble:myOriginalOrigin], @"myOriginalOrigin", [NSNumber numberWithDouble:partnerOriginalOrigin], @"partnerOriginalOrigin", [NSNumber numberWithDouble:myOriginalSize], @"myOriginalSize", [NSNumber numberWithDouble:partnerOriginalSize], @"partnerOriginalSize", [NSNumber numberWithDouble:myTargetOrigin], @"myTargetOrigin", [NSNumber numberWithDouble:partnerTargetOrigin], @"partnerTargetOrigin", [NSNumber numberWithDouble:myTargetSize], @"myTargetSize", [NSNumber numberWithDouble:partnerTargetSize], @"partnerTargetSize", nil];
if(_showHideAnimationTimer) {
[_showHideAnimationTimer invalidate];
- [_showHideAnimationTimer release];
}
- _showHideAnimationTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 / 30.0) target:self selector:@selector(animateShowHide:) userInfo:userInfo repeats:YES] retain];
+ _showHideAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / 30.0) target:self selector:@selector(animateShowHide:) userInfo:userInfo repeats:YES];
}
- (void)animateShowHide:(NSTimer *)timer {
@@ -888,7 +828,7 @@
}
[_showHideAnimationTimer invalidate];
- [_showHideAnimationTimer release]; _showHideAnimationTimer = nil;
+ _showHideAnimationTimer = nil;
}
[[self window] display];
}
@@ -906,8 +846,6 @@
}
- (void)setPartnerView:(id)view {
- [partnerView release];
- [view retain];
partnerView = view;
}
@@ -949,10 +887,8 @@
[_overflowPopUpButton setHidden:(overflowMenu == nil)];
[_overflowPopUpButton setMenu:overflowMenu];
- if(_animationTimer) {
[_animationTimer invalidate];
- [_animationTimer release]; _animationTimer = nil;
- }
+ _animationTimer = nil;
if(animate) {
NSMutableArray *targetFrames = [NSMutableArray arrayWithCapacity:[_cells count]];
@@ -969,12 +905,11 @@
NSAnimation *animation = [[NSAnimation alloc] initWithDuration:0.50 animationCurve:NSAnimationEaseInOut];
[animation setAnimationBlockingMode:NSAnimationNonblocking];
[animation startAnimation];
- _animationTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 / 30.0
+ _animationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 / 30.0
target:self
selector:@selector(_animateCells:)
userInfo:[NSArray arrayWithObjects:targetFrames, animation, nil]
- repeats:YES] retain];
- [animation release];
+ repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSEventTrackingRunLoopMode];
[self _animateCells:_animationTimer];
} else {
@@ -1067,7 +1002,7 @@
}
[_animationTimer invalidate];
- [_animationTimer release]; _animationTimer = nil;
+ _animationTimer = nil;
for(NSUInteger i = 0; i < cellCount; i++) {
currentCell = [_cells objectAtIndex:i];
@@ -1143,7 +1078,7 @@
if([window showsResizeIndicator] && NSIntersectsRect([self frame], resizeWidgetFrame)) {
//the resize widgets are larger on metal windows
- _resizeAreaCompensation = [window styleMask] & NSTexturedBackgroundWindowMask ? 20 : 8;
+ _resizeAreaCompensation = [window styleMask] & NSWindowStyleMaskTexturedBackground ? 20 : 8;
} else {
_resizeAreaCompensation = 0;
}
@@ -1183,7 +1118,7 @@
if(overClose &&
![self disableTabClose] &&
![cell isCloseButtonSuppressed] &&
- ([self allowsBackgroundTabClosing] || [[cell representedObject] isEqualTo:[tabView selectedTabViewItem]] || [theEvent modifierFlags] & NSCommandKeyMask)) {
+ ([self allowsBackgroundTabClosing] || [[cell representedObject] isEqualTo:[tabView selectedTabViewItem]] || [theEvent modifierFlags] & NSEventModifierFlagCommand)) {
[cell setCloseButtonOver:NO];
[cell setCloseButtonPressed:YES];
_closeClicked = YES;
@@ -1269,9 +1204,9 @@
NSRect iconRect = [mouseDownCell closeButtonRectForFrame:mouseDownCellFrame];
if((NSMouseInRect(mousePt, iconRect, [self isFlipped])) && ![self disableTabClose] && ![cell isCloseButtonSuppressed] && [mouseDownCell closeButtonPressed]) {
- if(([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0) {
+ if(([[NSApp currentEvent] modifierFlags] & NSEventModifierFlagOption) != 0) {
//If the user is holding Option, close all other tabs
- NSEnumerator *enumerator = [[[[self cells] copy] autorelease] objectEnumerator];
+ NSEnumerator *enumerator = [[[self cells] copy] objectEnumerator];
PSMTabBarCell *otherCell;
while((otherCell = [enumerator nextObject])) {
@@ -1386,18 +1321,18 @@
//If the user has dragged to a different tab, reset the timer.
if(_tabViewItemWithSpring != [cell representedObject]) {
[_springTimer invalidate];
- [_springTimer release]; _springTimer = nil;
+ _springTimer = nil;
_tabViewItemWithSpring = [cell representedObject];
}
if(!_springTimer) {
//Finder's default delay time, as of Tiger, is 668 ms. If the user has never changed it, there's no setting in its defaults, so we default to that amount.
- NSNumber *delayNumber = [(NSNumber *)CFPreferencesCopyAppValue((CFStringRef)@"SpringingDelayMilliseconds", (CFStringRef)@"com.apple.finder") autorelease];
+ NSNumber *delayNumber = (__bridge_transfer NSNumber *)CFPreferencesCopyAppValue((CFStringRef)@"SpringingDelayMilliseconds", (CFStringRef)@"com.apple.finder");
NSTimeInterval delaySeconds = delayNumber ?[delayNumber doubleValue] / 1000.0 : 0.668;
- _springTimer = [[NSTimer scheduledTimerWithTimeInterval:delaySeconds
+ _springTimer = [NSTimer scheduledTimerWithTimeInterval:delaySeconds
target:self
selector:@selector(fireSpring:)
userInfo:sender
- repeats:NO] retain];
+ repeats:NO];
}
return NSDragOperationCopy;
}
@@ -1407,7 +1342,7 @@
- (void)draggingExited:(id <NSDraggingInfo>)sender {
[_springTimer invalidate];
- [_springTimer release]; _springTimer = nil;
+ _springTimer = nil;
[[PSMTabDragAssistant sharedDragAssistant] draggingExitedTabBar:self];
}
@@ -1447,7 +1382,7 @@
_tabViewItemWithSpring = nil;
[_springTimer invalidate];
- [_springTimer release]; _springTimer = nil;
+ _springTimer = nil;
}
#pragma mark -
@@ -1460,7 +1395,6 @@
- (void)closeTabClick:(id)sender {
NSTabViewItem *item = [sender representedObject];
- [sender retain];
if(([_cells count] == 1) && (![self canCloseOnlyTab])) {
return;
}
@@ -1473,11 +1407,8 @@
}
}
- [item retain];
[tabView removeTabViewItem:item];
- [item release];
- [sender release];
}
- (void)tabClick:(id)sender {
@@ -1633,16 +1564,12 @@
[aTabView setDelegate:nil];
// move it all around first
- [tabViewItem retain];
- [thisCell retain];
[aTabView removeTabViewItem:tabViewItem];
[aTabView insertTabViewItem:tabViewItem atIndex:0];
[_cells removeObjectAtIndex:tabIndex];
[_cells insertObject:thisCell atIndex:0];
[thisCell setIsInOverflowMenu:NO]; //very important else we get a fun recursive loop going
[[_cells objectAtIndex:[_cells count] - 1] setIsInOverflowMenu:YES]; //these 2 lines are pretty uncool and this logic needs to be updated
- [thisCell release];
- [tabViewItem release];
[aTabView setDelegate:tempDelegate];
@@ -1677,7 +1604,7 @@
- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)aTabView {
NSArray *tabItems = [tabView tabViewItems];
// go through cells, remove any whose representedObjects are not in [tabView tabViewItems]
- NSEnumerator *e = [[[_cells copy] autorelease] objectEnumerator];
+ NSEnumerator *e = [[_cells copy] objectEnumerator];
PSMTabBarCell *cell;
while((cell = [e nextObject])) {
//remove the observer binding
@@ -1769,11 +1696,11 @@
[self setPostsFrameChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(frameDidChange:) name:NSViewFrameDidChangeNotification object:self];
if ([aDecoder allowsKeyedCoding]) {
- _cells = [[aDecoder decodeObjectForKey:@"PSMcells"] retain];
- tabView = [[aDecoder decodeObjectForKey:@"PSMtabView"] retain];
- _overflowPopUpButton = [[aDecoder decodeObjectForKey:@"PSMoverflowPopUpButton"] retain];
- _addTabButton = [[aDecoder decodeObjectForKey:@"PSMaddTabButton"] retain];
- style = [[aDecoder decodeObjectForKey:@"PSMstyle"] retain];
+ _cells = [aDecoder decodeObjectForKey:@"PSMcells"] ;
+ tabView = [aDecoder decodeObjectForKey:@"PSMtabView"] ;
+ _overflowPopUpButton = [aDecoder decodeObjectForKey:@"PSMoverflowPopUpButton"] ;
+ _addTabButton = [aDecoder decodeObjectForKey:@"PSMaddTabButton"] ;
+ style = [aDecoder decodeObjectForKey:@"PSMstyle"] ;
_orientation = (PSMTabBarOrientation)[aDecoder decodeIntegerForKey:@"PSMorientation"];
_canCloseOnlyTab = [aDecoder decodeBoolForKey:@"PSMcanCloseOnlyTab"];
_disableTabClose = [aDecoder decodeBoolForKey:@"PSMdisableTabClose"];
@@ -1788,13 +1715,13 @@
_cellOptimumWidth = [aDecoder decodeIntegerForKey:@"PSMcellOptimumWidth"];
_currentStep = [aDecoder decodeIntegerForKey:@"PSMcurrentStep"];
_isHidden = [aDecoder decodeBoolForKey:@"PSMisHidden"];
- partnerView = [[aDecoder decodeObjectForKey:@"PSMpartnerView"] retain];
+ partnerView = [aDecoder decodeObjectForKey:@"PSMpartnerView"] ;
_awakenedFromNib = [aDecoder decodeBoolForKey:@"PSMawakenedFromNib"];
- _lastMouseDownEvent = [[aDecoder decodeObjectForKey:@"PSMlastMouseDownEvent"] retain];
+ _lastMouseDownEvent = [aDecoder decodeObjectForKey:@"PSMlastMouseDownEvent"] ;
_useOverflowMenu = [aDecoder decodeBoolForKey:@"PSMuseOverflowMenu"];
_automaticallyAnimates = [aDecoder decodeBoolForKey:@"PSMautomaticallyAnimates"];
_alwaysShowActiveTab = [aDecoder decodeBoolForKey:@"PSMalwaysShowActiveTab"];
- delegate = [[aDecoder decodeObjectForKey:@"PSMdelegate"] retain];
+ delegate = [aDecoder decodeObjectForKey:@"PSMdelegate"] ;
}
}
[self setTarget:self];