std::vector<WLinkedCssStyleSheet> WBootstrapTheme::styleSheets() const { std::vector<WLinkedCssStyleSheet> result; std::string themeDir = resourcesUrl(); std::stringstream themeVersionDir; themeVersionDir << themeDir << static_cast<unsigned int>(version_) << "/"; result.push_back(WLinkedCssStyleSheet (WLink(themeVersionDir.str() + "bootstrap.css"))); WApplication *app = WApplication::instance(); if (responsive_) { if (version_ == BootstrapVersion::v2) result.push_back(WLinkedCssStyleSheet (WLink(themeVersionDir.str() + "bootstrap-responsive.css"))); else if (app) { WString v = app->metaHeader(MetaHeaderType::Meta, "viewport"); if (v.empty()) app->addMetaHeader("viewport", "width=device-width, initial-scale=1"); } } result.push_back(WLinkedCssStyleSheet (WLink(themeVersionDir.str() + "wt.css"))); return result; }
std::vector<WCssStyleSheet> WBootstrapTheme::styleSheets() const { std::vector<WCssStyleSheet> result; std::string themeDir = resourcesUrl(); result.push_back(WCssStyleSheet(WLink(themeDir + "bootstrap.css"))); result.push_back(WCssStyleSheet(WLink(themeDir + "bootstrap-responsive.css"))); result.push_back(WCssStyleSheet(WLink(themeDir + "wt.css"))); return result; }
WImage::WImage(const std::string& imageRef, WContainerWidget *parent) : WInteractWidget(parent), imageLink_(WLink(WLink::Url, imageRef)), map_(0) { setLoadLaterWhenInvisible(false); }
mapboxApplication::mapboxApplication(const WEnvironment & env) : WApplication(env) { if (appRoot().empty()) { std::cerr << "!!!!!!!!!!" << std::endl << "!! Warning: read the README.md file for hints on deployment," << " the approot looks suspect!" << std::endl << "!!!!!!!!!!" << std::endl; } setTheme(new WBootstrapTheme()); this->useStyleSheet(WLink("wtMapExample.css")); setTitle("Mapbox Examples"); WContainerWidget * mainContent = new WContainerWidget(root()); mainContent->setStyleClass("examplemap"); map = new MapBox::Map(mainContent, true); map->setMapStyle(MapBox::MAPSTYLE::Streets); map->zoom(14).center(MapBox::Coordinate(51.515823, -0.124331)); // add all controls // map->addNavigationControl(); // map->addGeoLocateControl(); // map->addGeoCoderControl(); menuBar = new MenuBar(root()); }
WLink WMenuItem::link() const { WAnchor *a = anchor(); if (a) return a->link(); else return WLink(); }
WLink WMediaPlayer::getSource(Encoding encoding) const { for (unsigned i = 0; i < media_.size(); ++i) { if (media_[i].encoding == encoding) return media_[i].link; } return WLink(""); }
WImage::WImage(WResource *resource, const WString& altText, WContainerWidget *parent) : WInteractWidget(parent), altText_(altText), map_(0) { setLoadLaterWhenInvisible(false); setImageLink(WLink(resource)); }
void WMenuItem::updateInternalPath() { if (menu_ && menu_->internalPathEnabled() && internalPathEnabled()) { std::string internalPath = menu_->internalBasePath() + pathComponent(); WLink link(WLink::InternalPath, internalPath); WAnchor *a = anchor(); if (a) a->setLink(link); } else { WAnchor *a = anchor(); if (a && !customLink_) { if (WApplication::instance()->environment().agent() == WEnvironment::IE6) a->setLink(WLink("#")); else a->setLink(WLink()); } } }
void WMessageBox::setIcon(Icon icon) { icon_ = icon; /* * Ignore icons for now... Icons are so desktop ? */ if (false && icon_ != NoIcon) { if (!iconImage_) { iconImage_ = new WImage(WLink(iconURI[icon_ - 1])); contents()->insertBefore(iconImage_, text_); } else iconImage_->setImageLink(WLink(iconURI[icon_ - 1])); } else { delete iconImage_; iconImage_ = 0; } }
CornerImage::CornerImage(Corner c, WColor fg, WColor bg, int radius) : WImage(), corner_(c), fg_(fg), bg_(bg), radius_(radius) { resource_ = std::make_shared<CornerResource>(this); setImageLink(WLink(resource_)); }
std::vector<WCssStyleSheet> WCssTheme::styleSheets() const { std::vector<WCssStyleSheet> result; if (!name_.empty()) { std::string themeDir = resourcesUrl(); WApplication *app = WApplication::instance(); result.push_back(WCssStyleSheet(WLink(themeDir + "wt.css"))); if (app->environment().agentIsIE()) result.push_back(WCssStyleSheet(WLink(themeDir + "wt_ie.css"))); if (app->environment().agent() == WEnvironment::IE6) result.push_back(WCssStyleSheet(WLink(themeDir + "wt_ie6.css"))); } return result; }
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 WMenuItem::setIcon(const std::string& path) { if (!icon_) { WAnchor *a = anchor(); if (!a) return; icon_ = new WText(" "); a->insertWidget(0, icon_); WApplication *app = WApplication::instance(); app->theme()->apply(this, icon_, MenuItemIconRole); } icon_->decorationStyle().setBackgroundImage(WLink(path)); }
void WMenuItem::connectSignals() { if (!signalsConnected_) { signalsConnected_ = true; if (!contents_ || contentsLoaded()) implementStateless(&WMenuItem::selectVisual, &WMenuItem::undoSelectVisual); WAnchor *a = anchor(); if (a) { SignalBase *as; bool selectFromCheckbox = false; if (checkBox_ && !checkBox_->clicked().propagationPrevented()) { as = &checkBox_->changed(); /* * Because the checkbox is not a properly exposed form object, * we need to relay its value ourselves */ checkBox_->checked().connect(this, &WMenuItem::setCheckBox); checkBox_->unChecked().connect(this, &WMenuItem::setUnCheckBox); selectFromCheckbox = true; } else as = &a->clicked(); if (checkBox_) a->setLink(WLink()); if (contentsContainer_ && contentsContainer_->count() == 0) as->connect(this, &WMenuItem::selectNotLoaded); else { as->connect(this, &WMenuItem::selectVisual); if (!selectFromCheckbox) as->connect(this, &WMenuItem::select); } } } }
HomeUI::HomeUI(WContainerWidget *parent) : WContainerWidget(parent), importUI(0) { setContentAlignment(AlignCenter); session_.login().changed().connect(this, &HomeUI::onAuthEvent); Auth::AuthModel *authModel = new Auth::AuthModel(Session::auth(), session_.users(), this); authModel->addPasswordAuth(&Session::passwordAuth()); authModel->addOAuth(Session::oAuth()); Auth::AuthWidget *authWidget = new Auth::AuthWidget(session_.login()); authWidget->setModel(authModel); authWidget->setRegistrationEnabled(false); WText *title = new WText(WString::fromUTF8("<h1>数据管理平台</h1>")); addWidget(title); addWidget(authWidget); mainStack_ = new WStackedWidget(); mainStack_->setStyleClass("mainstack"); addWidget(mainStack_); links_ = new WContainerWidget(); links_->setStyleClass("links"); links_->hide(); addWidget(links_); importUIAnchor_ = new WAnchor("/dataimport", "Data Import", links_); importUIAnchor_->setLink(WLink(WLink::InternalPath, "/dataimport")); WApplication::instance()->internalPathChanged().connect(this, &HomeUI::handleInternalPath); authWidget->processEnvironment(); }
void WMediaPlayer::addAnchor(WTemplate *t, ButtonControlId id, const char *bindId, const std::string& styleClass, const std::string& altText) { std::string text; if (altText.empty()) text = styleClass.substr(3).c_str(); else text = altText; text = "Wt.WMediaPlayer." + text; WAnchor *anchor = new WAnchor(WLink("javascript:;"), WString::tr(text)); anchor->setStyleClass(styleClass); anchor->setAttributeValue("tabindex", "1"); anchor->setToolTip(WString::tr(text)); anchor->setInline(false); t->bindWidget(bindId, anchor); setButton(id, anchor); }
void WAnchor::setResource(WResource *resource) { setLink(WLink(resource)); }
void WAnchor::setRefInternalPath(const std::string& path) { setLink(WLink(WLink::InternalPath, path)); }
void WAnchor::setRef(const std::string& url) { setLink(WLink(WLink::Url, url)); }
void WImage::setResource(WResource *resource) { setImageLink(WLink(resource)); }
void WPushButton::setResource(WResource *resource) { setLink(WLink(resource)); }
void WPushButton::setRef(const std::string& url) { setLink(WLink(url)); }
void WImage::setImageRef(const std::string& ref) { setImageLink(WLink(ref)); }
void WCssTheme::apply(WWidget *widget, WWidget *child, int widgetRole) const { switch (widgetRole) { case MenuItemIconRole: child->addStyleClass("Wt-icon"); break; case MenuItemCheckBoxRole: child->addStyleClass("Wt-chkbox"); break; case MenuItemCloseRole: widget->addStyleClass("Wt-closable"); child->addStyleClass("closeicon"); break; case DialogCoverRole: child->setStyleClass("Wt-dialogcover"); break; case DialogTitleBarRole: child->addStyleClass("titlebar"); break; case DialogBodyRole: child->addStyleClass("body"); break; case DialogFooterRole: child->addStyleClass("footer"); break; case DialogCloseIconRole: child->addStyleClass("closeicon"); break; case TableViewRowContainerRole: { WAbstractItemView *view = dynamic_cast<WAbstractItemView *>(widget); std::string backgroundImage; if (view->alternatingRowColors()) backgroundImage = "stripes/stripe-"; else backgroundImage = "no-stripes/no-stripe-"; backgroundImage = resourcesUrl() + backgroundImage + boost::lexical_cast<std::string> (static_cast<int>(view->rowHeight().toPixels())) + "px.gif"; child->decorationStyle().setBackgroundImage(WLink(backgroundImage)); break; } case DatePickerPopupRole: child->addStyleClass("Wt-datepicker"); break; case PanelTitleBarRole: child->addStyleClass("titlebar"); break; case PanelBodyRole: child->addStyleClass("body"); break; case AuthWidgets: WApplication *app = WApplication::instance(); app->useStyleSheet(WApplication::relativeResourcesUrl() + "form.css"); app->builtinLocalizedStrings().useBuiltin(skeletons::AuthCssTheme_xml1); break; } }
void Home::createHome() { WTemplate *result = new WTemplate(tr("template"), root()); homePage_ = result; WContainerWidget *languagesDiv = new WContainerWidget(); languagesDiv->setId("top_languages"); for (unsigned i = 0; i < languages.size(); ++i) { if (i != 0) new WText("- ", languagesDiv); const Lang& l = languages[i]; new WAnchor(WLink(WLink::InternalPath, l.path_), WString::fromUTF8(l.longDescription_), languagesDiv); } WStackedWidget *contents = new WStackedWidget(); WAnimation fade(WAnimation::Fade, WAnimation::Linear, 250); contents->setTransitionAnimation(fade); contents->setId("main_page"); mainMenu_ = new WMenu(contents, Vertical); mainMenu_->addItem (tr("introduction"), introduction())->setPathComponent(""); mainMenu_->addItem (tr("blog"), deferCreate(boost::bind(&Home::blog, this))); mainMenu_->addItem (tr("features"), wrapView(&Home::features), WMenuItem::PreLoading); mainMenu_->addItem (tr("documentation"), wrapView(&Home::documentation), WMenuItem::PreLoading); mainMenu_->addItem (tr("examples"), examples(), WMenuItem::PreLoading)->setPathComponent("examples/"); mainMenu_->addItem (tr("download"), deferCreate(boost::bind(&Home::download, this)), WMenuItem::PreLoading); mainMenu_->addItem (tr("community"), wrapView(&Home::community), WMenuItem::PreLoading); mainMenu_->addItem (tr("other-language"), wrapView(&Home::otherLanguage), WMenuItem::PreLoading); mainMenu_->itemSelectRendered().connect(this, &Home::updateTitle); mainMenu_->itemSelected().connect(this, &Home::googleAnalyticsLogger); // Make the menu be internal-path aware. mainMenu_->setInternalPathEnabled("/"); sideBarContent_ = new WContainerWidget(); result->bindWidget("languages", languagesDiv); result->bindWidget("menu", mainMenu_); result->bindWidget("contents", contents); result->bindWidget("sidebar", sideBarContent_); }
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; }