Esempio n. 1
0
  /*! \brief Creates a title widget.
   */
  WText *createTitle(const WString& title) {
    WText *result = new WText(title);
    result->setInline(false);
    result->setStyleClass("title");

    return result;
  }
Esempio n. 2
0
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);
}
Esempio n. 3
0
void WTreeTable::addColumn(const WString& header, const WLength& width)
{
  if (treeRoot())
    throw WException("WTreeTable::addColumn(): must be called before "
		     "setTreeRoot()");

  WText *t = new WText(header);
  t->resize(width, WLength::Auto);
  t->setInline(false);
  t->setFloatSide(Left);
  headerContainer_->addWidget(t);

  columnWidths_.push_back(width);
}
Esempio n. 4
0
void WTreeTableNode::createExtraColumns(int numColumns)
{
  if (!row_) {
    row_ = new WContainerWidget();
    labelArea()->insertBefore(row_, labelArea()->children()[0]);
    row_->setFloatSide(Right);
    labelArea()->resize(WLength(100, WLength::Percentage), WLength::Auto);
    labelArea()->table()->resize(WLength(100, WLength::Percentage),
				 WLength::Auto);
  }

  while (static_cast<int>(columnWidgets_.size()) < numColumns) {
    WText *w = new WText(WString::fromUTF8(" "), row_);
    w->setInline(false);
    columnWidgets_.push_back(ColumnWidget(w, false));
    w->setFloatSide(Left);
    w->resize(columnWidth(columnWidgets_.size()), 1);
  }
}
Esempio n. 5
0
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;
}
Esempio n. 6
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();
  }
}