void WStackedWidget::defineJavaScript() { if (!javaScriptDefined_) { javaScriptDefined_ = true; WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WStackedWidget.js", "WStackedWidget", wtjs1); setJavaScriptMember(" WStackedWidget", "new " WT_CLASS ".WStackedWidget(" + app->javaScriptClass() + "," + jsRef() + ");"); setJavaScriptMember(WT_RESIZE_JS, "$('#" + id() + "').data('obj').wtResize"); setJavaScriptMember(WT_GETPS_JS, "$('#" + id() + "').data('obj').wtGetPs"); if (!animation_.empty()) { loadAnimateJS(); setJavaScriptMember("wtAnimateChild", "$('#" + id() + "').data('obj').animateChild"); setJavaScriptMember("wtAutoReverse", autoReverseAnimation_ ? "true" : "false"); } } }
void WStackedWidget::loadAnimateJS() { if (!loadAnimateJS_) { loadAnimateJS_ = true; if (javaScriptDefined_) { LOAD_JAVASCRIPT(WApplication::instance(), "js/WStackedWidget.js", "WStackedWidget.prototype.animateChild", wtjs2); setJavaScriptMember("wtAnimateChild", "$('#" + id() + "').data('obj').animateChild"); setJavaScriptMember("wtAutoReverse", autoReverseAnimation_ ? "true" : "false"); } } }
void WStackedWidget::setTransitionAnimation(const WAnimation& animation, bool autoReverse) { if (loadAnimateJS()) { if (!animation.empty()) addStyleClass("Wt-animated"); animation_ = animation; autoReverseAnimation_ = autoReverse; setJavaScriptMember("wtAnimateChild", WT_CLASS ".WStackedWidget.animateChild"); setJavaScriptMember("wtAutoReverse", autoReverseAnimation_ ? "true" : "false"); } }
void WTextEdit::init() { WApplication *app = WApplication::instance(); setInline(false); initTinyMCE(); version_ = getTinyMCEVersion(); setJavaScriptMember(" WTextEdit", "new " WT_CLASS ".WTextEdit(" + app->javaScriptClass() + "," + jsRef() + ");"); setJavaScriptMember (WT_RESIZE_JS, "function(e, w, h) { var obj = $('#" + id() + "').data('obj'); " "obj.wtResize(e, w, h); };"); std::string direction = app->layoutDirection() == LayoutDirection::LeftToRight ? "ltr" : "rtl"; setConfigurationSetting("directionality", direction); std::string toolbar; if (version_ < 4) toolbar = "fontselect,|,bold,italic,underline,|,fontsizeselect,|" ",forecolor,backcolor,|" ",justifyleft,justifycenter,justifyright,justifyfull,|,anchor,|" ",numlist,bullist"; else toolbar = "undo redo | styleselect | bold italic | link"; setToolBar(0, toolbar); for (int i = 1; i <= 3; i++) setToolBar(i, std::string()); setConfigurationSetting("doctype", wApp->docType()); setConfigurationSetting("relative_urls", true); if (version_ < 4) { //this setting is no longer mentioned in the tinymce documenation though... setConfigurationSetting("button_tile_map", true); setConfigurationSetting("theme", std::string("advanced")); setConfigurationSetting("theme_advanced_toolbar_location", std::string("top")); setConfigurationSetting("theme_advanced_toolbar_align", std::string("left")); } onChange_.connect(this, &WTextEdit::propagateOnChange); }
void WTabWidget::create() { setImplementation(layout_ = new WContainerWidget()); menu_ = new WMenu(new WStackedWidget()); layout_->addWidget(menu_); layout_->addWidget(menu_->contentsStack()); setJavaScriptMember(WT_RESIZE_JS, StdWidgetItemImpl::secondResizeJS()); setJavaScriptMember(WT_GETPS_JS, StdWidgetItemImpl::secondGetPSJS()); menu_->itemSelected().connect(this, &WTabWidget::onItemSelected); menu_->itemClosed().connect(this, &WTabWidget::onItemClosed); }
void WStackedWidget::setCurrentIndex(int index, const WAnimation& animation, bool autoReverse) { if (!animation.empty() && loadAnimateJS() && (isRendered() || !canOptimizeUpdates())) { if (canOptimizeUpdates() && index == currentIndex_) return; WWidget *previous = currentWidget(); setJavaScriptMember("wtAutoReverse", autoReverse ? "true" : "false"); if (previous) previous->animateHide(animation); widget(index)->animateShow(animation); currentIndex_ = index; } else { currentIndex_ = index; for (int i = 0; i < count(); ++i) if (widget(i)->isHidden() != (currentIndex_ != i)) widget(i)->setHidden(currentIndex_ != i); if (isRendered()) doJavaScript("$('#" + id() + "').data('obj').setCurrent(" + widget(currentIndex_)->jsRef() + ");"); } }
void WTabWidget::create() { layout_ = new WContainerWidget(); setImplementation(std::unique_ptr<WWidget>(layout_)); std::unique_ptr<WStackedWidget> stack(new WStackedWidget()); menu_ = new WMenu(stack.get()); layout_->addWidget(std::unique_ptr<WWidget>(menu_)); layout_->addWidget(std::move(stack)); setJavaScriptMember(WT_RESIZE_JS, StdWidgetItemImpl::secondResizeJS()); setJavaScriptMember(WT_GETPS_JS, StdWidgetItemImpl::secondGetPSJS()); menu_->itemSelected().connect(this, &WTabWidget::onItemSelected); menu_->itemClosed().connect(this, &WTabWidget::onItemClosed); }
void WStackedWidget::setCurrentIndex(int index, const WAnimation& animation, bool autoReverse) { if (!animation.empty() && WApplication::instance()->environment().supportsCss3Animations() && ((isRendered() && javaScriptDefined_) || !canOptimizeUpdates())) { if (canOptimizeUpdates() && index == currentIndex_) return; loadAnimateJS(); WWidget *previous = currentWidget(); doJavaScript("$('#" + id() + "').data('obj').adjustScroll(" + widget(currentIndex_)->jsRef() + ");"); setJavaScriptMember("wtAutoReverse", autoReverse ? "true" : "false"); if (previous) previous->animateHide(animation); widget(index)->animateShow(animation); currentIndex_ = index; } else { currentIndex_ = index; for (int i = 0; i < count(); ++i) if (widget(i)->isHidden() != (currentIndex_ != i)) widget(i)->setHidden(currentIndex_ != i); if (currentIndex_ >= 0 && isRendered() && javaScriptDefined_) doJavaScript("$('#" + id() + "').data('obj').setCurrent(" + widget(currentIndex_)->jsRef() + ");"); } }
void WTabWidget::create(WFlags<AlignmentFlag> layoutAlignment) { setImplementation(layout_ = new WContainerWidget()); WT_DEBUG( setObjectName("WTabWidget") ); menu_ = new WMenu(new WStackedWidget(), Horizontal); menu_->setRenderAsList(true); WContainerWidget *menuDiv = new WContainerWidget(); menuDiv->setStyleClass("Wt-tabs"); menuDiv->addWidget(menu_); layout_->addWidget(menuDiv); layout_->addWidget(menu_->contentsStack()); setJavaScriptMember (WT_RESIZE_JS, std::string() + "function(self, w, h) {" """self.style.height= h + 'px';" """var c = self.firstChild;" """var t = self.lastChild;" """h -= c.offsetHeight + " WT_CLASS ".px(c, 'marginTop') " "" "+ " WT_CLASS ".px(c, 'marginBottom');" """if (h > 0)" "" "t." + WT_RESIZE_JS + "(t, w, h);" "};"); menu_->itemSelected().connect(this, &WTabWidget::onItemSelected); menu_->itemClosed().connect(this, &WTabWidget::onItemClosed); }
void WPopupMenu::prepareRender(WApplication *app) { if (app->environment().agentIsIE()) { doJavaScript(jsRef() + ".lastChild.style.width=" + jsRef() + ".lastChild.offsetWidth + 'px';"); } // FIXME: we should really also prepareRender() of submenus when shown... if (!cancel_.isConnected()) { LOAD_JAVASCRIPT(app, "js/WPopupMenu.js", "WPopupMenu", wtjs1); std::vector<WPopupMenu *> subMenus; getSubMenus(subMenus); WStringStream s; s << "new " WT_CLASS ".WPopupMenu(" << app->javaScriptClass() << ',' << jsRef() << ',' << autoHideDelay_ << ",["; for (unsigned i = 0; i < subMenus.size(); ++i) { if (i != 0) s << ','; s << WWebWidget::jsStringLiteral(subMenus[i]->id()); } s << "]);"; setJavaScriptMember(" WPopupMenu", s.str()); cancel_.connect(this, &WPopupMenu::done); } }
void WLineEdit::defineJavaScript() { if (javaScriptDefined_) return; javaScriptDefined_ = true; WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WLineEdit.js", "WLineEdit", wtjs1); std::u32string space; space += spaceChar_; std::string jsObj = "new " WT_CLASS ".WLineEdit(" + app->javaScriptClass() + "," + jsRef() + "," + WWebWidget::jsStringLiteral(mask_) + "," + WWebWidget::jsStringLiteral(raw_) + "," + WWebWidget::jsStringLiteral(displayContent_) + "," + WWebWidget::jsStringLiteral(case_) + "," + WWebWidget::jsStringLiteral(space) + "," + (inputMaskFlags_.test(InputMaskFlag::KeepMaskWhileBlurred) ? "0x1" : "0x0") + ");"; setJavaScriptMember(" WLineEdit", jsObj); #ifdef WT_CNOR EventSignalBase& b = mouseMoved(); EventSignalBase& c = keyWentDown(); #endif connectJavaScript(keyWentDown(), "keyDown"); connectJavaScript(keyPressed(), "keyPressed"); connectJavaScript(focussed(), "focussed"); connectJavaScript(blurred(), "blurred"); connectJavaScript(clicked(), "clicked"); }
WPaintedWidget::WPaintedWidget(WContainerWidget *parent) : WInteractWidget(parent), preferredMethod_(HtmlCanvas), painter_(0), needRepaint_(false), sizeChanged_(false), areaImageAdded_(false), repaintFlags_(0), areaImage_(0), renderWidth_(0), renderHeight_(0) { if (WApplication::instance()) { const WEnvironment& env = WApplication::instance()->environment(); if (env.agentIsOpera() && env.userAgent().find("Mac OS X") == std::string::npos) preferredMethod_ = InlineSvgVml; } setLayoutSizeAware(true); setJavaScriptMember(WT_RESIZE_JS, "function(self, w, h) {" """var u = $(self).find('canvas, img');" """if (w >= 0) " "" "u.width(w);" """if (h >= 0) " "" "u.height(h);" "}"); setInline(false); }
void WTreeTable::defineJavaScript() { WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WTreeTable.js", "WTreeTable", wtjs1); setJavaScriptMember(" WTreeTable", "new " WT_CLASS ".WTreeTable(" + app->javaScriptClass() + "," + jsRef() + ");"); }
WAbstractSpinBox::WAbstractSpinBox(WContainerWidget *parent) : WLineEdit(parent), changed_(false), valueChangedConnection_(false), preferNative_(false), setup_(false) { setJavaScriptMember("_a", "0"); }
void WFormWidget::setToolTip(const WString& text, TextFormat textFormat) { WInteractWidget::setToolTip(text, textFormat); if (validator_ && textFormat == PlainText) { setJavaScriptMember("defaultTT", text.jsStringLiteral()); validate(); } }
void WStackedWidget::setTransitionAnimation(const WAnimation& animation, bool autoReverse) { if (loadAnimateJS()) { if (!animation.empty()) addStyleClass("Wt-animated"); animation_ = animation; autoReverseAnimation_ = autoReverse; if (isRendered()) { setJavaScriptMember("wtAnimateChild", "$('#" + id() + "').data('obj').animateChild"); setJavaScriptMember("wtAutoReverse", autoReverseAnimation_ ? "true" : "false"); } } }
WStackedWidget::WStackedWidget(WContainerWidget *parent) : WContainerWidget(parent), currentIndex_(-1) { WT_DEBUG( setObjectName("WStackedWidget") ); setJavaScriptMember(WT_RESIZE_JS, StdGridLayoutImpl::childrenResizeJS()); addStyleClass("Wt-stack"); }
void WPopupWidget::defineJavaScript() { WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WPopupWidget.js", "WPopupWidget", wtjs1); WStringStream jsObj; jsObj << "new " WT_CLASS ".WPopupWidget(" << app->javaScriptClass() << ',' << jsRef() << ',' << transient_ << ',' << autoHideDelay_ << ',' << !isHidden() << ");"; setJavaScriptMember(" WPopupWidget", jsObj.str()); }
void WSuggestionPopup::defineJavaScript() { WApplication *app = WApplication::instance(); const char *THIS_JS = "js/WSuggestionPopup.js"; LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopup", wtjs1); LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopupStdMatcher", wtjs2); setJavaScriptMember(" WSuggestionPopup", "new " WT_CLASS ".WSuggestionPopup(" + app->javaScriptClass() + "," + jsRef() + "," + replacerJS_ + "," + matcherJS_ + "," + boost::lexical_cast<std::string>(filterLength_) + "," + boost::lexical_cast<std::string>(defaultValue_) + ");"); }
void WAbstractSpinBox::defineJavaScript() { WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WSpinBox.js", "WSpinBox", wtjs1); std::string jsObj = "new " WT_CLASS ".WSpinBox(" + app->javaScriptClass() + "," + jsRef() + "," + boost::lexical_cast<std::string>(decimals()) + "," + prefix().jsStringLiteral() + "," + suffix().jsStringLiteral() + "," + jsMinMaxStep() + ");"; setJavaScriptMember("_a", "0;" + jsObj); }
void WTreeTable::render(WFlags<RenderFlag> flags) { if (flags.test(RenderFlag::Full)) { defineJavaScript(); setJavaScriptMember(WT_RESIZE_JS, jsRef() + ".wtObj.wtResize"); resize(width(), height()); WApplication::instance()->addAutoJavaScript ("{var obj = " + jsRef() + ";" "if (obj && obj.wtObj) obj.wtObj.autoJavaScript();}"); } WCompositeWidget::render(flags); }
void WTreeTable::render(WFlags<RenderFlag> flags) { if (flags & RenderFull) { defineJavaScript(); setJavaScriptMember(WT_RESIZE_JS, "$('#" + id() + "').data('obj').wtResize"); resize(width(), height()); WApplication::instance()->addAutoJavaScript ("{var obj = $('#" + id() + "').data('obj');" "if (obj) obj.autoJavaScript();}"); } WCompositeWidget::render(flags); }
void WFormWidget::defineJavaScript(bool force) { if (force || !flags_.test(BIT_JS_OBJECT)) { flags_.set(BIT_JS_OBJECT); if (!isRendered()) return; WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WFormWidget.js", "WFormWidget", wtjs1); setJavaScriptMember(" WFormWidget", "new " WT_CLASS ".WFormWidget(" + app->javaScriptClass() + "," + jsRef() + "," + emptyText_.jsStringLiteral() + ");"); } }
void WAbstractSpinBox::defineJavaScript() { WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WSpinBox.js", "WSpinBox", wtjs1); WStringStream ss; ss << "new " WT_CLASS ".WSpinBox(" << app->javaScriptClass() << "," << jsRef() << "," << decimals() << "," << prefix().jsStringLiteral() << "," << suffix().jsStringLiteral() << "," << jsMinMaxStep() << "," << jsStringLiteral(WLocale::currentLocale().decimalPoint()) << "," << jsStringLiteral(WLocale::currentLocale().groupSeparator()) << ");"; setJavaScriptMember(" WSpinBox", ss.str()); }
void WSuggestionPopup::defineJavaScript() { WApplication *app = WApplication::instance(); const char *THIS_JS = "js/WSuggestionPopup.js"; LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopup", wtjs1); LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopupStdMatcher", wtjs2); std::string ddUnfiltered = isDropDownIconUnfiltered_ ? "true" : "false"; setJavaScriptMember(" WSuggestionPopup", "new " WT_CLASS ".WSuggestionPopup(" + app->javaScriptClass() + "," + jsRef() + "," + replacerJS_ + "," + matcherJS_ + "," + boost::lexical_cast<std::string> (std::max(0, filterLength_)) + "," + boost::lexical_cast<std::string>(partialResults()) + "," + boost::lexical_cast<std::string>(defaultValue_) + "," + ddUnfiltered + ");"); }
void WFormWidget::validatorChanged() { std::string validateJS = validator_->javaScriptValidate(); if (!validateJS.empty()) { setJavaScriptMember("wtValidate", validateJS); if (!validateJs_) { validateJs_ = new JSlot(); validateJs_->setJavaScript("function(o){" WT_CLASS ".validate(o)}"); keyWentUp().connect(*validateJs_); changed().connect(*validateJs_); if (domElementType() != DomElement_SELECT) clicked().connect(*validateJs_); } else if (isRendered()) validateJs_->exec(jsRef()); } else { delete validateJs_; validateJs_ = 0; } std::string inputFilter = validator_->inputFilter(); if (!inputFilter.empty()) { if (!filterInput_) { filterInput_ = new JSlot(); keyPressed().connect(*filterInput_); } Wt::Utils::replace(inputFilter, '/', "\\/"); filterInput_->setJavaScript ("function(o,e){" WT_CLASS ".filter(o,e," + jsStringLiteral(inputFilter) + ")}"); } else { delete filterInput_; filterInput_ = 0; } validate(); }
void WPopupMenu::prepareRender(WApplication *app) { if (!cancel_.isConnected()) { LOAD_JAVASCRIPT(app, "js/WPopupMenu.js", "WPopupMenu", wtjs1); WStringStream s; s << "new " WT_CLASS ".WPopupMenu(" << app->javaScriptClass() << ',' << jsRef() << ',' << autoHideDelay_ << ");"; setJavaScriptMember(" WPopupMenu", s.str()); cancel_.connect(this, &WPopupMenu::cancel); connectSignals(this); } adjustPadding(); }
void WDialog::setResizable(bool resizable) { if (resizable != resizable_) { resizable_ = resizable; toggleStyleClass("Wt-resizable", resizable); setSelectable(!resizable); if (resizable) contents_->setSelectable(true); if (resizable_) { Resizable::loadJavaScript(WApplication::instance()); setJavaScriptMember (" Resizable", "(new " WT_CLASS ".Resizable(" WT_CLASS "," + jsRef() + ")).onresize(function(w, h) {" "var obj = $('#" + id() + "').data('obj');" "if (obj) obj.onresize(w, h);" " });"); } } }
void WDateEdit::defineJavaScript() { WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WDateEdit.js", "WDateEdit", wtjs1); std::string jsObj = "new " WT_CLASS ".WDateEdit(" + app->javaScriptClass() + "," + jsRef() + "," + popup_->jsRef() + ");"; setJavaScriptMember(" WDateEdit", jsObj); #ifdef WT_CNOR EventSignalBase& b = mouseMoved(); EventSignalBase& c = keyWentDown(); #endif connectJavaScript(mouseMoved(), "mouseMove"); connectJavaScript(mouseWentUp(), "mouseUp"); connectJavaScript(mouseWentDown(), "mouseDown"); connectJavaScript(mouseWentOut(), "mouseOut"); }
void WFileUpload::create() { // NOTE: this is broken on konqueror: you cannot target a form anymore bool methodIframe = WApplication::instance()->environment().ajax(); if (methodIframe) { fileUploadTarget_ = new WFileUploadResource(this); fileUploadTarget_->setUploadProgress(true); fileUploadTarget_->dataReceived().connect(this, &WFileUpload::onData); setJavaScriptMember(WT_RESIZE_JS, "function(self, w, h) {" """if (w >= 0) " "" "$(self).find('input').width(w);" "}"); } else fileUploadTarget_ = 0; setFormObject(!fileUploadTarget_); uploaded().connect(this, &WFileUpload::onUploaded); fileTooLarge().connect(this, &WFileUpload::onUploaded); }