mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-22 22:20:44 +00:00
Added new inspector files pulled out of inspectors.m.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@21631 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5157232268
commit
b471f14c0b
17 changed files with 911 additions and 730 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,21 @@
|
|||
2005-08-11 23:00 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* GormCore/GormInspectorsManager.m: Removed explicit check for table
|
||||
or text view.
|
||||
* GormCore/GormScrollViewAttributesInspector.m: removed explicit
|
||||
check for table or text view.
|
||||
* Palettes/3Containers/inspectors.m: Added editorClassName
|
||||
* Palettes/4Data/GNUmakefile: Added new files.
|
||||
* Palettes/4Data/GormImageViewAttributesInspector.m: Pulled out
|
||||
IBObjectAdditions category
|
||||
* Palettes/4Data/GormTextViewAttributesInspector.[hm]: Change class
|
||||
name to GormTextViewAttributesInspector.
|
||||
* Palettes/4Data/GormNumberFormatterAttributesInspector.m: Split
|
||||
* Palettes/4Data/GormDateFormatterAttributesInspector.m: Split
|
||||
* Palettes/4Data/GormTextViewEditor.m: Split
|
||||
* Palettes/4Data/inspectors.m: Moved all IBObjectAdditions categories
|
||||
here.
|
||||
|
||||
2005-08-10 21:05 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Palettes/3Containers/GormTableViewEditor.m: in pasteInSelection,
|
||||
|
|
|
@ -35,18 +35,12 @@
|
|||
|
||||
#define NUM_DEFAULT_INSPECTORS 5
|
||||
|
||||
/*
|
||||
* The GormEmptyInspector is a placeholder for an empty selection.
|
||||
*/
|
||||
@interface GormEmptyInspector : IBInspector
|
||||
@interface GormDummyInspector : IBInspector
|
||||
- (NSString *)title;
|
||||
@end
|
||||
|
||||
@implementation GormEmptyInspector
|
||||
- (void) dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@implementation GormDummyInspector
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
|
@ -63,7 +57,7 @@
|
|||
button = [[NSButton alloc] initWithFrame: [contents bounds]];
|
||||
[button setAutoresizingMask:
|
||||
NSViewHeightSizable | NSViewWidthSizable];
|
||||
[button setStringValue: _(@"Empty Selection")];
|
||||
[button setStringValue: [self title]];
|
||||
[button setBordered: NO];
|
||||
[button setEnabled: NO];
|
||||
[contents addSubview: button];
|
||||
|
@ -71,83 +65,49 @@
|
|||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
@end;
|
||||
|
||||
/*
|
||||
* The GormEmptyInspector is a placeholder for an empty selection.
|
||||
*/
|
||||
@interface GormEmptyInspector : GormDummyInspector
|
||||
@end
|
||||
|
||||
|
||||
@implementation GormEmptyInspector
|
||||
- (NSString *)title
|
||||
{
|
||||
return _(@"Empty Selection");
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* The GormMultipleInspector is a placeholder for a multiple selection.
|
||||
*/
|
||||
@interface GormMultipleInspector : IBInspector
|
||||
@interface GormMultipleInspector : GormDummyInspector
|
||||
@end
|
||||
|
||||
@implementation GormMultipleInspector
|
||||
- (void) dealloc
|
||||
- (NSString *)title
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
NSView *contents;
|
||||
NSButton *button;
|
||||
|
||||
window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, IVW, IVH)
|
||||
styleMask: NSBorderlessWindowMask
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO];
|
||||
contents = [window contentView];
|
||||
button = [[NSButton alloc] initWithFrame: [contents bounds]];
|
||||
[button setAutoresizingMask:
|
||||
NSViewHeightSizable | NSViewWidthSizable];
|
||||
[button setStringValue: _(@"Multiple Selection")];
|
||||
[button setBordered: NO];
|
||||
[button setEnabled: NO];
|
||||
[contents addSubview: button];
|
||||
RELEASE(button);
|
||||
}
|
||||
return self;
|
||||
return _(@"Multiple Selection");
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* The GormNotApplicableInspector is a uitility for odd objects.
|
||||
*/
|
||||
@interface GormNotApplicableInspector : IBInspector
|
||||
@interface GormNotApplicableInspector : GormDummyInspector
|
||||
@end
|
||||
|
||||
@implementation GormNotApplicableInspector
|
||||
- (void) dealloc
|
||||
- (NSString *)title
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
NSView *contents;
|
||||
NSButton *button;
|
||||
|
||||
window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, IVW, IVH)
|
||||
styleMask: NSBorderlessWindowMask
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO];
|
||||
contents = [window contentView];
|
||||
button = [[NSButton alloc] initWithFrame: [contents bounds]];
|
||||
[button setAutoresizingMask:
|
||||
NSViewHeightSizable | NSViewWidthSizable];
|
||||
[button setStringValue: _(@"Not Applicable")];
|
||||
[button setBordered: NO];
|
||||
[button setEnabled: NO];
|
||||
[contents addSubview: button];
|
||||
RELEASE(button);
|
||||
}
|
||||
return self;
|
||||
return _(@"Not Applicable");
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -459,36 +419,40 @@
|
|||
NSDebugLog(@"current %i",current);
|
||||
|
||||
// Operate on the document view if the selected object is a NSScrollView
|
||||
if ([obj isKindOfClass: [NSScrollView class]]
|
||||
&& ([(NSScrollView *)obj documentView] != nil)
|
||||
&& ([[(NSScrollView *)obj documentView] isKindOfClass: [NSTableView class]]
|
||||
|| [[(NSScrollView *)obj documentView] isKindOfClass: [NSTextView class]]))
|
||||
if ([obj isKindOfClass: [NSScrollView class]] &&
|
||||
[(NSScrollView *)obj documentView])
|
||||
{
|
||||
// && [[(NSScrollView *)obj documentView] conformsToProtocol: @protocol(IBEditors)] == NO)
|
||||
|
||||
obj = [(NSScrollView *)obj documentView];
|
||||
// FIXME: Find a more generalized way to do this.
|
||||
if ([obj isKindOfClass: [NSTableView class]])
|
||||
if ([obj selectedColumn] != -1)
|
||||
obj = [[obj tableColumns] objectAtIndex:[obj selectedColumn]];
|
||||
{
|
||||
if ([obj selectedColumn] != -1)
|
||||
{
|
||||
obj = [[obj tableColumns] objectAtIndex:
|
||||
[obj selectedColumn]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if(obj != selectedObject)
|
||||
// refresh object.
|
||||
selectedObject = obj;
|
||||
|
||||
// remove any items beyond the original items on the list..
|
||||
[self _addDefaultModes];
|
||||
|
||||
// inform the world that the object is about to be inspected.
|
||||
[nc postNotificationName: IBWillInspectObjectNotification object: obj];
|
||||
|
||||
// set key equivalent
|
||||
[self _refreshPopUp];
|
||||
|
||||
if([modes count] == NUM_DEFAULT_INSPECTORS)
|
||||
{
|
||||
selectedObject = obj;
|
||||
|
||||
// remove any items beyond the original items on the list..
|
||||
[self _addDefaultModes];
|
||||
|
||||
// inform the world that the object is about to be inspected.
|
||||
[nc postNotificationName: IBWillInspectObjectNotification object: obj];
|
||||
|
||||
// set key equivalent
|
||||
[self _refreshPopUp];
|
||||
|
||||
if([modes count] == NUM_DEFAULT_INSPECTORS)
|
||||
if(current > (NUM_DEFAULT_INSPECTORS - 1))
|
||||
{
|
||||
if(current > (NUM_DEFAULT_INSPECTORS - 1))
|
||||
{
|
||||
current = 0;
|
||||
}
|
||||
current = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,14 +38,14 @@
|
|||
|
||||
- (NSString*) editorClassName
|
||||
{
|
||||
if ([self documentView]
|
||||
&& [[self documentView] isKindOfClass: [NSTableView class]])
|
||||
return @"GormTableViewEditor";
|
||||
else if ([self documentView]
|
||||
&& [[self documentView] isKindOfClass: [NSTextView class]])
|
||||
return @"GormTextViewEditor";
|
||||
else
|
||||
return @"GormScrollViewEditor";
|
||||
if ([self documentView])
|
||||
{
|
||||
return [[self documentView] editorClassName];
|
||||
}
|
||||
else
|
||||
{
|
||||
return @"GormScrollViewEditor";
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
#include <AppKit/AppKit.h>
|
||||
#include <InterfaceBuilder/InterfaceBuilder.h>
|
||||
|
||||
/* This macro makes sure that the string contains a value, even if @"" */
|
||||
#define VSTR(str) ({id _str = str; (_str) ? _str : @"";})
|
||||
|
||||
/**
|
||||
* IBObjectAdditions categories.
|
||||
*/
|
||||
|
@ -72,4 +69,9 @@
|
|||
{
|
||||
return @"GormTableViewSizeInspector";
|
||||
}
|
||||
|
||||
- (NSString*) editorClassName
|
||||
{
|
||||
return @"GormTableViewEditor";
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -27,11 +27,16 @@ PALETTE_NAME = 4Data
|
|||
4Data_PALETTE_ICON = DataPalette
|
||||
4Data_PRINCIPAL_CLASS = DataPalette
|
||||
|
||||
4Data_OBJC_FILES = GormNSComboBoxAttributesInspector.m\
|
||||
GormImageViewAttributesInspector.m\
|
||||
GormTextViewAttributesInspector.m\
|
||||
inspectors.m\
|
||||
DataPalette.m
|
||||
4Data_OBJC_FILES = \
|
||||
DataPalette.m \
|
||||
GormDateFormatterAttributesInspector.m \
|
||||
GormImageViewAttributesInspector.m \
|
||||
GormNSComboBoxAttributesInspector.m \
|
||||
GormNumberFormatterAttributesInspector.m \
|
||||
GormTextViewAttributesInspector.m \
|
||||
GormTextViewEditor.m \
|
||||
GormTextViewSizeInspector.m \
|
||||
inspectors.m
|
||||
|
||||
|
||||
4Data_RESOURCE_FILES = DataPalette.tiff \
|
||||
|
|
41
Palettes/4Data/GormDateFormatterAttributesInspector.h
Normal file
41
Palettes/4Data/GormDateFormatterAttributesInspector.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* inspectors - Various inspectors for data elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Laurent Julliard <laurent@julliard-online.org>
|
||||
Date: Nov 2001
|
||||
Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
Date: Nov 2003,2004,2005
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_GormDateFormatterAttributesInspector_h
|
||||
#define INCLUDED_GormDateFormatterAttributesInspector_h
|
||||
|
||||
#include <InterfaceBuilder/InterfaceBuilder.h>
|
||||
|
||||
@interface GormDateFormatterAttributesInspector : IBInspector
|
||||
{
|
||||
NSTableView *formatTable;
|
||||
id formatField;
|
||||
id languageSwitch;
|
||||
id detachButton;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif
|
177
Palettes/4Data/GormDateFormatterAttributesInspector.m
Normal file
177
Palettes/4Data/GormDateFormatterAttributesInspector.m
Normal file
|
@ -0,0 +1,177 @@
|
|||
/* inspectors - Various inspectors for data elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Laurent Julliard <laurent@julliard-online.org>
|
||||
Date: Nov 2001
|
||||
Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
Date: Nov 2003,2004,2005
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <InterfaceBuilder/InterfaceBuilder.h>
|
||||
#include <GormCore/GormPrivate.h>
|
||||
#include <GormCore/GormViewEditor.h>
|
||||
#include <GormCore/NSColorWell+GormExtensions.h>
|
||||
#include <GormCore/GormViewSizeInspector.h>
|
||||
#include "GormDateFormatterAttributesInspector.h"
|
||||
|
||||
/* this macro makes sure that the string contains a value, even if @"" */
|
||||
#define VSTR(str) ({id _str = str; (_str) ? _str : @"";})
|
||||
|
||||
extern NSArray *predefinedDateFormats;
|
||||
|
||||
@implementation GormDateFormatterAttributesInspector
|
||||
- (id) init
|
||||
{
|
||||
if ([super init] != nil)
|
||||
{
|
||||
if ([NSBundle loadNibNamed: @"GormNSDateFormatterInspector"
|
||||
owner: self] == NO)
|
||||
{
|
||||
NSLog(@"Could not gorm GormDateFormatterInspector");
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) ok: (id)sender
|
||||
{
|
||||
BOOL allowslanguage;
|
||||
NSString *dateFmt;
|
||||
NSDateFormatter *fmtr;
|
||||
|
||||
if (sender == detachButton)
|
||||
{
|
||||
[[object cell] setFormatter: nil];
|
||||
[[(id<IB>)NSApp activeDocument] setSelectionFromEditor: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSCell *cell = [object cell];
|
||||
|
||||
if (sender == formatTable)
|
||||
{
|
||||
int row;
|
||||
|
||||
if ((row = [sender selectedRow]) != -1)
|
||||
{
|
||||
dateFmt = [NSDateFormatter formatAtIndex: row];
|
||||
}
|
||||
|
||||
[formatField setStringValue: VSTR(dateFmt) ];
|
||||
}
|
||||
else if (sender == formatField)
|
||||
{
|
||||
int idx;
|
||||
|
||||
dateFmt = [sender stringValue];
|
||||
|
||||
// If the string typed is a predefined one then highligh it in
|
||||
// table dateFormat table view above
|
||||
if ( (idx = [NSDateFormatter indexOfFormat: dateFmt]) == NSNotFound)
|
||||
{
|
||||
[formatTable deselectAll:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[formatTable selectRow:idx byExtendingSelection:NO];
|
||||
}
|
||||
|
||||
}
|
||||
else if (sender == languageSwitch)
|
||||
{
|
||||
allowslanguage = ([sender state] == NSOnState);
|
||||
}
|
||||
|
||||
// Update the Formatter and refresh the Cell value
|
||||
fmtr = [[NSDateFormatter alloc] initWithDateFormat:dateFmt
|
||||
allowNaturalLanguage:allowslanguage];
|
||||
[cell setFormatter:fmtr];
|
||||
RELEASE(fmtr);
|
||||
|
||||
[cell setObjectValue: [cell objectValue]];
|
||||
|
||||
}
|
||||
|
||||
[super ok: sender];
|
||||
}
|
||||
|
||||
- (void) revert: (id)sender
|
||||
{
|
||||
int idx;
|
||||
NSDateFormatter *fmtr = [[object cell] formatter];
|
||||
|
||||
// If the string typed is a predefined one then highligh it in
|
||||
// table dateFormat table view above
|
||||
if ( (idx = [NSDateFormatter indexOfFormat: [fmtr dateFormat]]) == NSNotFound)
|
||||
{
|
||||
[formatTable deselectAll:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[formatTable selectRow:idx byExtendingSelection:NO];
|
||||
}
|
||||
|
||||
[formatField setStringValue: VSTR([fmtr dateFormat]) ];
|
||||
[languageSwitch setState: [fmtr allowsNaturalLanguage]];
|
||||
|
||||
[super revert: sender];
|
||||
}
|
||||
|
||||
/* NSDateFormatter inspector: table view delegate and data source */
|
||||
|
||||
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
|
||||
{
|
||||
return [NSDateFormatter formatCount];
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)aTableView
|
||||
objectValueForTableColumn:(NSTableColumn *)aTableColumn
|
||||
row:(int)rowIndex
|
||||
{
|
||||
NSString *fmt = [NSDateFormatter formatAtIndex:rowIndex];
|
||||
|
||||
if ( [[aTableColumn identifier] isEqualToString: @"format"] )
|
||||
{
|
||||
return fmt;
|
||||
}
|
||||
else if ( [[aTableColumn identifier] isEqualToString: @"date"] )
|
||||
{
|
||||
return [[NSDateFormatter defaultFormatValue]
|
||||
descriptionWithCalendarFormat:fmt ];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Huuh?? Only 2 columns
|
||||
NSLog(@"Date table view only doesn't known column identifier: %@", [aTableColumn identifier]);
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
[self ok: formatTable];
|
||||
}
|
||||
|
||||
@end
|
|
@ -31,9 +31,7 @@
|
|||
*/
|
||||
|
||||
#include "GormImageViewAttributesInspector.h"
|
||||
|
||||
#include <Foundation/NSNotification.h>
|
||||
|
||||
#include <AppKit/NSButton.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
#include <AppKit/NSImageView.h>
|
||||
|
@ -44,17 +42,6 @@
|
|||
/* This macro makes sure that the string contains a value, even if @"" */
|
||||
#define VSTR(str) ({id _str = str; (_str) ? _str : @"";})
|
||||
|
||||
|
||||
/*
|
||||
IBObjectAdditions category
|
||||
*/
|
||||
@implementation NSImageView (IBObjectAdditions)
|
||||
- (NSString*) inspectorClassName
|
||||
{
|
||||
return @"GormNSImageViewAttributesInspector";
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormImageViewAttributesInspector
|
||||
|
||||
- (id) init
|
||||
|
@ -72,7 +59,7 @@
|
|||
}
|
||||
|
||||
/* Commit changes that the user makes in the Attributes Inspector */
|
||||
- (void) ok: (id) sender
|
||||
- (void) ok: (id)sender
|
||||
{
|
||||
/* icon name */
|
||||
if (sender == iconField)
|
||||
|
@ -90,19 +77,15 @@
|
|||
if (image == nil)
|
||||
{
|
||||
image = [[NSImage alloc] initByReferencingFile: name];
|
||||
|
||||
if (image)
|
||||
[image setName: name];
|
||||
{
|
||||
[image setName: name];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[object setImage: image ];
|
||||
}
|
||||
#warning Not Sure
|
||||
if ( image != nil )
|
||||
[object setImage: image ];
|
||||
// if (image == nil)
|
||||
// {
|
||||
// NSRunAlertPanel(@"Gorm ImageView", @"Cannot find image",
|
||||
// @"OK", NULL, NULL);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
/* border */
|
||||
else if (sender == borderMatrix)
|
||||
|
|
46
Palettes/4Data/GormNumberFormatterAttributesInspector.h
Normal file
46
Palettes/4Data/GormNumberFormatterAttributesInspector.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* inspectors - Various inspectors for data elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Laurent Julliard <laurent@julliard-online.org>
|
||||
Date: Nov 2001
|
||||
Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
Date: Nov 2003,2004,2005
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_GormNumberFormatterAttributesInspector_h
|
||||
#define INCLUDED_GormNumberFormatterAttributesInspector_h
|
||||
|
||||
#include <InterfaceBuilder/InterfaceBuilder.h>
|
||||
|
||||
@interface GormNumberFormatterAttributesInspector : IBInspector
|
||||
{
|
||||
id addThousandSeparatorSwitch;
|
||||
id commaPointSwitch;
|
||||
id formatForm;
|
||||
id formatTable;
|
||||
id localizeSwitch;
|
||||
id negativeField;
|
||||
id negativeRedSwitch;
|
||||
id positiveField;
|
||||
id detachButton;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif
|
277
Palettes/4Data/GormNumberFormatterAttributesInspector.m
Normal file
277
Palettes/4Data/GormNumberFormatterAttributesInspector.m
Normal file
|
@ -0,0 +1,277 @@
|
|||
/* inspectors - Various inspectors for data elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Laurent Julliard <laurent@julliard-online.org>
|
||||
Date: Nov 2001
|
||||
Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
Date: Nov 2003,2004,2005
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
#include <GormCore/GormPrivate.h>
|
||||
#include <GormCore/GormViewEditor.h>
|
||||
#include <GormCore/NSColorWell+GormExtensions.h>
|
||||
#include <GormCore/GormViewSizeInspector.h>
|
||||
|
||||
#include "GormNumberFormatterAttributesInspector.h"
|
||||
|
||||
/* this macro makes sure that the string contains a value, even if @"" */
|
||||
#define VSTR(str) ({id _str = str; (_str) ? _str : @"";})
|
||||
|
||||
extern NSArray *predefinedNumberFormats;
|
||||
|
||||
@implementation GormNumberFormatterAttributesInspector
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ([super init] != nil)
|
||||
{
|
||||
if ([NSBundle loadNibNamed: @"GormNSNumberFormatterInspector"
|
||||
owner: self] == NO)
|
||||
{
|
||||
NSLog(@"Could not gorm GormNumberFormatterInspector");
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSNumberFormatter *fmtr = [[NSNumberFormatter alloc] init];
|
||||
[fmtr setFormat: [NSNumberFormatter defaultFormat]];
|
||||
[[positiveField cell] setFormatter: fmtr];
|
||||
[[negativeField cell] setFormatter: fmtr];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) updateAppearanceFieldsWithFormat: (NSString *)format;
|
||||
{
|
||||
|
||||
[[[positiveField cell] formatter] setFormat: format];
|
||||
[[positiveField cell] setObjectValue:
|
||||
[NSDecimalNumber decimalNumberWithString: @"123456.789"]];
|
||||
|
||||
[[[negativeField cell] formatter] setFormat: format];
|
||||
[[negativeField cell] setObjectValue:
|
||||
[NSDecimalNumber decimalNumberWithString: @"-123456.789"]];
|
||||
}
|
||||
|
||||
- (void) ok: (id)sender
|
||||
{
|
||||
NSString *positiveFmt, *negativeFmt, *zeroFmt, *fullFmt;
|
||||
NSString *minValue, *maxValue;
|
||||
NSCell *cell = [object cell];
|
||||
NSNumberFormatter *fmtr = [cell formatter];
|
||||
|
||||
if (sender == detachButton)
|
||||
{
|
||||
[cell setFormatter: nil];
|
||||
[[(id<IB>)NSApp activeDocument] setSelectionFromEditor: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sender == formatTable)
|
||||
{
|
||||
int row;
|
||||
|
||||
if ((row = [sender selectedRow]) != -1)
|
||||
{
|
||||
positiveFmt = [NSNumberFormatter positiveFormatAtIndex:row];
|
||||
zeroFmt = [NSNumberFormatter zeroFormatAtIndex:row];
|
||||
negativeFmt = [NSNumberFormatter negativeFormatAtIndex:row];
|
||||
fullFmt = [NSNumberFormatter formatAtIndex:row];
|
||||
}
|
||||
|
||||
// Update Appearance samples
|
||||
[self updateAppearanceFieldsWithFormat: fullFmt];
|
||||
|
||||
// Update editable format fields
|
||||
[[formatForm cellAtIndex:0] setStringValue: VSTR(positiveFmt)];
|
||||
[[formatForm cellAtIndex:1] setStringValue: VSTR(zeroFmt)];
|
||||
[[formatForm cellAtIndex:2] setStringValue: VSTR(negativeFmt)];
|
||||
|
||||
[fmtr setFormat:fullFmt];
|
||||
|
||||
}
|
||||
|
||||
else if (sender == formatForm)
|
||||
{
|
||||
int idx;
|
||||
|
||||
positiveFmt = [[sender cellAtIndex:0] stringValue];
|
||||
zeroFmt = [[sender cellAtIndex:1] stringValue];
|
||||
negativeFmt = [[sender cellAtIndex:2] stringValue];
|
||||
minValue = [[sender cellAtIndex:3] stringValue];
|
||||
maxValue = [[sender cellAtIndex:4] stringValue];
|
||||
NSDebugLog(@"min,max: %@, %@", minValue, maxValue);
|
||||
|
||||
fullFmt = [NSString stringWithFormat:@"%@;%@;%@",
|
||||
positiveFmt, zeroFmt, negativeFmt];
|
||||
|
||||
// If the 3 formats correspond to a predefined set then highlight it in
|
||||
// number Format table view above
|
||||
if ( (idx = [NSNumberFormatter indexOfFormat: fullFmt]) == NSNotFound)
|
||||
{
|
||||
[formatTable deselectAll:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[formatTable selectRow:idx byExtendingSelection:NO];
|
||||
NSDebugLog(@"format found at index: %d", idx);
|
||||
}
|
||||
|
||||
// Update Appearance samples
|
||||
[self updateAppearanceFieldsWithFormat: fullFmt];
|
||||
|
||||
[fmtr setFormat: fullFmt];
|
||||
|
||||
if (minValue != nil)
|
||||
{
|
||||
[fmtr setMinimum:
|
||||
[NSDecimalNumber decimalNumberWithString:
|
||||
minValue]];
|
||||
}
|
||||
|
||||
if (maxValue != nil)
|
||||
{
|
||||
[fmtr setMaximum:
|
||||
[NSDecimalNumber decimalNumberWithString:
|
||||
maxValue]];
|
||||
}
|
||||
}
|
||||
else if (sender == localizeSwitch)
|
||||
{
|
||||
[fmtr setLocalizesFormat:([sender state] == NSOnState)];
|
||||
}
|
||||
else if (sender == negativeRedSwitch)
|
||||
{
|
||||
NSMutableDictionary *newAttrs = [NSMutableDictionary dictionary];
|
||||
|
||||
[newAttrs setObject:[NSColor redColor] forKey:@"NSColor"];
|
||||
[fmtr setTextAttributesForNegativeValues:newAttrs];
|
||||
}
|
||||
else if (sender == addThousandSeparatorSwitch)
|
||||
{
|
||||
[fmtr setHasThousandSeparators:([sender state] == NSOnState)];
|
||||
}
|
||||
else if (sender == commaPointSwitch)
|
||||
{
|
||||
[fmtr setDecimalSeparator:
|
||||
([sender state] == NSOnState) ? @"," : @"."];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) revert: (id)sender
|
||||
{
|
||||
int idx;
|
||||
NSNumberFormatter *fmtr = [[object cell] formatter];
|
||||
|
||||
// Format form
|
||||
NSDebugLog(@"format from object: %@", [fmtr format]);
|
||||
[[formatForm cellAtIndex:0] setStringValue: [fmtr positiveFormat]];
|
||||
[[formatForm cellAtIndex:1] setStringValue: [fmtr zeroFormat]];
|
||||
[[formatForm cellAtIndex:2] setStringValue: [fmtr negativeFormat]];
|
||||
[[formatForm cellAtIndex:3] setObjectValue: [fmtr minimum]];
|
||||
[[formatForm cellAtIndex:4] setObjectValue: [fmtr maximum]];
|
||||
|
||||
// If the string typed is a predefined one then highligh it in
|
||||
// Number Format table view above
|
||||
if ( (idx = [NSNumberFormatter indexOfFormat: [fmtr format]]) == NSNotFound)
|
||||
{
|
||||
[formatTable deselectAll:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[formatTable selectRow:idx byExtendingSelection:NO];
|
||||
}
|
||||
|
||||
// Option switches
|
||||
[localizeSwitch setState:
|
||||
([fmtr localizesFormat] == YES) ? NSOnState : NSOffState];
|
||||
|
||||
[addThousandSeparatorSwitch setState:
|
||||
([fmtr hasThousandSeparators] == YES) ?
|
||||
NSOnState : NSOffState];
|
||||
|
||||
if ([[fmtr decimalSeparator] isEqualToString: @","] )
|
||||
[commaPointSwitch setState: NSOnState];
|
||||
else
|
||||
[commaPointSwitch setState: NSOffState];
|
||||
|
||||
if ( [[[fmtr textAttributesForNegativeValues] objectForKey: @"NSColor"]
|
||||
isEqual: [NSColor redColor] ] )
|
||||
[negativeRedSwitch setState: NSOnState];
|
||||
else
|
||||
[negativeRedSwitch setState: NSOffState];
|
||||
|
||||
}
|
||||
|
||||
/* Positive/Negative Format table data source */
|
||||
|
||||
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
|
||||
{
|
||||
return [NSNumberFormatter formatCount];
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)aTableView
|
||||
objectValueForTableColumn:(NSTableColumn *)aTableColumn
|
||||
row:(int)rowIndex
|
||||
{
|
||||
if ( [[aTableColumn identifier] isEqualToString: @"positive"] )
|
||||
{
|
||||
return [NSNumberFormatter positiveValueAtIndex:rowIndex];
|
||||
}
|
||||
else if ( [[aTableColumn identifier] isEqualToString: @"negative"] )
|
||||
{
|
||||
return [NSNumberFormatter negativeValueAtIndex:rowIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Huuh?? Only 2 columns
|
||||
NSLog(@"Number table view doesn't known column identifier: %@",
|
||||
[aTableColumn identifier]);
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
||||
}
|
||||
|
||||
/* Positive/Negative Format table Delegate */
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
// When a row is selected update the rest of the inspector accordingly
|
||||
[self ok: formatTable];
|
||||
}
|
||||
|
||||
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell
|
||||
forTableColumn:(NSTableColumn*)aTableColumn row:(int)rowIndex
|
||||
{
|
||||
NSNumberFormatter *fmtr;
|
||||
|
||||
// Adjust the cell formatter before it is displayed
|
||||
fmtr = [[NSNumberFormatter alloc] init];
|
||||
[fmtr setFormat: [NSNumberFormatter formatAtIndex:rowIndex]];
|
||||
[aCell setFormatter: fmtr];
|
||||
}
|
||||
|
||||
@end
|
|
@ -38,7 +38,7 @@
|
|||
@class NSColorWell;
|
||||
@class NSMatrix;
|
||||
|
||||
@interface GormNSTextViewAttributesInspector : IBInspector
|
||||
@interface GormTextViewAttributesInspector : IBInspector
|
||||
{
|
||||
NSColorWell *backgroundColorWell;
|
||||
NSColorWell *textColorWell;
|
||||
|
|
|
@ -41,20 +41,7 @@
|
|||
#include <AppKit/NSScrollView.h>
|
||||
#include <AppKit/NSTextView.h>
|
||||
|
||||
|
||||
/*
|
||||
IBObjectAdditions category
|
||||
*/
|
||||
@implementation NSTextView (IBObjectAdditions)
|
||||
- (NSString*) inspectorClassName
|
||||
{
|
||||
return @"GormNSTextViewAttributesInspector";
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation GormNSTextViewAttributesInspector
|
||||
@implementation GormTextViewAttributesInspector
|
||||
|
||||
- (id) init
|
||||
{
|
||||
|
@ -147,5 +134,4 @@
|
|||
[super revert:sender];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
41
Palettes/4Data/GormTextViewEditor.h
Normal file
41
Palettes/4Data/GormTextViewEditor.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* inspectors - Various inspectors for data elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Laurent Julliard <laurent@julliard-online.org>
|
||||
Date: Nov 2001
|
||||
Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
Date: Nov 2003,2004,2005
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_GormTextViewEditor_h
|
||||
#define INCLUDED_GormTextViewEditor_h
|
||||
|
||||
#include <InterfaceBuilder/InterfaceBuilder.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <GormCore/GormViewEditor.h>
|
||||
|
||||
@interface GormTextViewEditor : GormViewEditor
|
||||
{
|
||||
NSTextView *textView;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif
|
131
Palettes/4Data/GormTextViewEditor.m
Normal file
131
Palettes/4Data/GormTextViewEditor.m
Normal file
|
@ -0,0 +1,131 @@
|
|||
/* inspectors - Various inspectors for data elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Laurent Julliard <laurent@julliard-online.org>
|
||||
Date: Nov 2001
|
||||
Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
Date: Nov 2003,2004,2005
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <InterfaceBuilder/InterfaceBuilder.h>
|
||||
|
||||
#include <GormCore/GormPrivate.h>
|
||||
#include <GormCore/GormViewEditor.h>
|
||||
#include <GormCore/NSColorWell+GormExtensions.h>
|
||||
#include <GormCore/GormViewSizeInspector.h>
|
||||
|
||||
#include "GormTextViewEditor.h"
|
||||
|
||||
@implementation GormTextViewEditor
|
||||
|
||||
- (BOOL) activate
|
||||
{
|
||||
if ([super activate])
|
||||
{
|
||||
if ([_editedObject isKindOfClass: [NSScrollView class]])
|
||||
textView = [(NSScrollView *)_editedObject documentView];
|
||||
else
|
||||
textView = (NSTextView *)_editedObject;
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (unsigned) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
|
||||
{
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
id destination = nil;
|
||||
NSView *hitView =
|
||||
[[textView enclosingScrollView]
|
||||
hitTest:
|
||||
[[[textView enclosingScrollView] superview]
|
||||
convertPoint: [sender draggingLocation]
|
||||
fromView: nil]];
|
||||
|
||||
if ((hitView == textView) || (hitView == [textView superview]))
|
||||
destination = textView;
|
||||
|
||||
if (destination == nil)
|
||||
destination = _editedObject;
|
||||
|
||||
[NSApp displayConnectionBetween: [NSApp connectSource]
|
||||
and: destination];
|
||||
return NSDragOperationLink;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
}
|
||||
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
id destination = nil;
|
||||
NSView *hitView =
|
||||
[[textView enclosingScrollView]
|
||||
hitTest:
|
||||
[[[textView enclosingScrollView] superview]
|
||||
convertPoint: [sender draggingLocation]
|
||||
fromView: nil]];
|
||||
|
||||
if ((hitView == textView) || (hitView == [textView superview]))
|
||||
destination = textView;
|
||||
|
||||
if (destination == nil)
|
||||
destination = _editedObject;
|
||||
|
||||
[NSApp displayConnectionBetween: [NSApp connectSource]
|
||||
and: destination];
|
||||
[NSApp startConnecting];
|
||||
return YES;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSWindow *)windowAndRect: (NSRect *)prect
|
||||
forObject: (id) object
|
||||
{
|
||||
if (object == textView)
|
||||
{
|
||||
*prect = [[textView superview] convertRect: [[textView superview] visibleRect]
|
||||
toView :nil];
|
||||
return _window;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [super windowAndRect: prect forObject: object];
|
||||
}
|
||||
}
|
||||
@end
|
36
Palettes/4Data/GormTextViewSizeInspector.h
Normal file
36
Palettes/4Data/GormTextViewSizeInspector.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* inspectors - Various inspectors for data elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Laurent Julliard <laurent@julliard-online.org>
|
||||
Date: Nov 2001
|
||||
Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
Date: Nov 2003,2004,2005
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_GormTextViewSizeInspector_h
|
||||
#define INCLUDED_GormTextViewSizeInspector_h
|
||||
|
||||
#include <InterfaceBuilder/InterfaceBuilder.h>
|
||||
#include <GormCore/GormViewSizeInspector.h>
|
||||
|
||||
@interface GormTextViewSizeInspector : GormViewSizeInspector
|
||||
@end
|
||||
|
||||
#endif
|
38
Palettes/4Data/GormTextViewSizeInspector.m
Normal file
38
Palettes/4Data/GormTextViewSizeInspector.m
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* inspectors - Various inspectors for data elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Laurent Julliard <laurent@julliard-online.org>
|
||||
Date: Nov 2001
|
||||
Author: Gregory Casamento <greg_casamento@yahoo.com>
|
||||
Date: Nov 2003,2004,2005
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GormTextViewSizeInspector.h"
|
||||
|
||||
@implementation GormTextViewSizeInspector
|
||||
- (void) setObject: (id)anObject
|
||||
{
|
||||
id scrollView;
|
||||
scrollView = [anObject enclosingScrollView];
|
||||
|
||||
[super setObject: scrollView];
|
||||
}
|
||||
@end
|
||||
|
|
@ -27,160 +27,27 @@
|
|||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <InterfaceBuilder/InterfaceBuilder.h>
|
||||
#include <GormCore/GormPrivate.h>
|
||||
#include <GormCore/GormViewEditor.h>
|
||||
#include <GormCore/NSColorWell+GormExtensions.h>
|
||||
#include <GormCore/GormViewSizeInspector.h>
|
||||
|
||||
/* this macro makes sure that the string contains a value, even if @"" */
|
||||
#define VSTR(str) ({id _str = str; (_str) ? _str : @"";})
|
||||
|
||||
|
||||
extern NSArray *predefinedDateFormats, *predefinedNumberFormats;
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* NSImageView
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* NSTextView (possibly embedded in a Scroll view)
|
||||
*/
|
||||
|
||||
@interface GormTextViewSizeInspector : GormViewSizeInspector
|
||||
@end
|
||||
|
||||
@implementation GormTextViewSizeInspector
|
||||
- (void) setObject: (id)anObject
|
||||
{
|
||||
id scrollView;
|
||||
scrollView = [anObject enclosingScrollView];
|
||||
|
||||
[super setObject: scrollView];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSTextView (IBInspectorClassNames)
|
||||
@implementation NSTextView (IBObjectAdditions)
|
||||
|
||||
- (NSString*) sizeInspectorClassName
|
||||
{
|
||||
return @"GormTextViewSizeInspector";
|
||||
}
|
||||
|
||||
- (NSString*) inspectorClassName
|
||||
{
|
||||
return @"GormTextViewAttributesInspector";
|
||||
}
|
||||
|
||||
- (NSString*) editorClassName
|
||||
{
|
||||
return @"GormTextViewEditor";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface GormTextViewEditor : GormViewEditor
|
||||
{
|
||||
NSTextView *textView;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormTextViewEditor
|
||||
|
||||
- (BOOL) activate
|
||||
{
|
||||
if ([super activate])
|
||||
{
|
||||
if ([_editedObject isKindOfClass: [NSScrollView class]])
|
||||
textView = [(NSScrollView *)_editedObject documentView];
|
||||
else
|
||||
textView = (NSTextView *)_editedObject;
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (unsigned) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
|
||||
{
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
id destination = nil;
|
||||
NSView *hitView =
|
||||
[[textView enclosingScrollView]
|
||||
hitTest:
|
||||
[[[textView enclosingScrollView] superview]
|
||||
convertPoint: [sender draggingLocation]
|
||||
fromView: nil]];
|
||||
|
||||
if ((hitView == textView) || (hitView == [textView superview]))
|
||||
destination = textView;
|
||||
|
||||
if (destination == nil)
|
||||
destination = _editedObject;
|
||||
|
||||
[NSApp displayConnectionBetween: [NSApp connectSource]
|
||||
and: destination];
|
||||
return NSDragOperationLink;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
}
|
||||
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
id destination = nil;
|
||||
NSView *hitView =
|
||||
[[textView enclosingScrollView]
|
||||
hitTest:
|
||||
[[[textView enclosingScrollView] superview]
|
||||
convertPoint: [sender draggingLocation]
|
||||
fromView: nil]];
|
||||
|
||||
if ((hitView == textView) || (hitView == [textView superview]))
|
||||
destination = textView;
|
||||
|
||||
if (destination == nil)
|
||||
destination = _editedObject;
|
||||
|
||||
[NSApp displayConnectionBetween: [NSApp connectSource]
|
||||
and: destination];
|
||||
[NSApp startConnecting];
|
||||
return YES;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSWindow *)windowAndRect: (NSRect *)prect
|
||||
forObject: (id) object
|
||||
{
|
||||
if (object == textView)
|
||||
{
|
||||
*prect = [[textView superview] convertRect: [[textView superview] visibleRect]
|
||||
toView :nil];
|
||||
return _window;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [super windowAndRect: prect forObject: object];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
* NSDateFormatter
|
||||
*
|
||||
* Rk: The Inspector object is also the table view delegate and data source
|
||||
*-----------------------------------------------------------------*/
|
||||
|
||||
@implementation NSDateFormatter (IBInspectorClassNames)
|
||||
@implementation NSDateFormatter (IBObjectAdditions)
|
||||
|
||||
- (NSString*) inspectorClassName
|
||||
{
|
||||
|
@ -189,179 +56,7 @@ extern NSArray *predefinedDateFormats, *predefinedNumberFormats;
|
|||
|
||||
@end
|
||||
|
||||
@interface GormDateFormatterAttributesInspector : IBInspector
|
||||
{
|
||||
NSTableView *formatTable;
|
||||
id formatField;
|
||||
id languageSwitch;
|
||||
id detachButton;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormDateFormatterAttributesInspector
|
||||
|
||||
- (void) _setValuesFromControl: control
|
||||
{
|
||||
BOOL allowslanguage;
|
||||
NSString *dateFmt;
|
||||
NSDateFormatter *fmtr;
|
||||
|
||||
if (control == detachButton)
|
||||
{
|
||||
[[object cell] setFormatter: nil];
|
||||
[[(id<IB>)NSApp activeDocument] setSelectionFromEditor: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSCell *cell = [object cell];
|
||||
|
||||
if (control == formatTable)
|
||||
{
|
||||
int row;
|
||||
|
||||
if ((row = [control selectedRow]) != -1)
|
||||
{
|
||||
dateFmt = [NSDateFormatter formatAtIndex: row];
|
||||
}
|
||||
|
||||
[formatField setStringValue: VSTR(dateFmt) ];
|
||||
}
|
||||
else if (control == formatField)
|
||||
{
|
||||
int idx;
|
||||
|
||||
dateFmt = [control stringValue];
|
||||
|
||||
// If the string typed is a predefined one then highligh it in
|
||||
// table dateFormat table view above
|
||||
if ( (idx = [NSDateFormatter indexOfFormat: dateFmt]) == NSNotFound)
|
||||
{
|
||||
[formatTable deselectAll:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[formatTable selectRow:idx byExtendingSelection:NO];
|
||||
}
|
||||
|
||||
}
|
||||
else if (control == languageSwitch)
|
||||
{
|
||||
allowslanguage = ([control state] == NSOnState);
|
||||
}
|
||||
|
||||
// Update the Formatter and refresh the Cell value
|
||||
fmtr = [[NSDateFormatter alloc] initWithDateFormat:dateFmt
|
||||
allowNaturalLanguage:allowslanguage];
|
||||
[cell setFormatter:fmtr];
|
||||
RELEASE(fmtr);
|
||||
|
||||
[cell setObjectValue: [cell objectValue]];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void) _getValuesFromObject: (id) anObject
|
||||
{
|
||||
int idx;
|
||||
NSDateFormatter *fmtr = [[anObject cell] formatter];
|
||||
|
||||
if (anObject != object)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// If the string typed is a predefined one then highligh it in
|
||||
// table dateFormat table view above
|
||||
if ( (idx = [NSDateFormatter indexOfFormat: [fmtr dateFormat]]) == NSNotFound)
|
||||
{
|
||||
[formatTable deselectAll:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[formatTable selectRow:idx byExtendingSelection:NO];
|
||||
}
|
||||
[formatField setStringValue: VSTR([fmtr dateFormat]) ];
|
||||
[languageSwitch setState: [fmtr allowsNaturalLanguage]];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
|
||||
if ([super init] == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
if ([NSBundle loadNibNamed: @"GormNSDateFormatterInspector" owner: self] == NO)
|
||||
{
|
||||
NSLog(@"Could not gorm GormDateFormatterInspector");
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) ok: (id)sender
|
||||
{
|
||||
[super ok: sender];
|
||||
[self _setValuesFromControl: sender];
|
||||
}
|
||||
|
||||
- (void) setObject: (id)anObject
|
||||
{
|
||||
NSDebugLog(@"Formatting object: %@", anObject);
|
||||
[super setObject: anObject];
|
||||
[self _getValuesFromObject: anObject];
|
||||
}
|
||||
|
||||
/* NSDateFormatter inspector: table view delegate and data source */
|
||||
|
||||
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
|
||||
{
|
||||
return [NSDateFormatter formatCount];
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)aTableView
|
||||
objectValueForTableColumn:(NSTableColumn *)aTableColumn
|
||||
row:(int)rowIndex
|
||||
{
|
||||
NSString *fmt = [NSDateFormatter formatAtIndex:rowIndex];
|
||||
|
||||
if ( [[aTableColumn identifier] isEqualToString: @"format"] )
|
||||
{
|
||||
return fmt;
|
||||
}
|
||||
else if ( [[aTableColumn identifier] isEqualToString: @"date"] )
|
||||
{
|
||||
return [[NSDateFormatter defaultFormatValue]
|
||||
descriptionWithCalendarFormat:fmt ];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Huuh?? Only 2 columns
|
||||
NSLog(@"Date table view only doesn't known column identifier: %@", [aTableColumn identifier]);
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
[self _setValuesFromControl: formatTable];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
* NSNumberFormatter
|
||||
*
|
||||
* Rk: The Inspector object is also the table view delegate and data source
|
||||
*-----------------------------------------------------------------*/
|
||||
|
||||
@implementation NSNumberFormatter (IBInspectorClassNames)
|
||||
@implementation NSNumberFormatter (IBObjectAdditions)
|
||||
|
||||
- (NSString*) inspectorClassName
|
||||
{
|
||||
|
@ -370,272 +65,13 @@ extern NSArray *predefinedDateFormats, *predefinedNumberFormats;
|
|||
|
||||
@end
|
||||
|
||||
@interface GormNumberFormatterAttributesInspector : IBInspector
|
||||
/*
|
||||
IBObjectAdditions category
|
||||
*/
|
||||
@implementation NSImageView (IBObjectAdditions)
|
||||
- (NSString*) inspectorClassName
|
||||
{
|
||||
id addThousandSeparatorSwitch;
|
||||
id commaPointSwitch;
|
||||
id formatForm;
|
||||
id formatTable;
|
||||
id localizeSwitch;
|
||||
id negativeField;
|
||||
id negativeRedSwitch;
|
||||
id positiveField;
|
||||
id detachButton;
|
||||
return @"GormImageViewAttributesInspector";
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormNumberFormatterAttributesInspector
|
||||
|
||||
- (void) updateAppearanceFieldsWithFormat: (NSString *)format;
|
||||
{
|
||||
|
||||
[[[positiveField cell] formatter] setFormat: format];
|
||||
[[positiveField cell] setObjectValue:
|
||||
[NSDecimalNumber decimalNumberWithString: @"123456.789"]];
|
||||
|
||||
[[[negativeField cell] formatter] setFormat: format];
|
||||
[[negativeField cell] setObjectValue:
|
||||
[NSDecimalNumber decimalNumberWithString: @"-123456.789"]];
|
||||
}
|
||||
|
||||
|
||||
- (void) _setValuesFromControl: control
|
||||
{
|
||||
NSString *positiveFmt, *negativeFmt, *zeroFmt, *fullFmt;
|
||||
NSString *minValue, *maxValue;
|
||||
NSCell *cell = [object cell];
|
||||
NSNumberFormatter *fmtr = [cell formatter];
|
||||
|
||||
if (control == detachButton)
|
||||
{
|
||||
[cell setFormatter: nil];
|
||||
[[(id<IB>)NSApp activeDocument] setSelectionFromEditor: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (control == formatTable)
|
||||
{
|
||||
int row;
|
||||
|
||||
if ((row = [control selectedRow]) != -1)
|
||||
{
|
||||
positiveFmt = [NSNumberFormatter positiveFormatAtIndex:row];
|
||||
zeroFmt = [NSNumberFormatter zeroFormatAtIndex:row];
|
||||
negativeFmt = [NSNumberFormatter negativeFormatAtIndex:row];
|
||||
fullFmt = [NSNumberFormatter formatAtIndex:row];
|
||||
}
|
||||
|
||||
// Update Appearance samples
|
||||
[self updateAppearanceFieldsWithFormat: fullFmt];
|
||||
|
||||
// Update editable format fields
|
||||
[[formatForm cellAtIndex:0] setStringValue: VSTR(positiveFmt)];
|
||||
[[formatForm cellAtIndex:1] setStringValue: VSTR(zeroFmt)];
|
||||
[[formatForm cellAtIndex:2] setStringValue: VSTR(negativeFmt)];
|
||||
|
||||
[fmtr setFormat:fullFmt];
|
||||
|
||||
}
|
||||
|
||||
else if (control == formatForm)
|
||||
{
|
||||
int idx;
|
||||
|
||||
positiveFmt = [[control cellAtIndex:0] stringValue];
|
||||
zeroFmt = [[control cellAtIndex:1] stringValue];
|
||||
negativeFmt = [[control cellAtIndex:2] stringValue];
|
||||
minValue = [[control cellAtIndex:3] stringValue];
|
||||
maxValue = [[control cellAtIndex:4] stringValue];
|
||||
NSDebugLog(@"min,max: %@, %@", minValue, maxValue);
|
||||
|
||||
fullFmt = [NSString stringWithFormat:@"%@;%@;%@",
|
||||
positiveFmt, zeroFmt, negativeFmt];
|
||||
|
||||
// If the 3 formats correspond to a predefined set then highlight it in
|
||||
// number Format table view above
|
||||
if ( (idx = [NSNumberFormatter indexOfFormat: fullFmt]) == NSNotFound)
|
||||
{
|
||||
[formatTable deselectAll:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[formatTable selectRow:idx byExtendingSelection:NO];
|
||||
NSDebugLog(@"format found at index: %d", idx);
|
||||
}
|
||||
|
||||
// Update Appearance samples
|
||||
[self updateAppearanceFieldsWithFormat: fullFmt];
|
||||
|
||||
[fmtr setFormat: fullFmt];
|
||||
|
||||
if (minValue != nil)
|
||||
[fmtr setMinimum: [NSDecimalNumber decimalNumberWithString: minValue]];
|
||||
if (maxValue != nil)
|
||||
[fmtr setMaximum: [NSDecimalNumber decimalNumberWithString: maxValue]];
|
||||
|
||||
|
||||
}
|
||||
else if (control == localizeSwitch)
|
||||
{
|
||||
[fmtr setLocalizesFormat:([control state] == NSOnState)];
|
||||
}
|
||||
else if (control == negativeRedSwitch)
|
||||
{
|
||||
NSMutableDictionary *newAttrs = [NSMutableDictionary dictionary];
|
||||
|
||||
[newAttrs setObject:[NSColor redColor] forKey:@"NSColor"];
|
||||
[fmtr setTextAttributesForNegativeValues:newAttrs];
|
||||
}
|
||||
else if (control == addThousandSeparatorSwitch)
|
||||
{
|
||||
[fmtr setHasThousandSeparators:([control state] == NSOnState)];
|
||||
}
|
||||
else if (control == commaPointSwitch)
|
||||
{
|
||||
[fmtr setDecimalSeparator:([control state] == NSOnState) ? @"," : @"."];
|
||||
}
|
||||
|
||||
// FIXME: Force cell refresh with the new formatter. Really useful ?
|
||||
//[cell setObjectValue: [cell objectValue]];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void) _getValuesFromObject: (id) anObject
|
||||
{
|
||||
int idx;
|
||||
NSNumberFormatter *fmtr = [[anObject cell] formatter];
|
||||
|
||||
|
||||
if (anObject != object)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Format form
|
||||
NSDebugLog(@"format from object: %@", [fmtr format]);
|
||||
[[formatForm cellAtIndex:0] setStringValue: [fmtr positiveFormat]];
|
||||
[[formatForm cellAtIndex:1] setStringValue: [fmtr zeroFormat]];
|
||||
[[formatForm cellAtIndex:2] setStringValue: [fmtr negativeFormat]];
|
||||
[[formatForm cellAtIndex:3] setObjectValue: [fmtr minimum]];
|
||||
[[formatForm cellAtIndex:4] setObjectValue: [fmtr maximum]];
|
||||
|
||||
// If the string typed is a predefined one then highligh it in
|
||||
// Number Format table view above
|
||||
if ( (idx = [NSNumberFormatter indexOfFormat: [fmtr format]]) == NSNotFound)
|
||||
{
|
||||
[formatTable deselectAll:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[formatTable selectRow:idx byExtendingSelection:NO];
|
||||
}
|
||||
|
||||
// Option switches
|
||||
[localizeSwitch setState: ([fmtr localizesFormat] == YES) ? NSOnState : NSOffState];
|
||||
|
||||
[addThousandSeparatorSwitch setState: ([fmtr hasThousandSeparators] == YES) ? NSOnState : NSOffState];
|
||||
|
||||
if ([[fmtr decimalSeparator] isEqualToString: @","] )
|
||||
[commaPointSwitch setState: NSOnState];
|
||||
else
|
||||
[commaPointSwitch setState: NSOffState];
|
||||
|
||||
if ( [[[fmtr textAttributesForNegativeValues] objectForKey: @"NSColor"] isEqual: [NSColor redColor] ] )
|
||||
[negativeRedSwitch setState: NSOnState];
|
||||
else
|
||||
[negativeRedSwitch setState: NSOffState];
|
||||
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
|
||||
if ([super init] == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
if ([NSBundle loadNibNamed: @"GormNSNumberFormatterInspector"
|
||||
owner: self] == NO)
|
||||
{
|
||||
NSLog(@"Could not gorm GormNumberFormatterInspector");
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Initialize Positive/Negative appearance fields formatter
|
||||
{
|
||||
NSNumberFormatter *fmtr = [[NSNumberFormatter alloc] init];
|
||||
[fmtr setFormat: [NSNumberFormatter defaultFormat]];
|
||||
[[positiveField cell] setFormatter: fmtr];
|
||||
[[negativeField cell] setFormatter: fmtr];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) ok: (id)sender
|
||||
{
|
||||
[super ok: sender];
|
||||
[self _setValuesFromControl: sender];
|
||||
}
|
||||
|
||||
- (void) setObject: (id)anObject
|
||||
{
|
||||
NSDebugLog(@"Formatting object: %@", anObject);
|
||||
[super setObject: anObject];
|
||||
[self _getValuesFromObject: anObject];
|
||||
}
|
||||
|
||||
/* Positive/Negative Format table data source */
|
||||
|
||||
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
|
||||
{
|
||||
return [NSNumberFormatter formatCount];
|
||||
}
|
||||
|
||||
- (id)tableView:(NSTableView *)aTableView
|
||||
objectValueForTableColumn:(NSTableColumn *)aTableColumn
|
||||
row:(int)rowIndex
|
||||
{
|
||||
if ( [[aTableColumn identifier] isEqualToString: @"positive"] )
|
||||
{
|
||||
return [NSNumberFormatter positiveValueAtIndex:rowIndex];
|
||||
}
|
||||
else if ( [[aTableColumn identifier] isEqualToString: @"negative"] )
|
||||
{
|
||||
return [NSNumberFormatter negativeValueAtIndex:rowIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Huuh?? Only 2 columns
|
||||
NSLog(@"Number table view doesn't known column identifier: %@", [aTableColumn identifier]);
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
||||
}
|
||||
|
||||
/* Positive/Negative Format table Delegate */
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
// When a row is selected update the rest of the inspector accordingly
|
||||
[self _setValuesFromControl: formatTable];
|
||||
}
|
||||
|
||||
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell
|
||||
forTableColumn:(NSTableColumn*)aTableColumn row:(int)rowIndex
|
||||
{
|
||||
NSNumberFormatter *fmtr;
|
||||
|
||||
// Adjust the cell formatter before it is displayed
|
||||
fmtr = [[NSNumberFormatter alloc] init];
|
||||
[fmtr setFormat: [NSNumberFormatter formatAtIndex:rowIndex]];
|
||||
[aCell setFormatter: fmtr];
|
||||
//RELEASE(fmtr);
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue