af6f2559caeab6934f287ce4ccfa6286c7bc4ce8
[blender.git] / source / blender / windowmanager / WM_api.h
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 #ifndef __WM_API_H__
20 #define __WM_API_H__
21
22 /** \file
23  * \ingroup wm
24  *
25  * \page wmpage windowmanager
26  * \section wmabout About windowmanager
27  * \ref wm handles events received from \ref GHOST and manages
28  * the screens, areas and input for Blender
29  * \section wmnote NOTE
30  * \todo document
31  */
32
33 /* dna-savable wmStructs here */
34 #include "DNA_windowmanager_types.h"
35 #include "WM_keymap.h"
36 #include "BLI_compiler_attrs.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 struct ARegion;
43 struct GHashIterator;
44 struct GPUViewport;
45 struct IDProperty;
46 struct ImBuf;
47 struct ImageFormatData;
48 struct Main;
49 struct MenuType;
50 struct PointerRNA;
51 struct PropertyRNA;
52 struct ScrArea;
53 struct ViewLayer;
54 struct bContext;
55 struct bToolRef_Runtime;
56 struct rcti;
57 struct wmDrag;
58 struct wmDropBox;
59 struct wmEvent;
60 struct wmEventHandler;
61 struct wmEventHandler_Keymap;
62 struct wmEventHandler_UI;
63 struct wmGesture;
64 struct wmJob;
65 struct wmMsgSubscribeKey;
66 struct wmMsgSubscribeValue;
67 struct wmOperator;
68 struct wmOperatorType;
69 struct wmPaintCursor;
70
71 #ifdef WITH_INPUT_NDOF
72 struct wmNDOFMotionData;
73 #endif
74
75 typedef struct wmGizmo wmGizmo;
76 typedef struct wmGizmoMap wmGizmoMap;
77 typedef struct wmGizmoMapType wmGizmoMapType;
78 typedef struct wmJob wmJob;
79
80 /* general API */
81 void WM_init_state_app_template_set(const char *app_template);
82 const char *WM_init_state_app_template_get(void);
83
84 void WM_init_state_size_set(int stax, int stay, int sizx, int sizy);
85 void WM_init_state_fullscreen_set(void);
86 void WM_init_state_normal_set(void);
87 void WM_init_state_maximized_set(void);
88 void WM_init_state_start_with_console_set(bool value);
89 void WM_init_window_focus_set(bool do_it);
90 void WM_init_native_pixels(bool do_it);
91 void WM_init_tablet_api(void);
92
93 void WM_init(struct bContext *C, int argc, const char **argv);
94 void WM_exit_ext(struct bContext *C, const bool do_python);
95
96 void WM_exit(struct bContext *C) ATTR_NORETURN;
97
98 void WM_main(struct bContext *C) ATTR_NORETURN;
99
100 void WM_init_splash(struct bContext *C);
101
102 void WM_init_opengl(struct Main *bmain);
103
104 void WM_check(struct bContext *C);
105 void WM_reinit_gizmomap_all(struct Main *bmain);
106
107 int WM_window_pixels_x(const struct wmWindow *win);
108 int WM_window_pixels_y(const struct wmWindow *win);
109 void WM_window_rect_calc(const struct wmWindow *win, struct rcti *r_rect);
110 void WM_window_screen_rect_calc(const struct wmWindow *win, struct rcti *r_rect);
111 bool WM_window_is_fullscreen(struct wmWindow *win);
112
113 void WM_windows_scene_data_sync(const ListBase *win_lb, struct Scene *scene) ATTR_NONNULL();
114 struct Scene *WM_windows_scene_get_from_screen(const struct wmWindowManager *wm,
115                                                const struct bScreen *screen)
116     ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
117 struct WorkSpace *WM_windows_workspace_get_from_screen(const wmWindowManager *wm,
118                                                        const struct bScreen *screen)
119     ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
120
121 struct Scene *WM_window_get_active_scene(const struct wmWindow *win)
122     ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
123 void WM_window_set_active_scene(struct Main *bmain,
124                                 struct bContext *C,
125                                 struct wmWindow *win,
126                                 struct Scene *scene_new) ATTR_NONNULL();
127 struct WorkSpace *WM_window_get_active_workspace(const struct wmWindow *win)
128     ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
129 void WM_window_set_active_workspace(struct bContext *C,
130                                     struct wmWindow *win,
131                                     struct WorkSpace *workspace) ATTR_NONNULL(1);
132 struct WorkSpaceLayout *WM_window_get_active_layout(const struct wmWindow *win)
133     ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
134 void WM_window_set_active_layout(struct wmWindow *win,
135                                  struct WorkSpace *workspace,
136                                  struct WorkSpaceLayout *layout) ATTR_NONNULL(1);
137 struct bScreen *WM_window_get_active_screen(const struct wmWindow *win)
138     ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
139 void WM_window_set_active_screen(struct wmWindow *win,
140                                  struct WorkSpace *workspace,
141                                  struct bScreen *screen) ATTR_NONNULL(1);
142
143 struct ViewLayer *WM_window_get_active_view_layer(const struct wmWindow *win)
144     ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
145 void WM_window_set_active_view_layer(struct wmWindow *win, struct ViewLayer *view_layer)
146     ATTR_NONNULL(1);
147 void WM_window_ensure_active_view_layer(struct wmWindow *win) ATTR_NONNULL(1);
148
149 bool WM_window_is_temp_screen(const struct wmWindow *win) ATTR_WARN_UNUSED_RESULT;
150
151 void *WM_opengl_context_create(void);
152 void WM_opengl_context_dispose(void *context);
153 void WM_opengl_context_activate(void *context);
154 void WM_opengl_context_release(void *context);
155
156 /* defines for 'type' WM_window_open_temp */
157 enum {
158   WM_WINDOW_RENDER = 1,
159   WM_WINDOW_USERPREFS,
160   WM_WINDOW_DRIVERS,
161   // WM_WINDOW_FILESEL // UNUSED
162 };
163
164 struct wmWindow *WM_window_open(struct bContext *C, const struct rcti *rect);
165 struct wmWindow *WM_window_open_temp(
166     struct bContext *C, int x, int y, int sizex, int sizey, int type);
167 void WM_window_set_dpi(wmWindow *win);
168
169 bool WM_stereo3d_enabled(struct wmWindow *win, bool only_fullscreen_test);
170
171 /* files */
172 void WM_file_autoexec_init(const char *filepath);
173 bool WM_file_read(struct bContext *C, const char *filepath, struct ReportList *reports);
174 void WM_autosave_init(struct wmWindowManager *wm);
175 void WM_recover_last_session(struct bContext *C, struct ReportList *reports);
176 void WM_file_tag_modified(void);
177
178 void WM_lib_reload(struct Library *lib, struct bContext *C, struct ReportList *reports);
179
180 /* mouse cursors */
181 void WM_cursor_set(struct wmWindow *win, int curs);
182 bool WM_cursor_set_from_tool(struct wmWindow *win, const ScrArea *sa, const ARegion *ar);
183 void WM_cursor_modal_set(struct wmWindow *win, int curs);
184 void WM_cursor_modal_restore(struct wmWindow *win);
185 void WM_cursor_wait(bool val);
186 void WM_cursor_grab_enable(struct wmWindow *win, bool wrap, bool hide, int bounds[4]);
187 void WM_cursor_grab_disable(struct wmWindow *win, const int mouse_ungrab_xy[2]);
188 void WM_cursor_time(struct wmWindow *win, int nr);
189
190 struct wmPaintCursor *WM_paint_cursor_activate(
191     struct wmWindowManager *wm,
192     short space_type,
193     short region_type,
194     bool (*poll)(struct bContext *C),
195     void (*draw)(struct bContext *C, int, int, void *customdata),
196     void *customdata);
197
198 bool WM_paint_cursor_end(struct wmWindowManager *wm, struct wmPaintCursor *handle);
199 void WM_paint_cursor_tag_redraw(struct wmWindow *win, struct ARegion *ar);
200
201 void WM_cursor_warp(struct wmWindow *win, int x, int y);
202 void WM_cursor_compatible_xy(wmWindow *win, int *x, int *y);
203 float WM_cursor_pressure(const struct wmWindow *win);
204
205 /* event map */
206 int WM_userdef_event_map(int kmitype);
207 int WM_userdef_event_type_from_keymap_type(int kmitype);
208
209 /* handlers */
210
211 struct wmEventHandler_Keymap *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap);
212 /* boundbox, optional subwindow boundbox for offset */
213 struct wmEventHandler_Keymap *WM_event_add_keymap_handler_bb(ListBase *handlers,
214                                                              wmKeyMap *keymap,
215                                                              const rcti *bb,
216                                                              const rcti *swinbb);
217 /* priority not implemented, it adds in begin */
218 struct wmEventHandler_Keymap *WM_event_add_keymap_handler_priority(ListBase *handlers,
219                                                                    wmKeyMap *keymap,
220                                                                    int priority);
221
222 typedef struct wmKeyMap *(wmEventHandler_KeymapDynamicFn)(
223     wmWindowManager *wm, struct wmEventHandler_Keymap *handler)ATTR_WARN_UNUSED_RESULT;
224
225 struct wmKeyMap *WM_event_get_keymap_from_toolsystem(struct wmWindowManager *wm,
226                                                      struct wmEventHandler_Keymap *handler);
227
228 struct wmEventHandler_Keymap *WM_event_add_keymap_handler_dynamic(
229     ListBase *handlers, wmEventHandler_KeymapDynamicFn *keymap_fn, void *user_data);
230
231 void WM_event_remove_keymap_handler(ListBase *handlers, wmKeyMap *keymap);
232
233 void WM_event_set_keymap_handler_post_callback(struct wmEventHandler_Keymap *handler,
234                                                void(keymap_tag)(wmKeyMap *keymap,
235                                                                 wmKeyMapItem *kmi,
236                                                                 void *user_data),
237                                                void *user_data);
238 wmKeyMap *WM_event_get_keymap_from_handler(wmWindowManager *wm,
239                                            struct wmEventHandler_Keymap *handler);
240
241 typedef int (*wmUIHandlerFunc)(struct bContext *C, const struct wmEvent *event, void *userdata);
242 typedef void (*wmUIHandlerRemoveFunc)(struct bContext *C, void *userdata);
243
244 struct wmEventHandler_UI *WM_event_add_ui_handler(const struct bContext *C,
245                                                   ListBase *handlers,
246                                                   wmUIHandlerFunc ui_handle,
247                                                   wmUIHandlerRemoveFunc ui_remove,
248                                                   void *userdata,
249                                                   const char flag);
250 void WM_event_remove_ui_handler(ListBase *handlers,
251                                 wmUIHandlerFunc ui_handle,
252                                 wmUIHandlerRemoveFunc ui_remove,
253                                 void *userdata,
254                                 const bool postpone);
255 void WM_event_remove_area_handler(struct ListBase *handlers, void *area);
256 void WM_event_free_ui_handler_all(struct bContext *C,
257                                   ListBase *handlers,
258                                   wmUIHandlerFunc ui_handle,
259                                   wmUIHandlerRemoveFunc ui_remove);
260
261 struct wmEventHandler_Op *WM_event_add_modal_handler(struct bContext *C, struct wmOperator *op);
262 void WM_event_modal_handler_area_replace(wmWindow *win,
263                                          const struct ScrArea *old_area,
264                                          struct ScrArea *new_area);
265 void WM_event_modal_handler_region_replace(wmWindow *win,
266                                            const struct ARegion *old_region,
267                                            struct ARegion *new_region);
268
269 void WM_event_remove_handlers(struct bContext *C, ListBase *handlers);
270
271 /* handler flag */
272 enum {
273   WM_HANDLER_BLOCKING = (1 << 0),         /* after this handler all others are ignored */
274   WM_HANDLER_ACCEPT_DBL_CLICK = (1 << 1), /* handler accepts double key press events */
275
276   /* internal */
277   WM_HANDLER_DO_FREE = (1 << 7), /* handler tagged to be freed in wm_handlers_do() */
278 };
279
280 struct wmEventHandler_Dropbox *WM_event_add_dropbox_handler(ListBase *handlers,
281                                                             ListBase *dropboxes);
282
283 /* mouse */
284 void WM_event_add_mousemove(const struct bContext *C);
285 bool WM_event_is_modal_tweak_exit(const struct wmEvent *event, int tweak_event);
286 bool WM_event_is_last_mousemove(const struct wmEvent *event);
287
288 #ifdef WITH_INPUT_NDOF
289 /* 3D mouse */
290 void WM_ndof_deadzone_set(float deadzone);
291 #endif
292 /* notifiers */
293 void WM_event_add_notifier(const struct bContext *C, unsigned int type, void *reference);
294 void WM_main_add_notifier(unsigned int type, void *reference);
295 void WM_main_remove_notifier_reference(const void *reference);
296 void WM_main_remap_editor_id_reference(struct ID *old_id, struct ID *new_id);
297
298 /* reports */
299 void WM_report_banner_show(void);
300 void WM_report(ReportType type, const char *message);
301 void WM_reportf(ReportType type, const char *format, ...) ATTR_PRINTF_FORMAT(2, 3);
302
303 struct wmEvent *wm_event_add_ex(struct wmWindow *win,
304                                 const struct wmEvent *event_to_add,
305                                 const struct wmEvent *event_to_add_after) ATTR_NONNULL(1, 2);
306 struct wmEvent *wm_event_add(struct wmWindow *win, const struct wmEvent *event_to_add)
307     ATTR_NONNULL(1, 2);
308
309 void wm_event_init_from_window(struct wmWindow *win, struct wmEvent *event);
310
311 /* at maximum, every timestep seconds it triggers event_type events */
312 struct wmTimer *WM_event_add_timer(struct wmWindowManager *wm,
313                                    struct wmWindow *win,
314                                    int event_type,
315                                    double timestep);
316 struct wmTimer *WM_event_add_timer_notifier(struct wmWindowManager *wm,
317                                             struct wmWindow *win,
318                                             unsigned int type,
319                                             double timestep);
320 void WM_event_remove_timer(struct wmWindowManager *wm,
321                            struct wmWindow *win,
322                            struct wmTimer *timer);
323 void WM_event_remove_timer_notifier(struct wmWindowManager *wm,
324                                     struct wmWindow *win,
325                                     struct wmTimer *timer);
326 void WM_event_timer_sleep(struct wmWindowManager *wm,
327                           struct wmWindow *win,
328                           struct wmTimer *timer,
329                           bool do_sleep);
330
331 /* operator api, default callbacks */
332 /* invoke callback, uses enum property named "type" */
333 void WM_operator_view3d_unit_defaults(struct bContext *C, struct wmOperator *op);
334 int WM_operator_smooth_viewtx_get(const struct wmOperator *op);
335 int WM_menu_invoke_ex(struct bContext *C, struct wmOperator *op, int opcontext);
336 int WM_menu_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
337 void WM_menu_name_call(struct bContext *C, const char *menu_name, short context);
338 int WM_enum_search_invoke_previews(struct bContext *C,
339                                    struct wmOperator *op,
340                                    short prv_cols,
341                                    short prv_rows);
342 int WM_enum_search_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
343 /* invoke callback, confirm menu + exec */
344 int WM_operator_confirm(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
345 int WM_operator_confirm_or_exec(struct bContext *C,
346                                 struct wmOperator *op,
347                                 const struct wmEvent *event);
348 /* invoke callback, file selector "filepath" unset + exec */
349 int WM_operator_filesel(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
350 bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op,
351                                            const struct ImageFormatData *im_format);
352 /* poll callback, context checks */
353 bool WM_operator_winactive(struct bContext *C);
354 /* invoke callback, exec + redo popup */
355 int WM_operator_props_popup_confirm(struct bContext *C,
356                                     struct wmOperator *op,
357                                     const struct wmEvent *event);
358 int WM_operator_props_popup_call(struct bContext *C,
359                                  struct wmOperator *op,
360                                  const struct wmEvent *event);
361 int WM_operator_props_popup(struct bContext *C,
362                             struct wmOperator *op,
363                             const struct wmEvent *event);
364 int WM_operator_props_dialog_popup(struct bContext *C,
365                                    struct wmOperator *op,
366                                    int width,
367                                    int height);
368 int WM_operator_redo_popup(struct bContext *C, struct wmOperator *op);
369 int WM_operator_ui_popup(struct bContext *C, struct wmOperator *op, int width, int height);
370
371 int WM_operator_confirm_message_ex(struct bContext *C,
372                                    struct wmOperator *op,
373                                    const char *title,
374                                    const int icon,
375                                    const char *message);
376 int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message);
377
378 /* operator api */
379 void WM_operator_free(struct wmOperator *op);
380 void WM_operator_free_all_after(wmWindowManager *wm, struct wmOperator *op);
381 void WM_operator_type_set(struct wmOperator *op, struct wmOperatorType *ot);
382 void WM_operator_stack_clear(struct wmWindowManager *wm);
383 void WM_operator_handlers_clear(wmWindowManager *wm, struct wmOperatorType *ot);
384
385 bool WM_operator_poll(struct bContext *C, struct wmOperatorType *ot);
386 bool WM_operator_poll_context(struct bContext *C, struct wmOperatorType *ot, short context);
387 int WM_operator_call_ex(struct bContext *C, struct wmOperator *op, const bool store);
388 int WM_operator_call(struct bContext *C, struct wmOperator *op);
389 int WM_operator_call_notest(struct bContext *C, struct wmOperator *op);
390 int WM_operator_repeat(struct bContext *C, struct wmOperator *op);
391 int WM_operator_repeat_interactive(struct bContext *C, struct wmOperator *op);
392 bool WM_operator_repeat_check(const struct bContext *C, struct wmOperator *op);
393 bool WM_operator_is_repeat(const struct bContext *C, const struct wmOperator *op);
394 int WM_operator_name_call_ptr(struct bContext *C,
395                               struct wmOperatorType *ot,
396                               short context,
397                               struct PointerRNA *properties);
398 int WM_operator_name_call(struct bContext *C,
399                           const char *opstring,
400                           short context,
401                           struct PointerRNA *properties);
402 int WM_operator_call_py(struct bContext *C,
403                         struct wmOperatorType *ot,
404                         short context,
405                         struct PointerRNA *properties,
406                         struct ReportList *reports,
407                         const bool is_undo);
408
409 void WM_operator_properties_alloc(struct PointerRNA **ptr,
410                                   struct IDProperty **properties,
411                                   const char *opstring); /* used for keymap and macro items */
412 void WM_operator_properties_sanitize(
413     struct PointerRNA *ptr, const bool no_context); /* make props context sensitive or not */
414 bool WM_operator_properties_default(struct PointerRNA *ptr, const bool do_update);
415 void WM_operator_properties_reset(struct wmOperator *op);
416 void WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring);
417 void WM_operator_properties_create_ptr(struct PointerRNA *ptr, struct wmOperatorType *ot);
418 void WM_operator_properties_clear(struct PointerRNA *ptr);
419 void WM_operator_properties_free(struct PointerRNA *ptr);
420
421 bool WM_operator_check_ui_empty(struct wmOperatorType *ot);
422 bool WM_operator_check_ui_enabled(const struct bContext *C, const char *idname);
423
424 IDProperty *WM_operator_last_properties_ensure_idprops(struct wmOperatorType *ot);
425 void WM_operator_last_properties_ensure(struct wmOperatorType *ot, struct PointerRNA *ptr);
426 wmOperator *WM_operator_last_redo(const struct bContext *C);
427 ID *WM_operator_drop_load_path(struct bContext *C, struct wmOperator *op, const short idcode);
428
429 bool WM_operator_last_properties_init(struct wmOperator *op);
430 bool WM_operator_last_properties_store(struct wmOperator *op);
431
432 /* wm_operator_props.c */
433 void WM_operator_properties_confirm_or_exec(struct wmOperatorType *ot);
434 void WM_operator_properties_filesel(struct wmOperatorType *ot,
435                                     int filter,
436                                     short type,
437                                     short action,
438                                     short flag,
439                                     short display,
440                                     short sort);
441 void WM_operator_properties_border(struct wmOperatorType *ot);
442 void WM_operator_properties_border_to_rcti(struct wmOperator *op, struct rcti *rect);
443 void WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect);
444 void WM_operator_properties_gesture_box_ex(struct wmOperatorType *ot, bool deselect, bool extend);
445 void WM_operator_properties_gesture_box(struct wmOperatorType *ot);
446 void WM_operator_properties_gesture_box_select(struct wmOperatorType *ot);
447 void WM_operator_properties_gesture_box_zoom(struct wmOperatorType *ot);
448 void WM_operator_properties_gesture_lasso(struct wmOperatorType *ot);
449 void WM_operator_properties_gesture_straightline(struct wmOperatorType *ot, int cursor);
450 void WM_operator_properties_gesture_circle(struct wmOperatorType *ot);
451 void WM_operator_properties_mouse_select(struct wmOperatorType *ot);
452 void WM_operator_properties_select_all(struct wmOperatorType *ot);
453 void WM_operator_properties_select_action(struct wmOperatorType *ot,
454                                           int default_action,
455                                           bool hide_gui);
456 void WM_operator_properties_select_action_simple(struct wmOperatorType *ot,
457                                                  int default_action,
458                                                  bool hide_gui);
459 void WM_operator_properties_select_random(struct wmOperatorType *ot);
460 int WM_operator_properties_select_random_seed_increment_get(wmOperator *op);
461 void WM_operator_properties_select_operation(struct wmOperatorType *ot);
462 void WM_operator_properties_select_operation_simple(struct wmOperatorType *ot);
463 struct CheckerIntervalParams {
464   int nth; /* bypass when set to zero */
465   int skip;
466   int offset;
467 };
468 void WM_operator_properties_checker_interval(struct wmOperatorType *ot, bool nth_can_disable);
469 void WM_operator_properties_checker_interval_from_op(struct wmOperator *op,
470                                                      struct CheckerIntervalParams *op_params);
471 bool WM_operator_properties_checker_interval_test(const struct CheckerIntervalParams *op_params,
472                                                   int depth);
473
474 /* flags for WM_operator_properties_filesel */
475 #define WM_FILESEL_RELPATH (1 << 0)
476
477 #define WM_FILESEL_DIRECTORY (1 << 1)
478 #define WM_FILESEL_FILENAME (1 << 2)
479 #define WM_FILESEL_FILEPATH (1 << 3)
480 #define WM_FILESEL_FILES (1 << 4)
481
482 /* operator as a python command (resultuing string must be freed) */
483 char *WM_operator_pystring_ex(struct bContext *C,
484                               struct wmOperator *op,
485                               const bool all_args,
486                               const bool macro_args,
487                               struct wmOperatorType *ot,
488                               struct PointerRNA *opptr);
489 char *WM_operator_pystring(struct bContext *C,
490                            struct wmOperator *op,
491                            const bool all_args,
492                            const bool macro_args);
493 bool WM_operator_pystring_abbreviate(char *str, int str_len_max);
494 char *WM_prop_pystring_assign(struct bContext *C,
495                               struct PointerRNA *ptr,
496                               struct PropertyRNA *prop,
497                               int index);
498 void WM_operator_bl_idname(char *to, const char *from);
499 void WM_operator_py_idname(char *to, const char *from);
500 bool WM_operator_py_idname_ok_or_report(struct ReportList *reports,
501                                         const char *classname,
502                                         const char *idname);
503 const char *WM_context_member_from_ptr(struct bContext *C, const struct PointerRNA *ptr);
504
505 /* wm_operator_type.c */
506 struct wmOperatorType *WM_operatortype_find(const char *idname, bool quiet);
507 void WM_operatortype_iter(struct GHashIterator *ghi);
508 void WM_operatortype_append(void (*opfunc)(struct wmOperatorType *));
509 void WM_operatortype_append_ptr(void (*opfunc)(struct wmOperatorType *, void *), void *userdata);
510 void WM_operatortype_append_macro_ptr(void (*opfunc)(struct wmOperatorType *, void *),
511                                       void *userdata);
512 void WM_operatortype_remove_ptr(struct wmOperatorType *ot);
513 bool WM_operatortype_remove(const char *idname);
514 void WM_operatortype_last_properties_clear_all(void);
515 void WM_operatortype_props_advanced_begin(struct wmOperatorType *ot);
516 void WM_operatortype_props_advanced_end(struct wmOperatorType *ot);
517
518 #define WM_operatortype_prop_tag(property, tags) \
519   { \
520     CHECK_TYPE(tags, eOperatorPropTags); \
521     RNA_def_property_tags(prop, tags); \
522   } \
523   (void)0
524
525 struct wmOperatorType *WM_operatortype_append_macro(const char *idname,
526                                                     const char *name,
527                                                     const char *description,
528                                                     int flag);
529 struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *ot,
530                                                          const char *idname);
531
532 /* wm_uilist_type.c */
533 void WM_uilisttype_init(void);
534 struct uiListType *WM_uilisttype_find(const char *idname, bool quiet);
535 bool WM_uilisttype_add(struct uiListType *ult);
536 void WM_uilisttype_freelink(struct uiListType *ult);
537 void WM_uilisttype_free(void);
538
539 /* wm_menu_type.c */
540 void WM_menutype_init(void);
541 struct MenuType *WM_menutype_find(const char *idname, bool quiet);
542 bool WM_menutype_add(struct MenuType *mt);
543 void WM_menutype_freelink(struct MenuType *mt);
544 void WM_menutype_free(void);
545 bool WM_menutype_poll(struct bContext *C, struct MenuType *mt);
546
547 /* wm_panel_type.c */
548 void WM_paneltype_init(void);
549 void WM_paneltype_clear(void);
550 struct PanelType *WM_paneltype_find(const char *idname, bool quiet);
551 bool WM_paneltype_add(struct PanelType *mt);
552 void WM_paneltype_remove(struct PanelType *mt);
553
554 /* wm_gesture_ops.c */
555 int WM_gesture_box_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
556 int WM_gesture_box_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
557 void WM_gesture_box_cancel(struct bContext *C, struct wmOperator *op);
558 int WM_gesture_circle_invoke(struct bContext *C,
559                              struct wmOperator *op,
560                              const struct wmEvent *event);
561 int WM_gesture_circle_modal(struct bContext *C,
562                             struct wmOperator *op,
563                             const struct wmEvent *event);
564 void WM_gesture_circle_cancel(struct bContext *C, struct wmOperator *op);
565 int WM_gesture_lines_invoke(struct bContext *C,
566                             struct wmOperator *op,
567                             const struct wmEvent *event);
568 int WM_gesture_lines_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
569 void WM_gesture_lines_cancel(struct bContext *C, struct wmOperator *op);
570 int WM_gesture_lasso_invoke(struct bContext *C,
571                             struct wmOperator *op,
572                             const struct wmEvent *event);
573 int WM_gesture_lasso_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
574 void WM_gesture_lasso_cancel(struct bContext *C, struct wmOperator *op);
575 const int (*WM_gesture_lasso_path_to_array(struct bContext *C,
576                                            struct wmOperator *op,
577                                            int *mcords_tot))[2];
578 int WM_gesture_straightline_invoke(struct bContext *C,
579                                    struct wmOperator *op,
580                                    const struct wmEvent *event);
581 int WM_gesture_straightline_modal(struct bContext *C,
582                                   struct wmOperator *op,
583                                   const struct wmEvent *event);
584 void WM_gesture_straightline_cancel(struct bContext *C, struct wmOperator *op);
585
586 /* Gesture manager API */
587 struct wmGesture *WM_gesture_new(struct bContext *C, const struct wmEvent *event, int type);
588 void WM_gesture_end(struct bContext *C, struct wmGesture *gesture);
589 void WM_gestures_remove(struct bContext *C);
590 bool WM_gesture_is_modal_first(const struct wmGesture *gesture);
591
592 /* fileselecting support */
593 void WM_event_add_fileselect(struct bContext *C, struct wmOperator *op);
594 void WM_event_fileselect_event(struct wmWindowManager *wm, void *ophandle, int eventval);
595 void WM_event_print(const struct wmEvent *event);
596
597 void WM_operator_region_active_win_set(struct bContext *C);
598
599 /* drag and drop */
600 struct wmDrag *WM_event_start_drag(
601     struct bContext *C, int icon, int type, void *poin, double value, unsigned int flags);
602 void WM_event_drag_image(struct wmDrag *, struct ImBuf *, float scale, int sx, int sy);
603 void WM_drag_free(struct wmDrag *drag);
604 void WM_drag_free_list(struct ListBase *lb);
605
606 struct wmDropBox *WM_dropbox_add(
607     ListBase *lb,
608     const char *idname,
609     bool (*poll)(struct bContext *, struct wmDrag *, const struct wmEvent *event, const char **),
610     void (*copy)(struct wmDrag *, struct wmDropBox *));
611 ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
612
613 /* ID drag and drop */
614 void WM_drag_add_ID(struct wmDrag *drag, struct ID *id, struct ID *from_parent);
615 struct ID *WM_drag_ID(const struct wmDrag *drag, short idcode);
616 struct ID *WM_drag_ID_from_event(const struct wmEvent *event, short idcode);
617
618 /* Set OpenGL viewport and scissor */
619 void wmViewport(const struct rcti *rect);
620 void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct);
621 void wmWindowViewport(struct wmWindow *win);
622
623 /* OpenGL utilities with safety check */
624 void wmOrtho2(float x1, float x2, float y1, float y2);
625 /* use for conventions (avoid hard-coded offsets all over) */
626 void wmOrtho2_region_pixelspace(const struct ARegion *ar);
627 void wmOrtho2_pixelspace(const float x, const float y);
628 void wmGetProjectionMatrix(float mat[4][4], const struct rcti *winrct);
629
630 /* threaded Jobs Manager */
631 enum {
632   WM_JOB_PRIORITY = (1 << 0),
633   WM_JOB_EXCL_RENDER = (1 << 1),
634   WM_JOB_PROGRESS = (1 << 2),
635   WM_JOB_SUSPEND = (1 << 3),
636 };
637
638 /* identifying jobs by owner alone is unreliable, this isnt saved, order can change (keep 0 for 'any') */
639 enum {
640   WM_JOB_TYPE_ANY = 0,
641   WM_JOB_TYPE_COMPOSITE,
642   WM_JOB_TYPE_RENDER,
643   WM_JOB_TYPE_RENDER_PREVIEW, /* UI preview */
644   WM_JOB_TYPE_OBJECT_SIM_OCEAN,
645   WM_JOB_TYPE_OBJECT_SIM_FLUID,
646   WM_JOB_TYPE_OBJECT_BAKE_TEXTURE,
647   WM_JOB_TYPE_OBJECT_BAKE,
648   WM_JOB_TYPE_FILESEL_READDIR,
649   WM_JOB_TYPE_CLIP_BUILD_PROXY,
650   WM_JOB_TYPE_CLIP_TRACK_MARKERS,
651   WM_JOB_TYPE_CLIP_SOLVE_CAMERA,
652   WM_JOB_TYPE_CLIP_PREFETCH,
653   WM_JOB_TYPE_SEQ_BUILD_PROXY,
654   WM_JOB_TYPE_SEQ_BUILD_PREVIEW,
655   WM_JOB_TYPE_POINTCACHE,
656   WM_JOB_TYPE_DPAINT_BAKE,
657   WM_JOB_TYPE_ALEMBIC,
658   WM_JOB_TYPE_SHADER_COMPILATION,
659   WM_JOB_TYPE_STUDIOLIGHT,
660   WM_JOB_TYPE_LIGHT_BAKE,
661   /* add as needed, screencast, seq proxy build
662    * if having hard coded values is a problem */
663 };
664
665 struct wmJob *WM_jobs_get(struct wmWindowManager *wm,
666                           struct wmWindow *win,
667                           void *owner,
668                           const char *name,
669                           int flag,
670                           int job_type);
671
672 bool WM_jobs_test(struct wmWindowManager *wm, void *owner, int job_type);
673 float WM_jobs_progress(struct wmWindowManager *wm, void *owner);
674 char *WM_jobs_name(struct wmWindowManager *wm, void *owner);
675 double WM_jobs_starttime(struct wmWindowManager *wm, void *owner);
676 void *WM_jobs_customdata(struct wmWindowManager *wm, void *owner);
677 void *WM_jobs_customdata_from_type(struct wmWindowManager *wm, int job_type);
678
679 bool WM_jobs_is_running(struct wmJob *);
680 bool WM_jobs_is_stopped(wmWindowManager *wm, void *owner);
681 void *WM_jobs_customdata_get(struct wmJob *);
682 void WM_jobs_customdata_set(struct wmJob *, void *customdata, void (*free)(void *));
683 void WM_jobs_timer(struct wmJob *, double timestep, unsigned int note, unsigned int endnote);
684 void WM_jobs_callbacks(struct wmJob *,
685                        void (*startjob)(void *, short *, short *, float *),
686                        void (*initjob)(void *),
687                        void (*update)(void *),
688                        void (*endjob)(void *));
689
690 void WM_jobs_start(struct wmWindowManager *wm, struct wmJob *);
691 void WM_jobs_stop(struct wmWindowManager *wm, void *owner, void *startjob);
692 void WM_jobs_kill(struct wmWindowManager *wm,
693                   void *owner,
694                   void (*)(void *, short int *, short int *, float *));
695 void WM_jobs_kill_all(struct wmWindowManager *wm);
696 void WM_jobs_kill_all_except(struct wmWindowManager *wm, void *owner);
697 void WM_jobs_kill_type(struct wmWindowManager *wm, void *owner, int job_type);
698
699 bool WM_jobs_has_running(struct wmWindowManager *wm);
700
701 void WM_job_main_thread_lock_acquire(struct wmJob *job);
702 void WM_job_main_thread_lock_release(struct wmJob *job);
703
704 /* clipboard */
705 char *WM_clipboard_text_get(bool selection, int *r_len);
706 char *WM_clipboard_text_get_firstline(bool selection, int *r_len);
707 void WM_clipboard_text_set(const char *buf, bool selection);
708
709 /* progress */
710 void WM_progress_set(struct wmWindow *win, float progress);
711 void WM_progress_clear(struct wmWindow *win);
712
713 /* Draw (for screenshot) */
714 void *WM_draw_cb_activate(struct wmWindow *win,
715                           void (*draw)(const struct wmWindow *, void *),
716                           void *customdata);
717 void WM_draw_cb_exit(struct wmWindow *win, void *handle);
718 void WM_redraw_windows(struct bContext *C);
719
720 /* Region drawing */
721 void WM_draw_region_free(struct ARegion *ar);
722 struct GPUViewport *WM_draw_region_get_viewport(struct ARegion *ar, int view);
723 struct GPUViewport *WM_draw_region_get_bound_viewport(struct ARegion *ar);
724
725 void WM_main_playanim(int argc, const char **argv);
726
727 /* debugging only, convenience function to write on crash */
728 bool write_crash_blend(void);
729
730 /* Lock the interface for any communication */
731 void WM_set_locked_interface(struct wmWindowManager *wm, bool lock);
732
733 #ifdef WITH_INPUT_NDOF
734 void WM_event_ndof_pan_get(const struct wmNDOFMotionData *ndof,
735                            float r_pan[3],
736                            const bool use_zoom);
737 void WM_event_ndof_rotate_get(const struct wmNDOFMotionData *ndof, float r_rot[3]);
738
739 float WM_event_ndof_to_axis_angle(const struct wmNDOFMotionData *ndof, float axis[3]);
740 void WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4]);
741 #endif /* WITH_INPUT_NDOF */
742
743 float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip, float tilt[2]);
744 bool WM_event_is_tablet(const struct wmEvent *event);
745
746 #ifdef WITH_INPUT_IME
747 bool WM_event_is_ime_switch(const struct wmEvent *event);
748 #endif
749
750 /* For testing only 'G_FLAG_EVENT_SIMULATE' */
751 struct wmEvent *WM_event_add_simulate(struct wmWindow *win, const struct wmEvent *event_to_add);
752
753 const char *WM_window_cursor_keymap_status_get(const struct wmWindow *win,
754                                                int button_index,
755                                                int type_index);
756 void WM_window_cursor_keymap_status_refresh(struct bContext *C, struct wmWindow *win);
757
758 void WM_window_status_area_tag_redraw(struct wmWindow *win);
759 struct ScrArea *WM_window_status_area_find(struct wmWindow *win, struct bScreen *sc);
760 bool WM_window_modal_keymap_status_draw(struct bContext *C,
761                                         struct wmWindow *win,
762                                         struct uiLayout *layout);
763
764 /* wm_tooltip.c */
765 typedef struct ARegion *(*wmTooltipInitFn)(struct bContext *C,
766                                            struct ARegion *ar,
767                                            int *pass,
768                                            double *r_pass_delay,
769                                            bool *r_exit_on_event);
770
771 void WM_tooltip_immediate_init(struct bContext *C,
772                                struct wmWindow *win,
773                                struct ARegion *ar,
774                                wmTooltipInitFn init);
775 void WM_tooltip_timer_init_ex(struct bContext *C,
776                               struct wmWindow *win,
777                               struct ARegion *ar,
778                               wmTooltipInitFn init,
779                               double delay);
780 void WM_tooltip_timer_init(struct bContext *C,
781                            struct wmWindow *win,
782                            struct ARegion *ar,
783                            wmTooltipInitFn init);
784 void WM_tooltip_timer_clear(struct bContext *C, struct wmWindow *win);
785 void WM_tooltip_clear(struct bContext *C, struct wmWindow *win);
786 void WM_tooltip_init(struct bContext *C, struct wmWindow *win);
787 void WM_tooltip_refresh(struct bContext *C, struct wmWindow *win);
788 double WM_tooltip_time_closed(void);
789
790 #ifdef __cplusplus
791 }
792 #endif
793
794 #endif /* __WM_API_H__ */