m_python_keys.insert(std::pair<std::string,ePythonKeyBinding>(context, bind));
}
+struct call_entry
+{
+ PyObject *m_fnc, *m_arg;
+ eWidget *m_widget;
+ void *m_widget_arg, *m_widget_arg2;
+ call_entry(PyObject *fnc, PyObject *arg): m_fnc(fnc), m_arg(arg), m_widget(0), m_widget_arg(0) { }
+ call_entry(eWidget *widget, void *arg, void *arg2): m_fnc(0), m_arg(0), m_widget(widget), m_widget_arg(arg), m_widget_arg2(arg2) { }
+};
+
void eActionMap::keyPressed(int device, int key, int flags)
{
+ std::list<call_entry> call_list;
+
/* iterate active contexts. */
for (std::multimap<int,eActionBinding>::const_iterator c(m_bindings.begin()); c != m_bindings.end();)
{
/* is this a native context? */
if (i->second.m_widget)
{
- std::multimap<std::string,eNativeKeyBinding>::const_iterator
- k = m_native_keys.lower_bound(i->second.m_context),
- e = m_native_keys.upper_bound(i->second.m_context);
-
- for (; k != e; ++k)
+ /* is this a named context, i.e. not the wildcard? */
+ if (i->second.m_context.size())
{
- if (
- // (k->second.m_device == m_device) &&
- (k->second.m_key == key) &&
- ((k->second.m_flags & flags)==flags))
+ std::multimap<std::string,eNativeKeyBinding>::const_iterator
+ k = m_native_keys.lower_bound(i->second.m_context),
+ e = m_native_keys.upper_bound(i->second.m_context);
+
+ for (; k != e; ++k)
{
- if (i->second.m_widget->event(eWidget::evtAction, 0, (void*)k->second.m_action))
- return;
+ if (
+ // (k->second.m_device == m_device) &&
+ (k->second.m_key == key) &&
+ (k->second.m_flags & (1<<flags)))
+ call_list.push_back(call_entry(i->second.m_widget, (void*)i->second.m_id, (void*)k->second.m_action));
}
+ } else
+ {
+ /* wildcard - get any keys. */
+ if (i->second.m_widget->event(eWidget::evtKey, (void*)key, (void*)flags))
+ return;
}
} else if (i->second.m_fnc)
{
- std::multimap<std::string,ePythonKeyBinding>::const_iterator
- k = m_python_keys.lower_bound(i->second.m_context),
- e = m_python_keys.upper_bound(i->second.m_context);
-
- for (; k != e;)
+ if (i->second.m_context.size())
{
- if (
- // (k->second.m_device == m_device) &&
- (k->second.m_key == key) &&
- ((k->second.m_flags & flags)==flags))
+ std::multimap<std::string,ePythonKeyBinding>::const_iterator
+ k = m_python_keys.lower_bound(i->second.m_context),
+ e = m_python_keys.upper_bound(i->second.m_context);
+
+ for (; k != e;)
{
- PyObject *pArgs = PyTuple_New(2);
- PyTuple_SetItem(pArgs, 0, PyString_FromString(k->first.c_str()));
- PyTuple_SetItem(pArgs, 1, PyString_FromString(k->second.m_action.c_str()));
- ++k;
- ePython::call(i->second.m_fnc, pArgs);
- Py_DECREF(pArgs);
- } else
- ++k;
+ if (
+ // (k->second.m_device == m_device) &&
+ (k->second.m_key == key) &&
+ (k->second.m_flags & (1<<flags)))
+ {
+ PyObject *pArgs = PyTuple_New(2);
+ PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(k->first.c_str()));
+ PyTuple_SET_ITEM(pArgs, 1, PyString_FromString(k->second.m_action.c_str()));
+ ++k;
+ Py_INCREF(i->second.m_fnc);
+ call_list.push_back(call_entry(i->second.m_fnc, pArgs));
+ } else
+ ++k;
+ }
+ } else
+ {
+ PyObject *pArgs = PyTuple_New(2);
+ PyTuple_SET_ITEM(pArgs, 0, PyInt_FromLong(key));
+ PyTuple_SET_ITEM(pArgs, 1, PyInt_FromLong(flags));
+ Py_INCREF(i->second.m_fnc);
+ call_list.push_back(call_entry(i->second.m_fnc, pArgs));
}
}
}
+
+ int res = 0;
+ /* we need to iterate over all to not loose a reference */
+ for (std::list<call_entry>::iterator i(call_list.begin()); i != call_list.end(); ++i)
+ {
+ if (i->m_fnc)
+ {
+ if (!res)
+ res = ePython::call(i->m_fnc, i->m_arg);
+ Py_DECREF(i->m_fnc);
+ Py_DECREF(i->m_arg);
+ } else if (i->m_widget)
+ {
+ if (!res)
+ res = i->m_widget->event(eWidget::evtAction, (void*)i->m_widget_arg, (void*)i->m_widget_arg2 );
+ }
+ }
}
eAutoInitPtr<eActionMap> init_eActionMap(eAutoInitNumbers::actions, "eActionMap");