Project

General

Profile

Bug #3652 » test_20141105a_dialog_escape.C

Bruce Toll, 11/06/2014 09:44 PM

 
1
#include <Wt/WApplication>
2
#include <Wt/WEnvironment>
3
#include <Wt/WContainerWidget>
4
#include <Wt/WDialog>
5
#include <Wt/WPushButton>
6
#include <Wt/WText>
7
#include <Wt/WTable>
8
#include <Wt/WBootstrapTheme>
9

    
10
using namespace Wt;
11

    
12
class TestApplication : public WApplication
13
{
14
public:
15
  TestApplication(const WEnvironment& env);
16
  ~TestApplication() { delete theme(); }
17
private:
18
  int next_dialog_ {0};
19
  const int POSITION_ROWS = 4;
20
  const int POSITION_COLS = 5;
21
};
22

    
23
TestApplication::TestApplication(const WEnvironment& env) : WApplication(env)
24
{
25
  setTitle("Test WDialog Escape");
26
  setTheme(new WBootstrapTheme());
27

    
28
  new WText("<h4>Press button to open a few dialogs. Re-order by clicking dialog titles. "
29
      "Pressing escape key should close dialogs based on their stack order.</h4>", root());
30
  auto openDialogButton = new WPushButton("Open WDialog", root());
31
  auto positionTable = new WTable(root());
32
  for (int row=0; row <  POSITION_ROWS; row++) {
33
    for (int col=0; col < POSITION_COLS; col++) {
34
      positionTable->elementAt(row, col)->resize(80, 80);
35
    }
36
  }
37

    
38
  openDialogButton->clicked().connect(std::bind([=] {
39
    int row = (next_dialog_  * 3 / POSITION_COLS) % POSITION_ROWS;
40
    int col = next_dialog_ * 3 % POSITION_COLS;
41
    next_dialog_ += 1;
42

    
43
    auto dialog = new WDialog("Click to raise");
44
    dialog->setModal(false);
45
    dialog->setResizable(true);
46
    dialog->setClosable(true);
47
    dialog->rejectWhenEscapePressed(true);
48
    dialog->positionAt(positionTable->elementAt(row, col));
49
    new WText(WString("<h1>Dialog {1}</h1>").arg(next_dialog_),
50
      dialog->contents());
51
    dialog->setCanReceiveFocus(true);
52
  }));
53
}
54

    
55
int main(int argc, char **argv)
56
{
57
  return WRun(argc, argv, [](const WEnvironment& env) {return new TestApplication(env);});
58
}
(1-1/2)