Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Applications/Gorm/Palettes/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ SUBPROJECTS = \
1Windows \
2Controls \
3Containers \
4Data
4Data \
5Formatters \
6GridStack

-include GNUmakefile.preamble

Expand Down
17 changes: 16 additions & 1 deletion GormCore/Resources/ClassInformation.plist
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@
NSMutableArray = {Super = NSArray; };
NSMutableDictionary = {Super = NSDictionary; };
NSNumberFormatter = {Super = NSFormatter; };
NSObject = {};
NSOpenGLView = {Super = NSView; };
NSOutlineView = {Super = NSTableView; };
NSPanel = {Super = NSWindow; };
Expand Down Expand Up @@ -420,4 +419,20 @@
Outlets = ();
Super = NSArrayController;
};
Object = {};
};
NSDatePicker = {
Super = NSControl;
};
NSPathControl = {
Super = NSControl;
};
NSGridView = {
Super = NSView;
};
NSSwitch = {
Super = NSControl;
};
NSObject = {};
Object = {};
}
66 changes: 66 additions & 0 deletions Palettes/5Formatters/FormattersPalette.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* DataPalette - Formatter Additions...

Copyright (C) 2021 Free Software Foundation, Inc.

Author: Gregory Casamento <[email protected]>
Date: June 1 2021

This file is part of GNUstep.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.

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

#ifndef INCLUDED_FormattersPalette_h
#define INCLUDED_FormattersPalette_h

#include <Foundation/Foundation.h>
#include <InterfaceBuilder/InterfaceBuilder.h>

/*
* NSDateFormatter and NSNumberFormatter extensions
* for Gorm Formatters used in the Data Palette
*/

@interface NSDateFormatter (GormAdditions)

+ (int) formatCount;
+ (NSString *) formatAtIndex: (int)index;
+ (NSInteger) indexOfFormat: (NSString *) format;
+ (NSString *) defaultFormat;
+ (id) defaultFormatValue;

@end

@interface NSNumberFormatter (GormAdditions)

+ (int) formatCount;
+ (NSString *) formatAtIndex: (int)index;
+ (NSString *) positiveFormatAtIndex: (int)index;
+ (NSString *) zeroFormatAtIndex: (int)index;
+ (NSString *) negativeFormatAtIndex: (int)index;
+ (NSDecimalNumber *) positiveValueAtIndex: (int)index;
+ (NSDecimalNumber *) negativeValueAtIndex: (int)index;
+ (NSInteger) indexOfFormat: (NSString *)format;
+ (NSString *) defaultFormat;
+ (id) defaultFormatValue;
- (NSString *) zeroFormat;

@end

@interface FormattersPalette: IBPalette <IBViewResourceDraggingDelegates>
@end

#endif

234 changes: 234 additions & 0 deletions Palettes/5Formatters/FormattersPalette.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
/* FormattersPalette.m

Copyright (C) 2021 Free Software Foundation, Inc.

Author: Gregory Casamento <[email protected]>
Date: Jun 4 2021

This file is part of GNUstep.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.

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

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <Foundation/NSByteCountFormatter.h>

#import <InterfaceBuilder/InterfaceBuilder.h>
#import "FormattersPalette.h"

/* -----------------------------------------------------------
* Some additions to the Formatters Classes specific to Gorm
* -----------------------------------------------------------*/
NSArray *predefinedNumberFormats;
int defaultNumberFormatIndex = 0;

@implementation FormattersPalette

- (id) init
{
if((self = [super init]) != nil)
{
// Make ourselves a delegate, so that when the formatter is dragged in,
// this code is called...
[NSView registerViewResourceDraggingDelegate: self];

// subscribe to the notification...
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(willInspectObject:)
name: IBWillInspectObjectNotification
object: nil];
}

return self;
}

- (void) dealloc
{
[NSView unregisterViewResourceDraggingDelegate: self];
[[NSNotificationCenter defaultCenter] removeObserver: self];
[super dealloc];
}

- (void) placeFormatter: (NSFormatter *)fm
withImageNamed: (NSString *)imageName
atRect: (NSRect)frame
inView: (NSView *)contents
toolTip: (NSString *)tooltip
{
id v;
NSImage *img;
NSString *path = [[NSBundle bundleForClass: [self class]]
pathForImageResource: imageName];

img = [[NSImage alloc] initWithContentsOfFile: path];
v = [[NSImageView alloc] initWithFrame: frame];
[v setImageFrameStyle: NSImageFramePhoto];
[v setImageScaling: NSScaleProportionally];
[v setImageAlignment: NSImageAlignCenter];
[v setImage: img];
[v setToolTip: tooltip];
[contents addSubview: v];
[self associateObject: fm type: IBFormatterPboardType with: v];
RELEASE(v);
RELEASE(img);
}

