I am wondering why all selected cells become white one by one and why
the previous does not become gray thought it should - if I did not
make
a mistake.The way they become gray is quite rhapsodic and imprevisible
and ununderstandable for me.
There is a mistake in my code? Where? And what? (ok, it is not too
elegant, but i think it should work). please help andras
#include <AppKit/AppKit.h>
#include <Foundation/Foundation.h>
@interface CalViewer : NSControl
{
id matrix;
id previouscell;
}
- (id) initWithFrame: (NSRect) aFrame; @end
#include "CalViewer.h"
@implementation CalViewer
- (id) initWithFrame: (NSRect) aFrame {
self = [super initWithFrame: aFrame]; int i, j, k; k = 0;
matrix = [[NSMatrix alloc] initWithFrame: NSMakeRect(0,0,25,25)]; id
protocell = [[NSTextFieldCell alloc] init]; [protocell
setDrawsBackground: YES];
[protocell setBackgroundColor: [NSColor windowBackgroundColor]];
[protocell setAction: @selector(changeBackground:)]; [protocell
setTarget: matrix];
[matrix setPrototype: protocell];
[matrix setIntercellSpacing: NSMakeSize(0,0)]; [matrix insertRow: 3];
[matrix insertColumn: 3];
for (i=0; i< 4; i++)
for(j=0; j<4; j++)
{
if (k == 0)
[[matrix cellAtRow: i column: j] setEnabled: NO];
else
{
[[matrix cellAtRow: i column: j] setIntValue: k];
[[matrix cellAtRow: i column: j] setFont: [NSFont
boldSystemFontOfSize: 12]]; [[matrix cellAtRow: i column: j]
setAlignment: NSCenterTextAlignment]; }
k++;
}
previouscell = [matrix cellAtRow: 0 column: 2]; [previouscell
setBackgroundColor: [NSColor whiteColor]]; [matrix sizeToCells];
[self addSubview: matrix];
return self;
}
- (void) changeBackground: (id) sender {
[previouscell setBackgroundColor: [NSColor windowBackgroundColor]];
[[matrix selectedCell] setBackgroundColor: [NSColor whiteColor]];
previouscell = [matrix selectedCell];
}
@end