コード例 #1
0
ファイル: WIntValidator.C プロジェクト: 913862627/wt
std::string WIntValidator::javaScriptValidate() const
{
  loadJavaScript(WApplication::instance());

  WStringStream js;

  js << "new " WT_CLASS ".WIntValidator("
     << isMandatory()
     << ',';

  if (bottom_ != std::numeric_limits<int>::min())
    js << bottom_;
  else
    js << "null";

  js << ',';

  if (top_ != std::numeric_limits<int>::max())
    js << top_;
  else
    js << "null";

  js << "," << WWebWidget::jsStringLiteral(WLocale::currentLocale()
					   .groupSeparator())
     << ',' << invalidBlankText().jsStringLiteral()
     << ',' << invalidNotANumberText().jsStringLiteral()
     << ',' << invalidTooSmallText().jsStringLiteral()
     << ',' << invalidTooLargeText().jsStringLiteral()
     << ");";

  return js.str();
}
コード例 #2
0
ファイル: WCssTheme.C プロジェクト: NeilNienaber/wt
void WCssTheme::applyValidationStyle(WWidget *widget,
				     const Wt::WValidator::Result& validation,
				     WFlags<ValidationStyleFlag> styles) const
{
  WApplication *app = WApplication::instance();

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

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

    widget->doJavaScript(js.str());
  } else {
    bool validStyle
      = (validation.state() == WValidator::Valid) && 
      (styles & ValidationValidStyle);
    bool invalidStyle
      = (validation.state() != WValidator::Valid) && 
      (styles & ValidationInvalidStyle);

    widget->toggleStyleClass("Wt-valid", validStyle);
    widget->toggleStyleClass("Wt-invalid", invalidStyle);
  }
}
コード例 #3
0
ファイル: Utils.C プロジェクト: 913862627/wt
std::string urlDecode(const std::string &text)
{
  WStringStream result;

  for (unsigned i = 0; i < text.length(); ++i) {
    char c = text[i];

    if (c == '+') {
      result << ' ';
    } else if (c == '%' && i + 2 < text.length()) {
      std::string h = text.substr(i + 1, 2);
      char *e = 0;
      int hval = std::strtol(h.c_str(), &e, 16);

      if (*e == 0) {
	result << (char)hval;
	i += 2;
      } else
	// not a proper %XX with XX hexadecimal format
	result << c;
    } else
      result << c;
  }

  return result.str();
}
コード例 #4
0
ファイル: XSSFilter.C プロジェクト: 913862627/wt
bool XSSFilterRemoveScript(WString& text)
{
  if (text.empty())
    return true;

  std::string result = "<span>" + text.toUTF8() + "</span>";
  char *ctext = const_cast<char *>(result.c_str()); // Shhht it's okay !

  try {
    xml_document<> doc;
    doc.parse<parse_comment_nodes
      | parse_validate_closing_tags
      | parse_validate_utf8
      | parse_xhtml_entity_translation>(ctext);

    XSSSanitize(doc.first_node());

    WStringStream out;
    print(out.back_inserter(), *doc.first_node(), print_no_indenting);
    result = out.str();
  } catch (parse_error& e) {
    LOG_ERROR("Error reading XHTML string: " << e.what());
    return false;
  }

  if (result.length() < 13)
    result.clear();
  else
    result = result.substr(6, result.length() - 13);

  text = WString::fromUTF8(result);

  return true;
}
コード例 #5
0
ファイル: WPopupMenu.C プロジェクト: ReWeb3D/wt
void WPopupMenu::prepareRender(WApplication *app)
{
  if (app->environment().agentIsIE()) {
    doJavaScript(jsRef() + ".lastChild.style.width="
		 + jsRef() + ".lastChild.offsetWidth + 'px';");
  }

  // FIXME: we should really also prepareRender() of submenus when shown...

  if (!cancel_.isConnected()) {
    LOAD_JAVASCRIPT(app, "js/WPopupMenu.js", "WPopupMenu", wtjs1);

    std::vector<WPopupMenu *> subMenus;
    getSubMenus(subMenus);

    WStringStream s;

    s << "new " WT_CLASS ".WPopupMenu("
      << app->javaScriptClass() << ',' << jsRef() << ','
      << autoHideDelay_ << ",[";

    for (unsigned i = 0; i < subMenus.size(); ++i) {
      if (i != 0)
	s << ',';
      s << WWebWidget::jsStringLiteral(subMenus[i]->id());
    }

    s << "]);";

    setJavaScriptMember(" WPopupMenu", s.str());

    cancel_.connect(this, &WPopupMenu::done);
  }
}
コード例 #6
0
ファイル: WLengthValidator.C プロジェクト: 913862627/wt
std::string WLengthValidator::javaScriptValidate() const
{
  loadJavaScript(WApplication::instance());

  WStringStream js;

  js << "new " WT_CLASS ".WLengthValidator("
     << isMandatory()
     << ',';

  if (minLength_ != 0)
    js << minLength_;
  else
    js << "null";

  js << ',';

  if (maxLength_ != std::numeric_limits<int>::max())
    js << maxLength_;
  else
    js << "null";

  js << ',' << invalidBlankText().jsStringLiteral()
     << ',' << invalidTooShortText().jsStringLiteral()
     << ',' << invalidTooLongText().jsStringLiteral()
     << ");";

  return js.str();
}
コード例 #7
0
ファイル: WRegExpValidator.C プロジェクト: DTidd/wt
std::string WRegExpValidator::javaScriptValidate() const
{
  loadJavaScript(WApplication::instance());

  WStringStream js;

  js << "new " WT_CLASS ".WRegExpValidator("
     << isMandatory()
     << ',';

  if (regexp_) {
    js << WWebWidget::jsStringLiteral(regexp_->pattern())
       << ",'";

#ifndef WT_TARGET_JAVA
    WFlags<RegExpFlag> flags = regexp_->flags();
#else
    int flags = regexp_->flags();
#endif

    if (flags & MatchCaseInsensitive)
      js << 'i';

    js << '\'';
  } else
    js << "null, null";

  js << ',' << WWebWidget::jsStringLiteral(invalidBlankText())
     << ',' << WWebWidget::jsStringLiteral(invalidNoMatchText())
     << ");";

  return js.str();
}
コード例 #8
0
ファイル: WColor.C プロジェクト: Dinesh-Ramakrishnan/wt
const std::string WColor::cssText(bool withAlpha) const
{
  if (default_)
    return std::string();
  else {
    if (!name_.empty())
      return name_.toUTF8();
    else {
      WStringStream s;

#ifndef WT_TARGET_JAVA
      char buf[30];
#else
      char *buf;
#endif

      if (alpha_ != 255 && withAlpha) {
	s << "rgba(" << red_
	  << ',' << green_
	  << ',' << blue_
	  << ',' << Utils::round_css_str(alpha_ / 255., 2, buf) << ')';
      }	else
	s << "rgb(" << red_ << ',' << green_ << ',' << blue_ << ')';

      return s.c_str();
    }
  }
}
コード例 #9
0
ファイル: RefEncoder.C プロジェクト: NovaWova/wt
void EncodeRefs(WString& text, WFlags<RefEncoderOption> options)
{
  if (text.empty())
    return;

  std::string result = "<span>" + text.toUTF8() + "</span>";
  char *ctext = const_cast<char *>(result.c_str()); // Shhht it's okay !

  WApplication *app = WApplication::instance();

  try {
    xml_document<> doc;
    doc.parse<parse_comment_nodes
      | parse_validate_closing_tags
      | parse_validate_utf8
      | parse_xhtml_entity_translation>(ctext);

    EncodeRefs(doc.first_node(), app, options);

    WStringStream out;
    print(out.back_inserter(), *doc.first_node(), print_no_indenting);

    result = out.str();
  } catch (parse_error& e) {
    LOG_ERROR("Error reading XHTML string: " << e.what());
    return;
  }

  if (result.length() < 13)
    result.clear();
  else
    result = result.substr(6, result.length() - 13);

  text = WString::fromUTF8(result);
}
コード例 #10
0
ファイル: RefEncoder.C プロジェクト: NovaWova/wt
static std::string replaceUrlInStyle(std::string& style, WApplication *app)
{
  boost::regex re("url\\((.*//.*)\\)",
		  boost::regex::perl | boost::regex::icase);

  boost::sregex_iterator i(style.begin(), style.end(), re);
  boost::sregex_iterator end;

  WStringStream result;
  std::size_t pos = 0;

  for (; i != end; ++i) {
    result << style.substr(pos, i->position(1) - pos);

    std::string url = style.substr(i->position(1), i->length(1));
    boost::algorithm::trim(url);
    if (url.length() > 2)
      if (url[0] == '\'' || url[1] == '"')
	url = url.substr(1, url.length() - 2);
    
    result << WWebWidget::jsStringLiteral(app->encodeUntrustedUrl(url), '\'');

    pos = i->position(1) + i->length(1);
  }

  result << style.substr(pos);

  return result.str();
}
コード例 #11
0
ファイル: WPointF.C プロジェクト: hhirsch/wtim
std::string WPointF::jsValue() const
{
  char buf[30];
  WStringStream ss;
  ss << '[';
  ss << Utils::round_js_str(x_, 3, buf) << ',';
  ss << Utils::round_js_str(y_, 3, buf) << ']';
  return ss.str();
}
コード例 #12
0
ファイル: WPaintedWidget.C プロジェクト: pgquiles/wt
void WWidgetCanvasPainter::createContents(DomElement *result,
					  WPaintDevice *device)
{
  std::string wstr = boost::lexical_cast<std::string>(widget_->renderWidth_);
  std::string hstr = boost::lexical_cast<std::string>(widget_->renderHeight_);

  result->setProperty(PropertyStylePosition, "relative");
  result->setProperty(PropertyStyleOverflowX, "hidden");
  result->setProperty(PropertyStyleOverflowY, "hidden");

  DomElement *canvas = DomElement::createNew(DomElement_CANVAS);
  canvas->setId('c' + widget_->id());
  canvas->setProperty(PropertyStyleDisplay, "block");
  canvas->setAttribute("width", wstr);
  canvas->setAttribute("height", hstr);
  result->addChild(canvas);
  widget_->sizeChanged_ = false;

  WCanvasPaintDevice *canvasDevice = dynamic_cast<WCanvasPaintDevice *>(device);

  DomElement *text = 0;
  if (canvasDevice->textMethod() == WCanvasPaintDevice::DomText) {
    text = DomElement::createNew(DomElement_DIV);
    text->setId('t' + widget_->id());
    text->setProperty(PropertyStylePosition, "absolute");
    text->setProperty(PropertyStyleZIndex, "1");
    text->setProperty(PropertyStyleTop, "0px");
    text->setProperty(PropertyStyleLeft, "0px");
  }

  DomElement *el = text ? text : result;
  bool hasJsObjects = widget_->jsObjects_.size() > 0;

  if (hasJsObjects) {
    WStringStream ss;
    WApplication *app = WApplication::instance();
    ss << "new " WT_CLASS ".WPaintedWidget("
      << app->javaScriptClass() << "," << widget_->jsRef() << ");";
    widget_->jsObjects_.updateJs(ss);
    el->callJavaScript(ss.str());
  }

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

  if (hasJsObjects) {
    WStringStream ss;
    ss << widget_->objJsRef() << ".repaint=function(){";
    ss << canvasDevice->recordedJs_.str();
    ss << "};";
    el->callJavaScript(ss.str());
  }

  if (text)
    result->addChild(text);

  delete device;
}
コード例 #13
0
ファイル: WImage.C プロジェクト: LifeGo/wt
std::string WImage::setAreaCoordsJS()
{
  WStringStream ss;
  if (!targetJS_.empty()) {
    ss << "jQuery.data(" << jsRef() << ", 'obj').setAreaCoordsJSON("
       << updateAreaCoordsJSON() << ");";
  }
  return ss.str();
}
コード例 #14
0
ファイル: BsString.cpp プロジェクト: MarcoROG/BansheeEngine
	WString toWString(wchar_t val, unsigned short width, char fill, std::ios::fmtflags flags)
	{
		WStringStream stream;
		stream.width(width);
		stream.fill(fill);
		if (flags)
			stream.setf(flags);
		stream << val;
		return stream.str();
	}
