-
- assert(false);
- } else {
- BindingTree *p = _mousetree;
- while (p) {
- if (p->binding.key == key && p->binding.modifiers == modifiers) {
- python_callback_binding(p->id, type, window, modifiers, key, time);
- break;
+ }
+}
+
+void OBBindings::reset(OBBindings *self)
+{
+ self->_timer.stop();
+ self->grabKeys(false);
+ self->_curpos = &self->_keytree;
+ self->grabKeys(true);
+}
+
+
+bool OBBindings::addButton(const std::string &but, MouseContext context,
+ MouseAction action, PyObject *callback)
+{
+ assert(context >= 0 && context < NUM_MOUSE_CONTEXT);
+
+ Binding b(0,0);
+ if (!translate(but, b, false))
+ return false;
+
+ ButtonBindingList::iterator it, end = _buttons[context].end();
+
+ // look for a duplicate binding
+ for (it = _buttons[context].begin(); it != end; ++it)
+ if ((*it)->binding.key == b.key &&
+ (*it)->binding.modifiers == b.modifiers) {
+ if ((*it)->callback[action] == callback)
+ return true; // already bound
+ break;
+ }
+
+ ButtonBinding *bind;
+
+ // the binding didnt exist yet, add it
+ if (it == end) {
+ bind = new ButtonBinding();
+ bind->binding.key = b.key;
+ bind->binding.modifiers = b.modifiers;
+ _buttons[context].push_back(bind);
+ // XXX GRAB the new button everywhere!
+ } else
+ bind = *it;
+ Py_XDECREF(bind->callback[action]); // if it was already bound, unbind it
+ bind->callback[action] = callback;
+ Py_INCREF(callback);
+ return true;
+}
+
+void OBBindings::removeAllButtons()
+{
+ // XXX: UNGRAB shits
+ for (int i = i; i < NUM_MOUSE_CONTEXT; ++i) {
+ ButtonBindingList::iterator it, end = _buttons[i].end();
+ for (it = _buttons[i].begin(); it != end; ++it)
+ for (int a = 0; a < NUM_MOUSE_ACTION; ++a) {
+ Py_XDECREF((*it)->callback[a]);
+ (*it)->callback[a] = 0;