aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lllineeditor.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llui/lllineeditor.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llui/lllineeditor.h')
-rw-r--r--linden/indra/llui/lllineeditor.h320
1 files changed, 320 insertions, 0 deletions
diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h
new file mode 100644
index 0000000..427860d
--- /dev/null
+++ b/linden/indra/llui/lllineeditor.h
@@ -0,0 +1,320 @@
1/**
2 * @file lllineeditor.h
3 * @brief LLLineEditor base class
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// Text editor widget to let users enter/edit a single line.
29//
30//
31// Features:
32// Text entry of a single line (text, delete, left and right arrow, insert, return).
33// Callbacks either on every keystroke or just on the return key.
34// Focus (allow multiple text entry widgets)
35// Clipboard (cut, copy, and paste)
36// Horizontal scrolling to allow strings longer than widget size allows
37// Pre-validation (limit which keys can be used)
38
39
40#ifndef LL_LLLINEEDITOR_H
41#define LL_LLLINEEDITOR_H
42
43#include "v4color.h"
44#include "llframetimer.h"
45
46#include "lleditmenuhandler.h"
47#include "lluictrl.h"
48#include "lluistring.h"
49#include "llviewborder.h"
50
51class LLFontGL;
52class LLLineEditorRollback;
53class LLButton;
54
55typedef BOOL (*LLLinePrevalidateFunc)(const LLWString &wstr);
56
57//
58// Classes
59//
60class LLLineEditor
61: public LLUICtrl, public LLEditMenuHandler
62{
63 friend class LLLineEditorRollback;
64
65public:
66 LLLineEditor(const LLString& name,
67 const LLRect& rect,
68 const LLString& default_text = LLString::null,
69 const LLFontGL* glfont = NULL,
70 S32 max_length_bytes = 254,
71 void (*commit_callback)(LLUICtrl* caller, void* user_data) = NULL,
72 void (*keystroke_callback)(LLLineEditor* caller, void* user_data) = NULL,
73 void (*focus_lost_callback)(LLLineEditor* caller, void* user_data) = NULL,
74 void* userdata = NULL,
75 LLLinePrevalidateFunc prevalidate_func = NULL,
76 LLViewBorder::EBevel border_bevel = LLViewBorder::BEVEL_IN,
77 LLViewBorder::EStyle border_style = LLViewBorder::STYLE_LINE,
78 S32 border_thickness = 1);
79
80 virtual ~LLLineEditor();
81 virtual EWidgetType getWidgetType() const;
82 virtual LLString getWidgetTag() const;
83 virtual LLXMLNodePtr getXML(bool save_children = true) const;
84 void setColorParameters(LLXMLNodePtr node);
85 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
86
87 // mousehandler overrides
88 /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask);
89 /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask);
90 /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask);
91 /*virtual*/ BOOL handleDoubleClick(S32 x,S32 y,MASK mask);
92 /*virtual*/ BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent );
93 /*virtual*/ BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent);
94
95 // LLEditMenuHandler overrides
96 virtual void cut();
97 virtual BOOL canCut();
98
99 virtual void copy();
100 virtual BOOL canCopy();
101
102 virtual void paste();
103 virtual BOOL canPaste();
104
105 virtual void doDelete();
106 virtual BOOL canDoDelete();
107
108 virtual void selectAll();
109 virtual BOOL canSelectAll();
110
111 virtual void deselect();
112 virtual BOOL canDeselect();
113
114 // view overrides
115 virtual void draw();
116 virtual void reshape(S32 width,S32 height,BOOL called_from_parent=TRUE);
117 virtual void onFocusLost();
118 virtual void setEnabled(BOOL enabled);
119
120 // UI control overrides
121 virtual void clear();
122 virtual void onTabInto();
123 virtual void setFocus( BOOL b );
124 virtual void setRect(const LLRect& rect);
125 virtual BOOL acceptsTextInput() const;
126 virtual void onCommit();
127
128 // assumes UTF8 text
129 virtual void setValue(const LLSD& value );
130 virtual LLSD getValue() const;
131 virtual BOOL setTextArg( const LLString& key, const LLString& text );
132 virtual BOOL setLabelArg( const LLString& key, const LLString& text );
133
134 void setLabel(const LLString &new_label);
135 void setText(const LLString &new_text);
136
137 const LLString& getText() const { return mText.getString(); }
138 const LLWString& getWText() const { return mText.getWString(); }
139 S32 getLength() const { return mText.length(); }
140
141 S32 getCursor() { return mCursorPos; }
142 void setCursor( S32 pos );
143 void setCursorToEnd();
144
145 // Selects characters 'start' to 'end'.
146 void setSelection(S32 start, S32 end);
147
148 void setCommitOnFocusLost( BOOL b ) { mCommitOnFocusLost = b; }
149 void setRevertOnEsc( BOOL b ) { mRevertOnEsc = b; }
150
151 void setCursorColor(const LLColor4& c) { mCursorColor = c; }
152 const LLColor4& getCursorColor() const { return mCursorColor; }
153
154 void setFgColor( const LLColor4& c ) { mFgColor = c; }
155 void setReadOnlyFgColor( const LLColor4& c ) { mReadOnlyFgColor = c; }
156 void setTentativeFgColor(const LLColor4& c) { mTentativeFgColor = c; }
157 void setWriteableBgColor( const LLColor4& c ) { mWriteableBgColor = c; }
158 void setReadOnlyBgColor( const LLColor4& c ) { mReadOnlyBgColor = c; }
159 void setFocusBgColor(const LLColor4& c) { mFocusBgColor = c; }
160
161 const LLColor4& getFgColor() const { return mFgColor; }
162 const LLColor4& getReadOnlyFgColor() const { return mReadOnlyFgColor; }
163 const LLColor4& getTentativeFgColor() const { return mTentativeFgColor; }
164 const LLColor4& getWriteableBgColor() const { return mWriteableBgColor; }
165 const LLColor4& getReadOnlyBgColor() const { return mReadOnlyBgColor; }
166 const LLColor4& getFocusBgColor() const { return mFocusBgColor; }
167
168 void setIgnoreArrowKeys(BOOL b) { mIgnoreArrowKeys = b; }
169 void setIgnoreTab(BOOL b) { mIgnoreTab = b; }
170 void setPassDelete(BOOL b) { mPassDelete = b; }
171
172 void setDrawAsterixes(BOOL b) { mDrawAsterixes = b; }
173
174 // get the cursor position of the beginning/end of the prev/next word in the text
175 S32 prevWordPos(S32 cursorPos) const;
176 S32 nextWordPos(S32 cursorPos) const;
177
178 BOOL hasSelection() { return (mSelectionStart != mSelectionEnd); }
179 void startSelection();
180 void endSelection();
181 void extendSelection(S32 new_cursor_pos);
182 void deleteSelection();
183
184 void setHandleEditKeysDirectly( BOOL b ) { mHandleEditKeysDirectly = b; }
185 void setSelectAllonFocusReceived(BOOL b);
186
187 void setKeystrokeCallback(void (*keystroke_callback)(LLLineEditor* caller, void* user_data));
188 void setFocusLostCallback(void (*keystroke_callback)(LLLineEditor* caller, void* user_data));
189
190 void setMaxTextLength(S32 max_text_length);
191 void setBorderWidth(S32 left, S32 right);
192
193 static BOOL isPartOfWord(llwchar c);
194 // Prevalidation controls which keystrokes can affect the editor
195 void setPrevalidate( BOOL (*func)(const LLWString &) ) { mPrevalidateFunc = func; }
196 static BOOL prevalidateFloat(const LLWString &str );
197 static BOOL prevalidateInt(const LLWString &str );
198 static BOOL prevalidatePositiveS32(const LLWString &str);
199 static BOOL prevalidateNonNegativeS32(const LLWString &str);
200 static BOOL prevalidateAlphaNum(const LLWString &str );
201 static BOOL prevalidateAlphaNumSpace(const LLWString &str );
202 static BOOL prevalidatePrintableNotPipe(const LLWString &str);
203 static BOOL prevalidatePrintableNoSpace(const LLWString &str);
204 static BOOL prevalidateASCII(const LLWString &str);
205
206 static BOOL postvalidateFloat(const LLString &str);
207
208 static void onMouseCaptureLost( LLMouseHandler* old_captor );
209
210protected:
211 void removeChar();
212 void addChar(const llwchar c);
213 void setCursorAtLocalPos(S32 local_mouse_x);
214
215 S32 findPixelNearestPos(S32 cursor_offset = 0);
216 void reportBadKeystroke();
217
218 BOOL handleSpecialKey(KEY key, MASK mask);
219 BOOL handleSelectionKey(KEY key, MASK mask);
220 BOOL handleControlKey(KEY key, MASK mask);
221 S32 handleCommitKey(KEY key, MASK mask);
222
223protected:
224 LLUIString mText; // The string being edited.
225 LLString mPrevText; // Saved string for 'ESC' revert
226 LLUIString mLabel; // text label that is visible when no user text provided
227
228 LLViewBorder* mBorder;
229 const LLFontGL* mGLFont;
230 S32 mMaxLengthChars; // Max number of characters
231 S32 mMaxLengthBytes; // Max length of the UTF8 string.
232 S32 mCursorPos; // I-beam is just after the mCursorPos-th character.
233 S32 mScrollHPos; // Horizontal offset from the start of mText. Used for scrolling.
234 LLFrameTimer mScrollTimer;
235 S32 mMinHPixels;
236 S32 mMaxHPixels;
237 S32 mBorderLeft;
238 S32 mBorderRight;
239
240 BOOL mCommitOnFocusLost;
241 BOOL mRevertOnEsc;
242
243 void (*mKeystrokeCallback)( LLLineEditor* caller, void* userdata );
244 void (*mFocusLostCallback)( LLLineEditor* caller, void* userdata );
245
246 BOOL mIsSelecting; // Selection for clipboard operations
247 S32 mSelectionStart;
248 S32 mSelectionEnd;
249 S32 mLastSelectionX;
250 S32 mLastSelectionY;
251
252 S32 (*mPrevalidateFunc)(const LLWString &str);
253
254 LLFrameTimer mKeystrokeTimer;
255
256 LLColor4 mCursorColor;
257
258 LLColor4 mFgColor;
259 LLColor4 mReadOnlyFgColor;
260 LLColor4 mTentativeFgColor;
261 LLColor4 mWriteableBgColor;
262 LLColor4 mReadOnlyBgColor;
263 LLColor4 mFocusBgColor;
264
265 S32 mBorderThickness;
266
267 BOOL mIgnoreArrowKeys;
268 BOOL mIgnoreTab;
269 BOOL mDrawAsterixes;
270
271 BOOL mHandleEditKeysDirectly; // If true, the standard edit keys (Ctrl-X, Delete, etc,) are handled here instead of routed by the menu system
272 BOOL mSelectAllonFocusReceived;
273 BOOL mPassDelete;
274
275 BOOL mReadOnly;
276};
277
278
279class LLSearchEditor : public LLUICtrl
280{
281friend class LLLineEditorRollback;
282
283public:
284 LLSearchEditor(const LLString& name,
285 const LLRect& rect,
286 S32 max_length_bytes,
287 void (*search_callback)(const LLString& search_string, void* user_data),
288 void* userdata);
289
290 virtual ~LLSearchEditor();
291
292 /*virtual*/ void draw();
293
294 virtual EWidgetType getWidgetType() const;
295 virtual LLString getWidgetTag() const;
296 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
297
298 void setText(const LLString &new_text);
299
300 void setSearchCallback(void (*search_callback)(const LLString& search_string, void* user_data), void* data) { mSearchCallback = search_callback; mCallbackUserData = data; }
301
302 // LLUICtrl interface
303 virtual void setValue(const LLSD& value );
304 virtual LLSD getValue() const;
305 virtual BOOL setTextArg( const LLString& key, const LLString& text );
306 virtual BOOL setLabelArg( const LLString& key, const LLString& text );
307 virtual void clear();
308
309
310protected:
311 LLLineEditor* mSearchEdit;
312 LLButton* mClearSearchButton;
313
314 void (*mSearchCallback)(const LLString& search_string, void* user_data);
315
316 static void onSearchEdit(LLLineEditor* caller, void* user_data );
317 static void onClearSearch(void* user_data);
318};
319
320#endif // LL_LINEEDITOR_