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.
list_control.h
Go to the documentation of this file.
1 #pragma once
5 #include "control.h"
6 
8 namespace xtd {
10  namespace forms {
20  public:
22  class item {
23  public:
25  class sorter {
26  public:
31  template<typename type_t>
32  void operator()(type_t first, type_t last) {
33  std::sort(first, last);
34  }
35  };
36 
38  item() = default;
41  item(const xtd::ustring& value) : value_(value) {}
45  item(const xtd::ustring& value, const std::any& tag) : value_(value), tag_(tag) {}
47  item(const char* value) : value_(value) {}
48  item(const item& value) = default;
49  item(item&& value) = default;
50  item& operator=(const item& value) = default;
51  item& operator=(item&& value) = default;
52  virtual ~item() = default;
53  bool operator==(const item& value) const {return value_ == value.value_;}
54  bool operator!=(const item& value) const {return !operator==(value);}
55  bool operator<(const item& value) const {return value_ < value.value_;}
56  bool operator<=(const item& value) const {return value_ <= value.value_;}
57  bool operator>(const item& value) const {return value_ > value.value_;}
58  bool operator>=(const item& value) const {return value_ >= value.value_;}
59  friend std::ostream& operator<<(std::ostream& os, const item& value) {return os << value.to_string();}
61 
64  virtual const xtd::ustring& value() const {return value_;}
65 
68  virtual std::any tag() const {return tag_;}
69 
72  xtd::ustring to_string() const {return value_;}
73 
74  private:
75  xtd::ustring value_;
76  std::any tag_;
77  };
78 
81 
84  virtual size_t selected_index() const {return selected_index_;}
88  virtual list_control& selected_index(size_t selected_index) = 0;
89 
93 
97 
99  static const size_t npos = std::numeric_limits<size_t>::max();
100 
101  protected:
104 
107  virtual bool allow_selection() {return true;}
108 
109  virtual drawing::color default_back_color() const override {return xtd::forms::theme_colors::current_theme().window();}
110 
111  virtual drawing::color default_fore_color() const override {return xtd::forms::theme_colors::current_theme().window_text();}
112 
114  virtual void on_selected_index_changed(const event_args& e) {selected_index_changed(*this, e);}
115 
117  virtual void on_selected_value_changed(const event_args& e) {selected_value_changed(*this, e);}
118 
120  size_t selected_index_ = npos;
122  };
123  }
124 }
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.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
Represents an event.
Definition: event.h:21
Defines the base class for controls, which are components with visual representation.
Definition: control.h:67
Represents a collection of objects.
Definition: arranged_element_collection.h:28
Represent the sorter class used by list_control::object_collection collection.
Definition: list_control.h:25
void operator()(type_t first, type_t last)
sorter functor.
Definition: list_control.h:32
Represent an item contained in the list_control::object_collection collection.
Definition: list_control.h:22
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:45
item()=default
Initializes a new instance of the item class.
item(const xtd::ustring &value)
Initializes a new instance of the item class with specified value.
Definition: list_control.h:41
virtual const xtd::ustring & value() const
Gets the value of the item.
Definition: list_control.h:64
virtual std::any tag() const
Gets the tag of the item.
Definition: list_control.h:68
xtd::ustring to_string() const
Returns a string containing the value of the item.
Definition: list_control.h:72
Provides a common implementation of members for the list_box, choice and combo_box classes.
Definition: list_control.h:19
virtual list_control & selected_index(size_t selected_index)=0
When overridden in a derived class, Sets the zero-based index of the currently selected item.
virtual drawing::color default_fore_color() const override
Gets the default foreground color of the control.
Definition: list_control.h:111
virtual bool allow_selection()
Gets a value indicating whether the list enables selection of list items.
Definition: list_control.h:107
virtual void on_selected_index_changed(const event_args &e)
Raises the list_control::selected_index_changed event.
Definition: list_control.h:114
virtual drawing::color default_back_color() const override
Gets the default background color of the control.
Definition: list_control.h:109
virtual void on_selected_value_changed(const event_args &e)
Raises the list_control::selected_value_changed event.
Definition: list_control.h:117
list_control()
Initializes a new instance of the list_control class.
virtual size_t selected_index() const
Gets the zero-based index of the currently selected item.
Definition: list_control.h:84
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::forms::control control.
event< list_control, event_handler > selected_index_changed
Occurs when the selected_index property changes.
Definition: list_control.h:92
event< list_control, event_handler > selected_value_changed
Occurs when the selected_value property changes.
Definition: list_control.h:96
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
@ e
The E key.
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