mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-24 20:11:20 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@21777 72102866-910b-0410-8b05-ffd578937521
217 lines
5.3 KiB
Objective-C
217 lines
5.3 KiB
Objective-C
/*
|
|
GormWindowSizeInspector.m
|
|
|
|
Copyright (C) 1999-2005 Free Software Foundation, Inc.
|
|
|
|
Author: Richard frith-Macdonald (richard@brainstorm.co.uk>
|
|
Date: 1999
|
|
Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
|
Date: 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.
|
|
*/
|
|
|
|
/*
|
|
July 2005 : Split inspector classes into separate files.
|
|
Always use ok: revert: methods
|
|
Clean up
|
|
Author : Fabien Vallon <fabien@sonappart.net>
|
|
*/
|
|
|
|
#include "GormWindowSizeInspector.h"
|
|
|
|
#include <Foundation/NSNotification.h>
|
|
|
|
#include <GNUstepGUI/GSNibTemplates.h>
|
|
#include <AppKit/NSButton.h>
|
|
#include <AppKit/NSForm.h>
|
|
#include <AppKit/NSNibLoading.h>
|
|
#include <AppKit/NSPanel.h>
|
|
#include <AppKit/NSWindow.h>
|
|
|
|
|
|
/*
|
|
IBObjectAdditions category for NSPanel
|
|
*/
|
|
@implementation NSPanel (IBObjectAdditionsSize)
|
|
- (NSString*) sizeInspectorClassName
|
|
{
|
|
return @"GormWindowSizeInspector";
|
|
}
|
|
@end
|
|
|
|
/*
|
|
IBObjectAdditions category for NSWindow
|
|
*/
|
|
@implementation NSWindow (IBObjectAdditionsSize)
|
|
- (NSString*) sizeInspectorClassName
|
|
{
|
|
return @"GormWindowSizeInspector";
|
|
}
|
|
@end
|
|
|
|
@implementation GormWindowSizeInspector
|
|
|
|
- (id) init
|
|
{
|
|
if ([super init] == nil)
|
|
return nil;
|
|
|
|
if ([NSBundle loadNibNamed: @"GormNSWindowSizeInspector" owner: self] == NO)
|
|
{
|
|
NSLog(@"Could not gorm GormNSWindowSizeInspector");
|
|
return nil;
|
|
}
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
addObserver: self
|
|
selector: @selector(windowChangeNotification:)
|
|
name: NSWindowDidMoveNotification
|
|
object: object];
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
addObserver: self
|
|
selector: @selector(windowChangeNotification:)
|
|
name: NSWindowDidResizeNotification
|
|
object: object];
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void) setObject: (id)obj
|
|
{
|
|
[super setObject: obj];
|
|
|
|
// set up tags...
|
|
[top setTag: GSWindowMaxYMargin];
|
|
[bottom setTag: GSWindowMinYMargin];
|
|
[left setTag: GSWindowMinXMargin];
|
|
[right setTag: GSWindowMaxXMargin];
|
|
}
|
|
|
|
|
|
/* Commit changes that the user makes in the Window Size Inspector */
|
|
- (void) ok: (id)sender
|
|
{
|
|
/* Size */
|
|
if (sender == sizeForm)
|
|
{
|
|
NSRect rect;
|
|
rect = NSMakeRect([[sender cellAtIndex: 0] floatValue],
|
|
[[sender cellAtIndex: 1] floatValue],
|
|
[[sender cellAtIndex: 2] floatValue],
|
|
[[sender cellAtIndex: 3] floatValue]);
|
|
|
|
[object setFrame: rect display: YES];
|
|
}
|
|
/* Min Size */
|
|
else if (sender == minForm)
|
|
{
|
|
NSSize size;
|
|
size = NSMakeSize([[minForm cellAtIndex: 0] floatValue],
|
|
[[minForm cellAtIndex: 1] floatValue]);
|
|
[object setMinSize: size];
|
|
}
|
|
/* Max Size */
|
|
else if (sender == maxForm)
|
|
{
|
|
NSSize size;
|
|
size = NSMakeSize([[maxForm cellAtIndex: 0] floatValue],
|
|
[[maxForm cellAtIndex: 1] floatValue]);
|
|
[object setMaxSize: size];
|
|
}
|
|
|
|
/* AutoPosition */
|
|
else if ( sender == top || sender == bottom ||
|
|
sender == left || sender == right )
|
|
{
|
|
unsigned mask = [sender tag];
|
|
if ([sender state] == NSOnState)
|
|
{
|
|
mask = [object autoPositionMask] | mask;
|
|
}
|
|
else
|
|
{
|
|
mask = [object autoPositionMask] & ~mask;
|
|
}
|
|
[object setAutoPositionMask: mask];
|
|
}
|
|
|
|
[super ok: sender];
|
|
}
|
|
|
|
/* Sync from object ( NSWindow ) changes to the inspector */
|
|
- (void) revert:(id)sender
|
|
{
|
|
NSRect frame;
|
|
NSSize size;
|
|
unsigned int mask;
|
|
|
|
if ( object == nil )
|
|
return;
|
|
|
|
mask = [object autoPositionMask];
|
|
|
|
frame = [object 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)];
|
|
|
|
size = [object minSize];
|
|
[[minForm cellAtIndex: 0] setFloatValue: size.width];
|
|
[[minForm cellAtIndex: 1] setFloatValue: size.height];
|
|
|
|
size = [object maxSize];
|
|
[[maxForm cellAtIndex: 0] setFloatValue: size.width];
|
|
[[maxForm cellAtIndex: 1] setFloatValue: size.height];
|
|
|
|
if (mask & GSWindowMaxYMargin)
|
|
[top setState: NSOnState];
|
|
else
|
|
[top setState: NSOffState];
|
|
|
|
if (mask & GSWindowMinYMargin)
|
|
[bottom setState: NSOnState];
|
|
else
|
|
[bottom setState: NSOffState];
|
|
|
|
if (mask & GSWindowMaxXMargin)
|
|
[right setState: NSOnState];
|
|
else
|
|
[right setState: NSOffState];
|
|
|
|
if (mask & GSWindowMinXMargin)
|
|
[left setState: NSOnState];
|
|
else
|
|
[left setState: NSOffState];
|
|
|
|
[super revert:object];
|
|
}
|
|
|
|
- (void) windowChangeNotification: (NSNotification*)aNotification
|
|
{
|
|
[self ok: [aNotification object]];
|
|
}
|
|
|
|
|
|
/* Delegate for textFields / Forms */
|
|
- (void)controlTextDidChange:(NSNotification *)aNotification
|
|
{
|
|
[self ok: [aNotification object]];
|
|
}
|
|
@end
|