UTF8: Fl_Text_Display and related:

+ Constrained many Fl_Text_Display (get and measurement) methods to const.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6823 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Fabien Costantini
2009-07-04 00:57:46 +00:00
parent 691ab84503
commit 1b4b02f7a1
3 changed files with 51 additions and 51 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
CHANGES IN FLTK 1.3.0 CHANGES IN FLTK 1.3.0
- Corrected const methods of Fl_Text_Buffer, Fl_Text_Selection - Corrected const methods of Fl_Text_{Buffer|Display|Selection}
to be declared const, corrected an Fl_Text_Buffer attrib. typo to be declared const, corrected an Fl_Text_Buffer attrib. typo
- Fixed OpenGL shared context handling (STR #2135) - Fixed OpenGL shared context handling (STR #2135)
- Fixed gray-scale images with alpha channel (STR #2105) - Fixed gray-scale images with alpha channel (STR #2105)
+28 -28
View File
@@ -98,23 +98,23 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group {
Gets the current text buffer associated with the text widget. Gets the current text buffer associated with the text widget.
Multiple text widgets can be associated with the same text buffer. Multiple text widgets can be associated with the same text buffer.
*/ */
Fl_Text_Buffer* buffer() { return mBuffer; } Fl_Text_Buffer* buffer() const { return mBuffer; }
void redisplay_range(int start, int end); void redisplay_range(int start, int end);
void scroll(int topLineNum, int horizOffset); void scroll(int topLineNum, int horizOffset);
void insert(const char* text); void insert(const char* text);
void overstrike(const char* text); void overstrike(const char* text);
void insert_position(int newPos); void insert_position(int newPos);
/** Gets the position of the text insertion cursor for text display */ /** Gets the position of the text insertion cursor for text display */
int insert_position() { return mCursorPos; } int insert_position() const { return mCursorPos; }
int in_selection(int x, int y); int in_selection(int x, int y) const;
void show_insert_position(); void show_insert_position();
int move_right(); int move_right();
int move_left(); int move_left();
int move_up(); int move_up();
int move_down(); int move_down();
int count_lines(int start, int end, bool start_pos_is_line_start); int count_lines(int start, int end, bool start_pos_is_line_start) const;
int line_start(int pos); int line_start(int pos) const;
int line_end(int pos, bool start_pos_is_line_start); int line_end(int pos, bool start_pos_is_line_start) const;
int skip_lines(int startPos, int nLines, bool startPosIsLineStart); int skip_lines(int startPos, int nLines, bool startPosIsLineStart);
int rewind_lines(int startPos, int nLines); int rewind_lines(int startPos, int nLines);
void next_word(void); void next_word(void);
@@ -128,17 +128,17 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group {
/** Sets or gets the text cursor color. */ /** Sets or gets the text cursor color. */
void cursor_color(Fl_Color n) {mCursor_color = n;} void cursor_color(Fl_Color n) {mCursor_color = n;}
/** Sets or gets the width/height of the scrollbars. */ /** Sets or gets the width/height of the scrollbars. */
int scrollbar_width() { return scrollbar_width_; } int scrollbar_width() const { return scrollbar_width_; }
/** Sets or gets the width/height of the scrollbars. */ /** Sets or gets the width/height of the scrollbars. */
void scrollbar_width(int W) { scrollbar_width_ = W; } void scrollbar_width(int W) { scrollbar_width_ = W; }
/** Gets the scrollbar alignment type */ /** Gets the scrollbar alignment type */
Fl_Align scrollbar_align() { return scrollbar_align_; } Fl_Align scrollbar_align() const { return scrollbar_align_; }
/** Sets the scrollbar alignment type */ /** Sets the scrollbar alignment type */
void scrollbar_align(Fl_Align a) { scrollbar_align_ = a; } void scrollbar_align(Fl_Align a) { scrollbar_align_ = a; }
/** Moves the insert position to the beginning of the current word. */ /** Moves the insert position to the beginning of the current word. */
int word_start(int pos) { return buffer()->word_start(pos); } int word_start(int pos) const { return buffer()->word_start(pos); }
/** Moves the insert position to the end of the current word. */ /** Moves the insert position to the end of the current word. */
int word_end(int pos) { return buffer()->word_end(pos); } int word_end(int pos) const { return buffer()->word_end(pos); }
void highlight_data(Fl_Text_Buffer *styleBuffer, void highlight_data(Fl_Text_Buffer *styleBuffer,
@@ -148,7 +148,7 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group {
void *cbArg); void *cbArg);
int position_style(int lineStartPos, int lineLen, int lineIndex, int position_style(int lineStartPos, int lineLen, int lineIndex,
int dispIndex); int dispIndex) const;
/** \todo FIXME : get set methods pointing on shortcut_ /** \todo FIXME : get set methods pointing on shortcut_
have no effects as shortcut_ is unused in this class and derived! */ have no effects as shortcut_ is unused in this class and derived! */
int shortcut() const {return shortcut_;} int shortcut() const {return shortcut_;}
@@ -169,8 +169,8 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group {
/** Sets the default color of text in the widget. */ /** Sets the default color of text in the widget. */
void textcolor(unsigned n) {textcolor_ = n;} void textcolor(unsigned n) {textcolor_ = n;}
int wrapped_column(int row, int column); int wrapped_column(int row, int column) const;
int wrapped_row(int row); int wrapped_row(int row) const;
void wrap_mode(int wrap, int wrap_margin); void wrap_mode(int wrap, int wrap_margin);
virtual void resize(int X, int Y, int W, int H); virtual void resize(int X, int Y, int W, int H);
@@ -206,8 +206,8 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group {
void calc_last_char(); void calc_last_char();
int position_to_line( int pos, int* lineNum ); int position_to_line( int pos, int* lineNum ) const;
int string_width(const char* string, int length, int style); int string_width(const char* string, int length, int style) const;
static void scroll_timer_cb(void*); static void scroll_timer_cb(void*);
@@ -220,22 +220,22 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group {
static void v_scrollbar_cb( Fl_Scrollbar* w, Fl_Text_Display* d); static void v_scrollbar_cb( Fl_Scrollbar* w, Fl_Text_Display* d);
void update_v_scrollbar(); void update_v_scrollbar();
void update_h_scrollbar(); void update_h_scrollbar();
int measure_vline(int visLineNum); int measure_vline(int visLineNum) const;
int longest_vline(); int longest_vline() const;
int empty_vlines(); int empty_vlines() const;
int vline_length(int visLineNum); int vline_length(int visLineNum) const;
int xy_to_position(int x, int y, int PosType = CHARACTER_POS); int xy_to_position(int x, int y, int PosType = CHARACTER_POS) const;
void xy_to_rowcol(int x, int y, int* row, int* column, void xy_to_rowcol(int x, int y, int* row, int* column,
int PosType = CHARACTER_POS); int PosType = CHARACTER_POS) const;
int position_to_xy(int pos, int* x, int* y); int position_to_xy(int pos, int* x, int* y) const;
void maintain_absolute_top_line_number(int state); void maintain_absolute_top_line_number(int state);
int get_absolute_top_line_number(); int get_absolute_top_line_number() const;
void absolute_top_line_number(int oldFirstChar); void absolute_top_line_number(int oldFirstChar);
int maintaining_absolute_top_line_number(); int maintaining_absolute_top_line_number() const;
void reset_absolute_top_line_number(); void reset_absolute_top_line_number();
int position_to_linecol(int pos, int* lineNum, int* column); int position_to_linecol(int pos, int* lineNum, int* column) const;
void scroll_(int topLineNum, int horizOffset); void scroll_(int topLineNum, int horizOffset);
void extend_range_for_styles(int* start, int* end); void extend_range_for_styles(int* start, int* end);
@@ -248,11 +248,11 @@ class FL_EXPORT Fl_Text_Display: public Fl_Group {
int maxLines, bool startPosIsLineStart, int maxLines, bool startPosIsLineStart,
int styleBufOffset, int *retPos, int *retLines, int styleBufOffset, int *retPos, int *retLines,
int *retLineStart, int *retLineEnd, int *retLineStart, int *retLineEnd,
bool countLastLineMissingNewLine = true); bool countLastLineMissingNewLine = true) const;
void find_line_end(int pos, bool start_pos_is_line_start, int *lineEnd, void find_line_end(int pos, bool start_pos_is_line_start, int *lineEnd,
int *nextLineStart); int *nextLineStart);
int measure_proportional_character(char c, int colNum, int pos); int measure_proportional_character(char c, int colNum, int pos) const;
int wrap_uses_character(int lineEndPos); int wrap_uses_character(int lineEndPos) const;
int range_touches_selection(const Fl_Text_Selection *sel, int rangeStart, int range_touches_selection(const Fl_Text_Selection *sel, int rangeStart,
int rangeEnd) const; int rangeEnd) const;
#ifndef FL_DOXYGEN #ifndef FL_DOXYGEN
+22 -22
View File
@@ -350,7 +350,7 @@ int TextDMaxFontWidth(textDisp *textD, Boolean considerStyles) {
} }
#endif #endif
int Fl_Text_Display::longest_vline() { int Fl_Text_Display::longest_vline() const {
int longest = 0; int longest = 0;
for (int i = 0; i < mNVisibleLines; i++) for (int i = 0; i < mNVisibleLines; i++)
longest = max(longest, measure_vline(i)); longest = max(longest, measure_vline(i));
@@ -798,7 +798,7 @@ void Fl_Text_Display::overstrike(const char* text) {
X coordinate where the position would be if it were visible. X coordinate where the position would be if it were visible.
*/ */
int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) { int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) const {
int charIndex, lineStartPos, fontHeight, lineLen; int charIndex, lineStartPos, fontHeight, lineLen;
int visLineNum, charLen, outIndex, xStep, charStyle; int visLineNum, charLen, outIndex, xStep, charStyle;
char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ]; char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
@@ -876,7 +876,7 @@ int Fl_Text_Display::position_to_xy( int pos, int* X, int* Y ) {
If continuous wrap mode is on, returns the absolute line number (as opposed If continuous wrap mode is on, returns the absolute line number (as opposed
to the wrapped line number which is used for scrolling). to the wrapped line number which is used for scrolling).
*/ */
int Fl_Text_Display::position_to_linecol( int pos, int* lineNum, int* column ) { int Fl_Text_Display::position_to_linecol( int pos, int* lineNum, int* column ) const {
int retVal; int retVal;
/* In continuous wrap mode, the absolute (non-wrapped) line count is /* In continuous wrap mode, the absolute (non-wrapped) line count is
@@ -904,7 +904,7 @@ int Fl_Text_Display::position_to_linecol( int pos, int* lineNum, int* column ) {
/** /**
Return 1 if position (X, Y) is inside of the primary Fl_Text_Selection Return 1 if position (X, Y) is inside of the primary Fl_Text_Selection
*/ */
int Fl_Text_Display::in_selection( int X, int Y ) { int Fl_Text_Display::in_selection( int X, int Y ) const {
int row, column, pos = xy_to_position( X, Y, CHARACTER_POS ); int row, column, pos = xy_to_position( X, Y, CHARACTER_POS );
Fl_Text_Buffer *buf = mBuffer; Fl_Text_Buffer *buf = mBuffer;
int ok = 0; int ok = 0;
@@ -933,7 +933,7 @@ int Fl_Text_Display::in_selection( int X, int Y ) {
from the last newline. Obviously this is time consuming, because it from the last newline. Obviously this is time consuming, because it
invloves character re-counting. invloves character re-counting.
*/ */
int Fl_Text_Display::wrapped_column(int row, int column) { int Fl_Text_Display::wrapped_column(int row, int column) const {
int lineStart, dispLineStart; int lineStart, dispLineStart;
if (!mContinuousWrap || row < 0 || row > mNVisibleLines) if (!mContinuousWrap || row < 0 || row > mNVisibleLines)
@@ -953,7 +953,7 @@ int Fl_Text_Display::wrapped_column(int row, int column) {
newlines, rather than display wrapping, and anywhere a rectangular selection newlines, rather than display wrapping, and anywhere a rectangular selection
needs a row, it needs it in terms of un-wrapped lines. needs a row, it needs it in terms of un-wrapped lines.
*/ */
int Fl_Text_Display::wrapped_row(int row) { int Fl_Text_Display::wrapped_row(int row) const{
if (!mContinuousWrap || row < 0 || row > mNVisibleLines) if (!mContinuousWrap || row < 0 || row > mNVisibleLines)
return row; return row;
return buffer()->count_lines(mFirstChar, mLineStarts[row]); return buffer()->count_lines(mFirstChar, mLineStarts[row]);
@@ -1131,7 +1131,7 @@ int Fl_Text_Display::move_down() {
by avoiding the additional step of scanning back to the last newline. by avoiding the additional step of scanning back to the last newline.
*/ */
int Fl_Text_Display::count_lines(int startPos, int endPos, int Fl_Text_Display::count_lines(int startPos, int endPos,
bool startPosIsLineStart) { bool startPosIsLineStart) const {
int retLines, retPos, retLineStart, retLineEnd; int retLines, retPos, retLineStart, retLineEnd;
#ifdef DEBUG #ifdef DEBUG
@@ -1196,7 +1196,7 @@ int Fl_Text_Display::skip_lines(int startPos, int nLines,
the start of the next line. This is also consistent with the model used by the start of the next line. This is also consistent with the model used by
visLineLength. visLineLength.
*/ */
int Fl_Text_Display::line_end(int pos, bool startPosIsLineStart) { int Fl_Text_Display::line_end(int pos, bool startPosIsLineStart) const {
int retLines, retPos, retLineStart, retLineEnd; int retLines, retPos, retLineStart, retLineEnd;
/* If we're not wrapping use more efficien BufEndOfLine */ /* If we're not wrapping use more efficien BufEndOfLine */
@@ -1215,7 +1215,7 @@ int Fl_Text_Display::line_end(int pos, bool startPosIsLineStart) {
Same as BufStartOfLine, but returns the character after last wrap point Same as BufStartOfLine, but returns the character after last wrap point
rather than the last newline. rather than the last newline.
*/ */
int Fl_Text_Display::line_start(int pos) { int Fl_Text_Display::line_start(int pos) const {
int retLines, retPos, retLineStart, retLineEnd; int retLines, retPos, retLineStart, retLineEnd;
/* If we're not wrapping, use the more efficient BufStartOfLine */ /* If we're not wrapping, use the more efficient BufStartOfLine */
@@ -1448,7 +1448,7 @@ void Fl_Text_Display::maintain_absolute_top_line_number(int state) {
Returns the absolute (non-wrapped) line number of the first line displayed. Returns the absolute (non-wrapped) line number of the first line displayed.
Returns 0 if the absolute top line number is not being maintained. Returns 0 if the absolute top line number is not being maintained.
*/ */
int Fl_Text_Display::get_absolute_top_line_number() { int Fl_Text_Display::get_absolute_top_line_number() const {
if (!mContinuousWrap) if (!mContinuousWrap)
return mTopLineNum; return mTopLineNum;
if (maintaining_absolute_top_line_number()) if (maintaining_absolute_top_line_number())
@@ -1472,7 +1472,7 @@ void Fl_Text_Display::absolute_top_line_number(int oldFirstChar) {
Return true if a separate absolute top line number is being maintained Return true if a separate absolute top line number is being maintained
(for displaying line numbers or showing in the statistics line). (for displaying line numbers or showing in the statistics line).
*/ */
int Fl_Text_Display::maintaining_absolute_top_line_number() { int Fl_Text_Display::maintaining_absolute_top_line_number() const {
return mContinuousWrap && return mContinuousWrap &&
(mLineNumWidth != 0 || mNeedAbsTopLineNum); (mLineNumWidth != 0 || mNeedAbsTopLineNum);
} }
@@ -1491,7 +1491,7 @@ void Fl_Text_Display::reset_absolute_top_line_number() {
Find the line number of position "pos" relative to the first line of Find the line number of position "pos" relative to the first line of
displayed text. Returns 0 if the line is not displayed. displayed text. Returns 0 if the line is not displayed.
*/ */
int Fl_Text_Display::position_to_line( int pos, int *lineNum ) { int Fl_Text_Display::position_to_line( int pos, int *lineNum ) const {
int i; int i;
*lineNum = 0; *lineNum = 0;
@@ -1957,7 +1957,7 @@ void Fl_Text_Display::draw_cursor( int X, int Y ) {
be more appropriate. be more appropriate.
*/ */
int Fl_Text_Display::position_style( int lineStartPos, int Fl_Text_Display::position_style( int lineStartPos,
int lineLen, int lineIndex, int dispIndex ) { int lineLen, int lineIndex, int dispIndex ) const {
Fl_Text_Buffer * buf = mBuffer; Fl_Text_Buffer * buf = mBuffer;
Fl_Text_Buffer *styleBuf = mStyleBuffer; Fl_Text_Buffer *styleBuf = mStyleBuffer;
int pos, style = 0; int pos, style = 0;
@@ -1989,7 +1989,7 @@ int Fl_Text_Display::position_style( int lineStartPos,
/** /**
Find the width of a string in the font of a particular style Find the width of a string in the font of a particular style
*/ */
int Fl_Text_Display::string_width( const char *string, int length, int style ) { int Fl_Text_Display::string_width( const char *string, int length, int style ) const {
Fl_Font font; Fl_Font font;
int fsize; int fsize;
@@ -2016,7 +2016,7 @@ int Fl_Text_Display::string_width( const char *string, int length, int style ) {
position, and CHARACTER_POS means return the position of the character position, and CHARACTER_POS means return the position of the character
closest to (X, Y). closest to (X, Y).
*/ */
int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) { int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) const {
int charIndex, lineStart, lineLen, fontHeight; int charIndex, lineStart, lineLen, fontHeight;
int charWidth, charLen, charStyle, visLineNum, xStep, outIndex; int charWidth, charLen, charStyle, visLineNum, xStep, outIndex;
char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ]; char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
@@ -2082,7 +2082,7 @@ int Fl_Text_Display::xy_to_position( int X, int Y, int posType ) {
means translate the position to the nearest character cell. means translate the position to the nearest character cell.
*/ */
void Fl_Text_Display::xy_to_rowcol( int X, int Y, int *row, void Fl_Text_Display::xy_to_rowcol( int X, int Y, int *row,
int *column, int posType ) { int *column, int posType ) const {
int fontHeight = mMaxsize; int fontHeight = mMaxsize;
int fontWidth = TMPFONTWIDTH; //mFontStruct->max_bounds.width; int fontWidth = TMPFONTWIDTH; //mFontStruct->max_bounds.width;
@@ -2479,7 +2479,7 @@ static int countlines( const char *string ) {
/** /**
Return the width in pixels of the displayed line pointed to by "visLineNum" Return the width in pixels of the displayed line pointed to by "visLineNum"
*/ */
int Fl_Text_Display::measure_vline( int visLineNum ) { int Fl_Text_Display::measure_vline( int visLineNum ) const {
int i, width = 0, len, style, lineLen = vline_length( visLineNum ); int i, width = 0, len, style, lineLen = vline_length( visLineNum );
int charCount = 0, lineStartPos = mLineStarts[ visLineNum ]; int charCount = 0, lineStartPos = mLineStarts[ visLineNum ];
char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ]; char expandedChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
@@ -2519,7 +2519,7 @@ int Fl_Text_Display::measure_vline( int visLineNum ) {
/** /**
Return true if there are lines visible with no corresponding buffer text Return true if there are lines visible with no corresponding buffer text
*/ */
int Fl_Text_Display::empty_vlines() { int Fl_Text_Display::empty_vlines() const {
return mNVisibleLines > 0 && return mNVisibleLines > 0 &&
mLineStarts[ mNVisibleLines - 1 ] == -1; mLineStarts[ mNVisibleLines - 1 ] == -1;
} }
@@ -2528,7 +2528,7 @@ int Fl_Text_Display::empty_vlines() {
Return the length of a line (number of displayable characters) by examining Return the length of a line (number of displayable characters) by examining
entries in the line starts array rather than by scanning for newlines entries in the line starts array rather than by scanning for newlines
*/ */
int Fl_Text_Display::vline_length( int visLineNum ) { int Fl_Text_Display::vline_length( int visLineNum ) const {
int nextLineStart, lineStartPos; int nextLineStart, lineStartPos;
if (visLineNum < 0 || visLineNum >= mNVisibleLines) if (visLineNum < 0 || visLineNum >= mNVisibleLines)
@@ -2794,7 +2794,7 @@ void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) {
void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos, void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
int maxPos, int maxLines, bool startPosIsLineStart, int styleBufOffset, int maxPos, int maxLines, bool startPosIsLineStart, int styleBufOffset,
int *retPos, int *retLines, int *retLineStart, int *retLineEnd, int *retPos, int *retLines, int *retLineStart, int *retLineEnd,
bool countLastLineMissingNewLine) { bool countLastLineMissingNewLine) const {
int lineStart, newLineStart = 0, b, p, colNum, wrapMargin; int lineStart, newLineStart = 0, b, p, colNum, wrapMargin;
int maxWidth, i, foundBreak, width; int maxWidth, i, foundBreak, width;
bool countPixels; bool countPixels;
@@ -2932,7 +2932,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
insertion/deletion, though static display and wrapping and resizing insertion/deletion, though static display and wrapping and resizing
should now be solid because they are now used for online help display. should now be solid because they are now used for online help display.
*/ */
int Fl_Text_Display::measure_proportional_character(char c, int colNum, int pos) { int Fl_Text_Display::measure_proportional_character(char c, int colNum, int pos) const {
int charLen, style; int charLen, style;
char expChar[ FL_TEXT_MAX_EXP_CHAR_LEN ]; char expChar[ FL_TEXT_MAX_EXP_CHAR_LEN ];
Fl_Text_Buffer *styleBuf = mStyleBuffer; Fl_Text_Buffer *styleBuf = mStyleBuffer;
@@ -2996,7 +2996,7 @@ void Fl_Text_Display::find_line_end(int startPos, bool startPosIsLineStart,
used as a wrap point, and just guesses that it wasn't. So if an exact used as a wrap point, and just guesses that it wasn't. So if an exact
accounting is necessary, don't use this function. accounting is necessary, don't use this function.
*/ */
int Fl_Text_Display::wrap_uses_character(int lineEndPos) { int Fl_Text_Display::wrap_uses_character(int lineEndPos) const {
char c; char c;
if (!mContinuousWrap || lineEndPos == buffer()->length()) if (!mContinuousWrap || lineEndPos == buffer()->length())