|
/*
|
|
* Copyright (C) 2008 Emweb bv, Herent, Belgium.
|
|
*
|
|
* See the LICENSE file for terms of use.
|
|
*/
|
|
|
|
#include <Wt/WApplication>
|
|
#include <Wt/WBreak>
|
|
#include <Wt/WContainerWidget>
|
|
#include <Wt/WDialog>
|
|
#include <Wt/WLineEdit>
|
|
#include <Wt/WMenu>
|
|
#include <Wt/WMenuItem>
|
|
#include <Wt/WPushButton>
|
|
#include <Wt/WText>
|
|
|
|
// c++0x only, for std::bind
|
|
// #include <functional>
|
|
|
|
using namespace Wt;
|
|
|
|
/*
|
|
* A simple hello world application class which demonstrates how to react
|
|
* to events, read input, and give feed-back.
|
|
*/
|
|
class HelloApplication : public WApplication
|
|
{
|
|
public:
|
|
HelloApplication(const WEnvironment& env);
|
|
|
|
private:
|
|
Wt::WMenu* apMenu;
|
|
void SubMenuItemSelected(Wt::WMenu* apSubMenu, Wt::WMenu* apSubSubMenu, Wt::WMenuItem* apSubMenuItem);
|
|
};
|
|
|
|
/*
|
|
* The env argument contains information about the new session, and
|
|
* the initial request. It must be passed to the WApplication
|
|
* constructor so it is typically also an argument for your custom
|
|
* application constructor.
|
|
*/
|
|
HelloApplication::HelloApplication(const WEnvironment& env)
|
|
: WApplication(env)
|
|
{
|
|
setTitle("Hello world"); // application title
|
|
|
|
apMenu = new Wt::WMenu();
|
|
apMenu->itemSelected().connect([=, this](Wt::WMenuItem* apSubMenuItem) { SubMenuItemSelected(apMenu, (Wt::WMenu*) 0, apSubMenuItem);});
|
|
Wt::WMenuItem *pMenuItem = apMenu->addItem("xxxx", nullptr, ContentLoading::Lazy);
|
|
|
|
Wt::WMenu* pSubMenu = new Wt::WMenu();
|
|
pSubMenu->itemSelected().connect([=, this](Wt::WMenuItem* apSubMenuItem) { SubMenuItemSelected(apMenu, pSubMenu, apSubMenuItem);});
|
|
pMenuItem = pSubMenu->addItem("abc", nullptr, ContentLoading::Lazy);
|
|
pMenuItem = pSubMenu->addItem("def", nullptr, ContentLoading::Lazy);
|
|
apMenu->addMenu("submenu", std::unique_ptr<Wt::WMenu>(pSubMenu));
|
|
|
|
root()->addWidget(std::unique_ptr<Wt::WMenu>(apMenu));
|
|
}
|
|
|
|
|
|
void HelloApplication::SubMenuItemSelected(Wt::WMenu* apSubMenu, Wt::WMenu* apSubSubMenu, Wt::WMenuItem* apSubMenuItem)
|
|
{
|
|
static int nested = 0;
|
|
nested++;
|
|
printf("%s %d: nested %d apSubMenuItem %s inSubMenu %s isMenu %s\n", __FILE__, __LINE__, nested, apSubMenuItem->text().toUTF8().c_str(), apSubSubMenu != NULL ? "true" : "false", apSubMenuItem->menu() != NULL ? "true" : "false");
|
|
//if (nested == 1)
|
|
{
|
|
std::vector<Wt::WMenuItem *> items = apSubMenu->items();
|
|
for (std::size_t i = 0; i < items.size(); ++i)
|
|
{
|
|
if (items[i]->menu() && items[i]->menu() == apSubSubMenu) { printf("%s %d\n", __FILE__, __LINE__); apSubMenu->select(i); }
|
|
else if (items[i]->menu()) { printf("%s %d\n", __FILE__, __LINE__); items[i]->menu()->select(-1); }
|
|
}
|
|
|
|
if (apSubSubMenu) { printf("%s %d\n", __FILE__, __LINE__);apSubSubMenu->select(apSubMenuItem); }
|
|
else if (apSubMenuItem->menu()) { printf("%s %d\n", __FILE__, __LINE__);apSubMenuItem->menu()->select(0); }
|
|
|
|
//apSubMenu->select(apSubMenuItem);
|
|
}
|
|
nested--;
|
|
|
|
printf("%s %d: %s %d\n", __FILE__, __LINE__, apMenu->currentItem()->text().toUTF8().c_str(), apMenu->currentIndex());
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
/*
|
|
* Your main method may set up some shared resources, but should then
|
|
* start the server application (FastCGI or httpd) that starts listening
|
|
* for requests, and handles all of the application life cycles.
|
|
*
|
|
* The last argument to WRun specifies the function that will instantiate
|
|
* new application objects. That function is executed when a new user surfs
|
|
* to the Wt application, and after the library has negotiated browser
|
|
* support. The function should return a newly instantiated application
|
|
* object.
|
|
*/
|
|
|
|
static const char STR_HTTP_ARG[] = "--http-address=";
|
|
static const char STR_APPROOT_ARG[] = "--approot=/etc/opt/pixxel/webui/approot";
|
|
static const char STR_DOCROOT_ARG[] = "--docroot=/etc/opt/pixxel/webui/docroot";
|
|
static const char FMT_HTTP_PORT_ARG[] = "--http-port=%d";
|
|
static const char STR_ACCESSLOG_ARG[] = "--accesslog=/var/opt/pixxel/log/webui_log.txt"; //@TODO, make using this file optional (http://vmivm4:8000/Archos/ticket/3238)
|
|
static const char STR_THREADS_ARG[] = "--threads=1";
|
|
|
|
// collect information required to start Wt server
|
|
char httpArg[32];
|
|
snprintf(httpArg, sizeof(httpArg), "%s%s", STR_HTTP_ARG, "0.0.0.0");
|
|
const char* szProcName = "hello";
|
|
|
|
/** @todo argc/argv style arguments vs These options are not specified in the wt_config.xml configuration file,
|
|
but may be indicated on the command-line, or within a configuration file that is located at /etc/wt/wthttpd. */
|
|
char STR_HTTP_PORT_ARG[32];
|
|
snprintf(STR_HTTP_PORT_ARG, sizeof(STR_HTTP_PORT_ARG), FMT_HTTP_PORT_ARG, 80);
|
|
const char* myArgv[]=
|
|
{
|
|
szProcName,
|
|
STR_APPROOT_ARG,
|
|
STR_DOCROOT_ARG,
|
|
httpArg,
|
|
STR_HTTP_PORT_ARG,
|
|
STR_ACCESSLOG_ARG,
|
|
STR_THREADS_ARG
|
|
};
|
|
int myArgc = sizeof(myArgv) / sizeof(char*);
|
|
|
|
return WRun(myArgc, (char**)myArgv, [](const Wt::WEnvironment &env) {
|
|
/*
|
|
* You could read information from the environment to decide whether
|
|
* the user has permission to start a new application
|
|
*/
|
|
return std::make_unique<HelloApplication>(env);
|
|
});
|
|
}
|
|
|