2005-08-06 17:59:08 +00:00
|
|
|
/*
|
|
|
|
GormMatrixdAttributesInspector.m
|
|
|
|
|
|
|
|
Copyright (C) 2001-2005 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Adam Fedor <fedor@gnu.org>
|
|
|
|
Laurent Julliard <laurent@julliard-online.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
|
2007-11-05 23:44:36 +00:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2005-08-06 17:59:08 +00:00
|
|
|
(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>
|
|
|
|
*/
|
|
|
|
|
2019-11-03 01:57:39 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#include <AppKit/AppKit.h>
|
2005-08-06 17:59:08 +00:00
|
|
|
|
2019-11-03 01:57:39 +00:00
|
|
|
#include <GormCore/GormCore.h>
|
2005-08-06 17:59:08 +00:00
|
|
|
|
2019-11-03 01:57:39 +00:00
|
|
|
#include "GormMatrixAttributesInspector.h"
|
2005-08-06 17:59:08 +00:00
|
|
|
|
|
|
|
|
2020-01-10 08:52:30 +00:00
|
|
|
#include <InterfaceBuilder/IBApplicationAdditions.h>
|
|
|
|
#include <GormCore/GormViewKnobs.h>
|
2005-08-06 17:59:08 +00:00
|
|
|
|
|
|
|
@implementation NSMatrix (IBObjectAdditions)
|
|
|
|
- (NSString*) inspectorClassName
|
|
|
|
{
|
|
|
|
return @"GormMatrixAttributesInspector";
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormMatrixAttributesInspector
|
|
|
|
|
2014-05-27 07:27:32 +00:00
|
|
|
NSUInteger rowsStepperValue;
|
|
|
|
NSUInteger colsStepperValue;
|
|
|
|
|
2020-01-10 16:44:27 +00:00
|
|
|
- (void) _displayObject: (id)obj resize: (BOOL)resize
|
2020-01-10 08:52:30 +00:00
|
|
|
{
|
|
|
|
id document = [(id<IB>)NSApp documentForObject: obj];
|
|
|
|
id editor = [document editorForObject: obj create: NO];
|
|
|
|
NSRect eoFrame = [editor frame];
|
|
|
|
|
2020-01-10 16:44:27 +00:00
|
|
|
if (resize == NO)
|
|
|
|
{
|
|
|
|
NSRect rect = [obj frame];
|
|
|
|
NSSize cell = [obj cellSize];
|
|
|
|
NSSize inter = [obj intercellSpacing];
|
|
|
|
cell.width = (rect.size.width + inter.width) / colsStepperValue - inter.width;
|
|
|
|
cell.height = (rect.size.height + inter.height) / rowsStepperValue - inter.height;
|
|
|
|
[object setCellSize: cell];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[obj sizeToCells];
|
|
|
|
}
|
2020-01-10 08:52:30 +00:00
|
|
|
[obj setNeedsDisplay: YES];
|
|
|
|
[[editor superview] setNeedsDisplayInRect: GormExtBoundsForRect(eoFrame)];
|
|
|
|
}
|
|
|
|
|
2005-08-06 17:59:08 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ([super init] == nil)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
if ([NSBundle loadNibNamed: @"GormNSMatrixInspector" owner: self] == NO)
|
|
|
|
{
|
|
|
|
NSLog(@"Could not gorm GormMatrixInspector");
|
|
|
|
return nil;
|
|
|
|
}
|
2014-05-27 07:27:32 +00:00
|
|
|
/* It shouldn't break functionality of rows/columns number
|
|
|
|
changing if someone will decide in the future to change
|
|
|
|
the values of the corresponding steppers in the gorm file.
|
|
|
|
So we stores those values from the gorm file in the auxillary
|
|
|
|
variables to use its later in -[ok:].
|
|
|
|
(It allows us to avoid the values being hardcoded).
|
|
|
|
*/
|
|
|
|
rowsStepperValue = [rowsStepper intValue];
|
|
|
|
colsStepperValue = [colsStepper intValue];
|
2005-08-06 17:59:08 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Commit changes that the user makes in the Attributes Inspector */
|
|
|
|
- (void) ok: (id) sender
|
|
|
|
{
|
|
|
|
if (sender == autosizeSwitch)
|
|
|
|
{
|
|
|
|
[object setAutosizesCells: ([sender state] == NSOnState)];
|
|
|
|
}
|
|
|
|
else if (sender == autotagSwitch)
|
|
|
|
{
|
2013-01-30 12:43:27 +00:00
|
|
|
NSInteger rows;
|
|
|
|
NSInteger cols;
|
2005-08-06 17:59:08 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
[object getNumberOfRows: &rows columns: &cols];
|
|
|
|
|
|
|
|
if ((rows == 1) && (cols > 1))
|
|
|
|
{
|
|
|
|
for (i = 0; i < cols; i++)
|
|
|
|
{
|
|
|
|
[[object cellAtRow:0 column:i] setTag: i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((rows > 1) && (cols ==1))
|
|
|
|
{
|
|
|
|
for (i = 0; i < rows; i++)
|
|
|
|
{
|
|
|
|
[[object cellAtRow:i column:0] setTag: i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sender == backgroundColorWell)
|
|
|
|
{
|
|
|
|
[object setBackgroundColor: [sender color]];
|
|
|
|
}
|
|
|
|
else if (sender == drawsBackgroundSwitch)
|
|
|
|
{
|
|
|
|
[object setDrawsBackground: ([sender state] == NSOnState)];
|
|
|
|
}
|
|
|
|
else if (sender == modeMatrix)
|
|
|
|
{
|
|
|
|
[(NSMatrix *)object setMode: [[sender selectedCell] tag]];
|
|
|
|
}
|
|
|
|
else if (sender == propagateSwitch)
|
|
|
|
{
|
2020-01-08 16:41:12 +00:00
|
|
|
NSButtonCell *cell;
|
|
|
|
NSInteger tag;
|
|
|
|
NSString *title;
|
2020-01-16 23:01:14 +00:00
|
|
|
int c;
|
|
|
|
for (c = 0; c < [object numberOfColumns]; c++)
|
2020-01-05 01:20:17 +00:00
|
|
|
{
|
2020-01-16 23:01:14 +00:00
|
|
|
int r;
|
|
|
|
for (r = 0; r < [object numberOfRows]; r++)
|
2020-01-05 01:20:17 +00:00
|
|
|
{
|
2020-01-08 16:41:12 +00:00
|
|
|
cell = [object cellAtRow: r column: c];
|
|
|
|
tag = [cell tag];
|
|
|
|
title = [cell title];
|
|
|
|
cell = [[object prototype] copy];
|
|
|
|
[cell setTag: tag];
|
|
|
|
[cell setTitle: title];
|
|
|
|
[object putCell:cell atRow:r column:c];
|
|
|
|
[cell release];
|
|
|
|
}
|
2020-01-05 01:20:17 +00:00
|
|
|
}
|
2020-01-05 01:53:41 +00:00
|
|
|
[object deselectAllCells];
|
|
|
|
[object selectCellAtRow: 0 column: 0];
|
2005-08-06 17:59:08 +00:00
|
|
|
}
|
|
|
|
else if (sender == selRectSwitch)
|
|
|
|
{
|
|
|
|
[object setSelectionByRect: ([sender state] == NSOnState)];
|
|
|
|
}
|
|
|
|
else if (sender == tagForm)
|
|
|
|
{
|
|
|
|
[object setTag: [[sender cellAtIndex: 0] intValue]];
|
|
|
|
}
|
2020-01-10 16:44:27 +00:00
|
|
|
else if (sender == rowsForm || sender == colsForm)
|
2014-05-27 07:27:32 +00:00
|
|
|
{
|
2020-01-10 16:44:27 +00:00
|
|
|
int rows = [[rowsForm cellAtIndex: 0] intValue];
|
|
|
|
int cols = [[colsForm cellAtIndex: 0] intValue];
|
2014-05-27 07:27:32 +00:00
|
|
|
int num;
|
|
|
|
|
|
|
|
while((num = [object numberOfRows]) != rows)
|
|
|
|
{
|
|
|
|
if(num > rows)
|
|
|
|
{
|
|
|
|
[object removeRow: num - 1]; // remove last row
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[object addRow];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while((num = [object numberOfColumns]) != cols)
|
|
|
|
{
|
|
|
|
if(num > cols)
|
|
|
|
{
|
|
|
|
[object removeColumn: num - 1]; // remove last column
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[object addColumn];
|
|
|
|
}
|
|
|
|
}
|
2020-01-10 16:44:27 +00:00
|
|
|
[self _displayObject: object resize: YES];
|
2014-05-27 07:27:32 +00:00
|
|
|
}
|
|
|
|
else if(sender == rowsStepper)
|
|
|
|
{
|
|
|
|
int delta = [sender intValue] - rowsStepperValue;
|
|
|
|
int num = [object numberOfRows];
|
|
|
|
|
|
|
|
while(delta > 0)
|
|
|
|
{
|
|
|
|
[object addRow];
|
|
|
|
delta--;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
while((delta < 0) && (num > 1))
|
|
|
|
{
|
|
|
|
[object removeRow: num - 1];
|
|
|
|
num--;
|
|
|
|
delta++;
|
|
|
|
}
|
2020-01-10 16:44:27 +00:00
|
|
|
[[rowsForm cellAtIndex: 0] setIntValue: num];
|
|
|
|
[sender setIntValue: num];
|
|
|
|
rowsStepperValue = num;
|
|
|
|
[self _displayObject: object resize: YES];
|
2014-05-27 07:27:32 +00:00
|
|
|
}
|
|
|
|
else if(sender == colsStepper)
|
|
|
|
{
|
|
|
|
int delta = [sender intValue] - colsStepperValue;
|
|
|
|
int num = [object numberOfColumns];
|
|
|
|
|
|
|
|
while(delta > 0)
|
|
|
|
{
|
|
|
|
[object addColumn];
|
|
|
|
delta--;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
while((delta < 0) && (num > 1))
|
|
|
|
{
|
|
|
|
[object removeColumn: num - 1];
|
|
|
|
num--;
|
|
|
|
delta++;
|
|
|
|
}
|
2020-01-10 16:44:27 +00:00
|
|
|
[[colsForm cellAtIndex: 0] setIntValue: num];
|
|
|
|
[sender setIntValue: num];
|
|
|
|
colsStepperValue = num;
|
|
|
|
[self _displayObject: object resize: YES];
|
2014-05-27 07:27:32 +00:00
|
|
|
}
|
2005-08-06 17:59:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypeMatrix
|
|
|
|
* If prototype cell is set show it else show a matrix cell
|
|
|
|
*/
|
|
|
|
if ([object prototype] == nil)
|
|
|
|
{
|
|
|
|
[prototypeMatrix putCell: [object cellAtRow:0 column:0] atRow:0 column:0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-05 01:20:17 +00:00
|
|
|
[prototypeMatrix putCell: [object prototype] atRow:0 column:0];
|
2005-08-06 17:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[super ok:sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Sync from object ( NSMatrix ) changes to the inspector */
|
|
|
|
- (void) revert:(id)sender
|
|
|
|
{
|
|
|
|
if (object == nil)
|
|
|
|
return;
|
|
|
|
|
|
|
|
[autosizeSwitch setState:
|
|
|
|
([object autosizesCells]) ? NSOnState : NSOffState];
|
|
|
|
|
|
|
|
{
|
2013-01-30 12:43:27 +00:00
|
|
|
NSInteger rows;
|
|
|
|
NSInteger cols;
|
2005-08-06 17:59:08 +00:00
|
|
|
|
|
|
|
[object getNumberOfRows: &rows columns: &cols];
|
|
|
|
|
|
|
|
if ((rows == 1 && cols > 1) || (cols == 1 && rows > 1))
|
|
|
|
[autotagSwitch setEnabled: YES];
|
|
|
|
else
|
|
|
|
[autotagSwitch setEnabled: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
[backgroundColorWell setColorWithoutAction: [object backgroundColor]];
|
|
|
|
[drawsBackgroundSwitch setState:
|
2020-01-05 01:20:17 +00:00
|
|
|
([object drawsBackground]) ? NSOnState : NSOffState];
|
2005-08-06 17:59:08 +00:00
|
|
|
|
|
|
|
[modeMatrix selectCellWithTag: [(NSMatrix *)object mode]];
|
|
|
|
|
2020-01-05 01:20:17 +00:00
|
|
|
if ([object prototype] == nil)
|
|
|
|
[prototypeMatrix putCell: [object cellAtRow:0 column:0] atRow:0 column:0];
|
|
|
|
else
|
|
|
|
[prototypeMatrix putCell: [object prototype] atRow:0 column:0];
|
|
|
|
|
2005-08-06 17:59:08 +00:00
|
|
|
[selRectSwitch setState:
|
|
|
|
([object isSelectionByRect]) ? NSOnState : NSOffState];
|
|
|
|
[[tagForm cellAtIndex: 0] setIntValue: [object tag]];
|
2020-01-10 16:44:27 +00:00
|
|
|
rowsStepperValue = [object numberOfRows];
|
|
|
|
[[rowsForm cellAtIndex: 0] setIntValue: rowsStepperValue];
|
|
|
|
[rowsStepper setIntValue: rowsStepperValue];
|
|
|
|
colsStepperValue = [object numberOfColumns];
|
|
|
|
[[colsForm cellAtIndex: 0] setIntValue: colsStepperValue];
|
|
|
|
[colsStepper setIntValue: colsStepperValue];
|
2005-08-06 17:59:08 +00:00
|
|
|
|
|
|
|
[super revert:sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* delegate method for tag Form */
|
2020-01-09 01:15:50 +00:00
|
|
|
- (void) controlTextDidEndEditing: (NSNotification*)aNotification
|
2005-08-06 17:59:08 +00:00
|
|
|
{
|
|
|
|
[self ok:[aNotification object]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|