mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 09:21:00 +00:00
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:
parent
c51f88e0a8
commit
b5e5ca3ae4
2 changed files with 174 additions and 144 deletions
|
@ -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
|
* Source/NSBox.m: Tidied and added code to prevent attempts to set
|
||||||
contentview to negative dimensions.
|
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>
|
Wed Mar 10 12:56:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <gnustep/gui/config.h>
|
#include <gnustep/gui/config.h>
|
||||||
#include <Foundation/NSCoder.h>
|
#include <Foundation/NSCoder.h>
|
||||||
#include <Foundation/NSArray.h>
|
#include <Foundation/NSArray.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSProcessInfo.h>
|
#include <Foundation/NSProcessInfo.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSNotification.h>
|
#include <Foundation/NSNotification.h>
|
||||||
|
@ -67,7 +68,7 @@
|
||||||
// Class variables
|
// Class variables
|
||||||
static NSFont* menuFont = nil;
|
static NSFont* menuFont = nil;
|
||||||
|
|
||||||
- initWithFrame:(NSRect)rect
|
- (id) initWithFrame: (NSRect)rect
|
||||||
{
|
{
|
||||||
[super initWithFrame: rect];
|
[super initWithFrame: rect];
|
||||||
cells = [NSMutableArray new];
|
cells = [NSMutableArray new];
|
||||||
|
@ -91,11 +92,12 @@ static NSFont* menuFont = nil;
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone*)zone
|
- (id) copyWithZone: (NSZone*)zone
|
||||||
{
|
{
|
||||||
NSMenuMatrix* copy = [[isa alloc] initWithFrame:[self frame]];
|
NSMenuMatrix* copy = [[isa allocWithZone: zone] initWithFrame: [self frame]];
|
||||||
int i, count;
|
int i, count;
|
||||||
|
|
||||||
NSDebugLog (@"copy menu matrix of menu with title '%@'", [menu title]);
|
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 aCell = [cells objectAtIndex: i];
|
||||||
id cellCopy = [[aCell copyWithZone: zone] autorelease];
|
id cellCopy = [[aCell copyWithZone: zone] autorelease];
|
||||||
|
|
||||||
|
@ -104,7 +106,8 @@ static NSFont* menuFont = nil;
|
||||||
|
|
||||||
copy->cellSize = cellSize;
|
copy->cellSize = cellSize;
|
||||||
copy->menu = menu;
|
copy->menu = menu;
|
||||||
if (selectedCell) {
|
if (selectedCell)
|
||||||
|
{
|
||||||
int index = [cells indexOfObject: selectedCell];
|
int index = [cells indexOfObject: selectedCell];
|
||||||
|
|
||||||
copy->selectedCell = [[cells objectAtIndex: index] retain];
|
copy->selectedCell = [[cells objectAtIndex: index] retain];
|
||||||
|
@ -122,7 +125,8 @@ static NSFont* menuFont = nil;
|
||||||
/* Compute the new width of the menu cells matrix */
|
/* Compute the new width of the menu cells matrix */
|
||||||
cellSize.width = 0;
|
cellSize.width = 0;
|
||||||
count = [cells count];
|
count = [cells count];
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
titleWidth = [menuFont widthOfString:
|
titleWidth = [menuFont widthOfString:
|
||||||
[[cells objectAtIndex: i] stringValue]];
|
[[cells objectAtIndex: i] stringValue]];
|
||||||
cellSize.width = MAX(titleWidth + ADDITIONAL_WIDTH, cellSize.width);
|
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 */
|
/* Resize the frame to hold all the menu cells */
|
||||||
[super setFrameSize: NSMakeSize (cellSize.width,
|
[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
|
- (id <NSMenuItem>)insertItemWithTitle: (NSString*)aString
|
||||||
|
@ -143,8 +147,7 @@ static NSFont* menuFont = nil;
|
||||||
{
|
{
|
||||||
id menuCell = [[[NSMenu cellClass] new] autorelease];
|
id menuCell = [[[NSMenu cellClass] new] autorelease];
|
||||||
|
|
||||||
[menuCell setFont:menuFont]; // set font first in order to avoid
|
[menuCell setFont: menuFont];
|
||||||
// recalc of some cached params in xraw
|
|
||||||
[menuCell setTitle: aString];
|
[menuCell setTitle: aString];
|
||||||
[menuCell setAction: aSelector];
|
[menuCell setAction: aSelector];
|
||||||
[menuCell setKeyEquivalent: charCode];
|
[menuCell setKeyEquivalent: charCode];
|
||||||
|
@ -164,14 +167,18 @@ static NSFont* menuFont = nil;
|
||||||
[cells removeObjectAtIndex: row];
|
[cells removeObjectAtIndex: row];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*)itemArray { return cells; }
|
- (NSArray*) itemArray
|
||||||
|
{
|
||||||
|
return cells;
|
||||||
|
}
|
||||||
|
|
||||||
- (id <NSMenuItem>) itemWithTitle: (NSString*)aString
|
- (id <NSMenuItem>) itemWithTitle: (NSString*)aString
|
||||||
{
|
{
|
||||||
int i, count = [cells count];
|
unsigned i, count = [cells count];
|
||||||
id menuCell;
|
id menuCell;
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
menuCell = [cells objectAtIndex: i];
|
menuCell = [cells objectAtIndex: i];
|
||||||
if ([[menuCell title] isEqual: aString])
|
if ([[menuCell title] isEqual: aString])
|
||||||
return menuCell;
|
return menuCell;
|
||||||
|
@ -181,10 +188,11 @@ static NSFont* menuFont = nil;
|
||||||
|
|
||||||
- (id <NSMenuItem>) itemWithTag: (int)aTag
|
- (id <NSMenuItem>) itemWithTag: (int)aTag
|
||||||
{
|
{
|
||||||
int i, count = [cells count];
|
unsigned i, count = [cells count];
|
||||||
id menuCell;
|
id menuCell;
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
menuCell = [cells objectAtIndex: i];
|
menuCell = [cells objectAtIndex: i];
|
||||||
if ([menuCell tag] == aTag)
|
if ([menuCell tag] == aTag)
|
||||||
return menuCell;
|
return menuCell;
|
||||||
|
@ -194,10 +202,13 @@ static NSFont* menuFont = nil;
|
||||||
|
|
||||||
- (NSRect) cellFrameAtRow: (int)index
|
- (NSRect) cellFrameAtRow: (int)index
|
||||||
{
|
{
|
||||||
|
unsigned count = [cells count];
|
||||||
NSRect rect;
|
NSRect rect;
|
||||||
|
|
||||||
|
NSAssert(index >= 0 && index < count+1, @"invalid row coordinate");
|
||||||
|
|
||||||
rect.origin.x = 0;
|
rect.origin.x = 0;
|
||||||
rect.origin.y = ([cells count] - index - 1)
|
rect.origin.y = (count - index - 1)
|
||||||
* (cellSize.height + INTERCELL_SPACE);
|
* (cellSize.height + INTERCELL_SPACE);
|
||||||
rect.size = cellSize;
|
rect.size = cellSize;
|
||||||
|
|
||||||
|
@ -206,7 +217,7 @@ static NSFont* menuFont = nil;
|
||||||
|
|
||||||
- (void)drawRect: (NSRect)rect
|
- (void)drawRect: (NSRect)rect
|
||||||
{
|
{
|
||||||
int i, count = [cells count];
|
unsigned i, count = [cells count];
|
||||||
int max, howMany;
|
int max, howMany;
|
||||||
NSRect intRect = {{0, 0}, {0, 0}};
|
NSRect intRect = {{0, 0}, {0, 0}};
|
||||||
|
|
||||||
|
@ -218,7 +229,8 @@ static NSFont* menuFont = nil;
|
||||||
|
|
||||||
intRect.origin.y = (count - max) * (cellSize.height + INTERCELL_SPACE);
|
intRect.origin.y = (count - max) * (cellSize.height + INTERCELL_SPACE);
|
||||||
intRect.size = cellSize;
|
intRect.size = cellSize;
|
||||||
for (i = max - 1; howMany > 0; i--, howMany--) {
|
for (i = max - 1; howMany > 0; i--, howMany--)
|
||||||
|
{
|
||||||
id aCell = [cells objectAtIndex: i];
|
id aCell = [cells objectAtIndex: i];
|
||||||
|
|
||||||
[aCell drawWithFrame: intRect inView: self];
|
[aCell drawWithFrame: intRect inView: self];
|
||||||
|
@ -226,11 +238,30 @@ static NSFont* menuFont = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSSize)cellSize { return cellSize; }
|
- (NSSize) cellSize
|
||||||
- (void)setMenu:(NSMenu*)anObject { menu = anObject; }
|
{
|
||||||
- (void)setSelectedCell:(id)aCell { selectedCell = aCell; }
|
return cellSize;
|
||||||
- (id)selectedCell { return selectedCell; }
|
}
|
||||||
- (NSRect)selectedCellRect { return selectedCellRect; }
|
|
||||||
|
- (void) setMenu: (NSMenu*)anObject
|
||||||
|
{
|
||||||
|
menu = anObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setSelectedCell: (id)aCell
|
||||||
|
{
|
||||||
|
selectedCell = aCell;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) selectedCell
|
||||||
|
{
|
||||||
|
return selectedCell;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSRect) selectedCellRect
|
||||||
|
{
|
||||||
|
return selectedCellRect;
|
||||||
|
}
|
||||||
|
|
||||||
@end /* NSMenuMatrix */
|
@end /* NSMenuMatrix */
|
||||||
|
|
||||||
|
@ -272,7 +303,7 @@ static Class menuCellClass = nil;
|
||||||
return menuCellClass;
|
return menuCellClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
- init
|
- (id) init
|
||||||
{
|
{
|
||||||
return [self initWithTitle:
|
return [self initWithTitle:
|
||||||
[[[NSProcessInfo processInfo] processName] lastPathComponent]];
|
[[[NSProcessInfo processInfo] processName] lastPathComponent]];
|
||||||
|
@ -355,7 +386,7 @@ static Class menuCellClass = nil;
|
||||||
action: aSelector
|
action: aSelector
|
||||||
keyEquivalent: charCode
|
keyEquivalent: charCode
|
||||||
atIndex: index];
|
atIndex: index];
|
||||||
menuHasChanged = YES; // menu needs update
|
menuHasChanged = YES;
|
||||||
|
|
||||||
return menuCell;
|
return menuCell;
|
||||||
}
|
}
|
||||||
|
@ -363,7 +394,7 @@ static Class menuCellClass = nil;
|
||||||
- (void) removeItem: (id <NSMenuItem>)anItem
|
- (void) removeItem: (id <NSMenuItem>)anItem
|
||||||
{
|
{
|
||||||
[menuCells removeItem: anItem];
|
[menuCells removeItem: anItem];
|
||||||
menuHasChanged = YES; // menu needs update
|
menuHasChanged = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*) itemArray
|
- (NSArray*) itemArray
|
||||||
|
@ -390,10 +421,7 @@ static Class menuCellClass = nil;
|
||||||
if (aMenu)
|
if (aMenu)
|
||||||
aMenu->supermenu = self;
|
aMenu->supermenu = self;
|
||||||
|
|
||||||
[itemTitle retain];
|
ASSIGN(aMenu->title, itemTitle);
|
||||||
// [aMenu->title release];
|
|
||||||
aMenu->title = itemTitle;
|
|
||||||
|
|
||||||
[self _menuChanged];
|
[self _menuChanged];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue