[gtk/readonly-events-1: 28/51] win32: Use event constructors



commit dfa2ae93ecd26d4c5c611747e93efa3d50df00f6
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 15 13:23:55 2020 -0500

    win32: Use event constructors

 gdk/win32/gdkdevicemanager-win32.c | 105 ++++++-----
 gdk/win32/gdkdevicemanager-win32.h |   3 +-
 gdk/win32/gdkevents-win32.c        | 371 +++++++++++++++++++------------------
 3 files changed, 253 insertions(+), 226 deletions(-)
---
diff --git a/gdk/win32/gdkdevicemanager-win32.c b/gdk/win32/gdkdevicemanager-win32.c
index 85be7bf06b..8ebd1822ab 100644
--- a/gdk/win32/gdkdevicemanager-win32.c
+++ b/gdk/win32/gdkdevicemanager-win32.c
@@ -874,9 +874,8 @@ gdk_device_manager_find_wintab_device (GdkDeviceManagerWin32 *device_manager,
   return NULL;
 }
 
-gboolean
+GdkEvent *
 gdk_input_other_event (GdkDisplay *display,
-                       GdkEvent   *event,
                        MSG        *msg,
                        GdkSurface  *window)
 {
@@ -884,21 +883,29 @@ gdk_input_other_event (GdkDisplay *display,
   GdkDeviceWintab *source_device = NULL;
   GdkDeviceGrabInfo *last_grab;
   guint key_state;
+  GdkEvent *event;
 
   PACKET packet;
   gint root_x, root_y;
   gint num_axes;
   double x, y;
   guint translated_buttons, button_diff, button_mask;
+
+  GdkEventType event_type;
+  int event_button;
+  GdkModifierType event_state;
+  double event_x, event_y;
+  double *axes;
+
   /* Translation from tablet button state to GDK button state for
    * buttons 1-3 - swap button 2 and 3.
    */
   static guint button_map[8] = {0, 1, 4, 5, 2, 3, 6, 7};
 
-  if (event->any.surface != wintab_window)
+  if (window != wintab_window)
     {
       g_warning ("gdk_input_other_event: not wintab_window?");
-      return FALSE;
+      return NULL;
     }
 
   device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager);
@@ -914,7 +921,7 @@ gdk_input_other_event (GdkDisplay *display,
   if (msg->message == WT_PACKET || msg->message == WT_CSRCHANGE)
     {
       if (!(*p_WTPacket) ((HCTX) msg->lParam, msg->wParam, &packet))
-        return FALSE;
+        return NULL;
     }
 
   switch (msg->message)
@@ -966,7 +973,7 @@ gdk_input_other_event (GdkDisplay *display,
 
       if (source_device == NULL ||
          gdk_device_get_mode (GDK_DEVICE (source_device)) == GDK_MODE_DISABLED)
-       return FALSE;
+       return NULL;
 
       /* Don't produce any button or motion events while a window is being
        * moved or resized, see bug #151090.
@@ -974,7 +981,7 @@ gdk_input_other_event (GdkDisplay *display,
       if (_modal_operation_in_progress & GDK_WIN32_MODAL_OP_SIZEMOVE_MASK)
         {
           GDK_NOTE (EVENTS_OR_INPUT, g_print ("... ignored when moving/sizing\n"));
-          return FALSE;
+          return NULL;
         }
 
       last_grab = _gdk_display_get_last_device_grab (display, GDK_DEVICE (source_device));
@@ -989,7 +996,7 @@ gdk_input_other_event (GdkDisplay *display,
       if (window == NULL)
         {
           GDK_NOTE (EVENTS_OR_INPUT, g_print ("... is root\n"));
-          return FALSE;
+          return NULL;
         }
 
       num_axes = 0;
@@ -1018,7 +1025,7 @@ gdk_input_other_event (GdkDisplay *display,
           button_diff = translated_buttons ^ source_device->button_state;
 
           /* Gdk buttons are numbered 1.. */
-          event->button.button = 1;
+          event_button = 1;
 
           for (button_mask = 1; button_mask != 0x80000000;
                button_mask <<= 1, event->button.button++)
@@ -1032,47 +1039,49 @@ gdk_input_other_event (GdkDisplay *display,
 
           if (!(translated_buttons & button_mask))
             {
-              event->any.type = GDK_BUTTON_RELEASE;
+              event_type = GDK_BUTTON_RELEASE;
             }
           else
             {
-              event->any.type = GDK_BUTTON_PRESS;
+              event_type = GDK_BUTTON_PRESS;
             }
           source_device->button_state ^= button_mask;
         }
       else
         {
-          event->any.type = GDK_MOTION_NOTIFY;
+          event_type = GDK_MOTION_NOTIFY;
         }
 
-      event->any.surface = window;
       key_state = get_modifier_key_state ();
-      if (event->any.type == GDK_BUTTON_PRESS ||
-          event->any.type == GDK_BUTTON_RELEASE)
+      if (event_type == GDK_BUTTON_PRESS ||
+          event_type == GDK_BUTTON_RELEASE)
         {
-          event->button.time = _gdk_win32_get_next_tick (msg->time);
-         if (source_device->sends_core)
-           gdk_event_set_device (event, device_manager->core_pointer);
-          gdk_event_set_source_device (event, GDK_DEVICE (source_device));
-
-          event->button.axes = g_new (gdouble, num_axes);
-         gdk_surface_get_origin (window, &root_x, &root_y);
+          axes = g_new (gdouble, num_axes);
 
           _gdk_device_wintab_translate_axes (source_device,
                                              window,
-                                             event->button.axes,
-                                             &event->button.x,
-                                             &event->button.y);
-
-          event->button.x_root = event->button.x + root_x;
-          event->button.y_root = event->button.y + root_y;
+                                             axes,
+                                             &event_x,
+                                             &event_y);
 
-          event->button.state =
+          event_state =
             key_state | ((source_device->button_state << 8)
                          & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK
                             | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
                             | GDK_BUTTON5_MASK));
 
+          event = gdk_event_button_new (event_type,
+                                        window,
+                                        device_manager->core_pointer,
+                                        source_device,
+                                        NULL,
+                                        _gdk_win32_get_next_tick (msg->time),
+                                        event_state,
+                                        event_button,
+                                        event_x,
+                                        event_y,
+                                        axes);
+                                          
           GDK_NOTE (EVENTS_OR_INPUT,
                     g_print ("WINTAB button %s:%d %g,%g\n",
                              (event->any.type == GDK_BUTTON_PRESS ?
@@ -1082,33 +1091,33 @@ gdk_input_other_event (GdkDisplay *display,
         }
       else
         {
-          event->motion.time = _gdk_win32_get_next_tick (msg->time);
-          gdk_event_set_device (event, device_manager->core_pointer);
-          gdk_event_set_source_device (event, GDK_DEVICE (source_device));
-
-          event->motion.axes = g_new (gdouble, num_axes);
-         gdk_surface_get_origin (window, &root_x, &root_y);
-
+          axes = g_new (gdouble, num_axes);
           _gdk_device_wintab_translate_axes (source_device,
                                              window,
-                                             event->motion.axes,
-                                             &event->motion.x,
-                                             &event->motion.y);
+                                             axes,
+                                             &event_x,
+                                             &event_y);
 
-          event->motion.x_root = event->motion.x + root_x;
-          event->motion.y_root = event->motion.y + root_y;
-
-          event->motion.state =
+          event_state =
             key_state | ((source_device->button_state << 8)
                          & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK
                             | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
                             | GDK_BUTTON5_MASK));
 
+          event = gdk_event_motion_new (window,
+                                        device_manager->core_pointer,
+                                        source_device,
+                                        NULL,
+                                        _gdk_win32_get_next_tick (msg->time),
+                                        event_state,
+                                        event_x,
+                                        event_y,
+                                        axes);
           GDK_NOTE (EVENTS_OR_INPUT,
                     g_print ("WINTAB motion: %g,%g\n",
                              event->motion.x, event->motion.y));
         }
-      return TRUE;
+      return event;
 
     case WT_CSRCHANGE:
       if (device_manager->dev_entered_proximity > 0)
@@ -1117,7 +1126,7 @@ gdk_input_other_event (GdkDisplay *display,
       if ((source_device = gdk_device_manager_find_wintab_device (device_manager,
                                                                  (HCTX) msg->lParam,
                                                                  packet.pkCursor)) == NULL)
-       return FALSE;
+       return NULL;
 
       if (source_device->sends_core &&
          gdk_device_get_mode (GDK_DEVICE (source_device)) != GDK_MODE_DISABLED)
@@ -1127,7 +1136,7 @@ gdk_input_other_event (GdkDisplay *display,
          _gdk_input_ignore_core += 1;
        }
 
-      return FALSE;
+      return NULL;
 
     case WT_PROXIMITY:
       if (LOWORD (msg->lParam) == 0)
@@ -1146,8 +1155,8 @@ gdk_input_other_event (GdkDisplay *display,
          device_manager->dev_entered_proximity += 1;
        }
 
-      return FALSE;
+      return NULL;
     }
 
-  return FALSE;
+  return NULL;
 }
diff --git a/gdk/win32/gdkdevicemanager-win32.h b/gdk/win32/gdkdevicemanager-win32.h
index fc8ead5a10..53411d7c5c 100644
--- a/gdk/win32/gdkdevicemanager-win32.h
+++ b/gdk/win32/gdkdevicemanager-win32.h
@@ -57,8 +57,7 @@ struct _GdkDeviceManagerWin32Class
 GType gdk_device_manager_win32_get_type (void) G_GNUC_CONST;
 
 void     _gdk_input_set_tablet_active (void);
-gboolean gdk_input_other_event        (GdkDisplay *display,
-                                       GdkEvent   *event,
+GdkEvent * gdk_input_other_event      (GdkDisplay *display,
                                        MSG        *msg,
                                        GdkSurface  *window);
 
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c
index 56541e71e7..d997ec55fb 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -205,11 +205,7 @@ generate_focus_event (GdkDeviceManagerWin32 *device_manager,
   device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
   source_device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->system_keyboard;
 
-  event = gdk_event_new (GDK_FOCUS_CHANGE);
-  event->any.surface = window;
-  event->focus_change.in = in;
-  gdk_event_set_device (event, device);
-  gdk_event_set_source_device (event, source_device);
+  event = gdk_event_focus_new (window, device, source_device, in);
 
   _gdk_win32_append_event (event);
 }
@@ -220,28 +216,26 @@ generate_grab_broken_event (GdkDeviceManagerWin32 *device_manager,
                             gboolean          keyboard,
                             GdkSurface        *grab_window)
 {
-  GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
+  GdkEvent *event;
   GdkDevice *device;
   GdkDevice *source_device;
 
   if (keyboard)
     {
-      device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_keyboard;
-      source_device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->system_keyboard;
+      device = device_manager->core_keyboard;
+      source_device = device_manager->system_keyboard;
     }
   else
     {
-      device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->core_pointer;
-      source_device = GDK_DEVICE_MANAGER_WIN32 (device_manager)->system_pointer;
+      device = device_manager->core_pointer;
+      source_device = device_manager->system_pointer;
     }
 
-  event->any.surface = window;
-  event->any.send_event = 0;
-  event->grab_broken.keyboard = keyboard;
-  event->grab_broken.implicit = FALSE;
-  event->grab_broken.grab_surface = grab_window;
-  gdk_event_set_device (event, device);
-  gdk_event_set_source_device (event, source_device);
+  event = gdk_event_grab_broken_new (window,
+                                     device,
+                                     source_device,
+                                     grab_window,
+                                     FALSE);
 
   _gdk_win32_append_event (event);
 }
@@ -633,51 +627,62 @@ find_window_for_mouse_event (GdkSurface* reported_window,
   return event_surface;
 }
 
-static void
-build_key_event_state (GdkEvent *event,
-                      BYTE     *key_state)
+static GdkModifierType
+build_key_event_state (BYTE *key_state)
 {
+  GdkModifierType state;
   GdkWin32Keymap *keymap;
 
-  event->key.state = 0;
+  state = 0;
 
   if (key_state[VK_SHIFT] & 0x80)
-    event->key.state |= GDK_SHIFT_MASK;
+    state |= GDK_SHIFT_MASK;
 
   if (key_state[VK_CAPITAL] & 0x01)
-    event->key.state |= GDK_LOCK_MASK;
+    state |= GDK_LOCK_MASK;
 
   if (key_state[VK_LBUTTON] & 0x80)
-    event->key.state |= GDK_BUTTON1_MASK;
+    state |= GDK_BUTTON1_MASK;
   if (key_state[VK_MBUTTON] & 0x80)
-    event->key.state |= GDK_BUTTON2_MASK;
+    state |= GDK_BUTTON2_MASK;
   if (key_state[VK_RBUTTON] & 0x80)
-    event->key.state |= GDK_BUTTON3_MASK;
+    state |= GDK_BUTTON3_MASK;
   if (key_state[VK_XBUTTON1] & 0x80)
-    event->key.state |= GDK_BUTTON4_MASK;
+    state |= GDK_BUTTON4_MASK;
   if (key_state[VK_XBUTTON2] & 0x80)
-    event->key.state |= GDK_BUTTON5_MASK;
+    state |= GDK_BUTTON5_MASK;
 
   keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
-  event->key.group = _gdk_win32_keymap_get_active_group (keymap);
 
   if (_gdk_win32_keymap_has_altgr (keymap) &&
       (key_state[VK_LCONTROL] & 0x80) &&
       (key_state[VK_RMENU] & 0x80))
     {
-      event->key.state |= GDK_MOD2_MASK;
+      state |= GDK_MOD2_MASK;
       if (key_state[VK_RCONTROL] & 0x80)
-       event->key.state |= GDK_CONTROL_MASK;
+       state |= GDK_CONTROL_MASK;
       if (key_state[VK_LMENU] & 0x80)
-       event->key.state |= GDK_MOD1_MASK;
+       state |= GDK_MOD1_MASK;
     }
   else
     {
       if (key_state[VK_CONTROL] & 0x80)
-       event->key.state |= GDK_CONTROL_MASK;
+       state |= GDK_CONTROL_MASK;
       if (key_state[VK_MENU] & 0x80)
-       event->key.state |= GDK_MOD1_MASK;
+       state |= GDK_MOD1_MASK;
     }
+
+  return state;
+}
+
+static guint8
+get_active_group (void)
+{
+  GdkWin32Keymap *keymap;
+
+  keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
+
+  return _gdk_win32_keymap_get_active_group (keymap);
 }
 
 static gint
@@ -727,20 +732,6 @@ build_pointer_event_state (MSG *msg)
   return state;
 }
 
-static void
-build_wm_ime_composition_event (GdkEvent *event,
-                               MSG      *msg,
-                               wchar_t   wc,
-                               BYTE     *key_state)
-{
-  event->key.time = _gdk_win32_get_next_tick (msg->time);
-
-  build_key_event_state (event, key_state);
-
-  event->key.hardware_keycode = 0; /* FIXME: What should it be? */
-  event->key.keyval = gdk_unicode_to_keyval (wc);
-}
-
 #ifdef G_ENABLE_DEBUG
 
 static void
@@ -1098,23 +1089,17 @@ send_crossing_event (GdkDisplay                 *display,
   pt = *screen_pt;
   ScreenToClient (GDK_SURFACE_HWND (window), &pt);
 
-  event = gdk_event_new (type);
-  event->any.surface = window;
-  event->crossing.child_surface = subwindow;
-  event->crossing.time = _gdk_win32_get_next_tick (time_);
-  event->crossing.x = pt.x / impl->surface_scale;
-  event->crossing.y = pt.y / impl->surface_scale;
-  event->crossing.x_root = (screen_pt->x + _gdk_offset_x) / impl->surface_scale;
-  event->crossing.y_root = (screen_pt->y + _gdk_offset_y) / impl->surface_scale;
-  event->crossing.mode = mode;
-  event->crossing.detail = notify_type;
-  event->crossing.mode = mode;
-  event->crossing.detail = notify_type;
-  event->crossing.focus = FALSE;
-  event->crossing.state = mask;
-  gdk_event_set_device (event, device_manager->core_pointer);
-  gdk_event_set_source_device (event, device_manager->system_pointer);
-
+  event = gdk_event_crossing_new (type,
+                                  window,
+                                  device_manager->core_pointer,
+                                  device_manager->system_pointer,
+                                  _gdk_win32_next_tick (time_),
+                                  mask,
+                                  pt.x / impl->surface_scale,
+                                  pt.y / impl->surface_scale,
+                                  mode,
+                                  notify_type);
+          
   _gdk_win32_append_event (event);
 }
 
@@ -1601,7 +1586,7 @@ generate_button_event (GdkEventType      type,
                        GdkSurface        *window,
                        MSG              *msg)
 {
-  GdkEvent *event = gdk_event_new (type);
+  GdkEvent *event;
   GdkDeviceManagerWin32 *device_manager;
   GdkWin32Surface *impl = GDK_WIN32_SURFACE (window);
 
@@ -1610,18 +1595,21 @@ generate_button_event (GdkEventType      type,
 
   device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager);
 
-  event->any.surface = window;
-  event->button.time = _gdk_win32_get_next_tick (msg->time);
-  event->button.x = current_x = (gint16) GET_X_LPARAM (msg->lParam) / impl->surface_scale;
-  event->button.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam) / impl->surface_scale;
-  event->button.x_root = (msg->pt.x + _gdk_offset_x) / impl->surface_scale;
-  event->button.y_root = (msg->pt.y + _gdk_offset_y) / impl->surface_scale;
-  event->button.axes = NULL;
-  event->button.state = build_pointer_event_state (msg);
-  event->button.button = button;
-  gdk_event_set_device (event, device_manager->core_pointer);
-  gdk_event_set_source_device (event, device_manager->system_pointer);
-
+  current_x = (gint16) GET_X_LPARAM (msg->lParam) / impl->surface_scale;
+  current_y = (gint16) GET_Y_LPARAM (msg->lParam) / impl->surface_scale;
+
+  event = gdk_event_button_new (type,
+                                window,
+                                device_manager->core_pointer,
+                                device_manager->system_pointer,
+                                NULL,
+                                _gdk_win32_get_next_tick (msg->time),
+                                build_pointer_event_state (msg),
+                                button,
+                                current_x,
+                                current_y,
+                                NULL);
+                                
   _gdk_win32_append_event (event);
 }
 
@@ -2078,6 +2066,16 @@ gdk_event_translate (MSG  *msg,
 
   int i;
 
+  GdkModifierType state;
+  guint keyval;
+  guint16 keycode;
+  guint16 scancode;
+  guint8 group;
+  gboolean is_modifier;
+
+  double delta_x, delta_y;
+  GdkScrollDirection direction;
+
   display = gdk_display_get_default ();
   win32_display = GDK_WIN32_DISPLAY (display);
 
@@ -2150,17 +2148,17 @@ gdk_event_translate (MSG  *msg,
       gdk_display_setting_changed (display, "gtk-im-module");
 
       /* Generate a dummy key event to "nudge" IMContext */
-      event = gdk_event_new (GDK_KEY_PRESS);
-      event->any.surface = window;
-      event->key.time = _gdk_win32_get_next_tick (msg->time);
-      event->key.keyval = GDK_KEY_VoidSymbol;
-      event->key.hardware_keycode = 0;
-      event->key.group = 0;
-      gdk_event_set_scancode (event, 0);
-      gdk_event_set_device (event, device_manager_win32->core_keyboard);
-      gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
-      event->key.is_modifier = FALSE;
-      event->key.state = 0;
+      event = gdk_event_key_new (GDK_KEY_PRESS,
+                                 window,
+                                 device_manager_win32->core_keyboard,
+                                 device_manager_win32->system_keyboard,
+                                 _gdk_win32_get_next_tick (msg->time),
+                                 0,
+                                 GDK_KEY_VoidSymbol,
+                                 0,
+                                 0,
+                                 0,
+                                 FALSE);
       _gdk_win32_append_event (event);
       break;
 
@@ -2244,44 +2242,38 @@ gdk_event_translate (MSG  *msg,
            }
        }
 
-      event = gdk_event_new ((msg->message == WM_KEYDOWN ||
-                             msg->message == WM_SYSKEYDOWN) ?
-                            GDK_KEY_PRESS : GDK_KEY_RELEASE);
-      event->any.surface = window;
-      event->key.time = _gdk_win32_get_next_tick (msg->time);
-      event->key.keyval = GDK_KEY_VoidSymbol;
-      event->key.hardware_keycode = msg->wParam;
-      /* save original scancode */
-      gdk_event_set_scancode (event, msg->lParam >> 16);
-      gdk_event_set_device (event, device_manager_win32->core_keyboard);
-      gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
+      keyval = GDK_KEY_VoidSymbol;
+      keycode = msg->wParam;
+      scancode = msg->lParam >> 16;
+
       if (HIWORD (msg->lParam) & KF_EXTENDED)
        {
          switch (msg->wParam)
            {
            case VK_CONTROL:
-             event->key.hardware_keycode = VK_RCONTROL;
+             keycode = VK_RCONTROL;
              break;
            case VK_SHIFT:      /* Actually, KF_EXTENDED is not set
                                 * for the right shift key.
                                 */
-             event->key.hardware_keycode = VK_RSHIFT;
+             keycode = VK_RSHIFT;
              break;
            case VK_MENU:
-             event->key.hardware_keycode = VK_RMENU;
+             keycode = VK_RMENU;
              break;
            }
        }
       else if (msg->wParam == VK_SHIFT &&
               LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (GDK_WIN32_KEYMAP 
(_gdk_win32_display_get_keymap (_gdk_display))))
-       event->key.hardware_keycode = VK_RSHIFT;
+       keycode = VK_RSHIFT;
 
-      event->key.is_modifier = (msg->wParam == VK_CONTROL ||
-                                msg->wParam == VK_SHIFT ||
-                                msg->wParam == VK_MENU);
+      is_modifier = (msg->wParam == VK_CONTROL ||
+                     msg->wParam == VK_SHIFT ||
+                     msg->wParam == VK_MENU);
       /* g_print ("ctrl:%02x lctrl:%02x rctrl:%02x alt:%02x lalt:%02x ralt:%02x\n", key_state[VK_CONTROL], 
key_state[VK_LCONTROL], key_state[VK_RCONTROL], key_state[VK_MENU], key_state[VK_LMENU], 
key_state[VK_RMENU]); */
 
-      build_key_event_state (event, key_state);
+      state = build_key_event_state (key_state);
+      group = get_active_group ();
 
       if (msg->wParam == VK_PACKET && ccount == 1)
        {
@@ -2298,20 +2290,20 @@ gdk_event_translate (MSG  *msg,
              else
                leading = impl->leading_surrogate_keyup;
 
-             event->key.keyval = gdk_unicode_to_keyval ((leading - 0xD800) * 0x400 + wbuf[0] - 0xDC00 + 
0x10000);
+             keyval = gdk_unicode_to_keyval ((leading - 0xD800) * 0x400 + wbuf[0] - 0xDC00 + 0x10000);
            }
          else
            {
-             event->key.keyval = gdk_unicode_to_keyval (wbuf[0]);
+             keyval = gdk_unicode_to_keyval (wbuf[0]);
            }
        }
       else
        {
          gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (display),
-                                              event->key.hardware_keycode,
-                                              event->key.state,
-                                              event->key.group,
-                                              &event->key.keyval,
+                                              keycode,
+                                              state,
+                                              group,
+                                              &keyval,
                                               NULL, NULL, NULL);
        }
 
@@ -2354,7 +2346,21 @@ gdk_event_translate (MSG  *msg,
 
       /* Reset MOD1_MASK if it is the Alt key itself */
       if (msg->wParam == VK_MENU)
-       event->key.state &= ~GDK_MOD1_MASK;
+       state &= ~GDK_MOD1_MASK;
+
+      event = gdk_event_key_new ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
+                                   ? GDK_KEY_PRESS
+                                   : GDK_KEY_RELEASE,
+                                 window,
+                                 device_manager_win32->core_keyboard,
+                                 device_manager_win32->system_keyboard,
+                                 _gdk_win32_get_next_tick (msg->time),
+                                 state,
+                                 keyval,
+                                 keycode,
+                                 scancode,
+                                 group,
+                                 is_modifier);
 
       _gdk_win32_append_event (event);
 
@@ -2416,20 +2422,32 @@ gdk_event_translate (MSG  *msg,
       for (i = 0; i < ccount; i++)
        {
           /* Build a key press event */
-          event = gdk_event_new (GDK_KEY_PRESS);
-          event->any.surface = window;
-          gdk_event_set_device (event, device_manager_win32->core_keyboard);
-          gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
-          build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
+          event = gdk_event_key_new (GDK_KEY_PRESS,
+                                     window,
+                                     device_manager_win32->core_keyboard,
+                                     device_manager_win32->system_keyboard,
+                                     _gdk_win32_get_next_tick (msg->time),
+                                     build_key_event_state (key_state),
+                                     gdk_unicode_to_keyval (wbuf[i]),               
+                                     0,
+                                     0,
+                                     get_active_group (),
+                                     FALSE);
 
           _gdk_win32_append_event (event);
 
           /* Build a key release event.  */
-          event = gdk_event_new (GDK_KEY_RELEASE);
-          event->any.surface = window;
-          gdk_event_set_device (event, device_manager_win32->core_keyboard);
-          gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
-          build_wm_ime_composition_event (event, msg, wbuf[i], key_state);
+          event = gdk_event_key_new (GDK_KEY_RELEASE,
+                                     window,
+                                     device_manager_win32->core_keyboard,
+                                     device_manager_win32->system_keyboard,
+                                     _gdk_win32_get_next_tick (msg->time),
+                                     build_key_event_state (key_state),
+                                     gdk_unicode_to_keyval (wbuf[i]),               
+                                     0,
+                                     0,
+                                     get_active_group (),
+                                     FALSE);
 
           _gdk_win32_append_event (event);
        }
@@ -2631,17 +2649,18 @@ gdk_event_translate (MSG  *msg,
         }
       else if (_gdk_input_ignore_core == 0)
        {
-         event = gdk_event_new (GDK_MOTION_NOTIFY);
-         event->any.surface = window;
-         event->motion.time = _gdk_win32_get_next_tick (msg->time);
-         event->motion.x = current_x = (gint16) GET_X_LPARAM (msg->lParam) / impl->surface_scale;
-         event->motion.y = current_y = (gint16) GET_Y_LPARAM (msg->lParam) / impl->surface_scale;
-         event->motion.x_root = current_root_x;
-         event->motion.y_root = current_root_y;
-         event->motion.axes = NULL;
-         event->motion.state = build_pointer_event_state (msg);
-         gdk_event_set_device (event, device_manager_win32->core_pointer);
-         gdk_event_set_source_device (event, device_manager_win32->system_pointer);
+         current_x = (gint16) GET_X_LPARAM (msg->lParam) / impl->surface_scale;
+         current_y = (gint16) GET_Y_LPARAM (msg->lParam) / impl->surface_scale;
+
+         event = gdk_event_motion_new (window,
+                                       device_manager_win32->core_pointer,
+                                       device_manager_win32->system_pointer,
+                                        NULL,
+                                        _gdk_win32_get_next_tick (msg->time),
+                                       build_pointer_event_state (msg),
+                                        current_x,
+                                        current_y,
+                                        NULL);
 
          _gdk_win32_append_event (event);
        }
@@ -2748,44 +2767,48 @@ gdk_event_translate (MSG  *msg,
       impl = GDK_WIN32_SURFACE (window);
       ScreenToClient (msg->hwnd, &point);
 
-      event = gdk_event_new (GDK_SCROLL);
-      event->any.surface = window;
-      event->scroll.direction = GDK_SCROLL_SMOOTH;
+      delta_x = delta_y = 0.0;
 
       if (msg->message == WM_MOUSEWHEEL)
-        {
-          event->scroll.delta_y = (gdouble) GET_WHEEL_DELTA_WPARAM (msg->wParam) / (gdouble) WHEEL_DELTA;
-        }
+        delta_y = (double) GET_WHEEL_DELTA_WPARAM (msg->wParam) / (gdouble) WHEEL_DELTA;
       else if (msg->message == WM_MOUSEHWHEEL)
-        {
-          event->scroll.delta_x = (gdouble) GET_WHEEL_DELTA_WPARAM (msg->wParam) / (gdouble) WHEEL_DELTA;
-        }
+        delta_x = (double) GET_WHEEL_DELTA_WPARAM (msg->wParam) / (gdouble) WHEEL_DELTA;
       /* Positive delta scrolls up, not down,
          see API documentation for WM_MOUSEWHEEL message.
        */
-      event->scroll.delta_y *= -1.0;
-      event->scroll.time = _gdk_win32_get_next_tick (msg->time);
-      event->scroll.x = (gint16) point.x / impl->surface_scale;
-      event->scroll.y = (gint16) point.y / impl->surface_scale;
-      event->scroll.x_root = ((gint16) GET_X_LPARAM (msg->lParam) + _gdk_offset_x) / impl->surface_scale;
-      event->scroll.y_root = ((gint16) GET_Y_LPARAM (msg->lParam) + _gdk_offset_y) / impl->surface_scale;
-      event->scroll.state = build_pointer_event_state (msg);
-      gdk_event_set_device (event, device_manager_win32->core_pointer);
-      gdk_event_set_source_device (event, device_manager_win32->system_pointer);
-      gdk_event_set_pointer_emulated (event, FALSE);
-
-      _gdk_win32_append_event (gdk_event_copy (event));
+      delta_y *= -1.0;
+
+      event = gdk_event_scroll_new (window,
+                                    device_manager_win32->core_pointer,
+                                    device_manager_win32->system_pointer,
+                                    NULL,
+                                    _gdk_win32_get_next_tick (msg->time),
+                                    build_pointer_event_state (msg),
+                                    delta_x,
+                                    delta_y,
+                                    FALSE);
+
+      _gdk_win32_append_event (event);
 
       /* Append the discrete version too */
+      direction = 0;
       if (msg->message == WM_MOUSEWHEEL)
-       event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
-         GDK_SCROLL_UP : GDK_SCROLL_DOWN;
+       direction = (((short) HIWORD (msg->wParam)) > 0)
+                     ? GDK_SCROLL_UP
+                      : GDK_SCROLL_DOWN;
       else if (msg->message == WM_MOUSEHWHEEL)
-       event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ?
-         GDK_SCROLL_RIGHT : GDK_SCROLL_LEFT;
-      event->scroll.delta_x = 0;
-      event->scroll.delta_y = 0;
-      gdk_event_set_pointer_emulated (event, TRUE);
+       direction = (((short) HIWORD (msg->wParam)) > 0)
+                      ? GDK_SCROLL_RIGHT
+                      : GDK_SCROLL_LEFT;
+
+      event = gdk_event_scroll_new (window,
+                                    device_manager_win32->core_pointer,
+                                    device_manager_win32->system_pointer,
+                                    NULL,
+                                    _gdk_win32_get_next_tick (msg->time),
+                                    build_pointer_event_state (msg),
+                                    direction,
+                                    TRUE);
 
       _gdk_win32_append_event (event);
 
@@ -3414,8 +3437,7 @@ gdk_event_translate (MSG  *msg,
       if (GDK_SURFACE_DESTROYED (window))
        break;
 
-      event = gdk_event_new (GDK_DELETE);
-      event->any.surface = window;
+      event = gdk_event_delete_new (window);
 
       _gdk_win32_append_event (event);
 
@@ -3449,8 +3471,7 @@ gdk_event_translate (MSG  *msg,
       if (window == NULL || GDK_SURFACE_DESTROYED (window))
        break;
 
-      event = gdk_event_new (GDK_DESTROY);
-      event->any.surface = window;
+      event = gdk_event_delete_new (window);
 
       _gdk_win32_append_event (event);
 
@@ -3563,14 +3584,12 @@ gdk_event_translate (MSG  *msg,
       /* Fall through */
     wintab:
 
-      event = gdk_event_new (GDK_NOTHING);
-      event->any.surface = window;
-      g_object_ref (window);
-
-      if (gdk_input_other_event (display, event, msg, window))
-       _gdk_win32_append_event (event);
-      else
-       g_object_unref (event);
+      event = gdk_input_other_event (display, msg, window);
+      if (event)
+        {
+          _gdk_win32_append_event (event);
+         g_object_unref (event);
+        }
 
       break;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]