1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
/*
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-tk-lib
* Created on: 6 мая 2020 г.
*
* lsp-tk-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-tk-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-tk-lib. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LSP_PLUG_IN_TK_STYLE_SCHEMA_H_
#define LSP_PLUG_IN_TK_STYLE_SCHEMA_H_
#ifndef LSP_PLUG_IN_TK_IMPL
#error "use <lsp-plug.in/tk/tk.h>"
#endif
#include <lsp-plug.in/lltl/parray.h>
#include <lsp-plug.in/lltl/pphash.h>
#include <lsp-plug.in/runtime/LSPString.h>
#include <lsp-plug.in/runtime/Color.h>
#include <lsp-plug.in/io/Path.h>
#include <lsp-plug.in/io/IInStream.h>
#include <lsp-plug.in/io/IInSequence.h>
#include <lsp-plug.in/fmt/xml/PullParser.h>
#include <lsp-plug.in/resource/ILoader.h>
namespace lsp
{
namespace tk
{
class Atoms;
class Display;
// Style definition
namespace style
{
LSP_TK_STYLE_DEF_BEGIN(Root, Style)
prop::Float sScaling;
prop::Float sFontScaling;
prop::Font sFont;
prop::DrawMode sDrawMode;
prop::Boolean sInvertMouseHScroll;
prop::Boolean sInvertMouseVScroll;
LSP_TK_STYLE_DEF_END
}
/**
* This class describes the system schema.
* The schema provides complete style hierarchy and may be
* reconfigured by applying another style sheet.
*/
class Schema
{
protected:
enum flags_t
{
S_CONFIGURING = 1 << 0, // Schema is in configuration state
S_INITIALIZED = 1 << 1, // Schema is initialized
};
typedef struct raw_property_t
{
const LSPString *name;
const LSPString *value;
ssize_t order;
} raw_property_t;
typedef struct property_value_t
{
property_type_t type;
union
{
bool bvalue;
int ivalue;
float fvalue;
};
LSPString svalue;
} property_value_t;
protected:
mutable Atoms *pAtoms;
mutable Display *pDisplay;
size_t nFlags;
Style *pRoot;
lltl::pphash<LSPString, Style> vBuiltin;
lltl::pphash<LSPString, Style> vStyles;
lltl::pphash<LSPString, lsp::Color> vColors;
prop::Float sScaling;
prop::Float sFontScaling;
prop::Font sFont;
prop::DrawMode sDrawMode;
prop::Boolean sInvertMouseHScroll;
prop::Boolean sInvertMouseVScroll;
protected:
static ssize_t compare_properties_by_order(const raw_property_t *a, const raw_property_t *b);
static bool make_raw_properties(StyleSheet::style_t *xs, lltl::darray<raw_property_t> *props);
protected:
status_t create_builtin_style(IStyleFactory *init);
status_t create_style(const LSPString *name);
status_t create_missing_styles(const StyleSheet *sheet);
status_t unlink_styles();
status_t link_styles(const StyleSheet *sheet);
status_t configure_styles(const StyleSheet *sheet);
static bool check_parents_configured(Style *s);
status_t apply_settings(Style *s, StyleSheet::style_t *xs);
status_t apply_relations(Style *s, const lltl::parray<LSPString> *parents);
status_t apply_relations(Style *s, const char *parents);
void destroy_colors();
status_t init_colors_from_sheet(const StyleSheet *sheet);
status_t load_fonts_from_sheet(const StyleSheet *sheet, resource::ILoader *loader);
static status_t parse_property_value(property_value_t *v, const LSPString *text, property_type_t pt);
void bind(Style *root);
status_t apply_internal(const StyleSheet *sheet, resource::ILoader *loader);
public:
explicit Schema(Atoms *atoms, Display *dpy);
Schema(const Schema &) = delete;
Schema(Schema &&) = delete;
virtual ~Schema();
Schema & operator = (const Schema &) = delete;
Schema & operator = (Schema &&) = delete;
/**
* Initialize schema with the specified list of styles
* Can be run only once after the schema is instantiated. Otherwise
* it will return error
*
* @param list list of styles
* @return status of operation
*/
status_t init(lltl::parray<IStyleFactory> *list);
status_t init(lltl::parray<IStyleFactory> &list);
/**
* Initialize schema with the specified list of styles
* Can be run only once after the schema is instantiated. Otherwise
* it will return error
*
* @param list array of pointers to style initializers
* @param n number of elements in array
* @return status of operation
*/
status_t init(IStyleFactory **list, size_t n);
/**
* Register additional styles
* @param list list of styles to register
* @return status of operation
*/
status_t add(lltl::parray<IStyleFactory> *list);
status_t add(lltl::parray<IStyleFactory> &list);
/**
* Register additional styles
* @param list array of pointers to style initializers
* @param n number of elements in array
* @return status of operation
*/
status_t add(IStyleFactory **list, size_t n);
/**
* Register additional style
* @param factory style factory
* @return status of operation
*/
status_t add(IStyleFactory *factory);
/**
* Apply stylesheet settings to the schema
* @param sheet style sheet
* @param loader resource loader
* @return status of operation
*/
status_t apply(const StyleSheet *sheet, resource::ILoader *loader = NULL);
public:
LSP_TK_PROPERTY(Float, scaling, &sScaling)
LSP_TK_PROPERTY(Float, font_scaling, &sFontScaling)
LSP_TK_PROPERTY(Font, font, &sFont)
LSP_TK_PROPERTY(DrawMode, draw_mode, &sDrawMode)
LSP_TK_PROPERTY(Boolean, invert_mouse_hscroll, &sInvertMouseHScroll)
LSP_TK_PROPERTY(Boolean, invert_mouse_vscroll, &sInvertMouseVScroll)
public:
/**
* Get color by identifier
* @param id color identifier
* @return color or NULL if not present
*/
lsp::Color *color(const char *id);
/**
* Get color by identifier
* @param id color identifier
* @return color or NULL if not present
*/
lsp::Color *color(const LSPString *id);
/**
* Get root style
* @return root style or NULL on error
*/
inline Style *root() { return pRoot; }
/**
* Get style by class identifier.
* If style does not exists, it will be automatically created and bound to the root style
* @return style or NULL on error
*/
Style *get(const char *id);
/**
* Get style by class identifier.
* If style does not exists, it will be automatically created and bound to the root style
* @return style or NULL on error
*/
Style *get(const LSPString *id);
/**
* Get atom identifier by name
* @param name atom name
* @return atom identifier or negative error code
*/
atom_t atom_id(const char *name) const;
/**
* Get atom identifier by name
* @param name atom name
* @return atom identifier or negative error code
*/
atom_t atom_id(const LSPString *name) const;
/**
* Get atom name by identifier
* @param name atom name or NULL
* @return atom identifier
*/
const char *atom_name(atom_t id) const;
/**
* Get currently used language
* @param dst pointer to store the result
* @return status of operation
*/
status_t get_language(LSPString *dst) const;
/**
* Set currently used language
* @param lang language identifier
* @return status of operation
*/
status_t set_lanugage(const LSPString *lang);
status_t set_lanugage(const char *lang);
/**
* Check that schema is in configuration mode:
* - no implicit overrides of style properties are allowed
* - automatic property synchronization on change is enabled
* @return
*/
inline bool config_mode() const { return nFlags & S_CONFIGURING; }
/**
* Load font and add to the repository
* @param name font name in UTF-8
* @param path path to the file that contains the font data (UTF-8)
* @return status of operation
*/
status_t add_font(const char *name, const char *path);
/**
* Load font and add to the repository
* @param name font name in UTF-8
* @param path path to the file that contains the font data (UTF-8)
* @return status of operation
*/
status_t add_font(const char *name, const io::Path *path);
/**
* Load font and add to the repository
* @param name font name in UTF-8
* @param path path to the file that contains the font data (UTF-8)
* @return status of operation
*/
status_t add_font(const char *name, const LSPString *path);
/**
* Load font from stream and add to the repository
* @param name font name in UTF-8
* @param path path to the file that contains the font data (UTF-8)
* @return status of operation
*/
status_t add_font(const char *name, io::IInStream *is);
/**
* Add an alias to the font name
* @param name font name
* @param alias alias for the font name
* @return status of operation
*/
status_t add_font_alias(const char *name, const char *alias);
/**
* Remove font or font alias by identifier
* @param name name font name or font alias
* @return status of operation
*/
status_t remove_font(const char *name);
/**
* Remove all previously loaded custom fonts and aliases
*/
void remove_all_fonts();
};
} /* namespace tk */
} /* namespace lsp */
#endif /* LSP_PLUG_IN_TK_STYLE_SCHEMA_H_ */
|