Ejemplo n.º 1
0
void WTemplate::updateDom(DomElement& element, bool all)
{
  if (changed_ || all) {
    std::set<WWidget *> previouslyRendered;
    std::vector<WWidget *> newlyRendered;

    for (WidgetMap::const_iterator i = widgets_.begin(); i != widgets_.end();
	 ++i) {
      WWidget *w = i->second;
      if (w->isRendered() && w->webWidget()->domCanBeSaved()) {
	previouslyRendered.insert(w);
      }
    }

    bool saveWidgets = element.mode() == DomElement::ModeUpdate;

    previouslyRendered_ = saveWidgets ? &previouslyRendered : 0;
    newlyRendered_ = &newlyRendered;

    std::stringstream html;
    renderTemplate(html);

    previouslyRendered_ = 0;
    newlyRendered_ = 0;

    for (unsigned i = 0; i < newlyRendered.size(); ++i) {
      WWidget *w = newlyRendered[i];
      if (previouslyRendered.find(w) != previouslyRendered.end()) {
	if (saveWidgets)
	  element.saveChild(w->id());
	previouslyRendered.erase(w);
      }
    }

    element.setProperty(Wt::PropertyInnerHTML, html.str());
    changed_ = false;

    for (std::set<WWidget *>::const_iterator i = previouslyRendered.begin();
	 i != previouslyRendered.end(); ++i) {
      WWidget *w = *i;
      w->webWidget()->setRendered(false);
    }
  }

  WInteractWidget::updateDom(element, all);
}
Ejemplo n.º 2
0
void WContainerWidget::propagateLayoutItemsOk(WLayoutItem *item)
{
  if (!item)
    return;

  if (item->layout()) {
    WLayout *layout = item->layout();
    const int c = layout->count();
    for (int i = 0; i < c; ++i)
      propagateLayoutItemsOk(layout->itemAt(i));
  } else if (item->widget()) {
    WWidget *w = item->widget();
    w->webWidget()->propagateRenderOk(true);
  }
}
Ejemplo n.º 3
0
void WCalendar::render(WFlags<RenderFlag> flags)
{
  if (needRenderMonth_) {
    bool create = cellClickMapper_ == 0;
#ifndef WT_TARGET_JAVA
    char buf[30];
#else
    char *buf;
#endif // WT_TARGET_JAVA

    if (create) {
      // FIXME catch events only on container, and use 'tid' to identify
      // the cell -- in Ajax mode
      cellClickMapper_ = new WSignalMapper<Coordinate>(this);
      cellClickMapper_->mapped().connect(this, &WCalendar::cellClicked);
      cellDblClickMapper_ = new WSignalMapper<Coordinate>(this);
      cellDblClickMapper_->mapped().connect(this, &WCalendar::cellDblClicked);
    }

    int m = currentMonth_ - 1;
    if (monthEdit_->currentIndex() != m)
      monthEdit_->setCurrentIndex(m);

    int y = currentYear_;
    Utils::itoa(y, buf);
    if (yearEdit_->text().toUTF8() != buf)
      yearEdit_->setText(WString::fromUTF8(buf));

    WDate todayd = WDate::currentDate();
    date today(todayd.year(), todayd.month(), todayd.day());

    // The first line contains the last day of the previous month.
    date d(currentYear_, currentMonth_, 1);
    d -= date_duration(1);
 
    greg_weekday gw = firstDayOfWeek_ % 7;
    d = previous_weekday(d, gw);

    for (unsigned i = 0; i < 6; ++i) {
      for (unsigned j = 0; j < 7; ++j) {
	Utils::itoa(i * 7 + j, buf);
	std::string cell = std::string("c") + buf;
	
	WDate date(d.year(), d.month(), d.day());

	WWidget *w = impl_->resolveWidget(cell);
	WWidget *rw = renderCell(w, date);
	impl_->bindWidget(cell, rw);

	WInteractWidget* iw = dynamic_cast<WInteractWidget*>(rw->webWidget());

	if (iw && iw != w) {
	  if (clicked().isConnected()
	      || (selectionMode_ == ExtendedSelection)
	      || (selectionMode_ != ExtendedSelection && singleClickSelect_
		  && activated().isConnected()))
	    cellClickMapper_
	      ->mapConnect(iw->clicked(), Coordinate(i, j));

	  if ((selectionMode_ != ExtendedSelection && !singleClickSelect_
	       && (activated().isConnected() ||
		   selectionChanged().isConnected())))
	    cellDblClickMapper_
	      ->mapConnect(iw->doubleClicked(), Coordinate(i, j));
	}

	d += date_duration(1);
      }
    }

    needRenderMonth_ = false;
  }

  WCompositeWidget::render(flags);
}
Ejemplo n.º 4
0
bool WWidget::isRendered() const
{
    WWidget *self = const_cast<WWidget *>(this);
    return self->webWidget()->isRendered();
}
Ejemplo n.º 5
0
void WTemplate::updateDom(DomElement& element, bool all)
{
  if (changed_ || all) {
    std::set<WWidget *> previouslyRendered;
    std::vector<WWidget *> newlyRendered;

    for (WidgetMap::const_iterator i = widgets_.begin(); i != widgets_.end();
	 ++i) {
      WWidget *w = i->second;
      if (w->isRendered() && w->webWidget()->domCanBeSaved()) {
	previouslyRendered.insert(w);
      }
    }

    bool saveWidgets = element.mode() == DomElement::ModeUpdate;

    previouslyRendered_ = saveWidgets ? &previouslyRendered : 0;
    newlyRendered_ = &newlyRendered;

    std::stringstream html;
    renderTemplate(html);

    previouslyRendered_ = 0;
    newlyRendered_ = 0;

    for (unsigned i = 0; i < newlyRendered.size(); ++i) {
      WWidget *w = newlyRendered[i];
      if (previouslyRendered.find(w) != previouslyRendered.end()) {
	if (saveWidgets)
	  element.saveChild(w->id());
	previouslyRendered.erase(w);
      }
    }

    if (encodeTemplateText_)
      element.setProperty(Wt::PropertyInnerHTML, html.str());
    else
      element.setProperty(Wt::PropertyInnerHTML, encode(html.str()));

    changed_ = false;

    for (std::set<WWidget *>::const_iterator i = previouslyRendered.begin();
	 i != previouslyRendered.end(); ++i) {
      WWidget *w = *i;
      // it could be that the widget was removed/deleted in the mean time
      // as a side-effect of rendering some of the widgets; thus we check
      // that the widget is still a child
      for (WidgetMap::const_iterator j = widgets_.begin();
	   j != widgets_.end(); ++j) {
	if (j->second == w) {
	  w->webWidget()->setRendered(false);
	  break;
	}
      }
    }

    WApplication::instance()->session()->renderer()
      .updateFormObjects(this, true);
  }

  WInteractWidget::updateDom(element, all);
}
Ejemplo n.º 6
0
void WCalendar::render(WFlags<RenderFlag> flags)
{
  if (needRenderMonth_) {
#ifndef WT_TARGET_JAVA
    char buf[30];
#else
    char *buf;
#endif // WT_TARGET_JAVA

    int m = currentMonth_ - 1;
    if (monthEdit_->currentIndex() != m)
      monthEdit_->setCurrentIndex(m);

    int y = currentYear_;
    Utils::itoa(y, buf);
    if (yearEdit_->text().toUTF8() != buf)
      yearEdit_->setText(WString::fromUTF8(buf));

    // The first line contains the last day of the previous month.
    WDate d(currentYear_, currentMonth_, 1);
    d = d.addDays(-1);
 
    d = WDate::previousWeekday(d, firstDayOfWeek_);

    for (unsigned i = 0; i < 6; ++i) {
      for (unsigned j = 0; j < 7; ++j) {
	Utils::itoa(i * 7 + j, buf);
	std::string cell = std::string("c") + buf;
	
	WDate date(d.year(), d.month(), d.day());

	WWidget *w = impl_->resolveWidget(cell);
	WWidget *rw = renderCell(w, date);
	WInteractWidget* iw = dynamic_cast<WInteractWidget*>(rw->webWidget());

	if (rw != w)
	  impl_->bindWidget(cell, std::unique_ptr<WWidget>(rw));

	if (iw && iw != w) {
	  if (clicked().isConnected()
	      || (selectionMode_ == SelectionMode::Extended)
	      || (selectionMode_ != SelectionMode::Extended && 
		  singleClickSelect_ && activated().isConnected())) {
            const Coordinate c(i, j);
	    iw->clicked().connect
	      (this,
	       std::bind(&WCalendar::cellClicked, this, c));
          }

	  if ((selectionMode_ != SelectionMode::Extended &&
	       !singleClickSelect_ && (activated().isConnected() ||
		   selectionChanged().isConnected()))) {
            const Coordinate c(i, j);
	    iw->doubleClicked().connect
	      (this,
	       std::bind(&WCalendar::cellDblClicked, this, c));
          }
	}

    d = d.addDays(1);
      }
    }

    needRenderMonth_ = false;
  }

  WCompositeWidget::render(flags);
}