diff options
Diffstat (limited to 'linden/indra/llui/lltexteditor.cpp')
-rw-r--r-- | linden/indra/llui/lltexteditor.cpp | 107 |
1 files changed, 95 insertions, 12 deletions
diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 3813e76..8fa253a 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp | |||
@@ -1203,6 +1203,18 @@ BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) | |||
1203 | } | 1203 | } |
1204 | 1204 | ||
1205 | 1205 | ||
1206 | BOOL LLTextEditor::handleMiddleMouseDown(S32 x, S32 y, MASK mask) | ||
1207 | { | ||
1208 | setFocus( TRUE ); | ||
1209 | if( canPastePrimary() ) | ||
1210 | { | ||
1211 | setCursorAtLocalPos( x, y, TRUE ); | ||
1212 | pastePrimary(); | ||
1213 | } | ||
1214 | return TRUE; | ||
1215 | } | ||
1216 | |||
1217 | |||
1206 | BOOL LLTextEditor::handleHover(S32 x, S32 y, MASK mask) | 1218 | BOOL LLTextEditor::handleHover(S32 x, S32 y, MASK mask) |
1207 | { | 1219 | { |
1208 | BOOL handled = FALSE; | 1220 | BOOL handled = FALSE; |
@@ -1323,6 +1335,9 @@ BOOL LLTextEditor::handleMouseUp(S32 x, S32 y, MASK mask) | |||
1323 | 1335 | ||
1324 | setCursorAtLocalPos( x, y, TRUE ); | 1336 | setCursorAtLocalPos( x, y, TRUE ); |
1325 | endSelection(); | 1337 | endSelection(); |
1338 | |||
1339 | // take selection to primary clipboard | ||
1340 | updatePrimary(); | ||
1326 | } | 1341 | } |
1327 | 1342 | ||
1328 | if( !hasSelection() ) | 1343 | if( !hasSelection() ) |
@@ -1330,6 +1345,9 @@ BOOL LLTextEditor::handleMouseUp(S32 x, S32 y, MASK mask) | |||
1330 | handleMouseUpOverSegment( x, y, mask ); | 1345 | handleMouseUpOverSegment( x, y, mask ); |
1331 | } | 1346 | } |
1332 | 1347 | ||
1348 | // take selection to 'primary' clipboard | ||
1349 | updatePrimary(); | ||
1350 | |||
1333 | handled = TRUE; | 1351 | handled = TRUE; |
1334 | } | 1352 | } |
1335 | 1353 | ||
@@ -1392,8 +1410,12 @@ BOOL LLTextEditor::handleDoubleClick(S32 x, S32 y, MASK mask) | |||
1392 | // delay cursor flashing | 1410 | // delay cursor flashing |
1393 | resetKeystrokeTimer(); | 1411 | resetKeystrokeTimer(); |
1394 | 1412 | ||
1413 | // take selection to 'primary' clipboard | ||
1414 | updatePrimary(); | ||
1415 | |||
1395 | handled = TRUE; | 1416 | handled = TRUE; |
1396 | } | 1417 | } |
1418 | |||
1397 | return handled; | 1419 | return handled; |
1398 | } | 1420 | } |
1399 | 1421 | ||
@@ -1689,6 +1711,12 @@ BOOL LLTextEditor::handleSelectionKey(const KEY key, const MASK mask) | |||
1689 | } | 1711 | } |
1690 | } | 1712 | } |
1691 | 1713 | ||
1714 | if( handled ) | ||
1715 | { | ||
1716 | // take selection to 'primary' clipboard | ||
1717 | updatePrimary(); | ||
1718 | } | ||
1719 | |||
1692 | return handled; | 1720 | return handled; |
1693 | } | 1721 | } |
1694 | 1722 | ||
@@ -1868,22 +1896,46 @@ BOOL LLTextEditor::canPaste() const | |||
1868 | return !mReadOnly && gClipboard.canPasteString(); | 1896 | return !mReadOnly && gClipboard.canPasteString(); |
1869 | } | 1897 | } |
1870 | 1898 | ||
1871 | |||
1872 | // paste from clipboard | 1899 | // paste from clipboard |
1873 | void LLTextEditor::paste() | 1900 | void LLTextEditor::paste() |
1874 | { | 1901 | { |
1875 | if (!canPaste()) | 1902 | bool is_primary = false; |
1903 | pasteHelper(is_primary); | ||
1904 | } | ||
1905 | |||
1906 | // paste from primary | ||
1907 | void LLTextEditor::pastePrimary() | ||
1908 | { | ||
1909 | bool is_primary = true; | ||
1910 | pasteHelper(is_primary); | ||
1911 | } | ||
1912 | |||
1913 | // paste from primary (itsprimary==true) or clipboard (itsprimary==false) | ||
1914 | void LLTextEditor::pasteHelper(bool is_primary) | ||
1915 | { | ||
1916 | bool can_paste_it; | ||
1917 | if (is_primary) | ||
1918 | can_paste_it = canPastePrimary(); | ||
1919 | else | ||
1920 | can_paste_it = canPaste(); | ||
1921 | |||
1922 | if (!can_paste_it) | ||
1876 | { | 1923 | { |
1877 | return; | 1924 | return; |
1878 | } | 1925 | } |
1879 | LLUUID source_id; | 1926 | LLUUID source_id; |
1880 | LLWString paste = gClipboard.getPasteWString(&source_id); | 1927 | LLWString paste; |
1928 | if (is_primary) | ||
1929 | paste = gClipboard.getPastePrimaryWString(&source_id); | ||
1930 | else | ||
1931 | paste = gClipboard.getPasteWString(&source_id); | ||
1932 | |||
1881 | if (paste.empty()) | 1933 | if (paste.empty()) |
1882 | { | 1934 | { |
1883 | return; | 1935 | return; |
1884 | } | 1936 | } |
1885 | // Delete any selected characters (the paste replaces them) | 1937 | // Delete any selected characters (the paste replaces them) |
1886 | if( hasSelection() ) | 1938 | if( (!is_primary) && hasSelection() ) |
1887 | { | 1939 | { |
1888 | deleteSelection(TRUE); | 1940 | deleteSelection(TRUE); |
1889 | } | 1941 | } |
@@ -1917,6 +1969,32 @@ void LLTextEditor::paste() | |||
1917 | } | 1969 | } |
1918 | 1970 | ||
1919 | 1971 | ||
1972 | |||
1973 | // copy selection to primary | ||
1974 | void LLTextEditor::copyPrimary() | ||
1975 | { | ||
1976 | if( !canCopy() ) | ||
1977 | { | ||
1978 | return; | ||
1979 | } | ||
1980 | S32 left_pos = llmin( mSelectionStart, mSelectionEnd ); | ||
1981 | S32 length = abs( mSelectionStart - mSelectionEnd ); | ||
1982 | gClipboard.copyFromPrimarySubstring(mWText, left_pos, length, mSourceID); | ||
1983 | } | ||
1984 | |||
1985 | BOOL LLTextEditor::canPastePrimary() const | ||
1986 | { | ||
1987 | return !mReadOnly && gClipboard.canPastePrimaryString(); | ||
1988 | } | ||
1989 | |||
1990 | void LLTextEditor::updatePrimary() | ||
1991 | { | ||
1992 | if (canCopy()) | ||
1993 | { | ||
1994 | copyPrimary(); | ||
1995 | } | ||
1996 | } | ||
1997 | |||
1920 | BOOL LLTextEditor::handleControlKey(const KEY key, const MASK mask) | 1998 | BOOL LLTextEditor::handleControlKey(const KEY key, const MASK mask) |
1921 | { | 1999 | { |
1922 | BOOL handled = FALSE; | 2000 | BOOL handled = FALSE; |
@@ -1992,6 +2070,11 @@ BOOL LLTextEditor::handleControlKey(const KEY key, const MASK mask) | |||
1992 | } | 2070 | } |
1993 | } | 2071 | } |
1994 | 2072 | ||
2073 | if (handled) | ||
2074 | { | ||
2075 | updatePrimary(); | ||
2076 | } | ||
2077 | |||
1995 | return handled; | 2078 | return handled; |
1996 | } | 2079 | } |
1997 | 2080 | ||
@@ -3522,13 +3605,13 @@ void LLTextEditor::appendColoredText(const std::string &new_text, | |||
3522 | style->setVisible(true); | 3605 | style->setVisible(true); |
3523 | style->setColor(color); | 3606 | style->setColor(color); |
3524 | style->setFontName(font_name); | 3607 | style->setFontName(font_name); |
3525 | appendStyledText(new_text, allow_undo, prepend_newline, &style); | 3608 | appendStyledText(new_text, allow_undo, prepend_newline, style); |
3526 | } | 3609 | } |
3527 | 3610 | ||
3528 | void LLTextEditor::appendStyledText(const std::string &new_text, | 3611 | void LLTextEditor::appendStyledText(const std::string &new_text, |
3529 | bool allow_undo, | 3612 | bool allow_undo, |
3530 | bool prepend_newline, | 3613 | bool prepend_newline, |
3531 | const LLStyleSP *stylep) | 3614 | const LLStyleSP stylep) |
3532 | { | 3615 | { |
3533 | if(mParseHTML) | 3616 | if(mParseHTML) |
3534 | { | 3617 | { |
@@ -3543,14 +3626,14 @@ void LLTextEditor::appendStyledText(const std::string &new_text, | |||
3543 | html->setColor(mLinkColor); | 3626 | html->setColor(mLinkColor); |
3544 | if (stylep) | 3627 | if (stylep) |
3545 | { | 3628 | { |
3546 | html->setFontName((*stylep)->getFontString()); | 3629 | html->setFontName(stylep->getFontString()); |
3547 | } | 3630 | } |
3548 | html->mUnderline = TRUE; | 3631 | html->mUnderline = TRUE; |
3549 | 3632 | ||
3550 | if (start > 0) appendText(text.substr(0,start),allow_undo, prepend_newline, stylep); | 3633 | if (start > 0) appendText(text.substr(0,start),allow_undo, prepend_newline, stylep); |
3551 | html->setLinkHREF(text.substr(start,end-start)); | 3634 | html->setLinkHREF(text.substr(start,end-start)); |
3552 | appendText(text.substr(start, end-start),allow_undo, prepend_newline, &html); | 3635 | appendText(text.substr(start, end-start),allow_undo, prepend_newline, html); |
3553 | if (end < (S32)text.length()) | 3636 | if (end < (S32)text.length()) |
3554 | { | 3637 | { |
3555 | text = text.substr(end,text.length() - end); | 3638 | text = text.substr(end,text.length() - end); |
3556 | end=0; | 3639 | end=0; |
@@ -3570,7 +3653,7 @@ void LLTextEditor::appendStyledText(const std::string &new_text, | |||
3570 | 3653 | ||
3571 | // Appends new text to end of document | 3654 | // Appends new text to end of document |
3572 | void LLTextEditor::appendText(const std::string &new_text, bool allow_undo, bool prepend_newline, | 3655 | void LLTextEditor::appendText(const std::string &new_text, bool allow_undo, bool prepend_newline, |
3573 | const LLStyleSP *stylep) | 3656 | const LLStyleSP stylep) |
3574 | { | 3657 | { |
3575 | // Save old state | 3658 | // Save old state |
3576 | BOOL was_scrolled_to_bottom = (mScrollbar->getDocPos() == mScrollbar->getDocPosMax()); | 3659 | BOOL was_scrolled_to_bottom = (mScrollbar->getDocPos() == mScrollbar->getDocPosMax()); |
@@ -3602,7 +3685,7 @@ void LLTextEditor::appendText(const std::string &new_text, bool allow_undo, bool | |||
3602 | { | 3685 | { |
3603 | S32 segment_start = old_length; | 3686 | S32 segment_start = old_length; |
3604 | S32 segment_end = getLength(); | 3687 | S32 segment_end = getLength(); |
3605 | LLTextSegment* segment = new LLTextSegment(*stylep, segment_start, segment_end ); | 3688 | LLTextSegment* segment = new LLTextSegment(stylep, segment_start, segment_end ); |
3606 | mSegments.push_back(segment); | 3689 | mSegments.push_back(segment); |
3607 | } | 3690 | } |
3608 | 3691 | ||