コード例 #15
0
ファイル: WBrush.C プロジェクト: AlexanderKotliar/wt
std::string WBrush::jsValue() const
{
  WStringStream ss;
  ss << "{\"color\":["
    << color_.red() << ","
    << color_.green() << ","
    << color_.blue() << ","
    << color_.alpha() << "]}";
  return ss.str();
}
コード例 #16
0
ファイル: AuthModel.C プロジェクト: kdeforche/wt
void AuthModel::updateThrottling(WInteractWidget *button)
{
  if (passwordAuth() && passwordAuth()->attemptThrottlingEnabled()) {
    WStringStream s;
    s << button->jsRef() << ".wtThrottle.reset("
      << throttlingDelay_ << ");";

    button->doJavaScript(s.str());
  }
}
コード例 #17
0
ファイル: Money.C プロジェクト: 913862627/wt
const std::string Money::toString() const
{
  WStringStream ans;
  if(cents() > 9)
    ans << value() << "." << cents(); //todo use formater.
  else
    ans << value() << ".0" << cents(); //todo use formater.

  return ans.str();
}
コード例 #18
0
ファイル: WPopupWidget.C プロジェクト: hhirsch/wtim
void WPopupWidget::setTransient(bool isTransient, int autoHideDelay)
{
    transient_ = isTransient;
    autoHideDelay_ = autoHideDelay;
    if (isRendered()) {
        WStringStream ss;
        ss << "jQuery.data(" << jsRef() << ", 'popup').setTransient("
           << transient_ << ',' << autoHideDelay_ << ");";
        doJavaScript(ss.str());
    }
}
コード例 #19
0
ファイル: WImage.C プロジェクト: LifeGo/wt
void WImage::defineJavaScript()
{
  WApplication *app = WApplication::instance();

  LOAD_JAVASCRIPT(app, "js/WImage.js", "WImage", wtjs1);

  WStringStream ss;
  ss << "new " WT_CLASS ".WImage("
     << app->javaScriptClass() << "," << jsRef() << "," << targetJS_ << ");";
  doJavaScript(ss.str());
}
コード例 #20
0
ファイル: WFont.C プロジェクト: 913862627/wt
const std::string WFont::cssText(bool combined) const
{
  WStringStream result;

  if (combined) {
    std::string s;
    s = cssStyle(false);
    if (!s.empty())
      result << s << ' ';

    s = cssVariant(false);
    if (!s.empty())
      result << s << ' ';

    s = cssWeight(false);
    if (!s.empty())
      result << s << ' ';

    result << cssSize(true) << ' ';

    s = cssFamily(true);
    if (!s.empty())
      result << s << ' ';
    else
      result << s << " inherit";
  } else {
    std::string s;
    s = cssSize(false);
    if (!s.empty())
      result << "font-size: " << s << ";";

    s = cssStyle(false);
    if (!s.empty())
      result << "font-style: " << s << ";";

    s = cssVariant(false);
    if (!s.empty())
      result << "font-variant: " << s << ";";

    s = cssWeight(false);
    if (!s.empty())
      result << "font-weight: " << s << ";";

    // Last because of workaround in WVmlImage that searches for a ','
    s = cssFamily(false);
    if (!s.empty())
      result << "font-family: " << s << ";";

  }

  return result.str();
}
コード例 #21
0
ファイル: WMediaPlayer.C プロジェクト: 913862627/wt
void WMediaPlayer::playerDo(const std::string& method, const std::string& args)
{
  WStringStream ss;

  ss << ".jPlayer('" << method << '\'';

  if (!args.empty()) {
    ss << ',' << args;
  }

  ss << ')';

  playerDoRaw(ss.str());
}
コード例 #22
0
ファイル: WTransform.C プロジェクト: LifeGo/wt
std::string WTransform::jsValue() const
{
  char buf[30];

  WStringStream ss;
  ss << '[';
  ss << Utils::round_js_str(m_[0], 3, buf) << ',';
  ss << Utils::round_js_str(m_[2], 3, buf) << ',';
  ss << Utils::round_js_str(m_[1], 3, buf) << ',';
  ss << Utils::round_js_str(m_[3], 3, buf) << ',';
  ss << Utils::round_js_str(m_[4], 3, buf) << ',';
  ss << Utils::round_js_str(m_[5], 3, buf) << ']';
  return ss.str();
}
コード例 #23
0
ファイル: BsString.cpp プロジェクト: MarcoROG/BansheeEngine
	WString toWString(const Matrix3& val)
	{
		WStringStream stream;
		stream << val[0][0] << L" " 
			<< val[0][1] << L" "             
			<< val[0][2] << L" "             
			<< val[1][0] << L" "             
			<< val[1][1] << L" "             
			<< val[1][2] << L" "             
			<< val[2][0] << L" "             
			<< val[2][1] << L" "             
			<< val[2][2];
		return stream.str();
	}
