Hi,
Thanks for the reply.
I used matrix to display data inside a sector years ago, when I had just
started learning cocoa.
I know its a crude and inefficient way to make a hex viewer, but currently its
not required to be sophisticated at all and I didn't have the time to make any
big changes.
I'm pasting here all of the code related to views, if it can give any clues.
My sub-class of NSTextFieldCell: (currently does nothing but sets highlight
color)
@implementation HexCell
-(NSColor *)highlightColorWithFrame:(NSRect)rect inView:(NSView *)controlView
{
return [NSColor yellowColor];
}
@end
My NSMatrix sub-class: (I'm not calling drawRect:)
@implementation MatrixHex
- (id)initWithFrame:(NSRect)frameRect rows:(int)rows columns:(int)columns
{
HexCell *aCell = [self prototype];
// initiates matrix:
[self initWithFrame:frameRect
mode:NSListModeMatrix
prototype:aCell
numberOfRows:rows
numberOfColumns:columns];
[self setScrollable:YES];
return self;
}
- (id)prototype
{
HexCell *aCell = [[ HexCell alloc] init];
[aCell setEnabled:YES];
[aCell setStringValue:@"00"];
[aCell setFont:[NSFont systemFontOfSize:10.0]];
return aCell;
}
@end
In my AppController, I have:
id matOffset = matrixOffset;
id matHex = matrixHex;
id matAscii = matrixAscii;
matrixOffset = [[MatrixHex alloc] initWithFrame:NSMakeRect(0.0, 0.0, 44.0,
16.0) rows:1 columns:1];
[matrixOffset setCellSize:NSMakeSize(40.0, 13.0)];
[matrixOffset setIntercellSpacing:NSMakeSize(0.0, 2.0)];
matrixAscii = [[MatrixHex alloc] initWithFrame:NSMakeRect(0.0, 0.0,
192.0, 16.0) rows:1 columns:16];
[matrixAscii setCellSize:NSMakeSize(12.0, 13.0)];
[matrixAscii setIntercellSpacing:NSMakeSize(0.0, 2.0)];
matrixHex = [[MatrixHex alloc] initWithFrame:NSMakeRect(0.0, 0.0,
364.0, 16.0) rows:1 columns:16];
[matrixHex setCellSize:NSMakeSize(19.0, 13.0)];
[matrixHex setIntercellSpacing:NSMakeSize(4.0, 2.0)];
rowsInSector = sectorSize / 16;
int i = 0;
for (i = 0; i < rowsInSector; i++)//one row already there. so one extra
row for showing "---"
{
[matrixOffset addRow];
[matrixHex addRow];
[matrixAscii addRow];
}
[matrixOffset sizeToCells];
[matrixAscii sizeToCells];
[matrixHex sizeToCells];
[splitViewForMatrices setVertical:YES];
[splitViewForMatrices setFrameSize:NSMakeSize([splitViewForMatrices
frame].size.width, [matrixOffset frame].size.height + 4)];
if (matOffset)
{
[splitViewForMatrices replaceSubview:matOffset
with:matrixOffset];
[splitViewForMatrices replaceSubview:matHex with:matrixHex];
[splitViewForMatrices replaceSubview:matAscii with:matrixAscii];
matOffset = matrixOffset;
matHex = matrixHex;
matAscii = matrixAscii;
}
else
{
[splitViewForMatrices addSubview:matrixOffset];
[splitViewForMatrices addSubview:matrixHex];
[splitViewForMatrices addSubview:matrixAscii];
}
[scrollView setNeedsDisplay:YES];
Please share any insights you may have about the problem.
Thanks,
Nick
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]