mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +00:00
Previously, when changing the controlSize of a CPSegmentedControl, Cappuccino didn't have the theme to do that. Now, Cappuccino supports the controlSize small and mini. Aristo and Aristo2 have new attributes for that. The attribute theme "default-height" has been replaced by "min-size" and "max-size" (used everywhere else in Cappuccino). The CPSegmentedControl has now the theme attribute "nib2cib-adjustment-frame". This pull request fixed alignment issue when adding a CPSegmentedControl from xCode. In the method initWithCode, we didn't care about the divider thickness, now we do. This same method will also add leftovers pixel to have exactly the same size as in xCode. Leftovers pixels are here because FLOOR operation and size of the font. Manual test in Tests/Manual/CPSegmentedControlTest Manual test in Tests/Manual/Nib2CibAlignment
160 lines
4.0 KiB
Plaintext
160 lines
4.0 KiB
Plaintext
/*
|
|
* NSSegmentedControl.j
|
|
* nib2cib
|
|
*
|
|
* Created by Thomas Robinson.
|
|
* Copyright 2008, 280 North, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
@import <AppKit/CPSegmentedControl.j>
|
|
|
|
@import "NSCell.j"
|
|
|
|
@class Nib2Cib
|
|
|
|
|
|
@implementation CPSegmentedControl (CPCoding)
|
|
|
|
- (id)NS_initWithCoder:(CPCoder)aCoder
|
|
{
|
|
_segments = [];
|
|
_themeStates = [];
|
|
|
|
return [super NS_initWithCoder:aCoder];
|
|
}
|
|
|
|
- (void)NS_initWithCell:(NSCell)cell
|
|
{
|
|
[super NS_initWithCell:cell];
|
|
|
|
_segments = [cell segments];
|
|
_selectedSegment = [cell selectedSegment];
|
|
_segmentStyle = [cell segmentStyle];
|
|
_trackingMode = [cell trackingMode];
|
|
|
|
[self setValue:CPCenterTextAlignment forThemeAttribute:@"alignment"];
|
|
|
|
// HACK
|
|
for (var i = 0; i < _segments.length; i++)
|
|
{
|
|
_themeStates[i] = _segments[i].selected ? CPThemeStateSelected : CPThemeStateNormal;
|
|
[self tileWithChangedSegment:i];
|
|
}
|
|
|
|
[self setEnabled:[cell isEnabled]];
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation NSSegmentedControl : CPSegmentedControl
|
|
{
|
|
}
|
|
|
|
- (id)initWithCoder:(CPCoder)aCoder
|
|
{
|
|
self = [self NS_initWithCoder:aCoder];
|
|
|
|
if (self)
|
|
{
|
|
var cell = [aCoder decodeObjectForKey:@"NSCell"];
|
|
[self NS_initWithCell:cell];
|
|
[self _adjustNib2CibSize];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (Class)classForKeyedArchiver
|
|
{
|
|
return [CPSegmentedControl class];
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation NSSegmentedCell : NSActionCell
|
|
{
|
|
CPArray _segments @accessors(readonly, getter=segments);
|
|
int _selectedSegment @accessors(readonly, getter=selectedSegment);
|
|
int _segmentStyle @accessors(readonly, getter=segmentStyle);
|
|
CPSegmentSwitchTracking _trackingMode @accessors(readonly, getter=trackingMode);
|
|
}
|
|
|
|
- (id)initWithCoder:(CPCoder)aCoder
|
|
{
|
|
if (self = [super initWithCoder:aCoder])
|
|
{
|
|
_segments = [aCoder decodeObjectForKey:"NSSegmentImages"];
|
|
_selectedSegment = [aCoder decodeObjectForKey:"NSSelectedSegment"];
|
|
|
|
if (_selectedSegment === nil)
|
|
_selectedSegment = -1;
|
|
|
|
_segmentStyle = [aCoder decodeIntForKey:"NSSegmentStyle"];
|
|
_trackingMode = [aCoder decodeIntForKey:"NSTrackingMode"];
|
|
|
|
if (_trackingMode == CPSegmentSwitchTrackingSelectOne && _selectedSegment == -1)
|
|
_selectedSegment = 0;
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation _CPSegmentItem (CPCoding)
|
|
|
|
- (id)NS_initWithCoder:(CPCoder)aCoder
|
|
{
|
|
if (self = [super init])
|
|
{
|
|
image = [aCoder decodeObjectForKey:"NSSegmentItemImage"];
|
|
label = [aCoder decodeObjectForKey:"NSSegmentItemLabel"];
|
|
menu = [aCoder decodeObjectForKey:"NSSegmentItemMenu"];
|
|
selected = [aCoder decodeBoolForKey:"NSSegmentItemSelected"];
|
|
enabled = ![aCoder decodeBoolForKey:"NSSegmentItemDisabled"];
|
|
tag = [aCoder decodeIntForKey:"NSSegmentItemTag"];
|
|
width = [aCoder decodeIntForKey:"NSSegmentItemWidth"];
|
|
|
|
frame = CGRectMakeZero();
|
|
|
|
// NSSegmentItemImageScaling
|
|
// NSSegmentItemTooltip
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation NSSegmentItem : _CPSegmentItem
|
|
{
|
|
}
|
|
|
|
- (id)initWithCoder:(CPCoder)aCoder
|
|
{
|
|
return [self NS_initWithCoder:aCoder];
|
|
}
|
|
|
|
- (Class)classForKeyedArchiver
|
|
{
|
|
return [_CPSegmentItem class];
|
|
}
|
|
|
|
@end
|
|
|