HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DM_ModifierKeys.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: DM_ModifierKeys.h ( DM Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __DM_ModifierKeys__
12 #define __DM_ModifierKeys__
13 
14 #include "DM_API.h"
15 
16 #include <UT/UT_ValArray.h>
17 
18 class UI_Event;
19 class UT_WorkBuffer;
20 class UT_StringHolder;
21 
22 enum class DM_ModifierKeyConstraint : short
23 {
24  FloorXY,
25  FloorH
26 };
27 
28 /// @brief Definition of a modifier key context
29 ///
30 /// A modifier key context consists of a list of modifier key states, each
31 /// mapping to an integer identifier. A UI_Event can then be mapped to the
32 /// appropriate identifier by its myAltFlags member.
34 {
35 public:
36  /// Returns the identifier for the modifier matching the event, if any.
37  /// In the event of no matching modifier, a value of -1 is returned.
38  int findMatch(const UI_Event *event) const;
39 
40  /// Returns whether the event matches the specified modifier identifier.
41  /// An event with multiple modifier keys set can match multiple modifier
42  /// identifiers when the matched modifiers are proper subsets.
43  bool match(const UI_Event *event, int modifier_id) const;
44 
45  /// Append a modifier. The order these modifiers are appended is what
46  /// determines their relative priorities. When modifier_key_flags is
47  /// supplied, that value overrides any loaded from the configuration files.
48  ///
49  /// TODO: Specify whether the modifier can be combined with other modifiers
50  /// or must stand alone.
51  void append(int modifier_id);
52  void append(int modifier_id, short modifier_key_flags);
53  void append(const DM_ModifierKeys &src_context);
54 
55  /// Call after appending any modifier(s).
56  void update();
57 
58  void clear()
59  { myModifiers.clear(); }
60  exint entries() const
61  { return myModifiers.entries(); }
62 
63  /// Query the description string for the specified modifier. Returns
64  /// false if the modifier is not found or is in conflict with a higher
65  /// priority modifier.
66  bool resolveDescription(int modifier_id,
67  UT_WorkBuffer &buffer) const;
68 
69  /// Register a new modifier token and return the corresponding identifier
70  /// to use in instances of this class.
71  static int registerModifier(const char *modifier_token);
72 
73  /// Add and register a new modifier definition along with its assigment keys.
74  /// Returns a new modifier id or -1 if the operation failed.
75  static int addModifier(const char *modifier_token,
76  UT_Array<UT_StringHolder> const& key_assigments);
77 
78  /// Remove a modifier previously added with addModifier
79  static void removeModifier(const char* modifier_token);
80 
81 private:
82  struct ModifierInfo
83  {
84  ModifierInfo(int id, int key_flags) : myId(id), myKeyFlags(key_flags)
85  {}
86 
87  int myId;
88  int myKeyFlags;
89  };
90 
91  UT_ValArray<ModifierInfo> myModifiers;
92 };
93 
94 #endif
exint entries() const
int64 exint
Definition: SYS_Types.h:125
struct _cl_event * event
Definition: glcorearb.h:2961
#define DM_API
Definition: DM_API.h:10
Definition: core.h:760
DM_ModifierKeyConstraint
Definition of a modifier key context.