UTF8: Fl_Text_Display and related:

+ Made char * text() const., this method should be further checked for UTF8 compat.
  + Added a fixme comment to remember we must check for the potential incorrect
  assumption that that a buffer size equals the string length + 1.
  + Correct a protected attrib. typo as we  don't need to care about ABI compat. for now.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6818 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Fabien Costantini
2009-07-03 23:32:47 +00:00
parent 510ad42f4e
commit d4e85cef93
2 changed files with 17 additions and 17 deletions
+2 -2
View File
@@ -102,7 +102,7 @@ class FL_EXPORT Fl_Text_Buffer {
/** Returns the number of characters in the buffer. */ /** Returns the number of characters in the buffer. */
int length() { return mLength; } int length() { return mLength; }
char* text(); char* text() const;
void text(const char* text); void text(const char* text);
char* text_range(int start, int end); char* text_range(int start, int end);
char character(int pos); char character(int pos);
@@ -297,7 +297,7 @@ class FL_EXPORT Fl_Text_Buffer {
tabs for padding in rectangular operations */ tabs for padding in rectangular operations */
int mNModifyProcs; /**< number of modify-redisplay procs attached */ int mNModifyProcs; /**< number of modify-redisplay procs attached */
Fl_Text_Modify_Cb* /**< procedures to call when buffer is */ Fl_Text_Modify_Cb* /**< procedures to call when buffer is */
mNodifyProcs; /**< modified to redisplay contents */ mModifyProcs; /**< modified to redisplay contents */
void** mCbArgs; /**< caller arguments for modifyProcs above */ void** mCbArgs; /**< caller arguments for modifyProcs above */
int mNPredeleteProcs; /**< number of pre-delete procs attached */ int mNPredeleteProcs; /**< number of pre-delete procs attached */
Fl_Text_Predelete_Cb* /**< procedure to call before text is deleted */ Fl_Text_Predelete_Cb* /**< procedure to call before text is deleted */
+15 -15
View File
@@ -122,7 +122,7 @@ Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize) {
mHighlight.mSelected = 0; mHighlight.mSelected = 0;
mHighlight.mStart = mHighlight.mEnd = 0; mHighlight.mStart = mHighlight.mEnd = 0;
mHighlight.mRectangular = 0; mHighlight.mRectangular = 0;
mNodifyProcs = NULL; mModifyProcs = NULL;
mCbArgs = NULL; mCbArgs = NULL;
mNModifyProcs = 0; mNModifyProcs = 0;
mNPredeleteProcs = 0; mNPredeleteProcs = 0;
@@ -140,7 +140,7 @@ Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize) {
Fl_Text_Buffer::~Fl_Text_Buffer() { Fl_Text_Buffer::~Fl_Text_Buffer() {
free(mBuf); free(mBuf);
if (mNModifyProcs != 0) { if (mNModifyProcs != 0) {
delete[] mNodifyProcs; delete[] mModifyProcs;
delete[] mCbArgs; delete[] mCbArgs;
} }
if (mNPredeleteProcs != 0) { if (mNPredeleteProcs != 0) {
@@ -153,10 +153,10 @@ Fl_Text_Buffer::~Fl_Text_Buffer() {
Get the entire contents of a text buffer. Memory is allocated to contain Get the entire contents of a text buffer. Memory is allocated to contain
the returned string, which the caller must free. the returned string, which the caller must free.
*/ */
char * Fl_Text_Buffer::text() { char * Fl_Text_Buffer::text() const {
char *t; char *t;
t = (char *)malloc(mLength + 1); t = (char *)malloc(mLength + 1); // FIX ME UTF8: we alloc from a string len, is len the strlen or the string buffer size ?
memcpy(t, mBuf, mGapStart); memcpy(t, mBuf, mGapStart);
memcpy(&t[ mGapStart ], &mBuf[ mGapEnd ], memcpy(&t[ mGapStart ], &mBuf[ mGapEnd ],
mLength - mGapStart); mLength - mGapStart);
@@ -777,17 +777,17 @@ void Fl_Text_Buffer::add_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
newModifyProcs = new Fl_Text_Modify_Cb [ mNModifyProcs + 1 ]; newModifyProcs = new Fl_Text_Modify_Cb [ mNModifyProcs + 1 ];
newCBArgs = new void * [ mNModifyProcs + 1 ]; newCBArgs = new void * [ mNModifyProcs + 1 ];
for (i = 0; i < mNModifyProcs; i++) { for (i = 0; i < mNModifyProcs; i++) {
newModifyProcs[ i + 1 ] = mNodifyProcs[ i ]; newModifyProcs[ i + 1 ] = mModifyProcs[ i ];
newCBArgs[ i + 1 ] = mCbArgs[ i ]; newCBArgs[ i + 1 ] = mCbArgs[ i ];
} }
if (mNModifyProcs != 0) { if (mNModifyProcs != 0) {
delete [] mNodifyProcs; delete [] mModifyProcs;
delete [] mCbArgs; delete [] mCbArgs;
} }
newModifyProcs[ 0 ] = bufModifiedCB; newModifyProcs[ 0 ] = bufModifiedCB;
newCBArgs[ 0 ] = cbArg; newCBArgs[ 0 ] = cbArg;
mNModifyProcs++; mNModifyProcs++;
mNodifyProcs = newModifyProcs; mModifyProcs = newModifyProcs;
mCbArgs = newCBArgs; mCbArgs = newCBArgs;
} }
/** Removes a modify callback.*/ /** Removes a modify callback.*/
@@ -799,7 +799,7 @@ void Fl_Text_Buffer::remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
/* find the matching callback to remove */ /* find the matching callback to remove */
for (i = 0; i < mNModifyProcs; i++) { for (i = 0; i < mNModifyProcs; i++) {
if (mNodifyProcs[ i ] == bufModifiedCB && mCbArgs[ i ] == cbArg) { if (mModifyProcs[ i ] == bufModifiedCB && mCbArgs[ i ] == cbArg) {
toRemove = i; toRemove = i;
break; break;
} }
@@ -814,8 +814,8 @@ void Fl_Text_Buffer::remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
mNModifyProcs--; mNModifyProcs--;
if (mNModifyProcs == 0) { if (mNModifyProcs == 0) {
mNModifyProcs = 0; mNModifyProcs = 0;
delete[] mNodifyProcs; delete[] mModifyProcs;
mNodifyProcs = NULL; mModifyProcs = NULL;
delete[] mCbArgs; delete[] mCbArgs;
mCbArgs = NULL; mCbArgs = NULL;
return; return;
@@ -825,16 +825,16 @@ void Fl_Text_Buffer::remove_modify_callback(Fl_Text_Modify_Cb bufModifiedCB,
/* copy out the remaining members and free the old lists */ /* copy out the remaining members and free the old lists */
for (i = 0; i < toRemove; i++) { for (i = 0; i < toRemove; i++) {
newModifyProcs[ i ] = mNodifyProcs[ i ]; newModifyProcs[ i ] = mModifyProcs[ i ];
newCBArgs[ i ] = mCbArgs[ i ]; newCBArgs[ i ] = mCbArgs[ i ];
} }
for (; i < mNModifyProcs; i++) { for (; i < mNModifyProcs; i++) {
newModifyProcs[ i ] = mNodifyProcs[ i + 1 ]; newModifyProcs[ i ] = mModifyProcs[ i + 1 ];
newCBArgs[ i ] = mCbArgs[ i + 1 ]; newCBArgs[ i ] = mCbArgs[ i + 1 ];
} }
delete[] mNodifyProcs; delete[] mModifyProcs;
delete[] mCbArgs; delete[] mCbArgs;
mNodifyProcs = newModifyProcs; mModifyProcs = newModifyProcs;
mCbArgs = newCBArgs; mCbArgs = newCBArgs;
} }
@@ -2102,7 +2102,7 @@ void Fl_Text_Buffer::call_modify_callbacks(int pos, int nDeleted,
int i; int i;
for (i = 0; i < mNModifyProcs; i++) for (i = 0; i < mNModifyProcs; i++)
(*mNodifyProcs[ i ]) (pos, nInserted, nDeleted, nRestyled, (*mModifyProcs[ i ]) (pos, nInserted, nDeleted, nRestyled,
deletedText, mCbArgs[ i ]); deletedText, mCbArgs[ i ]);
} }