void WTreeNode::update() { bool isLast = isLastChildNode(); if (!visible_) { layout_->bindString("selected", "Wt-root"); childContainer()->addStyleClass("Wt-root"); } else { if (tree()) { const WTree::WTreeNodeSet &s = tree()->selectedNodes(); if (s.find(this) != s.end()) layout_->bindString("selected", WApplication::instance()->theme()->activeClass()); else layout_->bindEmpty("selected"); } else layout_->bindEmpty("selected"); childContainer()->removeStyleClass("Wt-root"); } WTreeNode *parent = parentNode(); if (parent && !parent->childrenDecorated_) { // FIXME } if (expandIcon_->state() != (isExpanded() ? 1 : 0)) expandIcon_->setState(isExpanded() ? 1 : 0); if (childContainer()->isHidden() != !isExpanded()) childContainer()->setHidden(!isExpanded()); if (labelIcon_ && (labelIcon_->state() != (isExpanded() ? 1 : 0))) labelIcon_->setState(isExpanded() ? 1 : 0); toggleStyleClass("Wt-trunk", !isLast); layout_->bindString("trunk-class", isLast ? "Wt-end" : "Wt-trunk"); if (!parentNode() || parentNode()->isExpanded()) { if (childCountPolicy_ == Enabled && !populated_) doPopulate(); if (!expandable()) { if (noExpandIcon_->parent() == 0) { layout_->takeWidget("expand"); layout_->bindWidget("expand", noExpandIcon_); } } else { if (expandIcon_->parent() == 0) { layout_->takeWidget("expand"); layout_->bindWidget("expand", expandIcon_); } } } if (childCountPolicy_ != Disabled && populated_ && childCountLabel_) { int n = displayedChildCount(); if (n) childCountLabel_->setText (WString::fromUTF8("(" + boost::lexical_cast<std::string>(n) + ")")); else childCountLabel_->setText(WString()); } }
void WInteractWidget::propagateSetEnabled(bool enabled) { flags_.set(BIT_ENABLED, enabled); WApplication *app = WApplication::instance(); std::string disabledClass = app->theme()->disabledClass(); toggleStyleClass(disabledClass, !enabled, true); WWebWidget::propagateSetEnabled(enabled); }
void WMenuItem::renderSelected(bool selected) { WApplication *app = WApplication::instance(); std::string active = app->theme()->activeClass(); if (active == "Wt-selected"){ // for CSS theme, our styles are messed up removeStyleClass(!selected ? "itemselected" : "item", true); addStyleClass(selected ? "itemselected" : "item", true); } else toggleStyleClass(active, selected, true); }
void WPushButton::updateDom(DomElement& element, bool all) { if (all && element.type() == DomElement_BUTTON) element.setAttribute("type", "button"); bool updateInnerHtml = !icon_.isNull() && flags_.test(BIT_TEXT_CHANGED); if (updateInnerHtml || flags_.test(BIT_ICON_CHANGED) || (all && !icon_.isNull())) { DomElement *image = DomElement::createNew(DomElement_IMG); image->setProperty(PropertySrc, icon_.resolveUrl(WApplication::instance())); image->setId("im" + formName()); element.insertChildAt(image, 0); flags_.set(BIT_ICON_RENDERED); flags_.reset(BIT_ICON_CHANGED); } if (flags_.test(BIT_TEXT_CHANGED) || all) { element.setProperty(Wt::PropertyInnerHTML, text_.formattedText()); flags_.reset(BIT_TEXT_CHANGED); } // bool needsUrlResolution = false; if (flags_.test(BIT_LINK_CHANGED) || all) { if (element.type() == DomElement_A) { /* needsUrlResolution = */ WAnchor::renderHRef(this, linkState_, element); WAnchor::renderHTarget(linkState_, element, all); } else renderHRef(element); flags_.reset(BIT_LINK_CHANGED); } if (isCheckable()) { if (flags_.test(BIT_CHECKED_CHANGED) || all) { if (!all || flags_.test(BIT_IS_CHECKED)) { toggleStyleClass("active", flags_.test(BIT_IS_CHECKED), true); } flags_.reset(BIT_CHECKED_CHANGED); } } if (!all) WApplication::instance()->theme()->apply(this, element, MainElementThemeRole); WFormWidget::updateDom(element, all); }
WValidator::State WFormWidget::validate() { if (validator()) { WValidator::Result result = validator()->validate(valueText()); toggleStyleClass("Wt-invalid", result.state() != WValidator::Valid, true); setToolTip(result.message()); validated_.emit(result); return result.state(); } else return WValidator::Valid; }
void WDialog::setResizable(bool resizable) { if (resizable != resizable_) { resizable_ = resizable; toggleStyleClass("Wt-resizable", resizable); setSelectable(!resizable); if (resizable) contents_->setSelectable(true); if (resizable_) { Resizable::loadJavaScript(WApplication::instance()); setJavaScriptMember (" Resizable", "(new " WT_CLASS ".Resizable(" WT_CLASS "," + jsRef() + ")).onresize(function(w, h) {" "var obj = $('#" + id() + "').data('obj');" "if (obj) obj.onresize(w, h);" " });"); } } }
void WWidget::toggleStyleClass(const char *styleClass, bool add, bool force) { toggleStyleClass(WString::fromUTF8(styleClass), add, force); }