Skip to content

Commit

Permalink
Adding ShortcutRecorder framework to bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscrowe committed Oct 7, 2010
1 parent 96ac6cd commit 8204ba2
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 0 deletions.
Binary file added ShiftIt/English.lproj/ShortcutRecorder.strings
Binary file not shown.
1 change: 1 addition & 0 deletions ShiftIt/ShortcutRecorder.framework/Headers
1 change: 1 addition & 0 deletions ShiftIt/ShortcutRecorder.framework/Resources
1 change: 1 addition & 0 deletions ShiftIt/ShortcutRecorder.framework/ShortcutRecorder
185 changes: 185 additions & 0 deletions ShiftIt/ShortcutRecorder.framework/Versions/A/Headers/SRCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
//
// SRCommon.h
// ShortcutRecorder
//
// Copyright 2006-2007 Contributors. All rights reserved.
//
// License: BSD
//
// Contributors:
// David Dauer
// Jesper
// Jamie Kirkpatrick

#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
#import <CoreServices/CoreServices.h>

#pragma mark Dummy class

@interface SRDummyClass : NSObject {} @end

#pragma mark -
#pragma mark Typedefs

typedef struct _KeyCombo {
NSUInteger flags; // 0 for no flags
NSInteger code; // -1 for no code
} KeyCombo;

#pragma mark -
#pragma mark Enums

// Unicode values of some keyboard glyphs
enum {
KeyboardTabRightGlyph = 0x21E5,
KeyboardTabLeftGlyph = 0x21E4,
KeyboardCommandGlyph = kCommandUnicode,
KeyboardOptionGlyph = kOptionUnicode,
KeyboardShiftGlyph = kShiftUnicode,
KeyboardControlGlyph = kControlUnicode,
KeyboardReturnGlyph = 0x2305,
KeyboardReturnR2LGlyph = 0x21A9,
KeyboardDeleteLeftGlyph = 0x232B,
KeyboardDeleteRightGlyph = 0x2326,
KeyboardPadClearGlyph = 0x2327,
KeyboardLeftArrowGlyph = 0x2190,
KeyboardRightArrowGlyph = 0x2192,
KeyboardUpArrowGlyph = 0x2191,
KeyboardDownArrowGlyph = 0x2193,
KeyboardPageDownGlyph = 0x21DF,
KeyboardPageUpGlyph = 0x21DE,
KeyboardNorthwestArrowGlyph = 0x2196,
KeyboardSoutheastArrowGlyph = 0x2198,
KeyboardEscapeGlyph = 0x238B,
KeyboardHelpGlyph = 0x003F,
KeyboardUpArrowheadGlyph = 0x2303,
};

// Special keys
enum {
kSRKeysF1 = 122,
kSRKeysF2 = 120,
kSRKeysF3 = 99,
kSRKeysF4 = 118,
kSRKeysF5 = 96,
kSRKeysF6 = 97,
kSRKeysF7 = 98,
kSRKeysF8 = 100,
kSRKeysF9 = 101,
kSRKeysF10 = 109,
kSRKeysF11 = 103,
kSRKeysF12 = 111,
kSRKeysF13 = 105,
kSRKeysF14 = 107,
kSRKeysF15 = 113,
kSRKeysF16 = 106,
kSRKeysF17 = 64,
kSRKeysF18 = 79,
kSRKeysF19 = 80,
kSRKeysSpace = 49,
kSRKeysDeleteLeft = 51,
kSRKeysDeleteRight = 117,
kSRKeysPadClear = 71,
kSRKeysLeftArrow = 123,
kSRKeysRightArrow = 124,
kSRKeysUpArrow = 126,
kSRKeysDownArrow = 125,
kSRKeysSoutheastArrow = 119,
kSRKeysNorthwestArrow = 115,
kSRKeysEscape = 53,
kSRKeysPageDown = 121,
kSRKeysPageUp = 116,
kSRKeysReturnR2L = 36,
kSRKeysReturn = 76,
kSRKeysTabRight = 48,
kSRKeysHelp = 114
};

#pragma mark -
#pragma mark Macros

// Localization macros, for use in any bundle
#define SRLoc(key) SRLocalizedString(key, nil)
#define SRLocalizedString(key, comment) NSLocalizedStringFromTableInBundle(key, @"ShortcutRecorder", [NSBundle bundleForClass: [SRDummyClass class]], comment)

// Image macros, for use in any bundle
//#define SRImage(name) [[[NSImage alloc] initWithContentsOfFile: [[NSBundle bundleForClass: [self class]] pathForImageResource: name]] autorelease]
#define SRResIndImage(name) [SRSharedImageProvider supportingImageWithName:name]
#define SRImage(name) SRResIndImage(name)

//#define SRCommonWriteDebugImagery

