diff --git a/ChangeLog b/ChangeLog index 18204b55..b3a67b82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2018-09-02 Markus Gans * Fix mouse wheel behavior over horizontal scroll bars in FTextView + * Some small code improvements 2018-09-01 Markus Gans * Compiles now with newer gcc diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index 5afcbc52..e81cdb62 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -91,7 +91,7 @@ void move (int xold, int yold, int xnew, int ynew) // prints the cursor move escape sequence std::string sequence; char* buffer; - char from[10], to[10], byte[20]; + char from[26], to[26], byte[20]; uInt len; const std::string ctrl_character[] = { @@ -104,8 +104,8 @@ void move (int xold, int yold, int xnew, int ynew) term_boundaries(xold, yold); term_boundaries(xnew, ynew); - snprintf (from, sizeof(from), "(%d;%d)", xold, yold); - snprintf (to, sizeof(to), "(%d;%d)", xnew, ynew); + snprintf (from, sizeof(from), "(%3d;%3d)", xold, yold); + snprintf (to, sizeof(to), "(%3d;%3d)", xnew, ynew); std::cout << std::right << std::setw(10) << from << " -> " << std::left << std::setw(10) << to diff --git a/src/fkeyboard.cpp b/src/fkeyboard.cpp index 56a4fb5a..9124f883 100644 --- a/src/fkeyboard.cpp +++ b/src/fkeyboard.cpp @@ -372,8 +372,12 @@ int FKeyboard::UTF8decode (const char utf8[]) { register int ucs = 0; const int max = 4; + int len = int(std::strlen(utf8)); - for (register int i = 0; i < int(std::strlen(utf8)) && i < max; ++i) + if ( len > max ) + len = max; + + for (register int i = 0; i < len; ++i) { register uChar ch = uChar(utf8[i]); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index a2dfec1b..97d58eff 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -538,15 +538,11 @@ void FLineEdit::onTimer (FTimerEvent*) return; } - text_offset--; + if ( text_offset > 0 ) + text_offset--; - if ( text_offset < 0 ) - text_offset = 0; - - cursor_pos--; - - if ( cursor_pos < 0 ) - cursor_pos = 0; + if ( cursor_pos > 0 ) + cursor_pos--; break; @@ -557,15 +553,11 @@ void FLineEdit::onTimer (FTimerEvent*) return; } - text_offset++; + if ( text_offset <= len - getWidth() + 1 ) + text_offset++; - if ( text_offset > len - getWidth() + 2 ) - text_offset = len - getWidth() + 2; - - cursor_pos++; - - if ( cursor_pos > len ) - cursor_pos = len; + if ( cursor_pos < len ) + cursor_pos++; break; @@ -804,10 +796,8 @@ void FLineEdit::drawInputField() //---------------------------------------------------------------------- inline void FLineEdit::keyLeft() { - cursor_pos--; - - if ( cursor_pos < 0 ) - cursor_pos = 0; + if ( cursor_pos > 0 ) + cursor_pos--; if ( cursor_pos < text_offset ) text_offset--; @@ -817,10 +807,9 @@ inline void FLineEdit::keyLeft() inline void FLineEdit::keyRight() { int len = int(text.getLength()); - cursor_pos++; - if ( cursor_pos >= len ) - cursor_pos = len; + if ( cursor_pos < len ) + cursor_pos++; if ( cursor_pos - text_offset >= getWidth() - 2 && text_offset <= len - getWidth() + 1 ) diff --git a/src/flistview.cpp b/src/flistview.cpp index 9c0156c1..457a693f 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -1814,10 +1814,8 @@ inline void FListView::keyLeft (int& first_line_position_before) else { // Scroll left - xoffset--; - - if ( xoffset < 0 ) - xoffset = 0; + if ( xoffset > 0 ) + xoffset--; } } @@ -1838,10 +1836,8 @@ inline void FListView::keyRight (int& first_line_position_before) else { // Scroll right - xoffset++; - - if ( xoffset > xoffset_end ) - xoffset = xoffset_end; + if ( xoffset < xoffset_end ) + xoffset++; if ( xoffset < 0 ) xoffset = 0;