Blender V4.3
rna_wm_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cctype>
10#include <cstdio>
11#include <cstdlib>
12
13#include "BLI_utildefines.h"
14
15#include "RNA_define.hh"
16#include "RNA_enum_types.hh"
17
18#include "DNA_screen_types.h"
19#include "DNA_space_types.h"
21
22#include "UI_interface.hh"
23
24#include "wm_cursors.hh"
25#include "wm_event_types.hh"
26
27#include "WM_api.hh"
28#include "WM_types.hh"
29
30#include "rna_internal.hh" /* own include */
31
32/* confusing 2 enums mixed up here */
34 {WM_CURSOR_DEFAULT, "DEFAULT", 0, "Default", ""},
35 {WM_CURSOR_NONE, "NONE", 0, "None", ""},
36 {WM_CURSOR_WAIT, "WAIT", 0, "Wait", ""},
37 {WM_CURSOR_EDIT, "CROSSHAIR", 0, "Crosshair", ""},
38 {WM_CURSOR_X_MOVE, "MOVE_X", 0, "Move-X", ""},
39 {WM_CURSOR_Y_MOVE, "MOVE_Y", 0, "Move-Y", ""},
40
41 /* new */
42 {WM_CURSOR_KNIFE, "KNIFE", 0, "Knife", ""},
43 {WM_CURSOR_TEXT_EDIT, "TEXT", 0, "Text", ""},
44 {WM_CURSOR_PAINT_BRUSH, "PAINT_BRUSH", 0, "Paint Brush", ""},
45 {WM_CURSOR_PAINT, "PAINT_CROSS", 0, "Paint Cross", ""},
46 {WM_CURSOR_DOT, "DOT", 0, "Dot Cursor", ""},
47 {WM_CURSOR_ERASER, "ERASER", 0, "Eraser", ""},
48 {WM_CURSOR_HAND, "HAND", 0, "Open Hand", ""},
49 {WM_CURSOR_HAND_POINT, "HAND_POINT", 0, "Pointing Hand", ""},
50 {WM_CURSOR_HAND_CLOSED, "HAND_CLOSED", 0, "Closed Hand", ""},
51 {WM_CURSOR_EW_SCROLL, "SCROLL_X", 0, "Scroll-X", ""},
52 {WM_CURSOR_NS_SCROLL, "SCROLL_Y", 0, "Scroll-Y", ""},
53 {WM_CURSOR_NSEW_SCROLL, "SCROLL_XY", 0, "Scroll-XY", ""},
54 {WM_CURSOR_EYEDROPPER, "EYEDROPPER", 0, "Eyedropper", ""},
55 {WM_CURSOR_PICK_AREA, "PICK_AREA", 0, "Pick Area", ""},
56 {WM_CURSOR_STOP, "STOP", 0, "Stop", ""},
57 {WM_CURSOR_COPY, "COPY", 0, "Copy", ""},
58 {WM_CURSOR_CROSS, "CROSS", 0, "Cross", ""},
59 {WM_CURSOR_MUTE, "MUTE", 0, "Mute", ""},
60 {WM_CURSOR_ZOOM_IN, "ZOOM_IN", 0, "Zoom In", ""},
61 {WM_CURSOR_ZOOM_OUT, "ZOOM_OUT", 0, "Zoom Out", ""},
62 {0, nullptr, 0, nullptr, nullptr},
63};
64
65#ifdef RNA_RUNTIME
66
67# include "BKE_context.hh"
68# include "BKE_undo_system.hh"
69
70# include "WM_types.hh"
71
72/* Needed since RNA doesn't use `const` in function signatures. */
73static bool rna_KeyMapItem_compare(wmKeyMapItem *k1, wmKeyMapItem *k2)
74{
75 return WM_keymap_item_compare(k1, k2);
76}
77
78static void rna_KeyMapItem_to_string(wmKeyMapItem *kmi, bool compact, char *result)
79{
81 result, WM_keymap_item_to_string(kmi, compact).value_or("").c_str(), UI_MAX_SHORTCUT_STR);
82}
83
84static wmKeyMap *rna_keymap_active(wmKeyMap *km, bContext *C)
85{
87 return WM_keymap_active(wm, km);
88}
89
90static void rna_keymap_restore_to_default(wmKeyMap *km, bContext *C)
91{
93}
94
95static void rna_keymap_restore_item_to_default(wmKeyMap *km, bContext *C, wmKeyMapItem *kmi)
96{
98}
99
100static void rna_Operator_report(wmOperator *op, int type, const char *msg)
101{
102 BKE_report(op->reports, eReportType(type), msg);
103}
104
105static bool rna_Operator_is_repeat(wmOperator *op, bContext *C)
106{
107 return WM_operator_is_repeat(C, op);
108}
109
110/* since event isn't needed... */
111static void rna_Operator_enum_search_invoke(bContext *C, wmOperator *op)
112{
113 WM_enum_search_invoke(C, op, nullptr);
114}
115
116static bool rna_event_modal_handler_add(bContext *C, ReportList *reports, wmOperator *op)
117{
118 wmWindow *win = CTX_wm_window(C);
119 if (win == nullptr) {
120 BKE_report(reports, RPT_ERROR, "No active window in context!");
121 return false;
122 }
123 ScrArea *area = CTX_wm_area(C);
124 ARegion *region = CTX_wm_region(C);
125 return WM_event_add_modal_handler_ex(win, area, region, op) != nullptr;
126}
127
128static wmTimer *rna_event_timer_add(wmWindowManager *wm, float time_step, wmWindow *win)
129{
130 /* NOTE: we need a way for Python to know event types, `TIMER` is hard coded. */
131 return WM_event_timer_add(wm, win, TIMER, time_step);
132}
133
134static void rna_event_timer_remove(wmWindowManager *wm, wmTimer *timer)
135{
137}
138
139static wmGizmoGroupType *wm_gizmogrouptype_find_for_add_remove(ReportList *reports,
140 const char *idname)
141{
142 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, true);
143 if (gzgt == nullptr) {
144 BKE_reportf(reports, RPT_ERROR, "Gizmo group type '%s' not found!", idname);
145 return nullptr;
146 }
148 BKE_reportf(reports, RPT_ERROR, "Gizmo group '%s' has 'PERSISTENT' option set!", idname);
149 return nullptr;
150 }
151 return gzgt;
152}
153
154static void rna_gizmo_group_type_ensure(ReportList *reports, const char *idname)
155{
156 wmGizmoGroupType *gzgt = wm_gizmogrouptype_find_for_add_remove(reports, idname);
157 if (gzgt != nullptr) {
159 }
160}
161
162static void rna_gizmo_group_type_unlink_delayed(ReportList *reports, const char *idname)
163{
164 wmGizmoGroupType *gzgt = wm_gizmogrouptype_find_for_add_remove(reports, idname);
165 if (gzgt != nullptr) {
167 }
168}
169
170/* Placeholder data for final implementation of a true progress-bar. */
171static struct wmStaticProgress {
172 float min;
173 float max;
174 bool is_valid;
175} wm_progress_state = {0, 0, false};
176
177static void rna_progress_begin(wmWindowManager * /*wm*/, float min, float max)
178{
179 float range = max - min;
180 if (range != 0) {
181 wm_progress_state.min = min;
182 wm_progress_state.max = max;
183 wm_progress_state.is_valid = true;
184 }
185 else {
186 wm_progress_state.is_valid = false;
187 }
188}
189
190static void rna_progress_update(wmWindowManager *wm, float value)
191{
192 if (wm_progress_state.is_valid) {
193 /* Map to cursor_time range [0,9999] */
194 wmWindow *win = wm->winactive;
195 if (win) {
196 int val = int(10000 * (value - wm_progress_state.min) /
197 (wm_progress_state.max - wm_progress_state.min));
198 WM_cursor_time(win, val);
199 }
200 }
201}
202
203static void rna_progress_end(wmWindowManager *wm)
204{
205 if (wm_progress_state.is_valid) {
206 wmWindow *win = wm->winactive;
207 if (win) {
209 wm_progress_state.is_valid = false;
210 }
211 }
212}
213
214/* wrap these because of 'const wmEvent *' */
215static int rna_Operator_confirm(bContext *C,
216 wmOperator *op,
217 wmEvent * /*event*/,
218 const char *title,
219 const char *message,
220 const char *confirm_text,
221 const int icon,
222 const char *text_ctxt,
223 const bool translate)
224{
225 title = RNA_translate_ui_text(title, text_ctxt, nullptr, nullptr, translate);
226 message = RNA_translate_ui_text(message, text_ctxt, nullptr, nullptr, translate);
227 confirm_text = RNA_translate_ui_text(confirm_text, text_ctxt, nullptr, nullptr, translate);
228 return WM_operator_confirm_ex(C, op, title, message, confirm_text, icon);
229}
230
231static int rna_Operator_props_popup(bContext *C, wmOperator *op, wmEvent *event)
232{
233 return WM_operator_props_popup(C, op, event);
234}
235
236static int rna_Operator_props_dialog_popup(bContext *C,
237 wmOperator *op,
238 const int width,
239 const char *title,
240 const char *confirm_text,
241 const bool cancel_default,
242 const char *text_ctxt,
243 const bool translate)
244{
245 title = RNA_translate_ui_text(title, text_ctxt, nullptr, nullptr, translate);
246 confirm_text = RNA_translate_ui_text(confirm_text, text_ctxt, nullptr, nullptr, translate);
248 C,
249 op,
250 width,
251 title ? std::make_optional<std::string>(title) : std::nullopt,
252 confirm_text ? std::make_optional<std::string>(confirm_text) : std::nullopt,
253 cancel_default);
254}
255
256static int keymap_item_modifier_flag_from_args(bool any, int shift, int ctrl, int alt, int oskey)
257{
258 int modifier = 0;
259 if (any) {
260 modifier = KM_ANY;
261 }
262 else {
263 if (shift == KM_MOD_HELD) {
264 modifier |= KM_SHIFT;
265 }
266 else if (shift == KM_ANY) {
267 modifier |= KM_SHIFT_ANY;
268 }
269
270 if (ctrl == KM_MOD_HELD) {
271 modifier |= KM_CTRL;
272 }
273 else if (ctrl == KM_ANY) {
274 modifier |= KM_CTRL_ANY;
275 }
276
277 if (alt == KM_MOD_HELD) {
278 modifier |= KM_ALT;
279 }
280 else if (alt == KM_ANY) {
281 modifier |= KM_ALT_ANY;
282 }
283
284 if (oskey == KM_MOD_HELD) {
285 modifier |= KM_OSKEY;
286 }
287 else if (oskey == KM_ANY) {
288 modifier |= KM_OSKEY_ANY;
289 }
290 }
291 return modifier;
292}
293
294static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km,
295 ReportList *reports,
296 const char *idname,
297 int type,
298 int value,
299 bool any,
300 int shift,
301 int ctrl,
302 int alt,
303 int oskey,
304 int keymodifier,
305 int direction,
306 bool repeat,
307 bool head)
308{
309 /* only on non-modal maps */
310 if (km->flag & KEYMAP_MODAL) {
311 BKE_report(reports, RPT_ERROR, "Not a non-modal keymap");
312 return nullptr;
313 }
314
315 // wmWindowManager *wm = CTX_wm_manager(C);
316 wmKeyMapItem *kmi = nullptr;
317 char idname_bl[OP_MAX_TYPENAME];
318 const int modifier = keymap_item_modifier_flag_from_args(any, shift, ctrl, alt, oskey);
319
320 WM_operator_bl_idname(idname_bl, idname);
321
322 KeyMapItem_Params keymap_item_params{};
323 keymap_item_params.type = type;
324 keymap_item_params.value = value;
325 keymap_item_params.modifier = modifier;
326 keymap_item_params.keymodifier = keymodifier;
327 keymap_item_params.direction = direction;
328
329 /* create keymap item */
330 kmi = WM_keymap_add_item(km, idname_bl, &keymap_item_params);
331
332 if (!repeat) {
333 kmi->flag |= KMI_REPEAT_IGNORE;
334 }
335
336 /* #32437 allow scripts to define hotkeys that get added to start of keymap
337 * so that they stand a chance against catch-all defines later on
338 */
339 if (head) {
340 BLI_remlink(&km->items, kmi);
341 BLI_addhead(&km->items, kmi);
342 }
343
344 return kmi;
345}
346
347static wmKeyMapItem *rna_KeyMap_item_new_from_item(wmKeyMap *km,
348 ReportList *reports,
349 wmKeyMapItem *kmi_src,
350 bool head)
351{
352 // wmWindowManager *wm = CTX_wm_manager(C);
353
354 if ((km->flag & KEYMAP_MODAL) == (kmi_src->idname[0] != '\0')) {
355 BKE_report(reports, RPT_ERROR, "Cannot mix modal/non-modal items");
356 return nullptr;
357 }
358
359 /* create keymap item */
360 wmKeyMapItem *kmi = WM_keymap_add_item_copy(km, kmi_src);
361 if (head) {
362 BLI_remlink(&km->items, kmi);
363 BLI_addhead(&km->items, kmi);
364 }
365 return kmi;
366}
367
368static wmKeyMapItem *rna_KeyMap_item_new_modal(wmKeyMap *km,
369 ReportList *reports,
370 const char *propvalue_str,
371 int type,
372 int value,
373 bool any,
374 int shift,
375 int ctrl,
376 int alt,
377 int oskey,
378 int keymodifier,
379 int direction,
380 bool repeat)
381{
382 /* only modal maps */
383 if ((km->flag & KEYMAP_MODAL) == 0) {
384 BKE_report(reports, RPT_ERROR, "Not a modal keymap");
385 return nullptr;
386 }
387
388 wmKeyMapItem *kmi = nullptr;
389 const int modifier = keymap_item_modifier_flag_from_args(any, shift, ctrl, alt, oskey);
390 int propvalue = 0;
391
393 params.type = type;
394 params.value = value;
395 params.modifier = modifier;
396 params.keymodifier = keymodifier;
397 params.direction = direction;
398
399 /* not initialized yet, do delayed lookup */
400 if (!km->modal_items) {
401 kmi = WM_modalkeymap_add_item_str(km, &params, propvalue_str);
402 }
403 else {
404 if (RNA_enum_value_from_id(static_cast<const EnumPropertyItem *>(km->modal_items),
405 propvalue_str,
406 &propvalue) == 0)
407 {
408 BKE_report(reports, RPT_WARNING, "Property value not in enumeration");
409 }
410 kmi = WM_modalkeymap_add_item(km, &params, propvalue);
411 }
412
413 if (!repeat) {
414 kmi->flag |= KMI_REPEAT_IGNORE;
415 }
416
417 return kmi;
418}
419
420static void rna_KeyMap_item_remove(wmKeyMap *km, ReportList *reports, PointerRNA *kmi_ptr)
421{
422 wmKeyMapItem *kmi = static_cast<wmKeyMapItem *>(kmi_ptr->data);
423
424 if (UNLIKELY(BLI_findindex(&km->items, kmi) == -1)) {
426 reports, RPT_ERROR, "KeyMapItem '%s' not found in KeyMap '%s'", kmi->idname, km->idname);
427 return;
428 }
429
430 WM_keymap_remove_item(km, kmi);
431 RNA_POINTER_INVALIDATE(kmi_ptr);
432}
433
434static PointerRNA rna_KeyMap_item_find_from_operator(ID *id,
435 wmKeyMap *km,
436 const char *idname,
437 PointerRNA *properties,
438 int include_mask,
439 int exclude_mask)
440{
441 char idname_bl[OP_MAX_TYPENAME];
442 WM_operator_bl_idname(idname_bl, idname);
443
445 km, idname_bl, static_cast<IDProperty *>(properties->data), include_mask, exclude_mask);
446 PointerRNA kmi_ptr = RNA_pointer_create(id, &RNA_KeyMapItem, kmi);
447 return kmi_ptr;
448}
449
450static PointerRNA rna_KeyMap_item_match_event(ID *id, wmKeyMap *km, bContext *C, wmEvent *event)
451{
452 wmKeyMapItem *kmi = WM_event_match_keymap_item(C, km, event);
453 PointerRNA kmi_ptr = RNA_pointer_create(id, &RNA_KeyMapItem, kmi);
454 return kmi_ptr;
455}
456
457static wmKeyMap *rna_KeyMaps_new(wmKeyConfig *keyconf,
458 ReportList *reports,
459 const char *idname,
460 int spaceid,
461 int regionid,
462 bool modal,
463 bool tool)
464{
465 if (modal) {
466 /* Sanity check: Don't allow add-ons to override internal modal key-maps
467 * because this isn't supported, the restriction can be removed when
468 * add-ons can define modal key-maps.
469 * Currently this is only useful for add-ons to override built-in modal keymaps
470 * which is not the intended use for add-on keymaps. */
471 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
472 if (keyconf == wm->addonconf) {
473 BKE_reportf(reports, RPT_ERROR, "Modal key-maps not supported for add-on key-config");
474 return nullptr;
475 }
476 }
477
478 wmKeyMap *keymap;
479
480 if (modal == 0) {
481 keymap = WM_keymap_ensure(keyconf, idname, spaceid, regionid);
482 }
483 else {
484 keymap = WM_modalkeymap_ensure(keyconf, idname, nullptr); /* items will be lazy init */
485 }
486
487 if (keymap && tool) {
488 keymap->flag |= KEYMAP_TOOL;
489 }
490
491 return keymap;
492}
493
494static wmKeyMap *rna_KeyMaps_find(wmKeyConfig *keyconf,
495 const char *idname,
496 int spaceid,
497 int regionid)
498{
499 return WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
500}
501
502static wmKeyMap *rna_KeyMaps_find_modal(wmKeyConfig * /*keyconf*/, const char *idname)
503{
505
506 if (!ot) {
507 return nullptr;
508 }
509 else {
510 return ot->modalkeymap;
511 }
512}
513
514static void rna_KeyMaps_remove(wmKeyConfig *keyconfig, ReportList *reports, PointerRNA *keymap_ptr)
515{
516 wmKeyMap *keymap = static_cast<wmKeyMap *>(keymap_ptr->data);
517
518 if (UNLIKELY(BLI_findindex(&keyconfig->keymaps, keymap) == -1)) {
519 BKE_reportf(reports,
520 RPT_ERROR,
521 "KeyMap '%s' not found in KeyConfig '%s'",
522 keymap->idname,
523 keyconfig->idname);
524 return;
525 }
526
527 WM_keymap_remove(keyconfig, keymap);
528 RNA_POINTER_INVALIDATE(keymap_ptr);
529}
530
531static void rna_KeyMaps_clear(wmKeyConfig *keyconfig)
532{
533 WM_keyconfig_clear(keyconfig);
534}
535
536wmKeyConfig *rna_KeyConfig_new(wmWindowManager *wm, const char *idname)
537{
538 return WM_keyconfig_ensure(wm, idname, true);
539}
540
541static void rna_KeyConfig_remove(wmWindowManager *wm, ReportList *reports, PointerRNA *keyconf_ptr)
542{
543 wmKeyConfig *keyconf = static_cast<wmKeyConfig *>(keyconf_ptr->data);
544 if (UNLIKELY(BLI_findindex(&wm->keyconfigs, keyconf) == -1)) {
545 BKE_reportf(reports, RPT_ERROR, "KeyConfig '%s' cannot be removed", keyconf->idname);
546 return;
547 }
548 WM_keyconfig_remove(wm, keyconf);
549 RNA_POINTER_INVALIDATE(keyconf_ptr);
550}
551
552static PointerRNA rna_KeyConfig_find_item_from_operator(wmWindowManager *wm,
553 bContext *C,
554 const char *idname,
555 int opcontext,
556 PointerRNA *properties,
557 int include_mask,
558 int exclude_mask,
559 PointerRNA *km_ptr)
560{
561 char idname_bl[OP_MAX_TYPENAME];
562 WM_operator_bl_idname(idname_bl, idname);
563
564 wmKeyMap *km = nullptr;
566 idname_bl,
567 wmOperatorCallContext(opcontext),
568 static_cast<IDProperty *>(properties->data),
569 include_mask,
570 exclude_mask,
571 &km);
572 *km_ptr = RNA_pointer_create(&wm->id, &RNA_KeyMap, km);
573 PointerRNA kmi_ptr = RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi);
574 return kmi_ptr;
575}
576
577static void rna_KeyConfig_update(wmWindowManager *wm, bool keep_properties)
578{
579 WM_keyconfig_update_ex(wm, keep_properties);
580}
581
583static bool rna_popup_context_ok_or_report(bContext *C, ReportList *reports)
584{
585 if (CTX_wm_window(C) == nullptr) {
586 BKE_report(reports, RPT_ERROR, "context \"window\" is None");
587 return false;
588 }
589 return true;
590}
591
592/* popup menu wrapper */
593static PointerRNA rna_PopMenuBegin(bContext *C,
594 ReportList *reports,
595 const char *title,
596 const int icon)
597{
598 if (!rna_popup_context_ok_or_report(C, reports)) {
599 return PointerRNA_NULL;
600 }
601
602 void *data = (void *)UI_popup_menu_begin(C, title, icon);
603 PointerRNA r_ptr = RNA_pointer_create(nullptr, &RNA_UIPopupMenu, data);
604 return r_ptr;
605}
606
607static void rna_PopMenuEnd(bContext *C, PointerRNA *handle)
608{
609 UI_popup_menu_end(C, static_cast<uiPopupMenu *>(handle->data));
610}
611
612/* popover wrapper */
613static PointerRNA rna_PopoverBegin(bContext *C,
614 ReportList *reports,
615 const int ui_units_x,
616 const bool from_active_button)
617{
618 if (!rna_popup_context_ok_or_report(C, reports)) {
619 return PointerRNA_NULL;
620 }
621
622 void *data = (void *)UI_popover_begin(C, U.widget_unit * ui_units_x, from_active_button);
623 PointerRNA r_ptr = RNA_pointer_create(nullptr, &RNA_UIPopover, data);
624 return r_ptr;
625}
626
627static void rna_PopoverEnd(bContext *C, PointerRNA *handle, wmKeyMap *keymap)
628{
629 UI_popover_end(C, static_cast<uiPopover *>(handle->data), keymap);
630}
631
632/* pie menu wrapper */
633static PointerRNA rna_PieMenuBegin(
634 bContext *C, ReportList *reports, const char *title, const int icon, PointerRNA *event)
635{
636 if (!rna_popup_context_ok_or_report(C, reports)) {
637 return PointerRNA_NULL;
638 }
639
640 void *data = (void *)UI_pie_menu_begin(
641 C, title, icon, static_cast<const wmEvent *>(event->data));
642
643 PointerRNA r_ptr = RNA_pointer_create(nullptr, &RNA_UIPieMenu, data);
644 return r_ptr;
645}
646
647static void rna_PieMenuEnd(bContext *C, PointerRNA *handle)
648{
649 UI_pie_menu_end(C, static_cast<uiPieMenu *>(handle->data));
650}
651
652static void rna_WindowManager_print_undo_steps(wmWindowManager *wm)
653{
655}
656
657static void rna_WindowManager_tag_script_reload()
658{
661}
662
663static PointerRNA rna_WindoManager_operator_properties_last(const char *idname)
664{
665 wmOperatorType *ot = WM_operatortype_find(idname, true);
666
667 if (ot != nullptr) {
670 return ptr;
671 }
672 return PointerRNA_NULL;
673}
674
675static wmEvent *rna_Window_event_add_simulate(wmWindow *win,
676 ReportList *reports,
677 int type,
678 int value,
679 const char *unicode,
680 int x,
681 int y,
682 bool shift,
683 bool ctrl,
684 bool alt,
685 bool oskey)
686{
687 if ((G.f & G_FLAG_EVENT_SIMULATE) == 0) {
688 BKE_report(reports, RPT_ERROR, "Not running with '--enable-event-simulate' enabled");
689 return nullptr;
690 }
691
692 if (!ELEM(value, KM_PRESS, KM_RELEASE, KM_NOTHING)) {
693 BKE_report(reports, RPT_ERROR, "Value: only 'PRESS/RELEASE/NOTHING' are supported");
694 return nullptr;
695 }
696 if (ISKEYBOARD(type) || ISMOUSE_BUTTON(type)) {
697 if (!ELEM(value, KM_PRESS, KM_RELEASE)) {
698 BKE_report(reports, RPT_ERROR, "Value: must be 'PRESS/RELEASE' for keyboard/buttons");
699 return nullptr;
700 }
701 }
702 if (ISMOUSE_MOTION(type)) {
703 if (value != KM_NOTHING) {
704 BKE_report(reports, RPT_ERROR, "Value: must be 'NOTHING' for motion");
705 return nullptr;
706 }
707 }
708 if (unicode != nullptr) {
709 if (value != KM_PRESS) {
710 BKE_report(reports, RPT_ERROR, "Value: must be 'PRESS' when unicode is set");
711 return nullptr;
712 }
713 }
714 /* TODO: validate NDOF. */
715
716 if (unicode != nullptr) {
717 int len = BLI_str_utf8_size_or_error(unicode);
718 if (len == -1 || unicode[len] != '\0') {
719 BKE_report(reports, RPT_ERROR, "Only a single character supported");
720 return nullptr;
721 }
722 }
723
724 wmEvent e = *win->eventstate;
725 e.type = type;
726 e.val = value;
727 e.flag = eWM_EventFlag(0);
728 e.xy[0] = x;
729 e.xy[1] = y;
730
731 e.modifier = 0;
732 if (shift) {
733 e.modifier |= KM_SHIFT;
734 }
735 if (ctrl) {
736 e.modifier |= KM_CTRL;
737 }
738 if (alt) {
739 e.modifier |= KM_ALT;
740 }
741 if (oskey) {
742 e.modifier |= KM_OSKEY;
743 }
744
745 e.utf8_buf[0] = '\0';
746 if (unicode != nullptr) {
747 STRNCPY(e.utf8_buf, unicode);
748 }
749
750 /* Until we expose setting tablet values here. */
752
753 return WM_event_add_simulate(win, &e);
754}
755
756#else
757
758# define WM_GEN_INVOKE_EVENT (1 << 0)
759# define WM_GEN_INVOKE_SIZE (1 << 1)
760# define WM_GEN_INVOKE_RETURN (1 << 2)
761
763{
764 PropertyRNA *parm;
765
767 parm = RNA_def_pointer(func, "operator", "Operator", "", "Operator to call");
769
771 parm = RNA_def_pointer(func, "event", "Event", "", "Event");
773 }
774
775 if (flag & WM_GEN_INVOKE_SIZE) {
776 RNA_def_int(func, "width", 300, 0, INT_MAX, "", "Width of the popup", 0, INT_MAX);
777 }
778
780 parm = RNA_def_enum_flag(
781 func, "result", rna_enum_operator_return_items, OPERATOR_FINISHED, "result", "");
782 RNA_def_function_return(func, parm);
783 }
784}
785
787{
788 FunctionRNA *func;
789 PropertyRNA *parm;
790
791 func = RNA_def_function(srna, "cursor_warp", "WM_cursor_warp");
792 parm = RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "", "", INT_MIN, INT_MAX);
794 parm = RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "", "", INT_MIN, INT_MAX);
796 RNA_def_function_ui_description(func, "Set the cursor position");
797
798 func = RNA_def_function(srna, "cursor_set", "WM_cursor_set");
799 parm = RNA_def_property(func, "cursor", PROP_ENUM, PROP_NONE);
802 RNA_def_function_ui_description(func, "Set the cursor");
803
804 func = RNA_def_function(srna, "cursor_modal_set", "WM_cursor_modal_set");
805 parm = RNA_def_property(func, "cursor", PROP_ENUM, PROP_NONE);
808 RNA_def_function_ui_description(func, "Set the cursor, so the previous cursor can be restored");
809
810 RNA_def_function(srna, "cursor_modal_restore", "WM_cursor_modal_restore");
812 func, "Restore the previous cursor after calling ``cursor_modal_set``");
813
814 /* Arguments match 'rna_KeyMap_item_new'. */
815 func = RNA_def_function(srna, "event_simulate", "rna_Window_event_add_simulate");
817 parm = RNA_def_enum(func, "type", rna_enum_event_type_items, 0, "Type", "");
819 parm = RNA_def_enum(func, "value", rna_enum_event_value_items, 0, "Value", "");
821 parm = RNA_def_string(func, "unicode", nullptr, 0, "", "");
823
824 RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "", "", INT_MIN, INT_MAX);
825 RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "", "", INT_MIN, INT_MAX);
826
827 RNA_def_boolean(func, "shift", false, "Shift", "");
828 RNA_def_boolean(func, "ctrl", false, "Ctrl", "");
829 RNA_def_boolean(func, "alt", false, "Alt", "");
830 RNA_def_boolean(func, "oskey", false, "OS Key", "");
831 parm = RNA_def_pointer(func, "event", "Event", "Item", "Added key map item");
832 RNA_def_function_return(func, parm);
833}
834
836 {ALERT_ICON_NONE, "NONE", 0, "None", ""},
837 {ALERT_ICON_WARNING, "WARNING", 0, "Warning", ""},
838 {ALERT_ICON_QUESTION, "QUESTION", 0, "Question", ""},
839 {ALERT_ICON_ERROR, "ERROR", 0, "Error", ""},
840 {ALERT_ICON_INFO, "INFO", 0, "Info", ""},
841 {0, nullptr, 0, nullptr, nullptr},
842};
843
845{
846 FunctionRNA *func;
847 PropertyRNA *parm;
848
849 func = RNA_def_function(srna, "fileselect_add", "WM_event_add_fileselect");
851 func,
852 "Opens a file selector with an operator. "
853 "The string properties 'filepath', 'filename', 'directory' and a 'files' "
854 "collection are assigned when present in the operator.");
855 rna_generic_op_invoke(func, 0);
856
857 func = RNA_def_function(srna, "modal_handler_add", "rna_event_modal_handler_add");
859 func,
860 "Add a modal handler to the window manager, for the given modal operator "
861 "(called by invoke() with self, just before returning {'RUNNING_MODAL'})");
863 parm = RNA_def_pointer(func, "operator", "Operator", "", "Operator to call");
866 func,
867 RNA_def_boolean(func, "handle", true, "", "Whether adding the handler was successful"));
868
869 func = RNA_def_function(srna, "event_timer_add", "rna_event_timer_add");
871 func, "Add a timer to the given window, to generate periodic 'TIMER' events");
872 parm = RNA_def_property(func, "time_step", PROP_FLOAT, PROP_NONE);
875 RNA_def_property_ui_text(parm, "Time Step", "Interval in seconds between timer events");
876 RNA_def_pointer(func, "window", "Window", "", "Window to attach the timer to, or None");
877 parm = RNA_def_pointer(func, "result", "Timer", "", "");
878 RNA_def_function_return(func, parm);
879
880 func = RNA_def_function(srna, "event_timer_remove", "rna_event_timer_remove");
881 parm = RNA_def_pointer(func, "timer", "Timer", "", "");
883
884 func = RNA_def_function(srna, "gizmo_group_type_ensure", "rna_gizmo_group_type_ensure");
886 func, "Activate an existing widget group (when the persistent option isn't set)");
888 parm = RNA_def_string(func, "identifier", nullptr, 0, "", "Gizmo group type name");
890
891 func = RNA_def_function(
892 srna, "gizmo_group_type_unlink_delayed", "rna_gizmo_group_type_unlink_delayed");
894 "Unlink a widget group (when the persistent option is set)");
896 parm = RNA_def_string(func, "identifier", nullptr, 0, "", "Gizmo group type name");
898
899 /* Progress bar interface */
900 func = RNA_def_function(srna, "progress_begin", "rna_progress_begin");
901 RNA_def_function_ui_description(func, "Start progress report");
902 parm = RNA_def_property(func, "min", PROP_FLOAT, PROP_NONE);
903 RNA_def_property_ui_text(parm, "min", "any value in range [0,9999]");
905 parm = RNA_def_property(func, "max", PROP_FLOAT, PROP_NONE);
907 RNA_def_property_ui_text(parm, "max", "any value in range [min+1,9998]");
908
909 func = RNA_def_function(srna, "progress_update", "rna_progress_update");
910 RNA_def_function_ui_description(func, "Update the progress feedback");
911 parm = RNA_def_property(func, "value", PROP_FLOAT, PROP_NONE);
914 parm, "value", "Any value between min and max as set in progress_begin()");
915
916 func = RNA_def_function(srna, "progress_end", "rna_progress_end");
917 RNA_def_function_ui_description(func, "Terminate progress report");
918
919 /* invoke functions, for use with python */
920 func = RNA_def_function(srna, "invoke_props_popup", "rna_Operator_props_popup");
922 func,
923 "Operator popup invoke "
924 "(show operator properties and execute it automatically on changes)");
926
927 /* invoked dialog opens popup with OK button, does not auto-exec operator. */
928 func = RNA_def_function(srna, "invoke_props_dialog", "rna_Operator_props_dialog_popup");
930 func,
931 "Operator dialog (non-autoexec popup) invoke "
932 "(show operator properties and only execute it on click on OK button)");
934
935 parm = RNA_def_property(func, "title", PROP_STRING, PROP_NONE);
936 RNA_def_property_ui_text(parm, "Title", "Optional text to show as title of the popup");
937 parm = RNA_def_property(func, "confirm_text", PROP_STRING, PROP_NONE);
939 parm,
940 "Confirm Text",
941 "Optional text to show instead to the default \"OK\" confirmation button text");
942 RNA_def_property(func, "cancel_default", PROP_BOOLEAN, PROP_NONE);
944
945 /* invoke enum */
946 func = RNA_def_function(srna, "invoke_search_popup", "rna_Operator_enum_search_invoke");
948 func,
949 "Operator search popup invoke which "
950 "searches values of the operator's :class:`bpy.types.Operator.bl_property` "
951 "(which must be an EnumProperty), executing it on confirmation");
952 rna_generic_op_invoke(func, 0);
953
954 /* invoke functions, for use with python */
955 func = RNA_def_function(srna, "invoke_popup", "WM_operator_ui_popup");
957 "Operator popup invoke "
958 "(only shows operator's properties, without executing it)");
960
961 func = RNA_def_function(srna, "invoke_confirm", "rna_Operator_confirm");
963 func,
964 "Operator confirmation popup "
965 "(only to let user confirm the execution, no operator properties shown)");
967
968 parm = RNA_def_property(func, "title", PROP_STRING, PROP_NONE);
969 RNA_def_property_ui_text(parm, "Title", "Optional text to show as title of the popup");
970
971 parm = RNA_def_property(func, "message", PROP_STRING, PROP_NONE);
972 RNA_def_property_ui_text(parm, "Message", "Optional first line of content text");
973
974 parm = RNA_def_property(func, "confirm_text", PROP_STRING, PROP_NONE);
976 parm,
977 "Confirm Text",
978 "Optional text to show instead to the default \"OK\" confirmation button text");
979
980 parm = RNA_def_property(func, "icon", PROP_ENUM, PROP_NONE);
983 RNA_def_property_ui_text(parm, "Icon", "Optional icon displayed in the dialog");
984
986
987 /* wrap UI_popup_menu_begin */
988 func = RNA_def_function(srna, "popmenu_begin__internal", "rna_PopMenuBegin");
990 parm = RNA_def_string(func, "title", nullptr, 0, "", "");
992 parm = RNA_def_property(func, "icon", PROP_ENUM, PROP_NONE);
994 /* return */
995 parm = RNA_def_pointer(func, "menu", "UIPopupMenu", "", "");
997 RNA_def_function_return(func, parm);
998
999 /* wrap UI_popup_menu_end */
1000 func = RNA_def_function(srna, "popmenu_end__internal", "rna_PopMenuEnd");
1002 parm = RNA_def_pointer(func, "menu", "UIPopupMenu", "", "");
1004
1005 /* wrap UI_popover_begin */
1006 func = RNA_def_function(srna, "popover_begin__internal", "rna_PopoverBegin");
1008 RNA_def_property(func, "ui_units_x", PROP_INT, PROP_UNSIGNED);
1009 /* return */
1010 parm = RNA_def_pointer(func, "menu", "UIPopover", "", "");
1012 RNA_def_function_return(func, parm);
1014 func, "from_active_button", false, "Use Button", "Use the active button for positioning");
1015
1016 /* wrap UI_popover_end */
1017 func = RNA_def_function(srna, "popover_end__internal", "rna_PopoverEnd");
1019 parm = RNA_def_pointer(func, "menu", "UIPopover", "", "");
1021 RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Active key map");
1022
1023 /* wrap uiPieMenuBegin */
1024 func = RNA_def_function(srna, "piemenu_begin__internal", "rna_PieMenuBegin");
1026 parm = RNA_def_string(func, "title", nullptr, 0, "", "");
1028 parm = RNA_def_property(func, "icon", PROP_ENUM, PROP_NONE);
1030 parm = RNA_def_pointer(func, "event", "Event", "", "");
1032 /* return */
1033 parm = RNA_def_pointer(func, "menu_pie", "UIPieMenu", "", "");
1035 RNA_def_function_return(func, parm);
1036
1037 /* wrap uiPieMenuEnd */
1038 func = RNA_def_function(srna, "piemenu_end__internal", "rna_PieMenuEnd");
1040 parm = RNA_def_pointer(func, "menu", "UIPieMenu", "", "");
1042
1043 /* access last operator options (optionally create). */
1044 func = RNA_def_function(
1045 srna, "operator_properties_last", "rna_WindoManager_operator_properties_last");
1047 parm = RNA_def_string(func, "operator", nullptr, 0, "", "");
1049 /* return */
1050 parm = RNA_def_pointer(func, "result", "OperatorProperties", "", "");
1052 RNA_def_function_return(func, parm);
1053
1054 RNA_def_function(srna, "print_undo_steps", "rna_WindowManager_print_undo_steps");
1055
1056 /* Used by (#SCRIPT_OT_reload). */
1057 func = RNA_def_function(srna, "tag_script_reload", "rna_WindowManager_tag_script_reload");
1059 func, "Tag for refreshing the interface after scripts have been reloaded");
1061
1062 parm = RNA_def_property(srna, "is_interface_locked", PROP_BOOLEAN, PROP_NONE);
1063 RNA_def_property_boolean_sdna(parm, nullptr, "runtime->is_interface_locked", 0);
1065 parm,
1066 "Is Interface Locked",
1067 "If true, the interface is currently locked by a running job and data shouldn't be modified "
1068 "from application timers. Otherwise, the running job might conflict with the handler "
1069 "causing unexpected results or even crashes.");
1071}
1072
1074{
1075 FunctionRNA *func;
1076 PropertyRNA *parm;
1077
1078 /* utility, not for registering */
1079 func = RNA_def_function(srna, "report", "rna_Operator_report");
1080 parm = RNA_def_enum_flag(func, "type", rna_enum_wm_report_items, 0, "Type", "");
1082 parm = RNA_def_string(func, "message", nullptr, 0, "Report Message", "");
1084
1085 /* utility, not for registering */
1086 func = RNA_def_function(srna, "is_repeat", "rna_Operator_is_repeat");
1088 /* return */
1089 parm = RNA_def_boolean(func, "result", false, "result", "");
1090 RNA_def_function_return(func, parm);
1091
1092 /* Registration */
1093
1094 /* poll */
1095 func = RNA_def_function(srna, "poll", nullptr);
1096 RNA_def_function_ui_description(func, "Test if the operator can be called or not");
1098 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
1099 parm = RNA_def_pointer(func, "context", "Context", "", "");
1101
1102 /* exec */
1103 func = RNA_def_function(srna, "execute", nullptr);
1104 RNA_def_function_ui_description(func, "Execute the operator");
1106 parm = RNA_def_pointer(func, "context", "Context", "", "");
1108
1109 /* better name? */
1110 parm = RNA_def_enum_flag(
1111 func, "result", rna_enum_operator_return_items, OPERATOR_FINISHED, "result", "");
1112 RNA_def_function_return(func, parm);
1113
1114 /* check */
1115 func = RNA_def_function(srna, "check", nullptr);
1117 func, "Check the operator settings, return True to signal a change to redraw");
1119 parm = RNA_def_pointer(func, "context", "Context", "", "");
1121
1122 parm = RNA_def_boolean(func, "result", false, "result", ""); /* better name? */
1123 RNA_def_function_return(func, parm);
1124
1125 /* invoke */
1126 func = RNA_def_function(srna, "invoke", nullptr);
1127 RNA_def_function_ui_description(func, "Invoke the operator");
1129 parm = RNA_def_pointer(func, "context", "Context", "", "");
1131 parm = RNA_def_pointer(func, "event", "Event", "", "");
1133
1134 /* better name? */
1135 parm = RNA_def_enum_flag(
1136 func, "result", rna_enum_operator_return_items, OPERATOR_FINISHED, "result", "");
1137 RNA_def_function_return(func, parm);
1138
1139 func = RNA_def_function(srna, "modal", nullptr); /* same as invoke */
1140 RNA_def_function_ui_description(func, "Modal operator function");
1142 parm = RNA_def_pointer(func, "context", "Context", "", "");
1144 parm = RNA_def_pointer(func, "event", "Event", "", "");
1146
1147 /* better name? */
1148 parm = RNA_def_enum_flag(
1149 func, "result", rna_enum_operator_return_items, OPERATOR_FINISHED, "result", "");
1150 RNA_def_function_return(func, parm);
1151
1152 /* draw */
1153 func = RNA_def_function(srna, "draw", nullptr);
1154 RNA_def_function_ui_description(func, "Draw function for the operator");
1156 parm = RNA_def_pointer(func, "context", "Context", "", "");
1158
1159 /* cancel */
1160 func = RNA_def_function(srna, "cancel", nullptr);
1161 RNA_def_function_ui_description(func, "Called when the operator is canceled");
1163 parm = RNA_def_pointer(func, "context", "Context", "", "");
1165
1166 /* description */
1167 func = RNA_def_function(srna, "description", nullptr);
1168 RNA_def_function_ui_description(func, "Compute a description string that depends on parameters");
1170 parm = RNA_def_string(func, "result", nullptr, 4096, "result", "");
1173 RNA_def_function_output(func, parm);
1174 parm = RNA_def_pointer(func, "context", "Context", "", "");
1176 parm = RNA_def_pointer(func, "properties", "OperatorProperties", "", "");
1178}
1179
1181{
1182 FunctionRNA *func;
1183 PropertyRNA *parm;
1184
1185 /* utility, not for registering */
1186 func = RNA_def_function(srna, "report", "rna_Operator_report");
1187 parm = RNA_def_enum_flag(func, "type", rna_enum_wm_report_items, 0, "Type", "");
1189 parm = RNA_def_string(func, "message", nullptr, 0, "Report Message", "");
1191
1192 /* Registration */
1193
1194 /* poll */
1195 func = RNA_def_function(srna, "poll", nullptr);
1196 RNA_def_function_ui_description(func, "Test if the operator can be called or not");
1198 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
1199 parm = RNA_def_pointer(func, "context", "Context", "", "");
1201
1202 /* draw */
1203 func = RNA_def_function(srna, "draw", nullptr);
1204 RNA_def_function_ui_description(func, "Draw function for the operator");
1206 parm = RNA_def_pointer(func, "context", "Context", "", "");
1208}
1209
1211{
1212 // FunctionRNA *func;
1213 // PropertyRNA *parm;
1214}
1215
1217{
1218 FunctionRNA *func;
1219 PropertyRNA *parm;
1220
1221 func = RNA_def_function(srna, "active", "rna_keymap_active");
1223 parm = RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Active key map");
1224 RNA_def_function_return(func, parm);
1225
1226 func = RNA_def_function(srna, "restore_to_default", "rna_keymap_restore_to_default");
1228
1229 func = RNA_def_function(srna, "restore_item_to_default", "rna_keymap_restore_item_to_default");
1231 parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
1233}
1234
1236{
1237 FunctionRNA *func;
1238 PropertyRNA *parm;
1239
1240 func = RNA_def_function(srna, "compare", "rna_KeyMapItem_compare");
1241 parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
1243 parm = RNA_def_boolean(func, "result", false, "Comparison result", "");
1244 RNA_def_function_return(func, parm);
1245
1246 func = RNA_def_function(srna, "to_string", "rna_KeyMapItem_to_string");
1247 RNA_def_boolean(func, "compact", false, "Compact", "");
1248 parm = RNA_def_string(func, "result", nullptr, UI_MAX_SHORTCUT_STR, "result", "");
1250 RNA_def_function_output(func, parm);
1251}
1252
1254{
1255 FunctionRNA *func;
1256 PropertyRNA *parm;
1257
1258 func = RNA_def_function(srna, "new", "rna_KeyMap_item_new");
1260 parm = RNA_def_string(func, "idname", nullptr, 0, "Operator Identifier", "");
1262 parm = RNA_def_enum(func, "type", rna_enum_event_type_items, 0, "Type", "");
1264 parm = RNA_def_enum(func, "value", rna_enum_event_value_items, 0, "Value", "");
1266 RNA_def_boolean(func, "any", false, "Any", "");
1267 RNA_def_int(func, "shift", KM_NOTHING, KM_ANY, KM_MOD_HELD, "Shift", "", KM_ANY, KM_MOD_HELD);
1268 RNA_def_int(func, "ctrl", KM_NOTHING, KM_ANY, KM_MOD_HELD, "Ctrl", "", KM_ANY, KM_MOD_HELD);
1269 RNA_def_int(func, "alt", KM_NOTHING, KM_ANY, KM_MOD_HELD, "Alt", "", KM_ANY, KM_MOD_HELD);
1270 RNA_def_int(func, "oskey", KM_NOTHING, KM_ANY, KM_MOD_HELD, "OS Key", "", KM_ANY, KM_MOD_HELD);
1271 RNA_def_enum(func, "key_modifier", rna_enum_event_type_items, 0, "Key Modifier", "");
1272 RNA_def_enum(func, "direction", rna_enum_event_direction_items, KM_ANY, "Direction", "");
1273 RNA_def_boolean(func, "repeat", false, "Repeat", "When set, accept key-repeat events");
1274 RNA_def_boolean(func,
1275 "head",
1276 false,
1277 "At Head",
1278 "Force item to be added at start (not end) of key map so that "
1279 "it doesn't get blocked by an existing key map item");
1280 parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item");
1281 RNA_def_function_return(func, parm);
1282
1283 func = RNA_def_function(srna, "new_modal", "rna_KeyMap_item_new_modal");
1285 parm = RNA_def_string(func, "propvalue", nullptr, 0, "Property Value", "");
1287 parm = RNA_def_enum(func, "type", rna_enum_event_type_items, 0, "Type", "");
1289 parm = RNA_def_enum(func, "value", rna_enum_event_value_items, 0, "Value", "");
1291 RNA_def_boolean(func, "any", false, "Any", "");
1292 RNA_def_int(func, "shift", KM_NOTHING, KM_ANY, KM_MOD_HELD, "Shift", "", KM_ANY, KM_MOD_HELD);
1293 RNA_def_int(func, "ctrl", KM_NOTHING, KM_ANY, KM_MOD_HELD, "Ctrl", "", KM_ANY, KM_MOD_HELD);
1294 RNA_def_int(func, "alt", KM_NOTHING, KM_ANY, KM_MOD_HELD, "Alt", "", KM_ANY, KM_MOD_HELD);
1295 RNA_def_int(func, "oskey", KM_NOTHING, KM_ANY, KM_MOD_HELD, "OS Key", "", KM_ANY, KM_MOD_HELD);
1296 RNA_def_enum(func, "key_modifier", rna_enum_event_type_items, 0, "Key Modifier", "");
1297 RNA_def_enum(func, "direction", rna_enum_event_direction_items, KM_ANY, "Direction", "");
1298 RNA_def_boolean(func, "repeat", false, "Repeat", "When set, accept key-repeat events");
1299 parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item");
1300 RNA_def_function_return(func, parm);
1301
1302 func = RNA_def_function(srna, "new_from_item", "rna_KeyMap_item_new_from_item");
1304 parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Item to use as a reference");
1306 RNA_def_boolean(func, "head", false, "At Head", "");
1307 parm = RNA_def_pointer(func, "result", "KeyMapItem", "Item", "Added key map item");
1308 RNA_def_function_return(func, parm);
1309
1310 func = RNA_def_function(srna, "remove", "rna_KeyMap_item_remove");
1312 parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
1315
1316 func = RNA_def_function(srna, "from_id", "WM_keymap_item_find_id");
1317 parm = RNA_def_property(func, "id", PROP_INT, PROP_NONE);
1319 RNA_def_property_ui_text(parm, "id", "ID of the item");
1320 parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
1321 RNA_def_function_return(func, parm);
1322
1323 /* Keymap introspection
1324 * Args follow: KeyConfigs.find_item_from_operator */
1325 func = RNA_def_function(srna, "find_from_operator", "rna_KeyMap_item_find_from_operator");
1327 parm = RNA_def_string(func, "idname", nullptr, 0, "Operator Identifier", "");
1329 parm = RNA_def_pointer(func, "properties", "OperatorProperties", "", "");
1332 func, "include", rna_enum_event_type_mask_items, EVT_TYPE_MASK_ALL, "Include", "");
1333 RNA_def_enum_flag(func, "exclude", rna_enum_event_type_mask_items, 0, "Exclude", "");
1334 parm = RNA_def_pointer(func, "item", "KeyMapItem", "", "");
1336 RNA_def_function_return(func, parm);
1337
1338 func = RNA_def_function(srna, "match_event", "rna_KeyMap_item_match_event");
1340 parm = RNA_def_pointer(func, "event", "Event", "", "");
1342 parm = RNA_def_pointer(func, "item", "KeyMapItem", "", "");
1344 RNA_def_function_return(func, parm);
1345}
1346
1348{
1349 FunctionRNA *func;
1350 PropertyRNA *parm;
1351
1352 func = RNA_def_function(srna, "new", "rna_KeyMaps_new");
1355 func,
1356 "Ensure the keymap exists. This will return the one with the given name/space type/region "
1357 "type, or create a new one if it does not exist yet.");
1358
1359 parm = RNA_def_string(func, "name", nullptr, 0, "Name", "");
1361 RNA_def_enum(func, "space_type", rna_enum_space_type_items, SPACE_EMPTY, "Space Type", "");
1363 func, "region_type", rna_enum_region_type_items, RGN_TYPE_WINDOW, "Region Type", "");
1364 RNA_def_boolean(func, "modal", false, "Modal", "Keymap for modal operators");
1365 RNA_def_boolean(func, "tool", false, "Tool", "Keymap for active tools");
1366 parm = RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Added key map");
1367 RNA_def_function_return(func, parm);
1368
1369 func = RNA_def_function(srna, "remove", "rna_KeyMaps_remove");
1371 parm = RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Removed key map");
1374
1375 func = RNA_def_function(srna, "clear", "rna_KeyMaps_clear");
1376 RNA_def_function_ui_description(func, "Remove all keymaps.");
1377
1378 func = RNA_def_function(srna, "find", "rna_KeyMaps_find");
1379 parm = RNA_def_string(func, "name", nullptr, 0, "Name", "");
1381 RNA_def_enum(func, "space_type", rna_enum_space_type_items, SPACE_EMPTY, "Space Type", "");
1383 func, "region_type", rna_enum_region_type_items, RGN_TYPE_WINDOW, "Region Type", "");
1384 parm = RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map");
1385 RNA_def_function_return(func, parm);
1386
1387 func = RNA_def_function(srna, "find_modal", "rna_KeyMaps_find_modal");
1388 parm = RNA_def_string(func, "name", nullptr, 0, "Operator Name", "");
1390 parm = RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map");
1391 RNA_def_function_return(func, parm);
1392}
1393
1395{
1396 FunctionRNA *func;
1397 PropertyRNA *parm;
1398
1399 func = RNA_def_function(srna, "new", "rna_KeyConfig_new"); /* add_keyconfig */
1400 parm = RNA_def_string(func, "name", nullptr, 0, "Name", "");
1402 parm = RNA_def_pointer(
1403 func, "keyconfig", "KeyConfig", "Key Configuration", "Added key configuration");
1404 RNA_def_function_return(func, parm);
1405
1406 func = RNA_def_function(srna, "remove", "rna_KeyConfig_remove"); /* remove_keyconfig */
1408 parm = RNA_def_pointer(
1409 func, "keyconfig", "KeyConfig", "Key Configuration", "Removed key configuration");
1412
1413 /* Helper functions */
1414
1415 /* Keymap introspection */
1416 func = RNA_def_function(
1417 srna, "find_item_from_operator", "rna_KeyConfig_find_item_from_operator");
1419 parm = RNA_def_string(func, "idname", nullptr, 0, "Operator Identifier", "");
1421 parm = RNA_def_property(func, "context", PROP_ENUM, PROP_NONE);
1423 parm = RNA_def_pointer(func, "properties", "OperatorProperties", "", "");
1426 func, "include", rna_enum_event_type_mask_items, EVT_TYPE_MASK_ALL, "Include", "");
1427 RNA_def_enum_flag(func, "exclude", rna_enum_event_type_mask_items, 0, "Exclude", "");
1428 parm = RNA_def_pointer(func, "keymap", "KeyMap", "", "");
1430 parm = RNA_def_pointer(func, "item", "KeyMapItem", "", "");
1432 RNA_def_function_return(func, parm);
1433
1434 func = RNA_def_function(srna, "update", "rna_KeyConfig_update"); /* WM_keyconfig_update */
1436 func,
1437 "keep_properties",
1438 false,
1439 "Keep Properties",
1440 "Operator properties are kept to allow the operators to be registered again in the future");
1441}
1442
1443#endif
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
@ G_FLAG_EVENT_SIMULATE
#define G_MAIN
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
void BKE_undosys_print(UndoStack *ustack)
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:90
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:130
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define STRNCPY(dst, src)
Definition BLI_string.h:593
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
int BLI_str_utf8_size_or_error(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define UNLIKELY(x)
#define ELEM(...)
@ RGN_TYPE_WINDOW
@ SPACE_EMPTY
#define OP_MAX_TYPENAME
#define RNA_POINTER_INVALIDATE(ptr)
ParameterFlag
Definition RNA_types.hh:396
@ PARM_RNAPTR
Definition RNA_types.hh:399
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ PARM_OUTPUT
Definition RNA_types.hh:398
@ FUNC_USE_REPORTS
Definition RNA_types.hh:680
@ FUNC_NO_SELF
Definition RNA_types.hh:673
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:679
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:667
@ FUNC_REGISTER_OPTIONAL
Definition RNA_types.hh:689
@ FUNC_ALLOW_WRITE
Definition RNA_types.hh:695
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_INT
Definition RNA_types.hh:66
@ PROP_STRING
Definition RNA_types.hh:68
PropertyFlag
Definition RNA_types.hh:201
@ PROP_THICK_WRAP
Definition RNA_types.hh:312
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_UNSIGNED
Definition RNA_types.hh:152
constexpr PointerRNA PointerRNA_NULL
Definition RNA_types.hh:45
void UI_popover_end(bContext *C, uiPopover *pup, wmKeyMap *keymap)
uiPopover * UI_popover_begin(bContext *C, int ui_menu_width, bool from_active_button) ATTR_NONNULL(1)
void UI_popup_menu_end(bContext *C, uiPopupMenu *pup)
uiPieMenu * UI_pie_menu_begin(bContext *C, const char *title, int icon, const wmEvent *event) ATTR_NONNULL()
uiPopupMenu * UI_popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void UI_pie_menu_end(bContext *C, uiPieMenu *pie)
#define UI_MAX_SHORTCUT_STR
@ ALERT_ICON_NONE
@ ALERT_ICON_INFO
@ ALERT_ICON_WARNING
@ ALERT_ICON_QUESTION
@ ALERT_ICON_ERROR
@ WM_GIZMOGROUPTYPE_PERSISTENT
#define NC_WINDOW
Definition WM_types.hh:342
eWM_EventFlag
Definition WM_types.hh:637
@ KM_NOTHING
Definition WM_types.hh:283
@ KM_ANY
Definition WM_types.hh:282
@ KM_PRESS
Definition WM_types.hh:284
@ KM_RELEASE
Definition WM_types.hh:285
wmOperatorCallContext
Definition WM_types.hh:216
@ KM_CTRL
Definition WM_types.hh:256
@ KM_ALT
Definition WM_types.hh:257
@ KM_ALT_ANY
Definition WM_types.hh:264
@ KM_OSKEY_ANY
Definition WM_types.hh:265
@ KM_SHIFT_ANY
Definition WM_types.hh:262
@ KM_OSKEY
Definition WM_types.hh:259
@ KM_CTRL_ANY
Definition WM_types.hh:263
@ KM_SHIFT
Definition WM_types.hh:255
#define KM_MOD_HELD
Definition WM_types.hh:270
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
unsigned int U
Definition btGjkEpa3.h:78
int len
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define G(x, y, z)
const char * RNA_translate_ui_text(const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, int translate)
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void api_ui_item_common_translation(FunctionRNA *func)
const EnumPropertyItem rna_enum_region_type_items[]
Definition rna_screen.cc:24
const EnumPropertyItem rna_enum_space_type_items[]
Definition rna_space.cc:97
const EnumPropertyItem rna_enum_operator_context_items[]
Definition rna_ui.cc:33
const EnumPropertyItem rna_enum_icon_items[]
Definition rna_ui_api.cc:31
const EnumPropertyItem rna_enum_event_direction_items[]
Definition rna_wm.cc:477
const EnumPropertyItem rna_enum_event_value_items[]
Definition rna_wm.cc:465
const EnumPropertyItem rna_enum_event_type_mask_items[]
Definition rna_wm.cc:496
const EnumPropertyItem rna_enum_event_type_items[]
Definition rna_wm.cc:206
const EnumPropertyItem rna_enum_wm_report_items[]
Definition rna_wm.cc:594
const EnumPropertyItem rna_enum_operator_return_items[]
Definition rna_wm.cc:562
void RNA_api_keymapitem(StructRNA *srna)
#define WM_GEN_INVOKE_EVENT
void RNA_api_window(StructRNA *srna)
void RNA_api_wm(StructRNA *srna)
#define WM_GEN_INVOKE_SIZE
void RNA_api_keyconfigs(StructRNA *srna)
const EnumPropertyItem rna_operator_popup_icon_items[]
void RNA_api_macro(StructRNA *srna)
void RNA_api_keymap(StructRNA *srna)
void RNA_api_keymapitems(StructRNA *srna)
#define WM_GEN_INVOKE_RETURN
void RNA_api_keyconfig(StructRNA *)
void RNA_api_keymaps(StructRNA *srna)
const EnumPropertyItem rna_enum_window_cursor_items[]
Definition rna_wm_api.cc:33
static void rna_generic_op_invoke(FunctionRNA *func, int flag)
void RNA_api_operator(StructRNA *srna)
#define min(a, b)
Definition sort.c:32
#define FLT_MAX
Definition stdcycles.h:14
Definition DNA_ID.h:413
void * data
Definition RNA_types.hh:42
eWM_GizmoFlagGroupTypeFlag flag
const void * modal_items
wmKeyMap * modalkeymap
Definition WM_types.hh:1098
struct ReportList * reports
wmWindow * win
Definition WM_types.hh:913
struct UndoStack * undo_stack
struct wmWindow * winactive
struct wmKeyConfig * addonconf
struct wmEvent * eventstate
float max
wmTimer * timer
void WM_cursor_modal_restore(wmWindow *win)
void WM_cursor_time(wmWindow *win, int nr)
@ WM_CURSOR_WAIT
Definition wm_cursors.hh:17
@ WM_CURSOR_COPY
Definition wm_cursors.hh:20
@ WM_CURSOR_HAND
Definition wm_cursors.hh:22
@ WM_CURSOR_NSEW_SCROLL
Definition wm_cursors.hh:51
@ WM_CURSOR_CROSS
Definition wm_cursors.hh:26
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:15
@ WM_CURSOR_HAND_CLOSED
Definition wm_cursors.hh:23
@ WM_CURSOR_PAINT
Definition wm_cursors.hh:27
@ WM_CURSOR_Y_MOVE
Definition wm_cursors.hh:39
@ WM_CURSOR_PICK_AREA
Definition wm_cursors.hh:61
@ WM_CURSOR_TEXT_EDIT
Definition wm_cursors.hh:16
@ WM_CURSOR_PAINT_BRUSH
Definition wm_cursors.hh:33
@ WM_CURSOR_NS_SCROLL
Definition wm_cursors.hh:52
@ WM_CURSOR_DOT
Definition wm_cursors.hh:28
@ WM_CURSOR_ZOOM_OUT
Definition wm_cursors.hh:56
@ WM_CURSOR_EDIT
Definition wm_cursors.hh:19
@ WM_CURSOR_ZOOM_IN
Definition wm_cursors.hh:55
@ WM_CURSOR_KNIFE
Definition wm_cursors.hh:31
@ WM_CURSOR_STOP
Definition wm_cursors.hh:18
@ WM_CURSOR_EYEDROPPER
Definition wm_cursors.hh:35
@ WM_CURSOR_ERASER
Definition wm_cursors.hh:34
@ WM_CURSOR_HAND_POINT
Definition wm_cursors.hh:24
@ WM_CURSOR_EW_SCROLL
Definition wm_cursors.hh:53
@ WM_CURSOR_MUTE
Definition wm_cursors.hh:59
@ WM_CURSOR_NONE
Definition wm_cursors.hh:58
@ WM_CURSOR_X_MOVE
Definition wm_cursors.hh:38
wmEvent * WM_event_add_simulate(wmWindow *win, const wmEvent *event_to_add)
void WM_main_add_notifier(uint type, void *reference)
void WM_event_tablet_data_default_set(wmTabletData *tablet_data)
wmEventHandler_Op * WM_event_add_modal_handler_ex(wmWindow *win, ScrArea *area, ARegion *region, wmOperator *op)
bool WM_operator_is_repeat(const bContext *C, const wmOperator *op)
wmKeyMapItem * WM_event_match_keymap_item(bContext *C, wmKeyMap *keymap, const wmEvent *event)
#define ISMOUSE_BUTTON(event_type)
#define ISMOUSE_MOTION(event_type)
#define ISKEYBOARD(event_type)
@ TIMER
#define EVT_TYPE_MASK_ALL
PointerRNA * ptr
Definition wm_files.cc:4126
wmOperatorType * ot
Definition wm_files.cc:4125
bool WM_gizmo_group_type_ensure_ptr(wmGizmoGroupType *gzgt)
void WM_gizmo_group_type_unlink_delayed_ptr(wmGizmoGroupType *gzgt)
wmGizmoGroupType * WM_gizmogrouptype_find(const char *idname, bool quiet)
void WM_script_tag_reload()
void WM_keyconfig_clear(wmKeyConfig *keyconf)
Definition wm_keymap.cc:350
void WM_keymap_item_restore_to_default(wmWindowManager *wm, wmKeyMap *keymap, wmKeyMapItem *kmi)
wmKeyMapItem * WM_key_event_operator(const bContext *C, const char *opname, wmOperatorCallContext opcontext, IDProperty *properties, const short include_mask, const short exclude_mask, wmKeyMap **r_keymap)
void WM_keymap_restore_to_default(wmKeyMap *keymap, wmWindowManager *wm)
wmKeyMapItem * WM_keymap_add_item_copy(wmKeyMap *keymap, wmKeyMapItem *kmi_src)
Definition wm_keymap.cc:566
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:933
wmKeyMapItem * WM_key_event_operator_from_keymap(wmKeyMap *keymap, const char *opname, IDProperty *properties, const short include_mask, const short exclude_mask)
wmKeyMapItem * WM_modalkeymap_add_item(wmKeyMap *km, const KeyMapItem_Params *params, int value)
Definition wm_keymap.cc:973
void WM_keyconfig_update_ex(wmWindowManager *wm, bool keep_properties)
wmKeyConfig * WM_keyconfig_ensure(wmWindowManager *wm, const char *idname, bool user_defined)
Definition wm_keymap.cc:305
wmKeyMap * WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap)
wmKeyMapItem * WM_keymap_add_item(wmKeyMap *keymap, const char *idname, const KeyMapItem_Params *params)
Definition wm_keymap.cc:546
std::optional< std::string > WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact)
void WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap)
Definition wm_keymap.cc:461
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:897
wmKeyMap * WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:868
wmKeyMapItem * WM_modalkeymap_add_item_str(wmKeyMap *km, const KeyMapItem_Params *params, const char *value)
Definition wm_keymap.cc:990
void WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf)
Definition wm_keymap.cc:328
void WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
Definition wm_keymap.cc:579
bool WM_keymap_item_compare(const wmKeyMapItem *k1, const wmKeyMapItem *k2)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
int WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, int icon, bool cancel_default)
void WM_operator_last_properties_ensure(wmOperatorType *ot, PointerRNA *ptr)
size_t WM_operator_bl_idname(char *dst, const char *src)
int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *)
int WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default)
int WM_operator_props_popup(bContext *C, wmOperator *op, const wmEvent *)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const int event_type, const double time_step)
uint8_t flag
Definition wm_window.cc:138