SignalBase& WSubMenuItem::activateSignal() { if (subMenu_) { WContainerWidget *contents = dynamic_cast<WContainerWidget *>(itemWidget()); WInteractWidget *wi = dynamic_cast<WInteractWidget *> (contents->widget(0)->webWidget()); return wi->clicked(); } else return WMenuItem::activateSignal(); }
void AuthWidget::updatePasswordLoginView() { if (model_->passwordAuth()) { setCondition("if:passwords", true); updateView(model_); WInteractWidget *login = resolve<WInteractWidget *>("login"); if (!login) { login = new WPushButton(tr("Wt.Auth.login")); login->clicked().connect(this, &AuthWidget::attemptPasswordLogin); bindWidget("login", login); model_->configureThrottling(login); if (model_->baseAuth()->emailVerificationEnabled()) { WText *text = new WText(tr("Wt.Auth.lost-password")); text->clicked().connect(this, &AuthWidget::handleLostPassword); bindWidget("lost-password", text); } else bindEmpty("lost-password"); if (registrationEnabled_) { WInteractWidget *w; if (!basePath_.empty()) { w = new WAnchor (WLink(WLink::InternalPath, basePath_ + "register"), tr("Wt.Auth.register")); } else { w = new WText(tr("Wt.Auth.register")); w->clicked().connect(this, &AuthWidget::registerNewUser); } bindWidget("register", w); } else bindEmpty("register"); if (model_->baseAuth()->emailVerificationEnabled() && registrationEnabled_) bindString("sep", " | "); else bindEmpty("sep"); } model_->updateThrottling(login); } else { bindEmpty("lost-password"); bindEmpty("sep"); bindEmpty("register"); bindEmpty("login"); } }
void PaintedSlider::updateSliderPosition() { double l = (slider_->orientation() == Horizontal) ? w() : h(); double pixelsPerUnit = (l - slider_->handleWidth()) / range(); double u = ((double)slider_->value() - slider_->minimum()) * pixelsPerUnit; if (slider_->orientation() == Horizontal) { handle_->setOffsets(u, Left); fill_->setWidth(u + slider_->handleWidth() / 2); } else { handle_->setOffsets(h() - slider_->handleWidth() - u, Top); fill_->setHeight(u + slider_->handleWidth() / 2); } }
void WNavigationBar::undoExpandContents() { WContainerWidget *contents = resolve<WContainerWidget *>("contents"); WInteractWidget *collapseButton = resolve<WInteractWidget *>("collapse-button"); WInteractWidget *expandButton = resolve<WInteractWidget *>("expand-button"); collapseButton->hide(); expandButton->show(); if (!animatedResponsive()) contents->hide(); else contents->show(); /* We are collapsed only in appearance */ }
void WNavigationBar::expandContents() { WContainerWidget *contents = resolve<WContainerWidget *>("contents"); WInteractWidget *collapseButton = resolve<WInteractWidget *>("collapse-button"); WInteractWidget *expandButton = resolve<WInteractWidget *>("expand-button"); collapseButton->show(); expandButton->hide(); if (!animatedResponsive()) contents->show(); else { if (canOptimizeUpdates()) contents->show(); else contents->animateShow(WAnimation(WAnimation::SlideInFromTop, WAnimation::Ease)); } }
void WNavigationBar::setResponsive(bool responsive) { NavContainer *contents = resolve<NavContainer *>("contents"); if (responsive) { WInteractWidget *collapseButton = resolve<WInteractWidget *>("collapse-button"); WInteractWidget *expandButton = resolve<WInteractWidget *>("expand-button"); if (!collapseButton) { bindWidget("collapse-button", collapseButton = createCollapseButton()); collapseButton->clicked().connect(this, &WNavigationBar::collapseContents); collapseButton->hide(); bindWidget("expand-button", expandButton = createExpandButton()); expandButton->clicked().connect(this, &WNavigationBar::expandContents); } wApp->theme()->apply(this, contents, NavCollapseRole); contents->hide(); if (contents->isBootstrap2Responsive()) { /* Comply with bootstrap responsive CSS assumptions */ contents->setJavaScriptMember ("wtAnimatedHidden", "function(hidden) {" """if (hidden) " "" "this.style.height=''; this.style.display='';" "}"); } } else { bindEmpty("collapse-button"); } }
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); }
WWidget *WItemDelegate::update(WWidget *widget, const WModelIndex& index, WFlags<ViewItemRenderFlag> flags) { bool editing = widget && widget->find("t") == 0; if (flags & RenderEditing) { if (!editing) { widget = createEditor(index, flags); WInteractWidget *iw = dynamic_cast<WInteractWidget *>(widget); if (iw) { // Disable drag & drop and selection behaviour iw->mouseWentDown().preventPropagation(); iw->clicked().preventPropagation(); } } } else { if (editing) widget = 0; } WidgetRef widgetRef(widget); bool isNew = false; if (!(flags & RenderEditing)) { if (!widgetRef.w) { isNew = true; IndexText *t = new IndexText(index); t->setObjectName("t"); if (index.isValid() && !(index.flags() & ItemIsXHTMLText)) t->setTextFormat(PlainText); t->setWordWrap(true); widgetRef.w = t; } if (!index.isValid()) return widgetRef.w; bool haveCheckBox = false; boost::any checkedData = index.data(CheckStateRole); if (!checkedData.empty()) { haveCheckBox = true; CheckState state = (checkedData.type() == typeid(bool) ? (boost::any_cast<bool>(checkedData) ? Checked : Unchecked) : (checkedData.type() == typeid(CheckState) ? boost::any_cast<CheckState>(checkedData) : Unchecked)); IndexCheckBox *icb = checkBox(widgetRef, index, true, index.flags() & ItemIsTristate); icb->setCheckState(state); icb->setEnabled(index.flags() & ItemIsUserCheckable); } else if (!isNew) delete checkBox(widgetRef, index, false); boost::any linkData = index.data(LinkRole); if (!linkData.empty()) { WLink link = boost::any_cast<WLink>(linkData); IndexAnchor *a = anchorWidget(widgetRef, index); a->setLink(link); if (link.type() == WLink::Resource) a->setTarget(TargetNewWindow); } IndexText *t = textWidget(widgetRef, index); WString label = asString(index.data(), textFormat_); if (label.empty() && haveCheckBox) label = WString::fromUTF8(" "); t->setText(label); std::string iconUrl = asString(index.data(DecorationRole)).toUTF8(); if (!iconUrl.empty()) { iconWidget(widgetRef, index, true)->setImageLink(WLink(iconUrl)); } else if (!isNew) delete iconWidget(widgetRef, index, false); } if (index.flags() & ItemHasDeferredTooltip){ widgetRef.w->setDeferredToolTip(true, (index.flags() & ItemIsXHTMLText) ? XHTMLText : PlainText); } else { WString tooltip = asString(index.data(ToolTipRole)); if (!tooltip.empty() || !isNew) widgetRef.w->setToolTip(tooltip, (index.flags() & ItemIsXHTMLText) ? XHTMLText : PlainText); } WT_USTRING sc = asString(index.data(StyleClassRole)); if (flags & RenderSelected) sc += WT_USTRING::fromUTF8 (" " + WApplication::instance()->theme()->activeClass()); if (flags & RenderEditing) sc += WT_USTRING::fromUTF8(" Wt-delegate-edit"); widgetRef.w->setStyleClass(sc); if (index.flags() & ItemIsDropEnabled) widgetRef.w->setAttributeValue("drop", WString::fromUTF8("true")); else if (!widgetRef.w->attributeValue("drop").empty()) widgetRef.w->setAttributeValue("drop", WString::fromUTF8("f")); return widgetRef.w; }
void PaintedSlider::updateState() { bool rtl = WApplication::instance()->layoutDirection() == RightToLeft; Orientation o = slider_->orientation(); if (o == Horizontal) { handle_->resize(slider_->handleWidth(), h()); handle_->setOffsets(0, Top); } else { handle_->resize(w(), slider_->handleWidth()); handle_->setOffsets(0, Left); } double l = o == Horizontal ? w() : h(); double pixelsPerUnit = (l - slider_->handleWidth()) / range(); std::string dir; std::string size; if (o == Horizontal) { dir = rtl ? "right" : "left"; size = "width"; } else { dir = "top"; size = "height"; } char u = (o == Horizontal ? 'x' : 'y'); double max = l - slider_->handleWidth(); bool horizontal = o == Horizontal; /* * Note: cancelling the mouseDown event prevents the selection behaviour */ WStringStream mouseDownJS; mouseDownJS << "obj.setAttribute('down', " WT_CLASS << ".widgetCoordinates(obj, event)." << u << ");" << WT_CLASS ".cancelEvent(event);"; WStringStream computeD; // = 'u' position relative to background, corrected for slider computeD << "var objh = " << handle_->jsRef() << "," << "objf = " << fill_->jsRef() << "," << "objb = " << jsRef() << "," << "page_u = WT.pageCoordinates(event)." << u << "," << "widget_page_u = WT.widgetPageCoordinates(objb)." << u << "," << "pos = page_u - widget_page_u," << "rtl = " << rtl << "," << "horizontal = " << horizontal << ";" << "if (rtl && horizontal)" << "pos = " << l << " - pos;" << "var d = pos - down;"; WStringStream mouseMovedJS; mouseMovedJS << "var down = obj.getAttribute('down');" << "var WT = " WT_CLASS ";" << "if (down != null && down != '') {" << computeD.str() << "d = Math.max(0, Math.min(d, " << max << "));" << "var v = Math.round(d/" << pixelsPerUnit << ");" << "var intd = v*" << pixelsPerUnit << ";" << "if (Math.abs(WT.pxself(objh, '" << dir << "') - intd) > 1) {" << "objf.style." << size << " = "; if (o == Vertical) mouseMovedJS << '(' << max << " - intd + " << (slider_->handleWidth() / 2) << ")"; else mouseMovedJS << "intd + " << (slider_->handleWidth() / 2); mouseMovedJS << " + 'px';" << "objh.style." << dir << " = intd + 'px';" << "var vs = "; if (o == Horizontal) mouseMovedJS << "v + " << slider_->minimum(); else mouseMovedJS << slider_->maximum() << " - v"; mouseMovedJS << ";" << "var f = objb.parentNode.onValueChange;" << "if (f) f(vs);"; if (slider_->sliderMoved().needsUpdate(true)) mouseMovedJS << slider_->sliderMoved().createCall("vs"); mouseMovedJS << "}" << "}"; WStringStream mouseUpJS; mouseUpJS << "var down = obj.getAttribute('down');" << "var WT = " WT_CLASS ";" << "if (down != null && down != '') {" << computeD.str() << "d += " << (slider_->handleWidth() / 2) << ";" << sliderReleased_.createCall("d") << "obj.removeAttribute('down');" << "}"; bool enabled = !slider_->isDisabled(); mouseDownJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseDownJS.str() : "") + "}"); mouseMovedJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseMovedJS.str() : "") + "}"); mouseUpJS_.setJavaScript(std::string("function(obj, event) {") + (enabled ? mouseUpJS.str() : "") + "}"); update(); updateSliderPosition(); }
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); }