Пример #1
0
ChatWidget::ChatWidget(const WEnvironment& env, SimpleChatServer& server)
  : WApplication(env),
    login_(this, "login")
{
  setCssTheme("");
  useStyleSheet("chatwidget.css");
  useStyleSheet("chatwidget_ie6.css", "lt IE 7");

  const std::string *div = env.getParameter("div");
  std::string defaultDiv = "div";
  if (!div)
   div = &defaultDiv;

  if (div) {
    setJavaScriptClass(*div);
    PopupChatWidget *chatWidget = new PopupChatWidget(server, *div);
    bindWidget(chatWidget, *div);

    login_.connect(chatWidget, &PopupChatWidget::setName);

    std::string chat = javaScriptClass();
    doJavaScript("if (window." + chat + "User) "
		 + chat + ".emit(" + chat + ", 'login', " + chat + "User);"
		 + "document.body.appendChild(" + chatWidget->jsRef() + ");");
  } else {
    std::cerr << "Missing: parameter: 'div'" << std::endl;
    quit();
  }
}
Пример #2
0
HelloApplication::HelloApplication(const WEnvironment& env, bool embedded)
  : WApplication(env)
{
  WContainerWidget *top;

  setTitle("Hello world");

  if (!embedded) {
    /*
     * In Application mode, we have the root() is a container
     * corresponding to the entire browser window
     */
    top = root();

  } else {
    /*
     * In WidgetSet mode, we create and bind containers to existing
     * divs in the web page. In this example, we create a single div
     * whose DOM id was passed as a request argument.
     */

      std::unique_ptr<WContainerWidget> topPtr
          = cpp14::make_unique<WContainerWidget>();
      top = topPtr.get();

      const std::string *div = env.getParameter("div");
      if (div) {
          setJavaScriptClass(*div);
          bindWidget(std::move(topPtr), *div);
      } else {
          std::cerr << "Missing: parameter: 'div'" << std::endl;
          return;
      }
  }


  if (!embedded)
    root()->addWidget(cpp14::make_unique<WText>(
       "<p><emph>Note: you can also run this application "
       "from within <a href=\"hello.html\">a web page</a>.</emph></p>"));

  /*
   * Everything else is business as usual.
   */

  top->addWidget(cpp14::make_unique<WText>("Your name, please ? "));
  nameEdit_ = top->addWidget(cpp14::make_unique<WLineEdit>());
  nameEdit_->setFocus();

  auto b = top->addWidget(cpp14::make_unique<WPushButton>("Greet me."));
  b->setMargin(5, Side::Left);

  top->addWidget(cpp14::make_unique<WBreak>());

  greeting_ = top->addWidget(cpp14::make_unique<WText>());

  /*
   * Connect signals with slots
   */
  b->clicked().connect(this, &HelloApplication::greet);
  nameEdit_->enterPressed().connect(this, &HelloApplication::greet);
}