Exemple #1
0
bool WAbstractSpinBox::parseValue(const WT_USTRING& text)
{
  std::string textUtf8 = text.toUTF8();

  bool valid = true;

  if (!nativeControl()) {
    valid = false;

    std::string prefixUtf8 = prefix_.toUTF8();
    std::string suffixUtf8 = suffix_.toUTF8();

    if (boost::starts_with(textUtf8, prefixUtf8)) {
      textUtf8 = textUtf8.substr(prefixUtf8.length());
      if (boost::ends_with(textUtf8, suffixUtf8)) {
	textUtf8 = textUtf8.substr(0, textUtf8.length() - suffixUtf8.length());
	valid = true;
      }
    }
  }

  if (valid)
    valid = textUtf8.length() > 0;

  if (valid)
    valid = parseNumberValue(textUtf8);

  return valid;
}
Exemple #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);
}
Exemple #3
0
int WAbstractSpinBox::boxPadding(Orientation orientation) const
{
  if (!nativeControl() && orientation == Horizontal)
    return WLineEdit::boxPadding(orientation) + 8; // Half since for one side
  else
    return WLineEdit::boxPadding(orientation);
}
Exemple #4
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 & RenderFull) {
    bool useNative = nativeControl();

    if (!useNative) {
      if (!paintedSlider_) {
	addChild(paintedSlider_ = new PaintedSlider(this));
	paintedSlider_->sliderResized(width(), height());
      }
    } else {
      delete paintedSlider_;
      paintedSlider_ = 0;
    }

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

  WFormWidget::render(flags);
}
Exemple #5
0
WString WDoubleSpinBox::textFromValue() const
{
  std::string result = WLocale::currentLocale().toFixedString(value_, precision_).toUTF8();

  if (!nativeControl())
    result = prefix().toUTF8() + result + suffix().toUTF8();

  return WString::fromUTF8(result);
}
Exemple #6
0
void WAbstractSpinBox::updateDom(DomElement& element, bool all)
{
  if (all || changed_) {
    if (!all) {
      if (!nativeControl())
	doJavaScript("jQuery.data(" + jsRef() + ", 'obj')"
		     ".update(" + jsMinMaxStep() + ","
		     + boost::lexical_cast<std::string>(decimals()) + ");");
      else
	setValidator(createValidator());
    }
  }

  changed_ = false;

  WLineEdit::updateDom(element, all);

  if (all && nativeControl())
    element.setAttribute("type", "number");
}
Exemple #7
0
WString WSpinBox::textFromValue() const
{
  if (nativeControl())    
    return WLocale::currentLocale().toString(value_);
  else {
    std::string text = prefix().toUTF8()
      + WLocale::currentLocale().toString(value_).toUTF8()
      + suffix().toUTF8();

    return WString::fromUTF8(text);
  }
}
Exemple #8
0
WString WSpinBox::textFromValue() const
{
  if (nativeControl())    
    return WString::fromUTF8(boost::lexical_cast<std::string>(value_));
  else {
    std::string text = prefix().toUTF8()
      +  boost::lexical_cast<std::string>(value_)
      + suffix().toUTF8();

    return WString::fromUTF8(text);
  }
}
Exemple #9
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 & RenderFull) {
    setup_ = true;
    bool useNative = nativeControl();
    setup(useNative);
  }

  WLineEdit::render(flags);
}
void WAbstractSpinBox::updateDom(DomElement& element, bool all)
{
  if (all || changed_) {
    if (!all) {
      if (!nativeControl())
	doJavaScript("jQuery.data(" + jsRef() + ", 'obj')"
		     ".configure("
		     + std::to_string(decimals()) + ","
		     + prefix().jsStringLiteral() + ","
		     + suffix().jsStringLiteral() + ","
		     + jsMinMaxStep() + ");");
      else
	setValidator(std::shared_ptr<WValidator>(createValidator().release()));
    }
  }

  changed_ = false;

  WLineEdit::updateDom(element, all);

  if (all && nativeControl())
    element.setAttribute("type", "number");
}
Exemple #11
0
void WSpinBox::updateDom(DomElement& element, bool all)
{
  if (all || changed_) {
    if (nativeControl()) {
      element.setAttribute("min", boost::lexical_cast<std::string>(min_));
      element.setAttribute("max", boost::lexical_cast<std::string>(max_));
      element.setAttribute("step", boost::lexical_cast<std::string>(step_));
    } else {
      /* Make sure the JavaScript validator is loaded */
      WIntValidator v;
      v.javaScriptValidate();
    }
  }

  WAbstractSpinBox::updateDom(element, all);
}
Exemple #12
0
void WSpinBox::updateDom(DomElement& element, bool all)
{
    if (all || changed_) {
        if (nativeControl()) {
            element.setAttribute("min", boost::lexical_cast<std::string>(min_));
            element.setAttribute("max", boost::lexical_cast<std::string>(max_));
            element.setAttribute("step", boost::lexical_cast<std::string>(step_));
        } else {
            /* Make sure the JavaScript validator is loaded */
            WIntValidator v;
            v.javaScriptValidate();

            doJavaScript("jQuery.data(" + jsRef() + ", 'obj')"
                         + ".setWrapAroundEnabled("
                         + (wrapAroundEnabled() ? "true" : "false") + ");");
        }
    }

    WAbstractSpinBox::updateDom(element, all);
}
WString WDoubleSpinBox::textFromValue() const
{
  // FIXME, need to use WLocale here somehow !!

#ifndef WT_TARGET_JAVA
  // can't use round_str, because (1) precision is only a hint, and
  // (2) precision is limited to values < 7
  std::stringstream ss;
  ss.precision(precision_);
  ss << std::fixed << std::showpoint << value_;

  std::string result = ss.str();
#else
  char buf[30];

  std::string result = Utils::round_js_str(value_, precision_, buf);
#endif // WT_TARGET_JAVA

  if (!nativeControl())
    result = prefix().toUTF8() + result + suffix().toUTF8();

  return WString::fromUTF8(result);
}
Exemple #14
0
void WAbstractSpinBox::setup()
{
  setup_ = true;
  bool useNative = nativeControl();

  if (!useNative) {
    defineJavaScript();

#ifdef WT_CNOR
    EventSignalBase& b = mouseMoved();
    EventSignalBase& c = keyWentDown();
#endif

    connectJavaScript(mouseMoved(), "mouseMove");
    connectJavaScript(mouseWentUp(), "mouseUp");
    connectJavaScript(mouseWentDown(), "mouseDown");
    connectJavaScript(mouseWentOut(), "mouseOut");
    connectJavaScript(keyWentDown(), "keyDown");
    connectJavaScript(keyWentUp(), "keyUp");

    if (!prefix_.empty() || !suffix_.empty())
      setValidator(new SpinBoxValidator(this));
  }
}