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
|
/*
* Copyright (C) 2021 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2021 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-plugin-fw
* Created on: 9 апр. 2021 г.
*
* lsp-plugin-fw 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-plugin-fw 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-plugin-fw. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LSP_PLUG_IN_UI_UICONTEXT_H_
#define LSP_PLUG_IN_UI_UICONTEXT_H_
#ifndef LSP_PLUG_IN_PLUG_FW_UI_IMPL_H_
#error "Use #include <lsp-plug.in/plug-fw/ui/ui.h>"
#endif /* LSP_PLUG_IN_PLUG_FW_UI_IMPL_H_ */
#include <lsp-plug.in/plug-fw/version.h>
#include <lsp-plug.in/plug-fw/ui/IWrapper.h>
#include <lsp-plug.in/plug-fw/ui/Module.h>
#include <lsp-plug.in/plug-fw/ctl.h>
#include <lsp-plug.in/expr/Expression.h>
#include <lsp-plug.in/expr/Variables.h>
#include <lsp-plug.in/tk/tk.h>
namespace lsp
{
namespace ctl
{
class Widget;
class Registry;
}
namespace ui
{
/**
* UI context, stores main variables and state of XML document parsing structure
* which allows to build the UI from XML document
*/
class UIContext
{
private:
UIContext & operator = (const UIContext &);
UIContext(const UIContext &);
protected:
ui::IWrapper *pWrapper;
ctl::Registry *pControllers;
tk::Registry *pWidgets;
expr::Resolver *pResolver;
lltl::parray<expr::Variables> vStack;
expr::Variables vRoot;
UIOverrides sOverrides;
public:
explicit UIContext(ui::IWrapper *wrapper, ctl::Registry *controllers, tk::Registry *widgets);
~UIContext();
status_t init();
public:
/**
* Get the pointer to plugin UI
* @return pointer to plugin UI
*/
inline ui::Module *ui() { return pWrapper->ui(); }
/**
* Get the pointer to the UI wrapper
* @return pointer to the UI wrapper
*/
inline ui::IWrapper *wrapper() { return pWrapper; }
/**
* Get the registry for controllers
* @return the registry for controllers
*/
inline ctl::Registry *controllers() { return pControllers; }
/**
* Get the registry for widget
* @return the registry for widgets
*/
inline tk::Registry *widgets() { return pWidgets; }
/**
* Get the display
* @return display
*/
inline tk::Display *display() { return (pWrapper != NULL) ? pWrapper->ui()->display() : NULL; }
/**
* Get the attribute overrides settings
* @return attribute overrides settings
*/
inline UIOverrides *overrides() { return &sOverrides; }
public:
/**
* Start new nested variable scope
* @return status of operation
*/
status_t push_scope();
/**
* Remove nested variable scope and destroy all nested variables
* @return status of operation
*/
status_t pop_scope();
/**
* Get current variable resolver
* @return current variable resolver
*/
inline expr::Resolver *resolver()
{
expr::Variables *r = vStack.last();
return (r != NULL) ? r : &vRoot;
}
/**
* Get current variable scope
* @return current variable scope
*/
inline expr::Variables *vars()
{
expr::Variables *r = vStack.last();
return (r != NULL) ? r : &vRoot;
}
/**
* Get root variable scope
* @return root variable scope
*/
inline expr::Variables *root() { return &vRoot; }
/**
* Evaluate expression
* @param eval expression to evaluate
* @param expr expression to evaluate
* @param flags expression compilation flags
* @return status of operation
*/
status_t evaluate(expr::Expression *eval, const LSPString *expr, size_t flags);
/**
* Evaluate expression
* @param value value to return
* @param expr expression to evaluate
* @param flags expression compilation flags
* @return status of operation
*/
status_t evaluate(expr::value_t *value, const LSPString *expr, size_t flags);
/**
* Evaluate value and return as string
* @param var pointer to store string
* @param expr expression
* @return status of operation
*/
status_t eval_string(LSPString *value, const LSPString *expr);
/**
* Evaluate value and return as boolean
* @param var pointer to store string
* @param expr expression
* @return status of operation
*/
status_t eval_bool(bool *value, const LSPString *expr);
/**
* Evaluate value and return as integer
* @param var pointer to store integer value
* @param expr expression
* @return status of operation
*/
status_t eval_int(ssize_t *value, const LSPString *expr);
/**
* Create widget controller by the tag name
*
* @param name the tag name of the widget
* @return pointer to widget controller
*/
ctl::Widget *create_controller(const LSPString *name);
/**
* Set attributes to widget
* @param widget widget to set attributes
* @param atts attributes to set
* @return status of operation
*/
status_t set_attributes(ctl::Widget *widget, const LSPString * const *atts);
};
}
}
#endif /* LSP_PLUG_IN_UI_UICONTEXT_H_ */
|