Exemplo n.º 1
0
void WTemplate::resolveString(const std::string& varName,
			      const std::vector<WString>& args,
			      std::ostream& result)
{
  /*
   * FIXME: have an extra result parameter which indicates whether the
   * widget is view-only. Better to do that in resolveValue() and
   * provide a utility method that converts a widget to XHTML ?
   */

  StringMap::const_iterator i = strings_.find(varName);
  if (i != strings_.end())
    result << i->second;
  else {
    WWidget *w = resolveWidget(varName);
    if (w) {
      w->setParentWidget(this);

      if (previouslyRendered_
	  && previouslyRendered_->find(w) != previouslyRendered_->end()) {
	result << "<span id=\"" << w->id() << "\"> </span>";
      } else {
	applyArguments(w, args);
	w->htmlText(result);
      }

      if (newlyRendered_)
        newlyRendered_->push_back(w);
    } else
      handleUnresolvedVariable(varName, args, result);
  }
}
Exemplo n.º 2
0
Arquivo: Widget.C Projeto: ReWeb3D/wt
std::string Widget::createMixed(const std::vector<WWidget *>& items,
				std::stringstream& js)
{
  std::string refs;
 
  for (unsigned i = 0; i < items.size(); ++i) {
    WWidget *c = items[i];
    Widget *w = dynamic_cast<Widget *>(c);
    FormField *ff = dynamic_cast<FormField *>(c);

    std::string var;
    if (w && !ff) {
      var = w->createExtElement(js, 0);
    } else {
      var = c->createJavaScript(js, "document.body.appendChild(");
    }

    if (i != 0)
      refs += ",";

    refs += var;
  }

  return refs;
}
Exemplo n.º 3
0
void WStackedWidget::setCurrentIndex(int index, const WAnimation& animation,
				     bool autoReverse)
{
  if (!animation.empty() && loadAnimateJS()
      && (isRendered() || !canOptimizeUpdates())) {
    if (canOptimizeUpdates() && index == currentIndex_)
      return;

    WWidget *previous = currentWidget();

    setJavaScriptMember("wtAutoReverse", autoReverse ? "true" : "false");

    if (previous)
      previous->animateHide(animation);
    widget(index)->animateShow(animation);

    currentIndex_ = index;
  } else {
    currentIndex_ = index;

    for (int i = 0; i < count(); ++i)
      if (widget(i)->isHidden() != (currentIndex_ != i))
	widget(i)->setHidden(currentIndex_ != i);

    if (isRendered())
      doJavaScript("$('#" + id() + "').data('obj').setCurrent("
		   + widget(currentIndex_)->jsRef() + ");");
  }
}
Exemplo n.º 4
0
void WStackedWidget::setCurrentIndex(int index, const WAnimation& animation,
				     bool autoReverse)
{
  if (!animation.empty() && 
      WApplication::instance()->environment().supportsCss3Animations() &&
      ((isRendered() && javaScriptDefined_) || !canOptimizeUpdates())) {
    if (canOptimizeUpdates() && index == currentIndex_)
      return;

    loadAnimateJS();

    WWidget *previous = currentWidget();

    doJavaScript("$('#" + id() + "').data('obj').adjustScroll("
		 + widget(currentIndex_)->jsRef() + ");");
    setJavaScriptMember("wtAutoReverse", autoReverse ? "true" : "false");

    if (previous)
      previous->animateHide(animation);
    widget(index)->animateShow(animation);

    currentIndex_ = index;
  } else {
    currentIndex_ = index;

    for (int i = 0; i < count(); ++i)
      if (widget(i)->isHidden() != (currentIndex_ != i))
	widget(i)->setHidden(currentIndex_ != i);

    if (currentIndex_ >= 0 && isRendered() && javaScriptDefined_)
      doJavaScript("$('#" + id() + "').data('obj').setCurrent("
		   + widget(currentIndex_)->jsRef() + ");");
  }
}
Exemplo n.º 5
0
void WWidget::childResized(WWidget *child, WFlags<Orientation> directions)
{
    WWidget *p = parent();

    if (p)
        p->childResized(this, directions);
}
Exemplo n.º 6
0
Arquivo: WWidget.C Projeto: DTidd/wt
void WWidget::scheduleRerender(bool laterOnly, WFlags<RepaintFlag> flags)
{
  if (!flags_.test(BIT_NEED_RERENDER)) {
    flags_.set(BIT_NEED_RERENDER);
    WApplication::instance()->session()->renderer().needUpdate(this, laterOnly);
  }

  if ((flags & RepaintSizeAffected) &&
      !flags_.test(BIT_NEED_RERENDER_SIZE_CHANGE)) {
    flags_.set(BIT_NEED_RERENDER_SIZE_CHANGE);

    webWidget()->parentResized(this, Vertical);

    /*
     * A size change to an absolutely positioned widget will not affect
     * a layout computation, except if it's itself in a layout!
     */
    if (positionScheme() == Absolute && !isInLayout())
      return;

    /*
     * Propagate event up, this will be caught by a container widget
     * with a layout manager.
     */
    WWidget *p = parent();

    if (p)
      p->childResized(this, Vertical);
  }
}
Exemplo n.º 7
0
DomElement *StdWidgetItemImpl::createDomElement(bool fitWidth, bool fitHeight,
						WApplication *app)
{
  WWidget *w = item_->widget();

  w->setInline(false);

  DomElement *d = w->createSDomElement(app);
  DomElement *result = d;

  if (app->environment().agentIsIElt(9) &&
      (d->type() == DomElement_TEXTAREA || d->type() == DomElement_SELECT
       || d->type() == DomElement_INPUT || d->type() == DomElement_BUTTON)) {
    d->removeProperty(PropertyStyleDisplay);
  }

  // FIXME IE9 does border-box perhaps ?
  if (!app->environment().agentIsIE() && 
      w->javaScriptMember(WWidget::WT_RESIZE_JS).empty() &&
      d->type() != DomElement_TABLE /* buggy in Chrome, see #1856 */ &&
      app->theme()->canBorderBoxElement(*d))
    d->setProperty(PropertyStyleBoxSizing, "border-box");

  return result;
}
Exemplo n.º 8
0
void PrintResource::handleRequest(const Wt::Http::Request& request,
                                  Wt::Http::Response& response)
{
    //log("info")<<"PrintResource::handleRequest() "<<__LINE__;
    response.addHeader("Cache-Control", "max-age=315360000");
    response.setMimeType("text/html; charset=utf-8");
    std::ostringstream htmlStream;// = std::cout;
    htmlStream << "";

    //log("info")<<m_content->find("order_form");
    if(WContainerWidget *form = dynamic_cast<WContainerWidget*>(m_content->find("order_form")))
    {
        for(int i=0;i < form->count()-1;i++)
        {
            WWidget *item = form->widget(i);
            if(item->id() == "comments")
            {
                item->decorationStyle().setBorder(WBorder());
            }else
                item->setHidden(true);
        }
    }

    response.out() <<"<link href=\"http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css\" type=\"text/css\" rel=\"stylesheet\">"<<std::endl;
    response.out() <<"<link href=\"http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css\" type=\"text/css\" rel=\"stylesheet\">"<<std::endl;
    response.out() << "<script src=\"/css/ie_console.js\"></script>";

    response.out() << ""
    "<script type=\"text/javascript\">\n"
    "        window.setTimeout(function () {\n"
    "            window.print();\n"
    "        }, 1000);\n"
    "</script>\n"<<std::endl;

    m_content->htmlText(response.out());
    //log("info")<<"PrintResource::handleRequest() "<<__LINE__;

/*
    response.out() << ""
    "<script type=\"text/javascript\">\n"
    "    (function() { \n"
    "        window.setTimeout(function () {\n"
    "            window.print();\n"
    "        }, 1500);\n"
    "    }); \n"
    "</script>\n"<<std::endl;

*/
    //m_content->htmlText(htmlStream);
    //std::string htmlStr= "";
    //htmlStr << htmlStream;
    //std::cout <<htmlStream<<std::endl;
    //renderer.render(WString().fromUTF8(htmlStream.str()));

    response.out() << WString().fromUTF8(htmlStream.str()) << std::endl;
}
Exemplo n.º 9
0
bool StdGridLayoutImpl2::hasItem(int row, int col) const
{
  WLayoutItem *item = grid_.items_[row][col].item_;

  if (item) {
    WWidget *w = item->widget();
    return !w || !w->isHidden();
  } else
    return false;
}
Exemplo n.º 10
0
WWidget *WTemplate::takeWidget(const std::string& varName)
{
  WidgetMap::iterator i = widgets_.find(varName);

  if (i != widgets_.end()) {
    WWidget *result = i->second;
    result->setParentWidget(0);
    return result;
  } else
    return 0;
}
Exemplo n.º 11
0
bool WWidget::containsExposed(WWidget *w) const
{
    if (w == this)
        return true;

    for (WWidget *p = w; p; p = p->parent())
        if (p == this)
            return true;

    return false;
}
Exemplo n.º 12
0
bool WWidget::isInLayout() const
{
    WWidget *p = parent();
    if (p != 0 &&
            (dynamic_cast<WCompositeWidget *>(p) != 0 ||
             !p->javaScriptMember(WT_RESIZE_JS).empty()))
        return p->isInLayout();

    WContainerWidget *c = dynamic_cast<WContainerWidget *>(p);

    return c != 0 && c->layout() != 0;
}
Exemplo n.º 13
0
WWidget *WScrollArea::takeWidget()
{
  WWidget *result = widget_;
  widget_ = 0;

  setWidget(0);

  if (result)
    result->setParent(0);

  return result;
}
Exemplo n.º 14
0
Arquivo: WWidget.C Projeto: DTidd/wt
void WWidget::childResized(WWidget *child, WFlags<Orientation> directions)
{
  /*
   * Stop propagation at an absolutely positioned widget
   */
  if (positionScheme() == Absolute && !isInLayout())
    return;

  WWidget *p = parent();

  if (p)
    p->childResized(this, directions);
}
Exemplo n.º 15
0
int main(int argc, char *argv[])
{
	QApplication app(argc, argv);

	QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
	QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
	QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));

	WWidget wwidget;
	wwidget.show();

	return app.exec();
	return 0;
}
Exemplo n.º 16
0
bool WTemplate::_id(const std::vector<WString>& args,
		    std::ostream& result)
{
  if (args.size() == 1) {
    WWidget *w = this->resolveWidget(args[0].toUTF8());
    if (w) {
      result << w->id();
      return true;
    } else
      return false;
  } else {
    LOG_ERROR("Functions::tr(): expects exactly one argument");
    return false;
  }
}
Exemplo n.º 17
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);
  }
}
Exemplo n.º 18
0
void WTreeTableNode::setTable(WTreeTable *table)
{
  if (table_ != table) {
    table_ = table;

    for (unsigned i = 0; i < childNodes().size(); ++i)
      dynamic_cast<WTreeTableNode *>(childNodes()[i])->setTable(table);

    createExtraColumns(table->columnCount() - 1);

    for (unsigned i = 0; i < columnWidgets_.size(); ++i) {
      WWidget *w = columnWidgets_[i].widget;
      w->resize(columnWidth(i + 1), w->height());
    }
  }
}
Exemplo n.º 19
0
void WTemplateFormView::updateViewField(WFormModel *model,
					WFormModel::Field field)
{
  const std::string var = field;

  if (model->isVisible(field)) {
    setCondition("if:" + var, true);
    WWidget *edit = resolveWidget(var);
    if (!edit) {
      edit = createFormWidget(field);
      if (!edit) {
	LOG_ERROR("updateViewField: createFormWidget('"
		  << field << "') returned 0");
	return;
      }
      bindWidget(var, edit);
    }

    WFormWidget *fedit = dynamic_cast<WFormWidget *>(edit);
    if (fedit) {
      if (fedit->validator() != model->validator(field) &&
	  model->validator(field))
	fedit->setValidator(model->validator(field));
      updateViewValue(model, field, fedit);
    } else
      updateViewValue(model, field, edit);

    WText *info = resolve<WText *>(var + "-info");
    if (!info) {
      info = new WText();
      bindWidget(var + "-info", info);
    }

    bindString(var + "-label", model->label(field));

    const WValidator::Result& v = model->validation(field);
    info->setText(v.message());
    indicateValidation(field, model->isValidated(field),
		       info, edit, v);
    edit->setDisabled(model->isReadOnly(field));
  } else {
    setCondition("if:" + var, false);
    bindEmpty(var);
    bindEmpty(var + "-info");    
  }
}
Exemplo n.º 20
0
void WWidget::askRerender(bool laterOnly)
{
    if (!flags_.test(BIT_NEED_RERENDER)) {
        flags_.set(BIT_NEED_RERENDER);
        WApplication::instance()->session()->renderer().needUpdate(this, laterOnly);

        /*
         * Let's start with assuming that every change is a potential resize
         *
         * Propagate event up, this will be caught by a container widget
         * with a layout manager.
         */
        WWidget *p = parent();

        if (p)
            p->childResized(this, Vertical);
    }
}
Exemplo n.º 21
0
std::unique_ptr<WWidget> WMenuItem::removeContents()
{
  auto contents = oContents_.get();
  oContents_.reset();

  WWidget *c = contentsInStack();

  if (c) {
    /* Remove from stack */
    std::unique_ptr<WWidget> w = c->parent()->removeWidget(c);

    if (oContentsContainer_)
      return oContentsContainer_->removeWidget(contents);
    else
      return w;
  } else
    return std::move(uContents_);
}
Exemplo n.º 22
0
bool WPopupMenu::isExposed(WWidget *w)
{
  /*
   * w is the popupmenu or contained by the popup menu
   */
  if (WCompositeWidget::isExposed(w))
    return true;

  if (w == WApplication::instance()->root())
    return true;

  /*
   * w is the location at which the popup was positioned, we ignore
   * events on this widget without closing the popup
   */
  if (w == location_)
    return false;

  /*
   * w is a contained popup menu or contained by a sub-popup menu
   */
  for (int i = 0; i < count(); ++i) {
    WPopupMenuItem *item = itemAt(i);
    if (item->popupMenu())
      if (item->popupMenu()->isExposed(w))
	return true;
  }

  // Signal outside of the menu:
  //  - signal of a widget that is an ancestor of location_: ignore it
  //  - otherwise: close the menu and let it be handled.
  if (location_) {
    for (WWidget *p = location_->parent(); p; p = p->parent())
      if (w == p)
	return false;
  }

  if (!parentItem_) {
    done();
    return true;
  } else
    return false;
}
Exemplo n.º 23
0
Arquivo: Home.C Projeto: GuLinux/wt
WWidget *Home::quoteForm()
{
  WContainerWidget *result = new WContainerWidget();
  result->setStyleClass("quote");

  WTemplate *requestTemplate = new WTemplate(tr("quote.request"), result);

  WPushButton *quoteButton = new WPushButton(tr("quote.requestbutton"));
  requestTemplate->bindWidget("button", quoteButton);

  WWidget *quoteForm = createQuoteForm();
  result->addWidget(quoteForm);

  quoteButton->clicked().connect(quoteForm, &WWidget::show);
  quoteButton->clicked().connect(requestTemplate, &WWidget::hide);

  quoteForm->hide();

  return result;
}
Exemplo n.º 24
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);
}
Exemplo n.º 25
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);
}
Exemplo n.º 26
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);
}
Exemplo n.º 27
0
void WContainerWidget::updateDom(DomElement& element, bool all)
{
  if (all && element.type() == DomElement_LI && isInline())
    element.setProperty(PropertyStyleDisplay, "inline");

  if (flags_.test(BIT_CONTENT_ALIGNMENT_CHANGED) || all) {
    AlignmentFlag hAlign = contentAlignment_ & AlignHorizontalMask;

    bool ltr = WApplication::instance()->layoutDirection() == LeftToRight;

    switch (hAlign) {
    case AlignLeft:
      if (flags_.test(BIT_CONTENT_ALIGNMENT_CHANGED))
	element.setProperty(PropertyStyleTextAlign, ltr ? "left" : "right");
      break;
    case AlignRight:
      element.setProperty(PropertyStyleTextAlign, ltr ? "right" : "left");
      break;
    case AlignCenter:
      element.setProperty(PropertyStyleTextAlign, "center");
      break;
    case AlignJustify:
#ifndef WT_NO_LAYOUT
      if (!layout_)
#endif // WT_NO_LAYOUT
	element.setProperty(PropertyStyleTextAlign, "justify");
      break;
    default:
      break;
    }

    if (domElementType() == DomElement_TD) {
      AlignmentFlag vAlign = contentAlignment_ & AlignVerticalMask;
      switch (vAlign) {
      case AlignTop:
	if (flags_.test(BIT_CONTENT_ALIGNMENT_CHANGED))
	  element.setProperty(PropertyStyleVerticalAlign, "top");
	break;
      case AlignMiddle:
	element.setProperty(PropertyStyleVerticalAlign, "middle");
	break;
      case AlignBottom:
	element.setProperty(PropertyStyleVerticalAlign, "bottom");
      default:
	break;
      }
    }
  }

  if (flags_.test(BIT_ADJUST_CHILDREN_ALIGN)
      || flags_.test(BIT_CONTENT_ALIGNMENT_CHANGED) || all) {
    /*
     * Welcome to CSS hell.
     *
     * Apparently, the text-align property only applies to inline elements.
     * To center non-inline children, the standard says to set its left and
     * right margin to 'auto'.
     *
     * I assume the same applies for aligning to the right ?
     */
    for (unsigned i = 0; i < children_->size(); ++i) {
      WWidget *child = (*children_)[i];

      if (!child->isInline()) {
	AlignmentFlag ha = contentAlignment_ & AlignHorizontalMask;
	if (ha == AlignCenter) {
	  if (!child->margin(Left).isAuto())
	    child->setMargin(WLength::Auto, Left);
	  if (!child->margin(Right).isAuto())
	    child->setMargin(WLength::Auto, Right);
	} else if (ha == AlignRight) {
	  if (!child->margin(Left).isAuto())
	    child->setMargin(WLength::Auto, Left);
	}
      }
    }

    flags_.reset(BIT_CONTENT_ALIGNMENT_CHANGED);
    flags_.reset(BIT_ADJUST_CHILDREN_ALIGN);
  }

  if (flags_.test(BIT_PADDINGS_CHANGED)
      || (all && padding_ &&
	  !(   padding_[0].isAuto() && padding_[1].isAuto()
	    && padding_[2].isAuto() && padding_[3].isAuto()))) {

    if ((padding_[0] == padding_[1])
	&& (padding_[0] == padding_[2])
	&& (padding_[0] == padding_[3]))
      element.setProperty(PropertyStylePadding,
			  padding_[0].cssText());
    else
      element.setProperty(PropertyStylePadding,
			  padding_[0].cssText()
			  + " " + padding_[1].cssText()
			  + " " + padding_[2].cssText()
			  + " " + padding_[3].cssText());

    flags_.reset(BIT_PADDINGS_CHANGED);
  }

  WInteractWidget::updateDom(element, all);

  if (flags_.test(BIT_OVERFLOW_CHANGED)
      || (all && overflow_ &&
	  !(overflow_[0] == OverflowVisible
	    && overflow_[1] == OverflowVisible))) {
    static const char *cssText[] = { "visible", "auto", "hidden", "scroll" };

    element.setProperty(PropertyStyleOverflowX, cssText[overflow_[0]]);
    element.setProperty(PropertyStyleOverflowY, cssText[overflow_[1]]);

    flags_.reset(BIT_OVERFLOW_CHANGED);

    /* If a container widget has overflow, then, if ever something
     * inside it has position scheme relative/absolute, it will not
     * scroll properly unless every element up to the container and including 
     * the container itself has overflow: relative.
     *
     * The following fixes the common case:
     * container (overflow) - container - layout
     */
    WApplication *app = WApplication::instance();
    if (app->environment().agentIsIE()
	&& (overflow_[0] == OverflowAuto || overflow_[0] == OverflowScroll))
      if (positionScheme() == Static)
	element.setProperty(PropertyStylePosition, "relative");
  }
}
Exemplo n.º 28
0
void WContainerWidget::updateDom(DomElement& element, bool all)
{
  if (contentAlignmentChanged_ || all) {
    switch(contentAlignment_) {
    case AlignLeft:
      if (contentAlignmentChanged_)
	element.setProperty(PropertyStyleTextAlign, "left");
      break;
    case AlignRight:
      element.setProperty(PropertyStyleTextAlign, "right");
      break;
    case AlignCenter:
      element.setProperty(PropertyStyleTextAlign, "center");
      break;
    case AlignJustify:
      element.setProperty(PropertyStyleTextAlign, "justify");
    }

    /*
     * Welcome to CSS hell.
     *
     * Apparently, the text-align property only applies to inline elements.
     * To center non-inline children, the standard says to set its left and
     * right margin to 'auto'.
     *
     * I assume the same applies for aligning to the right ?
     */
    for (unsigned i = 0; i < children().size(); ++i) {
      WWidget *child = children()[i];

      if (!child->isInline()) {
	if (contentAlignment_ == AlignCenter) {
	  if (!child->margin(Left).isAuto())
	    child->setMargin(WLength(), Left);
	  if (!child->margin(Right).isAuto())
	    child->setMargin(WLength(), Right);
	}
	if (contentAlignment_ == AlignRight) {
	  if (!child->margin(Left).isAuto())
	    child->setMargin(WLength(), Left);
	}
      }
    }

    contentAlignmentChanged_ = false;
  }

  if (paddingsChanged_ || all) {
    if (paddingsChanged_
	|| !padding_[0].isAuto()
	|| !padding_[1].isAuto()
	|| !padding_[2].isAuto()
	|| !padding_[3].isAuto()) {
      if ((padding_[0] == padding_[1])
	  && (padding_[0] == padding_[2])
	  && (padding_[0] == padding_[3]))
	element.setProperty(PropertyStylePadding,
			    padding_[0].cssText());
      else
	element.setProperty(PropertyStylePadding,
			    padding_[0].cssText()
			    + " " + padding_[1].cssText()
			    + " " + padding_[2].cssText()
			    + " " + padding_[3].cssText());
    }

    paddingsChanged_ = false;
  }

  WInteractWidget::updateDom(element, all);

  bool wasEmpty 
    = (((addedChildren_ ? addedChildren_->size() : 0) == children_->size())
       && (otherImpl_ ? (otherImpl_->scriptFunctions_
			? otherImpl_->scriptFunctions_->empty() : true)
	   : true));
  element.setWasEmpty(wasEmpty);

  if (addedChildren_) {
    for (unsigned i = 0; i < addedChildren_->size(); ++i) {
      DomElement *c = (*addedChildren_)[i]->webWidget()->createSDomElement();
      element.addChild(c);
    }

    delete addedChildren_;
    addedChildren_ = 0;
  }
}
Exemplo n.º 29
0
WWidget *WWidget::adam()
{
    WWidget *p = parent();
    return p ? p->adam() : this;
}
Exemplo n.º 30
0
bool WWidget::isRendered() const
{
    WWidget *self = const_cast<WWidget *>(this);
    return self->webWidget()->isRendered();
}