mirror of https://github.com/fltk/fltk
Added flexible gap size for text buffer (STR #2046)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6618 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
3c38aa5331
commit
c15fc3e71a
1
CHANGES
1
CHANGES
|
@ -1,5 +1,6 @@
|
|||
CHANGES IN FLTK 1.3.0
|
||||
|
||||
- Added flexible gap size for text buffer (STR #2046)
|
||||
- Fixed static linking of image libraries (STR #1962)
|
||||
- Fixed fl_set_spot() for Windows (STR #2101)
|
||||
- Added sorting to Fl_Browser_ (STR #2113)
|
||||
|
|
|
@ -97,7 +97,7 @@ typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
|
|||
*/
|
||||
class FL_EXPORT Fl_Text_Buffer {
|
||||
public:
|
||||
Fl_Text_Buffer(int requestedSize = 0);
|
||||
Fl_Text_Buffer(int requestedSize = 0, int preferredGapSize = 1024);
|
||||
~Fl_Text_Buffer();
|
||||
|
||||
/** Returns the number of characters in the buffer. */
|
||||
|
@ -312,6 +312,9 @@ class FL_EXPORT Fl_Text_Buffer {
|
|||
use it */
|
||||
char mCanUndo; /**< if this buffer is used for attributes, it must
|
||||
not do any undo calls */
|
||||
int mPreferredGapSize; /**< the default allocation for the text gap is 1024
|
||||
bytes and should only be increased if frequent
|
||||
and large changes in buffer size are expected */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,11 +34,6 @@
|
|||
#include <FL/Fl_Text_Buffer.H>
|
||||
|
||||
|
||||
#define PREFERRED_GAP_SIZE 1024
|
||||
/* Initial size for the buffer gap (empty space
|
||||
in the buffer where text might be inserted
|
||||
if the user is typing sequential chars) */
|
||||
|
||||
static void histogramCharacters(const char *string, int length, char hist[ 256 ],
|
||||
int init);
|
||||
static void subsChars(char *string, int length, char fromChar, char toChar);
|
||||
|
@ -122,16 +117,21 @@ static void undobuffersize(int n) {
|
|||
}
|
||||
|
||||
/**
|
||||
Create an empty text buffer of a pre-determined size (use this to
|
||||
avoid unnecessary re-allocation if you know exactly how much the buffer
|
||||
will need to hold
|
||||
Create an empty text buffer of a pre-determined size.
|
||||
|
||||
\param requestedSize use this to avoid unnecessary re-allocation
|
||||
if you know exactly how much the buffer will need to hold
|
||||
\param preferredGapSize Initial size for the buffer gap (empty space
|
||||
in the buffer where text might be inserted
|
||||
if the user is typing sequential chars)
|
||||
*/
|
||||
/** Creates a new text buffer of the specified initial size.*/
|
||||
Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize) {
|
||||
Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize) {
|
||||
mLength = 0;
|
||||
mBuf = (char *)malloc(requestedSize + PREFERRED_GAP_SIZE);
|
||||
mPreferredGapSize = preferredGapSize;
|
||||
mBuf = (char *)malloc(requestedSize + mPreferredGapSize);
|
||||
mGapStart = 0;
|
||||
mGapEnd = PREFERRED_GAP_SIZE;
|
||||
mGapEnd = mPreferredGapSize;
|
||||
mTabDist = 8;
|
||||
mUseTabs = 1;
|
||||
mPrimary.mSelected = 0;
|
||||
|
@ -197,12 +197,12 @@ void Fl_Text_Buffer::text(const char *t) {
|
|||
deletedLength = mLength;
|
||||
free((void *)mBuf);
|
||||
|
||||
/* Start a new buffer with a gap of PREFERRED_GAP_SIZE in the center */
|
||||
/* Start a new buffer with a gap of mPreferredGapSize in the center */
|
||||
insertedLength = strlen(t);
|
||||
mBuf = (char *)malloc(insertedLength + PREFERRED_GAP_SIZE);
|
||||
mBuf = (char *)malloc(insertedLength + mPreferredGapSize);
|
||||
mLength = insertedLength;
|
||||
mGapStart = insertedLength / 2;
|
||||
mGapEnd = mGapStart + PREFERRED_GAP_SIZE;
|
||||
mGapEnd = mGapStart + mPreferredGapSize;
|
||||
memcpy(mBuf, t, mGapStart);
|
||||
memcpy(&mBuf[ mGapEnd ], &t[ mGapStart ], insertedLength - mGapStart);
|
||||
#ifdef PURIFY
|
||||
|
@ -347,9 +347,9 @@ void Fl_Text_Buffer::copy(Fl_Text_Buffer *fromBuf, int fromStart,
|
|||
the current buffer, just move the gap (if necessary) to where
|
||||
the text should be inserted. If the new text is too large, reallocate
|
||||
the buffer with a gap large enough to accomodate the new text and a
|
||||
gap of PREFERRED_GAP_SIZE */
|
||||
gap of mPreferredGapSize */
|
||||
if (copiedLength > mGapEnd - mGapStart)
|
||||
reallocate_with_gap(toPos, copiedLength + PREFERRED_GAP_SIZE);
|
||||
reallocate_with_gap(toPos, copiedLength + mPreferredGapSize);
|
||||
else if (toPos != mGapStart)
|
||||
move_gap(toPos);
|
||||
|
||||
|
@ -1439,9 +1439,9 @@ int Fl_Text_Buffer::insert_(int pos, const char *text) {
|
|||
the current buffer, just move the gap (if necessary) to where
|
||||
the text should be inserted. If the new text is too large, reallocate
|
||||
the buffer with a gap large enough to accomodate the new text and a
|
||||
gap of PREFERRED_GAP_SIZE */
|
||||
gap of mPreferredGapSize */
|
||||
if (insertedLength > mGapEnd - mGapStart)
|
||||
reallocate_with_gap(pos, insertedLength + PREFERRED_GAP_SIZE);
|
||||
reallocate_with_gap(pos, insertedLength + mPreferredGapSize);
|
||||
else if (pos != mGapStart)
|
||||
move_gap(pos);
|
||||
|
||||
|
|
Loading…
Reference in New Issue