Project

General

Profile

Support #2195 ยป Wt_ticket_2195.txt

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

 
#include <Wt/WLineEdit>
#include <Wt/WMenu>
#include <Wt/WMessageBox>
#include <Wt/WNavigationBar>
#include <Wt/WPopupMenu>
#include <Wt/WPopupMenuItem>
#include <Wt/WStackedWidget>
#include <Wt/WText>
#include <Wt/WServer>

#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WContainerWidget>
#include <Wt/WBootstrapTheme>

#include <Wt/WHBoxLayout>

using namespace std;
using namespace Wt;

class App: public WApplication {
private:
std::string appName;

public:
Wt::WContainerWidget* container;

App(const WEnvironment &env): WApplication(env) {
setTitle("Home");
appName = "App";
setTheme(new WBootstrapTheme());

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

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

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

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

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

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

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

// Create a popup submenu for the Help menu.
Wt::WPopupMenu *popup = new Wt::WPopupMenu();
popup->addItem("Contents");
popup->addItem("Index");
popup->addSeparator();
popup->addItem("About");

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

messageBox->buttonClicked().connect(std::bind([=] () {
delete messageBox;
}));
messageBox->show();
}, std::placeholders::_1));
// end bug block

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

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

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

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

container->addWidget(contentsStack);

header();
sidebar();
footer();
}

void header()
{
WContainerWidget* header = new WContainerWidget(root());
header->setId("header");
// header layout
Wt::WHBoxLayout *hbox = new Wt::WHBoxLayout();
header->setLayout(hbox);
header->setMargin(5);

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

hbox->addWidget(item);
}

void footer()
{
WContainerWidget* footer = new WContainerWidget(root());
footer->setId("footer");
footer->addWidget(new WText("Under Construction"));
footer->setMargin(5);
}

void sidebar()
{
WContainerWidget* sidebar = new WContainerWidget(root());
sidebar->setId("sidebar");
sidebar->addWidget(new WText("Sidebar Information"));
sidebar->setMargin(5);
}
};

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

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

    (1-1/1)