Project

General

Profile

Bug #6958 ยป test.cpp

Diego Villalpando, 03/14/2019 08:53 PM

 
#include <Wt/WApplication>
#include <Wt/WServer>
#include <Wt/WContainerWidget>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WDialog>
#include <Wt/WHBoxLayout>
#include <Wt/WBootstrapTheme>


using namespace Wt;

class testApplication : public WApplication{
public:
testApplication(const WEnvironment& env);
};

testApplication::testApplication(const WEnvironment& env): WApplication(env){
WBootstrapTheme *boostrap = new WBootstrapTheme(wApp);
boostrap->setVersion(WBootstrapTheme::Version3);
this->setTheme(boostrap);

WDialog *d1 = new WDialog("Dialog 1",this);
d1->setWidth(350);
d1->setClosable(true);
d1->setModal(false);
d1->contents()->addWidget(new WText("Test Dialog 1"));

WPushButton *btn1 = new WPushButton("Show Dialog 1");
btn1->clicked().connect(d1, &WDialog::show);

WPushButton *btn2 = new WPushButton("Show Dialog 2");
btn2->clicked().connect(std::bind([=] {
WDialog *d2 = new WDialog("Dialog 2", this);
d2->setWidth(350);
d2->setClosable(true);
d2->setModal(false);
d2->contents()->addWidget(new WText("Test Dialog 2"));
d2->show();
}));

WContainerWidget *c1 = new WContainerWidget();
c1->addWidget(btn1);
c1->addWidget(btn2);

WContainerWidget *c2 = new WContainerWidget();
c2->decorationStyle().setBackgroundColor(lightGray);

WHBoxLayout *hlayout = new WHBoxLayout();
hlayout->addWidget(c1);
hlayout->addWidget(c2);
hlayout->setResizable(0);
root()->setLayout(hlayout);

}


Wt::WApplication *createApplication(const Wt::WEnvironment& env) {
return new testApplication(env);
}

int main(int argc, char **argv) {
const int webArgCount = 4;
char *webArgs[webArgCount];

//Exec Path
webArgs[0] = new char[(strlen(argv[0]) + 1)];
strncpy(webArgs[0], argv[0], (strlen(argv[0]) + 1));

//IP
std::string httpAdd = "--http-address=0.0.0.0";
webArgs[1] = new char[(strlen(httpAdd.c_str()) + 1)];
strncpy(webArgs[1], httpAdd.data(), (strlen(httpAdd.data()) + 1));

//Port
std::string httpPort = "--http-port=8080";
webArgs[2] = new char[(strlen(httpPort.c_str()) + 1)];
strncpy(webArgs[2], httpPort.data(), (strlen(httpPort.data()) + 1));

//doc root
std::string doc = "--docroot=C:\\projects\\P170-ims\\dev\\rt\\wt_test\\Debug;/resources";
webArgs[3] = new char[(strlen(doc.data()) + 1)];
strncpy(webArgs[3], doc.data(), (strlen(doc.data()) + 1));

try {
WServer server(argv[0]);
server.setServerConfiguration(webArgCount,webArgs, WTHTTP_CONFIGURATION);
server.addEntryPoint(Wt::Application, createApplication);
if (server.start()) {

while (true) {
std::string input;
std::getline(std::cin, input);

if (input.compare("quit") == 0) {
break;
}
}

server.stop();
}
}
catch (WServer::Exception& e) {
std::cerr << e.what() << "\n";
}
catch (std::exception& e) {
std::cerr << "exception: " << e.what() << "\n";
}

for (int i = 0; i < 4; i++) {
delete webArgs[i];
}

return 1;
}
    (1-1/1)