summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-04-06 23:00:56 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-04-06 23:00:56 +0000
commit29317e7b2ddabf9ef99cba82c30455c439ae1115 (patch)
treee62082a55aa9b5ae8e6ef52abe7f053e01c02aa2 /src
parentb24875d8cd3b2e289035ed0a99e904efd96cd7bf (diff)
Marked some more issues with Fl_Text_...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7462 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Text_Buffer.cxx79
-rw-r--r--src/Fl_Text_Display.cxx26
-rw-r--r--src/Fl_Text_Editor.cxx2
3 files changed, 79 insertions, 28 deletions
diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx
index 0e8884972..5b8341640 100644
--- a/src/Fl_Text_Buffer.cxx
+++ b/src/Fl_Text_Buffer.cxx
@@ -161,6 +161,8 @@ static void undobuffersize(int n)
}
}
+
+// unicode ok
Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize)
{
mLength = 0;
@@ -196,6 +198,8 @@ Fl_Text_Buffer::Fl_Text_Buffer(int requestedSize, int preferredGapSize)
#endif
}
+
+// unicode ok
Fl_Text_Buffer::~Fl_Text_Buffer()
{
free(mBuf);
@@ -221,6 +225,8 @@ char *Fl_Text_Buffer::text() const {
return t;
}
+
+// unicode ok, functions called have not been verified yet
void Fl_Text_Buffer::text(const char *t)
{
call_predelete_callbacks(0, length());
@@ -230,14 +236,13 @@ void Fl_Text_Buffer::text(const char *t)
int deletedLength = mLength;
free((void *) mBuf);
- /* Start a new buffer with a gap of mPreferredGapSize in the center */
+ /* Start a new buffer with a gap of mPreferredGapSize at the end */
int insertedLength = strlen(t);
mBuf = (char *) malloc(insertedLength + mPreferredGapSize);
mLength = insertedLength;
- mGapStart = insertedLength / 2;
+ mGapStart = insertedLength;
mGapEnd = mGapStart + mPreferredGapSize;
- memcpy(mBuf, t, mGapStart);
- memcpy(&mBuf[mGapEnd], &t[mGapStart], insertedLength - mGapStart);
+ memcpy(mBuf, t, insertedLength);
#ifdef PURIFY
{
int i;
@@ -293,17 +298,17 @@ char *Fl_Text_Buffer::text_range(int start, int end) const {
}
-// FIXME: a character must be UCS-4 encoded
-char Fl_Text_Buffer::character(int pos) const {
+// TODO: we will need the same signature function to get bytes (style buffer)
+// unicode ok
+unsigned int Fl_Text_Buffer::character(int pos) const {
if (pos < 0 || pos >= mLength)
return '\0';
- if (pos < mGapStart)
- return mBuf[pos];
- else
- return mBuf[pos + mGapEnd - mGapStart];
+ const char *src = address(pos);
+ return fl_utf8decode(src, 0, 0);
}
+// unicode ok, dependents not tested
void Fl_Text_Buffer::insert(int pos, const char *text)
{
/* if pos is not contiguous to existing text, make it */
@@ -321,6 +326,8 @@ void Fl_Text_Buffer::insert(int pos, const char *text)
call_modify_callbacks(pos, 0, nInserted, 0, NULL);
}
+
+// unicode ok, dependents not tested
void Fl_Text_Buffer::replace(int start, int end, const char *text)
{
// Range check...
@@ -334,13 +341,14 @@ void Fl_Text_Buffer::replace(int start, int end, const char *text)
call_predelete_callbacks(start, end - start);
const char *deletedText = text_range(start, end);
remove_(start, end);
- //undoyankcut = undocut;
int nInserted = insert_(start, text);
mCursorPosHint = start + nInserted;
call_modify_callbacks(start, end - start, nInserted, 0, deletedText);
free((void *) deletedText);
}
+
+// unicode ok, dependents not tested
void Fl_Text_Buffer::remove(int start, int end)
{
/* Make sure the arguments make sense */
@@ -441,6 +449,8 @@ int Fl_Text_Buffer::undo(int *cursorPos)
return 1;
}
+
+// unicode ok
void Fl_Text_Buffer::canUndo(char flag)
{
mCanUndo = flag;
@@ -918,26 +928,34 @@ remove_predelete_callback(Fl_Text_Predelete_Cb bufPreDeleteCB, void *cbArg)
char *Fl_Text_Buffer::line_text(int pos) const {
return text_range(line_start(pos), line_end(pos));
-} int Fl_Text_Buffer::line_start(int pos) const {
+}
+
+int Fl_Text_Buffer::line_start(int pos) const {
if (!findchar_backward(pos, '\n', &pos))
return 0;
return pos + 1;
-} int Fl_Text_Buffer::line_end(int pos) const {
+}
+
+int Fl_Text_Buffer::line_end(int pos) const {
if (!findchar_forward(pos, '\n', &pos))
pos = mLength;
return pos;
-} int Fl_Text_Buffer::word_start(int pos) const {
- while (pos && (isalnum(character(pos)) || character(pos) == '_'))
- {
+}
+
+int Fl_Text_Buffer::word_start(int pos) const {
+ // FIXME: character is ucs-4
+ while (pos && (isalnum(character(pos)) || character(pos) == '_')) {
pos--;
- } if (!(isalnum(character(pos)) || character(pos) == '_'))
+ }
+ // FIXME: character is ucs-4
+ if (!(isalnum(character(pos)) || character(pos) == '_'))
pos++;
return pos;
}
int Fl_Text_Buffer::word_end(int pos) const {
- while (pos < length()
- && (isalnum(character(pos)) || character(pos) == '_'))
+ // FIXME: character is ucs-4
+ while (pos < length() && (isalnum(character(pos)) || character(pos) == '_'))
{
pos++;
} return pos;
@@ -1121,13 +1139,13 @@ int Fl_Text_Buffer::rewind_lines(int startPos, int nLines)
int Fl_Text_Buffer::search_forward(int startPos, const char *searchString,
int *foundPos,
- int matchCase) const {
+ int matchCase) const
+{
if (!searchString)
return 0;
int bp;
const char *sp;
- while (startPos < length())
- {
+ while (startPos < length()) {
bp = startPos;
sp = searchString;
do {
@@ -1135,6 +1153,7 @@ int Fl_Text_Buffer::search_forward(int startPos, const char *searchString,
*foundPos = startPos;
return 1;
}
+ // FIXME: character is ucs-4
} while ((matchCase ? character(bp++) == *sp++ :
toupper(character(bp++)) == toupper(*sp++))
&& bp < length());
@@ -1159,6 +1178,7 @@ int Fl_Text_Buffer::search_backward(int startPos, const char *searchString,
*foundPos = bp + 1;
return 1;
}
+ // FIXME: character is ucs-4
} while ((matchCase ? character(bp--) == *sp-- :
toupper(character(bp--)) == toupper(*sp--))
&& bp >= 0);
@@ -1331,7 +1351,7 @@ void Fl_Text_Buffer::insert_column_(int column, int startPos,
is counted with the length of insText) */
int start = line_start(startPos);
int nLines = countLines(insText) + 1;
- int insWidth = textWidth(insText, mTabDist);
+ int insWidth = textWidth(insText, mTabDist); // this function probably returns a useless value
int end = line_end(skip_lines(start, nLines - 1));
int expReplLen, expInsLen, len, endOffset;
const char *replText = text_range(start, end);
@@ -2137,14 +2157,15 @@ static int textWidth(const char *text, int tabDist)
{
int width = 0, maxWidth = 0;
- for (const char *c = text; *c != '\0'; c++) { // FIXME: increment is wrong!
+ // HUH? Why is "c" incremented? Shouldn't "text" be incrmented?
+ // FIXME: increment is wrong!
+ for (const char *c = text; *c != '\0'; c++) {
if (*c == '\n') {
if (width > maxWidth)
maxWidth = width;
width = 0;
} else
- width +=
- Fl_Text_Buffer::character_width(c, width, tabDist);
+ width += Fl_Text_Buffer::character_width(c, width, tabDist);
}
if (width > maxWidth)
return width;
@@ -2163,11 +2184,12 @@ void Fl_Text_Buffer::rectangular_selection_boundaries(int lineStartPos,
/* find the start of the selection */
for (pos = lineStartPos; pos < mLength; pos++)
{
+ // FIXME: character is ucs-4
c = character(pos);
if (c == '\n')
break;
width =
- Fl_Text_Buffer::character_width(&c, indent, mTabDist); // FIXME: c si not unicode
+ Fl_Text_Buffer::character_width(&c, indent, mTabDist); // FIXME: c is not unicode
if (indent + width > rectStart) {
if (indent != rectStart && c != '\t') {
pos++;
@@ -2181,6 +2203,7 @@ void Fl_Text_Buffer::rectangular_selection_boundaries(int lineStartPos,
/* find the end */
for (; pos < mLength; pos++) {
+ // FIXME: character is ucs-4
c = character(pos);
if (c == '\n')
break;
@@ -2338,7 +2361,7 @@ int Fl_Text_Buffer::outputfile(const char *file, int start, int end,
int buflen)
{
FILE *fp;
- if (!(fp = fl_fopen(file, "w")))
+ if (!(fp = fl_fopen(file, "wb")))
return 1;
for (int n; (n = min(end - start, buflen)); start += n) {
const char *p = text_range(start, start + n);
diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx
index 4d1441240..9a6c2eceb 100644
--- a/src/Fl_Text_Display.cxx
+++ b/src/Fl_Text_Display.cxx
@@ -426,6 +426,7 @@ void Fl_Text_Display::draw_text( int left, int top, int width, int height ) {
void Fl_Text_Display::redisplay_range(int startpos, int endpos) {
int ok = 0;
while (!ok && startpos > 0) {
+ // FIXME: character is ucs-4
char c = buffer()->character( startpos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -434,6 +435,7 @@ void Fl_Text_Display::redisplay_range(int startpos, int endpos) {
}
}
while (!ok && endpos < buffer()->length()) {
+ // FIXME: character is ucs-4
char c = buffer()->character( endpos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -638,6 +640,7 @@ void Fl_Text_Display::overstrike(const char* text) {
for ( p = startPos; ; p++ ) {
if ( p == buf->length() )
break;
+ // FIXME: character is ucs-4
ch = buf->character( p );
if ( ch == '\n' )
break;
@@ -779,6 +782,7 @@ int Fl_Text_Display::in_selection( int X, int Y ) const {
Fl_Text_Buffer *buf = mBuffer;
int ok = 0;
while (!ok) {
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -894,6 +898,7 @@ int Fl_Text_Display::move_right() {
return 0;
insert_position( mCursorPos + 1 );
int pos = insert_position();
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) ok = 1;
}
@@ -907,6 +912,7 @@ int Fl_Text_Display::move_left() {
return 0;
insert_position( mCursorPos - 1 );
int pos = insert_position();
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) ok = 1;
}
@@ -947,6 +953,7 @@ int Fl_Text_Display::move_up() {
int ok = 0;
while (!ok) {
int pos = insert_position();
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -983,6 +990,7 @@ int Fl_Text_Display::move_down() {
int ok = 0;
while (!ok) {
int pos = insert_position();
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -1132,9 +1140,11 @@ static inline int fl_isseparator(int c) {
/** Moves the current insert position right one word.*/
void Fl_Text_Display::next_word() {
int pos = insert_position();
+ // FIXME: character is ucs-4
while (pos < buffer()->length() && !fl_isseparator(buffer()->character(pos))) {
pos++;
}
+ // FIXME: character is ucs-4
while (pos < buffer()->length() && fl_isseparator(buffer()->character(pos))) {
pos++;
}
@@ -1147,12 +1157,15 @@ void Fl_Text_Display::previous_word() {
int pos = insert_position();
if (pos==0) return;
pos--;
+ // FIXME: character is ucs-4
while (pos && fl_isseparator(buffer()->character(pos))) {
pos--;
}
+ // FIXME: character is ucs-4
while (pos && !fl_isseparator(buffer()->character(pos))) {
pos--;
}
+ // FIXME: character is ucs-4
if (fl_isseparator(buffer()->character(pos))) pos++;
insert_position( pos );
@@ -1820,10 +1833,12 @@ int Fl_Text_Display::position_style( int lineStartPos,
if ( lineIndex >= lineLen )
style = FILL_MASK;
else if ( styleBuf != NULL ) {
+ // FIXME: character is ucs-4
style = ( unsigned char ) styleBuf->character( pos );
if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
/* encountered "unfinished" style, trigger parsing */
(mUnfinishedHighlightCB)( pos, mHighlightCBArg);
+ // FIXME: character is ucs-4
style = (unsigned char) styleBuf->character( pos);
}
}
@@ -2344,6 +2359,7 @@ int Fl_Text_Display::measure_vline( int visLineNum ) const {
for ( i = 0; i < lineLen; i++ ) {
len = mBuffer->expand_character( lineStartPos + i,
charCount, expandedChar );
+ // FIXME: character is ucs-4
style = ( unsigned char ) mStyleBuffer->character(
lineStartPos + i ) - 'A';
@@ -2452,6 +2468,7 @@ void Fl_Text_Display::find_wrap_range(const char *deletedText, int pos,
lineStart = retPos;
nLines++;
if (lineStart > pos + nInserted &&
+ // FIXME: character is ucs-4
buf->character(lineStart-1) == '\n') {
countTo = lineStart;
*modRangeEnd = lineStart;
@@ -2597,6 +2614,7 @@ void Fl_Text_Display::measure_deleted_lines(int pos, int nDeleted) {
lineStart = retPos;
nLines++;
if (lineStart > pos + nDeleted &&
+ // FIXME: character is ucs-4
buf->character(lineStart-1) == '\n') {
break;
}
@@ -2674,6 +2692,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
colNum = 0;
width = 0;
for (p=lineStart; p<buf->length(); p++) {
+ // FIXME: character is ucs-4
c = (unsigned char)buf->character(p);
/* If the character was a newline, count the line and start over,
@@ -2708,6 +2727,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
if (colNum > wrapMargin || width > maxWidth) {
foundBreak = false;
for (b=p; b>=lineStart; b--) {
+ // FIXME: character is ucs-4
c = (unsigned char)buf->character(b);
if (c == '\t' || c == ' ') {
newLineStart = b + 1;
@@ -2716,6 +2736,7 @@ void Fl_Text_Display::wrapped_line_counter(Fl_Text_Buffer *buf, int startPos,
width = 0;
for (i=b+1; i<p+1; i++) {
width += measure_proportional_character(
+ // FIXME: character is ucs-4
buf->character(i), colNum,
i+styleBufOffset);
colNum++;
@@ -2784,10 +2805,12 @@ int Fl_Text_Display::measure_proportional_character(char c, int colNum, int pos)
if (styleBuf == 0) {
style = 0;
} else {
+ // FIXME: character is ucs-4
style = (unsigned char)styleBuf->character(pos);
if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
/* encountered "unfinished" style, trigger parsing */
(mUnfinishedHighlightCB)(pos, mHighlightCBArg);
+ // FIXME: character is ucs-4
style = (unsigned char)styleBuf->character(pos);
}
}
@@ -2844,6 +2867,7 @@ int Fl_Text_Display::wrap_uses_character(int lineEndPos) const {
if (!mContinuousWrap || lineEndPos == buffer()->length())
return 1;
+ // FIXME: character is ucs-4
c = buffer()->character(lineEndPos);
return c == '\n' || ((c == '\t' || c == ' ') &&
lineEndPos + 1 != buffer()->length());
@@ -3123,6 +3147,7 @@ int Fl_Text_Display::handle(int event) {
int pos = xy_to_position(Fl::event_x(), Fl::event_y(), CURSOR_POS);
int ok = 0;
while (!ok) {
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
@@ -3188,6 +3213,7 @@ int Fl_Text_Display::handle(int event) {
pos = xy_to_position(X, Y, CURSOR_POS);
int ok = 0;
while (!ok) {
+ // FIXME: character is ucs-4
char c = buffer()->character( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx
index 54f680185..76ce92ddd 100644
--- a/src/Fl_Text_Editor.cxx
+++ b/src/Fl_Text_Editor.cxx
@@ -254,6 +254,7 @@ int Fl_Text_Editor::kf_ignore(int, Fl_Text_Editor*) {
int Fl_Text_Editor::kf_backspace(int, Fl_Text_Editor* e) {
if (!e->buffer()->selected() && e->move_left()) {
int l = 1;
+ // FIXME: character is ucs-4
char c = e->buffer()->character(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
@@ -449,6 +450,7 @@ int Fl_Text_Editor::kf_insert(int, Fl_Text_Editor* e) {
int Fl_Text_Editor::kf_delete(int, Fl_Text_Editor* e) {
if (!e->buffer()->selected()) {
int l = 1;
+ // FIXME: character is ucs-4
char c = e->buffer()->character(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);