コード例 #24
0
ファイル: WPointF.C プロジェクト: hhirsch/wtim
WPointF WPointF::swapHV(double width) const
{
  WPointF result(width - y(), x());
  
  if (isJavaScriptBound()) {
    WStringStream ss;
    char buf[30];
    ss << "((function(p){return [";
    ss << Utils::round_js_str(width, 3, buf) << " - p[1],p[0]];})(" << jsRef() + "))";
    result.assignBinding(*this, ss.str());
  }

  return result;
}
コード例 #25
0
ファイル: WPopupWidget.C プロジェクト: devbazy/wt
void WPopupWidget::defineJavaScript()
{
  WApplication *app = WApplication::instance();

  LOAD_JAVASCRIPT(app, "js/WPopupWidget.js", "WPopupWidget", wtjs1);

  WStringStream jsObj;
  jsObj << "new " WT_CLASS ".WPopupWidget("
	<< app->javaScriptClass() << ',' << jsRef() << ','
	<< transient_ << ',' << autoHideDelay_ << ','
	<< !isHidden() << ");";

  setJavaScriptMember(" WPopupWidget", jsObj.str());
}
コード例 #26
0
ファイル: WTimeValidator.C プロジェクト: bytemaster/wt-1
std::string WTimeValidator::javaScriptValidate() const
{
  loadJavaScript(WApplication::instance());

  WStringStream js;

  js << "new " WT_CLASS ".WTimeValidator("
     << (isMandatory() ? "true" : "false") << ",[";

  for (unsigned i = 0; i < formats_.size(); ++i) {
    WTime::RegExpInfo r = WTime::formatToRegExp(formats_[i]);

    if (i != 0)
      js << ',';

    js << "{"
       << "regexp:" << WWebWidget::jsStringLiteral(r.regexp) << ','
       << "getHour:function(results){" << r.hourGetJS << ";},"
       << "getMinute:function(results){" << r.minuteGetJS << ";},"
       << "getSecond:function(results){" << r.secGetJS << ";}"
       << "getMSec:function(results){" << r.msecGetJS << ";}"
       << "}";
  }

  js << "],";

  if (!bottom_.isNull())
    js << "new Time("
       << bottom_.hour() << ',' << bottom_.minute()-1 << ',' << bottom_.second()
       << ")";
  else
    js << "null";

  js << ',';

  if (!top_.isNull())
    js << "new Time("
       << top_.hour() << ',' << top_.minute()-1 << ',' << top_.second()
       << ")";
  else
    js << "null";

  js << ',' << invalidBlankText().jsStringLiteral()
     << ',' << invalidNotATimeText().jsStringLiteral()
     << ',' << invalidTooEarlyText().jsStringLiteral()
     << ',' << invalidTooLateText().jsStringLiteral()
     << ");";

  return js.str();
}
コード例 #27
0
ファイル: WDateValidator.C プロジェクト: LifeGo/wt
std::string WDateValidator::javaScriptValidate() const
{
  loadJavaScript(WApplication::instance());

  WStringStream js;

  js << "new " WT_CLASS ".WDateValidator("
     << isMandatory()
     << ",[";

  for (unsigned i = 0; i < formats_.size(); ++i) {
    WDate::RegExpInfo r = WDate::formatToRegExp(formats_[i]);
    if (i != 0)
      js << ',';

    js << "{"
       << "regexp:" << WWebWidget::jsStringLiteral(r.regexp) << ','
       << "getMonth:function(results){" << r.monthGetJS << ";},"
       << "getDay:function(results){" << r.dayGetJS << ";},"
       << "getYear:function(results){" << r.yearGetJS << ";}"
       << "}";
  }

  js << "],";

  if (!bottom_.isNull())
    js << "new Date("
       << bottom_.year() << ',' << bottom_.month()-1 << ',' << bottom_.day()
       << ")";
  else
    js << "null";

  js << ',';

  if (!top_.isNull())
    js << "new Date("
       << top_.year() << ',' << top_.month()-1 << ',' << top_.day()
       << ")";
  else
    js << "null";

  js << ',' << invalidBlankText().jsStringLiteral()
     << ',' << invalidNotADateText().jsStringLiteral()
     << ',' << invalidTooEarlyText().jsStringLiteral()
     << ',' << invalidTooLateText().jsStringLiteral()
     << ");";

  return js.str();
}
コード例 #28
0
	void GUIStatusBar::setProject(const WString& name, bool modified)
	{
		WStringStream content;
		content << L"Project: ";

		if (name.size() > 20)
			content << name.substr(0, 20) << L"...";
		else
			content << name;

		if (modified)
			content << L"*";

		mProject->setContent(HString(content.str()));
	}
コード例 #29
0
ファイル: WImage.C プロジェクト: LifeGo/wt
std::string WImage::updateAreasJS()
{
  WStringStream ss;
  if (!targetJS_.empty()) {
    ss <<
      "(function(){"
      """var w = " << jsRef() << ";"
      """if (w) {"
      ""  "var o = jQuery.data(" << jsRef() << ", 'obj');"
      ""  "if (o) { o.updateAreas(); }"
      """}"
      "})();";
  }
  return ss.str();
}
コード例 #30
0
	void GUIStatusBar::setScene(const WString& name, bool modified)
	{
		WStringStream content;
		content << L"Scene: ";

		if (name.size() > 15)
			content << name.substr(0, 15) << L"...";
		else
			content << name;

		if (modified)
			content << L"*";

		mScene->setContent(HString(content.str()));
	}