diff options
Diffstat (limited to 'linden/indra/llxml/llcontrol.h')
-rw-r--r-- | linden/indra/llxml/llcontrol.h | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/linden/indra/llxml/llcontrol.h b/linden/indra/llxml/llcontrol.h new file mode 100644 index 0000000..846a3b5 --- /dev/null +++ b/linden/indra/llxml/llcontrol.h | |||
@@ -0,0 +1,274 @@ | |||
1 | /** | ||
2 | * @file llcontrol.h | ||
3 | * @brief A mechanism for storing "control state" for a program | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LLCONTROL_H | ||
29 | #define LL_LLCONTROL_H | ||
30 | |||
31 | #include "llevent.h" | ||
32 | #include "llnametable.h" | ||
33 | #include "llmap.h" | ||
34 | #include "llstring.h" | ||
35 | #include "llrect.h" | ||
36 | |||
37 | class LLVector3; | ||
38 | class LLVector3d; | ||
39 | class LLColor4; | ||
40 | class LLColor3; | ||
41 | class LLColor4U; | ||
42 | |||
43 | const BOOL NO_PERSIST = FALSE; | ||
44 | |||
45 | typedef enum e_control_type | ||
46 | { | ||
47 | TYPE_U32, | ||
48 | TYPE_S32, | ||
49 | TYPE_F32, | ||
50 | TYPE_BOOLEAN, | ||
51 | TYPE_STRING, | ||
52 | TYPE_VEC3, | ||
53 | TYPE_VEC3D, | ||
54 | TYPE_RECT, | ||
55 | TYPE_COL4, | ||
56 | TYPE_COL3, | ||
57 | TYPE_COL4U | ||
58 | } eControlType; | ||
59 | |||
60 | class LLControlBase : public LLSimpleListenerObservable | ||
61 | { | ||
62 | friend class LLControlGroup; | ||
63 | protected: | ||
64 | LLString mName; | ||
65 | LLString mComment; | ||
66 | eControlType mType; | ||
67 | BOOL mHasRange; | ||
68 | BOOL mPersist; | ||
69 | BOOL mIsDefault; | ||
70 | static std::set<LLControlBase*> mChangedControls; | ||
71 | static std::list<S32> mFreeIDs;//These lists are used to store the ID's of registered event listeners. | ||
72 | static std::list<S32> mUsedIDs; | ||
73 | static S32 mTopID;//This is the index of the highest ID event listener ID. When the free pool is exhausted, new IDs are allocated from here. | ||
74 | |||
75 | public: | ||
76 | static void releaseListenerID(S32 id); | ||
77 | static S32 allocateListenerID(); | ||
78 | static void updateAllListeners(); | ||
79 | virtual void updateListeners() = 0; | ||
80 | |||
81 | LLControlBase(const LLString& name, eControlType type, const LLString& comment, BOOL persist) | ||
82 | : mName(name), | ||
83 | mComment(comment), | ||
84 | mType(type), | ||
85 | mHasRange(FALSE), | ||
86 | mPersist(persist), | ||
87 | mIsDefault(TRUE) | ||
88 | { | ||
89 | if (mPersist && mComment.empty()) | ||
90 | { | ||
91 | llerrs << "Must supply a comment for control " << mName << llendl; | ||
92 | } | ||
93 | sMaxControlNameLength = llmax((U32)mName.size(), sMaxControlNameLength); | ||
94 | } | ||
95 | |||
96 | virtual ~LLControlBase(); | ||
97 | |||
98 | const LLString& getName() const { return mName; } | ||
99 | const LLString& getComment() const { return mComment; } | ||
100 | |||
101 | eControlType type() { return mType; } | ||
102 | BOOL isType(eControlType tp) { return tp == mType; } | ||
103 | |||
104 | // Defaults to no-op | ||
105 | virtual void resetToDefault(); | ||
106 | |||
107 | LLSD registerListener(LLSimpleListenerObservable *listener, LLSD userdata = ""); | ||
108 | |||
109 | virtual LLSD get() const = 0; | ||
110 | virtual LLSD getValue() const = 0; | ||
111 | virtual void setValue(LLSD value) = 0; | ||
112 | virtual void set(LLSD value) = 0; | ||
113 | |||
114 | // From LLSimpleListener | ||
115 | virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata); | ||
116 | |||
117 | void firePropertyChanged(); | ||
118 | |||
119 | static U32 sMaxControlNameLength; | ||
120 | |||
121 | protected: | ||
122 | const char* name() { return mName.c_str(); } | ||
123 | const char* comment() { return mComment.c_str(); } | ||
124 | }; | ||
125 | |||
126 | class LLControl | ||
127 | : public LLControlBase | ||
128 | { | ||
129 | friend class LLControlGroup; | ||
130 | protected: | ||
131 | LLSD mCurrent; | ||
132 | LLSD mDefault; | ||
133 | |||
134 | public: | ||
135 | |||
136 | typedef void tListenerCallback(const LLSD& newValue,S32 listenerID, LLControl& control); | ||
137 | typedef struct{ | ||
138 | S32 mID; | ||
139 | LLSD mNewValue; | ||
140 | tListenerCallback* mCBFN; | ||
141 | }tPropertyChangedEvent; | ||
142 | |||
143 | typedef std::list<tPropertyChangedEvent>::iterator tPropertyChangedListIter; | ||
144 | std::list<tPropertyChangedEvent> mChangeEvents; | ||
145 | std::list< tListenerCallback* > mListeners; | ||
146 | std::list< S32 > mListenerIDs; | ||
147 | |||
148 | virtual void updateListeners(); | ||
149 | S32 addListener(tListenerCallback* cbfn); | ||
150 | |||
151 | LLControl( | ||
152 | const LLString& name, | ||
153 | eControlType type, | ||
154 | LLSD initial, const | ||
155 | LLString& comment, | ||
156 | BOOL persist = TRUE); | ||
157 | |||
158 | void set(LLSD val) { setValue(val); } | ||
159 | LLSD get() const { return getValue(); } | ||
160 | LLSD getdefault() const { return mDefault; } | ||
161 | LLSD getValue() const { return mCurrent; } | ||
162 | BOOL llsd_compare(const LLSD& a, const LLSD& b); | ||
163 | |||
164 | void setValue(LLSD value) | ||
165 | { | ||
166 | if (llsd_compare(mCurrent, value) == FALSE) | ||
167 | { | ||
168 | mCurrent = value; | ||
169 | mIsDefault = llsd_compare(mCurrent, mDefault); | ||
170 | firePropertyChanged(); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | /*virtual*/ void resetToDefault() { mCurrent = mDefault; mIsDefault = TRUE;} | ||
175 | |||
176 | virtual ~LLControl() | ||
177 | { | ||
178 | //Remove and deregister all listeners.. | ||
179 | while(mListenerIDs.size()) | ||
180 | { | ||
181 | S32 id = mListenerIDs.front(); | ||
182 | mListenerIDs.pop_front(); | ||
183 | releaseListenerID(id); | ||
184 | } | ||
185 | } | ||
186 | }; | ||
187 | |||
188 | //const U32 STRING_CACHE_SIZE = 10000; | ||
189 | class LLControlGroup | ||
190 | { | ||
191 | public: | ||
192 | typedef std::map<LLString, LLPointer<LLControlBase> > ctrl_name_table_t; | ||
193 | ctrl_name_table_t mNameTable; | ||
194 | std::set<LLString> mWarnings; | ||
195 | |||
196 | public: | ||
197 | LLControlGroup(); | ||
198 | ~LLControlGroup(); | ||
199 | void cleanup(); | ||
200 | |||
201 | LLControlBase* getControl(const LLString& name); | ||
202 | LLSD registerListener(const LLString& name, LLSimpleListenerObservable *listener); | ||
203 | |||
204 | BOOL declareControl(const LLString& name, eControlType type, const LLSD initial_val, const LLString& comment, BOOL persist); | ||
205 | BOOL declareU32(const LLString& name, U32 initial_val, const LLString& comment, BOOL persist = TRUE); | ||
206 | BOOL declareS32(const LLString& name, S32 initial_val, const LLString& comment, BOOL persist = TRUE); | ||
207 | BOOL declareF32(const LLString& name, F32 initial_val, const LLString& comment, BOOL persist = TRUE); | ||
208 | BOOL declareBOOL(const LLString& name, BOOL initial_val, const LLString& comment, BOOL persist = TRUE); | ||
209 | BOOL declareString(const LLString& name, const LLString &initial_val, const LLString& comment, BOOL persist = TRUE); | ||
210 | BOOL declareVec3(const LLString& name, const LLVector3 &initial_val,const LLString& comment, BOOL persist = TRUE); | ||
211 | BOOL declareVec3d(const LLString& name, const LLVector3d &initial_val, const LLString& comment, BOOL persist = TRUE); | ||
212 | BOOL declareRect(const LLString& name, const LLRect &initial_val, const LLString& comment, BOOL persist = TRUE); | ||
213 | BOOL declareColor4U(const LLString& name, const LLColor4U &initial_val, const LLString& comment, BOOL persist = TRUE); | ||
214 | BOOL declareColor4(const LLString& name, const LLColor4 &initial_val, const LLString& comment, BOOL persist = TRUE); | ||
215 | BOOL declareColor3(const LLString& name, const LLColor3 &initial_val, const LLString& comment, BOOL persist = TRUE); | ||
216 | |||
217 | LLString findString(const LLString& name); | ||
218 | |||
219 | LLString getString(const LLString& name); | ||
220 | LLWString getWString(const LLString& name); | ||
221 | LLString getText(const LLString& name); | ||
222 | LLVector3 getVector3(const LLString& name); | ||
223 | LLVector3d getVector3d(const LLString& name); | ||
224 | LLRect getRect(const LLString& name); | ||
225 | BOOL getBOOL(const LLString& name); | ||
226 | S32 getS32(const LLString& name); | ||
227 | F32 getF32(const LLString& name); | ||
228 | U32 getU32(const LLString& name); | ||
229 | LLSD getValue(const LLString& name); | ||
230 | |||
231 | |||
232 | // Note: If an LLColor4U control exists, it will cast it to the correct | ||
233 | // LLColor4 for you. | ||
234 | LLColor4 getColor(const LLString& name); | ||
235 | LLColor4U getColor4U(const LLString& name); | ||
236 | LLColor4 getColor4(const LLString& name); | ||
237 | LLColor3 getColor3(const LLString& name); | ||
238 | |||
239 | void setBOOL(const LLString& name, BOOL val); | ||
240 | void setS32(const LLString& name, S32 val); | ||
241 | void setF32(const LLString& name, F32 val); | ||
242 | void setU32(const LLString& name, U32 val); | ||
243 | void setString(const LLString& name, const LLString& val); | ||
244 | void setVector3(const LLString& name, const LLVector3 &val); | ||
245 | void setVector3d(const LLString& name, const LLVector3d &val); | ||
246 | void setRect(const LLString& name, const LLRect &val); | ||
247 | void setColor4U(const LLString& name, const LLColor4U &val); | ||
248 | void setColor4(const LLString& name, const LLColor4 &val); | ||
249 | void setColor3(const LLString& name, const LLColor3 &val); | ||
250 | void setValue(const LLString& name, const LLSD& val); | ||
251 | |||
252 | BOOL controlExists(const LLString& name); | ||
253 | |||
254 | // Returns number of controls loaded, 0 if failed | ||
255 | // If require_declaration is false, will auto-declare controls it finds | ||
256 | // as the given type. | ||
257 | U32 loadFromFileLegacy(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING); | ||
258 | U32 loadFromFile(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING); | ||
259 | U32 saveToFile(const LLString& filename, BOOL skip_if_default); | ||
260 | void applyOverrides(const std::map<std::string, std::string>& overrides); | ||
261 | void resetToDefaults(); | ||
262 | |||
263 | // Ignorable Warnings | ||
264 | |||
265 | // Add a config variable to be reset on resetWarnings() | ||
266 | void addWarning(const LLString& name); | ||
267 | BOOL getWarning(const LLString& name); | ||
268 | void setWarning(const LLString& name, BOOL val); | ||
269 | |||
270 | // Resets all ignorables | ||
271 | void resetWarnings(); | ||
272 | }; | ||
273 | |||
274 | #endif | ||