diff --git a/ChangeLog b/ChangeLog index 7b52e91f1..be54b91cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +2007-01-17 Fred Kiefer + + * Headers/AppKit/NSResponder.h: Add MacOS 10.4 methods. + * Source/NSResponder.m: Implement new MacOS 10.4 methods. + * Headers/AppKit/NSDocumentFrameworkPrivate.h: Remove. + * Source/NSDocumentFrameworkPrivate.h: Add. + * Source/GNUmakefile: Don't install NSDocumentFrameworkPrivate.h. + * Headers/AppKit/NSDocument.h: Add MacOS 10.4 methods and + additional ivars. Rename ivars to adopt to coding standards. + * Source/NSDocument.m: Implement new MacOS 10.4 methods adopted + to changes of ivar names. + * Headers/AppKit/NSDocument.h: Add MacOS 10.4 methods and + additional ivars. Rename ivars to adopt to coding standards. + * Source/NSDocument.m: Adopt include of NSDocumentFrameworkPrivate.h. + Implement new MacOS 10.4 methods and adopt to changes of ivar names. + * Headers/AppKit/NSDocumentController.h: Add MacOS 10.4 methods and + additional ivars. Rename ivars to adopt to coding standards. Fix includes. + * Source/NSDocumentController.m: Adopt include of NSDocumentFrameworkPrivate.h. + Implement new MacOS 10.4 methods and adopt to changes of ivar names. + * Headers/AppKit/NSWindowController.h: Rename ivars to adopt to coding standards. + * Source/NSWindowController.m: Adopt include of NSDocumentFrameworkPrivate.h. + Adopt to changes of ivar names. + + * Headers/AppKit/NSPrintOperation.h: Add MacOS 10.4 methods and + additional ivars. Rename ivars to adopt to coding standards. + * Source/NSPrintOperation.m: Implement new MacOS 10.4 methods and + adopt to changes of ivar names. + * Source/GSPrintOperation.m, + * Source/GSEPSPrintOperation.m, + * Printing/GSLPR/GSLPRPrintOperation.m, + * Printing/GSCUPS/GSCUPSPrintOperation.m: Adopt to changes in super class. + + * Headers/AppKit/NSCell.h: Add MacOS 10.4 methods and + additional ivars. Store the state in two bits only. Rename ivar to + adopt to coding standards. Move mnemonic_location into flags. + * Source/NSCell.m: Implement new MacOS 10.3 and 10.4 methods and + adopt to changes of ivar names. Add encoding and decoding of new + ivars and improve keyed coding and decoding. + + * Headers/AppKit/NSColor.h: Adopt values of NSControlTint + enumerator to Cocoa values. + * Headers/AppKit/NSParagraphstyle.h: Add protection against double inclusion. + * Source/GSServicemanager.m, + * Source/NSAttributedString.m, + * Source/NSView.m, + * Source/NSApplication.m: Correct includes to avoid compiler warnings. + 2007-01-14 Stefan Bidigaray * Source/NSWindow.m: diff --git a/Headers/AppKit/NSCell.h b/Headers/AppKit/NSCell.h index 36eba8748..630660242 100644 --- a/Headers/AppKit/NSCell.h +++ b/Headers/AppKit/NSCell.h @@ -36,8 +36,12 @@ // For tint #include +// for NSWritingDirection +#include // For text alignment #include +// for NSFocusRingType +#include @class NSString; @class NSMutableDictionary; @@ -58,9 +62,9 @@ enum { NSPositiveIntType, NSFloatType, NSPositiveFloatType, - NSDateType, NSDoubleType, - NSPositiveDoubleType + NSPositiveDoubleType, + NSDateType }; typedef enum { @@ -121,7 +125,7 @@ enum { NSString *_contents; NSImage *_cell_image; NSFont *_font; - id _objectValue; + id _object_value; struct GSCellFlagsType { // total 32 bits. 0 bits left. unsigned contents_is_attributed_string: 1; @@ -144,30 +148,40 @@ enum { unsigned type: 2; // 3 values unsigned image_position: 3; // 7 values unsigned entry_type: 4; // 8 values + unsigned allows_undo: 1; + unsigned line_break_mode: 3; // 6 values + + // total 19 bits. 4 bits extension, 9 bits left. + int state: 2; // 3 values but one negative + unsigned mnemonic_location: 8; + unsigned control_tint: 3; + unsigned control_size: 2; + unsigned focus_ring_type: 2; // 3 values + unsigned base_writing_direction: 2; // 3 values // 4 bits reserved for subclass use unsigned subclass_bool_one: 1; unsigned subclass_bool_two: 1; unsigned subclass_bool_three: 1; unsigned subclass_bool_four: 1; - /* This is not in the bitfield now (for simpler macosx compatibility) - but who knows in the future */ - int state; // 3 values but one negative } _cell; - unsigned char _mnemonic_location; unsigned int _mouse_down_flags; unsigned int _action_mask; NSFormatter *_formatter; NSMenu *_menu; id _represented_object; + void *_reserved1; } // // Class methods // +#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) ++ (NSFocusRingType)defaultFocusRingType; +#endif #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) + (NSMenu *)defaultMenu; #endif -+ (BOOL) prefersTrackingUntilMouseUp; ++ (BOOL)prefersTrackingUntilMouseUp; // // Initializing an NSCell @@ -217,6 +231,10 @@ enum { - (BOOL)isOpaque; - (void)setBezeled:(BOOL)flag; - (void)setBordered:(BOOL)flag; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) +- (NSFocusRingType)focusRingType; +- (void)setFocusRingType:(NSFocusRingType)type; +#endif // // Setting the NSCell's State @@ -254,6 +272,14 @@ enum { - (void)setTitle:(NSString *)aString; - (NSString *)title; #endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) +- (NSWritingDirection)baseWritingDirection; +- (void)setBaseWritingDirection:(NSWritingDirection)direction; +#endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (NSLineBreakMode)lineBreakMode; +- (void)setLineBreakMode:(NSLineBreakMode)mode; +#endif // // Target and Action @@ -437,6 +463,10 @@ enum { - (BOOL)sendsActionOnEndEditing; - (void)setSendsActionOnEndEditing:(BOOL)flag; #endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (BOOL)allowsUndo; +- (void)setAllowsUndo:(BOOL)flag; +#endif @end diff --git a/Headers/AppKit/NSColor.h b/Headers/AppKit/NSColor.h index feb106466..339ba8c24 100644 --- a/Headers/AppKit/NSColor.h +++ b/Headers/AppKit/NSColor.h @@ -41,9 +41,9 @@ typedef enum _NSControlTint { NSDefaultControlTint, - NSClearControlTint, NSBlueControlTint, - NSGraphiteControlTint + NSGraphiteControlTint = 6, + NSClearControlTint } NSControlTint; typedef enum _NSControlSize { diff --git a/Headers/AppKit/NSDocument.h b/Headers/AppKit/NSDocument.h index 72c6b26f6..150117cf3 100644 --- a/Headers/AppKit/NSDocument.h +++ b/Headers/AppKit/NSDocument.h @@ -7,6 +7,9 @@ Author: Carl Lindberg Date: 1999 + Modifications: Fred Kiefer + Date: Dec 2006 + Added MacOS 10.4 methods. This file is part of the GNUstep GUI Library. @@ -41,6 +44,9 @@ @class NSArray; @class NSMutableArray; @class NSData; +@class NSDate; +@class NSDictionary; +@class NSError; @class NSFileManager; @class NSURL; @class NSUndoManager; @@ -50,7 +56,9 @@ @class NSView; @class NSSavePanel; @class NSMenuItem; +@class NSPageLayout; @class NSPrintInfo; +@class NSPrintOperation; @class NSPopUpButton; @class NSFileWrapper; @class NSDocumentController; @@ -60,49 +68,87 @@ typedef enum _NSDocumentChangeType { NSChangeDone = 0, NSChangeUndone = 1, - NSChangeCleared = 2 + NSChangeCleared = 2, +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) + NSChangeReadOtherContents = 3, + NSChangeAutosaved = 4 +#endif } NSDocumentChangeType; typedef enum _NSSaveOperationType { NSSaveOperation = 0, NSSaveAsOperation = 1, - NSSaveToOperation = 2 + NSSaveToOperation = 2, +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) + NSAutosaveOperation = 3 +#endif } NSSaveOperationType; @interface NSDocument : NSObject { @private NSWindow *_window; // Outlet for the single window case - NSMutableArray *_windowControllers; // WindowControllers for this document - NSString *_fileName; // Save location - NSString *_fileType; // file/document type - NSPrintInfo *_printInfo; // print info record - long _changeCount; // number of time the document has been changed - NSView *savePanelAccessory; // outlet for the accessory save-panel view - NSPopUpButton *spaButton; // outlet for "the File Format:" button in the save panel. - int _documentIndex; // Untitled index - NSUndoManager *_undoManager; // Undo manager for this document - NSString *_saveType; // the currently selected extension. + NSMutableArray *_window_controllers; // WindowControllers for this document + NSURL *_file_url; // Save location as URL + NSString *_file_name; // Save location + NSString *_file_type; // file/document type + NSDate *_file_modification_date;// file modification date + NSString *_last_component_file_name; // file name last component + NSURL *_autosaved_file_url; // Autosave location as URL + NSPrintInfo *_print_info; // print info record + NSView *_save_panel_accessory; // outlet for the accessory save-panel view + NSPopUpButton *_spa_button; // outlet for "the File Format:" button in the save panel. + NSString *_save_type; // the currently selected extension. + NSUndoManager *_undo_manager; // Undo manager for this document + long _change_count; // number of time the document has been changed + long _autosave_change_count; // number of time the document has been changed since the last autosave + int _document_index; // Untitled index struct __docFlags { - unsigned int inClose:1; - unsigned int hasUndoManager:1; + unsigned int in_close:1; + unsigned int has_undo_manager:1; unsigned int RESERVED:30; - } _docFlags; + } _doc_flags; void *_reserved1; } ++ (NSArray *)readableTypes; ++ (NSArray *)writableTypes; ++ (BOOL)isNativeType:(NSString *)type; + /*" Initialization "*/ - (id)init; - (id)initWithContentsOfFile:(NSString *)fileName ofType:(NSString *)fileType; - (id)initWithContentsOfURL:(NSURL *)url ofType:(NSString *)fileType; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (id)initForURL:(NSURL *)forUrl +withContentsOfURL:(NSURL *)url + ofType:(NSString *)type + error:(NSError **)error; +- (id)initWithContentsOfURL:(NSURL *)url + ofType:(NSString *)type + error:(NSError **)error; +- (id)initWithType:(NSString *)type + error:(NSError **)error; +#endif /*" Window management "*/ - (NSArray *)windowControllers; - (void)addWindowController:(NSWindowController *)windowController; +#if OS_API_VERSION(GS_API_MACOSX, MAC_OS_X_VERSION_10_4) - (BOOL)shouldCloseWindowController:(NSWindowController *)windowController; +#endif +#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) +- (void)shouldCloseWindowController:(NSWindowController *)windowController + delegate:(id)delegate + shouldCloseSelector:(SEL)callback + contextInfo:(void *)contextInfo; +#endif - (void)showWindows; - (void)removeWindowController:(NSWindowController *)windowController; - (void)setWindow:(NSWindow *)aWindow; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (NSWindow *)windowForSheet; +#endif /*" Window controller creation "*/ - (void)makeWindowControllers; // Manual creation @@ -125,16 +171,28 @@ typedef enum _NSSaveOperationType { /*" Closing "*/ - (void)close; +#if OS_API_VERSION(GS_API_MACOSX, MAC_OS_X_VERSION_10_4) - (BOOL)canCloseDocument; +#endif +#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) +- (void)canCloseDocumentWithDelegate:(id)delegate + shouldCloseSelector:(SEL)shouldCloseSelector + contextInfo:(void *)contextInfo; +#endif /*" Type and location "*/ - (NSString *)fileName; - (void)setFileName:(NSString *)fileName; - (NSString *)fileType; - (void)setFileType:(NSString *)type; -+ (NSArray *)readableTypes; -+ (NSArray *)writableTypes; -+ (BOOL)isNativeType:(NSString *)type; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (NSURL *)fileURL; +- (void)setFileURL:(NSURL *)url; +- (NSDate *)fileModificationDate; +- (void)setFileModificationDate: (NSDate *)date; +- (NSString *)lastComponentOfFileName; +- (void)setLastComponentOfFileName:(NSString *)str; +#endif /*" Read/Write/Revert "*/ @@ -152,11 +210,43 @@ typedef enum _NSSaveOperationType { - (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)type; - (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)type; - (BOOL)revertToSavedFromURL:(NSURL *)url ofType:(NSString *)type; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (NSData *)dataOfType:(NSString *)type + error:(NSError **)error; +- (NSFileWrapper *)fileWrapperOfType:(NSString *)type + error:(NSError **)error; +- (BOOL)readFromData:(NSData *)data + ofType:(NSString *)type + error:(NSError **)error; +- (BOOL)readFromFileWrapper:(NSFileWrapper *)wrapper + ofType:(NSString *)type + error:(NSError **)error; +- (BOOL)readFromURL:(NSURL *)url + ofType:(NSString *)type + error:(NSError **)error; +- (BOOL)revertToContentsOfURL:(NSURL *)url + ofType:(NSString *)type + error:(NSError **)error; +- (BOOL)writeSafelyToURL:(NSURL *)url + ofType:(NSString *)type + forSaveOperation:(NSSaveOperationType)op + error:(NSError **)error; +- (BOOL)writeToURL:(NSURL *)url + ofType:(NSString *)type + error:(NSError **)error; +- (BOOL)writeToURL:(NSURL *)url + ofType:(NSString *)type + forSaveOperation:(NSSaveOperationType)op +originalContentsURL:(NSURL *)orig + error:(NSError **)error; +#endif /*" Save panel "*/ - (BOOL)shouldRunSavePanelWithAccessoryView; +#if OS_API_VERSION(GS_API_MACOSX, MAC_OS_X_VERSION_10_4) - (NSString *)fileNameFromRunningSavePanelForSaveOperation:(NSSaveOperationType)saveOperation; - (int)runModalSavePanel:(NSSavePanel *)savePanel withAccessoryView:(NSView *)accessoryView; +#endif - (NSString *)fileTypeFromLastRunSavePanel; - (NSDictionary *)fileAttributesToWriteToFile: (NSString *)fullDocumentPath ofType: (NSString *)docType @@ -168,6 +258,15 @@ typedef enum _NSSaveOperationType { - (BOOL)writeWithBackupToFile:(NSString *)fileName ofType:(NSString *)fileType saveOperation:(NSSaveOperationType)saveOp; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (NSArray *)writableTypesForSaveOperation:(NSSaveOperationType)op; +- (NSDictionary *)fileAttributesToWriteToURL:(NSURL *)url + ofType:(NSString *)type + forSaveOperation:(NSSaveOperationType)op + originalContentsURL:(NSURL *)original + error:(NSError **)error; +- (BOOL)fileNameExtensionWasHiddenInLastRunSavePanel; +#endif /*" Printing "*/ - (NSPrintInfo *)printInfo; @@ -177,6 +276,24 @@ typedef enum _NSSaveOperationType { - (int)runModalPageLayoutWithPrintInfo:(NSPrintInfo *)printInfo; - (IBAction)printDocument:(id)sender; - (void)printShowingPrintPanel:(BOOL)flag; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (BOOL)preparePageLayout:(NSPageLayout *)pageLayout; +- (void)runModalPageLayoutWithPrintInfo:(NSPrintInfo *)info + delegate:(id)delegate + didRunSelector:(SEL)sel + contextInfo:(void *)context; +- (void)printDocumentWithSettings:(NSDictionary *)settings + showPrintPanel:(BOOL)flag + delegate:(id)delegate + didPrintSelector:(SEL)sel + contextInfo:(void *)context; +- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)settings + error:(NSError **)error; +- (void)runModalPrintOperation:(NSPrintOperation *)op + delegate:(id)delegate + didRunSelector:(SEL)sel + contextInfo:(void *)context; +#endif /*" IB Actions "*/ - (IBAction)saveDocument:(id)sender; @@ -195,13 +312,6 @@ typedef enum _NSSaveOperationType { - (void)setHasUndoManager:(BOOL)flag; /* NEW delegate operations*/ -- (void)shouldCloseWindowController:(NSWindowController *)windowController - delegate:(id)delegate - shouldCloseSelector:(SEL)callback - contextInfo:(void *)contextInfo; -- (void)canCloseDocumentWithDelegate:(id)delegate - shouldCloseSelector:(SEL)shouldCloseSelector - contextInfo:(void *)contextInfo; - (void)saveToFile:(NSString *)fileName saveOperation:(NSSaveOperationType)saveOperation delegate:(id)delegate @@ -216,6 +326,36 @@ typedef enum _NSSaveOperationType { didSaveSelector:(SEL)didSaveSelector contextInfo:(void *)contextInfo; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (BOOL)saveToURL:(NSURL *)url + ofType:(NSString *)type + forSaveOperation:(NSSaveOperationType)op + error:(NSError **)error; +- (BOOL)saveToURL:(NSURL *)url + ofType:(NSString *)type + forSaveOperation:(NSSaveOperationType)op + delegate:(id)delegate + didSaveSelector:(SEL)didSaveSelector + contextInfo:(void *)contextInfo; + +/* Autosaving */ +- (NSURL *)autosavedContentsFileURL; +- (void)setAutosavedContentsFileURL:(NSURL *)url; +- (void)autosaveDocumentWithDelegate:(id)delegate + didAutosaveSelector:(SEL)didAutosaveSelector + contextInfo:(void *)context; +- (NSString *)autosavingFileType; +- (BOOL)hasUnautosavedChanges; + + +- (BOOL)presentError:(NSError *)error; +- (void)presentError:(NSError *)error + modalForWindow:(NSWindow *)window + delegate:(id)delegate + didPresentSelector:(SEL)sel + contextInfo:(void *)context; +- (NSError *)willPresentError:(NSError *)error; +#endif @end #endif // _GNUstep_H_NSDocument diff --git a/Headers/AppKit/NSDocumentController.h b/Headers/AppKit/NSDocumentController.h index 688ef4511..f21462a20 100644 --- a/Headers/AppKit/NSDocumentController.h +++ b/Headers/AppKit/NSDocumentController.h @@ -32,27 +32,33 @@ #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -#include +#include #include #include -@class NSArray, NSMutableArray; +@class NSArray; +@class NSError; +@class NSMutableArray; @class NSURL; -@class NSMenuItem, NSOpenPanel, NSWindow; +@class NSString; + @class NSDocument; +@class NSMenuItem; +@class NSOpenPanel; +@class NSWindow; @interface NSDocumentController : NSObject { @private NSMutableArray *_documents; - NSMutableArray *_recentDocuments; - struct __controllerFlags { - unsigned int shouldCreateUI:1; - unsigned int RESERVED:31; - } _controllerFlags; + NSMutableArray *_recent_documents; NSArray *_types; // from info.plist with key NSTypes + NSTimeInterval _autosavingDelay; + struct __controller_flags { + unsigned int should_create_ui:1; + unsigned int RESERVED:31; + } _controller_flags; void *_reserved1; - void *_reserved2; } + (id)sharedDocumentController; @@ -67,6 +73,32 @@ - (id)makeDocumentWithContentsOfURL:(NSURL *)url ofType:(NSString *)type; - (id)openDocumentWithContentsOfURL:(NSURL *)url display:(BOOL)display; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (id)makeDocumentForURL:(NSURL *)url + withContentsOfURL:(NSURL *)contents + ofType:(NSString *)type + error:(NSError **)err; +- (id)makeDocumentWithContentsOfURL:(NSURL *)url + ofType:(NSString *)type + error:(NSError **)err; +- (id)makeUntitledDocumentOfType:(NSString *)type + error:(NSError **)err; +- (id)openDocumentWithContentsOfURL:(NSURL *) url + display:(BOOL) flag + error:(NSError **) err; +- (id)openUntitledDocumentAndDisplay:(BOOL)flag + error:(NSError **)err; +- (BOOL)reopenDocumentForURL:(NSURL *)url + withContentsOfURL:(NSURL *)contents + error:(NSError **)err; +- (BOOL)presentError:(NSError *)err; +- (void)presentError:(NSError *)err + modalForWindow:(NSWindow *)win + delegate:(id)delegate + didPresentSelector:(SEL)sel + contextInfo:(void *)context; +- (NSError *)willPresentError:(NSError *)err; +#endif /*" With or without UI "*/ - (BOOL)shouldCreateUI; @@ -107,6 +139,9 @@ - (NSString *)currentDirectory; - (id)documentForWindow:(NSWindow *)window; - (id)documentForFileName:(NSString *)fileName; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (id)documentForURL:(NSURL *)url; +#endif /*" Menu validation "*/ @@ -118,10 +153,20 @@ - (NSString *)typeFromFileExtension:(NSString *)fileExtension; - (NSArray *)fileExtensionsFromType:(NSString *)type; - (Class)documentClassForType:(NSString *)type; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (NSString *)defaultType; +- (NSArray *)documentClassNames; +- (NSString *)typeForContentsOfURL:(NSURL *)url error:(NSError **)err; +#endif + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +/* Autosaving */ +- (NSTimeInterval)autosavingDelay; +- (void)setAutosavingDelay:(NSTimeInterval)autosavingDelay; +#endif @end #endif // GS_API_MACOSX #endif // _GNUstep_H_NSDocumentController - diff --git a/Headers/AppKit/NSParagraphStyle.h b/Headers/AppKit/NSParagraphStyle.h index 3473b4a16..02f12c533 100644 --- a/Headers/AppKit/NSParagraphStyle.h +++ b/Headers/AppKit/NSParagraphStyle.h @@ -1,5 +1,4 @@ /* -#import NSParagraphStyle.h NSParagraphStyle and NSMutableParagraphStyle hold paragraph style @@ -7,7 +6,7 @@ Copyright (C) 1996,1999 Free Software Foundation, Inc. - Author: Daniel Bðhringer + Author: Daniel Böhringer Date: August 1998 Update: Richard Frith-Macdonald March 1999 @@ -29,6 +28,9 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#ifndef _GNUstep_H_NSParagraphStyle +#define _GNUstep_H_NSParagraphStyle +#import #include @@ -135,7 +137,7 @@ typedef enum _NSWritingDirection { - (float) maximumLineHeight; - (NSLineBreakMode) lineBreakMode; -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) +#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST) /* * Returns the writing direction of "language", which is an ISO 639 * two- or three letter code, e.g. "en", or an ISO language-region @@ -165,7 +167,9 @@ typedef enum _NSWritingDirection { - (void) setTabStops: (NSArray*)array; - (void) setParagraphStyle: (NSParagraphStyle*)obj; -#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) +#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST) - (void) setBaseWritingDirection: (NSWritingDirection)direction; #endif @end + +#endif // _GNUstep_H_NSParagraphStyle diff --git a/Headers/AppKit/NSPrintOperation.h b/Headers/AppKit/NSPrintOperation.h index c6f0fb8c3..06c4a85ed 100644 --- a/Headers/AppKit/NSPrintOperation.h +++ b/Headers/AppKit/NSPrintOperation.h @@ -61,17 +61,22 @@ typedef enum _NSPrintingPageOrder { @interface NSPrintOperation : NSObject { // Attributes - NSPrintInfo *_printInfo; + NSPrintInfo *_print_info; NSView *_view; NSRect _rect; NSMutableData *_data; NSString *_path; NSGraphicsContext *_context; - NSPrintPanel *_printPanel; - NSView *_accessoryView; - NSPrintingPageOrder _pageOrder; - BOOL _showPanels; - //BOOL _pathSet; removed, just test _path for nil + NSPrintPanel *_print_panel; + NSView *_accessory_view; + NSString *_job_style_hint; + NSPrintingPageOrder _page_order; + struct __Flags { + unsigned int show_print_panel:1; + unsigned int show_progress_panel:1; + unsigned int can_spawn_separate_thread:1; + unsigned int RESERVED:29; + } _flags; int _currentPage; } @@ -137,6 +142,12 @@ typedef enum _NSPrintingPageOrder { - (BOOL)showPanels; - (void)setPrintPanel:(NSPrintPanel *)panel; - (void)setShowPanels:(BOOL)flag; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (BOOL)showsPrintPanel; +- (void)setShowsPrintPanel:(BOOL)flag; +- (BOOL)showsProgressPanel; +- (void)setShowsProgressPanel:(BOOL)flag; +#endif #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) - (NSView *)accessoryView; @@ -164,10 +175,16 @@ typedef enum _NSPrintingPageOrder { - (BOOL)deliverResult; - (BOOL)runOperation; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) -- (void)runOperationModalForWindow: (NSWindow *)docWindow - delegate: (id)delegate - didRunSelector: (SEL)didRunSelector +- (void)runOperationModalForWindow:(NSWindow *)docWindow + delegate:(id)delegate + didRunSelector:(SEL)didRunSelector contextInfo:(void *)contextInfo; +- (BOOL)canSpawnSeparateThread; +- (void)setCanSpawnSeparateThread:(BOOL)flag; +#endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST) +- (NSString *) jobStyleHint; +- (void)setJobStyleHint:(NSString *)hint; #endif // diff --git a/Headers/AppKit/NSResponder.h b/Headers/AppKit/NSResponder.h index 21ecbef60..ed46a4546 100644 --- a/Headers/AppKit/NSResponder.h +++ b/Headers/AppKit/NSResponder.h @@ -36,10 +36,13 @@ #include @class NSCoder; +@class NSError; @class NSString; + @class NSEvent; @class NSMenu; @class NSUndoManager; +@class NSWindow; @interface NSResponder : NSObject { @@ -128,7 +131,9 @@ - (void) rightMouseDown: (NSEvent*)theEvent; - (void) rightMouseDragged: (NSEvent*)theEvent; - (void) rightMouseUp: (NSEvent*)theEvent; +#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) - (void) scrollWheel: (NSEvent *)theEvent; +#endif /* * Services menu support @@ -175,6 +180,17 @@ - (BOOL) shouldBeTreatedAsInkEvent: (NSEvent *)theEvent; #endif + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (BOOL)presentError:(NSError *)error; +- (void)presentError:(NSError *)error + modalForWindow:(NSWindow *)window + delegate:(id)delegate + didPresentSelector:(SEL)sel + contextInfo:(void *)context; +- (NSError *)willPresentError:(NSError *)error; +#endif + @end #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) @@ -231,6 +247,7 @@ - (void) selectParagraph: (id)sender; - (void) selectToMark: (id)sender; - (void) selectWord: (id)sender; +- (void) setMark: (id)sender; - (void) showContextHelp: (id)sender; - (void) swapWithMark: (id)sender; - (void) transpose: (id)sender; @@ -238,11 +255,22 @@ - (void) uppercaseWord: (id)sender; - (void) yank: (id)sender; -// New in MacOSX 10.3 +#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) - (void) cancelOperation: (id)sender; - (void) deleteBackwardByDecomposingPreviousCharacter: (id)sender; - (void) moveLeftAndModifySelection: (id)sender; - (void) moveRightAndModifySelection: (id)sender; +- (void) moveWordLeft: (id)sender; +- (void) moveWordLeftAndModifySelection: (id)sender; +- (void) moveWordRight: (id)sender; +- (void) moveWordRightAndModifySelection: (id)sender; +#endif +#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) +- (void) insertContainerBreak: (id)sender; +- (void) insertLineBreak: (id)sender; +- (void) tabletPoint:(NSEvent *)event; +- (void) tabletProximity:(NSEvent *)event; +#endif @end #endif diff --git a/Headers/AppKit/NSWindowController.h b/Headers/AppKit/NSWindowController.h index 065e07980..d8da47c64 100644 --- a/Headers/AppKit/NSWindowController.h +++ b/Headers/AppKit/NSWindowController.h @@ -38,17 +38,17 @@ { @private NSWindow *_window; - NSString *_windowNibName; - NSString *_windowNibPath; - NSString *_windowFrameAutosaveName; + NSString *_window_nib_name; + NSString *_window_nib_path; + NSString *_window_frame_autosave_name; NSDocument *_document; - NSArray *_topLevelObjects; + NSArray *_top_level_objects; id _owner; struct ___wcFlags { - unsigned int shouldCloseDocument:1; - unsigned int shouldCascade:1; - unsigned int nibIsLoaded:1; + unsigned int should_close_document:1; + unsigned int should_cascade:1; + unsigned int nib_is_loaded:1; unsigned int RESERVED:29; } _wcFlags; void *_reserved1; diff --git a/Printing/GSCUPS/GSCUPSPrintOperation.m b/Printing/GSCUPS/GSCUPSPrintOperation.m index da3af7ffa..894d01a83 100644 --- a/Printing/GSCUPS/GSCUPSPrintOperation.m +++ b/Printing/GSCUPS/GSCUPSPrintOperation.m @@ -97,9 +97,9 @@ //NSMutableArray *args; NSDebugMLLog(@"GSPrinting", @""); - name = [[_printInfo printer] name]; + name = [[[self printInfo] printer] name]; status = [NSString stringWithFormat: @"Spooling to printer %@.", name]; - [_printPanel _setStatusStringValue: status]; + [[self printPanel] _setStatusStringValue: status]; cupsPrintFile( [name UTF8String], [_path UTF8String], @@ -107,7 +107,7 @@ 0, NULL ); - //dict = [_printInfo dictionary]; + //dict = [[self printInfo] dictionary]; //args = [NSMutableArray array]; //copies = [[dict objectForKey: NSPrintCopies] intValue]; //if (copies > 1) @@ -141,7 +141,7 @@ } NSDebugMLLog(@"GSPrinting", @"Creating context."); - info = [_printInfo dictionary]; + info = [[self printInfo] dictionary]; output = [info objectForKey: NSPrintSavePath]; if (output) diff --git a/Printing/GSLPR/GSLPRPrintOperation.m b/Printing/GSLPR/GSLPRPrintOperation.m index 1c3ce5c52..64f7d280f 100644 --- a/Printing/GSLPR/GSLPRPrintOperation.m +++ b/Printing/GSLPR/GSLPRPrintOperation.m @@ -102,11 +102,11 @@ NSMutableArray *args; NSDebugMLLog(@"GSPrinting", @""); - name = [[_printInfo printer] name]; + name = [[[self printInfo] printer] name]; status = [NSString stringWithFormat: @"Spooling to printer %@.", name]; - [_printPanel _setStatusStringValue: status]; + [[self printPanel] _setStatusStringValue: status]; - dict = [_printInfo dictionary]; + dict = [[self printInfo] dictionary]; args = [NSMutableArray array]; copies = [[dict objectForKey: NSPrintCopies] intValue]; if (copies > 1) @@ -140,7 +140,7 @@ } NSDebugMLLog(@"GSPrinting", @"Creating context."); - info = [_printInfo dictionary]; + info = [[self printInfo] dictionary]; output = [info objectForKey: NSPrintSavePath]; if (output) diff --git a/Source/GNUmakefile b/Source/GNUmakefile index b499b31c5..ffed9d66f 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -347,7 +347,6 @@ NSWindow+Toolbar.h \ NSWorkspace.h \ NSAttributedString.h \ NSColorPicking.h \ -NSDocumentFrameworkPrivate.h \ NSDragging.h \ NSGraphics.h \ NSNibConnector.h \ diff --git a/Source/GSEPSPrintOperation.m b/Source/GSEPSPrintOperation.m index 37adffab8..c0330d70a 100644 --- a/Source/GSEPSPrintOperation.m +++ b/Source/GSEPSPrintOperation.m @@ -98,8 +98,8 @@ { /* Save this for the view to look at. Seems like there should be a better way to pass it to beginDocument */ - [[_printInfo dictionary] setObject: [NSValue valueWithRect: _rect] - forKey: @"NSPrintSheetBounds"]; + [[[self printInfo] dictionary] setObject: [NSValue valueWithRect: _rect] + forKey: @"NSPrintSheetBounds"]; [_view beginDocument]; @@ -136,7 +136,7 @@ if (_context) return _context; - info = [_printInfo dictionary]; + info = [[self printInfo] dictionary]; [info setObject: _path forKey: @"NSOutputFile"]; diff --git a/Source/GSPrintOperation.m b/Source/GSPrintOperation.m index cd6936044..8a137465c 100644 --- a/Source/GSPrintOperation.m +++ b/Source/GSPrintOperation.m @@ -88,7 +88,7 @@ toData: [NSMutableData data] printInfo: aPrintInfo]; - _showPanels = YES; + [self setShowPanels: YES]; return self; } @@ -116,7 +116,7 @@ NSString *job; success = YES; - job = [_printInfo jobDisposition]; + job = [[self printInfo] jobDisposition]; if ([job isEqual: NSPrintPreviewJob]) { /* Check to see if there is a GNUstep app that can preview PS files. @@ -126,7 +126,7 @@ NSTask *task; NSString *preview; NSWorkspace *ws = [NSWorkspace sharedWorkspace]; - [_printPanel _setStatusStringValue: @"Opening in previewer..."]; + [[self printPanel] _setStatusStringValue: @"Opening in previewer..."]; preview = [ws getBestAppInRole: @"Viewer" forExtension: @"ps"]; diff --git a/Source/GSServicesManager.m b/Source/GSServicesManager.m index ee4d444b7..1971eb303 100644 --- a/Source/GSServicesManager.m +++ b/Source/GSServicesManager.m @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include diff --git a/Source/NSApplication.m b/Source/NSApplication.m index ce940b20f..a4cb52283 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -33,18 +33,24 @@ #include #include -#include +#include +#include +#include #include #include +#include +#include #include #include -#include -#include -#include +#include #include -#include +#include +#include +#include +#include +#include #include -#include +#include #ifndef LIB_FOUNDATION_LIBRARY # include @@ -52,20 +58,20 @@ #include "AppKit/AppKitExceptions.h" #include "AppKit/NSApplication.h" +#include "AppKit/NSCell.h" +#include "AppKit/NSCursor.h" #include "AppKit/NSDocumentController.h" -#include "AppKit/NSPasteboard.h" -#include "AppKit/NSFontManager.h" -#include "AppKit/NSPanel.h" #include "AppKit/NSEvent.h" +#include "AppKit/NSFontManager.h" #include "AppKit/NSImage.h" #include "AppKit/NSMenu.h" #include "AppKit/NSMenuItem.h" -#include "AppKit/NSMenuItemCell.h" -#include "AppKit/NSMenuView.h" -#include "AppKit/NSCursor.h" -#include "AppKit/NSWorkspace.h" #include "AppKit/NSNibLoading.h" #include "AppKit/NSPageLayout.h" +#include "AppKit/NSPanel.h" +#include "AppKit/NSPasteboard.h" +#include "AppKit/NSWorkspace.h" +#include "AppKit/NSScreen.h" #include "AppKit/PSOperators.h" #include "GNUstepGUI/GSDisplayServer.h" diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index 83b9b9617..6cbcd48c7 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -28,10 +28,16 @@ */ #include -#include -#include #include +#include +#include +#include #include +#include +#include +#include +#include + #include "AppKit/NSAttributedString.h" #include "AppKit/NSDocumentController.h" #include "AppKit/NSParagraphStyle.h" diff --git a/Source/NSCell.m b/Source/NSCell.m index c73087897..719b3bdf1 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -99,7 +99,7 @@ static NSColor *shadowCol; { if (self == [NSCell class]) { - [self setVersion: 1]; + [self setVersion: 2]; colorClass = [NSColor class]; cellClass = [NSCell class]; fontClass = [NSFont class]; @@ -117,11 +117,16 @@ static NSColor *shadowCol; } } -+ (NSMenu*)defaultMenu ++ (NSMenu*) defaultMenu { return nil; } ++ (NSFocusRingType) defaultFocusRingType +{ + return NSFocusRingTypeDefault; +} + /**

This class method returns NO. This method should be overrided by subclasses.

*/ @@ -170,6 +175,7 @@ static NSColor *shadowCol; //_cell.state = 0; _action_mask = NSLeftMouseUpMask; _menu = [isa defaultMenu]; + [self setFocusRingType: [isa defaultFocusRingType]]; return self; } @@ -199,6 +205,7 @@ static NSColor *shadowCol; //_cell.is_selectable = NO; _action_mask = NSLeftMouseUpMask; _menu = [isa defaultMenu]; + [self setFocusRingType: [isa defaultFocusRingType]]; return self; } @@ -209,7 +216,7 @@ static NSColor *shadowCol; TEST_RELEASE (_cell_image); TEST_RELEASE (_font); TEST_RELEASE (_represented_object); - TEST_RELEASE (_objectValue); + TEST_RELEASE (_object_value); TEST_RELEASE (_formatter); TEST_RELEASE (_menu); @@ -223,7 +230,7 @@ static NSColor *shadowCol; { if (_cell.has_valid_object_value) { - return _objectValue; + return _object_value; } else { @@ -242,9 +249,9 @@ static NSColor *shadowCol; - (double) doubleValue { if ((_cell.has_valid_object_value == YES) && - ([_objectValue respondsToSelector: @selector(doubleValue)])) + ([_object_value respondsToSelector: @selector(doubleValue)])) { - return [_objectValue doubleValue]; + return [_object_value doubleValue]; } else { @@ -258,9 +265,9 @@ static NSColor *shadowCol; - (float) floatValue { if ((_cell.has_valid_object_value == YES) && - ([_objectValue respondsToSelector: @selector(floatValue)])) + ([_object_value respondsToSelector: @selector(floatValue)])) { - return [_objectValue floatValue]; + return [_object_value floatValue]; } else { @@ -274,9 +281,9 @@ static NSColor *shadowCol; - (int) intValue { if ((_cell.has_valid_object_value == YES) && - ([_objectValue respondsToSelector: @selector(intValue)])) + ([_object_value respondsToSelector: @selector(intValue)])) { - return [_objectValue intValue]; + return [_object_value intValue]; } else { @@ -291,7 +298,7 @@ static NSColor *shadowCol; { if (_cell.contents_is_attributed_string == NO) { - // If we have a formatter this is also the string of the _objectValue + // If we have a formatter this is also the string of the _object_value return _contents; } else @@ -304,7 +311,7 @@ static NSColor *shadowCol; { id newContents; - ASSIGN (_objectValue, object); + ASSIGN (_object_value, object); if (_formatter == nil) { @@ -322,14 +329,14 @@ static NSColor *shadowCol; } else { - newContents = [_objectValue description]; + newContents = [_object_value description]; _cell.contents_is_attributed_string = NO; _cell.has_valid_object_value = YES; } } else { - newContents = [_formatter stringForObjectValue: _objectValue]; + newContents = [_formatter stringForObjectValue: _object_value]; _cell.contents_is_attributed_string = NO; if (newContents != nil) { @@ -414,7 +421,7 @@ static NSColor *shadowCol; if (_formatter == nil) { ASSIGN (_contents, string); - ASSIGN (_objectValue, string); + ASSIGN (_object_value, string); _cell.has_valid_object_value = YES; } else @@ -708,6 +715,16 @@ static NSColor *shadowCol; _cell.is_bezeled = NO; } +- (NSFocusRingType) focusRingType +{ + return _cell.focus_ring_type; +} + +- (void) setFocusRingType: (NSFocusRingType)type +{ + _cell.focus_ring_type = type; +} + /**

Sets the NSCell's state. Please use always symbolic constants when calling this method. The integer values could be changed in the this implementation. (Currently they match the Cocoa values but they are @@ -896,6 +913,11 @@ static NSColor *shadowCol; if (flag) { _cell.is_scrollable = NO; + [self setLineBreakMode: NSLineBreakByWordWrapping]; + } + else + { + [self setLineBreakMode: NSLineBreakByClipping]; } } @@ -935,7 +957,7 @@ static NSColor *shadowCol; NSAttributedString *attrStr; attributes = [self _nonAutoreleasedTypingAttributes]; - attrStr = [_formatter attributedStringForObjectValue: _objectValue + attrStr = [_formatter attributedStringForObjectValue: _object_value withDefaultAttributes: attributes]; RELEASE(attributes); if (attrStr != nil) @@ -1022,6 +1044,26 @@ static NSColor *shadowCol; [self setStringValue: aString]; } +- (NSLineBreakMode) lineBreakMode +{ + return _cell.line_break_mode; +} + +- (void) setLineBreakMode: (NSLineBreakMode)mode +{ + _cell.line_break_mode = mode; +} + +- (NSWritingDirection) baseWritingDirection +{ + return _cell.base_writing_direction; +} + +- (void) setBaseWritingDirection: (NSWritingDirection)direction +{ + _cell.base_writing_direction = direction; +} + /**

Implemented by subclasses to return the action method. The NSCell implementaiton returns NULL.

See Also: -setAction: -setTarget: -target

@@ -1247,7 +1289,7 @@ static NSColor *shadowCol; } /* - * respond to keyboard + * Should this cell respond to keyboard input? */ - (BOOL) acceptsFirstResponder { @@ -1287,23 +1329,19 @@ static NSColor *shadowCol; - (void) setMnemonicLocation: (unsigned int)location { - _mnemonic_location = location; + _cell.mnemonic_location = location; } - (unsigned int) mnemonicLocation { - return _mnemonic_location; + return _cell.mnemonic_location; } -/* Apple Compatibility method - do not use - please test whether the - cell is enabled or disabled instead. */ - (BOOL) refusesFirstResponder { return _cell.refuses_first_responder; } -/* Apple Compatibility method - do not use - please disable the cell - instead. */ - (void) setRefusesFirstResponder: (BOOL)flag { _cell.refuses_first_responder = flag; @@ -1845,24 +1883,22 @@ static NSColor *shadowCol; - (void) setControlSize: (NSControlSize)controlSize { - // FIXME + _cell.control_size = controlSize; } - (NSControlSize) controlSize { - // FIXME - return NSRegularControlSize; + return _cell.control_size; } - (void) setControlTint: (NSControlTint)controlTint { - // FIXME + _cell.control_tint = controlTint; } - (NSControlTint) controlTint { - // FIXME - return NSDefaultControlTint; + return _cell.control_tint; } /**

This method is used by subclasses to specified the control view. @@ -1947,7 +1983,10 @@ static NSColor *shadowCol; } if (_cell.shows_first_responder) - NSDottedFrameRect(cellFrame); + { + // FIXME: Should depend on _cell.focus_ring_type + NSDottedFrameRect(cellFrame); + } // NB: We don't do any highlighting to make it easier for subclasses // to reuse this code while doing their own custom highlighting and @@ -2082,7 +2121,7 @@ static NSColor *shadowCol; { NSString *contents; - contents = [_formatter editingStringForObjectValue: _objectValue]; + contents = [_formatter editingStringForObjectValue: _object_value]; if (contents == nil) { contents = _contents; @@ -2126,7 +2165,7 @@ static NSColor *shadowCol; [clipView removeFromSuperview]; } -/**

TODO.This method does nothing if a the controlView is nil, +/**

This method does nothing if the controlView is nil, if text object does not exist or if the cell's type is not NSTextCellType

*/ @@ -2148,7 +2187,7 @@ static NSColor *shadowCol; { NSString *contents; - contents = [_formatter editingStringForObjectValue: _objectValue]; + contents = [_formatter editingStringForObjectValue: _object_value]; if (contents == nil) { contents = _contents; @@ -2185,6 +2224,16 @@ static NSColor *shadowCol; _cell.sends_action_on_end_editing = flag; } +- (BOOL) allowsUndo +{ + return _cell.allows_undo; +} + +- (void) setAllowsUndo: (BOOL)flag +{ + _cell.allows_undo = flag; +} + /* * Copying */ @@ -2198,7 +2247,7 @@ static NSColor *shadowCol; pointers to the objects are copied. We need to RETAIN them all though. */ TEST_RETAIN (_font); - TEST_RETAIN (_objectValue); + TEST_RETAIN (_object_value); TEST_RETAIN (_menu); TEST_RETAIN (_cell_image); TEST_RETAIN (_formatter); @@ -2218,40 +2267,55 @@ static NSColor *shadowCol; unsigned int cFlags2 = 0; // encode contents - [aCoder encodeObject: _contents forKey: @"NSContents"]; + [aCoder encodeObject: [self objectValue] forKey: @"NSContents"]; // flags + cFlags |= [self focusRingType]; + cFlags |= [self showsFirstResponder] ? 0x4 : 0; + cFlags |= (_action_mask & NSLeftMouseUpMask) ? 0 : 0x20; cFlags |= [self wraps] ? 0x40 : 0; + cFlags |= (_action_mask & NSLeftMouseDraggedMask) ? 0x100 : 0; + cFlags |= ([self lineBreakMode] << 12); + cFlags |= (_action_mask & NSLeftMouseDownMask) ? 0x40000 : 0; + cFlags |= [self isContinuous] ? 0x80000 : 0; cFlags |= [self isScrollable] ? 0x100000 : 0; - cFlags |= [self isSelectable] ? 0x200001 : 0; + cFlags |= [self isSelectable] ? 0x200000 : 0; cFlags |= [self isBezeled] ? 0x400000 : 0; cFlags |= [self isBordered] ? 0x800000 : 0; - cFlags |= ([self type] == NSTextCellType) ? 0x4000000 : 0; - cFlags |= [self isContinuous] ? 0x40000 : 0; + cFlags |= ([self type] << 26); cFlags |= [self isEditable] ? 0x10000000 : 0; cFlags |= ([self isEnabled] == NO) ? 0x20000000 : 0; - cFlags |= ([self state] == NSOnState) ? 0x80000000 : 0; cFlags |= [self isHighlighted] ? 0x40000000 : 0; + cFlags |= ([self state] == NSOnState) ? 0x80000000 : 0; [aCoder encodeInt: cFlags forKey: @"NSCellFlags"]; // flags part 2 + cFlags2 |= ([self controlTint] << 5); + cFlags2 |= ([self controlSize] << 17); cFlags2 |= [self sendsActionOnEndEditing] ? 0x400000 : 0; cFlags2 |= [self allowsMixedState] ? 0x1000000 : 0; cFlags2 |= [self refusesFirstResponder] ? 0x2000000 : 0; - cFlags2 |= ([self alignment] == NSRightTextAlignment) ? 0x4000000 : 0; - cFlags2 |= ([self alignment] == NSCenterTextAlignment) ? 0x8000000 : 0; - cFlags2 |= ([self alignment] == NSJustifiedTextAlignment) ? 0xC000000 : 0; - cFlags2 |= ([self alignment] == NSNaturalTextAlignment) ? 0x10000000 : 0; + cFlags2 |= ([self alignment] << 26); cFlags2 |= [self importsGraphics] ? 0x20000000 : 0; cFlags2 |= [self allowsEditingTextAttributes] ? 0x40000000 : 0; [aCoder encodeInt: cFlags2 forKey: @"NSCellFlags2"]; - // font and formatter. - [aCoder encodeObject: [self font] forKey: @"NSSupport"]; - - if ([self formatter]) - { - [aCoder encodeObject: [self formatter] forKey: @"NSFormatter"]; + if (_cell.type == NSTextCellType) + { + // font and formatter. + if ([self font]) + { + [aCoder encodeObject: [self font] forKey: @"NSSupport"]; + } + + if ([self formatter]) + { + [aCoder encodeObject: [self formatter] forKey: @"NSFormatter"]; + } + } + else if ([self image]) + { + [aCoder encodeObject: [self image] forKey: @"NSSupport"]; } } else @@ -2262,7 +2326,7 @@ static NSColor *shadowCol; [aCoder encodeObject: _contents]; [aCoder encodeObject: _cell_image]; [aCoder encodeObject: _font]; - [aCoder encodeObject: _objectValue]; + [aCoder encodeObject: _object_value]; flag = _cell.contents_is_attributed_string; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; flag = _cell.is_highlighted; @@ -2297,7 +2361,7 @@ static NSColor *shadowCol; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; flag = _cell.allows_mixed_state; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; - flag = _cell.wraps; + flag = [self wraps]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; tmp_int = _cell.text_align; [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; @@ -2307,14 +2371,29 @@ static NSColor *shadowCol; [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; tmp_int = _cell.entry_type; [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + // FIXME: State may be -1, why do we encode it as unsigned? tmp_int = _cell.state; [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; - [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &_mnemonic_location]; + tmp_int = _cell.mnemonic_location; + [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &_mouse_down_flags]; [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &_action_mask]; [aCoder encodeValueOfObjCType: @encode(id) at: &_formatter]; [aCoder encodeValueOfObjCType: @encode(id) at: &_menu]; [aCoder encodeValueOfObjCType: @encode(id) at: &_represented_object]; + + tmp_int = _cell.allows_undo; + [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + tmp_int = _cell.line_break_mode; + [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + tmp_int = _cell.control_tint; + [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + tmp_int = _cell.control_size; + [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + tmp_int = _cell.focus_ring_type; + [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + tmp_int = _cell.base_writing_direction; + [aCoder encodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; } } @@ -2336,66 +2415,67 @@ static NSColor *shadowCol; else { self = [self init]; + [self setObjectValue: contents]; } if ([aDecoder containsValueForKey: @"NSCellFlags"]) { unsigned long cFlags; - + unsigned long mask = 0; cFlags = [aDecoder decodeIntForKey: @"NSCellFlags"]; + [self setFocusRingType: (cFlags & 0x3)]; + [self setShowsFirstResponder: ((cFlags & 0x4) == 0x4)]; + // This bit flag is the other way around! + if ((cFlags & 0x20) != 0x20) + mask |= NSLeftMouseUpMask; // This bit flag is the other way around! [self setWraps: ((cFlags & 0x40) != 0x40)]; + if ((cFlags & 0x100) == 0x100) + mask |= NSLeftMouseDraggedMask; + [self setLineBreakMode: ((cFlags & 0x7000) >> 12)]; + if ((cFlags & 0x40000) == 0x40000) + mask |= NSLeftMouseDownMask; + if ((cFlags & 0x80000) == 0x80000) + mask |= NSPeriodicMask; + [self sendActionOn: mask]; [self setScrollable: ((cFlags & 0x100000) == 0x100000)]; - // Strange that this is not a simple bit flag - [self setSelectable: ((cFlags & 0x200001) == 0x200001)]; + [self setSelectable: ((cFlags & 0x200000) == 0x200000)]; [self setBezeled: ((cFlags & 0x400000) == 0x400000)]; [self setBordered: ((cFlags & 0x800000) == 0x800000)]; - if ((cFlags & 0x4000000) == 0x4000000) - { - [self setType: NSTextCellType]; - } - - [self setContinuous: ((cFlags & 0x40000) == 0x40000)]; + [self setType: ((cFlags & 0xC000000) >> 26)]; [self setEditable: ((cFlags & 0x10000000) == 0x10000000)]; // This bit flag is the other way around! [self setEnabled: ((cFlags & 0x20000000) != 0x20000000)]; [self setHighlighted: ((cFlags & 0x40000000) == 0x40000000)]; - [self setState: ((cFlags & 0x80000000) == 0x80000000)?NSOnState:NSOffState]; + [self setState: ((cFlags & 0x80000000) == 0x80000000) ? NSOnState : NSOffState]; } if ([aDecoder containsValueForKey: @"NSCellFlags2"]) { int cFlags2; cFlags2 = [aDecoder decodeIntForKey: @"NSCellFlags2"]; + [self setControlTint: ((cFlags2 & 0xE0) >> 5)]; + [self setControlSize: ((cFlags2 & 0xE0000) >> 17)]; [self setSendsActionOnEndEditing: (cFlags2 & 0x400000)]; [self setAllowsMixedState: ((cFlags2 & 0x1000000) == 0x1000000)]; [self setRefusesFirstResponder: ((cFlags2 & 0x2000000) == 0x2000000)]; - if ((cFlags2 & 0x4000000) == 0x4000000) - { - [self setAlignment: NSRightTextAlignment]; - } - if ((cFlags2 & 0x8000000) == 0x8000000) - { - [self setAlignment: NSCenterTextAlignment]; - } - if ((cFlags2 & 0xC000000) == 0xC000000) - { - [self setAlignment: NSJustifiedTextAlignment]; - } - if ((cFlags2 & 0x10000000) == 0x10000000) - { - [self setAlignment: NSNaturalTextAlignment]; - } - + [self setAlignment: ((cFlags2 & 0x1C000000) >> 26)]; [self setImportsGraphics: ((cFlags2 & 0x20000000) == 0x20000000)]; [self setAllowsEditingTextAttributes: ((cFlags2 & 0x40000000) == 0x40000000)]; } if ([aDecoder containsValueForKey: @"NSSupport"]) { - NSFont *support = [aDecoder decodeObjectForKey: @"NSSupport"]; + id support = [aDecoder decodeObjectForKey: @"NSSupport"]; - [self setFont: support]; + if ([support isKindOfClass: [NSFont class]]) + { + [self setFont: support]; + } + else if ([support isKindOfClass: [NSImage class]]) + { + [self setImage: support]; + } } if ([aDecoder containsValueForKey: @"NSFormatter"]) { @@ -2409,11 +2489,12 @@ static NSColor *shadowCol; BOOL flag; unsigned int tmp_int; id formatter, menu; + int version = [aDecoder versionForClassName: @"NSCell"]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_contents]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_cell_image]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_font]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_objectValue]; + [aDecoder decodeValueOfObjCType: @encode(id) at: &_object_value]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; _cell.contents_is_attributed_string = flag; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; @@ -2457,8 +2538,8 @@ static NSColor *shadowCol; _cell.entry_type = tmp_int; [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; _cell.state = tmp_int; - [aDecoder decodeValueOfObjCType: @encode(unsigned int) - at: &_mnemonic_location]; + [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + _cell.mnemonic_location = tmp_int; [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &_mouse_down_flags]; [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &_action_mask]; @@ -2472,7 +2553,7 @@ static NSColor *shadowCol; { NSString *contents; - contents = [_formatter stringForObjectValue: _objectValue]; + contents = [_formatter stringForObjectValue: _object_value]; if (contents != nil) { _cell.has_valid_object_value = YES; @@ -2480,6 +2561,22 @@ static NSColor *shadowCol; _cell.contents_is_attributed_string = NO; } } + + if (version >= 2) + { + [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + _cell.allows_undo = tmp_int; + [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + _cell.line_break_mode = tmp_int; + [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + _cell.control_tint = tmp_int; + [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + _cell.control_size = tmp_int; + [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + _cell.focus_ring_type = tmp_int; + [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int]; + _cell.base_writing_direction = tmp_int; + } } return self; } @@ -2507,21 +2604,12 @@ static NSColor *shadowCol; NSMutableParagraphStyle *paragraphStyle; color = [self textColor]; - /* Note: there are only 6 possible paragraph styles for cells. - TODO: Create them once at the beginning, and reuse them for the whole - app lifetime. */ + /* Note: There are only a few possible paragraph styles for cells. + TODO: Cache them and reuse them for the whole app lifetime. */ paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; - - if (_cell.wraps) - { - [paragraphStyle setLineBreakMode: NSLineBreakByWordWrapping]; - } - else - { - [paragraphStyle setLineBreakMode: NSLineBreakByClipping]; - } - - [paragraphStyle setAlignment: _cell.text_align]; + [paragraphStyle setLineBreakMode: [self lineBreakMode]]; + [paragraphStyle setBaseWritingDirection: [self baseWritingDirection]]; + [paragraphStyle setAlignment: [self alignment]]; attr = [[NSDictionary alloc] initWithObjectsAndKeys: _font, NSFontAttributeName, diff --git a/Source/NSDocument.m b/Source/NSDocument.m index 7a91ec4ad..b328134c3 100644 --- a/Source/NSDocument.m +++ b/Source/NSDocument.m @@ -7,7 +7,7 @@ Author: Carl Lindberg Date: 1999 Modifications: Fred Kiefer - Date: June 2000 + Date: June 2000, Dec 2006 This file is part of the GNUstep GUI Library. @@ -28,15 +28,16 @@ */ #include +#include "AppKit/NSBox.h" #include "AppKit/NSDocument.h" #include "AppKit/NSFileWrapper.h" #include "AppKit/NSSavePanel.h" -#include "AppKit/NSPrintInfo.h" #include "AppKit/NSPageLayout.h" -#include "AppKit/NSView.h" +#include "AppKit/NSPrintInfo.h" +#include "AppKit/NSPrintOperation.h" #include "AppKit/NSPopUpButton.h" +#include "AppKit/NSView.h" #include "AppKit/NSDocumentFrameworkPrivate.h" -#include "AppKit/NSBox.h" #include "GSGuiPrivate.h" @@ -69,16 +70,16 @@ self = [super init]; if (self != nil) { - _documentIndex = untitledCount++; - _windowControllers = [[NSMutableArray alloc] init]; + _document_index = untitledCount++; + _window_controllers = [[NSMutableArray alloc] init]; fileTypes = [[self class] readableTypes]; - _docFlags.hasUndoManager = YES; + _doc_flags.has_undo_manager = YES; /* Set our default type */ if ([fileTypes count]) { [self setFileType: [fileTypes objectAtIndex: 0]]; - ASSIGN(_saveType, [fileTypes objectAtIndex: 0]); + ASSIGN(_save_type, [fileTypes objectAtIndex: 0]); } } return self; @@ -94,10 +95,12 @@ self = [self init]; if (self != nil) { - [self setFileType: fileType]; - [self setFileName: fileName]; - - if (![self readFromFile: fileName ofType: fileType]) + if ([self readFromFile: fileName ofType: fileType]) + { + [self setFileType: fileType]; + [self setFileName: fileName]; + } + else { NSRunAlertPanel (_(@"Load failed"), _(@"Could not load file %@."), @@ -121,7 +124,7 @@ if ([self readFromURL: url ofType: fileType]) { [self setFileType: fileType]; - [self setFileName:[url path]]; + [self setFileName: [url path]]; } else { @@ -134,52 +137,172 @@ return self; } +- (id)initForURL: (NSURL *)forUrl +withContentsOfURL: (NSURL *)url + ofType: (NSString *)type + error: (NSError **)error +{ + self = [self initWithType: type error: error]; + if (self != nil) + { + if ([self readFromURL: url + ofType: type + error: error]) + { + if (forUrl != nil) + { + [self setFileURL: forUrl]; + } + } + else + { + DESTROY(self); + } + } + return self; +} + +- (id)initWithContentsOfURL: (NSURL *)url + ofType: (NSString *)type + error: (NSError **)error +{ + return [self initForURL: url + withContentsOfURL: url + ofType: type + error: error]; +} + +- (id)initWithType:(NSString *)type + error:(NSError **)error +{ + self = [self init]; + if (self != nil) + { + [self setFileType: type]; + } + return self; +} + - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver: self]; - RELEASE(_undoManager); - RELEASE(_fileName); - RELEASE(_fileType); - RELEASE(_windowControllers); + RELEASE(_undo_manager); + RELEASE(_file_name); + RELEASE(_file_url); + RELEASE(_file_type); + RELEASE(_last_component_file_name); + RELEASE(_autosaved_file_url); + RELEASE(_file_modification_date); + RELEASE(_window_controllers); RELEASE(_window); - RELEASE(_printInfo); - RELEASE(savePanelAccessory); - RELEASE(spaButton); - RELEASE(_saveType); + RELEASE(_print_info); + RELEASE(_save_panel_accessory); + RELEASE(_spa_button); + RELEASE(_save_type); [super dealloc]; } +/* + * Private helper method to check, if the method given via the selector sel + * has been overridden in the current subclass. + */ +- (BOOL)_hasOverridden: (SEL)sel +{ + // The actual signature is not important as we wont call the methods. + IMP meth1; + IMP meth2; + + meth1 = [self methodForSelector: sel]; + meth2 = [[NSDocument class] instanceMethodForSelector: sel]; + + return (meth1 != meth2); +} + +#define OVERRIDDEN(sel) [self _hasOverridden: @selector(sel)] + - (NSString *)fileName { - return _fileName; + return _file_name; } - (void)setFileName: (NSString *)fileName { - ASSIGN(_fileName, fileName); - - [_windowControllers makeObjectsPerformSelector: - @selector(synchronizeWindowTitleWithDocumentName)]; + // This check is to prevent super calls from recursing. + if (!OVERRIDDEN(setFileName:)) + { + [self setFileURL: [NSURL fileURLWithPath: fileName]]; + } + ASSIGN(_file_name, fileName); + [self setLastComponentOfFileName: [_file_name lastPathComponent]]; } - (NSString *)fileType { - return _fileType; + return _file_type; } - (void)setFileType: (NSString *)type { - ASSIGN(_fileType, type); + ASSIGN(_file_type, type); +} + +- (NSURL *)fileURL +{ + if (OVERRIDDEN(fileName)) + { + return [NSURL fileURLWithPath: [self fileName]]; + } + else + { + return _file_url; + } +} + +- (void)setFileURL: (NSURL *)url +{ + if (OVERRIDDEN(setFileName:) && + ((url == nil) || [url isFileURL])) + { + [self setFileName: [url path]]; + } + else + { + ASSIGN(_file_url, url); + [self setLastComponentOfFileName: [[_file_url path] lastPathComponent]]; + } +} + +- (NSDate *)fileModificationDate +{ + return _file_modification_date; +} + +- (void)setFileModificationDate: (NSDate *)date +{ + ASSIGN(_file_modification_date, date); +} + +- (NSString *)lastComponentOfFileName +{ + return _last_component_file_name; +} + +- (void)setLastComponentOfFileName: (NSString *)str +{ + ASSIGN(_last_component_file_name, str); + + [[self windowControllers] makeObjectsPerformSelector: + @selector(synchronizeWindowTitleWithDocumentName)]; } - (NSArray *)windowControllers { - return _windowControllers; + return _window_controllers; } - (void)addWindowController: (NSWindowController *)windowController { - [_windowControllers addObject: windowController]; + [_window_controllers addObject: windowController]; if ([windowController document] != self) { [windowController setDocument: self]; @@ -188,10 +311,10 @@ - (void)removeWindowController: (NSWindowController *)windowController { - if ([_windowControllers containsObject: windowController]) + if ([_window_controllers containsObject: windowController]) { [windowController setDocument: nil]; - [_windowControllers removeObject: windowController]; + [_window_controllers removeObject: windowController]; } } @@ -208,6 +331,19 @@ _window = aWindow; } +- (NSWindow *)windowForSheet +{ + NSWindow *win; + + if (([_window_controllers count] > 0) && + ((win = [[_window_controllers objectAtIndex: 0] window]) != nil)) + { + return win; + } + + return [NSApp mainWindow]; +} + /** * Creates the window controllers for the current document. Calls * addWindowController: on the receiver to add them to the controller @@ -241,25 +377,34 @@ */ - (void) showWindows { - [_windowControllers makeObjectsPerformSelector: @selector(showWindow:) + [_window_controllers makeObjectsPerformSelector: @selector(showWindow:) withObject: self]; } - (BOOL) isDocumentEdited { - return _changeCount != 0; + return _change_count != 0; } - (void)updateChangeCount: (NSDocumentChangeType)change { - int i, count = [_windowControllers count]; + int i, count = [_window_controllers count]; BOOL isEdited; switch (change) { - case NSChangeDone: _changeCount++; break; - case NSChangeUndone: _changeCount--; break; - case NSChangeCleared: _changeCount = 0; break; + case NSChangeDone: _change_count++; + _autosave_change_count++; + break; + case NSChangeUndone: _change_count--; + _autosave_change_count--; + break; + case NSChangeReadOtherContents: + case NSChangeCleared: _change_count = 0; + _autosave_change_count = 0; + break; + case NSChangeAutosaved: _autosave_change_count = 0; + break; } /* @@ -272,7 +417,7 @@ for (i=0; i 0) + { + NSString *extension = [extensions objectAtIndex: 0]; + NSString *newFileName = [[fileName stringByDeletingPathExtension] + stringByAppendingPathExtension: extension]; + + if ([fileManager fileExistsAtPath: newFileName]) + { + backupFilename = [self _backupFileNameFor: newFileName]; + + if (![self _writeBackupForFile: newFileName + toFile: backupFilename]) + { + return NO; + } + } + + if ([self writeToFile: fileName + ofType: fileType + originalFile: backupFilename + saveOperation: saveOp]) + { + // FIXME: Should set the file attributes + + if (saveOp != NSSaveToOperation) + { + [self setFileName: newFileName]; + [self setFileType: fileType]; + [self updateChangeCount: NSChangeCleared]; + } + + if (backupFilename && ![self keepBackupFile]) + { + [fileManager removeFileAtPath: backupFilename handler: nil]; + } + + return YES; + } + } + } + + return NO; +} + +- (BOOL)writeSafelyToURL: (NSURL *)url + ofType: (NSString *)type + forSaveOperation: (NSSaveOperationType)saveOp + error: (NSError **)error +{ + NSDictionary *attrs; + NSURL *original = [self fileURL]; + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString *backupFilename = nil; + BOOL isNativeType = [[self class] isNativeType: type]; + + if (OVERRIDDEN(writeWithBackupToFile:ofType:saveOperation:)) + { + if (saveOp == NSAutosaveOperation) + { + saveOp = NSSaveToOperation; + } + + return [self writeWithBackupToFile: [url path] + ofType: type + saveOperation: saveOp]; + } + + if (!isNativeType || (url == nil)) + { + return NO; + } + + if (saveOp == NSSaveOperation) + { + if ([url isFileURL]) + { + NSString *newFileName; + + newFileName = [url path]; + if ([fileManager fileExistsAtPath: newFileName]) + { + backupFilename = [self _backupFileNameFor: newFileName]; + + if (![self _writeBackupForFile: newFileName + toFile: backupFilename]) + { + // FIXME: Set error. + return NO; + } + } + } + } + + if (![self writeToURL: url + ofType: type + forSaveOperation: saveOp + originalContentsURL: original + error: error]) + { + return NO; + } + + attrs = [self fileAttributesToWriteToURL: url + ofType: type + forSaveOperation: saveOp + originalContentsURL: original + error: error]; + // FIXME: Should set the file attributes + + if (saveOp != NSSaveToOperation) + { + [self setFileURL: url]; + [self setFileType: type]; + [self updateChangeCount: NSChangeCleared]; + } + + if (backupFilename && ![self keepBackupFile]) + { + [fileManager removeFileAtPath: backupFilename handler: nil]; + } + + return YES; +} + +- (BOOL)writeToURL: (NSURL *)url + ofType: (NSString *)type + error: (NSError **)error +{ + NSFileWrapper *wrapper; + + if (OVERRIDDEN(writeToFile:ofType:)) + { + return [self writeToFile: [url path] ofType: type]; + } + + wrapper = [self fileWrapperOfType: type + error: error]; + if (wrapper == nil) + { + return NO; + } + + return [wrapper writeToFile: [url path] atomically: YES updateFilenames: YES]; +} + +- (BOOL)writeToURL: (NSURL *)url + ofType: (NSString *)type + forSaveOperation: (NSSaveOperationType)saveOp +originalContentsURL: (NSURL *)orig + error: (NSError **)error +{ + if (OVERRIDDEN(writeToFile:ofType:originalFile:saveOperation:)) + { + if (saveOp == NSAutosaveOperation) + { + saveOp = NSSaveToOperation; + } + + return [self writeToFile: [url path] + ofType: type + originalFile: [orig path] + saveOperation: saveOp]; + } + + return [self writeToURL: url + ofType: type + error: error]; +} + - (IBAction)changeSaveType: (id)sender { NSDocumentController *controller = [NSDocumentController sharedDocumentController]; NSArray *extensions = nil; - ASSIGN(_saveType, [controller _nameForHumanReadableType: + ASSIGN(_save_type, [controller _nameForHumanReadableType: [sender titleOfSelectedItem]]); - extensions = [controller fileExtensionsFromType: _saveType]; + extensions = [controller fileExtensionsFromType: _save_type]; if ([extensions count] > 0) { [(NSSavePanel *)[sender window] setRequiredFileType: [extensions objectAtIndex:0]]; @@ -477,6 +947,27 @@ return [savePanel runModal]; } +- (void)runModalSavePanelForSaveOperation: (NSSaveOperationType)saveOperation + delegate: (id)delegate + didSaveSelector: (SEL)didSaveSelector + contextInfo: (void *)contextInfo +{ + NSString *fileName; + + // FIXME: Setting of the delegate of the save panel is missing + fileName = [self fileNameFromRunningSavePanelForSaveOperation: saveOperation]; + [self saveToFile: fileName + saveOperation: saveOperation + delegate: delegate + didSaveSelector: didSaveSelector + contextInfo: contextInfo]; +} + +- (BOOL)prepareSavePanel: (NSSavePanel *)savePanel +{ + return YES; +} + - (BOOL)shouldRunSavePanelWithAccessoryView { return YES; @@ -484,21 +975,21 @@ - (void) _createPanelAccessory { - if (savePanelAccessory == nil) + if (_save_panel_accessory == nil) { NSRect accessoryFrame = NSMakeRect(0,0,380,70); NSRect spaFrame = NSMakeRect(115,14,150,22); - savePanelAccessory = [[NSBox alloc] initWithFrame: accessoryFrame]; - [(NSBox *)savePanelAccessory setTitle: @"File Type"]; - [savePanelAccessory setAutoresizingMask: + _save_panel_accessory = [[NSBox alloc] initWithFrame: accessoryFrame]; + [(NSBox *)_save_panel_accessory setTitle: @"File Type"]; + [_save_panel_accessory setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - spaButton = [[NSPopUpButton alloc] initWithFrame: spaFrame]; - [spaButton setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable | NSViewMinYMargin | + _spa_button = [[NSPopUpButton alloc] initWithFrame: spaFrame]; + [_spa_button setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable | NSViewMinYMargin | NSViewMaxYMargin | NSViewMinXMargin | NSViewMaxXMargin]; - [spaButton setTarget: self]; - [spaButton setAction: @selector(changeSaveType:)]; - [savePanelAccessory addSubview: spaButton]; + [_spa_button setTarget: self]; + [_spa_button setAction: @selector(changeSaveType:)]; + [_save_panel_accessory addSubview: _spa_button]; } } - (void) _addItemsToSpaButtonFromArray: (NSArray *)types @@ -509,25 +1000,25 @@ while ((title = [en nextObject]) != nil) { - [spaButton addItemWithTitle: title]; + [_spa_button addItemWithTitle: title]; i++; } // if it's more than one, then - [spaButton setEnabled: (i > 0)]; + [_spa_button setEnabled: (i > 0)]; // if we have some items, select the current filetype. if (i > 0) { NSString *title = [[NSDocumentController sharedDocumentController] displayNameForType: [self fileType]]; - if ([spaButton itemWithTitle: title] != nil) + if ([_spa_button itemWithTitle: title] != nil) { - [spaButton selectItemWithTitle: title]; + [_spa_button selectItemWithTitle: title]; } else { - [spaButton selectItemAtIndex: 0]; + [_spa_button selectItemAtIndex: 0]; } } } @@ -546,12 +1037,12 @@ if ([self shouldRunSavePanelWithAccessoryView]) { - if (savePanelAccessory == nil) + if (_save_panel_accessory == nil) [self _createPanelAccessory]; [self _addItemsToSpaButtonFromArray: displayNames]; - accessory = savePanelAccessory; + accessory = _save_panel_accessory; } if ([displayNames count] > 0) @@ -595,6 +1086,39 @@ return nil; } +- (NSArray *)writableTypesForSaveOperation: (NSSaveOperationType)op +{ + NSArray *types = [isa writableTypes]; + NSMutableArray *muTypes; + int i, len; + + if (op == NSSaveToOperation) + { + return types; + } + + len = [types count]; + muTypes = [NSMutableArray arrayWithCapacity: len]; + for (i = 0; i < len; i++) + { + NSString *type; + + type = [types objectAtIndex: i]; + if ([[self class] isNativeType: type]) + { + [muTypes addObject: type]; + } + } + + return muTypes; +} + +- (BOOL)fileNameExtensionWasHiddenInLastRunSavePanel +{ + // FIXME + return NO; +} + - (BOOL)shouldChangePrintInfo: (NSPrintInfo *)newPrintInfo { return YES; @@ -602,20 +1126,34 @@ - (NSPrintInfo *)printInfo { - return _printInfo? _printInfo : [NSPrintInfo sharedPrintInfo]; + return _print_info? _print_info : [NSPrintInfo sharedPrintInfo]; } - (void)setPrintInfo: (NSPrintInfo *)printInfo { - ASSIGN(_printInfo, printInfo); + ASSIGN(_print_info, printInfo); } // Page layout panel (Page Setup) +- (BOOL)preparePageLayout:(NSPageLayout *)pageLayout +{ + return YES; +} - (int)runModalPageLayoutWithPrintInfo: (NSPrintInfo *)printInfo { - return [[NSPageLayout pageLayout] runModalWithPrintInfo: printInfo]; + NSPageLayout *pageLayout; + + pageLayout = [NSPageLayout pageLayout]; + if ([self preparePageLayout: pageLayout]) + { + return [pageLayout runModalWithPrintInfo: printInfo]; + } + else + { + return NSCancelButton; + } } - (IBAction)runPageLayout: (id)sender @@ -630,6 +1168,28 @@ } } +- (void)runModalPageLayoutWithPrintInfo: (NSPrintInfo *)printInfo + delegate: (id)delegate + didRunSelector: (SEL)sel + contextInfo: (void *)context +{ + NSPageLayout *pageLayout; + + pageLayout = [NSPageLayout pageLayout]; + if ([self preparePageLayout: pageLayout]) + { + NSWindow *win; + + win = [self windowForSheet]; + + [pageLayout beginSheetWithPrintInfo: printInfo + modalForWindow: win + delegate: delegate + didEndSelector: sel + contextInfo: context]; + } +} + /* This is overridden by subclassers; the default implementation does nothing. */ - (void)printShowingPrintPanel: (BOOL)flag { @@ -640,6 +1200,62 @@ [self printShowingPrintPanel: YES]; } +- (void)printDocumentWithSettings: (NSDictionary *)settings + showPrintPanel: (BOOL)flag + delegate: (id)delegate + didPrintSelector: (SEL)sel + contextInfo: (void *)context +{ + NSPrintOperation *printOp; + NSError *error; + + if (OVERRIDDEN(printShowingPrintPanel:)) + { + // FIXME: More communication with the panel is needed. + return [self printShowingPrintPanel: flag]; + } + + printOp = [self printOperationWithSettings: settings + error: &error]; + if (printOp != nil) + { + [printOp setShowsPrintPanel: flag]; + [self runModalPrintOperation: printOp + delegate: delegate + didRunSelector: sel + contextInfo: context]; + } + else + { + [self presentError: error]; + + if (delegate != nil && sel != NULL) + { + void (*meth)(id, SEL, id, BOOL, void*); + meth = (void (*)(id, SEL, id, BOOL, void*))[delegate methodForSelector: sel]; + if (meth) + meth(delegate, sel, self, NO, context); + } + } +} + +- (NSPrintOperation *)printOperationWithSettings: (NSDictionary *)settings + error: (NSError **)error +{ + return nil; +} + +- (void)runModalPrintOperation: (NSPrintOperation *)op + delegate: (id)delegate + didRunSelector: (SEL)sel + contextInfo: (void *)context +{ + [op runOperationModalForWindow: [self windowForSheet] + delegate: delegate + didRunSelector: sel + contextInfo: context]; +} + - (BOOL)validateMenuItem: (NSMenuItem *)anItem { BOOL result = YES; @@ -652,40 +1268,40 @@ } else if (sel_eq(action, @selector(undo:))) { - if (_undoManager == nil) + if (_undo_manager == nil) { result = NO; } else { - if ([_undoManager canUndo]) + if ([_undo_manager canUndo]) { - [anItem setTitle: [_undoManager undoMenuItemTitle]]; + [anItem setTitle: [_undo_manager undoMenuItemTitle]]; result = YES; } else { - [anItem setTitle: [_undoManager undoMenuTitleForUndoActionName: @""]]; + [anItem setTitle: [_undo_manager undoMenuTitleForUndoActionName: @""]]; result = NO; } } } else if (sel_eq(action, @selector(redo:))) { - if (_undoManager == nil) + if (_undo_manager == nil) { result = NO; } else { - if ([_undoManager canRedo]) + if ([_undo_manager canRedo]) { - [anItem setTitle: [_undoManager redoMenuItemTitle]]; + [anItem setTitle: [_undo_manager redoMenuItemTitle]]; result = YES; } else { - [anItem setTitle: [_undoManager redoMenuTitleForUndoActionName: @""]]; + [anItem setTitle: [_undo_manager redoMenuTitleForUndoActionName: @""]]; result = NO; } } @@ -704,92 +1320,25 @@ - (NSString *)fileTypeFromLastRunSavePanel { - return _saveType; + return _save_type; } - (NSDictionary *)fileAttributesToWriteToFile: (NSString *)fullDocumentPath ofType: (NSString *)docType saveOperation: (NSSaveOperationType)saveOperationType { - // FIXME: Implement. + // FIXME: Implement. Should set NSFileExtensionHidden return [NSDictionary dictionary]; } -- (BOOL)writeToFile: (NSString *)fileName - ofType: (NSString *)type - originalFile: (NSString *)origFileName - saveOperation: (NSSaveOperationType)saveOp +- (NSDictionary *)fileAttributesToWriteToURL:(NSURL *)url + ofType:(NSString *)type + forSaveOperation:(NSSaveOperationType)op + originalContentsURL:(NSURL *)original + error:(NSError **)error { - return [self writeToFile: fileName ofType: type]; -} - -- (BOOL)writeWithBackupToFile: (NSString *)fileName - ofType: (NSString *)fileType - saveOperation: (NSSaveOperationType)saveOp -{ - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *backupFilename = nil; - BOOL isNativeType = [[self class] isNativeType: fileType]; - - if (fileName && isNativeType) - { - NSArray *extensions = [[NSDocumentController sharedDocumentController] - fileExtensionsFromType: fileType]; - - if ([extensions count] > 0) - { - NSString *extension = [extensions objectAtIndex: 0]; - NSString *newFileName = [[fileName stringByDeletingPathExtension] - stringByAppendingPathExtension: extension]; - - if ([fileManager fileExistsAtPath: newFileName]) - { - backupFilename = [newFileName stringByDeletingPathExtension]; - backupFilename = [backupFilename stringByAppendingString:@"~"]; - backupFilename = [backupFilename stringByAppendingPathExtension: extension]; - - /* Save panel has already asked if the user wants to replace it */ - - /* NSFileManager movePath: will fail if destination exists */ - if ([fileManager fileExistsAtPath: backupFilename]) - [fileManager removeFileAtPath: backupFilename handler: nil]; - - // Move or copy? - if (![fileManager movePath: newFileName toPath: backupFilename handler: nil] && - [self keepBackupFile]) - { - int result = NSRunAlertPanel(_(@"File Error"), - _(@"Can't create backup file. Save anyways?"), - _(@"Save"), _(@"Cancel"), nil); - - if (result != NSAlertDefaultReturn) return NO; - } - } - if ([self writeToFile: fileName - ofType: fileType - originalFile: backupFilename - saveOperation: saveOp]) - { - if (saveOp != NSSaveToOperation) - { - [self setFileName: newFileName]; - [self setFileType: fileType]; - [self updateChangeCount: NSChangeCleared]; - } - - // FIXME: Should set the file attributes - - if (backupFilename && ![self keepBackupFile]) - { - [fileManager removeFileAtPath: backupFilename handler: nil]; - } - - return YES; - } - } - } - - return NO; + // FIXME: Implement. Should set NSFileExtensionHidden + return [NSDictionary dictionary]; } - (IBAction)saveDocument: (id)sender @@ -809,34 +1358,43 @@ - (IBAction)saveDocumentAs: (id)sender { - NSString *filename = - [self fileNameFromRunningSavePanelForSaveOperation: - NSSaveAsOperation]; - - [self writeWithBackupToFile: filename - ofType: [self fileTypeFromLastRunSavePanel] - saveOperation: NSSaveAsOperation]; + [self runModalSavePanelForSaveOperation: NSSaveAsOperation + delegate: nil + didSaveSelector: NULL + contextInfo: NULL]; } - (IBAction)saveDocumentTo: (id)sender { - NSString *filename = - [self fileNameFromRunningSavePanelForSaveOperation: - NSSaveToOperation]; - - [self writeWithBackupToFile: filename - ofType: [self fileTypeFromLastRunSavePanel] - saveOperation: NSSaveToOperation]; + [self runModalSavePanelForSaveOperation: NSSaveToOperation + delegate: nil + didSaveSelector: NULL + contextInfo: NULL]; } - (void)saveDocumentWithDelegate: (id)delegate didSaveSelector: (SEL)didSaveSelector contextInfo: (void *)contextInfo { - [self runModalSavePanelForSaveOperation: NSSaveOperation - delegate: delegate - didSaveSelector: didSaveSelector - contextInfo: contextInfo]; + NSURL *fileURL = [self fileURL]; + NSString *type = [self fileType]; + + if ((fileURL != nil) && (type != nil)) + { + [self saveToURL: fileURL + ofType: type + forSaveOperation: NSSaveOperation + delegate: delegate + didSaveSelector: didSaveSelector + contextInfo: contextInfo]; + } + else + { + [self runModalSavePanelForSaveOperation: NSSaveOperation + delegate: delegate + didSaveSelector: didSaveSelector + contextInfo: contextInfo]; + } } - (void)saveToFile: (NSString *)fileName @@ -864,30 +1422,52 @@ } } -- (BOOL)prepareSavePanel: (NSSavePanel *)savePanel +- (BOOL)saveToURL: (NSURL *)url + ofType: (NSString *)type + forSaveOperation: (NSSaveOperationType)op + error: (NSError **)error { - return YES; + return [self writeSafelyToURL: url + ofType: type + forSaveOperation: op + error: error]; } -- (void)runModalSavePanelForSaveOperation: (NSSaveOperationType)saveOperation - delegate: (id)delegate - didSaveSelector: (SEL)didSaveSelector - contextInfo: (void *)contextInfo +- (BOOL)saveToURL: (NSURL *)url + ofType: (NSString *)type + forSaveOperation: (NSSaveOperationType)op + delegate: (id)delegate + didSaveSelector: (SEL)didSaveSelector + contextInfo:(void *)contextInfo { - NSString *fileName; + NSError *error; + BOOL saved; - // FIXME: Setting of the delegate of the save panel is missing - fileName = [self fileNameFromRunningSavePanelForSaveOperation: saveOperation]; - [self saveToFile: fileName - saveOperation: saveOperation - delegate: delegate - didSaveSelector: didSaveSelector - contextInfo: contextInfo]; + saved = [self saveToURL: url + ofType: type + forSaveOperation: op + error: &error]; + if (!saved) + { + [self presentError: error]; + } + + if (delegate != nil && didSaveSelector != NULL) + { + void (*meth)(id, SEL, id, BOOL, void*); + meth = (void (*)(id, SEL, id, BOOL, void*))[delegate methodForSelector: + didSaveSelector]; + if (meth) + meth(delegate, didSaveSelector, self, saved, contextInfo); + } + + return saved; } - (IBAction)revertDocumentToSaved: (id)sender { int result; + NSError *error; result = NSRunAlertPanel (_(@"Revert"), @@ -895,11 +1475,19 @@ _(@"Revert"), _(@"Cancel"), nil, [self displayName]); - if (result == NSAlertDefaultReturn && - [self revertToSavedFromFile:[self fileName] ofType:[self fileType]]) - { - [self updateChangeCount: NSChangeCleared]; - } + if (result == NSAlertDefaultReturn) + { + if ([self revertToContentsOfURL: [self fileURL] + ofType: [self fileType] + error: &error]) + { + [self updateChangeCount: NSChangeCleared]; + } + else + { + [self presentError: error]; + } + } } /** Closes all the windows owned by the document, then removes itself @@ -909,17 +1497,17 @@ */ - (void)close { - if (_docFlags.inClose == NO) + if (_doc_flags.in_close == NO) { - int count = [_windowControllers count]; + int count = [_window_controllers count]; /* Closing a windowController will also send us a close, so make sure we don't go recursive */ - _docFlags.inClose = YES; + _doc_flags.in_close = YES; if (count > 0) { NSWindowController *array[count]; - [_windowControllers getObjects: array]; + [_window_controllers getObjects: array]; while (count-- > 0) [array[count] close]; } @@ -932,36 +1520,36 @@ - (NSUndoManager *)undoManager { - if (_undoManager == nil && [self hasUndoManager]) + if (_undo_manager == nil && [self hasUndoManager]) { [self setUndoManager: AUTORELEASE([[NSUndoManager alloc] init])]; } - return _undoManager; + return _undo_manager; } - (void)setUndoManager: (NSUndoManager *)undoManager { - if (undoManager != _undoManager) + if (undoManager != _undo_manager) { NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; - if (_undoManager) + if (_undo_manager) { [center removeObserver: self name: NSUndoManagerWillCloseUndoGroupNotification - object:_undoManager]; + object:_undo_manager]; [center removeObserver: self name: NSUndoManagerDidUndoChangeNotification - object:_undoManager]; + object:_undo_manager]; [center removeObserver: self name: NSUndoManagerDidRedoChangeNotification - object:_undoManager]; + object:_undo_manager]; } - ASSIGN(_undoManager, undoManager); + ASSIGN(_undo_manager, undoManager); - if (_undoManager == nil) + if (_undo_manager == nil) { [self setHasUndoManager: NO]; } @@ -970,32 +1558,90 @@ [center addObserver: self selector:@selector(_changeWasDone:) name: NSUndoManagerWillCloseUndoGroupNotification - object:_undoManager]; + object:_undo_manager]; [center addObserver: self selector:@selector(_changeWasUndone:) name: NSUndoManagerDidUndoChangeNotification - object:_undoManager]; + object:_undo_manager]; [[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(_changeWasRedone:) name: NSUndoManagerDidRedoChangeNotification - object:_undoManager]; + object:_undo_manager]; } } } - (BOOL)hasUndoManager { - return _docFlags.hasUndoManager; + return _doc_flags.has_undo_manager; } - (void)setHasUndoManager: (BOOL)flag { - if (_undoManager && !flag) + if (_undo_manager && !flag) [self setUndoManager: nil]; - _docFlags.hasUndoManager = flag; + _doc_flags.has_undo_manager = flag; } + +- (BOOL)presentError: (NSError *)error +{ + error = [self willPresentError: error]; + return [[NSDocumentController sharedDocumentController] presentError: error]; +} + +- (void)presentError: (NSError *)error + modalForWindow: (NSWindow *)window + delegate: (id)delegate + didPresentSelector: (SEL)sel + contextInfo: (void *)context +{ + error = [self willPresentError: error]; + [[NSDocumentController sharedDocumentController] presentError: error + modalForWindow: window + delegate: delegate + didPresentSelector: sel + contextInfo: context]; +} + +- (NSError *)willPresentError:(NSError *)error +{ + return error; +} + +- (NSURL *)autosavedContentsFileURL +{ + return _autosaved_file_url; +} + +- (void)setAutosavedContentsFileURL: (NSURL *)url +{ + ASSIGN(_autosaved_file_url, url); +} + +- (void)autosaveDocumentWithDelegate: (id)delegate + didAutosaveSelector: (SEL)didAutosaveSelector + contextInfo: (void *)context +{ + [self saveToURL: [self autosavedContentsFileURL] + ofType: [self autosavingFileType] + forSaveOperation: NSAutosaveOperation + delegate: delegate + didSaveSelector: didAutosaveSelector + contextInfo: context]; +} + +- (NSString *)autosavingFileType +{ + return [self fileType]; +} + +- (BOOL)hasUnautosavedChanges +{ + return _autosave_change_count != 0; +} + @end @implementation NSDocument(Private) @@ -1015,14 +1661,14 @@ - (void) _removeWindowController: (NSWindowController *)windowController { - if ([_windowControllers containsObject: windowController]) + if ([_window_controllers containsObject: windowController]) { BOOL autoClose = [windowController shouldCloseDocument]; [windowController setDocument: nil]; - [_windowControllers removeObject: windowController]; + [_window_controllers removeObject: windowController]; - if (autoClose || [_windowControllers count] == 0) + if (autoClose || [_window_controllers count] == 0) { [self close]; } diff --git a/Source/NSDocumentController.m b/Source/NSDocumentController.m index 6dd4871c9..dc7ff220a 100644 --- a/Source/NSDocumentController.m +++ b/Source/NSDocumentController.m @@ -27,16 +27,22 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include +#include +#include +#include +#include +#include +#include + #include "AppKit/NSDocumentController.h" #include "AppKit/NSOpenPanel.h" #include "AppKit/NSApplication.h" #include "AppKit/NSMenuItem.h" #include "AppKit/NSWorkspace.h" -#include "AppKit/NSDocumentFrameworkPrivate.h" +#include "NSDocumentFrameworkPrivate.h" #include "GSGuiPrivate.h" -#include - static NSString *NSTypesKey = @"NSTypes"; static NSString *NSNameKey = @"NSName"; static NSString *NSRoleKey = @"NSRole"; @@ -165,22 +171,22 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ _documents = [[NSMutableArray alloc] init]; /* Get list of recent documents */ - _recentDocuments = [[NSUserDefaults standardUserDefaults] + _recent_documents = [[NSUserDefaults standardUserDefaults] objectForKey: NSRecentDocuments]; - if (_recentDocuments) + if (_recent_documents) { int i, count; - _recentDocuments = [_recentDocuments mutableCopy]; - count = [_recentDocuments count]; + _recent_documents = [_recent_documents mutableCopy]; + count = [_recent_documents count]; for (i = 0; i < count; i++) { NSURL *url; - url = [NSURL URLWithString: [_recentDocuments objectAtIndex: i]]; - [_recentDocuments replaceObjectAtIndex: i withObject: url]; + url = [NSURL URLWithString: [_recent_documents objectAtIndex: i]]; + [_recent_documents replaceObjectAtIndex: i withObject: url]; } } else - _recentDocuments = RETAIN([NSMutableArray array]); + _recent_documents = RETAIN([NSMutableArray array]); [self setShouldCreateUI:YES]; [[[NSWorkspace sharedWorkspace] notificationCenter] @@ -198,19 +204,47 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ { [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver: self]; RELEASE (_documents); - RELEASE (_recentDocuments); + RELEASE (_recent_documents); RELEASE (_types); [super dealloc]; } +/* + * Private helper method to check, if the method given via the selector sel + * has been overridden in the current subclass. + */ +- (BOOL)_hasOverridden: (SEL)sel +{ + // The actual signature is not important as we wont call the methods. + IMP meth1; + IMP meth2; + + meth1 = [self methodForSelector: sel]; + meth2 = [[NSDocument class] instanceMethodForSelector: sel]; + + return (meth1 != meth2); +} + +#define OVERRIDDEN(sel) [self _hasOverridden: @selector(sel)] + - (BOOL) shouldCreateUI { - return _controllerFlags.shouldCreateUI; + return _controller_flags.should_create_ui; } - (void) setShouldCreateUI: (BOOL)flag { - _controllerFlags.shouldCreateUI = flag; + _controller_flags.should_create_ui = flag; +} + +- (NSTimeInterval) autosavingDelay +{ + return _autosavingDelay; +} + +- (void) setAutosavingDelay: (NSTimeInterval)autosavingDelay +{ + _autosavingDelay = autosavingDelay; } - (id) makeUntitledDocumentOfType: (NSString *)type @@ -238,14 +272,69 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ ofType: type]); } -- _defaultType +- (id)makeDocumentForURL:(NSURL *)url + withContentsOfURL:(NSURL *)contents + ofType:(NSString *)type + error:(NSError **)err +{ + Class documentClass = [self documentClassForType: type]; + return AUTORELEASE([[documentClass alloc] initForURL: url + withContentsOfURL: contents + ofType: type + error: err]); +} + +- (id)makeDocumentWithContentsOfURL:(NSURL *)url + ofType:(NSString *)type + error:(NSError **)err +{ + Class documentClass = [self documentClassForType: type]; + return AUTORELEASE([[documentClass alloc] initWithContentsOfURL: url + ofType: type + error: err]); +} + +- (id)makeUntitledDocumentOfType:(NSString *)type + error:(NSError **)err +{ + Class documentClass = [self documentClassForType: type]; + return AUTORELEASE([[documentClass alloc] initWithType: type + error: err]); +} + +- (BOOL)presentError:(NSError *)error +{ + error = [self willPresentError: error]; + return [NSApp presentError: error]; +} + +- (void)presentError:(NSError *)error + modalForWindow:(NSWindow *)window + delegate:(id)delegate + didPresentSelector:(SEL)sel + contextInfo:(void *)context +{ + error = [self willPresentError: error]; + [NSApp presentError: error + modalForWindow: window + delegate: delegate + didPresentSelector: sel + contextInfo: context]; +} + +- (NSError *) willPresentError: (NSError *)error +{ + return error; +} + +- (NSString*) defaultType { if ([_types count] == 0) { return nil; // raise exception? } - return [(NSDictionary*)[_types objectAtIndex:0] objectForKey:NSNameKey]; + return [(NSDictionary*)[_types objectAtIndex: 0] objectForKey: NSNameKey]; } - (void) addDocument: (NSDocument *)document @@ -268,13 +357,10 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ } [self addDocument: document]; - if ([self shouldCreateUI]) + if (display && [self shouldCreateUI]) { [document makeWindowControllers]; - if (display) - { - [document showWindows]; - } + [document showWindows]; } return document; @@ -294,13 +380,16 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ { NSString *type = [self typeFromFileExtension: [fileName pathExtension]]; - if ((document = [self makeDocumentWithContentsOfFile: fileName - ofType: type])) + document = [self makeDocumentWithContentsOfFile: fileName ofType: type]; + + if (document == nil) { - [self addDocument: document]; + return nil; } - if ([self shouldCreateUI]) + [self addDocument: document]; + + if (display && [self shouldCreateUI]) { [document makeWindowControllers]; } @@ -324,11 +413,11 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ */ - (id) openDocumentWithContentsOfURL: (NSURL *)url display: (BOOL)display { - // Should we only do this if [url isFileURL] is YES? - NSDocument *document = [self documentForFileName: [url path]]; + NSDocument *document = [self documentForURL: url]; if (document == nil) { + // Should we only do this if [url isFileURL] is YES? NSString *type = [self typeFromFileExtension: [[url path] pathExtension]]; @@ -341,7 +430,7 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ [self addDocument: document]; - if ([self shouldCreateUI]) + if (display && [self shouldCreateUI]) { [document makeWindowControllers]; } @@ -358,6 +447,94 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ return document; } +- (id)openUntitledDocumentAndDisplay:(BOOL)display + error:(NSError **)err +{ + NSString *type; + + type = [self defaultType]; + + if (OVERRIDDEN(openUntitledDocumentOfType:display:)) + { + return [self openUntitledDocumentOfType: type display: display]; + } + else + { + NSDocument *document = [self makeUntitledDocumentOfType: type + error: err]; + + if (document == nil) + { + return nil; + } + + [self addDocument: document]; + if (display && [self shouldCreateUI]) + { + [document makeWindowControllers]; + [document showWindows]; + } + + return document; + } +} + +- (id) openDocumentWithContentsOfURL: (NSURL *)url + display: (BOOL)display + error: (NSError **)err +{ + if (OVERRIDDEN(openDocumentWithContentsOfFile:display:)) + { + NSString *fileName; + + fileName = [url path]; + return [self openDocumentWithContentsOfFile: fileName display: display]; + } + else + { + NSDocument *document = [self documentForURL: url]; + + if (document == nil) + { + // Should we only do this if [url isFileURL] is YES? + NSString *type = [self typeFromFileExtension: + [[url path] pathExtension]]; + + document = [self makeDocumentWithContentsOfURL: url ofType: type error: err]; + + if (document == nil) + { + return nil; + } + + [self addDocument: document]; + + if (display && [self shouldCreateUI]) + { + [document makeWindowControllers]; + } + } + + // remember this document as opened + [self noteNewRecentDocumentURL: url]; + + if (display && [self shouldCreateUI]) + { + [document showWindows]; + } + + return document; + } +} + +- (BOOL) reopenDocumentForURL: (NSURL *)url + withContentsOfURL: (NSURL *)contents + error: (NSError **)err +{ + // FIXME + return NO; +} + - (NSOpenPanel *) _setupOpenPanel { NSOpenPanel *openPanel = [NSOpenPanel openPanel]; @@ -455,7 +632,7 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ - (IBAction) newDocument: (id)sender { - [self openUntitledDocumentOfType: [self _defaultType] display: YES]; + [self openUntitledDocumentOfType: [self defaultType] display: YES]; } @@ -564,7 +741,7 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ - (BOOL) applicationOpenUntitledFile: (NSApplication *)sender { - return [self openUntitledDocumentOfType: [self _defaultType] + return [self openUntitledDocumentOfType: [self defaultType] display: YES] ? YES : NO; } @@ -691,6 +868,33 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ return nil; } +- (id)documentForURL: (NSURL *)url +{ + if (OVERRIDDEN(documentForFileName:)) + { + NSString *fileName; + + fileName = [url path]; + return [self documentForFileName: fileName]; + } + else + { + int i, count = [_documents count]; + + for (i = 0; i < count; i++) + { + NSDocument *document = [_documents objectAtIndex: i]; + + if ([[document fileURL] isEqual: url]) + { + return document; + } + } + + return nil; + } +} + - (BOOL) validateMenuItem: (NSMenuItem *)anItem { if ([anItem action] == @selector(saveAllDocuments:)) @@ -733,6 +937,15 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ return nil; } +- (NSString *) typeForContentsOfURL: (NSURL *)url error: (NSError **)err +{ + // FIXME + NSString *extension; + + extension = [[url path] pathExtension]; + return [self typeFromFileExtension: extension]; +} + - (NSArray *) fileExtensionsFromType: (NSString *)type { NSDictionary *typeInfo = TYPE_INFO(type); @@ -751,11 +964,29 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ return className? NSClassFromString(className) : Nil; } +- (NSArray *)documentClassNames +{ + int i, count = [_types count]; + NSMutableArray *classNames; + + classNames = [[NSMutableArray alloc] initWithCapacity: count]; + + for (i = 0; i < count; i++) + { + NSDictionary *typeInfo = [_types objectAtIndex: i]; + + [classNames addObject: [typeInfo objectForKey: NSDocumentClassKey]]; + } + + return AUTORELEASE(classNames); +} + + - (IBAction) clearRecentDocuments: (id)sender { - [_recentDocuments removeAllObjects]; + [_recent_documents removeAllObjects]; [[NSUserDefaults standardUserDefaults] - setObject: _recentDocuments forKey: NSRecentDocuments]; + setObject: _recent_documents forKey: NSRecentDocuments]; } // The number of remembered recent documents @@ -772,22 +1003,22 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ - (void) noteNewRecentDocumentURL: (NSURL *)anURL { - unsigned index = [_recentDocuments indexOfObject: anURL]; + unsigned index = [_recent_documents indexOfObject: anURL]; NSMutableArray *a; if (index != NSNotFound) { // Always keep the current object at the end of the list - [_recentDocuments removeObjectAtIndex: index]; + [_recent_documents removeObjectAtIndex: index]; } - else if ([_recentDocuments count] > MAX_DOCS) + else if ([_recent_documents count] > MAX_DOCS) { - [_recentDocuments removeObjectAtIndex: 0]; + [_recent_documents removeObjectAtIndex: 0]; } - [_recentDocuments addObject: anURL]; + [_recent_documents addObject: anURL]; - a = [_recentDocuments mutableCopy]; + a = [_recent_documents mutableCopy]; index = [a count]; while (index-- > 0) { @@ -801,7 +1032,7 @@ static NSDictionary *TypeInfoForHumanReadableName (NSArray *types, NSString *typ - (NSArray *) recentDocumentURLs { - return _recentDocuments; + return _recent_documents; } @end diff --git a/Headers/AppKit/NSDocumentFrameworkPrivate.h b/Source/NSDocumentFrameworkPrivate.h similarity index 93% rename from Headers/AppKit/NSDocumentFrameworkPrivate.h rename to Source/NSDocumentFrameworkPrivate.h index 647cb5312..6cb7e7f2f 100644 --- a/Headers/AppKit/NSDocumentFrameworkPrivate.h +++ b/Source/NSDocumentFrameworkPrivate.h @@ -28,9 +28,8 @@ */ #ifndef _GNUstep_H_NSDocumentFramworkPrivate #define _GNUstep_H_NSDocumentFramworkPrivate -#import -#include "NSDocumentController.h" +#include @interface NSDocumentController (Private) - (NSArray *)_editorAndViewerTypesForClass:(Class)documentClass; @@ -42,7 +41,7 @@ @end -#include "NSDocument.h" +#include @interface NSDocument (Private) - (void)_removeWindowController:(NSWindowController *)controller; @@ -50,7 +49,7 @@ @end -#include "NSWindowController.h" +#include @interface NSWindowController (Private) - (void)_windowDidLoad; diff --git a/Source/NSPrintOperation.m b/Source/NSPrintOperation.m index 4e3f9e185..20704598b 100644 --- a/Source/NSPrintOperation.m +++ b/Source/NSPrintOperation.m @@ -290,13 +290,14 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; - (void) dealloc { - RELEASE(_printInfo); + RELEASE(_print_info); RELEASE(_view); RELEASE(_data); TEST_RELEASE(_context); - TEST_RELEASE(_printPanel); - TEST_RELEASE(_accessoryView); + TEST_RELEASE(_print_panel); + TEST_RELEASE(_accessory_view); TEST_RELEASE(_path); + TEST_RELEASE(_job_style_hint); [super dealloc]; } @@ -324,17 +325,17 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; */ - (NSPrintPanel *)printPanel { - if (_printPanel == nil) - ASSIGN(_printPanel, [NSPrintPanel printPanel]); + if (_print_panel == nil) + ASSIGN(_print_panel, [NSPrintPanel printPanel]); - return _printPanel; + return _print_panel; } /** Returns YES if the reciever display an NSPrintPanel and other information when running a print operation. */ - (BOOL)showPanels { - return _showPanels; + return [self showsPrintPanel] && [self showsProgressPanel]; } /** Sets the NSPrintPanel used by the receiver obtaining and displaying @@ -342,7 +343,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; */ - (void)setPrintPanel:(NSPrintPanel *)panel { - ASSIGN(_printPanel, panel); + ASSIGN(_print_panel, panel); } /** Use this to set whether a print panel is displayed during a printing @@ -352,15 +353,37 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; */ - (void)setShowPanels:(BOOL)flag { - _showPanels = flag; + [self setShowsPrintPanel: flag]; + [self setShowsProgressPanel: flag]; } +- (BOOL)showsPrintPanel +{ + return _flags.show_print_panel; +} + +- (void)setShowsPrintPanel:(BOOL)flag +{ + _flags.show_print_panel = flag; +} + +- (BOOL)showsProgressPanel +{ + return _flags.show_progress_panel; +} + +- (void)setShowsProgressPanel:(BOOL)flag +{ + _flags.show_progress_panel = flag; +} + + /** Returns the accessory view used by the NSPrintPanel associated with the receiver. */ - (NSView *)accessoryView { - return _accessoryView; + return _accessory_view; } /** Set the accessory view used by the NSPrintPanel associated with the @@ -368,7 +391,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; */ - (void)setAccessoryView:(NSView *)aView { - ASSIGN(_accessoryView, aView); + ASSIGN(_accessory_view, aView); } // @@ -413,14 +436,14 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; */ - (NSPrintingPageOrder)pageOrder { - return _pageOrder; + return _page_order; } /** Set the page order used when printing. */ - (void)setPageOrder:(NSPrintingPageOrder)order { - _pageOrder = order; + _page_order = order; } // @@ -455,12 +478,12 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; { BOOL result; - if (_showPanels) + if ([self showsPrintPanel]) { NSPrintPanel *panel = [self printPanel]; int button; - [panel setAccessoryView: _accessoryView]; + [panel setAccessoryView: _accessory_view]; [self _setupPrintInfo]; [panel updateFromPrintInfo]; button = [panel runModal]; @@ -495,7 +518,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; NSPrintPanel *panel = [self printPanel]; /* Save the selector so we can use it later */ - dict = [_printInfo dictionary]; + dict = [_print_info dictionary]; [dict setObject: [NSValue value: &didRunSelector withObjCType: @encode(SEL)] forKey: @"GSModalRunSelector"]; [dict setObject: delegate @@ -504,10 +527,10 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; /* Assume we want to show the panel regardless of the value of _showPanels */ - [panel setAccessoryView: _accessoryView]; + [panel setAccessoryView: _accessory_view]; [self _setupPrintInfo]; [panel updateFromPrintInfo]; - [panel beginSheetWithPrintInfo: _printInfo + [panel beginSheetWithPrintInfo: _print_info modalForWindow: docWindow delegate: delegate didEndSelector: @@ -516,6 +539,26 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; [panel setAccessoryView: nil]; } +- (BOOL)canSpawnSeparateThread +{ + return _flags.can_spawn_separate_thread; +} + +- (void)setCanSpawnSeparateThread:(BOOL)flag +{ + _flags.can_spawn_separate_thread = flag; +} + +- (NSString *) jobStyleHint +{ + return _job_style_hint; +} + +- (void)setJobStyleHint:(NSString *)hint +{ + ASSIGN(_job_style_hint, hint); +} + // // Getting the NSPrintInfo Object // @@ -523,7 +566,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; */ - (NSPrintInfo *)printInfo { - return _printInfo; + return _print_info; } /** Set the NSPrintInfo object associated with the receiver. @@ -533,7 +576,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; if (aPrintInfo == nil) aPrintInfo = [NSPrintInfo sharedPrintInfo]; - ASSIGNCOPY(_printInfo, aPrintInfo); + ASSIGNCOPY(_print_info, aPrintInfo); } // @@ -565,8 +608,9 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; ASSIGN(_view, aView); _rect = rect; ASSIGN(_data, data); - _pageOrder = NSUnknownPageOrder; - _showPanels = NO; + _page_order = NSUnknownPageOrder; + [self setShowsPrintPanel: NO]; + [self setShowsProgressPanel: NO]; [self setPrintInfo: aPrintInfo]; _path = nil; _currentPage = 0; @@ -593,13 +637,13 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; return NO; result = NO; - if (_pageOrder == NSUnknownPageOrder) + if (_page_order == NSUnknownPageOrder) { - if ([[[_printInfo dictionary] objectForKey: NSPrintReversePageOrder] + if ([[[_print_info dictionary] objectForKey: NSPrintReversePageOrder] boolValue] == YES) - _pageOrder = NSDescendingPageOrder; + _page_order = NSDescendingPageOrder; else - _pageOrder = NSAscendingPageOrder; + _page_order = NSAscendingPageOrder; } [NSGraphicsContext setCurrentContext: _context]; @@ -626,7 +670,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; { BOOL knowsPageRange; NSRange viewPageRange; - NSMutableDictionary *dict = [_printInfo dictionary]; + NSMutableDictionary *dict = [_print_info dictionary]; knowsPageRange = [_view knowsPageRange: &viewPageRange]; if (knowsPageRange == YES) @@ -656,7 +700,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; success = [self deliverResult]; } [self cleanUpOperation]; - dict = [_printInfo dictionary]; + dict = [_print_info dictionary]; didRunSelector = [[dict objectForKey: @"GSModalRunSelector"] pointerValue]; delegate = [dict objectForKey: @"GSModalRunDelegate"]; didRun = (void (*)(id, SEL, BOOL, id))[delegate methodForSelector: @@ -693,10 +737,10 @@ scaleRect(NSRect rect, double scale) - (void) _printPaginateWithInfo: (page_info_t *)info knowsRange: (BOOL)knowsRange { NSMutableDictionary *dict; - dict = [_printInfo dictionary]; + dict = [_print_info dictionary]; - info->paperSize = [_printInfo paperSize]; - info->orient = [_printInfo orientation]; + info->paperSize = [_print_info paperSize]; + info->orient = [_print_info orientation]; info->printScale = [[dict objectForKey: NSPrintScalingFactor] doubleValue]; info->nup = [[dict objectForKey: NSPrintPagesPerSheet] intValue]; info->nupScale = 1; @@ -709,12 +753,12 @@ scaleRect(NSRect rect, double scale) /* Subtract the margins from the paper size to get print boundary */ info->paperBounds.size = info->paperSize; - info->paperBounds.origin.x = [_printInfo leftMargin]; - info->paperBounds.origin.y = [_printInfo bottomMargin]; + info->paperBounds.origin.x = [_print_info leftMargin]; + info->paperBounds.origin.y = [_print_info bottomMargin]; info->paperBounds.size.width -= - ([_printInfo rightMargin]+[_printInfo leftMargin]); + ([_print_info rightMargin]+[_print_info leftMargin]); info->paperBounds.size.height -= - ([_printInfo topMargin]+[_printInfo bottomMargin]); + ([_print_info topMargin]+[_print_info bottomMargin]); info->sheetBounds = info->paperBounds; if (info->orient == NSLandscapeOrientation) @@ -739,10 +783,10 @@ scaleRect(NSRect rect, double scale) if (knowsRange == NO) { /* Now calculate page fitting to get page scale */ - if ([_printInfo horizontalPagination] == NSFitPagination) + if ([_print_info horizontalPagination] == NSFitPagination) info->pageScale = info->paperBounds.size.width / NSWidth(info->scaledBounds); - if ([_printInfo verticalPagination] == NSFitPagination) + if ([_print_info verticalPagination] == NSFitPagination) info->pageScale = MIN(info->pageScale, NSHeight(info->paperBounds)/NSHeight(info->scaledBounds)); /* Scale bounds by pageScale */ @@ -751,9 +795,9 @@ scaleRect(NSRect rect, double scale) /* Now find out how many pages */ info->xpages = ceil(NSWidth(info->scaledBounds)/NSWidth(info->paperBounds)); info->ypages = ceil(NSHeight(info->scaledBounds)/NSHeight(info->paperBounds)); - if ([_printInfo horizontalPagination] == NSClipPagination) + if ([_print_info horizontalPagination] == NSClipPagination) info->xpages = 1; - if ([_printInfo verticalPagination] == NSClipPagination) + if ([_print_info verticalPagination] == NSClipPagination) info->ypages = 1; } @@ -869,7 +913,7 @@ scaleRect(NSRect rect, double scale) NSMutableDictionary *dict; page_info_t info; - dict = [_printInfo dictionary]; + dict = [_print_info dictionary]; /* Setup pagination */ allPages = [[dict objectForKey: NSPrintAllPages] boolValue]; @@ -917,7 +961,7 @@ scaleRect(NSRect rect, double scale) _currentPage = info.first; dir = 1; - if (_pageOrder == NSDescendingPageOrder) + if (_page_order == NSDescendingPageOrder) { _currentPage = info.last; dir = -1; @@ -975,12 +1019,12 @@ scaleRect(NSRect rect, double scale) /* Check if adjust pages forced part of the bounds onto another page */ if (NSMaxX(pageRect) < NSMaxX(_rect) - && [_printInfo horizontalPagination] != NSClipPagination) + && [_print_info horizontalPagination] != NSClipPagination) { info.xpages++; } if (NSMaxY(pageRect) < NSMaxY(_rect) - && [_printInfo verticalPagination] != NSClipPagination) + && [_print_info verticalPagination] != NSClipPagination) { info.ypages++; } diff --git a/Source/NSResponder.m b/Source/NSResponder.m index ed09500cf..73bd390bd 100644 --- a/Source/NSResponder.m +++ b/Source/NSResponder.m @@ -437,4 +437,48 @@ return NO; } +- (BOOL)presentError:(NSError *)error +{ + error = [self willPresentError: error]; + + if (_next_responder) + { + return [_next_responder presentError: error]; + } + else + { + return [NSApp presentError: error]; + } +} + +- (void)presentError:(NSError *)error + modalForWindow:(NSWindow *)window + delegate:(id)delegate + didPresentSelector:(SEL)sel + contextInfo:(void *)context +{ + error = [self willPresentError: error]; + if (_next_responder) + { + [_next_responder presentError: error + modalForWindow: window + delegate: delegate + didPresentSelector: sel + contextInfo: context]; + } + else + { + [NSApp presentError: error + modalForWindow: window + delegate: delegate + didPresentSelector: sel + contextInfo: context]; + } +} + +- (NSError *) willPresentError: (NSError *)error +{ + return error; +} + @end diff --git a/Source/NSView.m b/Source/NSView.m index 77ef45c09..3ed1a9930 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -36,6 +36,7 @@ #include #include +#include #include #include #include diff --git a/Source/NSWindowController.m b/Source/NSWindowController.m index 35053d30f..f8cc73df8 100644 --- a/Source/NSWindowController.m +++ b/Source/NSWindowController.m @@ -24,10 +24,15 @@ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. */ -#include "AppKit/NSWindowController.h" -#include "AppKit/NSPanel.h" +#include +#include +#include +#include + #include "AppKit/NSNibLoading.h" -#include "AppKit/NSDocumentFrameworkPrivate.h" +#include "AppKit/NSPanel.h" +#include "AppKit/NSWindowController.h" +#include "NSDocumentFrameworkPrivate.h" @implementation NSWindowController @@ -51,7 +56,7 @@ } self = [self initWithWindow: nil]; - ASSIGN(_windowNibName, windowNibName); + ASSIGN(_window_nib_name, windowNibName); _owner = owner; return self; } @@ -72,7 +77,7 @@ } self = [self initWithWindow: nil]; - ASSIGN(_windowNibPath, windowNibPath); + ASSIGN(_window_nib_path, windowNibPath); _owner = owner; return self; } @@ -81,9 +86,9 @@ { self = [super init]; - _windowFrameAutosaveName = @""; - _wcFlags.shouldCascade = YES; - _wcFlags.shouldCloseDocument = NO; + _window_frame_autosave_name = @""; + _wcFlags.should_cascade = YES; + _wcFlags.should_close_document = NO; [self setWindow: window]; if (_window != nil) @@ -103,40 +108,40 @@ - (void) dealloc { [self setWindow: nil]; - RELEASE (_windowNibName); - RELEASE (_windowNibPath); - RELEASE (_windowFrameAutosaveName); - RELEASE (_topLevelObjects); + RELEASE(_window_nib_name); + RELEASE(_window_nib_path); + RELEASE(_window_frame_autosave_name); + RELEASE(_top_level_objects); [super dealloc]; } - (NSString *) windowNibName { - if ((_windowNibName == nil) && (_windowNibPath != nil)) + if ((_window_nib_name == nil) && (_window_nib_path != nil)) { - return [[_windowNibPath lastPathComponent] + return [[_window_nib_path lastPathComponent] stringByDeletingPathExtension]; } - return _windowNibName; + return _window_nib_name; } - (NSString *)windowNibPath { - if ((_windowNibName != nil) && (_windowNibPath == nil)) + if ((_window_nib_name != nil) && (_window_nib_path == nil)) { NSString *path; path = [[NSBundle bundleForClass: [_owner class]] - pathForNibResource: _windowNibName]; + pathForNibResource: _window_nib_name]; if (path == nil) path = [[NSBundle mainBundle] - pathForNibResource: _windowNibName]; + pathForNibResource: _window_nib_name]; return path; } - return _windowNibPath; + return _window_nib_path; } - (id) owner @@ -187,7 +192,7 @@ - (void) setWindowFrameAutosaveName:(NSString *)name { - ASSIGN(_windowFrameAutosaveName, name); + ASSIGN(_window_frame_autosave_name, name); if ([self isWindowLoaded]) { @@ -197,27 +202,27 @@ - (NSString *) windowFrameAutosaveName { - return _windowFrameAutosaveName; + return _window_frame_autosave_name; } - (void) setShouldCloseDocument: (BOOL)flag { - _wcFlags.shouldCloseDocument = flag; + _wcFlags.should_close_document = flag; } - (BOOL) shouldCloseDocument { - return _wcFlags.shouldCloseDocument; + return _wcFlags.should_close_document; } - (void) setShouldCascadeWindows: (BOOL)flag { - _wcFlags.shouldCascade = flag; + _wcFlags.should_cascade = flag; } - (BOOL) shouldCascadeWindows { - return _wcFlags.shouldCascade; + return _wcFlags.should_cascade; } - (void) close @@ -375,7 +380,7 @@ - (BOOL) isWindowLoaded { - return _wcFlags.nibIsLoaded; + return _wcFlags.nib_is_loaded; } - (void) windowDidLoad @@ -388,15 +393,15 @@ - (void) _windowDidLoad { - _wcFlags.nibIsLoaded = YES; + _wcFlags.nib_is_loaded = YES; [self synchronizeWindowTitleWithDocumentName]; /* Make sure window sizes itself right */ - if ([_windowFrameAutosaveName length] > 0) + if ([_window_frame_autosave_name length] > 0) { - [_window setFrameUsingName: _windowFrameAutosaveName]; - [_window setFrameAutosaveName: _windowFrameAutosaveName]; + [_window setFrameUsingName: _window_frame_autosave_name]; + [_window setFrameAutosaveName: _window_frame_autosave_name]; } if ([self shouldCascadeWindows]) @@ -431,7 +436,7 @@ externalNameTable: table withZone: [_owner zone]]) { - _wcFlags.nibIsLoaded = YES; + _wcFlags.nib_is_loaded = YES; if (_window == nil && _document != nil && _owner == _document) { @@ -440,10 +445,10 @@ } else { - if (_windowNibName != nil) + if (_window_nib_name != nil) { NSLog (@"%@: could not load nib named %@.nib", - [self class], _windowNibName); + [self class], _window_nib_name); } } }