xtd - Reference Guide  0.1.1
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 {
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  item& operator=(const item& value) = default;
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  bool operator>=(const item& value) const {return list_box::item::operator>=(value);}
69  friend std::ostream& operator<<(std::ostream& os, const item& value) {return os << value.to_string();}
71 
74  virtual bool checked() const {return check_state_ != forms::check_state::unchecked;}
75 
79  virtual forms::check_state check_state() const {return check_state_;}
80 
81  private:
83  };
84 
87 
89  using checked_index_collection = std::vector<size_t>;
90 
92  using checked_item_collection = std::vector<item>;
93 
95  using selected_object_collection = std::vector<item>;
96 
100 
105 
110 
114  object_collection& items() {return items_;}
118  const object_collection& items() const {return items_;}
121  const list_box& items(const object_collection& items) {
122  items_ = items;
123  return *this;
124  }
125 
130  list_control& selected_index(size_t selected_index) override;
131 
132  std::vector<size_t> selected_indices() const override;
133 
138  const item& selected_item() const {return selected_item_;}
143  list_box& selected_item(const item& selected_item);
144 
150 
151  using list_box::text;
154  control& text(const xtd::ustring& text) override {
155  selected_item_ = {text};
156  return *this;
157  }
158 
161  void begin_update();
164  void end_update();
165 
170  bool get_item_checked(size_t index) const;
171 
177 
181  const xtd::ustring& get_item_text(size_t index) const;
182 
187  void set_item_checked(size_t index, bool checked);
188 
195 
199  void set_item_text(size_t index, const xtd::ustring& text);
200 
203 
204  protected:
205  bool allow_selection() override {return selection_mode_ != forms::selection_mode::none;}
206 
207  forms::create_params create_params() const override;
208 
209  void on_handle_created(const event_args& e) override;
210 
213  virtual void on_item_check(item_check_event_args& e) {item_check(*this, e);}
214 
215  void on_selected_value_changed(const event_args& e) override;
216 
217  void wnd_proc(message& message) override;
218 
220 
222 
223  void wm_mouse_down(message& message) override;
224 
225  void wm_mouse_up(message& message) override;
226 
228  object_collection items_;
229  item selected_item_;
231  };
232  }
233 }
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
Represents an event.
Definition: event.h:21
Represent an item contained in the checked_list_box::object_collection collection.
Definition: checked_list_box.h:29
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
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
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
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
item()=default
Initializes a new instance of the item class.
virtual bool checked() const
Gets a value indicating whether the item is in the checked state.
Definition: checked_list_box.h:74
virtual forms::check_state check_state() const
Gets the state of the item.
Definition: checked_list_box.h:79
item(const xtd::ustring &value)
Initializes a new instance of the item class with specified value.
Definition: checked_list_box.h:35
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
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
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:89
void wm_mouse_down(message &message) override
Processes the mouse down message the list_box control receives from the top-level window.
event< checked_list_box, item_check_event_handler > item_check
Occurs when the checked state of an item changes.
Definition: checked_list_box.h:202
void end_update()
Resumes painting the checked_list_box control after painting is suspended by the begin_update method.
list_control & selected_index(size_t selected_index) override
When overridden in a derived class, Sets the zero-based index of the currently selected item.
virtual void on_item_check(item_check_event_args &e)
Raises the checked_list_box::item_check event.
Definition: checked_list_box.h:213
void set_item_check_state(size_t index, forms::check_state check_state)
Sets the check state of the item at the specified index.
bool get_item_checked(size_t index) const
Returns a value indicating whether the specified item is checked.
checked_list_box()
Initializes a new instance of the checked_list_box class.
std::vector< size_t > selected_indices() const override
Gets a collection that contains the zero-based indexes of all currently selected items in the list_bo...
void wm_mouse_double_click(message &message) override
Processes the mouse double-click message the list_box control receives from the top-level window.
std::vector< item > checked_item_collection
Encapsulates the collection of checked items, including items in an indeterminate state,...
Definition: checked_list_box.h:92
forms::check_state get_item_check_state(size_t index) const
Returns a value indicating the check state of the current item.
void wnd_proc(message &message) override
Processes Windows messages.
void wm_reflect_command(message &message) override
Processes the command message the list_box control receives from the top-level window.
void begin_update()
Maintains performance while items are added to the checked_list_box one at a time by preventing the c...
void set_item_checked(size_t index, bool checked)
Sets check_state for the item at the specified index to checked.
list_box & selected_item(const item &selected_item)
Sets the currently selected item in the list_box.
object_collection & items()
Gets the collection of items in this checked_list_box.
Definition: checked_list_box.h:114
const xtd::ustring & get_item_text(size_t index) const
Returns the text value of the current item.
const item & selected_item() const
Gets the currently selected item in the checked_list_box.
Definition: checked_list_box.h:138
control & text(const xtd::ustring &text) override
Sets the text associated with this control.
Definition: checked_list_box.h:154
checked_item_collection checked_items() const
Collection of checked items in this checked_list_box.
const list_box & items(const object_collection &items)
Sets the collection of items in this checked_list_box.
Definition: checked_list_box.h:121
void on_handle_created(const event_args &e) override
Raises the control::handle_created event.
bool allow_selection() override
Gets a value indicating whether the list enables selection of list items.
Definition: checked_list_box.h:205
const object_collection & items() const
Gets the collection of items in this checked_list_box.
Definition: checked_list_box.h:118
forms::create_params create_params() const override
Gets the required creation parameters when the control handle is created.
std::vector< item > selected_object_collection
Represents the collection of selected items in the list_box.
Definition: checked_list_box.h:95
checked_index_collection checked_indices() const
Collection of checked indexes in this checked_list_box.
void wm_mouse_up(message &message) override
Processes the mouse up message the list_box control receives from the top-level window.
void set_item_text(size_t index, const xtd::ustring &text)
Sets the text value of the item at the specified index.
void on_selected_value_changed(const event_args &e) override
Raises the list_control::selected_value_changed event.
selected_object_collection selected_items() const
Gets a collection containing the currently selected items in the list_box.
Defines the base class for controls, which are components with visual representation.
Definition: control.h:67
virtual const xtd::ustring & text() const
Gets the text associated with this control.
Definition: control.h:650
Provides data for the item_check event of the checked_list_box and list_view controls.
Definition: item_check_event_args.h:25
Represents a collection of objects.
Definition: arranged_element_collection.h:28
Represents a standard Windows list box.
Definition: list_box.h:23
virtual size_t selected_index() const
Gets the zero-based index of the currently selected item.
Definition: list_control.h:84
Provides a common implementation of members for the list_box, choice and combo_box classes.
Definition: list_control.h:19
Implements a Windows message.
Definition: message.h:25
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
@ e
The E key.
check_state
Specifies the state of a control, such as a check box, that can be checked, unchecked,...
Definition: check_state.h:19
@ checked
The button has a checked or latched appearance. Use this appearance to show that a toggle button has ...
@ none
No items can be selected.
@ unchecked
The control is unchecked.
Contains xtd::forms::item_check_event_handler event handler.
Contains xtd::forms::list_box control.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17