1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief I dunno.. some binding stuff?
10 #include "otk/timer.hh"
24 typedef struct Binding {
25 unsigned int modifiers;
28 bool operator==(struct Binding &b2) { return key == b2.key &&
29 modifiers == b2.modifiers; }
30 bool operator!=(struct Binding &b2) { return key != b2.key ||
31 modifiers != b2.modifiers; }
32 Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; }
35 typedef struct BindingTree {
37 PyObject *callback; // the callback given for the binding in add()
38 bool chain; // true if this is a chain to another key (not an action)
40 struct BindingTree *next_sibling; // the next binding in the tree at the same
42 struct BindingTree *first_child; // the first child of this binding (next
43 // binding in a chained sequence).
44 BindingTree(PyObject *callback) : binding(0, 0) {
45 this->callback = callback; chain = true; next_sibling = first_child = 0;
47 BindingTree() : binding(0, 0) {
48 this->callback = 0; chain = true; next_sibling = first_child = 0;
55 typedef std::vector<std::string> StringVect;
58 BindingTree _tree; // root node of the tree (this doesn't have siblings!)
59 BindingTree *_curpos; // position in the keytree
61 Binding _resetkey; // the key which resets the key chain status
65 PyObject *find(BindingTree *search, bool *conflict) const;
66 BindingTree *buildtree(const StringVect &keylist, PyObject *callback) const;
67 void assimilate(BindingTree *node);
69 static void reset(OBBindings *self); // the timer's timeout function
72 //! Initializes an OBBindings object
74 //! Destroys the OBBindings object
75 virtual ~OBBindings();
77 //! Translates a binding string into the actual Binding
78 bool translate(const std::string &str, Binding &b, bool askey = true) const;
80 //! Adds a new key binding
82 A binding will fail to be added if the binding already exists (as part of
83 a chain or not), or if any of the strings in the keylist are invalid.
84 @return true if the binding could be added; false if it could not.
86 bool add(const StringVect &keylist, PyObject *callback);
88 //! Removes a key binding
90 @return The callbackid of the binding, or '< 0' if there was no binding to
93 bool remove(const StringVect &keylist);
95 //! Removes all key bindings
98 void fire(unsigned int modifiers,unsigned int key, Time time);
100 void setResetKey(const std::string &key);
102 void grabKeys(bool grab);
107 #endif // __binding_hh