53 lines
1.8 KiB
C++
53 lines
1.8 KiB
C++
#include "Hello.h"
|
|
#include "BoostLog.h"
|
|
#include <Wt/WContainerWidget.h>
|
|
#include <Wt/WEnvironment.h>
|
|
#include <Wt/WLineEdit.h>
|
|
#include <Wt/WPushButton.h>
|
|
#include <Wt/WText.h>
|
|
|
|
Hello::Hello(const Wt::WEnvironment &env, bool embedded) : Wt::WApplication(env) {
|
|
setTitle("Hello world");
|
|
Wt::WContainerWidget *top = nullptr;
|
|
if (!embedded) {
|
|
top = root();
|
|
} else {
|
|
std::unique_ptr<Wt::WContainerWidget> topPtr = std::make_unique<Wt::WContainerWidget>();
|
|
top = topPtr.get();
|
|
const std::string *div = env.getParameter("div");
|
|
if (div) {
|
|
setJavaScriptClass(*div);
|
|
bindWidget(std::move(topPtr), *div);
|
|
} else {
|
|
LOG(error) << "Missing: parameter: 'div'";
|
|
}
|
|
LOG(info) << "url: " << url();
|
|
LOG(info) << "relative resources url: " << relativeResourcesUrl();
|
|
LOG(info) << "resources url: " << resourcesUrl();
|
|
url();
|
|
}
|
|
|
|
if (!embedded) {
|
|
root()->addWidget(std::make_unique<Wt::WText>("<p><emph>Note: you can also run this application "
|
|
"from within <a href=\"hello.html\">a web page</a>.</emph></p>"));
|
|
}
|
|
|
|
top->addWidget(std::make_unique<Wt::WText>("Your name, please ? "));
|
|
m_nameEdit = top->addWidget(std::make_unique<Wt::WLineEdit>());
|
|
m_nameEdit->setFocus();
|
|
|
|
auto b = top->addWidget(std::make_unique<Wt::WPushButton>("点击我!"));
|
|
b->setMargin(5, Wt::Side::Left);
|
|
|
|
top->addWidget(std::make_unique<Wt::WBreak>());
|
|
|
|
m_greeting = top->addWidget(std::make_unique<Wt::WText>());
|
|
|
|
b->clicked().connect(this, &Hello::greet);
|
|
m_nameEdit->enterPressed().connect(this, &Hello::greet);
|
|
}
|
|
|
|
void Hello::greet() {
|
|
m_greeting->setText("Hello there, " + m_nameEdit->text());
|
|
}
|