mirror of
https://github.com/fltk/fltk.git
synced 2026-06-07 09:13:58 +08:00
Starting to rework Fl_Text_Display from scratch to make wrapping work correctly. Fixed a few issues that made wrapping crash. Using ASCII range only with fixed character sizes should still wrap as expected?!
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7794 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+12
-2
@@ -39,7 +39,7 @@
|
||||
?? "length" is the number of characters in a string
|
||||
?? "size" is the number of bytes
|
||||
?? "index" is the position in a string in number of characters
|
||||
?? "offset" is the position in a strin in bytes (and must be kept on a charater boundary)
|
||||
?? "offset" is the position in a string in bytes (and must be kept on a charater boundary)
|
||||
(there seems to be no standard in Uncode documents, howevere "length" is commonly
|
||||
referencing the number of bytes. Maybe "bytes" and "glyphs" would be the most
|
||||
obvious way to describe sizes?)
|
||||
@@ -154,6 +154,11 @@ typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
|
||||
/**
|
||||
\brief This class manages unicode displayed in one or more Fl_Text_Display widgets.
|
||||
|
||||
All text in Fl_Text_Buffermust be encoded in UTF-8. All indices used in the
|
||||
function calls must be aligned to the start of a UTF-8 sequence. All indices
|
||||
and pointers returned will be aligned. All functions that return a single
|
||||
character will return that in an unsiged int in UCS-4 encoding.
|
||||
|
||||
The Fl_Text_Buffer class is used by the Fl_Text_Display
|
||||
and Fl_Text_Editor to manage complex text data and is based upon the
|
||||
excellent NEdit text editor engine - see http://www.nedit.org/.
|
||||
@@ -193,7 +198,7 @@ public:
|
||||
|
||||
/**
|
||||
Replaces the entire contents of the text buffer.
|
||||
Text must be valid utf8.
|
||||
\param text Text must be valid utf8.
|
||||
\todo unicode check
|
||||
*/
|
||||
void text(const char* text);
|
||||
@@ -228,12 +233,16 @@ public:
|
||||
|
||||
/**
|
||||
Convert a byte offset in buffer into a memory address.
|
||||
\param pos byte offset into buffer
|
||||
\return byte offset converted to a memory address
|
||||
*/
|
||||
const char *address(int pos) const
|
||||
{ return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
|
||||
|
||||
/**
|
||||
Convert a byte offset in buffer into a memory address.
|
||||
\param pos byte offset into buffer
|
||||
\return byte offset converted to a memory address
|
||||
*/
|
||||
char *address(int pos)
|
||||
{ return (pos < mGapStart) ? mBuf+pos : mBuf+pos+mGapEnd-mGapStart; }
|
||||
@@ -748,6 +757,7 @@ protected:
|
||||
expensive and the length will be required by any caller who will continue
|
||||
on to call redisplay). \p pos must be contiguous with the existing text in
|
||||
the buffer (i.e. not past the end).
|
||||
\return the number of bytes inserted
|
||||
\todo unicode check
|
||||
*/
|
||||
int insert_(int pos, const char* text);
|
||||
|
||||
+298
-270
File diff suppressed because it is too large
Load Diff
+10
-3
@@ -270,6 +270,10 @@ char Fl_Text_Buffer::byte_at(int pos) const {
|
||||
*/
|
||||
void Fl_Text_Buffer::insert(int pos, const char *text)
|
||||
{
|
||||
/* check if there is actually any text */
|
||||
if (!text || !*text)
|
||||
return;
|
||||
|
||||
/* if pos is not contiguous to existing text, make it */
|
||||
if (pos > mLength)
|
||||
pos = mLength;
|
||||
@@ -1010,7 +1014,7 @@ int Fl_Text_Buffer::search_forward(int startPos, const char *searchString,
|
||||
return 1;
|
||||
}
|
||||
// FIXME: character is ucs-4
|
||||
} while ((matchCase ? char_at(bp++) == *sp++ :
|
||||
} while ((matchCase ? char_at(bp++) == (unsigned int)*sp++ :
|
||||
toupper(char_at(bp++)) == toupper(*sp++))
|
||||
&& bp < length());
|
||||
startPos++;
|
||||
@@ -1040,7 +1044,7 @@ int Fl_Text_Buffer::search_backward(int startPos, const char *searchString,
|
||||
return 1;
|
||||
}
|
||||
// FIXME: character is ucs-4
|
||||
} while ((matchCase ? char_at(bp--) == *sp-- :
|
||||
} while ((matchCase ? char_at(bp--) == (unsigned int)*sp-- :
|
||||
toupper(char_at(bp--)) == toupper(*sp--))
|
||||
&& bp >= 0);
|
||||
startPos--;
|
||||
@@ -1128,6 +1132,9 @@ int Fl_Text_Buffer::findchars_backward(int startPos, const char *searchChars,
|
||||
*/
|
||||
int Fl_Text_Buffer::insert_(int pos, const char *text)
|
||||
{
|
||||
if (!text || !*text)
|
||||
return 0;
|
||||
|
||||
int insertedLength = strlen(text);
|
||||
|
||||
/* Prepare the buffer to receive the new text. If the new text fits in
|
||||
@@ -1246,7 +1253,7 @@ int Fl_Text_Selection::position(int *startpos, int *endpos) const {
|
||||
*/
|
||||
int Fl_Text_Selection::includes(int pos) const {
|
||||
return (selected() && pos >= start() && pos < end() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+1341
-1336
File diff suppressed because it is too large
Load Diff
@@ -785,6 +785,7 @@ Fl_Window* new_view() {
|
||||
Fl_Menu_Bar* m = new Fl_Menu_Bar(0, 0, 660, 30);
|
||||
m->copy(menuitems, w);
|
||||
w->editor = new Fl_Text_Editor(0, 30, 660, 370);
|
||||
w->editor->wrap_mode(1, 32);
|
||||
w->editor->textfont(FL_COURIER);
|
||||
w->editor->textsize(TS);
|
||||
w->editor->buffer(textbuf);
|
||||
@@ -812,6 +813,7 @@ int main(int argc, char **argv) {
|
||||
" if ( fnfc.show() ) return;\n"
|
||||
" save_file(fnfc.filename());\n"
|
||||
"}\n\n"
|
||||
" 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0\n\n"
|
||||
"// Falsches Üben von Xylophonmusik quält jeden größeren Zwerg\n"
|
||||
"// (= Wrongful practicing of xylophone music tortures every larger dwarf)\n"
|
||||
"\n"
|
||||
|
||||
Reference in New Issue
Block a user