mirror of
https://github.com/fltk/fltk.git
synced 2026-05-21 14:31:40 +08:00
Preliminary implementation of Tab characters insisde Fl_Text-*. We still need to test wrapping, etc.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7895 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -197,7 +197,7 @@ void Fl_Text_Buffer::text(const char *t)
|
||||
*/
|
||||
char *Fl_Text_Buffer::text_range(int start, int end) const {
|
||||
IS_UTF8_ALIGNED2(this, (start))
|
||||
IS_UTF8_ALIGNED2(this, (start))
|
||||
IS_UTF8_ALIGNED2(this, (end))
|
||||
|
||||
char *s = NULL;
|
||||
|
||||
|
||||
+73
-28
@@ -1738,44 +1738,70 @@ int Fl_Text_Display::handle_vline(
|
||||
return 0;
|
||||
}
|
||||
|
||||
char currChar = 0, prevChar = 0;
|
||||
// draw the line
|
||||
style = position_style(lineStartPos, lineLen, 0);
|
||||
for (i=0; i<lineLen; ) {
|
||||
int len = fl_utf8len(lineStr[i]);
|
||||
currChar = lineStr[i]; // one byte is enough to handele tabs and other cases
|
||||
int len = fl_utf8len(currChar);
|
||||
charStyle = position_style(lineStartPos, lineLen, i);
|
||||
// FIXME: if the character is a tab, we need to do the correct indenting
|
||||
// FIXME: if the character is an optional hyphen, we need to ignore it unless we wrap the text
|
||||
if (charStyle!=style) {
|
||||
// draw a segment whenever the style changes
|
||||
int w = int( string_width( lineStr+startIndex, i-startIndex, style ) );
|
||||
if (mode==DRAW_LINE)
|
||||
draw_string( style, startX, Y, startX+w, lineStr+startIndex, i-startIndex );
|
||||
if (mode==FIND_INDEX && startX+w>rightClip) {
|
||||
// find x pos inside block
|
||||
int di = find_x(lineStr+startIndex, i-startIndex, style, rightClip-startX);
|
||||
free(lineStr);
|
||||
IS_UTF8_ALIGNED2(buffer(), (lineStartPos+startIndex+di))
|
||||
return lineStartPos + startIndex + di;
|
||||
if (charStyle!=style || currChar=='\t' || prevChar=='\t') {
|
||||
// draw a segment whenever the style changes or a Tab is found
|
||||
int w = 0;
|
||||
if (prevChar=='\t') {
|
||||
// draw a single Tab space
|
||||
int xAbs = (mode==GET_WIDTH) ? startX : startX+mHorizOffset-text_area.x;
|
||||
w = (((xAbs/100)+1)*100) - xAbs;
|
||||
if (mode==DRAW_LINE)
|
||||
draw_string( style|BG_ONLY_MASK, startX, Y, startX+w, 0, 0 );
|
||||
if (mode==FIND_INDEX && startX+w>rightClip) {
|
||||
// find x pos inside block
|
||||
free(lineStr);
|
||||
return lineStartPos + startIndex;
|
||||
}
|
||||
} else {
|
||||
// draw a text segment
|
||||
w = int( string_width( lineStr+startIndex, i-startIndex, style ) );
|
||||
if (mode==DRAW_LINE)
|
||||
draw_string( style, startX, Y, startX+w, lineStr+startIndex, i-startIndex );
|
||||
if (mode==FIND_INDEX && startX+w>rightClip) {
|
||||
// find x pos inside block
|
||||
int di = find_x(lineStr+startIndex, i-startIndex, style, rightClip-startX);
|
||||
free(lineStr);
|
||||
IS_UTF8_ALIGNED2(buffer(), (lineStartPos+startIndex+di))
|
||||
return lineStartPos + startIndex + di;
|
||||
}
|
||||
}
|
||||
style = charStyle;
|
||||
startX += w;
|
||||
startIndex = i;
|
||||
}
|
||||
if (len==-1) {
|
||||
// FIXME: what happened? Is there an illegal charater, or an illegal index?
|
||||
len = 1;
|
||||
}
|
||||
i += len;
|
||||
prevChar = currChar;
|
||||
}
|
||||
int w = int( string_width( lineStr+startIndex, i-startIndex, style ) );
|
||||
if (mode==DRAW_LINE)
|
||||
draw_string( style, startX, Y, startX+w, lineStr+startIndex, i-startIndex );
|
||||
if (mode==FIND_INDEX) {
|
||||
// find x pos inside block
|
||||
int di = find_x(lineStr+startIndex, i-startIndex, style, rightClip-startX);
|
||||
free(lineStr);
|
||||
IS_UTF8_ALIGNED2(buffer(), (lineStartPos+startIndex+di))
|
||||
return lineStartPos + startIndex + di;
|
||||
int w = 0;
|
||||
if (currChar=='\t') {
|
||||
// draw a single Tab space
|
||||
int xAbs = (mode==GET_WIDTH) ? startX : startX+mHorizOffset-text_area.x;
|
||||
w = (((xAbs/100)+1)*100) - xAbs;
|
||||
if (mode==DRAW_LINE)
|
||||
draw_string( style|BG_ONLY_MASK, startX, Y, startX+w, 0, 0 );
|
||||
if (mode==FIND_INDEX) {
|
||||
// find x pos inside block
|
||||
free(lineStr);
|
||||
return lineStartPos + startIndex + ( rightClip-startX>w ? 1 : 0 );
|
||||
}
|
||||
} else {
|
||||
w = int( string_width( lineStr+startIndex, i-startIndex, style ) );
|
||||
if (mode==DRAW_LINE)
|
||||
draw_string( style, startX, Y, startX+w, lineStr+startIndex, i-startIndex );
|
||||
if (mode==FIND_INDEX) {
|
||||
// find x pos inside block
|
||||
int di = find_x(lineStr+startIndex, i-startIndex, style, rightClip-startX);
|
||||
free(lineStr);
|
||||
IS_UTF8_ALIGNED2(buffer(), (lineStartPos+startIndex+di))
|
||||
return lineStartPos + startIndex + di;
|
||||
}
|
||||
}
|
||||
if (mode==GET_WIDTH) {
|
||||
free(lineStr);
|
||||
@@ -1944,7 +1970,17 @@ void Fl_Text_Display::draw_string(int style,
|
||||
if (!(style & BG_ONLY_MASK)) {
|
||||
fl_color( foreground );
|
||||
fl_font( font, fsize );
|
||||
fl_draw( string, nChars, X, Y + mMaxsize - fl_descent());
|
||||
|
||||
// FIXME: remove this again!
|
||||
char *buf = (char*)malloc(nChars);
|
||||
memcpy(buf, string, nChars);
|
||||
int i = 0;
|
||||
for (i=0; i<nChars; i++) {
|
||||
if (buf[i]=='\t') buf[i] = '$';
|
||||
}
|
||||
fl_draw( buf, nChars, X, Y + mMaxsize - fl_descent());
|
||||
|
||||
//fl_draw( string, nChars, X, Y + mMaxsize - fl_descent());
|
||||
}
|
||||
|
||||
// CET - FIXME
|
||||
@@ -2157,6 +2193,15 @@ double Fl_Text_Display::string_width( const char *string, int length, int style
|
||||
fsize = textsize();
|
||||
}
|
||||
fl_font( font, fsize );
|
||||
|
||||
// FIXME: remove this again!
|
||||
char *buf = (char*)malloc(length);
|
||||
memcpy(buf, string, length);
|
||||
int i = 0;
|
||||
for (i=0; i<length; i++) {
|
||||
if (buf[i]=='\t') buf[i] = '$';
|
||||
}
|
||||
return fl_width( buf, length);
|
||||
|
||||
return fl_width( string, length );
|
||||
}
|
||||
|
||||
+12
-1
@@ -304,7 +304,6 @@ void
|
||||
style_init(void) {
|
||||
char *style = new char[textbuf->length() + 1];
|
||||
char *text = textbuf->text();
|
||||
|
||||
|
||||
memset(style, 'A', textbuf->length());
|
||||
style[textbuf->length()] = '\0';
|
||||
@@ -778,9 +777,21 @@ Fl_Window* new_view() {
|
||||
w->editor->textsize(TS);
|
||||
//w->editor->wrap_mode(Fl_Text_Editor::WRAP_AT_BOUNDS, 100);
|
||||
w->editor->buffer(textbuf);
|
||||
w->editor->textfont(FL_HELVETICA);
|
||||
textbuf->text(
|
||||
"12345678912345678901234567890\n"
|
||||
"\tqwertyuiop\n"
|
||||
"WWWWWWWW\tqwertyuiop\n"
|
||||
"iiiiiiii\tqwertyuiop\n"
|
||||
"\tasdfghjkl\n"
|
||||
"\t\tasdfghjkl\t\n"
|
||||
"\t\t\tzxcvbnm,\t\t\n"
|
||||
"a\tb\tc\td\te\n"
|
||||
"nvfdnv");
|
||||
w->editor->highlight_data(stylebuf, styletable,
|
||||
sizeof(styletable) / sizeof(styletable[0]),
|
||||
'A', style_unfinished_cb, 0);
|
||||
style_init();
|
||||
w->end();
|
||||
w->resizable(w->editor);
|
||||
w->callback((Fl_Callback *)close_cb, w);
|
||||
|
||||
Reference in New Issue
Block a user