本文整理汇总了C++中WApplication::environment方法的典型用法代码示例。如果您正苦于以下问题:C++ WApplication::environment方法的具体用法?C++ WApplication::environment怎么用?C++ WApplication::environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WApplication
的用法示例。
在下文中一共展示了WApplication::environment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processAuthToken
User AuthModel::processAuthToken()
{
WApplication *app = WApplication::instance();
const WEnvironment& env = app->environment();
if (baseAuth()->authTokensEnabled()) {
const std::string *token =
env.getCookie(baseAuth()->authTokenCookieName());
if (token) {
AuthTokenResult result = baseAuth()->processAuthToken(*token, users());
switch(result.state()) {
case AuthTokenState::Valid: {
if (!result.newToken().empty()) {
/*
* Only extend the validity from what we had currently.
*/
app->setCookie(baseAuth()->authTokenCookieName(), result.newToken(),
result.newTokenValidity(), "", "", app->environment().urlScheme() == "https");
}
return result.user();
}
case AuthTokenState::Invalid:
app->setCookie(baseAuth()->authTokenCookieName(),std::string(), 0, "", "", app->environment().urlScheme() == "https");
return User();
}
}
}
return User();
}
示例2: exec
WDialog::DialogCode WDialog::exec(const WAnimation& animation)
{
if (recursiveEventLoop_)
throw WException("WDialog::exec(): already being executed.");
animateShow(animation);
#ifdef WT_TARGET_JAVA
if (!WebController::isAsyncSupported())
throw WException("WDialog#exec() requires a Servlet 3.0 enabled servlet "
"container and an application with async-supported "
"enabled.");
#endif
WApplication *app = WApplication::instance();
recursiveEventLoop_ = true;
if (app->environment().isTest()) {
app->environment().dialogExecuted().emit(this);
if (recursiveEventLoop_)
throw WException("Test case must close dialog");
} else {
do {
app->session()->doRecursiveEventLoop();
} while (recursiveEventLoop_);
}
hide();
return result_;
}
示例3: setImplementation
WDefaultLoadingIndicator::WDefaultLoadingIndicator()
{
setImplementation(std::unique_ptr<WWidget>
(new WText(tr("Wt.WDefaultLoadingIndicator.Loading"))));
setInline(false);
setStyleClass("Wt-loading");
WApplication *app = WApplication::instance();
app->styleSheet().addRule("div.Wt-loading",
"background-color: red; color: white;"
"font-family: Arial,Helvetica,sans-serif;"
"font-size: small;"
"position: absolute; right: 0px; top: 0px;");
app->styleSheet().addRule("body div > div.Wt-loading",
"position: fixed;");
if (app->environment().userAgent().find("MSIE 5.5") != std::string::npos
|| app->environment().userAgent().find("MSIE 6") != std::string::npos)
app->styleSheet().addRule
("div.Wt-loading",
"right: expression((("
"ignoreMe2 = document.documentElement.scrollLeft ? "
"document.documentElement.scrollLeft : "
"document.body.scrollLeft )) + 'px' );"
"top: expression((("
"ignoreMe = document.documentElement.scrollTop ? "
"document.documentElement.scrollTop : "
"document.body.scrollTop)) + 'px' );");
}
示例4: IndexContainerWidget
WWidget *WItemDelegate::createEditor(const WModelIndex& index,
WFlags<ViewItemRenderFlag> flags) const
{
IndexContainerWidget *const result =
new IndexContainerWidget(index);
result->setSelectable(true);
WLineEdit *lineEdit = new WLineEdit();
lineEdit->setText(asString(index.data(EditRole), textFormat_));
lineEdit->enterPressed().connect
(boost::bind(&WItemDelegate::doCloseEditor, this, result, true));
lineEdit->escapePressed().connect
(boost::bind(&WItemDelegate::doCloseEditor, this, result, false));
lineEdit->escapePressed().preventPropagation();
if (flags & RenderFocused)
lineEdit->setFocus(true);
// We use a layout so that the line edit fills the entire cell.
// Somehow, this does not work with konqueror, but it does respond
// properly to width, height being set to 100% !
WApplication *app = WApplication::instance();
if (app->environment().agent() != WEnvironment::Konqueror) {
result->setLayout(new WHBoxLayout());
result->layout()->setContentsMargins(1, 1, 1, 1);
result->layout()->addWidget(lineEdit);
} else {
lineEdit->resize(WLength(100, WLength::Percentage),
WLength(100, WLength::Percentage));
result->addWidget(lineEdit);
}
return result;
}
示例5: initTinyMCE
void WTextEdit::initTinyMCE()
{
const char *THIS_JS = "js/WTextEdit.js";
WApplication *app = WApplication::instance();
if (!app->javaScriptLoaded(THIS_JS)) {
if (app->environment().ajax())
app->doJavaScript("window.tinyMCE_GZ = { loaded: true };", false);
int version = getTinyMCEVersion();
std::string folder = version == 3 ? "tiny_mce/" : "tinymce/";
std::string jsFile = version == 3 ? "tiny_mce.js" : "tinymce.js";
std::string tinyMCEBaseURL = WApplication::relativeResourcesUrl() + folder;
WApplication::readConfigurationProperty("tinyMCEBaseURL", tinyMCEBaseURL);
if (!tinyMCEBaseURL.empty()
&& tinyMCEBaseURL[tinyMCEBaseURL.length()-1] != '/')
tinyMCEBaseURL += '/';
app->require(tinyMCEBaseURL + jsFile, "window['tinyMCE']");
app->styleSheet().addRule(".mceEditor",
"display: block; position: absolute;");
LOAD_JAVASCRIPT(app, THIS_JS, "WTextEdit", wtjs1);
}
}
示例6: setEmptyText
void WFormWidget::setEmptyText(const WString& emptyText)
{
emptyText_ = emptyText;
WApplication* app = WApplication::instance();
const WEnvironment& env = app->environment();
if (env.ajax()) {
if (!emptyText_.empty()) {
if (!flags_.test(BIT_JS_OBJECT))
defineJavaScript();
else
updateEmptyText();
if (!removeEmptyText_) {
removeEmptyText_ = new JSlot(this);
focussed().connect(*removeEmptyText_);
blurred().connect(*removeEmptyText_);
keyWentDown().connect(*removeEmptyText_);
std::string jsFunction =
"function(obj, event) {"
"""jQuery.data(" + jsRef() + ", 'obj').applyEmptyText();"
"}";
removeEmptyText_->setJavaScript(jsFunction);
}
} else {
delete removeEmptyText_;
removeEmptyText_ = 0;
}
} else {
setToolTip(emptyText);
}
}
示例7: updateContents
void WWidgetVectorPainter::updateContents(std::vector<DomElement *>& result,
WPaintDevice *device)
{
WVectorImage *vectorDevice = dynamic_cast<WVectorImage *>(device);
if (widget_->repaintFlags_ & PaintUpdate) {
DomElement *painter = DomElement::updateGiven
(WT_CLASS ".getElement('p" + widget_->id()+ "').firstChild",
DomElement_DIV);
painter->setProperty(PropertyAddedInnerHTML, vectorDevice->rendered());
WApplication *app = WApplication::instance();
if (app->environment().agentIsOpera())
painter->callMethod("forceRedraw();");
result.push_back(painter);
} else {
DomElement *canvas = DomElement::getForUpdate
('p' + widget_->id(), DomElement_DIV);
/*
* In fact, we should use another property, since we could be using
* document.importNode() instead of myImportNode() since the xml does not
* need to be interpreted as HTML...
*/
canvas->setProperty(PropertyInnerHTML, vectorDevice->rendered());
result.push_back(canvas);
}
widget_->sizeChanged_ = false;
delete device;
}
示例8: applyValidationStyle
void WCssTheme::applyValidationStyle(WWidget *widget,
const Wt::WValidator::Result& validation,
WFlags<ValidationStyleFlag> styles) const
{
WApplication *app = WApplication::instance();
LOAD_JAVASCRIPT(app, "js/CssThemeValidate.js", "validate", wtjs1);
LOAD_JAVASCRIPT(app, "js/CssThemeValidate.js", "setValidationState", wtjs2);
if (app->environment().ajax()) {
WStringStream js;
js << WT_CLASS ".setValidationState(" << widget->jsRef() << ","
<< (validation.state() == WValidator::Valid ? 1 : 0) << ","
<< validation.message().jsStringLiteral() << ","
<< styles.value() << ");";
widget->doJavaScript(js.str());
} else {
bool validStyle
= (validation.state() == WValidator::Valid) &&
(styles & ValidationValidStyle);
bool invalidStyle
= (validation.state() != WValidator::Valid) &&
(styles & ValidationInvalidStyle);
widget->toggleStyleClass("Wt-valid", validStyle);
widget->toggleStyleClass("Wt-invalid", invalidStyle);
}
}
示例9: loadAnimateJS
bool WStackedWidget::loadAnimateJS()
{
WApplication *app = WApplication::instance();
if (app->environment().supportsCss3Animations()) {
LOAD_JAVASCRIPT(app, "js/WStackedWidget.js", "WStackedWidget", wtjs1);
return true;
} else
return false;
}
示例10: render
void WDialog::render(WFlags<RenderFlag> flags)
{
if (flags & RenderFull) {
WApplication *app = WApplication::instance();
bool centerX = offset(Left).isAuto() && offset(Right).isAuto(),
centerY = offset(Top).isAuto() && offset(Bottom).isAuto();
/*
* Make sure layout adjusts to contents preferred width, especially
* important for IE workaround which uses static position scheme
*/
if (app->environment().ajax())
if (width().isAuto())
if (maximumWidth().unit() == WLength::Percentage ||
maximumWidth().toPixels() == 0)
impl_->resolveWidget("layout")->setMaximumSize(999999, maximumHeight());
doJavaScript("new " WT_CLASS ".WDialog("
+ app->javaScriptClass() + "," + jsRef()
+ "," + titleBar_->jsRef()
+ "," + (centerX ? "1" : "0")
+ "," + (centerY ? "1" : "0") + ");");
/*
* When a dialog is shown immediately for a new session, the recentering
* logic comes too late and causes a glitch. Thus we include directly in
* the HTML a JavaScript block to mitigate that
*/
if (!app->environment().agentIsIElt(9)) {
std::string js = WString::tr("Wt.WDialog.CenterJS").toUTF8();
Utils::replace(js, "$el", "'" + id() + "'");
Utils::replace(js, "$centerX", centerX ? "1" : "0");
Utils::replace(js, "$centerY", centerY ? "1" : "0");
impl_->bindString
("center-script", "<script>" + js + "</script>", XHTMLUnsafeText);
} else
impl_->bindEmpty("center-script");
}
WCompositeWidget::render(flags);
}
示例11: resourcesUrl
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;
}
示例12: doRedirect
void WPushButton::doRedirect()
{
WApplication *app = WApplication::instance();
if (!app->environment().ajax()) {
if (linkState_.link.type() == WLink::InternalPath)
app->setInternalPath(linkState_.link.internalPath().toUTF8(), true);
else
app->redirect(linkState_.link.url());
}
}
示例13: setRememberMeCookie
void AuthModel::setRememberMeCookie(const User& user)
{
WApplication *app = WApplication::instance();
const AuthService *s = baseAuth();
app->setCookie(s->authTokenCookieName(),
s->createAuthToken(user),
s->authTokenValidity() * 60,
s->authTokenCookieDomain(),
"",
app->environment().urlScheme() == "https");
}
示例14: setHidden
void MessageBox::setHidden(bool hidden, const WAnimation& animation)
{
if (hidden != hidden_) {
hidden_ = hidden;
WApplication *app = WApplication::instance();
if (!hidden)
setExposeMask(app);
else
restoreExposeMask(app);
if (hidden)
app->doJavaScript(elRef() + ".hide();");
else {
std::stringstream config;
config << "{a:0";
createConfig(config);
config << "}";
std::string var;
if (firstDisplay_) {
var = elRef() + "=Ext.Msg";
/* fix cursor problem in FF 1.5, 2 */
if (!app->environment().agentIsIE())
app->doJavaScript
("Ext.Msg.getDialog().on('show', function(d) {"
"var div = Ext.get(d.el);"
"div.setStyle('overflow', 'auto');"
"var text = div.select('.ext-mb-textarea', true);"
"if (!text.item(0))"
"text = div.select('.ext-mb-text', true);"
"if (text.item(0))"
"text.item(0).dom.select();});");
} else
var = elRef();
WApplication::instance()
->doJavaScript(var + ".show(" + config.str() + ");");
if (progress_) {
WApplication::instance()
->doJavaScript(elRef() + ".updateProgress("
+ boost::lexical_cast<std::string>(progressValue_)
+ ");");
}
firstDisplay_ = false;
}
}
}
示例15: gotTimeout
void WTimer::gotTimeout()
{
if (active_) {
if (!singleShot_) {
*timeout_ = Time() + static_cast<int>(interval_.count());
if (!timerWidget_->jsRepeat()) {
WApplication *app = WApplication::instance();
timerWidget_->timerStart(app->environment().ajax());
}
} else
stop();
}
}