Handle<Value> TiUIBase::_add(void* userContext, TiObject*, const Arguments& args) { HandleScope handleScope; TiUIBase* obj = (TiUIBase*) userContext; if ((args.Length() > 0) && (args[0]->IsObject())) { TiObject* addObj = getTiObjectFromJsObject(args[0]); if ((addObj == NULL) || (!addObj->isUIObject())) { return ThrowException(String::New(Ti::Msg::Invalid_add_argument)); } TiUIBase* uiObj = (TiUIBase*) addObj; NativeObject* childNO = uiObj->getNativeObject(); if (childNO == NULL) { return ThrowException(String::New(Ti::Msg::Invalid_add_argument)); } NativeObject* parentNO = obj->getNativeObject(); if (N_SUCCEEDED(parentNO->addChildNativeObject(childNO))) { ObjectEntry entry = addObj; obj->childControls_.push_back(entry); obj->jsChildren_->Set(obj->jsChildren_->Length(), addObj->getValue()); } childNO->release(); parentNO->release(); } else { // TODO: expand this exception } return Undefined(); }
Handle<Value> TiUIBase::_remove(void* userContext, TiObject*, const Arguments& args) { HandleScope handleScope; // JavaScript usage: // // arg[0] = Titanium.UI.View // if (args.Length() < 1) { return ThrowException(String::New(Ti::Msg::Missing_argument)); } if (!args[0]->IsObject()) { return ThrowException(String::New(Ti::Msg::Invalid_remove_argument)); } TiUIBase* obj = (TiUIBase*) userContext; TiObject* removeObject = TiObject::getTiObjectFromJsObject(args[0]); if (removeObject == NULL) { return ThrowException(String::New(Ti::Msg::Invalid_remove_argument)); } NativeObject* parentControl = obj->getNativeObject(); if (parentControl == NULL) { return ThrowException(String::New(Ti::Msg::INTERNAL__Missing_native_object)); } vector<ObjectEntry>::const_iterator it; bool foundChild = false; for (it = obj->childControls_.begin(); it != obj->childControls_.end(); it++) { if ((*it).isSameInstance(removeObject)) { NativeObject* childControl = (*it)->getNativeObject(); if (childControl == NULL) { parentControl->release(); return ThrowException(String::New(Ti::Msg::INTERNAL__Missing_native_object)); } parentControl->removeChildNativeObject(childControl); childControl->release(); foundChild = true; break; } } parentControl->release(); if (!foundChild) { TI_WARNING(Ti::Msg::Remove_child_warning); } return Undefined(); }
void TiUITableViewRow::initializeTiObject(TiObject* parentContext) { if (isInitialized()) return; TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_TABLE_VIEW_ROW, this); setNativeObject(obj); obj->release(); }
Handle<Value> TiUIBase::_hide(void* userContext, TiObject*, const Arguments&) { TiUIBase* obj = (TiUIBase*) userContext; NativeObject* no = obj->getNativeObject(); no->setVisibility(false); no->release(); return Undefined(); }
void TiObject::onSetupEvents() { NativeObject* nativeObject = getNativeObject(); if (nativeObject != NULL) { nativeObject->completeInitialization(); nativeObject->release(); } }
void TiUIImageButton::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_IMAGE_BUTTON, this); setNativeObject(obj); obj->release(); } }
void TiAnnotationObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_ANNOTATION, this); setNativeObject(obj); obj->release(); } }
void TiVideoPlayerObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_VIDEOPLAYER, this); setNativeObject(obj); obj->release(); } }
void TiHTTPClientObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiProxy::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_HTTPCLIENT, this); setNativeObject(obj); obj->release(); } }
void TiGeolocation::initializeTiObject(TiObject* parentContext) { if (isInitialized()) { return; } TiProxy::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_GEOLOCATION, this); setNativeObject(obj); obj->release(); }
void TiAccelerometer::initializeTiObject(TiObject* parentContext) { if (isInitialized()) { return; } TiProxy::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_ACCELEROMETER, this); setNativeObject(obj); obj->release(); }
void TiUIAlertDialog::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiProxy::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_ALERTDIALOG, this); setNativeObject(obj); obj->release(); } }
void TiTCPSocketObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiIOStreamObject::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_TCPSOCKET, this); setNativeObject(obj); obj->release(); } }
void TiUITextArea::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_TEXT_AREA, this); setNativeObject(obj); obj->release(); } }
void TiMapView::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_MAPVIEW, this); setNativeObject(obj); obj->release(); } }
void TiAudioRecorderObject::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiUIBase::initializeTiObject(parentContext); NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_AUDIORECORDER, this); setNativeObject(obj); obj->release(); } }
int TitaniumRuntime::messageLoop(void* context) { TitaniumRuntime* self = (TitaniumRuntime*)context; NativeObject* nativeObject = self->objectFactory_->getRootContainer(); self->mainApp_->setScene(nativeObject); if (nativeObject != NULL) { nativeObject->release(); } return bb::cascades::Application::exec(); }
void TiUIBase::initializeTiObject(TiObject* parentContext) { if (!isInitialized()) { TiProxy::initializeTiObject(parentContext); /* Don't create a native view object for derived classes */ if (string("View") == getName()) { NativeObject* obj = getNativeObjectFactory()->createNativeObject(N_TYPE_VIEW, this); setNativeObject(obj); obj->release(); } } }
Handle<Value> TiUITab::_open(void* userContext, TiObject*, const Arguments& args) { HandleScope handleScope; if ((args.Length() > 0) && (args[0]->IsObject())) { TiObject* addObj = getTiObjectFromJsObject(args[0]); if ((addObj == NULL) || (!addObj->isUIObject())) { return Undefined(); } TiUIBase* uiObj = (TiUIBase*) addObj; NativeObject* win = uiObj->getNativeObject(); TiUITab* obj = (TiUITab*) userContext; NativeObject* tab = obj->getNativeObject(); tab->openWindowOnTab(win); tab->release(); win->release(); } else { return ThrowException(String::New(Native::Msg::Expected_argument_of_type_object_or_external)); } return Undefined(); }
Handle<Value> TiProxy::_fireEvent(void* userContext, TiObject*, const Arguments& args) { if (args.Length() < 1) { return Undefined(); } const TiProxy* obj = (TiProxy*) userContext; if(QString(obj->getName()) == "App") { Local<Object> eventParams = Object::New(); if(args.Length() > 1) { eventParams->Set(String::New("data"), args[1]->ToObject()); } else { eventParams->Set(String::New("data"), Object::New()); } eventParams->Set(String::New("id"), args[0]->ToString()); Local<String> event = JSON::Stringify(eventParams); QString eventString = titanium::V8ValueToQString(event); QList<TiUIWebView*> webViews = TiUIWebView::getWebViews(); for(int i = 0, len = webViews.length(); i < len; i++) { webViews.at(i)->getNativeWebView()->postMessage(eventString); } } NativeObject* no = obj->getNativeObject(); if (!no) return Undefined(); const String::Utf8Value name(args[0]->ToString()); if (args.Length() >= 2) { const TiObject event("", args[1]); no->fireEvent(*name, &event); } else { no->fireEvent(*name, NULL); } no->release(); return Undefined(); }
void TiProxy::setParametersFromObject(void* userContext, Local<Object> obj) { HandleScope handleScope; Handle<Value> value; Handle<Value> controlValue = getValue(); if (!controlValue->IsObject()) { return; } Handle<Array> propNames = obj->GetPropertyNames(); uint32_t props = propNames->Length(); Local<Value> propValue; for (uint32_t i = 0; i < props; i++) { Handle<String> propString = Handle<String>::Cast(propNames->Get(Integer::New(i))); String::Utf8Value propNameUTF(propString); Local<Value> propValue = obj->Get(propString); TiObject* foundProp = onLookupMember(*propNameUTF); if (foundProp != NULL) { TiObject* addObj = getTiObjectFromJsObject(propValue); if (addObj) { TiProxy* obj = (TiProxy*) userContext; TiProxy* uiObj = (TiProxy*) addObj; NativeObject* childNO = uiObj->getNativeObject(); NativeObject* parentNO = obj->getNativeObject(); parentNO->addChildNativeObject(childNO); parentNO->release(); } else { foundProp->setValue(propValue); } } else { // Set any custom properties onto the JS object. getValue()->ToObject()->ForceSet(propString, propValue); } } }
void TiProxy::onAddEventListener(const char* eventName, Handle<Function> eventFunction) { NativeObject* no = getNativeObject(); if (no == NULL) { // To support events we need to create a native proxy // instance here if no native object has been set yet. no = new NativeProxyObject(this); setNativeObject(no); } Handle<Object> source = Handle<Object>::Cast(getValue()); TiV8Event* event = TiV8Event::createEvent(eventName, eventFunction, source); no->setEventHandler(eventName, event); no->release(); no = NULL; int id = event->getId(); eventFunction->SetHiddenValue(String::New("POINTER"), External::New(event)); eventFunction->SetHiddenValue(String::New("OWNER"), External::New(this)); eventFunction->SetHiddenValue(String::New("ID"), Integer::New(id)); }
void TiProxy::onRemoveEventListener(const char* eventName, Handle<Function> eventFunction) { NativeObject* no = getNativeObject(); if (no == NULL) { return; } // Get the event subscriber's id so we know which to remove from the event container. Handle<Int32> v8id = eventFunction->GetHiddenValue(String::New("ID"))->ToInt32(); if ((v8id.IsEmpty()) || (v8id->Value() == 0)) { return; } // Make sure that the function being removed has been added to this event container. Handle<Value> v8extValue = eventFunction->GetHiddenValue(String::New("OWNER")); if ((v8extValue.IsEmpty()) || (!v8extValue->IsExternal())) { return; } Handle<External> v8ext = Handle<External>::Cast(v8extValue); TiProxy* referencedControl = (TiProxy*)v8ext->Value(); if (referencedControl != this) { // User was attempting to remove an event handler from a control that it // doesn't belong to. return; } no->removeEventHandler(eventName, v8id->Value()); no->release(); no = NULL; // Free up the memory used by the TiV8Event Handle<Value> v8evtValue = eventFunction->GetHiddenValue(String::New("POINTER")); if ((v8evtValue.IsEmpty()) || (!v8evtValue->IsExternal())) { return; } Handle<External> v8evt = Handle<External>::Cast(v8evtValue); delete(TiV8Event*)v8evt->Value(); }
Ti::TiValue Ti::TiViewProxy::add(Ti::TiValue value) { if(value.isProxy()) { Ti::TiViewProxy *childProxy = static_cast<Ti::TiViewProxy*>(value.toProxy()); childProxy->clearWeak(); _childViewsProxies.append(childProxy); Ti::TiView* childView = childProxy->getView(); Ti::TiView* thisView = getView(); thisView->add(childView); childProxy->_parentProxy = this; } else { TiObject* addObj = TiObject::getTiObjectFromJsObject(value.toJSValue()); TiUIBase* uiObj = (TiUIBase*) addObj; NativeObject* childNO = uiObj->getNativeObject(); getView()->addOldObject(childNO); Local<Value> children = _jsObject->Get(String::New("children")); Local<Array> array; if(children.IsEmpty() || children->IsUndefined()) { array = Array::New(); _jsObject->Set(String::New("children"), array); } else { array = Local<Array>::Cast(children); } array->Set(array->Length(), value.toJSValue()); childNO->release(); } Ti::TiValue val; val.setUndefined(); return val; }
VALUE_MODIFY TiObject::_valueModify(int propertyNumber, TiObject* value, void* context) { TiObject* self = static_cast<TiObject*>(context); NativeObject* object = self->getNativeObject(); if (object == NULL) { return VALUE_MODIFY_NOT_SUPPORTED; } VALUE_MODIFY modify = VALUE_MODIFY_ALLOW; switch (object->setPropertyValue(propertyNumber, value)) { case NATIVE_ERROR_OK: modify = VALUE_MODIFY_ALLOW; break; case NATIVE_ERROR_NOTSUPPORTED: modify = VALUE_MODIFY_ALLOW; //VALUE_MODIFY_NOT_SUPPORTED; break; default: modify = VALUE_MODIFY_INVALID; break; } object->release(); return modify; }