@@ -66,7 +66,7 @@ - (NSRect)cellFrameAtIndex:(NSInteger)index {
66
66
NSRect rect;
67
67
68
68
if (index > -1 && index < [_cellFrames count ]) {
69
- rect = [[_cellFrames objectAtIndex: index ] rectValue ];
69
+ rect = [[_cellFrames objectAtIndex: ( NSUInteger ) index ] rectValue ];
70
70
} else {
71
71
NSLog (@" cellFrameAtIndex: Invalid index (%ld )" , (long )index );
72
72
rect = NSZeroRect ;
@@ -106,16 +106,17 @@ - (void)setSelectedCell:(PSMTabBarCell *)cell {
106
106
[cell setTabState: PSMTab_SelectedMask];
107
107
108
108
if (![cell isInOverflowMenu ]) {
109
- NSInteger cellIndex = [cells indexOfObject: cell];
110
-
111
- if (cellIndex > 0 ) {
112
- nextCell = [cells objectAtIndex: cellIndex - 1 ];
113
- [nextCell setTabState: [nextCell tabState ] | PSMTab_RightIsSelectedMask];
114
- }
109
+ NSUInteger cellIndex = [cells indexOfObject: cell];
110
+ if (cellIndex != NSNotFound ) {
111
+ if (cellIndex > 0 ) {
112
+ nextCell = [cells objectAtIndex: cellIndex - 1 ];
113
+ [nextCell setTabState: [nextCell tabState ] | PSMTab_RightIsSelectedMask];
114
+ }
115
115
116
- if (cellIndex < [cells count ] - 1 ) {
117
- nextCell = [cells objectAtIndex: cellIndex + 1 ];
118
- [nextCell setTabState: [nextCell tabState ] | PSMTab_LeftIsSelectedMask];
116
+ if (cellIndex < [cells count ] - 1 ) {
117
+ nextCell = [cells objectAtIndex: cellIndex + 1 ];
118
+ [nextCell setTabState: [nextCell tabState ] | PSMTab_LeftIsSelectedMask];
119
+ }
119
120
}
120
121
}
121
122
}
@@ -129,7 +130,7 @@ - (void)setSelectedCell:(PSMTabBarCell *)cell {
129
130
130
131
- (void )layoutCells {
131
132
NSArray *cells = [_control cells ];
132
- NSInteger cellCount = [cells count ];
133
+ NSUInteger cellCount = [cells count ];
133
134
134
135
// make sure all of our tabs are accounted for before updating
135
136
if ([[_control tabView ] numberOfTabViewItems ] != cellCount) {
@@ -152,20 +153,21 @@ - (void)layoutCells {
152
153
*/
153
154
- (NSInteger )_shrinkWidths : (NSMutableArray *)newWidths towardMinimum : (NSInteger )minimum withAvailableWidth : (CGFloat )availableWidth {
154
155
BOOL changed = NO ;
155
- NSInteger count = [newWidths count ];
156
+ NSUInteger count = [newWidths count ];
156
157
NSInteger totalWidths = [[newWidths valueForKeyPath: @" @sum.intValue" ] integerValue ];
157
158
NSInteger originalTotalWidths = totalWidths;
158
159
159
160
do {
160
161
changed = NO ;
161
162
162
- for (NSInteger q = (count - 1 ); q >= 0 ; q--) {
163
- CGFloat cellWidth = [[newWidths objectAtIndex: q] doubleValue ];
163
+ for (NSUInteger q = count; q > 0 ; q--) {
164
+ NSUInteger index = q - 1 ;
165
+ CGFloat cellWidth = [[newWidths objectAtIndex: index ] doubleValue ];
164
166
if (cellWidth - 1 >= minimum) {
165
167
cellWidth--;
166
168
totalWidths--;
167
169
168
- [newWidths replaceObjectAtIndex: q
170
+ [newWidths replaceObjectAtIndex: index
169
171
withObject: [NSNumber numberWithDouble: cellWidth]];
170
172
171
173
changed = YES ;
@@ -188,9 +190,9 @@ - (NSInteger)_shrinkWidths:(NSMutableArray *)newWidths towardMinimum:(NSInteger)
188
190
*/
189
191
static NSInteger potentialMinimumForArray (NSArray *array, NSInteger minimum){
190
192
NSInteger runningTotal = 0 ;
191
- NSInteger count = [array count ];
193
+ NSUInteger count = [array count ];
192
194
193
- for (NSInteger i = 0 ; i < count; i++) {
195
+ for (NSUInteger i = 0 ; i < count; i++) {
194
196
NSInteger currentValue = [[array objectAtIndex: i] integerValue ];
195
197
runningTotal += MIN (currentValue, minimum);
196
198
}
@@ -208,7 +210,7 @@ static NSInteger potentialMinimumForArray(NSArray *array, NSInteger minimum){
208
210
*/
209
211
210
212
- (NSArray *)_generateWidthsFromCells : (NSArray *)cells {
211
- NSInteger cellCount = [cells count ], i, numberOfVisibleCells = ([_control orientation ] == PSMTabBarHorizontalOrientation) ? 1 : 0 ;
213
+ NSUInteger cellCount = [cells count ], i, numberOfVisibleCells = ([_control orientation ] == PSMTabBarHorizontalOrientation) ? 1 : 0 ;
212
214
NSMutableArray *newWidths = [NSMutableArray arrayWithCapacity: cellCount];
213
215
id <PSMTabStyle> style = [_control style ];
214
216
CGFloat availableWidth = [_control availableCellWidth ], currentOrigin = 0 , totalOccupiedWidth = 0.0 , width;
@@ -248,12 +250,12 @@ - (NSArray *)_generateWidthsFromCells:(NSArray *)cells {
248
250
249
251
// If we're not going to use the overflow menu, cram all the tab cells into the bar regardless of minimum width
250
252
if (![_control useOverflowMenu ]) {
251
- NSInteger j, averageWidth = (availableWidth / cellCount);
253
+ NSInteger averageWidth = (availableWidth / cellCount);
252
254
253
255
numberOfVisibleCells = cellCount;
254
256
[newWidths removeAllObjects ];
255
257
256
- for (j = 0 ; j < cellCount; j++) {
258
+ for (NSUInteger j = 0 ; j < cellCount; j++) {
257
259
CGFloat desiredWidth = [[cells objectAtIndex: j] desiredWidthOfCell ];
258
260
[newWidths addObject: [NSNumber numberWithDouble: (desiredWidth < averageWidth && [_control sizeCellsToFit ]) ? desiredWidth : averageWidth]];
259
261
}
@@ -323,11 +325,10 @@ - (NSArray *)_generateWidthsFromCells:(NSArray *)cells {
323
325
*/
324
326
NSInteger leftoverWidth = availableWidth - totalOccupiedWidth;
325
327
if (leftoverWidth > 0 ) {
326
- NSInteger q;
327
- for (q = numberOfVisibleCells - 1 ; q >= 0 ; q--) {
328
- NSInteger desiredAddition = (NSInteger )leftoverWidth / (q + 1 );
329
- NSInteger newCellWidth = (NSInteger )[[newWidths objectAtIndex: q] doubleValue ] + desiredAddition;
330
- [newWidths replaceObjectAtIndex: q withObject: [NSNumber numberWithDouble: newCellWidth]];
328
+ for (NSUInteger q = numberOfVisibleCells; q > 0 ; q--) {
329
+ NSInteger desiredAddition = leftoverWidth / (NSInteger )q;
330
+ NSInteger newCellWidth = (NSInteger )[[newWidths objectAtIndex: q-1 ] doubleValue ] + desiredAddition;
331
+ [newWidths replaceObjectAtIndex: q-1 withObject: [NSNumber numberWithDouble: newCellWidth]];
331
332
leftoverWidth -= desiredAddition;
332
333
totalOccupiedWidth += desiredAddition;
333
334
}
@@ -342,11 +343,10 @@ - (NSArray *)_generateWidthsFromCells:(NSArray *)cells {
342
343
343
344
// stretch - distribute leftover room among cells, since we can't add this cell
344
345
NSInteger leftoverWidth = availableWidth - totalOccupiedWidth;
345
- NSInteger q;
346
- for (q = i - 1 ; q >= 0 ; q--) {
347
- NSInteger desiredAddition = (NSInteger )leftoverWidth / (q + 1 );
348
- NSInteger newCellWidth = (NSInteger )[[newWidths objectAtIndex: q] doubleValue ] + desiredAddition;
349
- [newWidths replaceObjectAtIndex: q withObject: [NSNumber numberWithDouble: newCellWidth]];
346
+ for (NSUInteger q = i; q > 0 ; q--) {
347
+ NSInteger desiredAddition = leftoverWidth / (NSInteger )q;
348
+ NSInteger newCellWidth = (NSInteger )[[newWidths objectAtIndex: q-1 ] doubleValue ] + desiredAddition;
349
+ [newWidths replaceObjectAtIndex: q-1 withObject: [NSNumber numberWithDouble: newCellWidth]];
350
350
leftoverWidth -= desiredAddition;
351
351
}
352
352
@@ -468,15 +468,16 @@ - (NSArray *)_generateWidthsFromCells:(NSArray *)cells {
468
468
*/
469
469
470
470
- (void )_setupCells : (NSArray *)cells withWidths : (NSArray *)widths {
471
- NSInteger i, tabState, cellCount = [cells count ];
471
+ NSInteger tabState;
472
+ NSUInteger cellCount = [cells count ];
472
473
NSRect cellRect = [_control genericCellRect ];
473
474
PSMTabBarCell *cell;
474
475
NSTabViewItem *selectedTabViewItem = [[_control tabView ] selectedTabViewItem ];
475
476
NSMenuItem *menuItem;
476
477
477
478
[_overflowMenu release ], _overflowMenu = nil ;
478
479
479
- for (i = 0 ; i < cellCount; i++) {
480
+ for (NSUInteger i = 0 ; i < cellCount; i++) {
480
481
cell = [cells objectAtIndex: i];
481
482
482
483
if (i < [widths count ]) {
0 commit comments