Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSStoryboard refactoring #274

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Headers/Additions/GNUstepGUI/GSXibKeyedUnarchiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ APPKIT_EXPORT_CLASS

+ (BOOL) checkXib5: (NSData *)data;

+ (BOOL) checkStoryboard: (NSData *)data;

+ (NSKeyedUnarchiver *) unarchiverForReadingWithData: (NSData *)data;

- (void) _initCommon;
Expand Down
6 changes: 4 additions & 2 deletions Headers/AppKit/NSStoryboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
extern "C" {
#endif

@class NSString, NSBundle, NSMutableDictionary;
@class NSBundle;
@class NSMutableDictionary;
@class NSString;

typedef NSString *NSStoryboardName;
typedef NSString *NSStoryboardSceneIdentifier;
Expand All @@ -43,7 +45,7 @@ DEFINE_BLOCK_TYPE(NSStoryboardControllerCreator, NSCoder*, id);
APPKIT_EXPORT_CLASS
@interface NSStoryboard : NSObject
{
id _transform;
NSMutableDictionary *_scenes;
}

#if OS_API_VERSION(MAC_OS_X_VERSION_10_13, GS_API_LATEST)
Expand Down
5 changes: 4 additions & 1 deletion Source/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ GSDisplayServer.m \
GSHelpManagerPanel.m \
GSInfoPanel.m \
GSMemoryPanel.m \
GSScene.m \
GSSlideView.m \
GSStoryboardLoader.m \
GSTextStorage.m \
GSTrackingRect.m \
GSServicesManager.m \
Expand All @@ -332,6 +334,7 @@ GSGormLoading.m \
GSIconManager.m \
GSImageMagickImageRep.m \
GSNibLoading.m \
GSScenes.m \
GSTheme.m \
GSThemeDrawing.m \
GSThemeInspector.m \
Expand All @@ -346,7 +349,7 @@ GSToolTips.m \
GSToolbarView.m \
GSToolbarCustomizationPalette.m \
GSStandardWindowDecorationView.m \
GSStoryboardTransform.m \
GSStoryboardKeyedUnarchiver.m \
GSWindowDecorationView.m \
GSPrinting.m \
GSPrintOperation.m \
Expand Down
2 changes: 1 addition & 1 deletion Source/GSModelLoaderFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ + (NSString *) type

+ (float) priority
{
return 0.0;
return FLT_MAX;
}

- (BOOL) loadModelData: (NSData *)data
Expand Down
60 changes: 60 additions & 0 deletions Source/GSScene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* Interface of class GSScene
Copyright (C) 2024 Free Software Foundation, Inc.

By: Gregory John Casamento
Date: 12-05-2024

This file is part of the GNUstep Library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/

#ifndef _GSScene_h_GNUSTEP_GUI_INCLUDE
#define _GSScene_h_GNUSTEP_GUI_INCLUDE

#import <Foundation/NSObject.h>
#import <Foundation/NSGeometry.h>

#if defined(__cplusplus)
extern "C" {
#endif

@class NSMutableArray;
@class NSString;

@interface GSScene : NSObject <NSCoding, NSCopying>
{
NSString *_sceneID;
NSMutableArray *_objects;
NSPoint _canvasLocation;
}

- (NSString *) sceneID;
- (void) setSceneID: (NSString *)sceneID;

- (NSMutableArray *) objects;
- (void) setObjects: (NSMutableArray *)objects;

- (NSPoint) canvasLocation;
- (void) setCanvasLocation: (NSPoint)point;

@end

#if defined(__cplusplus)
}
#endif

#endif /* _GSScene_h_GNUSTEP_GUI_INCLUDE */
123 changes: 123 additions & 0 deletions Source/GSScene.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* Implementation of class GSScene
Copyright (C) 2024 Free Software Foundation, Inc.

By: Gregory John Casamento
Date: 12-05-2024

This file is part of the GNUstep Library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/

#import <Foundation/NSKeyedArchiver.h>

#import "GSScene.h"

@implementation GSScene

- (instancetype) init
{
self = [super init];
if (self != nil)
{
_sceneID = nil;
_objects = nil;
_canvasLocation = NSMakePoint(0.0, 0.0);
}
return self;
}

- (void) dealloc
{
RELEASE(_sceneID);
RELEASE(_objects);
[super dealloc];
}

- (NSString *) sceneID
{
return _sceneID;
}

- (void) setSceneID: (NSString *)sceneID
{
ASSIGN(_sceneID, sceneID);
}

- (NSMutableArray *) objects
{
return _objects;
}

- (void) setObjects: (NSMutableArray *)objects
{
ASSIGN(_objects, objects);
}

- (NSPoint) canvasLocation
{
return _canvasLocation;
}

- (void) setCanvasLocation: (NSPoint)point
{
_canvasLocation = point;
}

// NSCoding

- (instancetype) initWithCoder: (NSCoder *)coder
{
NSLog(@"Decoding GSScene");
if ([coder allowsKeyedCoding])
{
if ([coder containsValueForKey: @"NSSceneID"])
{
[self setSceneID: [coder decodeObjectForKey: @"NSSceneID"]];
}

if ([coder containsValueForKey: @"NSObjects"])
{
[self setObjects: [coder decodeObjectForKey: @"NSObjects"]];
}

if ([coder containsValueForKey: @"NSCanvasLocation"])
{
[self setCanvasLocation: [coder decodePointForKey: @"NSCanvasLocation"]];
}
}
return self;
}

- (void) encodeWithCoder: (NSCoder *)coder
{
}

// NSCopying

- (id) copyWithZone: (NSZone *)zone
{
GSScene *scene = [[GSScene allocWithZone: zone] init];

[scene setSceneID: [self sceneID]];
[scene setObjects: [self objects]];
[scene setCanvasLocation: [self canvasLocation]];

return scene;
}

@end

50 changes: 50 additions & 0 deletions Source/GSScenes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Interface of class GSScenes
Copyright (C) 2024 Free Software Foundation, Inc.

By: Gregory John Casamento
Date: 18-05-2024

This file is part of the GNUstep Library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/

#ifndef _GSScenes_h_GNUSTEP_GUI_INCLUDE
#define _GSScenes_h_GNUSTEP_GUI_INCLUDE

#import <Foundation/NSObject.h>
#import <Foundation/NSKeyedArchiver.h>

#if defined(__cplusplus)
extern "C" {
#endif

@interface GSScenes : NSObject <NSCoding, NSCopying>
{
NSMutableArray *_scenes;
}

- (NSMutableArray *) scenes;
- (void) setScenes: (NSMutableArray *)scenes;

@end

#if defined(__cplusplus)
}
#endif

#endif /* _GSScenes_h_GNUSTEP_GUI_INCLUDE */

82 changes: 82 additions & 0 deletions Source/GSScenes.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Implementation of class GSScenes
Copyright (C) 2024 Free Software Foundation, Inc.

By: Gregory John Casamento
Date: 18-05-2024

This file is part of the GNUstep Library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/

#import "GSScenes.h"

@implementation GSScenes

- (instancetype) init
{
self = [super init];
if (self != nil)
{
_scenes = [[NSMutableArray alloc] init];
}
return self;
}

- (void) dealloc
{
RELEASE(_scenes);
[super dealloc];
}

- (NSMutableArray *)scenes
{
return _scenes;
}

- (void) setScenes: (NSMutableArray *)scenes
{
ASSIGN(_scenes, scenes);
}

- (id) initWithCoder: (NSCoder *)coder
{
NSLog(@"GSScenes...");
if ([coder allowsKeyedCoding] == YES)
{
if ([coder containsValueForKey: @"GSScenes"])
{
[self setScenes: [coder decodeObjectForKey: @"GSScenes"]];
}
}
return self;
}

- (void) encodeWithCoder: (NSCoder *)coder
{
}

- (id) copyWithZone: (NSZone *)zone
{
GSScenes *scenes = [[GSScenes allocWithZone: zone] init];

[scenes setScenes: [[self scenes] copyWithZone: zone]];

return scenes;
}

@end

Loading