xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
list_control.h
Go to the documentation of this file.
1
4#pragma once
5#include "control.h"
6
7#include <algorithm>
8
10namespace xtd {
12 namespace forms {
22 public:
24 class item {
25 public:
27 class sorter {
28 public:
33 template<typename type_t>
34 void operator()(type_t first, type_t last) {
35 std::sort(first, last);
36 }
37 };
38
40 item() = default;
43 item(const xtd::ustring& value) : value_(value) {}
47 item(const xtd::ustring& value, const std::any& tag) : value_(value), tag_(tag) {}
49 item(const char* value) : value_(value) {}
50 item(const item& value) = default;
51 item(item&& value) = default;
52 item& operator=(const item& value) = default;
53 item& operator=(item&& value) = default;
54 virtual ~item() = default;
55 bool operator==(const item& value) const {return value_ == value.value_;}
56 bool operator!=(const item& value) const {return !operator==(value);}
57 bool operator<(const item& value) const {return value_ < value.value_;}
58 bool operator<=(const item& value) const {return value_ <= value.value_;}
59 bool operator>(const item& value) const {return value_ > value.value_;}
60 bool operator>=(const item& value) const {return value_ >= value.value_;}
61 friend std::ostream& operator<<(std::ostream& os, const item& value) {return os << value.to_string();}
63
66 virtual const xtd::ustring& value() const {return value_;}
67
70 virtual std::any tag() const {return tag_;}
71
74 xtd::ustring to_string() const {return value_;}
75
76 private:
77 xtd::ustring value_;
78 std::any tag_;
79 };
80
83
86 virtual size_t selected_index() const {return selected_index_;}
90 virtual list_control& selected_index(size_t selected_index) = 0;
91
95
99
101 static const size_t npos = std::numeric_limits<size_t>::max();
102
103 protected:
106
109 virtual bool allow_selection() {return true;}
110
111 virtual drawing::color default_back_color() const override {return xtd::forms::theme_colors::current_theme().window();}
112
113 virtual drawing::color default_fore_color() const override {return xtd::forms::theme_colors::current_theme().window_text();}
114
116 virtual void on_selected_index_changed(const event_args& e) {selected_index_changed(*this, e);}
117
119 virtual void on_selected_value_changed(const event_args& e) {selected_value_changed(*this, e);}
120
122 size_t selected_index_ = npos;
124 };
125 }
126}
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:27
void operator()(type_t first, type_t last)
sorter functor.
Definition list_control.h:34
Represent an item contained in the list_control::object_collection collection.
Definition list_control.h:24
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:47
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:43
virtual std::any tag() const
Gets the tag of the item.
Definition list_control.h:70
virtual const xtd::ustring & value() const
Gets the value of the item.
Definition list_control.h:66
xtd::ustring to_string() const
Returns a string containing the value of the item.
Definition list_control.h:74
Provides a common implementation of members for the list_box, choice and combo_box classes.
Definition list_control.h:21
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:113
virtual bool allow_selection()
Gets a value indicating whether the list enables selection of list items.
Definition list_control.h:109
virtual void on_selected_index_changed(const event_args &e)
Raises the list_control::selected_index_changed event.
Definition list_control.h:116
virtual drawing::color default_back_color() const override
Gets the default background color of the control.
Definition list_control.h:111
virtual void on_selected_value_changed(const event_args &e)
Raises the list_control::selected_value_changed event.
Definition list_control.h:119
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:86
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:94
event< list_control, event_handler > selected_value_changed
Occurs when the selected_value property changes.
Definition list_control.h:98
#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