#import <appkit/NXColorWell.h>
#import <appkit/Matrix.h>

#import "MiscCalendarView.subproj/MiscCalendarView.h"
#import "MiscCalendarView.subproj/MiscCalendarViewConstants.h"

#import "MiscCalendarViewInspector.h"


@interface MiscCalendarViewInspector (Private)

- cellColorMatrix;

@end

@implementation MiscCalendarViewInspector


- init
{
    char 	buf[MAXPATHLEN + 1];
    id 		bundle;

    [super init];
    
    bundle = [NXBundle bundleForClass:[MiscCalendarView class]];

    [bundle getPath:buf forResource:"MiscCalendarViewInspector" ofType:"nib"];

    [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];

    return self;
}

- ok:sender
{
    BOOL	display;
    id		date;

    if (sender == titleSwitchesMatrix)
    {
	display = [[sender selectedCell] state] ? YES : NO;

	[object forHeader:[[sender selectedCell] tag] display:display];
    }

    else if (sender == setDateButton)
    {
	date = [calendar dateDelegate];

	[[object dateDelegate] setYear:[date year] month:[date month]
	 day:[date day]];

	[object displayDate:self];
    }
    else if (sender == matrixModeRadioMatrix)
      [object setHighlightMode:[[sender selectedCell] tag]];

    else if (sender == matrixCellsColorWell)
      [object setColorOf:[[cellColorRadioMatrix selectedCell] tag]
       to:[sender color]];

    else if (sender == cellColorRadioMatrix)
      [matrixCellsColorWell 
       setColor:[object colorOf:[[cellColorRadioMatrix selectedCell] tag]]];

    return [super ok:sender];
}

- revert:sender
{
    id	date;

    [matrixModeRadioMatrix selectCellWithTag:[object highlightMode]];

    date = [object dateDelegate];

    [[calendar dateDelegate] setYear:[date year] month:[date month]
     day:[date day]];

    [calendar displayDate:self];
    [calendar updateDate:self];

    [[titleSwitchesMatrix findCellWithTag:MISC_CV_DOWHEADER] 
     setIntValue:[object isHeaderDisplayed:MISC_CV_DOWHEADER]];
    [[titleSwitchesMatrix findCellWithTag:MISC_CV_MONTHHEADER]
     setIntValue:[object isHeaderDisplayed:MISC_CV_MONTHHEADER]];
    [[titleSwitchesMatrix findCellWithTag:MISC_CV_YEARHEADER] 
     setIntValue:[object isHeaderDisplayed:MISC_CV_YEARHEADER]];
    [[titleSwitchesMatrix findCellWithTag:MISC_CV_MONTHANDYEARHEADER] 
     setIntValue:[object isHeaderDisplayed:MISC_CV_MONTHANDYEARHEADER]];

    [matrixCellsColorWell 
     setColor:[object colorOf:[[cellColorRadioMatrix selectedCell] tag]]];

    return [super revert:sender];
}

- (BOOL)wantsButtons
{
    return NO;
}

@end

@implementation MiscCalendarViewInspector (Private)

- cellColorMatrix
{
    return cellColorRadioMatrix;
}

@end
