33#ifndef DRAIN_IMAGE_MOUSEXML2_H_
34#define DRAIN_IMAGE_MOUSEXML2_H_
41#include "drain/js/coords.h"
55 typedef DRAIN_XML_TREE(N) tree_t;
58 MouseEventXML(tree_t & root, drain::image::MouseXML::EventClass mouseEvent,
const std::string & owner) :
61 handlerName(getHandlerFunctionName(mouseEvent)),
62 initName(getInitialiserFunctionName(mouseEvent)),
63 scopeJS(ensureListenerHandler(root, handlerName)),
66 scopeJS[owner]->setProgramComment(
"Set by: ", owner);
84 bool routineIsSet(tree_t & elem)
const {
86 drain::Logger(__FILE__, __FUNCTION__).
warn(
"Owner undefined, potential duplicate listeners cannot be identified");
90 tree_t & listenerScope = MouseXML::getListenerScope(root, handlerName);
91 return listenerScope.hasChild(owner);
97 void setListenerNEW(tree_t & elem)
const {
98 attachListener(elem, eventName, handlerName);
102 tree_t & getListenerRoutine()
const {
105 tree_t & listenerScope = MouseXML::getListenerScope(root, handlerName);
114 return listenerScope;
123 void defineVariable(
const std::string & name,
const V & value)
const;
127 void useCoordinates(CoordinateProcessing level)
const {
128 adjustListenerGeoRef(scopeJS, level);
133 void connectTag(
const std::string & s)
const;
136 void connectTag(
const typename N::tag_t & type)
const {
146 void connectElement(
const typename N::tag_t & type)
const {
152 void connectElement(
const std::string & arg)
const {
157 void connectElement(
const char *arg)
const {
193 const std::string eventName;
194 const std::string handlerName;
195 const std::string initName;
206 std::set<std::string> connectedObjects;
218 DRAIN_XML_TREE(N) & scope = getListenerInitScope(root, initName);
219 DRAIN_XML_TREE(N) & subScope = scope[N::tag_t::SCOPE_CURLY](N::tag_t::SCOPE_CURLY);
220 if (subScope.empty()){
221 subScope->setText(
"with(listener.ctx)");
222 subScope.addChild()->setProgramComment(
"Scope exposed by ", __FUNCTION__);
239void MouseEventXML<N>::connectClass(
const drain::ClassXML & cls)
const {
240 Logger mout(__FILE__, __FUNCTION__);
242 mout.debug(
"connecting CLASS ", cls,
" = ", cls.strPrefixed());
243 DRAIN_XML_TREE(N) & scope = getListenerInitScope(root, initName);
244 scope[cls]->setText(
"listener.ctx['", cls,
"'] = group.querySelector('", cls.strPrefixed(),
"')");
245 connectedObjects.insert(cls);
254void MouseEventXML<N>::defineVariable(
const std::string & name,
const V & value)
const {
255 Logger mout(__FILE__, __FUNCTION__);
258 DRAIN_XML_TREE(N) & scope = getListenerInitScope(root, initName);
259 scope[name]->setText(
"listener.ctx['", name,
"'] = ", sprinter(value,
Sprinter::jsLayout),
';');
269void MouseEventXML<N>::connectTag(
const std::string & arg)
const {
270 DRAIN_XML_TREE(N) & scope = getListenerInitScope(root, initName);
271 scope[arg]->setText(
"listener.ctx['", arg,
"'] = group.querySelector('", arg,
"')");
272 connectedObjects.insert(arg);
A wrapper marking string an CSS effect.
Definition ClassXML.h:57
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:440
static const SprinterLayout plainLayout
Display plain values, concatenating them with comma (except for strings).
Definition Sprinter.h:212
static const SprinterLayout jsLayout
JavaScript layout. Like JSON layout, but keys without hyphens.
Definition Sprinter.h:227
Definition MouseEventXML.h:51
tree_t & getListenerInitSubScope() const
Scope inside ctx.
static std::string getEventFunctionName(MouseXML::EventClass eventKey)
Modifies short mouse event name like "click" to "onmouseclick", or prefixed form "handleClick".
Definition MouseXML.cpp:73
A container for a static dictionary of enumeration values.
Definition Enum.h:51