xtd 0.2.0
style_sheet.h
Go to the documentation of this file.
1 #pragma once
5 #include "../../forms_export.h"
6 #include "../border_style.h"
7 #include "button.h"
8 #include "control.h"
9 #include "form.h"
10 #include "label.h"
11 #include "link_label.h"
12 #include "panel.h"
13 #include "pseudo_state.h"
14 #include "status_bar.h"
15 #include "status_bar_panel.h"
16 #include "system_colors.h"
17 #include "theme.h"
18 #include "user_control.h"
19 #include "toggle_button.h"
20 #include "tool_bar.h"
21 #include "tool_bar_button.h"
22 #include <xtd/web/css/css_reader>
23 #include <xtd/event_handler>
24 #include <xtd/iequatable>
25 #include <xtd/object>
26 #include <xtd/uri>
27 #include <map>
28 #include <vector>
29 
31 class __test_style_sheet__; // Necessary for the test unit to access the private member functions
33 
35 namespace xtd {
37  namespace forms {
39  class control;
40  class form;
42 
44  namespace style_sheets {
62  class forms_export_ style_sheet final : public xtd::iequatable<style_sheet>, public xtd::object {
63  struct data;
64 
65  public:
67 
70  using buttons_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::button>;
72  using controls_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::control>;
74  using forms_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::form>;
76  using labels_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::label>;
78  using link_labels_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::link_label>;
80  using panels_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::panel>;
82  using style_sheets_t = std::map<xtd::ustring, style_sheet>;
84  using style_sheet_names_t = std::vector<xtd::ustring>;
86  using status_bars_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::status_bar>;
88  using status_bar_panels_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::status_bar_panel>;
90  using toggle_buttons_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::toggle_button>;
92  using tool_bars_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::tool_bar>;
94  using tool_bar_buttons_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::tool_bar_button>;
96  using user_controls_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::user_control>;
98 
100 
103  static const style_sheet empty;
105 
107 
109  style_sheet();
113  explicit style_sheet(const xtd::ustring& css_text);
114 
116  style_sheet(const style_sheet&);
117  style_sheet(style_sheet&&) = default;
118  style_sheet& operator =(const style_sheet&);
120 
122 
126  xtd::forms::style_sheets::button button() const noexcept;
130  xtd::forms::style_sheets::button button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
133  const buttons_t& buttons() const noexcept;
134 
137  xtd::forms::style_sheets::control control() const noexcept;
141  xtd::forms::style_sheets::control control(xtd::forms::style_sheets::pseudo_state state) const noexcept;
144  const controls_t& controls() const noexcept;
145 
149  static const style_sheet& current_style_sheet() noexcept;
153  static void current_style_sheet(const style_sheet& value);
154 
157  xtd::forms::style_sheets::button flat_button() const noexcept;
161  xtd::forms::style_sheets::button flat_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
164  const buttons_t& flat_buttons() const noexcept;
165 
168  xtd::forms::style_sheets::toggle_button flat_toggle_button() const noexcept;
172  xtd::forms::style_sheets::toggle_button flat_toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
175  const toggle_buttons_t& flat_toggle_buttons() const noexcept;
176 
179  xtd::forms::style_sheets::form form() const noexcept;
183  xtd::forms::style_sheets::form form(xtd::forms::style_sheets::pseudo_state state) const noexcept;
186  const forms_t& forms() const noexcept;
187 
191  bool is_system_style_sheet() const noexcept;
192 
195  xtd::forms::style_sheets::label label() const noexcept;
199  xtd::forms::style_sheets::label label(xtd::forms::style_sheets::pseudo_state state) const noexcept;
202  const labels_t& labels() const noexcept;
203 
206  xtd::forms::style_sheets::link_label link_label() const noexcept;
210  xtd::forms::style_sheets::link_label link_label(xtd::forms::style_sheets::pseudo_state state) const noexcept;
213  const link_labels_t& link_labels() const noexcept;
214 
217  xtd::forms::style_sheets::panel panel() const noexcept;
221  xtd::forms::style_sheets::panel panel(xtd::forms::style_sheets::pseudo_state state) const noexcept;
224  const panels_t& panels() const noexcept;
225 
228  xtd::forms::style_sheets::button popup_button() const noexcept;
232  xtd::forms::style_sheets::button popup_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
235  const buttons_t& popup_buttons() const noexcept;
236 
239  xtd::forms::style_sheets::toggle_button popup_toggle_button() const noexcept;
243  xtd::forms::style_sheets::toggle_button popup_toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
246  const toggle_buttons_t& popup_toggle_buttons() const noexcept;
247 
250  xtd::forms::style_sheets::status_bar status_bar() const noexcept;
254  xtd::forms::style_sheets::status_bar status_bar(xtd::forms::style_sheets::pseudo_state state) const noexcept;
257  const status_bars_t& status_bars() const noexcept;
258 
261  xtd::forms::style_sheets::status_bar_panel status_bar_panel() const noexcept;
265  xtd::forms::style_sheets::status_bar_panel status_bar_panel(xtd::forms::style_sheets::pseudo_state state) const noexcept;
268  const status_bar_panels_t& status_bar_panels() const noexcept;
269 
273  static const style_sheets_t& style_sheets() noexcept;
274 
278  static const style_sheet_names_t& style_sheet_names() noexcept;
279 
282  const xtd::forms::style_sheets::system_colors& system_colors() const noexcept;
283 
288  static const style_sheet& system_style_sheet() noexcept;
289 
292  const xtd::forms::style_sheets::theme& theme() const noexcept;
293 
296  xtd::forms::style_sheets::toggle_button toggle_button() const noexcept;
300  xtd::forms::style_sheets::toggle_button toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
303  const toggle_buttons_t& toggle_buttons() const noexcept;
304 
307  xtd::forms::style_sheets::tool_bar tool_bar() const noexcept;
311  xtd::forms::style_sheets::tool_bar tool_bar(xtd::forms::style_sheets::pseudo_state state) const noexcept;
314  const tool_bars_t& tool_bars() const noexcept;
315 
318  xtd::forms::style_sheets::tool_bar_button tool_bar_button() const noexcept;
322  xtd::forms::style_sheets::tool_bar_button tool_bar_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
325  const tool_bar_buttons_t& tool_bar_buttons() const noexcept;
326 
329  xtd::forms::style_sheets::user_control user_control() const noexcept;
333  xtd::forms::style_sheets::user_control user_control(xtd::forms::style_sheets::pseudo_state state) const noexcept;
336  const user_controls_t& user_controls() const noexcept;
338 
340 
342  bool equals(const style_sheet& other) const noexcept override;
343 
348  static buttons_t button_from_css(const xtd::ustring& css_text);
349 
354  static controls_t control_from_css(const xtd::ustring& css_text);
355 
361  static style_sheet get_style_sheet_from_name(const xtd::ustring& name);
362 
368  static style_sheet get_style_sheet_from_file(const xtd::ustring& file_name);
369 
375  static style_sheet get_style_sheet_from_path(const xtd::ustring& path_name);
376 
381  static forms_t form_from_css(const xtd::ustring& css_text);
382 
387  static xtd::forms::style_sheets::system_colors system_colors_from_css(const xtd::ustring& css_text);
388 
393  static xtd::forms::style_sheets::theme theme_from_css(const xtd::ustring& css_text);
394 
398  static std::tuple<xtd::forms::style_sheets::border_type, int32, int32> to_border_type(xtd::forms::border_style border);
400 
402 
407  static event<style_sheet, event_handler> style_sheet_changed;
409 
410  private:
411  friend class ::__test_style_sheet__; // Necessary for the test unit to access the private member functions
412  friend class xtd::forms::control;
413  friend class xtd::forms::form;
414  style_sheet(const xtd::ustring& css_text, bool init_system);
415 
416  xtd::drawing::color background_color_from_css(const xtd::ustring& css_text, const xtd::drawing::color& default_value) const noexcept;
417  background_image background_image_from_css(const xtd::ustring& css_text, const background_image& default_value) const noexcept;
418  border_color border_color_from_css(const xtd::ustring& css_text, const border_color& default_value) const noexcept;
419  border_style border_style_from_css(const ustring& text, const border_style& default_value) const noexcept;
420  border_radius border_radius_from_css(const xtd::ustring& css_text, const border_radius& default_value) const noexcept;
421  border_width border_width_from_css(const xtd::ustring& css_text, const border_width& default_value) const noexcept;
422  xtd::drawing::color color_from_css(const xtd::ustring& css_text, const xtd::drawing::color& default_value) const noexcept;
423  length length_from_css(const xtd::ustring& css_text, const length& default_value) const noexcept;
424  margin margin_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
425  margin margin_bottom_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
426  margin margin_left_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
427  margin margin_right_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
428  margin margin_top_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
429  padding padding_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
430  padding padding_bottom_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
431  padding padding_left_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
432  padding padding_right_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
433  padding padding_top_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
434  ustring string_from_css(const xtd::ustring& css_text, const xtd::ustring& default_value) const noexcept;
435  xtd::forms::content_alignment text_align_from_css(const xtd::ustring& css_text, const xtd::forms::content_alignment& default_value) const noexcept;
436  xtd::forms::style_sheets::text_decoration text_decoration_from_css(const xtd::ustring& css_text, const xtd::forms::style_sheets::text_decoration& default_value) const noexcept;
437  xtd::forms::style_sheets::text_transformation text_transformation_from_css(const xtd::ustring& css_text, const xtd::forms::style_sheets::text_transformation& default_value) const noexcept;
438  xtd::uri uri_from_css(const xtd::ustring& css_text, const xtd::uri& default_value) const noexcept;
439  xtd::forms::style_sheets::white_space white_space_from_css(const xtd::ustring& css_text, const xtd::forms::style_sheets::white_space& default_value) const noexcept;
440 
441  template<typename type_t, typename collection_t>
442  type_t get_state_control(const collection_t& collection, pseudo_state state) const noexcept {
443  auto result = type_t();
444  auto it = collection.find(pseudo_state::standard);
445  if (it != collection.end()) result = it->second;
446  it = collection.find(state);
447  if (it != collection.end()) result = it->second;
448  return result;
449  }
450 
451  static void on_style_sheet_changed(const xtd::event_args& e);
452  static void on_system_colors_changed(const event_args& e);
453  std::vector<xtd::ustring> split_values_from_text(const xtd::ustring& text) const noexcept;
454 
455  void button_reader(xtd::web::css::css_reader& reader) noexcept;
456  void control_reader(xtd::web::css::css_reader& reader) noexcept;
457  void fill_control(const xtd::web::css::selector_map::const_iterator& selectors_iterator, xtd::forms::style_sheets::control& control) noexcept;
458  void flat_button_reader(xtd::web::css::css_reader& reader) noexcept;
459  void flat_toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
460  void form_reader(xtd::web::css::css_reader& reader) noexcept;
461  void label_reader(xtd::web::css::css_reader& reader) noexcept;
462  void link_label_reader(xtd::web::css::css_reader& reader) noexcept;
463  void panel_reader(xtd::web::css::css_reader& reader) noexcept;
464  void popup_button_reader(xtd::web::css::css_reader& reader) noexcept;
465  void popup_toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
466  void status_bar_reader(xtd::web::css::css_reader& reader) noexcept;
467  void status_bar_panel_reader(xtd::web::css::css_reader& reader) noexcept;
468  void system_colors_reader(xtd::web::css::css_reader& reader) noexcept;
469  void theme_reader(xtd::web::css::css_reader& reader) noexcept;
470  void toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
471  void tool_bar_reader(xtd::web::css::css_reader& reader) noexcept;
472  void tool_bar_button_reader(xtd::web::css::css_reader& reader) noexcept;
473  void user_control_reader(xtd::web::css::css_reader& reader) noexcept;
474 
475  //static style_sheet system_style_sheet_gnome_dark() noexcept; // Declared in system_style_sheet_gnome_dark.cpp
476  //static style_sheet system_style_sheet_gnome_light() noexcept; // Declared in system_style_sheet_gnome_light.cpp
477  //static style_sheet system_style_sheet_kde_dark() noexcept; // Declared in system_style_sheet_kde_dark.cpp
478  //static style_sheet system_style_sheet_kde_light() noexcept; // Declared in system_style_sheet_kde_light.cpp
479  //static style_sheet system_style_sheet_macos_dark() noexcept; // Declared in system_style_sheet_macos_dark.cpp
480  //static style_sheet system_style_sheet_macos_light() noexcept; // Declared in system_style_sheet_macos_light.cpp
481  static style_sheet system_style_sheet_unknown_dark() noexcept; // Declared in system_style_sheet_unknown_dark.cpp
482  static style_sheet system_style_sheet_unknown_light() noexcept; // Declared in system_style_sheet_unknown_light.cpp
483  //static style_sheet system_style_sheet_windows_dark() noexcept; // Declared in system_style_sheet_windows_dark.cpp
484  //static style_sheet system_style_sheet_windows_light() noexcept; // Declared in system_style_sheet_windows_light.cpp
485 
486  bool try_parse_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
487  bool try_parse_hex_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
488  bool try_parse_linear_gradient(const xtd::ustring& text, background_image& result) const noexcept;
489  bool try_parse_named_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
490  bool try_parse_rgb_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
491  bool try_parse_rgba_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
492  bool try_parse_hsv_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
493  bool try_parse_hsva_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
494  bool try_parse_hsl_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
495  bool try_parse_hsla_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
496  bool try_parse_system_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
497  bool try_parse_uri(const xtd::ustring& text, xtd::uri& result) const noexcept;
498 
499  void system_colors_(const xtd::forms::style_sheets::system_colors& system_colors);
500  void theme_(const xtd::forms::style_sheets::theme& theme);
501  void theme_name_(const xtd::ustring& name);
502 
503  static style_sheet current_style_sheet_;
504  static style_sheets_t style_sheets_;
505  static style_sheet_names_t style_sheet_names_;
506  static style_sheet system_style_sheet_;
507 
508  std::shared_ptr<data> data_;
509  };
510  }
511  }
512 }
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::panel > panels_t
Represents a style sheet panels collection.
Definition: style_sheet.h:80
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::form > forms_t
Represents a style sheet forms collection.
Definition: style_sheet.h:74
Contains xtd::forms::style_sheets::status_bar_panel alias.
Contains xtd::forms::style_sheets::control class.
The xtd::forms::style_sheets::border_color is used to set the color of the borders.
Definition: border_color.h:31
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::label > labels_t
Represents a style sheet labels collection.
Definition: style_sheet.h:76
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
border_type
The border_type enum class specifies what kind of border to display.
Definition: border_type.h:21
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::status_bar > status_bars_t
Represents a style sheet tool_bars collection.
Definition: style_sheet.h:86
xtd::forms::style_sheets::control button
The buttton data allows you to specify the box of a button control.
Definition: button.h:23
Contains xtd::forms::style_sheets::label class.
The control selector allows you to specify the box and color of a control.
Definition: control.h:33
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::tool_bar_button > tool_bar_buttons_t
Represents a style sheet buttons collection.
Definition: style_sheet.h:94
The radius is used to add rounded borders to an element.
Definition: border_radius.h:31
white_space
The white_space enum class specifies how white-space inside an element is handled.
Definition: white_space.h:21
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Contains xtd::forms::style_sheets::theme class.
The image data allows you to specify the url or gradient mode.
Definition: background_image.h:40
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::user_control > user_controls_t
Represents a style sheet user_controls collection.
Definition: style_sheet.h:96
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Contains xtd::forms::style_sheets::status_bar class.
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::toggle_button > toggle_buttons_t
Represents a style sheet toggle buttons collection.
Definition: style_sheet.h:90
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::control > controls_t
Represents a style sheet controls collection.
Definition: style_sheet.h:72
pseudo_state
The pseudo_state enum class flag specifies the pseudo state of an element.
Definition: pseudo_state.h:21
std::map< xtd::ustring, style_sheet > style_sheets_t
Represents a style_sheets collection.
Definition: style_sheet.h:82
The theme data allows you to specify the theme informations.
Definition: theme.h:30
Definition: css_reader.h:16
Contains xtd::forms::style_sheets::system_colors class.
Contains xtd::forms::style_sheets::pseudo_state enum class.
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::link_label > link_labels_t
Represents a style sheet link_label collection.
Definition: style_sheet.h:78
Represents an event.
Definition: event.h:21
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::tool_bar > tool_bars_t
Represents a style sheet tool_bars collection.
Definition: style_sheet.h:92
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::status_bar_panel > status_bar_panels_t
Represents a style sheet buttons collection.
Definition: style_sheet.h:88
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
content_alignment
Specifies alignment of content on the drawing surface.
Definition: content_alignment.h:19
Contains xtd::forms::style_sheets::user_control class.
The style specifies what kind of borders to display.
Definition: border_style.h:31
Provides a collection of button objects for use by a Windows Forms application.
Definition: buttons.h:23
std::vector< xtd::ustring > style_sheet_names_t
Represents a style_sheet names collection.
Definition: style_sheet.h:84
text_transformation
The xtd::forms::style_sheets::text_transformation enum class is used to specify uppercase and lowerca...
Definition: text_transformation.h:22
Contains xtd::forms::style_sheets::toggle_button alias.
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition: uri.h:103
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
xtd::forms::style_sheets::control form
The form data allows you to specify the box of a form control.
Definition: form.h:21
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
The xtd::forms::style_sheets::length specifies the legth and unit of many properties of the xtd::form...
Definition: length.h:75
The length specifies the length of the borders.
Definition: lengths.h:31
Contains xtd::forms::style_sheets::button alias.
Contains xtd::forms::style_sheets::panel class.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
Contains xtd::forms::style_sheets::tool_bar class.
Provides a collection of toggle_button objects for use by a Windows Forms application.
Definition: toggle_buttons.h:23
text_decoration
The xtd::forms::style_sheets::text_decoration enum class is used to set or remove decorations from te...
Definition: text_decoration.h:23
The theme data allows you to specify the theme informations.
Definition: system_colors.h:32
Contains xtd::forms::style_sheets::tool_bar_button alias.
The xtd::forms::style_sheets::style_sheet allows you to specify an xtd style sheet.
Definition: style_sheet.h:62
Contains xtd::forms::style_sheets::form alias.
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::button > buttons_t
Represents a style sheet buttons collection.
Definition: style_sheet.h:70
static const style_sheet empty
Provides an empty xtd::forms::style_sheets::style_sheet object.
Definition: style_sheet.h:103
The left or right CTRL modifier key.