Boost.UI
User Interface Boost library
check_box.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Kolya Kosenko
2 
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5 
7 
8 #ifndef BOOST_UI_CHECK_BOX_HPP
9 #define BOOST_UI_CHECK_BOX_HPP
10 
11 #include <boost/ui/config.hpp>
12 
13 #ifdef BOOST_HAS_PRAGMA_ONCE
14 #pragma once
15 #endif
16 
17 #include <boost/ui/def.hpp>
18 #include <boost/ui/widget.hpp>
19 #include <boost/logic/tribool.hpp>
20 #include <boost/optional.hpp>
21 
22 namespace boost {
23 namespace ui {
24 
27 
28 class BOOST_UI_DECL check_box_base : public widget
29 {
30 public:
32  check_box_base& check(nullopt_t) { indeterminate(); return *this; }
33  check_box_base& check(bool checked = true);
34  check_box_base& uncheck() { return check(false); }
35  check_box_base& indeterminate();
36  check_box_base& tribool(boost::tribool value)
37  {
38  if ( value ) check();
39  else if ( !value ) uncheck();
40  else indeterminate();
41  return *this;
42  }
43  check_box_base& optional(boost::optional<bool> value)
44  {
45  if ( !value ) indeterminate();
46  else if ( *value ) check();
47  else uncheck();
48  return *this;
49  }
51 
53  bool is_checked() const;
54  bool is_unchecked() const;
55  bool is_indeterminate() const;
56  boost::tribool tribool() const
57  {
58  return is_checked() ? boost::tribool(true)
59  : is_unchecked() ? boost::tribool(false)
60  : boost::indeterminate;
61  }
62  boost::optional<bool> optional() const
63  {
64  return is_checked() ? boost::optional<bool>(true)
65  : is_unchecked() ? boost::optional<bool>(false)
66  : boost::none;
67  }
69 
71  BOOST_UI_DETAIL_HANDLER(toggle, check_box_base);
72 
73 protected:
74  check_box_base() {}
75 
76 #ifndef DOXYGEN
77  void detail_create(widget& parent, const uistring& text, bool is_tri_state);
78 #endif
79 
80 private:
81  void on_toggle_raw(const boost::function<void()>& handler);
82 
83  class detail_impl;
84  detail_impl* get_impl();
85  const detail_impl* get_impl() const;
86 };
87 
91 
92 class BOOST_UI_DECL check_box : public check_box_base
93 {
94 public:
95  check_box() {}
96 
98  explicit check_box(widget& parent, const uistring& text)
99  { create(parent, text); }
100  check_box& create(widget& parent, const uistring& text)
101  { detail_create(parent, text, false); return *this; }
103 };
104 
108 
109 class BOOST_UI_DECL tri_state_check_box : public check_box_base
110 {
111 public:
113 
115  explicit tri_state_check_box(widget& parent, const uistring& text)
116  { create(parent, text); }
117  tri_state_check_box& create(widget& parent, const uistring& text)
118  { detail_create(parent, text, true); return *this; }
120 };
121 
122 } // namespace ui
123 } // namespace boost
124 
125 #endif // BOOST_UI_CHECK_BOX_HPP
boost::ui::uistring
Helper class to convert string between UI and application logic only.
Definition: string.hpp:49
boost::ui::check_box::create
check_box & create(widget &parent, const uistring &text)
Creates check box widget with text.
Definition: check_box.hpp:100
config.hpp
Configuration options.
boost::ui::check_box_base::uncheck
check_box_base & uncheck()
Sets check box state.
Definition: check_box.hpp:34
boost::ui::check_box
Labelled widget that that permits the user to make a binary choice.
Definition: check_box.hpp:92
boost::ui::check_box_base
Check box base class.
Definition: check_box.hpp:28
boost::ui::check_box_base::optional
boost::optional< bool > optional() const
Returns check box state.
Definition: check_box.hpp:62
boost::ui::check_box_base::check
check_box_base & check(nullopt_t)
Sets check box state.
Definition: check_box.hpp:32
boost::ui::check_box_base::tribool
check_box_base & tribool(boost::tribool value)
Sets check box state.
Definition: check_box.hpp:36
widget.hpp
Widget class.
boost::ui::check_box_base::optional
check_box_base & optional(boost::optional< bool > value)
Sets check box state.
Definition: check_box.hpp:43
def.hpp
Definitions.
boost
Boost C++ libraries namespace.
Definition: window.hpp:19
boost::ui::tri_state_check_box
Labelled widget that that permits the user to make a ternary choice.
Definition: check_box.hpp:109
boost::ui::check_box::check_box
check_box(widget &parent, const uistring &text)
Creates check box widget with text.
Definition: check_box.hpp:98
boost::ui::tri_state_check_box::tri_state_check_box
tri_state_check_box(widget &parent, const uistring &text)
Creates tri-state check box widget with text.
Definition: check_box.hpp:115
boost::ui::widget
Base class for all widgets.
Definition: widget.hpp:45
boost::ui::tri_state_check_box::create
tri_state_check_box & create(widget &parent, const uistring &text)
Creates tri-state check box widget with text.
Definition: check_box.hpp:117
boost::ui::check_box_base::tribool
boost::tribool tribool() const
Returns check box state.
Definition: check_box.hpp:56