mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 16:10:55 +00:00
[sizeToFit] cleanup and new class GSCloseButton
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16183 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e734c04808
commit
86d76d089e
1 changed files with 34 additions and 6 deletions
|
@ -53,10 +53,16 @@
|
||||||
/* A menu's title is an instance of this class */
|
/* A menu's title is an instance of this class */
|
||||||
@class NSButton;
|
@class NSButton;
|
||||||
|
|
||||||
|
@interface GSCloseButton : NSButton
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@interface NSMenuWindowTitleView : NSView
|
@interface NSMenuWindowTitleView : NSView
|
||||||
{
|
{
|
||||||
NSMenu *menu;
|
NSMenu *menu;
|
||||||
NSButton *button;
|
GSCloseButton *button;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addCloseButton;
|
- (void) addCloseButton;
|
||||||
|
@ -500,6 +506,7 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
unsigned i;
|
unsigned i;
|
||||||
unsigned howMany = [_itemCells count];
|
unsigned howMany = [_itemCells count];
|
||||||
float neededImageAndTitleWidth = [_font widthOfString: [_menu title]];
|
float neededImageAndTitleWidth = [_font widthOfString: [_menu title]];
|
||||||
|
float initialImageAndTitleWidth = neededImageAndTitleWidth;
|
||||||
float neededKeyEquivalentWidth = 0.0;
|
float neededKeyEquivalentWidth = 0.0;
|
||||||
float neededStateImageWidth = 0.0;
|
float neededStateImageWidth = 0.0;
|
||||||
float accumulatedOffset = 0.0;
|
float accumulatedOffset = 0.0;
|
||||||
|
@ -570,6 +577,11 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
neededKeyEquivalentWidth = aKeyEquivalentWidth;
|
neededKeyEquivalentWidth = aKeyEquivalentWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (neededImageAndTitleWidth == initialImageAndTitleWidth)
|
||||||
|
{
|
||||||
|
neededImageAndTitleWidth += 10;
|
||||||
|
}
|
||||||
|
|
||||||
// Cache the needed widths.
|
// Cache the needed widths.
|
||||||
_stateImageWidth = neededStateImageWidth;
|
_stateImageWidth = neededStateImageWidth;
|
||||||
_imageAndTitleWidth = neededImageAndTitleWidth;
|
_imageAndTitleWidth = neededImageAndTitleWidth;
|
||||||
|
@ -1521,15 +1533,11 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
(_frame.size.height - imageSize.height) / 2},
|
(_frame.size.height - imageSize.height) / 2},
|
||||||
{ imageSize.height, imageSize.width } };
|
{ imageSize.height, imageSize.width } };
|
||||||
|
|
||||||
button = [[NSButton alloc] initWithFrame: rect];
|
button = [[GSCloseButton alloc] initWithFrame: rect];
|
||||||
[button setButtonType: NSMomentaryLight];
|
|
||||||
[button setImagePosition: NSImageOnly];
|
|
||||||
[button setImage: closeImage];
|
[button setImage: closeImage];
|
||||||
[button setAlternateImage: closeHImage];
|
[button setAlternateImage: closeHImage];
|
||||||
[button setBordered: NO];
|
|
||||||
[button setTarget: menu];
|
[button setTarget: menu];
|
||||||
[button setAction: @selector(_performMenuClose:)];
|
[button setAction: @selector(_performMenuClose:)];
|
||||||
[button setAutoresizingMask: NSViewMinXMargin];
|
|
||||||
|
|
||||||
[self setAutoresizingMask:
|
[self setAutoresizingMask:
|
||||||
NSViewMinXMargin | NSViewMinYMargin | NSViewMaxYMargin];
|
NSViewMinXMargin | NSViewMinYMargin | NSViewMaxYMargin];
|
||||||
|
@ -1560,3 +1568,23 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
||||||
}
|
}
|
||||||
|
|
||||||
@end /* NSMenuWindowTitleView */
|
@end /* NSMenuWindowTitleView */
|
||||||
|
|
||||||
|
@implementation GSCloseButton
|
||||||
|
|
||||||
|
- (id) initWithFrame: (NSRect) rect
|
||||||
|
{
|
||||||
|
self = [super initWithFrame: rect];
|
||||||
|
[self setButtonType: NSMomentaryChangeButton];
|
||||||
|
[self setImagePosition: NSImageOnly];
|
||||||
|
[self setBordered: NO];
|
||||||
|
[self setAutoresizingMask: NSViewMinXMargin];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) acceptsFirstResponder
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
Loading…
Reference in a new issue