mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 08:21:27 +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 */
|
||||
@class NSButton;
|
||||
|
||||
@interface GSCloseButton : NSButton
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface NSMenuWindowTitleView : NSView
|
||||
{
|
||||
NSMenu *menu;
|
||||
NSButton *button;
|
||||
GSCloseButton *button;
|
||||
}
|
||||
|
||||
- (void) addCloseButton;
|
||||
|
@ -500,6 +506,7 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
|||
unsigned i;
|
||||
unsigned howMany = [_itemCells count];
|
||||
float neededImageAndTitleWidth = [_font widthOfString: [_menu title]];
|
||||
float initialImageAndTitleWidth = neededImageAndTitleWidth;
|
||||
float neededKeyEquivalentWidth = 0.0;
|
||||
float neededStateImageWidth = 0.0;
|
||||
float accumulatedOffset = 0.0;
|
||||
|
@ -570,6 +577,11 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
|||
neededKeyEquivalentWidth = aKeyEquivalentWidth;
|
||||
}
|
||||
|
||||
if (neededImageAndTitleWidth == initialImageAndTitleWidth)
|
||||
{
|
||||
neededImageAndTitleWidth += 10;
|
||||
}
|
||||
|
||||
// Cache the needed widths.
|
||||
_stateImageWidth = neededStateImageWidth;
|
||||
_imageAndTitleWidth = neededImageAndTitleWidth;
|
||||
|
@ -1521,15 +1533,11 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
|||
(_frame.size.height - imageSize.height) / 2},
|
||||
{ imageSize.height, imageSize.width } };
|
||||
|
||||
button = [[NSButton alloc] initWithFrame: rect];
|
||||
[button setButtonType: NSMomentaryLight];
|
||||
[button setImagePosition: NSImageOnly];
|
||||
button = [[GSCloseButton alloc] initWithFrame: rect];
|
||||
[button setImage: closeImage];
|
||||
[button setAlternateImage: closeHImage];
|
||||
[button setBordered: NO];
|
||||
[button setTarget: menu];
|
||||
[button setAction: @selector(_performMenuClose:)];
|
||||
[button setAutoresizingMask: NSViewMinXMargin];
|
||||
|
||||
[self setAutoresizingMask:
|
||||
NSViewMinXMargin | NSViewMinYMargin | NSViewMaxYMargin];
|
||||
|
@ -1560,3 +1568,23 @@ _addLeftBorderOffsetToRect(NSRect aRect, BOOL isHorizontal)
|
|||
}
|
||||
|
||||
@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