xtd 0.2.0
style_sheet.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../../forms_export.hpp"
6#include "../border_style.hpp"
7#include "button.hpp"
8#include "control.hpp"
9#include "form.hpp"
10#include "label.hpp"
11#include "link_label.hpp"
12#include "panel.hpp"
13#include "pseudo_state.hpp"
14#include "status_bar.hpp"
15#include "status_bar_panel.hpp"
16#include "system_colors.hpp"
17#include "theme.hpp"
18#include "user_control.hpp"
19#include "toggle_button.hpp"
20#include "tool_bar.hpp"
21#include "tool_bar_button.hpp"
22#include <xtd/collections/generic/list>
23#include <xtd/web/css/css_reader>
24#include <xtd/event_handler>
25#include <xtd/iequatable>
26#include <xtd/object>
27#include <xtd/uri>
28#include <map>
29
31class __test_style_sheet__; // Necessary for the test unit to access the private member functions
33
35namespace xtd {
37 namespace forms {
39 class control;
40 class form;
42
44 namespace style_sheets {
64 class forms_export_ style_sheet final : public xtd::iequatable<style_sheet>, public xtd::object {
65 struct data;
66
67 public:
69
72 using buttons_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::button>;
74 using controls_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::control>;
76 using forms_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::form>;
78 using labels_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::label>;
80 using link_labels_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::link_label>;
82 using panels_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::panel>;
84 using style_sheets_t = std::map<xtd::string, style_sheet>;
88 using status_bars_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::status_bar>;
90 using status_bar_panels_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::status_bar_panel>;
92 using toggle_buttons_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::toggle_button>;
94 using tool_bars_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::tool_bar>;
96 using tool_bar_buttons_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::tool_bar_button>;
98 using user_controls_t = std::map<xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::user_control>;
100
102
105 static const style_sheet empty;
107
109
115 explicit style_sheet(const xtd::string& css_text);
116
118 style_sheet(const style_sheet&);
119 style_sheet(style_sheet&&) = default;
120 style_sheet& operator =(const style_sheet&);
122
124
132 xtd::forms::style_sheets::button button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
135 const buttons_t& buttons() const noexcept;
136
139 xtd::forms::style_sheets::control control() const noexcept;
143 xtd::forms::style_sheets::control control(xtd::forms::style_sheets::pseudo_state state) const noexcept;
146 const controls_t& controls() const noexcept;
147
150 xtd::forms::style_sheets::button flat_button() const noexcept;
154 xtd::forms::style_sheets::button flat_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
157 const buttons_t& flat_buttons() const noexcept;
158
161 xtd::forms::style_sheets::toggle_button flat_toggle_button() const noexcept;
165 xtd::forms::style_sheets::toggle_button flat_toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
168 const toggle_buttons_t& flat_toggle_buttons() const noexcept;
169
172 xtd::forms::style_sheets::form form() const noexcept;
176 xtd::forms::style_sheets::form form(xtd::forms::style_sheets::pseudo_state state) const noexcept;
179 const forms_t& forms() const noexcept;
180
184 bool is_system_style_sheet() const noexcept;
185
188 xtd::forms::style_sheets::label label() const noexcept;
192 xtd::forms::style_sheets::label label(xtd::forms::style_sheets::pseudo_state state) const noexcept;
195 const labels_t& labels() const noexcept;
196
199 xtd::forms::style_sheets::link_label link_label() const noexcept;
203 xtd::forms::style_sheets::link_label link_label(xtd::forms::style_sheets::pseudo_state state) const noexcept;
206 const link_labels_t& link_labels() const noexcept;
207
210 xtd::forms::style_sheets::panel panel() const noexcept;
214 xtd::forms::style_sheets::panel panel(xtd::forms::style_sheets::pseudo_state state) const noexcept;
217 const panels_t& panels() const noexcept;
218
221 xtd::forms::style_sheets::button popup_button() const noexcept;
225 xtd::forms::style_sheets::button popup_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
228 const buttons_t& popup_buttons() const noexcept;
229
232 xtd::forms::style_sheets::toggle_button popup_toggle_button() const noexcept;
236 xtd::forms::style_sheets::toggle_button popup_toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
239 const toggle_buttons_t& popup_toggle_buttons() const noexcept;
240
243 xtd::forms::style_sheets::status_bar status_bar() const noexcept;
247 xtd::forms::style_sheets::status_bar status_bar(xtd::forms::style_sheets::pseudo_state state) const noexcept;
250 const status_bars_t& status_bars() const noexcept;
251
254 xtd::forms::style_sheets::status_bar_panel status_bar_panel() const noexcept;
258 xtd::forms::style_sheets::status_bar_panel status_bar_panel(xtd::forms::style_sheets::pseudo_state state) const noexcept;
261 const status_bar_panels_t& status_bar_panels() const noexcept;
262
265 const xtd::forms::style_sheets::system_colors& system_colors() const noexcept;
266
269 const xtd::forms::style_sheets::theme& theme() const noexcept;
270
273 xtd::forms::style_sheets::toggle_button toggle_button() const noexcept;
277 xtd::forms::style_sheets::toggle_button toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
280 const toggle_buttons_t& toggle_buttons() const noexcept;
281
284 xtd::forms::style_sheets::tool_bar tool_bar() const noexcept;
288 xtd::forms::style_sheets::tool_bar tool_bar(xtd::forms::style_sheets::pseudo_state state) const noexcept;
291 const tool_bars_t& tool_bars() const noexcept;
292
295 xtd::forms::style_sheets::tool_bar_button tool_bar_button() const noexcept;
299 xtd::forms::style_sheets::tool_bar_button tool_bar_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
302 const tool_bar_buttons_t& tool_bar_buttons() const noexcept;
303
306 xtd::forms::style_sheets::user_control user_control() const noexcept;
310 xtd::forms::style_sheets::user_control user_control(xtd::forms::style_sheets::pseudo_state state) const noexcept;
313 const user_controls_t& user_controls() const noexcept;
315
317
322 static const style_sheet& current_style_sheet() noexcept;
326 static void current_style_sheet(const style_sheet& value);
327
331 static const style_sheets_t& style_sheets() noexcept;
332
336 static const style_sheet_names_t& style_sheet_names() noexcept;
337
342 static const style_sheet& system_style_sheet() noexcept;
344
346
351 bool equals(const xtd::object& obj) const noexcept override;
355 bool equals(const style_sheet& other) const noexcept override;
356
359 xtd::size get_hash_code() const noexcept override;
361
363
369 static buttons_t button_from_css(const xtd::string& css_text);
370
375 static controls_t control_from_css(const xtd::string& css_text);
376
382 static style_sheet get_style_sheet_from_name(const xtd::string& name);
383
389 static style_sheet get_style_sheet_from_file(const xtd::string& file_name);
390
396 static style_sheet get_style_sheet_from_path(const xtd::string& path_name);
397
402 static forms_t form_from_css(const xtd::string& css_text);
403
408 static xtd::forms::style_sheets::system_colors system_colors_from_css(const xtd::string& css_text);
409
414 static xtd::forms::style_sheets::theme theme_from_css(const xtd::string& css_text);
415
419 static std::tuple<xtd::forms::style_sheets::border_type, int32, int32> to_border_type(xtd::forms::border_style border);
421
423
428 static event<style_sheet, event_handler> style_sheet_changed;
430
431 private:
432 friend class ::__test_style_sheet__; // Necessary for the test unit to access the private member functions
433 friend class xtd::forms::control;
434 friend class xtd::forms::form;
435 style_sheet(const xtd::string& css_text, bool init_system);
436
437 xtd::drawing::color background_color_from_css(const xtd::string& css_text, const xtd::drawing::color& default_value) const noexcept;
438 background_image background_image_from_css(const xtd::string& css_text, const background_image& default_value) const noexcept;
439 border_color border_color_from_css(const xtd::string& css_text, const border_color& default_value) const noexcept;
440 border_style border_style_from_css(const string& text, const border_style& default_value) const noexcept;
441 border_radius border_radius_from_css(const xtd::string& css_text, const border_radius& default_value) const noexcept;
442 border_width border_width_from_css(const xtd::string& css_text, const border_width& default_value) const noexcept;
443 xtd::drawing::color color_from_css(const xtd::string& css_text, const xtd::drawing::color& default_value) const noexcept;
444 length length_from_css(const xtd::string& css_text, const length& default_value) const noexcept;
445 margin margin_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
446 margin margin_bottom_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
447 margin margin_left_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
448 margin margin_right_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
449 margin margin_top_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
450 padding padding_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
451 padding padding_bottom_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
452 padding padding_left_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
453 padding padding_right_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
454 padding padding_top_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
455 string string_from_css(const xtd::string& css_text, const xtd::string& default_value) const noexcept;
456 xtd::forms::content_alignment text_align_from_css(const xtd::string& css_text, const xtd::forms::content_alignment& default_value) const noexcept;
457 xtd::forms::style_sheets::text_decoration text_decoration_from_css(const xtd::string& css_text, const xtd::forms::style_sheets::text_decoration& default_value) const noexcept;
458 xtd::forms::style_sheets::text_transformation text_transformation_from_css(const xtd::string& css_text, const xtd::forms::style_sheets::text_transformation& default_value) const noexcept;
459 xtd::uri uri_from_css(const xtd::string& css_text, const xtd::uri& default_value) const noexcept;
460 xtd::forms::style_sheets::white_space white_space_from_css(const xtd::string& css_text, const xtd::forms::style_sheets::white_space& default_value) const noexcept;
461
462 template<class type_t, class collection_t>
463 type_t get_state_control(const collection_t& collection, pseudo_state state) const noexcept {
464 auto result = type_t();
465 auto it = collection.find(pseudo_state::standard);
466 if (it != collection.end()) result = it->second;
467 it = collection.find(state);
468 if (it != collection.end()) result = it->second;
469 return result;
470 }
471
472 static void on_style_sheet_changed(const xtd::event_args& e);
473 static void on_system_colors_changed(const event_args& e);
474 xtd::array<xtd::string> split_values_from_text(const xtd::string& text) const noexcept;
475
476 void button_reader(xtd::web::css::css_reader& reader) noexcept;
477 void control_reader(xtd::web::css::css_reader& reader) noexcept;
478 void fill_control(const xtd::web::css::selector_map::const_iterator& selectors_iterator, xtd::forms::style_sheets::control& control) noexcept;
479 void flat_button_reader(xtd::web::css::css_reader& reader) noexcept;
480 void flat_toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
481 void form_reader(xtd::web::css::css_reader& reader) noexcept;
482 void label_reader(xtd::web::css::css_reader& reader) noexcept;
483 void link_label_reader(xtd::web::css::css_reader& reader) noexcept;
484 void panel_reader(xtd::web::css::css_reader& reader) noexcept;
485 void popup_button_reader(xtd::web::css::css_reader& reader) noexcept;
486 void popup_toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
487 void status_bar_reader(xtd::web::css::css_reader& reader) noexcept;
488 void status_bar_panel_reader(xtd::web::css::css_reader& reader) noexcept;
489 void system_colors_reader(xtd::web::css::css_reader& reader) noexcept;
490 void theme_reader(xtd::web::css::css_reader& reader) noexcept;
491 void toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
492 void tool_bar_reader(xtd::web::css::css_reader& reader) noexcept;
493 void tool_bar_button_reader(xtd::web::css::css_reader& reader) noexcept;
494 void user_control_reader(xtd::web::css::css_reader& reader) noexcept;
495
496 //static style_sheet system_style_sheet_gnome_dark() noexcept; // Declared in system_style_sheet_gnome_dark.cpp
497 //static style_sheet system_style_sheet_gnome_light() noexcept; // Declared in system_style_sheet_gnome_light.cpp
498 //static style_sheet system_style_sheet_kde_dark() noexcept; // Declared in system_style_sheet_kde_dark.cpp
499 //static style_sheet system_style_sheet_kde_light() noexcept; // Declared in system_style_sheet_kde_light.cpp
500 //static style_sheet system_style_sheet_macos_dark() noexcept; // Declared in system_style_sheet_macos_dark.cpp
501 //static style_sheet system_style_sheet_macos_light() noexcept; // Declared in system_style_sheet_macos_light.cpp
502 static style_sheet system_style_sheet_unknown_dark() noexcept; // Declared in system_style_sheet_unknown_dark.cpp
503 static style_sheet system_style_sheet_unknown_light() noexcept; // Declared in system_style_sheet_unknown_light.cpp
504 //static style_sheet system_style_sheet_windows_dark() noexcept; // Declared in system_style_sheet_windows_dark.cpp
505 //static style_sheet system_style_sheet_windows_light() noexcept; // Declared in system_style_sheet_windows_light.cpp
506
507 bool try_parse_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
508 bool try_parse_hex_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
509 bool try_parse_linear_gradient(const xtd::string& text, background_image& result) const noexcept;
510 bool try_parse_named_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
511 bool try_parse_rgb_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
512 bool try_parse_rgba_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
513 bool try_parse_hsv_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
514 bool try_parse_hsva_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
515 bool try_parse_hsl_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
516 bool try_parse_hsla_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
517 bool try_parse_system_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
518 bool try_parse_uri(const xtd::string& text, xtd::uri& result) const noexcept;
519
520 void system_colors_(const xtd::forms::style_sheets::system_colors& system_colors);
521 void theme_(const xtd::forms::style_sheets::theme& theme);
522 void theme_name_(const xtd::string& name);
523
524 static style_sheet current_style_sheet_;
525 static style_sheets_t style_sheets_;
526 static style_sheet_names_t style_sheet_names_;
527 static style_sheet system_style_sheet_;
528
529 xtd::sptr<data> data_;
530 };
531 }
532 }
533}
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
Represents text as a sequence of character units.
Definition basic_string.hpp:71
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
Represents an event.
Definition event.hpp:21
Provides a collection of button objects for use by a Windows Forms application.
Definition buttons.hpp:24
Provides a collection of label objects for use by a Windows Forms application.
Definition labels.hpp:24
The image data allows you to specify the url or gradient mode.
Definition background_image.hpp:42
The xtd::forms::style_sheets::border_color is used to set the color of the borders.
Definition border_color.hpp:33
The radius is used to add rounded borders to an element.
Definition border_radius.hpp:33
The style specifies what kind of borders to display.
Definition border_style.hpp:33
The control selector allows you to specify the box and color of a control.
Definition control.hpp:35
The xtd::forms::style_sheets::length specifies the legth and unit of many properties of the xtd::form...
Definition length.hpp:77
The length specifies the length of the borders.
Definition lengths.hpp:33
The xtd::forms::style_sheets::style_sheet allows you to specify an xtd style sheet.
Definition style_sheet.hpp:64
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.hpp:90
style_sheet(const xtd::string &css_text)
Initialize a new xtd::forms::style_sheets::style_sheet instance from specified css forrmated text.
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.hpp:96
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.hpp:94
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::control > controls_t
Represents a style sheet controls collection.
Definition style_sheet.hpp:74
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.hpp:92
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.hpp:88
std::map< xtd::string, style_sheet > style_sheets_t
Represents a style_sheets collection.
Definition style_sheet.hpp:84
static const style_sheet empty
Provides an empty xtd::forms::style_sheets::style_sheet object.
Definition style_sheet.hpp:105
style_sheet()
Initialize a new xtd::forms::style_sheets::style_sheet instance.
xtd::forms::style_sheets::button button() const noexcept
Gets the style sheet button for the xtd::forms::style_sheets::pseudo_state::standard pseudo state.
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::button > buttons_t
Represents a style sheet buttons collection.
Definition style_sheet.hpp:72
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.hpp:80
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.hpp:98
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::label > labels_t
Represents a style sheet labels collection.
Definition style_sheet.hpp:78
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::form > forms_t
Represents a style sheet forms collection.
Definition style_sheet.hpp:76
std::map< xtd::forms::style_sheets::pseudo_state, xtd::forms::style_sheets::panel > panels_t
Represents a style sheet panels collection.
Definition style_sheet.hpp:82
The theme data allows you to specify the theme informations.
Definition system_colors.hpp:34
The theme data allows you to specify the theme informations.
Definition theme.hpp:32
Provides a collection of toggle_button objects for use by a Windows Forms application.
Definition toggle_buttons.hpp:24
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
The xtd::shared_ptr_object is a shared pointer as std::shared_ptr.
Definition shared_ptr_object.hpp:30
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition uri.hpp:103
Definition css_reader.hpp:16
generic_event_handler< const xtd::event_args & > event_handler
Represents the method that will handle an event that has no event data.
Definition event_handler.hpp:24
#define forms_export_
Define shared library export.
Definition forms_export.hpp:13
xtd::forms::style_sheets::control form
The form data allows you to specify the box of a form control.
Definition form.hpp:23
text_decoration
The xtd::forms::style_sheets::text_decoration enum class is used to set or remove decorations from te...
Definition text_decoration.hpp:25
white_space
The white_space enum class specifies how white-space inside an element is handled.
Definition white_space.hpp:23
pseudo_state
The pseudo_state enum class flag specifies the pseudo state of an element.
Definition pseudo_state.hpp:23
text_transformation
The xtd::forms::style_sheets::text_transformation enum class is used to specify uppercase and lowerca...
Definition text_transformation.hpp:24
border_type
The border_type enum class specifies what kind of border to display.
Definition border_type.hpp:23
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
@ control
The left or right CTRL modifier key.
content_alignment
Specifies alignment of content on the drawing surface.
Definition content_alignment.hpp:21
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::forms::style_sheets::pseudo_state enum class.
Contains xtd::forms::style_sheets::button alias.
Contains xtd::forms::style_sheets::control class.
Contains xtd::forms::style_sheets::form alias.
Contains xtd::forms::style_sheets::label class.
Contains xtd::forms::style_sheets::panel class.
Contains xtd::forms::style_sheets::status_bar class.
Contains xtd::forms::style_sheets::status_bar_panel alias.
Contains xtd::forms::style_sheets::theme class.
Contains xtd::forms::toggle_button control.
Contains xtd::forms::tool_bar container.
Contains xtd::forms::tool_bar_button container.
Contains xtd::forms::user_control control.
Contains xtd::forms::style_sheets::system_colors class.