Browse Source

Internally manage alloc'ed copy of linenumber_format().

(As per Alrecht's comment #9 in STR #2621)



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10396 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/49/head
Greg Ercolano 11 years ago
parent
commit
78127ffdd5
  1. 18
      src/Fl_Text_Display.cxx

18
src/Fl_Text_Display.cxx

@ -25,6 +25,7 @@
#include "flstring.h" #include "flstring.h"
#include <limits.h> #include <limits.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> // strdup()
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/Fl_Text_Buffer.H> #include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Text_Display.H> #include <FL/Fl_Text_Display.H>
@ -158,7 +159,7 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
linenumber_fgcolor_ = FL_INACTIVE_COLOR; linenumber_fgcolor_ = FL_INACTIVE_COLOR;
linenumber_bgcolor_ = 53; // ~90% gray linenumber_bgcolor_ = 53; // ~90% gray
linenumber_align_ = FL_ALIGN_RIGHT; linenumber_align_ = FL_ALIGN_RIGHT;
linenumber_format_ = "%d"; linenumber_format_ = strdup("%d");
#endif #endif
} }
@ -180,6 +181,10 @@ Fl_Text_Display::~Fl_Text_Display() {
mBuffer->remove_predelete_callback(buffer_predelete_cb, this); mBuffer->remove_predelete_callback(buffer_predelete_cb, this);
} }
if (mLineStarts) delete[] mLineStarts; if (mLineStarts) delete[] mLineStarts;
if (linenumber_format_) {
free((void*)linenumber_format_);
linenumber_format_ = 0;
}
} }
@ -321,7 +326,13 @@ Fl_Align Fl_Text_Display::linenumber_align() const {
/** /**
Sets the printf() style format string used for line numbers. Sets the printf() style format string used for line numbers.
Default is "%d" for normal unpadded decimal integers. Example values: Default is "%d" for normal unpadded decimal integers.
An internal copy of \p val is allocated and managed;
it is automatically freed whenever a new value is assigned,
or when the widget is destroyed.
Example values:
- "%d" -- For normal line numbers without padding (Default) - "%d" -- For normal line numbers without padding (Default)
- "%03d" -- For 000 padding - "%03d" -- For 000 padding
@ -332,7 +343,8 @@ Fl_Align Fl_Text_Display::linenumber_align() const {
*/ */
void Fl_Text_Display::linenumber_format(const char* val) { void Fl_Text_Display::linenumber_format(const char* val) {
#if FLTK_ABI_VERSION >= 10303 #if FLTK_ABI_VERSION >= 10303
linenumber_format_ = val; if ( linenumber_format_ ) free((void*)linenumber_format_);
linenumber_format_ = val ? strdup(val) : 0;
#else #else
// do nothing // do nothing
#endif #endif

Loading…
Cancel
Save