mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-22 22:20:44 +00:00
Size NSForms when titles edited. Add slider instector
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@10726 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e3c62bfcf6
commit
f36b66a949
6 changed files with 274 additions and 6 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2001-08-18 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* GormWindowEditor.m (-_editTextView:withEvent:): Size the NSForm
|
||||
to fit when titles are edited.
|
||||
|
||||
* Add slider inspector.
|
||||
* Palettes/2Controls/inspectors.m: New file.
|
||||
* Palettes/2Controls/GormSliderInspector.gorm: Likewise.
|
||||
* Palettes/2Controls/GNUmakefile: Update
|
||||
|
||||
2001-07-18 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Version 0.0.3.
|
||||
|
|
|
@ -62,6 +62,46 @@ _constrainPointToBounds(NSPoint point, NSRect bounds)
|
|||
return point;
|
||||
}
|
||||
|
||||
@interface NSFormCell (GormAdditions)
|
||||
- (void) printAuto;
|
||||
@end
|
||||
|
||||
@implementation NSFormCell (GormAdditions)
|
||||
|
||||
- (void) printAuto
|
||||
{
|
||||
NSLog(@"Auto for cell is %d, width %f",
|
||||
_formcell_auto_title_width, _displayedTitleWidth);
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSForm (GormAdditions)
|
||||
- (float) titleWidth;
|
||||
@end
|
||||
|
||||
@implementation NSForm (GormAdditions)
|
||||
|
||||
- (float)titleWidth
|
||||
{
|
||||
int i, count = [self numberOfRows];
|
||||
float new_title_width = 0;
|
||||
float candidate_title_width = 0;
|
||||
|
||||
// Compute max of title width in the cells
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
candidate_title_width = [_cells[i][0] titleWidth];
|
||||
[_cells[i][0] printAuto];
|
||||
if (candidate_title_width > new_title_width)
|
||||
new_title_width = candidate_title_width;
|
||||
}
|
||||
return new_title_width;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation NSWindow (GormObjectAdditions)
|
||||
- (NSString*) editorClassName
|
||||
{
|
||||
|
@ -230,9 +270,7 @@ static BOOL done_editing;
|
|||
editCell = [(NSForm *)view cellAtRow: row column: col];
|
||||
frame = [(NSForm *)view cellFrameAtRow: row column: col];
|
||||
frame.origin.x += NSMinX([view frame]);
|
||||
frame.size.width = [(NSFormCell *)editCell titleWidth];
|
||||
/* Disable resizing of the title */
|
||||
[editCell setTitleWidth: frame.size.width];
|
||||
frame.size.width = [(NSForm *)view titleWidth];
|
||||
if ([view isFlipped])
|
||||
{
|
||||
frame.origin.y = NSMaxY([view frame]) - NSMaxY(frame);
|
||||
|
@ -309,10 +347,27 @@ static BOOL done_editing;
|
|||
[nc removeObserver: self
|
||||
name: NSControlTextDidEndEditingNotification
|
||||
object: nil];
|
||||
[(NSFormCell *)editCell setTitle: [editField stringValue]];
|
||||
|
||||
/* Set the new title and resize the form to match the titles */
|
||||
[self makeSelectionVisible: NO];
|
||||
{
|
||||
float oldTitleWidth, titleWidth;
|
||||
NSRect oldFrame;
|
||||
oldTitleWidth = [(NSForm *)view titleWidth];
|
||||
[(NSFormCell *)editCell setTitle: [editField stringValue]];
|
||||
[(NSForm *)view calcSize];
|
||||
titleWidth = [(NSForm *)view titleWidth];
|
||||
NSLog(@"old width %f new %f", oldTitleWidth, titleWidth);
|
||||
oldFrame = frame = [view frame];
|
||||
frame.origin.x -= (titleWidth - oldTitleWidth);
|
||||
frame.size.width += (titleWidth - oldTitleWidth);
|
||||
[(NSForm *)view setEntryWidth: NSWidth(frame)];
|
||||
[(NSForm *)view setFrame: frame];
|
||||
frame = NSUnionRect(frame, oldFrame);
|
||||
}
|
||||
[edit_view removeSubview: editField];
|
||||
[edit_view displayRect: frame];
|
||||
[self makeSelectionVisible: YES];
|
||||
|
||||
RELEASE(editField);
|
||||
}
|
||||
|
|
|
@ -25,9 +25,10 @@ include $(GNUSTEP_MAKEFILES)/common.make
|
|||
|
||||
PALETTE_NAME = 2Controls
|
||||
2Controls_PALETTE_ICON = ControlsPalette
|
||||
2Controls_OBJC_FILES = main.m
|
||||
2Controls_OBJC_FILES = main.m inspectors.m
|
||||
2Controls_PRINCIPAL_CLASS = ControlsPalette
|
||||
2Controls_RESOURCE_FILES = ControlsPalette.tiff
|
||||
2Controls_RESOURCE_FILES = ControlsPalette.tiff \
|
||||
GormSliderInspector.gorm
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
|
|
78
Palettes/2Controls/GormSliderInspector.classes
Normal file
78
Palettes/2Controls/GormSliderInspector.classes
Normal file
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
GormSliderInspector = {
|
||||
Actions = (
|
||||
);
|
||||
Outlets = (
|
||||
knobField,
|
||||
numberOfTicks,
|
||||
snapToTicks,
|
||||
tickPosition,
|
||||
unitForm,
|
||||
valueForm,
|
||||
altForm
|
||||
);
|
||||
Super = IBInspector;
|
||||
};
|
||||
IBInspector = {
|
||||
Actions = (
|
||||
);
|
||||
Outlets = (
|
||||
okButton,
|
||||
revertButton,
|
||||
window
|
||||
);
|
||||
Super = NSObject;
|
||||
};
|
||||
NSApplication = {
|
||||
Outlets = (
|
||||
delegate
|
||||
);
|
||||
Super = NSResponder;
|
||||
};
|
||||
NSButton = {
|
||||
Super = NSControl;
|
||||
};
|
||||
NSControl = {
|
||||
Actions = (
|
||||
"takeDoubleValueFrom:",
|
||||
"takeFloatValueFrom:",
|
||||
"takeIntValueFrom:",
|
||||
"takeObjectValueFrom:",
|
||||
"takeStringValueFrom:"
|
||||
);
|
||||
Outlets = (
|
||||
target
|
||||
);
|
||||
Super = NSView;
|
||||
};
|
||||
NSMenu = {
|
||||
Super = NSObject;
|
||||
};
|
||||
NSMenuItem = {
|
||||
Outlets = (
|
||||
target
|
||||
);
|
||||
Super = NSObject;
|
||||
};
|
||||
NSResponder = {
|
||||
Super = NSObject;
|
||||
};
|
||||
NSSlider = {
|
||||
Super = NSControl;
|
||||
};
|
||||
NSTextField = {
|
||||
Outlets = (
|
||||
delegate
|
||||
);
|
||||
Super = NSControl;
|
||||
};
|
||||
NSView = {
|
||||
Super = NSResponder;
|
||||
};
|
||||
NSWindow = {
|
||||
Outlets = (
|
||||
delegate
|
||||
);
|
||||
Super = NSResponder;
|
||||
};
|
||||
}
|
BIN
Palettes/2Controls/GormSliderInspector.gorm
Normal file
BIN
Palettes/2Controls/GormSliderInspector.gorm
Normal file
Binary file not shown.
124
Palettes/2Controls/inspectors.m
Normal file
124
Palettes/2Controls/inspectors.m
Normal file
|
@ -0,0 +1,124 @@
|
|||
/* inspectors - Various inspectors for control elements
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: Aug 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.
|
||||
*/
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
#include "../../GormPrivate.h"
|
||||
|
||||
@implementation NSSlider (IBInspectorClassNames)
|
||||
- (NSString*) inspectorClassName
|
||||
{
|
||||
return @"GormSliderAttributesInspector";
|
||||
}
|
||||
|
||||
- (NSString*) sizeInspectorClassName
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface GormSliderAttributesInspector : IBInspector
|
||||
{
|
||||
id unitForm;
|
||||
id altForm;
|
||||
id numberOfTicks;
|
||||
id tickPosition;
|
||||
id snapToTicks;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormSliderAttributesInspector
|
||||
|
||||
- (void) _setValuesFromControl: control
|
||||
{
|
||||
if (control == unitForm)
|
||||
{
|
||||
[object setMinValue: [[control cellAtIndex: 0] doubleValue]];
|
||||
[object setDoubleValue: [[control cellAtIndex: 1] doubleValue]];
|
||||
[object setMaxValue: [[control cellAtIndex: 2] doubleValue]];
|
||||
}
|
||||
else if (control == altForm)
|
||||
{
|
||||
[[object cell] setAltIncrementValue:
|
||||
[[control cellAtIndex: 0] doubleValue]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) _getValuesFromObject: anObject
|
||||
{
|
||||
if (anObject != object)
|
||||
return;
|
||||
|
||||
[[unitForm cellAtIndex: 0] setDoubleValue: [anObject minValue]];
|
||||
[[unitForm cellAtIndex: 1] setDoubleValue: [anObject doubleValue]];
|
||||
[[unitForm cellAtIndex: 2] setDoubleValue: [anObject maxValue]];
|
||||
|
||||
[[altForm cellAtIndex: 2] setDoubleValue:
|
||||
[[anObject cell] altIncrementValue]];
|
||||
|
||||
}
|
||||
|
||||
- (void) controlTextDidEndEditing: (NSNotification*)aNotification
|
||||
{
|
||||
id notifier = [aNotification object];
|
||||
[self _setValuesFromControl: notifier];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
RELEASE(window);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ([super init] == nil)
|
||||
return nil;
|
||||
|
||||
if ([NSBundle loadNibNamed: @"GormSliderInspector" owner: self] == NO)
|
||||
{
|
||||
NSLog(@"Could not gorm GormSliderInspector");
|
||||
return nil;
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(controlTextDidEndEditing:)
|
||||
name: NSControlTextDidEndEditingNotification
|
||||
object: nil];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) ok: (id)sender
|
||||
{
|
||||
[self _setValuesFromControl: unitForm];
|
||||
[self _setValuesFromControl: altForm];
|
||||
}
|
||||
|
||||
- (void) setObject: (id)anObject
|
||||
{
|
||||
[super setObject: anObject];
|
||||
[self _getValuesFromObject: anObject];
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in a new issue