// Macros for glyps
#define SRInt(x) [NSNumber numberWithInteger:x]
#define SRChar(x) [NSString stringWithFormat: @"%C", x]

// Some default values
#define ShortcutRecorderEmptyFlags 0
#define ShortcutRecorderAllFlags ShortcutRecorderEmptyFlags | (NSCommandKeyMask | NSAlternateKeyMask | NSControlKeyMask | NSShiftKeyMask | NSFunctionKeyMask)
#define ShortcutRecorderEmptyCode -1

// These keys will cancel the recoding mode if not pressed with any modifier
#define ShortcutRecorderEscapeKey 53
#define ShortcutRecorderBackspaceKey 51
#define ShortcutRecorderDeleteKey 117

#pragma mark -
#pragma mark Getting a string of the key combination

//
// ################### +- Returns string from keyCode like NSEvent's -characters
// # EXPLANATORY # | +- Returns string from keyCode like NSEvent's -charactersUsingModifiers
// # CHART # | | +- Returns fully readable and localized name of modifier (if modifier given)
// ################### | | | +- Returns glyph of modifier (if modifier given)
// SRString... X - - X
// SRReadableString... X - X -
// SRCharacter... - X - -
//
NSString * SRStringForKeyCode( NSInteger keyCode );
NSString * SRStringForCarbonModifierFlags( NSUInteger flags );
NSString * SRStringForCarbonModifierFlagsAndKeyCode( NSUInteger flags, NSInteger keyCode );
NSString * SRStringForCocoaModifierFlags( NSUInteger flags );
NSString * SRStringForCocoaModifierFlagsAndKeyCode( NSUInteger flags, NSInteger keyCode );
NSString * SRReadableStringForCarbonModifierFlagsAndKeyCode( NSUInteger flags, NSInteger keyCode );
NSString * SRReadableStringForCocoaModifierFlagsAndKeyCode( NSUInteger flags, NSInteger keyCode );
NSString *SRCharacterForKeyCodeAndCarbonFlags(NSInteger keyCode, NSUInteger carbonFlags);
NSString *SRCharacterForKeyCodeAndCocoaFlags(NSInteger keyCode, NSUInteger cocoaFlags);

#pragma mark Converting between Cocoa and Carbon modifier flags

NSUInteger SRCarbonToCocoaFlags( NSUInteger carbonFlags );
NSUInteger SRCocoaToCarbonFlags( NSUInteger cocoaFlags );

#pragma mark -
#pragma mark Animation pace function

CGFloat SRAnimationEaseInOut(CGFloat t);

#pragma mark -
#pragma mark Inlines

FOUNDATION_STATIC_INLINE KeyCombo SRMakeKeyCombo(NSInteger code, NSUInteger flags) {
KeyCombo kc;
kc.code = code;
kc.flags = flags;
return kc;
}

FOUNDATION_STATIC_INLINE BOOL SRIsSpecialKey(NSInteger keyCode) {
return (keyCode == kSRKeysF1 || keyCode == kSRKeysF2 || keyCode == kSRKeysF3 || keyCode == kSRKeysF4 || keyCode == kSRKeysF5 || keyCode == kSRKeysF6 || keyCode == kSRKeysF7 || keyCode == kSRKeysF8 || keyCode == kSRKeysF9 || keyCode == kSRKeysF10 || keyCode == kSRKeysF11 || keyCode == kSRKeysF12 || keyCode == kSRKeysF13 || keyCode == kSRKeysF14 || keyCode == kSRKeysF15 || keyCode == kSRKeysF16 || keyCode == kSRKeysSpace || keyCode == kSRKeysDeleteLeft || keyCode == kSRKeysDeleteRight || keyCode == kSRKeysPadClear || keyCode == kSRKeysLeftArrow || keyCode == kSRKeysRightArrow || keyCode == kSRKeysUpArrow || keyCode == kSRKeysDownArrow || keyCode == kSRKeysSoutheastArrow || keyCode == kSRKeysNorthwestArrow || keyCode == kSRKeysEscape || keyCode == kSRKeysPageDown || keyCode == kSRKeysPageUp || keyCode == kSRKeysReturnR2L || keyCode == kSRKeysReturn || keyCode == kSRKeysTabRight || keyCode == kSRKeysHelp);
}

#pragma mark -
#pragma mark Additions

@interface NSAlert( SRAdditions )
+ (NSAlert *) alertWithNonRecoverableError:(NSError *)error;
@end

#pragma mark -
#pragma mark Image provider

@interface SRSharedImageProvider : NSObject
+ (NSImage *)supportingImageWithName:(NSString *)name;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SRKeyCodeTransformer.h
// ShortcutRecorder
//
// Copyright 2006-2007 Contributors. All rights reserved.
//
// License: BSD
//
// Contributors:
// David Dauer
// Jesper
// Jamie Kirkpatrick

