mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 17:10:37 +00:00
Added suport for model loading.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@2665 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e46ccd1acf
commit
07252e51bb
33 changed files with 2684 additions and 43 deletions
|
@ -47,9 +47,8 @@
|
|||
#ifdef MAX
|
||||
# undef MAX
|
||||
#endif
|
||||
# define MAX(a, b) \
|
||||
({typedef _ta = (a), _tb = (b); \
|
||||
_ta _a = (a); _tb _b = (b); \
|
||||
#define MAX(a, b) \
|
||||
({typeof(a) _a = (a); typeof(b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
|
||||
|
||||
|
@ -57,6 +56,10 @@
|
|||
- (void)_menuChanged;
|
||||
@end
|
||||
|
||||
@interface NSMenuMatrix (PrivateMethods2)
|
||||
- (void)_resizeMenuForCellSize;
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSMenuMatrix
|
||||
|
||||
|
@ -112,6 +115,21 @@ static NSFont* menuFont = nil;
|
|||
|
||||
- (void)_resizeMenuForCellSize
|
||||
{
|
||||
int i, count;
|
||||
float titleWidth;
|
||||
|
||||
/* Compute the new width of the menu cells matrix */
|
||||
cellSize.width = 0;
|
||||
count = [cells count];
|
||||
for (i = 0; i < count; i++) {
|
||||
titleWidth = [menuFont widthOfString:
|
||||
[[cells objectAtIndex:i] stringValue]];
|
||||
cellSize.width = MAX(titleWidth + ADDITIONAL_WIDTH, cellSize.width);
|
||||
}
|
||||
cellSize.width = MAX([menuFont widthOfString:[menu title]]
|
||||
+ ADDITIONAL_WIDTH,
|
||||
cellSize.width);
|
||||
|
||||
/* Resize the frame to hold all the menu cells */
|
||||
[super setFrameSize:NSMakeSize (cellSize.width,
|
||||
(cellSize.height + INTERCELL_SPACE) * [cells count] - INTERCELL_SPACE)];
|
||||
|
@ -123,18 +141,13 @@ static NSFont* menuFont = nil;
|
|||
atIndex:(unsigned int)index
|
||||
{
|
||||
id menuCell = [[[NSMenu cellClass] new] autorelease];
|
||||
float titleWidth;
|
||||
|
||||
[menuCell setTitle:aString];
|
||||
[menuCell setAction:aSelector];
|
||||
[menuCell setKeyEquivalent:charCode];
|
||||
[menuCell setFont:menuFont];
|
||||
|
||||
titleWidth = [menuFont widthOfString:aString];
|
||||
cellSize = NSMakeSize (MAX(titleWidth + ADDITIONAL_WIDTH, cellSize.width),
|
||||
cellSize.height);
|
||||
[cells insertObject:menuCell atIndex:index];
|
||||
|
||||
[self _resizeMenuForCellSize];
|
||||
|
||||
return menuCell;
|
||||
|
@ -143,22 +156,11 @@ static NSFont* menuFont = nil;
|
|||
- (void)removeItem:(id <NSMenuItem>)anItem
|
||||
{
|
||||
int row = [cells indexOfObject:anItem];
|
||||
float titleWidth;
|
||||
int i, count;
|
||||
|
||||
if (row == -1)
|
||||
return;
|
||||
|
||||
[cells removeObjectAtIndex:row];
|
||||
|
||||
/* Compute the new width of the menu cells matrix */
|
||||
cellSize.width = 0;
|
||||
count = [cells count];
|
||||
for (i = 0; i < count; i++) {
|
||||
titleWidth = [menuFont widthOfString:[cells objectAtIndex:i]];
|
||||
cellSize.width = MAX(titleWidth + ADDITIONAL_WIDTH, cellSize.width);
|
||||
}
|
||||
|
||||
[self _resizeMenuForCellSize];
|
||||
}
|
||||
|
||||
|
@ -710,9 +712,17 @@ static Class menuCellClass = nil;
|
|||
- (void)sizeToFit
|
||||
{
|
||||
// SUBCLASS
|
||||
[menuCells _resizeMenuForCellSize];
|
||||
[menuCells setNeedsDisplay:YES];
|
||||
menuHasChanged = NO;
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString*)aTitle
|
||||
{
|
||||
ASSIGN(title, aTitle);
|
||||
[self sizeToFit];
|
||||
}
|
||||
|
||||
- (NSString*)title
|
||||
{
|
||||
return title;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue