xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
checked_list_box.h
Go to the documentation of this file.
1 #pragma once
6 #include "list_box.h"
7 
9 namespace xtd {
11  namespace forms {
26  class forms_export_ checked_list_box : public list_box {
27  public:
29  class item : public list_box::item {
30  public:
32  item() = default;
35  item(const xtd::ustring& value) : list_box::item(value) {}
39  item(const xtd::ustring& value, bool checked) : list_box::item(value), check_state_(checked ? forms::check_state::checked : forms::check_state::unchecked) {}
43  item(const xtd::ustring& value, forms::check_state check_state) : list_box::item(value), check_state_(check_state) {}
47  item(const xtd::ustring& value, const std::any& tag) : list_box::item(value, tag) {}
52  item(const xtd::ustring& value, bool checked, const std::any& tag) : list_box::item(value, tag), check_state_(checked ? forms::check_state::checked : forms::check_state::unchecked) {}
57  item(const xtd::ustring& value, forms::check_state check_state, const std::any& tag) : list_box::item(value, tag), check_state_(check_state) {}
58 
60  item(const char* value) : list_box::item(value) {}
61  item(const item& value) = default;
62  bool operator==(const item& value) const {return list_box::item::operator==(value);}
63  bool operator!=(const item& value) const {return list_box::item::operator!=(value);}
64  bool operator<(const item& value) const {return list_box::item::operator<(value);}
65  bool operator<=(const item& value) const {return list_box::item::operator<=(value);}
66  bool operator>(const item& value) const {return list_box::item::operator>(value);}
67  bool operator>=(const item& value) const {return list_box::item::operator>=(value);}
68  friend std::ostream& operator<<(std::ostream& os, const item& value) {return os << value.to_string();}
70 
73  virtual bool checked() const {return check_state_ != forms::check_state::unchecked;}
74 
78  virtual forms::check_state check_state() const {return check_state_;}
79 
80  private:
82  };
83 
86 
88  using checked_index_collection = std::vector<size_t>;
89 
91  using checked_item_collection = std::vector<item>;
92 
94  using selected_object_collection = std::vector<item>;
95 
99 
103  checked_index_collection checked_indices() const;
104 
108  checked_item_collection checked_items() const;
109 
113  object_collection& items() {return items_;}
117  const object_collection& items() const {return items_;}
120  const list_box& items(const object_collection& items) {
121  items_ = items;
122  return *this;
123  }
124 
129  list_control& selected_index(size_t selected_index) override;
130 
131  std::vector<size_t> selected_indices() const override;
132 
137  const item& selected_item() const {return selected_item_;}
142  list_box& selected_item(const item& selected_item);
143 
148  selected_object_collection selected_items() const;
149 
150  using list_box::text;
153  control& text(const xtd::ustring& text) override {
154  selected_item_ = {text};
155  return *this;
156  }
157 
160  void begin_update();
163  void end_update();
164 
169  bool get_item_checked(size_t index) const;
170 
175  forms::check_state get_item_check_state(size_t index) const;
176 
180  const xtd::ustring& get_item_text(size_t index) const;
181 
186  void set_item_checked(size_t index, bool checked);
187 
193  void set_item_check_state(size_t index, forms::check_state check_state);
194 
198  void set_item_text(size_t index, const xtd::ustring& text);
199 
202 
203  protected:
204  bool allow_selection() override {return selection_mode_ != forms::selection_mode::none;}
205 
206  forms::create_params create_params() const override;
207 
208  void on_handle_created(const event_args& e) override;
209 
212  virtual void on_item_check(item_check_event_args& e) {item_check(*this, e);}
213 
214  void on_selected_value_changed(const event_args& e) override;
215 
216  void wnd_proc(message& message) override;
217 
218  void wm_reflect_command(message& message) override;
219 
220  void wm_mouse_double_click(message& message) override;
221 
222  void wm_mouse_down(message& message) override;
223 
224  void wm_mouse_up(message& message) override;
225 
227  object_collection items_;
228  item selected_item_;
230  };
231  }
232 }
virtual forms::check_state check_state() const
Gets the state of the item.
Definition: checked_list_box.h:78
Represents a standard Windows list box.
Definition: list_box.h:23
item(const xtd::ustring &value, const std::any &tag)
Initializes a new instance of the item class with specified value and tag.
Definition: checked_list_box.h:47
check_state
Specifies the state of a control, such as a check box, that can be checked, unchecked, or set to an indeterminate state.
Definition: check_state.h:19
Contains xtd::forms::item_check_event_handler event handler.
The control is unchecked.
const item & selected_item() const
Gets the currently selected item in the checked_list_box.
Definition: checked_list_box.h:137
std::vector< item > selected_object_collection
Represents the collection of selected items in the list_box.
Definition: checked_list_box.h:94
std::vector< item > checked_item_collection
Encapsulates the collection of checked items, including items in an indeterminate state...
Definition: checked_list_box.h:91
item(const xtd::ustring &value, bool checked)
Initializes a new instance of the item class with specified value and check state.
Definition: checked_list_box.h:39
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
The button has a checked or latched appearance. Use this appearance to show that a toggle button has ...
Represent an item contained in the checked_list_box::object_collection collection.
Definition: checked_list_box.h:29
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
item(const xtd::ustring &value)
Initializes a new instance of the item class with specified value.
Definition: checked_list_box.h:35
Contains xtd::forms::list_box control.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Represents a collection of objects.
Definition: arranged_element_collection.h:28
const object_collection & items() const
Gets the collection of items in this checked_list_box.
Definition: checked_list_box.h:117
item(const xtd::ustring &value, forms::check_state check_state)
Initializes a new instance of the item class with specified value and checked state.
Definition: checked_list_box.h:43
item(const xtd::ustring &value, bool checked, const std::any &tag)
Initializes a new instance of the item class with specified value, check state and tag...
Definition: checked_list_box.h:52
virtual void on_item_check(item_check_event_args &e)
Raises the checked_list_box::item_check event.
Definition: checked_list_box.h:212
Represents an event.
Definition: event.h:21
object_collection & items()
Gets the collection of items in this checked_list_box.
Definition: checked_list_box.h:113
No items can be selected.
Displays a xtd::forms::list_box in which a check box is displayed to the left of each item...
Definition: checked_list_box.h:26
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
std::vector< size_t > checked_index_collection
Encapsulates the collection of indexes of checked items (including items in an indeterminate state) ...
Definition: checked_list_box.h:88
Implements a Windows message.
Definition: message.h:25
Provides a common implementation of members for the list_box, choice and combo_box classes...
Definition: list_control.h:19
Defines the base class for controls, which are components with visual representation.
Definition: control.h:68
item(const xtd::ustring &value, forms::check_state check_state, const std::any &tag)
Initializes a new instance of the item class with specified value, check state and tag...
Definition: checked_list_box.h:57
control & text(const xtd::ustring &text) override
Sets the text associated with this control.
Definition: checked_list_box.h:153
bool allow_selection() override
Gets a value indicating whether the list enables selection of list items.
Definition: checked_list_box.h:204
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
virtual const xtd::ustring & text() const
Gets the text associated with this control.
Definition: control.h:678
Provides data for the item_check event of the checked_list_box and list_view controls.
Definition: item_check_event_args.h:25
event< checked_list_box, item_check_event_handler > item_check
Occurs when the checked state of an item changes.
Definition: checked_list_box.h:201
const list_box & items(const object_collection &items)
Sets the collection of items in this checked_list_box.
Definition: checked_list_box.h:120
virtual size_t selected_index() const
Gets the zero-based index of the currently selected item.
Definition: list_control.h:84
virtual bool checked() const
Gets a value indicating whether the item is in the checked state.
Definition: checked_list_box.h:73