//
// Time-stamp: <94/11/27 10:23:45 stephan>
//
// RulerManager.m
// Project: Rulers
//
// Stephan Wacker
// 93-01-31


#import "RulerManager.h"


@implementation RulerManager


- preferencesControl
// Answer the RulerPreferencesControl object.
{
    return preferences;
}

- rulerList
// Answer the List object containing all RulerControl-s.
{
    return rulerList;
}

- mainRuler
// Answer the currently selected RulerControl object.
{
    return mainRuler;
}



- add: aRulerControl
// Add aRulerControl to the rulerList.
// PRIVATE
{
    [rulerList addObject: aRulerControl];
    
    return self;
}

- remove: aRulerControl
// Remove aRulerControl from the rulerList.
// PRIVATE
{
    [rulerList removeObject: aRulerControl];
    if( aRulerControl == mainRuler ) mainRuler = nil;
    
    return self;
}



- rulerDidBecomeMain: sender
// Invoked when the sender becomes the main ruler.
// NB: There is no rulerDidResignMain: method.
{
    mainRuler = sender;
    
    return self;
}

- rulerWillClose: sender
// Invoked just before the sender is closed.
{
    return [self remove: sender];
}



- newHorizontal: sender
// Create a new instance of a horizontal ruler.
{
    if( [NXApp loadNibSection: "hRuler.nib" owner: self] == nil ) {
	return nil;
    }
    
    return [self add: newRuler];
}



- newVertical: sender
// Create a new instance of a horizontal ruler.
{
    if( [NXApp loadNibSection: "vRuler.nib" owner: self] == nil ) {
	return nil;
    }
    
    return [self add: newRuler];
}



- showPreferences: sender
// Open the preferences panel.
{
    if( !preferences 
     && ( ![NXApp loadNibSection: "preferences.nib" owner: self] )
    )
	return nil;
    
    [preferences run];
    
    return self;
}


@end // RulerManager



@implementation RulerManager( ApplicationDelegate )


- appDidInit: sender
// Initialize yourself after application has started.
{
    rulerList = [[List alloc] initCount: 8];
    [self newHorizontal: self];		// create initial ruler instance
    [self newVertical: self];		// create initial ruler instance
    
    return self;
}


@end // RulerManager( ApplicationDelegate )
