From b9ed1c16de3cab491dc8a747bcf60a0b8ead7e91 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sat, 28 May 2016 16:57:43 +0200 Subject: improve consistency for a std::string::size_type, the right value to use is not "-1", but std::string::npos. --- src/FbTk/TextBox.cc | 14 +++++++------- src/FbTk/TextBox.hh | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/FbTk/TextBox.cc b/src/FbTk/TextBox.cc index 838a069..e1f9e32 100644 --- a/src/FbTk/TextBox.cc +++ b/src/FbTk/TextBox.cc @@ -54,7 +54,7 @@ TextBox::TextBox(int screen_num, m_cursor_pos(0), m_start_pos(0), m_end_pos(0), - m_select_pos(-1) { + m_select_pos(std::string::npos) { FbTk::EventManager::instance()->add(*this, *this); } @@ -68,7 +68,7 @@ TextBox::TextBox(const FbWindow &parent, m_cursor_pos(0), m_start_pos(0), m_end_pos(0), - m_select_pos(-1) { + m_select_pos(std::string::npos) { FbTk::EventManager::instance()->add(*this, *this); } @@ -277,7 +277,7 @@ void TextBox::keyPressEvent(XKeyEvent &event) { if (IsModifierKey(ks)) return; - if (m_select_pos == -1 && (event.state & ShiftMask) == ShiftMask) { + if (m_select_pos == std::string::npos && (event.state & ShiftMask) == ShiftMask) { m_select_pos = m_cursor_pos + m_start_pos; } @@ -407,7 +407,7 @@ void TextBox::keyPressEvent(XKeyEvent &event) { insertText(val); } if ((event.state & ShiftMask) != ShiftMask) - m_select_pos = -1; + m_select_pos = std::string::npos; clear(); } @@ -432,7 +432,7 @@ void TextBox::adjustStartPos() { const char* visual = m_text.visual().c_str(); int text_width = font().textWidth(visual, m_end_pos); - if (m_cursor_pos > -1 && text_width < static_cast(width())) + if (m_cursor_pos >= 0 && text_width < static_cast(width())) return; int start_pos = 0; @@ -459,7 +459,7 @@ unsigned int TextBox::findEmptySpaceLeft(){ break; pos = next_pos; } - if (pos < 0) + if (pos < 0) pos = 0; return pos; @@ -517,7 +517,7 @@ void TextBox::select(std::string::size_type pos, int length) adjustPos(); } else { - m_select_pos = -1; + m_select_pos = std::string::npos; } clear(); } diff --git a/src/FbTk/TextBox.hh b/src/FbTk/TextBox.hh index 2c1ef9d..a3b857f 100644 --- a/src/FbTk/TextBox.hh +++ b/src/FbTk/TextBox.hh @@ -39,7 +39,7 @@ public: void setText(const FbTk::BiDiString &text); void setFont(const Font &font); void setGC(GC gc); - void setCursorPosition(int cursor); + void setCursorPosition(int cursor); void setInputFocus(); void cursorEnd(); void cursorHome(); @@ -65,7 +65,8 @@ public: int cursorPosition() const { return m_cursor_pos; } int textStartPos() const { return m_start_pos; } - bool hasSelection() const { return m_select_pos != -1 && m_select_pos != m_cursor_pos + m_start_pos; } + bool hasSelection() const { + return (m_select_pos != std::string::npos) && (m_select_pos != m_cursor_pos + m_start_pos); } void select(std::string::size_type pos, int length); void selectAll(); -- cgit v0.11.2