Wt examples  3.7.1
OptionList.C
Go to the documentation of this file.
1 // This may look like C code, but it's really -*- C++ -*-
2 /*
3  * Copyright (C) 2008 Emweb bv, Herent, Belgium.
4  *
5  * See the LICENSE file for terms of use.
6  */
7 
8 #include "OptionList.h"
9 #include "Option.h"
10 
12  : WContainerWidget(parent),
14 {
15  resize(WLength::Auto, WLength(2.5, WLength::FontEx));
16 }
17 
18 void OptionList::add(Option *option)
19 {
20  addWidget(option);
21  option->setOptionList(this);
22 
23  if (!options_.empty()) {
24  options_.back()->addSeparator();
25  }
26 
27  options_.push_back(option);
28 }
29 
31 {
32  if (optionNeedReset_ != 0)
34 
35  optionNeedReset_ = 0;
36 }
37 
39 {
40  /*
41  * Check if it was the last visible option, in that case the second last
42  * visible option loses its separator.
43  */
44  for (std::size_t i = options_.size() - 1; i > 0; --i) {
45  if (options_[i] == opt) {
46  for (int j = i - 1; j >= 0; --j) {
47  if (!options_[j]->isHidden()) {
48  if (hidden)
49  options_[j]->hideSeparator();
50  else
51  options_[j]->showSeparator();
52  break;
53  }
54  }
55  break;
56  } else
57  if (!options_[i]->isHidden())
58  break;
59  }
60 
61  /*
62  * The Option to the right needs to relearn its stateless
63  * slot code for hide() and show().
64  */
65  for (unsigned i = 0; i < options_.size(); ++i) {
66  if (options_[i] == opt) {
67  for (unsigned j = i + 1; j < options_.size(); ++j) {
68  if (!options_[j]->isHidden()) {
70  break;
71  }
72  }
73 
74  break;
75  }
76  }
77 }
78 
void setOptionList(OptionList *l)
Definition: Option.C:28
A clickable option.
Definition: Option.h:31
OptionList(WContainerWidget *parent=0)
Create an OptionList.
Definition: OptionList.C:11
void update()
Updates the stateless implementations after an Option has been hidden or shown.
Definition: OptionList.C:30
std::vector< Option * > options_
The list of options.
Definition: OptionList.h:58
void resetLearnedSlots()
WWidget * parent() const
void optionVisibilityChanged(Option *opt, bool hidden)
An option changed visibility: possibly update the separators inbetween.
Definition: OptionList.C:38
virtual void resize(const WLength &width, const WLength &height) override
Option * optionNeedReset_
The option that needs its stateless code updated.
Definition: OptionList.h:61
virtual bool isHidden() const override
virtual void addWidget(std::unique_ptr< WWidget > widget)
void add(Option *option)
Add an Option to the list.
Definition: OptionList.C:18

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13