xtd 0.2.0
list_control.h
Go to the documentation of this file.
1 #pragma once
5 #include "application.h"
6 #include "control.h"
7 #include <xtd/iequatable>
8 
10 namespace xtd {
12  namespace forms {
23  class forms_export_ list_control : public control {
24  struct data;
25 
26  public:
28  class item : public object, public icomparable<item>, public xtd::iequatable<item> {
29  public:
31  class sorter {
32  public:
34 
40  template<typename type_t>
41  void operator()(type_t first, type_t last) {
42  std::sort(first, last);
43  }
45  };
46 
48 
51  item() = default;
54  item(const xtd::ustring& value); // Can't be explicit by design.
58  item(const xtd::ustring& value, const std::any& tag);
60 
62  item(const char* value); // Can't be explicit by design.
63  item(const item& value) = default;
64  item(item&& value) = default;
65  item& operator =(const item& value) = default;
66  item& operator =(item&& value) = default;
67  virtual ~item() = default;
69 
71 
75  virtual const xtd::ustring& value() const noexcept;
76 
79  virtual std::any tag() const noexcept;
81 
83 
85  int32 compare_to(const item& value) const noexcept override;
86 
87  bool equals(const item& value) const noexcept override;
88 
91  xtd::ustring to_string() const noexcept override;
93 
94  private:
95  xtd::ustring value_;
96  std::any tag_;
97  };
98 
100 
105 
107 
110  static const size_t npos = std::numeric_limits<size_t>::max();
112 
114 
118  virtual size_t selected_index() const noexcept;
122  virtual list_control& selected_index(size_t selected_index) = 0;
124 
126 
130  event<list_control, event_handler> selected_index_changed;
131 
134  event<list_control, event_handler> selected_value_changed;
136 
137  protected:
139 
142  list_control();
144 
146 
148  drawing::color default_back_color() const noexcept override;
149  drawing::color default_fore_color() const noexcept override;
151 
153 
157  virtual bool allow_selection() const noexcept;
158 
160  virtual void on_selected_index_changed(const event_args& e);
161 
163  virtual void on_selected_value_changed(const event_args& e);
164 
167  void set_selected_index(size_t value);
169 
170  private:
171  std::shared_ptr<data> data_;
172  };
173  }
174 }
Contains xtd::forms::application class.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition: event_handler.h:32
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition: icomparable.h:17
Represent an item contained in the list_control::object_collection collection.
Definition: list_control.h:28
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Represents a collection of objects.
Definition: arranged_element_collection.h:31
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: date_time.h:1063
void operator()(type_t first, type_t last)
sorter functor.
Definition: list_control.h:41
Represents an event.
Definition: event.h:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
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:31
Provides a common implementation of members for the list_box, choice and combo_box classes...
Definition: list_control.h:23
Defines the base class for controls, which are components with visual representation.
Definition: control.h:78
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
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