1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief I dunno.. some binding stuff?
11 #include "otk/timer.hh"
25 typedef struct Binding
{
26 unsigned int modifiers
;
29 bool operator==(struct Binding
&b2
) { return key
== b2
.key
&&
30 modifiers
== b2
.modifiers
; }
31 bool operator!=(struct Binding
&b2
) { return key
!= b2
.key
||
32 modifiers
!= b2
.modifiers
; }
33 Binding(unsigned int mod
, unsigned int k
) { modifiers
= mod
; key
= k
; }
36 typedef struct KeyBindingTree
{
38 PyObject
*callback
; // the callback given for the binding in add()
39 bool chain
; // true if this is a chain to another key (not an action)
41 struct KeyBindingTree
*next_sibling
; // the next binding in the tree at the same
43 struct KeyBindingTree
*first_child
; // the first child of this binding (next
44 // binding in a chained sequence).
45 KeyBindingTree(PyObject
*callback
) : binding(0, 0) {
46 this->callback
= callback
; chain
= true; next_sibling
= first_child
= 0;
48 KeyBindingTree() : binding(0, 0) {
49 this->callback
= 0; chain
= true; next_sibling
= first_child
= 0;
53 typedef struct ButtonBinding
{
55 PyObject
*callback
[NUM_MOUSE_ACTION
];
56 ButtonBinding() : binding(0, 0) {
57 for(int i
=0; i
<NUM_MOUSE_ACTION
; ++i
) callback
[i
] = 0;
64 typedef std::vector
<std::string
> StringVect
;
67 // root node of the tree (this doesn't have siblings!)
68 KeyBindingTree _keytree
;
69 KeyBindingTree
*_curpos
; // position in the keytree
71 Binding _resetkey
; // the key which resets the key chain status
75 PyObject
*find(KeyBindingTree
*search
, bool *conflict
) const;
76 KeyBindingTree
*buildtree(const StringVect
&keylist
,
77 PyObject
*callback
) const;
78 void assimilate(KeyBindingTree
*node
);
80 static void reset(OBBindings
*self
); // the timer's timeout function
82 typedef std::list
<ButtonBinding
*> ButtonBindingList
;
83 ButtonBindingList _buttons
[NUM_MOUSE_CONTEXT
];
86 //! Initializes an OBBindings object
88 //! Destroys the OBBindings object
89 virtual ~OBBindings();
91 //! Translates a binding string into the actual Binding
92 bool translate(const std::string
&str
, Binding
&b
, bool askey
= true) const;
94 //! Adds a new key binding
96 A binding will fail to be added if the binding already exists (as part of
97 a chain or not), or if any of the strings in the keylist are invalid.
98 @return true if the binding could be added; false if it could not.
100 bool addKey(const StringVect
&keylist
, PyObject
*callback
);
102 //! Removes a key binding
104 @return The callbackid of the binding, or '< 0' if there was no binding to
107 bool removeKey(const StringVect
&keylist
);
109 //! Removes all key bindings
110 void removeAllKeys();
112 void fireKey(unsigned int modifiers
,unsigned int key
, Time time
);
114 void setResetKey(const std::string
&key
);
116 void grabKeys(bool grab
);
118 bool addButton(const std::string
&but
, MouseContext context
,
119 MouseAction action
, PyObject
*callback
);
121 void grabButtons(bool grab
, OBClient
*client
);
123 //! Removes all button bindings
124 void removeAllButtons();
126 void fireButton(ButtonData
*data
);
131 #endif // __binding_hh