aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/lltexteditor.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/lltexteditor.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 '')
-rw-r--r--linden/indra/llui/lltexteditor.h503
1 files changed, 503 insertions, 0 deletions
diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h
new file mode 100644
index 0000000..e5ba8ca
--- /dev/null
+++ b/linden/indra/llui/lltexteditor.h
@@ -0,0 +1,503 @@
1/**
2 * @file lltexteditor.h
3 * @brief LLTextEditor 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 a a multi-line ASCII document//
29
30#ifndef LL_LLTEXTEDITOR_H
31#define LL_LLTEXTEDITOR_H
32
33#include "llrect.h"
34#include "llkeywords.h"
35#include "lluictrl.h"
36#include "llframetimer.h"
37#include "lldarray.h"
38#include "llstyle.h"
39#include "lleditmenuhandler.h"
40#include "lldarray.h"
41
42class LLFontGL;
43class LLScrollbar;
44class LLViewBorder;
45class LLKeywordToken;
46class LLTextCmd;
47class LLUICtrlFactory;
48
49//
50// Constants
51//
52
53const llwchar FIRST_EMBEDDED_CHAR = 0x100000;
54const llwchar LAST_EMBEDDED_CHAR = 0x10ffff;
55const S32 MAX_EMBEDDED_ITEMS = LAST_EMBEDDED_CHAR - FIRST_EMBEDDED_CHAR + 1;
56
57//
58// Classes
59//
60class LLTextSegment;
61class LLTextCmd;
62
63class LLTextEditor : public LLUICtrl, LLEditMenuHandler
64{
65 friend class LLTextCmd;
66public:
67 LLTextEditor(const LLString& name,
68 const LLRect& rect,
69 S32 max_length,
70 const LLString &default_text,
71 const LLFontGL* glfont = NULL,
72 BOOL allow_embedded_items = FALSE);
73
74 virtual ~LLTextEditor();
75
76 virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_TEXT_EDITOR; }
77 virtual LLString getWidgetTag() const;
78
79 virtual LLXMLNodePtr getXML(bool save_children = true) const;
80 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
81 void setTextEditorParameters(LLXMLNodePtr node);
82 void setParseHTML(BOOL parsing) {mParseHTML=parsing;}
83
84 // mousehandler overrides
85 virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
86 virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);
87 virtual BOOL handleHover(S32 x, S32 y, MASK mask);
88 virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks);
89 virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask );
90 virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent );
91 virtual BOOL handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent);
92
93 virtual BOOL handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect);
94 virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
95 EDragAndDropType cargo_type, void *cargo_data,
96 EAcceptance *accept, LLString& tooltip_msg);
97
98 // view overrides
99 virtual void reshape(S32 width, S32 height, BOOL called_from_parent);
100 virtual void draw();
101 virtual void onFocusLost();
102 virtual void setEnabled(BOOL enabled);
103
104 // uictrl overrides
105 virtual void onTabInto();
106 virtual void clear();
107 virtual void setFocus( BOOL b );
108 virtual BOOL acceptsTextInput() const;
109
110 // LLEditMenuHandler interface
111 virtual void undo();
112 virtual BOOL canUndo();
113
114 virtual void redo();
115 virtual BOOL canRedo();
116
117 virtual void cut();
118 virtual BOOL canCut();
119
120 virtual void copy();
121 virtual BOOL canCopy();
122
123 virtual void paste();
124 virtual BOOL canPaste();
125
126 virtual void doDelete();
127 virtual BOOL canDoDelete();
128
129 virtual void selectAll();
130 virtual BOOL canSelectAll();
131
132 virtual void deselect();
133 virtual BOOL canDeselect();
134
135 void selectNext(const LLString& search_text_in, BOOL case_insensitive, BOOL wrap = TRUE);
136 BOOL replaceText(const LLString& search_text, const LLString& replace_text, BOOL case_insensitive, BOOL wrap = TRUE);
137 void replaceTextAll(const LLString& search_text, const LLString& replace_text, BOOL case_insensitive);
138
139 // Undo/redo stack
140 void blockUndo();
141
142 // Text editing
143 virtual void makePristine();
144 BOOL isPristine() const;
145
146 // inserts text at cursor
147 void insertText(const LLString &text);
148 // appends text at end
149 void appendText(const LLString &wtext, bool allow_undo, bool prepend_newline,
150 const LLStyle* segment_style = NULL);
151
152 void appendColoredText(const LLString &wtext, bool allow_undo,
153 bool prepend_newline,
154 const LLColor4 &color,
155 const LLString& font_name = LLString::null);
156 // if styled text starts a line, you need to prepend a newline.
157 void appendStyledText(const LLString &new_text, bool allow_undo,
158 bool prepend_newline,
159 const LLStyle &style);
160
161 // Removes text from the end of document
162 // Does not change highlight or cursor position.
163 void removeTextFromEnd(S32 num_chars);
164
165 BOOL tryToRevertToPristineState();
166
167 void setCursor(S32 row, S32 column);
168 void setCursorPos(S32 offset);
169 void setCursorAndScrollToEnd();
170
171 void getCurrentLineAndColumn( S32* line, S32* col, BOOL include_wordwrap );
172
173 void loadKeywords(const LLString& filename,
174 const LLDynamicArray<const char*>& funcs,
175 const LLDynamicArray<const char*>& tooltips,
176 const LLColor3& func_color);
177
178 void setCursorColor(const LLColor4& c) { mCursorColor = c; }
179 void setFgColor( const LLColor4& c ) { mFgColor = c; }
180 void setReadOnlyFgColor( const LLColor4& c ) { mReadOnlyFgColor = c; }
181 void setWriteableBgColor( const LLColor4& c ) { mWriteableBgColor = c; }
182 void setReadOnlyBgColor( const LLColor4& c ) { mReadOnlyBgColor = c; }
183
184 void setTrackColor( const LLColor4& color );
185 void setThumbColor( const LLColor4& color );
186 void setHighlightColor( const LLColor4& color );
187 void setShadowColor( const LLColor4& color );
188
189 // Hacky methods to make it into a word-wrapping, potentially scrolling,
190 // read-only text box.
191 void setBorderVisible(BOOL b);
192 void setTakesNonScrollClicks(BOOL b);
193 void setHideScrollbarForShortDocs(BOOL b);
194
195 void setWordWrap( BOOL b );
196 void setTabToNextField(BOOL b) { mTabToNextField = b; }
197 void setCommitOnFocusLost(BOOL b) { mCommitOnFocusLost = b; }
198
199 // If takes focus, will take keyboard focus on click.
200 void setTakesFocus(BOOL b) { mTakesFocus = b; }
201
202 // Hack to handle Notecards
203 virtual BOOL importBuffer(const LLString& buffer );
204 virtual BOOL exportBuffer(LLString& buffer );
205
206 void setSourceID(const LLUUID& id) { mSourceID = id; }
207 void setAcceptCallingCardNames(BOOL enable) { mAcceptCallingCardNames = enable; }
208
209 void setHandleEditKeysDirectly( BOOL b ) { mHandleEditKeysDirectly = b; }
210
211 // Callbacks
212 static void onMouseCaptureLost( LLMouseHandler* old_captor );
213 static void setLinkColor(LLColor4 color) { mLinkColor = color; }
214 static void setURLCallbacks( void (*callback1) (const char* url),
215 BOOL (*callback2) (LLString url) )
216 { mURLcallback = callback1; mSecondlifeURLcallback = callback2;}
217
218 void setOnScrollEndCallback(void (*callback)(void*), void* userdata);
219
220 // new methods
221 void setValue(const LLSD& value);
222 LLSD getValue() const;
223
224 const LLString& getText() const;
225
226 // Non-undoable
227 void setText(const LLString &utf8str);
228 void setWText(const LLWString &wtext);
229
230 S32 getMaxLength() const { return mMaxTextLength; }
231
232 // Change cursor
233 void startOfLine();
234 void endOfLine();
235 void endOfDoc();
236
237 // Getters
238 const LLWString& getWText() const;
239 llwchar getWChar(S32 pos);
240 LLWString getWSubString(S32 pos, S32 len);
241
242protected:
243 S32 getLength() const;
244 void getSegmentAndOffset( S32 startpos, S32* segidxp, S32* offsetp );
245
246 void drawBackground();
247 void drawSelectionBackground();
248 void drawCursor();
249 void drawText();
250 void drawClippedSegment(const LLWString &wtext, S32 seg_start, S32 seg_end, F32 x, F32 y, S32 selection_left, S32 selection_right, const LLStyle& color, F32* right_x);
251
252 void updateLineStartList(S32 startpos = 0);
253 void updateScrollFromCursor();
254 void updateTextRect();
255 void updateSegments();
256 void pruneSegments();
257
258 void assignEmbedded(const LLString &s);
259 void truncate();
260
261 static BOOL isPartOfWord(llwchar c);
262
263 void removeCharOrTab();
264 void setCursorAtLocalPos(S32 x, S32 y, BOOL round);
265 S32 getCursorPosFromLocalCoord( S32 local_x, S32 local_y, BOOL round );
266
267 void indentSelectedLines( S32 spaces );
268 S32 indentLine( S32 pos, S32 spaces );
269 void unindentLineBeforeCloseBrace();
270
271 S32 getSegmentIdxAtOffset(S32 offset);
272 LLTextSegment* getSegmentAtLocalPos(S32 x, S32 y);
273 LLTextSegment* getSegmentAtOffset(S32 offset);
274
275 void reportBadKeystroke();
276
277 BOOL handleNavigationKey(const KEY key, const MASK mask);
278 BOOL handleSpecialKey(const KEY key, const MASK mask, BOOL* return_key_hit);
279 BOOL handleSelectionKey(const KEY key, const MASK mask);
280 BOOL handleControlKey(const KEY key, const MASK mask);
281 BOOL handleEditKey(const KEY key, const MASK mask);
282
283 BOOL hasSelection() { return (mSelectionStart !=mSelectionEnd); }
284 BOOL selectionContainsLineBreaks();
285 void startSelection();
286 void endSelection();
287 void deleteSelection(BOOL transient_operation);
288
289 S32 prevWordPos(S32 cursorPos) const;
290 S32 nextWordPos(S32 cursorPos) const;
291
292 S32 getLineCount();
293 S32 getLineStart( S32 line );
294 void getLineAndOffset(S32 pos, S32* linep, S32* offsetp);
295 S32 getPos(S32 line, S32 offset);
296
297 void changePage(S32 delta);
298 void changeLine(S32 delta);
299
300 void autoIndent();
301
302 S32 execute(LLTextCmd* cmd);
303
304 void findEmbeddedItemSegments();
305
306 virtual BOOL handleMouseUpOverSegment(S32 x, S32 y, MASK mask);
307 virtual llwchar pasteEmbeddedItem(llwchar ext_char);
308 virtual void bindEmbeddedChars(const LLFontGL* font);
309 virtual void unbindEmbeddedChars(const LLFontGL* font);
310
311 S32 findHTMLToken(const LLString &line, S32 pos, BOOL reverse);
312 BOOL findHTML(const LLString &line, S32 *begin, S32 *end);
313
314protected:
315 // Undoable operations
316 void addChar(llwchar c); // at mCursorPos
317 S32 addChar(S32 pos, llwchar wc);
318 S32 overwriteChar(S32 pos, llwchar wc);
319 void removeChar();
320 S32 removeChar(S32 pos);
321 S32 insert(const S32 pos, const LLWString &wstr, const BOOL group_with_next_op);
322 S32 remove(const S32 pos, const S32 length, const BOOL group_with_next_op);
323 S32 append(const LLWString &wstr, const BOOL group_with_next_op);
324
325 // direct operations
326 S32 insertStringNoUndo(S32 pos, const LLWString &utf8str); // returns num of chars actually inserted
327 S32 removeStringNoUndo(S32 pos, S32 length);
328 S32 overwriteCharNoUndo(S32 pos, llwchar wc);
329
330public:
331 LLKeywords mKeywords;
332 static LLColor4 mLinkColor;
333 static void (*mURLcallback) (const char* url);
334 static BOOL (*mSecondlifeURLcallback) (LLString url);
335protected:
336 LLWString mWText;
337 mutable LLString mUTF8Text;
338 mutable BOOL mTextIsUpToDate;
339
340 S32 mMaxTextLength; // Maximum length mText is allowed to be
341
342 const LLFontGL* mGLFont;
343
344 LLScrollbar* mScrollbar;
345 LLViewBorder* mBorder;
346
347 BOOL mBaseDocIsPristine;
348 LLTextCmd* mPristineCmd;
349
350 LLTextCmd* mLastCmd;
351
352 typedef std::deque<LLTextCmd*> undo_stack_t;
353 undo_stack_t mUndoStack;
354
355 S32 mCursorPos; // I-beam is just after the mCursorPos-th character.
356 LLRect mTextRect; // The rect in which text is drawn. Excludes borders.
357 // List of offsets and segment index of the start of each line. Always has at least one node (0).
358 struct line_info
359 {
360 line_info(S32 segment, S32 offset) : mSegment(segment), mOffset(offset) {}
361 S32 mSegment;
362 S32 mOffset;
363 };
364 struct line_info_compare
365 {
366 bool operator()(const line_info& a, const line_info& b) const
367 {
368 if (a.mSegment < b.mSegment)
369 return true;
370 else if (a.mSegment > b.mSegment)
371 return false;
372 else
373 return a.mOffset < b.mOffset;
374 }
375 };
376 typedef std::vector<line_info> line_list_t;
377 line_list_t mLineStartList;
378
379 // Are we in the middle of a drag-select? To figure out if there is a current
380 // selection, call hasSelection().
381 BOOL mIsSelecting;
382
383 S32 mSelectionStart;
384 S32 mSelectionEnd;
385
386 void (*mOnScrollEndCallback)(void*);
387 void *mOnScrollEndData;
388
389 typedef std::vector<LLTextSegment *> segment_list_t;
390 segment_list_t mSegments;
391 LLTextSegment* mHoverSegment;
392 LLFrameTimer mKeystrokeTimer;
393
394 LLColor4 mCursorColor;
395
396 LLColor4 mFgColor;
397 LLColor4 mReadOnlyFgColor;
398 LLColor4 mWriteableBgColor;
399 LLColor4 mReadOnlyBgColor;
400 LLColor4 mFocusBgColor;
401
402 BOOL mReadOnly;
403 BOOL mWordWrap;
404
405 BOOL mTabToNextField; // if true, tab moves focus to next field, else inserts spaces
406 BOOL mCommitOnFocusLost;
407 BOOL mTakesFocus;
408 BOOL mHideScrollbarForShortDocs;
409 BOOL mTakesNonScrollClicks;
410
411 BOOL mAllowEmbeddedItems;
412
413 BOOL mAcceptCallingCardNames;
414
415 LLUUID mSourceID;
416
417 BOOL mHandleEditKeysDirectly; // If true, the standard edit keys (Ctrl-X, Delete, etc,) are handled here instead of routed by the menu system
418
419 // Use these to determine if a click on an embedded item is a drag
420 // or not.
421 S32 mMouseDownX;
422 S32 mMouseDownY;
423
424 S32 mLastSelectionX;
425 S32 mLastSelectionY;
426
427 BOOL mParseHTML;
428 LLString mHTML;
429};
430
431class LLTextSegment
432{
433public:
434 // for creating a compare value
435 LLTextSegment(S32 start);
436 LLTextSegment( const LLStyle& style, S32 start, S32 end );
437 LLTextSegment( const LLColor4& color, S32 start, S32 end, BOOL is_visible);
438 LLTextSegment( const LLColor4& color, S32 start, S32 end );
439 LLTextSegment( const LLColor3& color, S32 start, S32 end );
440
441 S32 getStart() { return mStart; }
442 S32 getEnd() { return mEnd; }
443 void setEnd( S32 end ) { mEnd = end; }
444 const LLColor4& getColor() { return mStyle.getColor(); }
445 void setColor(const LLColor4 &color) { mStyle.setColor(color); }
446 const LLStyle& getStyle() { return mStyle; }
447 void setStyle(const LLStyle &style) { mStyle = style; }
448 void setIsDefault(BOOL b) { mIsDefault = b; }
449 BOOL getIsDefault() { return mIsDefault; }
450
451 void setToken( LLKeywordToken* token ) { mToken = token; }
452 LLKeywordToken* getToken() { return mToken; }
453 BOOL getToolTip( LLString& msg );
454
455 void dump();
456
457 struct compare
458 {
459 bool operator()(const LLTextSegment* a, const LLTextSegment* b) const
460 {
461 return a->mStart < b->mStart;
462 }
463 };
464
465private:
466 LLStyle mStyle;
467 S32 mStart;
468 S32 mEnd;
469 LLKeywordToken* mToken;
470 BOOL mIsDefault;
471};
472
473class LLTextCmd
474{
475public:
476 LLTextCmd( S32 pos, BOOL group_with_next )
477 : mPos(pos),
478 mGroupWithNext(group_with_next)
479 {
480 }
481 virtual ~LLTextCmd() {}
482 virtual BOOL execute(LLTextEditor* editor, S32* delta) = 0;
483 virtual S32 undo(LLTextEditor* editor) = 0;
484 virtual S32 redo(LLTextEditor* editor) = 0;
485 virtual BOOL canExtend(S32 pos);
486 virtual void blockExtensions();
487 virtual BOOL extendAndExecute( LLTextEditor* editor, S32 pos, llwchar c, S32* delta );
488 virtual BOOL hasExtCharValue( llwchar value );
489
490 // Define these here so they can access LLTextEditor through the friend relationship
491 S32 insert(LLTextEditor* editor, S32 pos, const LLWString &utf8str);
492 S32 remove(LLTextEditor* editor, S32 pos, S32 length);
493 S32 overwrite(LLTextEditor* editor, S32 pos, llwchar wc);
494
495 BOOL groupWithNext() { return mGroupWithNext; }
496
497protected:
498 S32 mPos;
499 BOOL mGroupWithNext;
500};
501
502
503#endif // LL_TEXTEDITOR_