apps-gorm/GormViewSizeInspector.m
Pierre-Yves Rivaille 582b406902 * GNUMakefile: added GormViewSizeInspector.m, GormGenericEditor.m
and GormImageEditor.m.
* GormGenericEditor.m: new abstract superclass of GormObjectEditor,
  GormImageEditor and GormSoundEditor.
* GormImageEditor.m: new class to deal with Images.
* GormSoundEditor.m: refactored code with GormGenericEditor,
  now looks like GormImageEditor.m
* GomCustomClassInspector.m: rewrote parts to stop using notification
  and use changeObject: method instead.
* Gorm.m, Gorm.h, GormPrivate.h, GormDocument.h, GormDocument.m:
  changes to accomodate new Image & Sound code.
* GormViewSizeInspector.m: new file. Contains code moved from
  GormObjectEditor.m.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@15013 72102866-910b-0410-8b05-ffd578937521
2002-11-18 20:54:26 +00:00

263 lines
6.9 KiB
Objective-C

/* GormViewSizeInspector.m
*
* Copyright (C) 1999 Free Software Foundation, Inc.
*
* Author: Richard Frith-Macdonald <richard@brainstrom.co.uk>
* Date: 1999
*
* 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 "GormPrivate.h"
@implementation NSView (GormInspectors)
- (NSString*) sizeInspectorClassName
{
return @"GormViewSizeInspector";
}
- (NSString*) customClassInspector
{
return @"GormCustomClassInspector";
}
@end
@interface GormViewSizeInspector : IBInspector
{
NSButton *top;
NSButton *bottom;
NSButton *left;
NSButton *right;
NSButton *width;
NSButton *height;
NSForm *sizeForm;
}
@end
@implementation GormViewSizeInspector
NSImage *eHCoil = nil;
NSImage *eVCoil = nil;
NSImage *eHLine = nil;
NSImage *eVLine = nil;
NSImage *mHCoil = nil;
NSImage *mVCoil = nil;
NSImage *mHLine = nil;
NSImage *mVLine = nil;
+ (void) initialize
{
if (self == [GormViewSizeInspector class])
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path;
path = [bundle pathForImageResource: @"GormEHCoil"];
eHCoil = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormEVCoil"];
eVCoil = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormEHLine"];
eHLine = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormEVLine"];
eVLine = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormMHCoil"];
mHCoil = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormMVCoil"];
mVCoil = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormMHLine"];
mHLine = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormMVLine"];
mVLine = [[NSImage alloc] initWithContentsOfFile: path];
}
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
RELEASE(window);
[super dealloc];
}
- (id) init
{
self = [super init];
if (self != nil)
{
if ([NSBundle loadNibNamed: @"GormViewSizeInspector"
owner: self] == NO)
{
NSDictionary *table;
NSBundle *bundle;
table = [NSDictionary dictionaryWithObject: self
forKey: @"NSOwner"];
bundle = [NSBundle mainBundle];
if ( [bundle loadNibFile: @"GormViewSizeInspector"
externalNameTable: table
withZone: [self zone]] == NO)
{
NSLog(@"Could not open gorm GormViewSizeInspector");
NSLog(@"self %@", self);
return nil;
}
}
[top setTag: NSViewMaxYMargin];
[bottom setTag: NSViewMinYMargin];
[right setTag: NSViewMaxXMargin];
[left setTag: NSViewMinXMargin];
[width setTag: NSViewWidthSizable];
[height setTag: NSViewHeightSizable];
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(viewFrameChangeNotification:)
name: NSViewFrameDidChangeNotification
object: nil];
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(controlTextDidEndEditing:)
name: NSControlTextDidEndEditingNotification
object: nil];
}
return self;
}
- (void) _setValuesFromControl: control
{
if (control == sizeForm)
{
NSRect rect;
rect = NSMakeRect([[control cellAtIndex: 0] floatValue],
[[control cellAtIndex: 1] floatValue],
[[control cellAtIndex: 2] floatValue],
[[control cellAtIndex: 3] floatValue]);
if (NSEqualRects(rect, [object frame]) == NO)
{
NSRect oldFrame = [object frame];
[object setFrame: rect];
[object display];
if ([object superview])
[[object superview] displayRect:
GormExtBoundsForRect(oldFrame)];
[[object superview] lockFocus];
GormDrawKnobsForRect([object frame]);
GormShowFastKnobFills();
[[object superview] unlockFocus];
[[object window] flushWindow];
}
}
}
- (void) _getValuesFromObject: anObject
{
NSRect frame;
if (anObject != object)
return;
frame = [anObject frame];
[[sizeForm cellAtIndex: 0] setFloatValue: NSMinX(frame)];
[[sizeForm cellAtIndex: 1] setFloatValue: NSMinY(frame)];
[[sizeForm cellAtIndex: 2] setFloatValue: NSWidth(frame)];
[[sizeForm cellAtIndex: 3] setFloatValue: NSHeight(frame)];
}
- (void) controlTextDidEndEditing: (NSNotification*)aNotification
{
id notifier = [aNotification object];
[self _setValuesFromControl: notifier];
}
- (void) viewFrameChangeNotification: (NSNotification*)aNotification
{
id notifier = [aNotification object];
[self _getValuesFromObject: notifier];
}
- (void) setAutosize: (id)sender
{
unsigned mask = [sender tag];
if ([sender state] == NSOnState)
{
mask = [object autoresizingMask] | mask;
}
else
{
mask = [object autoresizingMask] & ~mask;
}
[object setAutoresizingMask: mask];
}
- (void) setObject: (id)anObject
{
if ((object != nil) && (anObject != object))
[object setPostsFrameChangedNotifications: NO];
if (anObject != nil && anObject != object)
{
NSRect frame;
unsigned mask = [anObject autoresizingMask];
ASSIGN(object, anObject);
if (mask & NSViewMaxYMargin)
[top setState: NSOnState];
else
[top setState: NSOffState];
if (mask & NSViewMinYMargin)
[bottom setState: NSOnState];
else
[bottom setState: NSOffState];
if (mask & NSViewMaxXMargin)
[right setState: NSOnState];
else
[right setState: NSOffState];
if (mask & NSViewMinXMargin)
[left setState: NSOnState];
else
[left setState: NSOffState];
if (mask & NSViewWidthSizable)
[width setState: NSOnState];
else
[width setState: NSOffState];
if (mask & NSViewHeightSizable)
[height setState: NSOnState];
else
[height setState: NSOffState];
frame = [anObject frame];
[[sizeForm cellAtIndex: 0] setFloatValue: NSMinX(frame)];
[[sizeForm cellAtIndex: 1] setFloatValue: NSMinY(frame)];
[[sizeForm cellAtIndex: 2] setFloatValue: NSWidth(frame)];
[[sizeForm cellAtIndex: 3] setFloatValue: NSHeight(frame)];
[anObject setPostsFrameChangedNotifications: YES];
}
}
@end