void WDialog::setHidden(bool hidden, const WAnimation& animation) { if (isHidden() != hidden) { if (modal_) { WApplication *app = WApplication::instance(); WContainerWidget *cover = app->dialogCover(); if (!cover) return; // when application is being destroyed if (!hidden) { saveCoverState(app, cover); if (cover->isHidden()) { if (!animation.empty()) { cover->animateShow(WAnimation(WAnimation::Fade, WAnimation::Linear, animation.duration() * 4)); } else cover->show(); } cover->setZIndex(impl_->zIndex() - 1); app->pushExposedConstraint(this); // FIXME: this should only blur if the active element is outside // of the dialog doJavaScript ("try {" """var ae=document.activeElement;" // On IE when a dialog is shown on startup, activeElement is the // body. Bluring the body sends the window to the background if // it is the only tab. // http://redmine.emweb.be/boards/2/topics/6415 """if (ae && ae.blur && ae.nodeName != 'BODY') {" "" "document.activeElement.blur();" "}" "} catch (e) { }"); } else restoreCoverState(app, cover); } } WPopupWidget::setHidden(hidden, animation); }
void WDialog::setHidden(bool hidden, const WAnimation& animation) { if (isHidden() != hidden) { if (modal_) { WApplication *app = WApplication::instance(); WContainerWidget *cover = app->dialogCover(); if (!cover) return; // when application is being destroyed if (!hidden) { saveCoverState(app, cover); if (cover->isHidden()) { if (!animation.empty()) { cover->animateShow(WAnimation(WAnimation::Fade, WAnimation::Linear, animation.duration() * 4)); } else cover->show(); } cover->setZIndex(impl_->zIndex() - 1); app->pushExposedConstraint(this); // FIXME: this should only blur if the active element is outside // of the dialog doJavaScript ("try {" """if (document.activeElement && document.activeElement.blur)" "" "document.activeElement.blur();" "} catch (e) { }"); } else restoreCoverState(app, cover); } } WCompositeWidget::setHidden(hidden, animation); }
void WDialog::create() { closeIcon_ = 0; footer_ = 0; modal_ = true; resizable_ = false; recursiveEventLoop_ = false; impl_ = dynamic_cast<WTemplate *>(implementation()); const char *CSS_RULES_NAME = "Wt::WDialog"; WApplication *app = WApplication::instance(); if (!app->styleSheet().isDefined(CSS_RULES_NAME)) { /* Needed for the dialog cover */ if (app->environment().agentIsIElt(9)) app->styleSheet().addRule("body", "height: 100%;"); std::string position = app->environment().agent() == WEnvironment::IE6 ? "absolute" : "fixed"; // we use left: 50%, top: 50%, margin hack when JavaScript is not available // see below for an IE workaround app->styleSheet().addRule("div.Wt-dialog", std::string() + (app->environment().ajax() ? "visibility: hidden;" : "") //"position: " + position + ';' + (!app->environment().ajax() ? "left: 50%; top: 50%;" "margin-left: -100px; margin-top: -50px;" : "left: 0px; top: 0px;"), CSS_RULES_NAME); if (app->environment().agent() == WEnvironment::IE6) { app->styleSheet().addRule ("div.Wt-dialogcover", "position: absolute;" "left: expression(" "(ignoreMe2 = document.documentElement.scrollLeft) + 'px' );" "top: expression(" "(ignoreMe = document.documentElement.scrollTop) + 'px' );"); // simulate position: fixed left: 50%; top 50% if (!app->environment().ajax()) app->styleSheet().addRule ("div.Wt-dialog", "position: absolute;" "left: expression(" "(ignoreMe2 = document.documentElement.scrollLeft + " "document.documentElement.clientWidth/2) + 'px' );" "top: expression(" "(ignoreMe = document.documentElement.scrollTop + " "document.documentElement.clientHeight/2) + 'px' );"); } } LOAD_JAVASCRIPT(app, "js/WDialog.js", "WDialog", wtjs1); WContainerWidget *layoutContainer = new WContainerWidget(); layoutContainer->setStyleClass("dialog-layout"); WVBoxLayout *layout = new WVBoxLayout(layoutContainer); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); impl_->bindWidget("layout", layoutContainer); titleBar_ = new WContainerWidget(); app->theme()->apply(this, titleBar_, DialogTitleBarRole); caption_ = new WText(titleBar_); caption_->setInline(false); contents_ = new WContainerWidget(); app->theme()->apply(this, contents_, DialogBodyRole); layout->addWidget(titleBar_); layout->addWidget(contents_, 1); saveCoverState(app, app->dialogCover()); /* * Cannot be done using the CSS stylesheet in case there are * contained elements with setHideWithOffsets() set * * For IE, we cannot set it yet since it will confuse width measurements * to become minimum size instead of (unconstrained) preferred size */ if (app->environment().ajax()) { setAttributeValue("style", "visibility: hidden"); /* * This is needed for animations only, but setting absolute or * fixed positioning confuses layout measurement in IE browsers */ if (!app->environment().agentIsIElt(9)) setPositionScheme(Fixed); } else setPositionScheme(app->environment().agent() == WEnvironment::IE6 ? Absolute : Fixed); }