Project

General

Profile

Bug #1489 ยป positionAt.cpp

Koen Deforche, 10/23/2012 08:42 AM

 
/*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <iostream>

#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
#include <Wt/WLineEdit>
#include <Wt/WMessageBox>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WDialog>

using namespace Wt;

class DialogExample : public WApplication
{
public:
DialogExample(const WEnvironment& env)
: WApplication(env),
messageBox_(0)
{
WContainerWidget *buttons = new WContainerWidget(root());

WPushButton *button;

button = new WPushButton("Discard", buttons);
button->clicked().connect(this, &DialogExample::messageBox4);

WContainerWidget *cont = new WContainerWidget(root());
cont->resize(500, 500);

status_ = new WText("Go ahead...", root());
status_->setInline(false);
status_->setPositionScheme(Absolute);
status_->setOffsets(100, Left|Top);
}
void messageBox4()
{
messageBox_
= new WMessageBox("Your work",
"Your work is not saved",
NoIcon, NoButton);

messageBox_->addButton("Cancel modifications", Ok);
messageBox_->addButton("Continue modifying work", Cancel);

messageBox_->positionAt(status_);

messageBox_
->buttonClicked().connect(this, &DialogExample::messageBoxDone);

messageBox_->show();
}

void messageBoxDone(StandardButton result)
{
switch (result) {
case Ok:
setStatus("Ok'ed"); break;
case Cancel:
setStatus("Cancelled!"); break;
case Yes:
setStatus("Me too!"); break;
case No:
setStatus("Me neither!"); break;
default:
setStatus("Unkonwn result?");
}

delete messageBox_;
messageBox_ = 0;
}

void setStatus(const WString& result)
{
status_->setText(result);
}

private:
WText *status_;
WMessageBox *messageBox_;
};

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

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

    (1-1/1)