void dmz::JsExtV8Input::receive_switch_event ( const Handle Channel, const InputEventSwitch &Value) { if (_v8Context.IsEmpty () == false) { v8::Context::Scope cscope(_v8Context); v8::HandleScope scope; V8Object event = v8::Object::New (); event->Set (_sourceStr, v8::Integer::New (Value.get_source_handle ())); event->Set (_idStr, v8::Integer::New (Value.get_switch_id ())); event->Set (_valueStr, v8::Integer::New (Value.get_switch_value ())); event->Set (_previousStr, v8::Integer::New (Value.get_switch_previous_value ())); const int Argc (3); V8Value argv[Argc]; argv[0] = v8::Integer::New (Channel); argv[1] = event; _do_all_callbacks (Argc, argv, _leverTable); } }
dmz::V8Value dmz::JsModuleUiV8QtBasic::_create_message_box (const v8::Arguments &Args) { v8::HandleScope scope; V8Value result = v8::Undefined (); JsModuleUiV8QtBasic *self = _to_self (Args); if (self) { QWidget *parent = 0; V8Object params = v8_to_object (Args[0]); if (Args.Length () >= 2) { parent = self->_to_qwidget (Args[1]); } if (!params.IsEmpty ()) { QMessageBox *dialog = self->_create_message_box (params, parent); result = self->create_v8_qwidget (dialog); } } return scope.Close (result); }
dmz::V8Value dmz::JsModuleUiV8QtBasic::create_v8_qevent (QEvent *value) { v8::Context::Scope cscope (_state.context); v8::HandleScope scope; V8Value result = v8::Undefined (); if (value) { V8Object obj; // NOTE: Adding a default will cause a DMZ crash for some events when the "type" // function is called. Until the specific reason is found, add and test events // on a case-by-case basis. switch (value->type ()) { case QEvent::MouseButtonDblClick: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::Enter: case QEvent::Leave: case QEvent::MouseMove: if (!_mouseEventCtor.IsEmpty ()) { obj = _mouseEventCtor->NewInstance (); } break; case QEvent::GraphicsSceneMouseDoubleClick: case QEvent::GraphicsSceneMouseMove: case QEvent::GraphicsSceneMousePress: case QEvent::GraphicsSceneMouseRelease: if (!_gsceneMouseEventCtor.IsEmpty ()) { obj = _gsceneMouseEventCtor->NewInstance (); } break; case QEvent::Resize: if (!_resizeEventCtor.IsEmpty ()) { obj = _resizeEventCtor->NewInstance (); } break; } if (!obj.IsEmpty ()) { obj->SetInternalField (0, v8::External::Wrap ((void *)value)); result = obj; } } return scope.Close (result); }
QTreeWidgetItem * dmz::JsModuleUiV8QtBasic::_to_qtreewidgetitem (V8Value value) { v8::HandleScope scope; QTreeWidgetItem *result (0); V8Object obj = v8_to_object (value); if (!obj.IsEmpty ()) { if (_treeWidgetItemTemp->HasInstance (obj)) { result = (QTreeWidgetItem *)v8::External::Unwrap (obj->GetInternalField (0)); } } return result; }
dmz::V8QtObject::V8QtObject ( const V8Object &Self, QObject *object, JsModuleUiV8QtBasicState *state) : QObject (0), _object (object), _state (state), _current (0), _deleteObject (True) { setObjectName ("V8QtObject"); if (!Self.IsEmpty ()) { Self->SetInternalField (0, v8::External::Wrap ((void *)this)); self = V8ObjectPersist::New (Self); } }
QEvent * dmz::JsModuleUiV8QtBasic::_to_qevent (V8Value value) { v8::HandleScope scope; QEvent *result (0); V8Object obj = v8_to_object (value); if (!obj.IsEmpty ()) { if (_eventTemp->HasInstance (obj) || _gsceneMouseEventTemp->HasInstance (obj) || _mouseEventTemp->HasInstance (obj) || _resizeEventTemp->HasInstance (obj)) { result = (QEvent *)v8::External::Unwrap (obj->GetInternalField (0)); } } return result; }
dmz::V8Value dmz::JsModuleUiV8QtBasic::_mouse_event_posf (const v8::Arguments &Args) { v8::HandleScope scope; V8Object result; JsModuleUiV8QtBasic *self = _to_self (Args); if (self) { QMouseEvent *event = (QMouseEvent *)self->_to_qevent (Args.This ()); if (event) { QPointF pos = event->posF (); result = v8::Object::New (); result->Set(v8::String::NewSymbol ("x"), v8::Number::New (pos.x ())); result->Set(v8::String::NewSymbol ("y"), v8::Number::New (pos.y ())); } } return scope.Close (result); }
dmz::V8Value dmz::JsModuleUiV8QtBasic::create_v8_qtreewidgetitem (QTreeWidgetItem *value) { v8::Context::Scope cscope (_state.context); v8::HandleScope scope; V8Value result = v8::Undefined (); if (value) { V8Object obj; if (!_treeWidgetItemCtor.IsEmpty ()) { obj = _treeWidgetItemCtor->NewInstance (); } if (!obj.IsEmpty ()) { obj->SetInternalField (0, v8::External::Wrap ((void *)value)); result = obj; } } return scope.Close (result); }
void dmz::JsExtV8Input::receive_key_event ( const Handle Channel, const InputEventKey &Value) { if (_v8Context.IsEmpty () == false) { v8::Context::Scope cscope(_v8Context); v8::HandleScope scope; V8Object event = v8::Object::New (); event->Set (_sourceStr, v8::Integer::New (Value.get_source_handle ())); event->Set (_keyStr, v8::Integer::New (Value.get_key ())); event->Set (_stateStr, v8::Boolean::New (Value.get_key_state ())); const int Argc (3); V8Value argv[Argc]; argv[0] = v8::Integer::New (Channel); argv[1] = event; _do_all_callbacks (Argc, argv, _keyTable); } }
void dmz::JsExtV8HTTPCurl::_add_upload ( const V8Object &Self, const String &Address, const String &Value, const V8Function &Func) { Upload *ul = new Upload (Address, Value); if (ul) { if (Self.IsEmpty () == false) { ul->self = V8ObjectPersist::New (Self); } if (Func.IsEmpty () == false) { ul->func = V8FunctionPersist::New (Func); } ul->next = _ulList; _ulList = ul; } }
// JsExtV8Input Interface dmz::V8Value dmz::JsExtV8Input::_register_callback (const v8::Arguments &Args, const Mask &Type) { v8::HandleScope scope; V8Value result = v8::Undefined (); const int Length = Args.Length (); V8Object src = v8_to_object (Args[0]); Handle channel (_defaultChannel); V8Function func; if (Length == 2) { func = v8_to_function (Args[1]); } else if (Length > 2) { channel = _to_handle (Args[1]); func = v8_to_function (Args[2]); } const Handle Obs = _core ? _core->get_instance_handle (src) : 0; ObsStruct *os = _obsTable.lookup (Obs); if (Obs && !os) { os = new ObsStruct; if (os && !_obsTable.store (Obs, os)) { delete os; os = 0; } } CallbackTable *ct (0); if (channel) { if (Type.contains (InputEventChannelStateMask)) { ct = _stateTable.lookup (channel); } else if (Type.contains (InputEventAxisMask)) { ct = _axisTable.lookup (channel); } else if (Type.contains (InputEventButtonMask)) { ct = _buttonTable.lookup (channel); } else if (Type.contains (InputEventSwitchMask)) { ct = _leverTable.lookup (channel); } else if (Type.contains (InputEventKeyMask)) { ct = _keyTable.lookup (channel); } else if (Type.contains (InputEventMouseMask)) { ct = _mouseTable.lookup (channel); } else if (Type.contains (InputEventDataMask)) { ct = _dataTable.lookup (channel); } if (!ct) { ct = new CallbackTable (channel, Type); if (ct) { if (Type.contains (InputEventChannelStateMask)) { if (!_stateTable.store (channel, ct)) { delete ct; ct = 0; } } else if (Type.contains (InputEventAxisMask)) { if (!_axisTable.store (channel, ct)) { delete ct; ct = 0; } } else if (Type.contains (InputEventButtonMask)) { if (!_buttonTable.store (channel, ct)) { delete ct; ct = 0; } } else if (Type.contains (InputEventSwitchMask)) { if (!_leverTable.store (channel, ct)) { delete ct; ct = 0; } } else if (Type.contains (InputEventKeyMask)) { if (!_keyTable.store (channel, ct)) { delete ct; ct = 0; } } else if (Type.contains (InputEventMouseMask)) { if (!_mouseTable.store (channel, ct)) { delete ct; ct = 0; } } else if (Type.contains (InputEventDataMask)) { if (!_dataTable.store (channel, ct)) { delete ct; ct = 0; } } } } if (ct && os && (src.IsEmpty () == false) && (func.IsEmpty () == false)) { CallbackStruct *cb = new CallbackStruct (*ct); if (cb) { const Boolean Activate = (ct->table.get_count () == 0); if (ct->table.store (Obs, cb)) { cb->self = V8ObjectPersist::New (src); cb->func = V8FunctionPersist::New (func); result = func; cb->next = os->list; os->list = cb; if (Activate) { activate_input_channel (channel, Type | InputEventChannelStateMask); } else if ((Type & InputEventChannelStateMask) && _active.contains (channel)) { const int Argc (3); V8Value argv[Argc]; argv[0] = v8::Integer::New (channel); argv[1] = v8::Boolean::New (true); CallbackTable tmp (channel, Type); tmp.table.store (Obs, cb); HandleContainer called; _do_callback (Argc, argv, tmp, called); tmp.table.remove (Obs); } } else { delete cb; cb = 0; } } } } return scope.Close (result); }