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 {
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>;
86 using style_sheet_names_t = std::vector<xtd::string>;
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
348 using object::equals;
349 bool equals(const style_sheet& other) const noexcept override;
351
353
359 static buttons_t button_from_css(const xtd::string& css_text);
360
365 static controls_t control_from_css(const xtd::string& css_text);
366
372 static style_sheet get_style_sheet_from_name(const xtd::string& name);
373
379 static style_sheet get_style_sheet_from_file(const xtd::string& file_name);
380
386 static style_sheet get_style_sheet_from_path(const xtd::string& path_name);
387
392 static forms_t form_from_css(const xtd::string& css_text);
393
398 static xtd::forms::style_sheets::system_colors system_colors_from_css(const xtd::string& css_text);
399
404 static xtd::forms::style_sheets::theme theme_from_css(const xtd::string& css_text);
405
409 static std::tuple<xtd::forms::style_sheets::border_type, int32, int32> to_border_type(xtd::forms::border_style border);
411
413
418 static event<style_sheet, event_handler> style_sheet_changed;
420
421 private:
422 friend class ::__test_style_sheet__; // Necessary for the test unit to access the private member functions
423 friend class xtd::forms::control;
424 friend class xtd::forms::form;
425 style_sheet(const xtd::string& css_text, bool init_system);
426
427 xtd::drawing::color background_color_from_css(const xtd::string& css_text, const xtd::drawing::color& default_value) const noexcept;
428 background_image background_image_from_css(const xtd::string& css_text, const background_image& default_value) const noexcept;
429 border_color border_color_from_css(const xtd::string& css_text, const border_color& default_value) const noexcept;
430 border_style border_style_from_css(const string& text, const border_style& default_value) const noexcept;
431 border_radius border_radius_from_css(const xtd::string& css_text, const border_radius& default_value) const noexcept;
432 border_width border_width_from_css(const xtd::string& css_text, const border_width& default_value) const noexcept;
433 xtd::drawing::color color_from_css(const xtd::string& css_text, const xtd::drawing::color& default_value) const noexcept;
434 length length_from_css(const xtd::string& css_text, const length& default_value) const noexcept;
435 margin margin_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
436 margin margin_bottom_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
437 margin margin_left_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
438 margin margin_right_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
439 margin margin_top_from_css(const xtd::string& css_text, const margin& default_value) const noexcept;
440 padding padding_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
441 padding padding_bottom_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
442 padding padding_left_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
443 padding padding_right_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
444 padding padding_top_from_css(const xtd::string& css_text, const padding& default_value) const noexcept;
445 string string_from_css(const xtd::string& css_text, const xtd::string& default_value) const noexcept;
446 xtd::forms::content_alignment text_align_from_css(const xtd::string& css_text, const xtd::forms::content_alignment& default_value) const noexcept;
447 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;
448 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;
449 xtd::uri uri_from_css(const xtd::string& css_text, const xtd::uri& default_value) const noexcept;
450 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;
451
452 template<typename type_t, typename collection_t>
453 type_t get_state_control(const collection_t& collection, pseudo_state state) const noexcept {
454 auto result = type_t();
455 auto it = collection.find(pseudo_state::standard);
456 if (it != collection.end()) result = it->second;
457 it = collection.find(state);
458 if (it != collection.end()) result = it->second;
459 return result;
460 }
461
462 static void on_style_sheet_changed(const xtd::event_args& e);
463 static void on_system_colors_changed(const event_args& e);
464 std::vector<xtd::string> split_values_from_text(const xtd::string& text) const noexcept;
465
466 void button_reader(xtd::web::css::css_reader& reader) noexcept;
467 void control_reader(xtd::web::css::css_reader& reader) noexcept;
468 void fill_control(const xtd::web::css::selector_map::const_iterator& selectors_iterator, xtd::forms::style_sheets::control& control) noexcept;
469 void flat_button_reader(xtd::web::css::css_reader& reader) noexcept;
470 void flat_toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
471 void form_reader(xtd::web::css::css_reader& reader) noexcept;
472 void label_reader(xtd::web::css::css_reader& reader) noexcept;
473 void link_label_reader(xtd::web::css::css_reader& reader) noexcept;
474 void panel_reader(xtd::web::css::css_reader& reader) noexcept;
475 void popup_button_reader(xtd::web::css::css_reader& reader) noexcept;
476 void popup_toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
477 void status_bar_reader(xtd::web::css::css_reader& reader) noexcept;
478 void status_bar_panel_reader(xtd::web::css::css_reader& reader) noexcept;
479 void system_colors_reader(xtd::web::css::css_reader& reader) noexcept;
480 void theme_reader(xtd::web::css::css_reader& reader) noexcept;
481 void toggle_button_reader(xtd::web::css::css_reader& reader) noexcept;
482 void tool_bar_reader(xtd::web::css::css_reader& reader) noexcept;
483 void tool_bar_button_reader(xtd::web::css::css_reader& reader) noexcept;
484 void user_control_reader(xtd::web::css::css_reader& reader) noexcept;
485
486 //static style_sheet system_style_sheet_gnome_dark() noexcept; // Declared in system_style_sheet_gnome_dark.cpp
487 //static style_sheet system_style_sheet_gnome_light() noexcept; // Declared in system_style_sheet_gnome_light.cpp
488 //static style_sheet system_style_sheet_kde_dark() noexcept; // Declared in system_style_sheet_kde_dark.cpp
489 //static style_sheet system_style_sheet_kde_light() noexcept; // Declared in system_style_sheet_kde_light.cpp
490 //static style_sheet system_style_sheet_macos_dark() noexcept; // Declared in system_style_sheet_macos_dark.cpp
491 //static style_sheet system_style_sheet_macos_light() noexcept; // Declared in system_style_sheet_macos_light.cpp
492 static style_sheet system_style_sheet_unknown_dark() noexcept; // Declared in system_style_sheet_unknown_dark.cpp
493 static style_sheet system_style_sheet_unknown_light() noexcept; // Declared in system_style_sheet_unknown_light.cpp
494 //static style_sheet system_style_sheet_windows_dark() noexcept; // Declared in system_style_sheet_windows_dark.cpp
495 //static style_sheet system_style_sheet_windows_light() noexcept; // Declared in system_style_sheet_windows_light.cpp
496
497 bool try_parse_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
498 bool try_parse_hex_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
499 bool try_parse_linear_gradient(const xtd::string& text, background_image& result) const noexcept;
500 bool try_parse_named_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
501 bool try_parse_rgb_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
502 bool try_parse_rgba_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
503 bool try_parse_hsv_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
504 bool try_parse_hsva_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
505 bool try_parse_hsl_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
506 bool try_parse_hsla_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
507 bool try_parse_system_color(const xtd::string& text, xtd::drawing::color& result) const noexcept;
508 bool try_parse_uri(const xtd::string& text, xtd::uri& result) const noexcept;
509
510 void system_colors_(const xtd::forms::style_sheets::system_colors& system_colors);
511 void theme_(const xtd::forms::style_sheets::theme& theme);
512 void theme_name_(const xtd::string& name);
513
514 static style_sheet current_style_sheet_;
515 static style_sheets_t style_sheets_;
516 static style_sheet_names_t style_sheet_names_;
517 static style_sheet system_style_sheet_;
518
519 xtd::sptr<data> data_;
520 };
521 }
522 }
523}
Represents text as a sequence of character units.
Definition basic_string.h:79
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:24
Provides a collection of label objects for use by a Windows Forms application.
Definition labels.h:24
The image data allows you to specify the url or gradient mode.
Definition background_image.h:42
The xtd::forms::style_sheets::border_color is used to set the color of the borders.
Definition border_color.h:33
The radius is used to add rounded borders to an element.
Definition border_radius.h:33
The style specifies what kind of borders to display.
Definition border_style.h:33
The control selector allows you to specify the box and color of a control.
Definition control.h:35
The xtd::forms::style_sheets::length specifies the legth and unit of many properties of the xtd::form...
Definition length.h:77
The length specifies the length of the borders.
Definition lengths.h:33
The xtd::forms::style_sheets::style_sheet allows you to specify an xtd style sheet.
Definition style_sheet.h: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.h: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.h: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.h: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.h: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.h: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.h:88
std::map< xtd::string, style_sheet > style_sheets_t
Represents a style_sheets collection.
Definition style_sheet.h:84
static const style_sheet empty
Provides an empty xtd::forms::style_sheets::style_sheet object.
Definition style_sheet.h: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.h: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.h:80
std::vector< xtd::string > style_sheet_names_t
Represents a style_sheet names collection.
Definition style_sheet.h:86
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: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.h: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.h: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.h:82
The theme data allows you to specify the theme informations.
Definition system_colors.h:34
The theme data allows you to specify the theme informations.
Definition theme.h:32
Provides a collection of toggle_button objects for use by a Windows Forms application.
Definition toggle_buttons.h:24
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition uri.h:103
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: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:25
white_space
The white_space enum class specifies how white-space inside an element is handled.
Definition white_space.h:23
pseudo_state
The pseudo_state enum class flag specifies the pseudo state of an element.
Definition pseudo_state.h:23
text_transformation
The xtd::forms::style_sheets::text_transformation enum class is used to specify uppercase and lowerca...
Definition text_transformation.h:24
border_type
The border_type enum class specifies what kind of border to display.
Definition border_type.h:23
int32_t int32
Represents a 32-bit signed integer.
Definition int32.h:23
std::shared_ptr< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.h:25
@ control
The left or right CTRL modifier key.
content_alignment
Specifies alignment of content on the drawing surface.
Definition content_alignment.h:21
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.