Esempio n. 1
0
void WBootstrapTheme
::applyValidationStyle(WWidget *widget,
		       const Wt::WValidator::Result& validation,
		       WFlags<ValidationStyleFlag> styles) const
{
  WApplication *app = WApplication::instance();

  LOAD_JAVASCRIPT(app, "js/BootstrapValidate.js", "validate", wtjs1);
  LOAD_JAVASCRIPT(app, "js/BootstrapValidate.js", "setValidationState", wtjs2);

  if (app->environment().ajax()) {
    WStringStream js;
    js << WT_CLASS ".setValidationState(" << widget->jsRef() << ","
       << (validation.state() == ValidationState::Valid ? 1 : 0) << ","
       << validation.message().jsStringLiteral() << ","
       << styles.value() << ");";

    widget->doJavaScript(js.str());
  } else {
    bool validStyle
      = (validation.state() == ValidationState::Valid) &&
      styles.test(ValidationStyleFlag::ValidStyle);
    bool invalidStyle
      = (validation.state() != ValidationState::Valid) &&
      styles.test(ValidationStyleFlag::InvalidStyle);

    widget->toggleStyleClass("Wt-valid", validStyle);
    widget->toggleStyleClass("Wt-invalid", invalidStyle);
  }
}
Esempio n. 2
0
void WSlider::render(WFlags<RenderFlag> flags)
{
  /*
   * In theory we are a bit late here to decide what we want to become:
   * somebody could already have asked the domElementType()
   */
  if (flags.test(RenderFlag::Full)) {
    bool useNative = nativeControl();

    if (!useNative) {
      if (!paintedSlider_) {
	manageWidget
	  (paintedSlider_,
	   std::unique_ptr<PaintedSlider>(new PaintedSlider(this)));
	paintedSlider_->sliderResized(width(), height());
      }
    } else {
      manageWidget(paintedSlider_, std::unique_ptr<PaintedSlider>());
    }

    setLayoutSizeAware(!useNative);
    setFormObject(useNative);
  }

  WFormWidget::render(flags);
}
Esempio n. 3
0
void WMessageBox::setStandardButtons(WFlags<StandardButton> buttons)
{
  buttons_.clear();
  footer()->clear();

  defaultButton_ = escapeButton_ = nullptr;

  for (int i = 0; i < 9; ++i)
    if (buttons.test(order_[i]))
      addButton(order_[i]);
}
Esempio n. 4
0
void WTreeTable::render(WFlags<RenderFlag> flags)
{
  if (flags.test(RenderFlag::Full)) {
    defineJavaScript();

    setJavaScriptMember(WT_RESIZE_JS,
                        jsRef() + ".wtObj.wtResize");

    resize(width(), height());

    WApplication::instance()->addAutoJavaScript
      ("{var obj = " + jsRef() + ";"
       "if (obj && obj.wtObj) obj.wtObj.autoJavaScript();}");
  }

  WCompositeWidget::render(flags);
}
Esempio n. 5
0
void WGLWidget::render(WFlags<RenderFlag> flags)
{
  if (flags.test(RenderFlag::Full)) {
    if (!pImpl_) {
      if (renderOptions_.test(GLRenderOption::ClientSide) &&
	  WApplication::instance()->environment().webGL()) {
	pImpl_.reset(new WClientGLWidget(this));
      } else {
#ifndef WT_TARGET_JAVA
#ifdef WT_USE_OPENGL
	if (renderOptions_.test(GLRenderOption::ServerSide)) {
	  try {
	    pImpl_.reset(new WServerGLWidget(this));
	  } catch (WException& e) {
	    LOG_WARN("Failed to initialize server rendering fallback: " << e.what());
	  }
	} else {
	  pImpl_.reset();
	}
#else
	pImpl_.reset();
#endif
#else
	if (renderOptions_ & GLRenderOption::ServerSide) {
	  pImpl_.reset(new WServerGLWidget(this));
	} else {
	  pImpl_.reset();
	}
#endif
      }
    }

    if (pImpl_ && !width().isAuto() && !height().isAuto()) {
      layoutSizeChanged(static_cast<int>(width().toPixels()),
			static_cast<int>(height().toPixels()));
    }

    defineJavaScript();
  }

  if (pImpl_)
    pImpl_->render(jsRef(), flags);

  WInteractWidget::render(flags);
}
Esempio n. 6
0
void WAbstractSpinBox::render(WFlags<RenderFlag> flags)
{
  /*
   * In theory we are a bit late here to decide what we want to become:
   * somebody could already have asked the domElementType()
   */
  if (!setup_ && flags.test(RenderFlag::Full)) {
    setup();
  }

  if (jsValueChanged().needsUpdate(true)) {
    WStringStream function;
    function << "jQuery.data(" + jsRef() + ",'obj').jsValueChanged=";
    if (jsValueChanged().isConnected()) {
      function << "function(oldv, v){"
               << "var o=null;var e=null;" << jsValueChanged().createCall({"oldv", "v"}) << "};";
    } else {
      function << "function() {};";
    }
    doJavaScript(function.str());
  }

  WLineEdit::render(flags);
}
Esempio n. 7
0
void WMeasurePaintDevice::setChanged(WFlags<PainterChangeFlag> flags)
{
  if (device_->painter() != painter_ && (flags.test(PainterChangeFlag::Font)))
    device_->painter()->setFont(painter_->font());
  device_->setChanged(flags);
}