Project

General

Profile

Support #2195 ยป Wt_ticket_2195.txt

Bud T, 09/21/2013 11:08 AM

 
1
#include <Wt/WLineEdit>
2
#include <Wt/WMenu>
3
#include <Wt/WMessageBox>
4
#include <Wt/WNavigationBar>
5
#include <Wt/WPopupMenu>
6
#include <Wt/WPopupMenuItem>
7
#include <Wt/WStackedWidget>
8
#include <Wt/WText>
9
#include <Wt/WServer>
10

    
11
#include <Wt/WApplication>
12
#include <Wt/WEnvironment>
13
#include <Wt/WContainerWidget>
14
#include <Wt/WBootstrapTheme>
15

    
16
#include <Wt/WHBoxLayout>
17

    
18
using namespace std;
19
using namespace Wt;
20

    
21
class App: public WApplication {
22
private:
23
  std::string appName;
24

    
25
public: 
26
	Wt::WContainerWidget* container;
27

    
28
  App(const WEnvironment &env): WApplication(env) {
29
    setTitle("Home");
30
    appName = "App";
31
		setTheme(new WBootstrapTheme());
32

    
33
    // Container widget into which we place navigation bar
34
		Wt::WContainerWidget *container = new Wt::WContainerWidget(root());
35

    
36
		// Create a navigation bar with a link to a web page.
37
		Wt::WNavigationBar *navigation = new Wt::WNavigationBar(container);
38
		navigation->setTitle("App, Inc.",
39
			"http://www.test.com");
40
		navigation->setResponsive(true);
41

    
42
    // Stacked widget into which we place menus - added to container
43
		Wt::WStackedWidget *contentsStack = new Wt::WStackedWidget(container);
44
		contentsStack->addStyleClass("contents");
45

    
46
		// Setup a Left-aligned menu and add to stack which has container as parent
47
		Wt::WMenu *leftMenu = new Wt::WMenu(contentsStack, container);
48
    // Add this menu to the navigation bar
49
		navigation->addMenu(leftMenu);
50

    
51
    // Create a textbox for display on Sales menu link action
52
		Wt::WText *searchResult = new Wt::WText("Buy or Sell... Bye!");
53

    
54
    // Add items to menu just added to nav bar with values determine in three ways:
55
    // Text object created on fly
56
		leftMenu->addItem("Home", new Wt::WText("There is no better place!"));
57
		// Text object created on fly with a hyperlink formatting
58
    leftMenu->addItem("Layout", new Wt::WText("Layout contents"))
59
			->setLink(Wt::WLink(Wt::WLink::InternalPath, "/layout"));
60
		// Text object used that has already been created
61
    leftMenu->addItem("Sales", searchResult);
62

    
63
    // Setup a Right-aligned menu.
64
    Wt::WMenu *rightMenu = new Wt::WMenu();
65
    navigation->addMenu(rightMenu, Wt::AlignRight);
66

    
67
    // Create a popup submenu for the Help menu.
68
    Wt::WPopupMenu *popup = new Wt::WPopupMenu();
69
    popup->addItem("Contents");
70
    popup->addItem("Index");
71
    popup->addSeparator();
72
    popup->addItem("About");
73

    
74
// start bug block
75
    popup->itemSelected().connect(std::bind([=] (Wt::WMenuItem *item) {
76
      Wt::WMessageBox *messageBox = new Wt::WMessageBox(
77
        "Help",
78
	      Wt::WString::fromUTF8("<p>Showing Help: {1}</p>").arg(item->text()),
79
	      Wt::Information, Wt::Ok
80
      );
81

    
82
      messageBox->buttonClicked().connect(std::bind([=] () {
83
	      delete messageBox;
84
      }));
85
      messageBox->show();
86
    }, std::placeholders::_1));
87
// end bug block
88

    
89
    Wt::WMenuItem *item = new Wt::WMenuItem("Help");
90
    item->setMenu(popup);
91
    rightMenu->addItem(item);
92

    
93
    // Add a Search control.
94
    Wt::WLineEdit *edit = new Wt::WLineEdit();
95
    edit->setEmptyText("Enter a search item");
96

    
97
    edit->enterPressed().connect(std::bind([=] () {
98
        leftMenu->select(2); // is the index of the "Sales"
99
        searchResult->setText(Wt::WString("Nothing found for {1}.")
100
			      .arg(edit->text()));
101
    }));
102

    
103
    navigation->addSearch(edit, Wt::AlignRight);
104

    
105
		container->addWidget(contentsStack);
106

    
107
    header();
108
    sidebar();
109
    footer();
110
	}
111

    
112
  void header()
113
  {
114
   WContainerWidget* header = new WContainerWidget(root());
115
   header->setId("header");
116
	 
117
	 // header layout
118
   Wt::WHBoxLayout *hbox = new Wt::WHBoxLayout();
119
   header->setLayout(hbox);
120
   header->setMargin(5);
121

    
122
   Wt::WText *item = new Wt::WText("<h1>" + appName + "</h1>");
123
   item->setId("box");
124
   header->setStyleClass("hdr");
125

    
126
   hbox->addWidget(item);
127
  }
128

    
129
  void footer() 
130
  {
131
    WContainerWidget* footer = new WContainerWidget(root());
132
    footer->setId("footer");
133
    footer->addWidget(new WText("Under Construction"));
134
    footer->setMargin(5);
135
  }
136

    
137
  void sidebar() 
138
  {
139
    WContainerWidget* sidebar = new WContainerWidget(root());
140
    sidebar->setId("sidebar");
141
    sidebar->addWidget(new WText("Sidebar Information"));
142
    sidebar->setMargin(5);
143
  }
144
};
145

    
146
Wt::WApplication* createApplication(const Wt::WEnvironment &env) {    
147
	return new App(env);
148
}
149

    
150
int main(int argc, char** argv) {
151
	return Wt::WRun(argc, argv, &createApplication);
152
}
153

    
    (1-1/1)