1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2007 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup wm
22  */
23 
24 #pragma once
25 
26 /* return value of handler-operator call */
27 #define WM_HANDLER_CONTINUE 0
28 #define WM_HANDLER_BREAK 1
29 #define WM_HANDLER_HANDLED 2
30 #define WM_HANDLER_MODAL 4 /* MODAL|BREAK means unhandled */
31 
32 struct ARegion;
33 struct GHOST_TabletData;
34 struct ScrArea;
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /* wmKeyMap is in DNA_windowmanager.h, it's saveable */
41 
42 /** Custom types for handlers, for signaling, freeing */
43 enum eWM_EventHandlerType {
44   WM_HANDLER_TYPE_GIZMO = 1,
45   WM_HANDLER_TYPE_UI,
46   WM_HANDLER_TYPE_OP,
47   WM_HANDLER_TYPE_DROPBOX,
48   WM_HANDLER_TYPE_KEYMAP,
49 };
50 
51 typedef bool (*EventHandlerPoll)(const ARegion *region, const wmEvent *event);
52 
53 typedef struct wmEventHandler {
54   struct wmEventHandler *next, *prev;
55 
56   enum eWM_EventHandlerType type;
57   char flag; /* WM_HANDLER_BLOCKING, ... */
58 
59   EventHandlerPoll poll;
60 } wmEventHandler;
61 
62 /** Run after the keymap item runs. */
63 struct wmEventHandler_KeymapPost {
64   void (*post_fn)(wmKeyMap *keymap, wmKeyMapItem *kmi, void *user_data);
65   void *user_data;
66 };
67 
68 /** Support for a getter function that looks up the keymap each access. */
69 struct wmEventHandler_KeymapDynamic {
70   wmEventHandler_KeymapDynamicFn *keymap_fn;
71   void *user_data;
72 };
73 
74 /** #WM_HANDLER_TYPE_KEYMAP */
75 typedef struct wmEventHandler_Keymap {
76   wmEventHandler head;
77 
78   /** Pointer to builtin/custom keymaps (never NULL). */
79   wmKeyMap *keymap;
80 
81   struct wmEventHandler_KeymapPost post;
82   struct wmEventHandler_KeymapDynamic dynamic;
83 
84   struct bToolRef *keymap_tool;
85 } wmEventHandler_Keymap;
86 
87 /** #WM_HANDLER_TYPE_GIZMO */
88 typedef struct wmEventHandler_Gizmo {
89   wmEventHandler head;
90 
91   /** Gizmo handler (never NULL). */
92   struct wmGizmoMap *gizmo_map;
93 } wmEventHandler_Gizmo;
94 
95 /** #WM_HANDLER_TYPE_UI */
96 typedef struct wmEventHandler_UI {
97   wmEventHandler head;
98 
99   wmUIHandlerFunc handle_fn;       /* callback receiving events */
100   wmUIHandlerRemoveFunc remove_fn; /* callback when handler is removed */
101   void *user_data;                 /* user data pointer */
102 
103   /** Store context for this handler for derived/modal handlers. */
104   struct {
105     struct ScrArea *area;
106     struct ARegion *region;
107     struct ARegion *menu;
108   } context;
109 } wmEventHandler_UI;
110 
111 /** #WM_HANDLER_TYPE_OP */
112 typedef struct wmEventHandler_Op {
113   wmEventHandler head;
114 
115   /** Operator can be NULL. */
116   wmOperator *op;
117 
118   /** Hack, special case for file-select. */
119   bool is_fileselect;
120 
121   /** Store context for this handler for derived/modal handlers. */
122   struct {
123     /* To override the window, and hence the screen. Set for few cases only, usually window/screen
124      * can be taken from current context. */
125     struct wmWindow *win;
126 
127     struct ScrArea *area;
128     struct ARegion *region;
129     short region_type;
130   } context;
131 } wmEventHandler_Op;
132 
133 /** #WM_HANDLER_TYPE_DROPBOX */
134 typedef struct wmEventHandler_Dropbox {
135   wmEventHandler head;
136 
137   /** Never NULL. */
138   ListBase *dropboxes;
139 } wmEventHandler_Dropbox;
140 
141 /* wm_event_system.c */
142 void wm_event_free_all(wmWindow *win);
143 void wm_event_free(wmEvent *event);
144 void wm_event_free_handler(wmEventHandler *handler);
145 
146 /* goes over entire hierarchy:  events -> window -> screen -> area -> region */
147 void wm_event_do_handlers(bContext *C);
148 
149 void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void *customdata);
150 
151 void wm_event_do_depsgraph(bContext *C, bool is_after_open_file);
152 void wm_event_do_refresh_wm_and_depsgraph(bContext *C);
153 void wm_event_do_notifiers(bContext *C);
154 
155 void wm_event_handler_ui_cancel_ex(bContext *C,
156                                    wmWindow *win,
157                                    ARegion *region,
158                                    bool reactivate_button);
159 
160 /* wm_event_query.c */
161 float wm_pressure_curve(float raw_pressure);
162 void wm_tablet_data_from_ghost(const struct GHOST_TabletData *tablet_data, wmTabletData *wmtab);
163 
164 /* wm_keymap.c */
165 
166 /* wm_dropbox.c */
167 void wm_dropbox_free(void);
168 void wm_drags_check_ops(bContext *C, const wmEvent *event);
169 void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect);
170 
171 #ifdef __cplusplus
172 }
173 #endif
174