summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan MacArthur <imacarthur@gmail.com>2011-08-03 08:17:34 +0000
committerIan MacArthur <imacarthur@gmail.com>2011-08-03 08:17:34 +0000
commitec4275818360e23556d697a355952e8d78ffa5e7 (patch)
treec1036b0e7b82b9237179b4d095137eb9716ee801 /src
parent0fbe0257ab9d218a3d9c2bfdf896ae54ef3114f7 (diff)
fix typo in debug output, as per #2690
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8911 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Text_Display.cxx824
1 files changed, 412 insertions, 412 deletions
diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx
index 00aa03ff5..e6151d4a3 100644
--- a/src/Fl_Text_Display.cxx
+++ b/src/Fl_Text_Display.cxx
@@ -74,16 +74,16 @@ static int scroll_x = 0;
-/**
+/**
\brief Creates a new text display widget.
-
+
\param X, Y, W, H position and size of widget
\param l label text, defaults to none
*/
Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
: Fl_Group(X, Y, W, H, l) {
int i;
-
+
mMaxsize = 0;
damage_range1_start = damage_range1_end = -1;
damage_range2_start = damage_range2_end = -1;
@@ -91,30 +91,30 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
dragType = DRAG_CHAR;
display_insert_position_hint = 0;
shortcut_ = 0;
-
+
color(FL_BACKGROUND2_COLOR, FL_SELECTION_COLOR);
box(FL_DOWN_FRAME);
textsize(FL_NORMAL_SIZE);
textcolor(FL_FOREGROUND_COLOR);
textfont(FL_HELVETICA);
set_flag(SHORTCUT_LABEL);
-
+
text_area.x = 0;
text_area.y = 0;
text_area.w = 0;
text_area.h = 0;
-
+
mVScrollBar = new Fl_Scrollbar(0,0,1,1);
mVScrollBar->callback((Fl_Callback*)v_scrollbar_cb, this);
mHScrollBar = new Fl_Scrollbar(0,0,1,1);
mHScrollBar->callback((Fl_Callback*)h_scrollbar_cb, this);
mHScrollBar->type(FL_HORIZONTAL);
-
+
end();
-
+
scrollbar_width(Fl::scrollbar_size());
scrollbar_align(FL_ALIGN_BOTTOM_RIGHT);
-
+
mCursorOn = 0;
mCursorPos = 0;
mCursorOldY = -100;
@@ -129,9 +129,9 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
mAbsTopLineNum = 1;
mNeedAbsTopLineNum = 0;
mHorizOffset = mHorizOffsetHint = 0;
-
+
mCursor_color = FL_FOREGROUND_COLOR;
-
+
mStyleBuffer = 0;
mStyleTable = 0;
mNStyles = 0;
@@ -143,11 +143,11 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
mSuppressResync = 0;
mNLinesDeleted = 0;
mModifyingTabDistance = 0;
-
+
mUnfinishedStyle = 0;
mUnfinishedHighlightCB = 0;
mHighlightCBArg = 0;
-
+
mLineNumLeft = mLineNumWidth = 0;
mContinuousWrap = 0;
mWrapMarginPix = 0;
@@ -158,7 +158,7 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
/**
Free a text display and release its associated memory.
-
+
Note, the text BUFFER that the text display displays is a separate
entity and is not freed, nor are the style buffer or style table.
*/
@@ -176,7 +176,7 @@ Fl_Text_Display::~Fl_Text_Display() {
-/**
+/**
Attach a text buffer to display, replacing the current buffer (if any)
\param buf attach this text buffer
*/
@@ -193,27 +193,27 @@ void Fl_Text_Display::buffer( Fl_Text_Buffer *buf ) {
mBuffer->remove_modify_callback( buffer_modified_cb, this );
mBuffer->remove_predelete_callback( buffer_predelete_cb, this );
}
-
+
/* Add the buffer to the display, and attach a callback to the buffer for
receiving modification information when the buffer contents change */
mBuffer = buf;
if (mBuffer) {
mBuffer->add_modify_callback( buffer_modified_cb, this );
mBuffer->add_predelete_callback( buffer_predelete_cb, this );
-
+
/* Update the display */
buffer_modified_cb( 0, buf->length(), 0, 0, 0, this );
}
-
+
/* Resize the widget to update the screen... */
resize(x(), y(), w(), h());
}
-/**
+/**
\brief Attach (or remove) highlight information in text display and redisplay.
-
+
Highlighting information consists of a style buffer which parallels the
normal text buffer, but codes font and color information for the display;
a style table which translates style buffer codes (indexed by buffer
@@ -222,14 +222,14 @@ void Fl_Text_Display::buffer( Fl_Text_Buffer *buf ) {
"unfinishedStyle". Style buffer can trigger additional redisplay during
a normal buffer modification if the buffer contains a primary Fl_Text_Selection
(see extendRangeForStyleMods for more information on this protocol).
-
+
Style buffers, tables and their associated memory are managed by the caller.
-
+
Styles are ranged from 65 ('A') to 126.
-
+
\param styleBuffer this buffer works in parallel to the text buffer. For every
- character in the text buffer, the stye buffer has a byte at the same offset
- that contains an index into an array of possible styles.
+ character in the text buffer, the stye buffer has a byte at the same offset
+ that contains an index into an array of possible styles.
\param styleTable a list of styles indexed by the style buffer
\param nStyles number of styles in the style table
\param unfinishedStyle if this style is found, the callback below is called
@@ -250,7 +250,7 @@ void Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer,
mUnfinishedHighlightCB = unfinishedHighlightCB;
mHighlightCBArg = cbArg;
mColumnScale = 0;
-
+
mStyleBuffer->canUndo(0);
damage(FL_DAMAGE_EXPOSE);
}
@@ -282,7 +282,7 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
#endif // DEBUG
const int oldWidth = w();
#ifdef DEBUG
- printf(" oldWidth=%d, mContinuousWrap=%d, mWrapMargin=%d\n", oldWidth, mContinuousWrap, mWrapMargin);
+ printf(" oldWidth=%d, mContinuousWrap=%d, mWrapMarginPix=%d\n", oldWidth, mContinuousWrap, mWrapMarginPix);
#endif // DEBUG
Fl_Widget::resize(X,Y,W,H);
if (!buffer()) return;
@@ -290,25 +290,25 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
Y += Fl::box_dy(box());
W -= Fl::box_dw(box());
H -= Fl::box_dh(box());
-
+
text_area.x = X+LEFT_MARGIN;
text_area.y = Y+TOP_MARGIN;
text_area.w = W-LEFT_MARGIN-RIGHT_MARGIN;
text_area.h = H-TOP_MARGIN-BOTTOM_MARGIN;
int i;
-
+
/* Find the new maximum font height for this text display */
for (i = 0, mMaxsize = fl_height(textfont(), textsize()); i < mNStyles; i++)
mMaxsize = max(mMaxsize, fl_height(mStyleTable[i].font, mStyleTable[i].size));
-
+
// did we have scrollbars initially?
unsigned int hscrollbarvisible = mHScrollBar->visible();
unsigned int vscrollbarvisible = mVScrollBar->visible();
-
+
// try without scrollbars first
mVScrollBar->clear_visible();
mHScrollBar->clear_visible();
-
+
for (int again = 1; again;) {
again = 0;
/* In continuous wrap mode, a change in width affects the total number of
@@ -319,12 +319,12 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
mNBufferLines = count_lines(0, buffer()->length(), true);
mFirstChar = line_start(mFirstChar);
mTopLineNum = count_lines(0, mFirstChar, true)+1;
- absolute_top_line_number(oldFirstChar);
+ absolute_top_line_number(oldFirstChar);
#ifdef DEBUG
printf(" mNBufferLines=%d\n", mNBufferLines);
#endif // DEBUG
}
-
+
/* reallocate and update the line starts array, which may have changed
size and / or contents. */
int nvlines = (text_area.h + mMaxsize - 1) / mMaxsize;
@@ -334,10 +334,10 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
if (mLineStarts) delete[] mLineStarts;
mLineStarts = new int [mNVisibleLines];
}
-
+
calc_line_starts(0, mNVisibleLines);
calc_last_char();
-
+
// figure the scrollbars
if (scrollbar_width()) {
/* Decide if the vertical scrollbar needs to be visible */
@@ -357,7 +357,7 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
scrollbar_width(), text_area.h+TOP_MARGIN+BOTTOM_MARGIN);
}
}
-
+
/*
Decide if the horizontal scrollbar needs to be visible. If there
is a vertical scrollbar, a horizontal is always created too. This
@@ -400,11 +400,11 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
}
}
}
-
+
// user request to change viewport
if (mTopLineNumHint != mTopLineNum || mHorizOffsetHint != mHorizOffset)
scroll_(mTopLineNumHint, mHorizOffsetHint);
-
+
// everything will fit in the viewport
if (mNBufferLines < mNVisibleLines || mBuffer == NULL || mBuffer->length() == 0) {
scroll_(1, mHorizOffset);
@@ -412,29 +412,29 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
display more text by scrolling down */
} else {
while ( mNVisibleLines>=2
- && (mLineStarts[mNVisibleLines-2]==-1)
+ && (mLineStarts[mNVisibleLines-2]==-1)
&& scroll_(mTopLineNum-1, mHorizOffset))
{ }
}
-
+
// user request to display insert position
if (display_insert_position_hint)
display_insert();
-
+
// in case horizontal offset is now greater than longest line
int maxhoffset = max(0, longest_vline()-text_area.w);
if (mHorizOffset > maxhoffset)
scroll_(mTopLineNumHint, maxhoffset);
-
+
mTopLineNumHint = mTopLineNum;
mHorizOffsetHint = mHorizOffset;
display_insert_position_hint = 0;
-
+
if (mContinuousWrap ||
hscrollbarvisible != mHScrollBar->visible() ||
vscrollbarvisible != mVScrollBar->visible())
redraw();
-
+
update_v_scrollbar();
update_h_scrollbar();
}
@@ -442,36 +442,36 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
/**
- \brief Refresh a rectangle of the text display.
+ \brief Refresh a rectangle of the text display.
\param left, top are in coordinates of the text drawing window.
- \param width, height size in pixels
+ \param width, height size in pixels
*/
void Fl_Text_Display::draw_text( int left, int top, int width, int height ) {
int fontHeight, firstLine, lastLine, line;
-
+
/* find the line number range of the display */
fontHeight = mMaxsize ? mMaxsize : textsize_;
firstLine = ( top - text_area.y - fontHeight + 1 ) / fontHeight;
lastLine = ( top + height - text_area.y ) / fontHeight + 1;
-
+
fl_push_clip( left, top, width, height );
-
+
/* draw the lines */
for ( line = firstLine; line <= lastLine; line++ )
draw_vline( line, left, left + width, 0, INT_MAX );
-
+
/* draw the line numbers if exposed area includes them */
if (mLineNumWidth != 0 && left <= mLineNumLeft + mLineNumWidth)
draw_line_numbers(false);
-
+
fl_pop_clip();
}
-/**
+/**
\brief Marks text from start to end as needing a redraw.
- This function will trigger a damage event and later a redraw of parts of
+ This function will trigger a damage event and later a redraw of parts of
the widget.
\param startpos index of first character needing redraw
\param endpos index after last character needing redraw
@@ -479,7 +479,7 @@ void Fl_Text_Display::draw_text( int left, int top, int width, int height ) {
void Fl_Text_Display::redisplay_range(int startpos, int endpos) {
IS_UTF8_ALIGNED2(buffer(), startpos)
IS_UTF8_ALIGNED2(buffer(), endpos)
-
+
if (damage_range1_start == -1 && damage_range1_end == -1) {
damage_range1_start = startpos;
damage_range1_end = endpos;
@@ -515,19 +515,19 @@ void Fl_Text_Display::redisplay_range(int startpos, int endpos) {
void Fl_Text_Display::draw_range(int startpos, int endpos) {
startpos = buffer()->utf8_align(startpos);
endpos = buffer()->utf8_align(endpos);
-
+
int i, startLine, lastLine, startIndex, endIndex;
-
+
/* If the range is outside of the displayed text, just return */
- if ( endpos < mFirstChar || ( startpos > mLastChar && !empty_vlines() ) )
+ if ( endpos < mFirstChar || ( startpos > mLastChar && !empty_vlines() ) )
return;
-
+
/* Clean up the starting and ending values */
if ( startpos < 0 ) startpos = 0;
if ( startpos > mBuffer->length() ) startpos = mBuffer->length();
if ( endpos < 0 ) endpos = 0;
if ( endpos > mBuffer->length() ) endpos = mBuffer->length();
-
+
/* Get the starting and ending lines */
if ( startpos < mFirstChar )
startpos = mFirstChar;
@@ -541,7 +541,7 @@ void Fl_Text_Display::draw_range(int startpos, int endpos) {
lastLine = mNVisibleLines - 1;
}
}
-
+
/* Get the starting and ending positions within the lines */
startIndex = mLineStarts[ startLine ] == -1 ? 0 : startpos - mLineStarts[ startLine ];
if ( endpos >= mLastChar )
@@ -550,7 +550,7 @@ void Fl_Text_Display::draw_range(int startpos, int endpos) {
endIndex = 0;
else
endIndex = endpos - mLineStarts[ lastLine ];
-
+
/* If the starting and ending lines are the same, redisplay the single
line between "start" and "end" */
if ( startLine == lastLine ) {
@@ -571,7 +571,7 @@ void Fl_Text_Display::draw_range(int startpos, int endpos) {
-/**
+/**
\brief Sets the position of the text insertion cursor for text display.
Move the insertion cursor in front of the character at \p newPos.
This function may trigger a redraw.
@@ -579,27 +579,27 @@ void Fl_Text_Display::draw_range(int startpos, int endpos) {
*/
void Fl_Text_Display::insert_position( int newPos ) {
IS_UTF8_ALIGNED2(buffer(), newPos)
-
+
/* make sure new position is ok, do nothing if it hasn't changed */
if ( newPos == mCursorPos ) return;
if ( newPos < 0 ) newPos = 0;
if ( newPos > mBuffer->length() ) newPos = mBuffer->length();
-
+
/* cursor movement cancels vertical cursor motion column */
mCursorPreferredXPos = -1;
-
+
/* erase the cursor at its previous position */
redisplay_range(buffer()->prev_char_clipped(mCursorPos), buffer()->next_char(mCursorPos));
-
+
mCursorPos = newPos;
-
+
/* draw cursor at its new position */
redisplay_range(buffer()->prev_char_clipped(mCursorPos), buffer()->next_char(mCursorPos));
}
-/**
+/**
\brief Shows the text cursor.
This function may trigger a redraw.
\param b show(1) or hide(0) the text cursor (caret).
@@ -614,16 +614,16 @@ void Fl_Text_Display::show_cursor(int b) {
/**
\brief Sets the text cursor style.
Sets the text cursor style to one of the following:
-
+
\li Fl_Text_Display::NORMAL_CURSOR - Shows an I beam.
\li Fl_Text_Display::CARET_CURSOR - Shows a caret under the text.
\li Fl_Text_Display::DIM_CURSOR - Shows a dimmed I beam.
\li Fl_Text_Display::BLOCK_CURSOR - Shows an unfilled box around the current
character.
\li Fl_Text_Display::HEAVY_CURSOR - Shows a thick I beam.
-
+
This call also switches the cursor on and may trigger a redraw.
-
+
\param style new cursor style
*/
void Fl_Text_Display::cursor_style(int style) {
@@ -635,15 +635,15 @@ void Fl_Text_Display::cursor_style(int style) {
/**
\brief Set the new text wrap mode.
-
+
If \p wrap mode is not zero, this call enables automatic word wrapping at column
\p wrapMargin. Word-wrapping does not change the text buffer itself, only the way
the text is displayed. Different Text Displays can have different wrap modes,
even if they share the same Text Buffer.
\param wrap new wrap mode is WRAP_NONE (don't wrap text at all), WRAP_AT_COLUMN
- (wrap text at the given text column), WRAP_AT_PIXEL (wrap text at a pixel
- position), or WRAP_AT_BOUNDS (wrap text so that it fits into the
+ (wrap text at the given text column), WRAP_AT_PIXEL (wrap text at a pixel
+ position), or WRAP_AT_BOUNDS (wrap text so that it fits into the
widget width)
\param wrapMargin in WRAP_AT_COLUMN mode, text will wrap at the n'th character.
For variable width fonts, an average character width is calculated. The
@@ -655,37 +655,37 @@ void Fl_Text_Display::cursor_style(int style) {
*/
void Fl_Text_Display::wrap_mode(int wrap, int wrapMargin) {
switch (wrap) {
- case WRAP_NONE:
+ case WRAP_NONE:
mWrapMarginPix = 0;
mContinuousWrap = 0;
break;
- case WRAP_AT_COLUMN:
+ case WRAP_AT_COLUMN:
default:
mWrapMarginPix = int(col_to_x(wrapMargin));
mContinuousWrap = 1;
break;
- case WRAP_AT_PIXEL:
+ case WRAP_AT_PIXEL:
mWrapMarginPix = wrapMargin;
mContinuousWrap = 1;
break;
- case WRAP_AT_BOUNDS:
+ case WRAP_AT_BOUNDS:
mWrapMarginPix = 0;
mContinuousWrap = 1;
break;
}
-
+
if (buffer()) {
/* wrapping can change the total number of lines, re-count */
mNBufferLines = count_lines(0, buffer()->length(), true);
-
+
/* changing wrap margins or changing from wrapped mode to non-wrapped
can leave the character at the top no longer at a line start, and/or
change the line number */
mFirstChar = line_start(mFirstChar);
mTopLineNum = count_lines(0, mFirstChar, true) + 1;
-
+
reset_absolute_top_line_number();
-
+
/* update the line starts array */
calc_line_starts(0, mNVisibleLines);
calc_last_char();
@@ -696,27 +696,27 @@ void Fl_Text_Display::wrap_mode(int wrap, int wrapMargin) {
mTopLineNum = 1;
mAbsTopLineNum = 0;
}
-
+
resize(x(), y(), w(), h());
}
/**
- \brief Inserts "text" at the current cursor location.
-
- This has the same effect as inserting the text into the buffer using BufInsert
+ \brief Inserts "text" at the current cursor location.
+
+ This has the same effect as inserting the text into the buffer using BufInsert
and then moving the insert position after the newly inserted text, except
that it's optimized to do less redrawing.
-
+
\param text new text in UTF-8 encoding.
*/
void Fl_Text_Display::insert(const char* text) {
IS_UTF8_ALIGNED2(buffer(), mCursorPos)
IS_UTF8_ALIGNED(text)
-
+
int pos = mCursorPos;
-
+
mCursorToHint = pos + strlen( text );
mBuffer->insert( pos, text );
mCursorToHint = NO_HINT;
@@ -724,16 +724,16 @@ void Fl_Text_Display::insert(const char* text) {
-/**
+/**
\brief Replaces text at the current insert position.
\param text new text in UTF-8 encoding
-
+
\todo Unicode? Find out exactly what we do here and simplify.
*/
void Fl_Text_Display::overstrike(const char* text) {
IS_UTF8_ALIGNED2(buffer(), mCursorPos)
IS_UTF8_ALIGNED(text)
-
+
int startPos = mCursorPos;
Fl_Text_Buffer *buf = mBuffer;
int lineStart = buf->line_start( startPos );
@@ -742,14 +742,14 @@ void Fl_Text_Display::overstrike(const char* text) {
const char *c;
unsigned int ch;
char *paddedText = NULL;
-
+
/* determine how many displayed character positions are covered */
startIndent = mBuffer->count_displayed_characters( lineStart, startPos );
indent = startIndent;
for ( c = text; *c != '\0'; c += fl_utf8len1(*c) )
indent++;
endIndent = indent;
-
+
/* find which characters to remove, and if necessary generate additional
padding to make up for removed control characters at the end */
indent = startIndent;
@@ -776,7 +776,7 @@ void Fl_Text_Display::overstrike(const char* text) {
}
}
endPos = p;
-
+
mCursorToHint = startPos + textLen;
buf->replace( startPos, endPos, paddedText == NULL ? text : paddedText );
mCursorToHint = NO_HINT;
@@ -788,9 +788,9 @@ void Fl_Text_Display::overstrike(const char* text) {
/**
\brief Convert a character index into a pixel position.
-
- Translate a buffer text position to the XY location where the top left of the
- cursor would be positioned to point to that character. Returns 0 if the
+
+ Translate a buffer text position to the XY location where the top left of the
+ cursor would be positioned to point to that character. Returns 0 if the
position is not displayed because it is \e \b vertically out of view.
If the position is horizontally out of view, returns the X coordinate where
the position would be if it were visible.
@@ -804,12 +804,12 @@ int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) const {
int lineStartPos, fontHeight, lineLen;
int visLineNum;
-
+
/* If position is not displayed, return false */
if (pos < mFirstChar || (pos > mLastChar && !empty_vlines())) {
return 0;
}
-
+
/* Calculate Y coordinate */
if (!position_to_line(pos, &visLineNum)) {
return 0;
@@ -817,10 +817,10 @@ int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) const {
if (visLineNum < 0 || visLineNum > mNBufferLines) {
return 0;
}
-
+
fontHeight = mMaxsize;
*Y = text_area.y + visLineNum * fontHeight;
-
+
/* Get the text, length, and buffer position of the line. If the position
is beyond the end of the buffer and should be at the first position on
the first empty line, don't try to get or scan the text */
@@ -837,27 +837,27 @@ int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) const {
/**
- \brief Find the line and column number of position \p pos.
+ \brief Find the line and column number of position \p pos.
- This only works for displayed lines. If the line is not displayed, the
+ This only works for displayed lines. If the line is not displayed, the
function returns 0 (without the mLineStarts array it could turn in to very long
calculation involving scanning large amounts of text in the buffer).
If continuous wrap mode is on, returns the absolute line number (as opposed
to the wrapped line number which is used for scrolling).
-
+
\param pos character index
\param[out] lineNum absolute (unwrapped) line number
\param[out] column character offset to the beginning of the line
\return 0 if \p pos is off screen, line number otherwise
- \todo a column number makes little sense in the UTF-8/variable font width
- environment. We will have to further define what exactly we want to return.
+ \todo a column number makes little sense in the UTF-8/variable font width
+ environment. We will have to further define what exactly we want to return.
Please check the functions that call this particular function.
*/
int Fl_Text_Display::position_to_linecol( int pos, int* lineNum, int* column ) const {
IS_UTF8_ALIGNED2(buffer(), pos)
-
+
int retVal;
-
+
/* In continuous wrap mode, the absolute (non-wrapped) line count is
maintained separately, as needed. Only return it if we're actually
keeping track of it and pos is in the displayed text */
@@ -868,7 +868,7 @@ int Fl_Text_Display::position_to_linecol( int pos, int* lineNum, int* column ) c
*column = buffer()->count_displayed_characters(buffer()->line_start(pos), pos);
return 1;
}
-
+
retVal = position_to_line( pos, lineNum );
if ( retVal ) {
*column = mBuffer->count_displayed_characters( mLineStarts[ *lineNum ], pos );
@@ -895,7 +895,7 @@ int Fl_Text_Display::in_selection( int X, int Y ) const {
/**
\brief Nobody knows what this function does.
-
+
Correct a column number based on an unconstrained position (as returned by
TextDXYToUnconstrainedPosition) to be relative to the last actual newline
in the buffer before the row and column position given, rather than the
@@ -904,18 +904,18 @@ int Fl_Text_Display::in_selection( int X, int Y ) const {
which thinks that the unconstrained column is the number of characters
from the last newline. Obviously this is time consuming, because it
invloves character re-counting.
-
+
\param row
\param column
\return something unknown
- \todo What does this do and how is it useful? Column numbers mean little in
+ \todo What does this do and how is it useful? Column numbers mean little in
this context. Which functions depend on this one?
-
+
\todo Unicode?
*/
int Fl_Text_Display::wrapped_column(int row, int column) const {
int lineStart, dispLineStart;
-
+
if (!mContinuousWrap || row < 0 || row > mNVisibleLines)
return column;
dispLineStart = mLineStarts[row];
@@ -929,16 +929,16 @@ int Fl_Text_Display::wrapped_column(int row, int column) const {
/**
\brief Nobody knows what this function does.
-
+
Correct a row number from an unconstrained position (as returned by
TextDXYToUnconstrainedPosition) to a straight number of newlines from the
top line of the display. Because rectangular selections are based on
newlines, rather than display wrapping, and anywhere a rectangular selection
needs a row, it needs it in terms of un-wrapped lines.
-
+
\param row
\return something unknown
- \todo What does this do and how is it useful? Column numbers mean little in
+ \todo What does this do and how is it useful? Column numbers mean little in
this context. Which functions depend on this one?
*/
int Fl_Text_Display::wrapped_row(int row) const {
@@ -956,14 +956,14 @@ int Fl_Text_Display::wrapped_row(int row) const {
(scroll_() counts them too) and/or to count from the most efficient
starting point, but the efficiency of this routine is not as important to
the overall performance of the text display.
-
+
\todo Unicode?
*/
void Fl_Text_Display::display_insert() {
int hOffset, topLine, X, Y;
hOffset = mHorizOffset;
topLine = mTopLineNum;
-
+
if (insert_position() < mFirstChar) {
topLine -= count_lines(insert_position(), mFirstChar, false);
} else if (mNVisibleLines>=2 && mLineStarts[mNVisibleLines-2] != -1) {
@@ -972,7 +972,7 @@ void Fl_Text_Display::display_insert() {
topLine += count_lines(lastChar - (wrap_uses_character(mLastChar) ? 0 : 1),
insert_position(), false);
}
-
+
/* Find the new setting for horizontal offset (this is a bit ungraceful).
If the line is visible, just use PositionToXY to get the position
to scroll to, otherwise, do the vertical scrolling first, then the
@@ -990,16 +990,16 @@ void Fl_Text_Display::display_insert() {
hOffset += X-(text_area.x + text_area.w);
else if (X < text_area.x)
hOffset += X-text_area.x;
-
+
/* Do the scroll */
if (topLine != mTopLineNum || hOffset != mHorizOffset)
scroll_(topLine, hOffset);
}
-/**
+/**
\brief Scrolls the text buffer to show the current insert position.
- This function triggers a complete recalculation, ending in a call to
+ This function triggers a complete recalculation, ending in a call to
Fl_Text_Display::display_insert()
*/
void Fl_Text_Display::show_insert_position() {
@@ -1012,7 +1012,7 @@ void Fl_Text_Display::show_insert_position() {
Cursor movement functions
*/
-/**
+/**
\brief Moves the current insert position right one character.
\return 1 if the cursor moved, 0 if the end of the text was reached
*/
@@ -1027,7 +1027,7 @@ int Fl_Text_Display::move_right() {
-/**
+/**
\brief Moves the current insert position left one character.
\return 1 if the cursor moved, 0 if the beginning of the text was reached
*/
@@ -1042,13 +1042,13 @@ int Fl_Text_Display::move_left() {
-/**
+/**
\brief Moves the current insert position up one line.
\return 1 if the cursor moved, 0 if the beginning of the text was reached
*/
int Fl_Text_Display::move_up() {
int lineStartPos, xPos, prevLineStartPos, newPos, visLineNum;
-
+
/* Find the position of the start of the line. Use the line starts array
if possible */
if ( position_to_line( mCursorPos, &visLineNum ) )
@@ -1059,27 +1059,27 @@ int Fl_Text_Display::move_up() {
}
if ( lineStartPos == 0 )
return 0;
-
+
/* Decide what column to move to, if there's a preferred column use that */
if (mCursorPreferredXPos >= 0)
xPos = mCursorPreferredXPos;
else
- xPos = handle_vline(GET_WIDTH, lineStartPos, mCursorPos-lineStartPos,
+ xPos = handle_vline(GET_WIDTH, lineStartPos, mCursorPos-lineStartPos,
0, 0, 0, 0, 0, INT_MAX);
-
+
/* count forward from the start of the previous line to reach the column */
if ( visLineNum != -1 && visLineNum != 0 )
prevLineStartPos = mLineStarts[ visLineNum - 1 ];
else
prevLineStartPos = rewind_lines( lineStartPos, 1 );
-
+
int lineEnd = line_end(prevLineStartPos, true);
- newPos = handle_vline(FIND_INDEX_FROM_ZERO, prevLineStartPos, lineEnd-prevLineStartPos,
+ newPos = handle_vline(FIND_INDEX_FROM_ZERO, prevLineStartPos, lineEnd-prevLineStartPos,
0, 0, 0, 0, 0, xPos);
-
+
/* move the cursor */
insert_position( newPos );
-
+
/* if a preferred column wasn't aleady established, establish it */
mCursorPreferredXPos = xPos;
return 1;
@@ -1087,16 +1087,16 @@ int Fl_Text_Display::move_up() {
-/**
+/**
\brief Moves the current insert position down one line.
\return 1 if the cursor moved, 0 if the beginning of the text was reached
*/
int Fl_Text_Display::move_down() {
int lineStartPos, xPos, newPos, visLineNum;
-
+
if ( mCursorPos == mBuffer->length() )
return 0;
-
+
if ( position_to_line( mCursorPos, &visLineNum ) )
lineStartPos = mLineStarts[ visLineNum ];
else {
@@ -1106,15 +1106,15 @@ int Fl_Text_Display::move_down() {
if (mCursorPreferredXPos >= 0) {
xPos = mCursorPreferredXPos;
} else {
- xPos = handle_vline(GET_WIDTH, lineStartPos, mCursorPos-lineStartPos,
+ xPos = handle_vline(GET_WIDTH, lineStartPos, mCursorPos-lineStartPos,
0, 0, 0, 0, 0, INT_MAX);
}
-
+
int nextLineStartPos = skip_lines( lineStartPos, 1, true );
int lineEnd = line_end(nextLineStartPos, true);
- newPos = handle_vline(FIND_INDEX_FROM_ZERO, nextLineStartPos, lineEnd-nextLineStartPos,
+ newPos = handle_vline(FIND_INDEX_FROM_ZERO, nextLineStartPos, lineEnd-nextLineStartPos,
0, 0, 0, 0, 0, xPos);
-
+
insert_position( newPos );
mCursorPreferredXPos = xPos;
return 1;
@@ -1139,27 +1139,27 @@ int Fl_Text_Display::count_lines(int startPos, int endPos,
bool startPosIsLineStart) const {
IS_UTF8_ALIGNED2(buffer(), startPos)
IS_UTF8_ALIGNED2(buffer(), endPos)
-
+
int retLines, retPos, retLineStart, retLineEnd;
-
+
#ifdef DEBUG
printf("Fl_Text_Display::count_lines(startPos=%d, endPos=%d, startPosIsLineStart=%d\n",
startPos, endPos, startPosIsLineStart);
#endif // DEBUG
-
+
/* If we're not wrapping use simple (and more efficient) BufCountLines */
if (!mContinuousWrap)
return buffer()->count_lines(startPos, endPos);
-
+
wrapped_line_counter(buffer(), startPos, endPos, INT_MAX,
startPosIsLineStart, 0, &retPos, &retLines, &retLineStart,
&retLineEnd);
-
+
#ifdef DEBUG
printf(" # after WLC: retPos=%d, retLines=%d, retLineStart=%d, retLineEnd=%d\n",
retPos, retLines, retLineStart, retLineEnd);
#endif // DEBUG
-
+
return retLines;
}
@@ -1172,7 +1172,7 @@ int Fl_Text_Display::count_lines(int startPos, int endPos,
wrapping is turned on. If the caller knows that startPos is at a line start,
it can pass "startPosIsLineStart" as True to make the call more efficient
by avoiding the additional step of scanning back to the last newline.
-
+
\param startPos index to starting character
\param nLines number of lines to skip ahead
\param startPosIsLineStart avoid scanning back to the line start
@@ -1183,18 +1183,18 @@ int Fl_Text_Display::skip_lines(int startPos, int nLines,
IS_UTF8_ALIGNED2(buffer(), startPos)
int retLines, retPos, retLineStart, retLineEnd;
-
+
/* if we're not wrapping use more efficient BufCountForwardNLines */
if (!mContinuousWrap)
return buffer()->skip_lines(startPos, nLines);
-
+
/* wrappedLineCounter can't handle the 0 lines case */
if (nLines == 0)
return startPos;
-
+
/* use the common line counting routine to count forward */
wrapped_line_counter(buffer(), startPos, buffer()->length(),
- nLines, startPosIsLineStart, 0,
+ nLines, startPosIsLineStart, 0,
&retPos, &retLines, &retLineStart, &retLineEnd);
IS_UTF8_ALIGNED2(buffer(), retPos)
return retPos;
@@ -1204,7 +1204,7 @@ int Fl_Text_Display::skip_lines(int startPos, int nLines,
/**
\brief Returns the end of a line.
-
+
Same as BufEndOfLine, but takes into account line breaks when wrapping
is turned on. If the caller knows that \p startPos is at a line start, it
can pass "startPosIsLineStart" as True to make the call more efficient
@@ -1219,7 +1219,7 @@ int Fl_Text_Display::skip_lines(int startPos, int nLines,
line had no whitespace. In this case, this routine returns a pointer to
the start of the next line. This is also consistent with the model used by
visLineLength.
-
+
\param startPos index to starting character
\param startPosIsLineStart avoid scanning back to the line start
\return new position as index
@@ -1228,18 +1228,18 @@ int Fl_Text_Display::line_end(int startPos, bool startPosIsLineStart) const {
IS_UTF8_ALIGNED2(buffer(), startPos)
int retLines, retPos, retLineStart, retLineEnd;
-
+
/* If we're not wrapping use more efficient BufEndOfLine */
if (!mContinuousWrap)
return buffer()->line_end(startPos);
-
+
if (startPos == buffer()->length())
return startPos;
-
+
wrapped_line_counter(buffer(), startPos, buffer()->length(), 1,
startPosIsLineStart, 0, &retPos, &retLines, &retLineStart,
&retLineEnd);
-
+
IS_UTF8_ALIGNED2(buffer(), retLineEnd)
return retLineEnd;
}
@@ -1251,7 +1251,7 @@ int Fl_Text_Display::line_end(int startPos, bool startPosIsLineStart) const {
Same as BufStartOfLine, but returns the character after last wrap point
rather than the last newline.
-
+
\param pos index to starting character
\return new position as index
*/
@@ -1259,11 +1259,11 @@ int Fl_Text_Display::line_start(int pos) const {
IS_UTF8_ALIGNED2(buffer(), pos)
int retLines, retPos, retLineStart, retLineEnd;
-
+
/* If we're not wrapping, use the more efficient BufStartOfLine */
if (!mContinuousWrap)
return buffer()->line_start(pos);
-
+
wrapped_line_counter(buffer(), buffer()->line_start(pos), pos, INT_MAX, true, 0,
&retPos, &retLines, &retLineStart, &retLineEnd);
@@ -1288,15 +1288,15 @@ int Fl_Text_Display::rewind_lines(int startPos, int nLines) {
Fl_Text_Buffer *buf = buffer();
int pos, lineStart, retLines, retPos, retLineStart, retLineEnd;
-
+
/* If we're not wrapping, use the more efficient BufCountBackwardNLines */
if (!mContinuousWrap)
return buf->rewind_lines(startPos, nLines);
-
+
pos = startPos;
for (;;) {
lineStart = buf->line_start(pos);
- wrapped_line_counter(buf, lineStart, pos, INT_MAX, true, 0,
+ wrapped_line_counter(buf, lineStart, pos, INT_MAX, true, 0,
&retPos, &retLines, &retLineStart, &retLineEnd, false);
if (retLines > nLines)
return skip_lines(lineStart, retLines-nLines, true);
@@ -1317,7 +1317,7 @@ static inline int fl_isseparator(unsigned int c) {
-/**
+/**
\brief Moves the current insert position right one word.
*/
void Fl_Text_Display::next_word() {
@@ -1330,13 +1330,13 @@ void Fl_Text_Display::next_word() {
while (pos < buffer()->length() && fl_isseparator(buffer()->char_at(pos))) {
pos = buffer()->next_char(pos);
}
-
+
insert_position( pos );
}
-/**
+/**
\brief Moves the current insert position left one word.
*/
void Fl_Text_Display::previous_word() {
@@ -1355,7 +1355,7 @@ void Fl_Text_Display::previous_word() {
if (fl_isseparator(buffer()->char_at(pos))) {
pos = buffer()->next_char(pos);
}
-
+
insert_position( pos );
}
@@ -1363,10 +1363,10 @@ void Fl_Text_Display::previous_word() {
/**
\brief This is called before any characters are deleted.
-
+
Callback attached to the text buffer to receive delete information before
the modifications are actually made.
-
+
\param pos starting index of deletion
\param nDeleted number of bytes we will delete (must be UTF-8 aligned!)
\param cbArg "this" pointer for static callback function
@@ -1393,7 +1393,7 @@ void Fl_Text_Display::buffer_predelete_cb(int pos, int nDeleted, void *cbArg) {
/**
\brief This is called whenever the buffer is modified.
-
+
Callback attached to the text buffer to receive modification information
\param pos starting index of modification
@@ -1414,11 +1414,11 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
IS_UTF8_ALIGNED2(buf, pos)
IS_UTF8_ALIGNED2(buf, oldFirstChar)
-
+
/* buffer modification cancels vertical cursor motion column */
if ( nInserted != 0 || nDeleted != 0 )
textD->mCursorPreferredXPos = -1;
-
+
/* Count the number of lines inserted and deleted, and in the case
of continuous wrap mode, how much has changed */
if (textD->mContinuousWrap) {
@@ -1428,7 +1428,7 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
linesInserted = nInserted == 0 ? 0 : buf->count_lines( pos, pos + nInserted );
linesDeleted = nDeleted == 0 ? 0 : countlines( deletedText );
}
-
+
/* Update the line starts and mTopLineNum */
if ( nInserted != 0 || nDeleted != 0 ) {
if (textD->mContinuousWrap) {
@@ -1441,7 +1441,7 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
}
} else
scrolled = 0;
-
+
/* If we're counting non-wrapped lines as well, maintain the absolute
(non-wrapped) line number of the text displayed */
if (textD->maintaining_absolute_top_line_number() &&
@@ -1451,11 +1451,11 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
countlines(deletedText);
else if (pos < oldFirstChar)
textD->reset_absolute_top_line_number();
- }
-
+ }
+
/* Update the line count for the whole buffer */
textD->mNBufferLines += linesInserted - linesDeleted;
-
+
/* Update the cursor position */
if ( textD->mCursorToHint != NO_HINT ) {
textD->mCursorPos = textD->mCursorToHint;
@@ -1466,13 +1466,13 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
else
textD->mCursorPos += nInserted - nDeleted;
}
-
+
// refigure scrollbars & stuff
textD->resize(textD->x(), textD->y(), textD->w(), textD->h());
-
+
// don't need to do anything else if not visible?
if (!textD->visible_r()) return;
-
+
/* If the changes caused scrolling, re-paint everything and we're done. */
if ( scrolled ) {
textD->damage(FL_DAMAGE_EXPOSE);
@@ -1480,7 +1480,7 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
textD->mStyleBuffer->primary_selection()->selected(0);
return;
}
-
+
/* If the changes didn't cause scrolling, decide the range of characters
that need to be re-painted. Also if the cursor position moved, be
sure that the redisplay range covers the old cursor position so the
@@ -1488,11 +1488,11 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
beyond the left and right edges of the text. */
startDispPos = textD->mContinuousWrap ? wrapModStart : pos;
IS_UTF8_ALIGNED2(buf, startDispPos)
-
+
if ( origCursorPos == startDispPos && textD->mCursorPos != startDispPos )
startDispPos = min( startDispPos, buf->prev_char_clipped(origCursorPos) );
IS_UTF8_ALIGNED2(buf, startDispPos)
-
+
if ( linesInserted == linesDeleted ) {
if ( nInserted == 0 && nDeleted == 0 )
endDispPos = pos + nRestyled;
@@ -1501,11 +1501,11 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
endDispPos = wrapModEnd;
else
endDispPos = buf->next_char(buf->line_end( pos + nInserted ));
-
+
// CET - FIXME if ( origCursorPos >= startDispPos &&
// ( origCursorPos <= endDispPos || endDispPos == buf->length() ) )
}
-
+
if (linesInserted > 1) textD->draw_line_numbers(false);
} else {
endDispPos = buf->next_char(textD->mLastChar);
@@ -1513,13 +1513,13 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
/* If more than one line is inserted/deleted, a line break may have
been inserted or removed in between, and the line numbers may
have changed. If only one line is altered, line numbers cannot
- be affected (the insertion or removal of a line break always
+ be affected (the insertion or removal of a line break always
results in at least two lines being redrawn). */
textD->draw_line_numbers(false);
}
IS_UTF8_ALIGNED2(buf, startDispPos)
IS_UTF8_ALIGNED2(buf, endDispPos)
-
+
/* If there is a style buffer, check if the modification caused additional
changes that need to be redisplayed. (Redisplaying separately would
cause double-redraw on almost every modification involving styled
@@ -1528,7 +1528,7 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
textD->extend_range_for_styles( &startDispPos, &endDispPos );
IS_UTF8_ALIGNED2(buf, startDispPos)
IS_UTF8_ALIGNED2(buf, endDispPos)
-
+
/* Redisplay computed range */
textD->redisplay_range( startDispPos, endDispPos );
}
@@ -1537,7 +1537,7 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
/**
\brief Line numbering stuff, currently unused.
-
+
In continuous wrap mode, internal line numbers are calculated after
wrapping. A separate non-wrapped line count is maintained when line
numbering is turned on. There is some performance cost to maintaining this
@@ -1556,7 +1556,7 @@ void Fl_Text_Display::maintain_absolute_top_line_number(int state) {
/**
\brief Line numbering stuff, currently unused.
-
+
Returns the absolute (non-wrapped) line number of the first line displayed.
Returns 0 if the absolute top line number is not being maintained.
*/
@@ -1572,7 +1572,7 @@ int Fl_Text_Display::get_absolute_top_line_number() const {
/**
\brief Line numbering stuff, currently unused.
-
+
Re-calculate absolute top line number for a change in scroll position.
*/
void Fl_Text_Display::absolute_top_line_number(int oldFirstChar) {
@@ -1588,7 +1588,7 @@ void Fl_Text_Display::absolute_top_line_number(int oldFirstChar) {
/**
\brief Line numbering stuff, currently unused.
-
+
Return true if a separate absolute top line number is being maintained
(for displaying line numbers or showing in the statistics line).
*/
@@ -1601,7 +1601,7 @@ int Fl_Text_Display::maintaining_absolute_top_line_number() const {
/**
\brief Line numbering stuff, probably unused.
-
+
Count lines from the beginning of the buffer to reestablish the
absolute (non-wrapped) top line number. If mode is not continuous wrap,
or the number is not being maintained, does nothing.
@@ -1615,10 +1615,10 @@ void Fl_Text_Display::reset_absolute_top_line_number() {
/**
\brief Convert a position index into a line number offset.
-
+
Find the line number of position \p pos relative to the first line of
displayed text. Returns 0 if the line is not displayed.
-
+
\param pos ??
\param[out] lineNum ??
\return ??
@@ -1628,7 +1628,7 @@ int Fl_Text_Display::position_to_line( int pos, int *lineNum ) const {
IS_UTF8_ALIGNED2(buffer(), pos)
int i;
-
+
*lineNum = 0;
if ( pos < mFirstChar ) return 0;
if ( pos > mLastChar ) {
@@ -1646,7 +1646,7 @@ int Fl_Text_Display::position_to_line( int pos, int *lineNum ) const {
}
return 0;
}
-
+
for ( i = mNVisibleLines - 1; i >= 0; i-- ) {
if ( mLineStarts[ i ] != -1 && pos >= mLineStarts[ i ] ) {
*lineNum = i;
@@ -1670,44 +1670,44 @@ int Fl_Text_Display::position_to_line( int pos, int *lineNum ) const {
\param[in] lineLen size of string in bytes
\param[in] leftChar, rightChar
\param[in] Y drawing position
- \param[in] bottomClip, leftClip, rightClip stop work when we reach the clipped
+ \param[in] bottomClip, leftClip, rightClip stop work when we reach the clipped
area. rightClip is the X position that we search in FIND_INDEX.
\retval DRAW_LINE index of last drawn character
\retval GET_WIDTH width in pixels of text segment if we would draw it
\retval FIND_INDEX index of character at given x position in window coordinates
\retval FIND_INDEX_FROM_ZERO index of character at given x position without scrolling and widget offsets
\todo we need to handle hidden hyphens and tabs here!
- \todo we handle all styles and selections
+ \todo we handle all styles and selections
\todo we must provide code to get pixel positions of the middle of a character as well
*/
int Fl_Text_Display::handle_vline(
- int mode,
+ int mode,
int lineStartPos, int lineLen, int leftChar, int rightChar,
int Y, int bottomClip,
int leftClip, int rightClip) const
{
IS_UTF8_ALIGNED2(buffer(), lineStartPos)
- // FIXME: we need to allow two modes for FIND_INDEX: one on the edge of the
+ // FIXME: we need to allow two modes for FIND_INDEX: one on the edge of the
// FIXME: character for selection, and one on the character center for cursors.
int i, X, startX, startIndex, style, charStyle;
char *lineStr;
-
+
if ( lineStartPos == -1 ) {
lineStr = NULL;
} else {
lineStr = mBuffer->text_range( lineStartPos, lineStartPos + lineLen );
}
-
+
if (mode==GET_WIDTH) {
X = 0;
} else if (mode==FIND_INDEX_FROM_ZERO) {
- X = 0;
+ X = 0;
mode = FIND_INDEX;
} else {
X = text_area.x - mHorizOffset;
}
-
+
startX = X;
startIndex = 0;
if (!lineStr) {
@@ -1722,7 +1722,7 @@ int Fl_Text_Display::handle_vline(
}
return 0;
}
-
+
char currChar = 0, prevChar = 0;
// draw the line
style = position_style(lineStartPos, lineLen, 0);
@@ -1795,13 +1795,13 @@ int Fl_Text_Display::handle_vline(
free(lineStr);
return startX+w;
}
-
+
// clear the rest of the line
startX += w;
style = position_style(lineStartPos, lineLen, i);
if (mode==DRAW_LINE)
draw_string( style|BG_ONLY_MASK, startX, Y, text_area.x+text_area.w, lineStr, lineLen );
-
+
free(lineStr);
IS_UTF8_ALIGNED2(buffer(), (lineStartPos+lineLen))
return lineStartPos + lineLen;
@@ -1824,10 +1824,10 @@ int Fl_Text_Display::find_x(const char *s, int len, int style, int x) const {
while (i<len) {
int cl = fl_utf8len1(s[i]);
int w = int( string_width(s, i+cl, style) );
- if (w>x)
+ if (w>x)
return i;
i += cl;
- }
+ }
return len;
}
@@ -1835,13 +1835,13 @@ int Fl_Text_Display::find_x(const char *s, int len, int style, int x) const {
/**
\brief Draw a single line of text.
-
+
Draw the text on a single line represented by \p visLineNum (the
number of lines down from the top of the display), limited by
\p leftClip and \p rightClip window coordinates and \p leftCharIndex and
\p rightCharIndex character positions (not including the character at
position \p rightCharIndex).
-
+
\param visLineNum index of line in the visible line number lookup
\param leftClip, rightClip pixel position of clipped area
\param leftCharIndex, rightCharIndex index into line of segment that we want to draw
@@ -1849,19 +1849,19 @@ int Fl_Text_Display::find_x(const char *s, int len, int style, int x) const {
void Fl_Text_Display::draw_vline(int visLineNum, int leftClip, int rightClip,
int leftCharIndex, int rightCharIndex) {
int Y, lineStartPos, lineLen, fontHeight;
-
+
// printf("draw_vline(visLineNum=%d, leftClip=%d, rightClip=%d, leftCharIndex=%d, rightCharIndex=%d)\n",
// visLineNum, leftClip, rightClip, leftCharIndex, rightCharIndex);
// printf("nNVisibleLines=%d\n", mNVisibleLines);
-
+
/* If line is not displayed, skip it */
if ( visLineNum < 0 || visLineNum >= mNVisibleLines )
return;
-
+
/* Calculate Y coordinate of the string to draw */
fontHeight = mMaxsize;
Y = text_area.y + visLineNum * fontHeight;
-
+
/* Get the text, length, and buffer position of the line to display */
lineStartPos = mLineStarts[ visLineNum ];
if ( lineStartPos == -1 ) {
@@ -1869,12 +1869,12 @@ void Fl_Text_Display::draw_vline(int visLineNum, int leftClip, int rightClip,
} else {
lineLen = vline_length( visLineNum );
}
-
+
/* Shrink the clipping range to the active display area */
leftClip = max( text_area.x, leftClip );
rightClip = min( rightClip, text_area.x + text_area.w );
-
- handle_vline(DRAW_LINE,
+
+ handle_vline(DRAW_LINE,
lineStartPos, lineLen, leftCharIndex, rightCharIndex,
Y, Y+fontHeight, leftClip, rightClip);
return;
@@ -1884,27 +1884,27 @@ void Fl_Text_Display::draw_vline(int visLineNum, int leftClip, int rightClip,
/**
\brief Draw a text segment in a single style.
-
+
Draw a string or blank area according to parameter \p style, using the
appropriate colors and drawing method for that style, with top left
corner at \p X, \p Y. If style says to draw text, use \p string as
source of characters, and draw \p nChars, if style is FILL, erase
rectangle where text would have drawn from \p X to \p toX and from
\p Y to the maximum y extent of the current font(s).
-
+
\param style index into style lookup table
\param X, Y drawing origin
\param toX rightmost position if this is a fill operation
\param string text if this is a drawing operation
\param nChars number of characters to draw
*/
-void Fl_Text_Display::draw_string(int style,
+void Fl_Text_Display::draw_string(int style,
int X, int Y, int toX,
const char *string, int nChars) const {
IS_UTF8_ALIGNED(string)
const Style_Table_Entry * styleRec;
-
+
/* Draw blank area rather than text, if that was the request */
if ( style & FILL_MASK ) {
if (style & TEXT_ONLY_MASK) return;
@@ -1915,21 +1915,21 @@ void Fl_Text_Display::draw_string(int style,
for normal drawing, or drawing within a Fl_Text_Selection or highlight are
pre-allocated and pre-configured. For syntax highlighting, GCs are
configured here, on the fly. */
-
+
Fl_Font font = textfont();
int fsize = textsize();
Fl_Color foreground;
Fl_Color background;
-
+
if ( style & STYLE_LOOKUP_MASK ) {
int si = (style & STYLE_LOOKUP_MASK) - 'A';
if (si < 0) si = 0;
else if (si >= mNStyles) si = mNStyles - 1;
-
+
styleRec = mStyleTable + si;
font = styleRec->font;
fsize = styleRec->size;
-
+
if (style & PRIMARY_MASK) {
if (Fl::focus() == (Fl_Widget*)this) background = selection_color();
else background = fl_color_average(color(), selection_color(), 0.4f);
@@ -1950,7 +1950,7 @@ void Fl_Text_Display::draw_string(int style,
foreground = textcolor();
background = color();
}
-
+
if (!(style & TEXT_ONLY_MASK)) {
fl_color( background );
fl_rectf( X, Y, toX - X, mMaxsize );
@@ -1967,7 +1967,7 @@ void Fl_Text_Display::draw_string(int style,
fl_pop_clip();
#endif
}
-
+
// CET - FIXME
/* If any space around the character remains unfilled (due to use of
different sized fonts for highlighting), fill in above or below
@@ -1980,7 +1980,7 @@ void Fl_Text_Display::draw_string(int style,
mDescent - fs->descent);
*/
/* Underline if style is secondary Fl_Text_Selection */
-
+
/*
if (style & SECONDARY_MASK)
XDrawLine(XtDisplay(mW), XtWindow(mW), gc, x,
@@ -1992,17 +1992,17 @@ void Fl_Text_Display::draw_string(int style,
/**
\brief Clear a rectangle with the appropriate background color for \p style.
-
+
\param style index into style table
\param X, Y, width, height size and position of background area
*/
-void Fl_Text_Display::clear_rect(int style,
+void Fl_Text_Display::clear_rect(int style,
int X, int Y,
int width, int height) const {
/* A width of zero means "clear to end of window" to XClearArea */
if ( width == 0 )
return;
-
+
if (style & PRIMARY_MASK) {
if (Fl::focus()==(Fl_Widget*)this) {
fl_color(selection_color());
@@ -2025,7 +2025,7 @@ void Fl_Text_Display::clear_rect(int style,
/**
\brief Draw a cursor with top center at \p X, \p Y.
-
+
\param X, Y cursor position in pixels
*/
void Fl_Text_Display::draw_cursor( int X, int Y ) {
@@ -2042,17 +2042,17 @@ void Fl_Text_Display::draw_cursor( int X, int Y ) {
int nSegs = 0;
int fontHeight = mMaxsize;
int bot = Y + fontHeight - 1;
-
+
if ( X < text_area.x - 1 || X > text_area.x + text_area.w )
return;
-
+
/* For cursors other than the block, make them around 2/3 of a character
width, rounded to an even number of pixels so that X will draw an
odd number centered on the stem at x. */
cursorWidth = 4; //(fontWidth/3) * 2;
left = X - cursorWidth / 2;
right = left + cursorWidth;
-
+
/* Create segments and draw cursor */
if ( mCursorStyle == CARET_CURSOR ) {
midY = bot - fontHeight / 5;
@@ -2088,7 +2088,7 @@ void Fl_Text_Display::draw_cursor( int X, int Y ) {
nSegs = 4;
}
fl_color( mCursor_color );
-
+
for ( int k = 0; k < nSegs; k++ ) {
fl_line( segs[ k ].x1, segs[ k ].y1, segs[ k ].x2, segs[ k ].y2 );
}
@@ -2119,19 +2119,19 @@ void Fl_Text_Display::draw_cursor( int X, int Y ) {
\param lineIndex position of character within line
\return style for the given character
*/
-int Fl_Text_Display::position_style( int lineStartPos, int lineLen, int lineIndex) const
+int Fl_Text_Display::position_style( int lineStartPos, int lineLen, int lineIndex) const
{
IS_UTF8_ALIGNED2(buffer(), lineStartPos)
Fl_Text_Buffer * buf = mBuffer;
Fl_Text_Buffer *styleBuf = mStyleBuffer;
int pos, style = 0;
-
+
if ( lineStartPos == -1 || buf == NULL )
return FILL_MASK;
-
+
pos = lineStartPos + min( lineIndex, lineLen );
-
+
if ( lineIndex >= lineLen )
style = FILL_MASK;
else if ( styleBuf != NULL ) {
@@ -2154,7 +2154,7 @@ int Fl_Text_Display::position_style( int lineStartPos, int lineLen, int lineInde
/**
\brief Find the width of a string in the font of a particular style.
-
+
\param string the text
\param length number of bytes in string
\param style index into style table
@@ -2165,12 +2165,12 @@ double Fl_Text_Display::string_width( const char *string, int length, int style
Fl_Font font;
Fl_Fontsize fsize;
-
+
if ( mNStyles && (style & STYLE_LOOKUP_MASK) ) {
int si = (style & STYLE_LOOKUP_MASK) - 'A';
if (si < 0) si = 0;
else if (si >= mNStyles) si = mNStyles - 1;
-
+
font = mStyleTable[si].font;
fsize = mStyleTable[si].size;
} else {
@@ -2199,7 +2199,7 @@ double Fl_Text_Display::string_width( const char *string, int length, int style
int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) const {
int lineStart, lineLen, fontHeight;
int visLineNum;
-
+
/* Find the visible line number corresponding to the Y coordinate */
fontHeight = mMaxsize;
visLineNum = ( Y - text_area.y ) / fontHeight;
@@ -2207,19 +2207,19 @@ int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) const {
return mFirstChar;
if ( visLineNum >= mNVisibleLines )
visLineNum = mNVisibleLines - 1;
-
+
/* Find the position at the start of the line */
lineStart = mLineStarts[ visLineNum ];
-
+
/* If the line start was empty, return the last position in the buffer */
if ( lineStart == -1 )
return mBuffer->length();
-
+
/* Get the line text and its length */
lineLen = vline_length( visLineNum );
-
- return handle_vline(FIND_INDEX,
- lineStart, lineLen, 0, 0,
+
+ return handle_vline(FIND_INDEX,
+ lineStart, lineLen, 0, 0,
0, 0,
text_area.x, X);
}
@@ -2228,14 +2228,14 @@ int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) const {
/**
\brief Translate pixel coordinates into row and column.
-
+
Translate window coordinates to the nearest row and column number for
positioning the cursor. This, of course, makes no sense when the font is
proportional, since there are no absolute columns. The parameter posType
specifies how to interpret the position: CURSOR_POS means translate the
coordinates to the nearest position between characters, and CHARACTER_POS
means translate the position to the nearest character cell.
-
+
\param X, Y pixel coordinates
\param[out] row, column neares row and column
\param posType CURSOR_POS or CHARACTER_POS
@@ -2244,12 +2244,12 @@ void Fl_Text_Display::xy_to_rowcol( int X, int Y, int *row,
int *column, int posType ) const {
int fontHeight = mMaxsize;
int fontWidth = TMPFONTWIDTH; //mFontStruct->max_bounds.width;
-
+
/* Find the visible line number corresponding to the Y coordinate */
*row = ( Y - text_area.y ) / fontHeight;
if ( *row < 0 ) *row = 0;
if ( *row >= mNVisibleLines ) *row = mNVisibleLines - 1;
-
+
*column = ( ( X - text_area.x ) + mHorizOffset +
( posType == CURSOR_POS ? fontWidth / 2 : 0 ) ) / fontWidth;
if ( *column < 0 ) * column = 0;
@@ -2259,13 +2259,13 @@ void Fl_Text_Display::xy_to_rowcol( int X, int Y, int *row,
/**
\brief Offset line start counters for a new vertical scroll position.
-
+
Offset the line starts array, mTopLineNum, mFirstChar and lastChar, for a new
vertical scroll position given by newTopLineNum. If any currently displayed
lines will still be visible, salvage the line starts values, otherwise,
count lines from the nearest known line start (start or end of buffer, or
the closest value in the mLineStarts array)
-
+
\param newTopLineNum index into buffer
*/
void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
@@ -2276,11 +2276,11 @@ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
int *lineStarts = mLineStarts;
int i, lastLineNum;
Fl_Text_Buffer *buf = mBuffer;
-
+
/* If there was no offset, nothing needs to be changed */
if ( lineDelta == 0 )
return;
-
+
/* Find the new value for mFirstChar by counting lines from the nearest
known line start (start or end of buffer, or the closest value in the
lineStarts array) */
@@ -2297,7 +2297,7 @@ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
} else {
mFirstChar = rewind_lines( buf->length(), mNBufferLines - newTopLineNum + 1 );
}
-
+
/* Fill in the line starts array */
if ( lineDelta < 0 && -lineDelta < nVisLines ) {
for ( i = nVisLines - 1; i >= -lineDelta; i-- )
@@ -2309,11 +2309,11 @@ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
calc_line_starts( nVisLines - lineDelta, nVisLines - 1 );
} else
calc_line_starts( 0, nVisLines );
-
+
/* Set lastChar and mTopLineNum */
calc_last_char();
mTopLineNum = newTopLineNum;
-
+
/* If we're numbering lines or being asked to maintain an absolute line
number, re-calculate the absolute line number */
absolute_top_line_number(oldFirstChar);
@@ -2337,7 +2337,7 @@ void Fl_Text_Display::offset_line_starts( int newTopLineNum ) {
\param[out] scrolled set to 1 if the text display needs to be scrolled
*/
void Fl_Text_Display::update_line_starts(int pos, int charsInserted,
- int charsDeleted, int linesInserted,
+ int charsDeleted, int linesInserted,
int linesDeleted, int *scrolled ) {
IS_UTF8_ALIGNED2(buffer(), pos)
@@ -2345,7 +2345,7 @@ void Fl_Text_Display::update_line_starts(int pos, int charsInserted,
int i, lineOfPos, lineOfEnd, nVisLines = mNVisibleLines;
int charDelta = charsInserted - charsDeleted;
int lineDelta = linesInserted - linesDeleted;
-
+
/* If all of the changes were before the displayed text, the display
doesn't change, just update the top line num and offset the line
start entries and first and last characters */
@@ -2358,7 +2358,7 @@ void Fl_Text_Display::update_line_starts(int pos, int charsInserted,
*scrolled = 0;
return;
}
-
+
/* The change began before the beginning of the displayed text, but
part or all of the displayed text was deleted */
if ( pos < mFirstChar ) {
@@ -2381,7 +2381,7 @@ void Fl_Text_Display::update_line_starts(int pos, int charsInserted,
*scrolled = 1;
return;
}
-
+
/* If the change was in the middle of the displayed text (it usually is),
salvage as much of the line starts array as possible by moving and
offsetting the entries after the changed area, and re-counting the
@@ -2413,7 +2413,7 @@ void Fl_Text_Display::update_line_starts(int pos, int charsInserted,
*scrolled = 0;
return;
}
-
+
/* Change was past the end of the displayed text, but displayable by virtue
of being an insert at the end of the buffer into visible blank lines */
if ( empty_vlines() ) {
@@ -2423,7 +2423,7 @@ void Fl_Text_Display::update_line_starts(int pos, int charsInserted,
*scrolled = 0;
return;
}
-
+
/* Change was beyond the end of the buffer and not visible, do nothing */
*scrolled = 0;
}
@@ -2432,21 +2432,21 @@ void Fl_Text_Display::update_line_starts(int pos, int charsInserted,
/**
\brief Update the line start arrays.
-
+
Scan through the text in the "textD"'s buffer and recalculate the line
starts array values beginning at index "startLine" and continuing through
(including) "endLine". It assumes that the line starts entry preceding
"startLine" (or mFirstChar if startLine is 0) is good, and re-counts
newlines to fill in the requested entries. Out of range values for
"startLine" and "endLine" are acceptable.
-
+
\param startLine, endLine range of lines to scan as line numbers
*/
void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) {
int startPos, bufLen = mBuffer->length();
int line, lineEnd, nextLineStart, nVis = mNVisibleLines;
int *lineStarts = mLineStarts;
-
+
/* Clean up (possibly) messy input parameters */
if ( endLine < 0 ) endLine = 0;
if ( endLine >= nVis ) endLine = nVis - 1;
@@ -2454,14 +2454,14 @@ void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) {
if ( startLine >= nVis ) startLine = nVis - 1;
if ( startLine > endLine )
return;
-
+
/* Find the last known good line number -> position mapping */
if ( startLine == 0 ) {
lineStarts[ 0 ] = mFirstChar;
startLine = 1;
}
startPos = lineStarts[ startLine - 1 ];
-
+
/* If the starting position is already past the end of the text,
fill in -1's (means no text on line) and return */
if ( startPos == -1 ) {
@@ -2469,7 +2469,7 @@ void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) {
lineStarts[ line ] = -1;
return;
}
-
+
/* Loop searching for ends of lines and storing the positions of the
start of the next line in lineStarts */
for ( line = startLine; line <= endLine; line++ ) {
@@ -2489,7 +2489,7 @@ void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) {
}
lineStarts[ line ] = startPos;
}
-
+
/* Set any entries beyond the end of the text to -1 */
for ( ; line <= endLine; line++ )
lineStarts[ line ] = -1;
@@ -2499,7 +2499,7 @@ void Fl_Text_Display::calc_line_starts( int startLine, int endLine ) {
/**
\brief Update last display character index.
-
+
Given a Fl_Text_Display with a complete, up-to-date lineStarts array, update
the lastChar entry to point to the last buffer position displayed.
*/
@@ -2511,7 +2511,7 @@ void Fl_Text_Display::calc_last_char() {
-/**
+/**
\brief Scrolls the current buffer to start at the specified line and column.
\param topLineNum top line number
\param horizOffset column number
@@ -2525,7 +2525,7 @@ void Fl_Text_Display::scroll(int topLineNum, int horizOffset) {
-/**
+/**
\brief Scrolls the current buffer to start at the specified line and column.
\param topLineNum top line number
\param horizOffset in pixels
@@ -2536,23 +2536,23 @@ int Fl_Text_Display::scroll_(int topLineNum, int horizOffset) {
if (topLineNum > mNBufferLines + 3 - mNVisibleLines)
topLineNum = mNBufferLines + 3 - mNVisibleLines;
if (topLineNum < 1) topLineNum = 1;
-
+
if (horizOffset > longest_vline() - text_area.w)
horizOffset = longest_vline() - text_area.w;
if (horizOffset < 0) horizOffset = 0;
-
+
/* Do nothing if scroll position hasn't actually changed or there's no
window to draw in yet */
if (mHorizOffset == horizOffset && mTopLineNum == topLineNum)
return 0;
-
+
/* If the vertical scroll position has changed, update the line
starts array and related counters in the text display */
offset_line_starts(topLineNum);
-
+
/* Just setting mHorizOffset is enough information for redisplay */
mHorizOffset = horizOffset;
-
+
// redraw all text
damage(FL_DAMAGE_EXPOSE);
return 1;
@@ -2562,7 +2562,7 @@ int Fl_Text_Display::scroll_(int topLineNum, int horizOffset) {
/**
\brief Update vertical scrollbar.
-
+
Update the minimum, maximum, slider size, page increment, and value
for vertical scrollbar.
*/
@@ -2576,7 +2576,7 @@ void Fl_Text_Display::update_v_scrollbar() {
" mTopLineNum=%d, mNVisibleLines=%d, mNBufferLines=%d\n",
mTopLineNum, mNVisibleLines, mNBufferLines);
#endif // DEBUG
-
+
mVScrollBar->value(mTopLineNum, mNVisibleLines, 1, mNBufferLines+2);
mVScrollBar->linesize(3);
}
@@ -2584,7 +2584,7 @@ void Fl_Text_Display::update_v_scrollbar() {
/**
\brief Update vertical scrollbar.
-
+
Update the minimum, maximum, slider size, page increment, and value
for the horizontal scrollbar.
*/
@@ -2616,12 +2616,12 @@ void Fl_Text_Display::h_scrollbar_cb(Fl_Scrollbar* b, Fl_Text_Display* textD) {
/**
- \brief Refresh the line number area.
-
- If clearAll is False, writes only over the character cell areas. Setting
- clearAll to True will clear out any stray marks outside of the character cell
+ \brief Refresh the line number area.
+
+ If clearAll is False, writes only over the character cell areas. Setting
+ clearAll to True will clear out any stray marks outside of the character cell
area, which might have been left from before a resize or font change.
-
+
This function is not used.
*/
void Fl_Text_Display::draw_line_numbers(bool /*clearAll*/) {
@@ -2630,12 +2630,12 @@ void Fl_Text_Display::draw_line_numbers(bool /*clearAll*/) {
char lineNumString[12];
int lineHeight = mMaxsize ? mMaxsize : textsize_;
int charWidth = TMPFONTWIDTH; //mFontStruct->max_bounds.width;
-
+
/* Don't draw if mLineNumWidth == 0 (line numbers are hidden), or widget is
not yet realized */
if (mLineNumWidth == 0 || visible_r())
return;
-
+
/* GC is allocated on demand, since not everyone will use line numbering */
if (textD->lineNumGC == NULL) {
XGCValues values;
@@ -2645,12 +2645,12 @@ void Fl_Text_Display::draw_line_numbers(bool /*clearAll*/) {
textD->lineNumGC = XtGetGC(textD->w,
GCFont| GCForeground | GCBackground, &values);
}
-
+
/* Erase the previous contents of the line number area, if requested */
if (clearAll)
XClearArea(XtDisplay(textD->w), XtWindow(textD->w), textD->lineNumLeft,
textD->top, textD->lineNumWidth, textD->height, False);
-
+
/* Draw the line numbers, aligned to the text */
nCols = min(11, textD->lineNumWidth / charWidth);
y = textD->top;
@@ -2694,9 +2694,9 @@ static int countlines( const char *string ) {
const char * c;
int lineCount = 0;
-
+
if (!string) return 0;
-
+
for ( c = string; *c != '\0'; c++ )
if ( *c == '\n' ) lineCount++;
return lineCount;
@@ -2731,35 +2731,35 @@ int Fl_Text_Display::empty_vlines() const {
/**
\brief Count number of bytes in a visible line.
-
+
Return the length of a line (number of bytes) by examining
entries in the line starts array rather than by scanning for newlines.
-
+
\param visLineNum index of line in visible line array
\return number of bytes in this line
*/
int Fl_Text_Display::vline_length( int visLineNum ) const {
int nextLineStart, lineStartPos;
-
+
if (visLineNum < 0 || visLineNum >= mNVisibleLines)
return (0);
-
+
lineStartPos = mLineStarts[ visLineNum ];
-
+
if ( lineStartPos == -1 )
return 0;
-
+
if ( visLineNum + 1 >= mNVisibleLines )
return mLastChar - lineStartPos;
-
+
nextLineStart = mLineStarts[ visLineNum + 1 ];
if ( nextLineStart == -1 )
return mLastChar - lineStartPos;
-
+
int nextLineStartMinus1 = buffer()->prev_char(nextLineStart);
if (wrap_uses_character(nextLineStartMinus1))
return nextLineStartMinus1 - lineStartPos;
-
+
return nextLineStart - lineStartPos;
}
@@ -2767,7 +2767,7 @@ int Fl_Text_Display::vline_length( int visLineNum ) const {
/**
\brief Wrapping calculations.
-
+
When continuous wrap is on, and the user inserts or deletes characters,
wrapping can happen before and beyond the changed position. This routine
finds the extent of the changes, and counts the deleted and inserted lines
@@ -2775,7 +2775,7 @@ int Fl_Text_Display::vline_length( int visLineNum ) const {
what has to be counted and re-displayed, so the results can be useful
both for delimiting where the line starts need to be recalculated, and
for deciding what part of the text to redisplay.
-
+
\param deletedText
\param pos
\param nInserted
@@ -2786,7 +2786,7 @@ int Fl_Text_Display::vline_length( int visLineNum ) const {
\param linesDeleted
*/
void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
- int nInserted, int nDeleted,
+ int nInserted, int nDeleted,
int *modRangeStart, int *modRangeEnd,
int *linesInserted, int *linesDeleted) {
IS_UTF8_ALIGNED(deletedText)
@@ -2798,7 +2798,7 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
int *lineStarts = mLineStarts;
int countFrom, countTo, lineStart, adjLineStart, i;
int visLineNum = 0, nLines = 0;
-
+
/*
** Determine where to begin searching: either the previous newline, or
** if possible, limit to the start of the (original) previous displayed
@@ -2819,9 +2819,9 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
} else {
countFrom = buf->line_start(pos);
}
-
+
IS_UTF8_ALIGNED2(buf, countFrom)
-
+
/*
** Move forward through the (new) text one line at a time, counting
** displayed lines, and looking for either a real newline, or for the
@@ -2830,7 +2830,7 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
lineStart = countFrom;
*modRangeStart = countFrom;
for (;;) {
-
+
/* advance to the next line. If the line ended in a real newline
or the end of the buffer, that's far enough */
wrapped_line_counter(buf, lineStart, buf->length(), 1, true, 0,
@@ -2850,16 +2850,16 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
*modRangeEnd = lineStart;
break;
}
-
+
/* Don't try to resync in continuous wrap mode with non-fixed font
sizes; it would result in a chicken-and-egg dependency between
- the calculations for the inserted and the deleted lines.
+ the calculations for the inserted and the deleted lines.
If we're in that mode, the number of deleted lines is calculated in
advance, without resynchronization, so we shouldn't resynchronize
for the inserted lines either. */
if (mSuppressResync)
continue;
-
+
/* check for synchronization with the original line starts array
before pos, if so, the modified range can begin later */
if (lineStart <= pos) {
@@ -2875,7 +2875,7 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
} else
*modRangeStart = min(*modRangeStart, buf->prev_char(lineStart));
}
-
+
/* check for synchronization with the original line starts array
after pos, if so, the modified range can end early */
else if (lineStart > pos + nInserted) {
@@ -2891,8 +2891,8 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
}
}
*linesInserted = nLines;
-
-
+
+
/* Count deleted lines between countFrom and countTo as the text existed
before the modification (that is, as if the text between pos and
pos+nInserted were replaced by "deletedText"). This extra context is
@@ -2900,14 +2900,14 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
as a result of adding or deleting text in the region. This is done by
creating a textBuffer containing the deleted text and the necessary
additional context, and calling the wrappedLineCounter on it.
-
+
NOTE: This must not be done in continuous wrap mode when the font
width is not fixed. In that case, the calculation would try
to access style information that is no longer available (deleted
- text), or out of date (updated highlighting), possibly leading
+ text), or out of date (updated highlighting), possibly leading
to completely wrong calculations and/or even crashes eventually.
(This is not theoretical; it really happened.)
-
+
In that case, the calculation of the number of deleted lines
has happened before the buffer was modified (only in that case,
because resynchronization of the line starts is impossible
@@ -2918,7 +2918,7 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
mSuppressResync = 0;
return;
}
-
+
length = (pos-countFrom) + nDeleted +(countTo-(pos+nInserted));
deletedTextBuf = new Fl_Text_Buffer(length);
deletedTextBuf->copy(buffer(), countFrom, pos, 0);
@@ -2927,7 +2927,7 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
deletedTextBuf->copy(buffer(), pos+nInserted, countTo, pos-countFrom+nDeleted);
/* Note that we need to take into account an offset for the style buffer:
the deletedTextBuf can be out of sync with the style buffer. */
- wrapped_line_counter(deletedTextBuf, 0, length, INT_MAX, true, countFrom,
+ wrapped_line_counter(deletedTextBuf, 0, length, INT_MAX, true, countFrom,
&retPos, &retLines, &retLineStart, &retLineEnd, false);
delete deletedTextBuf;
*linesDeleted = retLines;
@@ -2938,14 +2938,14 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
/**
\brief Wrapping calculations.
-
+
This is a stripped-down version of the findWrapRange() function above,
intended to be used to calculate the number of "deleted" lines during
a buffer modification. It is called _before_ the modification takes place.
-
+
This function should only be called in continuous wrap mode with a
non-fixed font width. In that case, it is impossible to calculate
- the number of deleted lines, because the necessary style information
+ the number of deleted lines, because the necessary style information
is no longer available _after_ the modification. In other cases, we
can still perform the calculation afterwards (possibly even more
efficiently).
@@ -2978,7 +2978,7 @@ void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) {
countFrom = buf->line_start(pos);
} else
countFrom = buf->line_start(pos);
-
+
/*
** Move forward through the (new) text one line at a time, counting
** displayed lines, and looking for either a real newline, or for the
@@ -3000,15 +3000,15 @@ void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) {
if (lineStart > pos + nDeleted && buf->char_at(lineStart-1) == '\n') {
break;
}
-
- /* Unlike in the findWrapRange() function above, we don't try to
- resync with the line starts, because we don't know the length
- of the inserted text yet, nor the updated style information.
-
+
+ /* Unlike in the findWrapRange() function above, we don't try to
+ resync with the line starts, because we don't know the length
+ of the inserted text yet, nor the updated style information.
+
Because of that, we also shouldn't resync with the line starts
after the modification either, because we must perform the
- calculations for the deleted and inserted lines in the same way.
-
+ calculations for the deleted and inserted lines in the same way.
+
This can result in some unnecessary recalculation and redrawing
overhead, and therefore we should only use this two-phase mode
of calculation when it's really needed (continuous wrap + variable
@@ -3022,7 +3022,7 @@ void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) {
/**
\brief Wrapping calculations.
-
+
Count forward from startPos to either maxPos or maxLines (whichever is
reached first), and return all relevant positions and line count.
The provided textBuffer may differ from the actual text buffer of the
@@ -3038,7 +3038,7 @@ void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) {
\param styleBufOffset
\param[out] retPos Position where counting ended. When counting lines, the
- position returned is the start of the line "maxLines" lines
+ position returned is the start of the line "maxLines" lines
beyond "startPos".
\param[out] retLines Number of line breaks counted
\param[out] retLineStart Start of the line where counting ended
@@ -3057,21 +3057,21 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
double width;
int nLines = 0;
unsigned int c;
-
+
/* Set the wrap margin to the wrap column or the view width */
if (mWrapMarginPix != 0) {
wrapMarginPix = mWrapMarginPix;
} else {
wrapMarginPix = text_area.w;
}
-
+
/* Find the start of the line if the start pos is not marked as a
line start. */
if (startPosIsLineStart)
lineStart = startPos;
else
lineStart = line_start(startPos);
-
+
/*
** Loop until position exceeds maxPos or line count exceeds maxLines.
** (actually, continues beyond maxPos to end of line containing maxPos,
@@ -3081,7 +3081,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
width = 0;
for (p=lineStart; p<buf->length(); p=buf->next_char(p)) {
c = buf->char_at(p); // UCS-4
-
+
/* If the character was a newline, count the line and start over,
otherwise, add it to the width and column counts */
if (c == '\n') {
@@ -3108,11 +3108,11 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
const char *s = buf->address(p);
colNum++;
// FIXME: it is not a good idea to simply add character widths because on
- // some platforms, the width is a floating point value and depends on the
+ // some platforms, the width is a floating point value and depends on the
// previous character as well.
width += measure_proportional_character(s, (int)width, p+styleBufOffset);
}
-
+
/* If character exceeded wrap margin, find the break point and wrap there */
if (width > wrapMarginPix) {
foundBreak = false;
@@ -3124,7 +3124,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
width = 0;
int iMax = buf->next_char(p);
for (i=buf->next_char(b); i<iMax; i = buf->next_char(i)) {
- width += measure_proportional_character(buf->address(i), (int)width,
+ width += measure_proportional_character(buf->address(i), (int)width,
i+styleBufOffset);
colNum++;
}
@@ -3156,11 +3156,11 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
lineStart = newLineStart;
}
}
-
+
/* reached end of buffer before reaching pos or line target */
*retPos = buf->length();
*retLines = nLines;
- if (countLastLineMissingNewLine && colNum > 0)
+ if (countLastLineMissingNewLine && colNum > 0)
*retLines = buf->next_char(*retLines);
*retLineStart = lineStart;
*retLineEnd = buf->length();
@@ -3170,7 +3170,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
/**
\brief Wrapping calculations.
-
+
Measure the width in pixels of the first character of string "s" at a
particular column "colNum" and buffer position "pos". This is for measuring
characters in proportional or mixed-width highlighting fonts.
@@ -3183,7 +3183,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
width syntax highlighting cases where things don't redraw properly for
insertion/deletion, though static display and wrapping and resizing
should now be solid because they are now used for online help display.
-
+
\param s text string
\param xPix x pixel position needed for calculating tab widths
\param pos offset within string
@@ -3191,12 +3191,12 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
*/
double Fl_Text_Display::measure_proportional_character(const char *s, int xPix, int pos) const {
IS_UTF8_ALIGNED(s)
-
+
if (*s=='\t') {
int tab = (int)col_to_x(mBuffer->tab_distance());
return (((xPix/tab)+1)*tab) - xPix;
}
-
+
int charLen = fl_utf8len1(*s), style = 0;
if (mStyleBuffer) {
style = mStyleBuffer->byte_at(pos);
@@ -3207,8 +3207,8 @@ double Fl_Text_Display::measure_proportional_character(const char *s, int xPix,
/**
- \brief Finds both the end of the current line and the start of the next line.
-
+ \brief Finds both the end of the current line and the start of the next line.
+
Why?
In continuous wrap mode, if you need to know both, figuring out one from the
other can be expensive or error prone. The problem comes when there's a
@@ -3217,7 +3217,7 @@ double Fl_Text_Display::measure_proportional_character(const char *s, int xPix,
whether the trailing space or tab is being used as a line break or just a
normal character, and to find that out would otherwise require counting all
the way back to the beginning of the line.
-
+
\param startPos
\param startPosIsLineStart
\param[out] lineEnd
@@ -3228,7 +3228,7 @@ void Fl_Text_Display::find_line_end(int startPos, bool startPosIsLineStart,
IS_UTF8_ALIGNED2(buffer(), startPos)
int retLines, retLineStart;
-
+
/* if we're not wrapping use more efficient BufEndOfLine */
if (!mContinuousWrap) {
int le = buffer()->line_end(startPos);
@@ -3237,7 +3237,7 @@ void Fl_Text_Display::find_line_end(int startPos, bool startPosIsLineStart,
*nextLineStart = min(buffer()->length(), ls);
return;
}
-
+
/* use the wrapped line counter routine to count forward one line */
wrapped_line_counter(buffer(), startPos, buffer()->length(),
1, startPosIsLineStart, 0, nextLineStart, &retLines,
@@ -3248,7 +3248,7 @@ void Fl_Text_Display::find_line_end(int startPos, bool startPosIsLineStart,
/**
\brief Check if the line break is caused by a \\n or by line wrapping.
-
+
Line breaks in continuous wrap mode usually happen at newlines or
whitespace. This line-terminating character is not included in line
width measurements and has a special status as a non-visible character.
@@ -3263,18 +3263,18 @@ void Fl_Text_Display::find_line_end(int startPos, bool startPosIsLineStart,
buffer, this function can't tell for certain whether a trailing space was
used as a wrap point, and just guesses that it wasn't. So if an exact
accounting is necessary, don't use this function.
-
+
\param lineEndPos index of character where the line wraps
\return 1 if a \\n character causes the line wrap
- */
+ */
int Fl_Text_Display::wrap_uses_character(int lineEndPos) const {
IS_UTF8_ALIGNED2(buffer(), lineEndPos)
unsigned int c;
-
+
if (!mContinuousWrap || lineEndPos == buffer()->length())
return 1;
-
+
c = buffer()->char_at(lineEndPos);
return c == '\n' || ((c == '\t' || c == ' ') &&
lineEndPos + 1 < buffer()->length());
@@ -3284,23 +3284,23 @@ int Fl_Text_Display::wrap_uses_character(int lineEndPos) const {
/**
\brief I don't know what this does!
-
+
Extend the range of a redraw request (from *start to *end) with additional
redraw requests resulting from changes to the attached style buffer (which
contains auxiliary information for coloring or styling text).
-
+
\param startpos ??
\param endpos ??
-
+
\todo Unicode?
*/
void Fl_Text_Display::extend_range_for_styles( int *startpos, int *endpos ) {
- IS_UTF8_ALIGNED2(buffer(), (*startpos))
- IS_UTF8_ALIGNED2(buffer(), (*endpos))
-
+ IS_UTF8_ALIGNED2(buffer(), (*startpos))
+ IS_UTF8_ALIGNED2(buffer(), (*endpos))
+
Fl_Text_Selection * sel = mStyleBuffer->primary_selection();
int extended = 0;
-
+
/* The peculiar protocol used here is that modifications to the style
buffer are marked by selecting them with the buffer's primary Fl_Text_Selection.
The style buffer is usually modified in response to a modify callback on
@@ -3316,23 +3316,23 @@ void Fl_Text_Display::extend_range_for_styles( int *startpos, int *endpos ) {
*startpos = sel->start();
// somewhere while deleting, alignment is lost. We do this just to be sure.
*startpos = buffer()->utf8_align(*startpos);
- IS_UTF8_ALIGNED2(buffer(), (*startpos))
+ IS_UTF8_ALIGNED2(buffer(), (*startpos))
extended = 1;
}
if ( sel->end() > *endpos ) {
*endpos = sel->end();
*endpos = buffer()->utf8_align(*endpos);
- IS_UTF8_ALIGNED2(buffer(), (*endpos))
+ IS_UTF8_ALIGNED2(buffer(), (*endpos))
extended = 1;
}
}
-
+
/* If the Fl_Text_Selection was extended due to a style change, and some of the
fonts don't match in spacing, extend redraw area to end of line to
redraw characters exposed by possible font size changes */
if ( extended )
*endpos = mBuffer->line_end( *endpos ) + 1;
-
+
IS_UTF8_ALIGNED2(buffer(), (*endpos))
}
@@ -3340,15 +3340,15 @@ void Fl_Text_Display::extend_range_for_styles( int *startpos, int *endpos ) {
/**
\brief Draw the widget.
-
+
This function tries to limit drawing to smaller areas if possible.
*/
void Fl_Text_Display::draw(void) {
// don't even try if there is no associated text buffer!
if (!buffer()) { draw_box(); return; }
-
+
fl_push_clip(x(),y(),w(),h()); // prevent drawing outside widget area
-
+
// draw the non-text, non-scrollbar areas.
if (damage() & FL_DAMAGE_ALL) {
// printf("drawing all (box = %d)\n", box());
@@ -3359,36 +3359,36 @@ void Fl_Text_Display::draw(void) {
// draw the box()
int W = w(), H = h();
draw_box(box(), x(), y(), W, H, color());
-
+
if (mHScrollBar->visible())
W -= scrollbar_width();
if (mVScrollBar->visible())
H -= scrollbar_width();
-
+
// left margin
fl_rectf(text_area.x-LEFT_MARGIN, text_area.y-TOP_MARGIN,
LEFT_MARGIN, text_area.h+TOP_MARGIN+BOTTOM_MARGIN,
color());
-
+
// right margin
fl_rectf(text_area.x+text_area.w, text_area.y-TOP_MARGIN,
RIGHT_MARGIN, text_area.h+TOP_MARGIN+BOTTOM_MARGIN,
color());
-
+
// top margin
fl_rectf(text_area.x, text_area.y-TOP_MARGIN,
text_area.w, TOP_MARGIN, color());
-
+
// bottom margin
fl_rectf(text_area.x, text_area.y+text_area.h,
text_area.w, BOTTOM_MARGIN, color());
-
+
// draw that little box in the corner of the scrollbars
if (mVScrollBar->visible() && mHScrollBar->visible())
fl_rectf(mVScrollBar->x(), mHScrollBar->y(),
mVScrollBar->w(), mHScrollBar->h(),
FL_GRAY);
-
+
// blank the previous cursor protrusions
}
else if (damage() & (FL_DAMAGE_SCROLL | FL_DAMAGE_EXPOSE)) {
@@ -3404,7 +3404,7 @@ void Fl_Text_Display::draw(void) {
RIGHT_MARGIN, mMaxsize, color());
fl_pop_clip();
}
-
+
// draw the scrollbars
if (damage() & (FL_DAMAGE_ALL | FL_DAMAGE_CHILD)) {
mVScrollBar->damage(FL_DAMAGE_ALL);
@@ -3412,7 +3412,7 @@ void Fl_Text_Display::draw(void) {
}
update_child(*mVScrollBar);
update_child(*mHScrollBar);
-
+
// draw all of the text
if (damage() & (FL_DAMAGE_ALL | FL_DAMAGE_EXPOSE)) {
//printf("drawing all text\n");
@@ -3441,7 +3441,7 @@ void Fl_Text_Display::draw(void) {
damage_range2_start = damage_range2_end = -1;
fl_pop_clip();
}
-
+
// draw the text cursor
if (damage() & (FL_DAMAGE_ALL | FL_DAMAGE_SCROLL | FL_DAMAGE_EXPOSE)
&& !buffer()->primary_selection()->selected() &&
@@ -3450,7 +3450,7 @@ void Fl_Text_Display::draw(void) {
text_area.y,
text_area.w+LEFT_MARGIN+RIGHT_MARGIN,
text_area.h);
-
+
int X, Y;
if (position_to_xy(mCursorPos, &X, &Y)) draw_cursor(X, Y);
// else puts("position_to_xy() failed - unable to draw cursor!");
@@ -3499,9 +3499,9 @@ void fl_text_drag_me(int pos, Fl_Text_Display* d) {
/**
\brief Timer callback for scroll events.
-
+
This timer event scrolls the text view proportionally to
- how far the mouse pointer has left the text area. This
+ how far the mouse pointer has left the text area. This
allows for smooth scrolling without "wiggeling" the mouse.
*/
void Fl_Text_Display::scroll_timer_cb(void *user_data) {
@@ -3545,7 +3545,7 @@ int Fl_Text_Display::handle(int event) {
event != FL_KEYBOARD && event != FL_KEYUP) {
return Fl_Group::handle(event);
}
-
+
switch (event) {
case FL_ENTER:
case FL_MOVE:
@@ -3557,24 +3557,24 @@ int Fl_Text_Display::handle(int event) {
} else {
return 0;
}
-
+
case FL_LEAVE:
case FL_HIDE:
if (active_r() && window()) {
window()->cursor(FL_CURSOR_DEFAULT);
-
+
return 1;
} else {
return 0;
}
-
+
case FL_PUSH: {
if (active_r() && window()) {
if (Fl::event_inside(text_area.x, text_area.y, text_area.w,
text_area.h)) window()->cursor(FL_CURSOR_INSERT);
else window()->cursor(FL_CURSOR_DEFAULT);
}
-
+
if (Fl::focus() != this) {
Fl::focus(this);
handle(FL_FOCUS);
@@ -3597,7 +3597,7 @@ int Fl_Text_Display::handle(int event) {
buffer()->select(word_start(pos), word_end(pos));
dragPos = word_start(pos);
}
-
+
if (buffer()->primary_selection()->selected())
insert_position(buffer()->primary_selection()->end());
else
@@ -3605,7 +3605,7 @@ int Fl_Text_Display::handle(int event) {
show_insert_position();
return 1;
}
-
+
case FL_DRAG: {
if (dragType==DRAG_NONE)
return 1;
@@ -3659,9 +3659,9 @@ int Fl_Text_Display::handle(int event) {
fl_text_drag_me(pos, this);
return 1;
}
-
+
case FL_RELEASE: {
- if (Fl::event_is_click() && (! Fl::event_clicks()) &&
+ if (Fl::event_is_click() && (! Fl::event_clicks()) &&
buffer()->primary_selection()->includes(dragPos) && !(Fl::event_state()&FL_SHIFT) ) {
buffer()->unselect(); // clicking in the selection: unselect and move cursor
insert_position(dragPos);
@@ -3676,7 +3676,7 @@ int Fl_Text_Display::handle(int event) {
Fl::remove_timeout(scroll_timer_cb, this);
scroll_direction = 0;
}
-
+
// convert from WORD or LINE selection to CHAR
/*if (insert_position() >= dragPos)
dragPos = buffer()->primary_selection()->start();
@@ -3684,17 +3684,17 @@ int Fl_Text_Display::handle(int event) {
dragPos = buffer()->primary_selection()->end();*/
dragType = DRAG_CHAR;
}
-
+
const char* copy = buffer()->selection_text();
if (*copy) Fl::copy(copy, strlen(copy), 0);
free((void*)copy);
return 1;
}
-
+
case FL_MOUSEWHEEL:
if (Fl::event_dy()) return mVScrollBar->handle(event);
else return mHScrollBar->handle(event);
-
+
case FL_UNFOCUS:
if (active_r() && window()) window()->cursor(FL_CURSOR_DEFAULT);
case FL_FOCUS:
@@ -3714,7 +3714,7 @@ int Fl_Text_Display::handle(int event) {
redisplay_range(start, end);
}
return 1;
-
+
case FL_KEYBOARD:
// Copy?
if ((Fl::event_state()&(FL_CTRL|FL_COMMAND)) && Fl::event_key()=='c') {
@@ -3724,7 +3724,7 @@ int Fl_Text_Display::handle(int event) {
free((void*)copy);
return 1;
}
-
+
// Select all ?
if ((Fl::event_state()&(FL_CTRL|FL_COMMAND)) && Fl::event_key()=='a') {
buffer()->select(0,buffer()->length());
@@ -3733,12 +3733,12 @@ int Fl_Text_Display::handle(int event) {
free((void*)copy);
return 1;
}
-
+
if (mVScrollBar->handle(event)) return 1;
if (mHScrollBar->handle(event)) return 1;
-
+
break;
-
+
case FL_SHORTCUT:
if (!(shortcut() ? Fl::test_shortcut(shortcut()) : test_shortcut()))
return 0;
@@ -3747,9 +3747,9 @@ int Fl_Text_Display::handle(int event) {
return 1;
}
break;
-
+
}
-
+
return 0;
}
@@ -3773,7 +3773,7 @@ double Fl_Text_Display::col_to_x(double col) const
{
if (!mColumnScale) {
// recalculate column scale value
- x_to_col(0);
+ x_to_col(0);
}
return col*mColumnScale;
}