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); }
void WContainerWidget::updateDomChildren(DomElement& parent, WApplication *app) { if (!app->session()->renderer().preLearning() && !layout_) { if (parent.mode() == DomElement::ModeUpdate) parent.setWasEmpty(wasEmpty()); if (transientImpl_) { std::vector<int> orderedInserts; std::vector<WWidget *>& ac = transientImpl_->addedChildren_; for (unsigned i = 0; i < ac.size(); ++i) orderedInserts.push_back(Utils::indexOf(*children_, ac[i])); Utils::sort(orderedInserts); int addedCount = transientImpl_->addedChildren_.size(); int totalCount = children_->size(); int insertCount = 0; for (unsigned i = 0; i < orderedInserts.size(); ++i) { int pos = orderedInserts[i]; DomElement *c = (*children_)[pos]->createSDomElement(app); if (pos + (addedCount - insertCount) == totalCount) parent.addChild(c); else parent.insertChildAt(c, pos + firstChildIndex()); ++insertCount; } transientImpl_->addedChildren_.clear(); } } #ifndef WT_NO_LAYOUT if (flags_.test(BIT_LAYOUT_NEEDS_UPDATE)) { if (layout_) layoutImpl()->updateDom(parent); flags_.reset(BIT_LAYOUT_NEEDS_UPDATE); } #endif // WT_NO_LAYOUT }
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); }
void WBootstrapTheme::apply(WWidget *widget, DomElement& element, int elementRole) const { bool creating = element.mode() == DomElement::Mode::Create; if (!widget->isThemeStyleEnabled()) return; { WPopupWidget *popup = dynamic_cast<WPopupWidget *>(widget); if (popup) { WDialog *dialog = dynamic_cast<WDialog *>(widget); if (!dialog) element.addPropertyWord(Property::Class, "dropdown-menu"); } } switch (element.type()) { case DomElementType::A: { if (creating && dynamic_cast<WPushButton *>(widget)) element.addPropertyWord(Property::Class, classBtn(widget)); WPushButton *btn = dynamic_cast<WPushButton *>(widget); if (creating && btn && btn->isDefault()) element.addPropertyWord(Property::Class, "btn-primary"); if (element.getProperty(Property::Class).find("dropdown-toggle") != std::string::npos) { WMenuItem *item = dynamic_cast<WMenuItem *>(widget->parent()); if (!dynamic_cast<WPopupMenu *>(item->parentMenu())) { DomElement *b = DomElement::createNew(DomElementType::B); b->setProperty(Property::Class, "caret"); element.addChild(b); } } break; } case DomElementType::BUTTON: { if (creating && !widget->hasStyleClass("list-group-item")) element.addPropertyWord(Property::Class, classBtn(widget)); WPushButton *button = dynamic_cast<WPushButton *>(widget); if (button) { if (creating && button->isDefault()) element.addPropertyWord(Property::Class, "btn-primary"); if (button->menu() && element.properties().find(Property::InnerHTML) != element.properties().end()) { element.addPropertyWord(Property::InnerHTML, "<span class=\"caret\"></span>"); } if (creating && !button->text().empty()) element.addPropertyWord(Property::Class, "with-label"); if (!button->link().isNull()) LOG_ERROR("Cannot use WPushButton::setLink() after the button has " "been rendered with WBootstrapTheme"); } break; } case DomElementType::DIV: { WDialog *dialog = dynamic_cast<WDialog *>(widget); if (dialog) { if (version_ == BootstrapVersion::v2) element.addPropertyWord(Property::Class, "modal"); else element.addPropertyWord(Property::Class, "modal-dialog Wt-dialog"); return; } WPanel *panel = dynamic_cast<WPanel *>(widget); if (panel) { element.addPropertyWord(Property::Class, classAccordionGroup()); return; } WProgressBar *bar = dynamic_cast<WProgressBar *>(widget); if (bar) { switch (elementRole) { case MainElement: element.addPropertyWord(Property::Class, "progress"); break; case ProgressBarBar: element.addPropertyWord(Property::Class, classBar()); break; case ProgressBarLabel: element.addPropertyWord(Property::Class, "bar-label"); } return; } WGoogleMap *map = dynamic_cast<WGoogleMap *>(widget); if (map) { element.addPropertyWord(Property::Class, "Wt-googlemap"); return; } WAbstractItemView *itemView = dynamic_cast<WAbstractItemView *>(widget); if (itemView) { element.addPropertyWord(Property::Class, "form-inline"); return; } WNavigationBar *navBar = dynamic_cast<WNavigationBar *>(widget); if (navBar) { element.addPropertyWord(Property::Class, classNavbar()); return; } } break; case DomElementType::LABEL: { if (elementRole == 1) { if (version_ == BootstrapVersion::v3) { WCheckBox *cb = dynamic_cast<WCheckBox *>(widget); WRadioButton *rb = nullptr; if (cb) { element.addPropertyWord(Property::Class, widget->isInline() ? "checkbox-inline" : "checkbox"); } else { rb = dynamic_cast<WRadioButton *>(widget); if (rb) element.addPropertyWord(Property::Class, widget->isInline() ? "radio-inline" : "radio"); } if ((cb || rb) && !widget->isInline()) element.setType(DomElementType::DIV); } else { WCheckBox *cb = dynamic_cast<WCheckBox *>(widget); WRadioButton *rb = nullptr; if (cb) { element.addPropertyWord(Property::Class, "checkbox"); } else { rb = dynamic_cast<WRadioButton *>(widget); if (rb) element.addPropertyWord(Property::Class, "radio"); } if ((cb || rb) && widget->isInline()) element.addPropertyWord(Property::Class, "inline"); } } } break; case DomElementType::LI: { WMenuItem *item = dynamic_cast<WMenuItem *>(widget); if (item) { if (item->isSeparator()) element.addPropertyWord(Property::Class, "divider"); if (item->isSectionHeader()) element.addPropertyWord(Property::Class, "nav-header"); if (item->menu()) { if (dynamic_cast<WPopupMenu *>(item->parentMenu())) element.addPropertyWord(Property::Class, "dropdown-submenu"); else element.addPropertyWord(Property::Class, "dropdown"); } } } break; case DomElementType::INPUT: { if (version_ == BootstrapVersion::v3 && formControlStyle_) { WAbstractToggleButton *tb = dynamic_cast<WAbstractToggleButton *>(widget); if (!tb) element.addPropertyWord(Property::Class, "form-control"); } WAbstractSpinBox *spinBox = dynamic_cast<WAbstractSpinBox *>(widget); if (spinBox) { element.addPropertyWord(Property::Class, "Wt-spinbox"); return; } WDateEdit *dateEdit = dynamic_cast<WDateEdit *>(widget); if (dateEdit) { element.addPropertyWord(Property::Class, "Wt-dateedit"); return; } WTimeEdit *timeEdit = dynamic_cast<WTimeEdit *>(widget); if (timeEdit) { element.addPropertyWord(Property::Class, "Wt-timeedit"); return; } } break; case DomElementType::TEXTAREA: case DomElementType::SELECT: if (version_ == BootstrapVersion::v3 && formControlStyle_) element.addPropertyWord(Property::Class, "form-control"); break; case DomElementType::UL: { WPopupMenu *popupMenu = dynamic_cast<WPopupMenu *>(widget); if (popupMenu) { element.addPropertyWord(Property::Class, "dropdown-menu"); if (popupMenu->parentItem() && dynamic_cast<WPopupMenu *>(popupMenu->parentItem()->parentMenu())) element.addPropertyWord(Property::Class, "submenu"); } else { WMenu *menu = dynamic_cast<WMenu *>(widget); if (menu) { element.addPropertyWord(Property::Class, "nav"); WTabWidget *tabs = dynamic_cast<WTabWidget *>(menu->parent()->parent()); if (tabs) element.addPropertyWord(Property::Class, "nav-tabs"); } else { WSuggestionPopup *suggestions = dynamic_cast<WSuggestionPopup *>(widget); if (suggestions) element.addPropertyWord(Property::Class, "typeahead"); } } } case DomElementType::SPAN: { WInPlaceEdit *inPlaceEdit = dynamic_cast<WInPlaceEdit *>(widget); if (inPlaceEdit) element.addPropertyWord(Property::Class, "Wt-in-place-edit"); else { WDatePicker *picker = dynamic_cast<WDatePicker *>(widget); if (picker) element.addPropertyWord(Property::Class, "Wt-datepicker"); } } break; default: break; } }
void WCssTheme::apply(WWidget *widget, DomElement& element, int elementRole) const { bool creating = element.mode() == DomElement::ModeCreate; { WPopupWidget *popup = dynamic_cast<WPopupWidget *>(widget); if (popup) element.addPropertyWord(PropertyClass, "Wt-outset"); } switch (element.type()) { case DomElement_BUTTON: if (creating) element.addPropertyWord(PropertyClass, "Wt-btn"); break; case DomElement_UL: if (dynamic_cast<WPopupMenu *>(widget)) element.addPropertyWord(PropertyClass, "Wt-popupmenu Wt-outset"); else { WTabWidget *tabs = dynamic_cast<WTabWidget *>(widget->parent()->parent()); if (tabs) element.addPropertyWord(PropertyClass, "Wt-tabs"); else { WSuggestionPopup *suggestions = dynamic_cast<WSuggestionPopup *>(widget); if (suggestions) element.addPropertyWord(PropertyClass, "Wt-suggest"); } } break; case DomElement_LI: { WMenuItem *item = dynamic_cast<WMenuItem *>(widget); if (item) { if (item->isSeparator()) element.addPropertyWord(PropertyClass, "Wt-separator"); if (item->isSectionHeader()) element.addPropertyWord(PropertyClass, "Wt-sectheader"); if (item->menu()) element.addPropertyWord(PropertyClass, "submenu"); } } break; case DomElement_DIV: { WDialog *dialog = dynamic_cast<WDialog *>(widget); if (dialog) { element.addPropertyWord(PropertyClass, "Wt-dialog"); return; } WPanel *panel = dynamic_cast<WPanel *>(widget); if (panel) { element.addPropertyWord(PropertyClass, "Wt-panel Wt-outset"); return; } WProgressBar *bar = dynamic_cast<WProgressBar *>(widget); if (bar) { switch (elementRole) { case MainElementThemeRole: element.addPropertyWord(PropertyClass, "Wt-progressbar"); break; case ProgressBarBarRole: element.addPropertyWord(PropertyClass, "Wt-pgb-bar"); break; case ProgressBarLabelRole: element.addPropertyWord(PropertyClass, "Wt-pgb-label"); } return; } } break; case DomElement_INPUT: { WAbstractSpinBox *spinBox = dynamic_cast<WAbstractSpinBox *>(widget); if (spinBox) { element.addPropertyWord(PropertyClass, "Wt-spinbox"); return; } WDateEdit *dateEdit = dynamic_cast<WDateEdit *>(widget); if (dateEdit) { element.addPropertyWord(PropertyClass, "Wt-dateedit"); return; } } break; default: break; } }
void WBootstrapTheme::apply(WWidget *widget, DomElement& element, int elementRole) const { bool creating = element.mode() == DomElement::ModeCreate; { WPopupWidget *popup = dynamic_cast<WPopupWidget *>(widget); if (popup) { WDialog *dialog = dynamic_cast<WDialog *>(widget); if (!dialog) element.addPropertyWord(PropertyClass, "dropdown-menu"); } } switch (element.type()) { case DomElement_A: if (creating && dynamic_cast<WPushButton *>(widget)) element.addPropertyWord(PropertyClass, "btn"); if (element.getProperty(PropertyClass).find("dropdown-toggle") != std::string::npos) { WMenuItem *item = dynamic_cast<WMenuItem *>(widget->parent()); if (!dynamic_cast<WPopupMenu *>(item->parentMenu())) { DomElement *b = DomElement::createNew(DomElement_B); b->setProperty(PropertyClass, "caret"); element.addChild(b); } } break; case DomElement_BUTTON: { if (creating) element.addPropertyWord(PropertyClass, "btn"); WPushButton *button = dynamic_cast<WPushButton *>(widget); if (button) { if (creating && button->isDefault()) element.addPropertyWord(PropertyClass, "btn-primary"); if (button->menu() && element.properties().find(PropertyInnerHTML) != element.properties().end()) { element.addPropertyWord(PropertyInnerHTML, "<span class=\"caret\"></span>"); } } break; } case DomElement_DIV: { WDialog *dialog = dynamic_cast<WDialog *>(widget); if (dialog) { element.addPropertyWord(PropertyClass, "modal"); return; } WPanel *panel = dynamic_cast<WPanel *>(widget); if (panel) { element.addPropertyWord(PropertyClass, "accordion-group"); return; } WProgressBar *bar = dynamic_cast<WProgressBar *>(widget); if (bar) { switch (elementRole) { case MainElementThemeRole: element.addPropertyWord(PropertyClass, "progress"); break; case ProgressBarBarRole: element.addPropertyWord(PropertyClass, "bar"); break; case ProgressBarLabelRole: element.addPropertyWord(PropertyClass, "bar-label"); } return; } WGoogleMap *map = dynamic_cast<WGoogleMap *>(widget); if (map) { element.addPropertyWord(PropertyClass, "Wt-googlemap"); return; } WAbstractItemView *itemView = dynamic_cast<WAbstractItemView *>(widget); if (itemView) { element.addPropertyWord(PropertyClass, "form-horizontal"); return; } } break; case DomElement_LABEL: { WCheckBox *cb = dynamic_cast<WCheckBox *>(widget); if (cb) { element.addPropertyWord(PropertyClass, "checkbox"); if (cb->isInline()) element.addPropertyWord(PropertyClass, "inline"); } else { WRadioButton *rb = dynamic_cast<WRadioButton *>(widget); if (rb) { element.addPropertyWord(PropertyClass, "radio"); if (rb->isInline()) element.addPropertyWord(PropertyClass, "inline"); } } } break; case DomElement_LI: { WMenuItem *item = dynamic_cast<WMenuItem *>(widget); if (item) { if (item->isSeparator()) element.addPropertyWord(PropertyClass, "divider"); if (item->isSectionHeader()) element.addPropertyWord(PropertyClass, "nav-header"); if (item->menu()) { if (dynamic_cast<WPopupMenu *>(item->parentMenu())) element.addPropertyWord(PropertyClass, "dropdown-submenu"); else element.addPropertyWord(PropertyClass, "dropdown"); } } } break; case DomElement_INPUT: { WAbstractSpinBox *spinBox = dynamic_cast<WAbstractSpinBox *>(widget); if (spinBox) { element.addPropertyWord(PropertyClass, "Wt-spinbox"); return; } WDateEdit *dateEdit = dynamic_cast<WDateEdit *>(widget); if (dateEdit) { element.addPropertyWord(PropertyClass, "Wt-dateedit"); return; } } break; case DomElement_UL: { WPopupMenu *popupMenu = dynamic_cast<WPopupMenu *>(widget); if (popupMenu) { element.addPropertyWord(PropertyClass, "dropdown-menu"); if (popupMenu->parentItem() && dynamic_cast<WPopupMenu *>(popupMenu->parentItem()->parentMenu())) element.addPropertyWord(PropertyClass, "submenu"); } else { WMenu *menu = dynamic_cast<WMenu *>(widget); if (menu) { element.addPropertyWord(PropertyClass, "nav"); WTabWidget *tabs = dynamic_cast<WTabWidget *>(menu->parent()->parent()); if (tabs) element.addPropertyWord(PropertyClass, "nav-tabs"); } else { WSuggestionPopup *suggestions = dynamic_cast<WSuggestionPopup *>(widget); if (suggestions) element.addPropertyWord(PropertyClass, "typeahead"); } } } case DomElement_SPAN: { WInPlaceEdit *inPlaceEdit = dynamic_cast<WInPlaceEdit *>(widget); if (inPlaceEdit) element.addPropertyWord(PropertyClass, "Wt-in-place-edit"); } break; default: break; } }