all repos — fluxbox @ b9ed1c16de3cab491dc8a747bcf60a0b8ead7e91

custom fork of the fluxbox windowmanager

improve consistency

for a std::string::size_type, the right value to use is not "-1", but
std::string::npos.
Mathias Gumz akira@fluxbox.org
commit

b9ed1c16de3cab491dc8a747bcf60a0b8ead7e91

parent

a9e17d409164b8141bc4c4cde5af767ce7ac894e

2 files changed, 10 insertions(+), 9 deletions(-)

jump to
M src/FbTk/TextBox.ccsrc/FbTk/TextBox.cc

@@ -54,7 +54,7 @@ m_gc(0),

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 @@ m_gc(0),

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 @@ // a modifier key by itself doesn't do anything

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 @@ val += keychar[0];

insertText(val); } if ((event.state & ShiftMask) != ShiftMask) - m_select_pos = -1; + m_select_pos = std::string::npos; clear(); }

@@ -432,7 +432,7 @@

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;

@@ -459,7 +459,7 @@ if (next_pos + 1 < pos)

break; pos = next_pos; } - if (pos < 0) + if (pos < 0) pos = 0; return pos;

@@ -517,7 +517,7 @@ }

adjustPos(); } else { - m_select_pos = -1; + m_select_pos = std::string::npos; } clear(); }
M src/FbTk/TextBox.hhsrc/FbTk/TextBox.hh

@@ -39,7 +39,7 @@

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 @@ GC gc() const { return m_gc; }

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