/core/externals/update-engine/externals/google-toolbox-for-mac/AppKit/GTMHotKeyTextField.h

http://macfuse.googlecode.com/ · C++ Header · 116 lines · 36 code · 18 blank · 62 comment · 0 complexity · 321aa374abf8faf8d177ba20e97ade50 MD5 · raw file

  1. //
  2. // GTMHotKeyTextField.h
  3. //
  4. // Copyright 2006-2010 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. // Text field for capturing hot key entry. This is intended to be similar to the
  19. // Apple key editor in their Keyboard pref pane.
  20. // NOTE: There are strings that need to be localized to use this field. See the
  21. // code in stringForKeycode the the keys. The keys are all the English versions
  22. // so you'll get reasonable things if you don't have a strings file.
  23. #import <Cocoa/Cocoa.h>
  24. #import "GTMDefines.h"
  25. @interface GTMHotKey : NSObject <NSCopying> {
  26. @private
  27. NSUInteger modifiers_;
  28. NSUInteger keyCode_;
  29. BOOL doubledModifier_;
  30. }
  31. + (id)hotKeyWithKeyCode:(NSUInteger)keyCode
  32. modifiers:(NSUInteger)modifiers
  33. useDoubledModifier:(BOOL)doubledModifier;
  34. - (id)initWithKeyCode:(NSUInteger)keyCode
  35. modifiers:(NSUInteger)modifiers
  36. useDoubledModifier:(BOOL)doubledModifier;
  37. // Custom accessors (readonly, nonatomic)
  38. - (NSUInteger)modifiers;
  39. - (NSUInteger)keyCode;
  40. - (BOOL)doubledModifier;
  41. @end
  42. // Notes:
  43. // - Though you are free to implement control:textShouldEndEditing: in your
  44. // delegate its return is always ignored. The field always accepts only
  45. // one hotkey keystroke before editing ends.
  46. // - The "value" binding of this control is to the dictionary describing the
  47. // hotkey.
  48. // - The field does not attempt to consume all hotkeys. Hotkeys which are
  49. // already bound in Apple prefs or other applications will have their
  50. // normal effect.
  51. //
  52. @interface GTMHotKeyTextField : NSTextField
  53. @end
  54. @interface GTMHotKeyTextFieldCell : NSTextFieldCell {
  55. @private
  56. GTMHotKey *hotKey_;
  57. }
  58. // Convert Cocoa modifier flags (-[NSEvent modifierFlags]) into a string for
  59. // display. Modifiers are represented in the string in the same order they would
  60. // appear in the Menu Manager.
  61. //
  62. // Args:
  63. // flags: -[NSEvent modifierFlags]
  64. //
  65. // Returns:
  66. // Autoreleased NSString
  67. //
  68. + (NSString *)stringForModifierFlags:(NSUInteger)flags;
  69. // Convert a keycode into a string that would result from typing the keycode in
  70. // the current keyboard layout. This may be one or more characters.
  71. //
  72. // Args:
  73. // keycode: Virtual keycode such as one obtained from NSEvent
  74. // useGlyph: In many cases the glyphs are confusing, and a string is clearer.
  75. // However, if you want to display in a menu item, use must
  76. // have a glyph. Set useGlyph to FALSE to get localized strings
  77. // which are better for UI display in places other than menus.
  78. // bundle: Localization bundle to use for localizable key names
  79. //
  80. // Returns:
  81. // Autoreleased NSString
  82. //
  83. + (NSString *)stringForKeycode:(UInt16)keycode
  84. useGlyph:(BOOL)useGlyph
  85. resourceBundle:(NSBundle *)bundle;
  86. @end
  87. // Custom field editor for use with hotkey entry fields (GTMHotKeyTextField).
  88. // See the GTMHotKeyTextField for instructions on using from the window
  89. // delegate.
  90. @interface GTMHotKeyFieldEditor : NSTextView {
  91. @private
  92. GTMHotKeyTextFieldCell *cell_;
  93. }
  94. // Get the shared field editor for all hot key fields
  95. + (GTMHotKeyFieldEditor *)sharedHotKeyFieldEditor;
  96. // Custom accessors (retain, nonatomic)
  97. - (GTMHotKeyTextFieldCell *)cell;
  98. @end