xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
checked_list_box.h
Go to the documentation of this file.
1
4#pragma once
6#include "list_box.h"
7
9namespace 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 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:
81 forms::check_state check_state_ = forms::check_state::unchecked;
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
104
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
125 using list_box::selected_index;
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
149
150 using list_box::text;
153 control& text(const xtd::ustring& text) override {
154 selected_item_ = {text};
155 return *this;
156 }
157
164
169 bool get_item_checked(size_t index) const;
170
176
180 const xtd::ustring& get_item_text(size_t index) const;
181
186 void set_item_checked(size_t index, bool checked);
187
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
219
221
223
224 void wm_mouse_up(message& message) override;
225
227 object_collection items_;
228 item selected_item_;
230 };
231 }
232}
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:73
virtual forms::check_state check_state() const
Gets the state of the item.
Definition: checked_list_box.h:78
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
const item & selected_item() const
Gets the currently selected item in the checked_list_box.
Definition: checked_list_box.h:137
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
void wm_mouse_down(message &message) override
Processes the mouse down message the list_box control receives from the top-level window.
const object_collection & items() const
Gets the collection of items in this checked_list_box.
Definition: checked_list_box.h:117
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
void end_update()
Resumes painting the checked_list_box control after painting is suspended by the begin_update method.
const list_box & items(const object_collection &items)
Sets the collection of items in this checked_list_box.
Definition: checked_list_box.h:120
control & text(const xtd::ustring &text) override
Sets the text associated with this control.
Definition: checked_list_box.h:153
virtual void on_item_check(item_check_event_args &e)
Raises the checked_list_box::item_check event.
Definition: checked_list_box.h:212
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.
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.
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:91
object_collection & items()
Gets the collection of items in this checked_list_box.
Definition: checked_list_box.h:113
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.
checked_item_collection checked_items() const
Collection of checked items in this checked_list_box.
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...
const xtd::ustring & get_item_text(size_t index) const
Returns the text value of the current item.
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:204
list_box & selected_item(const item &selected_item)
Sets the currently selected item in the list_box.
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:94
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
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
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 ...
@ 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