summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2005-11-09 21:34:04 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2005-11-09 21:34:04 +0000
commit258c3e81a4bd86b4bd9c11461b6565dcdc43576d (patch)
tree1fa4230d59df94ebe01e1faa5cec6050668e126f
parent0f41b3b0719f8ed94e7191e909843fa0119421bc (diff)
Fl_Text_Display::wrap_mode() would crash if no buffer was
associated with the widget (STR #1069) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4647 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--CHANGES2
-rw-r--r--src/Fl_Text_Display.cxx35
2 files changed, 24 insertions, 13 deletions
diff --git a/CHANGES b/CHANGES
index dc1eb972c..24160a4dc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,8 @@ CHANGES IN FLTK 1.1.7
- Documentation fixes (STR #571, STR #648, STR #692, STR
#730, STR #744, STR #745, STR #931, STR #942, STR #960,
STR #969)
+ - Fl_Text_Display::wrap_mode() would crash if no buffer
+ was associated with the widget (STR #1069)
- Updated the default label and text colors of all widgets
to use FL_FOREGROUND_COLOR instead of FL_BLACK (STR
#1052)
diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx
index fc188464b..8de05f424 100644
--- a/src/Fl_Text_Display.cxx
+++ b/src/Fl_Text_Display.cxx
@@ -658,19 +658,28 @@ void Fl_Text_Display::wrap_mode(int wrap, int wrapMargin) {
mWrapMargin = wrapMargin;
mContinuousWrap = wrap;
- /* wrapping can change change the total number of lines, re-count */
- mNBufferLines = count_lines(0, buffer()->length(), true);
-
- /* changing wrap margins wrap 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();
+ if (buffer()) {
+ /* wrapping can change change the total number of lines, re-count */
+ mNBufferLines = count_lines(0, buffer()->length(), true);
+
+ /* changing wrap margins wrap 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();
+ } else {
+ // No buffer, so just clear the state info for later...
+ mNBufferLines = 0;
+ mFirstChar = 0;
+ mTopLineNum = 1;
+ mAbsTopLineNum = 0;
+ }
resize(x(), y(), w(), h());
}