aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2016-05-28 14:57:43 (GMT)
committerMathias Gumz <akira@fluxbox.org>2016-05-28 14:57:43 (GMT)
commitb9ed1c16de3cab491dc8a747bcf60a0b8ead7e91 (patch)
tree1ac5f12cd6bdf3586b716b135f25fa73d4131287 /src/FbTk
parenta9e17d409164b8141bc4c4cde5af767ce7ac894e (diff)
downloadfluxbox-b9ed1c16de3cab491dc8a747bcf60a0b8ead7e91.zip
fluxbox-b9ed1c16de3cab491dc8a747bcf60a0b8ead7e91.tar.bz2
improve consistency
for a std::string::size_type, the right value to use is not "-1", but std::string::npos.
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/TextBox.cc14
-rw-r--r--src/FbTk/TextBox.hh5
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,
54 m_cursor_pos(0), 54 m_cursor_pos(0),
55 m_start_pos(0), 55 m_start_pos(0),
56 m_end_pos(0), 56 m_end_pos(0),
57 m_select_pos(-1) { 57 m_select_pos(std::string::npos) {
58 58
59 FbTk::EventManager::instance()->add(*this, *this); 59 FbTk::EventManager::instance()->add(*this, *this);
60} 60}
@@ -68,7 +68,7 @@ TextBox::TextBox(const FbWindow &parent,
68 m_cursor_pos(0), 68 m_cursor_pos(0),
69 m_start_pos(0), 69 m_start_pos(0),
70 m_end_pos(0), 70 m_end_pos(0),
71 m_select_pos(-1) { 71 m_select_pos(std::string::npos) {
72 72
73 FbTk::EventManager::instance()->add(*this, *this); 73 FbTk::EventManager::instance()->add(*this, *this);
74} 74}
@@ -277,7 +277,7 @@ void TextBox::keyPressEvent(XKeyEvent &event) {
277 if (IsModifierKey(ks)) return; 277 if (IsModifierKey(ks)) return;
278 278
279 279
280 if (m_select_pos == -1 && (event.state & ShiftMask) == ShiftMask) { 280 if (m_select_pos == std::string::npos && (event.state & ShiftMask) == ShiftMask) {
281 m_select_pos = m_cursor_pos + m_start_pos; 281 m_select_pos = m_cursor_pos + m_start_pos;
282 } 282 }
283 283
@@ -407,7 +407,7 @@ void TextBox::keyPressEvent(XKeyEvent &event) {
407 insertText(val); 407 insertText(val);
408 } 408 }
409 if ((event.state & ShiftMask) != ShiftMask) 409 if ((event.state & ShiftMask) != ShiftMask)
410 m_select_pos = -1; 410 m_select_pos = std::string::npos;
411 clear(); 411 clear();
412} 412}
413 413
@@ -432,7 +432,7 @@ void TextBox::adjustStartPos() {
432 const char* visual = m_text.visual().c_str(); 432 const char* visual = m_text.visual().c_str();
433 433
434 int text_width = font().textWidth(visual, m_end_pos); 434 int text_width = font().textWidth(visual, m_end_pos);
435 if (m_cursor_pos > -1 && text_width < static_cast<signed>(width())) 435 if (m_cursor_pos >= 0 && text_width < static_cast<signed>(width()))
436 return; 436 return;
437 437
438 int start_pos = 0; 438 int start_pos = 0;
@@ -459,7 +459,7 @@ unsigned int TextBox::findEmptySpaceLeft(){
459 break; 459 break;
460 pos = next_pos; 460 pos = next_pos;
461 } 461 }
462 if (pos < 0) 462 if (pos < 0)
463 pos = 0; 463 pos = 0;
464 464
465 return pos; 465 return pos;
@@ -517,7 +517,7 @@ void TextBox::select(std::string::size_type pos, int length)
517 517
518 adjustPos(); 518 adjustPos();
519 } else { 519 } else {
520 m_select_pos = -1; 520 m_select_pos = std::string::npos;
521 } 521 }
522 clear(); 522 clear();
523} 523}
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:
39 void setText(const FbTk::BiDiString &text); 39 void setText(const FbTk::BiDiString &text);
40 void setFont(const Font &font); 40 void setFont(const Font &font);
41 void setGC(GC gc); 41 void setGC(GC gc);
42 void setCursorPosition(int cursor); 42 void setCursorPosition(int cursor);
43 void setInputFocus(); 43 void setInputFocus();
44 void cursorEnd(); 44 void cursorEnd();
45 void cursorHome(); 45 void cursorHome();
@@ -65,7 +65,8 @@ public:
65 int cursorPosition() const { return m_cursor_pos; } 65 int cursorPosition() const { return m_cursor_pos; }
66 int textStartPos() const { return m_start_pos; } 66 int textStartPos() const { return m_start_pos; }
67 67
68 bool hasSelection() const { return m_select_pos != -1 && m_select_pos != m_cursor_pos + m_start_pos; } 68 bool hasSelection() const {
69 return (m_select_pos != std::string::npos) && (m_select_pos != m_cursor_pos + m_start_pos); }
69 void select(std::string::size_type pos, int length); 70 void select(std::string::size_type pos, int length);
70 void selectAll(); 71 void selectAll();
71 72