#import <Cocoa/Cocoa.h>

@interface SRKeyCodeTransformer : NSValueTransformer {} @end
137 changes: 137 additions & 0 deletions ShiftIt/ShortcutRecorder.framework/Versions/A/Headers/SRRecorderCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//
// SRRecorderCell.h
// ShortcutRecorder
//
// Copyright 2006-2007 Contributors. All rights reserved.
//
// License: BSD
//
// Contributors:
// David Dauer
// Jesper
// Jamie Kirkpatrick

#import <Cocoa/Cocoa.h>
#import "SRCommon.h"

#define SRMinWidth 50
#define SRMaxHeight 22

#define SRTransitionFPS 30.0f
#define SRTransitionDuration 0.35f
//#define SRTransitionDuration 2.35
#define SRTransitionFrames (SRTransitionFPS*SRTransitionDuration)
#define SRAnimationAxisIsY YES
#define ShortcutRecorderNewStyleDrawing

#define SRAnimationOffsetRect(X,Y) (SRAnimationAxisIsY ? NSOffsetRect(X,0.0f,-NSHeight(Y)) : NSOffsetRect(X,NSWidth(Y),0.0f))

@class SRRecorderControl, SRValidator;

enum SRRecorderStyle {
SRGradientBorderStyle = 0,
SRGreyStyle = 1
};
typedef enum SRRecorderStyle SRRecorderStyle;

@interface SRRecorderCell : NSActionCell <NSCoding>
{
NSGradient *recordingGradient;
NSString *autosaveName;

BOOL isRecording;
BOOL mouseInsideTrackingArea;
BOOL mouseDown;

SRRecorderStyle style;

BOOL isAnimating;
CGFloat transitionProgress;
BOOL isAnimatingNow;
BOOL isAnimatingTowardsRecording;
BOOL comboJustChanged;

NSTrackingRectTag removeTrackingRectTag;
NSTrackingRectTag snapbackTrackingRectTag;

KeyCombo keyCombo;
BOOL hasKeyChars;
NSString *keyChars;
NSString *keyCharsIgnoringModifiers;

NSUInteger allowedFlags;
NSUInteger requiredFlags;
NSUInteger recordingFlags;

BOOL allowsKeyOnly;
BOOL escapeKeysRecord;

NSSet *cancelCharacterSet;

SRValidator *validator;

IBOutlet id delegate;
BOOL globalHotKeys;
void *hotKeyModeToken;
}

- (void)resetTrackingRects;

#pragma mark *** Aesthetics ***

+ (BOOL)styleSupportsAnimation:(SRRecorderStyle)style;

- (BOOL)animates;
- (void)setAnimates:(BOOL)an;
- (SRRecorderStyle)style;
- (void)setStyle:(SRRecorderStyle)nStyle;

#pragma mark *** Delegate ***

- (id)delegate;
- (void)setDelegate:(id)aDelegate;

#pragma mark *** Responder Control ***

- (BOOL)becomeFirstResponder;
- (BOOL)resignFirstResponder;

#pragma mark *** Key Combination Control ***

- (BOOL)performKeyEquivalent:(NSEvent *)theEvent;
- (void)flagsChanged:(NSEvent *)theEvent;

- (NSUInteger)allowedFlags;
- (void)setAllowedFlags:(NSUInteger)flags;

- (NSUInteger)requiredFlags;
- (void)setRequiredFlags:(NSUInteger)flags;

- (BOOL)allowsKeyOnly;
- (void)setAllowsKeyOnly:(BOOL)nAllowsKeyOnly escapeKeysRecord:(BOOL)nEscapeKeysRecord;
- (BOOL)escapeKeysRecord;

- (BOOL)canCaptureGlobalHotKeys;
- (void)setCanCaptureGlobalHotKeys:(BOOL)inState;

- (KeyCombo)keyCombo;
- (void)setKeyCombo:(KeyCombo)aKeyCombo;

#pragma mark *** Autosave Control ***

- (NSString *)autosaveName;
- (void)setAutosaveName:(NSString *)aName;

// Returns the displayed key combination if set
- (NSString *)keyComboString;

- (NSString *)keyChars;
- (NSString *)keyCharsIgnoringModifiers;

@end

// Delegate Methods
@interface NSObject (SRRecorderCellDelegate)
- (BOOL)shortcutRecorderCell:(SRRecorderCell *)aRecorderCell isKeyCode:(NSInteger)keyCode andFlagsTaken:(NSUInteger)flags reason:(NSString **)aReason;
- (void)shortcutRecorderCell:(SRRecorderCell *)aRecorderCell keyComboDidChange:(KeyCombo)newCombo;
@end
Loading

0 comments on commit 8204ba2

Please sign in to comment.