PageRenderTime 43ms CodeModel.GetById 16ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llviewmodel.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 214 lines | 58 code | 16 blank | 140 comment | 0 complexity | c1a98536b7c9bf417e9f79c91a137493 MD5 | raw file
  1/**
  2 * @file   llviewmodel.h
  3 * @author Nat Goodspeed
  4 * @date   2008-08-08
  5 * @brief  Define "View Model" classes intended to store data values for use
  6 *         by LLUICtrl subclasses. The phrase is borrowed from Microsoft
  7 *         terminology, in which "View Model" means the storage object
  8 *         underlying a specific widget object -- as in our case -- rather
  9 *         than the business "model" object underlying the overall "view"
 10 *         presented by the collection of widgets.
 11 * 
 12 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
 13 * Second Life Viewer Source Code
 14 * Copyright (C) 2010, Linden Research, Inc.
 15 * 
 16 * This library is free software; you can redistribute it and/or
 17 * modify it under the terms of the GNU Lesser General Public
 18 * License as published by the Free Software Foundation;
 19 * version 2.1 of the License only.
 20 * 
 21 * This library is distributed in the hope that it will be useful,
 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 24 * Lesser General Public License for more details.
 25 * 
 26 * You should have received a copy of the GNU Lesser General Public
 27 * License along with this library; if not, write to the Free Software
 28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 29 * 
 30 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 31 * $/LicenseInfo$
 32 */
 33
 34#if ! defined(LL_LLVIEWMODEL_H)
 35#define LL_LLVIEWMODEL_H
 36
 37#include "llpointer.h"
 38#include "llsd.h"
 39#include "llrefcount.h"
 40#include "stdenums.h"
 41#include "llstring.h"
 42#include <string>
 43
 44class LLScrollListItem;
 45
 46class LLViewModel;
 47class LLTextViewModel;
 48class LLListViewModel;
 49// Because LLViewModel is derived from LLRefCount, always pass, store
 50// and return LLViewModelPtr rather than plain LLViewModel*.
 51typedef LLPointer<LLViewModel> LLViewModelPtr;
 52typedef LLPointer<LLTextViewModel> LLTextViewModelPtr;
 53typedef LLPointer<LLListViewModel> LLListViewModelPtr;
 54
 55/**
 56 * LLViewModel stores a scalar LLSD data item, the current display value of a
 57 * scalar LLUICtrl widget. LLViewModel subclasses are used to store data
 58 * collections used for aggregate widgets. LLViewModel is ref-counted because
 59 * -- for multiple skins -- we may have distinct widgets sharing the same
 60 * LLViewModel data. This way, the LLViewModel is quietly deleted when the
 61 * last referencing widget is destroyed.
 62 */
 63class LLViewModel: public LLRefCount
 64{
 65public:
 66    LLViewModel();
 67    /// Instantiate an LLViewModel with an existing data value
 68    LLViewModel(const LLSD& value);
 69
 70    /// Update the stored value
 71    virtual void setValue(const LLSD& value);
 72    /// Get the stored value, in appropriate type.
 73    virtual LLSD getValue() const;
 74
 75    /// Has the value been changed since last time we checked?
 76    bool isDirty() const { return mDirty; }
 77    /// Once the value has been saved to a file, or otherwise consumed by the
 78    /// app, we no longer need to enable the Save button
 79    void resetDirty() { mDirty = false; }
 80	// 
 81    void setDirty() { mDirty = true; }
 82
 83protected:
 84    LLSD mValue;
 85    bool mDirty;
 86};
 87
 88/**
 89 * LLTextViewModel stores a value displayed as text. 
 90 */
 91class LLTextViewModel: public LLViewModel
 92{
 93public:
 94    LLTextViewModel();
 95    /// Instantiate an LLViewModel with an existing data value
 96    LLTextViewModel(const LLSD& value);
 97	
 98	// LLViewModel functions
 99    virtual void setValue(const LLSD& value);
100    virtual LLSD getValue() const;
101
102	// New functions
103    /// Get the stored value in string form
104    const LLWString& getDisplay() const { return mDisplay; }
105
106    /**
107     * Set the display string directly (see LLTextEditor). What the user is
108     * editing is actually the LLWString value rather than the underlying
109     * UTF-8 value.
110     */
111    void setDisplay(const LLWString& value);
112	
113private:
114    /// To avoid converting every widget's stored value from LLSD to LLWString
115    /// every frame, cache the converted value
116    LLWString mDisplay;
117    /// As the user edits individual characters (setDisplay()), defer
118    /// LLWString-to-UTF8 conversions until s/he's done.
119    bool mUpdateFromDisplay;
120};
121
122/**
123 * LLListViewModel stores a list of data items. The semantics are borrowed
124 * from LLScrollListCtrl.
125 */
126class LLListViewModel: public LLViewModel
127{
128public:
129    LLListViewModel() {}
130    LLListViewModel(const LLSD& values);
131
132    virtual void addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
133    virtual void clearColumns();
134    virtual void setColumnLabel(const std::string& column, const std::string& label);
135    virtual LLScrollListItem* addElement(const LLSD& value, EAddPosition pos = ADD_BOTTOM,
136                                         void* userdata = NULL);
137    virtual LLScrollListItem* addSimpleElement(const std::string& value, EAddPosition pos,
138                                               const LLSD& id);
139    virtual void clearRows();
140    virtual void sortByColumn(const std::string& name, bool ascending);
141};
142
143//namespace LLViewModel
144//{
145//	class Value
146//	{
147//	public:
148//		Value(const LLSD& value = LLSD());
149//
150//		LLSD getValue() const { return mValue; }
151//		void setValue(const LLSD& value) { mValue = value; }
152//
153//		bool isAvailable() const { return false; }
154//		bool isReadOnly() const { return false; }
155//
156//		bool undo() { return false; }
157//		bool redo() { return false; }
158//
159//	    /// Has the value been changed since last time we checked?
160//		bool isDirty() const { return mDirty; }
161//		/// Once the value has been saved to a file, or otherwise consumed by the
162//		/// app, we no longer need to enable the Save button
163//		void resetDirty() { mDirty = false; }
164//		// 
165//		void setDirty() { mDirty = true; }
166//
167//	protected:
168//		LLSD	mValue;
169//		bool mDirty;
170//	};
171//
172//	class Numeric : public Value
173//	{
174//	public:
175//		Numeric(S32 value = 0);
176//		Numeric(F32 value);
177//
178//		F32 getPrecision();
179//		F32 getMin();
180//		F32 getMax();
181//
182//		void increment();
183//		void decrement();
184//	};
185//
186//	class MultipleValues : public Value
187//	{
188//		class Selector
189//		{};
190//
191//		MultipleValues();
192//		virtual S32 numElements();
193//	};
194//
195//	class Tuple : public MultipleValues
196//	{
197//		Tuple(S32 size);
198//		LLSD getValue(S32 which) const;
199//		void setValue(S32 which, const LLSD& value);
200//	};
201//
202//	class List : public MultipleValues
203//	{
204//		List();
205//
206//		void add(const ValueModel& value);
207//		bool remove(const Selector& item);
208//
209//		void setSortElement(const Selector& element);
210//		void sort();
211//	};
212//
213//};
214#endif /* ! defined(LL_LLVIEWMODEL_H) */