diff options
Diffstat (limited to 'indra/llui/lltexteditor.h')
-rw-r--r-- | indra/llui/lltexteditor.h | 293 |
1 files changed, 22 insertions, 271 deletions
diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index a04261c4be..0e5707a3a6 100644 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -37,7 +37,6 @@ #include "llrect.h" #include "llkeywords.h" -#include "lluictrl.h" #include "llframetimer.h" #include "lldarray.h" #include "llstyle.h" @@ -52,66 +51,27 @@ class LLFontGL; class LLScrollbar; class LLKeywordToken; -class LLTextCmd; +class TextCmd; class LLUICtrlFactory; class LLScrollContainer; -class LLInlineViewSegment : public LLTextSegment -{ -public: - LLInlineViewSegment(LLView* widget, S32 start, S32 end); - ~LLInlineViewSegment(); - /*virtual*/ S32 getWidth(S32 first_char, S32 num_chars) const; - /*virtual*/ S32 getNumChars(S32 num_pixels, S32 segment_offset, S32 line_offset, S32 max_chars) const; - /*virtual*/ void updateLayout(const class LLTextBase& editor); - /*virtual*/ F32 draw(S32 start, S32 end, S32 selection_start, S32 selection_end, const LLRect& draw_rect); - /*virtuaL*/ S32 getMaxHeight() const; - /*virtual*/ bool canEdit() const { return false; } - /*virtual*/ void unlinkFromDocument(class LLTextBase* editor); - /*virtual*/ void linkToDocument(class LLTextBase* editor); - -private: - LLView* mView; -}; - class LLTextEditor : public LLTextBase, - public LLUICtrl, - private LLEditMenuHandler, protected LLPreeditor { public: - struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> + struct Params : public LLInitParam::Block<Params, LLTextBase::Params> { Optional<std::string> default_text; - Optional<S32> max_text_length; - Optional<bool> read_only, - embedded_items, - word_wrap, + Optional<bool> embedded_items, ignore_tab, - hide_border, - track_bottom, handle_edit_keys_directly, show_line_numbers, commit_on_focus_lost; //colors - Optional<LLUIColor> cursor_color, - default_color, - text_color, - text_readonly_color, - bg_readonly_color, - bg_writeable_color, - bg_focus_color, - link_color; - - Optional<LLViewBorder::Params> border; - - Ignored type, - length, - is_unicode, - hide_scrollbar; + Optional<LLUIColor> default_color; Params(); }; @@ -128,15 +88,6 @@ public: static const llwchar LAST_EMBEDDED_CHAR = 0x10ffff; static const S32 MAX_EMBEDDED_ITEMS = LAST_EMBEDDED_CHAR - FIRST_EMBEDDED_CHAR + 1; - - struct compare_segment_end - { - bool operator()(const LLTextSegmentPtr& a, const LLTextSegmentPtr& b) const - { - return a->getEnd() < b->getEnd(); - } - }; - virtual ~LLTextEditor(); typedef boost::signals2::signal<void (LLTextEditor* caller)> keystroke_signal_t; @@ -155,14 +106,9 @@ public: virtual BOOL handleKeyHere(KEY key, MASK mask ); virtual BOOL handleUnicodeCharHere(llwchar uni_char); - virtual BOOL handleToolTip(S32 x, S32 y, std::string& msg, LLRect& sticky_rect); - virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, - EDragAndDropType cargo_type, void *cargo_data, - EAcceptance *accept, std::string& tooltip_msg); virtual void onMouseCaptureLost(); // view overrides - virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); virtual void draw(); virtual void onFocusReceived(); virtual void onFocusLost(); @@ -170,11 +116,8 @@ public: virtual void setEnabled(BOOL enabled); // uictrl overrides - virtual void clear(); virtual void setFocus( BOOL b ); - virtual BOOL acceptsTextInput() const; virtual BOOL isDirty() const; - virtual void setValue(const LLSD& value); // LLEditMenuHandler interface virtual void undo(); @@ -201,12 +144,9 @@ public: virtual void deselect(); virtual BOOL canDeselect() const; - virtual void onValueChange(S32 start, S32 end); - void selectNext(const std::string& search_text_in, BOOL case_insensitive, BOOL wrap = TRUE); BOOL replaceText(const std::string& search_text, const std::string& replace_text, BOOL case_insensitive, BOOL wrap = TRUE); void replaceTextAll(const std::string& search_text, const std::string& replace_text, BOOL case_insensitive); - BOOL hasSelection() const { return (mSelectionStart !=mSelectionEnd); } void replaceUrlLabel(const std::string &url, const std::string &label); // Undo/redo stack @@ -216,9 +156,6 @@ public: virtual void makePristine(); BOOL isPristine() const; BOOL allowsEmbeddedItems() const { return mAllowEmbeddedItems; } - S32 getLength() const { return getWText().length(); } - void setReadOnly(bool read_only) { mReadOnly = read_only; } - bool getReadOnly() { return mReadOnly; } // // Text manipulation @@ -226,25 +163,10 @@ public: // inserts text at cursor void insertText(const std::string &text); - // appends text at end - void appendText(const std::string &wtext, bool allow_undo, bool prepend_newline, - const LLStyle::Params& style = LLStyle::Params()); - - void appendColoredText(const std::string &wtext, bool allow_undo, - bool prepend_newline, - const LLColor4 &color, - const std::string& font_name = LLStringUtil::null); - // if styled text starts a line, you need to prepend a newline. - void appendStyledText(const std::string &new_text, bool allow_undo, - bool prepend_newline, - const LLStyle::Params& style); - void appendHighlightedText(const std::string &new_text, bool allow_undo, - bool prepend_newline, S32 highlight_part, - const LLStyle::Params& style); + void appendWidget(LLView* widget, const std::string &widget_text, bool allow_undo, bool prepend_newline); // Non-undoable void setText(const LLStringExplicit &utf8str); - void setWText(const LLWString &wtext); // Removes text from the end of document @@ -253,14 +175,9 @@ public: BOOL tryToRevertToPristineState(); - bool setCursor(S32 row, S32 column); - bool setCursorPos(S32 offset, bool keep_cursor_offset = false); void setCursorAndScrollToEnd(); - void getLineAndColumnForPosition( S32 position, S32* line, S32* col, BOOL include_wordwrap ); void getCurrentLineAndColumn( S32* line, S32* col, BOOL include_wordwrap ); - S32 getLineForPosition(S32 position); - S32 getCurrentLine(); void loadKeywords(const std::string& filename, const std::vector<std::string>& funcs, @@ -277,55 +194,17 @@ public: virtual BOOL importBuffer(const char* buffer, S32 length ); virtual BOOL exportBuffer(std::string& buffer ); - const class DocumentPanel* getDocumentPanel() const { return mDocumentPanel; } - const LLUUID& getSourceID() const { return mSourceID; } - // Callbacks - std::string getText() const; - - // Callback for when a Url has been resolved by the server - void onUrlLabelUpdated(const std::string &url, const std::string &label); - - // Getters - LLWString getWText() const; - llwchar getWChar(S32 pos) const { return getWText()[pos]; } - LLWString getWSubString(S32 pos, S32 len) const { return getWText().substr(pos, len); } - - typedef std::vector<LLTextSegmentPtr> segment_vec_t; - const LLTextSegmentPtr getPreviousSegment() const; void getSelectedSegments(segment_vec_t& segments) const; - void getSegmentsInRange(segment_vec_t& segments, S32 start, S32 end, bool include_partial) const; - LLRect getLocalRectFromDocIndex(S32 index) const; - - void addDocumentChild(LLView* view); - void removeDocumentChild(LLView* view); - protected: - // Change cursor - void startOfLine(); - void endOfLine(); - void startOfDoc(); - void endOfDoc(); - void drawPreeditMarker(); - void needsReflow() { mReflowNeeded = TRUE; } - void needsScroll() { mScrollNeeded = TRUE; } - void updateCursorXPos(); - - void updateScrollFromCursor(); - void updateTextRect(); - const LLRect& getTextRect() const { return mTextRect; } - void assignEmbedded(const std::string &s); - BOOL truncate(); // Returns true if truncation occurs void removeCharOrTab(); - void setCursorAtLocalPos(S32 x, S32 y, bool round, bool keep_cursor_offset = false); - /*virtual*/ S32 getDocIndexFromLocalCoord( S32 local_x, S32 local_y, BOOL round ) const; void indentSelectedLines( S32 spaces ); S32 indentLine( S32 pos, S32 spaces ); @@ -340,68 +219,21 @@ protected: BOOL handleEditKey(const KEY key, const MASK mask); BOOL selectionContainsLineBreaks(); - void startSelection(); - void endSelection(); void deleteSelection(BOOL transient_operation); S32 prevWordPos(S32 cursorPos) const; S32 nextWordPos(S32 cursorPos) const; - S32 getLineCount() const { return mLineInfoList.size(); } - S32 getLineStart( S32 line ) const; - S32 getLineHeight( S32 line ) const; - void getLineAndOffset(S32 pos, S32* linep, S32* offsetp, bool include_wordwrap = true) const; - S32 getPos(S32 line, S32 offset); - - void changePage(S32 delta); - void changeLine(S32 delta); - void autoIndent(); void findEmbeddedItemSegments(S32 start, S32 end); - void insertSegment(LLTextSegmentPtr segment_to_insert); - + void getSegmentsInRange(segment_vec_t& segments, S32 start, S32 end, bool include_partial) const; + virtual llwchar pasteEmbeddedItem(llwchar ext_char) { return ext_char; } - // Abstract inner base class representing an undoable editor command. - // Concrete sub-classes can be defined for operations such as insert, remove, etc. - // Used as arguments to the execute() method below. - class LLTextCmd - { - public: - LLTextCmd( S32 pos, BOOL group_with_next, LLTextSegmentPtr segment = LLTextSegmentPtr() ) - : mPos(pos), - mGroupWithNext(group_with_next) - { - if (segment.notNull()) - { - mSegments.push_back(segment); - } - } - virtual ~LLTextCmd() {} - virtual BOOL execute(LLTextEditor* editor, S32* delta) = 0; - virtual S32 undo(LLTextEditor* editor) = 0; - virtual S32 redo(LLTextEditor* editor) = 0; - virtual BOOL canExtend(S32 pos) const { return FALSE; } - virtual void blockExtensions() {} - virtual BOOL extendAndExecute( LLTextEditor* editor, S32 pos, llwchar c, S32* delta ) { llassert(0); return 0; } - virtual BOOL hasExtCharValue( llwchar value ) const { return FALSE; } - - // Defined here so they can access protected LLTextEditor editing methods - S32 insert(LLTextEditor* editor, S32 pos, const LLWString &wstr) { return editor->insertStringNoUndo( pos, wstr, &mSegments ); } - S32 remove(LLTextEditor* editor, S32 pos, S32 length) { return editor->removeStringNoUndo( pos, length ); } - S32 overwrite(LLTextEditor* editor, S32 pos, llwchar wc) { return editor->overwriteCharNoUndo(pos, wc); } - - S32 getPosition() const { return mPos; } - BOOL groupWithNext() const { return mGroupWithNext; } - - protected: - const S32 mPos; - BOOL mGroupWithNext; - segment_vec_t mSegments; - }; + // Here's the method that takes and applies text commands. - S32 execute(LLTextCmd* cmd); + S32 execute(TextCmd* cmd); // Undoable operations void addChar(llwchar c); // at mCursorPos @@ -411,15 +243,7 @@ protected: S32 removeChar(S32 pos); S32 insert(S32 pos, const LLWString &wstr, bool group_with_next_op, LLTextSegmentPtr segment); S32 remove(S32 pos, S32 length, bool group_with_next_op); - S32 append(const LLWString &wstr, bool group_with_next_op, LLTextSegmentPtr segment); - // Direct operations - S32 insertStringNoUndo(S32 pos, const LLWString &wstr, segment_vec_t* segments = NULL); // returns num of chars actually inserted - S32 removeStringNoUndo(S32 pos, S32 length); - S32 overwriteCharNoUndo(S32 pos, llwchar wc); - - void resetKeystrokeTimer() { mKeystrokeTimer.reset(); } - void updateAllowingLanguageInput(); BOOL hasPreeditString() const; @@ -432,6 +256,7 @@ protected: virtual void getSelectionRange(S32 *position, S32 *length) const; virtual BOOL getPreeditLocation(S32 query_offset, LLCoordGL *coord, LLRect *bounds, LLRect *control) const; virtual S32 getPreeditFontSize() const; + virtual LLWString getPreeditString() const { return getWText(); } // // Protected data // @@ -439,74 +264,31 @@ protected: // as possible behind protected accessor methods. // - // I-beam is just after the mCursorPos-th character. - S32 mCursorPos; - // Use these to determine if a click on an embedded item is a drag or not. S32 mMouseDownX; S32 mMouseDownY; - // Are we in the middle of a drag-select? To figure out if there is a current - // selection, call hasSelection(). - BOOL mIsSelecting; - S32 mSelectionStart; - S32 mSelectionEnd; - S32 mLastSelectionX; - S32 mLastSelectionY; - - BOOL mParseHighlights; - - // Scrollbar data - class DocumentPanel* mDocumentPanel; - LLScrollContainer* mScroller; - - void *mOnScrollEndData; - LLWString mPreeditWString; LLWString mPreeditOverwrittenWString; std::vector<S32> mPreeditPositions; std::vector<BOOL> mPreeditStandouts; - S32 mScrollIndex; // index into document that controls default scroll position - protected: - LLUIColor mCursorColor; - LLUIColor mFgColor; - LLUIColor mDefaultColor; - LLUIColor mReadOnlyFgColor; - LLUIColor mWriteableBgColor; - LLUIColor mReadOnlyBgColor; - LLUIColor mFocusBgColor; - LLUIColor mLinkColor; + LLUIColor mDefaultColor; - BOOL mReadOnly; - BOOL mShowLineNumbers; + BOOL mShowLineNumbers; - void updateSegments(); - void updateLinkSegments(); + /*virtual*/ void updateSegments(); + void updateLinkSegments(); private: - // // Methods // void pasteHelper(bool is_primary); - virtual LLTextViewModel* getViewModel() const; - void reflow(S32 startpos = 0); - - void createDefaultSegment(); - LLStyleSP getDefaultStyle(); - S32 getEditableIndex(S32 index, bool increasing_direction); - - void drawBackground(); - void drawSelectionBackground(); - void drawCursor(); - void drawText(); void drawLineNumbers(); - S32 getFirstVisibleLine() const; - void onKeyStroke(); // @@ -514,56 +296,25 @@ private: // LLKeywords mKeywords; - // Concrete LLTextCmd sub-classes used by the LLTextEditor base class - class LLTextCmdInsert; - class LLTextCmdAddChar; - class LLTextCmdOverwriteChar; - class LLTextCmdRemove; - - S32 mMaxTextByteLength; // Maximum length mText is allowed to be in bytes + // Concrete TextCmd sub-classes used by the LLTextEditor base class + class TextCmdInsert; + class TextCmdAddChar; + class TextCmdOverwriteChar; + class TextCmdRemove; class LLViewBorder* mBorder; BOOL mBaseDocIsPristine; - LLTextCmd* mPristineCmd; + TextCmd* mPristineCmd; - LLTextCmd* mLastCmd; + TextCmd* mLastCmd; - typedef std::deque<LLTextCmd*> undo_stack_t; + typedef std::deque<TextCmd*> undo_stack_t; undo_stack_t mUndoStack; - S32 mDesiredXPixel; // X pixel position where the user wants the cursor to be - LLRect mTextRect; // The rect in which text is drawn. Excludes borders. - // List of offsets and segment index of the start of each line. Always has at least one node (0). - struct line_info - { - line_info(S32 index_start, S32 index_end, S32 top, S32 bottom, S32 line_num) - : mDocIndexStart(index_start), - mDocIndexEnd(index_end), - mTop(top), - mBottom(bottom), - mLineNum(line_num) - {} - S32 mDocIndexStart; - S32 mDocIndexEnd; - S32 mTop; - S32 mBottom; - S32 mLineNum; // actual line count (ignoring soft newlines due to word wrap) - }; - struct compare_bottom; - struct compare_top; - struct line_end_compare; - typedef std::vector<line_info> line_list_t; - line_list_t mLineInfoList; - BOOL mReflowNeeded; - BOOL mScrollNeeded; - - LLFrameTimer mKeystrokeTimer; - BOOL mTabsToNextField; // if true, tab moves focus to next field, else inserts spaces BOOL mCommitOnFocusLost; BOOL mTakesFocus; - BOOL mTrackBottom; // if true, keeps scroll position at bottom during resize BOOL mAllowEmbeddedItems; |