Project

General

Profile

Bug #2488 » tstui1.cpp

Tiaan Wessels, 12/02/2013 10:11 AM

 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <string>

using namespace std;

#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WVBoxLayout>
#include <Wt/WLabel>
#include <Wt/WStackedWidget>
#include <Wt/WMenu>
#include <Wt/WBootstrapTheme>

using namespace Wt;

class TSTApplication : public WApplication
{
WContainerWidget *body;

void start();

public:
TSTApplication(const WEnvironment& env);
};

class TSTMessage : public WContainerWidget
{
public:
TSTMessage();
};

class TSTRelatives : public WContainerWidget
{
void expand();

public:
TSTRelatives(const string &);
};

class TSTChildren : public TSTRelatives
{
public:
TSTChildren();
};

class TSTParent : public TSTRelatives
{
public:
TSTParent();
};

const char *MESSAGE = "This is a message\n\
to help illustrate the problem i am\n\
having with the relative offsets of\n\
container widgets";

const char *BODY = " A Proferred Official ICP\n\
\n\
By Initial Connection Protocol (ICP), I mean a third level protocol\n\
which is initiated by a user process at one site in order to contact a\n\
server process at another site. Typically, the user process will be a\n\
Telnet and the server process will be a logger, but there may be other\n\
cases.\n\
\n\
In this RFC, I wish to describe a family of ICPs suitable for\n\
establishing one pair of connections (one in each direction) between any\n\
user process and any server process, and to propose further a particular\n\
subset of this family as the standard ICP for connecting user processes\n\
to loggers on systems which accept teletype-like devices.";

TSTMessage::TSTMessage()
{
WVBoxLayout *vbox = new WVBoxLayout;
vbox->addWidget(new WText("<pre>" + string(MESSAGE) + "</pre>"));
vbox->addWidget(new TSTParent);
vbox->addWidget(new TSTChildren);
vbox->addWidget(new WText("<pre>" + string(BODY) + "</pre>"));
vbox->addWidget(new WPushButton("Dummy Button"));
setLayout(vbox);
}

TSTRelatives::TSTRelatives
(
const string &who
)
{
setLayoutSizeAware(true);
WVBoxLayout *vbox = new WVBoxLayout;
WPushButton *expand = new WPushButton("Expand " + who);
expand->clicked().connect(this, &TSTRelatives::expand);
vbox->addWidget(expand);
setLayout(vbox);
}

void TSTRelatives::expand()
{
clear();
for (int i = 0; i < 2; i++)
{
this->addWidget(new WBreak);
WString num = WString("{1}<hr/>").arg(i);
this->addWidget(new WText(num));
this->addWidget(new TSTMessage);
}
}

TSTChildren::TSTChildren()
: TSTRelatives("Children")
{
setStyleClass("children");
}

TSTParent::TSTParent()
: TSTRelatives("Parent")
{
setStyleClass("parent");
}

void TSTApplication::start()
{
for (int i = 0; i < 3; i++)
{
body->addWidget(new WBreak);
WString num = WString("{1}<hr/>").arg(i);
body->addWidget(new WText(num));
body->addWidget(new TSTMessage);
}
}

TSTApplication::TSTApplication
(
const WEnvironment& env
)
: WApplication(env)
{
WApplication::instance()->useStyleSheet("tstui1.css");
WApplication::instance()->setTheme(new WBootstrapTheme);

WContainerWidget *appcont = new WContainerWidget;
WStackedWidget *contents = new WStackedWidget;
WMenu *menu = new WMenu(contents, Wt::Horizontal, appcont);
menu->addStyleClass("nav-tabs");

// tab1
WContainerWidget *cont = new WContainerWidget;
WVBoxLayout *vbox = new WVBoxLayout;
body = new WContainerWidget;
WPushButton *b = new WPushButton("Start");
b->clicked().connect(this, &TSTApplication::start);
vbox->addWidget(b);
vbox->addWidget(body);
cont->setLayout(vbox);
menu->addItem("TAB1", cont);

// tab2
cont = new WContainerWidget;
vbox = new WVBoxLayout;
vbox->addWidget(new WLabel("TODO"));
cont->setLayout(vbox);
menu->addItem("TAB2", cont);

appcont->addWidget(contents);

root()->addWidget(appcont);
}

WApplication *createApplication(const WEnvironment& env)
{
return new TSTApplication(env);
}

int main(int argc, char **argv)
{
return WRun(argc, argv, &createApplication);
}
(2-2/4)