Permalink
Browse files

Added missing license, added a lot more support for radio button attr…

…ibutes, included fix for issue #1190
  • Loading branch information...
1 parent 0218246 commit 93f36a232692944f7ec58c035ec6c3143cc24bf9 Aparajita Fishman committed Mar 29, 2011
Showing with 93 additions and 51 deletions.
  1. +3 −14 Tools/nib2cib/Converter+Mac.j
  2. +90 −37 Tools/nib2cib/NSMatrix.j
@@ -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)] &&
View
@@ -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
{
+ return [self NS_initWithCoder:aCoder];
}
-- (id)initWithCoder:(CPCoder)aCoder
+- (id)NS_initWithCoder:(CPCoder)aCoder
{
- var view = [[CPView alloc] 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"];
-
- if (isRadioMode)
- {
- var radioGroup = [CPRadioGroup new],
- frame = CGRectMake(0.0, 0.0, cellSize.width, cellSize.height);
+ self = [super NS_initWithCoder:aCoder];
- for (var rowIndex = 0; rowIndex < numberOfRows; ++rowIndex)
+ if (self)
+ {
+ 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"];
+
+ 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;
}
+ }
+
+ return self;
+}
+
+@end
+
+@implementation CPRadio (NS)
- if (drawsBackground)
- [view setBackgroundColor:backgroundColor];
+- (id)initWithFrame:(CGRect)aFrame radioGroup:(CPRadioGroup)aRadioGroup cell:(NSButtonCell)aCell
+{
+ self = [self initWithFrame:aFrame radioGroup:aRadioGroup];
- NIB_CONNECTION_EQUIVALENCY_TABLE[[self UID]] = view;
+ 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 view;
+ return self;
}
@end

0 comments on commit 93f36a2

Please sign in to comment.