summaryrefslogtreecommitdiff
path: root/gtk/gtkeventcontrollerprivate.h
blob: b9b83082c600f7615c0f1311236dcd7e0ef05de5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* GTK - The GIMP Toolkit
 * Copyright (C) 2012, One Laptop Per Child.
 * Copyright (C) 2014, Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Author(s): Carlos Garnacho <carlosg@gnome.org>
 */
#pragma once

#include "gtkeventcontroller.h"

/* GdkCrossingType:
 * @GTK_CROSSING_FOCUS: Focus moved from one widget to another
 * @GTK_CROSSING_ACTIVE: The active window changed (the crossing
 *    events in this case leave from the old active window's focus
 *    location to the new active window's one.
 * @GTK_CROSSING_POINTER: The pointer moved from one widget to another
 * @GTK_CROSSING_DROP: An active drag moved from one widget to another
 *
 * We emit various kinds of crossing events when the target widget
 * for keyboard or pointer events changes.
 */
typedef enum {
  GTK_CROSSING_FOCUS,
  GTK_CROSSING_ACTIVE,
  GTK_CROSSING_POINTER,
  GTK_CROSSING_DROP
} GtkCrossingType;

/*
 * GdkCrossingirection:
 * @GTK_CROSSING_IN: the event is on the downward slope, towards the new target
 * @GTK_CROSSING_OUT: the event is on the upward slope, away from the old target
 */
typedef enum {
  GTK_CROSSING_IN,
  GTK_CROSSING_OUT
} GtkCrossingDirection;

typedef struct _GtkCrossingData GtkCrossingData;

/**
 * GtkCrossingData:
 * @type: the type of crossing event
 * @direction: whether this is a focus-in or focus-out event
 * @mode: the crossing mode
 * @old_target: the old target
 * @old_descendent: the direct child of the receiving widget that
 *   is an ancestor of @old_target, or %NULL if @old_target is not
 *   a descendent of the receiving widget
 * @new_target: the new target
 * @new_descendent: the direct child of the receiving widget that
 *   is an ancestor of @new_target, or %NULL if @new_target is not
 *   a descendent of the receiving widget
 * @drop: the `GdkDrop` if this is info for a drop operation
 *
 * The struct that is passed to gtk_event_controller_handle_crossing().
 *
 * The @old_target and @new_target fields are set to the old or new
 * focus, drop or hover location.
 */
struct _GtkCrossingData {
  GtkCrossingType type;
  GtkCrossingDirection direction;
  GdkCrossingMode mode;
  GtkWidget *old_target;
  GtkWidget *old_descendent;
  GtkWidget *new_target;
  GtkWidget *new_descendent;
  GdkDrop *drop;
};

struct _GtkEventController
{
  GObject parent_instance;
};

struct _GtkEventControllerClass
{
  GObjectClass parent_class;

  void     (* set_widget)   (GtkEventController *controller,
                             GtkWidget          *widget);
  void     (* unset_widget) (GtkEventController *controller);
  gboolean (* handle_event) (GtkEventController *controller,
                             GdkEvent            *event,
                             double              x,
                             double              y);
  void     (* reset)        (GtkEventController *controller);

  void     (* handle_crossing) (GtkEventController    *controller,
                                const GtkCrossingData *crossing,
                                double                 x,
                                double                 y);

  /*<private>*/

  /* Tells whether the event is filtered out, %TRUE makes
   * the event unseen by the handle_event vfunc.
   */
  gboolean (* filter_event) (GtkEventController *controller,
                             GdkEvent           *event);

  gpointer padding[10];
};

GtkWidget * gtk_event_controller_get_target (GtkEventController *controller);


gboolean   gtk_event_controller_handle_event   (GtkEventController *controller,
                                                GdkEvent           *event,
                                                GtkWidget          *target,
                                                double              x,
                                                double              y);
void       gtk_event_controller_handle_crossing (GtkEventController    *controller,
                                                 const GtkCrossingData *crossing,
                                                 double                 x,
                                                 double                 y);