Beispiel #1
0
void WRasterImage::drawImage(const WRectF& rect, const std::string& imgUri,
			     int imgWidth, int imgHeight,
			     const WRectF& srect)
{
  SkBitmap bitmap;
  bool success = false;
  if (DataUri::isDataUri(imgUri)) {
    DataUri uri(imgUri);
    success =
      SkImageDecoder::DecodeMemory(&uri.data[0], uri.data.size(),
				   &bitmap, SkBitmap::kARGB_8888_Config,
				   SkImageDecoder::kDecodePixels_Mode, 0);
    if (!success)
      throw WException("WRasterImage: could not decode data URL (mime type "
		       + uri.mimeType);
  } else {
    success =
      SkImageDecoder::DecodeFile(imgUri.c_str(),
				 &bitmap, SkBitmap::kARGB_8888_Config,
				 SkImageDecoder::kDecodePixels_Mode, 0);
    if (!success)
      throw WException("WRasterImage: could not load file " + imgUri);
  }

  SkRect src = SkRect::MakeLTRB(SkDoubleToScalar(srect.left()),
				SkDoubleToScalar(srect.top()),
				SkDoubleToScalar(srect.right()),
				SkDoubleToScalar(srect.bottom()));
  SkRect dst = SkRect::MakeLTRB(SkDoubleToScalar(rect.left()),
				SkDoubleToScalar(rect.top()),
				SkDoubleToScalar(rect.right()),
				SkDoubleToScalar(rect.bottom()));
  impl_->canvas_->drawBitmapRectToRect(bitmap, &src, dst);
}
Beispiel #2
0
WDialog::DialogCode WDialog::exec(const WAnimation& animation)
{
  if (recursiveEventLoop_)
    throw WException("WDialog::exec(): already being executed.");

  animateShow(animation);

#ifdef WT_TARGET_JAVA
  if (!WebController::isAsyncSupported())
     throw WException("WDialog#exec() requires a Servlet 3.0 enabled servlet " 
		      "container and an application with async-supported "
		      "enabled.");
#endif

  WApplication *app = WApplication::instance();
  recursiveEventLoop_ = true;

  if (app->environment().isTest()) {
    app->environment().dialogExecuted().emit(this);
    if (recursiveEventLoop_)
      throw WException("Test case must close dialog");
  } else {
    do {
      app->session()->doRecursiveEventLoop();
    } while (recursiveEventLoop_);
  }

  hide();

  return result_;
}
Beispiel #3
0
void Money::checkCurrency(Money& ans, const Money& v1, const Money& v2)
{
  if(v1.currency() == "" && v1.valueInCents() != 0){
    throw WException("Payment::Money::checkCurrency "
                     "money with no currency has value.");
  }

  if(v2.currency() == "" && v2.valueInCents() != 0){
    throw WException("Payment::Money::checkCurrency "
                     "money with no currency has value.");
  }

  if(v1.currency() == ""){
    ans.setCurrency(v2.currency());
    return;
  }

  if(v2.currency() == ""){
    ans.setCurrency(v1.currency());
    return;
  }

  if(v1.currency() != v2.currency()){
    throw WException("Payment::Money::checkCurrency different currency");
  }
}
Beispiel #4
0
void WMediaPlayer::setFormData(const FormData& formData)
{
  if (!Utils::isEmpty(formData.values)) {
    std::vector<std::string> attributes;
    boost::split(attributes, formData.values[0], boost::is_any_of(";"));
    if (attributes.size() == 8) {
      try {
        status_.volume = boost::lexical_cast<double>(attributes[0]);
	status_.currentTime = boost::lexical_cast<double>(attributes[1]);
        status_.duration = boost::lexical_cast<double>(attributes[2]);
        status_.playing = (attributes[3] == "0");
        status_.ended = (attributes[4] == "1");
        status_.readyState
	  = intToReadyState(boost::lexical_cast<int>(attributes[5]));
	status_.playbackRate = boost::lexical_cast<double>(attributes[6]);
        status_.seekPercent = boost::lexical_cast<double>(attributes[7]);

	updateProgressBarState(Time);
	updateProgressBarState(Volume);

      } catch (const std::exception& e) {
	throw WException("WMediaPlayer: error parsing: "
			 + formData.values[0] + ": " + e.what());
      }
    } else
      throw WException("WMediaPlayer: error parsing: " + formData.values[0]);
  }
}
Beispiel #5
0
/*
 * Read until finding the boundary, saving to resultString or
 * resultFile. The boundary itself is not consumed.
 *
 * tossAtBoundary controls how many characters extra (<0)
 * or few (>0) are saved at the start of the boundary in the result.
 */
