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.
list_control.h
Go to the documentation of this file.
1 #pragma once
5 #include "control.h"
6 
8 namespace xtd {
10  namespace forms {
19  class forms_export_ list_control : public control {
20  public:
22  class item {
23  public:
25  class sorter {
26  public:
28 
34  template<typename type_t>
35  void operator()(type_t first, type_t last) {
36  std::sort(first, last);
37  }
39  };
40 
42 
45  item() = default;
48  item(const xtd::ustring& value) : value_(value) {}
52  item(const xtd::ustring& value, const std::any& tag) : value_(value), tag_(tag) {}
54 
56  item(const char* value) : value_(value) {}
57  item(const item& value) = default;
58  item(item&& value) = default;
59  item& operator=(const item& value) = default;
60  item& operator=(item&& value) = default;
61  virtual ~item() = default;
62  bool operator==(const item& value) const {return value_ == value.value_;}
63  bool operator!=(const item& value) const {return !operator==(value);}
64  bool operator<(const item& value) const {return value_ < value.value_;}
65  bool operator<=(const item& value) const {return value_ <= value.value_;}
66  bool operator>(const item& value) const {return value_ > value.value_;}
67  bool operator>=(const item& value) const {return value_ >= value.value_;}
68  friend std::ostream& operator<<(std::ostream& os, const item& value) {return os << value.to_string();}
70 
72 
76  virtual const xtd::ustring& value() const {return value_;}
77 
80  virtual std::any tag() const {return tag_;}
82 
84 
88  xtd::ustring to_string() const {return value_;}
90 
91  private:
92  xtd::ustring value_;
93  std::any tag_;
94  };
95 
97 
102 
104 
107  static const size_t npos = std::numeric_limits<size_t>::max();
109 
111 
115  virtual size_t selected_index() const {return data_->selected_index;}
119  virtual list_control& selected_index(size_t selected_index) = 0;
121 
123 
129 
135 
136  protected:
138 
141  list_control();
143 
145 
149  virtual bool allow_selection() {return true;}
150 
151  virtual drawing::color default_back_color() const override {return xtd::forms::theme_colors::current_theme().window();}
152  virtual drawing::color default_fore_color() const override {return xtd::forms::theme_colors::current_theme().window_text();}
153 
155  virtual void on_selected_index_changed(const event_args& e) {selected_index_changed(*this, e);}
156 
158  virtual void on_selected_value_changed(const event_args& e) {selected_value_changed(*this, e);}
159 
162  void set_selected_index(size_t value) {data_->selected_index = value;}
164 
165  private:
166  struct data {
167  size_t selected_index = npos;
168  };
169  std::shared_ptr<data> data_ = std::make_shared<data>();
170  };
171  }
172 }
virtual void on_selected_value_changed(const event_args &e)
Raises the list_control::selected_value_changed event.
Definition: list_control.h:158
item(const xtd::ustring &value)
Initializes a new instance of the item class with specified value.
Definition: list_control.h:48
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
Represent an item contained in the list_control::object_collection collection.
Definition: list_control.h:22
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
event< list_control, event_handler > selected_value_changed
Occurs when the selected_value property changes.
Definition: list_control.h:133
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
void set_selected_index(size_t value)
Set the currently selected item.
Definition: list_control.h:162
virtual void on_selected_index_changed(const event_args &e)
Raises the list_control::selected_index_changed event.
Definition: list_control.h:155
event< list_control, event_handler > selected_index_changed
Occurs when the selected_index property changes.
Definition: list_control.h:128
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
void operator()(type_t first, type_t last)
sorter functor.
Definition: list_control.h:35
Represents an event.
Definition: event.h:21
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
Represent the sorter class used by list_control::object_collection collection.
Definition: list_control.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, const std::any &tag)
Initializes a new instance of the item class with specified value and tag.
Definition: list_control.h:52
Contains xtd::forms::control control.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
virtual drawing::color default_back_color() const override
Gets the default background color of the control.
Definition: list_control.h:151
virtual bool allow_selection()
Gets a value indicating whether the list enables selection of list items.
Definition: list_control.h:149
virtual std::any tag() const
Gets the tag of the item.
Definition: list_control.h:80
xtd::ustring to_string() const
Returns a string containing the value of the item.
Definition: list_control.h:88
virtual const xtd::ustring & value() const
Gets the value of the item.
Definition: list_control.h:76
virtual size_t selected_index() const
Gets the zero-based index of the currently selected item.
Definition: list_control.h:115
virtual drawing::color default_fore_color() const override
Gets the default foreground color of the control.
Definition: list_control.h:152