Guest User

trax

a guest
Dec 23rd, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. #include <Wt/WPushButton>
  5.  
  6. #include <Wt/WServer>
  7. #include <Wt/WApplication>
  8. #include <Wt/WServer>
  9. #include <Wt/WBootstrapTheme>
  10. #include <Wt/WNavigationBar>
  11. #include <Wt/WMenu>
  12. #include <Wt/WStackedWidget>
  13. #include <Wt/WVBoxLayout>
  14.  
  15. #include <Wt/WText>
  16.  
  17. #include <boost/bind.hpp>
  18.  
  19.  
  20. namespace blog {
  21.  
  22. namespace view {
  23.  
  24.  
  25.  
  26. class WebGUI : public Wt::WApplication  {
  27. public:
  28.   WebGUI (const Wt::WEnvironment& env, Wt::WServer &server);
  29.  
  30. private:
  31.   Wt::WServer &server;
  32.   Wt::WStackedWidget *menuStack;  
  33.  
  34.   Wt::WVBoxLayout *globalLayout;
  35.  
  36.   void navigation (Wt::WStackedWidget *stack);
  37.  
  38.   Wt::WNavigationBar * createNavigationBar(Wt::WStackedWidget *stack,
  39.                                            Wt::WContainerWidget *parent = 0);
  40.  
  41.  
  42. };
  43.  
  44.  
  45.  
  46. void WebGUI::navigation (Wt::WStackedWidget *stack) {
  47.   auto app = Wt::WApplication::instance();
  48.   if (app->internalPath() == "/"){
  49.     stack->setCurrentIndex(0);
  50.   } else {
  51.     setInternalPathValid (false);
  52.   }
  53. }
  54.  
  55.  
  56. Wt::WNavigationBar * WebGUI::createNavigationBar(Wt::WStackedWidget *stack, Wt::WContainerWidget *parent) {
  57.   Wt::WNavigationBar * navigation = new Wt::WNavigationBar(parent);
  58.   navigation->setResponsive(true);
  59.  
  60.   Wt::WMenu *leftMenu = new Wt::WMenu(stack, parent);
  61.   Wt::WVBoxLayout *layout = new Wt::WVBoxLayout();
  62.  
  63.  
  64.  
  65.   auto mainContainer = new Wt::WContainerWidget();
  66.   mainContainer->setLayout(layout);
  67.  
  68.   leftMenu->addItem("Home", mainContainer);
  69.  
  70.  
  71.   for (int i = 0 ; i < 10 ; i++){
  72.     auto container = new Wt::WContainerWidget();
  73.     container->addWidget(new Wt::WText("<ol><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ol>"));
  74.     layout->addWidget(container);
  75.   }
  76.  
  77.   Wt::WApplication::instance()->enableUpdates(true);
  78.  
  79.   navigation->addMenu(leftMenu);
  80.  
  81.   return navigation;
  82. }
  83.  
  84.  
  85. WebGUI::WebGUI(const Wt::WEnvironment& env, Wt::WServer &server)
  86.   : Wt::WApplication(env),
  87.     server (server){
  88.  
  89.  
  90.  
  91.   menuStack  = new Wt::WStackedWidget();
  92.  
  93.   internalPathChanged().connect(std::bind([=] () {this->navigation(menuStack);}));
  94.  
  95.   globalLayout = new Wt::WVBoxLayout();
  96.   root()->setLayout(globalLayout);
  97.  
  98.   setTheme(new Wt::WBootstrapTheme());
  99.  
  100.  
  101.   root()->setStyleClass("container");
  102.  
  103.  
  104.   auto navBar     = createNavigationBar(menuStack, root());
  105.   globalLayout->addWidget(navBar,0);
  106.   globalLayout->addWidget(menuStack,1);
  107.   globalLayout->addStretch(1);
  108. }
  109.  
  110.  
  111. } // view
  112.  
  113. } // blog
  114.  
  115. Wt::WApplication *createApplication(const Wt::WEnvironment& env, Wt::WServer &server) {
  116.   return new blog::view::WebGUI(env, server);
  117. }
  118.  
  119. int main(int argc, char **argv) {
  120.  
  121.   Wt::WServer server(argv[0]);
  122.  
  123.   server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
  124.  
  125.   server.addEntryPoint(Wt::Application,
  126.                        boost::bind(createApplication, _1, std::ref(server)));
  127.  
  128.   if (server.start()) {
  129.     int sig = Wt::WServer::waitForShutdown();
  130.     std::cerr << "Shutting down: (signal = " << sig << ")" << std::endl;
  131.     server.stop();
  132.   }
  133.  
  134.   return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment