///////////////////////////////////////////////////////////////////////////////////////////////////////////// // 设置当前路径 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// void CEccGenTitle::setCurIndex(const string &szIndex) { PAIRLIST lsPath; CEccTreeView::MakePath(szIndex, lsPath); if(lsPath.size() >= 1 && m_pTitle) { m_pTitle->elementAt(0, 0)->clear(); sv_pair svitem; while(lsPath.size() > 1) { svitem = lsPath.front(); lsPath.pop_front(); WText *pName = new WText(svitem.value, m_pTitle->elementAt(0, 0)); if(pName) { string szCmd = "SetCurfocus(\"" + svitem.name + "\");"; pName->setStyleClass("tgrouptitle"); WObject::connect(pName, SIGNAL(clicked()), szCmd.c_str(), WObject::ConnectionType::JAVASCRIPT); } WText *pTemp = new WText(" : ", m_pTitle->elementAt(0, 0)); if(pTemp) pTemp->setStyleClass("tgrouptitle2"); } svitem = lsPath.front(); lsPath.pop_front(); WText *pTitle = new WText(svitem.value, m_pTitle->elementAt(0, 0)); if(pTitle) pTitle->setStyleClass("tgrouptitle2"); } }
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(); }
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; }
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); }
BlogImpl(const std::string& basePath, dbo::SqlConnectionPool& connectionPool, const std::string& rssFeedUrl, BlogView *blogView) : basePath_(basePath), rssFeedUrl_(rssFeedUrl), session_(connectionPool), blogView_(blogView), panel_(0), authorPanel_(0), users_(0), userEditor_(0), mustLoginWarning_(0), mustBeAdministratorWarning_(0), invalidUser_(0) { WApplication *app = wApp; app->messageResourceBundle().use(WApplication::appRoot() + "blog"); app->useStyleSheet("/css/blog.css"); app->useStyleSheet("/css/asciidoc.css"); app->internalPathChanged().connect(this, &BlogImpl::handlePathChange); loginStatus_ = new WTemplate(tr("blog-login-status"), this); panel_ = new WStackedWidget(this); items_ = new WContainerWidget(this); session_.login().changed().connect(this, &BlogImpl::onUserChanged); loginWidget_ = new BlogLoginWidget(session_, basePath); loginWidget_->hide(); WText *loginLink = new WText(tr("login")); loginLink->setStyleClass("link"); loginLink->clicked().connect(loginWidget_, &WWidget::show); loginLink->clicked().connect(loginLink, &WWidget::hide); WText *registerLink = new WText(tr("Wt.Auth.register")); registerLink->setStyleClass("link"); registerLink->clicked().connect(loginWidget_, &BlogLoginWidget::registerNewUser); WAnchor* archiveLink = new WAnchor (WLink(WLink::InternalPath, basePath_ + "all"), tr("archive")); loginStatus_->bindWidget("login", loginWidget_); loginStatus_->bindWidget("login-link", loginLink); loginStatus_->bindWidget("register-link", registerLink); loginStatus_->bindString("feed-url", rssFeedUrl_); loginStatus_->bindWidget("archive-link", archiveLink); onUserChanged(); loginWidget_->processEnvironment(); }
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; } }
/*! \brief Creates a title widget. */ WText *createTitle(const WString& title) { WText *result = new WText(title); result->setInline(false); result->setStyleClass("title"); return result; }
void CalendarCell::update(const dbo::ptr<UserAccount>& user, const WDate& date) { date_ = date; user_ = user; clear(); dbo::Session& session = PlannerApplication::plannerApplication()->session; dbo::Transaction transaction(session); WString day; day += boost::lexical_cast<std::string>(date.day()); if (date.day() == 1) day += " " + WDate::longMonthName(date.month()); WText* header = new WText(day); header->setStyleClass("cell-header"); addWidget(header); typedef dbo::collection< dbo::ptr<Entry> > Entries; Entries entries = user->entriesInRange(date, date.addDays(1)); const unsigned maxEntries = 4; unsigned counter = 0; for (Entries::const_iterator i = entries.begin(); i != entries.end(); ++i, ++counter) { if (counter == maxEntries) { WText* extra = new WText(tr("calendar.cell.extra") .arg((int)(entries.size() - maxEntries))); extra->setStyleClass("cell-extra"); addWidget(extra); extra->clicked().preventPropagation(); extra->clicked().connect(this, &CalendarCell::showAllEntriesDialog); break; } WString format = EntryDialog::timeFormat; addWidget(new WText((*i)->start.toString(format) + "-" + (*i)->stop.toString(format) + ": " + (*i)->summary)); } transaction.commit(); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////// // 设置标题文本 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// 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 *StyleLayout::wBorderLayout() { WContainerWidget *result = new WContainerWidget(); topic("WBorderLayout", result); addText(tr("layout-WBorderLayout"), result); WContainerWidget *container; container = new WContainerWidget(result); container->resize(WLength::Auto, 400); container->setStyleClass("yellow-box"); WBorderLayout *layout = new WBorderLayout(); container->setLayout(layout); WText *item; item = addText(tr("borderlayout-item").arg("North")); item->setStyleClass("green-box"); layout->addWidget(item, WBorderLayout::North); item = addText(tr("borderlayout-item").arg("West")); item->setStyleClass("green-box"); layout->addWidget(item, WBorderLayout::West); item = addText(tr("borderlayout-item").arg("East")); item->setStyleClass("green-box"); layout->addWidget(item, WBorderLayout::East); item = addText(tr("borderlayout-item").arg("South")); item->setStyleClass("green-box"); layout->addWidget(item, WBorderLayout::South); item = addText(tr("borderlayout-item").arg("Center")); item->setStyleClass("green-box"); layout->addWidget(item, WBorderLayout::Center); return result; }
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 EditUsers::limitList() { WContainerWidget* list = new WContainerWidget; bindWidget("user-list",list); typedef dbo::collection<dbo::ptr<User> > UserList; dbo::Transaction t(session_); UserList users = session_.find<User>().where("name like ?").bind("%"+limitEdit_->text()+"%").orderBy("name"); for (UserList::const_iterator i = users.begin(); i != users.end(); ++i) { WText* t = new WText((*i)->name, list); t->setStyleClass("link"); new WBreak(list); t->clicked().connect(boost::bind(&EditUsers::onUserClicked, this, (*i).id())); } if (!users.size()) new WText(tr("no-users-found"),list); }
WWidget* WCalendar::renderCell(WWidget* widget, const WDate& date) { WText* t = dynamic_cast<WText*>(widget); if (!t) { t = new WText(); t->setInline(false); t->setTextFormat(PlainText); } #ifndef WT_TARGET_JAVA char buf[30]; #else char *buf; #endif // WT_TARGET_JAVA Utils::itoa(date.day(), buf); t->setText(WString::fromUTF8(buf)); std::string styleClass; if (isInvalid(date)) styleClass += " Wt-cal-oor"; else if (date.month() != currentMonth()) styleClass += " Wt-cal-oom"; if (isSelected(date)) styleClass += " Wt-cal-sel"; WDate currentDate = WDate::currentDate(); if (date.day() == currentDate.day() && date.month() == currentDate.month() && date.year() == currentDate.year()) { if (!isSelected(date)) styleClass += " Wt-cal-now"; t->setToolTip(WString::tr("Wt.WCalendar.today")); } else t->setToolTip(""); t->setStyleClass(styleClass.c_str()); return t; }
void FormExample::setLanguage(const std::string lang) { bool haveLang = false; for (auto i : languageSelects_) { WText *t = i; // prefix match, e.g. en matches en-us. bool isLang = lang.find(t->text().toUTF8()) == 0; t->setStyleClass(isLang ? "langcurrent" : "lang"); haveLang = haveLang || isLang; } if (!haveLang) { languageSelects_[0]->setStyleClass("langcurrent"); WApplication::instance() ->setLocale(languageSelects_[0]->text().toUTF8()); } else WApplication::instance()->setLocale(lang); }
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A void PagesList::load() { impl_->clear(); // item count WText *wtitemt = new WText("Eintraege : ", impl_); wtitemt->setStyleClass("tableFilter"); WText *wtitems = new WText(lexical_cast<string>(table_->entriesCount()), impl_); wtitems->setStyleClass("pageNumbersCurr"); // pages WText *wtxtpg = new WText(" Seiten : ", impl_); wtxtpg->setStyleClass("tableFilter"); const unsigned int pagesCount = 1 + table_->entriesCount() / table_->entriesPerPage(); if(pagesCount > 1 && table_->pageNr() > 1) { WText *previous = new WText("<", impl_); previous->setStyleClass("pageNumbers"); previous->setToolTip("vorherige"); previous->clicked().connect(SLOT(this, PagesList::select)); } for(unsigned int i=0; i<pagesCount; ++i) { WText *wtxt = new WText(lexical_cast<string>(i+1), impl_); if(i + 1 == table_->pageNr()) wtxt->setStyleClass("pageNumbersCurr"); else { wtxt->setStyleClass("pageNumbers"); wtxt->clicked().connect(SLOT(this, PagesList::select)); } } if(pagesCount > 1 && table_->pageNr() < pagesCount) { WText *next = new WText(">", impl_); next->setStyleClass("pageNumbers"); next->setToolTip("nächste"); next->clicked().connect(SLOT(this, PagesList::select)); } }
void SVSEView::createTitle() { int nRow = numRows(); WTable *pSub = new WTable(elementAt(nRow, 0)); elementAt(nRow, 0)->setStyleClass("t1title"); if(pSub) { pSub->setStyleClass("t3"); nRow = pSub->numRows(); WText *pTitle = new WText(SVResString::getResString("IDS_SE_List_Title"), (WContainerWidget*)pSub->elementAt(nRow, 0)); if(pTitle) pTitle->setStyleClass("tgrouptitle2"); pSub->elementAt(nRow, 0)->setStyleClass("cell_80"); m_pTime = new WText("local time", pSub->elementAt(nRow, 1)); pSub->elementAt(nRow, 1)->setContentAlignment(AlignRight | AlignCenter); svutil::TTime ttime = svutil::TTime::GetCurrentTimeEx(); string curTime = ttime.Format(); if(m_pTime) { m_pTime->setStyleClass("tgrouptitle2"); m_pTime->setText(SVResString::getResString("IDS_Refresh_Time") + curTime); } } }
void TrendReportFrame::initQueryTable(WSVFlexTable **pFlexTable_Add ,int nRow,std::string strTitle, WSVMainTable * pUserTable) { *pFlexTable_Add = new WSVFlexTable((WContainerWidget *)pUserTable->GetContentTable()->elementAt(nRow,0), Blank, strTitle); WSVFlexTable *pFlexTable = *pFlexTable_Add; if(pFlexTable->GetContentTable() != NULL) { //标题链接 WTable *QueryTitleTable1 = new WTable(pFlexTable->GetContentTable()->elementAt(0,0)); QueryTitleTable1->elementAt(0, 1)->resize(WLength(8,WLength::Percentage),0); WText * p2HourText = new WText("2h", QueryTitleTable1->elementAt(0, 1)); p2HourText->setStyleClass("linktext"); connect(p2HourText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query2HourText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 2)->resize(WLength(8,WLength::Percentage),0); WText * p4HourText = new WText("4h", QueryTitleTable1->elementAt(0, 2)); p4HourText->setStyleClass("linktext"); connect(p4HourText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query4HourText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 3)->resize(WLength(8,WLength::Percentage),0); WText * p8HourText = new WText("8h", QueryTitleTable1->elementAt(0, 3)); p8HourText->setStyleClass("linktext"); connect(p8HourText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query8HourText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 4)->resize(WLength(8,WLength::Percentage),0); WText * p1DayText = new WText("1d", QueryTitleTable1->elementAt(0, 4)); p1DayText->setStyleClass("linktext"); connect(p1DayText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query1DayText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 5)->resize(WLength(8,WLength::Percentage),0); WText * p3DayText = new WText("3d", QueryTitleTable1->elementAt(0, 5)); p3DayText->setStyleClass("linktext"); connect(p3DayText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query3DayText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 6)->resize(WLength(8,WLength::Percentage),0); WText * p5DayText = new WText("5d", QueryTitleTable1->elementAt(0, 6)); p5DayText->setStyleClass("linktext"); connect(p5DayText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query5DayText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 7)->resize(WLength(8,WLength::Percentage),0); WText * p1WeekText = new WText("1w", QueryTitleTable1->elementAt(0, 7)); p1WeekText->setStyleClass("linktext"); connect(p1WeekText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query1WeekText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 8)->resize(WLength(12,WLength::Percentage),0); WText * pCurWeekText = new WText(strWeek, QueryTitleTable1->elementAt(0, 8)); pCurWeekText->setStyleClass("linktext"); connect(pCurWeekText, SIGNAL(clicked()), "showbar();" ,this, SLOT(QueryCurWeekText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 9)->resize(WLength(8,WLength::Percentage),0); WText * p1MonthText = new WText("1m", QueryTitleTable1->elementAt(0, 9)); p1MonthText->setStyleClass("linktext"); connect(p1MonthText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query1MonthText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 10)->resize(WLength(8,WLength::Percentage),0); WText * p3MonthText = new WText("3m", QueryTitleTable1->elementAt(0, 10)); p3MonthText->setStyleClass("linktext"); connect(p3MonthText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query3MonthText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 11)->resize(WLength(8,WLength::Percentage),0); WText * p6MonthText = new WText("6m", QueryTitleTable1->elementAt(0, 11)); p6MonthText->setStyleClass("linktext"); connect(p6MonthText, SIGNAL(clicked()), "showbar();" ,this, SLOT(Query6MonthText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); QueryTitleTable1->elementAt(0, 12)->resize(WLength(12,WLength::Percentage),0); WText * pCurDayText = new WText(strDay, QueryTitleTable1->elementAt(0, 12)); pCurDayText->setStyleClass("linktext"); connect(pCurDayText, SIGNAL(clicked()), "showbar();" ,this, SLOT(QueryCurDayText()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); //时间 WTable * QueryTitleTable2 = new WTable((WContainerWidget *)pFlexTable->GetContentTable()->elementAt(1,0)); pFlexTable->GetContentTable()->elementAt(1, 0)->setContentAlignment(AlignTop | AlignCenter); QueryTitleTable2->resize(WLength(100,WLength::Percentage),WLength(30,WLength::Pixel)); TTime curTime = TTime::GetCurrentTimeEx(); new WText(strStartTimeLabel, QueryTitleTable2->elementAt(0, 0)); pAlertStartTime = new WLineEdit("", QueryTitleTable2->elementAt(0, 1)); TTimeSpan ts(0,24,0,0); curTime -= ts; pAlertStartTime->setText(curTime.Format()); pAlertStartTime->setStyleClass("input_text"); strcpy(pAlertStartTime->contextmenu_ , "onFocus=\"calendar()\""); curTime = TTime::GetCurrentTimeEx(); new WText(strEndTimeLabel, QueryTitleTable2->elementAt(0, 3)); pAlertEndTime = new WLineEdit("", QueryTitleTable2->elementAt(0, 4)); pAlertEndTime->setText(curTime.Format()); pAlertEndTime->setStyleClass("input_text"); strcpy(pAlertEndTime->contextmenu_ , "onFocus=\"calendar()\""); pFlexTable->ShowOrHideHelp(); pFlexTable->HideAllErrorMsg(); } if(pFlexTable->GetActionTable()!=NULL) { WTable *pTbl; pTbl = new WTable(pFlexTable->GetActionTable()->elementAt(0, 1)); WSVButton * pQueryBtn = new WSVButton(pTbl->elementAt(0,0), strQueryBtn, "button_bg_m_black.png", "", true); connect(pQueryBtn, SIGNAL(clicked()), "showbar();" ,this, SLOT(TrendReportQuery()) , WObject::ConnectionType::JAVASCRIPTDYNAMIC); } }
void WCalendar::create() { selectionMode_ = SingleSelection; singleClickSelect_ = false; horizontalHeaderFormat_ = ShortDayNames; firstDayOfWeek_ = 1; cellClickMapper_ = 0; cellDblClickMapper_ = 0; WDate currentDay = WDate::currentDate(); currentYear_ = currentDay.year(); currentMonth_ = currentDay.month(); WStringStream text; text << "<table class=\"days ${table-class}\" cellspacing=\"0\" cellpadding=\"0\">" """<tr>" "" "<th class=\"caption\">${nav-prev}</th>" "" "<th class=\"caption\"colspan=\"5\">${month} ${year}</th>" "" "<th class=\"caption\">${nav-next}</th>" """</tr>" """<tr>"; for (int j = 0; j < 7; ++j) text << "<th title=\"${t" << j << "}\" scope=\"col\">${d" << j << "}</th>"; text << "</tr>"; for (int i = 0; i < 6; ++i) { text << "<tr>"; for (int j = 0; j < 7; ++j) text << "<td>${c" << (i * 7 + j) << "}</td>"; text << "</tr>"; } text << "</table>"; setImplementation(impl_ = new WTemplate()); impl_->setTemplateText(WString::fromUTF8(text.str()), XHTMLUnsafeText); impl_->setStyleClass("Wt-cal"); setSelectable(false); WText *prevMonth = new WText(tr("Wt.WCalendar.PrevMonth")); prevMonth->setStyleClass("Wt-cal-navbutton"); prevMonth->clicked().connect(this, &WCalendar::browseToPreviousMonth); WText *nextMonth = new WText(tr("Wt.WCalendar.NextMonth")); nextMonth->setStyleClass("Wt-cal-navbutton"); nextMonth->clicked().connect(this, &WCalendar::browseToNextMonth); monthEdit_ = new WComboBox(); monthEdit_->setInline(true); for (unsigned i = 0; i < 12; ++i) monthEdit_->addItem(WDate::longMonthName(i+1)); monthEdit_->activated().connect(this, &WCalendar::monthChanged); monthEdit_->setDisabled(!WApplication::instance()->environment().ajax()); yearEdit_ = new WInPlaceEdit(""); yearEdit_->setButtonsEnabled(false); yearEdit_->lineEdit()->setTextSize(4); yearEdit_->setStyleClass("Wt-cal-year"); yearEdit_->valueChanged().connect(this, &WCalendar::yearChanged); impl_->bindWidget("nav-prev", prevMonth); impl_->bindWidget("nav-next", nextMonth); impl_->bindWidget("month", monthEdit_); impl_->bindWidget("year", yearEdit_); setHorizontalHeaderFormat(horizontalHeaderFormat_); setFirstDayOfWeek(firstDayOfWeek_); }
void SimpleChatWidget::processChatEvent(const ChatEvent& event) { WApplication *app = WApplication::instance(); /* * This is where the "server-push" happens. The chat server posts to this * event from other sessions, see SimpleChatServer::postChatEvent() */ /* * Format and append the line to the conversation. * * This is also the step where the automatic XSS filtering will kick in: * - if another user tried to pass on some JavaScript, it is filtered away. * - if another user did not provide valid XHTML, the text is automatically * interpreted as PlainText */ /* * If it is not a plain message, also update the user list. */ if (event.type() != ChatEvent::Message) { if (event.type() == ChatEvent::Rename && event.user() == user_) user_ = event.data(); updateUsers(); } /* * This is the server call: we (schedule to) propagate the updated UI to * the client. * * This schedules an update and returns immediately */ app->triggerUpdate(); newMessage(); /* * Anything else doesn't matter if we are not logged in. */ if (!loggedIn()) return; bool display = event.type() != ChatEvent::Message || !userList_ || (users_.find(event.user()) != users_.end() && users_[event.user()]); if (display) { WText *w = new WText(messages_); /* * If it fails, it is because the content wasn't valid XHTML */ if (!w->setText(event.formattedHTML(user_, XHTMLText))) { w->setText(event.formattedHTML(user_, PlainText)); w->setTextFormat(XHTMLText); } w->setInline(false); w->setStyleClass("chat-msg"); /* * Leave no more than 100 messages in the back-log */ if (messages_->count() > 100) delete messages_->children()[0]; /* * Little javascript trick to make sure we scroll along with new content */ app->doJavaScript(messages_->jsRef() + ".scrollTop += " + messages_->jsRef() + ".scrollHeight;"); /* If this message belongs to another user, play a received sound */ if (event.user() != user_ && messageReceived_) messageReceived_->play(); } }
WWidget *RootLogin::Layout() { m_cgiRoot->setTitle(m_lang->GetString("ROOT_LOGIN_TITLE")); Div *root = new Div("RootLogin"); Div *dvNoScript = new Div(root, "dvNoScript"); new WText(m_lang->GetString("WARN_NO_SCRIPT"), dvNoScript); Div *dvLogin = new Div(root, "dvLogin"); new WText(m_lang->GetString("ROOT_LOGIN_FORM_TITLE"), dvLogin); Div *dvLangBar = new Div(dvLogin, "dvLangBar"); new WText(L"<span style=\"color: #333; font-family: Tahoma !important; letter-spacing: 1px;\">" "<a href=\"?enroot\" style=\"color: #666; text-decoration: none;\">EN</a>" " | " "<a href=\"?faroot\" style=\"color: #666; text-decoration: none;\">فا</a>" "</span>", dvLangBar); Div *dvLoginForm = new Div(dvLogin, "dvLoginForm", "form"); WGridLayout *dvLoginFormLayout = new WGridLayout(); m_loginUserEdit = new WLineEdit(); m_loginPwdEdit = new WLineEdit(); m_loginPwdEdit->setEchoMode(WLineEdit::Password); m_loginCaptchaEdit = new WLineEdit(); dvLoginFormLayout->addWidget(new WText(m_lang->GetString("ROOT_LOGIN_FORM_USER_TEXT")), 0, 0, AlignLeft | AlignMiddle); dvLoginFormLayout->addWidget(m_loginUserEdit, 0, 1); dvLoginFormLayout->addWidget(new WText(m_lang->GetString("ROOT_LOGIN_FORM_PWD_TEXT")), 1, 0, AlignLeft | AlignMiddle); dvLoginFormLayout->addWidget(m_loginPwdEdit, 1, 1); dvLoginFormLayout->addWidget(new WText(m_lang->GetString("ROOT_LOGIN_FORM_CAPTCHA_TEXT")), 2, 0, AlignLeft | AlignMiddle); dvLoginFormLayout->addWidget(m_loginCaptchaEdit, 2, 1); dvLoginFormLayout->setVerticalSpacing(11); dvLoginFormLayout->setColumnStretch(0, 100); dvLoginFormLayout->setColumnStretch(1, 200); dvLoginForm->resize(300, WLength::Auto); dvLoginForm->setLayout(dvLoginFormLayout); m_loginCaptchaImage = m_captcha->GenCap(); dvLogin->addWidget(m_loginCaptchaImage); m_errLoginText = new WText(dvLogin); WPushButton *loginBtn = new WPushButton(m_lang->GetString("ROOT_LOGIN_FORM_LOGIN_TEXT"), dvLogin); loginBtn->setStyleClass("formButton"); WText *forgotLink = new WText( L"<p style=\"text-align: right !important; margin-top: 25px;\">" + m_lang->GetString("ROOT_LOGIN_FORM_FORGOT_TEXT") + L"</p>", dvLogin); forgotLink->setStyleClass("link"); m_dvForgot = new Div(dvLogin, "dvForgot"); m_forgotFormFlag = false; Div *dvCopyright = new Div(root, "dvCopyright"); new WText(Base::Copyright(m_cgiEnv->CurrentLang), dvCopyright); WSignalMapper<WText *> *forgotMap = new WSignalMapper<WText *>(this); forgotMap->mapped().connect(this, &RootLogin::ForgotForm); forgotMap->mapConnect(forgotLink->clicked(), forgotLink); WLengthValidator *loginUserValidator = new WLengthValidator(Base::MIN_USERNAME_LENGTH, Base::MAX_USERNAME_LENGTH); loginUserValidator->setMandatory(true); m_loginUserEdit->setValidator(loginUserValidator); WLengthValidator *loginPwdValidator = new WLengthValidator(Base::MIN_PASSWORD_LENGTH, Base::MAX_PASSWORD_LENGTH); loginPwdValidator->setMandatory(true); m_loginPwdEdit->setValidator(loginPwdValidator); m_loginCaptchaValidator = new WIntValidator(m_captcha->Result, m_captcha->Result); m_loginCaptchaValidator->setMandatory(true); m_loginCaptchaEdit->setValidator(m_loginCaptchaValidator); m_loginUserEdit->enterPressed().connect(this, &RootLogin::LoginOK); m_loginPwdEdit->enterPressed().connect(this, &RootLogin::LoginOK); m_loginCaptchaEdit->enterPressed().connect(this, &RootLogin::LoginOK); loginBtn->clicked().connect(this, &RootLogin::LoginOK); return root; }
bool SimpleChatWidget::startChat(const WString& user) { /* * When logging in, we pass our processChatEvent method as the function that * is used to indicate a new chat event for this user. */ if (server_.login(user)) { loggedIn_ = true; connect(); user_ = user; clear(); userNameEdit_ = 0; messages_ = new WContainerWidget(); userList_ = new WContainerWidget(); messageEdit_ = new WTextArea(); messageEdit_->setRows(2); messageEdit_->setFocus(); // Display scroll bars if contents overflows messages_->setOverflow(WContainerWidget::OverflowAuto); userList_->setOverflow(WContainerWidget::OverflowAuto); sendButton_ = new WPushButton("Send"); WPushButton *logoutButton = new WPushButton("Logout"); createLayout(messages_, userList_, messageEdit_, sendButton_, logoutButton); /* * Connect event handlers: * - click on button * - enter in text area * * We will clear the input field using a small custom client-side * JavaScript invocation. */ // Create a JavaScript 'slot' (JSlot). The JavaScript slot always takes // 2 arguments: the originator of the event (in our case the // button or text area), and the JavaScript event object. clearInput_.setJavaScript ("function(o, e) { setTimeout(function() {" "" + messageEdit_->jsRef() + ".value='';" "}, 0); }"); // Bind the C++ and JavaScript event handlers. sendButton_->clicked().connect(this, &SimpleChatWidget::send); messageEdit_->enterPressed().connect(this, &SimpleChatWidget::send); sendButton_->clicked().connect(clearInput_); messageEdit_->enterPressed().connect(clearInput_); sendButton_->clicked().connect(messageEdit_, &WLineEdit::setFocus); messageEdit_->enterPressed().connect(messageEdit_, &WLineEdit::setFocus); // Prevent the enter from generating a new line, which is its default // action messageEdit_->enterPressed().preventDefaultAction(); logoutButton->clicked().connect(this, &SimpleChatWidget::logout); WText *msg = new WText ("<div><span class='chat-info'>You are joining as " + escapeText(user_) + ".</span></div>", messages_); msg->setStyleClass("chat-msg"); if (!userList_->parent()) { delete userList_; userList_ = 0; } if (!sendButton_->parent()) { delete sendButton_; sendButton_ = 0; } if (!logoutButton->parent()) delete logoutButton; updateUsers(); return true; } else return false; }
/*! \brief Creates the hints text. */ WWidget *aboutDisplay() { WText *result = new WText(WString::tr("about-text")); result->setStyleClass("about"); return result; }
WWidget *StyleLayout::wBoxLayout() { WContainerWidget *result = new WContainerWidget(); topic("WHBoxLayout", "WVBoxLayout", result); addText(tr("layout-WBoxLayout"), result); WContainerWidget *container; WText *item; WHBoxLayout *hbox; WVBoxLayout *vbox; /* * first hbox */ container = new WContainerWidget(result); container->setStyleClass("yellow-box"); hbox = new WHBoxLayout(); container->setLayout(hbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); hbox->addWidget(item); item = addText(tr("layout-item2")); item->setStyleClass("blue-box"); hbox->addWidget(item); addText(tr("layout-WBoxLayout-stretch"), result); /* * second hbox */ container = new WContainerWidget(result); container->setStyleClass("yellow-box"); hbox = new WHBoxLayout(); container->setLayout(hbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); hbox->addWidget(item, 1); item = addText(tr("layout-item2")); item->setStyleClass("blue-box"); hbox->addWidget(item); addText(tr("layout-WBoxLayout-vbox"), result); /* * first vbox */ container = new WContainerWidget(result); container->resize(150, 150); container->setStyleClass("yellow-box centered"); vbox = new WVBoxLayout(); container->setLayout(vbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); vbox->addWidget(item); item = addText(tr("layout-item2")); item->setStyleClass("blue-box"); vbox->addWidget(item); /* * second vbox */ container = new WContainerWidget(result); container->resize(150, 150); container->setStyleClass("yellow-box centered"); vbox = new WVBoxLayout(); container->setLayout(vbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); vbox->addWidget(item, 1); item = addText(tr("layout-item2")); item->setStyleClass("blue-box"); vbox->addWidget(item); addText(tr("layout-WBoxLayout-nested"), result); /* * nested boxes */ container = new WContainerWidget(result); container->resize(200, 200); container->setStyleClass("yellow-box centered"); vbox = new WVBoxLayout(); container->setLayout(vbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); vbox->addWidget(item, 1); hbox = new WHBoxLayout(); vbox->addLayout(hbox); item = addText(tr("layout-item2")); item->setStyleClass("green-box"); hbox->addWidget(item); item = addText(tr("layout-item3")); item->setStyleClass("blue-box"); hbox->addWidget(item); return result; }