Blender V5.3
rna_ui.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "DNA_screen_types.h"
12
13#include "BLT_translation.hh"
14
15#include "BKE_file_handler.hh"
16#include "BKE_screen.hh"
17
18#include "RNA_define.hh"
19
20#include "RNA_enum_types.hh"
21#include "rna_internal.hh"
22
23#include "UI_interface.hh"
24#include "UI_interface_c.hh"
26
27#include "WM_toolsystem.hh"
28#include "WM_types.hh"
29
30namespace blender {
31
32/* see WM_types.hh */
34
35/* clang-format off */
37 {int(wmOpCallContext::InvokeDefault), "INVOKE_DEFAULT", 0, "Invoke Default", ""},
38 {int(wmOpCallContext::InvokeRegionWin), "INVOKE_REGION_WIN", 0, "Invoke Region Window", ""},
39 {int(wmOpCallContext::InvokeRegionChannels), "INVOKE_REGION_CHANNELS", 0, "Invoke Region Channels", ""},
40 {int(wmOpCallContext::InvokeRegionPreview), "INVOKE_REGION_PREVIEW", 0, "Invoke Region Preview", ""},
41 {int(wmOpCallContext::InvokeArea), "INVOKE_AREA", 0, "Invoke Area", ""},
42 {int(wmOpCallContext::InvokeScreen), "INVOKE_SCREEN", 0, "Invoke Screen", ""},
43 {int(wmOpCallContext::ExecDefault), "EXEC_DEFAULT", 0, "Exec Default", ""},
44 {int(wmOpCallContext::ExecRegionWin), "EXEC_REGION_WIN", 0, "Exec Region Window", ""},
45 {int(wmOpCallContext::ExecRegionChannels), "EXEC_REGION_CHANNELS", 0, "Exec Region Channels", ""},
46 {int(wmOpCallContext::ExecRegionPreview), "EXEC_REGION_PREVIEW", 0, "Exec Region Preview", ""},
47 {int(wmOpCallContext::ExecArea), "EXEC_AREA", 0, "Exec Area", ""},
48 {int(wmOpCallContext::ExecScreen), "EXEC_SCREEN", 0, "Exec Screen", ""},
49 {0, nullptr, 0, nullptr, nullptr},
50};
51/* clang-format on */
52
54 {UILST_LAYOUT_DEFAULT, "DEFAULT", 0, "Default Layout", "Use the default, multi-rows layout"},
55 {UILST_LAYOUT_COMPACT, "COMPACT", 0, "Compact Layout", "Use the compact, single-row layout"},
56 {0, nullptr, 0, nullptr, nullptr},
57};
58
59} // namespace blender
60
61#ifdef RNA_RUNTIME
62
63# include "MEM_guardedalloc.h"
64
65# include "DNA_space_types.h"
66
67# include "RNA_access.hh"
68
69# include "BLI_dynstr.hh"
70# include "BLI_listbase.hh"
71# include "BLI_string.hh"
72# include "BLI_string_utf8.hh"
73
74# include "BKE_context.hh"
75# include "BKE_main.hh"
76# include "BKE_report.hh"
77# include "BKE_screen.hh"
78
79# include "ED_asset_library.hh"
80# include "ED_asset_shelf.hh"
81
82# include "WM_api.hh"
83
84namespace blender {
85
86using ui::Layout;
87
88static ARegionType *region_type_find(ReportList *reports, int space_type, int region_type)
89{
90 SpaceType *st;
91 ARegionType *art;
92
93 st = BKE_spacetype_from_id(space_type);
94
95 for (art = (st) ? st->regiontypes.first() : nullptr; art; art = art->next) {
96 if (art->regionid == region_type) {
97 break;
98 }
99 }
100
101 /* region type not found? abort */
102 if (art == nullptr) {
103 BKE_report(reports, RPT_ERROR, "Region not found in space type");
104 return nullptr;
105 }
106
107 return art;
108}
109
110/* Panel */
111
112static bool panel_poll(const bContext *C, PanelType *pt)
113{
114 extern FunctionRNA *rna_Panel_poll_func;
115
117 FunctionRNA *func;
118 void *ret;
119 bool visible;
120
121 PointerRNA ptr = RNA_pointer_create_discrete(nullptr, pt->rna_ext.srna, nullptr); /* dummy */
122 func = rna_Panel_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
123
124 RNA_parameter_list_create(&list, &ptr, func);
125 RNA_parameter_set_lookup(&list, "context", &C);
126 pt->rna_ext.call(const_cast<bContext *>(C), &ptr, func, &list);
127
128 RNA_parameter_get_lookup(&list, "visible", &ret);
129 visible = *static_cast<bool *>(ret);
130
132
133 return visible;
134}
135
136static void panel_draw(const bContext *C, Panel *panel)
137{
138 extern FunctionRNA *rna_Panel_draw_func;
139
141 FunctionRNA *func;
142
144 &CTX_wm_screen(C)->id, panel->type->rna_ext.srna, panel);
145 func = rna_Panel_draw_func; /* RNA_struct_find_function(&ptr, "draw"); */
146
147 RNA_parameter_list_create(&list, &ptr, func);
148 RNA_parameter_set_lookup(&list, "context", &C);
149 panel->type->rna_ext.call(const_cast<bContext *>(C), &ptr, func, &list);
150
152}
153
154static void panel_draw_header(const bContext *C, Panel *panel)
155{
156 extern FunctionRNA *rna_Panel_draw_header_func;
157
159 FunctionRNA *func;
160
162 &CTX_wm_screen(C)->id, panel->type->rna_ext.srna, panel);
163 func = rna_Panel_draw_header_func; /* RNA_struct_find_function(&ptr, "draw_header"); */
164
165 RNA_parameter_list_create(&list, &ptr, func);
166 RNA_parameter_set_lookup(&list, "context", &C);
167 panel->type->rna_ext.call(const_cast<bContext *>(C), &ptr, func, &list);
168
170}
171
172static void panel_draw_header_preset(const bContext *C, Panel *panel)
173{
174 extern FunctionRNA *rna_Panel_draw_header_preset_func;
175
177 FunctionRNA *func;
178
180 &CTX_wm_screen(C)->id, panel->type->rna_ext.srna, panel);
181 func = rna_Panel_draw_header_preset_func;
182
183 RNA_parameter_list_create(&list, &ptr, func);
184 RNA_parameter_set_lookup(&list, "context", &C);
185 panel->type->rna_ext.call(const_cast<bContext *>(C), &ptr, func, &list);
186
188}
189
190static void panel_type_clear_recursive(Panel *panel, const PanelType *type)
191{
192 if (panel->type == type) {
193 panel->type = nullptr;
194 }
195
196 for (Panel &child_panel : panel->children) {
197 panel_type_clear_recursive(&child_panel, type);
198 }
199}
200
201static bool rna_Panel_unregister(Main *bmain, StructRNA *type)
202{
203 ARegionType *art;
204 PanelType *pt = static_cast<PanelType *>(RNA_struct_blender_type_get(type));
205
206 if (!pt) {
207 return false;
208 }
209 if (!(art = region_type_find(nullptr, pt->space_type, pt->region_type))) {
210 return false;
211 }
212
214 RNA_struct_free_extension(type, &pt->rna_ext);
216
217 if (pt->parent) {
218 LinkData *link = static_cast<LinkData *>(
219 BLI_findptr(&pt->parent->children, pt, offsetof(LinkData, data)));
220 BLI_freelinkN(&pt->parent->children, link);
221 }
222
224
225 for (LinkData &link : pt->children) {
226 PanelType *child_pt = static_cast<PanelType *>(link.data);
227 child_pt->parent = nullptr;
228 }
229
230 for (bScreen &screen : bmain->screens) {
231 for (ScrArea &area : screen.areabase) {
232 for (SpaceLink &sl : area.spacedata) {
233 ListBaseT<ARegion> *regionbase = (&sl == area.spacedata.first()) ? &area.regionbase :
234 &sl.regionbase;
235 for (ARegion &region : *regionbase) {
236 for (Panel &panel : region.panels) {
237 panel_type_clear_recursive(&panel, pt);
238 }
239 /* The unregistered panel might have had a template that added instanced panels,
240 * so remove them just in case. They can be re-added on redraw anyway. */
241 ui::panels_free_instanced(nullptr, &region);
242 }
243 }
244 }
245 }
246
247 pt->children.free_no_destruct();
248 BLI_freelinkN(&art->paneltypes, pt);
249
250 /* update while blender is running */
252 return true;
253}
254
255static StructRNA *rna_Panel_register(Main *bmain,
256 ReportList *reports,
257 void *data,
258 const char *identifier,
259 StructValidateFunc validate,
262{
263 const char *error_prefix = RPT_("Registering panel class:");
264 ARegionType *art;
265 PanelType *pt, *parent = nullptr, dummy_pt = {nullptr};
266 Panel dummy_panel = {nullptr};
267 bool have_function[4];
268 size_t over_alloc = 0; /* Warning, if this becomes a mess, we better do another allocation. */
269 char _panel_descr[RNA_DYN_DESCR_MAX];
270 size_t description_size = 0;
271
272 /* setup dummy panel & panel type to store static properties in */
273 dummy_panel.type = &dummy_pt;
274 _panel_descr[0] = '\0';
275 dummy_panel.type->description = _panel_descr;
276 PointerRNA dummy_panel_ptr = RNA_pointer_create_discrete(nullptr, RNA_Panel, &dummy_panel);
277
278 /* We have to set default context! Else we get a void string... */
279 STRNCPY(dummy_pt.translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
280
281 /* validate the python class */
282 if (validate(&dummy_panel_ptr, data, have_function) != 0) {
283 return nullptr;
284 }
285
286 if (strlen(identifier) >= sizeof(dummy_pt.idname)) {
287 BKE_reportf(reports,
288 RPT_ERROR,
289 "%s '%s' is too long, maximum length is %d",
290 error_prefix,
291 identifier,
292 int(sizeof(dummy_pt.idname)));
293 return nullptr;
294 }
295
296 if (!(art = region_type_find(reports, dummy_pt.space_type, dummy_pt.region_type))) {
297 return nullptr;
298 }
299
301 if (dummy_pt.category[0] == '\0') {
302 /* Use a fallback, otherwise an empty value will draw the panel in every category. */
303 STRNCPY(dummy_pt.category, PNL_CATEGORY_FALLBACK);
304# ifndef NDEBUG
305 printf("%s '%s' misses category, please update the script\n", error_prefix, dummy_pt.idname);
306# endif
307 }
308 }
309 else {
310 if (dummy_pt.category[0] != '\0') {
311 if ((1 << dummy_pt.space_type) & WM_TOOLSYSTEM_SPACE_MASK) {
312 BKE_reportf(reports,
313 RPT_ERROR,
314 "%s '%s' has category '%s'",
315 error_prefix,
316 dummy_pt.idname,
317 dummy_pt.category);
318 return nullptr;
319 }
320 }
321 }
322
323 /* check if we have registered this panel type before, and remove it */
324 for (pt = art->paneltypes.first(); pt; pt = pt->next) {
325 if (STREQ(pt->idname, dummy_pt.idname)) {
326 PanelType *pt_next = pt->next;
327 StructRNA *srna = pt->rna_ext.srna;
328 if (srna) {
329 BKE_reportf(reports,
330 RPT_INFO,
331 "%s '%s', bl_idname '%s' has been registered before, unregistering previous",
332 error_prefix,
333 identifier,
334 dummy_pt.idname);
335 if (!rna_Panel_unregister(bmain, srna)) {
336 BKE_reportf(reports,
337 RPT_ERROR,
338 "%s '%s', bl_idname '%s' could not be unregistered",
339 error_prefix,
340 identifier,
341 dummy_pt.idname);
342 }
343 }
344 else {
345 BLI_freelinkN(&art->paneltypes, pt);
346 }
347
348 /* The order of panel types will be altered on re-registration. */
349 if (dummy_pt.parent_id[0] && (parent == nullptr)) {
350 for (pt = pt_next; pt; pt = pt->next) {
351 if (STREQ(pt->idname, dummy_pt.parent_id)) {
352 parent = pt;
353 break;
354 }
355 }
356 }
357
358 break;
359 }
360
361 if (dummy_pt.parent_id[0] && STREQ(pt->idname, dummy_pt.parent_id)) {
362 parent = pt;
363 }
364 }
365
366 if (!RNA_struct_available_or_report(reports, dummy_pt.idname)) {
367 return nullptr;
368 }
369 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_pt.idname, "_PT_")) {
370 return nullptr;
371 }
372 if (dummy_pt.parent_id[0] && !parent) {
373 BKE_reportf(reports,
374 RPT_ERROR,
375 "%s parent '%s' for '%s' not found",
376 error_prefix,
377 dummy_pt.parent_id,
378 dummy_pt.idname);
379 return nullptr;
380 }
381
382 /* create a new panel type */
383 if (_panel_descr[0]) {
384 description_size = strlen(_panel_descr) + 1;
385 over_alloc += description_size;
386 }
387 pt = static_cast<PanelType *>(
388 MEM_new_zeroed(sizeof(PanelType) + over_alloc, "Python buttons panel"));
389 memcpy(pt, &dummy_pt, sizeof(dummy_pt));
390
391 if (_panel_descr[0]) {
392 char *buf = reinterpret_cast<char *>(pt + 1);
393 memcpy(buf, _panel_descr, description_size);
394 pt->description = buf;
395 }
396 else {
397 pt->description = nullptr;
398 }
399
400 pt->rna_ext.srna = RNA_def_struct_ptr(&RNA_blender_rna_get(), pt->idname, RNA_Panel);
401 RNA_def_struct_translation_context(pt->rna_ext.srna, pt->translation_context);
402 pt->rna_ext.data = data;
403 pt->rna_ext.call = call;
404 pt->rna_ext.free = free;
405 RNA_struct_blender_type_set(pt->rna_ext.srna, pt);
407
408 pt->poll = (have_function[0]) ? panel_poll : nullptr;
409 pt->draw = (have_function[1]) ? panel_draw : nullptr;
410 pt->draw_header = (have_function[2]) ? panel_draw_header : nullptr;
411 pt->draw_header_preset = (have_function[3]) ? panel_draw_header_preset : nullptr;
412
413 /* Find position to insert panel based on order. */
414 PanelType *pt_iter = art->paneltypes.last();
415
416 for (; pt_iter; pt_iter = pt_iter->prev) {
417 /* No header has priority. */
418 if ((pt->flag & PANEL_TYPE_NO_HEADER) && !(pt_iter->flag & PANEL_TYPE_NO_HEADER)) {
419 continue;
420 }
421 if (pt_iter->order <= pt->order) {
422 break;
423 }
424 }
425
426 /* Insert into list. */
427 BLI_insertlinkafter(&art->paneltypes, pt_iter, pt);
428
429 if (parent) {
430 pt->parent = parent;
431 LinkData *pt_child_iter = parent->children.last();
432 for (; pt_child_iter; pt_child_iter = pt_child_iter->prev) {
433 PanelType *pt_child = static_cast<PanelType *>(pt_child_iter->data);
434 if (pt_child->order <= pt->order) {
435 break;
436 }
437 }
438 BLI_insertlinkafter(&parent->children, pt_child_iter, BLI_genericNodeN(pt));
439 }
440
441 {
442 const char *owner_id = RNA_struct_state_owner_get();
443 if (owner_id) {
444 STRNCPY(pt->owner_id, owner_id);
445 }
446 }
447
449
450 /* update while blender is running */
452
453 return pt->rna_ext.srna;
454}
455
456static StructRNA *rna_Panel_refine(PointerRNA *ptr)
457{
458 Panel *panel = static_cast<Panel *>(ptr->data);
459 return (panel->type && panel->type->rna_ext.srna) ? panel->type->rna_ext.srna : RNA_Panel;
460}
461
462static StructRNA *rna_Panel_custom_data_typef(PointerRNA *ptr)
463{
464 Panel *panel = static_cast<Panel *>(ptr->data);
465
466 return ui::panel_custom_data_get(panel)->type;
467}
468
469static PointerRNA rna_Panel_custom_data_get(PointerRNA *ptr)
470{
471 Panel *panel = static_cast<Panel *>(ptr->data);
472
473 /* Because the panel custom data is general we can't refine the pointer type here. */
474 return *ui::panel_custom_data_get(panel);
475}
476
477/* UIList */
478static int rna_UIList_filter_const_FILTER_ITEM_get(PointerRNA * /*ptr*/)
479{
480 return UILST_FLT_ITEM;
481}
482
483static int rna_UIList_item_never_show(PointerRNA * /*ptr*/)
484{
486}
487
488static IDProperty **rna_UIList_idprops(PointerRNA *ptr)
489{
490 uiList *ui_list = static_cast<uiList *>(ptr->data);
491 return &ui_list->properties;
492}
493
494static void rna_UIList_list_id_get(PointerRNA *ptr, char *value)
495{
496 uiList *ui_list = static_cast<uiList *>(ptr->data);
497 if (!ui_list->type) {
498 value[0] = '\0';
499 return;
500 }
501
502 strcpy(value, WM_uilisttype_list_id_get(ui_list->type, ui_list));
503}
504
505static int rna_UIList_list_id_length(PointerRNA *ptr)
506{
507 uiList *ui_list = static_cast<uiList *>(ptr->data);
508 if (!ui_list->type) {
509 return 0;
510 }
511
512 return strlen(WM_uilisttype_list_id_get(ui_list->type, ui_list));
513}
514
515static void uilist_draw_item(uiList *ui_list,
516 const bContext *C,
517 Layout &layout,
518 PointerRNA *dataptr,
519 PointerRNA *itemptr,
520 int icon,
521 PointerRNA *active_dataptr,
522 const char *active_propname,
523 int index,
524 int flt_flag)
525{
526 extern FunctionRNA *rna_UIList_draw_item_func;
527
529 FunctionRNA *func;
530
532 &CTX_wm_screen(C)->id, ui_list->type->rna_ext.srna, ui_list);
533 func = rna_UIList_draw_item_func; /* RNA_struct_find_function(&ul_ptr, "draw_item"); */
534
535 RNA_parameter_list_create(&list, &ul_ptr, func);
536 RNA_parameter_set_lookup(&list, "context", &C);
537 Layout *layout_ptr = &layout;
538 RNA_parameter_set_lookup(&list, "layout", &layout_ptr);
539 RNA_parameter_set_lookup(&list, "data", dataptr);
540 RNA_parameter_set_lookup(&list, "item", itemptr);
541 RNA_parameter_set_lookup(&list, "icon", &icon);
542 RNA_parameter_set_lookup(&list, "active_data", active_dataptr);
543 RNA_parameter_set_lookup(&list, "active_property", &active_propname);
545 RNA_parameter_set_lookup(&list, "flt_flag", &flt_flag);
546 ui_list->type->rna_ext.call(const_cast<bContext *>(C), &ul_ptr, func, &list);
547
549}
550
551static void uilist_draw_filter(uiList *ui_list, const bContext *C, Layout &layout)
552{
553 extern FunctionRNA *rna_UIList_draw_filter_func;
554
556 FunctionRNA *func;
557
559 &CTX_wm_screen(C)->id, ui_list->type->rna_ext.srna, ui_list);
560 func = rna_UIList_draw_filter_func; /* RNA_struct_find_function(&ul_ptr, "draw_filter"); */
561
562 RNA_parameter_list_create(&list, &ul_ptr, func);
563 RNA_parameter_set_lookup(&list, "context", &C);
564 Layout *layout_ptr = &layout;
565 RNA_parameter_set_lookup(&list, "layout", &layout_ptr);
566 ui_list->type->rna_ext.call(const_cast<bContext *>(C), &ul_ptr, func, &list);
567
569}
570
571static void uilist_filter_items(uiList *ui_list,
572 const bContext *C,
573 PointerRNA *dataptr,
574 const char *propname)
575{
576 extern FunctionRNA *rna_UIList_filter_items_func;
577
579 FunctionRNA *func;
580 PropertyRNA *parm;
581
582 uiListDyn *flt_data = ui_list->dyn_data;
583 int *filter_flags, *filter_neworder;
584 void *ret1, *ret2;
585 int ret_len;
586 int len = flt_data->items_len = RNA_collection_length(dataptr, propname);
587
589 &CTX_wm_screen(C)->id, ui_list->type->rna_ext.srna, ui_list);
590 func = rna_UIList_filter_items_func; /* RNA_struct_find_function(&ul_ptr, "filter_items"); */
591
592 RNA_parameter_list_create(&list, &ul_ptr, func);
593 RNA_parameter_set_lookup(&list, "context", &C);
594 RNA_parameter_set_lookup(&list, "data", dataptr);
595 RNA_parameter_set_lookup(&list, "property", &propname);
596
597 ui_list->type->rna_ext.call(const_cast<bContext *>(C), &ul_ptr, func, &list);
598
599 parm = RNA_function_find_parameter(nullptr, func, "filter_flags");
600 ret_len = RNA_parameter_dynamic_length_get(&list, parm);
601 if (!ELEM(ret_len, len, 0)) {
602 printf("%s: Error, py func returned %d items in %s, %d or none were expected.\n",
603 __func__,
605 "filter_flags",
606 len);
607 /* NOTE: we cannot return here, we would let flt_data in inconsistent state... see #38356. */
608 filter_flags = nullptr;
609 }
610 else {
611 RNA_parameter_get(&list, parm, &ret1);
612 filter_flags = static_cast<int *>(ret1);
613 }
614
615 parm = RNA_function_find_parameter(nullptr, func, "filter_neworder");
616 ret_len = RNA_parameter_dynamic_length_get(&list, parm);
617 if (!ELEM(ret_len, len, 0)) {
618 printf("%s: Error, py func returned %d items in %s, %d or none were expected.\n",
619 __func__,
621 "filter_neworder",
622 len);
623 /* NOTE: we cannot return here, we would let flt_data in inconsistent state... see #38356. */
624 filter_neworder = nullptr;
625 }
626 else {
627 RNA_parameter_get(&list, parm, &ret2);
628 filter_neworder = static_cast<int *>(ret2);
629 }
630
631 /* We have to do some final checks and transforms... */
632 {
633 int i;
634 if (filter_flags) {
635 flt_data->items_filter_flags = MEM_new_array_uninitialized<int>(size_t(len), __func__);
636 memcpy(flt_data->items_filter_flags, filter_flags, sizeof(int) * len);
637
638 if (filter_neworder) {
639 /* For sake of simplicity, py filtering is expected to filter all items,
640 * but we actually only want reordering data for shown items!
641 */
642 int items_shown, shown_idx;
643 int t_idx, t_ni, prev_ni;
644 flt_data->items_shown = 0;
645 for (i = 0, shown_idx = 0; i < len; i++) {
647 filter_neworder[shown_idx++] = filter_neworder[i];
648 }
649 }
650 items_shown = flt_data->items_shown = shown_idx;
651 flt_data->items_filter_neworder = MEM_new_array_uninitialized<int>(size_t(items_shown),
652 __func__);
653 /* And now, bring back new indices into the [0, items_shown) range!
654 * XXX This is O(N^2). :/
655 */
656 for (shown_idx = 0, prev_ni = -1; shown_idx < items_shown; shown_idx++) {
657 for (i = 0, t_ni = len, t_idx = -1; i < items_shown; i++) {
658 int ni = filter_neworder[i];
659 if (ni > prev_ni && ni < t_ni) {
660 t_idx = i;
661 t_ni = ni;
662 }
663 }
664 if (t_idx >= 0) {
665 prev_ni = t_ni;
666 flt_data->items_filter_neworder[t_idx] = shown_idx;
667 }
668 }
669 }
670 else {
671 /* we still have to set flt_data->items_shown... */
672 flt_data->items_shown = 0;
673 for (i = 0; i < len; i++) {
675 flt_data->items_shown++;
676 }
677 }
678 }
679 }
680 else {
681 flt_data->items_shown = len;
682
683 if (filter_neworder) {
684 flt_data->items_filter_neworder = MEM_new_array_uninitialized<int>(size_t(len), __func__);
685 memcpy(flt_data->items_filter_neworder, filter_neworder, sizeof(int) * len);
686 }
687 }
688 }
689
691}
692
693static bool rna_UIList_unregister(Main *bmain, StructRNA *type)
694{
695 uiListType *ult = static_cast<uiListType *>(RNA_struct_blender_type_get(type));
696
697 if (!ult) {
698 return false;
699 }
701 RNA_struct_free_extension(type, &ult->rna_ext);
703
704 WM_uilisttype_remove_ptr(bmain, ult);
705
706 /* update while blender is running */
708 return true;
709}
710
711static StructRNA *rna_UIList_register(Main *bmain,
712 ReportList *reports,
713 void *data,
714 const char *identifier,
715 StructValidateFunc validate,
718{
719 const char *error_prefix = "Registering uilist class:";
720 uiListType *ult, dummy_ult = {nullptr};
721 uiList dummy_uilist = {nullptr};
722 bool have_function[3];
723
724 /* setup dummy menu & menu type to store static properties in */
725 dummy_uilist.type = &dummy_ult;
726 PointerRNA dummy_ul_ptr = RNA_pointer_create_discrete(nullptr, RNA_UIList, &dummy_uilist);
727
728 /* validate the python class */
729 if (validate(&dummy_ul_ptr, data, have_function) != 0) {
730 return nullptr;
731 }
732
733 if (strlen(identifier) >= sizeof(dummy_ult.idname)) {
734 BKE_reportf(reports,
735 RPT_ERROR,
736 "%s '%s' is too long, maximum length is %d",
737 error_prefix,
738 identifier,
739 int(sizeof(dummy_ult.idname)));
740 return nullptr;
741 }
742
743 /* Check if we have registered this UI-list type before, and remove it. */
744 ult = WM_uilisttype_find(dummy_ult.idname, true);
745 if (ult) {
746 BKE_reportf(reports,
747 RPT_INFO,
748 "%s '%s', bl_idname '%s' has been registered before, unregistering previous",
749 error_prefix,
750 identifier,
751 dummy_ult.idname);
752
753 StructRNA *srna = ult->rna_ext.srna;
754 if (!(srna && rna_UIList_unregister(bmain, srna))) {
755 BKE_reportf(reports,
756 RPT_ERROR,
757 "%s '%s', bl_idname '%s' %s",
758 error_prefix,
759 identifier,
760 dummy_ult.idname,
761 srna ? "is built-in" : "could not be unregistered");
762 return nullptr;
763 }
764 }
765 if (!RNA_struct_available_or_report(reports, dummy_ult.idname)) {
766 return nullptr;
767 }
768 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_ult.idname, "_UL_")) {
769 return nullptr;
770 }
771
772 /* create a new menu type */
773 ult = MEM_new_zeroed<uiListType>("python uilist");
774 memcpy(ult, &dummy_ult, sizeof(dummy_ult));
775
776 ult->rna_ext.srna = RNA_def_struct_ptr(&RNA_blender_rna_get(), ult->idname, RNA_UIList);
777 ult->rna_ext.data = data;
778 ult->rna_ext.call = call;
779 ult->rna_ext.free = free;
780 RNA_struct_blender_type_set(ult->rna_ext.srna, ult);
781
782 ult->draw_item = (have_function[0]) ? uilist_draw_item : nullptr;
783 ult->draw_filter = (have_function[1]) ? uilist_draw_filter : nullptr;
784 ult->filter_items = (have_function[2]) ? uilist_filter_items : nullptr;
785
787
788 /* update while blender is running */
790
791 return ult->rna_ext.srna;
792}
793
794static StructRNA *rna_UIList_refine(PointerRNA *ptr)
795{
796 uiList *ui_list = static_cast<uiList *>(ptr->data);
797 return (ui_list->type && ui_list->type->rna_ext.srna) ? ui_list->type->rna_ext.srna : RNA_UIList;
798}
799
800/* Header */
801
802static void header_draw(const bContext *C, Header *hdr)
803{
804 extern FunctionRNA *rna_Header_draw_func;
805
807 FunctionRNA *func;
808
810 &CTX_wm_screen(C)->id, hdr->type->rna_ext.srna, hdr);
811 func = rna_Header_draw_func; /* RNA_struct_find_function(&htr, "draw"); */
812
813 RNA_parameter_list_create(&list, &htr, func);
814 RNA_parameter_set_lookup(&list, "context", &C);
815 hdr->type->rna_ext.call(const_cast<bContext *>(C), &htr, func, &list);
816
818}
819
820static bool rna_Header_unregister(Main *bmain, StructRNA *type)
821{
822 ARegionType *art;
823 HeaderType *ht = static_cast<HeaderType *>(RNA_struct_blender_type_get(type));
824
825 if (!ht) {
826 return false;
827 }
828
829 if (!(art = region_type_find(nullptr, ht->space_type, ht->region_type))) {
830 return false;
831 }
832
834 RNA_struct_free_extension(type, &ht->rna_ext);
836
837 BLI_freelinkN(&art->headertypes, ht);
838
839 /* update while blender is running */
841 return true;
842}
843
844static StructRNA *rna_Header_register(Main *bmain,
845 ReportList *reports,
846 void *data,
847 const char *identifier,
848 StructValidateFunc validate,
851{
852 const char *error_prefix = "Registering header class:";
853 ARegionType *art;
854 HeaderType *ht, dummy_ht = {nullptr};
855 Header dummy_header = {nullptr};
856 bool have_function[1];
857
858 /* setup dummy header & header type to store static properties in */
859 dummy_header.type = &dummy_ht;
860 dummy_ht.region_type = RGN_TYPE_HEADER; /* RGN_TYPE_HEADER by default, may be overridden */
861 PointerRNA dummy_header_ptr = RNA_pointer_create_discrete(nullptr, RNA_Header, &dummy_header);
862
863 /* validate the python class */
864 if (validate(&dummy_header_ptr, data, have_function) != 0) {
865 return nullptr;
866 }
867
868 if (strlen(identifier) >= sizeof(dummy_ht.idname)) {
869 BKE_reportf(reports,
870 RPT_ERROR,
871 "%s '%s' is too long, maximum length is %d",
872 error_prefix,
873 identifier,
874 int(sizeof(dummy_ht.idname)));
875 return nullptr;
876 }
877
878 if (!(art = region_type_find(reports, dummy_ht.space_type, dummy_ht.region_type))) {
879 return nullptr;
880 }
881
882 /* check if we have registered this header type before, and remove it */
883 ht = static_cast<HeaderType *>(
884 BLI_findstring(&art->headertypes, dummy_ht.idname, offsetof(HeaderType, idname)));
885 if (ht) {
886 BKE_reportf(reports,
887 RPT_INFO,
888 "%s '%s', bl_idname '%s' has been registered before, unregistering previous",
889 error_prefix,
890 identifier,
891 dummy_ht.idname);
892
893 StructRNA *srna = ht->rna_ext.srna;
894 if (!(srna && rna_Header_unregister(bmain, srna))) {
895 BKE_reportf(reports,
896 RPT_ERROR,
897 "%s '%s', bl_idname '%s' %s",
898 error_prefix,
899 identifier,
900 dummy_ht.idname,
901 srna ? "is built-in" : "could not be unregistered");
902 return nullptr;
903 }
904 }
905
906 if (!RNA_struct_available_or_report(reports, dummy_ht.idname)) {
907 return nullptr;
908 }
909 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_ht.idname, "_HT_")) {
910 return nullptr;
911 }
912
913 /* create a new header type */
914 ht = MEM_new_zeroed<HeaderType>(__func__);
915 memcpy(ht, &dummy_ht, sizeof(dummy_ht));
916
917 ht->rna_ext.srna = RNA_def_struct_ptr(&RNA_blender_rna_get(), ht->idname, RNA_Header);
918 ht->rna_ext.data = data;
919 ht->rna_ext.call = call;
920 ht->rna_ext.free = free;
921 RNA_struct_blender_type_set(ht->rna_ext.srna, ht);
922
923 ht->draw = (have_function[0]) ? header_draw : nullptr;
924
925 BLI_addtail(&art->headertypes, ht);
926
927 /* update while blender is running */
929
930 return ht->rna_ext.srna;
931}
932
933static StructRNA *rna_Header_refine(PointerRNA *htr)
934{
935 Header *hdr = static_cast<Header *>(htr->data);
936 return (hdr->type && hdr->type->rna_ext.srna) ? hdr->type->rna_ext.srna : RNA_Header;
937}
938
939/* Menu */
940
941static bool menu_poll(const bContext *C, MenuType *pt)
942{
943 extern FunctionRNA *rna_Menu_poll_func;
944
946 FunctionRNA *func;
947 void *ret;
948 bool visible;
949
950 PointerRNA ptr = RNA_pointer_create_discrete(nullptr, pt->rna_ext.srna, nullptr); /* dummy */
951 func = rna_Menu_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
952
953 RNA_parameter_list_create(&list, &ptr, func);
954 RNA_parameter_set_lookup(&list, "context", &C);
955 pt->rna_ext.call(const_cast<bContext *>(C), &ptr, func, &list);
956
957 RNA_parameter_get_lookup(&list, "visible", &ret);
958 visible = *static_cast<bool *>(ret);
959
961
962 return visible;
963}
964
965static void menu_draw(const bContext *C, Menu *menu)
966{
967 extern FunctionRNA *rna_Menu_draw_func;
968
970 FunctionRNA *func;
971
973 &CTX_wm_screen(C)->id, menu->type->rna_ext.srna, menu);
974 func = rna_Menu_draw_func; /* RNA_struct_find_function(&mtr, "draw"); */
975
976 RNA_parameter_list_create(&list, &mtr, func);
977 RNA_parameter_set_lookup(&list, "context", &C);
978 menu->type->rna_ext.call(const_cast<bContext *>(C), &mtr, func, &list);
979
981}
982
983static bool rna_Menu_unregister(Main *bmain, StructRNA *type)
984{
985 MenuType *mt = static_cast<MenuType *>(RNA_struct_blender_type_get(type));
986
987 if (!mt) {
988 return false;
989 }
990
992 RNA_struct_free_extension(type, &mt->rna_ext);
994
996
997 /* update while blender is running */
999 return true;
1000}
1001
1002static StructRNA *rna_Menu_register(Main *bmain,
1003 ReportList *reports,
1004 void *data,
1005 const char *identifier,
1006 StructValidateFunc validate,
1007 StructCallbackFunc call,
1009{
1010 const char *error_prefix = "Registering menu class:";
1011 MenuType *mt, dummy_mt = {nullptr};
1012 Menu dummy_menu = {nullptr};
1013 bool have_function[2];
1014 size_t over_alloc = 0; /* Warning, if this becomes a mess, we better do another allocation. */
1015 size_t description_size = 0;
1016 char _menu_descr[RNA_DYN_DESCR_MAX];
1017
1018 /* setup dummy menu & menu type to store static properties in */
1019 dummy_menu.type = &dummy_mt;
1020 _menu_descr[0] = '\0';
1021 dummy_menu.type->description = _menu_descr;
1022 PointerRNA dummy_menu_ptr = RNA_pointer_create_discrete(nullptr, RNA_Menu, &dummy_menu);
1023
1024 /* We have to set default context! Else we get a void string... */
1025 STRNCPY(dummy_mt.translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
1026
1027 /* validate the python class */
1028 if (validate(&dummy_menu_ptr, data, have_function) != 0) {
1029 return nullptr;
1030 }
1031
1032 if (strlen(identifier) >= sizeof(dummy_mt.idname)) {
1033 BKE_reportf(reports,
1034 RPT_ERROR,
1035 "%s '%s' is too long, maximum length is %d",
1036 error_prefix,
1037 identifier,
1038 int(sizeof(dummy_mt.idname)));
1039 return nullptr;
1040 }
1041
1042 /* check if we have registered this menu type before, and remove it */
1043 mt = WM_menutype_find(dummy_mt.idname, true);
1044 if (mt) {
1045 BKE_reportf(reports,
1046 RPT_INFO,
1047 "%s '%s', bl_idname '%s' has been registered before, unregistering previous",
1048 error_prefix,
1049 identifier,
1050 dummy_mt.idname);
1051
1052 StructRNA *srna = mt->rna_ext.srna;
1053 if (!(srna && rna_Menu_unregister(bmain, srna))) {
1054 BKE_reportf(reports,
1055 RPT_ERROR,
1056 "%s '%s', bl_idname '%s' %s",
1057 error_prefix,
1058 identifier,
1059 dummy_mt.idname,
1060 srna ? "is built-in" : "could not be unregistered");
1061 return nullptr;
1062 }
1063 }
1064 if (!RNA_struct_available_or_report(reports, dummy_mt.idname)) {
1065 return nullptr;
1066 }
1067 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_mt.idname, "_MT_")) {
1068 return nullptr;
1069 }
1070
1071 /* create a new menu type */
1072 if (_menu_descr[0]) {
1073 description_size = strlen(_menu_descr) + 1;
1074 over_alloc += description_size;
1075 }
1076
1077 mt = static_cast<MenuType *>(
1078 MEM_new_zeroed(sizeof(MenuType) + over_alloc, "Python buttons menu"));
1079 memcpy(mt, &dummy_mt, sizeof(dummy_mt));
1080
1081 if (_menu_descr[0]) {
1082 char *buf = reinterpret_cast<char *>(mt + 1);
1083 memcpy(buf, _menu_descr, description_size);
1084 mt->description = buf;
1085 }
1086 else {
1087 mt->description = nullptr;
1088 }
1089
1090 mt->rna_ext.srna = RNA_def_struct_ptr(&RNA_blender_rna_get(), mt->idname, RNA_Menu);
1091 RNA_def_struct_translation_context(mt->rna_ext.srna, mt->translation_context);
1092 mt->rna_ext.data = data;
1093 mt->rna_ext.call = call;
1094 mt->rna_ext.free = free;
1095 RNA_struct_blender_type_set(mt->rna_ext.srna, mt);
1097
1098 mt->poll = (have_function[0]) ? menu_poll : nullptr;
1099 mt->draw = (have_function[1]) ? menu_draw : nullptr;
1100
1101 {
1102 const char *owner_id = RNA_struct_state_owner_get();
1103 if (owner_id) {
1104 STRNCPY(mt->owner_id, owner_id);
1105 }
1106 }
1107
1108 WM_menutype_add(mt);
1109
1110 /* update while blender is running */
1112
1113 return mt->rna_ext.srna;
1114}
1115
1116static StructRNA *rna_Menu_refine(PointerRNA *mtr)
1117{
1118 Menu *menu = static_cast<Menu *>(mtr->data);
1119 return (menu->type && menu->type->rna_ext.srna) ? menu->type->rna_ext.srna : RNA_Menu;
1120}
1121
1122/* Asset Shelf */
1123
1124static bool asset_shelf_asset_poll(const AssetShelfType *shelf_type,
1126{
1127 extern FunctionRNA *rna_AssetShelf_asset_poll_func;
1128
1130 nullptr, shelf_type->rna_ext.srna, nullptr); /* dummy */
1131 FunctionRNA *func = rna_AssetShelf_asset_poll_func;
1132
1134 RNA_parameter_list_create(&list, &ptr, func);
1135 RNA_parameter_set_lookup(&list, "asset", &asset);
1136 shelf_type->rna_ext.call(nullptr, &ptr, func, &list);
1137
1138 void *ret;
1139 RNA_parameter_get_lookup(&list, "visible", &ret);
1140 /* Get the value before freeing. */
1141 const bool is_visible = *static_cast<bool *>(ret);
1142
1144
1145 return is_visible;
1146}
1147
1148static bool asset_shelf_poll(const bContext *C, const AssetShelfType *shelf_type)
1149{
1150 extern FunctionRNA *rna_AssetShelf_poll_func;
1151
1153 nullptr, shelf_type->rna_ext.srna, nullptr); /* dummy */
1154 FunctionRNA *func = rna_AssetShelf_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
1155
1157 RNA_parameter_list_create(&list, &ptr, func);
1158 RNA_parameter_set_lookup(&list, "context", &C);
1159 shelf_type->rna_ext.call(const_cast<bContext *>(C), &ptr, func, &list);
1160
1161 void *ret;
1162 RNA_parameter_get_lookup(&list, "visible", &ret);
1163 /* Get the value before freeing. */
1164 const bool is_visible = *static_cast<bool *>(ret);
1165
1167
1168 return is_visible;
1169}
1170
1171static const AssetWeakReference *asset_shelf_get_active_asset(const AssetShelfType *shelf_type)
1172{
1173 extern FunctionRNA *rna_AssetShelf_get_active_asset_func;
1174
1176 nullptr, shelf_type->rna_ext.srna, nullptr); /* dummy */
1177
1178 FunctionRNA *func = rna_AssetShelf_get_active_asset_func;
1179
1181 RNA_parameter_list_create(&list, &ptr, func);
1182 shelf_type->rna_ext.call(nullptr, &ptr, func, &list);
1183
1184 void *ret;
1185 RNA_parameter_get_lookup(&list, "asset_reference", &ret);
1186 /* Get the value before freeing. */
1187 AssetWeakReference *active_asset = *static_cast<AssetWeakReference **>(ret);
1188
1190
1191 return active_asset;
1192}
1193
1194static void asset_shelf_draw_context_menu(const bContext *C,
1195 const AssetShelfType *shelf_type,
1197 Layout &layout)
1198{
1199 extern FunctionRNA *rna_AssetShelf_draw_context_menu_func;
1200
1202 nullptr, shelf_type->rna_ext.srna, nullptr); /* dummy */
1203
1204 FunctionRNA *func = rna_AssetShelf_draw_context_menu_func;
1205 // RNA_struct_find_function(&ptr, "draw_context_menu");
1206
1208 RNA_parameter_list_create(&list, &ptr, func);
1209 RNA_parameter_set_lookup(&list, "context", &C);
1210 RNA_parameter_set_lookup(&list, "asset", &asset);
1211 Layout *layout_ptr = &layout;
1212 RNA_parameter_set_lookup(&list, "layout", &layout_ptr);
1213 shelf_type->rna_ext.call(const_cast<bContext *>(C), &ptr, func, &list);
1214
1216}
1217
1218static bool rna_AssetShelf_unregister(Main *bmain, StructRNA *type)
1219{
1220 AssetShelfType *shelf_type = static_cast<AssetShelfType *>(RNA_struct_blender_type_get(type));
1221
1222 if (!shelf_type) {
1223 return false;
1224 }
1225
1226 ed::asset::shelf::type_unlink(*bmain, *shelf_type);
1227
1229 RNA_struct_free_extension(type, &shelf_type->rna_ext);
1231
1233
1234 /* update while blender is running */
1236
1237 return true;
1238}
1239
1240static StructRNA *rna_AssetShelf_register(Main *bmain,
1241 ReportList *reports,
1242 void *data,
1243 const char *identifier,
1244 StructValidateFunc validate,
1245 StructCallbackFunc call,
1247{
1248 std::unique_ptr<AssetShelfType> shelf_type = std::make_unique<AssetShelfType>();
1249
1250 /* setup dummy shelf & shelf type to store static properties in */
1251 AssetShelf dummy_shelf = {};
1252 dummy_shelf.type = shelf_type.get();
1253 PointerRNA dummy_shelf_ptr = RNA_pointer_create_discrete(nullptr, RNA_AssetShelf, &dummy_shelf);
1254
1255 bool have_function[4];
1256
1257 /* validate the python class */
1258 if (validate(&dummy_shelf_ptr, data, have_function) != 0) {
1259 return nullptr;
1260 }
1261
1262 if (strlen(identifier) >= sizeof(shelf_type->idname)) {
1263 BKE_reportf(reports,
1264 RPT_ERROR,
1265 "Registering asset shelf class: '%s' is too long, maximum length is %d",
1266 identifier,
1267 int(sizeof(shelf_type->idname)));
1268 return nullptr;
1269 }
1270
1271 /* Check if we have registered this asset shelf type before, and remove it. */
1272 {
1274 shelf_type->idname);
1275 if (existing_shelf_type && existing_shelf_type->rna_ext.srna) {
1276 BKE_reportf(reports,
1277 RPT_INFO,
1278 "Registering asset shelf class: '%s' has been registered before, "
1279 "unregistering previous",
1280 shelf_type->idname);
1281
1282 rna_AssetShelf_unregister(bmain, existing_shelf_type->rna_ext.srna);
1283 }
1284 }
1285
1286 if (!RNA_struct_available_or_report(reports, shelf_type->idname)) {
1287 return nullptr;
1288 }
1289 if (!RNA_struct_bl_idname_ok_or_report(reports, shelf_type->idname, "_AST_")) {
1290 return nullptr;
1291 }
1292
1293 /* Create the new shelf type. */
1294 shelf_type->rna_ext.srna = RNA_def_struct_ptr(
1295 &RNA_blender_rna_get(), shelf_type->idname, RNA_AssetShelf);
1296 shelf_type->rna_ext.data = data;
1297 shelf_type->rna_ext.call = call;
1298 shelf_type->rna_ext.free = free;
1299 RNA_struct_blender_type_set(shelf_type->rna_ext.srna, shelf_type.get());
1300
1301 shelf_type->poll = have_function[0] ? asset_shelf_poll : nullptr;
1302 shelf_type->asset_poll = have_function[1] ? asset_shelf_asset_poll : nullptr;
1303 shelf_type->get_active_asset = have_function[2] ? asset_shelf_get_active_asset : nullptr;
1304 shelf_type->draw_context_menu = have_function[3] ? asset_shelf_draw_context_menu : nullptr;
1305
1306 StructRNA *srna = shelf_type->rna_ext.srna;
1307
1308 ed::asset::shelf::type_register(std::move(shelf_type));
1309
1310 /* update while blender is running */
1312
1313 return srna;
1314}
1315
1316static void rna_AssetShelf_activate_operator_get(PointerRNA *ptr, char *value)
1317{
1318 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1319 strcpy(value, shelf->type->activate_operator.c_str());
1320}
1321
1322static int rna_AssetShelf_activate_operator_length(PointerRNA *ptr)
1323{
1324 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1325 return shelf->type->activate_operator.size();
1326}
1327
1328static void rna_AssetShelf_activate_operator_set(PointerRNA *ptr, const char *value)
1329{
1330 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1331 shelf->type->activate_operator = value;
1332}
1333
1334static void rna_AssetShelf_drag_operator_get(PointerRNA *ptr, char *value)
1335{
1336 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1337 strcpy(value, shelf->type->drag_operator.c_str());
1338}
1339
1340static int rna_AssetShelf_drag_operator_length(PointerRNA *ptr)
1341{
1342 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1343 return shelf->type->drag_operator.size();
1344}
1345
1346static void rna_AssetShelf_drag_operator_set(PointerRNA *ptr, const char *value)
1347{
1348 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1349 shelf->type->drag_operator = value;
1350}
1351
1352static StructRNA *rna_AssetShelf_refine(PointerRNA *shelf_ptr)
1353{
1354 AssetShelf *shelf = static_cast<AssetShelf *>(shelf_ptr->data);
1355 return (shelf->type && shelf->type->rna_ext.srna) ? shelf->type->rna_ext.srna : RNA_AssetShelf;
1356}
1357
1358static int rna_AssetShelf_asset_library_get(PointerRNA *ptr)
1359{
1360 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1361 return ed::asset::library_reference_to_enum_value(&shelf->settings.asset_library_reference);
1362}
1363
1364static void rna_AssetShelf_asset_library_set(PointerRNA *ptr, int value)
1365{
1366 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1367 shelf->settings.asset_library_reference = ed::asset::library_reference_from_enum_value(value);
1368}
1369
1370static int rna_AssetShelf_preview_size_default(PointerRNA *ptr, PropertyRNA * /*prop*/)
1371{
1372 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1373 if (shelf->type && shelf->type->default_preview_size) {
1374 return shelf->type->default_preview_size;
1375 }
1377}
1378
1379static void rna_Panel_bl_description_set(PointerRNA *ptr, const char *value)
1380{
1381 Panel *data = static_cast<Panel *>(ptr->data);
1382 char *str = const_cast<char *>(data->type->description);
1383 if (!str[0]) {
1385 }
1386 else {
1387 BLI_assert_msg(0, "setting the bl_description on a non-builtin panel");
1388 }
1389}
1390
1391static void rna_Menu_bl_description_set(PointerRNA *ptr, const char *value)
1392{
1393 Menu *data = static_cast<Menu *>(ptr->data);
1394 char *str = const_cast<char *>(data->type->description);
1395 if (!str[0]) {
1397 }
1398 else {
1399 BLI_assert_msg(0, "setting the bl_description on a non-builtin menu");
1400 }
1401}
1402
1403/* UILayout */
1404
1405static bool rna_UILayout_active_get(PointerRNA *ptr)
1406{
1407 return ptr->data_as<const Layout>()->active();
1408}
1409
1410static void rna_UILayout_active_set(PointerRNA *ptr, bool value)
1411{
1412 ptr->data_as<Layout>()->active_set(value);
1413}
1414
1415static bool rna_UILayout_active_default_get(PointerRNA *ptr)
1416{
1417 return ptr->data_as<const Layout>()->active_default();
1418}
1419
1420static void rna_UILayout_active_default_set(PointerRNA *ptr, bool value)
1421{
1422 ptr->data_as<Layout>()->active_default_set(value);
1423}
1424
1425static bool rna_UILayout_activate_init_get(PointerRNA *ptr)
1426{
1427 return ptr->data_as<const Layout>()->activate_init();
1428}
1429
1430static void rna_UILayout_activate_init_set(PointerRNA *ptr, bool value)
1431{
1432 ptr->data_as<Layout>()->activate_init_set(value);
1433}
1434
1435static bool rna_UILayout_alert_get(PointerRNA *ptr)
1436{
1437 return ptr->data_as<const Layout>()->red_alert();
1438}
1439
1440static void rna_UILayout_alert_set(PointerRNA *ptr, bool value)
1441{
1442 ptr->data_as<Layout>()->red_alert_set(value);
1443}
1444
1445static void rna_UILayout_op_context_set(PointerRNA *ptr, int value)
1446{
1447 ptr->data_as<Layout>()->operator_context_set(wm::OpCallContext(value));
1448}
1449
1450static int rna_UILayout_op_context_get(PointerRNA *ptr)
1451{
1452 return int(ptr->data_as<const Layout>()->operator_context());
1453}
1454
1455static bool rna_UILayout_enabled_get(PointerRNA *ptr)
1456{
1457 return ptr->data_as<const Layout>()->enabled();
1458}
1459
1460static void rna_UILayout_enabled_set(PointerRNA *ptr, bool value)
1461{
1462 ptr->data_as<Layout>()->enabled_set(value);
1463}
1464
1465# if 0
1466static int rna_UILayout_red_alert_get(PointerRNA *ptr)
1467{
1468 return ptr->data_as<const Layout>()->red_alert();
1469}
1470
1471static void rna_UILayout_red_alert_set(PointerRNA *ptr, bool value)
1472{
1473 ptr->data_as<Layout>()->red_alert_set(value);
1474}
1475# endif
1476
1477static int rna_UILayout_alignment_get(PointerRNA *ptr)
1478{
1479 return int(ptr->data_as<const Layout>()->alignment());
1480}
1481
1482static void rna_UILayout_alignment_set(PointerRNA *ptr, int value)
1483{
1484 ptr->data_as<Layout>()->alignment_set(ui::LayoutAlign(value));
1485}
1486
1487static int rna_UILayout_direction_get(PointerRNA *ptr)
1488{
1489 return int(ptr->data_as<const Layout>()->local_direction());
1490}
1491
1492static float rna_UILayout_scale_x_get(PointerRNA *ptr)
1493{
1494 return ptr->data_as<const Layout>()->scale_x();
1495}
1496
1497static void rna_UILayout_scale_x_set(PointerRNA *ptr, float value)
1498{
1499 ptr->data_as<Layout>()->scale_x_set(value);
1500}
1501
1502static float rna_UILayout_scale_y_get(PointerRNA *ptr)
1503{
1504 return ptr->data_as<const Layout>()->scale_y();
1505}
1506
1507static void rna_UILayout_scale_y_set(PointerRNA *ptr, float value)
1508{
1509 ptr->data_as<Layout>()->scale_y_set(value);
1510}
1511
1512static float rna_UILayout_units_x_get(PointerRNA *ptr)
1513{
1514 return ptr->data_as<const Layout>()->ui_units_x();
1515}
1516
1517static void rna_UILayout_units_x_set(PointerRNA *ptr, float value)
1518{
1519 ptr->data_as<Layout>()->ui_units_x_set(value);
1520}
1521
1522static float rna_UILayout_units_y_get(PointerRNA *ptr)
1523{
1524 return ptr->data_as<const Layout>()->ui_units_y();
1525}
1526
1527static float rna_UIlayout_property_split_factor_get(PointerRNA * /*ptr*/)
1528{
1529 return Layout::PROPERTY_SPLIT_FACTOR;
1530}
1531
1532static void rna_UILayout_units_y_set(PointerRNA *ptr, float value)
1533{
1534 ptr->data_as<Layout>()->ui_units_y_set(value);
1535}
1536
1537static int rna_UILayout_emboss_get(PointerRNA *ptr)
1538{
1539 return int(ptr->data_as<const Layout>()->emboss());
1540}
1541
1542static void rna_UILayout_emboss_set(PointerRNA *ptr, int value)
1543{
1544 ptr->data_as<Layout>()->emboss_set(ui::EmbossType(value));
1545}
1546
1547static bool rna_UILayout_property_split_get(PointerRNA *ptr)
1548{
1549 return ptr->data_as<const Layout>()->use_property_split();
1550}
1551
1552static void rna_UILayout_property_split_set(PointerRNA *ptr, bool value)
1553{
1554 ptr->data_as<Layout>()->use_property_split_set(value);
1555}
1556
1557static bool rna_UILayout_property_decorate_get(PointerRNA *ptr)
1558{
1559 return ptr->data_as<const Layout>()->use_property_decorate();
1560}
1561
1562static void rna_UILayout_property_decorate_set(PointerRNA *ptr, bool value)
1563{
1564 ptr->data_as<Layout>()->use_property_decorate_set(value);
1565}
1566
1567/* File Handler */
1568
1569static bool file_handler_poll_drop(const bContext *C, bke::FileHandlerType *file_handler_type)
1570{
1571 extern FunctionRNA *rna_FileHandler_poll_drop_func;
1572
1574 nullptr, file_handler_type->rna_ext.srna, nullptr); /* dummy */
1575 FunctionRNA *func = rna_FileHandler_poll_drop_func;
1576
1578 RNA_parameter_list_create(&list, &ptr, func);
1579 RNA_parameter_set_lookup(&list, "context", &C);
1580 file_handler_type->rna_ext.call(const_cast<bContext *>(C), &ptr, func, &list);
1581
1582 void *ret;
1583 RNA_parameter_get_lookup(&list, "is_usable", &ret);
1584 /* Get the value before freeing. */
1585 const bool is_usable = *static_cast<bool *>(ret);
1586
1588
1589 return is_usable;
1590}
1591
1592static bool rna_FileHandler_unregister(Main * /*bmain*/, StructRNA *type)
1593{
1594 bke::FileHandlerType *file_handler_type = static_cast<bke::FileHandlerType *>(
1596
1597 if (!file_handler_type) {
1598 return false;
1599 }
1600
1601 RNA_struct_free_extension(type, &file_handler_type->rna_ext);
1603
1604 bke::file_handler_remove(file_handler_type);
1605
1606 return true;
1607}
1608
1609static StructRNA *rna_FileHandler_register(Main *bmain,
1610 ReportList *reports,
1611 void *data,
1612 const char *identifier,
1613 StructValidateFunc validate,
1614 StructCallbackFunc call,
1616{
1617 bke::FileHandlerType dummy_file_handler_type{};
1618 FileHandler dummy_file_handler{};
1619
1620 dummy_file_handler.type = &dummy_file_handler_type;
1621
1622 /* Setup dummy file handler type to store static properties in. */
1623 PointerRNA dummy_file_handler_ptr = RNA_pointer_create_discrete(
1624 nullptr, RNA_FileHandler, &dummy_file_handler);
1625
1626 bool have_function[1];
1627
1628 /* Validate the python class. */
1629 if (validate(&dummy_file_handler_ptr, data, have_function) != 0) {
1630 return nullptr;
1631 }
1632
1633 if (strlen(identifier) >= sizeof(dummy_file_handler_type.idname)) {
1634 BKE_reportf(reports,
1635 RPT_ERROR,
1636 "Registering file handler class: '%s' is too long, maximum length is %d",
1637 identifier,
1638 int(sizeof(dummy_file_handler_type.idname)));
1639 return nullptr;
1640 }
1641
1642 /* Check if there is a file handler registered with the same `idname`, and remove it. */
1643 auto registered_file_handler = bke::file_handler_find(dummy_file_handler_type.idname);
1644 if (registered_file_handler) {
1645 rna_FileHandler_unregister(bmain, registered_file_handler->rna_ext.srna);
1646 }
1647
1648 if (!RNA_struct_available_or_report(reports, dummy_file_handler_type.idname)) {
1649 return nullptr;
1650 }
1651 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_file_handler_type.idname, "_FH_")) {
1652 return nullptr;
1653 }
1654
1655 /* Create the new file handler type. */
1656 auto file_handler_type = std::make_unique<bke::FileHandlerType>();
1657 *file_handler_type = dummy_file_handler_type;
1658
1659 file_handler_type->rna_ext.srna = RNA_def_struct_ptr(
1660 &RNA_blender_rna_get(), file_handler_type->idname, RNA_FileHandler);
1661 file_handler_type->rna_ext.data = data;
1662 file_handler_type->rna_ext.call = call;
1663 file_handler_type->rna_ext.free = free;
1664 RNA_struct_blender_type_set(file_handler_type->rna_ext.srna, file_handler_type.get());
1665
1666 file_handler_type->poll_drop = have_function[0] ? file_handler_poll_drop : nullptr;
1667
1668 auto srna = file_handler_type->rna_ext.srna;
1669 bke::file_handler_add(std::move(file_handler_type));
1670
1671 return srna;
1672}
1673
1674static StructRNA *rna_FileHandler_refine(PointerRNA *file_handler_ptr)
1675{
1676 FileHandler *file_handler = static_cast<FileHandler *>(file_handler_ptr->data);
1677 return (file_handler->type && file_handler->type->rna_ext.srna) ?
1678 file_handler->type->rna_ext.srna :
1679 RNA_FileHandler;
1680}
1681
1682static void rna_FileHandler_label_with_extensions(const char *idname, char *result)
1683{
1684 const bke::FileHandlerType *file_handler = bke::file_handler_find(idname);
1686 file_handler ? file_handler->label_with_extensions().c_str() : "",
1688}
1689
1690} // namespace blender
1691
1692#else /* RNA_RUNTIME */
1693
1694namespace blender {
1695
1697{
1698 StructRNA *srna;
1699 PropertyRNA *prop;
1700
1701 static const EnumPropertyItem alignment_items[] = {
1702 {int(ui::LayoutAlign::Expand), "EXPAND", 0, "Expand", ""},
1703 {int(ui::LayoutAlign::Left), "LEFT", 0, "Left", ""},
1704 {int(ui::LayoutAlign::Center), "CENTER", 0, "Center", ""},
1705 {int(ui::LayoutAlign::Right), "RIGHT", 0, "Right", ""},
1706 {0, nullptr, 0, nullptr, nullptr},
1707 };
1708
1709 static const EnumPropertyItem direction_items[] = {
1710 {int(ui::LayoutDirection::Horizontal), "HORIZONTAL", 0, "Horizontal", ""},
1711 {int(ui::LayoutDirection::Vertical), "VERTICAL", 0, "Vertical", ""},
1712 {0, nullptr, 0, nullptr, nullptr},
1713 };
1714
1715 static const EnumPropertyItem emboss_items[] = {
1716 {int(ui::EmbossType::Emboss), "NORMAL", 0, "Regular", "Draw standard button emboss style"},
1717 {int(ui::EmbossType::None), "NONE", 0, "None", "Draw only text and icons"},
1719 "PULLDOWN_MENU",
1720 0,
1721 "Pull-down Menu",
1722 "Draw pull-down menu style"},
1723 {int(ui::EmbossType::PieMenu), "PIE_MENU", 0, "Pie Menu", "Draw radial menu style"},
1725 "NONE_OR_STATUS",
1726 0,
1727 "None or Status",
1728 "Draw with no emboss unless the button has a coloring status like an animation state"},
1729 {0, nullptr, 0, nullptr, nullptr},
1730 };
1731
1732 /* layout */
1733
1734 srna = RNA_def_struct(brna, "UILayout", nullptr);
1735 RNA_def_struct_sdna(srna, "ui::Layout");
1736 RNA_def_struct_ui_text(srna, "UI Layout", "User interface layout in a panel or header");
1737
1738 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
1739 RNA_def_property_boolean_funcs(prop, "rna_UILayout_active_get", "rna_UILayout_active_set");
1741 "Active",
1742 "When false, all items within this layout are grayed out. Values can "
1743 "still be changed and interactions are allowed");
1744
1745 prop = RNA_def_property(srna, "active_default", PROP_BOOLEAN, PROP_NONE);
1747 prop, "rna_UILayout_active_default_get", "rna_UILayout_active_default_set");
1749 prop,
1750 "Active Default",
1751 "When true, an operator button defined after this will be activated when pressing return"
1752 "(use with popup dialogs)");
1753
1754 prop = RNA_def_property(srna, "activate_init", PROP_BOOLEAN, PROP_NONE);
1756 prop, "rna_UILayout_activate_init_get", "rna_UILayout_activate_init_set");
1758 prop,
1759 "Activate on Init",
1760 "When true, buttons defined in popups will be activated on first display "
1761 "(use so you can type into a field without having to click on it first)");
1762
1763 prop = RNA_def_property(srna, "operator_context", PROP_ENUM, PROP_NONE);
1766 prop, "rna_UILayout_op_context_get", "rna_UILayout_op_context_set", nullptr);
1768 "Operator Context",
1769 "Typically set to 'INVOKE_REGION_WIN', except some cases "
1770 "in :class:`bpy.types.Menu` when it's set to 'EXEC_REGION_WIN'.");
1771
1772 prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
1773 RNA_def_property_boolean_funcs(prop, "rna_UILayout_enabled_get", "rna_UILayout_enabled_set");
1775 "Enabled",
1776 "When false, all items within this layout are grayed out. Values "
1777 "cannot be changed and interactions are disabled");
1778
1779 prop = RNA_def_property(srna, "alert", PROP_BOOLEAN, PROP_NONE);
1780 RNA_def_property_boolean_funcs(prop, "rna_UILayout_alert_get", "rna_UILayout_alert_set");
1781
1782 prop = RNA_def_property(srna, "alignment", PROP_ENUM, PROP_NONE);
1783 RNA_def_property_enum_items(prop, alignment_items);
1785 prop, "rna_UILayout_alignment_get", "rna_UILayout_alignment_set", nullptr);
1786
1787 prop = RNA_def_property(srna, "direction", PROP_ENUM, PROP_NONE);
1788 RNA_def_property_enum_items(prop, direction_items);
1789 RNA_def_property_enum_funcs(prop, "rna_UILayout_direction_get", nullptr, nullptr);
1791
1792 prop = RNA_def_property(srna, "scale_x", PROP_FLOAT, PROP_UNSIGNED);
1794 prop, "rna_UILayout_scale_x_get", "rna_UILayout_scale_x_set", nullptr);
1796 prop, "Scale X", "Scale factor along the X for items in this (sub)layout");
1797
1798 prop = RNA_def_property(srna, "scale_y", PROP_FLOAT, PROP_UNSIGNED);
1800 prop, "rna_UILayout_scale_y_get", "rna_UILayout_scale_y_set", nullptr);
1802 prop, "Scale Y", "Scale factor along the Y for items in this (sub)layout");
1803
1804 prop = RNA_def_property(srna, "ui_units_x", PROP_FLOAT, PROP_UNSIGNED);
1806 prop, "rna_UILayout_units_x_get", "rna_UILayout_units_x_set", nullptr);
1808 prop, "Units X", "Fixed size along the X for items in this (sub)layout");
1809
1810 prop = RNA_def_property(srna, "ui_units_y", PROP_FLOAT, PROP_UNSIGNED);
1812 prop, "rna_UILayout_units_y_get", "rna_UILayout_units_y_set", nullptr);
1814 prop, "Units Y", "Fixed size along the Y for items in this (sub)layout");
1815 RNA_api_ui_layout(srna);
1816
1817 prop = RNA_def_property(srna, "emboss", PROP_ENUM, PROP_NONE);
1818 RNA_def_property_enum_items(prop, emboss_items);
1819 RNA_def_property_enum_funcs(prop, "rna_UILayout_emboss_get", "rna_UILayout_emboss_set", nullptr);
1820
1821 prop = RNA_def_property(srna, "use_property_split", PROP_BOOLEAN, PROP_NONE);
1823 prop, "rna_UILayout_property_split_get", "rna_UILayout_property_split_set");
1824
1825 prop = RNA_def_float(srna,
1826 "property_split_factor",
1830 "Property Split Factor",
1831 "Factor used by the layout system when property split is enabled",
1835 RNA_def_property_float_funcs(prop, "rna_UIlayout_property_split_factor_get", nullptr, nullptr);
1836
1837 prop = RNA_def_property(srna, "use_property_decorate", PROP_BOOLEAN, PROP_NONE);
1839 prop, "rna_UILayout_property_decorate_get", "rna_UILayout_property_decorate_set");
1840}
1841
1842static void rna_def_panel(BlenderRNA *brna)
1843{
1844 StructRNA *srna;
1845 PropertyRNA *prop;
1846 PropertyRNA *parm;
1847 FunctionRNA *func;
1848
1849 static const EnumPropertyItem panel_flag_items[] = {
1851 "DEFAULT_CLOSED",
1852 0,
1853 "Default Closed",
1854 "Defines if the panel has to be open or collapsed at the time of its creation"},
1856 "HIDE_HEADER",
1857 0,
1858 "Hide Header",
1859 "If set to False, the panel shows a header, which contains a clickable "
1860 "arrow to collapse the panel and the label (see bl_label)"},
1862 "INSTANCED",
1863 0,
1864 "Instanced Panel",
1865 "Multiple panels with this type can be used as part of a list depending on data external "
1866 "to the UI. Used to create panels for the modifiers and other stacks."},
1868 "HEADER_LAYOUT_EXPAND",
1869 0,
1870 "Expand Header Layout",
1871 "Allow buttons in the header to stretch and shrink to fill the entire layout width"},
1872 {0, nullptr, 0, nullptr, nullptr},
1873 };
1874
1875 srna = RNA_def_struct(brna, "Panel", nullptr);
1876 RNA_def_struct_ui_text(srna, "Panel", "Panel containing UI elements");
1877 RNA_def_struct_sdna(srna, "Panel");
1878 RNA_def_struct_refine_func(srna, "rna_Panel_refine");
1879 RNA_def_struct_register_funcs(srna, "rna_Panel_register", "rna_Panel_unregister", nullptr);
1882
1883 /* poll */
1884 func = RNA_def_function(srna, "poll", nullptr);
1886 func, "If this method returns a non-null output, then the panel can be drawn");
1888 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
1889 parm = RNA_def_pointer(func, "context", "Context", "", "");
1891
1892 /* draw */
1893 func = RNA_def_function(srna, "draw", nullptr);
1894 RNA_def_function_ui_description(func, "Draw UI elements into the panel UI layout");
1896 parm = RNA_def_pointer(func, "context", "Context", "", "");
1898
1899 func = RNA_def_function(srna, "draw_header", nullptr);
1900 RNA_def_function_ui_description(func, "Draw UI elements into the panel's header UI layout");
1902 parm = RNA_def_pointer(func, "context", "Context", "", "");
1904
1905 func = RNA_def_function(srna, "draw_header_preset", nullptr);
1906 RNA_def_function_ui_description(func, "Draw UI elements for presets in the panel's header");
1908 parm = RNA_def_pointer(func, "context", "Context", "", "");
1910
1911 prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
1912 RNA_def_property_struct_type(prop, "UILayout");
1913 RNA_def_property_ui_text(prop, "Layout", "Defines the structure of the panel in the UI");
1914
1915 prop = RNA_def_property(srna, "text", PROP_STRING, PROP_NONE);
1916 RNA_def_property_string_sdna(prop, nullptr, "drawname");
1917 RNA_def_property_ui_text(prop, "Text", "Override for the panel label in the UI");
1918
1919 prop = RNA_def_property(srna, "custom_data", PROP_POINTER, PROP_NONE);
1920 RNA_def_property_struct_type(prop, "Constraint");
1921 RNA_def_property_pointer_sdna(prop, nullptr, "runtime.custom_data_ptr");
1923 prop, "rna_Panel_custom_data_get", nullptr, "rna_Panel_custom_data_typef", nullptr);
1924 RNA_def_property_ui_text(prop, "Custom Data", "Panel data");
1926
1927 /* registration */
1928 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
1929 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
1932 "ID Name",
1933 "If this is set, the panel gets a custom ID, otherwise it takes the "
1934 "name of the class used to define the panel. For example, if the "
1935 "class name is \"OBJECT_PT_hello\", and bl_idname is not set by the "
1936 "script, then bl_idname = \"OBJECT_PT_hello\".");
1937
1938 prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
1939 RNA_def_property_string_sdna(prop, nullptr, "type->label");
1942 "Label",
1943 "The panel label, shows up in the panel header at the right of the "
1944 "triangle used to collapse the panel");
1945
1946 prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
1947 RNA_def_property_string_sdna(prop, nullptr, "type->translation_context");
1951 "",
1952 "Specific translation context, only define when the label needs to be "
1953 "disambiguated from others using the exact same label");
1954
1956
1957 prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE);
1958 RNA_def_property_string_sdna(prop, nullptr, "type->description");
1959 RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1960 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_Panel_bl_description_set");
1961 // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1963 RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for nullptr */
1964 RNA_def_property_ui_text(prop, "", "The panel tooltip");
1965
1966 prop = RNA_def_property(srna, "bl_category", PROP_STRING, PROP_NONE);
1967 RNA_def_property_string_sdna(prop, nullptr, "type->category");
1970 prop, "", "The category (tab) in which the panel will be displayed, when applicable");
1971
1972 prop = RNA_def_property(srna, "bl_icon", PROP_ENUM, PROP_NONE);
1973 RNA_def_property_enum_sdna(prop, nullptr, "type->icon");
1976 RNA_def_property_ui_text(prop, "Icon", "Icon override for the panel category tab");
1977
1978 prop = RNA_def_property(srna, "bl_icon_value", PROP_INT, PROP_NONE);
1979 RNA_def_property_int_sdna(prop, nullptr, "type->icon");
1981 RNA_def_property_ui_text(prop, "Icon Value", "Icon value override for the panel category tab");
1982
1983 prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
1984 RNA_def_property_string_sdna(prop, nullptr, "type->owner_id");
1986 RNA_def_property_ui_text(prop, "", "The ID owning the data displayed in the panel, if any");
1987
1988 prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
1989 RNA_def_property_enum_sdna(prop, nullptr, "type->space_type");
1992 RNA_def_property_ui_text(prop, "Space Type", "The space where the panel is going to be used in");
1993
1994 prop = RNA_def_property(srna, "bl_region_type", PROP_ENUM, PROP_NONE);
1995 RNA_def_property_enum_sdna(prop, nullptr, "type->region_type");
1999 prop, "Region Type", "The region where the panel is going to be used in");
2000
2001 prop = RNA_def_property(srna, "bl_context", PROP_STRING, PROP_NONE);
2002 RNA_def_property_string_sdna(prop, nullptr, "type->context");
2004 prop, PROP_REGISTER_OPTIONAL); /* Only used in Properties Editor and 3D View - Thomas */
2006 "Context",
2007 "The context in which the panel belongs to. (TODO: explain the "
2008 "possible combinations bl_context/bl_region_type/bl_space_type)");
2009
2010 prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
2012 RNA_def_property_enum_sdna(prop, nullptr, "type->flag");
2013 RNA_def_property_enum_items(prop, panel_flag_items);
2014 RNA_def_property_ui_text(prop, "Options", "Options for this panel type");
2015
2016 prop = RNA_def_property(srna, "bl_parent_id", PROP_STRING, PROP_NONE);
2017 RNA_def_property_string_sdna(prop, nullptr, "type->parent_id");
2020 prop, "Parent ID Name", "If this is set, the panel becomes a sub-panel");
2021
2022 prop = RNA_def_property(srna, "bl_ui_units_x", PROP_INT, PROP_UNSIGNED);
2023 RNA_def_property_int_sdna(prop, nullptr, "type->ui_units_x");
2025 RNA_def_property_ui_text(prop, "Units X", "When set, defines popup panel width");
2026
2027 prop = RNA_def_property(srna, "bl_order", PROP_INT, PROP_UNSIGNED);
2028 RNA_def_property_int_sdna(prop, nullptr, "type->order");
2031 prop,
2032 "Order",
2033 "Panels with lower numbers are default ordered before panels with higher numbers");
2034
2035 prop = RNA_def_property(srna, "use_pin", PROP_BOOLEAN, PROP_NONE);
2036 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PNL_PIN);
2037 RNA_def_property_ui_text(prop, "Pin Panel", "Show the panel on all tabs");
2038 /* XXX, should only tag region for redraw */
2039 RNA_def_property_update(prop, NC_WINDOW, nullptr);
2040
2041 prop = RNA_def_property(srna, "is_popover", PROP_BOOLEAN, PROP_NONE);
2042 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PNL_POPOVER);
2044 RNA_def_property_ui_text(prop, "Popover", "");
2045}
2046
2047static void rna_def_uilist(BlenderRNA *brna)
2048{
2049 StructRNA *srna;
2050 PropertyRNA *prop;
2051 PropertyRNA *parm;
2052 FunctionRNA *func;
2053
2054 srna = RNA_def_struct(brna, "UIList", nullptr);
2055 RNA_def_struct_ui_text(srna, "UIList", "UI list containing the elements of a collection");
2056 RNA_def_struct_sdna(srna, "uiList");
2057 RNA_def_struct_refine_func(srna, "rna_UIList_refine");
2058 RNA_def_struct_register_funcs(srna, "rna_UIList_register", "rna_UIList_unregister", nullptr);
2059 RNA_def_struct_system_idprops_func(srna, "rna_UIList_idprops");
2061
2062 /* Registration */
2063 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2064 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2067 "ID Name",
2068 "If this is set, the uilist gets a custom ID, otherwise it takes the "
2069 "name of the class used to define the uilist (for example, if the "
2070 "class name is \"OBJECT_UL_vgroups\", and bl_idname is not set by the "
2071 "script, then bl_idname = \"OBJECT_UL_vgroups\")");
2072
2073 /* Data */
2074 /* Note that this is the "non-full" list-ID as obtained through #WM_uilisttype_list_id_get(),
2075 * which differs from the (internal) `uiList.list_id`. */
2076 prop = RNA_def_property(srna, "list_id", PROP_STRING, PROP_NONE);
2079 prop, "rna_UIList_list_id_get", "rna_UIList_list_id_length", nullptr);
2081 "List Name",
2082 "Identifier of the list, if any was passed to the \"list_id\" "
2083 "parameter of \"template_list()\"");
2084
2085 prop = RNA_def_property(srna, "layout_type", PROP_ENUM, PROP_NONE);
2088
2089 /* Filter options */
2090 prop = RNA_def_property(srna, "use_filter_show", PROP_BOOLEAN, PROP_NONE);
2091 RNA_def_property_boolean_sdna(prop, nullptr, "filter_flag", UILST_FLT_SHOW);
2092 RNA_def_property_ui_text(prop, "Show Filter", "Show filtering options");
2093
2094 prop = RNA_def_property(srna, "filter_name", PROP_STRING, PROP_NONE);
2095 RNA_def_property_string_sdna(prop, nullptr, "filter_byname");
2098 prop, "Filter by Name", "Only show items matching this name (use '*' as wildcard)");
2099
2100 prop = RNA_def_property(srna, "use_filter_invert", PROP_BOOLEAN, PROP_NONE);
2101 RNA_def_property_boolean_sdna(prop, nullptr, "filter_flag", UILST_FLT_EXCLUDE);
2102 RNA_def_property_ui_text(prop, "Invert", "Invert filtering (show hidden items, and vice versa)");
2103
2104 /* WARNING: This is sort of an abuse, sort-by-alpha is actually a value,
2105 * should even be an enum in full logic (of two values, sort by index and sort by name).
2106 * But for default UIList, it's nicer (better UI-wise) to show this as a boolean bit-flag option,
2107 * avoids having to define custom setters/getters using UILST_FLT_SORT_MASK to mask out
2108 * actual bitflags on same var, etc.
2109 */
2110 prop = RNA_def_property(srna, "use_filter_sort_alpha", PROP_BOOLEAN, PROP_NONE);
2111 RNA_def_property_boolean_sdna(prop, nullptr, "filter_sort_flag", UILST_FLT_SORT_ALPHA);
2112 RNA_def_property_ui_icon(prop, ICON_SORTALPHA, 0);
2113 RNA_def_property_ui_text(prop, "Sort by Name", "Sort items by their name");
2114
2115 prop = RNA_def_property(srna, "use_filter_sort_reverse", PROP_BOOLEAN, PROP_NONE);
2116 RNA_def_property_boolean_sdna(prop, nullptr, "filter_sort_flag", UILST_FLT_SORT_REVERSE);
2117 RNA_def_property_ui_text(prop, "Reverse", "Reverse the order of shown items");
2118
2119 prop = RNA_def_property(srna, "use_filter_sort_lock", PROP_BOOLEAN, PROP_NONE);
2120 RNA_def_property_boolean_sdna(prop, nullptr, "filter_sort_flag", UILST_FLT_SORT_LOCK);
2122 prop, "Lock Order", "Lock the order of shown items (user cannot change it)");
2123
2124 /* draw_item */
2125 func = RNA_def_function(srna, "draw_item", nullptr);
2127 func,
2128 "Draw an item in the list (NOTE: when you define your own draw_item "
2129 "function, you may want to check given 'item' is of the right type...)");
2131 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2133 parm = RNA_def_pointer(func, "layout", "UILayout", "", "Layout to draw the item");
2135 parm = RNA_def_pointer(
2136 func, "data", "AnyType", "", "Data from which to take Collection property");
2138 parm = RNA_def_pointer(func, "item", "AnyType", "", "Item of the collection property");
2140 parm = RNA_def_int(
2141 func, "icon", 0, 0, INT_MAX, "", "Icon of the item in the collection", 0, INT_MAX);
2143 parm = RNA_def_pointer(func,
2144 "active_data",
2145 "AnyType",
2146 "",
2147 "Data from which to take property for the active element");
2149 parm = RNA_def_string(func,
2150 "active_property",
2151 nullptr,
2152 0,
2153 "",
2154 "Identifier of property in active_data, for the active element");
2156 parm = RNA_def_int(
2157 func, "index", 0, 0, INT_MAX, "", "Index of the item in the collection", 0, INT_MAX);
2159 parm = RNA_def_property(func, "flt_flag", PROP_INT, PROP_UNSIGNED);
2160 RNA_def_property_ui_text(parm, "", "The filter-flag result for this item");
2162
2163 /* draw_filter */
2164 func = RNA_def_function(srna, "draw_filter", nullptr);
2165 RNA_def_function_ui_description(func, "Draw filtering options");
2167 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2169 parm = RNA_def_pointer(func, "layout", "UILayout", "", "Layout to draw the item");
2171
2172 /* filter */
2173 func = RNA_def_function(srna, "filter_items", nullptr);
2175 func,
2176 "Filter and/or re-order items of the collection (output filter results in "
2177 "filter_flags, and reorder results in filter_neworder arrays)");
2179 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2181 parm = RNA_def_pointer(
2182 func, "data", "AnyType", "", "Data from which to take Collection property");
2184 parm = RNA_def_string(
2185 func, "property", nullptr, 0, "", "Identifier of property in data, for the collection");
2187 prop = RNA_def_property(func, "filter_flags", PROP_INT, PROP_UNSIGNED);
2189 RNA_def_property_array(prop, 1); /* XXX Dummy value, default 0 does not work */
2191 "",
2192 "An array of filter flags, one for each item in the collection (NOTE: "
2193 "The upper 16 bits, including FILTER_ITEM, are reserved, only use the "
2194 "lower 16 bits for custom usages)");
2195 RNA_def_function_output(func, prop);
2196 prop = RNA_def_property(func, "filter_neworder", PROP_INT, PROP_UNSIGNED);
2198 RNA_def_property_array(prop, 1); /* XXX Dummy value, default 0 does not work */
2200 prop,
2201 "",
2202 "An array of indices, one for each item in the collection, mapping the org "
2203 "index to the new one");
2204 RNA_def_function_output(func, prop);
2205
2206 /* "Constants"! */
2207 RNA_define_verify_sdna(false); /* not in sdna */
2208
2209 prop = RNA_def_property(srna, "bitflag_filter_item", PROP_INT, PROP_UNSIGNED);
2211 prop,
2212 "FILTER_ITEM",
2213 "The value of the reserved bitflag 'FILTER_ITEM' (in filter_flags values)");
2214 RNA_def_property_int_funcs(prop, "rna_UIList_filter_const_FILTER_ITEM_get", nullptr, nullptr);
2216
2217 prop = RNA_def_property(srna, "bitflag_item_never_show", PROP_INT, PROP_UNSIGNED);
2218 RNA_def_property_ui_text(prop, "ITEM_NEVER_SHOW", "Skip the item from displaying in the list");
2219 RNA_def_property_int_funcs(prop, "rna_UIList_item_never_show", nullptr, nullptr);
2221}
2222
2223static void rna_def_header(BlenderRNA *brna)
2224{
2225 StructRNA *srna;
2226 PropertyRNA *prop;
2227 PropertyRNA *parm;
2228 FunctionRNA *func;
2229
2230 srna = RNA_def_struct(brna, "Header", nullptr);
2231 RNA_def_struct_ui_text(srna, "Header", "Editor header containing UI elements");
2232 RNA_def_struct_sdna(srna, "Header");
2233 RNA_def_struct_refine_func(srna, "rna_Header_refine");
2234 RNA_def_struct_register_funcs(srna, "rna_Header_register", "rna_Header_unregister", nullptr);
2236
2237 /* draw */
2238 func = RNA_def_function(srna, "draw", nullptr);
2239 RNA_def_function_ui_description(func, "Draw UI elements into the header UI layout");
2241 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2243
2244 RNA_define_verify_sdna(false); /* not in sdna */
2245
2246 prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
2247 RNA_def_property_pointer_sdna(prop, nullptr, "layout");
2248 RNA_def_property_struct_type(prop, "UILayout");
2249 RNA_def_property_ui_text(prop, "Layout", "Structure of the header in the UI");
2250
2251 /* registration */
2252 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2253 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2256 "ID Name",
2257 "If this is set, the header gets a custom ID, otherwise it takes the "
2258 "name of the class used to define the header; for example, if the "
2259 "class name is \"OBJECT_HT_hello\", and bl_idname is not set by the "
2260 "script, then bl_idname = \"OBJECT_HT_hello\"");
2261
2262 prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
2263 RNA_def_property_enum_sdna(prop, nullptr, "type->space_type");
2267 prop, "Space Type", "The space where the header is going to be used in");
2268
2269 prop = RNA_def_property(srna, "bl_region_type", PROP_ENUM, PROP_NONE);
2270 RNA_def_property_enum_sdna(prop, nullptr, "type->region_type");
2275 "Region Type",
2276 "The region where the header is going to be used in "
2277 "(defaults to header region)");
2278
2280}
2281
2282static void rna_def_menu(BlenderRNA *brna)
2283{
2284 StructRNA *srna;
2285 PropertyRNA *prop;
2286 PropertyRNA *parm;
2287 FunctionRNA *func;
2288
2289 static const EnumPropertyItem menu_flag_items[] = {
2291 "SEARCH_ON_KEY_PRESS",
2292 0,
2293 "Search on Key Press",
2294 "Open a menu search when a key pressed while the menu is open"},
2295 {0, nullptr, 0, nullptr, nullptr},
2296 };
2297
2298 srna = RNA_def_struct(brna, "Menu", nullptr);
2299 RNA_def_struct_ui_text(srna, "Menu", "Editor menu containing buttons");
2300 RNA_def_struct_sdna(srna, "Menu");
2301 RNA_def_struct_refine_func(srna, "rna_Menu_refine");
2302 RNA_def_struct_register_funcs(srna, "rna_Menu_register", "rna_Menu_unregister", nullptr);
2305
2306 /* poll */
2307 func = RNA_def_function(srna, "poll", nullptr);
2309 func, "If this method returns a non-null output, then the menu can be drawn");
2311 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
2312 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2314
2315 /* draw */
2316 func = RNA_def_function(srna, "draw", nullptr);
2317 RNA_def_function_ui_description(func, "Draw UI elements into the menu UI layout");
2319 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2321
2322 RNA_define_verify_sdna(false); /* not in sdna */
2323
2324 prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
2325 RNA_def_property_pointer_sdna(prop, nullptr, "layout");
2326 RNA_def_property_struct_type(prop, "UILayout");
2327 RNA_def_property_ui_text(prop, "Layout", "Defines the structure of the menu in the UI");
2328
2329 /* registration */
2330 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2331 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2334 "ID Name",
2335 "If this is set, the menu gets a custom ID, otherwise it takes the "
2336 "name of the class used to define the menu (for example, if the "
2337 "class name is \"OBJECT_MT_hello\", and bl_idname is not set by the "
2338 "script, then bl_idname = \"OBJECT_MT_hello\")");
2339
2340 prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
2341 RNA_def_property_string_sdna(prop, nullptr, "type->label");
2343 RNA_def_property_ui_text(prop, "Label", "The menu label");
2344
2345 prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
2346 RNA_def_property_string_sdna(prop, nullptr, "type->translation_context");
2349
2350 prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE);
2351 RNA_def_property_string_sdna(prop, nullptr, "type->description");
2352 RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
2353 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_Menu_bl_description_set");
2354 // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2356 RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for nullptr */
2357
2358 prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
2359 RNA_def_property_string_sdna(prop, nullptr, "type->owner_id");
2361
2362 prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
2364 RNA_def_property_enum_sdna(prop, nullptr, "type->flag");
2365 RNA_def_property_enum_items(prop, menu_flag_items);
2366 RNA_def_property_ui_text(prop, "Options", "Options for this menu type");
2367
2369}
2370
2372{
2373 StructRNA *srna;
2374 PropertyRNA *prop;
2375
2376 static const EnumPropertyItem asset_shelf_flag_items[] = {
2378 "NO_ASSET_DRAG",
2379 0,
2380 "No Asset Dragging",
2381 "Disable the default asset dragging on drag events. Useful for implementing custom "
2382 "dragging via custom key-map items."},
2384 "DEFAULT_VISIBLE",
2385 0,
2386 "Visible by Default",
2387 "Unhide the asset shelf when it's available for the first time, otherwise it will be "
2388 "hidden"},
2390 "STORE_ENABLED_CATALOGS_IN_PREFERENCES",
2391 0,
2392 "Store Enabled Catalogs in Preferences",
2393 "Store the shelf's enabled catalogs in the preferences rather than the local asset shelf "
2394 "settings"},
2396 "ACTIVATE_FOR_CONTEXT_MENU",
2397 0,
2398 "",
2399 "When spawning a context menu for an asset, activate the asset and call "
2400 "`bl_activate_operator` if present, rather than just highlighting the asset"},
2401 {0, nullptr, 0, nullptr, nullptr},
2402 };
2403
2404 srna = RNA_def_struct(brna, "AssetShelf", nullptr);
2405 RNA_def_struct_ui_text(srna, "Asset Shelf", "Regions for quick access to assets");
2406 RNA_def_struct_refine_func(srna, "rna_AssetShelf_refine");
2408 srna, "rna_AssetShelf_register", "rna_AssetShelf_unregister", nullptr);
2411
2412 /* registration */
2413
2414 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2415 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2418 "ID Name",
2419 "If this is set, the asset gets a custom ID, otherwise it takes the "
2420 "name of the class used to define the asset (for example, if the "
2421 "class name is \"OBJECT_AST_hello\", and bl_idname is not set by the "
2422 "script, then bl_idname = \"OBJECT_AST_hello\")");
2423
2424 prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
2425 RNA_def_property_enum_sdna(prop, nullptr, "type->space_type");
2429 "Space Type",
2430 "The space where the asset shelf will show up in. Ignored for popup "
2431 "asset shelves which can be displayed in any space.");
2432
2433 prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
2435 RNA_def_property_enum_sdna(prop, nullptr, "type->flag");
2436 RNA_def_property_enum_items(prop, asset_shelf_flag_items);
2437 RNA_def_property_ui_text(prop, "Options", "Options for this asset shelf type");
2438
2439 prop = RNA_def_property(srna, "bl_activate_operator", PROP_STRING, PROP_NONE);
2441 "rna_AssetShelf_activate_operator_get",
2442 "rna_AssetShelf_activate_operator_length",
2443 "rna_AssetShelf_activate_operator_set");
2446 prop,
2447 "Activate Operator",
2448 "Operator to call when activating an item with asset reference properties");
2449
2450 prop = RNA_def_property(srna, "bl_drag_operator", PROP_STRING, PROP_NONE);
2452 "rna_AssetShelf_drag_operator_get",
2453 "rna_AssetShelf_drag_operator_length",
2454 "rna_AssetShelf_drag_operator_set");
2457 prop,
2458 "Drag Operator",
2459 "Operator to call when dragging an item with asset reference properties");
2460
2461 prop = RNA_def_property(srna, "bl_default_preview_size", PROP_INT, PROP_UNSIGNED);
2462 RNA_def_property_int_sdna(prop, nullptr, "type->default_preview_size");
2463 RNA_def_property_range(prop, 32, 256);
2466 prop, "Default Preview Size", "Default size of the asset preview thumbnails in pixels");
2467
2468 for (uint i = 0; rna_enum_id_type_filter_items[i].identifier; i++) {
2470
2472 RNA_def_property_boolean_sdna(prop, nullptr, "type->id_types_prefilter", item->flag);
2473 RNA_def_property_ui_text(prop, item->name, item->description);
2474 RNA_def_property_ui_icon(prop, item->icon, 0);
2476 }
2477
2478 PropertyRNA *parm;
2479 FunctionRNA *func;
2480
2481 func = RNA_def_function(srna, "poll", nullptr);
2483 func, "If this method returns a non-null output, the asset shelf will be visible");
2485 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
2486 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2488
2489 func = RNA_def_function(srna, "asset_poll", nullptr);
2491 func,
2492 "Determine if an asset should be visible in the asset shelf. If this method returns a "
2493 "non-null output, the asset will be visible.");
2495 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
2496 parm = RNA_def_pointer(
2497 func, "asset", "AssetRepresentation", "", "The asset to test for visibility");
2499
2500 func = RNA_def_function(srna, "get_active_asset", nullptr);
2502 func,
2503 "Return a reference to the asset that should be highlighted as active in the asset shelf");
2505 /* return type */
2506 parm = RNA_def_pointer(func,
2507 "asset_reference",
2508 "AssetWeakReference",
2509 "",
2510 "The weak reference to the asset to be highlighted as active, or None");
2511 RNA_def_function_return(func, parm);
2512
2513 func = RNA_def_function(srna, "draw_context_menu", nullptr);
2515 func, "Draw UI elements into the context menu UI layout displayed on right click");
2517 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2519 parm = RNA_def_pointer(func, "asset", "AssetRepresentation", "", "The active asset");
2521 parm = RNA_def_pointer(func, "layout", "UILayout", "", "The layout to draw into");
2523
2525 srna, "rna_AssetShelf_asset_library_get", "rna_AssetShelf_asset_library_set");
2527 prop, "Asset Library", "Choose the asset library to display assets from");
2529
2530 prop = RNA_def_property(srna, "show_names", PROP_BOOLEAN, PROP_NONE);
2531 RNA_def_property_boolean_sdna(prop, nullptr, "settings.display_flag", ASSETSHELF_SHOW_NAMES);
2533 "Show Names",
2534 "Show the asset name together with the preview. Otherwise only the "
2535 "preview will be visible.");
2537
2538 prop = RNA_def_property(srna, "preview_size", PROP_INT, PROP_UNSIGNED);
2539 RNA_def_property_int_sdna(prop, nullptr, "settings.preview_size");
2540 RNA_def_property_range(prop, 24, 256);
2541 RNA_def_property_int_default_func(prop, "rna_AssetShelf_preview_size_default");
2542 RNA_def_property_ui_text(prop, "Preview Size", "Size of the asset preview thumbnails in pixels");
2544
2545 prop = RNA_def_property(srna, "search_filter", PROP_STRING, PROP_NONE);
2546 RNA_def_property_string_sdna(prop, nullptr, "settings.search_string");
2547 RNA_def_property_ui_text(prop, "Display Filter", "Filter assets by name");
2550}
2551
2553{
2554 StructRNA *srna;
2555 PropertyRNA *prop;
2556
2557 srna = RNA_def_struct(brna, "FileHandler", nullptr);
2559 "File Handler Type",
2560 "Extends functionality to operators that manages files, such as adding "
2561 "drag and drop support");
2562 RNA_def_struct_refine_func(srna, "rna_FileHandler_refine");
2564 srna, "rna_FileHandler_register", "rna_FileHandler_unregister", nullptr);
2565
2568
2569 /* registration */
2570
2571 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2572 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2575 prop,
2576 "ID Name",
2577 "If this is set, the file handler gets a custom ID, otherwise it takes the "
2578 "name of the class used to define the file handler (for example, if the "
2579 "class name is \"OBJECT_FH_hello\", and bl_idname is not set by the "
2580 "script, then bl_idname = \"OBJECT_FH_hello\")");
2581
2582 prop = RNA_def_property(srna, "bl_import_operator", PROP_STRING, PROP_NONE);
2583 RNA_def_property_string_sdna(prop, nullptr, "type->import_operator");
2586 prop,
2587 "Operator",
2588 "Operator that can handle import for files with the extensions given in bl_file_extensions");
2589 prop = RNA_def_property(srna, "bl_export_operator", PROP_STRING, PROP_NONE);
2590 RNA_def_property_string_sdna(prop, nullptr, "type->export_operator");
2593 prop,
2594 "Operator",
2595 "Operator that can handle export for files with the extensions given in bl_file_extensions");
2596
2597 prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
2598 RNA_def_property_string_sdna(prop, nullptr, "type->label");
2600 RNA_def_property_ui_text(prop, "Label", "The file handler label");
2601
2602 prop = RNA_def_property(srna, "bl_file_extensions", PROP_STRING, PROP_NONE);
2603 RNA_def_property_string_sdna(prop, nullptr, "type->file_extensions_str");
2606 prop,
2607 "File Extensions",
2608 "Formatted string of file extensions supported by the file handler, each extension should "
2609 "start with a \".\" and be separated by \";\"."
2610 "\nFor Example: ``\".blend;.ble\"``");
2611
2612 PropertyRNA *parm;
2613 FunctionRNA *func;
2614
2615 func = RNA_def_function(srna, "poll_drop", nullptr);
2617 func,
2618 "If this method returns True, can be used to handle the drop of a drag-and-drop action");
2620 RNA_def_function_return(func, RNA_def_boolean(func, "is_usable", false, "", ""));
2621 parm = RNA_def_pointer(func, "context", "Context", "", "The context");
2623
2624 func = RNA_def_function(srna, "label_with_extensions", "rna_FileHandler_label_with_extensions");
2626 func, "Return the label of the file handler with the given ID, with its file extensions");
2628 parm = RNA_def_string(func, "idname", nullptr, sizeof(bke::FileHandlerType::idname), "", "");
2630 parm = RNA_def_string(
2631 func, "result", nullptr, FH_MAX_FILE_EXTENSIONS_STR + OP_MAX_TYPENAME + 3, "result", "");
2633 RNA_def_function_output(func, parm);
2634}
2635
2637{
2638 StructRNA *srna;
2639 PropertyRNA *prop;
2640
2641 srna = RNA_def_struct(brna, "LayoutPanelState", nullptr);
2642
2643 prop = RNA_def_property(srna, "is_open", PROP_BOOLEAN, PROP_NONE);
2645 RNA_def_property_ui_text(prop, "Is Open", "");
2646}
2647
2649{
2650 StructRNA *srna = RNA_def_struct(brna, "TextboxState", nullptr);
2651 RNA_def_struct_sdna(srna, "TextboxState");
2652 PropertyRNA *prop;
2653 prop = RNA_def_property(srna, "visible_lines", PROP_INT, PROP_NONE);
2655 prop = RNA_def_property(srna, "scroll", PROP_INT, PROP_NONE);
2657}
2658
2660{
2661 rna_def_ui_layout(brna);
2662 rna_def_panel(brna);
2663 rna_def_uilist(brna);
2664 rna_def_header(brna);
2665 rna_def_menu(brna);
2666 rna_def_asset_shelf(brna);
2670}
2671
2672} // namespace blender
2673
2674#endif /* RNA_RUNTIME */
#define FH_MAX_FILE_EXTENSIONS_STR
#define ASSET_SHELF_PREVIEW_SIZE_DEFAULT
A dynamically sized string ADT.
#define RPT_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
#define PNL_CATEGORY_FALLBACK
#define OP_MAX_TYPENAME
Read Blender memory allocation and freeing.
#define RNA_DYN_DESCR_MAX
#define C
Definition RandGen.cpp:29
#define WM_TOOLSYSTEM_SPACE_MASK
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_REGIONS_ASSET_SHELF
Definition WM_types.hh:586
#define NC_SPACE
Definition WM_types.hh:405
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define offsetof(t, d)
#define str(s)
#define INT_MAX
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
void free(Subdiv *subdiv)
Definition subdiv.cc:192
FileHandlerType * file_handler_find(StringRef idname)
void file_handler_add(std::unique_ptr< FileHandlerType > file_handler)
void file_handler_remove(FileHandlerType *file_handler)
AssetShelfType * type_find_from_idname(StringRef idname)
void type_unregister(const AssetShelfType &shelf_type)
void type_unlink(const Main &bmain, const AssetShelfType &shelf_type)
void type_register(std::unique_ptr< AssetShelfType > type)
int library_reference_to_enum_value(const AssetLibraryReference *library)
AssetLibraryReference library_reference_from_enum_value(int value)
void panels_free_instanced(const bContext *C, ARegion *region)
void refresh_for_srna_unregister(Main *bmain, StructRNA *srna_to_unreg)
bool uilist_item_index_is_filtered_visible(const struct uiList *ui_list, int item_idx)
PointerRNA * panel_custom_data_get(const Panel *panel)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void * BLI_findptr(const ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:710
PropertyRNA * RNA_function_find_parameter(PointerRNA *, FunctionRNA *func, const char *identifier)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
const char * WM_uilisttype_list_id_get(const uiListType *ult, uiList *list)
@ LAYOUT_PANEL_STATE_FLAG_OPEN
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
char * STRNCPY(char(&dst)[N], const char *src)
void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **r_value)
static void rna_def_layout_panel_state(BlenderRNA *brna)
Definition rna_ui.cc:2636
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
int(*)(PointerRNA *ptr, void *data, bool *have_function) StructValidateFunc
void RNA_def_ui(BlenderRNA *brna)
Definition rna_ui.cc:2659
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_function_output(FunctionRNA *, PropertyRNA *ret)
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
@ STRUCT_PUBLIC_NAMESPACE_INHERIT
@ STRUCT_NO_IDPROPERTIES
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
bool WM_paneltype_add(PanelType *pt)
const EnumPropertyItem rna_enum_space_type_items[]
Definition rna_space.cc:91
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
static void rna_def_header(BlenderRNA *brna)
Definition rna_ui.cc:2223
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_struct_system_idprops_func(StructRNA *srna, const char *system_idproperties)
bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
static void rna_def_panel(BlenderRNA *brna)
Definition rna_ui.cc:1842
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
const char * RNA_struct_state_owner_get()
@ FUNC_NO_SELF
Definition RNA_types.hh:998
@ FUNC_REGISTER_OPTIONAL
@ FUNC_REGISTER
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void * RNA_struct_blender_type_get(StructRNA *srna)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
static void rna_def_asset_shelf(BlenderRNA *brna)
Definition rna_ui.cc:2371
const IDFilterEnumPropertyItem rna_enum_id_type_filter_items[]
Definition rna_ID.cc:126
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
ParameterList * RNA_parameter_list_create(ParameterList *parms, PointerRNA *, FunctionRNA *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
static void rna_def_ui_layout(BlenderRNA *brna)
Definition rna_ui.cc:1696
bool BKE_regiontype_uses_categories(const ARegionType *region_type)
Definition screen.cc:398
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
PropertyRNA * rna_def_asset_library_ui_reference_common(StructRNA *srna, const char *get, const char *set)
Definition rna_asset.cc:896
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:339
@ UILST_FLT_ITEM_NEVER_SHOW
const EnumPropertyItem rna_enum_operator_context_items[]
Definition rna_ui.cc:36
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
int RNA_parameter_dynamic_length_get(ParameterList *parms, PropertyRNA *parm)
static void rna_def_uilist(BlenderRNA *brna)
Definition rna_ui.cc:2047
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
LinkData * BLI_genericNodeN(void *data)
Definition listbase.cc:936
static void rna_def_menu(BlenderRNA *brna)
Definition rna_ui.cc:2282
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
SpaceType * BKE_spacetype_from_id(int spaceid)
Definition screen.cc:354
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void(*)(void *data) StructFreeFunc
void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg, const char *instance)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **r_value)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
static void rna_def_ui_textbox_state(BlenderRNA *brna)
Definition rna_ui.cc:2648
const EnumPropertyItem rna_enum_region_type_items[]
Definition rna_screen.cc:28
bool WM_uilisttype_add(uiListType *ult)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
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)
bool RNA_struct_bl_idname_ok_or_report(ReportList *reports, const char *identifier, const char *sep)
void RNA_def_struct_flag(StructRNA *srna, StructFlag flag)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
static void rna_def_file_handler(BlenderRNA *brna)
Definition rna_ui.cc:2552
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void RNA_api_ui_layout(StructRNA *srna)
void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
@ PANEL_TYPE_HEADER_EXPAND
@ PANEL_TYPE_DEFAULT_CLOSED
@ PANEL_TYPE_NO_HEADER
@ PANEL_TYPE_INSTANCED
@ ASSET_SHELF_TYPE_FLAG_STORE_CATALOGS_IN_PREFS
@ ASSET_SHELF_TYPE_FLAG_ACTIVATE_FOR_CONTEXT_MENU
@ ASSET_SHELF_TYPE_FLAG_NO_ASSET_DRAG
@ ASSET_SHELF_TYPE_FLAG_DEFAULT_VISIBLE
bool WM_menutype_add(MenuType *mt)
const EnumPropertyItem rna_enum_uilist_layout_type_items[]
Definition rna_ui.cc:53
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ PROP_TEXTEDIT_UPDATE
Definition RNA_types.hh:396
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_ENUM_FLAG
Definition RNA_types.hh:474
@ PROP_DYNAMIC
Definition RNA_types.hh:498
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_REGISTER_OPTIONAL
Definition RNA_types.hh:482
@ PROP_REGISTER
Definition RNA_types.hh:481
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
uiListType * WM_uilisttype_find(const StringRef idname, bool quiet)
bScreen * CTX_wm_screen(const bContext *C)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_define_verify_sdna(bool verify)
void WM_paneltype_remove(PanelType *pt)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_UNSIGNED
Definition RNA_types.hh:306
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_PYFUNC_REGISTER_OPTIONAL
Definition RNA_types.hh:643
@ PARM_RNAPTR
Definition RNA_types.hh:633
const EnumPropertyItem rna_enum_icon_items[]
Definition rna_ui_api.cc:30
void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *rna_ext)
wm::OpCallContext wmOpCallContext
Definition rna_ui.cc:33
void RNA_def_property_int_default_func(PropertyRNA *prop, const char *get_default)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
int(*)(bContext *C, PointerRNA *ptr, FunctionRNA *func, ParameterList *list) StructCallbackFunc
void WM_uilisttype_remove_ptr(Main *bmain, uiListType *ult)
void RNA_parameter_list_free(ParameterList *parms)
void WM_menutype_freelink(MenuType *mt)
int RNA_collection_length(PointerRNA *ptr, const char *name)
BlenderRNA RNA_blender_rna_get()
StructRNA * RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
struct AssetShelfType * type
bke::FileHandlerType * type
ExtensionRNA rna_ext
HeaderType * type
ExtensionRNA rna_ext
const char * description
MenuType * type
PanelType * parent
const char * description
ExtensionRNA rna_ext
struct PanelType * type
ListBaseT< Panel > children
StructRNA * type
Definition RNA_types.hh:63
ExtensionRNA rna_ext
IDProperty * properties
struct uiListType * type
static constexpr float PROPERTY_SPLIT_FACTOR