1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 4 мар. 2020 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef UI_TK_UTIL_LSPSTYLETRIGGER_H_
23 #define UI_TK_UTIL_LSPSTYLETRIGGER_H_
24 
25 namespace lsp
26 {
27     namespace tk
28     {
29         enum style_trigger_action_t
30         {
31             STYLE_TRG_REDRAW,
32             STYLE_TRG_RESIZE
33         };
34 
35         class LSPWidget;
36 
37         class LSPStyleTrigger: public IStyleListener
38         {
39             private:
40                 LSPStyleTrigger & operator = (const LSPStyleTrigger &);
41 
42             protected:
43                 typedef struct binding_t
44                 {
45                     ui_atom_t               id;
46                     style_trigger_action_t  action;
47                 } binding_t;
48 
49             protected:
50                 LSPWidget              *pWidget;
51                 cstorage<binding_t>     vBindings;
52 
53             public:
54                 explicit LSPStyleTrigger(LSPWidget *widget);
55                 virtual ~LSPStyleTrigger();
56 
57             public:
58                 virtual void notify(ui_atom_t property);
59 
60             public:
61                 /**
62                  * Bind trigger to the specified atom and data type
63                  * @param id style property identifier
64                  * @param type property type
65                  * @param action trigger action
66                  * @return status of operation
67                  */
68                 status_t            bind(ui_atom_t id, ui_property_type_t type, style_trigger_action_t action);
69 
70                 /**
71                  * Bind trigger to the specified atom and data type
72                  * @param id style property name
73                  * @param type property type
74                  * @param action trigger action
75                  * @return status of operation
76                  */
77                 status_t            bind(const char *name, ui_property_type_t type, style_trigger_action_t action);
78 
79                 /**
80                  * Bind trigger to the specified atom and data type
81                  * @param id style property name
82                  * @param type property type
83                  * @param action trigger action
84                  * @return status of operation
85                  */
86                 status_t            bind(const LSPString *name, ui_property_type_t type, style_trigger_action_t action);
87 
bind_int(ui_atom_t id,style_trigger_action_t action)88                 inline status_t     bind_int(ui_atom_t id, style_trigger_action_t action)               { return bind(id, PT_INT, action); };
bind_float(ui_atom_t id,style_trigger_action_t action)89                 inline status_t     bind_float(ui_atom_t id, style_trigger_action_t action)             { return bind(id, PT_FLOAT, action); };
bind_bool(ui_atom_t id,style_trigger_action_t action)90                 inline status_t     bind_bool(ui_atom_t id, style_trigger_action_t action)              { return bind(id, PT_BOOL, action); };
bind_string(ui_atom_t id,style_trigger_action_t action)91                 inline status_t     bind_string(ui_atom_t id, style_trigger_action_t action)            { return bind(id, PT_STRING, action); };
92 
bind_int(const char * name,style_trigger_action_t action)93                 inline status_t     bind_int(const char *name, style_trigger_action_t action)           { return bind(name, PT_INT, action); };
bind_float(const char * name,style_trigger_action_t action)94                 inline status_t     bind_float(const char *name, style_trigger_action_t action)         { return bind(name, PT_FLOAT, action); };
bind_bool(const char * name,style_trigger_action_t action)95                 inline status_t     bind_bool(const char *name, style_trigger_action_t action)          { return bind(name, PT_BOOL, action); };
bind_string(const char * name,style_trigger_action_t action)96                 inline status_t     bind_string(const char *name, style_trigger_action_t action)        { return bind(name, PT_STRING, action); };
97 
bind_int(const LSPString * name,style_trigger_action_t action)98                 inline status_t     bind_int(const LSPString *name, style_trigger_action_t action)      { return bind(name, PT_INT, action); };
bind_float(const LSPString * name,style_trigger_action_t action)99                 inline status_t     bind_float(const LSPString *name, style_trigger_action_t action)    { return bind(name, PT_FLOAT, action); };
bind_bool(const LSPString * name,style_trigger_action_t action)100                 inline status_t     bind_bool(const LSPString *name, style_trigger_action_t action)     { return bind(name, PT_BOOL, action); };
bind_string(const LSPString * name,style_trigger_action_t action)101                 inline status_t     bind_string(const LSPString *name, style_trigger_action_t action)   { return bind(name, PT_STRING, action); };
102 
103                 /**
104                  * Check that trigger is already bound with the specified action
105                  * @param id property identifier
106                  * @param listener listener
107                  * @return true if listener is bound
108                  */
109                 bool                is_bound(ui_atom_t id, style_trigger_action_t action) const;
110 
111                 /**
112                  * Check that trigger is already bound with the specified action
113                  * @param id property name
114                  * @param listener listener
115                  * @return true if listener is bound
116                  */
117                 bool                is_bound(const char *name, style_trigger_action_t action) const;
118 
119                 /**
120                  * Check that trigger is already bound with the specified action
121                  * @param id property name
122                  * @param listener listener
123                  * @return true if listener is bound
124                  */
125                 bool                is_bound(const LSPString *name, style_trigger_action_t action) const;
126 
127                 /**
128                  * Unbind trigger
129                  * @param id style property identifier
130                  * @param listener property listener
131                  * @return status of operation
132                  */
133                 status_t            unbind(ui_atom_t id, style_trigger_action_t action);
134 
135                 /**
136                  * Unbind trigger
137                  * @param name name of the style property
138                  * @param listener property listener
139                  * @return status of operation
140                  */
141                 status_t            unbind(const char *name, style_trigger_action_t action);
142 
143                 /**
144                  * Unbind trigger
145                  * @param name name of the style property
146                  * @param listener property listener
147                  * @return status of operation
148                  */
149                 status_t            unbind(const LSPString *name, style_trigger_action_t action);
150         };
151 
152     } /* namespace tk */
153 } /* namespace lsp */
154 
155 #endif /* UI_TK_UTIL_LSPSTYLETRIGGER_H_ */
156