Author: matt
Date: 2010-04-30 12:39:18 -0700 (Fri, 30 Apr 2010)
New Revision: 7568
Log:
Removing more useless stuff. Starting to replace the 0-31 character
substitution.
Modified:
branches/branch-1.3-STR2158-matt/FL/Fl_Text_Buffer.H
branches/branch-1.3-STR2158-matt/src/Fl_Text_Buffer.cxx
branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx
branches/branch-1.3-STR2158-matt/src/Fl_Text_Editor.cxx
branches/branch-1.3-STR2158-matt/test/editor.cxx
Modified: branches/branch-1.3-STR2158-matt/FL/Fl_Text_Buffer.H
===================================================================
--- branches/branch-1.3-STR2158-matt/FL/Fl_Text_Buffer.H 2010-04-30
19:04:13 UTC (rev 7567)
+++ branches/branch-1.3-STR2158-matt/FL/Fl_Text_Buffer.H 2010-04-30
19:39:18 UTC (rev 7568)
@@ -105,13 +105,13 @@
\return a non-zero number if any text has been selected, or 0
if no text is selected.
*/
- char selected() const { return mSelected; }
+ bool selected() const { return mSelected; }
/**
\brief Modify the 'selected' flag.
\param b new flag
*/
- void selected(char b) { mSelected = b; }
+ void selected(bool b) { mSelected = b; }
/**
Return true if position \p pos with indentation \p dispIndex is in
@@ -129,15 +129,17 @@
protected:
- char mSelected; ///< this flag is set if any text is selected
int mStart; ///< byte offset to the first selected character
int mEnd; ///< byte offset to the character after the last
selected character
+ bool mSelected; ///< this flag is set if any text is selected
};
+
typedef void (*Fl_Text_Modify_Cb)(int pos, int nInserted, int nDeleted,
int nRestyled, const char* deletedText,
void* cbArg);
+
typedef void (*Fl_Text_Predelete_Cb)(int pos, int nDeleted, void* cbArg);
@@ -177,12 +179,13 @@
\brief Get a copy of the entire contents of the text buffer.
Memory is allocated to contain the returned string, which the caller
must free.
- \return newly allocated text buffer - must be free'd
+ \return newly allocated text buffer - must be free'd, text is utf8
*/
char* text() const;
/**
- Replaces the entire contents of the text buffer
+ Replaces the entire contents of the text buffer.
+ Text must be valid utf8.
\todo unicode check
*/
void text(const char* text);
@@ -195,7 +198,7 @@
When you are done with the text, free it using the free() function.
\param start byte offset to first character
\param end byte offset after last character in range
- \return newly allocated text buffer - must be free'd
+ \return newly allocated text buffer - must be free'd, text is utf8
*/
char* text_range(int start, int end) const;
@@ -205,7 +208,7 @@
\param pos byte offset into buffer
\return Unicode UCS-4 encoded character
*/
- unsigned int character(int pos) const;
+ unsigned int at(int pos) const;
/**
Convert a byte offset in buffer into a memory address.
@@ -228,6 +231,7 @@
/**
Appends the text string to the end of the buffer.
+ \param t utf-8 encoded and nul terminated text
\todo unicode check
*/
void append(const char* t) { insert(length(), t); }
@@ -248,8 +252,11 @@
void replace(int start, int end, const char *text);
/**
- Copies text from one buffer to this one; fromBuf may
- be the same as this.
+ Copies text from one buffer to this one.
+ \param fromBuf source text buffer may be the same as this
+ \param fromStart byte offset into buffer
+ \param fromEnd byte offset into buffer
+ \param toPos destination byte offset into buffer
\todo unicode check
*/
void copy(Fl_Text_Buffer* fromBuf, int fromStart, int fromEnd, int toPos);
@@ -489,12 +496,16 @@
Returns the text from the entire line containing the specified
character position. When you are done with the text, free it
using the free() function.
+ \param pos byte index into buffer
+ \return copy of utf8 text, must be free'd
\todo unicode check
*/
char* line_text(int pos) const;
/**
Returns the position of the start of the line containing position \p pos.
+ \param pos byte index into buffer
+ \return byte offset to line start
\todo unicode check
*/
int line_start(int pos) const;
@@ -503,18 +514,24 @@
Finds and returns the position of the end of the line containing position
\p pos
(which is either a pointer to the newline character ending the line,
or a pointer to one character beyond the end of the buffer)
+ \param pos byte index into buffer
+ \return byte offset to line end
\todo unicode check
*/
int line_end(int pos) const;
/**
Returns the position corresponding to the start of the word
+ \param pos byte index into buffer
+ \return byte offset to word start
\todo unicode check
*/
int word_start(int pos) const;
/**
Returns the position corresponding to the end of the word.
+ \param pos byte index into buffer
+ \return byte offset to word end
\todo unicode check
*/
int word_end(int pos) const;
@@ -557,7 +574,7 @@
\return number of byte in substitution
*/
static int character_width(const char *src, int indent, int tabDist);
- static int character_width(const char c, int indent, int tabDist);
+ //static int character_width(const char c, int indent, int tabDist);
/**
Count the number of displayed characters between buffer position
@@ -609,9 +626,13 @@
BufSearchForward is that it's optimized for single characters. The
overall performance of the text widget is dependent on its ability to
count lines quickly, hence searching for a single character: newline)
+ \param startPos byte offset to start position
+ \param searchChar UCS4 character that we want to find
+ \param foundPos byte offset where the character was found
+ \return 1 if found, 0 if not
\todo unicode check
*/
- int findchar_forward(int startPos, char searchChar, int* foundPos) const;
+ int findchar_forward(int startPos, unsigned searchChar, int* foundPos) const;
/**
Search backwards in buffer \p buf for character \p searchChar, starting
@@ -620,15 +641,23 @@
BufSearchBackward is that it's optimized for single characters. The
overall performance of the text widget is dependent on its ability to
count lines quickly, hence searching for a single character: newline)
+ \param startPos byte offset to start position
+ \param searchChar UCS4 character that we want to find
+ \param foundPos byte offset where the character was found
+ \return 1 if found, 0 if not
\todo unicode check
*/
- int findchar_backward(int startPos, char searchChar, int* foundPos) const;
+ int findchar_backward(int startPos, unsigned searchChar, int* foundPos)
const;
/**
Finds the next occurrence of the specified characters.
Search forwards in buffer for characters in \p searchChars, starting
with the character \p startPos, and returning the result in \p foundPos
returns 1 if found, 0 if not.
+ \param startPos byte offset to start position
+ \param searchChars utf8 string that we want to find
+ \param foundPos byte offset where the string was found
+ \return 1 if found, 0 if not
\todo unicode check
*/
int findchars_forward(int startPos, const char* searchChars, int* foundPos)
const;
@@ -638,6 +667,10 @@
Search backwards in buffer for characters in \p searchChars, starting
with the character BEFORE \p startPos, returning the result in \p foundPos
returns 1 if found, 0 if not.
+ \param startPos byte offset to start position
+ \param searchChars utf8 string that we want to find
+ \param foundPos byte offset where the string was found
+ \return 1 if found, 0 if not
\todo unicode check
*/
int findchars_backward(int startPos, const char* searchChars, int* foundPos)
const;
@@ -646,6 +679,11 @@
Search forwards in buffer for string \p searchString, starting with the
character \p startPos, and returning the result in \p foundPos
returns 1 if found, 0 if not.
+ \param startPos byte offset to start position
+ \param searchString utf8 string that we want to find
+ \param foundPos byte offset where the string was found
+ \param matchCase if set, match character case
+ \return 1 if found, 0 if not
\todo unicode check
*/
int search_forward(int startPos, const char* searchString, int* foundPos,
@@ -655,6 +693,11 @@
Search backwards in buffer for string <i>searchCharssearchString</i>,
starting with the
character BEFORE \p startPos, returning the result in \p foundPos
returns 1 if found, 0 if not.
+ \param startPos byte offset to start position
+ \param searchString utf8 string that we want to find
+ \param foundPos byte offset where the string was found
+ \param matchCase if set, match character case
+ \return 1 if found, 0 if not
\todo unicode check
*/
int search_backward(int startPos, const char* searchString, int* foundPos,
@@ -770,12 +813,12 @@
int mUseTabs; /**< True if buffer routines are allowed to
use
tabs for padding in rectangular operations
*/
int mNModifyProcs; /**< number of modify-redisplay procs
attached */
- Fl_Text_Modify_Cb* /**< procedures to call when buffer is */
- mModifyProcs; /**< modified to redisplay contents */
+ Fl_Text_Modify_Cb *mModifyProcs;/**< procedures to call when buffer is
+ modified to redisplay contents */
void** mCbArgs; /**< caller arguments for modifyProcs above
*/
int mNPredeleteProcs; /**< number of pre-delete procs attached */
- Fl_Text_Predelete_Cb* /**< procedure to call before text is
deleted */
- mPredeleteProcs; /**< from the buffer; at most one is
supported. */
+ Fl_Text_Predelete_Cb *mPredeleteProcs; /**< procedure to call before text is
deleted
+ from the buffer; at most one is supported.
*/
void **mPredeleteCbArgs; /**< caller argument for pre-delete proc
above */
int mCursorPosHint; /**< hint for reasonable cursor position
after
a buffer modification operation */
Modified: branches/branch-1.3-STR2158-matt/src/Fl_Text_Buffer.cxx
===================================================================
--- branches/branch-1.3-STR2158-matt/src/Fl_Text_Buffer.cxx 2010-04-30
19:04:13 UTC (rev 7567)
+++ branches/branch-1.3-STR2158-matt/src/Fl_Text_Buffer.cxx 2010-04-30
19:39:18 UTC (rev 7568)
@@ -236,7 +236,7 @@
// TODO: we will need the same signature function to get bytes (style buffer)
// unicode ok
-unsigned int Fl_Text_Buffer::character(int pos) const {
+unsigned int Fl_Text_Buffer::at(int pos) const {
if (pos < 0 || pos >= mLength)
return '\0';
const char *src = address(pos);
@@ -661,18 +661,18 @@
int Fl_Text_Buffer::word_start(int pos) const {
// FIXME: character is ucs-4
- while (pos && (isalnum(character(pos)) || character(pos) == '_')) {
+ while (pos && (isalnum(at(pos)) || at(pos) == '_')) {
pos--;
}
// FIXME: character is ucs-4
- if (!(isalnum(character(pos)) || character(pos) == '_'))
+ if (!(isalnum(at(pos)) || at(pos) == '_'))
pos++;
return pos;
}
int Fl_Text_Buffer::word_end(int pos) const {
// FIXME: character is ucs-4
- while (pos < length() && (isalnum(character(pos)) || character(pos) == '_'))
+ while (pos < length() && (isalnum(at(pos)) || at(pos) == '_'))
{
pos++;
} return pos;
@@ -749,9 +749,11 @@
if ((c & 0x80) && !(c & 0x40)) { // other byte of UTF-8 sequence
return 0;
}
- return character_width(c, indent, tabDist);
+ return 1; // FIXME: ouch!
+ //return character_width(c, indent, tabDist);
}
+#if 0
// FIXME: merge the following with the char* version above.
// but the question then is: how to reorganise expand_character()?
//
@@ -775,6 +777,7 @@
}
return 1;
}
+#endif
int Fl_Text_Buffer::count_displayed_characters(int lineStartPos,
int targetPos) const
@@ -893,8 +896,8 @@
return 1;
}
// FIXME: character is ucs-4
- } while ((matchCase ? character(bp++) == *sp++ :
- toupper(character(bp++)) == toupper(*sp++))
+ } while ((matchCase ? at(bp++) == *sp++ :
+ toupper(at(bp++)) == toupper(*sp++))
&& bp < length());
startPos++;
}
@@ -918,8 +921,8 @@
return 1;
}
// FIXME: character is ucs-4
- } while ((matchCase ? character(bp--) == *sp-- :
- toupper(character(bp--)) == toupper(*sp--))
+ } while ((matchCase ? at(bp--) == *sp-- :
+ toupper(at(bp--)) == toupper(*sp--))
&& bp >= 0);
startPos--;
}
@@ -1285,7 +1288,7 @@
}
}
-int Fl_Text_Buffer::findchar_forward(int startPos, char searchChar,
+int Fl_Text_Buffer::findchar_forward(int startPos, unsigned searchChar,
int *foundPos) const {
if (startPos < 0 || startPos >= mLength)
{
@@ -1312,7 +1315,7 @@
return 0;
}
-int Fl_Text_Buffer::findchar_backward(int startPos, char searchChar,
+int Fl_Text_Buffer::findchar_backward(int startPos, unsigned searchChar,
int *foundPos) const {
if (startPos <= 0 || startPos > mLength)
Modified: branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx
===================================================================
--- branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx 2010-04-30
19:04:13 UTC (rev 7567)
+++ branches/branch-1.3-STR2158-matt/src/Fl_Text_Display.cxx 2010-04-30
19:39:18 UTC (rev 7568)
@@ -427,7 +427,7 @@
int ok = 0;
while (!ok && startpos > 0) {
// FIXME: character is ucs-4
- char c = buffer()->character( startpos );
+ char c = buffer()->at( startpos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
@@ -436,7 +436,7 @@
}
while (!ok && endpos < buffer()->length()) {
// FIXME: character is ucs-4
- char c = buffer()->character( endpos );
+ char c = buffer()->at( endpos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
@@ -641,7 +641,7 @@
if ( p == buf->length() )
break;
// FIXME: character is ucs-4
- ch = buf->character( p );
+ ch = buf->at( p );
if ( ch == '\n' )
break;
const char *s = buf->address(p);
@@ -886,7 +886,7 @@
insert_position( mCursorPos + 1 );
int pos = insert_position();
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->at( pos );
if (!((c & 0x80) && !(c & 0x40))) ok = 1;
}
return 1;
@@ -900,7 +900,7 @@
insert_position( mCursorPos - 1 );
int pos = insert_position();
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->at( pos );
if (!((c & 0x80) && !(c & 0x40))) ok = 1;
}
return 1;
@@ -941,7 +941,7 @@
while (!ok) {
int pos = insert_position();
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->at( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
@@ -978,7 +978,7 @@
while (!ok) {
int pos = insert_position();
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->at( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
@@ -1128,11 +1128,11 @@
void Fl_Text_Display::next_word() {
int pos = insert_position();
// FIXME: character is ucs-4
- while (pos < buffer()->length() &&
!fl_isseparator(buffer()->character(pos))) {
+ while (pos < buffer()->length() && !fl_isseparator(buffer()->at(pos))) {
pos++;
}
// FIXME: character is ucs-4
- while (pos < buffer()->length() && fl_isseparator(buffer()->character(pos)))
{
+ while (pos < buffer()->length() && fl_isseparator(buffer()->at(pos))) {
pos++;
}
@@ -1145,15 +1145,15 @@
if (pos==0) return;
pos--;
// FIXME: character is ucs-4
- while (pos && fl_isseparator(buffer()->character(pos))) {
+ while (pos && fl_isseparator(buffer()->at(pos))) {
pos--;
}
// FIXME: character is ucs-4
- while (pos && !fl_isseparator(buffer()->character(pos))) {
+ while (pos && !fl_isseparator(buffer()->at(pos))) {
pos--;
}
// FIXME: character is ucs-4
- if (fl_isseparator(buffer()->character(pos))) pos++;
+ if (fl_isseparator(buffer()->at(pos))) pos++;
insert_position( pos );
}
@@ -1807,12 +1807,12 @@
style = FILL_MASK;
else if ( styleBuf != NULL ) {
// FIXME: character is ucs-4
- style = ( unsigned char ) styleBuf->character( pos );
+ style = ( unsigned char ) styleBuf->at( pos );
if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
/* encountered "unfinished" style, trigger parsing */
(mUnfinishedHighlightCB)( pos, mHighlightCBArg);
// FIXME: character is ucs-4
- style = (unsigned char) styleBuf->character( pos);
+ style = (unsigned char) styleBuf->at( pos);
}
}
if (buf->primary_selection()->includes(pos))
@@ -2333,7 +2333,7 @@
len = mBuffer->expand_character( lineStartPos + i,
charCount, expandedChar );
// FIXME: character is ucs-4
- style = ( unsigned char ) mStyleBuffer->character(
+ style = ( unsigned char ) mStyleBuffer->at(
lineStartPos + i ) - 'A';
if (style < 0) style = 0;
@@ -2442,7 +2442,7 @@
nLines++;
if (lineStart > pos + nInserted &&
// FIXME: character is ucs-4
- buf->character(lineStart-1) == '\n') {
+ buf->at(lineStart-1) == '\n') {
countTo = lineStart;
*modRangeEnd = lineStart;
break;
@@ -2588,7 +2588,7 @@
nLines++;
if (lineStart > pos + nDeleted &&
// FIXME: character is ucs-4
- buf->character(lineStart-1) == '\n') {
+ buf->at(lineStart-1) == '\n') {
break;
}
@@ -2666,7 +2666,7 @@
width = 0;
for (p=lineStart; p<buf->length(); p++) {
// FIXME: character is ucs-4
- c = (unsigned char)buf->character(p);
+ c = (unsigned char)buf->at(p);
/* If the character was a newline, count the line and start over,
otherwise, add it to the width and column counts */
@@ -2702,7 +2702,7 @@
foundBreak = false;
for (b=p; b>=lineStart; b--) {
// FIXME: character is ucs-4
- c = (unsigned char)buf->character(b);
+ c = (unsigned char)buf->at(b);
if (c == '\t' || c == ' ') {
newLineStart = b + 1;
if (countPixels) {
@@ -2782,12 +2782,12 @@
style = 0;
} else {
// FIXME: character is ucs-4
- style = (unsigned char)styleBuf->character(pos);
+ style = (unsigned char)styleBuf->at(pos);
if (style == mUnfinishedStyle && mUnfinishedHighlightCB) {
/* encountered "unfinished" style, trigger parsing */
(mUnfinishedHighlightCB)(pos, mHighlightCBArg);
// FIXME: character is ucs-4
- style = (unsigned char)styleBuf->character(pos);
+ style = (unsigned char)styleBuf->at(pos);
}
}
return string_width(expChar, charLen, style);
@@ -2844,7 +2844,7 @@
return 1;
// FIXME: character is ucs-4
- c = buffer()->character(lineEndPos);
+ c = buffer()->at(lineEndPos);
return c == '\n' || ((c == '\t' || c == ' ') &&
lineEndPos + 1 != buffer()->length());
}
@@ -3114,7 +3114,7 @@
int ok = 0;
while (!ok) {
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->at( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
@@ -3180,7 +3180,7 @@
int ok = 0;
while (!ok) {
// FIXME: character is ucs-4
- char c = buffer()->character( pos );
+ char c = buffer()->at( pos );
if (!((c & 0x80) && !(c & 0x40))) {
ok = 1;
} else {
Modified: branches/branch-1.3-STR2158-matt/src/Fl_Text_Editor.cxx
===================================================================
--- branches/branch-1.3-STR2158-matt/src/Fl_Text_Editor.cxx 2010-04-30
19:04:13 UTC (rev 7567)
+++ branches/branch-1.3-STR2158-matt/src/Fl_Text_Editor.cxx 2010-04-30
19:39:18 UTC (rev 7568)
@@ -255,7 +255,7 @@
if (!e->buffer()->selected() && e->move_left()) {
int l = 1;
// FIXME: character is ucs-4
- char c = e->buffer()->character(e->insert_position());
+ char c = e->buffer()->at(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
}
@@ -451,7 +451,7 @@
if (!e->buffer()->selected()) {
int l = 1;
// FIXME: character is ucs-4
- char c = e->buffer()->character(e->insert_position());
+ char c = e->buffer()->at(e->insert_position());
if (c & 0x80 && c & 0x40) {
l = fl_utf8len(c);
}
Modified: branches/branch-1.3-STR2158-matt/test/editor.cxx
===================================================================
--- branches/branch-1.3-STR2158-matt/test/editor.cxx 2010-04-30 19:04:13 UTC
(rev 7567)
+++ branches/branch-1.3-STR2158-matt/test/editor.cxx 2010-04-30 19:39:18 UTC
(rev 7568)
@@ -791,7 +791,40 @@
int main(int argc, char **argv) {
textbuf = new Fl_Text_Buffer;
- textbuf->text("Rügenwälder Ruß.");
+ textbuf->text(
+ "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg\n"
+ "(= Wrongful practicing of xylophone music tortures every
larger dwarf)\n"
+ "\n"
+ "Zwölf Boxkämpfer jagten Eva quer über den Sylter Deich\n"
+ "(= Twelve boxing fighters hunted Eva across the dike of
Sylt)\n"
+ "\n"
+ "Heizölrückstoßabdämpfung\n"
+ "(= fuel oil recoil absorber)\n"
+ "\n"
+ "Hiragana: (Iroha)\n"
+ "\n"
+ "いろはにほへとちりぬるを\n"
+ "わかよたれそつねならむ\n"
+ "うゐのおくやまけふこえて\n"
+ "あさきゆめみしゑひもせす\n"
+ "\n"
+ "Katakana:\n"
+ "\n"
+ "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム\n"
+ "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン\n"
+ "\n"
+ "? דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה\n"
+ "\n"
+ "いろはにほへと ちりぬるを わかよ\n"
+ "たれそ つねならむ うゐのおくやま\n"
+ "けふこえて あさきゆめみし ゑひも\n"
+ "せす\n"
+ "Even colours and sweet perfume / Will eventually fade /\n"
+ "Even our world / Is not eternal /\n"
+ "The deep mountains of vanity / Cross them today /\n"
+ "And superficial dreams / Shall no longer delude you.\n"
+ "(from Iroha-uta)"
+ );
style_init();
Fl_Window* window = new_view();
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit