aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llxml/llcontrol.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llxml/llcontrol.h210
1 files changed, 78 insertions, 132 deletions
diff --git a/linden/indra/llxml/llcontrol.h b/linden/indra/llxml/llcontrol.h
index e717bf1..9e11628 100644
--- a/linden/indra/llxml/llcontrol.h
+++ b/linden/indra/llxml/llcontrol.h
@@ -38,6 +38,26 @@
38#include "llstring.h" 38#include "llstring.h"
39#include "llrect.h" 39#include "llrect.h"
40 40
41#include <vector>
42
43// *NOTE: boost::visit_each<> generates warning 4675 on .net 2003
44// Disable the warning for the boost includes.
45#if LL_WINDOWS
46# if (_MSC_VER >= 1300 && _MSC_VER < 1400)
47# pragma warning(push)
48# pragma warning( disable : 4675 )
49# endif
50#endif
51
52#include <boost/bind.hpp>
53#include <boost/signal.hpp>
54
55#if LL_WINDOWS
56# if (_MSC_VER >= 1300 && _MSC_VER < 1400)
57# pragma warning(pop)
58# endif
59#endif
60
41class LLVector3; 61class LLVector3;
42class LLVector3d; 62class LLVector3d;
43class LLColor4; 63class LLColor4;
@@ -48,7 +68,7 @@ const BOOL NO_PERSIST = FALSE;
48 68
49typedef enum e_control_type 69typedef enum e_control_type
50{ 70{
51 TYPE_U32, 71 TYPE_U32 = 0,
52 TYPE_S32, 72 TYPE_S32,
53 TYPE_F32, 73 TYPE_F32,
54 TYPE_BOOLEAN, 74 TYPE_BOOLEAN,
@@ -58,159 +78,82 @@ typedef enum e_control_type
58 TYPE_RECT, 78 TYPE_RECT,
59 TYPE_COL4, 79 TYPE_COL4,
60 TYPE_COL3, 80 TYPE_COL3,
61 TYPE_COL4U 81 TYPE_COL4U,
82 TYPE_LLSD,
83 TYPE_COUNT
62} eControlType; 84} eControlType;
63 85
64class LLControlBase : public LLSimpleListenerObservable 86class LLControlVariable
65{ 87{
66friend class LLControlGroup; 88 friend class LLControlGroup;
67protected: 89 typedef boost::signal<void(const LLSD&)> signal_t;
90
91private:
68 LLString mName; 92 LLString mName;
69 LLString mComment; 93 LLString mComment;
70 eControlType mType; 94 eControlType mType;
71 BOOL mHasRange;
72 BOOL mPersist; 95 BOOL mPersist;
73 BOOL mIsDefault; 96 std::vector<LLSD> mValues;
74 97
75 static std::set<LLControlBase*> mChangedControls; 98 signal_t mSignal;
76 static std::list<S32> mFreeIDs;//These lists are used to store the ID's of registered event listeners. 99
77 static std::list<S32> mUsedIDs;
78 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.
79
80public: 100public:
81 static void releaseListenerID(S32 id); 101 LLControlVariable(const LLString& name, eControlType type,
82 static S32 allocateListenerID(); 102 LLSD initial, const LLString& comment,
83 static void updateAllListeners(); 103 BOOL persist = TRUE);
84 virtual void updateListeners() = 0;
85
86 LLControlBase(const LLString& name, eControlType type, const LLString& comment, BOOL persist)
87 : mName(name),
88 mComment(comment),
89 mType(type),
90 mHasRange(FALSE),
91 mPersist(persist),
92 mIsDefault(TRUE)
93 {
94 if (mPersist && mComment.empty())
95 {
96 llerrs << "Must supply a comment for control " << mName << llendl;
97 }
98 sMaxControlNameLength = llmax((U32)mName.size(), sMaxControlNameLength);
99 }
100
101 virtual ~LLControlBase();
102 104
105 virtual ~LLControlVariable();
106
103 const LLString& getName() const { return mName; } 107 const LLString& getName() const { return mName; }
104 const LLString& getComment() const { return mComment; } 108 const LLString& getComment() const { return mComment; }
105 109
106 eControlType type() { return mType; } 110 eControlType type() { return mType; }
107 BOOL isType(eControlType tp) { return tp == mType; } 111 BOOL isType(eControlType tp) { return tp == mType; }
108 112
109 // Defaults to no-op 113 void resetToDefault(bool fire_signal = TRUE);
110 virtual void resetToDefault(); 114
111 115 signal_t* getSignal() { return &mSignal; }
112 LLSD registerListener(LLSimpleListenerObservable *listener, LLSD userdata = ""); 116
113 117 bool isDefault() { return (mValues.size() == 1); }
114 virtual LLSD get() const = 0; 118 bool isSaveValueDefault();
115 virtual LLSD getValue() const = 0; 119 bool isPersisted() { return mPersist; }
116 virtual void setValue(LLSD value) = 0; 120 void set(const LLSD& val) { setValue(val); }
117 virtual void set(LLSD value) = 0; 121 LLSD get() const { return getValue(); }
118 122 LLSD getDefault() const { return mValues.front(); }
119 // From LLSimpleListener 123 LLSD getValue() const { return mValues.back(); }
120 virtual bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata); 124 LLSD getSaveValue() const;
121 125 void setValue(const LLSD& value, bool saved_value = TRUE);
122 void firePropertyChanged(); 126 void firePropertyChanged()
123
124 static U32 sMaxControlNameLength;
125
126protected:
127 const char* name() { return mName.c_str(); }
128 const char* comment() { return mComment.c_str(); }
129};
130
131class LLControl
132: public LLControlBase
133{
134friend class LLControlGroup;
135protected:
136 LLSD mCurrent;
137 LLSD mDefault;
138
139public:
140
141 typedef void tListenerCallback(const LLSD& newValue,S32 listenerID, LLControl& control);
142 typedef struct{
143 S32 mID;
144 LLSD mNewValue;
145 tListenerCallback* mCBFN;
146 }tPropertyChangedEvent;
147
148 typedef std::list<tPropertyChangedEvent>::iterator tPropertyChangedListIter;
149 std::list<tPropertyChangedEvent> mChangeEvents;
150 std::list< tListenerCallback* > mListeners;
151 std::list< S32 > mListenerIDs;
152
153 virtual void updateListeners();
154 S32 addListener(tListenerCallback* cbfn);
155
156 LLControl(
157 const LLString& name,
158 eControlType type,
159 LLSD initial, const
160 LLString& comment,
161 BOOL persist = TRUE);
162
163 void set(LLSD val) { setValue(val); }
164 LLSD get() const { return getValue(); }
165 LLSD getdefault() const { return mDefault; }
166 LLSD getValue() const { return mCurrent; }
167 BOOL llsd_compare(const LLSD& a, const LLSD& b);
168
169 void setValue(LLSD value)
170 {
171 if (llsd_compare(mCurrent, value) == FALSE)
172 {
173 mCurrent = value;
174 mIsDefault = llsd_compare(mCurrent, mDefault);
175 firePropertyChanged();
176 }
177 }
178
179 /*virtual*/ void resetToDefault()
180 {
181 setValue(mDefault);
182 }
183
184 virtual ~LLControl()
185 { 127 {
186 //Remove and deregister all listeners.. 128 mSignal(mValues.back());
187 while(mListenerIDs.size())
188 {
189 S32 id = mListenerIDs.front();
190 mListenerIDs.pop_front();
191 releaseListenerID(id);
192 }
193 } 129 }
130 BOOL llsd_compare(const LLSD& a, const LLSD& b);
194}; 131};
195 132
196//const U32 STRING_CACHE_SIZE = 10000; 133//const U32 STRING_CACHE_SIZE = 10000;
197class LLControlGroup 134class LLControlGroup
198{ 135{
199public: 136protected:
200 typedef std::map<LLString, LLPointer<LLControlBase> > ctrl_name_table_t; 137 typedef std::map<LLString, LLControlVariable* > ctrl_name_table_t;
201 ctrl_name_table_t mNameTable; 138 ctrl_name_table_t mNameTable;
202 std::set<LLString> mWarnings; 139 std::set<LLString> mWarnings;
203 std::set<LLString> mLoadedSettings; // Filled in with names loaded from settings.xml 140 LLString mTypeString[TYPE_COUNT];
204 141
142 eControlType typeStringToEnum(const LLString& typestr);
143 LLString typeEnumToString(eControlType typeenum);
205public: 144public:
206 LLControlGroup(); 145 LLControlGroup();
207 ~LLControlGroup(); 146 ~LLControlGroup();
208 void cleanup(); 147 void cleanup();
209 bool hasLoaded(const LLString& name) { return mLoadedSettings.find(name) != mLoadedSettings.end(); }
210 void clearLoaded() { mLoadedSettings.clear(); } // Call once we've done any settings tweaks which may need this data
211 148
212 LLControlBase* getControl(const LLString& name); 149 LLControlVariable* getControl(const LLString& name);
213 LLSD registerListener(const LLString& name, LLSimpleListenerObservable *listener); 150
151 struct ApplyFunctor
152 {
153 virtual ~ApplyFunctor() {};
154 virtual void apply(const LLString& name, LLControlVariable* control) = 0;
155 };
156 void applyToAll(ApplyFunctor* func);
214 157
215 BOOL declareControl(const LLString& name, eControlType type, const LLSD initial_val, const LLString& comment, BOOL persist); 158 BOOL declareControl(const LLString& name, eControlType type, const LLSD initial_val, const LLString& comment, BOOL persist);
216 BOOL declareU32(const LLString& name, U32 initial_val, const LLString& comment, BOOL persist = TRUE); 159 BOOL declareU32(const LLString& name, U32 initial_val, const LLString& comment, BOOL persist = TRUE);
@@ -224,6 +167,7 @@ public:
224 BOOL declareColor4U(const LLString& name, const LLColor4U &initial_val, const LLString& comment, BOOL persist = TRUE); 167 BOOL declareColor4U(const LLString& name, const LLColor4U &initial_val, const LLString& comment, BOOL persist = TRUE);
225 BOOL declareColor4(const LLString& name, const LLColor4 &initial_val, const LLString& comment, BOOL persist = TRUE); 168 BOOL declareColor4(const LLString& name, const LLColor4 &initial_val, const LLString& comment, BOOL persist = TRUE);
226 BOOL declareColor3(const LLString& name, const LLColor3 &initial_val, const LLString& comment, BOOL persist = TRUE); 169 BOOL declareColor3(const LLString& name, const LLColor3 &initial_val, const LLString& comment, BOOL persist = TRUE);
170 BOOL declareLLSD(const LLString& name, const LLSD &initial_val, const LLString& comment, BOOL persist = TRUE);
227 171
228 LLString findString(const LLString& name); 172 LLString findString(const LLString& name);
229 173
@@ -237,7 +181,7 @@ public:
237 S32 getS32(const LLString& name); 181 S32 getS32(const LLString& name);
238 F32 getF32(const LLString& name); 182 F32 getF32(const LLString& name);
239 U32 getU32(const LLString& name); 183 U32 getU32(const LLString& name);
240 LLSD getValue(const LLString& name); 184 LLSD getLLSD(const LLString& name);
241 185
242 186
243 // Note: If an LLColor4U control exists, it will cast it to the correct 187 // Note: If an LLColor4U control exists, it will cast it to the correct
@@ -258,19 +202,21 @@ public:
258 void setColor4U(const LLString& name, const LLColor4U &val); 202 void setColor4U(const LLString& name, const LLColor4U &val);
259 void setColor4(const LLString& name, const LLColor4 &val); 203 void setColor4(const LLString& name, const LLColor4 &val);
260 void setColor3(const LLString& name, const LLColor3 &val); 204 void setColor3(const LLString& name, const LLColor3 &val);
205 void setLLSD(const LLString& name, const LLSD& val);
261 void setValue(const LLString& name, const LLSD& val); 206 void setValue(const LLString& name, const LLSD& val);
262 207
208
263 BOOL controlExists(const LLString& name); 209 BOOL controlExists(const LLString& name);
264 210
265 // Returns number of controls loaded, 0 if failed 211 // Returns number of controls loaded, 0 if failed
266 // If require_declaration is false, will auto-declare controls it finds 212 // If require_declaration is false, will auto-declare controls it finds
267 // as the given type. 213 // as the given type.
268 U32 loadFromFileLegacy(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING); 214 U32 loadFromFileLegacy(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING);
269 U32 loadFromFile(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING); 215 U32 saveToFile(const LLString& filename, BOOL nondefault_only);
270 U32 saveToFile(const LLString& filename, BOOL skip_if_default); 216 U32 loadFromFile(const LLString& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING);
271 void applyOverrides(const std::map<std::string, std::string>& overrides);
272 void resetToDefaults(); 217 void resetToDefaults();
273 218
219
274 // Ignorable Warnings 220 // Ignorable Warnings
275 221
276 // Add a config variable to be reset on resetWarnings() 222 // Add a config variable to be reset on resetWarnings()