xtd 0.2.0
Loading...
Searching...
No Matches
style_sheet.h
Go to the documentation of this file.
1
4#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
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 {
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
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
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
148 xtd::forms::style_sheets::button flat_button() const noexcept;
152 xtd::forms::style_sheets::button flat_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
155 const buttons_t& flat_buttons() const noexcept;
156
159 xtd::forms::style_sheets::toggle_button flat_toggle_button() const noexcept;
163 xtd::forms::style_sheets::toggle_button flat_toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
166 const toggle_buttons_t& flat_toggle_buttons() const noexcept;
167
170 xtd::forms::style_sheets::form form() const noexcept;
174 xtd::forms::style_sheets::form form(xtd::forms::style_sheets::pseudo_state state) const noexcept;
177 const forms_t& forms() const noexcept;
178
182 bool is_system_style_sheet() const noexcept;
183
186 xtd::forms::style_sheets::label label() const noexcept;
190 xtd::forms::style_sheets::label label(xtd::forms::style_sheets::pseudo_state state) const noexcept;
193 const labels_t& labels() const noexcept;
194
197 xtd::forms::style_sheets::link_label link_label() const noexcept;
201 xtd::forms::style_sheets::link_label link_label(xtd::forms::style_sheets::pseudo_state state) const noexcept;
204 const link_labels_t& link_labels() const noexcept;
205
208 xtd::forms::style_sheets::panel panel() const noexcept;
212 xtd::forms::style_sheets::panel panel(xtd::forms::style_sheets::pseudo_state state) const noexcept;
215 const panels_t& panels() const noexcept;
216
219 xtd::forms::style_sheets::button popup_button() const noexcept;
223 xtd::forms::style_sheets::button popup_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
226 const buttons_t& popup_buttons() const noexcept;
227
230 xtd::forms::style_sheets::toggle_button popup_toggle_button() const noexcept;
234 xtd::forms::style_sheets::toggle_button popup_toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
237 const toggle_buttons_t& popup_toggle_buttons() const noexcept;
238
241 xtd::forms::style_sheets::status_bar status_bar() const noexcept;
245 xtd::forms::style_sheets::status_bar status_bar(xtd::forms::style_sheets::pseudo_state state) const noexcept;
248 const status_bars_t& status_bars() const noexcept;
249
252 xtd::forms::style_sheets::status_bar_panel status_bar_panel() const noexcept;
256 xtd::forms::style_sheets::status_bar_panel status_bar_panel(xtd::forms::style_sheets::pseudo_state state) const noexcept;
259 const status_bar_panels_t& status_bar_panels() const noexcept;
260
263 const xtd::forms::style_sheets::system_colors& system_colors() const noexcept;
264
267 const xtd::forms::style_sheets::theme& theme() const noexcept;
268
271 xtd::forms::style_sheets::toggle_button toggle_button() const noexcept;
275 xtd::forms::style_sheets::toggle_button toggle_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
278 const toggle_buttons_t& toggle_buttons() const noexcept;
279
282 xtd::forms::style_sheets::tool_bar tool_bar() const noexcept;
286 xtd::forms::style_sheets::tool_bar tool_bar(xtd::forms::style_sheets::pseudo_state state) const noexcept;
289 const tool_bars_t& tool_bars() const noexcept;
290
293 xtd::forms::style_sheets::tool_bar_button tool_bar_button() const noexcept;
297 xtd::forms::style_sheets::tool_bar_button tool_bar_button(xtd::forms::style_sheets::pseudo_state state) const noexcept;
300 const tool_bar_buttons_t& tool_bar_buttons() const noexcept;
301
304 xtd::forms::style_sheets::user_control user_control() const noexcept;
308 xtd::forms::style_sheets::user_control user_control(xtd::forms::style_sheets::pseudo_state state) const noexcept;
311 const user_controls_t& user_controls() const noexcept;
313
315
320 static const style_sheet& current_style_sheet() noexcept;
324 static void current_style_sheet(const style_sheet& value);
325
329 static const style_sheets_t& style_sheets() noexcept;
330
334 static const style_sheet_names_t& style_sheet_names() noexcept;
335
340 static const style_sheet& system_style_sheet() noexcept;
342
344
346 bool equals(const style_sheet& other) const noexcept override;
348
350
356 static buttons_t button_from_css(const xtd::ustring& css_text);
357
362 static controls_t control_from_css(const xtd::ustring& css_text);
363
369 static style_sheet get_style_sheet_from_name(const xtd::ustring& name);
370
376 static style_sheet get_style_sheet_from_file(const xtd::ustring& file_name);
377
383 static style_sheet get_style_sheet_from_path(const xtd::ustring& path_name);
384
389 static forms_t form_from_css(const xtd::ustring& css_text);
390
395 static xtd::forms::style_sheets::system_colors system_colors_from_css(const xtd::ustring& css_text);
396
401 static xtd::forms::style_sheets::theme theme_from_css(const xtd::ustring& css_text);
402
406 static std::tuple<xtd::forms::style_sheets::border_type, int32, int32> to_border_type(xtd::forms::border_style border);
408
410
415 static event<style_sheet, event_handler> style_sheet_changed;
417
418 private:
419 friend class ::__test_style_sheet__; // Necessary for the test unit to access the private member functions
420 friend class xtd::forms::control;
421 friend class xtd::forms::form;
422 style_sheet(const xtd::ustring& css_text, bool init_system);
423
424 xtd::drawing::color background_color_from_css(const xtd::ustring& css_text, const xtd::drawing::color& default_value) const noexcept;
425 background_image background_image_from_css(const xtd::ustring& css_text, const background_image& default_value) const noexcept;
426 border_color border_color_from_css(const xtd::ustring& css_text, const border_color& default_value) const noexcept;
427 border_style border_style_from_css(const ustring& text, const border_style& default_value) const noexcept;
428 border_radius border_radius_from_css(const xtd::ustring& css_text, const border_radius& default_value) const noexcept;
429 border_width border_width_from_css(const xtd::ustring& css_text, const border_width& default_value) const noexcept;
430 xtd::drawing::color color_from_css(const xtd::ustring& css_text, const xtd::drawing::color& default_value) const noexcept;
431 length length_from_css(const xtd::ustring& css_text, const length& default_value) const noexcept;
432 margin margin_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
433 margin margin_bottom_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
434 margin margin_left_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
435 margin margin_right_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
436 margin margin_top_from_css(const xtd::ustring& css_text, const margin& default_value) const noexcept;
437 padding padding_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
438 padding padding_bottom_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
439 padding padding_left_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
440 padding padding_right_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
441 padding padding_top_from_css(const xtd::ustring& css_text, const padding& default_value) const noexcept;
442 ustring string_from_css(const xtd::ustring& css_text, const xtd::ustring& default_value) const noexcept;
443 xtd::forms::content_alignment text_align_from_css(const xtd::ustring& css_text, const xtd::forms::content_alignment& default_value) const noexcept;
444 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;
445 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;
446 xtd::uri uri_from_css(const xtd::ustring& css_text, const xtd::uri& default_value) const noexcept;
447 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;
448
449 template<typename type_t, typename collection_t>
450 type_t get_state_control(const collection_t& collection, pseudo_state state) const noexcept {
451 auto result = type_t();
452 auto it = collection.find(pseudo_state::standard);
453 if (it != collection.end()) result = it->second;
454 it = collection.find(state);
455 if (it != collection.end()) result = it->second;
456 return result;
457 }
458
459 static void on_style_sheet_changed(const xtd::event_args& e);
460 static void on_system_colors_changed(const event_args& e);
461 std::vector<xtd::ustring> split_values_from_text(const xtd::ustring& text) const noexcept;
462
463 void button_reader(xtd::web::css::css_reader& reader) noexcept;
464 void control_reader(xtd::web::css::css_reader& reader) noexcept;
465 void fill_control(const xtd::web::css::selector_map::const_iterator& selectors_iterator, xtd::forms::style_sheets::control& control) noexcept;
466 void flat_button_reader(xtd::web::css::css_reader& reader) noexcept;
467 void flat_toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
468 void form_reader(xtd::web::css::css_reader& reader) noexcept;
469 void label_reader(xtd::web::css::css_reader& reader) noexcept;
470 void link_label_reader(xtd::web::css::css_reader& reader) noexcept;
471 void panel_reader(xtd::web::css::css_reader& reader) noexcept;
472 void popup_button_reader(xtd::web::css::css_reader& reader) noexcept;
473 void popup_toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
474 void status_bar_reader(xtd::web::css::css_reader& reader) noexcept;
475 void status_bar_panel_reader(xtd::web::css::css_reader& reader) noexcept;
476 void system_colors_reader(xtd::web::css::css_reader& reader) noexcept;
477 void theme_reader(xtd::web::css::css_reader& reader) noexcept;
478 void toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
479 void tool_bar_reader(xtd::web::css::css_reader& reader) noexcept;
480 void tool_bar_button_reader(xtd::web::css::css_reader& reader) noexcept;
481 void user_control_reader(xtd::web::css::css_reader& reader) noexcept;
482
483 //static style_sheet system_style_sheet_gnome_dark() noexcept; // Declared in system_style_sheet_gnome_dark.cpp
484 //static style_sheet system_style_sheet_gnome_light() noexcept; // Declared in system_style_sheet_gnome_light.cpp
485 //static style_sheet system_style_sheet_kde_dark() noexcept; // Declared in system_style_sheet_kde_dark.cpp
486 //static style_sheet system_style_sheet_kde_light() noexcept; // Declared in system_style_sheet_kde_light.cpp
487 //static style_sheet system_style_sheet_macos_dark() noexcept; // Declared in system_style_sheet_macos_dark.cpp
488 //static style_sheet system_style_sheet_macos_light() noexcept; // Declared in system_style_sheet_macos_light.cpp
489 static style_sheet system_style_sheet_unknown_dark() noexcept; // Declared in system_style_sheet_unknown_dark.cpp
490 static style_sheet system_style_sheet_unknown_light() noexcept; // Declared in system_style_sheet_unknown_light.cpp
491 //static style_sheet system_style_sheet_windows_dark() noexcept; // Declared in system_style_sheet_windows_dark.cpp
492 //static style_sheet system_style_sheet_windows_light() noexcept; // Declared in system_style_sheet_windows_light.cpp
493
494 bool try_parse_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
495 bool try_parse_hex_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
496 bool try_parse_linear_gradient(const xtd::ustring& text, background_image& result) const noexcept;
497 bool try_parse_named_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
498 bool try_parse_rgb_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
499 bool try_parse_rgba_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
500 bool try_parse_hsv_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
501 bool try_parse_hsva_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
502 bool try_parse_hsl_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
503 bool try_parse_hsla_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
504 bool try_parse_system_color(const xtd::ustring& text, xtd::drawing::color& result) const noexcept;
505 bool try_parse_uri(const xtd::ustring& text, xtd::uri& result) const noexcept;
506
507 void system_colors_(const xtd::forms::style_sheets::system_colors& system_colors);
508 void theme_(const xtd::forms::style_sheets::theme& theme);
509 void theme_name_(const xtd::ustring& name);
510
511 static style_sheet current_style_sheet_;
512 static style_sheets_t style_sheets_;
513 static style_sheet_names_t style_sheet_names_;
514 static style_sheet system_style_sheet_;
515
516 std::shared_ptr<data> data_;
517 };
518 }
519 }
520}
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
Provides a collection of button objects for use by a Windows Forms application.
Definition buttons.h:22
Provides a collection of label objects for use by a Windows Forms application.
Definition labels.h:22
The image data allows you to specify the url or gradient mode.
Definition background_image.h:40
The xtd::forms::style_sheets::border_color is used to set the color of the borders.
Definition border_color.h:31
The radius is used to add rounded borders to an element.
Definition border_radius.h:31
The style specifies what kind of borders to display.
Definition border_style.h:31
The control selector allows you to specify the box and color of a control.
Definition control.h:33
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
The xtd::forms::style_sheets::style_sheet allows you to specify an xtd style sheet.
Definition style_sheet.h:62
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
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
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::control > controls_t
Represents a style sheet controls collection.
Definition style_sheet.h:72
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::status_bar > status_bars_t
Represents a style sheet tool_bars collection.
Definition style_sheet.h:86
static const style_sheet empty
Provides an empty xtd::forms::style_sheets::style_sheet object.
Definition style_sheet.h:103
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.h:70
std::map< xtd::ustring, style_sheet > style_sheets_t
Represents a style_sheets collection.
Definition style_sheet.h:82
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
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
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
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
std::vector< xtd::ustring > style_sheet_names_t
Represents a style_sheet names collection.
Definition style_sheet.h:84
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
style_sheet(const xtd::ustring &css_text)
Initialize a new xtd::forms::style_sheets::style_sheet instance from specified css forrmated text.
The theme data allows you to specify the theme informations.
Definition system_colors.h:32
The theme data allows you to specify the theme informations.
Definition theme.h:30
Provides a collection of toggle_button objects for use by a Windows Forms application.
Definition toggle_buttons.h:22
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:18
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition uri.h:103
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
Definition css_reader.h:16
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition event_handler.h:32
#define forms_export_
Define shared library export.
Definition forms_export.h:13
xtd::forms::style_sheets::control form
The form data allows you to specify the box of a form control.
Definition form.h:21
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
white_space
The white_space enum class specifies how white-space inside an element is handled.
Definition white_space.h:21
pseudo_state
The pseudo_state enum class flag specifies the pseudo state of an element.
Definition pseudo_state.h:21
text_transformation
The xtd::forms::style_sheets::text_transformation enum class is used to specify uppercase and lowerca...
Definition text_transformation.h:22
border_type
The border_type enum class specifies what kind of border to display.
Definition border_type.h:21
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
@ control
The left or right CTRL modifier key.
content_alignment
Specifies alignment of content on the drawing surface.
Definition content_alignment.h:19
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h: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.