Example #1
0
	void DomElement::set_child_string_ns(const DomString &namespace_uri, const DomString &qualified_name, const DomString &value)
	{
		DomString local_name;
		DomString::size_type pos = qualified_name.find(L':');
		if (pos != DomString::npos)
			local_name = qualified_name.substr(pos + 1);
		else
			local_name = qualified_name;

		DomElement element = named_item_ns(namespace_uri, local_name).to_element();
		if (element.is_null())
		{
			element = get_owner_document().create_element_ns(namespace_uri, qualified_name);
			append_child(element);
		}

		DomText dom_text = get_owner_document().create_text_node(value);
		if (element.get_first_child().is_text())
		{
			DomNode temp_domnode = element.get_first_child();
			replace_child(dom_text, temp_domnode);
		}
		else
		{
			element.append_child(dom_text);
		}
	}
Example #2
0
void WWidgetItemImpl::createComponent(DomElement *parentContainer)
{
  DomElement *e = item_->widget()->createSDomElement(WApplication::instance());

  e->setProperty(PropertyStyle, e->getProperty(PropertyStyle)
		  + "position:absolute;left:-10000px;top:-10000px;"
		  "visibility:hidden;");
  Container *c = dynamic_cast<Container *>(item_->widget());

  if (!c) {
    std::stringstream js;

    js << "var " << var_ << "=new Ext.BoxComponent({id:'"
       << id_ << "',applyTo:'" << item_->widget()->id() << "'";
    addConfig(js);
    Container::setSizeConfig(js, item_->widget());
    js << "});{var s="
       << item_->widget()->jsRef() << ";s.style.position='';"
      "s.style.left='';"
      "s.style.top='';"
      "s.style.visibility='';}";

    e->callJavaScript(js.str());
  }

  parentContainer->addChild(e);
}
Example #3
0
void WLineEdit::updateDom(DomElement& element, bool all)
{
  if (all || flags_.test(BIT_CONTENT_CHANGED)) {
    element.setProperty(Wt::PropertyValue, content_.toUTF8());
    flags_.reset(BIT_CONTENT_CHANGED);
  }

  if (all || flags_.test(BIT_ECHO_MODE_CHANGED)) {
    element.setAttribute("type", echoMode_ == Normal ? "text" : "password");
    flags_.reset(BIT_ECHO_MODE_CHANGED);
  }

  if (all || flags_.test(BIT_TEXT_SIZE_CHANGED)) {
    element.setAttribute("size",
			 boost::lexical_cast<std::string>(textSize_));
    flags_.reset(BIT_TEXT_SIZE_CHANGED);
  }

  if (all || flags_.test(BIT_MAX_LENGTH_CHANGED)) {
    if (!all || maxLength_ > 0)
      element.setAttribute("maxLength",
			   boost::lexical_cast<std::string>(maxLength_));

    flags_.reset(BIT_MAX_LENGTH_CHANGED);
  }

  WFormWidget::updateDom(element, all);
}
Example #4
0
void WContainerWidget::rootAsJavaScript(WApplication *app, std::ostream& out,
					bool all)
{
  std::vector<WWidget *> *toAdd
    = all ? children_ : (transientImpl_ ? &transientImpl_->addedChildren_ : 0);

  if (toAdd)
    for (unsigned i = 0; i < toAdd->size(); ++i) {
      DomElement *c = (*toAdd)[i]->createSDomElement(app);

      app->streamBeforeLoadJavaScript(out, false);

      c->callMethod("omousemove=function(e) {"
		    "if (!e) e = window.event;"
		    "return " + app->javaScriptClass()
		    + "._p_.dragDrag(event); }");
      c->callMethod("mouseup=function(e) {"
		    "if (!e) e = window.event;"
		    "return " + app->javaScriptClass()
		  + "._p_.dragEnd(event);}");
      c->callMethod("dragstart=function(){return false;}");
      c->asJavaScript(out);
      delete c;
    }

  if (transientImpl_)
    transientImpl_->addedChildren_.clear();

  if (!all) {
    /* Note: we ignore rendering of deletion of a bound widget... */
  }

  // FIXME
  propagateRenderOk(false);
}
Example #5
0
void Project::save_item(DomElement dom_parent, ProjectItem *item)
{
	DomElement dom_item;
	if (dynamic_cast<ProjectFolderItem*>(item))
	{
		ProjectFolderItem *folder_item = dynamic_cast<ProjectFolderItem*>(item);
		dom_item = dom_parent.get_owner_document().create_element("folder");
		dom_item.set_child_string("path", folder_item->path);
	}
	else if (dynamic_cast<ProjectFilterItem*>(item))
	{
		ProjectFilterItem *filter_item = dynamic_cast<ProjectFilterItem*>(item);
		dom_item = dom_parent.get_owner_document().create_element("filter");
		dom_item.set_child_string("name", filter_item->name);
	}
	else if (dynamic_cast<ProjectFileItem*>(item))
	{
		ProjectFileItem *file_item = dynamic_cast<ProjectFileItem*>(item);
		dom_item = dom_parent.get_owner_document().create_element("file");
		dom_item.set_child_string("filename", file_item->filename);
	}
	else
	{
		throw Exception("Unknown item type");
	}

	save_item_children(dom_item, item);
	dom_parent.append_child(dom_item);
}
Example #6
0
void WFileUpload::getDomChanges(std::vector<DomElement *>& result)
{
  if (renderState() == RenderUpdate) {
    if (!methodIframe_) {
      DomElement *e = DomElement::getForUpdate(this, DomElement::INPUT);

      updateDom(*e, false);

      result.push_back(e);
    } else {
      DomElement *e = DomElement::getForUpdate(this, DomElement::FORM);

      updateDom(*e, false);

      if (doUpload_) {
	iframe_ = wApp->useIframe();
	e->setAttribute("target", iframe_->formName());
	e->callMethod("submit()");
	doUpload_ = false;
      }

      result.push_back(e);
    }
  }
}
Example #7
0
void WPaintedWidget::getDomChanges(std::vector<DomElement *>& result,
				   WApplication *app)
{
  DomElement *e = DomElement::getForUpdate(this, DomElement_DIV);
  updateDom(*e, false);
  result.push_back(e);

  bool createdNew = createPainter();

  if (needRepaint_) {
    WPaintDevice *device = painter_->getPaintDevice
      ((repaintFlags_ & PaintUpdate) && !createdNew);

    if (renderWidth_ != 0 && renderHeight_ != 0) {
      paintEvent(device);

#ifdef WT_TARGET_JAVA
      if (device->painter())
	device->painter()->end();
#endif // WT_TARGET_JAVA
    }

    if (createdNew) {
      DomElement *canvas = DomElement::getForUpdate('p' + id(), DomElement_DIV);
      canvas->removeAllChildren();
      painter_->createContents(canvas, device);
      result.push_back(canvas);
    } else {
      painter_->updateContents(result, device);
    }

    needRepaint_ = false;
    repaintFlags_ = 0;
  }
}
Example #8
0
void WText::updateDom(DomElement& element, bool all)
{
  if (flags_.test(BIT_TEXT_CHANGED) || all) {
    std::string text = formattedText();
    if (flags_.test(BIT_TEXT_CHANGED) || !text.empty())
      element.setProperty(Wt::PropertyInnerHTML, text);
    flags_.reset(BIT_TEXT_CHANGED);
  }

  if (flags_.test(BIT_WORD_WRAP_CHANGED) || all) {
    if (!all || !flags_.test(BIT_WORD_WRAP))
      element.setProperty(Wt::PropertyStyleWhiteSpace,
			  flags_.test(BIT_WORD_WRAP) ? "normal" : "nowrap");
    flags_.reset(BIT_WORD_WRAP_CHANGED);
  }

  if (flags_.test(BIT_PADDINGS_CHANGED)
      || (all && padding_ &&
	  !(padding_[0].isAuto() && padding_[1].isAuto()))) {
    
    element.setProperty(PropertyStylePaddingRight, padding_[0].cssText());
    element.setProperty(PropertyStylePaddingLeft, padding_[1].cssText());

    flags_.reset(BIT_PADDINGS_CHANGED);
  }

  WInteractWidget::updateDom(element, all);
}
Example #9
0
void WWidgetVectorPainter::updateContents(std::vector<DomElement *>& result,
					  WPaintDevice *device)
{
  WVectorImage *vectorDevice = dynamic_cast<WVectorImage *>(device);

  if (widget_->repaintFlags_ & PaintUpdate) {
    DomElement *painter = DomElement::updateGiven
      (WT_CLASS ".getElement('p" + widget_->id()+ "').firstChild",
       DomElement_DIV);

    painter->setProperty(PropertyAddedInnerHTML, vectorDevice->rendered());

    WApplication *app = WApplication::instance();
    if (app->environment().agentIsOpera())
      painter->callMethod("forceRedraw();");

    result.push_back(painter);
  } else {
    DomElement *canvas = DomElement::getForUpdate
      ('p' + widget_->id(), DomElement_DIV);

    /*
     * In fact, we should use another property, since we could be using
     * document.importNode() instead of myImportNode() since the xml does not
     * need to be interpreted as HTML...
     */
    canvas->setProperty(PropertyInnerHTML, vectorDevice->rendered());
    result.push_back(canvas);
  }

  widget_->sizeChanged_ = false;

  delete device;
}
Example #10
0
void WWidgetCanvasPainter::updateContents(std::vector<DomElement *>& result,
					  WPaintDevice *device)
{
  WCanvasPaintDevice *canvasDevice = dynamic_cast<WCanvasPaintDevice *>(device);

  if (widget_->sizeChanged_) {
    DomElement *canvas = DomElement::getForUpdate('c' + widget_->id(),
						  DomElement_CANVAS);
    canvas->setAttribute("width",
		 boost::lexical_cast<std::string>(widget_->renderWidth_));
    canvas->setAttribute("height",
		 boost::lexical_cast<std::string>(widget_->renderHeight_));
    result.push_back(canvas);

    widget_->sizeChanged_ = false;
  }

  bool domText = canvasDevice->textMethod() == WCanvasPaintDevice::DomText;

  DomElement *el
    = DomElement::getForUpdate(domText ? 't' + widget_->id() : widget_->id(),
			       DomElement_DIV);
  if (domText)
    el->removeAllChildren();

  canvasDevice->render('c' + widget_->id(), el);

  result.push_back(el);

  delete device;
}
Example #11
0
void WSelectionBox::updateDom(DomElement& element, bool all)
{
  if (configChanged_ || all) {
    element.setAttribute("size", std::to_string(verticalSize_));

    if (!all || (selectionMode_ == SelectionMode::Extended)) {
      element.setProperty(Property::Multiple,
			  selectionMode_ == SelectionMode::Extended
			  ? "true" : "false");
      if (!all)
	selectionChanged_ = true;
    }

    configChanged_ = false;
  }

  if (selectionMode_ == SelectionMode::Extended) {
    if (selectionChanged_ && !all) {
      for (int i = 0; i < count(); ++i) {
	element.callMethod("options[" + std::to_string(i) + "].selected="
			   + (isSelected(i) ? "true" : "false"));
      }
    }
    selectionChanged_ = false;
  }

  WComboBox::updateDom(element, all);
}
Example #12
0
void WSlider::updateDom(DomElement& element, bool all)
{
  if (paintedSlider_)
    paintedSlider_->doUpdateDom(element, all);
  else {
    if (all || changed_) {
      element.setAttribute("type", "range");
      element.setProperty(Wt::PropertyValue,
			  boost::lexical_cast<std::string>(value_));
      element.setAttribute("min",
			   boost::lexical_cast<std::string>(minimum_));
      element.setAttribute("max",
			   boost::lexical_cast<std::string>(maximum_));

      if (!changedConnected_
	  && (valueChanged_.isConnected() || sliderMoved_.isConnected())) {
	changedConnected_ = true;
	changed().connect(this, &WSlider::onChange);
      }

      changed_ = false;
    }
  }

  WFormWidget::updateDom(element, all);
}
Example #13
0
	DomString DomElement::get_child_string_ns(const DomString &namespace_uri, const DomString &local_name, const DomString &default_value) const
	{
		DomElement element = named_item_ns(namespace_uri, local_name).to_element();
		if (!element.is_null() && element.get_first_child().is_text())
			return element.get_first_child().to_text().get_node_value();
		else
			return default_value;
	}
