forked from Kentzo/ShortcutRecorder
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSRCommon.h
executable file
·104 lines (81 loc) · 2.67 KB
/
SRCommon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// SRCommon.h
// ShortcutRecorder
//
// Copyright 2006-2012 Contributors. All rights reserved.
//
// License: BSD
//
// Contributors:
// David Dauer
// Jesper
// Jamie Kirkpatrick
// Andy Kim
// Ilya Kulakov
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
/*!
@brief Mask representing subset of Cocoa modifier flags suitable for shortcuts.
*/
static const NSUInteger SRCocoaModifierFlagsMask = NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask | NSControlKeyMask;
/*!
@brief Mask representing subset of Carbon modifier flags suitable for shortcuts.
*/
static const NSUInteger SRCarbonModifierFlagsMask = cmdKey | optionKey | shiftKey | controlKey;
/*!
@brief Converts carbon modifier flags to cocoa.
*/
FOUNDATION_STATIC_INLINE NSUInteger SRCarbonToCocoaFlags(UInt32 aCarbonFlags)
{
NSUInteger cocoaFlags = 0;
if (aCarbonFlags & cmdKey)
cocoaFlags |= NSCommandKeyMask;
if (aCarbonFlags & optionKey)
cocoaFlags |= NSAlternateKeyMask;
if (aCarbonFlags & controlKey)
cocoaFlags |= NSControlKeyMask;
if (aCarbonFlags & shiftKey)
cocoaFlags |= NSShiftKeyMask;
return cocoaFlags;
}
/*!
@brief Converts cocoa modifier flags to carbon.
*/
FOUNDATION_STATIC_INLINE UInt32 SRCocoaToCarbonFlags(NSUInteger aCocoaFlags)
{
UInt32 carbonFlags = 0;
if (aCocoaFlags & NSCommandKeyMask)
carbonFlags |= cmdKey;
if (aCocoaFlags & NSAlternateKeyMask)
carbonFlags |= optionKey;
if (aCocoaFlags & NSControlKeyMask)
carbonFlags |= controlKey;
if (aCocoaFlags & NSShiftKeyMask)
carbonFlags |= shiftKey;
return carbonFlags;
}
/*!
@brief Convenient method to get localized string from the framework bundle.
*/
FOUNDATION_STATIC_INLINE NSString *SRLoc(NSString *aKey)
{
return NSLocalizedStringFromTable(aKey, @"ShortcutRecorder", nil);
}
/*!
@brief Convenient method to get image from the framework bundle.
*/
FOUNDATION_STATIC_INLINE NSImage *SRImage(NSString *anImageName)
{
NSImage *image = [NSImage imageNamed:anImageName];
return image;
}
/*!
@brief Returns string representation of shortcut with modifier flags replaced with their localized
readable equivalents (e.g. ? -> Option).
*/
NSString *SRReadableStringForCocoaModifierFlagsAndKeyCode(NSUInteger aModifierFlags, unsigned short aKeyCode);
/*!
@brief Returns string representation of shortcut with modifier flags replaced with their localized
readable equivalents (e.g. ? -> Option) and ASCII character for key code.
*/
NSString *SRReadableASCIIStringForCocoaModifierFlagsAndKeyCode(NSUInteger aModifierFlags, unsigned short aKeyCode);