From d5e4858a60dbe1cac680a554a1faadf7209ed6a1 Mon Sep 17 00:00:00 2001 From: gcasa Date: Sat, 20 May 2006 22:12:46 +0000 Subject: [PATCH] Nib compatibility code merge. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@22957 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 387 ++++ Documentation/ReleaseNotes.gsdoc | 2 +- Headers/Additions/GNUstepGUI/GSInstantiator.h | 43 + .../GNUstepGUI/GSModelLoaderFactory.h | 52 + .../Additions/GNUstepGUI/GSNibCompatibility.h | 200 ++- Headers/Additions/GNUstepGUI/GSNibContainer.h | 41 + Headers/Additions/GNUstepGUI/GSNibTemplates.h | 9 +- Headers/AppKit/NSNib.h | 3 +- Source/GNUmakefile | 12 +- Source/GSGModelLoader.m | 103 ++ Source/GSGormLoader.m | 146 ++ Source/GSModelLoaderFactory.m | 178 ++ Source/GSNibCompatibility.m | 1578 ++++++++++------- Source/GSNibLoader.m | 145 ++ Source/NSActionCell.m | 9 + Source/NSBundleAdditions.m | 199 +-- Source/NSButtonCell.m | 127 +- Source/NSCell.m | 9 +- Source/NSClipView.m | 45 +- Source/NSColorWell.m | 55 +- Source/NSLayoutManager.m | 4 +- Source/NSMatrix.m | 58 +- Source/NSMenuItem.m | 60 +- Source/NSNib.m | 131 +- Source/NSOutlineView.m | 72 +- Source/NSPopUpButtonCell.m | 1 + Source/NSScrollView.m | 159 +- Source/NSScroller.m | 29 +- Source/NSSecureTextField.m | 14 +- Source/NSSliderCell.m | 72 +- Source/NSStepperCell.m | 38 +- Source/NSTableView.m | 189 +- Source/NSTextContainer.m | 15 +- Source/NSTextField.m | 12 +- Source/NSTextView.m | 136 +- Source/NSView.m | 65 +- 36 files changed, 3162 insertions(+), 1236 deletions(-) create mode 100644 Headers/Additions/GNUstepGUI/GSInstantiator.h create mode 100644 Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h create mode 100644 Headers/Additions/GNUstepGUI/GSNibContainer.h create mode 100644 Source/GSGModelLoader.m create mode 100644 Source/GSGormLoader.m create mode 100644 Source/GSModelLoaderFactory.m create mode 100644 Source/GSNibLoader.m diff --git a/ChangeLog b/ChangeLog index d5e83ca3e..7e1c4400c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,125 @@ +2006-05-20 18:11 Gregory John Casamento + + * ChangeLog + * Documentation/ReleaseNotes.gsdoc + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h + * Headers/Additions/GNUstepGUI/GSNibTemplates.h + * Headers/AppKit/NSNib.h + * Source/GNUmakefile + * Source/GSNibCompatibility.m + * Source/NSActionCell.m + * Source/NSBundleAdditions.m + * Source/NSButtonCell.m + * Source/NSCell.m + * Source/NSClipView.m + * Source/NSColorWell.m + * Source/NSLayoutManager.m + * Source/NSMatrix.m + * Source/NSMenuItem.m + * Source/NSNib.m + * Source/NSOutlineView.m + * Source/NSPopUpButtonCell.m + * Source/NSScroller.m + * Source/NSScrollView.m + * Source/NSSecureTextField.m + * Source/NSSliderCell.m + * Source/NSStepperCell.m + * Source/NSTableView.m + * Source/NSTextContainer.m + * Source/NSTextField.m + * Source/NSTextView.m + * Source/NSView.m: Merged nib loading code from NibCompatibility. + +2006-05-15 21:55 Gregory John Casamento + + * Source/GSNibCompatibility.m: Streamlined previous change. + +2006-05-15 00:54 Gregory John Casamento + + * Source/GSNibCompatibility.m: Add title mask if window has + a title in the archive. + * Source/NSPopUpButtonCell.m: Clear and reset the menu + in the popup button cell initWithCoder: method. + +2006-05-14 20:58 Gregory John Casamento + + * Source/GSNibCompatibility.m: Added autosaveName. + +2006-05-10 23:55 Gregory John Casamento + + * Source/NSButtonCell.m + * Source/NSCell.m + * Source/NSMatrix.m: Improved initWithCoder: nib support. + +2006-05-09 22:48 Gregory John Casamento + + * Source/NSStepperCell.m: Implemented keyed coding. + +2006-05-07 22:36 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h: Added + _originalClassName member. + * Source/GSNibCompatibility.m: use new member in + instantiateRealObject:withClassName: to allow auto-substitution + of cell classes. + * Source/NSSecureTextField.m: Remove code to copy properties. + +2006-05-07 20:29 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h: Addition of + flags fields for the window. + * Source/GSNibCompatibility.m: Improvments to NSWindowTemplate. + * Source/NSScrollView.m: Changed unsigned int to unsigned long in + initWithCoder: + * Source/NSSecureTextField.m: code to copy the text field cell. + * Source/NSTextField.m: Changed if and added a comment in + initWithCoder: + +2006-05-07 11:07 Gregory John Casamento + + * Source/GSNibCompatibility.m: Removed kludge in nibInstantiate:owner: + method and added a category for NSNibControlConnector to reformat + the method name. + +2006-05-07 10:52 Gregory John Casamento + + * Source/GSNibCompatibility.m + * Source/NSActionCell.m + * Source/NSCell.m + * Source/NSSliderCell.m: Changes and improvements to handling of + cells for nib decoding. + +2006-05-06 13:09 Gregory John Casamento + + * Source/NSBundleAdditions.m: Unarchive destination before source. + * Source/NSOutlineView.m: Proper initialization of outline view in + initWithCoder: + * Source/NSTableView.m: Rearrangement of keys in initWithCoder: + +2006-05-05 00:41 Gregory John Casamento + + * Source/NSTextView.m: Completion of code in initWithCoder: for + keyed unarchiving. + +2006-05-03 22:43 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h: Make + NSIBObjectData conform to GSNibContainer protocol. + * Headers/Additions/GNUstepGUI/GSNibContainer.h: New protocol. + * Headers/Additions/GNUstepGUI/GSNibTemplates.h: Use new protocol + as protocol for the GSNibContainer object. + * Source/GNUmakefile: Add GSNibContainer.h to makefile. + * Source/GSNibCompatibility.m: Implement GSNibContainer methods, + skeleton implementation for some. + * Source/NSScrollView.m: Correct issue with horiz/vert scroller. + * Source/NSTextView.m: More keyed archiving changes. + +2006-05-03 01:00 Gregory John Casamento + + * Source/NSLayoutManager.m + * Source/NSTextContainer.m + * Source/NSTextView.m: Improved keyed unarchiving for these classes. + 2006-05-12 Nicolas Roard * TextConverters/RTF/RTFProducer.h: @@ -115,6 +237,16 @@ modifier mask as suggested by Fred, rather than original hard-coded command modifier. +2006-04-30 17:12 Gregory John Casamento + + * Source/GSNibCompatibility.m: Addition of keyMap to NSKeyedUnarchiver + in a category. + * Source/NSScrollView.m: Change to re-align view only if scroller is + present. + * Source/NSTextView.m: Changed initWithCoder: + * Source/NSView.m: Changed the order of initialization so that the + view has it's frame prior to the unarchiving of subviews. + 2006-04-30 Richard Frith-Macdonald * Source/NSMenu.m: ([performKeyEquivalent:]) Ignore key eqivalents other @@ -146,12 +278,28 @@ update _leftBorderOffset instead. (-drawRect:): Always draw dark gray upper and left border. +2006-04-26 22:34 Gregory John Casamento + + * Source/NSTableView.m: Correction for header view. + + 2006-04-24 Fred Kiefer * Source/NSDocumentController.m (-makeUntitledDocumentOfType:): Set the type of the new document. Patch by Saso Kiselkov . +2006-04-24 22:02 Gregory John Casamento + + * Source/GSNibCompatibility.m: Implementation of + NSButtonImageSource. + * Source/NSButtonCell.m: Code to compensate for image + encoding anomalies in nibs. + * Source/NSScrollView.m: Changes to properly decode scrollview + attributes and border settings. + * Source/NSTableView.m: Changes to properly set height of + cornerview. + 2006-04-19 Adam Fedor * configure: Add arg to disable aspell (for use on Mac OS X). @@ -160,6 +308,68 @@ is not redefined on MingW by jmorecfg.h (Suggestion from Issac Trotts). +2006-04-18 19:54 Gregory John Casamento + + * Source/NSTableView.m: Corrected code in setHeaderView: to + properly set the table view into the header view if it has + a "setTableView:" method. + +2006-04-18 00:55 Gregory John Casamento + + * Source/NSScrollView.m: Corrections for keyed decoding of + border style and other settings. + * Source/NSTableView.m: Some cleanup of keyed coding. + +2006-04-15 23:07 Gregory John Casamento + + * Source/GSNibCompatibility.m: Changed order of decoding. + * Source/NSScroller.m: Properly set the horiz/vert flags + * Source/NSScrollView.m: Corrections to keyed decoding and + contentView handing. + * Source/NSTableView.m: Corrections to keyed decoding. Use of a + struct to decode. + +2006-04-15 02:41 Gregory John Casamento + + * Source/NSScrollView.m: initWithCoder: modify position of + clipView due to differences in OSX vs. GNUstep. + +2006-04-15 02:26 Gregory John Casamento + + * Source/GSNibCompatibility.m: Comment on _NSHeaderView. + * Source/NSScrollView.m: Corrected issue with content view and + keyed coding. + * Source/NSTableView.m: Added additional initialization logic in + keyed coder. + +2006-04-14 00:02 Gregory John Casamento + + * Source/GSNibCompatibility.m: Changed ordering to allow views + to be properly initialized. + +2006-04-11 23:45 Gregory John Casamento + + * Headers/AppKit/NSNib.h + * Source/NSNib.m: Added keyed coding. + +2006-04-09 23:14 Gregory John Casamento + + * Source/GSModelLoaderFactory.m: Fixed a problem with + pathForNibResource: + +2006-04-09 20:37 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h + * Source/GSGormLoader.m + * Source/GSModelLoaderFactory.m + * Source/GSNibLoader.m + * Source/NSNib.m: Refactoring to make NSNib use the new + model loading framework. + +2006-04-09 12:25 Gregory John Casamento + + * Tools/gopen.m: Streamline gopen code. + 2006-04-09 12:28 Gregory John Casamento * Tools/gopen.m: Streamline gopen code. @@ -168,6 +378,8 @@ * Tools/gcloseall.m: Include NSProcessInfo.h. Fixes bug #16212. + + 2006-03-31 Richard Frith-Macdonald * Source/NSMenuView.m: ([-rectOfItemAtIndex:]) fixup origin of @@ -299,6 +511,13 @@ config because there was nothing in the user defaults system, save the new config so we don't have to do it again next time. + +2006-02-18 08:36 Gregory John Casamento + + * Source/GSNibCompatibility.m: Changed aDecoder to coder in + NSIBObjectData encoderWithCoder: also added code to throw an + exception if a coder does not support keyed coding. + 2006-02-06 Fred Kiefer * Source/NSMatrix.m (-deselectAllCells): Allow empty selection, @@ -423,6 +642,15 @@ * Tools/GNUmakefile.preamble: Build new utility. +2006-01-26 00:01 Gregory John Casamento + + * Source/NSScrollView.m: Temporary fix to scrollview. + +2006-01-25 22:31 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h + * Source/GSModelLoaderFactory.m: Fixes to work with gcc 3.x + 2006-01-22 Fred Kiefer * Source/NSPopupButtonCell.m (-synchronizeTitleAndSelectedItem): @@ -440,22 +668,164 @@ * Source/NSWindow.m: minor fixups for 64bit cpu support. +2006-01-16 00:58 Gregory John Casamento + + * Source/GSNibCompatibility.m: Minor changes in initWithCoder: + * Source/NSClipView.m: Added logic to check flags in initWithCoder: + * Source/NSOutlineView.m: Added initial changes for keyed coding. + * Source/NSScrollView.m: Added logic to check flags. + * Source/NSTableView.m: Added logic to check for old grid flag in + initWithCoder: + +2006-01-14 09:28 Gregory John Casamento + + * Source/NSTableView.m: Corrected bits used for columnResizing + flag in initWithCoder: and encodeWithCoder: + +2006-01-14 08:58 Gregory John Casamento + + * Source/NSTableView.m: Implemented encodeWithCoder: for NSTableView. + +2006-01-14 08:29 Gregory John Casamento + + * Source/GSNibCompatibility.m: [NSIBObjectData objectForName:] return + nil, if the object is not in the array. + * Source/NSTableView.m: implement decoding of flags in initWithCoder: + +2006-01-13 00:29 Gregory John Casamento + + * Source/NSColorWell.m: Added keyed coding support in initWithCoder: + and encodeWithCoder: + +2006-01-11 01:26 Gregory John Casamento + + * Source/NSSliderCell.m: Encode NSValue for compatibility with + Cocoa. + +2006-01-11 01:02 Gregory John Casamento + + * Source/GSNibCompatibility.m: Changes to NSViewTemplate. + * Source/NSSliderCell.m: Addition of code to handle slider to both + initWithCoder: and encodeWithCoder: + * Source/NSTextField.m: Removed unecessary empty + if conditional. + +2006-01-10 00:12 Gregory John Casamento + + * Source/GSNibCompatibility.m: Rearranged order of unarchiving in + [NSIBObjectData initWithCoder:]. + * Source/NSView.m: Added "NSSuperview" to encodeWithCoder: + +2006-01-09 19:38 Gregory John Casamento + + * Source/GSNibCompatibility.m: Rearrange order of unarchiving + in [NSIBObjectData initWithCoder:] so that NSClassSwapper unarchives + and replaces itself correctly. + * Source/NSView.m: Move subview initialization to after + the decoding section for both keyed/serial archiving in initWithCoder: + 2006-01-09 06:25 Gregory John Casamento * Source/NSNib.m: Correction for bug#15348. Removed uneeded append in initWithNibNamed: +2006-01-08 14:01 Gregory John Casamento + + * Source/NSMenuItem.m: initWithCoder: added code to decode + NSSubmenu key so that menus are properly constructed. + +2006-01-08 13:53 Gregory John Casamento + + * Source/GSNibCompatibility.m: Removed forwardInvocation from + NSClassSwapper. + * Source/NSMenuItem.m: Added implementation of keyed coding + to NSMenu initWithCoder: + 2006-01-08 Fred Kiefer * Source/NSTableView.m (-initWithFrame:) Use different intercell spacing. Patch by Andreas Höschler . +2006-01-07 10:38 Gregory John Casamento + + * Source/GSNibCompatibility.m: Encoding for NSIBObjectData, and + for NSWindowTemplate. Implementation of NSClassSwapper. + 2006-01-04 Fred Kiefer * Source/NSSliderCell.m (-knobRectFlipped,-knobThickness -drawInteriorWithFrame:inView:, -setKnobThickness:): Protect against knob image being nil. Fixes Solaris problem reported by . +2006-01-01 21:02 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSInstantiator.h: Protocol and + private method for instantiation. + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h: Added new header + * Source/GNUmakefile: Added new header to makefile. + * Source/GSNibCompatibility.m: Added nibInstantiation support. + * Source/NSBundleAdditions.m: Addition of instantiateWithInstantiator: + +2006-01-01 14:36 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h: Added + NSCustomResource. + * Source/GSNibCompatibility.m: Added NSCustomResource. + * Source/GSNibLoader.m: Calls keyed archiver with "IB.objectdata" + key. + +2006-01-01 09:27 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h: Added + declaration for priority method. + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h: Added + awakeWithContext method. + * Source/GSGModelLoader.m: Added priority method. + * Source/GSGormLoader.m: Added priority method + * Source/GSModelLoaderFactory.m: Implemented sorting by priority + * Source/GSNibCompatibility.m: use ASSIGN in initWithCoder: + * Source/GSNibLoader.m: Added priority method + * Source/NSBundleAdditions.m: Removed AUTORELEASE, since the + loader itself is autoreleased by the factory. + +2005-12-31 17:25 Gregory John Casamento + + * Source/GSNibCompatibility.m: Added code to properly initialize the + maptables. + +2005-12-31 16:10 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h: + Added awakeWithContext: + * Source/GNUmakefile: Added GSNibLoader.m + * Source/GSGormLoader.m: Changed some log output + * Source/GSNibCompatibility.m: Added awakeWithContext: + * Source/GSNibLoader.m: Loader for .nib files. + +2005-12-31 11:49 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h: Removed + protocol. + * Source/GSGModelLoader.m: + * Source/GSGormLoader.m: Removed initialize method + * Source/GSModelLoaderFactory.m: Renamed + abstract class to GSModelLoader. Added code + in initialize to register all subclasses of GSModelLoader. + * Source/NSBundleAdditions.m: Make changes to use new abstract + class name. + +2005-12-31 01:31 Gregory John Casamento + + * Source/GNUmakefile: Added new classes. + * Source/NSBundleAdditions.m: Changes to use new model loader + factory and loaders. + * Source/GSModelLoaderFactory.h + * Source/GSModelLoaderFactory.m: Handles model loading in + dynamic way. Allows registration of additional classes to + handle loading of guis. + * Source/GSGormLoader.m: Loader for .gorm files. + * Source/GSGModelLoader.m: Loader for .gmodel files. + 2005-12-31 Matt Rice * Source/NSTableView.m (-mouseDown:): Copy the selected cell before @@ -463,6 +833,23 @@ (-mouseDown:): Check for pointer equality in addition to isEqual: which doesn't work with nil. (fix for bug #15316) +2005-12-30 00:49 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h + * Source/GSNibCompatibility.m: NSCustomView changes. + +2005-12-29 00:39 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h + * Source/GSNibCompatibility.m: NSClassSwapper, NSCustomView, and + NSCustomObject. + +2005-12-27 20:51 Gregory John Casamento + + * Headers/Additions/GNUstepGUI/GSNibCompatibility.h: + * Source/GSNibCompatibility.m: Addition of classes for true OSX nib + compatibility. + 2005-12-22 Adam Fedor * Version 0.10.2 diff --git a/Documentation/ReleaseNotes.gsdoc b/Documentation/ReleaseNotes.gsdoc index c60f8f7b7..71e8c84ae 100644 --- a/Documentation/ReleaseNotes.gsdoc +++ b/Documentation/ReleaseNotes.gsdoc @@ -7,7 +7,7 @@ - $Revision: 22201 $ + $Revision$ $Date$ 2005 Free Software Foundation, Inc. diff --git a/Headers/Additions/GNUstepGUI/GSInstantiator.h b/Headers/Additions/GNUstepGUI/GSInstantiator.h new file mode 100644 index 000000000..dd3e95d54 --- /dev/null +++ b/Headers/Additions/GNUstepGUI/GSInstantiator.h @@ -0,0 +1,43 @@ +/* + GSNibCompatibility.h + + Copyright (C) 1997, 1999 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: 2002 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. +*/ + +#ifndef _GNUstep_H_GSInstantiator +#define _GNUstep_H_GSInstantiator + +#include +#include +#include + +// instantiator +@protocol GSInstantiator +- (id) instantiateObject: (id)object; +@end + +// informal protocol +@interface NSNibConnector (NibInstantiation) +- (void) instantiateWithInstantiator: (id)instantiator; +@end + +#endif /* _GNUstep_H_GSNibCompatibility */ diff --git a/Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h b/Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h new file mode 100644 index 000000000..33c976249 --- /dev/null +++ b/Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h @@ -0,0 +1,52 @@ +/** NSBundleAdditions + + Implementation of NSBundle Additions + + Copyright (C) 1997, 1999 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: 2005 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef _GNUstep_H_GSModelLoaderFactory +#define _GNUstep_H_GSModelLoaderFactory + +#include + +@interface GSModelLoader : NSObject ++ (NSString *) type; ++ (float) priority; +- (BOOL) loadModelData: (NSData *)data + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone; +- (BOOL) loadModelFile: (NSString *)fileName + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone; +@end + +@interface GSModelLoaderFactory : NSObject ++ (void) registerModelLoaderClass: (Class)aClass; ++ (Class)classForType: (NSString *)type; ++ (NSString *) supportedModelFileAtPath: (NSString *)modelPath; ++ (GSModelLoader *)modelLoaderForFileType: (NSString *)type; ++ (GSModelLoader *)modelLoaderForFileName: (NSString *)modelPath; +@end + +#endif diff --git a/Headers/Additions/GNUstepGUI/GSNibCompatibility.h b/Headers/Additions/GNUstepGUI/GSNibCompatibility.h index 9fa69449d..039bb2a5e 100644 --- a/Headers/Additions/GNUstepGUI/GSNibCompatibility.h +++ b/Headers/Additions/GNUstepGUI/GSNibCompatibility.h @@ -35,72 +35,204 @@ #include #include -/* - As these classes are deprecated, they should disappear from the gnustep - distribution in the next major release. They are for backwards compatibility - ONLY. -*/ - -// DO NOT USE. +#include +#include +#include +#include +#include "GNUstepGUI/GSNibContainer.h" +#include "GNUstepGUI/GSInstantiator.h" // templates -@protocol __DeprecatedTemplate__ +@protocol OSXNibTemplate - (void) setClassName: (NSString *)className; - (NSString *)className; -- (id) instantiateObject: (NSCoder *)coder; +- (id) realObject; @end -@interface NSWindowTemplate : NSWindow <__DeprecatedTemplate__> + +typedef struct _GSWindowTemplateFlags +{ +#ifdef WORDS_BIGENDIAN + unsigned int isHiddenOnDeactivate:1; + unsigned int isNotReleasedOnClose:1; + unsigned int isDeferred:1; + unsigned int isOneShot:1; + unsigned int isVisible:1; + unsigned int wantsToBeColor:1; + unsigned int dynamicDepthLimit:1; + unsigned int autoPositionMask:6; + unsigned int savePosition:1; + unsigned int style:2; + unsigned int _unused:16; // currently not used, contains Cocoa specific info +#else + unsigned int _unused:16; // currently not used, contains Cocoa specific info + unsigned int style:2; + unsigned int savePosition:1; + unsigned int autoPositionMask:6; + unsigned int dynamicDepthLimit:1; + unsigned int wantsToBeColor:1; + unsigned int isVisible:1; + unsigned int isOneShot:1; + unsigned int isDeferred:1; + unsigned int isNotReleasedOnClose:1; + unsigned int isHiddenOnDeactivate:1; +#endif +} GSWindowTemplateFlags; + +/** + * This class acts as a placeholder for the window. It doesn't derive from + * NSWindow for two reasons. First, it shouldn't instantiate a window immediately + * when it's unarchived and second, it holds certain attributes (but doesn't set them + * on the window, when the window is being edited in the application builder. + */ +@interface NSWindowTemplate : NSObject +{ + NSBackingStoreType _backingStoreType; + NSSize _maxSize; + NSSize _minSize; + unsigned _windowStyle; + NSString *_title; + NSString *_viewClass; + NSString *_windowClass; + NSRect _windowRect; + NSRect _screenRect; + id _realObject; + id _view; + GSWindowTemplateFlags _flags; + NSString *_autosaveName; +} +- (void) setBackingStoreType: (NSBackingStoreType)type; +- (NSBackingStoreType) backingStoreType; +- (void) setDeferred: (BOOL)flag; +- (BOOL) isDeferred; +- (void) setMaxSize: (NSSize)maxSize; +- (NSSize) maxSize; +- (void) setMinSize: (NSSize)minSize; +- (NSSize) minSize; +- (void) setWindowStyle: (unsigned)sty; +- (unsigned) windowStyle; +- (void) setTitle: (NSString *) title; +- (NSString *)title; +- (void) setViewClass: (NSString *)viewClass; +- (NSString *)viewClass; +- (void) setWindowRect: (NSRect)rect; +- (NSRect)windowRect; +- (void) setScreenRect: (NSRect)rect; +- (NSRect) screenRect; +- (id) realObject; +- (void) setView: (id)view; +- (id) view; +@end + +@interface NSViewTemplate : NSView { NSString *_className; - NSString *_parentClassName; - BOOL _deferFlag; + id _realObject; } @end -@interface NSViewTemplate : NSView <__DeprecatedTemplate__> +@interface NSTextTemplate : NSViewTemplate { - NSString *_className; - NSString *_parentClassName; } @end -@interface NSTextTemplate : NSText <__DeprecatedTemplate__> +@interface NSTextViewTemplate : NSViewTemplate { - NSString *_className; - NSString *_parentClassName; } @end -@interface NSTextViewTemplate : NSTextView <__DeprecatedTemplate__> +@interface NSMenuTemplate : NSObject { - NSString *_className; - NSString *_parentClassName; + NSString *_menuClass; + NSString *_title; + id _realObject; + id _parentMenu; + NSPoint _location; + BOOL _isWindowsMenu; + BOOL _isServicesMenu; + BOOL _isFontMenu; + NSInterfaceStyle _interfaceStyle; } +- (void) setClassName: (NSString *)name; +- (NSString *)className; +- (id)nibInstantiate; @end -@interface NSMenuTemplate : NSMenu <__DeprecatedTemplate__> +@interface NSCustomObject : NSObject { - NSString *_className; - NSString *_parentClassName; + NSString *_className; + NSString *_extension; + id _object; } +- (void) setClassName: (NSString *)name; +- (NSString *)className; +- (void) setExtension: (NSString *)ext; +- (NSString *)extension; +- (void) setObject: (id)obj; +- (id)object; @end -@interface NSControlTemplate : NSControl <__DeprecatedTemplate__> +@interface NSCustomView : NSView { - NSString *_className; - NSString *_parentClassName; - id _delegate; - id _dataSource; - BOOL _usesDataSource; + NSString *_className; + NSString *_extension; + NSView *_superview; + NSView *_view; } +- (void) setClassName: (NSString *)name; +- (NSString *)className; +- (void) setExtension: (NSString *)view; +- (NSString *)extension; +- (id)nibInstantiate; @end -@interface NSButtonTemplate : NSButton <__DeprecatedTemplate__> +@interface NSCustomResource : NSObject { - NSString *_className; - NSString *_parentClassName; - NSButtonType _buttonType; + NSString *_className; + NSString *_resourceName; } +- (void) setClassName: (NSString *)className; +- (NSString *)className; +- (void) setResourceName: (NSString *)view; +- (NSString *)resourceName; +- (id)nibInstantiate; @end + +@interface NSClassSwapper : NSObject +{ + NSString *_className; + NSString *_originalClassName; + id _template; +} +- (void) setTemplate: (id)temp; +- (id) template; +- (void) setClassName: (NSString *)className; +- (NSString *)className; +@end + +@interface NSIBObjectData : NSObject +{ + id _root; + NSMapTable *_objects; + NSMapTable *_names; + NSMapTable *_oids; + NSMapTable *_classes; + NSMapTable *_instantiatedObjs; + NSMutableSet *_visibleWindows; + NSMutableArray *_connections; + id _firstResponder; + id _fontManager; + NSString *_framework; + id _document; + unsigned _nextOid; + NSMutableArray *_accessibilityConnectors; + NSMapTable *_accessibilityOids; +} +- (id) instantiateObject: (id)obj; +- (void) nibInstantiateWithOwner: (id)owner; +- (void) nibInstantiateWithOwner: (id)owner topLevelObjects: (NSMutableArray *)toplevel; +- (id) objectForName: (NSString *)name; +- (NSString *) nameForObject: (id)name; +@end + #endif /* _GNUstep_H_GSNibCompatibility */ diff --git a/Headers/Additions/GNUstepGUI/GSNibContainer.h b/Headers/Additions/GNUstepGUI/GSNibContainer.h new file mode 100644 index 000000000..cfb993f60 --- /dev/null +++ b/Headers/Additions/GNUstepGUI/GSNibContainer.h @@ -0,0 +1,41 @@ +/* + GSNibContainer.h + + Copyright (C) 1997, 1999 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: 2006 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. +*/ + +#ifndef _GNUstep_H_GSNibContainer +#define _GNUstep_H_GSNibContainer + +@class NSDictionary; +@class NSMutableDictionary; +@class NSMutableSet; +@class NSMutableArray; + +@protocol GSNibContainer +- (void) awakeWithContext: (NSDictionary *)context; +- (NSMutableDictionary*) nameTable; +- (NSMutableArray*) connections; +- (NSMutableSet*) topLevelObjects; +@end + +#endif /* _GNUstep_H_GSNibContainer */ diff --git a/Headers/Additions/GNUstepGUI/GSNibTemplates.h b/Headers/Additions/GNUstepGUI/GSNibTemplates.h index 7caa5f6db..8e68a3687 100644 --- a/Headers/Additions/GNUstepGUI/GSNibTemplates.h +++ b/Headers/Additions/GNUstepGUI/GSNibTemplates.h @@ -33,8 +33,9 @@ #include #include #include +#include "GNUstepGUI/GSNibContainer.h" -// versions of the nib container and the templates. +// version of the nib container and the templates. #define GNUSTEP_NIB_VERSION 1 #define GSSWAPPER_VERSION 0 #define GSWINDOWT_VERSION 1 @@ -62,17 +63,13 @@ enum { /* * This is the class that holds objects within a nib. */ -@interface GSNibContainer : NSObject +@interface GSNibContainer : NSObject { NSMutableDictionary *nameTable; NSMutableArray *connections; NSMutableSet *topLevelObjects; BOOL isAwake; } -- (void) awakeWithContext: (NSDictionary *)context; -- (NSMutableDictionary*) nameTable; -- (NSMutableArray*) connections; -- (NSMutableSet*) topLevelObjects; @end /* diff --git a/Headers/AppKit/NSNib.h b/Headers/AppKit/NSNib.h index 4f9a6008a..f0b16e4ff 100644 --- a/Headers/AppKit/NSNib.h +++ b/Headers/AppKit/NSNib.h @@ -55,7 +55,8 @@ @interface NSNib : NSObject { NSData *_nibData; - NSMutableArray *_topLevelItems; + id _loader; + NSURL *_url; } // reading the data... diff --git a/Source/GNUmakefile b/Source/GNUmakefile index e62410912..136623823 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -200,8 +200,11 @@ GSWindowDecorationView.m \ GSPrinting.m \ GSPrintOperation.m \ GSEPSPrintOperation.m \ -GSPDFPrintOperation.m - +GSPDFPrintOperation.m \ +GSModelLoaderFactory.m \ +GSGormLoader.m \ +GSGModelLoader.m \ +GSNibLoader.m # Turn off NSMenuItem warning that NSMenuItem conforms to , # but does not implement 's methods itself (it inherits @@ -360,6 +363,7 @@ GSTextConverter.h \ GSTrackingRect.h \ GSHelpManagerPanel.h \ GSNibTemplates.h \ +GSNibContainer.h \ GSDisplayServer.h \ GSFusedSilica.h \ GSTable.h \ @@ -380,7 +384,9 @@ GSTitleView.h \ GSPrinting.h \ GSPrintOperation.h \ GSEPSPrintOperation.h \ -GSPDFPrintOperation.h +GSPDFPrintOperation.h \ +GSModelLoaderFactory.h \ +GSInstantiator.h libgnustep-gui_HEADER_FILES = ${GUI_HEADERS} diff --git a/Source/GSGModelLoader.m b/Source/GSGModelLoader.m new file mode 100644 index 000000000..28cb771b5 --- /dev/null +++ b/Source/GSGModelLoader.m @@ -0,0 +1,103 @@ +/** GSGormLoader + + Gorm model loader + + Copyright (C) 1997, 1999 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: 2005 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include "GNUstepGUI/GSModelLoaderFactory.h" +#include "GNUstepGUI/IMLoading.h" + +static +Class gmodel_class(void) +{ + static Class gmclass = Nil; + + if (gmclass == Nil) + { + NSBundle *theBundle; + NSEnumerator *benum; + NSString *path; + + /* Find the bundle */ + benum = [NSStandardLibraryPaths() objectEnumerator]; + while ((path = [benum nextObject])) + { + path = [path stringByAppendingPathComponent: @"Bundles"]; + path = [path stringByAppendingPathComponent: @"libgmodel.bundle"]; + if ([[NSFileManager defaultManager] fileExistsAtPath: path]) + break; + path = nil; + } + NSCAssert(path != nil, @"Unable to load gmodel bundle"); + NSDebugLog(@"Loading gmodel from %@", path); + + theBundle = [NSBundle bundleWithPath: path]; + NSCAssert(theBundle != nil, @"Can't init gmodel bundle"); + gmclass = [theBundle classNamed: @"GMModel"]; + NSCAssert(gmclass, @"Can't load gmodel bundle"); + } + return gmclass; +} + +@interface GSGModelLoader : GSModelLoader +@end + +@implementation GSGModelLoader ++ (void) initialize +{ + // register for the gmodel type. +} + ++ (NSString *) type +{ + return @"gmodel"; +} + ++ (float) priority +{ + return 2.0; +} + +- (BOOL) loadModelFile: (NSString *)fileName + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone; +{ + NSString *ext = [fileName pathExtension]; + + /* + * If the file to be read is a gmodel, use the GMModel method to + * read it in and skip the dearchiving below. + */ + if ([ext isEqualToString: @"gmodel"]) + { + return [gmodel_class() loadIMFile: fileName + owner: [context objectForKey: @"NSOwner"]]; + } + + return NO; +} +@end diff --git a/Source/GSGormLoader.m b/Source/GSGormLoader.m new file mode 100644 index 000000000..8d557ef90 --- /dev/null +++ b/Source/GSGormLoader.m @@ -0,0 +1,146 @@ +/** GSGormLoader + + Gorm model loader + + Copyright (C) 1997, 1999 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: 2005 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include "GNUstepGUI/GSModelLoaderFactory.h" +#include "GNUstepGUI/GSNibTemplates.h" + +@interface GSGormLoader : GSModelLoader +@end + +@implementation GSGormLoader ++ (void) initialize +{ + // should do something... +} + ++ (NSString *)type +{ + return @"gorm"; +} + ++ (float) priority +{ + return 1.0; +} + + +- (BOOL) loadModelData: (NSData *)data + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone; +{ + BOOL loaded = NO; + NSUnarchiver *unarchiver = nil; + + NS_DURING + { + if (data != nil) + { + unarchiver = [[NSUnarchiver alloc] + initForReadingWithData: data]; + if (unarchiver != nil) + { + id obj; + + NSDebugLog(@"Invoking unarchiver"); + [unarchiver setObjectZone: zone]; + obj = [unarchiver decodeObject]; + if (obj != nil) + { + if ([obj isKindOfClass: [GSNibContainer class]]) + { + NSDebugLog(@"Calling awakeWithContext"); + [obj awakeWithContext: context]; + loaded = YES; + } + else + { + NSLog(@"Gorm does not have a container object!"); + } + } + RELEASE(unarchiver); + } + } + } + NS_HANDLER + { + NSLog(@"Exception occured while loading model: %@",[localException reason]); + TEST_RELEASE(unarchiver); + } + NS_ENDHANDLER + + if (loaded == NO) + { + NSLog(@"Failed to load Gorm\n"); + } + + return loaded; +} + +- (BOOL) loadModelFile: (NSString *)fileName + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone; +{ + NSFileManager *mgr = [NSFileManager defaultManager]; + BOOL isDir = NO; + BOOL loaded = NO; + + NSDebugLog(@"Loading Gorm `%@'...\n", fileName); + + if ([mgr fileExistsAtPath: fileName isDirectory: &isDir]) + { + NSData *data = nil; + + // if the data is in a directory, then load from objects.gorm in the directory + if (isDir == NO) + { + data = [NSData dataWithContentsOfFile: fileName]; + NSDebugLog(@"Loaded data from file..."); + } + else + { + NSString *newFileName = [fileName stringByAppendingPathComponent: @"objects.gorm"]; + data = [NSData dataWithContentsOfFile: newFileName]; + NSDebugLog(@"Loaded data from %@...",newFileName); + } + + loaded = [self loadModelData: data + externalNameTable: context + withZone: zone]; + + // report a problem if there is one. + if(loaded == NO) + { + NSLog(@"Could not load Gorm file: %@",fileName); + } + } + + return loaded; +} +@end diff --git a/Source/GSModelLoaderFactory.m b/Source/GSModelLoaderFactory.m new file mode 100644 index 000000000..86caf43da --- /dev/null +++ b/Source/GSModelLoaderFactory.m @@ -0,0 +1,178 @@ +/** GSModelLoaderFactory + + Model loader framework + + Copyright (C) 1997, 1999 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: 2005 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include "GNUstepGUI/GSModelLoaderFactory.h" +#include "GNUstepBase/GSObjCRuntime.h" + +@implementation GSModelLoader ++ (NSString *) type +{ + return nil; +} + ++ (float) priority +{ + return 0.0; +} + +- (BOOL) loadModelData: (NSData *)data + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone +{ + [NSException raise: NSInternalInconsistencyException + format: @"Abstract model loader."]; + return NO; +} + +- (BOOL) loadModelFile: (NSString *)fileName + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone +{ + [NSException raise: NSInternalInconsistencyException + format: @"Abstract model loader."]; + return NO; +} + ++ (NSComparisonResult) _comparePriority: (Class)loader +{ + NSComparisonResult result = NSOrderedSame; + + if([self priority] < [loader priority]) + { + result = NSOrderedAscending; + } + if([self priority] > [loader priority]) + { + result = NSOrderedDescending; + } + + return result; +} +@end + +static NSMutableDictionary *_modelMap = nil; + +@implementation GSModelLoaderFactory ++ (void) initialize +{ + NSArray *classes = GSObjCAllSubclassesOfClass([GSModelLoader class]); + NSEnumerator *en = [classes objectEnumerator]; + Class cls = nil; + + while((cls = [en nextObject]) != nil) + { + [self registerModelLoaderClass: cls]; + } +} + ++ (void) registerModelLoaderClass: (Class)aClass +{ + if(_modelMap == nil) + { + _modelMap = [[NSMutableDictionary alloc] initWithCapacity: 5]; + } + + [_modelMap setObject: aClass forKey: (NSString *)[aClass type]]; +} + ++ (Class)classForType: (NSString *)type +{ + return [_modelMap objectForKey: type]; +} + ++ (NSString *) supportedModelFileAtPath: (NSString *)modelPath +{ + NSString *result = nil; + NSFileManager *mgr = [NSFileManager defaultManager]; + NSString *ext = [modelPath pathExtension]; + + if([ext isEqual: @""]) + { + NSArray *objectArray = [_modelMap allValues]; + NSArray *sortedArray = [objectArray sortedArrayUsingSelector: + @selector(_comparePriority:)]; + NSEnumerator *oen = [sortedArray objectEnumerator]; + Class cls = nil; + + while((cls = [oen nextObject]) != nil && result == NO) + { + NSString *path = [modelPath stringByAppendingPathExtension: + (NSString *)[cls type]]; + if([mgr isReadableFileAtPath: path]) + { + result = path; + } + } + } + else + { + if([_modelMap objectForKey: ext] != nil) + { + if([mgr isReadableFileAtPath: modelPath]) + { + result = modelPath; + } + } + } + + return result; +} + ++ (GSModelLoader *)modelLoaderForFileType: (NSString *)type +{ + Class aClass = [GSModelLoaderFactory classForType: type]; + GSModelLoader *loader = nil; + + if(aClass != nil) + { + loader = AUTORELEASE([[aClass alloc] init]); + } + else + { + [NSException raise: NSInternalInconsistencyException + format: @"Unable to find model loader class."]; + } + + return loader; +} + ++ (GSModelLoader *)modelLoaderForFileName: (NSString *)modelPath +{ + NSString *path = [GSModelLoaderFactory supportedModelFileAtPath: modelPath]; + GSModelLoader *result = nil; + + if(path != nil) + { + NSString *ext = [path pathExtension]; + result = [self modelLoaderForFileType: ext]; + } + + return result; +} +@end diff --git a/Source/GSNibCompatibility.m b/Source/GSNibCompatibility.m index 3a6f64ba0..fbb30e299 100644 --- a/Source/GSNibCompatibility.m +++ b/Source/GSNibCompatibility.m @@ -1,21 +1,14 @@ /** GSNibCompatibility - These are the old template classes which were used in older .gorm files. - All of these classes are deprecated and should not be used directly. - They will be removed from the GUI library in the next few versions as - they need to be phased out gradually. -

