Exemplo n.º 1
0
bool
TopWindow::on_event(const SDL_Event &event)
{
  switch (event.type) {
    Window *w;

  case SDL_VIDEOEXPOSE:
    invalidated_lock.Lock();
    invalidated = false;
    invalidated_lock.Unlock();

    expose();
    return true;

  case SDL_KEYDOWN:
    w = get_focused_window();
    if (w == NULL)
      w = this;

    return w->on_key_down(event.key.keysym.sym);

  case SDL_KEYUP:
    w = get_focused_window();
    if (w == NULL)
      w = this;

    return w->on_key_up(event.key.keysym.sym);

  case SDL_MOUSEMOTION:
    // XXX keys
    return on_mouse_move(event.motion.x, event.motion.y, 0);

  case SDL_MOUSEBUTTONDOWN:
    if (event.button.button == SDL_BUTTON_WHEELUP)
      return on_mouse_wheel(event.button.x, event.button.y, 1);
    else if (event.button.button == SDL_BUTTON_WHEELDOWN)
      return on_mouse_wheel(event.button.x, event.button.y, -1);

    static PeriodClock double_click;
    return double_click.check_always_update(300)
      ? on_mouse_down(event.button.x, event.button.y)
      : on_mouse_double(event.button.x, event.button.y);

  case SDL_MOUSEBUTTONUP:
    if (event.button.button == SDL_BUTTON_WHEELUP ||
        event.button.button == SDL_BUTTON_WHEELDOWN)
      /* the wheel has already been handled in SDL_MOUSEBUTTONDOWN */
      return false;

    return on_mouse_up(event.button.x, event.button.y);

  case SDL_QUIT:
    return on_close();
  }

  return false;
}
Exemplo n.º 2
0
WindowReference
ContainerWindow::GetFocusedWindowReference()
{
  Window *focus = get_focused_window();
  return focus != NULL
    ? WindowReference(*this, *focus)
    : WindowReference();
}
Exemplo n.º 3
0
void
ContainerWindow::focus_previous_control()
{
  Window *focused = get_focused_window();
  Window *control = focused != NULL
    ? find_previous_control(focused)
    : NULL;
  if (control == NULL)
    control = find_last_control();
  if (control != NULL)
    control->set_focus();
}
Exemplo n.º 4
0
void
ContainerWindow::focus_next_control()
{
  Window *focused = get_focused_window();
  if (focused != NULL) {
    Window *control = find_next_control(focused);
    if (control != NULL)
      control->set_focus();
    else
      focus_first_control();
  } else
    focus_first_control();
}
Exemplo n.º 5
0
void
ContainerWindow::set_active_child(Window &child)
{
  if (active_child == &child)
    return;

  Window *focus = get_focused_window();
  if (focus != NULL)
    focus->on_killfocus();

  active_child = &child;

  if (parent != NULL)
    parent->set_active_child(*this);
}