Ejemplo n.º 1
0
bool
ListControl::OnKeyDown(unsigned key_code)
{
  scroll_bar.DragEnd(this);
  kinetic_timer.Cancel();

  switch (key_code) {
  case KEY_RETURN:
    if (CanActivateItem())
      ActivateItem();
    return true;

  case KEY_UP:
    // previous item
    if (GetCursorIndex() <= 0)
      break;

    MoveCursor(-1);
    return true;

  case KEY_DOWN:
    // next item
    if (GetCursorIndex() +1 >= length)
      break;

    MoveCursor(1);
    return true;

  case KEY_LEFT:
    // page up
    MoveCursor(-(int)items_visible);
    return true;

  case KEY_RIGHT:
    // page down
    MoveCursor(items_visible);
    return true;

  case KEY_HOME:
    SetCursorIndex(0);
    return true;

  case KEY_END:
    if (length > 0) {
      SetCursorIndex(length - 1);
    }
    return true;

  case KEY_PRIOR:
    MoveCursor(-(int)items_visible);
    return true;

  case KEY_NEXT:
    MoveCursor(items_visible);
    return true;
  }
  return PaintWindow::OnKeyDown(key_code);
}
Ejemplo n.º 2
0
void
ListControl::SetLength(unsigned n)
{
  if (n == length)
    return;

  unsigned cursor = GetCursorIndex();

  length = n;

  if (n == 0)
    cursor = 0;
  else if (cursor >= n)
    cursor = n - 1;

  items_visible = GetHeight() / item_height;

  if (n <= items_visible)
    origin = 0;
  else if (origin + items_visible > n)
    origin = n - items_visible;
  else if (cursor < origin)
    origin = cursor;

  show_or_hide_scroll_bar();
  Invalidate();

  SetCursorIndex(cursor);
}
Ejemplo n.º 3
0
inline void
MapItemListWidget::OnAckClicked()
{
  const AirspaceMapItem &as_item = *(const AirspaceMapItem *)
    list[GetCursorIndex()];
  GetAirspaceWarnings()->AcknowledgeDay(*as_item.airspace);
  UpdateButtons();
}
Ejemplo n.º 4
0
bool
ListControl::OnKeyCheck(unsigned key_code) const
{
  switch (key_code) {
  case KEY_RETURN:
    return CanActivateItem();

  case KEY_UP:
    return GetCursorIndex() > 0;

  case KEY_DOWN:
    return GetCursorIndex() + 1 < length;

  default:
    return false;
  }
}
Ejemplo n.º 5
0
bool
ListControl::CanActivateItem() const
{
  if (IsEmpty())
    return false;

  return cursor_handler != NULL &&
    cursor_handler->CanActivateItem(GetCursorIndex());
}
Ejemplo n.º 6
0
void
ListControl::ActivateItem()
{
  assert(CanActivateItem());

  unsigned index = GetCursorIndex();
  assert(index < GetLength());
  if (cursor_handler != NULL)
    cursor_handler->OnActivateItem(index);
}
Ejemplo n.º 7
0
bool
ListControl::OnKeyCheck(unsigned key_code) const
{
  switch (key_code) {
  case KEY_RETURN:
    return CanActivateItem();

  case KEY_LEFT:
    if (!HasPointer())
      /* no wrap-around on Altair, as KEY_LEFT is usually used to
         switch to the previous dialog page */
      return true;

    return GetCursorIndex() > 0;

  case KEY_UP:
    if (!HasPointer() && IsShort())
      /* no page up/down behaviour in short lists on Altair; this
         rotation knob should move focus */
      return false;

    return GetCursorIndex() > 0;

  case KEY_RIGHT:
    if (!HasPointer())
      /* no wrap-around on Altair, as KEY_RIGHT is usually used to
         switch to the next dialog page */
      return true;

    return GetCursorIndex() + 1 < length;

  case KEY_DOWN:
    if (!HasPointer() && IsShort())
      /* no page up/down behaviour in short lists on Altair; this
         rotation knob should move focus */
      return false;

    return GetCursorIndex() + 1 < length;

  default:
    return false;
  }
}
Ejemplo n.º 8
0
inline void
MapItemListWidget::OnGotoClicked()
{
  if (protected_task_manager == NULL)
    return;

  unsigned index = GetCursorIndex();
  auto const &item = *list[index];

  assert(item.type == MapItem::WAYPOINT);

  auto waypoint = ((const WaypointMapItem &)item).waypoint;
  protected_task_manager->DoGoto(std::move(waypoint));
  cancel_button->Click();
}
Ejemplo n.º 9
0
void
AlternatesListWidget::OnAction(int id)
{
  switch (id) {
  case GOTO:
    unsigned index = GetCursorIndex();

    auto const &item = alternates[index];
    auto const &waypoint = item.waypoint;

    protected_task_manager->DoGoto(waypoint);
    cancel_button->OnClicked();

    break;
  }
}
Ejemplo n.º 10
0
void
ListControl::OnResize(PixelSize new_size)
{
  PaintWindow::OnResize(new_size);

  items_visible = new_size.cy / item_height;

  if (unsigned(new_size.cy) >= length * item_height) {
    /* after the resize, there is enough room for all list items -
       scroll back to the top */
    origin = pixel_pan = 0;
  }

  if (length > 0)
    /* make sure the cursor is still visible */
    EnsureVisible(GetCursorIndex());

  show_or_hide_scroll_bar();
}
Ejemplo n.º 11
0
bool
ListControl::SetCursorIndex(unsigned i)
{
  if (i >= length)
    return false;

  if (i == GetCursorIndex())
    return true;

  EnsureVisible(i);

  Invalidate_item(cursor);
  cursor = i;
  Invalidate_item(cursor);

  if (cursor_handler != nullptr)
    cursor_handler->OnCursorMoved(i);
  return true;
}
Ejemplo n.º 12
0
 void UpdateButtons() {
   const unsigned current = GetCursorIndex();
   relocate_button->SetEnabled(!RealStartExists || current >= 1);
   remove_button->SetEnabled((!RealStartExists || current >= 1) &&
                             current < GetList().GetLength() - 1);
 }