Example #14
0
int LuaDomText2::removeThis(lua_State *L)
{
	DomText* obj = DomTextValue::check2( L, 1 );
	DomElement* p = obj->getParent(); 
	if( p == 0 || !p->remove( obj ) )
		luaL_error( L, "Error removing this node" );
	return 0;
}
Example #15
0
std::string WWidget::inlineCssStyle()
{
    WWebWidget *ww = webWidget();
    DomElement *e = DomElement::getForUpdate(ww, ww->domElementType());
    ww->updateDom(*e, true);
    std::string result = e->cssStyle();
    delete e;
    return result;
}
Example #16
0
DomElement *WScrollArea::createDomElement()
{
  DomElement *result = DomElement::createNew(DomElement::DIV);
  result->setId(this, true);

  updateDom(*result, true);

  return result;
}
Example #17
0
DomElement *WImage::createDomElement()
{
  DomElement *result = DomElement::createNew(DomElement::IMG);
  result->setId(this);

  updateDom(*result, true);

  return result;
}
Example #18
0
void Project::load_item_children(ProjectItem *item, DomElement dom_items)
{
	DomElement cur = dom_items.get_first_child_element();
	while (!cur.is_null())
	{
		item->add(load_item(cur));
		cur = cur.get_next_sibling_element();
	}
}
Example #19
0
DomElement *StdGridLayoutImpl2::createElement(WLayoutItem *item,
					      WApplication *app)
{
  DomElement *c = getImpl(item)->createDomElement(true, true, app); 

  c->setProperty(PropertyStyleVisibility, "hidden");

  return c;
}
Example #20
0
void WFormWidget::updateDom(DomElement& element, bool all)
{
  const WEnvironment& env = WApplication::instance()->environment();

  bool onChangeHandledElsewhere = dynamic_cast<WAbstractToggleButton *>(this);

  if (!onChangeHandledElsewhere) {
    EventSignal<> *s = voidEventSignal(CHANGE_SIGNAL, false);
    if (s)
      updateSignalConnection(element, *s, "change", all);
  }

  if (flags_.test(BIT_ENABLED_CHANGED) || all) {
    if (!all || !isEnabled())
      element.setProperty(Wt::PropertyDisabled,
			  isEnabled() ? "false" : "true");

    if (!all && isEnabled() && env.agentIsIE()) {
      /*
       * FIXME: implement a workaround for IE, reenabling a checkbox makes
       * the input box loose interactivity.
       */
    }
    flags_.reset(BIT_ENABLED_CHANGED);
  }

  if (flags_.test(BIT_READONLY_CHANGED) || all) {
    if (!all || isReadOnly())
      element.setProperty(Wt::PropertyReadOnly,
			  isReadOnly() ? "true" : "false");
    flags_.reset(BIT_READONLY_CHANGED);
  }

  if (flags_.test(BIT_TABINDEX_CHANGED) || all) {
    if (!all || tabIndex_)
      element.setProperty(PropertyTabIndex,
			  boost::lexical_cast<std::string>(tabIndex_));
    flags_.reset(BIT_TABINDEX_CHANGED);
  }

  if (isEnabled()) {
    if (all && flags_.test(BIT_GOT_FOCUS))
      flags_.set(BIT_INITIAL_FOCUS);

    if (flags_.test(BIT_GOT_FOCUS)
	|| (all && flags_.test(BIT_INITIAL_FOCUS))) {
      element.callJavaScript("setTimeout(function() {"
			     """var f = " + jsRef() + ";"
			     """if (f) try { f.focus(); } catch (e) { } }, "
			     + (env.agentIsIElt(9) ? "500" : "10") + ");");

      flags_.reset(BIT_GOT_FOCUS);
    }
  }

  WInteractWidget::updateDom(element, all);
}
Example #21
0
DomElement *WComboBox::createDomElement()
{
  DomElement *result = DomElement::createNew(DomElement::SELECT);
  result->setId(this, true);

  updateDom(*result, true);

  return result;
}
Example #22
0
void WTextEdit::updateDom(DomElement& element, bool all)
{
  WTextArea::updateDom(element, all);

  if (element.type() == DomElement_TEXTAREA)
    element.removeProperty(PropertyStyleDisplay);

  // we are creating the actual element
  if (all && element.type() == DomElement_TEXTAREA) {
    std::stringstream config;
    config << "{";

    bool first = true;

    for (SettingsMapType::const_iterator it = configurationSettings_.begin();
	 it != configurationSettings_.end(); ++it) {
      if (it->first == "plugins")
	continue;

      if (!first)
	config << ',';

      first = false;

      config << it->first << ": "
	     << Impl::asJSLiteral(it->second, XHTMLUnsafeText);
    }

    if (!first)
      config << ',';

    config << "plugins: '" << plugins() << "'";

    config <<
      ",init_instance_callback: obj.init"
      "}";

    DomElement dummy(DomElement::ModeUpdate, DomElement_TABLE);
    updateDom(dummy, true);

    element.callJavaScript("(function() { "
			   """var obj = $('#" + id() + "').data('obj');"
			   """obj.render(" + config.str() + ","
			   + jsStringLiteral(dummy.cssStyle()) + ","
			   + (changed().isConnected() ? "true" : "false")
			   + ");"
			   "})();");

    contentChanged_ = false;
  }

  if (!all && contentChanged_) {
    element.callJavaScript(jsRef() + ".ed.load();");
    contentChanged_ = false;
  }
}
Example #23
0
int LuaDomElement2::getAttribute(lua_State *L)
{
	DomElement* obj = DomElementValue::check2( L, 1 );
	QByteArray str = obj->getAttribute( luaL_checkstring( L, 2 ) );
	if( str.isNull() )
		lua_pushnil( L ); 
	else
		lua_pushstring(L, str ); 
	return 1;
}
Example #24
0
DomElement *WPushButton::createDomElement()
{
  DomElement *result = DomElement::createNew(DomElement::BUTTON);
  result->setAttribute("type", "button"); // default button
  result->setId(this);

  updateDom(*result, true);

  return result;
}
Example #25
0
void WCssStyleSheet::javaScriptUpdate(WApplication *app,
				      std::ostream& js, bool all)
{
  if (!all) {
    for (unsigned i = 0; i < rulesRemoved_.size(); ++i) {
      js << WT_CLASS ".removeCssRule(";
      DomElement::jsStringLiteral(js, rulesRemoved_[i], '\'');
      js << ");";
    }
    rulesRemoved_.clear();

    for (RuleSet::const_iterator i = rulesModified_.begin();
	 i != rulesModified_.end(); ++i) {
      js << "{ var d= " WT_CLASS ".getCssRule(";
      DomElement::jsStringLiteral(js, (*i)->selector(), '\'');
      js << ");if(d){";

      DomElement *d = DomElement::updateGiven("d", DomElement_SPAN);
      if ((*i)->updateDomElement(*d, false)) {
	EscapeOStream sout(js);
	d->asJavaScript(sout, DomElement::Update);
      }

      delete d;

      js << "}}";
    }
    rulesModified_.clear();
  }

  if (!app->environment().agentIsIElt(9)
      && app->environment().agent() != WEnvironment::Konqueror) {
    RuleList& toProcess = all ? rules_ : rulesAdded_;

    for (unsigned i = 0; i < toProcess.size(); ++i) {
      WCssRule *rule = toProcess[i];
      js << WT_CLASS ".addCss('"
	 << rule->selector() << "',";
      DomElement::jsStringLiteral(js, rule->declarations(), '\'');
      js << ");" << std::endl;
    }

    rulesAdded_.clear();
    if (all)
      rulesModified_.clear();
  } else {
    std::string text = cssText(all);

    if (!text.empty()) {
      js << WT_CLASS ".addCssText(";
      DomElement::jsStringLiteral(js, text, '\'');
      js << ");" << std::endl;
    }
  }
}
Example #26
0
void WLineEdit::getDomChanges(std::vector<DomElement *>& result,
			      WApplication *app)
{
  if (app->environment().agentIsIE() && flags_.test(BIT_ECHO_MODE_CHANGED)) {
    DomElement *e = DomElement::getForUpdate(this, domElementType());
    DomElement *d = createDomElement(app);
    e->replaceWith(d);
    result.push_back(e);
  } else
    WFormWidget::getDomChanges(result, app);
}
Example #27
0
void WFileUpload::getDomChanges(std::vector<DomElement *>& result,
				WApplication *app)
{
  if (flags_.test(BIT_ENABLE_AJAX)) {
    DomElement *plainE = DomElement::getForUpdate(this, DomElement_INPUT);
    DomElement *ajaxE = createDomElement(app);
    plainE->replaceWith(ajaxE);
    result.push_back(plainE);
  } else
    WWebWidget::getDomChanges(result, app);
}
Example #28
0
int LuaDomElement2::createElement(lua_State *L)
{
	DomElement* obj = DomElementValue::check2( L, 1 );
	// Param: Name
	// Erzeugt ein neues Element und fügt es ans Ende der Liste
	Root::Ref<DomElement> e = new DomElement();
	e->setName( luaL_checkstring( L, 2 ) );
	DomElementValue::create( L, e );
	obj->append( e );
	return 1;
}
Example #29
0
File: Widget.C Project: ReWeb3D/wt
DomElement *Widget::createDomElement(WApplication *app)
{
  DomElement *result = DomElement::createNew(domElementType());
  setId(result, app);

  std::stringstream js;
  createExtElement(js, result);
  result->callJavaScript(js.str());

  return result;
}
Example #30
0
void Project::save_item_children(DomElement dom_parent, ProjectItem *item)
{
	if (!item->children().empty())
	{
		DomElement dom_items = dom_parent.get_owner_document().create_element("items");
		for (size_t i = 0; i < item->children().size(); i++)
		{
			save_item(dom_items, item->children()[i]);
		}
		dom_parent.append_child(dom_items);
	}
}