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
|
/*
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2025 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-tk-lib
* Created on: 7 сент. 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_PROP_COLLECTION_STRINGLIST_H_
#define LSP_PLUG_IN_TK_PROP_COLLECTION_STRINGLIST_H_
#ifndef LSP_PLUG_IN_TK_IMPL
#error "use <lsp-plug.in/tk/tk.h>"
#endif
namespace lsp
{
namespace tk
{
/**
* String list: list containing string properties
*/
class StringList: public SimpleProperty
{
protected:
// Wrapper around the string
class StringItem: public tk::String
{
public:
explicit inline StringItem(i18n::IDictionary *dict, prop::Listener *listener = NULL): tk::String(NULL)
{
pDict = dict;
}
public:
inline void invalidate(i18n::IDictionary *dict)
{
pDict = dict;
tk::String::invalidate();
}
};
class Listener: public IStyleListener
{
protected:
StringList *pList;
public:
explicit Listener(StringList *lst) { pList = lst; }
public:
virtual void notify(atom_t property) override;
};
class Changes: public prop::Listener
{
protected:
StringList *pList;
bool bEnabled;
public:
explicit Changes(StringList *lst)
{
bEnabled = true;
pList = lst;
}
public:
virtual void notify(Property *prop) override;
inline void enable(bool enable) { bEnabled = enable; }
};
protected:
lltl::parray<StringItem> vItems; // List of strings
Listener sListener; // Style listener
Changes sChanges; // Change listener
i18n::IDictionary *pDict; // Related dictionary
protected:
status_t bind(atom_t property, Style *style, i18n::IDictionary *dict);
status_t bind(const char *property, Style *style, i18n::IDictionary *dict);
status_t bind(const LSPString *property, Style *style, i18n::IDictionary *dict);
status_t unbind();
StringItem *create_item();
void sync();
void invalidate();
virtual void commit(atom_t property) override;
protected:
explicit StringList(prop::Listener *listener = NULL);
StringList(const StringList &) = delete;
StringList(StringList &&) = delete;
virtual ~StringList() override;
StringList & operator = (const StringList &) = delete;
StringList & operator = (StringList &&) = delete;
public:
/**
* Insert string at the specified position
* @param index index to place the string
* @return inserted string or NULL on error
*/
String *insert(size_t index);
/**
* Append string to the end
* @return appended string or NULL on error
*/
String *append();
/**
* Prepend string at the beginning
* @return prepended string or NULL on error
*/
String *prepend();
/**
* Remove strings from the specified index
* @param index start index of the string
* @param count number of strings to remove
* @return status of operation
*/
status_t remove(size_t index, size_t count);
/**
* Clear the list.
*/
void clear();
/**
* Remove string at the specified index
* @param index index of the string
* @return status of operation
*/
status_t remove(size_t index);
/**
* Remove string from the list if it is present in the list
* @param s string to remove
* @return status of operation
*/
status_t premove(const String *s);
/**
* Get string at specified position
* @param index index of the string
* @return string object or NULL
*/
inline String *get(size_t index) { return vItems.get(index); }
/**
* Swap two strings
* @param i1 index of first string
* @param i2 index of last string
* @return status of operation
*/
status_t swap(size_t i1, size_t i2);
/**
* Get size of the list
* @return size of the list
*/
inline size_t size() const { return vItems.size(); }
};
namespace prop
{
class StringList: public tk::StringList
{
public:
explicit StringList(prop::Listener *listener = NULL): tk::StringList(listener) {};
StringList(const StringList &) = delete;
StringList(StringList &&) = delete;
StringList & operator = (const StringList &) = delete;
StringList & operator = (StringList &&) = delete;
public:
/**
* Bind property with specified name to the style of linked widget
*/
inline status_t bind(atom_t id, Style *style, i18n::IDictionary *dict) { return tk::StringList::bind(id, style, dict); }
inline status_t bind(const LSPString *id, Style *style, i18n::IDictionary *dict) { return tk::StringList::bind(id, style, dict); }
inline status_t bind(const char *id, Style *style, i18n::IDictionary *dict) { return tk::StringList::bind(id, style, dict); }
inline status_t bind(Style *style, i18n::IDictionary *dict) { return tk::StringList::bind(LSP_TK_PROP_LANGUAGE, style, dict); }
/**
* Unbind property
*/
inline status_t unbind() { return tk::StringList::unbind(); };
};
} /* namespace prop */
} /* namespace tk */
} /* namespace lsp */
#endif /* LSP_PLUG_IN_TK_PROP_COLLECTION_STRINGLIST_H_ */
|