Ejemplo n.º 13
0
 void UpdateButtons() {
   const unsigned current = GetCursorIndex();
   details_button->SetEnabled(HasDetails(*list[current]));
   goto_button->SetEnabled(CanGotoItem(current));
   ack_button->SetEnabled(CanAckItem(current));
 }
Ejemplo n.º 14
0
bool
ListControl::OnMouseDown(PixelScalar x, PixelScalar y)
{
  // End any previous drag
  scroll_bar.DragEnd(this);
  drag_end();

#ifndef _WIN32_WCE
  kinetic_timer.Cancel();
#endif

  RasterPoint Pos;
  Pos.x = x;
  Pos.y = y;

  // If possible -> Give focus to the Control
  const bool had_focus = HasFocus();
  if (!had_focus)
    SetFocus();

  if (scroll_bar.IsInsideSlider(Pos)) {
    // if click is on scrollbar handle
    // -> start mouse drag
    scroll_bar.DragBegin(this, Pos.y);
  } else if (scroll_bar.IsInside(Pos)) {
    // if click in scroll bar up/down/pgup/pgdn
    if (scroll_bar.IsInsideUpArrow(Pos.y))
      // up
      MoveOrigin(-1);
    else if (scroll_bar.IsInsideDownArrow(Pos.y))
      // down
      MoveOrigin(1);
    else if (scroll_bar.IsAboveSlider(Pos.y))
      // page up
      MoveOrigin(-(int)items_visible);
    else if (scroll_bar.IsBelowSlider(Pos.y))
      // page down
      MoveOrigin(items_visible);
  } else {
    // if click in ListBox area
    // -> select appropriate item

    int index = ItemIndexAt(y);
    // If mouse was clicked outside the list items -> cancel
    if (index < 0)
      return false;

    drag_y = GetPixelOrigin() + y;
    drag_y_window = y;

    if (had_focus && (unsigned)index == GetCursorIndex() &&
        CanActivateItem()) {
      drag_mode = DragMode::CURSOR;
      Invalidate_item(cursor);
    } else {
      // If item was not selected before
      // -> select it
      SetCursorIndex(index);
      drag_mode = DragMode::SCROLL;
    }
#ifndef _WIN32_WCE
    kinetic.MouseDown(GetPixelOrigin());
#endif
    SetCapture();
  }

  return true;
}
Ejemplo n.º 15
0
bool
ListControl::OnKeyDown(unsigned key_code)
{
  scroll_bar.DragEnd(this);

#ifndef _WIN32_WCE
  kinetic_timer.Cancel();
#endif

  switch (key_code) {
#ifdef GNAV
  // JMW added this to make data entry easier
  case KEY_APP4:
#endif
  case KEY_RETURN:
    if (CanActivateItem())
      ActivateItem();
    return true;

  case KEY_UP:
  case KEY_LEFT:
    if (!HasPointer() ^ (key_code == KEY_LEFT)) {
      // page up
      MoveCursor(-(int)items_visible);
      return true;
    } else {
      // previous item
      if (GetCursorIndex() <= 0)
        break;

      MoveCursor(-1);
      return true;
    }

  case KEY_DOWN:
  case KEY_RIGHT:
    if (!HasPointer() ^ (key_code == KEY_RIGHT)) {
      // page down
      MoveCursor(items_visible);
      return true;
    } else {
      // next item
      if (GetCursorIndex() +1 >= length)
        break;

      MoveCursor(1);
      return true;
    }

  case KEY_HOME:
    SetCursorIndex(0);
    return true;

  case KEY_END:
    if (length > 0) {
      SetCursorIndex(length - 1);
    }
    return true;

  case KEY_PRIOR:
    MoveCursor(-(int)items_visible);
    return true;

  case KEY_NEXT:
    MoveCursor(items_visible);
    return true;
  }
  return PaintWindow::OnKeyDown(key_code);
}
Ejemplo n.º 16
0
 void UpdateButtons() {
   const unsigned current = GetCursorIndex();
   details_button->SetEnabled(HasDetails(*list[current]));
 }