improve consistency

for a std::string::size_type, the right value to use is not "-1", but
std::string::npos.
This commit is contained in:
Mathias Gumz 2016-05-28 16:57:43 +02:00
parent a9e17d4091
commit b9ed1c16de
2 changed files with 10 additions and 9 deletions

View file

@ -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<signed>(width()))
if (m_cursor_pos >= 0 && text_width < static_cast<signed>(width()))
return;
int start_pos = 0;
@ -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();
}

View file

@ -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();