- (void) finishInstantiate
{
NSView *contents;

originalWindow = [[NSWindow alloc] initWithContentRect:
NSMakeRect(0, 0, 272, 192)
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreRetained
defer: NO];
[originalWindow setTitle: @"Formatters"];
contents = [originalWindow contentView];

/* Formatters. */
[self placeFormatter: [[NSByteCountFormatter alloc] init]
withImageNamed: @"bytecount_formatter"
atRect: NSMakeRect(192, 48, 43, 43)
inView: contents
toolTip: @"Byte Count"];

[self placeFormatter: [[NSDateComponentsFormatter alloc] init]
withImageNamed: @"date_comp_formatter"
atRect: NSMakeRect(144, 48, 43, 43)
inView: contents
toolTip: @"Date Components"];

[self placeFormatter: [[NSDateIntervalFormatter alloc] init]
withImageNamed: @"date_interval_formatter"
atRect: NSMakeRect(96, 48, 43, 43)
inView: contents
toolTip: @"Date Interval"];

[self placeFormatter: [[NSPersonNameComponentsFormatter alloc] init]
withImageNamed: @"energy_formatter"
atRect: NSMakeRect(48, 48, 43, 43)
inView: contents
toolTip: @"Energy"];

[self placeFormatter: [[NSMeasurementFormatter alloc] init]
withImageNamed: @"measurement_formatter"
atRect: NSMakeRect(0, 48, 43, 43)
inView: contents
toolTip: @"Measurement"];

[self placeFormatter: [[NSLengthFormatter alloc] init]
withImageNamed: @"length_formatter"
atRect: NSMakeRect(0, 96, 43, 43)
inView: contents
toolTip: @"Length"];
}

- (void) willInspectObject: (NSNotification *)notification
{
id o = [notification object];
if([o respondsToSelector: @selector(cell)])
{
id cell = [o cell];
if([cell respondsToSelector: @selector(formatter)])
{
id formatter = [o formatter];
if([formatter isKindOfClass: [NSFormatter class]])
{
NSString *ident = NSStringFromClass([formatter class]);
[[IBInspectorManager sharedInspectorManager]
addInspectorModeWithIdentifier: ident
forObject: o
localizedLabel: _(@"Formatter")
inspectorClassName: [formatter inspectorClassName]
ordering: -1.0];
}
}
}
}

// view resource dragging delegate...

/**
* Ask if the view accepts the object.
*/
- (BOOL) acceptsViewResourceFromPasteboard: (NSPasteboard *)pb
forObject: (id)obj
atPoint: (NSPoint)p
{
return ([obj respondsToSelector: @selector(setFormatter:)] &&
[[pb types] containsObject: IBFormatterPboardType]);
}

/**
* Perform the action of depositing the object.
*/
- (void) depositViewResourceFromPasteboard: (NSPasteboard *)pb
onObject: (id)obj
atPoint: (NSPoint)p
{
NSData *data = [pb dataForType: IBFormatterPboardType];
id array = [NSUnarchiver unarchiveObjectWithData: data];

if(array != nil)
{
if([array count] > 0)
{
id formatter = [array objectAtIndex: 0];

// Add the formatter if the object accepts one...
if([obj respondsToSelector: @selector(setFormatter:)])
{
// Touch the document...
[[(id<IB>)NSApp activeDocument] touch];

[obj setFormatter: formatter];
RETAIN(formatter);
if ([formatter isMemberOfClass: [NSNumberFormatter class]])
{
id fieldValue = [NSNumber numberWithFloat: 1.123456789];
[obj setStringValue: [fieldValue stringValue]];
[obj setObjectValue: fieldValue];
}
else if ([formatter isMemberOfClass: [NSDateFormatter class]])
{
id fieldValue = [NSDate date];
[obj setStringValue: [fieldValue description]];
[obj setObjectValue: fieldValue];
}
}
}
}
}

/**
* Should we draw the connection frame when the resource is
* dragged in?
*/
- (BOOL) shouldDrawConnectionFrame
{
return NO;
}

/**
* Types of resources accepted by this view.
*/
- (NSArray *)viewResourcePasteboardTypes
{
return [NSArray arrayWithObject: IBFormatterPboardType];
}

@end
Binary file added Palettes/5Formatters/FormattersPalette.tiff
Binary file not shown.
52 changes: 52 additions & 0 deletions Palettes/5Formatters/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# GNUmakefile
#
# Copyright (C) 1999, 2021 Free Software Foundation, Inc.
#
# Author: Gregory Casamento <[email protected]>
# Date: Nov 2001
#
# This file is part of GNUstep.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

PACKAGE_NAME = gorm
include $(GNUSTEP_MAKEFILES)/common.make

PALETTE_NAME = 5Formatters
5Formatters_PALETTE_ICON = FormattersPalette
5Formatters_PRINCIPAL_CLASS = FormattersPalette

5Formatters_OBJC_FILES = \
FormattersPalette.m

5Formatters_RESOURCE_FILES = FormattersPalette.tiff \
bytecount_formatter.tiff \
date_comp_formatter.tiff \
energy_formatter.tiff \
measurement_formatter.tiff \
date_interval_formatter.tiff \
length_formatter.tiff \
palette.table

5Formatters_STANDARD_INSTALL = no

-include GNUmakefile.preamble

-include GNUmakefile.local

include $(GNUSTEP_MAKEFILES)/palette.make

#-include GNUmakefile.postamble

Loading
Loading