Пример #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);
  }
}
Пример #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);
}
Пример #3
0
void WGLWidget::repaintGL(WFlags<GLClientSideRenderer> which)
{
  if (!pImpl_)
    return;

  pImpl_->repaintGL(which);

  if (!which.empty())
    repaint();
}
Пример #4
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]);
}
Пример #5
0
void WContainerWidget::setPadding(const WLength& length, WFlags<Side> sides)
{
  if (!padding_) {
    padding_ = new WLength[4];
#ifdef WT_TARGET_JAVA
    padding_[0] = padding_[1] = padding_[2] = padding_[3] = WLength::Auto;
#endif // WT_TARGET_JAVA
  }

  if (sides.testFlag(Top))
    padding_[0] = length;
  if (sides.testFlag(Right))
    padding_[1] = length;
  if (sides.testFlag(Bottom))
    padding_[2] = length;
  if (sides.testFlag(Left))
    padding_[3] = length;

  flags_.set(BIT_PADDINGS_CHANGED);
  repaint(RepaintPropertyAttribute);
}
Пример #6
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);
}
Пример #7
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);
}
Пример #8
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);
}
Пример #9
0
void WMeasurePaintDevice::setChanged(WFlags<PainterChangeFlag> flags)
{
  if (device_->painter() != painter_ && (flags.test(PainterChangeFlag::Font)))
    device_->painter()->setFont(painter_->font());
  device_->setChanged(flags);
}
Пример #10
0
void WPdfImage::setChanged(WFlags<PainterChangeFlag> flags)
{
  if (!flags.empty()) {
    HPDF_Page_GRestore(page_);
    HPDF_Page_GSave(page_);

    HPDF_ExtGState gstate;
    gstate = HPDF_CreateExtGState (pdf_);

    currentFont_ = WFont();

    if (painter()->hasClipping()) {
      const WTransform& t = painter()->clipPathTransform();

      if (!painter()->clipPath().isEmpty()) {
        applyTransform(t);

        drawPlainPath(painter()->clipPath());
        HPDF_Page_Clip(page_);
        HPDF_Page_EndPath(page_);

        applyTransform(t.inverted());
      }
    }

    applyTransform(painter()->combinedTransform());

    const WPen& pen = painter()->pen();

    if (pen.style() != PenStyle::None) {
      const WColor& color = pen.color();

      HPDF_Page_SetRGBStroke(page_,
                             color.red() / 255.,
                             color.green() / 255.,
                             color.blue() / 255.);

      HPDF_ExtGState_SetAlphaStroke (gstate, color.alpha()/255.);

      WLength w = painter()->normalizedPenWidth(pen.width(), false);
      HPDF_Page_SetLineWidth(page_, w.toPixels());

      switch (pen.capStyle()) {
      case PenCapStyle::Flat:
	HPDF_Page_SetLineCap(page_, HPDF_BUTT_END);
	break;
      case PenCapStyle::Square:
	HPDF_Page_SetLineCap(page_, HPDF_PROJECTING_SCUARE_END); // scuary !
	break;
      case PenCapStyle::Round:
	HPDF_Page_SetLineCap(page_, HPDF_ROUND_END);
	break;
      }

      switch (pen.joinStyle()) {
      case PenJoinStyle::Miter:
	HPDF_Page_SetLineJoin(page_, HPDF_MITER_JOIN);
	break;
      case PenJoinStyle::Bevel:
	HPDF_Page_SetLineJoin(page_, HPDF_BEVEL_JOIN);
	break;
      case PenJoinStyle::Round:
	HPDF_Page_SetLineJoin(page_, HPDF_ROUND_JOIN);
	break;
      }

      switch (pen.style()) {
      case PenStyle::None:
	break;
      case PenStyle::SolidLine:
	HPDF_Page_SetDash(page_, nullptr, 0, 0);
	break;
      case PenStyle::DashLine: {
	const HPDF_UINT16 dash_ptn[] = { 4, 2 };
	HPDF_Page_SetDash(page_, dash_ptn, 2, 0);
	break;
      }
      case PenStyle::DotLine: {
	const HPDF_UINT16 dash_ptn[] = { 1, 2 };
	HPDF_Page_SetDash(page_, dash_ptn, 2, 0);
	break;
      }
      case PenStyle::DashDotLine: {
	const HPDF_UINT16 dash_ptn[] = { 4, 2, 1, 2 };
	HPDF_Page_SetDash(page_, dash_ptn, 4, 0);
	break;
      }
      case PenStyle::DashDotDotLine: {
	const HPDF_UINT16 dash_ptn[] = { 4, 2, 1, 2, 1, 2 };
	HPDF_Page_SetDash(page_, dash_ptn, 6, 0);
	break;
      }
      }
    }

    const WBrush& brush = painter()->brush();

    if (brush.style() != BrushStyle::None) {
      const WColor& color = painter()->brush().color();

      HPDF_Page_SetRGBFill(page_,
                           color.red() / 255.,
                           color.green() / 255.,
                           color.blue() / 255.);

      HPDF_ExtGState_SetAlphaFill (gstate, color.alpha()/255.);
    }

    HPDF_Page_SetExtGState (page_, gstate);

    

    const WFont& font = painter()->font();

    if (font == currentFont_ && !trueTypeFonts_->busy())
      return;

    /*
     * First, try a true type font.
     */
    std::string ttfFont;
    if (trueTypeFonts_->busy()) {
      /*
       * We have a resolved true type font.
       */
      ttfFont = trueTypeFonts_->drawingFontPath();
    } else {
      FontSupport::FontMatch match = trueTypeFonts_->matchFont(font);

      if (match.matched())
	ttfFont = match.fileName();
    }

    LOG_DEBUG("font: " << ttfFont);

    if (font == currentFont_ &&
        !ttfFont.empty() &&
        currentTtfFont_ == ttfFont)
      return;

    currentFont_ = font;

    const char *font_name = nullptr;
    font_ = nullptr;

    if (!ttfFont.empty()) {

      bool fontOk = false;

      std::map<std::string, const char *>::const_iterator i
	= ttfFonts_.find(ttfFont);

      if (i != ttfFonts_.end()) {
	font_name = i->second;
	fontOk = true;
      } else if (ttfFont.length() > 4) {
	std::string suffix
	  = Utils::lowerCase(ttfFont.substr(ttfFont.length() - 4));

	if (suffix == ".ttf") {
	  font_name = HPDF_LoadTTFontFromFile (pdf_, ttfFont.c_str(),
					       HPDF_TRUE);
	} else if (suffix == ".ttc") {
	  /* Oops, pango didn't tell us which font to load ... */
	  font_name = HPDF_LoadTTFontFromFile2(pdf_, ttfFont.c_str(),
					       0, HPDF_TRUE);
	}

	if (!font_name)
	  HPDF_ResetError (pdf_);
	else {
	  ttfFonts_[ttfFont] = font_name;
	  fontOk = true;
	}
      }

      if (!fontOk)
	LOG_ERROR("cannot read font: '" << ttfFont << "': "
		  "expecting a true type font (.ttf, .ttc)");
    }

    if (!font_ && font_name) {
      font_ = HPDF_GetFont (pdf_, font_name, "UTF-8");

      if (!font_)
	HPDF_ResetError (pdf_);
      else {
	trueTypeFont_ = true;
        currentTtfFont_ = ttfFont;
      }
    }

    if (!font_) {
      trueTypeFont_ = false;
      currentTtfFont_.clear();

      std::string name = Pdf::toBase14Font(font);
      font_ = HPDF_GetFont(pdf_, name.c_str(), nullptr);
    }

    fontSize_ = font.sizeLength(12).toPixels();

    HPDF_Page_SetFontAndSize (page_, font_, fontSize_);
  }
}