aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lllineeditor.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llui/lllineeditor.h
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/llui/lllineeditor.h143
1 files changed, 88 insertions, 55 deletions
diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h
index 6d328e5..ba3c697 100644
--- a/linden/indra/llui/lllineeditor.h
+++ b/linden/indra/llui/lllineeditor.h
@@ -1,6 +1,15 @@
1/** 1/**
2 * @file lllineeditor.h 2 * @file lllineeditor.h
3 * @brief LLLineEditor base class 3 * @brief Text editor widget to let users enter/edit a single line.
4 *
5 * Features:
6 * Text entry of a single line (text, delete, left and right arrow, insert, return).
7 * Callbacks either on every keystroke or just on the return key.
8 * Focus (allow multiple text entry widgets)
9 * Clipboard (cut, copy, and paste)
10 * Horizontal scrolling to allow strings longer than widget size allows
11 * Pre-validation (limit which keys can be used)
12 * Optional line history so previous entries can be recalled by CTRL UP/DOWN
4 * 13 *
5 * $LicenseInfo:firstyear=2001&license=viewergpl$ 14 * $LicenseInfo:firstyear=2001&license=viewergpl$
6 * 15 *
@@ -29,19 +38,6 @@
29 * $/LicenseInfo$ 38 * $/LicenseInfo$
30 */ 39 */
31 40
32// Text editor widget to let users enter/edit a single line.
33//
34//
35// Features:
36// Text entry of a single line (text, delete, left and right arrow, insert, return).
37// Callbacks either on every keystroke or just on the return key.
38// Focus (allow multiple text entry widgets)
39// Clipboard (cut, copy, and paste)
40// Horizontal scrolling to allow strings longer than widget size allows
41// Pre-validation (limit which keys can be used)
42// Optional line history so previous entries can be recalled by CTRL UP/DOWN
43
44
45#ifndef LL_LLLINEEDITOR_H 41#ifndef LL_LLLINEEDITOR_H
46#define LL_LLLINEEDITOR_H 42#define LL_LLLINEEDITOR_H
47 43
@@ -61,13 +57,10 @@ class LLButton;
61 57
62typedef BOOL (*LLLinePrevalidateFunc)(const LLWString &wstr); 58typedef BOOL (*LLLinePrevalidateFunc)(const LLWString &wstr);
63 59
64// 60
65// Classes
66//
67class LLLineEditor 61class LLLineEditor
68: public LLUICtrl, public LLEditMenuHandler, protected LLPreeditor 62: public LLUICtrl, public LLEditMenuHandler, protected LLPreeditor
69{ 63{
70 friend class LLLineEditorRollback;
71 64
72public: 65public:
73 LLLineEditor(const LLString& name, 66 LLLineEditor(const LLString& name,
@@ -85,8 +78,8 @@ public:
85 S32 border_thickness = 1); 78 S32 border_thickness = 1);
86 79
87 virtual ~LLLineEditor(); 80 virtual ~LLLineEditor();
88 virtual EWidgetType getWidgetType() const; 81 virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_LINE_EDITOR; }
89 virtual LLString getWidgetTag() const; 82 virtual LLString getWidgetTag() const { return LL_LINE_EDITOR_TAG; };
90 virtual LLXMLNodePtr getXML(bool save_children = true) const; 83 virtual LLXMLNodePtr getXML(bool save_children = true) const;
91 void setColorParameters(LLXMLNodePtr node); 84 void setColorParameters(LLXMLNodePtr node);
92 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); 85 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
@@ -102,22 +95,22 @@ public:
102 95
103 // LLEditMenuHandler overrides 96 // LLEditMenuHandler overrides
104 virtual void cut(); 97 virtual void cut();
105 virtual BOOL canCut(); 98 virtual BOOL canCut() const;
106 99
107 virtual void copy(); 100 virtual void copy();
108 virtual BOOL canCopy(); 101 virtual BOOL canCopy() const;
109 102
110 virtual void paste(); 103 virtual void paste();
111 virtual BOOL canPaste(); 104 virtual BOOL canPaste() const;
112 105
113 virtual void doDelete(); 106 virtual void doDelete();
114 virtual BOOL canDoDelete(); 107 virtual BOOL canDoDelete() const;
115 108
116 virtual void selectAll(); 109 virtual void selectAll();
117 virtual BOOL canSelectAll(); 110 virtual BOOL canSelectAll() const;
118 111
119 virtual void deselect(); 112 virtual void deselect();
120 virtual BOOL canDeselect(); 113 virtual BOOL canDeselect() const;
121 114
122 // view overrides 115 // view overrides
123 virtual void draw(); 116 virtual void draw();
@@ -133,16 +126,16 @@ public:
133 virtual void setRect(const LLRect& rect); 126 virtual void setRect(const LLRect& rect);
134 virtual BOOL acceptsTextInput() const; 127 virtual BOOL acceptsTextInput() const;
135 virtual void onCommit(); 128 virtual void onCommit();
136 virtual BOOL isDirty() const; // Returns TRUE if the user has changed value at all 129 virtual BOOL isDirty() const { return mText.getString() != mPrevText; } // Returns TRUE if user changed value at all
137 virtual void resetDirty(); // Clear dirty state 130 virtual void resetDirty() { mPrevText = mText.getString(); } // Clear dirty state
138 131
139 // assumes UTF8 text 132 // assumes UTF8 text
140 virtual void setValue(const LLSD& value ); 133 virtual void setValue(const LLSD& value ) { setText(value.asString()); }
141 virtual LLSD getValue() const; 134 virtual LLSD getValue() const { return LLSD(getText()); }
142 virtual BOOL setTextArg( const LLString& key, const LLStringExplicit& text ); 135 virtual BOOL setTextArg( const LLString& key, const LLStringExplicit& text );
143 virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text ); 136 virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text );
144 137
145 void setLabel(const LLStringExplicit &new_label); 138 void setLabel(const LLStringExplicit &new_label) { mLabel = new_label; }
146 void setText(const LLStringExplicit &new_text); 139 void setText(const LLStringExplicit &new_text);
147 140
148 const LLString& getText() const { return mText.getString(); } 141 const LLString& getText() const { return mText.getString(); }
@@ -179,7 +172,6 @@ public:
179 void setIgnoreArrowKeys(BOOL b) { mIgnoreArrowKeys = b; } 172 void setIgnoreArrowKeys(BOOL b) { mIgnoreArrowKeys = b; }
180 void setIgnoreTab(BOOL b) { mIgnoreTab = b; } 173 void setIgnoreTab(BOOL b) { mIgnoreTab = b; }
181 void setPassDelete(BOOL b) { mPassDelete = b; } 174 void setPassDelete(BOOL b) { mPassDelete = b; }
182
183 void setDrawAsterixes(BOOL b); 175 void setDrawAsterixes(BOOL b);
184 176
185 // get the cursor position of the beginning/end of the prev/next word in the text 177 // get the cursor position of the beginning/end of the prev/next word in the text
@@ -216,23 +208,24 @@ public:
216 static BOOL postvalidateFloat(const LLString &str); 208 static BOOL postvalidateFloat(const LLString &str);
217 209
218 // line history support: 210 // line history support:
219 void setEnableLineHistory( BOOL enabled ); // switches line history on or off 211 void setEnableLineHistory( BOOL enabled ) { mHaveHistory = enabled; } // switches line history on or off
220 void updateHistory(); // stores current line in history 212 void updateHistory(); // stores current line in history
221 213
222protected: 214private:
215 // private helper classes
223 void removeChar(); 216 void removeChar();
224 void addChar(const llwchar c); 217 void addChar(const llwchar c);
225 void setCursorAtLocalPos(S32 local_mouse_x); 218 void setCursorAtLocalPos(S32 local_mouse_x);
226
227 S32 findPixelNearestPos(S32 cursor_offset = 0) const; 219 S32 findPixelNearestPos(S32 cursor_offset = 0) const;
228 void reportBadKeystroke(); 220 void reportBadKeystroke();
229
230 BOOL handleSpecialKey(KEY key, MASK mask); 221 BOOL handleSpecialKey(KEY key, MASK mask);
231 BOOL handleSelectionKey(KEY key, MASK mask); 222 BOOL handleSelectionKey(KEY key, MASK mask);
232 BOOL handleControlKey(KEY key, MASK mask); 223 BOOL handleControlKey(KEY key, MASK mask);
233 S32 handleCommitKey(KEY key, MASK mask); 224 S32 handleCommitKey(KEY key, MASK mask);
234 225
235protected: 226 //
227 // private data members
228 //
236 void updateAllowingLanguageInput(); 229 void updateAllowingLanguageInput();
237 BOOL hasPreeditString() const; 230 BOOL hasPreeditString() const;
238 // Implementation (overrides) of LLPreeditor 231 // Implementation (overrides) of LLPreeditor
@@ -308,13 +301,53 @@ protected:
308 LLWString mPreeditOverwrittenWString; 301 LLWString mPreeditOverwrittenWString;
309 std::vector<S32> mPreeditPositions; 302 std::vector<S32> mPreeditPositions;
310 LLPreeditor::standouts_t mPreeditStandouts; 303 LLPreeditor::standouts_t mPreeditStandouts;
311};
312
313 304
305 // private helper class
306 class LLLineEditorRollback
307 {
308 public:
309 LLLineEditorRollback( LLLineEditor* ed )
310 :
311 mCursorPos( ed->mCursorPos ),
312 mScrollHPos( ed->mScrollHPos ),
313 mIsSelecting( ed->mIsSelecting ),
314 mSelectionStart( ed->mSelectionStart ),
315 mSelectionEnd( ed->mSelectionEnd )
316 {
317 mText = ed->getText();
318 }
319
320 void doRollback( LLLineEditor* ed )
321 {
322 ed->mCursorPos = mCursorPos;
323 ed->mScrollHPos = mScrollHPos;
324 ed->mIsSelecting = mIsSelecting;
325 ed->mSelectionStart = mSelectionStart;
326 ed->mSelectionEnd = mSelectionEnd;
327 ed->mText = mText;
328 ed->mPrevText = mText;
329 }
330
331 LLString getText() { return mText; }
332
333 private:
334 LLString mText;
335 S32 mCursorPos;
336 S32 mScrollHPos;
337 BOOL mIsSelecting;
338 S32 mSelectionStart;
339 S32 mSelectionEnd;
340 }; // end class LLLineEditorRollback
341
342}; // end class LLLineEditor
343
344
345
346/*
347 * @brief A line editor with a button to clear it and a callback to call on every edit event.
348 */
314class LLSearchEditor : public LLUICtrl 349class LLSearchEditor : public LLUICtrl
315{ 350{
316friend class LLLineEditorRollback;
317
318public: 351public:
319 LLSearchEditor(const LLString& name, 352 LLSearchEditor(const LLString& name,
320 const LLRect& rect, 353 const LLRect& rect,
@@ -322,34 +355,34 @@ public:
322 void (*search_callback)(const LLString& search_string, void* user_data), 355 void (*search_callback)(const LLString& search_string, void* user_data),
323 void* userdata); 356 void* userdata);
324 357
325 virtual ~LLSearchEditor(); 358 virtual ~LLSearchEditor() {}
326 359
327 /*virtual*/ void draw(); 360 /*virtual*/ void draw();
328 361
329 virtual EWidgetType getWidgetType() const; 362 virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SEARCH_EDITOR; }
330 virtual LLString getWidgetTag() const; 363 virtual LLString getWidgetTag() const { return LL_SEARCH_EDITOR_TAG; }
331 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); 364 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
332 365
333 void setText(const LLStringExplicit &new_text); 366 void setText(const LLStringExplicit &new_text) { mSearchEdit->setText(new_text); }
334 367
335 void setSearchCallback(void (*search_callback)(const LLString& search_string, void* user_data), void* data) { mSearchCallback = search_callback; mCallbackUserData = data; } 368 void setSearchCallback(void (*search_callback)(const LLString& search_string, void* user_data), void* data) { mSearchCallback = search_callback; mCallbackUserData = data; }
336 369
337 // LLUICtrl interface 370 // LLUICtrl interface
338 virtual void setValue(const LLSD& value ); 371 virtual void setValue(const LLSD& value ) { mSearchEdit->setValue(value); }
339 virtual LLSD getValue() const; 372 virtual LLSD getValue() const { return mSearchEdit->getValue(); }
340 virtual BOOL setTextArg( const LLString& key, const LLStringExplicit& text ); 373 virtual BOOL setTextArg( const LLString& key, const LLStringExplicit& text ) { return mSearchEdit->setTextArg( key, text); }
341 virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text ); 374 virtual BOOL setLabelArg( const LLString& key, const LLStringExplicit& text ) { return mSearchEdit->setLabelArg(key, text); }
342 virtual void clear(); 375 virtual void clear() { if (mSearchEdit) mSearchEdit->clear(); }
343 376
344 377
345protected: 378private:
346 LLLineEditor* mSearchEdit; 379 static void onSearchEdit(LLLineEditor* caller, void* user_data );
347 LLButton* mClearSearchButton; 380 static void onClearSearch(void* user_data);
348 381
382 LLLineEditor* mSearchEdit;
383 class LLButton* mClearSearchButton;
349 void (*mSearchCallback)(const LLString& search_string, void* user_data); 384 void (*mSearchCallback)(const LLString& search_string, void* user_data);
350 385
351 static void onSearchEdit(LLLineEditor* caller, void* user_data );
352 static void onClearSearch(void* user_data);
353}; 386};
354 387
355#endif // LL_LINEEDITOR_ 388#endif // LL_LINEEDITOR_