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_box.h
Go to the documentation of this file.
1 #pragma once
6 #include "border_style.h"
7 #include "list_control.h"
8 #include "selection_mode.h"
9 
11 namespace xtd {
13  namespace forms {
23  class forms_export_ list_box : public list_control {
24  public:
26  using selected_index_collection = std::vector<size_t>;
27 
29  using selected_object_collection = std::vector<item>;
30 
32  list_box();
33 
36  virtual forms::border_style border_style() const {return data_->border_style;}
41 
42  drawing::color default_back_color() const override {return xtd::forms::theme_colors::current_theme().window();}
43 
44  drawing::color default_fore_color() const override {return xtd::forms::theme_colors::current_theme().window_text();}
45 
46  drawing::size default_size() const override {return {120, 96};}
47 
51  object_collection& items() {return data_->items;}
54  const object_collection& items() const {return data_->items;}
59  const list_box& items(const object_collection& items) {
60  data_->items = items;
61  return *this;
62  }
63 
68  list_control& selected_index(size_t selected_index) override;
69 
74  virtual selected_index_collection selected_indices() const;
75 
80  const item& selected_item() const {return data_->selected_item;}
86  list_box& selected_item(const item& selected_item);
87 
92  selected_object_collection selected_items() const;
93 
97  virtual forms::selection_mode selection_mode() const {return data_->selection_mode;}
103 
107  virtual bool sorted() const {return data_->sorted;}
112  virtual list_box& sorted(bool sorted);
113 
114  using list_control::text;
117  control& text(const xtd::ustring& text) override {return *this;}
118 
121  void begin_update();
124  void end_update();
125 
126  protected:
127  bool allow_selection() override {return data_->selection_mode != forms::selection_mode::none;}
128 
129  forms::create_params create_params() const override;
130 
131  void on_handle_created(const event_args& e) override;
132  void on_selected_value_changed(const event_args& e) override;
133 
134  void wnd_proc(message& message) override;
135 
138  virtual void wm_reflect_command(message& message);
139 
142  virtual void wm_mouse_double_click(message& message);
143 
146  virtual void wm_mouse_down(message& message);
147 
150  virtual void wm_mouse_up(message& message);
151 
152  private:
153  struct data {
155  object_collection items;
156  item selected_item;
158  bool sorted = false;
159  };
160  std::shared_ptr<data> data_ = std::make_shared<data>();
161  };
162  }
163 }
Represents a standard Windows list box.
Definition: list_box.h:23
Contains xtd::forms::selection_mode enum class.
drawing::size default_size() const override
Gets the default size of the control.
Definition: list_box.h:46
object_collection & items()
Gets the items of the list_box.
Definition: list_box.h:51
virtual forms::border_style border_style() const
Gets the type of border that is drawn around the list_box.
Definition: list_box.h:36
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
Contains xtd::forms::arranged_element_collection collection.
Represent an item contained in the list_control::object_collection collection.
Definition: list_control.h:22
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
virtual bool sorted() const
Gets a value indicating whether the items in the list_box are sorted alphabetically.
Definition: list_box.h:107
std::vector< item > selected_object_collection
Represents the collection of selected items in the list_box.
Definition: list_box.h:29
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
virtual forms::selection_mode selection_mode() const
Gets the method in which items are selected in the list_box.
Definition: list_box.h:97
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
std::vector< size_t > selected_index_collection
Represents the collection containing the indexes to the selected items in a list_box.
Definition: list_box.h:26
const object_collection & items() const
Gets the items of the list_box.
Definition: list_box.h:54
control & text(const xtd::ustring &text) override
Sets the text associated with this control.
Definition: list_box.h:117
drawing::color default_fore_color() const override
Gets the default foreground color of the control.
Definition: list_box.h:44
No items can be selected.
border_style
Specifies the border style for a control.
Definition: border_style.h:18
Implements a Windows message.
Definition: message.h:25
const list_box & items(const object_collection &items)
Sets the items of the list_box.
Definition: list_box.h:59
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
Contains xtd::forms::list_control control.
bool allow_selection() override
Gets a value indicating whether the list enables selection of list items.
Definition: list_box.h:127
const item & selected_item() const
Gets the currently selected item in the list_box.
Definition: list_box.h:80
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
Only one item can be selected.
virtual const xtd::ustring & text() const
Gets the text associated with this control.
Contains xtd::forms::border_style enum class.
selection_mode
Specifies the selection behavior of a list box.
Definition: selection_mode.h:18
virtual size_t selected_index() const
Gets the zero-based index of the currently selected item.
Definition: list_control.h:84
drawing::color default_back_color() const override
Gets the default background color of the control.
Definition: list_box.h:42