void WSuggestionPopup::modelDataChanged(const WModelIndex& topLeft, const WModelIndex& bottomRight) { if (topLeft.parent().isValid()) return; if (modelColumn_ < topLeft.column() || modelColumn_ > bottomRight.column()) return; for (int i = topLeft.row(); i <= bottomRight.row(); ++i) { WContainerWidget *w = dynamic_cast<WContainerWidget *>(impl_->widget(i)); WAnchor *anchor = dynamic_cast<WAnchor *>(w->widget(0)); WText *value = dynamic_cast<WText *>(anchor->widget(0)); WModelIndex index = model_->index(i, modelColumn_); boost::any d = index.data(); value->setText(asString(d)); TextFormat format = index.flags() & ItemIsXHTMLText ? XHTMLText : PlainText; value->setTextFormat(format); boost::any d2 = model_->data(i, modelColumn_, UserRole); if (d2.empty()) d2 = d; value->setAttributeValue("sug", asString(d2)); } }
ItemContaWidget::ItemContaWidget(Wt::WContainerWidget *parent, ContaWidget *view, int id_diario, std::string data, std::string descricao, Moeda debito, Moeda credito): WContainerWidget(parent), view_(view), id_diario_(id_diario), data_(data), descricao_(descricao), debito_(debito), credito_(credito){ setInline(true); WText *btnRemove = new WText("<button class='bg-color-red fg-color-white'>Remove</button>", Wt::XHTMLUnsafeText); btnRemove->clicked().connect(this, &ItemContaWidget::removeLancamento); WTemplate *t = new WTemplate(this); t->setTemplateText( "<tr>" "<td>${data}</td>" "<td>${descricao}</td>" "<td class='right'>${debito}</td>" "<td class='right'>${credito}</td>" "<td>${btnRemove}</td>" "</tr>", XHTMLUnsafeText); t->bindString("data", data_); t->bindString("descricao", WString(descricao_, UTF8)); t->bindString("debito", debito_.valStr()); t->bindString("credito", credito_.valStr()); t->bindWidget("btnRemove", btnRemove); t->setInline(true); }
void CAnswerTable::AddErrorText(WTable* childTable,const std::string strHelp, int nRow, int nCol) { WText* pText = new WText(strHelp, childTable->elementAt(nRow, nCol)); childTable->elementAt(nRow, nCol)->setStyleClass("errors"); m_pListErrorText.push_back(pText); pText->hide(); }
void showArchive(WContainerWidget *parent) { static const char* dateFormat = "MMMM yyyy"; new WText(tr("archive-title"), parent); Posts posts = session_.find<Post>("order by date desc"); WDateTime formerDate; for (Posts::const_iterator i = posts.begin(); i != posts.end(); ++i) { if ((*i)->state != Post::Published) continue; if (formerDate.isNull() || yearMonthDiffer(formerDate, (*i)->date)) { WText *title = new WText((*i)->date.date().toString(dateFormat), parent); title->setStyleClass("archive-month-title"); } WAnchor *a = new WAnchor(WLink(WLink::InternalPath, basePath_ + (*i)->permaLink()), (*i)->title, parent); a->setInline(false); formerDate = (*i)->date; } }
FormExample::FormExample() : WContainerWidget() { WContainerWidget *langLayout = this->addWidget(cpp14::make_unique<WContainerWidget>()); langLayout->setContentAlignment(AlignmentFlag::Right); langLayout->addWidget(cpp14::make_unique<WText>(tr("language"))); const char *lang[] = { "en", "nl" }; for (int i = 0; i < 2; ++i) { WText *t = langLayout->addWidget(cpp14::make_unique<WText>(lang[i])); t->setMargin(5); t->clicked().connect(std::bind(&FormExample::changeLanguage, this, t)); languageSelects_.push_back(t); } /* * Start with the reported locale, if available */ setLanguage(wApp->locale().name()); Form *form = this->addWidget(cpp14::make_unique<Form>()); form->setMargin(20); }
void UpdatePasswordWidget::updateView(const std::string& var, RegistrationModel::Field field) { WFormWidget *edit = resolve<WFormWidget *>(var); WText *info = resolve<WText *>(var + "-info"); const WValidator::Result& v = model_->validationResult(field); info->setText(v.message()); switch (v.state()) { case WValidator::InvalidEmpty: case WValidator::Invalid: edit->removeStyleClass("Wt-valid"); if (validated_) edit->addStyleClass("Wt-invalid"); info->addStyleClass("Wt-error"); break; case WValidator::Valid: edit->removeStyleClass("Wt-invalid"); if (validated_) edit->addStyleClass("Wt-valid"); info->removeStyleClass("Wt-error"); } }
void WBootstrapTheme::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 DialogCoverRole: child->addStyleClass("modal-backdrop"); break; case DialogTitleBarRole: child->addStyleClass("modal-header"); break; case DialogBodyRole: child->addStyleClass("modal-body"); break; case DialogFooterRole: child->addStyleClass("modal-footer"); break; case DialogCloseIconRole: { child->addStyleClass("close"); WText *t = dynamic_cast<WText *>(child); t->setText("×"); break; } case TableViewRowContainerRole: { WAbstractItemView *view = dynamic_cast<WAbstractItemView *>(widget); child->toggleStyleClass("Wt-striped", view->alternatingRowColors()); break; } case DatePickerPopupRole: child->addStyleClass("Wt-datepicker"); break; case PanelTitleBarRole: child->addStyleClass("accordion-heading"); break; case PanelCollapseButtonRole: case PanelTitleRole: child->addStyleClass("accordion-toggle"); break; case PanelBodyRole: child->addStyleClass("accordion-inner"); break; case AuthWidgets: WApplication *app = WApplication::instance(); app->builtinLocalizedStrings().useBuiltin (skeletons::AuthBootstrapTheme_xml1); break; } }
void WSuggestionPopup::modelRowsInserted(const WModelIndex& parent, int start, int end) { if (filterLength_ != 0 && !filtering_) return; if (modelColumn_ >= model_->columnCount()) return; if (parent.isValid()) return; for (int i = start; i <= end; ++i) { WContainerWidget *line = new WContainerWidget(); content_->insertWidget(i, line); boost::any d = model_->data(i, modelColumn_); WText *value = new WText(asString(d), PlainText); boost::any d2 = model_->data(i, modelColumn_, UserRole); if (d2.empty()) d2 = d; line->addWidget(value); value->setAttributeValue("sug", asString(d2)); } }
/*! \brief Creates a title widget. */ WText *createTitle(const WString& title) { WText *result = new WText(title); result->setInline(false); result->setStyleClass("title"); return result; }
WWidget *StyleLayout::wGridLayout() { WContainerWidget *result = new WContainerWidget(); topic("WGridLayout", result); addText(tr("layout-WGridLayout"), result); WContainerWidget *container; container = new WContainerWidget(result); container->resize(WLength::Auto, 400); container->setStyleClass("yellow-box"); WGridLayout *grid = new WGridLayout(); container->setLayout(grid); for (int row = 0; row < 3; ++row) { for (int column = 0; column < 4; ++column) { WText *t = addText(tr("grid-item").arg(row).arg(column)); if (row == 1 || column == 1 || column == 2) t->setStyleClass("blue-box"); else t->setStyleClass("green-box"); grid->addWidget(t, row, column); } } grid->setRowStretch(1, 1); grid->setColumnStretch(1, 1); grid->setColumnStretch(2, 1); return result; }
WWidget *WtHome::example(const char *textKey, const std::string& sourceDir) { WContainerWidget *result = new WContainerWidget(); WText *w = new WText(tr(textKey), result); w->setInternalPathEncoding(true); result->addWidget(linkSourceBrowser(sourceDir)); return result; }
void WSVFlexTable::SetNullTipInfo(string strInfo) { if(pNullTipTable) { pNullTipTable->elementAt(0 , 0)->setContentAlignment(AlignTop | AlignCenter); WText * textInfo = new WText(strInfo, (WContainerWidget *)pNullTipTable->elementAt(0, 0)); textInfo->decorationStyle().setForegroundColor(Wt::red); } }
void loggedIn() { WApplication::instance()->changeSessionId(); refresh(); loginStatus_->resolveWidget("login")->show(); loginStatus_->resolveWidget("login-link")->hide(); loginStatus_->resolveWidget("register-link")->hide(); WText *profileLink = new WText(tr("profile")); profileLink->setStyleClass("link"); profileLink->clicked().connect(this, &BlogImpl::editProfile); dbo::ptr<User> user = session().user(); if (user->role == User::Admin) { WText *editUsersLink = new WText(tr("edit-users")); editUsersLink->setStyleClass("link"); editUsersLink->clicked().connect(SLOT(this, BlogImpl::editUsers)); loginStatus_->bindWidget("userlist-link", editUsersLink); WText *authorPanelLink = new WText(tr("author-post")); authorPanelLink->setStyleClass("link"); authorPanelLink->clicked().connect(SLOT(this, BlogImpl::authorPanel)); loginStatus_->bindWidget("author-panel-link", authorPanelLink); } else { loginStatus_->bindEmpty("userlist-link"); loginStatus_->bindEmpty("author-panel-link"); } loginStatus_->bindWidget("profile-link", profileLink); bindPanelTemplates(); }
Playlist::Playlist(Session* session, Settings* settings, WContainerWidget* parent) : WPanel(parent), d(this, session) { setCentralWidget(d->container = new WContainerWidget); setTitleBar(true); addStyleClass("playlist"); setHeaderCollapsible(this); titleBarWidget()->addStyleClass("playtlist-titlebar"); setCollapsible(false); d->container->hide(); d->container->setList(true); d->container->addStyleClass("nav nav-pills nav-stacked"); d->container->setMargin(5, Side::Bottom); WText *showHideButtonText = WW<WText>(); d->setPlaylistVisible = [=](bool visible) { if(!visible) { showHideButtonText->setText(wtr("playlist.show")); settings->animateHide(Settings::PlaylistAnimation, d->container); } else { showHideButtonText->setText(wtr("playlist.hide")); settings->animateShow(Settings::PlaylistAnimation, d->container); } }; d->playSignal.connect([=](PlaylistItem*,_n5){ d->setPlaylistVisible(false); }); WContainerWidget *firstGroup = WW<WContainerWidget>().css("btn-group"); firstGroup->addWidget(WW<WAnchor>().css("btn btn-xs") .setImage(WW<WImage>(Settings::staticPath("/icons/actions/playlist.png")).setMargin(5, Side::Right)) .add(showHideButtonText) .onClick([=](WMouseEvent){ d->setPlaylistVisible(!d->container->isVisible()); })); firstGroup->addWidget(WW<WAnchor>().css("btn btn-xs") .setImage(WW<WImage>(Settings::staticPath("/icons/actions/playlist.clear.png")).setMargin(5, Side::Right)) .setText(wtr("playlist.clear")) .onClick([=](WMouseEvent){ for(auto item: d->internalQueue) delete item; d->internalQueue.clear(); })); WContainerWidget *secondGroup = WW<WContainerWidget>().css("btn-group"); WWidget *prev = WW<WAnchor>(secondGroup).css("btn btn-xs") .add(new WImage{Settings::staticPath("/icons/actions/previous.png")}).onClick(boost::bind(&Playlist::previous, this)); WWidget *next = WW<WAnchor>(secondGroup).css("btn btn-xs") .add(new WImage{Settings::staticPath("/icons/actions/next.png")}).onClick(boost::bind(&Playlist::next, this)); WContainerWidget *playlistButtonsContainer = WW<WContainerWidget>(titleBarWidget()).css("btn-toolbar") .add(firstGroup).add(secondGroup); d->setPlaylistVisible(false); }
WWidget *WCartesianChart::createLegendItemWidget(int index) { WContainerWidget *legendItem = new WContainerWidget(); legendItem->addWidget(new IconWidget(this, index)); WText *label = new WText(asString(model()->headerData(index))); label->setVerticalAlignment(AlignTop); legendItem->addWidget(label); return legendItem; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////// // 设置标题文本 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// void CEccGenTitle::setTitle(const string &szTitle) { if(m_pTitle) { m_pTitle->elementAt(0, 0)->clear(); WText *pTitle = new WText(szTitle, m_pTitle->elementAt(0, 0)); if(pTitle) pTitle->setStyleClass("tgrouptitle2"); } }
WWidget *WtHome::examples() { WContainerWidget *result = new WContainerWidget(); WText *intro = new WText(tr("home.examples")); intro->setInternalPathEncoding(true); result->addWidget(intro); examplesMenu_ = new WTabWidget(result); WAnimation animation(WAnimation::SlideInFromRight, WAnimation::EaseIn); examplesMenu_->contentsStack()->setTransitionAnimation(animation, true); /* * The following code is functionally equivalent to: * * examplesMenu_->addTab(helloWorldExample(), "Hello world"); * * However, we optimize here for memory consumption (it is a homepage * after all, and we hope to be slashdotted some day) * * Therefore, we wrap all the static content (including the tree * widgets), into WViewWidgets with static models. In this way the * widgets are not actually stored in memory on the server. */ // The call ->setPathComponent() is to use "/examples/" instead of // "/examples/hello_world" as internal path examplesMenu_->addTab(wrapView(&WtHome::helloWorldExample), tr("hello-world"))->setPathComponent(""); examplesMenu_->addTab(wrapView(&WtHome::chartExample), tr("charts")); examplesMenu_->addTab(wrapView(&WtHome::homepageExample), tr("wt-homepage")); examplesMenu_->addTab(wrapView(&WtHome::treeviewExample), tr("treeview")); examplesMenu_->addTab(wrapView(&WtHome::gitExample), tr("git")); examplesMenu_->addTab(wrapView(&WtHome::chatExample), tr("chat")); examplesMenu_->addTab(wrapView(&WtHome::composerExample), tr("mail-composer")); examplesMenu_->addTab(wrapView(&WtHome::hangmanExample), tr("hangman")); examplesMenu_->addTab(wrapView(&WtHome::widgetGalleryExample), tr("widget-gallery")); // Enable internal paths for the example menu examplesMenu_->setInternalPathEnabled("/examples"); examplesMenu_->currentChanged().connect(this, &Home::googleAnalyticsLogger); return result; }
WWidget *Home::linkSourceBrowser(const std::string& example) { /* * Instead of using a WAnchor, which will not progress properly because * it is wrapped with wrapView() (-- should we not fix that?), we use * a WText which contains an anchor, and enable internal path encoding. */ std::string path = "#/" + SRC_INTERNAL_PATH + "/" + example; WText *a = new WText(tr("source-browser-link").arg(path)); a->setInternalPathEncoding(true); return a; }
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 WMediaPlayer::addText(WTemplate *t, TextId id, const char *bindId, const std::string& styleClass) { WText *text = new WText(); text->setInline(false); if (!styleClass.empty()) text->setStyleClass(styleClass); t->bindWidget(bindId, text); setText(id, text); }
void DensityApp::plot() { const char *kernelstr[] = { "gaussian", "epanechnikov", "rectangular", "triangular", "cosine" }; greeting_->setText("Starting R call"); R_["tfile"] = tempfile_; R_["bw"] = bw_; R_["kernel"] = kernelstr[kernel_]; // passes the string to R R_["y"] = Yvec_; std::string cmd0 = "png(filename=tfile,width=600,height=400); plot(density(y, bw=bw/100, kernel=kernel), xlim=range(y)+c(-2,2), main=\"Kernel: "; std::string cmd1 = "\"); points(y, rep(0, length(y)), pch=16, col=rgb(0,0,0,1/4)); dev.off()"; std::string cmd = cmd0 + kernelstr[kernel_] + cmd1; // stick the selected kernel in the middle R_.parseEvalQ(cmd); // evaluate command -- generates new density plot imgfile_->setChanged(); // important: tells consumer that image has changed, forces refresh greeting_->setText("Finished request from " + this->environment().clientAddress() + " using " + this->environment().userAgent()) ; }
void WTreeTable::addColumn(const WString& header, const WLength& width) { if (treeRoot()) throw WException("WTreeTable::addColumn(): must be called before " "setTreeRoot()"); WText *t = new WText(header); t->resize(width, WLength::Auto); t->setInline(false); t->setFloatSide(Left); headerContainer_->addWidget(t); columnWidths_.push_back(width); }
void WsMenu::doLoadCurPath() { std::string rootPath = asString(option("rootPath")).toUTF8(); boost::algorithm::replace_all(rootPath, "&", "&"); // Si pas de root path on prend l'internal Path if ( rootPath.size() < 1 ){ m_sCurPath = WsApp->internalPath(); }else m_sCurPath = rootPath; std::string sWithoutPrefix = WsApp->WsModules().pathWithoutPrefix(m_sCurPath); WsUser* pUser = WsApp->wsUser(); NodePtr tmpNode = pUser->getAccessRoot().get()->eatPath(sWithoutPrefix); if ( !tmpNode.get() ) { wApp->log("notice") << "WsMenu::doLoadCurPath - eatPath return NULL "; return; } if ( tmpNode.get()->isRegularFile() ) { tmpNode = pUser->getAccessRoot().get()->eatPath(boost::filesystem::path(sWithoutPrefix).parent_path().string()); if ( !tmpNode.get() ) { wApp->log("notice") << "WsMenu::doLoadCurPath - eatPath on parent return NULL "; return; } } NodePtr startNode = pUser->getAccessRoot(); if ( !startNode.get() ) { wApp->log("notice") << "WsMenu::doLoadCurPath - startNode = " << startNode; return; } NodePtr pNode = startNode.get()->eatPath(tmpNode.get()->getPath().string()); if ( !pNode.get() ) return; if ( asString(option("useTitle")) == "true" ) { std::string sTitle(pNode.get()->getDisplayName()); boost::algorithm::replace_all(sTitle, "&", "&"); WText* title = new WText(sTitle); title->addStyleClass("WsMenuTitle"); addWidget(title); } WMenu* menuParent = 0; if ( asString(option("useButtons")) != "true" ) menuParent = new WMenu(this); if ( asString(option("showRoot")) == "true" ) if ( pNode.get()->getPath() == "/" ) { createMenu(pNode, menuParent); } loadMenu(pNode, menuParent); if ( asString(option("useImages")) == "true" ) loadImage(pNode); }
void CommentView::renderView() { clear(); bool isRootComment = !comment_->parent; setTemplateText(isRootComment ? tr("blog-root-comment") : tr("blog-comment")); bindString("collapse-expand", WString::Empty); // NYI WText *replyText = new WText(isRootComment ? tr("comment-add") : tr("comment-reply")); replyText->setStyleClass("link"); replyText->clicked().connect(this, &CommentView::reply); bindWidget("reply", replyText); bool mayEdit = session_.user() && (comment_->author == session_.user() || session_.user()->role == User::Admin); if (mayEdit) { WText *editText = new WText(tr("comment-edit")); editText->setStyleClass("link"); editText->clicked().connect(this, &CommentView::edit); bindWidget("edit", editText); } else bindString("edit", WString::Empty); bool mayDelete = (session_.user() && session_.user() == comment_->author) || session_.user() == comment_->post->author; if (mayDelete) { WText *deleteText = new WText(tr("comment-delete")); deleteText->setStyleClass("link"); deleteText->clicked().connect(this, &CommentView::rm); bindWidget("delete", deleteText); } else bindString("delete", WString::Empty); typedef std::vector< dbo::ptr<Comment> > CommentVector; CommentVector comments; { dbo::collection<dbo::ptr<Comment> > cmts = comment_->children.find().orderBy("date"); comments.insert(comments.end(), cmts.begin(), cmts.end()); } WContainerWidget *children = new WContainerWidget(); for (int i = (int)comments.size() - 1; i >= 0; --i) children->addWidget(new CommentView(session_, comments[i])); bindWidget("children", children); }
/*! \brief Change repository and/or revision */ void loadGitModel() { sourceView_->setIndex(WModelIndex()); repositoryError_->setText(""); revisionError_->setText(""); try { gitModel_->setRepositoryPath(repositoryEdit_->text().toUTF8()); try { gitModel_->loadRevision(revisionEdit_->text().toUTF8()); } catch (const Git::Exception& e) { revisionError_->setText(e.what()); } } catch (const Git::Exception& e) { repositoryError_->setText(e.what()); } }
void Example::get_search(MapViewer::GeoNode node) { Coordinate& pos = node.first; click_search_->setText( "You have chosen: " + node.second + " <br />Position: " + str(boost::format("%.4f %.4f") % pos.longitude() % pos.latitude())); mv_->time_zone(pos).connect(this, &Example::get_time_zone); }
void WMenuItem::setCloseable(bool closeable) { if (closeable_ != closeable) { closeable_ = closeable; if (closeable_) { WText *closeIcon = new WText(""); insertWidget(0, std::unique_ptr<WText>(closeIcon)); WApplication *app = WApplication::instance(); app->theme()->apply(this, closeIcon, WidgetThemeRole::MenuItemClose); closeIcon->clicked().connect(this, &WMenuItem::close); } else removeWidget(widget(0)); } }
void HelloApplication::greet() { /* * Update the text, using text input into the nameEdit_ field. */ greeting_->setText("Hello there, " + nameEdit_->text()); }
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"); } }
void WMenuItem::setCloseable(bool closeable) { if (closeable_ != closeable) { closeable_ = closeable; if (closeable_) { WText *closeIcon = new WText(""); insertWidget(0, closeIcon); WApplication *app = WApplication::instance(); app->theme()->apply(this, closeIcon, MenuItemCloseRole); closeIcon->clicked().connect(this, &WMenuItem::close); } else { delete widget(0); } } }