- If you have any older .gorm files which were created using custom classes, - you should load them into Gorm and save them so that they will use the new - system. Updating the .gorm files should be as easy as that. These - classes are included ONLY for backwards compatibility. + These are templates for use with OSX Nib files. These classes are the + templates and other things which are needed for reading/writing nib files. Copyright (C) 1997, 1999 Free Software Foundation, Inc. Author: Gregory John Casamento - Date: Oct 2003 + Date: 2003, 2005 This file is part of the GNUstep GUI Library. @@ -56,17 +49,7 @@ #include "AppKit/AppKit.h" #include #include - -////////////////////////////////////////////////////////////////////////////////////////// -////////////////// DEPRECATED TEMPLATES ----- THESE SHOULD NOT BE USED ////////////////// -////////////////////////////////////////////////////////////////////////////////////////// - -/* - As these classes are deprecated, they should disappear from the gnustep distribution - in the next major release. -*/ - -#define DEPRECATION_WARNING NSLog(@"WARNING: Attempt to encode/decode an deprecated template. Please update the .gorm. Load the gorm file in Gorm.app and resave to update it.") +#include @implementation NSWindowTemplate + (void) initialize @@ -79,151 +62,263 @@ - (void) dealloc { - RELEASE(_parentClassName); - RELEASE(_className); + RELEASE(_title); + RELEASE(_viewClass); + RELEASE(_windowClass); + RELEASE(_view); + RELEASE(_autosaveName); [super dealloc]; } -- init +- (id) initWithCoder: (NSCoder *)coder { - [super init]; - - // Start initially with the highest level class - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - - // defer flag - _deferFlag = NO; - - return self; -} - -- (id) initWithCoder: (NSCoder *)aDecoder -{ - /**/ - if ([aDecoder allowsKeyedCoding]) + if ([coder allowsKeyedCoding]) { - //NSRect screenRect = [aDecoder decodeRectForKey: @"NSScreenRect"]; - NSRect windowRect = [aDecoder decodeRectForKey: @"NSWindowRect"]; - //NSString *viewClass = [aDecoder decodeObjectForKey: @"NSViewClass"]; - NSString *windowClass = [aDecoder decodeObjectForKey: @"NSWindowClass"]; - int style = [aDecoder decodeIntForKey: @"NSWindowStyleMask"]; - int backing = [aDecoder decodeIntForKey: @"NSWindowBacking"]; - - ASSIGN(_className, windowClass); - self = [self initWithContentRect: windowRect - styleMask: style - backing: backing - defer: NO - screen: nil]; - - if ([aDecoder containsValueForKey: @"NSWindowView"]) + if ([coder containsValueForKey: @"NSViewClass"]) { - [self setContentView: - [aDecoder decodeObjectForKey: @"NSWindowView"]]; + ASSIGN(_viewClass, [coder decodeObjectForKey: @"NSViewClass"]); } - if ([aDecoder containsValueForKey: @"NSWTFlags"]) + if ([coder containsValueForKey: @"NSWindowClass"]) { - //int flags = [aDecoder decodeIntForKey: @"NSWTFlags"]; + ASSIGN(_windowClass, [coder decodeObjectForKey: @"NSWindowClass"]); } - if ([aDecoder containsValueForKey: @"NSMinSize"]) + if ([coder containsValueForKey: @"NSWindowStyleMask"]) { - NSSize minSize = [aDecoder decodeSizeForKey: @"NSMinSize"]; - [self setMinSize: minSize]; + _windowStyle = [coder decodeIntForKey: @"NSWindowStyleMask"]; } - if ([aDecoder containsValueForKey: @"NSMaxSize"]) + if([coder containsValueForKey: @"NSWindowBacking"]) + { + _backingStoreType = [coder decodeIntForKey: @"NSWindowBacking"]; + } + if ([coder containsValueForKey: @"NSWindowView"]) { - NSSize maxSize = [aDecoder decodeSizeForKey: @"NSMaxSize"]; - [self setMaxSize: maxSize]; + ASSIGN(_view, [coder decodeObjectForKey: @"NSWindowView"]); } - if ([aDecoder containsValueForKey: @"NSWindowTitle"]) + if ([coder containsValueForKey: @"NSWTFlags"]) { - [self setTitle: [aDecoder decodeObjectForKey: @"NSWindowTitle"]]; + unsigned long flags = [coder decodeIntForKey: @"NSWTFlags"]; + memcpy((void *)&_flags,(void *)&flags,sizeof(struct _GSWindowTemplateFlags)); + } + if ([coder containsValueForKey: @"NSMinSize"]) + { + _minSize = [coder decodeSizeForKey: @"NSMinSize"]; + } + if ([coder containsValueForKey: @"NSMaxSize"]) + { + _maxSize = [coder decodeSizeForKey: @"NSMaxSize"]; + } + if ([coder containsValueForKey: @"NSWindowRect"]) + { + _windowRect = [coder decodeRectForKey: @"NSWindowRect"]; + } + if ([coder containsValueForKey: @"NSFrameAutosaveName"]) + { + ASSIGN(_autosaveName, [coder decodeObjectForKey: @"NSFrameAutosaveName"]); + } + if ([coder containsValueForKey: @"NSWindowTitle"]) + { + ASSIGN(_title, [coder decodeObjectForKey: @"NSWindowTitle"]); + _windowStyle |= NSTitledWindowMask; } - - return self; } else { - DEPRECATION_WARNING; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_className]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_parentClassName]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_deferFlag]; - return [super initWithCoder: aDecoder]; + [NSException raise: NSInternalInconsistencyException + format: @"Can't decode %@ with %@.",NSStringFromClass([self class]), + NSStringFromClass([coder class])]; } + return self; } - (void) encodeWithCoder: (NSCoder *)aCoder { - DEPRECATION_WARNING; + if ([aCoder allowsKeyedCoding]) + { + unsigned long flags = 0; + + memcpy((void *)&flags,(void *)&_flags,sizeof(unsigned long)); + + [aCoder encodeObject: _viewClass forKey: @"NSViewClass"]; + [aCoder encodeObject: _windowClass forKey: @"NSWindowClass"]; + [aCoder encodeInt: _windowStyle forKey: @"NSWindowStyleMask"]; + [aCoder encodeInt: _backingStoreType forKey: @"NSWindowBacking"]; + [aCoder encodeObject: _view forKey: @"NSWindowView"]; + [aCoder encodeInt: flags forKey: @"NSWTFlags"]; + [aCoder encodeSize: _minSize forKey: @"NSMinSize"]; + [aCoder encodeSize: _maxSize forKey: @"NSMaxSize"]; + [aCoder encodeRect: _windowRect forKey: @"NSWindowRect"]; + [aCoder encodeObject: _title forKey: @"NSWindowTitle"]; + [aCoder encodeObject: _autosaveName forKey: @"NSFrameAutosaveName"]; + } } -- (id) awakeAfterUsingCoder: (NSCoder *)coder +- (id) nibInstantiate { - if ([self respondsToSelector: @selector(isInInterfaceBuilder)]) + if(_realObject == nil) { - // if we live in the interface builder, give them an instance of - // the parent, not the child.. - [self setClassName: _parentClassName]; - } - - return [self instantiateObject: coder]; -} + Class aClass = NSClassFromString(_windowClass); + NSEnumerator *en; + id v = nil; + + if (aClass == nil) + { + [NSException raise: NSInternalInconsistencyException + format: @"Unable to find class '%@'", _windowClass]; + } + + _realObject = [[aClass allocWithZone: NSDefaultMallocZone()] + initWithContentRect: _windowRect + styleMask: _windowStyle + backing: _backingStoreType + defer: _flags.isDeferred + screen: nil]; + + // set flags... + [_realObject setHidesOnDeactivate: _flags.isHiddenOnDeactivate]; + [_realObject setReleasedWhenClosed: !(_flags.isNotReleasedOnClose)]; + [_realObject setOneShot: _flags.isOneShot]; + // [_realObject setVisible: _flags.isVisible]; // this is determined by whether it's in the visible windows array... + // [_realObject setWantsToBeColor: _flags.wantsToBeColor]; // not applicable on GNUstep. + [_realObject setAutodisplay: YES]; + [_realObject setDynamicDepthLimit: _flags.dynamicDepthLimit]; + // [_realObject setAutoPositionMask: _flags.autoPositionMask]; // currently not implemented for nibs + // [_realObject setAutoPosition: _flags.autoPosition]; + [_realObject setDynamicDepthLimit: _flags.dynamicDepthLimit]; + [_realObject setFrameAutosaveName: _autosaveName]; -- (id) instantiateObject: (NSCoder *)coder -{ - id obj = nil; - Class aClass = NSClassFromString(_className); - - if (aClass == nil) - { - [NSException raise: NSInternalInconsistencyException - format: @"Unable to find class '%@'", _className]; - } - - obj = [[aClass allocWithZone: [self zone]] - initWithContentRect: [self frame] - styleMask: [self styleMask] - backing: [self backingType] - defer: _deferFlag]; - - // fill in actual object from template - [obj setBackgroundColor: [self backgroundColor]]; - [(NSWindow*)obj setContentView: [self contentView]]; - [obj setFrameAutosaveName: [self frameAutosaveName]]; - [obj setHidesOnDeactivate: [self hidesOnDeactivate]]; - [obj setInitialFirstResponder: [self initialFirstResponder]]; - [obj setAutodisplay: [self isAutodisplay]]; - [obj setReleasedWhenClosed: [self isReleasedWhenClosed]]; - [obj _setVisible: [self isVisible]]; - [obj setTitle: [self title]]; - [obj setFrame: [self frame] display: NO]; - - RELEASE(self); - RETAIN(obj); - - return obj; + // reset attributes... + [_realObject setContentView: _view]; + [_realObject setMinSize: _minSize]; + [_realObject setMaxSize: _maxSize]; + [_realObject setTitle: _title]; + + // swap out any views which need to be swapped... + en = [[[_realObject contentView] subviews] objectEnumerator]; + while((v = [en nextObject]) != nil) + { + if([v respondsToSelector: @selector(nibInstantiate)]) + { + [v nibInstantiate]; + } + } + } + return _realObject; } // setters and getters +- (void) setBackingStoreType: (NSBackingStoreType)type +{ + _backingStoreType = type; +} + +- (NSBackingStoreType) backingStoreType +{ + return _backingStoreType; +} + +- (void) setDeferred: (BOOL)flag +{ + _flags.isDeferred = flag; +} + +- (BOOL) isDeferred +{ + return _flags.isDeferred; +} + +- (void) setMaxSize: (NSSize)maxSize +{ + _maxSize = maxSize; +} + +- (NSSize) maxSize +{ + return _maxSize; +} + +- (void) setMinSize: (NSSize)minSize +{ + _minSize = minSize; +} + +- (NSSize) minSize +{ + return _minSize; +} + +- (void) setWindowStyle: (unsigned)style +{ + _windowStyle = style; +} + +- (unsigned) windowStyle +{ + return _windowStyle; +} + +- (void) setTitle: (NSString *) title +{ + ASSIGN(_title, title); +} + +- (NSString *)title; +{ + return _title; +} + +- (void) setViewClass: (NSString *)viewClass +{ + ASSIGN(_viewClass,viewClass); +} + +- (NSString *)viewClass +{ + return _viewClass; +} + +- (void) setWindowRect: (NSRect)rect +{ + _windowRect = rect; +} + +- (NSRect)windowRect +{ + return _windowRect; +} + +- (void) setScreenRect: (NSRect)rect +{ + _screenRect = rect; +} + +- (NSRect) screenRect +{ + return _screenRect; +} + +- (id) realObject +{ + return _realObject; +} + +- (void) setView: (id)view +{ + ASSIGN(_view,view); +} + +- (id) view +{ + return _view; +} + - (void) setClassName: (NSString *)name { - ASSIGN(_className, name); + ASSIGN(_windowClass, name); } - (NSString *)className { - return _className; -} - -- (BOOL)deferFlag -{ - return _deferFlag; -} - -- (void)setDeferFlag: (BOOL)flag -{ - _deferFlag = flag; + return _windowClass; } @end @@ -237,78 +332,51 @@ } } -- (void) dealloc +- (id) initWithCoder: (NSCoder *)coder { - RELEASE(_parentClassName); - RELEASE(_className); - [super dealloc]; -} - -- initWithFrame: (NSRect)frame -{ - // Start initially with the highest level class - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - [super initWithFrame: frame]; - + self = [super initWithCoder: coder]; + if(self != nil) + { + if([coder allowsKeyedCoding]) + { + _className = [coder decodeObjectForKey: @"NSClassName"]; + } + } + else + { + [NSException raise: NSInternalInconsistencyException + format: @"Can't decode %@ with %@.",NSStringFromClass([self class]), + NSStringFromClass([coder class])]; + } return self; } -- init +- (void) encodeWithCoder: (NSCoder *)coder { - // Start initially with the highest level class - [super init]; - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - return self; -} - -- (id) initWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; - [aCoder decodeValueOfObjCType: @encode(id) at: &_className]; - [aCoder decodeValueOfObjCType: @encode(id) at: &_parentClassName]; - return [super initWithCoder: aCoder]; -} - -- (void) encodeWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; -} - -- (id) awakeAfterUsingCoder: (NSCoder *)coder -{ - if ([self respondsToSelector: @selector(isInInterfaceBuilder)]) + if([coder allowsKeyedCoding]) { - // if we live in the interface builder, give them an instance of - // the parent, not the child.. - [self setClassName: _parentClassName]; + [coder encodeObject: (id)_className forKey: @"NSClassName"]; } - return [self instantiateObject: coder]; } -- (id) instantiateObject: (NSCoder *)coder +- (id)nibInstantiate { - Class aClass = NSClassFromString(_className); - NSRect theFrame = [self frame]; - id obj = nil; - - if (aClass == nil) + if(_realObject == nil) { - [NSException raise: NSInternalInconsistencyException - format: @"Unable to find class '%@'", _className]; + Class aClass = NSClassFromString(_className); + if(aClass == nil) + { + [NSException raise: NSInternalInconsistencyException + format: @"Unable to find class '%@'", _className]; + } + else + { + _realObject = [[aClass allocWithZone: NSDefaultMallocZone()] initWithFrame: [self frame]]; + [[self superview] replaceSubview: self with: _realObject]; // replace the old view... + } } - obj = [[aClass allocWithZone: NSDefaultMallocZone()] - initWithFrame: theFrame]; - - // set the attributes for the view - [obj setBounds: [self bounds]]; - - RELEASE(self); - RETAIN(obj); - - return obj; + return _realObject; } // setters and getters @@ -322,6 +390,10 @@ return _className; } +- (id) realObject +{ + return _realObject; +} @end // Template for any classes which derive from NSText @@ -333,100 +405,6 @@ [self setVersion: 0]; } } - -- (void) dealloc -{ - RELEASE(_parentClassName); - RELEASE(_className); - [super dealloc]; -} - -- initWithFrame: (NSRect)frame -{ - // Start initially with the highest level class - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - [super initWithFrame: frame]; - return self; -} - -- init -{ - // Start initially with the highest level class - [super init]; - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - return self; -} - -- (id) initWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; - [aCoder decodeValueOfObjCType: @encode(id) at: &_className]; - [aCoder decodeValueOfObjCType: @encode(id) at: &_parentClassName]; - return [super initWithCoder: aCoder]; -} - -- (void) encodeWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; -} - -- (id) awakeAfterUsingCoder: (NSCoder *)coder -{ - if ([self respondsToSelector: @selector(isInInterfaceBuilder)]) - { - // if we live in the interface builder, give them an instance of - // the parent, not the child.. - [self setClassName: _parentClassName]; - } - return [self instantiateObject: coder]; -} - -- (id) instantiateObject: (NSCoder *)coder -{ - Class aClass = NSClassFromString(_className); - NSRect theFrame = [self frame]; - id obj = nil; - - if (aClass == nil) - { - [NSException raise: NSInternalInconsistencyException - format: @"Unable to find class '%@'", _className]; - } - - obj = [[aClass allocWithZone: NSDefaultMallocZone()] - initWithFrame: theFrame]; - - // set the attributes for the view - [obj setBounds: [self bounds]]; - - // set the attributes for text - [obj setBackgroundColor: [self backgroundColor]]; - [obj setDrawsBackground: [self drawsBackground]]; - [obj setEditable: [self isEditable]]; - [obj setSelectable: [self isSelectable]]; - [obj setFieldEditor: [self isFieldEditor]]; - [obj setRichText: [self isRichText]]; - [obj setImportsGraphics: [self importsGraphics]]; - [obj setDelegate: [self delegate]]; - - RELEASE(self); - RETAIN(obj); - - return obj; -} - -// accessor methods -- (void) setClassName: (NSString *)name -{ - ASSIGN(_className, name); -} - -- (NSString *)className -{ - return _className; -} @end // Template for any classes which derive from NSTextView @@ -439,101 +417,24 @@ } } -- (void) dealloc +- (id)nibInstantiate { - RELEASE(_parentClassName); - RELEASE(_className); - [super dealloc]; -} - -- initWithFrame: (NSRect)frame -{ - // Start initially with the highest level class - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - [super initWithFrame: frame]; - return self; -} - -- init -{ - [super init]; - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - return self; -} - -- (id) initWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; - [aCoder decodeValueOfObjCType: @encode(id) at: &_className]; - [aCoder decodeValueOfObjCType: @encode(id) at: &_parentClassName]; - return [super initWithCoder: aCoder]; -} - -- (void) encodeWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; -} - -- (id) awakeAfterUsingCoder: (NSCoder *)coder -{ - if ([self respondsToSelector: @selector(isInInterfaceBuilder)]) + if(_realObject == nil) { - // if we live in the interface builder, give them an instance of - // the parent, not the child.. - [self setClassName: _parentClassName]; - } - return [self instantiateObject: coder]; -} - -- (id) instantiateObject: (NSCoder *)coder -{ - Class aClass = NSClassFromString(_className); - NSRect theFrame = [self frame]; - id obj = nil; - - if (aClass == nil) - { - [NSException raise: NSInternalInconsistencyException - format: @"Unable to find class '%@'", _className]; + Class aClass = NSClassFromString(_className); + if(aClass == nil) + { + [NSException raise: NSInternalInconsistencyException + format: @"Unable to find class '%@'", _className]; + } + else + { + _realObject = [[aClass allocWithZone: NSDefaultMallocZone()] initWithFrame: [self frame]]; + [[self superview] replaceSubview: self with: _realObject]; // replace the old view... + } } - obj = [[aClass allocWithZone: NSDefaultMallocZone()] - initWithFrame: theFrame]; - - // set the attributes for the view - [obj setBounds: [self bounds]]; - - // set the attributes for text - [obj setBackgroundColor: [self backgroundColor]]; - [obj setDrawsBackground: [self drawsBackground]]; - [obj setEditable: [self isEditable]]; - [obj setSelectable: [self isSelectable]]; - [obj setFieldEditor: [self isFieldEditor]]; - [obj setRichText: [self isRichText]]; - [obj setImportsGraphics: [self importsGraphics]]; - [obj setDelegate: [self delegate]]; - - // text view - [obj setRulerVisible: [self isRulerVisible]]; - [obj setInsertionPointColor: [self insertionPointColor]]; - - RELEASE(self); - RETAIN(obj); - - return obj; -} - -// accessors -- (void) setClassName: (NSString *)name -{ - ASSIGN(_className, name); -} - -- (NSString *)className -{ - return _className; + return _realObject; } @end @@ -547,196 +448,37 @@ } } -- (void) dealloc -{ - RELEASE(_parentClassName); - RELEASE(_className); - [super dealloc]; -} - -- init -{ - [super init]; - // Start initially with the highest level class - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - return self; -} - - (id) initWithCoder: (NSCoder *)aCoder { - DEPRECATION_WARNING; - [aCoder decodeValueOfObjCType: @encode(id) at: &_className]; - [aCoder decodeValueOfObjCType: @encode(id) at: &_parentClassName]; - return [super initWithCoder: aCoder]; + return nil; } - (void) encodeWithCoder: (NSCoder *)aCoder { - DEPRECATION_WARNING; } -- (id) awakeAfterUsingCoder: (NSCoder *)coder +- (id) nibInstantiate { - if ([self respondsToSelector: @selector(isInInterfaceBuilder)]) - { - // if we live in the interface builder, give them an instance of - // the parent, not the child.. - [self setClassName: _parentClassName]; - } - return [self instantiateObject: coder]; + return nil; } -- (id) instantiateObject: (NSCoder *)coder +- (void) setClassName: (NSString *)className { - Class aClass = NSClassFromString(_className); - id obj = nil; - - if (aClass == nil) - { - [NSException raise: NSInternalInconsistencyException - format: @"Unable to find class '%@'", _className]; - } - - obj = [[aClass allocWithZone: NSDefaultMallocZone()] init]; - - // copy attributes - [obj setAutoenablesItems: [self autoenablesItems]]; - [obj setTitle: [self title]]; - - RELEASE(self); - RETAIN(obj); - - return obj; -} - -// accessors -- (void) setClassName: (NSString *)name -{ - ASSIGN(_className, name); - RETAIN(_className); - + ASSIGN(_menuClass, className); } - (NSString *)className { - return _className; + return _menuClass; +} + +- (id) realObject +{ + return _realObject; } @end - -// Template for any classes which derive from NSControl -@implementation NSControlTemplate -+ (void) initialize -{ - if (self == [NSControlTemplate class]) - { - [self setVersion: 0]; - } -} - -- (void) dealloc -{ - RELEASE(_parentClassName); - RELEASE(_className); - [super dealloc]; -} - -- initWithFrame: (NSRect)frame -{ - // Start initially with the highest level class - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - [super initWithFrame: frame]; - - return self; -} - -- init -{ - // Start initially with the highest level class - [super init]; - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - return self; -} - -- (id) initWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; - [aCoder decodeValueOfObjCType: @encode(id) at: &_className]; - [aCoder decodeValueOfObjCType: @encode(id) at: &_parentClassName]; - [aCoder decodeValueOfObjCType: @encode(id) at: &_delegate]; - [aCoder decodeValueOfObjCType: @encode(id) at: &_dataSource]; - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &_usesDataSource]; - return [super initWithCoder: aCoder]; -} - -- (void) encodeWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; -} - -- (id) awakeAfterUsingCoder: (NSCoder *)coder -{ - if ([self respondsToSelector: @selector(isInInterfaceBuilder)]) - { - // if we live in the interface builder, give them an instance of - // the parent, not the child.. - [self setClassName: _parentClassName]; - } - return [self instantiateObject: coder]; -} - -- (id) instantiateObject: (NSCoder *)coder -{ - Class aClass = NSClassFromString(_className); - NSRect theFrame = [self frame]; - id obj = nil; - - if (aClass == nil) - { - [NSException raise: NSInternalInconsistencyException - format: @"Unable to find class '%@'", _className]; - } - - obj = [[aClass allocWithZone: NSDefaultMallocZone()] - initWithFrame: theFrame]; - - // set the attributes for the view - [obj setBounds: [self bounds]]; - - // set the attributes for the control - [obj setDoubleValue: [self doubleValue]]; - [obj setFloatValue: [self floatValue]]; - [obj setIntValue: [self intValue]]; - [obj setObjectValue: [self objectValue]]; - [obj setStringValue: [self stringValue]]; - [obj setTag: [self tag]]; - [obj setFont: [self font]]; - [obj setAlignment: [self alignment]]; - [obj setEnabled: [self isEnabled]]; - [obj setContinuous: [self isContinuous]]; - - // since only some controls have delegates, we need to test - if ([obj respondsToSelector: @selector(setDelegate:)]) - [obj setDelegate: _delegate]; - - // since only some controls have data sources, we need to test - if ([obj respondsToSelector: @selector(setDataSource:)]) - [obj setDataSource: _dataSource]; - - // since only some controls have data sources, we need to test - if ([obj respondsToSelector: @selector(setUsesDataSource:)]) - [obj setUsesDataSource: _usesDataSource]; - - RELEASE(self); - RETAIN(obj); - - return obj; -} - -// accessors +@implementation NSCustomObject - (void) setClassName: (NSString *)name { ASSIGN(_className, name); @@ -746,127 +488,659 @@ { return _className; } -@end -// Template for any classes which derive from NSButton -@implementation NSButtonTemplate -+ (void) initialize +- (void) setExtension: (NSString *)name { - if (self == [NSButtonTemplate class]) + ASSIGN(_extension, name); +} + +- (NSString *)extension +{ + return _extension; +} + +- (void) setObject: (id)obj +{ + ASSIGN(_object, obj); +} + +- (id) object +{ + return _object; +} + +- (id) initWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) { - [self setVersion: 0]; + ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]); + ASSIGN(_extension, [coder decodeObjectForKey: @"NSExtension"]); + } + else + { + [NSException raise: NSInternalInconsistencyException + format: @"Can't decode %@ with %@.",NSStringFromClass([self class]), + NSStringFromClass([coder class])]; + } + return self; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + [coder encodeObject: (id)_className forKey: @"NSClassName"]; + [coder encodeConditionalObject: (id)_extension forKey: @"NSExtension"]; } } -- (void) dealloc +- (id) nibInstantiate { - RELEASE(_parentClassName); - RELEASE(_className); - [super dealloc]; + if(_object == nil) + { + Class aClass = NSClassFromString(_className); + if(aClass == nil) + { + [NSException raise: NSInternalInconsistencyException + format: @"Unable to find class '%@'", _className]; + } + + _object = [[aClass allocWithZone: NSDefaultMallocZone()] init]; + } + return _object; +} +@end + +@implementation NSCustomView +- (void) setClassName: (NSString *)name +{ + ASSIGN(_className, name); } -- initWithFrame: (NSRect)frame +- (NSString *)className { - // Start initially with the highest level class - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - _buttonType = NSMomentaryLightButton; - [super initWithFrame: frame]; + return _className; +} +- (void) setExtension: (NSString *)ext; +{ + ASSIGN(_extension, ext); +} + +- (NSString *)extension +{ + return _extension; +} + +- (id)nibInstantiate +{ + if(_view == nil) + { + Class aClass = NSClassFromString(_className); + if(aClass == nil) + { + [NSException raise: NSInternalInconsistencyException + format: @"Unable to find class '%@'", _className]; + } + else + { + _view = [[aClass allocWithZone: NSDefaultMallocZone()] initWithFrame: [self frame]]; + [[self superview] replaceSubview: self with: _view]; // replace the old view... + } + } + + return _view; +} + +- (id) initWithCoder: (NSCoder *)coder +{ + self = [super initWithCoder: coder]; + if(self != nil) + { + if([coder allowsKeyedCoding]) + { + _className = [coder decodeObjectForKey: @"NSClassName"]; + } + } + return self; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + [coder encodeObject: (id)_className forKey: @"NSClassName"]; + } +} +@end + +@implementation NSCustomResource +- (void) setClassName: (NSString *)className +{ + ASSIGN(_className, className); +} + +- (NSString *)className +{ + return _className; +} + +- (void) setResourceName: (NSString *)resourceName +{ + ASSIGN(_resourceName, resourceName); +} + +- (NSString *)resourceName +{ + return _resourceName; +} + +- (id)nibInstantiate +{ + return self; +} + +- (id) initWithCoder: (NSCoder *)coder +{ + id realObject = nil; + if([coder allowsKeyedCoding]) + { + ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]); + ASSIGN(_resourceName, [coder decodeObjectForKey: @"NSResourceName"]); + + // this is a hack, but for now it should do. + if([_className isEqual: @"NSSound"]) + { + realObject = [NSSound soundNamed: _resourceName]; + } + else if([_className isEqual: @"NSImage"]) + { + realObject = [NSImage imageNamed: _resourceName]; + } + + // if an object has been substituted, then release the placeholder. + if(realObject != nil) + { + RELEASE(self); + } + } + else + { + [NSException raise: NSInternalInconsistencyException + format: @"Can't decode %@ with %@.",NSStringFromClass([self class]), + NSStringFromClass([coder class])]; + } + + return realObject; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + [coder encodeObject: (id)_className forKey: @"NSClassName"]; + [coder encodeObject: (id)_resourceName forKey: @"NSResourceName"]; + } +} +@end + +@interface NSKeyedUnarchiver (NSClassSwapperPrivate) +- (BOOL) replaceObject: (id)oldObj withObject: (id)newObj; +@end + +@implementation NSClassSwapper +- (void) setTemplate: (id)temp +{ + ASSIGN(_template, temp); +} + +- (id) template +{ + return _template; +} + +- (void) setClassName: (NSString *)className +{ + ASSIGN(_className, className); +} + +- (NSString *)className +{ + return _className; +} + ++ (BOOL) isInInterfaceBuilder +{ + return NO; +} + +- (void) instantiateRealObject: (NSCoder *)coder withClassName: (NSString *)className +{ + Class aClass = NSClassFromString(className); + id object = nil; + Class newCellClass = nil; + NSString *origCellClassName = nil; + Class origCellClass = nil; + + if(aClass == nil) + { + [NSException raise: NSInternalInconsistencyException + format: @"NSClassSwapper unable to find class '%@'", className]; + } + + // if this is a class which uses cells, override with the new cellClass, if the + // subclass responds to cellClass. + if([aClass respondsToSelector: @selector(cellClass)] && + [className isEqualToString: _originalClassName] == NO) + { + Class origClass = NSClassFromString(_originalClassName); + + origCellClass = [origClass cellClass]; + newCellClass = [aClass cellClass]; + origCellClassName = NSStringFromClass(origCellClass); + [(NSKeyedUnarchiver *)coder setClass: newCellClass forClassName: origCellClassName]; + } + + // swap the class... + object = [aClass allocWithZone: NSDefaultMallocZone()]; + [(NSKeyedUnarchiver *)coder replaceObject: self withObject: object]; + _template = [object initWithCoder: coder]; + if(object != _template) + { + [(NSKeyedUnarchiver *)coder replaceObject: object withObject: _template]; + } + + if(newCellClass != nil && origCellClass != nil) + { + [(NSKeyedUnarchiver *)coder setClass: origCellClass forClassName: nil]; + } +} + +- (id) initWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]); + ASSIGN(_originalClassName, [coder decodeObjectForKey: @"NSOriginalClassName"]); + + // build the real object... + if([NSClassSwapper isInInterfaceBuilder] == YES) + { + [self instantiateRealObject: coder withClassName: _originalClassName]; + } + else + { + [self instantiateRealObject: coder withClassName: _className]; + } + } + else + { + [NSException raise: NSInternalInconsistencyException + format: @"Can't decode %@ with %@.",NSStringFromClass([self class]), + NSStringFromClass([coder class])]; + } + + return _template; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + NSString *originalClassName = NSStringFromClass(_template); + [coder encodeObject: (id)_className forKey: @"NSClassName"]; + [coder encodeObject: (id)originalClassName forKey: @"NSOriginalClassName"]; + } +} +@end + +/* Correct some instances where the ":" is missing from the method name in the label */ +@interface NSNibControlConnector (NibCompatibility) +- (void) instantiateWithInstantiator: (id)instantiator; +@end + +@implementation NSNibControlConnector (NibCompatibility) +- (void) instantiateWithInstantiator: (id)instantiator +{ + NSRange colonRange = [_tag rangeOfString: @":"]; + unsigned int location = colonRange.location; - return self; -} - -- init -{ - // Start initially with the highest level class - [super init]; - ASSIGN(_className, NSStringFromClass([super class])); - ASSIGN(_parentClassName, NSStringFromClass([super class])); - _buttonType = NSMomentaryLightButton; - return self; -} - -- (id) initWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; - [aCoder decodeValueOfObjCType: @encode(id) at: &_className]; - [aCoder decodeValueOfObjCType: @encode(id) at: &_parentClassName]; - [aCoder decodeValueOfObjCType: @encode(int) at: &_buttonType]; - return [super initWithCoder: aCoder]; -} - -- (void) encodeWithCoder: (NSCoder *)aCoder -{ - DEPRECATION_WARNING; -} - -- (id) awakeAfterUsingCoder: (NSCoder *)coder -{ - if ([self respondsToSelector: @selector(isInInterfaceBuilder)]) + if(location == NSNotFound) { - // if we live in the interface builder, give them an instance of - // the parent, not the child.. - [self setClassName: _parentClassName]; - } - return [self instantiateObject: coder]; -} - -- (id) instantiateObject: (NSCoder *)coder -{ - Class aClass = NSClassFromString(_className); - NSRect theFrame = [self frame]; - id obj = nil; - - if (aClass == nil) - { - [NSException raise: NSInternalInconsistencyException - format: @"Unable to find class '%@'", _className]; + NSString *newTag = [NSString stringWithFormat: @"%@:",_tag]; + [self setLabel: (id)newTag]; } - obj = [[aClass allocWithZone: NSDefaultMallocZone()] - initWithFrame: theFrame]; - - // set the attributes for the view - [obj setBounds: [self bounds]]; - - // set the attributes for the control - [obj setDoubleValue: [self doubleValue]]; - [obj setFloatValue: [self floatValue]]; - [obj setIntValue: [self intValue]]; - [obj setObjectValue: [self objectValue]]; - [obj setStringValue: [self stringValue]]; - [obj setTag: [self tag]]; - [obj setFont: [self font]]; - [obj setAlignment: [self alignment]]; - [obj setEnabled: [self isEnabled]]; - [obj setContinuous: [self isContinuous]]; - - // button - [obj setButtonType: _buttonType]; - [obj setBezelStyle: [self bezelStyle]]; - [obj setBordered: [self isBordered]]; - [obj setAllowsMixedState: [self allowsMixedState]]; - [obj setTitle: [self title]]; - [obj setAlternateTitle: [self alternateTitle]]; - [obj setImage: [self image]]; - [obj setAlternateImage: [self alternateImage]]; - [obj setImagePosition: [self imagePosition]]; - [obj setKeyEquivalent: [self keyEquivalent]]; - - RELEASE(self); - RETAIN(obj); - - return obj; -} - -// accessors -- (void) setClassName: (NSString *)name -{ - ASSIGN(_className, name); -} - -- (NSString *)className -{ - return _className; + [super instantiateWithInstantiator: instantiator]; +} +@end + +@implementation NSIBObjectData +- (id)instantiateObject: (id)obj +{ + id newObject = obj; + if([obj respondsToSelector: @selector(nibInstantiate)]) + { + newObject = [obj nibInstantiate]; + if([newObject respondsToSelector: @selector(awakeFromNib)]) + { + // awaken the object. + [newObject awakeFromNib]; + } + } + return newObject; +} + +- (void) nibInstantiateWithOwner: (id)owner +{ + [self nibInstantiateWithOwner: owner topLevelObjects: nil]; +} + +- (void) nibInstantiateWithOwner: (id)owner topLevelObjects: (NSMutableArray *)topLevelObjects +{ + NSEnumerator *en = [_connections objectEnumerator]; + id obj = nil; + id menu = nil; + + // replace the owner with the actual instance provided. + [_root setObject: owner]; + + // iterate over connections, instantiate, and then establish them. + while((obj = [en nextObject]) != nil) + { + if([obj respondsToSelector: @selector(instantiateWithInstantiator:)]) + { + [obj instantiateWithInstantiator: self]; + [obj establishConnection]; + } + } + + en = [_visibleWindows objectEnumerator]; + while((obj = [en nextObject]) != nil) + { + id w = [self instantiateObject: obj]; + [w orderFront: self]; + } + + menu = [self objectForName: @"MainMenu"]; + if(menu != nil) + { + menu = [self instantiateObject: menu]; + [NSApp setMainMenu: menu]; + } +} + +- (void) awakeWithContext: (NSDictionary *)context +{ + NSMutableArray *tlo = [context objectForKey: @"NSTopLevelObjects"]; + id owner = [context objectForKey: @"NSOwner"]; + [self nibInstantiateWithOwner: owner topLevelObjects: tlo]; +} + +- (NSMutableArray *) connections +{ + return _connections; +} + +- (NSMutableSet *) topLevelObjects +{ + return nil; +} + +- (NSMutableDictionary *) nameTable +{ + return nil; +} + +- (id) objectForName: (NSString *)name +{ + NSArray *nameKeys = (NSArray *)NSAllMapTableKeys(_names); + NSArray *nameValues = (NSArray *)NSAllMapTableValues(_names); + int i = [nameValues indexOfObject: name]; + id result = nil; + + if(i != NSNotFound) + { + result = [nameKeys objectAtIndex: i]; + } + + return result; +} + +- (NSString *) nameForObject: (id)obj +{ + NSArray *nameKeys = (NSArray *)NSAllMapTableKeys(_names); + NSArray *nameValues = (NSArray *)NSAllMapTableValues(_names); + int i = [nameKeys indexOfObject: obj]; + NSString *result = [nameValues objectAtIndex: i]; + return result; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + NSArray *accessibilityOidsKeys = (NSArray *)NSAllMapTableKeys(_accessibilityOids); + NSArray *accessibilityOidsValues = (NSArray *)NSAllMapTableValues(_accessibilityOids); + NSArray *classKeys = (NSArray *)NSAllMapTableKeys(_classes); + NSArray *classValues = (NSArray *)NSAllMapTableValues(_classes); + NSArray *nameKeys = (NSArray *)NSAllMapTableKeys(_names); + NSArray *nameValues = (NSArray *)NSAllMapTableValues(_names); + NSArray *objectsKeys = (NSArray *)NSAllMapTableKeys(_objects); + NSArray *objectsValues = (NSArray *)NSAllMapTableValues(_objects); + NSArray *oidsKeys = (NSArray *)NSAllMapTableKeys(_oids); + NSArray *oidsValues = (NSArray *)NSAllMapTableValues(_oids); + + [coder encodeObject: (id)_accessibilityConnectors forKey: @"NSAccessibilityConnectors"]; + [coder encodeObject: (id) accessibilityOidsKeys forKey: @"NSAccessibilityOidsKeys"]; + [coder encodeObject: (id) accessibilityOidsValues forKey: @"NSAccessibilityOidsValues"]; + [coder encodeObject: (id) classKeys forKey: @"NSClassesKeys"]; + [coder encodeObject: (id) classValues forKey: @"NSClassesValues"]; + [coder encodeObject: (id) nameKeys forKey: @"NSNamesKeys"]; + [coder encodeObject: (id) nameValues forKey: @"NSNamesValues"]; + [coder encodeObject: (id) objectsKeys forKey: @"NSObjectsKeys"]; + [coder encodeObject: (id) objectsValues forKey: @"NSObjectsValues"]; + [coder encodeObject: (id) oidsKeys forKey: @"NSOidsKeys"]; + [coder encodeObject: (id) oidsValues forKey: @"NSOidsValues"]; + [coder encodeObject: (id) _connections forKey: @"NSConnections"]; + [coder encodeConditionalObject: (id) _fontManager forKey: @"NSFontManager"]; + [coder encodeConditionalObject: (id) _framework forKey: @"NSFramework"]; + [coder encodeObject: (id) _visibleWindows forKey: @"NSVisibleWindows"]; + [coder encodeInt: _nextOid forKey: @"NSNextOid"]; + [coder encodeConditionalObject: (id) _root forKey: @"NSRoot"]; + } +} + +- (void) _buildMap: (NSMapTable *)mapTable + withKeys: (NSArray *)keys + andValues: (NSArray *)values +{ + NSEnumerator *ken = [keys objectEnumerator]; + NSEnumerator *ven = [values objectEnumerator]; + id key = nil; + id value = nil; + + while((key = [ken nextObject]) != nil && (value = [ven nextObject]) != nil) + { + NSMapInsert(mapTable, key, value); + } +} + +- (id) initWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + ASSIGN(_root, [coder decodeObjectForKey: @"NSRoot"]); + ASSIGN(_visibleWindows, (NSMutableArray *)[coder decodeObjectForKey: @"NSVisibleWindows"]); + ASSIGN(_accessibilityConnectors, (NSMutableArray *)[coder decodeObjectForKey: @"NSAccessibilityConnectors"]); + ASSIGN(_fontManager, [coder decodeObjectForKey: @"NSFontManager"]); + ASSIGN(_framework, [coder decodeObjectForKey: @"NSFramework"]); + ASSIGN(_connections, (NSMutableArray *)[coder decodeObjectForKey: @"NSConnections"]); + _nextOid = [coder decodeIntForKey: @"NSNextOid"]; + + { + NSArray *objectsKeys = (NSArray *) + [coder decodeObjectForKey: @"NSObjectsKeys"]; + NSArray *objectsValues = (NSArray *) + [coder decodeObjectForKey: @"NSObjectsValues"]; + NSArray *nameKeys = (NSArray *) + [coder decodeObjectForKey: @"NSNamesKeys"]; + NSArray *nameValues = (NSArray *) + [coder decodeObjectForKey: @"NSNamesValues"]; + NSArray *oidsKeys = (NSArray *) + [coder decodeObjectForKey: @"NSOidsKeys"]; + NSArray *oidsValues = (NSArray *) + [coder decodeObjectForKey: @"NSOidsValues"]; + NSArray *classKeys = (NSArray *) + [coder decodeObjectForKey: @"NSClassesKeys"]; + NSArray *classValues = (NSArray *) + [coder decodeObjectForKey: @"NSClassesValues"]; + NSArray *accessibilityOidsKeys = (NSArray *) + [coder decodeObjectForKey: @"NSAccessibilityOidsKeys"]; + NSArray *accessibilityOidsValues = (NSArray *) + [coder decodeObjectForKey: @"NSAccessibilityOidsValues"]; + + // instantiate the maps.. + _objects = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + _names = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + _oids = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + _classes = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + _accessibilityOids = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + + // fill in the maps... + [self _buildMap: _accessibilityOids withKeys: accessibilityOidsKeys andValues: accessibilityOidsValues]; + [self _buildMap: _classes withKeys: classKeys andValues: classValues]; + [self _buildMap: _names withKeys: nameKeys andValues: nameValues]; + [self _buildMap: _objects withKeys: objectsKeys andValues: objectsValues]; + [self _buildMap: _oids withKeys: oidsKeys andValues: oidsValues]; + } + } + else + { + [NSException raise: NSInternalInconsistencyException + format: @"Can't decode %@ with %@.",NSStringFromClass([self class]), + NSStringFromClass([coder class])]; + } + + return self; +} + +- (id) init +{ + if((self = [super init]) != nil) + { + // instantiate the maps.. + _objects = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + _names = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + _oids = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + _classes = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + _accessibilityOids = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, 2); + + // initialize the objects... + _accessibilityConnectors = [[NSMutableArray alloc] init]; + _connections = [[NSMutableArray alloc] init]; + _visibleWindows = [[NSMutableArray alloc] init]; + _framework = nil; + _fontManager = nil; + _root = nil; + _nextOid = 0; + } + return self; +} + +- (void) dealloc +{ + // free the maps. + NSFreeMapTable(_objects); + NSFreeMapTable(_names); + NSFreeMapTable(_oids); + NSFreeMapTable(_classes); + NSFreeMapTable(_accessibilityOids); + + // free other objects. + RELEASE(_accessibilityConnectors); + RELEASE(_connections); + RELEASE(_fontManager); + RELEASE(_framework); + RELEASE(_visibleWindows); + RELEASE(_root); + [super dealloc]; +} + +- (void) setRoot: (id) root +{ + ASSIGN(_root, root); +} + +- (id) root +{ + return _root; +} +@end + +@interface NSButtonImageSource : NSObject +{ + NSString *imageName; +} +- (NSString *)imageName; +@end + +@implementation NSButtonImageSource +- (id) initWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + ASSIGN(imageName, [coder decodeObjectForKey: @"NSImageName"]); + } + RELEASE(self); + return [NSImage imageNamed: imageName]; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + [coder encodeObject: imageName forKey: @"NSImageName"]; + } +} + +- (NSString *)imageName +{ + return imageName; +} + +- (void) dealloc +{ + RELEASE(imageName); + [super dealloc]; +} +@end + +// ...dummy/placeholder classes... +// overridden in NSTableView to be GSTableCornerView, +// but the class needs to be present to be overridden. +@interface _NSCornerView : NSView +@end + +@implementation _NSCornerView +@end + +@interface NSKeyedUnarchiver (GSNibCompatibilityAdditions) +- (NSDictionary *)keyMap; +@end + +@implementation NSKeyedUnarchiver (GSNibCompatibilityAdditions) +- (NSDictionary *)keyMap +{ + return _keyMap; } @end diff --git a/Source/GSNibLoader.m b/Source/GSNibLoader.m new file mode 100644 index 000000000..03303df3a --- /dev/null +++ b/Source/GSNibLoader.m @@ -0,0 +1,145 @@ +/** GSNibLoader + + Nib (Cocoa XML) model loader + + Copyright (C) 1997, 1999 Free Software Foundation, Inc. + + Author: Gregory John Casamento + Date: 2005 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; + If not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include "GNUstepGUI/GSModelLoaderFactory.h" +#include "GNUstepGUI/GSNibCompatibility.h" + +@interface GSNibLoader : GSModelLoader +@end + +@implementation GSNibLoader ++ (void) initialize +{ + // should do something... +} + ++ (NSString *)type +{ + return @"nib"; +} + ++ (float) priority +{ + return 3.0; +} + +- (BOOL) loadModelData: (NSData *)data + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone; +{ + BOOL loaded = NO; + NSUnarchiver *unarchiver = nil; + + NS_DURING + { + if (data != nil) + { + unarchiver = [[NSKeyedUnarchiver alloc] + initForReadingWithData: data]; + if (unarchiver != nil) + { + id obj; + + NSDebugLog(@"Invoking unarchiver"); + [unarchiver setObjectZone: zone]; + obj = [unarchiver decodeObjectForKey: @"IB.objectdata"]; + if (obj != nil) + { + if ([obj isKindOfClass: [NSIBObjectData class]]) + { + NSDebugLog(@"Calling awakeWithContext"); + [obj awakeWithContext: context]; + loaded = YES; + } + else + { + NSLog(@"Nib without container object!"); + } + } + RELEASE(unarchiver); + } + } + } + NS_HANDLER + { + NSLog(@"Exception occured while loading model: %@",[localException reason]); + TEST_RELEASE(unarchiver); + } + NS_ENDHANDLER + + if (loaded == NO) + { + NSLog(@"Failed to load Nib\n"); + } + + return loaded; +} + +- (BOOL) loadModelFile: (NSString *)fileName + externalNameTable: (NSDictionary *)context + withZone: (NSZone *)zone; +{ + NSFileManager *mgr = [NSFileManager defaultManager]; + BOOL isDir = NO; + BOOL loaded = NO; + + NSDebugLog(@"Loading Nib `%@'...\n", fileName); + + if ([mgr fileExistsAtPath: fileName isDirectory: &isDir]) + { + NSData *data = nil; + + // if the data is in a directory, then load from keyedobjects.nib in the directory + if (isDir == NO) + { + data = [NSData dataWithContentsOfFile: fileName]; + NSDebugLog(@"Loaded data from file..."); + } + else + { + NSString *newFileName = [fileName stringByAppendingPathComponent: @"keyedobjects.nib"]; + data = [NSData dataWithContentsOfFile: newFileName]; + NSDebugLog(@"Loaded data from %@...",newFileName); + } + + loaded = [self loadModelData: data + externalNameTable: context + withZone: zone]; + + // report a problem if there is one. + if(loaded == NO) + { + NSLog(@"Could not load Gorm file: %@",fileName); + } + } + + return loaded; +} +@end diff --git a/Source/NSActionCell.m b/Source/NSActionCell.m index 5835dd334..fbda7d979 100644 --- a/Source/NSActionCell.m +++ b/Source/NSActionCell.m @@ -302,6 +302,15 @@ static Class controlClass; { [self setTag: [aDecoder decodeIntForKey: @"NSTag"]]; } + if ([aDecoder containsValueForKey: @"NSTarget"]) + { + [self setTarget: [aDecoder decodeObjectForKey: @"NSTarget"]]; + } + if ([aDecoder containsValueForKey: @"NSAction"]) + { + NSString *action = [aDecoder decodeObjectForKey: @"NSAction"]; + [self setAction: NSSelectorFromString(action)]; + } } else { diff --git a/Source/NSBundleAdditions.m b/Source/NSBundleAdditions.m index ebe91fd3d..5a43b9745 100644 --- a/Source/NSBundleAdditions.m +++ b/Source/NSBundleAdditions.m @@ -8,6 +8,8 @@ Date: 1997 Author: Richard Frith-Macdonald Date: 1999 + Author: Gregory John Casamento + Date: 2000 This file is part of the GNUstep GUI Library. @@ -45,10 +47,11 @@ #include #include #include +#include #include "AppKit/NSNibConnector.h" #include "AppKit/NSNibLoading.h" -#include "GNUstepGUI/GSNibTemplates.h" -#include "GNUstepGUI/IMLoading.h" +#include "GNUstepGUI/GSInstantiator.h" +#include "GNUstepGUI/GSModelLoaderFactory.h" @implementation NSNibConnector @@ -67,9 +70,18 @@ - (void) encodeWithCoder: (NSCoder*)aCoder { - [aCoder encodeObject: _src]; - [aCoder encodeObject: _dst]; - [aCoder encodeObject: _tag]; + if ([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: _src forKey: @"NSSource"]; + [aCoder encodeObject: _dst forKey: @"NSDestination"]; + [aCoder encodeObject: _tag forKey: @"NSLabel"]; + } + else + { + [aCoder encodeObject: _src]; + [aCoder encodeObject: _dst]; + [aCoder encodeObject: _tag]; + } } - (void) establishConnection @@ -80,8 +92,8 @@ { if ([aDecoder allowsKeyedCoding]) { - ASSIGN(_src, [aDecoder decodeObjectForKey: @"NSSource"]); ASSIGN(_dst, [aDecoder decodeObjectForKey: @"NSDestination"]); + ASSIGN(_src, [aDecoder decodeObjectForKey: @"NSSource"]); ASSIGN(_tag, [aDecoder decodeObjectForKey: @"NSLabel"]); } else @@ -144,6 +156,12 @@ return desc; } +- (void) instantiateWithInstantiator: (id)instantiator +{ + _src = [instantiator instantiateObject: _src]; + _dst = [instantiator instantiateObject: _dst]; +} + @end @implementation NSNibControlConnector @@ -196,139 +214,14 @@ @end @implementation NSBundle (NSBundleAdditions) - -static -Class gmodel_class(void) -{ - static Class gmclass = Nil; - - if (gmclass == Nil) - { - NSBundle *theBundle; - NSEnumerator *benum; - NSString *path; - - /* Find the bundle */ - benum = [NSStandardLibraryPaths() objectEnumerator]; - while ((path = [benum nextObject])) - { - path = [path stringByAppendingPathComponent: @"Bundles"]; - path = [path stringByAppendingPathComponent: @"libgmodel.bundle"]; - if ([[NSFileManager defaultManager] fileExistsAtPath: path]) - break; - path = nil; - } - NSCAssert(path != nil, @"Unable to load gmodel bundle"); - NSDebugLog(@"Loading gmodel from %@", path); - - theBundle = [NSBundle bundleWithPath: path]; - NSCAssert(theBundle != nil, @"Can't init gmodel bundle"); - gmclass = [theBundle classNamed: @"GMModel"]; - NSCAssert(gmclass, @"Can't load gmodel bundle"); - } - return gmclass; -} - + (BOOL) loadNibFile: (NSString*)fileName externalNameTable: (NSDictionary*)context withZone: (NSZone*)zone { - BOOL loaded = NO; - NSUnarchiver *unarchiver = nil; - NSString *ext = [fileName pathExtension]; - - if ([ext isEqual: @"nib"]) - { - NSFileManager *mgr = [NSFileManager defaultManager]; - NSString *base = [fileName stringByDeletingPathExtension]; - - /* We can't read nibs, look for an equivalent gorm or gmodel file */ - fileName = [base stringByAppendingPathExtension: @"gorm"]; - if ([mgr isReadableFileAtPath: fileName]) - { - ext = @"gorm"; - } - else - { - fileName = [base stringByAppendingPathExtension: @"gmodel"]; - ext = @"gmodel"; - } - } - - /* - * If the file to be read is a gmodel, use the GMModel method to - * read it in and skip the dearchiving below. - */ - if ([ext isEqualToString: @"gmodel"]) - { - return [gmodel_class() loadIMFile: fileName - owner: [context objectForKey: @"NSOwner"]]; - } - - NSDebugLog(@"Loading Nib `%@'...\n", fileName); - NS_DURING - { - NSFileManager *mgr = [NSFileManager defaultManager]; - BOOL isDir = NO; - - if ([mgr fileExistsAtPath: fileName isDirectory: &isDir]) - { - NSData *data = nil; - - // if the data is in a directory, then load from objects.gorm in the directory - if (isDir == NO) - { - data = [NSData dataWithContentsOfFile: fileName]; - NSDebugLog(@"Loaded data from file..."); - } - else - { - NSString *newFileName = [fileName stringByAppendingPathComponent: @"objects.gorm"]; - data = [NSData dataWithContentsOfFile: newFileName]; - NSDebugLog(@"Loaded data from %@...",newFileName); - } - - if (data != nil) - { - unarchiver = [[NSUnarchiver alloc] initForReadingWithData: data]; - if (unarchiver != nil) - { - id obj; - - NSDebugLog(@"Invoking unarchiver"); - [unarchiver setObjectZone: zone]; - obj = [unarchiver decodeObject]; - if (obj != nil) - { - if ([obj isKindOfClass: [GSNibContainer class]]) - { - NSDebugLog(@"Calling awakeWithContext"); - [obj awakeWithContext: context]; - loaded = YES; - } - else - { - NSLog(@"Nib '%@' without container object!", fileName); - } - } - // RELEASE(nibitems); - RELEASE(unarchiver); - } - } - } - } - NS_HANDLER - { - NSLog(@"Exception occured while loading model: %@",[localException reason]); - // TEST_RELEASE(nibitems); - TEST_RELEASE(unarchiver); - } - NS_ENDHANDLER - - if (loaded == NO) - { - NSLog(@"Failed to load Nib\n"); - } + GSModelLoader *loader = [GSModelLoaderFactory modelLoaderForFileName: fileName]; + BOOL loaded = [loader loadModelFile: fileName + externalNameTable: context + withZone: zone]; return loaded; } @@ -374,21 +267,12 @@ Class gmodel_class(void) - (NSString *) pathForNibResource: (NSString *)fileName { - NSFileManager *mgr = [NSFileManager defaultManager]; NSMutableArray *array = [NSMutableArray arrayWithCapacity: 8]; NSArray *languages = [NSUserDefaults userLanguages]; NSString *rootPath = [self bundlePath]; NSString *primary; NSString *language; NSEnumerator *enumerator; - NSString *ext; - - ext = [fileName pathExtension]; - fileName = [fileName stringByDeletingPathExtension]; - if ([ext isEqualToString: @"nib"] == YES) - { - ext = @""; - } /* * Build an array of resource paths that differs from the normal order - @@ -418,32 +302,13 @@ Class gmodel_class(void) enumerator = [array objectEnumerator]; while ((rootPath = [enumerator nextObject]) != nil) { - NSString *path; - - rootPath = [rootPath stringByAppendingPathComponent: fileName]; - // If the file does not have an extension, then we need to - // figure out what type of model file to load. - if ([ext isEqualToString: @""] == YES) + NSString *modelPath = [rootPath stringByAppendingPathComponent: fileName]; + NSString *path = [GSModelLoaderFactory supportedModelFileAtPath: modelPath]; + + if(path != nil) { - path = [rootPath stringByAppendingPathExtension: @"gorm"]; - if ([mgr isReadableFileAtPath: path] == NO) - { - path = [rootPath stringByAppendingPathExtension: @"gmodel"]; - if ([mgr isReadableFileAtPath: path] == NO) - { - continue; - } - } return path; } - else - { - path = [rootPath stringByAppendingPathExtension: ext]; - if ([mgr isReadableFileAtPath: path]) - { - return path; - } - } } return nil; diff --git a/Source/NSButtonCell.m b/Source/NSButtonCell.m index b0fbb3f47..a0fdb9f51 100644 --- a/Source/NSButtonCell.m +++ b/Source/NSButtonCell.m @@ -55,6 +55,54 @@ #include +typedef struct _GSButtonCellFlags +{ +#ifdef WORDS_BIGENDIAN + unsigned int isPushin:1; + unsigned int changeContents:1; + unsigned int changeBackground:1; + unsigned int changeGray:1; + unsigned int highlightByContents:1; + unsigned int highlightByBackground:1; + unsigned int highlightByGray:1; + unsigned int drawing:1; + unsigned int isBordered:1; + unsigned int imageDoesOverlap:1; + unsigned int isHorizontal:1; + unsigned int isBottomOrLeft:1; + unsigned int isImageAndText:1; + unsigned int isImageSizeDiff:1; + unsigned int hasKeyEquiv:1; + unsigned int lastState:1; + unsigned int isTransparent:1; + unsigned int inset:2 + unsigned int unused2:4; // doesn't dim:1 gradient:3 + unsigned int useButtonImageSource:1; + unsigned int unused3:8; // alt mnemonic loc. +#else + unsigned int unused3:8; // alt mnemonic loc. + unsigned int useButtonImageSource:1; + unsigned int unused0:6; // inset:2 doesn't dim:1 gradient:3 + unsigned int isTransparent:1; + unsigned int lastState:1; + unsigned int hasKeyEquiv:1; + unsigned int isImageSizeDiff:1; + unsigned int isImageAndText:1; + unsigned int isBottomOrLeft:1; + unsigned int isHorizontal:1; + unsigned int imageDoesOverlap:1; + unsigned int isBordered:1; + unsigned int drawing:1; + unsigned int highlightByGray:1; + unsigned int highlightByBackground:1; + unsigned int highlightByContents:1; + unsigned int changeGray:1; + unsigned int changeBackground:1; + unsigned int changeContents:1; + unsigned int isPushin:1; +#endif +} GSButtonCellFlags; + @interface NSButtonCell (Private) // Overriden private internal method - (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect @@ -1394,8 +1442,9 @@ */ - (void) encodeWithCoder: (NSCoder*)aCoder { - // FIXME: Add new ivars BOOL tmp; + + // FIXME: Add new ivars [super encodeWithCoder: aCoder]; [aCoder encodeObject: _keyEquivalent]; @@ -1420,10 +1469,10 @@ if ([aDecoder allowsKeyedCoding]) { - //NSControl *control = [aDecoder decodeObjectForKey: @"NSControlView"]; int delay = 0; - int interval = 0; - + int interval = 0; + // NSControl *control = [aDecoder decodeObjectForKey: @"NSControlView"]; + if ([aDecoder containsValueForKey: @"NSKeyEquivalent"]) { [self setKeyEquivalent: [aDecoder decodeObjectForKey: @"NSKeyEquivalent"]]; @@ -1432,52 +1481,38 @@ { [self setImage: [aDecoder decodeObjectForKey: @"NSNormalImage"]]; } - if ([aDecoder containsValueForKey: @"NSAlternateImage"]) - { - id image; - - image = [aDecoder decodeObjectForKey: @"NSAlternateImage"]; - // This test works around an Apple bug, where a font gets encoded here. - if ([image isKindOfClass: [NSImage class]]) - { - [self setAlternateImage: image]; - } - } if ([aDecoder containsValueForKey: @"NSAlternateContents"]) { [self setAlternateTitle: [aDecoder decodeObjectForKey: @"NSAlternateContents"]]; } if ([aDecoder containsValueForKey: @"NSButtonFlags"]) { - int bFlags; + unsigned int bFlags = [aDecoder decodeIntForKey: @"NSButtonFlags"]; int highlights = 0; int show_state = NSNoCellMask; + GSButtonCellFlags buttonCellFlags; + memcpy((void *)&buttonCellFlags,(void *)&bFlags,sizeof(struct _GSButtonCellFlags)); - bFlags = [aDecoder decodeIntForKey: @"NSButtonFlags"]; - - [self setTransparent: (bFlags & 0x8000)]; - // FIXME - if ((bFlags & 0x800000) == 0x800000) - { - [self setBordered: YES]; - } - if ((bFlags & 0x6000000) == 0x6000000) + [self setTransparent: buttonCellFlags.isTransparent]; + [self setBordered: buttonCellFlags.isBordered]; + + if (buttonCellFlags.highlightByBackground) { highlights |= NSChangeBackgroundCellMask; } - if ((bFlags & 0x8000000) == 0x8000000) + if (buttonCellFlags.highlightByContents) { highlights |= NSContentsCellMask; } - if ((bFlags & 0x30000000) == 0x30000000) + if (buttonCellFlags.changeBackground) { show_state |= NSChangeBackgroundCellMask; } - if ((bFlags & 0x40000000) == 0x40000000) + if (buttonCellFlags.changeContents) { show_state |= NSContentsCellMask; } - if ((bFlags & 0x80000000) == 0x80000000) + if (buttonCellFlags.isPushin) { highlights |= NSPushInCellMask; } @@ -1528,6 +1563,40 @@ break; } } + if ([aDecoder containsValueForKey: @"NSAlternateImage"]) + { + id image; + + // + // NOTE: Okay... this is a humongous kludge. It seems as though + // Cocoa is doing something very odd here. It doesn't seem to + // encode system images for buttons normally, if it is using + // images at all. Until I figure out what, this will stay. + // Danger, Will Robinson! :) + // + image = [aDecoder decodeObjectForKey: @"NSAlternateImage"]; + if ([image isKindOfClass: [NSImage class]]) + { + if([NSImage imageNamed: @"NSSwitch"] == image) + { + image = [NSImage imageNamed: @"NSHighlightedSwitch"]; + if([self image] == nil) + { + [self setImage: [NSImage imageNamed: @"NSSwitch"]]; + } + } + else if([NSImage imageNamed: @"NSRadioButton"] == image) + { + image = [NSImage imageNamed: @"NSHighlightedRadioButton"]; + if([self image] == nil) + { + [self setImage: [NSImage imageNamed: @"NSRadioButton"]]; + } + } + + [self setAlternateImage: image]; + } + } if ([aDecoder containsValueForKey: @"NSPeriodicDelay"]) { delay = [aDecoder decodeIntForKey: @"NSPeriodicDelay"]; diff --git a/Source/NSCell.m b/Source/NSCell.m index 478b63fda..c89da015d 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -2256,13 +2256,12 @@ static NSColor *shadowCol; if ([aDecoder containsValueForKey: @"NSCellFlags"]) { - int cFlags; + unsigned long cFlags; cFlags = [aDecoder decodeIntForKey: @"NSCellFlags"]; // This bit flag is the other way around! [self setWraps: ((cFlags & 0x40) != 0x40)]; - [self setContinuous: ((cFlags & 0x80000) == 0x80000)]; [self setScrollable: ((cFlags & 0x100000) == 0x100000)]; // Strange that this is not a simple bit flag [self setSelectable: ((cFlags & 0x200001) == 0x200001)]; @@ -2272,12 +2271,13 @@ static NSColor *shadowCol; { [self setType: NSTextCellType]; } + + [self setContinuous: ((cFlags & 0x40000) == 0x40000)]; [self setEditable: ((cFlags & 0x10000000) == 0x10000000)]; // This bit flag is the other way around! [self setEnabled: ((cFlags & 0x20000000) != 0x20000000)]; [self setHighlighted: ((cFlags & 0x40000000) == 0x40000000)]; - // FIXME - + [self setState: ((cFlags & 0x80000000) == 0x80000000)?NSOnState:NSOffState]; } if ([aDecoder containsValueForKey: @"NSCellFlags2"]) { @@ -2306,7 +2306,6 @@ static NSColor *shadowCol; [self setImportsGraphics: ((cFlags2 & 0x20000000) == 0x20000000)]; [self setAllowsEditingTextAttributes: ((cFlags2 & 0x40000000) == 0x40000000)]; - // FIXME } if ([aDecoder containsValueForKey: @"NSSupport"]) { diff --git a/Source/NSClipView.m b/Source/NSClipView.m index 8a5809fdc..0a92c1a16 100644 --- a/Source/NSClipView.m +++ b/Source/NSClipView.m @@ -753,29 +753,54 @@ static inline NSRect integralRect (NSRect rect, NSView *view) - (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; + if([aCoder allowsKeyedCoding]) + { + unsigned int flags = 0; + [aCoder encodeObject: [self backgroundColor] forKey: @"NSBGColor"]; + [aCoder encodeObject: [self documentCursor] forKey: @"NSCursor"]; + [aCoder encodeObject: [self documentView] forKey: @"NSDocView"]; + + if([self drawsBackground]) + flags |= 4; + if([self copiesOnScroll] == NO) + flags |= 2; - [aCoder encodeObject: _backgroundColor]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_copiesOnScroll]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_drawsBackground]; - [aCoder encodeObject: _cursor]; + [aCoder encodeInt: flags forKey: @"NScvFlags"]; + } + else + { + [aCoder encodeObject: _backgroundColor]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_copiesOnScroll]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_drawsBackground]; + [aCoder encodeObject: _cursor]; + } } - (id) initWithCoder: (NSCoder*)aDecoder { self = [super initWithCoder: aDecoder]; - if ([aDecoder allowsKeyedCoding]) { - int flags; - + [self setAutoresizesSubviews: YES]; + [self setBackgroundColor: [aDecoder decodeObjectForKey: @"NSBGColor"]]; [self setDocumentCursor: [aDecoder decodeObjectForKey: @"NSCursor"]]; - [self setDocumentView: [aDecoder decodeObjectForKey: @"NSDocView"]]; if ([aDecoder containsValueForKey: @"NScvFlags"]) { - flags = [aDecoder decodeIntForKey: @"NScvFlags"]; - // FIXME setCopiesOnScroll: setDrawsBackground: + int flags = [aDecoder decodeIntForKey: @"NScvFlags"]; + BOOL drawsBackground = ((4 & flags) > 0); + BOOL noCopyOnScroll = ((2 & flags) > 0); // ??? Not sure... + + [self setCopiesOnScroll: (noCopyOnScroll == NO)]; + [self setDrawsBackground: drawsBackground]; + } + + if ([[self subviews] count] > 0) + { + id document = [aDecoder decodeObjectForKey: @"NSDocView"]; + [self removeSubview: document]; + [self setDocumentView: document]; } } else diff --git a/Source/NSColorWell.m b/Source/NSColorWell.m index 22b7bf28f..8f2c4e109 100644 --- a/Source/NSColorWell.m +++ b/Source/NSColorWell.m @@ -235,11 +235,22 @@ static NSString *GSColorWellDidBecomeExclusiveNotification = - (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; - [aCoder encodeObject: _the_color]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_active]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_bordered]; - [aCoder encodeConditionalObject: _target]; - [aCoder encodeValueOfObjCType: @encode(SEL) at: &_action]; + if([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: _the_color forKey: @"NSColor"]; + // [aCoder encodeBool: _is_active forKey: @"NSEnabled"]; + [aCoder encodeBool: _is_bordered forKey: @"NSIsBordered"]; + [aCoder encodeConditionalObject: _target forKey: @"NSTarget"]; + [aCoder encodeConditionalObject: NSStringFromSelector(_action) forKey: @"NSAction"]; + } + else + { + [aCoder encodeObject: _the_color]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_active]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_bordered]; + [aCoder encodeConditionalObject: _target]; + [aCoder encodeValueOfObjCType: @encode(SEL) at: &_action]; + } } - (id) initWithCoder: (NSCoder*)aDecoder @@ -247,15 +258,31 @@ static NSString *GSColorWellDidBecomeExclusiveNotification = self = [super initWithCoder: aDecoder]; if (self != nil) { - [aDecoder decodeValueOfObjCType: @encode(id) at: &_the_color]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_active]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_bordered]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_target]; - // Undo RETAIN by decoder - TEST_RELEASE(_target); - [aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action]; - [self registerForDraggedTypes: - [NSArray arrayWithObjects: NSColorPboardType, nil]]; + if([aDecoder allowsKeyedCoding]) + { + NSString *action; + + ASSIGN(_the_color, [aDecoder decodeObjectForKey: @"NSColor"]); + // _is_active = [aDecoder decodeBoolForKey: @"NSEnabled"]; + _is_bordered = [aDecoder decodeBoolForKey: @"NSIsBordered"]; + _target = [aDecoder decodeObjectForKey: @"NSTarget"]; + action = [aDecoder decodeObjectForKey: @"NSAction"]; + _action = NSSelectorFromString(action); + [self registerForDraggedTypes: + [NSArray arrayWithObjects: NSColorPboardType, nil]]; + } + else + { + [aDecoder decodeValueOfObjCType: @encode(id) at: &_the_color]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_active]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_bordered]; + [aDecoder decodeValueOfObjCType: @encode(id) at: &_target]; + // Undo RETAIN by decoder + TEST_RELEASE(_target); + [aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action]; + [self registerForDraggedTypes: + [NSArray arrayWithObjects: NSColorPboardType, nil]]; + } } return self; } diff --git a/Source/NSLayoutManager.m b/Source/NSLayoutManager.m index 0cbaed070..61b88fda1 100644 --- a/Source/NSLayoutManager.m +++ b/Source/NSLayoutManager.m @@ -2183,7 +2183,9 @@ no_soft_invalidation: if ([aDecoder containsValueForKey: @"NSLMFlags"]) { flags = [aDecoder decodeIntForKey: @"NSLMFlags"]; - // FIXME + // nothing really to do with these flags.... + // they are runtime flags which, even if set into the archive + // they are ignored... } [self setDelegate: delegate]; [storage addLayoutManager: self]; diff --git a/Source/NSMatrix.m b/Source/NSMatrix.m index c35c82e8f..ef7257e56 100644 --- a/Source/NSMatrix.m +++ b/Source/NSMatrix.m @@ -121,6 +121,40 @@ typedef struct { int height; } MRect; +typedef struct _GSMatrixFlags { +#ifdef WORDS_BIGENDIAN + unsigned int isHighlight:1; + unsigned int isRadio:1; + unsigned int isList:1; + unsigned int allowsEmptySelection:1; + unsigned int autoScroll:1; + unsigned int selectionByRect:1; + unsigned int drawCellBackground:1; + unsigned int drawBackground:1; + unsigned int autosizesCells:1; + unsigned int drawingAncestor:1; + unsigned int tabKeyTraversesCells:1; + unsigned int tabKeyTraversesCellsExplicitly:1; + unsigned int canSearchIncrementally:1; + unsigned int unused:19; +#else + unsigned int unused:19; + unsigned int canSearchIncrementally:1; + unsigned int tabKeyTraversesCellsExplicitly:1; + unsigned int tabKeyTraversesCells:1; + unsigned int drawingAncestor:1; + unsigned int autosizesCells:1; + unsigned int drawBackground:1; + unsigned int drawCellBackground:1; + unsigned int selectionByRect:1; + unsigned int autoScroll:1; + unsigned int allowsEmptySelection:1; + unsigned int isList:1; + unsigned int isRadio:1; + unsigned int isHighlight:1; +#endif +} GSMatrixFlags; + static inline MPoint MakePoint (int x, int y) { MPoint point = { x, y }; @@ -2719,10 +2753,28 @@ static SEL getSel; } if ([aDecoder containsValueForKey: @"NSMatrixFlags"]) { - int mFlags; + int mFlags = [aDecoder decodeIntForKey: @"NSMatrixFlags"]; + GSMatrixFlags matrixFlags; + memcpy((void *)&matrixFlags,(void *)&mFlags,sizeof(struct _GSMatrixFlags)); - mFlags = [aDecoder decodeIntForKey: @"NSMatrixFlags"]; - // FIXME + if(matrixFlags.isRadio) + { + [self setMode: NSRadioModeMatrix]; + } + else if(matrixFlags.isList) + { + [self setMode: NSListModeMatrix]; + } + else if(matrixFlags.isHighlight) + { + [self setMode: NSHighlightModeMatrix]; + } + + [self setAllowsEmptySelection: matrixFlags.allowsEmptySelection]; + [self setSelectionByRect: matrixFlags.selectionByRect]; + [self setDrawsCellBackground: matrixFlags.drawCellBackground]; + [self setDrawsBackground: matrixFlags.drawBackground]; + _tabKeyTraversesCells = matrixFlags.tabKeyTraversesCells; } if ([aDecoder containsValueForKey: @"NSNumCols"]) { diff --git a/Source/NSMenuItem.m b/Source/NSMenuItem.m index 595d0adcd..6982d0739 100644 --- a/Source/NSMenuItem.m +++ b/Source/NSMenuItem.m @@ -436,22 +436,40 @@ static Class imageClass; */ - (void) encodeWithCoder: (NSCoder*)aCoder { - [aCoder encodeObject: _title]; - [aCoder encodeObject: _keyEquivalent]; - [aCoder encodeValueOfObjCType: "I" at: &_keyEquivalentModifierMask]; - [aCoder encodeValueOfObjCType: "I" at: &_mnemonicLocation]; - [aCoder encodeValueOfObjCType: "i" at: &_state]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_enabled]; - [aCoder encodeObject: _image]; - [aCoder encodeObject: _onStateImage]; - [aCoder encodeObject: _offStateImage]; - [aCoder encodeObject: _mixedStateImage]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_changesState]; - [aCoder encodeValueOfObjCType: @encode(SEL) at: &_action]; - [aCoder encodeValueOfObjCType: "i" at: &_tag]; - [aCoder encodeConditionalObject: _representedObject]; - [aCoder encodeObject: _submenu]; - [aCoder encodeConditionalObject: _target]; + if ([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: _title forKey: @"NSTitle"]; + [aCoder encodeObject: NSStringFromSelector(_action) forKey: @"NSAction"]; + [aCoder encodeObject: _keyEquivalent forKey: @"NSKeyEquiv"]; + [aCoder encodeObject: _onStateImage forKey: @"NSOnImage"]; + [aCoder encodeObject: _offStateImage forKey: @"NSOffImage"]; // ??????? + [aCoder encodeObject: _mixedStateImage forKey: @"NSMixedImage"]; + [aCoder encodeObject: _target forKey: @"NSTarget"]; + [aCoder encodeObject: _menu forKey: @"NSMenu"]; + [aCoder encodeObject: _submenu forKey: @"NSSubmenu"]; + [aCoder encodeInt: _keyEquivalentModifierMask forKey: @"NSKeyEquivModMask"]; + [aCoder encodeInt: _mnemonicLocation forKey: @"NSMnemonicLoc"]; + [aCoder encodeInt: _state forKey: @"NSState"]; + } + else + { + [aCoder encodeObject: _title]; + [aCoder encodeObject: _keyEquivalent]; + [aCoder encodeValueOfObjCType: "I" at: &_keyEquivalentModifierMask]; + [aCoder encodeValueOfObjCType: "I" at: &_mnemonicLocation]; + [aCoder encodeValueOfObjCType: "i" at: &_state]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_enabled]; + [aCoder encodeObject: _image]; + [aCoder encodeObject: _onStateImage]; + [aCoder encodeObject: _offStateImage]; + [aCoder encodeObject: _mixedStateImage]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_changesState]; + [aCoder encodeValueOfObjCType: @encode(SEL) at: &_action]; + [aCoder encodeValueOfObjCType: "i" at: &_tag]; + [aCoder encodeConditionalObject: _representedObject]; + [aCoder encodeObject: _submenu]; + [aCoder encodeConditionalObject: _target]; + } } - (id) initWithCoder: (NSCoder*)aDecoder @@ -461,10 +479,11 @@ static Class imageClass; NSString *title = [aDecoder decodeObjectForKey: @"NSTitle"]; NSString *action = [aDecoder decodeObjectForKey: @"NSAction"]; NSString *key = [aDecoder decodeObjectForKey: @"NSKeyEquiv"]; - //NSMenu *menu = [aDecoder decodeObjectForKey: @"NSMenu"]; NSImage *mixedImage = [aDecoder decodeObjectForKey: @"NSMixedImage"]; NSImage *onImage = [aDecoder decodeObjectForKey: @"NSOnImage"]; - id target = [aDecoder decodeObjectForKey: @"NSTarget"]; + id target = [aDecoder decodeObjectForKey: @"NSTarget"]; + NSMenu *menu = [aDecoder decodeObjectForKey: @"NSMenu"]; + NSMenu *submenu = [aDecoder decodeObjectForKey: @"NSSubmenu"]; self = [self initWithTitle: title action: NSSelectorFromString(action) @@ -472,10 +491,12 @@ static Class imageClass; [self setTarget: target]; [self setMixedStateImage: mixedImage]; [self setOnStateImage: onImage]; + [self setSubmenu: submenu]; if ([aDecoder containsValueForKey: @"NSKeyEquivModMask"]) { - //int keyMask = [aDecoder decodeIntForKey: @"NSKeyEquivModMask"]; + int keyMask = [aDecoder decodeIntForKey: @"NSKeyEquivModMask"]; + [self setKeyEquivalentModifierMask: keyMask]; } if ([aDecoder containsValueForKey: @"NSMnemonicLoc"]) { @@ -485,7 +506,6 @@ static Class imageClass; if ([aDecoder containsValueForKey: @"NSState"]) { int state = [aDecoder decodeIntForKey: @"NSState"]; - [self setState: state]; } } diff --git a/Source/NSNib.m b/Source/NSNib.m index 6d8346fe1..b06e571fb 100644 --- a/Source/NSNib.m +++ b/Source/NSNib.m @@ -51,57 +51,21 @@ #include #include +#include "GNUstepGUI/GSModelLoaderFactory.h" #include "GNUstepGUI/GSNibTemplates.h" #include "GNUstepGUI/IMLoading.h" @implementation NSNib -// Private methods... -+ (NSString *) _nibFilename: (NSString *)fileName -{ - NSFileManager *mgr = [NSFileManager defaultManager]; - BOOL isDir = NO; - NSString *newFileName = nil; - - // assign the filename... - ASSIGN(newFileName, fileName); - - // detect if it's a directory or not... - if ([mgr fileExistsAtPath: fileName isDirectory: &isDir]) - { - // if the data is in a directory, then load from objects.gorm in the directory - if (isDir == YES) - { - newFileName = [fileName stringByAppendingPathComponent: @"objects.gorm"]; - } - } - - return newFileName; -} - // private method to read in the data... - (void) _readNibData: (NSString *)fileName { - NSString *ext = [fileName pathExtension]; - - if ([ext isEqual: @"nib"]) - { - NSFileManager *mgr = [NSFileManager defaultManager]; - NSString *base = [fileName stringByDeletingPathExtension]; - - /* We can't read nibs, look for an equivalent gorm or gmodel file */ - fileName = [base stringByAppendingPathExtension: @"gorm"]; - if ([mgr isReadableFileAtPath: fileName]) - { - ext = @"gorm"; - } - } - - NSDebugLog(@"Loading Nib `%@'...\n", fileName); + NSDebugLog(@"Loading model `%@'...\n", fileName); NS_DURING { - NSString *newFileName = [NSNib _nibFilename: fileName]; - _nibData = [NSData dataWithContentsOfFile: newFileName]; + NSString *newFileName = [GSModelLoaderFactory supportedModelFileAtPath: fileName]; + ASSIGN(_nibData, [NSData dataWithContentsOfFile: newFileName]); + ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileName: newFileName]); NSDebugLog(@"Loaded data from %@...",newFileName); } NS_HANDLER @@ -155,6 +119,7 @@ { // load the nib data into memory... _nibData = [NSData dataWithContentsOfURL: nibFileURL]; + ASSIGN(_url, nibFileURL); } return self; } @@ -192,51 +157,9 @@ - (BOOL)instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable withZone: (NSZone *)zone { - BOOL loaded = NO; - NSUnarchiver *unarchiver = nil; - - NS_DURING - { - if (_nibData != nil) - { - unarchiver = [[NSUnarchiver alloc] initForReadingWithData: _nibData]; - if (unarchiver != nil) - { - id obj; - - [unarchiver setObjectZone: zone]; - obj = [unarchiver decodeObject]; - if (obj != nil) - { - if ([obj isKindOfClass: [GSNibContainer class]]) - { - NSDictionary *nameTable = [self _copyTable: externalNameTable]; - [obj awakeWithContext: nameTable]; - loaded = YES; - RELEASE(nameTable); - } - else - { - NSLog(@"Nib '%@' without container object!"); - } - } - RELEASE(unarchiver); - } - } - } - NS_HANDLER - { - NSLog(@"Exception occured while loading model: %@",[localException reason]); - TEST_RELEASE(unarchiver); - } - NS_ENDHANDLER - - if (loaded == NO) - { - NSLog(@"Failed to load Nib\n"); - } - - return loaded; + return [_loader loadModelData: _nibData + externalNameTable: externalNameTable + withZone: zone]; } /** @@ -277,21 +200,49 @@ { if ((self = [super init]) != nil) { - [coder decodeValueOfObjCType: @encode(id) - at: &_nibData]; + // + // NOTE: This is okay, since the only encodings which will ever be built into + // the gui library are nib and gorm. GModel only supports certain + // objects and is going to be deprecated in the future. There just so + // happens to be a one to one correspondence here. + // + if([coder allowsKeyedCoding]) + { + // Need to verify this key... + ASSIGN(_nibData, [coder decodeObjectForKey: @"NSData"]); + ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"nib"]); + } + else + { + // this is sort of a kludge... + [coder decodeValueOfObjCType: @encode(id) + at: &_nibData]; + ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"gorm"]); + } } return self; } - (void) encodeWithCoder: (NSCoder *)coder { - [coder encodeValueOfObjCType: @encode(id) - at: &_nibData]; + if([coder allowsKeyedCoding]) + { + // Need to verify this key... + [coder encodeObject: _nibData + forKey: @"NSData"]; + } + else + { + [coder encodeValueOfObjCType: @encode(id) + at: &_nibData]; + } } - (void) dealloc { RELEASE(_nibData); + RELEASE(_loader); + TEST_RELEASE(_url); [super dealloc]; } diff --git a/Source/NSOutlineView.m b/Source/NSOutlineView.m index a31a52bb4..726e8698a 100644 --- a/Source/NSOutlineView.m +++ b/Source/NSOutlineView.m @@ -756,35 +756,65 @@ static NSImage *unexpandable = nil; - (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoResizesOutlineColumn]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_indentationMarkerFollowsCell]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autosaveExpandedItems]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_indentationPerLevel]; - [aCoder encodeConditionalObject: _outlineTableColumn]; + if([aCoder allowsKeyedCoding]) + { + } + else + { + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoResizesOutlineColumn]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_indentationMarkerFollowsCell]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autosaveExpandedItems]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_indentationPerLevel]; + [aCoder encodeConditionalObject: _outlineTableColumn]; + } } - (id) initWithCoder: (NSCoder *)aDecoder { // Since we only have one version.... self = [super initWithCoder: aDecoder]; - - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autoResizesOutlineColumn]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_indentationMarkerFollowsCell]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autosaveExpandedItems]; - [aDecoder decodeValueOfObjCType: @encode(float) at: &_indentationPerLevel]; - _outlineTableColumn = [aDecoder decodeObject]; - - _itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks, - NSObjectMapValueCallBacks, - 64); - _items = [[NSMutableArray alloc] init]; - _expandedItems = [[NSMutableArray alloc] init]; - _selectedItems = [[NSMutableArray alloc] init]; - _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks, + if([aDecoder allowsKeyedCoding]) + { + _itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks, NSObjectMapValueCallBacks, - 64); + 64); + _items = [[NSMutableArray alloc] init]; + _expandedItems = [[NSMutableArray alloc] init]; + _selectedItems = [[NSMutableArray alloc] init]; + _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, + 64); + // these can't be chosen on IB. + _indentationPerLevel = 10.0; + _indentationMarkerFollowsCell = YES; + _autoResizesOutlineColumn = NO; + _autosaveExpandedItems = NO; + + // init the table column... (this can't be chosen on IB either)... + if([_tableColumns count] > 0) + { + _outlineTableColumn = [_tableColumns objectAtIndex: 0]; + } + } + else + { + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autoResizesOutlineColumn]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_indentationMarkerFollowsCell]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autosaveExpandedItems]; + [aDecoder decodeValueOfObjCType: @encode(float) at: &_indentationPerLevel]; + _outlineTableColumn = [aDecoder decodeObject]; + + _itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, + 64); + _items = [[NSMutableArray alloc] init]; + _expandedItems = [[NSMutableArray alloc] init]; + _selectedItems = [[NSMutableArray alloc] init]; + _levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, + 64); + } return self; } diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index d1b22911c..c59bc6593 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -1010,6 +1010,7 @@ static NSImage *_pbc_image[2]; } menu = [aDecoder decodeObjectForKey: @"NSMenu"]; + [self setMenu: nil]; [self setMenu: menu]; } else diff --git a/Source/NSScrollView.m b/Source/NSScrollView.m index 6520d7860..7a1b1bdf7 100644 --- a/Source/NSScrollView.m +++ b/Source/NSScrollView.m @@ -42,6 +42,27 @@ #include "AppKit/PSOperators.h" #include "GNUstepGUI/GSDrawFunctions.h" +// +// For nib compatibility, this is used to properly +// initialize the object from a OS X nib file in initWithCoder:. +// +typedef struct _scrollViewFlags +{ +#ifdef WORDS_BIGENDIAN + unsigned int __unused4:26; + unsigned int hasHScroller:1; // 16 + unsigned int hasVScroller:1; // 32 + unsigned int __unused0:2; + NSBorderType border:2; +#else + NSBorderType border:2; + unsigned int __unused0:2; + unsigned int hasVScroller:1; // 32 + unsigned int hasHScroller:1; // 16 + unsigned int __unused4:26; +#endif +} GSScrollViewFlags; + @implementation NSScrollView /* @@ -548,6 +569,15 @@ static float scrollerWidth; [_contentView scrollToPoint: point]; } +// +// This method is here purely for nib compatibility. This is the action +// connected to by NSScrollers in IB when building a scrollview. +// +- (void) _doScroller: (NSScroller *)scroller +{ + [self _doScroll: scroller]; +} + - (void) reflectScrolledClipView: (NSClipView *)aClipView { NSRect documentFrame = NSZeroRect; @@ -1188,38 +1218,44 @@ static float scrollerWidth; { [super encodeWithCoder: aCoder]; - [aCoder encodeObject: _contentView]; - [aCoder encodeValueOfObjCType: @encode(NSBorderType) at: &_borderType]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_scrollsDynamically]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_rulersVisible]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_hLineScroll]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_hPageScroll]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_vLineScroll]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_vPageScroll]; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasHorizScroller]; - if (_hasHorizScroller) - [aCoder encodeObject: _horizScroller]; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasVertScroller]; - if (_hasVertScroller) - [aCoder encodeObject: _vertScroller]; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasHorizRuler]; - if (_hasHorizRuler) - [aCoder encodeObject: _horizRuler]; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasVertRuler]; - if (_hasVertRuler) - [aCoder encodeObject: _vertRuler]; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasHeaderView]; - if (_hasHeaderView) - [aCoder encodeObject: _headerClipView]; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasCornerView]; - - /* We do not need to encode headerview, cornerview stuff */ + if([aCoder allowsKeyedCoding]) + { + } + else + { + [aCoder encodeObject: _contentView]; + [aCoder encodeValueOfObjCType: @encode(NSBorderType) at: &_borderType]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_scrollsDynamically]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_rulersVisible]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_hLineScroll]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_hPageScroll]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_vLineScroll]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_vPageScroll]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasHorizScroller]; + if (_hasHorizScroller) + [aCoder encodeObject: _horizScroller]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasVertScroller]; + if (_hasVertScroller) + [aCoder encodeObject: _vertScroller]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasHorizRuler]; + if (_hasHorizRuler) + [aCoder encodeObject: _horizRuler]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasVertRuler]; + if (_hasVertRuler) + [aCoder encodeObject: _vertRuler]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasHeaderView]; + if (_hasHeaderView) + [aCoder encodeObject: _headerClipView]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasCornerView]; + + /* We do not need to encode headerview, cornerview stuff */ + } } - (id) initWithCoder: (NSCoder*)aDecoder @@ -1228,32 +1264,71 @@ static float scrollerWidth; if ([aDecoder allowsKeyedCoding]) { - NSClipView *content = [aDecoder decodeObjectForKey: @"NSContentView"]; NSScroller *hScroller = [aDecoder decodeObjectForKey: @"NSHScroller"]; NSScroller *vScroller = [aDecoder decodeObjectForKey: @"NSVScroller"]; - + NSClipView *content = [aDecoder decodeObjectForKey: @"NSContentView"]; + + if ([aDecoder containsValueForKey: @"NSsFlags"]) + { + unsigned long flags = [aDecoder decodeIntForKey: @"NSsFlags"]; + GSScrollViewFlags scrollViewFlags; + memcpy((void *)&scrollViewFlags,(void *)&flags,sizeof(struct _scrollViewFlags)); + + _hasVertScroller = scrollViewFlags.hasVScroller; + _hasHorizScroller = scrollViewFlags.hasHScroller; + // _scrollsDynamically = (!scrollViewFlags.notDynamic); + // _rulersVisible = scrollViewFlags.rulersVisible; + // _hasHorizRuler = scrollViewFlags.hasHRuler; + // _hasVertRuler = scrollViewFlags.hasVRuler; + // [self setDrawsBackground: (!scrollViewFlags.doesNotDrawBack)]; + _borderType = scrollViewFlags.border; + } + if (content != nil) { + NSRect frame = [content frame]; + float w = [vScroller frame].size.width; + + if(_hasVertScroller) + { + // + // Slide the content view over, since on Mac OS X the scroller is on the + // right, the content view is not properly positioned since our scroller + // is on the left. + // + frame.origin.x += w; + [content setFrame: frame]; + } + + // retain the view and reset the content view... + RETAIN(content); [self setContentView: content]; + RELEASE(content); + _contentView = content; } - if (hScroller != nil) + + if (hScroller != nil && _hasHorizScroller) { [self setHorizontalScroller: hScroller]; } - if (vScroller != nil) + + if (vScroller != nil && _hasVertScroller) { [self setVerticalScroller: vScroller]; } - if ([aDecoder containsValueForKey: @"NSsFlags"]) - { - //int flags = [aDecoder decodeIntForKey: @"NSsFlags"]; - // FIXME + + if ([aDecoder containsValueForKey: @"NSHeaderClipView"]) + { + _hasHeaderView = YES; + _hasCornerView = YES; + ASSIGN(_headerClipView, [aDecoder decodeObjectForKey: @"NSHeaderClipView"]); } + + [self tile]; } else { - int version = [aDecoder versionForClassName: - @"NSScrollView"]; + int version = [aDecoder versionForClassName: @"NSScrollView"]; NSDebugLLog(@"NSScrollView", @"NSScrollView: start decoding\n"); [aDecoder decodeValueOfObjCType: @encode(id) at: &_contentView]; [aDecoder decodeValueOfObjCType: @encode(NSBorderType) at: &_borderType]; diff --git a/Source/NSScroller.m b/Source/NSScroller.m index 561ceaad0..886e02bde 100644 --- a/Source/NSScroller.m +++ b/Source/NSScroller.m @@ -181,7 +181,25 @@ static NSColor *scrollBarColor = nil; float value = 0.0; float percent = 0.0; int flags; - + + if (_frame.size.width > _frame.size.height) + { + _isHorizontal = YES; + } + else + { + _isHorizontal = NO; + } + + if (_isHorizontal) + { + _floatValue = 0.0; + } + else + { + _floatValue = 1.0; + } + if (action != nil) { [self setAction: NSSelectorFromString(action)]; @@ -201,8 +219,15 @@ static NSColor *scrollBarColor = nil; if ([aDecoder containsValueForKey: @"NSsFlags"]) { flags = [aDecoder decodeIntForKey: @"NSsFlags"]; - // FIXME + // is horiz is set above... + } + + // setup... + _hitPart = NSScrollerNoPart; + + [self drawParts]; + [self checkSpaceForParts]; } else { diff --git a/Source/NSSecureTextField.m b/Source/NSSecureTextField.m index 7a1ad050e..ba7261084 100644 --- a/Source/NSSecureTextField.m +++ b/Source/NSSecureTextField.m @@ -88,7 +88,6 @@ { return [_cell echosBullets]; } - @end /* NSSecureTextField */ @implementation NSSecureTextFieldCell @@ -133,10 +132,17 @@ return [super setUpFieldEditorAttributes: textObject]; } -- (id) initWithCoder:(NSCoder *)decoder +- (id) initWithCoder: (NSCoder *)decoder { - [super initWithCoder: decoder]; - [decoder decodeValueOfObjCType: @encode(BOOL) at: &_echosBullets]; + self = [super initWithCoder: decoder]; + if([decoder allowsKeyedCoding]) + { + // do nothing for now... + } + else + { + [decoder decodeValueOfObjCType: @encode(BOOL) at: &_echosBullets]; + } return self; } diff --git a/Source/NSSliderCell.m b/Source/NSSliderCell.m index 9a21c813d..0c56a8a1b 100644 --- a/Source/NSSliderCell.m +++ b/Source/NSSliderCell.m @@ -564,15 +564,40 @@ DEFINE_RINT_IF_MISSING - (id) initWithCoder: (NSCoder*)decoder { self = [super initWithCoder: decoder]; - [decoder decodeValuesOfObjCTypes: "fffi", - &_minValue, &_maxValue, &_altIncrementValue, &_isVertical]; - [decoder decodeValueOfObjCType: @encode(id) at: &_titleCell]; - [decoder decodeValueOfObjCType: @encode(id) at: &_knobCell]; - if ([decoder versionForClassName: @"NSSliderCell"] >= 2) + if([decoder allowsKeyedCoding]) { - [decoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsTickMarkValuesOnly]; - [decoder decodeValueOfObjCType: @encode(int) at: &_numberOfTickMarks]; - [decoder decodeValueOfObjCType: @encode(int) at: &_tickMarkPosition]; + _allowsTickMarkValuesOnly = [decoder decodeBoolForKey: @"NSAllowsTickMarkValuesOnly"]; + _numberOfTickMarks = [decoder decodeIntForKey: @"NSNumberOfTickMarks"]; + _tickMarkPosition = [decoder decodeIntForKey: @"NSTickMarkPosition"]; + _minValue = [decoder decodeFloatForKey: @"NSMinValue"]; + _maxValue = [decoder decodeFloatForKey: @"NSMaxValue"]; + _altIncrementValue = [decoder decodeFloatForKey: @"NSAltIncValue"]; + + // do these here, since the Cocoa version of the class does not save these values... + _knobCell = [NSCell new]; + _titleCell = [NSTextFieldCell new]; + [_titleCell setTextColor: [NSColor controlTextColor]]; + [_titleCell setStringValue: @""]; + [_titleCell setAlignment: NSCenterTextAlignment]; + + // if it's from a nib, make it bordered and bezeled so it's more attractive. + [self setBordered: YES]; + [self setBezeled: YES]; + + _isVertical = -1; + } + else + { + [decoder decodeValuesOfObjCTypes: "fffi", + &_minValue, &_maxValue, &_altIncrementValue, &_isVertical]; + [decoder decodeValueOfObjCType: @encode(id) at: &_titleCell]; + [decoder decodeValueOfObjCType: @encode(id) at: &_knobCell]; + if ([decoder versionForClassName: @"NSSliderCell"] >= 2) + { + [decoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsTickMarkValuesOnly]; + [decoder decodeValueOfObjCType: @encode(int) at: &_numberOfTickMarks]; + [decoder decodeValueOfObjCType: @encode(int) at: &_tickMarkPosition]; + } } return self; } @@ -580,14 +605,27 @@ DEFINE_RINT_IF_MISSING - (void) encodeWithCoder: (NSCoder*)coder { [super encodeWithCoder: coder]; - [coder encodeValuesOfObjCTypes: "fffi", - &_minValue, &_maxValue, &_altIncrementValue, &_isVertical]; - [coder encodeValueOfObjCType: @encode(id) at: &_titleCell]; - [coder encodeValueOfObjCType: @encode(id) at: &_knobCell]; - // New for version 2 - [coder encodeValueOfObjCType: @encode(BOOL) at: &_allowsTickMarkValuesOnly]; - [coder encodeValueOfObjCType: @encode(int) at: &_numberOfTickMarks]; - [coder encodeValueOfObjCType: @encode(int) at: &_tickMarkPosition]; + if([coder allowsKeyedCoding]) + { + [coder encodeBool: _allowsTickMarkValuesOnly forKey: @"NSAllowsTickMarkValuesOnly"]; + [coder encodeInt: _numberOfTickMarks forKey: @"NSNumberOfTickMarks"]; + [coder encodeInt: _tickMarkPosition forKey: @"NSTickMarkPosition"]; + [coder encodeFloat: _minValue forKey: @"NSMinValue"]; + [coder encodeFloat: _maxValue forKey: @"NSMaxValue"]; + [coder encodeFloat: _altIncrementValue forKey: @"NSAltIncValue"]; + [coder encodeFloat: _minValue forKey: @"NSValue"]; // encoded for compatibility + } + else + { + [coder encodeValuesOfObjCTypes: "fffi", + &_minValue, &_maxValue, &_altIncrementValue, &_isVertical]; + [coder encodeValueOfObjCType: @encode(id) at: &_titleCell]; + [coder encodeValueOfObjCType: @encode(id) at: &_knobCell]; + // New for version 2 + [coder encodeValueOfObjCType: @encode(BOOL) at: &_allowsTickMarkValuesOnly]; + [coder encodeValueOfObjCType: @encode(int) at: &_numberOfTickMarks]; + [coder encodeValueOfObjCType: @encode(int) at: &_tickMarkPosition]; + } } - + @end diff --git a/Source/NSStepperCell.m b/Source/NSStepperCell.m index 950d0d863..261cf4cbf 100644 --- a/Source/NSStepperCell.m +++ b/Source/NSStepperCell.m @@ -333,19 +333,33 @@ static inline void HighlightDownButton(NSRect aRect) int tmp1, tmp2; [super initWithCoder: aDecoder]; - [aDecoder decodeValueOfObjCType: @encode(double) - at: &_maxValue]; - [aDecoder decodeValueOfObjCType: @encode(double) - at: &_minValue]; - [aDecoder decodeValueOfObjCType: @encode(double) - at: &_increment]; - [aDecoder decodeValueOfObjCType: @encode(int) - at: &tmp1]; - [aDecoder decodeValueOfObjCType: @encode(int) - at: &tmp2]; + if([aDecoder allowsKeyedCoding]) + { + _autorepeat = [aDecoder decodeBoolForKey: @"NSAutorepeat"]; + _valueWraps = [aDecoder decodeBoolForKey: @"NSValueWraps"]; + _increment = [aDecoder decodeIntForKey: @"NSIncrement"]; + _maxValue = [aDecoder decodeIntForKey: @"NSMaxValue"]; + if([aDecoder containsValueForKey: @"NSMinValue"]) + { + _minValue = [aDecoder decodeIntForKey: @"NSMinValue"]; + } + } + else + { + [aDecoder decodeValueOfObjCType: @encode(double) + at: &_maxValue]; + [aDecoder decodeValueOfObjCType: @encode(double) + at: &_minValue]; + [aDecoder decodeValueOfObjCType: @encode(double) + at: &_increment]; + [aDecoder decodeValueOfObjCType: @encode(int) + at: &tmp1]; + [aDecoder decodeValueOfObjCType: @encode(int) + at: &tmp2]; - _autorepeat = (BOOL)tmp1; - _valueWraps = (BOOL)tmp2; + _autorepeat = (BOOL)tmp1; + _valueWraps = (BOOL)tmp2; + } return self; } diff --git a/Source/NSTableView.m b/Source/NSTableView.m index 704f9596c..9d12abcf6 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -37,6 +37,7 @@ #include #include #include +#include #include "AppKit/NSTableView.h" #include "AppKit/NSApplication.h" @@ -73,6 +74,31 @@ static int currentDropRow; static int lastQuarterPosition; static unsigned currentDragOperation; +/* + * Nib compatibility struct. This structure is used to + * pull the attributes out of the nib that we need to fill + * in the flags. + */ +typedef struct _tableViewFlags +{ +#ifdef WORDS_BIGENDIAN + unsigned int columnOrdering:1; + unsigned int columnResizing:1; + unsigned int drawsGrid:1; + unsigned int emptySelection:1; + unsigned int multipleSelection:1; + unsigned int columnSelection:1; + unsigned int __unused:26; +#else + unsigned int __unused:26; + unsigned int columnSelection:1; + unsigned int multipleSelection:1; + unsigned int emptySelection:1; + unsigned int drawsGrid:1; + unsigned int columnResizing:1; + unsigned int columnOrdering:1; +#endif +} GSTableViewFlags; #define ALLOWS_MULTIPLE (1) #define ALLOWS_EMPTY (1 << 1) @@ -80,7 +106,6 @@ static unsigned currentDragOperation; #define CONTROL_DOWN (1 << 3) #define ADDING_ROW (1 << 4) - @interface NSTableView (NotificationRequestMethods) - (void) _postSelectionIsChangingNotification; - (void) _postSelectionDidChangeNotification; @@ -2236,6 +2261,7 @@ _isCellEditable (id delegate, NSArray *tableColumns, /* We do *not* retain the dataSource, it's like a delegate */ _dataSource = anObject; + [self tile]; [self reloadData]; } @@ -3766,12 +3792,12 @@ static inline float computePeriod(NSPoint mouseLocationWin, - (void) setHeaderView: (NSTableHeaderView*)aHeaderView { - if ([_headerView respondsToSelector:@selector(setTableView)]) + if ([_headerView respondsToSelector:@selector(setTableView:)]) [_headerView setTableView: nil]; ASSIGN (_headerView, aHeaderView); - if ([_headerView respondsToSelector:@selector(setTableView)]) + if ([_headerView respondsToSelector:@selector(setTableView:)]) [_headerView setTableView: self]; [self tile]; // resizes corner and header views, then displays @@ -5112,30 +5138,70 @@ static inline float computePeriod(NSPoint mouseLocationWin, { [super encodeWithCoder: aCoder]; - [aCoder encodeConditionalObject: _dataSource]; - [aCoder encodeObject: _tableColumns]; - [aCoder encodeObject: _gridColor]; - [aCoder encodeObject: _backgroundColor]; - [aCoder encodeObject: _headerView]; - [aCoder encodeObject: _cornerView]; - [aCoder encodeConditionalObject: _delegate]; - [aCoder encodeConditionalObject: _target]; + if ([aCoder allowsKeyedCoding]) + { + unsigned int vFlags = 0; // (raw >> 26); // filter out settings not pertinent to us. + NSSize intercellSpacing = [self intercellSpacing]; - [aCoder encodeValueOfObjCType: @encode(int) at: &_numberOfRows]; - [aCoder encodeValueOfObjCType: @encode(int) at: &_numberOfColumns]; + [aCoder encodeObject: [self dataSource] forKey: @"NSDataSource"]; + [aCoder encodeObject: [self delegate] forKey: @"NSDelegate"]; + [aCoder encodeObject: [self target] forKey: @"NSTarget"]; + [aCoder encodeObject: NSStringFromSelector([self action]) forKey: @"NSAction"]; + [aCoder encodeObject: [self backgroundColor] forKey: @"NSBackgroundColor"]; + [aCoder encodeObject: [self gridColor] forKey: @"NSGridColor"]; + [aCoder encodeFloat: intercellSpacing.height forKey: @"NSIntercellSpacingHeight"]; + [aCoder encodeFloat: intercellSpacing.width forKey: @"NSIntercellSpacingWidth"]; + [aCoder encodeFloat: [self rowHeight] forKey: @"NSRowHeight"]; + [aCoder encodeObject: [self tableColumns] forKey: @"NSTableColumns"]; + + if([self allowsColumnSelection]) + vFlags |= 1; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_drawsGrid]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_rowHeight]; - [aCoder encodeValueOfObjCType: @encode(SEL) at: &_doubleAction]; - [aCoder encodeSize: _intercellSpacing]; + if([self allowsMultipleSelection]) + vFlags |= 2; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsMultipleSelection]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnSelection]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit]; + if([self allowsEmptySelection]) + vFlags |= 4; + if([self allowsColumnResizing]) + vFlags |= 16; + + if([self allowsColumnReordering]) + vFlags |= 32; + + // shift... + vFlags = vFlags << 26; + vFlags |= 0x2400000; // add the constant... + + // encode.. + [aCoder encodeInt: vFlags forKey: @"NSTvFlags"]; + } + else + { + [aCoder encodeConditionalObject: _dataSource]; + [aCoder encodeObject: _tableColumns]; + [aCoder encodeObject: _gridColor]; + [aCoder encodeObject: _backgroundColor]; + [aCoder encodeObject: _headerView]; + [aCoder encodeObject: _cornerView]; + [aCoder encodeConditionalObject: _delegate]; + [aCoder encodeConditionalObject: _target]; + + [aCoder encodeValueOfObjCType: @encode(int) at: &_numberOfRows]; + [aCoder encodeValueOfObjCType: @encode(int) at: &_numberOfColumns]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_drawsGrid]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_rowHeight]; + [aCoder encodeValueOfObjCType: @encode(SEL) at: &_doubleAction]; + [aCoder encodeSize: _intercellSpacing]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsMultipleSelection]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnSelection]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit]; + } } - (id) initWithCoder: (NSCoder*)aDecoder @@ -5149,10 +5215,19 @@ static inline float computePeriod(NSPoint mouseLocationWin, NSEnumerator *e; NSTableColumn *col; - [self setDataSource: [aDecoder decodeObjectForKey: @"NSDataSource"]]; - [self setDelegate: [aDecoder decodeObjectForKey: @"NSDelegate"]]; - - [self setTarget: [aDecoder decodeObjectForKey: @"NSTarget"]]; + [(NSKeyedUnarchiver *)aDecoder setClass: [GSTableCornerView class] forClassName: @"_NSCornerView"]; + if ([aDecoder containsValueForKey: @"NSDataSource"]) + { + [self setDataSource: [aDecoder decodeObjectForKey: @"NSDataSource"]]; + } + if ([aDecoder containsValueForKey: @"NSDelegate"]) + { + [self setDelegate: [aDecoder decodeObjectForKey: @"NSDelegate"]]; + } + if ([aDecoder containsValueForKey: @"NSTarget"]) + { + [self setTarget: [aDecoder decodeObjectForKey: @"NSTarget"]]; + } if ([aDecoder containsValueForKey: @"NSAction"]) { NSString *action = [aDecoder decodeObjectForKey: @"NSAction"]; @@ -5179,19 +5254,66 @@ static inline float computePeriod(NSPoint mouseLocationWin, { [self setRowHeight: [aDecoder decodeFloatForKey: @"NSRowHeight"]]; } + if ([aDecoder containsValueForKey: @"NSHeaderView"]) + { + NSRect viewFrame = [self frame]; + float rowHeight = [self rowHeight]; + + _headerView = [NSTableHeaderView new]; + [_headerView setFrameSize: NSMakeSize(viewFrame.size.width, rowHeight)]; + [_headerView setTableView: self]; + } + if ([aDecoder containsValueForKey: @"NSCornerView"]) + { + NSRect viewFrame; + float rowHeight = [self rowHeight]; + + [self setCornerView: [aDecoder decodeObjectForKey: @"NSCornerView"]]; + viewFrame = [[self cornerView] frame]; + viewFrame.size.height = rowHeight; + [[self cornerView] setFrame: viewFrame]; + } + + // get the table columns... columns = [aDecoder decodeObjectForKey: @"NSTableColumns"]; e = [columns objectEnumerator]; while ((col = [e nextObject]) != nil) { [self addTableColumn: col]; + [col setTableView: self]; } if ([aDecoder containsValueForKey: @"NSTvFlags"]) { - //int vFlags = [aDecoder decodeIntForKey: @"NSTvFlags"]; - // FIXME set the flags + unsigned long flags = [aDecoder decodeIntForKey: @"NSTvFlags"]; + GSTableViewFlags tableViewFlags; + memcpy((void *)&tableViewFlags,(void *)&flags,sizeof(struct _tableViewFlags)); + + [self setAllowsColumnSelection: tableViewFlags.columnSelection]; + [self setAllowsMultipleSelection: tableViewFlags.multipleSelection]; + [self setAllowsEmptySelection: tableViewFlags.emptySelection]; + [self setDrawsGrid: tableViewFlags.drawsGrid]; + [self setAllowsColumnResizing: tableViewFlags.columnResizing]; + [self setAllowsColumnReordering: tableViewFlags.columnOrdering]; } + + _numberOfColumns = [columns count]; + ASSIGN (_selectedColumns, [NSMutableIndexSet indexSet]); + ASSIGN (_selectedRows, [NSMutableIndexSet indexSet]); + if (_numberOfColumns) + _columnOrigins = NSZoneMalloc (NSDefaultMallocZone (), + sizeof(float) * _numberOfColumns); + + _clickedRow = -1; + _clickedColumn = -1; + _selectingColumns = NO; + _selectedColumn = -1; + _selectedRow = -1; + _editedColumn = -1; + _editedRow = -1; + + [self tile]; } else { @@ -5250,15 +5372,6 @@ static inline float computePeriod(NSPoint mouseLocationWin, { [self tile]; } - /* - NSLog(@"frame %@", NSStringFromRect([self frame])); - NSLog(@"dataSource %@", _dataSource); - if (_dataSource != nil) - { - [self setDataSource: _dataSource]; - NSLog(@"dataSource set"); - } - */ } return self; diff --git a/Source/NSTextContainer.m b/Source/NSTextContainer.m index 76c459372..e98c33c53 100644 --- a/Source/NSTextContainer.m +++ b/Source/NSTextContainer.m @@ -433,10 +433,9 @@ framework intact. { if ([aDecoder allowsKeyedCoding]) { - //NSLayoutManager *manager = [aDecoder decodeObjectForKey: @"NSLayoutManager"]; NSTextView *view = [aDecoder decodeObjectForKey: @"NSTextView"]; NSSize size = NSZeroSize; - + if ([aDecoder containsValueForKey: @"NSWidth"]) { size.width = [aDecoder decodeFloatForKey: @"NSWidth"]; @@ -444,10 +443,16 @@ framework intact. self = [self initWithContainerSize: size]; if ([aDecoder containsValueForKey: @"NSTCFlags"]) { - // FIXME - //int flags = [aDecoder decodeIntForKey: @"NSTCFlags"]; + int flags = [aDecoder decodeIntForKey: @"NSTCFlags"]; + + // decode the flags. + _widthTracksTextView = flags & 1; + _heightTracksTextView = flags & 2; + _observingFrameChanges = flags & 4; } - // No need to set manager as the decoding of the layout manager does it + + // decoding the manager adds this text container automatically... + [aDecoder decodeObjectForKey: @"NSLayoutManager"]; [self setTextView: view]; return self; } diff --git a/Source/NSTextField.m b/Source/NSTextField.m index ff0718cac..281c33164 100644 --- a/Source/NSTextField.m +++ b/Source/NSTextField.m @@ -709,17 +709,19 @@ static Class textFieldCellClass; - (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; - - [aCoder encodeConditionalObject: _delegate]; - [aCoder encodeValueOfObjCType: @encode(SEL) at: &_error_action]; + if(![aCoder allowsKeyedCoding]) + { + [aCoder encodeConditionalObject: _delegate]; + [aCoder encodeValueOfObjCType: @encode(SEL) at: &_error_action]; + } } - (id) initWithCoder: (NSCoder*)aDecoder { self = [super initWithCoder: aDecoder]; - - if ([aDecoder allowsKeyedCoding]) + if([aDecoder allowsKeyedCoding]) { + // do nothing for now... } else { diff --git a/Source/NSTextView.m b/Source/NSTextView.m index c560d8f62..587bd2b74 100644 --- a/Source/NSTextView.m +++ b/Source/NSTextView.m @@ -125,16 +125,24 @@ Interface for a bunch of internal methods that need to be cleaned up. // This class is a helper for keyed unarchiving only @interface NSTextViewSharedData : NSObject { -@public +@private NSColor *backgroundColor; NSParagraphStyle *paragraphStyle; - int flags; + unsigned int flags; NSColor *insertionColor; NSArray *linkAttr; NSArray *markAttr; NSArray *selectedAttr; NSTextView *textView; } +- (NSColor *) backgroundColor; +- (NSParagraphStyle *) paragraphStyle; +- (unsigned int) flags; +- (NSColor *) insertionColor; +- (NSArray *) linkAttributes; +- (NSArray *) markAttributes; +- (NSArray *) selectedAttributes; +- (NSTextView *) textView; @end @implementation NSTextViewSharedData @@ -151,9 +159,7 @@ Interface for a bunch of internal methods that need to be cleaned up. ASSIGN(markAttr, [aDecoder decodeObjectForKey: @"NSMarkedAttributes"]); ASSIGN(selectedAttr, [aDecoder decodeObjectForKey: @"NSSelectedAttributes"]); } - else - { - } + return self; } @@ -167,6 +173,45 @@ Interface for a bunch of internal methods that need to be cleaned up. RELEASE(selectedAttr); } +- (NSColor *)backgroundColor +{ + return backgroundColor; +} + +- (NSParagraphStyle *) paragraphStyle +{ + return paragraphStyle; +} + +- (unsigned int) flags +{ + return flags; +} + +- (NSColor *) insertionColor +{ + return insertionColor; +} + +- (NSArray *) linkAttributes +{ + return linkAttr; +} + +- (NSArray *) markAttributes +{ + return markAttr; +} + +- (NSArray *) selectedAttributes +{ + return selectedAttr; +} + +- (NSTextView *) textView +{ + return textView; +} @end @@ -646,45 +691,97 @@ that makes decoding and encoding compatible with the old code. -(id) initWithCoder: (NSCoder *)aDecoder { self = [super initWithCoder: aDecoder]; - if ([aDecoder allowsKeyedCoding]) - { + { + NSTextContainer *aTextContainer; + if ([aDecoder containsValueForKey: @"NSDelegate"]) { [self setDelegate: [aDecoder decodeObjectForKey: @"NSDelegate"]]; } + if ([aDecoder containsValueForKey: @"NSMaxSize"]) { [self setMaxSize: [aDecoder decodeSizeForKey: @"NSMaxSize"]]; } + if ([aDecoder containsValueForKey: @"NSMinize"]) { // it's NSMinize in pre-10.3 formats. [self setMinSize: [aDecoder decodeSizeForKey: @"NSMinize"]]; } + if ([aDecoder containsValueForKey: @"NSMinSize"]) { // However, if NSMinSize is present we want to use it. [self setMinSize: [aDecoder decodeSizeForKey: @"NSMinSize"]]; } - if ([aDecoder containsValueForKey: @"NSTextContainer"]) + + if ([aDecoder containsValueForKey: @"NSSharedData"]) { - [self setTextContainer: [aDecoder decodeObjectForKey: @"NSTextContainer"]]; + NSTextViewSharedData *shared = [aDecoder decodeObjectForKey: @"NSSharedData"]; + unsigned int flags = [shared flags]; + + ASSIGN(_insertionPointColor, [shared insertionColor]); + ASSIGN(_backgroundColor, [shared backgroundColor]); + + _tf.is_editable = ((0x01 & flags) > 0); + _tf.is_selectable = ((0x02 & flags) > 0); + _tf.is_rich_text = ((0x04 & flags) > 0); + _tf.imports_graphics = ((0x08 & flags) > 0); + _tf.is_field_editor = ((0x10 & flags) > 0); + _tf.uses_font_panel = ((0x20 & flags) > 0); + _tf.is_ruler_visible = ((0x40 & flags) > 0); + _tf.uses_ruler = ((0x100 & flags) > 0); + _tf.draws_background = ((0x800 & flags) > 0); + _tf.smart_insert_delete = ((0x2000000 & flags) > 0); + _tf.allows_undo = ((0x40000000 & flags) > 0); + + _tf.owns_text_network = YES; + _tf.is_horizontally_resizable = YES; + _tf.is_vertically_resizable = YES; + } + + // currently not used.... + if ([aDecoder containsValueForKey: @"NSTextStorage"]) + { + _textStorage = [aDecoder decodeObjectForKey: @"NSTextStorage"]; + } + + // currently not used.... + if ([aDecoder containsValueForKey: @"NSTextContainer"]) + { + NSSize size = NSMakeSize(0,_maxSize.height); + NSTextContainer *aTextContainer = [self buildUpTextNetwork: NSZeroSize]; + [aTextContainer setTextView: (NSTextView *)self]; + /* See initWithFrame: for comments on this RELEASE */ + RELEASE(self); + + [aTextContainer setContainerSize: size]; + [aTextContainer setWidthTracksTextView: YES]; + [aTextContainer setHeightTracksTextView: NO]; } if ([aDecoder containsValueForKey: @"NSTVFlags"]) { - //int vFlags = [aDecoder decodeIntForKey: @"NSTVFlags"]; - // FIXME set the flags - } - if ([aDecoder containsValueForKey: @"NSSharedData"]) - { - //NSTextViewSharedData *shared = [aDecoder decodeObjectForKey: @"NSSharedData"]; - } - if ([aDecoder containsValueForKey: @"NSTextStorage"]) - { - //NSTextStorage *storage = [aDecoder decodeObjectForKey: @"NSTextStorage"]; + int vFlags = [aDecoder decodeIntForKey: @"NSTVFlags"]; + // these flags are not used... } + + // register for services and subscribe to notifications. + [self _recacheDelegateResponses]; + [self invalidateTextContainerOrigin]; + + if (!did_register_for_services) + [isa registerForServices]; + + [self updateDragTypeRegistration]; + + [self setPostsFrameChangedNotifications: YES]; + [notificationCenter addObserver: self + selector: @selector(_updateState:) + name: NSViewFrameDidChangeNotification + object: self]; } else { @@ -1515,7 +1612,6 @@ incorrectly. */ [self setConstrainedFrameSize: size]; } - /* TODO: There is code in TextEdit that implies that the minimum size is mostly ignored, and that the size of the containing clip view is always diff --git a/Source/NSView.m b/Source/NSView.m index d65c42ced..5b2e326af 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -3915,6 +3915,8 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) [aCoder encodeInt: vFlags forKey: @"NSvFlags"]; + + [aCoder encodeObject: _super_view forKey: @"NSSuperview"]; } else { @@ -3938,6 +3940,10 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) - (id) initWithCoder: (NSCoder*)aDecoder { + NSEnumerator *e; + NSView *sub; + NSArray *subs; + // decode the superclass... [super initWithCoder: aDecoder]; @@ -3949,9 +3955,8 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) if ([aDecoder allowsKeyedCoding]) { - NSView *prevKeyView = [aDecoder decodeObjectForKey: @"NSPreviousKeyView"]; - NSView *nextKeyView = [aDecoder decodeObjectForKey: @"NSNextKeyView"]; - NSArray *subViews = [aDecoder decodeObjectForKey: @"NSSubviews"]; + NSView *prevKeyView = nil; + NSView *nextKeyView = nil; if ([aDecoder containsValueForKey: @"NSFrame"]) { @@ -3959,17 +3964,10 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) [_frameMatrix setFrameOrigin: _frame.origin]; } self = [self initWithFrame: _frame]; - - if (subViews != nil) - { - NSEnumerator *enumerator = [subViews objectEnumerator]; - NSView *sub; - - while ((sub = [enumerator nextObject]) != nil) - { - [self addSubview: sub]; - } - } + + subs = [aDecoder decodeObjectForKey: @"NSSubviews"]; + prevKeyView = [aDecoder decodeObjectForKey: @"NSPreviousKeyView"]; + nextKeyView = [aDecoder decodeObjectForKey: @"NSNextKeyView"]; if (nextKeyView != nil) { [self setNextKeyView: nextKeyView]; @@ -3992,9 +3990,6 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) else { NSRect rect; - NSEnumerator *e; - NSView *sub; - NSArray *subs; NSDebugLLog(@"NSView", @"NSView: start decoding\n"); @@ -4029,25 +4024,27 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) [[aDecoder decodeObject] setNextKeyView: self]; [aDecoder decodeValueOfObjCType: @encode(id) at: &subs]; - e = [subs objectEnumerator]; - while ((sub = [e nextObject]) != nil) - { - NSAssert(sub->_window == nil, NSInternalInconsistencyException); - NSAssert(sub->_super_view == nil, NSInternalInconsistencyException); - [sub viewWillMoveToWindow: _window]; - [sub viewWillMoveToSuperview: self]; - [sub setNextResponder: self]; - [_sub_views addObject: sub]; - _rFlags.has_subviews = 1; - [sub resetCursorRects]; - [sub setNeedsDisplay: YES]; - [sub _viewDidMoveToWindow]; - [sub viewDidMoveToSuperview]; - [self didAddSubview: sub]; - } - RELEASE(subs); NSDebugLLog(@"NSView", @"NSView: finish decoding\n"); } + + // iterate over subviews and put them into the view... + e = [subs objectEnumerator]; + while ((sub = [e nextObject]) != nil) + { + NSAssert([sub window] == nil, NSInternalInconsistencyException); + NSAssert([sub superview] == nil, NSInternalInconsistencyException); + [sub viewWillMoveToWindow: _window]; + [sub viewWillMoveToSuperview: self]; + [sub setNextResponder: self]; + [_sub_views addObject: sub]; + _rFlags.has_subviews = 1; + [sub resetCursorRects]; + [sub setNeedsDisplay: YES]; + [sub _viewDidMoveToWindow]; + [sub viewDidMoveToSuperview]; + [self didAddSubview: sub]; + } + RELEASE(subs); return self; }