// 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.
//
// $Header: /Network/Source/CVS/OmniGroup/Frameworks/OmniDocument/ODDocument.h,v 1.8 2000/01/19 23:36:25 kc Exp $

// The OmniDocument framework was used in OmniPDF and OmniImage, but we consider it obsolete now that NSDocument exists.

#import <OmniFoundation/OFObject.h>

@class NSNotification;
@class NSWindow;

typedef enum {
    ODDocumentSave,
    ODDocumentCancel,
    ODDocumentDiscard
} ODDocumentCloseResult;

#import <Foundation/NSGeometry.h> // For NSPoint
#import <AppKit/NSNibDeclarations.h> // For IBOutlet
#import "FrameworkDefines.h"

@interface ODDocument : OFObject
{
    IBOutlet NSWindow *window;

    NSString *path;
    struct {
        unsigned int isClosing:1;
        unsigned int isNewDocument:1;
    } _docFlags;
}

// documentLocationOffset is position from top left. (Use this to push docs past main menu.)
+ (void)setDocumentLocationOffset:(NSPoint)offset;
+ (NSPoint)documentLocationOffset;

+ (BOOL)isFilePackage;
+ (NSString *)nibFilePath;

+ (ODDocument *)documentWithPath:(NSString *)aPath;

// Init and dealloc
- initWithPath:(NSString *)aPath;

// API
- (void)setDocumentPath:(NSString *)aPath;
- (NSString *)documentPath;

- (NSWindow *)window;

- (void)activateDocument;
- (void)deactivateDocument;
- (void)hide;

- (void)setIsEdited:(BOOL)edited;
- (BOOL)isEdited;

- (BOOL)isNewDocument;

- (BOOL)saveIfNeeded;
- (ODDocumentCloseResult)close;

// Actions
- (IBAction)save:(id)sender;
- (IBAction)saveAs:(id)sender;
- (IBAction)saveToFile:(id)sender;
- (IBAction)revert:(id)sender;
- (IBAction)closeDocument:(id)sender;
- (IBAction)switchToNextDocument:(id)sender;
- (IBAction)switchToPreviousDocument:(id)sender;
- (IBAction)bringWindowForward:(id)sender;
- (IBAction)pushWindowBackward:(id)sender;

@end

@interface ODDocument (SubclassesOnly)
+ (NSString *)fileExtension;
- (BOOL)writeToPath:(NSString *)aPath;
- (BOOL)readFromPath:(NSString *)aPath;
- (void)loadNib;
- (ODDocumentCloseResult)willLoseChanges:(NSString *)reason canSave:(BOOL)canSave;
@end


// Notifications
OmniDocument_EXTERN NSString *ODDocumentWillClose;
OmniDocument_EXTERN NSString *ODDocumentDidClose;

OmniDocument_EXTERN NSString *ODDocumentWillActivate;
OmniDocument_EXTERN NSString *ODDocumentDidActivate;

OmniDocument_EXTERN NSString *ODDocumentWillDeactivate;
OmniDocument_EXTERN NSString *ODDocumentDidDeactivate;
