Project

General

Profile

Bug #7974 » main.cpp

Stefan Bn, 11/04/2021 02:49 PM

 
1
#include <Wt/WApplication.h>
2
#include <Wt/WBootstrapTheme.h>
3
#include <Wt/WServer.h>
4

    
5
#include <Wt/WContainerWidget.h>
6
#include <Wt/WText.h>
7
#include <Wt/WHBoxLayout.h>
8
#include <Wt/WPushButton.h>
9
#include <Wt/WPopupMenu.h>
10

    
11

    
12
using namespace Wt;
13

    
14

    
15

    
16
// -----------------------------------------------------------------------------------
17
std::unique_ptr<WApplication> createHelloApplication(const WEnvironment &env)
18
{
19
    auto app = std::make_unique<Wt::WApplication>(env);
20

    
21
    auto theme = std::make_shared<Wt::WBootstrapTheme>();
22
    theme->setVersion(Wt::BootstrapVersion::v3);
23
    app->setTheme(theme);
24

    
25
    WHBoxLayout *mainLayout = app->root()->setLayout(std::make_unique<WHBoxLayout>());
26

    
27
    auto leftCont = mainLayout->addWidget(std::make_unique<WContainerWidget>(), 1);
28
    leftCont->setOverflow(Overflow::Auto);
29
    leftCont->addWidget(std::make_unique<WText>("Left Container"));
30

    
31
    auto toolsCont = leftCont->addWidget(std::make_unique<WContainerWidget>());
32
    auto toolsLayout = toolsCont->setLayout(std::make_unique<WHBoxLayout>());
33

    
34
    toolsLayout->addWidget(std::make_unique<WText>("Click the right button to dipslay the popup"), 1);
35

    
36
    auto toolsPopup = std::make_unique<WPopupMenu>();
37

    
38
    toolsPopup->addItem("Long Long Long Demo Item 1");
39
    toolsPopup->addItem("Long Long Long Demo Item 2");
40
    toolsPopup->addItem("Long Long Long Demo Item 3");
41
    toolsPopup->addItem("Long Long Long Demo Item 4");
42
    toolsPopup->addItem("Long Long Long Demo Item 5");
43

    
44
    auto popupBt = toolsLayout->addWidget(std::make_unique<WPushButton>("Click here"));
45
    popupBt->setMenu(std::move(toolsPopup));
46

    
47
    for (int i = 0; i < 100; i++)
48
        leftCont->addWidget(std::make_unique<WText>("Popup Error Sample Line " + std::to_string(i)))->setInline(false);
49

    
50
    auto rightCont = mainLayout->addWidget(std::make_unique<WContainerWidget>());
51
    rightCont->setWidth(200);
52
    rightCont->addWidget(std::make_unique<WText>("Right Container"));
53

    
54
    return app;
55
}
56

    
57

    
58
// -----------------------------------------------------------------------------------
59
int main(int argc, char *argv[])
60
{
61
    try
62
    {
63
        WServer server(argc, argv, WTHTTP_CONFIGURATION);
64

    
65
        server.addEntryPoint(EntryPointType::Application,
66
                             std::bind(&createHelloApplication, std::placeholders::_1));
67

    
68
        if (server.start())
69
        {
70
          int sig = WServer::waitForShutdown();
71

    
72
          std::cerr << "*** Shutdown (signal = " << sig << ")" << std::endl;
73
          server.stop();
74

    
75
          if (sig == 1) // SIGHUP
76
            WServer::restart(argc, argv, environ);
77

    
78
          return 0;
79
        }
80
    }
81
    catch (WServer::Exception &e)
82
    {
83
        std::cerr << "*** Server Exception: " << e.what() << std::endl;
84
    }
85
    catch (std::exception &e)
86
    {
87
        std::cerr << "*** Std Exception: " << e.what() << std::endl;
88
    }
89
}
(3-3/3)