mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-04 03:44:58 +00:00
Added missing license, added a lot more support for radio button attributes, included fix for issue #1190
This commit is contained in:
1 parent
0218246678
commit
93f36a2326
2 files changed
+93
-51
No files matched your search
@@ -30,14 +30,13 @@
|
||||
{
|
||||
// Unarchive the NS data
|
||||
var unarchiver = [[Nib2CibKeyedUnarchiver alloc] initForReadingWithData:data resourcesPath:aResourcesPath],
|
||||
objectData = [unarchiver decodeObjectForKey:@"IB.objectdata"];
|
||||
objectData = [unarchiver decodeObjectForKey:@"IB.objectdata"],
|
||||
objects = [unarchiver allObjects],
|
||||
count = [objects count];
|
||||
|
||||
// Perform a bit of post-processing on fonts and views since all CP views are flipped.
|
||||
// It's better to do this here (instead of say, in NSView::initWithCoder:),
|
||||
// because at this point all the objects an mappings are stabilized.
|
||||
var objects = [unarchiver allObjects],
|
||||
count = [objects count];
|
||||
|
||||
while (count--)
|
||||
{
|
||||
var object = objects[count];
|
||||
@@ -78,22 +77,12 @@
|
||||
var convertedData = [CPData data],
|
||||
archiver = [[CPKeyedArchiver alloc] initForWritingWithMutableData:convertedData];
|
||||
|
||||
[archiver setDelegate:self];
|
||||
[archiver encodeObject:objectData forKey:@"CPCibObjectDataKey"];
|
||||
[archiver finishEncoding];
|
||||
|
||||
return convertedData;
|
||||
}
|
||||
|
||||
// For some reason, occasionally an attempt is made to archive NSMatrix. That will fail, so prevent it here.
|
||||
- (id)archiver:(CPKeyedArchiver)archiver willEncodeObject:(id)object
|
||||
{
|
||||
if ([object isKindOfClass:[NSMatrix class]])
|
||||
return nil;
|
||||
else
|
||||
return object;
|
||||
}
|
||||
|
||||
- (void)replaceFontForObject:(id)object
|
||||
{
|
||||
if ([object respondsToSelector:@selector(font)] &&
|
||||
|
||||
+90
-37
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
* NSMatrix.j
|
||||
* nib2cib
|
||||
*
|
||||
* Created by Francisco Tolmasky.
|
||||
* 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 <Foundation/CPObject.j>
|
||||
@import <AppKit/CPView.j>
|
||||
@@ -9,62 +30,94 @@ var NSMatrixRadioModeMask = 0x40000000,
|
||||
NSMatrixDrawsBackgroundMask = 0x01000000;
|
||||
|
||||
|
||||
@implementation NSMatrix : CPObject
|
||||
{
|
||||
}
|
||||
@implementation NSMatrix : CPView
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
var view = [[CPView alloc] NS_initWithCoder:aCoder];
|
||||
return [self NS_initWithCoder:aCoder];
|
||||
}
|
||||
|
||||
var numberOfRows = [aCoder decodeIntForKey:@"NSNumRows"],
|
||||
numberOfColumns = [aCoder decodeIntForKey:@"NSNumCols"],
|
||||
cellSize = [aCoder decodeSizeForKey:@"NSCellSize"],
|
||||
intercellSpacing = [aCoder decodeSizeForKey:@"NSIntercellSpacing"],
|
||||
flags = [aCoder decodeIntForKey:@"NSMatrixFlags"],
|
||||
isRadioMode = flags & NSMatrixRadioModeMask,
|
||||
drawsBackground = flags & NSMatrixDrawsBackgroundMask,
|
||||
backgroundColor = [aCoder decodeObjectForKey:@"NSBackgroundColor"],
|
||||
cells = [aCoder decodeObjectForKey:@"NSCells"],
|
||||
selectedCell = [aCoder decodeObjectForKey:@"NSSelectedCell"];
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super NS_initWithCoder:aCoder];
|
||||
|
||||
if (isRadioMode)
|
||||
if (self)
|
||||
{
|
||||
var radioGroup = [CPRadioGroup new],
|
||||
frame = CGRectMake(0.0, 0.0, cellSize.width, cellSize.height);
|
||||
var numberOfRows = [aCoder decodeIntForKey:@"NSNumRows"],
|
||||
numberOfColumns = [aCoder decodeIntForKey:@"NSNumCols"],
|
||||
cellSize = [aCoder decodeSizeForKey:@"NSCellSize"],
|
||||
intercellSpacing = [aCoder decodeSizeForKey:@"NSIntercellSpacing"],
|
||||
flags = [aCoder decodeIntForKey:@"NSMatrixFlags"],
|
||||
isRadioMode = flags & NSMatrixRadioModeMask,
|
||||
drawsBackground = flags & NSMatrixDrawsBackgroundMask,
|
||||
backgroundColor = [aCoder decodeObjectForKey:@"NSBackgroundColor"],
|
||||
cells = [aCoder decodeObjectForKey:@"NSCells"],
|
||||
selectedCell = [aCoder decodeObjectForKey:@"NSSelectedCell"];
|
||||
|
||||
for (var rowIndex = 0; rowIndex < numberOfRows; ++rowIndex)
|
||||
if (isRadioMode)
|
||||
{
|
||||
frame.origin.x = 0;
|
||||
var radioGroup = [CPRadioGroup new],
|
||||
frame = CGRectMake(0.0, 0.0, cellSize.width, cellSize.height);
|
||||
|
||||
for (var columnIndex = 0; columnIndex < numberOfColumns; ++columnIndex)
|
||||
for (var rowIndex = 0; rowIndex < numberOfRows; ++rowIndex)
|
||||
{
|
||||
var cell = cells[rowIndex * numberOfColumns + columnIndex],
|
||||
cellView = [[CPRadio alloc] initWithFrame:frame radioGroup:radioGroup];
|
||||
frame.origin.x = 0;
|
||||
|
||||
[cellView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
[cellView setTitle:[cell title]];
|
||||
[cellView setBackgroundColor:[CPColor clearColor]]; // the IB default
|
||||
[cellView setFont:[cell font]];
|
||||
[cellView setObjectValue:[cell objectValue]];
|
||||
for (var columnIndex = 0; columnIndex < numberOfColumns; ++columnIndex)
|
||||
{
|
||||
var cell = cells[rowIndex * numberOfColumns + columnIndex],
|
||||
cellView = [[CPRadio alloc] initWithFrame:frame radioGroup:radioGroup cell:cell];
|
||||
|
||||
[view addSubview:cellView];
|
||||
[self addSubview:cellView];
|
||||
|
||||
NIB_CONNECTION_EQUIVALENCY_TABLE[[cell UID]] = cellView;
|
||||
NIB_CONNECTION_EQUIVALENCY_TABLE[[cell UID]] = cellView;
|
||||
|
||||
frame.origin.x = CGRectGetMaxX(frame) + intercellSpacing.width;
|
||||
frame.origin.x = CGRectGetMaxX(frame) + intercellSpacing.width;
|
||||
}
|
||||
|
||||
frame.origin.y = CGRectGetMaxY(frame) + intercellSpacing.height;
|
||||
}
|
||||
|
||||
frame.origin.y = CGRectGetMaxY(frame) + intercellSpacing.height;
|
||||
if (drawsBackground)
|
||||
[self setBackgroundColor:backgroundColor];
|
||||
|
||||
self.isa = [CPView class];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-radio group NSMatrix is not supported
|
||||
self = nil;
|
||||
}
|
||||
|
||||
if (drawsBackground)
|
||||
[view setBackgroundColor:backgroundColor];
|
||||
|
||||
NIB_CONNECTION_EQUIVALENCY_TABLE[[self UID]] = view;
|
||||
}
|
||||
|
||||
return view;
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPRadio (NS)
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame radioGroup:(CPRadioGroup)aRadioGroup cell:(NSButtonCell)aCell
|
||||
{
|
||||
self = [self initWithFrame:aFrame radioGroup:aRadioGroup];
|
||||
|
||||
if (self)
|
||||
{
|
||||
[self setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
[self setTitle:[aCell title]];
|
||||
[self setBackgroundColor:[CPColor clearColor]]; // the IB default
|
||||
[self setFont:[aCell font]];
|
||||
[self setAlignment:[aCell alignment]];
|
||||
[self setLineBreakMode:[aCell lineBreakMode]];
|
||||
[self setImagePosition:[aCell imagePosition]];
|
||||
[self setKeyEquivalent:[aCell keyEquivalent]];
|
||||
[self setKeyEquivalentModifierMask:[aCell keyEquivalentModifierMask]];
|
||||
[self setAllowsMixedState:[aCell allowsMixedState]];
|
||||
[self setObjectValue:[aCell objectValue]];
|
||||
[self setEnabled:[aCell isEnabled]];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user