Example #1
0
StdGridLayoutImpl2::StdGridLayoutImpl2(WLayout *layout, Impl::Grid& grid)
  : StdLayoutImpl(layout),
    grid_(grid),
    needAdjust_(false),
    needRemeasure_(false),
    needConfigUpdate_(false)
{
  const char *THIS_JS = "js/StdGridLayoutImpl2.js";

  WApplication *app = WApplication::instance();

  if (!app->javaScriptLoaded(THIS_JS)) {
    app->styleSheet().addRule("table.Wt-hcenter", "margin: 0px auto;"
			      "position: relative");

    LOAD_JAVASCRIPT(app, THIS_JS, "StdLayout2", wtjs1);
    LOAD_JAVASCRIPT(app, THIS_JS, "layouts2", appjs1);

    app->doJavaScript(app->javaScriptClass() + ".layouts2.scheduleAdjust();");
    app->doJavaScript("$(window).load(function() { "
		      + app->javaScriptClass() + ".layouts2.scheduleAdjust();"
		      + "});");

    WApplication::instance()->addAutoJavaScript
      (app->javaScriptClass() + ".layouts2.adjustNow();");
  }
}
Example #2
0
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;
    }
  }
}
Example #3
0
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);
  }
}
Example #4
0
File: Widget.C Project: ReWeb3D/wt
Widget::~Widget()
{
  // to have virtual renderRemoveJs():
  setParentWidget(0);

  // in any case, delete Ext classes:
  WApplication *app = WApplication::instance();
  app->doJavaScript(app->javaScriptClass()
		    + ".deleteExtW('" + id() + "');");
}
Example #5
0
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();
  }
}
Example #6
0
void StdGridLayoutImpl2::updateDom(DomElement& parent)
{
  WApplication *app = WApplication::instance();

  if (needConfigUpdate_) {
    needConfigUpdate_ = false;

    DomElement *div = DomElement::getForUpdate(this, DomElement_DIV);

    for (unsigned i = 0; i < addedItems_.size(); ++i) {
      WLayoutItem *item = addedItems_[i];
      DomElement *c = createElement(item, app);
      div->addChild(c);
    }

    addedItems_.clear();

    for (unsigned i = 0; i < removedItems_.size(); ++i)
      parent.callJavaScript(WT_CLASS ".remove('" + removedItems_[i] + "');",
			    true);

    removedItems_.clear();

    parent.addChild(div);

    WStringStream js;
    js << app->javaScriptClass() << ".layouts2.updateConfig('"
       << id() << "',";
    streamConfig(js, app);
    js << ");";

    app->doJavaScript(js.str());
  }

  if (needRemeasure_) {
    needRemeasure_ = false;
    WStringStream js;
    js << app->javaScriptClass() << ".layouts2.setDirty('" << id() << "');";
    app->doJavaScript(js.str());
  }

  if (needAdjust_) {
    needAdjust_ = false;

    WStringStream js;
    js << app->javaScriptClass() << ".layouts2.adjust('" << id() << "', [";

    bool first = true;

    const unsigned colCount = grid_.columns_.size();
    const unsigned rowCount = grid_.rows_.size();

    for (unsigned row = 0; row < rowCount; ++row)
      for (unsigned col = 0; col < colCount; ++col)
	if (grid_.items_[row][col].update_) {
	  grid_.items_[row][col].update_ = false;
	  if (!first)
	    js << ",";
	  first = false;
	  js << "[" << (int)row << "," << (int)col << "]";
	}

    js << "]);";

    app->doJavaScript(js.str());
  }

  const unsigned colCount = grid_.columns_.size();
  const unsigned rowCount = grid_.rows_.size();

  for (unsigned i = 0; i < rowCount; ++i) {
    for (unsigned j = 0; j < colCount; ++j) {
      WLayoutItem *item = grid_.items_[i][j].item_;
      if (item) {
	WLayout *nested = item->layout();
	if (nested)
	  (dynamic_cast<StdLayoutImpl *>(nested->impl()))->updateDom(parent);
      }
    }
  }
}
Example #7
0
File: Widget.C Project: ReWeb3D/wt
void Widget::initExt()
{
  std::string extBaseURL = "ext";
  WApplication::readConfigurationProperty("extBaseURL", extBaseURL);

  if (!extBaseURL.empty() && extBaseURL[extBaseURL.length()-1] != '/')
    extBaseURL += '/';

  WApplication *app = WApplication::instance();

  if (app->require(extBaseURL + "ext-base.js", "window['Ext']")) {
    app->require(extBaseURL + "ext-all.js", "window.Ext['DomHelper']");
    app->useStyleSheet(extBaseURL + "resources/css/ext-all.css");

    // fixes for Firefox 3:
    app->styleSheet().addRule(".x-date-middle", "width:130px;");

    // rendering glitches on all browsers:
    app->styleSheet().addRule(".ext-gecko .x-form-text", "margin-top: -1px;");
    app->styleSheet().addRule(".ext-safari .x-form-text", "margin-top: -1px;");
    app->styleSheet().addRule(".ext-ie .x-form-text",
			      "margin-top: 0px !important;"
			      "margin-bottom: 0px !important;");
    app->doJavaScript(/*app->javaScriptClass() + '.' + */ "ExtW = new Array();"
		      "Ext.QuickTips.init();"
		      "Ext.BLANK_IMAGE_URL='" + extBaseURL 
		      + "resources/images/default/s.gif';", false);
    app->declareJavaScriptFunction("deleteExtW",
				   "" "function(id){"
				   ""   "var w=ExtW[id];"
				   ""   "if(w){"
				   ""      "if (w.el && w.destroy) w.destroy();"
				   ""      "delete ExtW[id];"
				   ""   "}"
				   "" "}");

    if (app->environment().agentIsIE())
      app->doJavaScript
	("if ((typeof Range !== 'undefined')"
	 ""    "&& !Range.prototype.createContextualFragment) {"
	 """Range.prototype.createContextualFragment = function(html) {"
	 ""  "var startNode = this.startContainer;"
	 ""  "var doc = startNode.nodeType == 9 ? startNode :"
	 ""            "startNode.ownerDocument;"
	 ""  "var container = doc.createElement('div');"
	 ""  "container.innerHTML = html;"
	 ""  "var frag = doc.createDocumentFragment(), n;"
	 ""  "while ( (n = container.firstChild) ) {"
	 ""    "frag.appendChild(n);"
	 ""  "}"
	 ""  "return frag;"
	 """};"
	 "}", false);
    /*
     * Normally, Ext does this in its onReady function, but this is not
     * fired when loading ExtJS on demand.
     */
    std::string bodyClass;
    if (app->environment().agentIsIE()) {
      bodyClass = " ext-ie ";
      bodyClass += app->environment().agent() == WEnvironment::IE6
	? "ext-ie6" : "ext-ie7 ";
    } else if (app->environment().agentIsSafari())
      bodyClass = " ext-safari";
    else if (app->environment().agentIsOpera())
      bodyClass = " ext-opera";
    else if (app->environment().agentIsGecko())
      bodyClass = " ext-gecko";

    const std::string& ua = app->environment().userAgent();

    if (ua.find("Linux") != std::string::npos)
      bodyClass += " ext-linux";
    if (ua.find("Macintosh") != std::string::npos
	|| ua.find("Mac OS X") != std::string::npos)
      bodyClass += " ext-mac";
    
    app->setBodyClass(app->bodyClass() + bodyClass);
    app->setHtmlClass(app->htmlClass() + " ext-strict");
  }
}