scrollpad: make m_beginning unsigned

This commit is contained in:
Andrzej Rybczak
2012-09-06 15:09:07 +02:00
parent fcf9ffe668
commit f0cac617fa
2 changed files with 15 additions and 28 deletions

View File

@@ -35,17 +35,10 @@ Scrollpad::Scrollpad(size_t startx,
m_beginning(0), m_beginning(0),
m_found_value_begin(-1), m_found_value_begin(-1),
m_found_value_end(-1), m_found_value_end(-1),
m_real_height(1) m_real_height(height)
{ {
} }
Scrollpad::Scrollpad(const Scrollpad &s) : Window(s)
{
m_buffer << s.m_buffer;
m_beginning = s.m_beginning;
m_real_height = s.m_real_height;
}
void Scrollpad::flush() void Scrollpad::flush()
{ {
m_real_height = 1; m_real_height = 1;
@@ -124,10 +117,9 @@ void Scrollpad::removeFormatting()
void Scrollpad::refresh() void Scrollpad::refresh()
{ {
int MaxBeginning = m_real_height-m_height; assert(m_real_height >= m_real_height);
assert(MaxBeginning >= 0); size_t max_beginning = m_real_height - m_height;
if (m_beginning > MaxBeginning) m_beginning = std::min(m_beginning, max_beginning);
m_beginning = MaxBeginning;
prefresh(m_window, m_beginning, 0, m_start_y, m_start_x, m_start_y+m_height-1, m_start_x+m_width-1); prefresh(m_window, m_beginning, 0, m_start_y, m_start_x, m_start_y+m_height-1, m_start_x+m_width-1);
} }
@@ -139,34 +131,33 @@ void Scrollpad::resize(size_t new_width, size_t new_height)
void Scrollpad::scroll(Where where) void Scrollpad::scroll(Where where)
{ {
int MaxBeginning = /*itsContent.size() < m_height ? 0 : */m_real_height-m_height; assert(m_real_height >= m_height);
size_t max_beginning = m_real_height - m_height;
switch (where) switch (where)
{ {
case wUp: case wUp:
{ {
if (m_beginning > 0) if (m_beginning > 0)
m_beginning--; --m_beginning;
break; break;
} }
case wDown: case wDown:
{ {
if (m_beginning < MaxBeginning) if (m_beginning < max_beginning)
m_beginning++; ++m_beginning;
break; break;
} }
case wPageUp: case wPageUp:
{ {
m_beginning -= m_height; if (m_beginning > m_height)
if (m_beginning < 0) m_beginning -= m_height;
else
m_beginning = 0; m_beginning = 0;
break; break;
} }
case wPageDown: case wPageDown:
{ {
m_beginning += m_height; m_beginning = std::min(m_beginning + m_height, max_beginning);
if (m_beginning > MaxBeginning)
m_beginning = MaxBeginning;
break; break;
} }
case wHome: case wHome:
@@ -176,7 +167,7 @@ void Scrollpad::scroll(Where where)
} }
case wEnd: case wEnd:
{ {
m_beginning = MaxBeginning; m_beginning = max_beginning;
break; break;
} }
} }

View File

@@ -41,10 +41,6 @@ struct Scrollpad: public Window
Scrollpad(size_t startx, size_t starty, size_t width, size_t height, Scrollpad(size_t startx, size_t starty, size_t width, size_t height,
const std::string &title, Color color, Border border); const std::string &title, Color color, Border border);
/// Copies the scrollpad
/// @param s copied scrollpad
Scrollpad(const Scrollpad &s);
/// Prints the text stored in internal buffer to window. Note that /// Prints the text stored in internal buffer to window. Note that
/// all changes that has been made for text stored in scrollpad won't /// all changes that has been made for text stored in scrollpad won't
/// be visible until one invokes this function /// be visible until one invokes this function
@@ -120,7 +116,7 @@ struct Scrollpad: public Window
private: private:
basic_buffer<my_char_t> m_buffer; basic_buffer<my_char_t> m_buffer;
int m_beginning; size_t m_beginning;
bool m_found_for_each; bool m_found_for_each;
bool m_found_case_sensitive; bool m_found_case_sensitive;