summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llscrollcontainer.cpp2
-rw-r--r--indra/llui/lltextbase.cpp157
-rw-r--r--indra/llui/lltextbase.h2
-rw-r--r--indra/llui/lltexteditor.cpp37
-rw-r--r--indra/llui/lltexteditor.h4
5 files changed, 120 insertions, 82 deletions
diff --git a/indra/llui/llscrollcontainer.cpp b/indra/llui/llscrollcontainer.cpp
index d8606c6889..5e17372fe9 100644
--- a/indra/llui/llscrollcontainer.cpp
+++ b/indra/llui/llscrollcontainer.cpp
@@ -432,7 +432,7 @@ void LLScrollContainer::draw()
LLLocalClipRect clip(LLRect(mInnerRect.mLeft,
mInnerRect.mBottom + (show_h_scrollbar ? scrollbar_size : 0) + visible_height,
- visible_width,
+ mInnerRect.mRight - (show_v_scrollbar ? scrollbar_size: 0),
mInnerRect.mBottom + (show_h_scrollbar ? scrollbar_size : 0)
));
drawChild(mScrolledView);
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index 22cce755b0..0add3fb500 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -232,7 +232,7 @@ LLTextBase::LLTextBase(const LLTextBase::Params &p)
createDefaultSegment();
- updateTextRect();
+ updateRects();
}
LLTextBase::~LLTextBase()
@@ -538,10 +538,6 @@ void LLTextBase::drawText()
next_start = getLineStart(cur_line + 1);
line_end = next_start;
}
- if ( text[line_end-1] == '\n' )
- {
- --line_end;
- }
LLRect text_rect(line.mRect.mLeft + mTextRect.mLeft - scrolled_view_rect.mLeft,
line.mRect.mTop - scrolled_view_rect.mBottom + mTextRect.mBottom,
@@ -944,7 +940,7 @@ void LLTextBase::reshape(S32 width, S32 height, BOOL called_from_parent)
// do this first after reshape, because other things depend on
// up-to-date mTextRect
- updateTextRect();
+ updateRects();
needsReflow();
}
@@ -957,10 +953,20 @@ void LLTextBase::draw()
// then update scroll position, as cursor may have moved
updateScrollFromCursor();
+ LLRect doc_rect;
+ if (mScroller)
+ {
+ mScroller->localRectToOtherView(mScroller->getContentWindowRect(), &doc_rect, this);
+ }
+ else
+ {
+ doc_rect = getLocalRect();
+ }
+
if (mBGVisible)
{
// clip background rect against extents, if we support scrolling
- LLLocalClipRect clip(getLocalRect(), mScroller != NULL);
+ LLLocalClipRect clip(doc_rect, mScroller != NULL);
LLColor4 bg_color = mReadOnly
? mReadOnlyBgColor.get()
@@ -975,7 +981,7 @@ void LLTextBase::draw()
{
// only clip if we support scrolling (mScroller != NULL)
- LLLocalClipRect clip(mTextRect, mScroller != NULL);
+ LLLocalClipRect clip(doc_rect, mScroller != NULL);
drawSelectionBackground();
drawText();
drawCursor();
@@ -1154,60 +1160,8 @@ void LLTextBase::reflow(S32 start_index)
}
}
- if (mLineInfoList.empty())
- {
- mContentsRect = LLRect(0, mVPad, mHPad, 0);
- }
- else
- {
-
- mContentsRect = mLineInfoList.begin()->mRect;
- for (line_list_t::const_iterator line_iter = ++mLineInfoList.begin();
- line_iter != mLineInfoList.end();
- ++line_iter)
- {
- mContentsRect.unionWith(line_iter->mRect);
- }
-
- mContentsRect.mRight += mHPad;
- mContentsRect.mTop += mVPad;
- // get around rounding errors when clipping text against rectangle
- mContentsRect.stretch(1);
- }
-
- // change mDocumentView size to accomodate reflowed text
- LLRect document_rect;
- if (mScroller)
- {
- // document is size of scroller or size of text contents, whichever is larger
- document_rect.setOriginAndSize(0, 0,
- mScroller->getContentWindowRect().getWidth(),
- llmax(mScroller->getContentWindowRect().getHeight(), mContentsRect.getHeight()));
- }
- else
- {
- // document size is just extents of reflowed text, reset to origin 0,0
- document_rect.set(0,
- getLocalRect().getHeight(),
- getLocalRect().getWidth(),
- llmin(0, getLocalRect().getHeight() - mContentsRect.getHeight()));
- }
- mDocumentView->setShape(document_rect);
-
- // after making document big enough to hold all the text, move the text to fit in the document
- if (!mLineInfoList.empty())
- {
- S32 delta_pos = mDocumentView->getRect().getHeight() - mLineInfoList.begin()->mRect.mTop - mVPad;
- // move line segments to fit new document rect
- for (line_list_t::iterator it = mLineInfoList.begin(); it != mLineInfoList.end(); ++it)
- {
- it->mRect.translate(0, delta_pos);
- }
- mContentsRect.translate(0, delta_pos);
- }
-
// calculate visible region for diplaying text
- updateTextRect();
+ updateRects();
for (segment_set_t::iterator segment_it = mSegments.begin();
segment_it != mSegments.end();
@@ -2075,8 +2029,30 @@ S32 LLTextBase::getEditableIndex(S32 index, bool increasing_direction)
}
}
-void LLTextBase::updateTextRect()
+void LLTextBase::updateRects()
{
+ if (mLineInfoList.empty())
+ {
+ mContentsRect = LLRect(0, mVPad, mHPad, 0);
+ }
+ else
+ {
+
+ mContentsRect = mLineInfoList.begin()->mRect;
+ for (line_list_t::const_iterator line_iter = ++mLineInfoList.begin();
+ line_iter != mLineInfoList.end();
+ ++line_iter)
+ {
+ mContentsRect.unionWith(line_iter->mRect);
+ }
+
+ mContentsRect.mRight += mHPad;
+ mContentsRect.mTop += mVPad;
+ // get around rounding errors when clipping text against rectangle
+ mContentsRect.stretch(1);
+ }
+
+
LLRect old_text_rect = mTextRect;
mTextRect = mScroller ? mScroller->getContentWindowRect() : getLocalRect();
//FIXME: replace border with image?
@@ -2090,6 +2066,37 @@ void LLTextBase::updateTextRect()
{
needsReflow();
}
+
+ // change document rect size too
+ LLRect document_rect;
+ if (mScroller)
+ {
+ // document is size of scroller or size of text contents, whichever is larger
+ document_rect.setOriginAndSize(0, 0,
+ mScroller->getContentWindowRect().getWidth(),
+ llmax(mScroller->getContentWindowRect().getHeight(), mContentsRect.getHeight()));
+ }
+ else
+ {
+ // document size is just extents of reflowed text, reset to origin 0,0
+ document_rect.set(0,
+ getLocalRect().getHeight(),
+ getLocalRect().getWidth(),
+ llmin(0, getLocalRect().getHeight() - mContentsRect.getHeight()));
+ }
+ mDocumentView->setShape(document_rect);
+
+ // after making document big enough to hold all the text, move the text to fit in the document
+ if (!mLineInfoList.empty())
+ {
+ S32 delta_pos = mDocumentView->getRect().getHeight() - mLineInfoList.begin()->mRect.mTop - mVPad;
+ // move line segments to fit new document rect
+ for (line_list_t::iterator it = mLineInfoList.begin(); it != mLineInfoList.end(); ++it)
+ {
+ it->mRect.translate(0, delta_pos);
+ }
+ mContentsRect.translate(0, delta_pos);
+ }
}
@@ -2218,6 +2225,11 @@ F32 LLNormalTextSegment::drawClippedSegment(S32 seg_start, S32 seg_end, S32 sele
const LLWString &text = mEditor.getWText();
+ if ( text[seg_end-1] == '\n' )
+ {
+ --seg_end;
+ }
+
F32 right_x = rect.mLeft;
if (!mStyle->isVisible())
{
@@ -2362,16 +2374,7 @@ void LLNormalTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& widt
{
LLWString text = mEditor.getWText();
- // look for any printable character, then return the font height
- height = 0;
- for (S32 index = mStart + first_char; index < mStart + first_char + num_chars; ++index)
- {
- if (text[index] != '\n')
- {
- height = mFontHeight;
- break;
- }
- }
+ height = mFontHeight;
width = mStyle->getFont()->getWidth(text.c_str(), mStart + first_char, num_chars);
}
@@ -2393,7 +2396,11 @@ S32 LLNormalTextSegment::getNumChars(S32 num_pixels, S32 segment_offset, S32 lin
S32 last_char = mStart + segment_offset;
for (; last_char != mEnd; ++last_char)
{
- if (text[last_char] == '\n') break;
+ if (text[last_char] == '\n')
+ {
+ last_char++;
+ break;
+ }
}
// set max characters to length of segment, or to first newline
@@ -2416,10 +2423,6 @@ S32 LLNormalTextSegment::getNumChars(S32 num_pixels, S32 segment_offset, S32 lin
// include terminating NULL
num_chars++;
}
- else if (text[mStart + segment_offset + num_chars] == '\n')
- {
- num_chars++;
- }
return num_chars;
}
diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h
index f0b8878491..d0787f001e 100644
--- a/indra/llui/lltextbase.h
+++ b/indra/llui/lltextbase.h
@@ -294,7 +294,7 @@ protected:
void endSelection();
// misc
- void updateTextRect();
+ void updateRects();
void needsReflow() { mReflowNeeded = TRUE; }
void needsScroll() { mScrollNeeded = TRUE; }
void replaceUrlLabel(const std::string &url, const std::string &label);
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index d507cf7ce4..570ca4b998 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -63,6 +63,7 @@
#include "llpanel.h"
#include "llurlregistry.h"
#include "lltooltip.h"
+#include "llmenugl.h"
#include <queue>
#include "llcombobox.h"
@@ -252,7 +253,8 @@ LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) :
mHandleEditKeysDirectly( p.handle_edit_keys_directly ),
mMouseDownX(0),
mMouseDownY(0),
- mTabsToNextField(p.ignore_tab)
+ mTabsToNextField(p.ignore_tab),
+ mContextMenu(NULL)
{
mDefaultFont = p.font;
@@ -273,7 +275,7 @@ LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) :
if (mShowLineNumbers)
{
mHPad += UI_TEXTEDITOR_LINE_NUMBER_MARGIN;
- updateTextRect();
+ updateRects();
}
}
@@ -301,6 +303,8 @@ LLTextEditor::~LLTextEditor()
// Scrollbar is deleted by LLView
std::for_each(mUndoStack.begin(), mUndoStack.end(), DeletePointer());
+
+ delete mContextMenu;
}
////////////////////////////////////////////////////////////
@@ -702,6 +706,19 @@ BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask)
return handled;
}
+BOOL LLTextEditor::handleRightMouseDown(S32 x, S32 y, MASK mask)
+{
+ BOOL handled = LLTextBase::handleRightMouseDown(x, y, mask);
+ if (!handled && hasTabStop())
+ {
+ setFocus( TRUE );
+ showContextMenu(x, y);
+ handled = TRUE;
+ }
+ return handled;
+}
+
+
BOOL LLTextEditor::handleMiddleMouseDown(S32 x, S32 y, MASK mask)
{
@@ -736,7 +753,6 @@ BOOL LLTextEditor::handleHover(S32 x, S32 y, MASK mask)
setCursorAtLocalPos( clamped_x, clamped_y, true );
mSelectionEnd = mCursorPos;
}
-
lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl;
getWindow()->setCursor(UI_CURSOR_IBEAM);
handled = TRUE;
@@ -1991,6 +2007,21 @@ void LLTextEditor::setEnabled(BOOL enabled)
}
}
+void LLTextEditor::showContextMenu(S32 x, S32 y)
+{
+ if (!mContextMenu)
+ {
+ mContextMenu = LLUICtrlFactory::instance().createFromFile<LLContextMenu>("menu_text_editor.xml",
+ LLMenuGL::sMenuContainer,
+ LLMenuHolderGL::child_registry_t::instance());
+ }
+
+ S32 screen_x, screen_y;
+ localPointToScreen(x, y, &screen_x, &screen_y);
+ mContextMenu->show(screen_x, screen_y);
+}
+
+
void LLTextEditor::drawPreeditMarker()
{
static LLUICachedControl<F32> preedit_marker_brightness ("UIPreeditMarkerBrightness", 0);
diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h
index 481a4d1a78..4847f4d117 100644
--- a/indra/llui/lltexteditor.h
+++ b/indra/llui/lltexteditor.h
@@ -99,6 +99,7 @@ public:
// mousehandler overrides
virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);
+ virtual BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
virtual BOOL handleHover(S32 x, S32 y, MASK mask);
virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask );
virtual BOOL handleMiddleMouseDown(S32 x,S32 y,MASK mask);
@@ -201,6 +202,7 @@ public:
void getSelectedSegments(segment_vec_t& segments) const;
protected:
+ void showContextMenu(S32 x, S32 y);
void drawPreeditMarker();
void assignEmbedded(const std::string &s);
@@ -328,6 +330,8 @@ private:
LLCoordGL mLastIMEPosition; // Last position of the IME editor
keystroke_signal_t mKeystrokeSignal;
+
+ LLContextMenu* mContextMenu;
}; // end class LLTextEditor