void CgiParser::readUntilBoundary(WebRequest& request,
				  const std::string boundary,
				  int tossAtBoundary,
				  std::string *resultString,
				  std::ostream *resultFile)
{
  int bpos;

  while ((bpos = index(boundary)) == -1) {
    /*
     * If we couldn't find it. We need to wind the buffer, but only save
     * not including the boundary length.
     */
    if (left_ == 0)
      throw WException("CgiParser: reached end of input while seeking end of "
		       "headers or content. Format of CGI input is wrong");

    /* save (up to) BUFSIZE from buffer to file or value string, but
     * mind the boundary length */
    int save = std::min((buflen_ - (int)boundary.length()), (int)BUFSIZE);

    if (save > 0) {
      if (resultString)
	*resultString += std::string(buf_, save);
      if (resultFile) 
	resultFile->write(buf_, save);

      /* wind buffer */
      windBuffer(save);
    }

    unsigned amt = static_cast<unsigned>
      (std::min(left_,
		static_cast< ::int64_t >(BUFSIZE + MAXBOUND - buflen_)));

    request.in().read(buf_ + buflen_, amt);    
    if (request.in().gcount() != (int)amt)
      throw WException("CgiParser: short read");

    left_ -= amt;
    buflen_ += amt;
  }

  if (resultString)
    *resultString += std::string(buf_, bpos - tossAtBoundary);
  if (resultFile)
    resultFile->write(buf_, bpos - tossAtBoundary);

  /* wind buffer */
  windBuffer(bpos);
}
Beispiel #6
0
void MessageBox::onClick(std::string buttonId, std::string value)
{
  hidden_ = true;
  restoreExposeMask(WApplication::instance());

  StandardButton b = NoButton;

  if      (buttonId == "ok")     b = Ok;
  else if (buttonId == "cancel") b = Cancel;
  else if (buttonId == "yes")    b = Yes;
  else if (buttonId == "no")     b = No;
  else
    throw WException("MessageBox: internal error, unknown buttonId '"
		     + buttonId + "';");

  bool accepted = b == Ok || b == Yes;

  if (accepted)
    value_ = WString::fromUTF8(value);
  result_ = b;
    
  bool wasDeleted = false;
  catchDelete_ = &wasDeleted;

  done(accepted ? Accepted : Rejected);

  if (!wasDeleted) {
    buttonClicked_.emit(b);
    catchDelete_ = 0;
  }
}
Beispiel #7
0
const User& AuthTokenResult::user() const
{
  if (user_.isValid())
    return user_;
  else
    throw WException("AuthTokenResult::user() invalid");
}
Beispiel #8
0
int AuthTokenResult::newTokenValidity() const
{
    if (user_.isValid())
        return newTokenValidity_;
    else
        throw WException("AuthTokenResult::newTokenValidity() invalid");
}
bool WLocalizedStrings::resolvePluralKey(const std::string& key,
										 long long ModuleId,
										 std::string& result, 
										 ::uint64_t amount)
{
	throw WException("WLocalizedStrings::resolvePluralKey is not supported");
}
Beispiel #10
0
void CgiParser::readMultipartData(WebRequest& request,
				  const std::string type, ::int64_t len)
{
  std::string boundary;
    
  if (!fishValue(type, boundary_e, boundary))
    throw WException("Could not find a boundary for multipart data.");
    
  boundary = "--" + boundary;

  buflen_ = 0;
  left_ = len;
  spoolStream_ = 0;
  currentKey_.clear();

  if (!parseBody(request, boundary))
    return;

  for (;;) {
    if (!parseHead(request))
      break;
    if (!parseBody(request,boundary)) 
      break;
  }
}
Beispiel #11
0
WPdfImage::WPdfImage(const WLength& width, const WLength& height)
  : width_(width),
    height_(height),
    painter_(nullptr)
{
  myPdf_ = true;

  pdf_ = HPDF_New(error_handler, this);
  if (!pdf_)
    throw WException("Could not create libharu document.");

  HPDF_SetCompressionMode(pdf_, HPDF_COMP_ALL);

  page_ = HPDF_AddPage(pdf_);

  font_ = nullptr;

  x_ = y_ = 0;

  HPDF_Page_SetWidth(page_, width_.toPixels());
  HPDF_Page_SetHeight(page_, height_.toPixels());
  HPDF_Page_GSave(page_);

  trueTypeFonts_ = new FontSupport(this, FontSupport::TrueTypeOnly);

#if HPDF_VERSION_ID>=20300
  HPDF_UseUTFEncodings(pdf_);
#endif
}
Beispiel #12
0
std::string AuthTokenResult::newToken() const
{
  if (user_.isValid())
    return newToken_;
  else
    throw WException("AuthTokenResult::newToken() invalid");
}
Beispiel #13
0
void WWidgetItem::setParentWidget(WWidget *parent)
{
  if (!widget_)
    return;

  if (parent) {
    WContainerWidget *pc = dynamic_cast<WContainerWidget *>(parent);

    if (widget_->parent()) {
      if (widget_->parent() != pc)
	throw WException("Cannot move a WWidgetItem to another container");
    } else
      pc->widgetAdded(widget_.get());

    bool flexLayout = dynamic_cast<FlexLayoutImpl *>
      (parentLayout_->impl()) != 0;

    if (flexLayout)
      impl_ = cpp14::make_unique<FlexItemImpl>(this);
    else
      impl_ = cpp14::make_unique<StdWidgetItemImpl>(this);
  } else {
    WContainerWidget *pc = dynamic_cast<WContainerWidget *>(widget_->parent());

    if (pc)
      pc->widgetRemoved(widget_.get(), true);

    impl_.reset();
  }
}
Beispiel #14
0
static void fatalFormatError(const WString& format, int c, const char* cs)
{
  std::stringstream s;
  s << "WTime format syntax error (for \"" << format.toUTF8()
    << "\"): Cannot handle " << c << " consecutive " << cs;

  throw WException(s.str());
}
Beispiel #15
0
void WGLWidget::uniformMatrix4(const UniformLocation &location,
			       const JavaScriptMatrix4x4 &jsm)
{
  if (!jsm.initialized())
    throw WException("JavaScriptMatrix4x4: matrix not initialized");

  pImpl_->uniformMatrix4(location, jsm);
}
Beispiel #16
0
const std::set<int>& WSelectionBox::selectedIndexes() const
{
  if (selectionMode_ != SelectionMode::Extended)
    throw WException("WSelectionBox::setSelectedIndexes() can only be used "
		     "for an SelectionMode::Extended mode");

  return selection_;
}
Beispiel #17
0
void WGLWidget::setJavaScriptMatrix4(JavaScriptMatrix4x4 &jsm,
				     const WGenericMatrix<double, 4, 4> &m)
{
  if (!jsm.initialized())
    throw WException("JavaScriptMatrix4x4: matrix not initialized");
  if (jsm.hasOperations())
    throw WException("JavaScriptMatrix4x4: matrix was already operated on");

  valueChanged_ = true;

  // set the server-side copy
  for (unsigned i = 0; i < jsMatrixList_.size(); i++)
    if (jsMatrixList_[i].id == jsm.id())
      jsMatrixList_[i].serverSideCopy = m;

  pImpl_->setJavaScriptMatrix4(jsm, m);
}
Beispiel #18
0
void WGLWidget::addJavaScriptMatrix4(JavaScriptMatrix4x4 &mat)
{
  if (mat.hasContext())
    throw WException("The given matrix is already associated with a WGLWidget!");
  mat.assignToContext(jsValues_++, this);

  jsMatrixList_.push_back(jsMatrixMap(mat.id(), WMatrix4x4()));
}
Beispiel #19
0
void WObject::removeChild(WObject *child)
{
    if (child->parent_ != this)
        throw WException("WObject::removeChild() called with non-child");

    assert(children_);
    Utils::erase(*children_, child);
    child->setParent(0);
}
Beispiel #20
0
void WLength::setUnit(Unit unit)
{
  unit_ = unit;

#ifndef WT_TARGET_JAVA
  if (unit_ < FontEm || unit_ > Percentage)
    throw WException("WLength: improper unit value.");
#endif // WT_TARGET_JAVA
}
Beispiel #21
0
void WPdfImage::errorHandler(HPDF_STATUS error_no,
			     HPDF_STATUS detail_no)
{
  char buf[200];
  snprintf(buf, 200, "WPdfImage error: error_no=%04X, detail_no=%d",
    (unsigned int) error_no, (int) detail_no);

  throw WException(buf);
}
Beispiel #22
0
WLink::WLink(Type type, const std::string& value)
{
  switch (type) {
  case Url: setUrl(value); break;
  case InternalPath: setInternalPath(WString::fromUTF8(value)); break;
  default:
    throw WException("WLink::WLink(type) cannot be used for a Resource");
  }
}
Beispiel #23
0
void WPdfImage::drawImage(const WRectF& rect, const std::string& imgUrl,
			  int imgWidth, int imgHeight,
			  const WRectF& srect)
{
  HPDF_Image img = 0;

  if (Uri::isDataUri(imgUrl)) {
    Uri::Uri uri = Uri::parseDataUri(imgUrl);
    if ("image/png" == uri.mimeType)
      img = HPDF_LoadPngImageFromMem(pdf_, 
				     (HPDF_BYTE*)uri.data.c_str(), 
				     uri.data.size()); 
    else if ("image/jpeg" == uri.mimeType)
      img = HPDF_LoadJpegImageFromMem(pdf_, 
				      (HPDF_BYTE*)uri.data.c_str(), 
				      uri.data.size()); 
  } else {
    std::string mimeType = Image::identifyImageFileMimeType(imgUrl);
    if ("image/png" == mimeType)
      img = HPDF_LoadPngImageFromFile2(pdf_, imgUrl.c_str());
    else if ("image/jpeg" == mimeType)
      img = HPDF_LoadJpegImageFromFile(pdf_, imgUrl.c_str());
  } 

  if (!img)
    throw WException("WPdfImage::drawImage(): cannot load image: " + imgUrl);

  double x = rect.x();
  double y = rect.y();
  double width = rect.width();
  double height = rect.height();

  HPDF_Page_GSave(page_);

  if (srect.x() != 0
      || srect.y() != 0
      || srect.width() != imgWidth
      || srect.height() != imgHeight) {
    double scaleX = width / imgWidth;
    double scaleY = height / imgHeight;

    x -= srect.x() * scaleX;
    y -= srect.y() * scaleY;
    width *= scaleX;
    height *= scaleY;

    HPDF_Page_Rectangle(page_, rect.x(), rect.y(), rect.width(), rect.height());
    HPDF_Page_Clip(page_);
  }

  HPDF_Page_Concat(page_, 1, 0, 0, -1, x, y + height); // revert upside-down

  HPDF_Page_DrawImage(page_, img, 0, 0, width, height);

  HPDF_Page_GRestore(page_);
}
Beispiel #24
0
void WSelectionBox::setSelectedIndexes(const std::set<int>& selection)
{
  if (selectionMode_ != ExtendedSelection)
    throw WException("WSelectionBox::setSelectedIndexes() can only be used "
		     "for an ExtendedSelection mode");

  selection_ = selection;
  selectionChanged_ = true;
  repaint(RepaintInnerHtml);
}
Beispiel #25
0
WGLWidget::JavaScriptMatrix4x4 WGLWidget::JavaScriptMatrix4x4::transposed() const
{
  if (!initialized())
    throw WException("JavaScriptMatrix4x4: matrix not initialized");
  WGLWidget::JavaScriptMatrix4x4 copy = WGLWidget::JavaScriptMatrix4x4(*this);
  copy.jsRef_ = WT_CLASS ".glMatrix.mat4.transpose(" +
    jsRef_ + ", " WT_CLASS ".glMatrix.mat4.create())";
  copy.operations_.push_back(op::TRANSPOSE);
  return copy;
}
Beispiel #26
0
void WSelectionBox::setSelectedIndexes(const std::set<int>& selection)
{
  if (selectionMode_ != SelectionMode::Extended)
    throw WException("WSelectionBox::setSelectedIndexes() can only be used "
		     "for an SelectionMode::Extended mode");

  selection_ = selection;
  selectionChanged_ = true;
  repaint();
}
Beispiel #27
0
void OAuthTokenEndpoint::setRSAKey(const std::string &path)
{
  if (privateKey)
    RSA_free(privateKey);
  RSA* rsa = RSA_new();
  privateKey = PEM_read_RSAPrivateKey(fopen(path.c_str(), "rb"), &rsa, NULL, NULL);
  if (!privateKey) {
    throw WException("OAuthTokenEndpoint: invalid RSA key \"" + path + "\"");
  }
}
Beispiel #28
0
JSlot::JSlot(int nbArgs, WWidget *parent)
  : widget_(parent),
    fid_(nextFid_++),
    nbArgs_(nbArgs)
{
  if (nbArgs_ < 0 || nbArgs_ > 6) {
    throw WException("The number of arguments given must be between 0 and 6.");
  }
  create();
}
Beispiel #29
0
void WRasterImage::init()
{
  if (!impl_->w_ || !impl_->h_)
    throw WException("Raster image should have non-0 width and height");

  // save unit matrix & empty clipping
  impl_->canvas_->save();

  setChanged(Clipping | Transform | Pen | Brush | Font | Hints);
}
Beispiel #30
0
const WDataSeries& WCartesianChart::series(int modelColumn) const
{
  int index = seriesIndexOf(modelColumn);

  if (index != -1)
    return series_[index];

  throw WException("Column " + boost::lexical_cast<std::string>(modelColumn)
		   + " not in plot");
}