gnu_java_awt_peer_gtk_gtkevents.c

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· C语言 代码 · 共 1,177 行 · 第 1/3 页

C
1,177
字号
/* gtkevents.c -- GDK/GTK event handlers   Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */#include "gtkpeer.h"#include <X11/Xlib.h>#include <gdk/gdkkeysyms.h>#include <stdarg.h>#include <assert.h>/* A widget can be composed of multipled windows, so we need to hook   events on all of them. */struct event_hook_info{  jobject *peer_obj;  int nwindows;  /* array of pointers to (GdkWindow *) */  GdkWindow ***windows;};static jintbutton_to_awt_mods (int button){  switch (button)    {    case 1:      return AWT_BUTTON1_MASK;    case 2:      return AWT_BUTTON2_MASK;    case 3:      return AWT_BUTTON3_MASK;    }  return 0;}static jintstate_to_awt_mods (guint state){  jint result = 0;  if (state & GDK_SHIFT_MASK)    result |= AWT_SHIFT_DOWN_MASK;  if (state & GDK_CONTROL_MASK)    result |= AWT_CTRL_DOWN_MASK;  if (state & GDK_MOD1_MASK)    result |= AWT_ALT_DOWN_MASK;  return result;}static jintstate_to_awt_mods_with_button_states (guint state){  jint result = 0;  if (state & GDK_SHIFT_MASK)    result |= AWT_SHIFT_DOWN_MASK;  if (state & GDK_CONTROL_MASK)    result |= AWT_CTRL_DOWN_MASK;  if (state & GDK_MOD1_MASK)    result |= AWT_ALT_DOWN_MASK;  if (state & GDK_BUTTON1_MASK)    result |= AWT_BUTTON1_DOWN_MASK;  if (state & GDK_BUTTON2_MASK)    result |= AWT_BUTTON2_DOWN_MASK;  if (state & GDK_BUTTON3_MASK)    result |= AWT_BUTTON3_DOWN_MASK;  return result;}/* Modifier key events need special treatment.  In Sun's peer   implementation, when a modifier key is pressed, the KEY_PRESSED   event has that modifier in its modifiers list.  The corresponding   KEY_RELEASED event's modifier list does not contain the modifier.   For example, pressing and releasing the shift key will produce a   key press event with modifiers=Shift, and a key release event with   no modifiers.  GDK's key events behave in the exact opposite way,   so this translation code is needed. */jintkeyevent_state_to_awt_mods (GdkEvent *event){  jint result = 0;  guint state;  if (event->type == GDK_KEY_PRESS)    {      state = event->key.state;      if (event->key.keyval == GDK_Shift_L          || event->key.keyval == GDK_Shift_R)        result |= AWT_SHIFT_DOWN_MASK;      else        {          if (state & GDK_SHIFT_MASK)            result |= AWT_SHIFT_DOWN_MASK;        }      if (event->key.keyval == GDK_Control_L          || event->key.keyval == GDK_Control_R)        result |= AWT_CTRL_DOWN_MASK;      else        {          if (state & GDK_CONTROL_MASK)            result |= AWT_CTRL_DOWN_MASK;        }      if (event->key.keyval == GDK_Alt_L          || event->key.keyval == GDK_Alt_R)        result |= AWT_ALT_DOWN_MASK;      else        {          if (state & GDK_MOD1_MASK)            result |= AWT_ALT_DOWN_MASK;        }    }  else if (event->type == GDK_KEY_RELEASE)    {      state = event->key.state;      if (event->key.keyval != GDK_Shift_L          && event->key.keyval != GDK_Shift_R)        {          if (state & GDK_SHIFT_MASK)            result |= AWT_SHIFT_DOWN_MASK;        }      if (event->key.keyval != GDK_Control_L          && event->key.keyval != GDK_Control_R)        {          if (state & GDK_CONTROL_MASK)            result |= AWT_CTRL_DOWN_MASK;        }      if (event->key.keyval != GDK_Alt_L          && event->key.keyval != GDK_Alt_R)        {          if (state & GDK_MOD1_MASK)            result |= AWT_ALT_DOWN_MASK;        }    }  return result;}/* Get the first keyval in the keymap for this event's keycode.  The   first keyval corresponds roughly to Java's notion of a virtual   key.  Returns the uppercase version of the first keyval. */static guintget_first_keyval_from_keymap (GdkEvent *event){  guint keyval;  guint *keyvals;  gint n_entries;  if (!gdk_keymap_get_entries_for_keycode (NULL,                                           event->key.hardware_keycode,                                           NULL,                                           &keyvals,                                           &n_entries))    {      g_warning ("No keyval found for hardware keycode %d\n",                 event->key.hardware_keycode);      /* Try to recover by using the keyval in the event structure. */      keyvals = &(event->key.keyval);    }  keyval = keyvals[0];  g_free (keyvals);  return gdk_keyval_to_upper (keyval);}#ifdef __GNUC____inline#endifstatic jintkeysym_to_awt_keycode (GdkEvent *event){  guint ukeyval;  guint state;  ukeyval = get_first_keyval_from_keymap (event);  state = event->key.state;  /* VK_A through VK_Z */  if (ukeyval >= GDK_A && ukeyval <= GDK_Z)    return ukeyval;  /* VK_0 through VK_9 */  if (ukeyval >= GDK_0 && ukeyval <= GDK_9)    return ukeyval;  switch (ukeyval)    {    case GDK_Return:    case GDK_KP_Enter:      return VK_ENTER;    case GDK_BackSpace:      return VK_BACK_SPACE;    case GDK_Tab:      return VK_TAB;    case GDK_Cancel:      return VK_CANCEL;    case GDK_Clear:      return VK_CLEAR;    case GDK_Shift_L:    case GDK_Shift_R:      return VK_SHIFT;    case GDK_Control_L:    case GDK_Control_R:      return VK_CONTROL;    case GDK_Alt_L:    case GDK_Alt_R:      return VK_ALT;    case GDK_Pause:      return VK_PAUSE;    case GDK_Caps_Lock:      return VK_CAPS_LOCK;    case GDK_Escape:      return VK_ESCAPE;    case GDK_space:      return VK_SPACE;    case GDK_KP_Page_Up:      /* For keys on the numeric keypad, the JVM produces one of two         virtual keys, depending on the num lock state. */      if (state & GDK_MOD2_MASK)        return VK_NUMPAD9;      else        return VK_PAGE_UP;    case GDK_Page_Up:      return VK_PAGE_UP;    case GDK_KP_Page_Down:      if (state & GDK_MOD2_MASK)        return VK_NUMPAD3;      else        return VK_PAGE_DOWN;    case GDK_Page_Down:      return VK_PAGE_DOWN;    case GDK_KP_End:      if (state & GDK_MOD2_MASK)        return VK_NUMPAD1;      else        return VK_END;    case GDK_End:      return VK_END;    case GDK_KP_Home:      if (state & GDK_MOD2_MASK)        return VK_NUMPAD7;      else        return VK_HOME;    case GDK_Home:      return VK_HOME;    case GDK_KP_Begin:      if (state & GDK_MOD2_MASK)        return VK_NUMPAD5;      else        return VK_UNDEFINED;    case GDK_Left:      return VK_LEFT;    case GDK_Up:      return VK_UP;    case GDK_Right:      return VK_RIGHT;    case GDK_Down:      return VK_DOWN;    case GDK_comma:      return VK_COMMA;    case GDK_minus:      return VK_MINUS;    case GDK_period:      return VK_PERIOD;    case GDK_slash:      return VK_SLASH;      /*      return VK_0;      return VK_1;      return VK_2;      return VK_3;      return VK_4;      return VK_5;      return VK_6;      return VK_7;      return VK_8;      return VK_9;      */    case GDK_semicolon:      return VK_SEMICOLON;    case GDK_equal:      return VK_EQUALS;      /*      return VK_A;      return VK_B;      return VK_C;      return VK_D;      return VK_E;      return VK_F;      return VK_G;      return VK_H;      return VK_I;      return VK_J;      return VK_K;      return VK_L;      return VK_M;      return VK_N;      return VK_O;      return VK_P;      return VK_Q;      return VK_R;      return VK_S;      return VK_T;      return VK_U;      return VK_V;      return VK_W;      return VK_X;      return VK_Y;      return VK_Z;      */    case GDK_bracketleft:      return VK_OPEN_BRACKET;    case GDK_backslash:      return VK_BACK_SLASH;    case GDK_bracketright:      return VK_CLOSE_BRACKET;    case GDK_KP_0:      return VK_NUMPAD0;    case GDK_KP_1:      return VK_NUMPAD1;    case GDK_KP_2:      return VK_NUMPAD2;    case GDK_KP_3:      return VK_NUMPAD3;    case GDK_KP_4:      return VK_NUMPAD4;    case GDK_KP_5:      return VK_NUMPAD5;    case GDK_KP_6:      return VK_NUMPAD6;    case GDK_KP_7:      return VK_NUMPAD7;    case GDK_KP_8:      return VK_NUMPAD8;    case GDK_KP_9:      return VK_NUMPAD9;    case GDK_KP_Multiply:      return VK_MULTIPLY;    case GDK_KP_Add:      return VK_ADD;      /*      return VK_SEPARATER;      */    case GDK_KP_Separator:      return VK_SEPARATOR;    case GDK_KP_Subtract:      return VK_SUBTRACT;    case GDK_KP_Decimal:      return VK_DECIMAL;    case GDK_KP_Divide:      return VK_DIVIDE;    case GDK_KP_Delete:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?