mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
Merge pull request #28 from trunkmaster/master
Attributed key equivalents in menu
This commit is contained in:
commit
0c0b77fc9a
2 changed files with 100 additions and 10 deletions
21
ChangeLog
21
ChangeLog
|
@ -1,3 +1,24 @@
|
|||
2019-04-10 Sergii Stoian <stoyan255@gmail.com>
|
||||
|
||||
* Source/NSMenuItemCell.m (drawKeyEquivalentWithFrame:inView:):
|
||||
use NCell's textColor instead of check if we're disabled/enabled.
|
||||
|
||||
2019-04-10 Sergii Stoian <stoyan255@ukr.net>
|
||||
|
||||
* Source/NSMenuItemCell.m (drawKeyEquivalentWithFrame:inView:):
|
||||
check if item is disabled/enabled and set color attribute for attributed
|
||||
key equivalent string.
|
||||
|
||||
2019-04-09 Sergii Stoian <stoyan255@gmail.com>
|
||||
|
||||
* Source/NSMenuItemCell.m (_keyEquivalentString): if modifier key string
|
||||
is not defined - set key equivalent font trait: Italic for Alternate modifier
|
||||
Bold - for Control.
|
||||
(_sizeKeyEquivalentText:): new method to calculate string size wrt font
|
||||
set in `_keyEquivalentString:`.
|
||||
(drawKeyEquivalentWithFrame:inView:): draw key equivalent as attributed
|
||||
string.
|
||||
|
||||
2019-04-08 Sergii Stoian <stoyan255@ukr.net>
|
||||
|
||||
* Source/NSApplication.m (becomesKeyOnlyIfNeeded): override NSWindow
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#import "AppKit/NSMenuItemCell.h"
|
||||
#import "AppKit/NSMenuView.h"
|
||||
#import "AppKit/NSParagraphStyle.h"
|
||||
#import "AppKit/NSStringDrawing.h"
|
||||
#import "GNUstepGUI/GSTheme.h"
|
||||
#import "GSGuiPrivate.h"
|
||||
|
||||
|
@ -255,19 +256,66 @@ static NSString *commandKeyString = @"#";
|
|||
if (m != 0)
|
||||
{
|
||||
BOOL shift;
|
||||
// shift mask and not an upper case string?
|
||||
shift = (m & NSShiftKeyMask) & ![key isEqualToString: ucKey];
|
||||
key = [NSString stringWithFormat:@"%@%@%@%@%@",
|
||||
(m & NSControlKeyMask) ? controlKeyString : @"",
|
||||
(m & NSAlternateKeyMask) ? alternateKeyString : @"",
|
||||
shift ? shiftKeyString : @"",
|
||||
(m & NSCommandKeyMask) ? commandKeyString : @"",
|
||||
key];
|
||||
NSFontTraitMask traits = 0;
|
||||
|
||||
if ((m & NSAlternateKeyMask) &&
|
||||
(!alternateKeyString || [alternateKeyString isEqualToString: @""]))
|
||||
{
|
||||
traits |= NSItalicFontMask;
|
||||
}
|
||||
if ((m & NSControlKeyMask) &&
|
||||
(!controlKeyString || [controlKeyString isEqualToString: @""]))
|
||||
{
|
||||
traits |= NSBoldFontMask;
|
||||
}
|
||||
|
||||
if (traits)
|
||||
{
|
||||
NSFont *font;
|
||||
font = [[NSFontManager sharedFontManager]
|
||||
fontWithFamily:[[NSFont controlContentFontOfSize:0.0] familyName]
|
||||
traits:traits
|
||||
weight:(traits & NSBoldFontMask) ? 9 : 5
|
||||
size:[NSFont systemFontSize]];
|
||||
if (font)
|
||||
[self setKeyEquivalentFont:font];
|
||||
}
|
||||
else
|
||||
{
|
||||
// shift mask and not an upper case string?
|
||||
shift = (m & NSShiftKeyMask) & ![key isEqualToString: ucKey];
|
||||
key = [NSString stringWithFormat:@"%@%@%@%@%@",
|
||||
(m & NSControlKeyMask) ? controlKeyString : @"",
|
||||
(m & NSAlternateKeyMask) ? alternateKeyString : @"",
|
||||
(shift != NO) ? shiftKeyString : @"",
|
||||
(m & NSCommandKeyMask) ? commandKeyString : @"",
|
||||
key];
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
- (NSSize) _sizeKeyEquivalentText: (NSString*)title
|
||||
{
|
||||
NSSize size;
|
||||
NSDictionary *attrs;
|
||||
|
||||
if (title == nil) {
|
||||
return NSMakeSize (0,0);
|
||||
}
|
||||
|
||||
if (_keyEquivalentFont) {
|
||||
attrs = [NSDictionary dictionaryWithObject: _keyEquivalentFont
|
||||
forKey: NSFontAttributeName];
|
||||
size = [title sizeWithAttributes: attrs];
|
||||
}
|
||||
else {
|
||||
size = [self _sizeText: title];
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
- (void) calcSize
|
||||
{
|
||||
NSSize componentSize;
|
||||
|
@ -339,7 +387,7 @@ static NSString *commandKeyString = @"#";
|
|||
_titleWidth = componentSize.width;
|
||||
if (componentSize.height > neededMenuItemHeight)
|
||||
neededMenuItemHeight = componentSize.height;
|
||||
componentSize = [self _sizeText: [self _keyEquivalentString]];
|
||||
componentSize = [self _sizeKeyEquivalentText: [self _keyEquivalentString]];
|
||||
_keyEquivalentWidth = componentSize.width;
|
||||
if (componentSize.height > neededMenuItemHeight)
|
||||
neededMenuItemHeight = componentSize.height;
|
||||
|
@ -736,7 +784,28 @@ static NSString *commandKeyString = @"#";
|
|||
*/
|
||||
else if (![[_menuView menu] _ownedByPopUp] || (_imageToDisplay == nil))
|
||||
{
|
||||
[self _drawText: [self _keyEquivalentString] inFrame: cellFrame];
|
||||
if (_keyEquivalentFont != nil)
|
||||
{
|
||||
NSDictionary *attrs;
|
||||
NSArray *attrObjects, *attrKeys;
|
||||
NSAttributedString *aString;
|
||||
|
||||
attrObjects = [NSArray arrayWithObjects: _keyEquivalentFont,
|
||||
[self textColor], nil];
|
||||
attrKeys = [NSArray arrayWithObjects: NSFontAttributeName,
|
||||
NSForegroundColorAttributeName, nil];
|
||||
attrs = [NSDictionary dictionaryWithObjects: attrObjects
|
||||
forKeys: attrKeys];
|
||||
aString = [[NSAttributedString alloc]
|
||||
initWithString: [self _keyEquivalentString]
|
||||
attributes: attrs];
|
||||
[self _drawAttributedText: aString inFrame: cellFrame];
|
||||
[aString release];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self _drawText: [self _keyEquivalentString] inFrame: cellFrame];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue