
#import "BoardWindow.h"
#import <appkit/Application.h>
#import <appkit/OpenPanel.h>
#import <appkit/View.h>
#import <objc/List.h>

@implementation BoardWindow

- highlightedSquare {
    return highlightedSquare;
}

- (BOOL) isSomeoneSelected {
    return isSomeoneSelected;
}

- (BOOL) isWhiteMove {
    return isWhiteMove;
}

- letOtherColorMove {
    [self setIsWhiteMove: ![self isWhiteMove]];
    return [self display];
}

- makeSquaresPerform: (SEL) aMessage {
    return [[self viewList] makeObjectsPerform: aMessage];
}

- makeSquaresPerform: (SEL) aMessage with: sender {
    return [[self viewList] makeObjectsPerform: aMessage with: sender];
}

- openNewBoard: sender {
    static const char *const  fileTypes[2] = {"nib", NULL};

    if ([[OpenPanel new] runModalForTypes: fileTypes] &&
		  [NXApp loadNibFile: [[OpenPanel new] filename] owner: NXApp])
	[[[[NXApp windowList] lastObject] makeKeyWindow] appDidInit: NXApp];
    return self;		/* ^ the last window added is the new board */
}

- setHighlightedSquare: aSquare {
    highlightedSquare = aSquare;
    return self;
}

- setIsSomeoneSelected: (BOOL) state {
    isSomeoneSelected = state;
    return self;
}

- setIsWhiteMove: (BOOL) state {
    isWhiteMove = state;
    return self;
}

/* Private methods: */

- appDidInit: sender {		/* our return value is ignored, so any is OK */
    isWhiteMove = YES;
    return [self makeSquaresPerform: @selector(appDidInit)];
}

- viewList {
    return [[self contentView] subviews];
}

@end
