Added some dimensions checking

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3899 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-03-11 12:34:04 +00:00
parent c51f88e0a8
commit b5e5ca3ae4
2 changed files with 174 additions and 144 deletions

View file

@ -1,7 +1,9 @@
Thu Mar 11 11:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Thu Mar 11 11:57:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSBox.m: Tidied and added code to prevent attempts to set
contentview to negative dimensions.
* Source/NSMenu.m: Tidied and added code to prevent attempts to set
mwnu matrix frame to negative dimensions.
Wed Mar 10 12:56:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>

View file

@ -28,6 +28,7 @@
#include <gnustep/gui/config.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSException.h>
#include <Foundation/NSProcessInfo.h>
#include <Foundation/NSString.h>
#include <Foundation/NSNotification.h>
@ -67,7 +68,7 @@
// Class variables
static NSFont* menuFont = nil;
- initWithFrame:(NSRect)rect
- (id) initWithFrame: (NSRect)rect
{
[super initWithFrame: rect];
cells = [NSMutableArray new];
@ -91,11 +92,12 @@ static NSFont* menuFont = nil;
- (id) copyWithZone: (NSZone*)zone
{
NSMenuMatrix* copy = [[isa alloc] initWithFrame:[self frame]];
NSMenuMatrix* copy = [[isa allocWithZone: zone] initWithFrame: [self frame]];
int i, count;
NSDebugLog (@"copy menu matrix of menu with title '%@'", [menu title]);
for (i = 0, count = [cells count]; i < count; i++) {
for (i = 0, count = [cells count]; i < count; i++)
{
id aCell = [cells objectAtIndex: i];
id cellCopy = [[aCell copyWithZone: zone] autorelease];
@ -104,7 +106,8 @@ static NSFont* menuFont = nil;
copy->cellSize = cellSize;
copy->menu = menu;
if (selectedCell) {
if (selectedCell)
{
int index = [cells indexOfObject: selectedCell];
copy->selectedCell = [[cells objectAtIndex: index] retain];
@ -122,7 +125,8 @@ static NSFont* menuFont = nil;
/* Compute the new width of the menu cells matrix */
cellSize.width = 0;
count = [cells count];
for (i = 0; i < count; i++) {
for (i = 0; i < count; i++)
{
titleWidth = [menuFont widthOfString:
[[cells objectAtIndex: i] stringValue]];
cellSize.width = MAX(titleWidth + ADDITIONAL_WIDTH, cellSize.width);
@ -133,7 +137,7 @@ static NSFont* menuFont = nil;
/* Resize the frame to hold all the menu cells */
[super setFrameSize: NSMakeSize (cellSize.width,
(cellSize.height + INTERCELL_SPACE) * [cells count] - INTERCELL_SPACE)];
count ? (cellSize.height + INTERCELL_SPACE)*count - INTERCELL_SPACE : 0)];
}
- (id <NSMenuItem>)insertItemWithTitle: (NSString*)aString
@ -143,8 +147,7 @@ static NSFont* menuFont = nil;
{
id menuCell = [[[NSMenu cellClass] new] autorelease];
[menuCell setFont:menuFont]; // set font first in order to avoid
// recalc of some cached params in xraw
[menuCell setFont: menuFont];
[menuCell setTitle: aString];
[menuCell setAction: aSelector];
[menuCell setKeyEquivalent: charCode];
@ -164,14 +167,18 @@ static NSFont* menuFont = nil;
[cells removeObjectAtIndex: row];
}
- (NSArray*)itemArray { return cells; }
- (NSArray*) itemArray
{
return cells;
}
- (id <NSMenuItem>) itemWithTitle: (NSString*)aString
{
int i, count = [cells count];
unsigned i, count = [cells count];
id menuCell;
for (i = 0; i < count; i++) {
for (i = 0; i < count; i++)
{
menuCell = [cells objectAtIndex: i];
if ([[menuCell title] isEqual: aString])
return menuCell;
@ -181,10 +188,11 @@ static NSFont* menuFont = nil;
- (id <NSMenuItem>) itemWithTag: (int)aTag
{
int i, count = [cells count];
unsigned i, count = [cells count];
id menuCell;
for (i = 0; i < count; i++) {
for (i = 0; i < count; i++)
{
menuCell = [cells objectAtIndex: i];
if ([menuCell tag] == aTag)
return menuCell;
@ -194,10 +202,13 @@ static NSFont* menuFont = nil;
- (NSRect) cellFrameAtRow: (int)index
{
unsigned count = [cells count];
NSRect rect;
NSAssert(index >= 0 && index < count+1, @"invalid row coordinate");
rect.origin.x = 0;
rect.origin.y = ([cells count] - index - 1)
rect.origin.y = (count - index - 1)
* (cellSize.height + INTERCELL_SPACE);
rect.size = cellSize;
@ -206,7 +217,7 @@ static NSFont* menuFont = nil;
- (void)drawRect: (NSRect)rect
{
int i, count = [cells count];
unsigned i, count = [cells count];
int max, howMany;
NSRect intRect = {{0, 0}, {0, 0}};
@ -218,7 +229,8 @@ static NSFont* menuFont = nil;
intRect.origin.y = (count - max) * (cellSize.height + INTERCELL_SPACE);
intRect.size = cellSize;
for (i = max - 1; howMany > 0; i--, howMany--) {
for (i = max - 1; howMany > 0; i--, howMany--)
{
id aCell = [cells objectAtIndex: i];
[aCell drawWithFrame: intRect inView: self];
@ -226,11 +238,30 @@ static NSFont* menuFont = nil;
}
}
- (NSSize)cellSize { return cellSize; }
- (void)setMenu:(NSMenu*)anObject { menu = anObject; }
- (void)setSelectedCell:(id)aCell { selectedCell = aCell; }
- (id)selectedCell { return selectedCell; }
- (NSRect)selectedCellRect { return selectedCellRect; }
- (NSSize) cellSize
{
return cellSize;
}
- (void) setMenu: (NSMenu*)anObject
{
menu = anObject;
}
- (void) setSelectedCell: (id)aCell
{
selectedCell = aCell;
}
- (id) selectedCell
{
return selectedCell;
}
- (NSRect) selectedCellRect
{
return selectedCellRect;
}
@end /* NSMenuMatrix */
@ -272,7 +303,7 @@ static Class menuCellClass = nil;
return menuCellClass;
}
- init
- (id) init
{
return [self initWithTitle:
[[[NSProcessInfo processInfo] processName] lastPathComponent]];
@ -355,7 +386,7 @@ static Class menuCellClass = nil;
action: aSelector
keyEquivalent: charCode
atIndex: index];
menuHasChanged = YES; // menu needs update
menuHasChanged = YES;
return menuCell;
}
@ -363,7 +394,7 @@ static Class menuCellClass = nil;
- (void) removeItem: (id <NSMenuItem>)anItem
{
[menuCells removeItem: anItem];
menuHasChanged = YES; // menu needs update
menuHasChanged = YES;
}
- (NSArray*) itemArray
@ -390,10 +421,7 @@ static Class menuCellClass = nil;
if (aMenu)
aMenu->supermenu = self;
[itemTitle retain];
// [aMenu->title release];
aMenu->title = itemTitle;
ASSIGN(aMenu->title, itemTitle);
[self _menuChanged];
}