Ejemplo n.º 1
0
gboolean iupgtkKeyReleaseEvent(GtkWidget *widget, GdkEventKey *evt, Ihandle *ih)
{
  /* this is called only for canvas */
  int result;
  int code = iupgtkKeyDecode(evt);
  if (code == 0) 
    return FALSE;

  result = iupKeyCallKeyPressCb(ih, code, 0);
  if (result == IUP_CLOSE)
  {
    IupExitLoop();
    return FALSE;
  }
  if (result == IUP_IGNORE)
    return TRUE;

  (void)widget;
  return FALSE;
}
Ejemplo n.º 2
0
gboolean iupgtkKeyPressEvent(GtkWidget *widget, GdkEventKey *evt, Ihandle *ih)
{
  int result;
  int code = iupgtkKeyDecode(evt);
  if (code == 0) 
    return FALSE;

  /* Avoid duplicate calls if a child of a native container contains the focus.
     GTK will call the callback for the child and for the container.
     Ignore the one sent to the parent. For now only IupDialog and IupTabs
     have keyboard signals intercepted.
     */
  if (iupObjectIsNativeContainer(ih))
  {
    GtkWindow* win = (GtkWindow*)IupGetDialog(ih)->handle;
    GtkWidget *widget_focus = gtk_window_get_focus(win);
    if (widget_focus && widget_focus != widget)
      return FALSE;
  }

  result = iupKeyCallKeyCb(ih, code);
  if (result == IUP_CLOSE)
  {
    IupExitLoop();
    return FALSE;
  }
  if (result == IUP_IGNORE)
    return TRUE;

  /* in the previous callback the dialog could be destroyed */
  if (iupObjectCheck(ih))
  {
    /* this is called only for canvas */
    if (ih->iclass->nativetype == IUP_TYPECANVAS) 
    {
      result = iupKeyCallKeyPressCb(ih, code, 1);
      if (result == IUP_CLOSE)
      {
        IupExitLoop();
        return FALSE;
      }
      if (result == IUP_IGNORE)
        return TRUE;
    }

    if (!iupKeyProcessNavigation(ih, code, evt->state & GDK_SHIFT_MASK))
      return TRUE;

    /* compensate the show-help limitation. 
     * It is not called on F1, only on Shift+F1 and Ctrl+F1. */
    if (code == K_F1)
    {
      Icallback cb = IupGetCallback(ih, "HELP_CB");
      if (cb)
      {
        if (cb(ih) == IUP_CLOSE) 
          IupExitLoop();
      }
    }
  }

  (void)widget;
  return FALSE;
}
static void iGdkEventFunc(GdkEvent *evt, gpointer	data)
{
  switch(evt->type)
  {
  case GDK_BUTTON_PRESS:
  case GDK_2BUTTON_PRESS:
  case GDK_3BUTTON_PRESS:
  case GDK_BUTTON_RELEASE:
    {
      IFiiiis cb = (IFiiiis)IupGetFunction("GLOBALBUTTON_CB");
      if (cb)
      {
        GdkEventButton* evt_button = (GdkEventButton*)evt;
        gint win_x = 0, win_y = 0;
        int doubleclick = 0, press = 1;
        int b = IUP_BUTTON1+(evt_button->button-1);
        char status[IUPKEY_STATUS_SIZE] = IUPKEY_STATUS_INIT;
        int x = (int)evt_button->x;
        int y = (int)evt_button->y;

        if (evt_button->type == GDK_BUTTON_RELEASE)
          press = 0;

        if (evt_button->type == GDK_2BUTTON_PRESS)
          doubleclick = 1;

        iupgtkButtonKeySetStatus(evt_button->state, evt_button->button, status, doubleclick);

        gdk_window_get_origin(evt_button->window, &win_x, &win_y);  /* GDK window relative to screen */
        x += win_x;
        y += win_y;

        if (doubleclick)
        {
          /* Must compensate the fact that in GTK there is an extra button press event 
             when occours a double click, we compensate that completing the event 
             with a button release before the double click. */
          status[5] = ' '; /* clear double click */
          cb(b, 0, x, y, status);  /* release */
          status[5] = 'D'; /* restore double click */
        }

        cb(b, press, x, y, status);
      }
      break;
    }
  case GDK_MOTION_NOTIFY:
    {
      IFiis cb = (IFiis)IupGetFunction("GLOBALMOTION_CB");
      if (cb)
      {
        GdkEventMotion* evt_motion = (GdkEventMotion*)evt;
        gint win_x = 0, win_y = 0;
        int x = (int)evt_motion->x;
        int y = (int)evt_motion->y;
        char status[IUPKEY_STATUS_SIZE] = IUPKEY_STATUS_INIT;

        iupgtkButtonKeySetStatus(evt_motion->state, 0, status, 0);

        if (evt_motion->is_hint)
          iupgtkWindowGetPointer(evt_motion->window, &x, &y, NULL);

        gdk_window_get_origin(evt_motion->window, &win_x, &win_y);  /* GDK window relative to screen */
        x += win_x;
        y += win_y;

        cb(x, y, status);
      }
      break;
    }
  case GDK_KEY_PRESS:
  case GDK_KEY_RELEASE:
    {
      IFii cb = (IFii)IupGetFunction("GLOBALKEYPRESS_CB");
      if (cb)
      {
        int pressed = (evt->type==GDK_KEY_PRESS)? 1: 0;
        int code = iupgtkKeyDecode((GdkEventKey*)evt);
        if (code != 0)
          cb(code, pressed);
      }
      break;
    }
  default:
    break;
  }

  (void)data;
  gtk_main_do_event(evt);
}