// Copyright 1997-2000 Omni Development, Inc.  All rights reserved.
//
// This software may only be used and reproduced according to the
// terms in the file OmniSourceLicense.html, which should be
// distributed with this project and can also be found at
// http://www.omnigroup.com/DeveloperResources/OmniSourceLicense.html.

#import "OHTextBuilderDefaultsHolder.h"

#import <Foundation/Foundation.h>
#import <OmniBase/OmniBase.h>
#import <OmniFoundation/OmniFoundation.h>
#import <OWF/OWF.h>

RCS_ID("$Header: /Network/Source/CVS/OmniGroup/Frameworks/OmniHTML/Building.subproj/OHTextBuilderDefaultsHolder.m,v 1.2 2000/01/20 00:27:46 kc Exp $")

@implementation OHTextBuilderDefaultsHolder

static OFUserDefaults *defaults;
static OHTextBuilderDefaultsHolder *textBuilderDefaults;
static NSLock *classLock;

+ (void)initialize;
{
    static BOOL initialized = NO;

    [super initialize];
    if (initialized)
        return;
    initialized = YES;

    defaults = [OFUserDefaults sharedUserDefaults];
    textBuilderDefaults = nil;
    classLock = [[NSLock alloc] init];
}


+ (OHTextBuilderDefaultsHolder *)defaultsHolder;
{
    OHTextBuilderDefaultsHolder *currentDefaults;

    [classLock lock];
    currentDefaults = [textBuilderDefaults retain];

    if (!currentDefaults || currentDefaults->lastDefaultsChangeCount != [defaults changeCount]) {
        [currentDefaults release];
        currentDefaults = [[OHTextBuilderDefaultsHolder alloc] init];
        [textBuilderDefaults release];
        textBuilderDefaults = [currentDefaults retain];
    }
    [classLock unlock];
    
    return [currentDefaults autorelease];
}


- init;
{
    [super init];

    lastDefaultsChangeCount = [defaults changeCount];

    normalFontName = [[defaults stringForKey:@"OHNormalFont"] retain];
    titleFontName = [[defaults stringForKey:@"OHTitleFont"] retain];
    fixedPitchFontName = [[defaults stringForKey:@"OHFixedPitchFont"] retain];

    normalFontSize = [defaults floatForKey:@"OHNormalFontSize"];
    titleFontSize = [defaults floatForKey:@"OHTitleFontSize"];
    fixedPitchFontSize = [defaults floatForKey:@"OHFixedPitchFontSize"];

    flags.underlineAnchors = [defaults boolForKey:@"OHUnderlineAnchors"];
    flags.incrementalDisplay = [defaults boolForKey:@"OHIncrementalDisplay"];
    
    // NOT USED yet -- move to OmniTextContainer when created
    delayFlushTime = [defaults floatForKey:@"OHWaitForImagesTime"];

    return self;
}

- (void)dealloc;
{
    [normalFontName release];
    [titleFontName release];
    [fixedPitchFontName release];
    
    [super dealloc];
}

@end
