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;
}
Beispiel #4
0
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;
}
Beispiel #6
0
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;
   }
}
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);
}
Beispiel #8
0
// 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);
}