bool
LargeTextWindow::OnKeyCheck(unsigned key_code) const
{
    switch (key_code) {
    case KEY_UP:
        return origin > 0;

    case KEY_DOWN:
        return GetRowCount() > GetVisibleRows() &&
               origin < GetRowCount() - GetVisibleRows();
    }

    return false;
}
void
LargeTextWindow::OnResize(PixelSize new_size)
{
    Window::OnResize(new_size);

    if (!value.empty()) {
        /* revalidate the scroll position */
        const unsigned visible_rows = GetVisibleRows();
        const unsigned row_count = GetRowCount();
        if (visible_rows >= row_count)
            origin = 0;
        else if (origin > row_count - visible_rows)
            origin = row_count - visible_rows;
        Invalidate();
    }
}
Exemple #3
0
void
LargeTextWindow::ScrollVertically(int delta_lines)
{
  const unsigned visible_rows = GetVisibleRows();
  const unsigned row_count = GetRowCount();

  if (visible_rows >= row_count)
    /* all rows are visible at a time, no scrolling needed/possible */
    return;

  unsigned new_origin = origin + delta_lines;
  if ((int)new_origin < 0)
    new_origin = 0;
  else if (new_origin > row_count - visible_rows)
    new_origin = row_count - visible_rows;

  if (new_origin != origin) {
    origin = new_origin;
    Invalidate();
  }
}