2002-12-30 06:31:45 +00:00
|
|
|
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
|
|
|
|
#ifndef __binding_hh
|
|
|
|
#define __binding_hh
|
|
|
|
|
|
|
|
/*! @file binding.hh
|
|
|
|
@brief I dunno.. some binding stuff?
|
|
|
|
*/
|
|
|
|
|
2002-12-30 22:27:46 +00:00
|
|
|
#include "actions.hh"
|
2002-12-31 19:15:24 +00:00
|
|
|
#include "otk/timer.hh"
|
2002-12-30 22:27:46 +00:00
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <Python.h>
|
|
|
|
}
|
|
|
|
|
2002-12-30 06:31:45 +00:00
|
|
|
#include <string>
|
2003-01-02 20:36:14 +00:00
|
|
|
#include <list>
|
2002-12-30 06:31:45 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace ob {
|
|
|
|
|
2002-12-30 22:27:46 +00:00
|
|
|
class OBClient;
|
|
|
|
|
2002-12-30 06:31:45 +00:00
|
|
|
typedef struct Binding {
|
|
|
|
unsigned int modifiers;
|
|
|
|
unsigned int key;
|
|
|
|
|
|
|
|
bool operator==(struct Binding &b2) { return key == b2.key &&
|
|
|
|
modifiers == b2.modifiers; }
|
|
|
|
bool operator!=(struct Binding &b2) { return key != b2.key ||
|
|
|
|
modifiers != b2.modifiers; }
|
|
|
|
Binding(unsigned int mod, unsigned int k) { modifiers = mod; key = k; }
|
|
|
|
} Binding;
|
|
|
|
|
|
|
|
typedef struct BindingTree {
|
|
|
|
Binding binding;
|
2003-01-02 20:36:14 +00:00
|
|
|
PyObject *callback; // the callback given for the binding in add()
|
|
|
|
bool chain; // true if this is a chain to another key (not an action)
|
2002-12-30 06:31:45 +00:00
|
|
|
|
|
|
|
struct BindingTree *next_sibling; // the next binding in the tree at the same
|
|
|
|
// level
|
|
|
|
struct BindingTree *first_child; // the first child of this binding (next
|
|
|
|
// binding in a chained sequence).
|
2003-01-02 20:36:14 +00:00
|
|
|
BindingTree(PyObject *callback) : binding(0, 0) {
|
|
|
|
this->callback = callback; chain = true; next_sibling = first_child = 0;
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
BindingTree() : binding(0, 0) {
|
2003-01-02 20:36:14 +00:00
|
|
|
this->callback = 0; chain = true; next_sibling = first_child = 0;
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
} BindingTree;
|
|
|
|
|
|
|
|
class OBBindings {
|
|
|
|
public:
|
|
|
|
//! A list of strings
|
|
|
|
typedef std::vector<std::string> StringVect;
|
|
|
|
|
|
|
|
private:
|
2002-12-31 08:46:17 +00:00
|
|
|
BindingTree _tree; // root node of the tree (this doesn't have siblings!)
|
2002-12-30 16:42:15 +00:00
|
|
|
BindingTree *_curpos; // position in the keytree
|
2002-12-30 06:31:45 +00:00
|
|
|
|
2002-12-31 06:59:46 +00:00
|
|
|
Binding _resetkey; // the key which resets the key chain status
|
2002-12-31 19:15:24 +00:00
|
|
|
|
|
|
|
otk::OBTimer _timer;
|
2002-12-30 16:42:15 +00:00
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
PyObject *find(BindingTree *search, bool *conflict) const;
|
|
|
|
BindingTree *buildtree(const StringVect &keylist, PyObject *callback) const;
|
2002-12-30 22:27:46 +00:00
|
|
|
void assimilate(BindingTree *node);
|
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
static void reset(OBBindings *self); // the timer's timeout function
|
2002-12-31 19:15:24 +00:00
|
|
|
|
2002-12-30 06:31:45 +00:00
|
|
|
public:
|
|
|
|
//! Initializes an OBBinding object
|
|
|
|
OBBindings();
|
|
|
|
//! Destroys the OBBinding object
|
|
|
|
virtual ~OBBindings();
|
|
|
|
|
2003-01-02 22:58:32 +00:00
|
|
|
//! Translates a binding string into the actual Binding
|
|
|
|
bool translate(const std::string &str, Binding &b, bool askey = true) const;
|
|
|
|
|
2002-12-30 16:42:15 +00:00
|
|
|
//! Adds a new key binding
|
2002-12-30 06:31:45 +00:00
|
|
|
/*!
|
|
|
|
A binding will fail to be added if the binding already exists (as part of
|
|
|
|
a chain or not), or if any of the strings in the keylist are invalid.
|
|
|
|
@return true if the binding could be added; false if it could not.
|
|
|
|
*/
|
2003-01-02 20:36:14 +00:00
|
|
|
bool add(const StringVect &keylist, PyObject *callback);
|
2002-12-30 06:31:45 +00:00
|
|
|
|
|
|
|
//! Removes a key binding
|
|
|
|
/*!
|
2003-01-02 20:36:14 +00:00
|
|
|
@return The callbackid of the binding, or '< 0' if there was no binding to
|
|
|
|
be removed.
|
2002-12-30 06:31:45 +00:00
|
|
|
*/
|
2003-01-02 20:36:14 +00:00
|
|
|
bool remove(const StringVect &keylist);
|
2002-12-30 06:31:45 +00:00
|
|
|
|
|
|
|
//! Removes all key bindings
|
2003-01-02 20:36:14 +00:00
|
|
|
void removeAll();
|
2002-12-30 16:42:15 +00:00
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
void fire(unsigned int modifiers,unsigned int key, Time time);
|
2002-12-30 22:27:46 +00:00
|
|
|
|
2002-12-31 06:59:46 +00:00
|
|
|
void setResetKey(const std::string &key);
|
|
|
|
|
|
|
|
void grabKeys(bool grab);
|
2002-12-30 06:31:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __binding_hh
|