Project

General

Profile

Bug #3677 » test_20141124a_dialog_move_resize.C

Bruce Toll, 11/25/2014 09:24 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/WCssTheme>
9
#include <Wt/WBootstrapTheme>
10

    
11
using namespace Wt;
12

    
13
class TestApplication : public WApplication
14
{
15
public:
16
  TestApplication(const WEnvironment& env);
17
  ~TestApplication() { delete theme_css_; }
18
private:
19
  int next_dialog_ {0};
20
  const int POSITION_ROWS = 4;
21
  const int POSITION_COLS = 5;
22
  WBootstrapTheme theme_;
23
  WCssTheme *theme_css_;
24
};
25

    
26
TestApplication::TestApplication(const WEnvironment& env) : WApplication(env), theme_css_(0)
27
{
28
  setTitle("Test WDialog Escape");
29
  const std::string *themePtr = env.getParameter("theme");
30
  std::string theme_s;
31
  if (!themePtr)
32
    theme_s = "bootstrap3";
33
  else
34
    theme_s = *themePtr;
35

    
36
  if (theme_s == "bootstrap2") {
37
    theme_.setVersion(WBootstrapTheme::Version2);
38
    setTheme(&theme_);
39
  }
40
  else if (theme_s == "bootstrap3") {
41
    theme_.setVersion(WBootstrapTheme::Version3);
42
    setTheme(&theme_);
43
  }
44
  else {
45
    theme_css_ = new WCssTheme(theme_s);
46
    setTheme(theme_css_);
47
  }
48

    
49
  new WText("<h4>Try different themes using theme parameter. Move and resize windows. "
50
      "Try using an initial window around the size of the grid and expanding it after "
51
      "opening a few dialogs.</h4>", root());
52
  auto openDialogButton = new WPushButton("Open WDialog", root());
53
  auto positionTable = new WTable(root());
54
  for (int row=0; row <  POSITION_ROWS; row++) {
55
    for (int col=0; col < POSITION_COLS; col++) {
56
      positionTable->elementAt(row, col)->resize(80, 80);
57
      WCssDecorationStyle(ds);
58
      ds.setBackgroundColor(WColor(11*(row*POSITION_COLS+col),
59
            11*(row*POSITION_COLS+col), 11*(row*POSITION_COLS+col)));
60
      positionTable->elementAt(row, col)->setDecorationStyle(ds);
61
    }
62
  }
63

    
64
  openDialogButton->clicked().connect(std::bind([=] {
65
    int row = (next_dialog_  * 3 / POSITION_COLS) % POSITION_ROWS;
66
    int col = next_dialog_ * 3 % POSITION_COLS;
67
    next_dialog_ += 1;
68

    
69
    auto dialog = new WDialog("Click to raise");
70
    dialog->setModal(false);
71
    dialog->setResizable(true);
72
    dialog->setClosable(true);
73
    dialog->rejectWhenEscapePressed(true);
74
    dialog->positionAt(positionTable->elementAt(row, col));
75
    new WText(WString("<h1>Dialog {1}</h1>").arg(next_dialog_),
76
      dialog->contents());
77
    dialog->setCanReceiveFocus(true);
78
  }));
79
}
80

    
81
int main(int argc, char **argv)
82
{
83
  return WRun(argc, argv, [](const WEnvironment& env) {return new TestApplication(env);});
84
}
(3-3/3)