summaryrefslogtreecommitdiff
path: root/src/Fl_Text_Display.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Fl_Text_Display.cxx')
-rw-r--r--src/Fl_Text_Display.cxx209
1 files changed, 101 insertions, 108 deletions
diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx
index ad31bd0ee..8b4450cfa 100644
--- a/src/Fl_Text_Display.cxx
+++ b/src/Fl_Text_Display.cxx
@@ -1,6 +1,4 @@
//
-// "$Id$"
-//
// Copyright 2001-2020 by Bill Spitzak and others.
// Original code Copyright Mark Edel. Permission to distribute under
// the LGPL for the FLTK library granted by Mark Edel.
@@ -11,9 +9,9 @@
//
// https://www.fltk.org/COPYING.php
//
-// Please report all bugs and problems on the following page:
+// Please see the following page on how to report bugs and issues:
//
-// https://www.fltk.org/str.php
+// https://www.fltk.org/bugs.php
//
// TODO: rendering of the "optional hyphen"
@@ -25,7 +23,7 @@
#include "flstring.h"
#include <limits.h>
#include <ctype.h>
-#include <string.h> // strdup()
+#include <string.h> // strdup()
#include <FL/Fl.H>
#include <FL/platform.H>
#include <FL/Fl_Text_Buffer.H>
@@ -39,7 +37,7 @@
// #define DEBUG
// #define DEBUG2
-#define LINENUM_LEFT_OF_VSCROLL // uncomment this line ...
+#define LINENUM_LEFT_OF_VSCROLL // uncomment this line ...
// ... if you want the line numbers to be drawn left of the vertical
// scrollbar (only if the vertical scrollbar is aligned left).
// This is the default.
@@ -137,7 +135,7 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
mMaxsize = 0;
mSuppressResync = 0;
mNLinesDeleted = 0;
- mModifyingTabDistance = 0; // XXX: UNUSED
+ mModifyingTabDistance = 0; // XXX: UNUSED
mColumnScale = 0;
mCursor_color = FL_FOREGROUND_COLOR;
@@ -148,7 +146,7 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
mVScrollBar = new Fl_Scrollbar(0,0,1,1);
mVScrollBar->callback((Fl_Callback*)v_scrollbar_cb, this);
- scrollbar_width_ = 0; // 0: default from Fl::scrollbar_size()
+ scrollbar_width_ = 0; // 0: default from Fl::scrollbar_size()
scrollbar_align_ = FL_ALIGN_BOTTOM_RIGHT;
dragPos = 0;
@@ -162,16 +160,16 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
text_area.h = 0;
shortcut_ = 0;
- textfont_ = FL_HELVETICA; // textfont()
- textsize_ = FL_NORMAL_SIZE; // textsize()
- textcolor_ = FL_FOREGROUND_COLOR; // textcolor()
+ textfont_ = FL_HELVETICA; // textfont()
+ textsize_ = FL_NORMAL_SIZE; // textsize()
+ textcolor_ = FL_FOREGROUND_COLOR; // textcolor()
mLineNumLeft = 0;
mLineNumWidth = 0;
linenumber_font_ = FL_HELVETICA;
linenumber_size_ = FL_NORMAL_SIZE;
linenumber_fgcolor_ = FL_INACTIVE_COLOR;
- linenumber_bgcolor_ = 53; // ~90% gray
+ linenumber_bgcolor_ = 53; // ~90% gray
linenumber_align_ = FL_ALIGN_RIGHT;
linenumber_format_ = strdup("%d");
@@ -189,7 +187,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.
+ and is not freed, nor are the style buffer or style table.
\see Fl_Text_Display::buffer(Fl_Text_Buffer* buf)
*/
@@ -216,12 +214,12 @@ Fl_Text_Display::~Fl_Text_Display() {
Use to also enable/disable line numbers.
A value of 0 disables line numbering, values >0 enable the line number display.
\param width The new width of the area for line numbers to appear, in pixels.
- 0 disables line numbers (default)
+ 0 disables line numbers (default)
*/
void Fl_Text_Display::linenumber_width(int width) {
if (width < 0) return;
mLineNumWidth = width;
- recalc_display(); // recalc line#s // resize(x(), y(), w(), h());
+ recalc_display(); // recalc line#s // resize(x(), y(), w(), h());
}
/**
@@ -344,7 +342,7 @@ const char* Fl_Text_Display::linenumber_format() const {
Multiple text widgets can be associated with the same text buffer.
\note The caller is responsible for the old (replaced) buffer (if any).
- This method does not delete the old buffer.
+ This method does not delete the old buffer.
\param buf attach this text buffer
*/
@@ -374,7 +372,7 @@ void Fl_Text_Display::buffer( Fl_Text_Buffer *buf ) {
}
/* Resize the widget to update the screen... */
- recalc_display(); // resize(x(), y(), w(), h());
+ recalc_display(); // resize(x(), y(), w(), h());
}
@@ -406,8 +404,8 @@ void Fl_Text_Display::buffer( Fl_Text_Buffer *buf ) {
\param cbArg an optional argument for the callback above, usually a pointer
to the Text Display.
- \todo "extendRangeForStyleMods" does not exist (might be a hangover
- from the port from nedit). Find the correct function.
+ \todo "extendRangeForStyleMods" does not exist (might be a hangover
+ from the port from nedit). Find the correct function.
*/
void Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer,
const Style_Table_Entry *styleTable,
@@ -454,11 +452,11 @@ void Fl_Text_Display::resize(int X, int Y, int W, int H) {
printf("Fl_Text_Display::resize(X=%d, Y=%d, W=%d, H=%d)\n", X, Y, W, H);
printf(" current size(x=%d, y=%d, w=%d, h=%d)\n", x(), y(), w(), h());
printf(" box_d* size(x=%d, y=%d, w=%d, h=%d)\n",
- Fl::box_dx(box()),Fl::box_dy(box()),Fl::box_dw(box()),Fl::box_dh(box()));
+ Fl::box_dx(box()),Fl::box_dy(box()),Fl::box_dw(box()),Fl::box_dh(box()));
printf(" text_area size(x=%d, y=%d, w=%d, h=%d)\n",
- text_area.x, text_area.y, text_area.w, text_area.h);
+ text_area.x, text_area.y, text_area.w, text_area.h);
printf(" mContinuousWrap=%d, mWrapMarginPix=%d\n",
- mContinuousWrap, mWrapMarginPix);
+ mContinuousWrap, mWrapMarginPix);
fflush(stdout);
#endif // DEBUG2
@@ -528,7 +526,7 @@ void Fl_Text_Display::recalc_display() {
#ifdef DEBUG2
printf("*** again ... text_area.w = %d, oldTAWidth = %d, diff = %d\n",
- text_area.w, oldTAWidth, text_area.w - oldTAWidth);
+ text_area.w, oldTAWidth, text_area.w - oldTAWidth);
#endif // DEBUG2
if (mContinuousWrap && !mWrapMarginPix && text_area.w != oldTAWidth) {
@@ -564,12 +562,12 @@ void Fl_Text_Display::recalc_display() {
/* Decide if the vertical scrollbar needs to be visible */
if (!mVScrollBar->visible() &&
- scrollbar_align() & (FL_ALIGN_LEFT|FL_ALIGN_RIGHT) &&
- mNBufferLines >= mNVisibleLines-(mContinuousWrap?0:1))
+ scrollbar_align() & (FL_ALIGN_LEFT|FL_ALIGN_RIGHT) &&
+ mNBufferLines >= mNVisibleLines-(mContinuousWrap?0:1))
{
- mVScrollBar->set_visible();
- text_area.w -= scrollsize;
- again = 1;
+ mVScrollBar->set_visible();
+ text_area.w -= scrollsize;
+ again = 1;
}
/*
@@ -596,7 +594,7 @@ void Fl_Text_Display::recalc_display() {
don't turn it off (ie mix both of your solutions). */
if (!mHScrollBar->visible() &&
- scrollbar_align() & (FL_ALIGN_TOP|FL_ALIGN_BOTTOM) &&
+ scrollbar_align() & (FL_ALIGN_TOP|FL_ALIGN_BOTTOM) &&
(mVScrollBar->visible() || longest_vline() > text_area.w))
{
char wrap_at_bounds = mContinuousWrap && (mWrapMarginPix<text_area.w);
@@ -636,23 +634,23 @@ void Fl_Text_Display::recalc_display() {
#endif
} else {
mVScrollBar->resize(X+W-scrollsize,
- text_area.y - TOP_MARGIN,
- scrollsize,
- text_area.h + TOP_MARGIN + BOTTOM_MARGIN);
+ text_area.y - TOP_MARGIN,
+ scrollsize,
+ text_area.h + TOP_MARGIN + BOTTOM_MARGIN);
}
}
if (mHScrollBar->visible()) {
if (scrollbar_align() & FL_ALIGN_TOP) {
mHScrollBar->resize(text_area.x - LEFT_MARGIN,
- Y,
- text_area.w + LEFT_MARGIN + RIGHT_MARGIN,
- scrollsize);
+ Y,
+ text_area.w + LEFT_MARGIN + RIGHT_MARGIN,
+ scrollsize);
} else {
mHScrollBar->resize(text_area.x - LEFT_MARGIN,
- Y + H - scrollsize,
- text_area.w + LEFT_MARGIN + RIGHT_MARGIN,
- scrollsize);
+ Y + H - scrollsize,
+ text_area.w + LEFT_MARGIN + RIGHT_MARGIN,
+ scrollsize);
}
}
@@ -899,10 +897,10 @@ void Fl_Text_Display::cursor_style(int style) {
Valid wrap modes are:
- - 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
- - WRAP_AT_BOUNDS : wrap text so that it fits into the widget width
+ - 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
+ - WRAP_AT_BOUNDS : wrap text so that it fits into the widget width
\param wrap new wrap mode (see above)
@@ -953,10 +951,10 @@ void Fl_Text_Display::wrap_mode(int wrap, int wrapMargin) {
mNBufferLines = 0;
mFirstChar = 0;
mTopLineNum = 1;
- mAbsTopLineNum = 1; // changed from 0 to 1 -- LZA / STR#2621
+ mAbsTopLineNum = 1; // changed from 0 to 1 -- LZA / STR#2621
}
- recalc_display(); // resize(x(), y(), w(), h());
+ recalc_display(); // resize(x(), y(), w(), h());
}
@@ -1065,7 +1063,7 @@ int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) const {
/* If position is not displayed, return false */
if ((pos < mFirstChar) ||
(pos > mLastChar && !empty_vlines()) ||
- (pos > buffer()->length()) ) { // STR #3231
+ (pos > buffer()->length()) ) { // STR #3231
return (*X=*Y=0); // make sure X & Y are set when it is out of view
}
@@ -1197,9 +1195,9 @@ int Fl_Text_Display::wrapped_column(int row, int column) const {
\param row
\return something unknown
- \todo What does this do and how is it useful? Column numbers mean little in
- this context. Which functions depend on this one?
- Function TextDXYToUnconstrainedPosition does not exist (nedit port?)
+ \todo What does this do and how is it useful? Column numbers mean little in
+ this context. Which functions depend on this one?
+ Function TextDXYToUnconstrainedPosition does not exist (nedit port?)
*/
int Fl_Text_Display::wrapped_row(int row) const {
if (!mContinuousWrap || row < 0 || row > mNVisibleLines)
@@ -1265,7 +1263,7 @@ void Fl_Text_Display::display_insert() {
*/
void Fl_Text_Display::show_insert_position() {
display_insert_position_hint = 1;
- recalc_display(); // resize(x(), y(), w(), h());
+ recalc_display(); // resize(x(), y(), w(), h());
}
@@ -1819,7 +1817,7 @@ void Fl_Text_Display::buffer_modified_cb( int pos, int nInserted, int nDeleted,
More specifically, this allows the line number reported in the statistics
line to be calibrated in absolute lines, rather than post-wrapped lines.
- \todo TextDPosToLineAndCol does not exist (nedit port?)
+ \todo TextDPosToLineAndCol does not exist (nedit port?)
*/
void Fl_Text_Display::maintain_absolute_top_line_number(int state) {
mNeedAbsTopLineNum = state;
@@ -1899,8 +1897,8 @@ void Fl_Text_Display::reset_absolute_top_line_number() {
Returns 1 if the line is displayed. In this case \p lineNum is the relative
line number.
- \param[in] pos byte position in buffer
- \param[out] lineNum relative line number of byte \p pos in buffer
+ \param[in] pos byte position in buffer
+ \param[out] lineNum relative line number of byte \p pos in buffer
\returns whether the character at byte position \p pos is currently displayed
\retval 0 \p pos is not displayed; \p lineNum is invalid (zero)
@@ -2286,11 +2284,11 @@ void Fl_Text_Display::draw_string(int style,
if (style & PRIMARY_MASK) {
if (Fl::focus() == (Fl_Widget*)this) {
- if (Fl::screen_driver()->has_marked_text() && Fl::compose_state)
+ if (Fl::screen_driver()->has_marked_text() && Fl::compose_state)
background = color();// Mac OS: underline marked text
- else
+ else
background = selection_color();
- }
+ }
else background = fl_color_average(color(), selection_color(), 0.4f);
} else if (style & HIGHLIGHT_MASK) {
if (Fl::focus() == (Fl_Widget*)this) background = fl_color_average(color(), selection_color(), 0.5f);
@@ -2893,7 +2891,7 @@ void Fl_Text_Display::calc_last_char() {
void Fl_Text_Display::scroll(int topLineNum, int horizOffset) {
mTopLineNumHint = topLineNum;
mHorizOffsetHint = horizOffset;
- recalc_display(); // resize(x(), y(), w(), h());
+ recalc_display(); // resize(x(), y(), w(), h());
}
@@ -2946,7 +2944,7 @@ void Fl_Text_Display::update_v_scrollbar() {
#ifdef DEBUG
printf("Fl_Text_Display::update_v_scrollbar():\n"
" mTopLineNum=%d, mNVisibleLines=%d, mNBufferLines=%d\n",
- mTopLineNum, mNVisibleLines, mNBufferLines);
+ mTopLineNum, mNVisibleLines, mNBufferLines);
#endif // DEBUG
mVScrollBar->value(mTopLineNum, mNVisibleLines, 1, mNBufferLines+1+(mContinuousWrap?0:1));
@@ -2988,8 +2986,8 @@ void Fl_Text_Display::h_scrollbar_cb(Fl_Scrollbar* b, Fl_Text_Display* textD) {
\brief Refresh the line number area.
\param clearAll -- (currently unused) If False, only draws the line number text,
does not clear the area behind it. If True, clears the area
- and redraws the text. Use False to avoid a 'flash' for
- single buffered windows.
+ and redraws the text. Use False to avoid a 'flash' for
+ single buffered windows.
*/
// This draw_line_numbers() method based on patch from
@@ -3046,16 +3044,16 @@ void Fl_Text_Display::draw_line_numbers(bool /*clearAll*/) {
for (visLine=0; visLine < mNVisibleLines; visLine++) {
lineStart = mLineStarts[visLine];
if (lineStart != -1 && (lineStart==0 || buffer()->char_at(lineStart-1)=='\n')) {
- sprintf(lineNumString, linenumber_format(), line);
- int xx = x() + xoff + 3,
- yy = Y,
- ww = mLineNumWidth - (3*2),
- hh = lineHeight;
- fl_draw(lineNumString, xx, yy, ww, hh, linenumber_align(), 0, 0);
- //DEBUG fl_rect(xx, yy, ww, hh);
- line++;
+ sprintf(lineNumString, linenumber_format(), line);
+ int xx = x() + xoff + 3,
+ yy = Y,
+ ww = mLineNumWidth - (3*2),
+ hh = lineHeight;
+ fl_draw(lineNumString, xx, yy, ww, hh, linenumber_align(), 0, 0);
+ //DEBUG fl_rect(xx, yy, ww, hh);
+ line++;
} else {
- if (visLine == 0) line++;
+ if (visLine == 0) line++;
}
Y += lineHeight;
}
@@ -3515,12 +3513,12 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
if (!foundBreak) { /* no whitespace, just break at margin */
newLineStart = max(p, buf->next_char(lineStart));
colNum++;
- if (b >= buf->length()) { // STR #2730
- width = 0;
- } else {
- const char *s = buf->address(b);
- width = measure_proportional_character(s, 0, p+styleBufOffset);
- }
+ if (b >= buf->length()) { // STR #2730
+ width = 0;
+ } else {
+ const char *s = buf->address(b);
+ width = measure_proportional_character(s, 0, p+styleBufOffset);
+ }
}
if (p >= maxPos) {
*retPos = maxPos;
@@ -3728,7 +3726,7 @@ 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
+ fl_push_clip(x(),y(),w(),h()); // prevent drawing outside widget area
// background color -- change if inactive
Fl_Color bgcolor = active_r() ? color() : fl_inactive(color());
@@ -3825,8 +3823,8 @@ void Fl_Text_Display::draw(void) {
int has_selection = buffer()->selection_position(&start, &end);
if (damage() & (FL_DAMAGE_ALL | FL_DAMAGE_SCROLL | FL_DAMAGE_EXPOSE)
&& (
- (Fl::screen_driver()->has_marked_text() && Fl::compose_state) ||
- (!has_selection) || mCursorPos < start || mCursorPos > end) &&
+ (Fl::screen_driver()->has_marked_text() && Fl::compose_state) ||
+ (!has_selection) || mCursorPos < start || mCursorPos > end) &&
mCursorOn && Fl::focus() == (Fl_Widget*)this ) {
fl_push_clip(text_area.x-LEFT_MARGIN,
text_area.y,
@@ -3938,9 +3936,9 @@ int Fl_Text_Display::handle(int event) {
case FL_MOVE:
if (active_r()) {
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);
- return 1;
+ text_area.h)) window()->cursor(FL_CURSOR_INSERT);
+ else window()->cursor(FL_CURSOR_DEFAULT);
+ return 1;
} else {
return 0;
}
@@ -3950,9 +3948,9 @@ int Fl_Text_Display::handle(int event) {
if (active_r() && window()) {
window()->cursor(FL_CURSOR_DEFAULT);
- return 1;
+ return 1;
} else {
- return 0;
+ return 0;
}
case FL_PUSH: {
@@ -3982,12 +3980,12 @@ int Fl_Text_Display::handle(int event) {
dragType = Fl::event_clicks();
if (dragType == DRAG_CHAR) {
buffer()->unselect();
-// Fl::copy("", 0, 0); /* removed for STR 2668 */
+// Fl::copy("", 0, 0); /* removed for STR 2668 */
}
else if (dragType == DRAG_WORD) {
buffer()->select(word_start(pos), word_end(pos));
- dragPos = word_start(pos);
- }
+ dragPos = word_start(pos);
+ }
if (buffer()->primary_selection()->selected())
insert_position(buffer()->primary_selection()->end());
@@ -4053,27 +4051,27 @@ int Fl_Text_Display::handle(int event) {
case FL_RELEASE: {
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);
- return 1;
+ buffer()->primary_selection()->includes(dragPos) && !(Fl::event_state()&FL_SHIFT) ) {
+ buffer()->unselect(); // clicking in the selection: unselect and move cursor
+ insert_position(dragPos);
+ return 1;
} else if (Fl::event_clicks() == DRAG_LINE && Fl::event_button() == FL_LEFT_MOUSE) {
buffer()->select(buffer()->line_start(dragPos), buffer()->next_char(buffer()->line_end(dragPos)));
- dragPos = line_start(dragPos);
- dragType = DRAG_CHAR;
+ dragPos = line_start(dragPos);
+ dragType = DRAG_CHAR;
} else {
- dragging = 0;
- if (scroll_direction) {
- 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();
- else
- dragPos = buffer()->primary_selection()->end();*/
- dragType = DRAG_CHAR;
+ dragging = 0;
+ if (scroll_direction) {
+ 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();
+ else
+ dragPos = buffer()->primary_selection()->end();*/
+ dragType = DRAG_CHAR;
}
const char* copy = buffer()->selection_text();
@@ -4168,8 +4166,3 @@ double Fl_Text_Display::col_to_x(double col) const
}
return col*mColumnScale;
}
-
-
-//
-// End of "$Id$".
-//