44 #include "RNA_prototypes.h"
145 const uint str_size = strlen(
str) + 1;
147 memcpy(str_dst,
str, str_size);
162 const char *drawstr_submenu,
169 const char *drawstr_override =
nullptr;
173 const bool drawstr_is_empty = (drawstr_sep == but->
drawstr) || (but->
drawstr[0] ==
'\0');
175 if (but->
optype !=
nullptr) {
176 if (drawstr_is_empty) {
181 item->
type = MenuSearch_Item::Type::Operator;
187 but->
opptr =
nullptr;
189 else if (but->
rnaprop !=
nullptr) {
192 if (drawstr_is_empty) {
194 const int value_enum = (int)but->
hardmax;
201 drawstr_override = enum_item.name;
205 drawstr_override =
"Unknown";
216 printf(
"Button '%s' in menu '%s' is a menu item with unsupported RNA type %d\n",
223 item->
type = MenuSearch_Item::Type::RNA;
235 if (item !=
nullptr) {
237 if (drawstr_override !=
nullptr) {
238 const char *drawstr_suffix = drawstr_sep ? drawstr_sep :
"";
239 std::string drawstr = std::string(
"(") + drawstr_override +
")" + drawstr_suffix;
266 bool changed =
false;
267 switch (item->
type) {
268 case MenuSearch_Item::Type::Operator: {
276 case MenuSearch_Item::Type::RNA: {
319 region ? ®ion->
handlers :
nullptr,
324 for (
int handler_index = 0; handler_index <
ARRAY_SIZE(handlers); handler_index++) {
325 if (handlers[handler_index] ==
nullptr) {
337 if (handler_base->poll ==
nullptr || handler_base->poll(region, win->
eventstate)) {
341 for (
int km_index = 0; km_index < km_result.
keymaps_len; km_index++) {
348 if (
STR_ELEM(kmi->idname,
"WM_OT_call_menu",
"WM_OT_call_menu_pie")) {
377 ListBase operator_items = {
nullptr,
nullptr};
394 item->
type = MenuSearch_Item::Type::Operator;
398 item->
op.context =
nullptr;
452 const char *idname_array[] = {
454 "TOPBAR_MT_file_open_recent",
457 "TOPBAR_MT_undo_history",
459 for (
int i = 0; i <
ARRAY_SIZE(idname_array); i++) {
483 const char *idname_array[] = {
485 "OUTLINER_MT_context_menu",
487 for (
int i = 0; i <
ARRAY_SIZE(idname_array); i++) {
499 int space_type_ui_items_len = 0;
500 bool space_type_ui_items_free =
false;
503 const char *global_menu_prefix =
nullptr;
505 if (include_all_areas) {
512 ScrArea area_dummy = {
nullptr};
522 &space_type_ui_items,
523 &space_type_ui_items_len,
524 &space_type_ui_items_free);
527 memarena,
sizeof(*wm_contexts) * space_type_ui_items_len);
528 for (
int i = 0; i < space_type_ui_items_len; i++) {
535 if (region !=
nullptr) {
541 if (space_type_ui_index == -1) {
545 if (wm_contexts[space_type_ui_index].space_type_ui_index != -1) {
546 ScrArea *area_best = wm_contexts[space_type_ui_index].
area;
549 if (value_best > value_test) {
555 wm_contexts[space_type_ui_index].
area =
area;
556 wm_contexts[space_type_ui_index].
region = region;
565 for (
int space_type_ui_index = -1; space_type_ui_index < space_type_ui_items_len;
566 space_type_ui_index += 1) {
572 if (include_all_areas) {
573 if (space_type_ui_index == -1) {
575 wm_context =
nullptr;
580 wm_context = &wm_contexts[space_type_ui_index];
586 region = wm_context->
region;
594 region = region_init;
602 const char *idname_array[2] = {
nullptr};
603 int idname_array_len = 0;
606 if (space_type_ui_index == -1) {
607 idname_array[idname_array_len++] =
"TOPBAR_MT_editor_menus";
610 #define SPACE_MENU_MAP(space_type, menu_id) \
612 idname_array[idname_array_len++] = menu_id; \
614 #define SPACE_MENU_NOP(space_type) \
618 if (
area !=
nullptr) {
632 "TIME_MT_editor_menus" :
633 "DOPESHEET_MT_editor_menus");
640 "CLIP_MT_tracking_editor_menus" :
641 "CLIP_MT_masking_editor_menus");
649 for (
int i = 0; i < idname_array_len; i++) {
659 #undef SPACE_MENU_MAP
660 #undef SPACE_MENU_NOP
662 bool has_keymap_menu_items =
false;
664 while (menu_stack !=
nullptr) {
690 but_test = but_test->
prev;
693 if (but_test ==
nullptr) {
695 menu_display_name_map, mt, (
void *)
strdup_memarena(memarena, but->drawstr));
699 data, memarena, mt,
nullptr, but, wm_context)) {
710 memarena,
sizeof(*menu_parent));
719 bool drawstr_is_empty =
false;
720 if (drawstr_sep !=
nullptr) {
723 const char *drawstr = but->drawstr;
724 int drawstr_len = drawstr_sep - but->drawstr;
727 drawstr_len = strlen(drawstr);
728 if (drawstr[0] ==
'\0') {
729 drawstr_is_empty =
true;
738 const char *drawstr = but->drawstr;
741 if (drawstr[0] ==
'\0') {
742 drawstr_is_empty =
true;
750 if (drawstr_is_empty) {
751 printf(
"Warning: '%s' menu has empty 'bl_label'.\n", mt_from_but->
idname);
755 else if (but->menu_create_func !=
nullptr) {
759 const char *drawstr_submenu = but->drawstr;
770 but->menu_create_func(
C, sub_layout, but->poin);
776 data, memarena, mt, drawstr_submenu, sub_but, wm_context);
794 if ((menu_stack ==
nullptr) && (has_keymap_menu_items ==
false)) {
795 has_keymap_menu_items =
true;
797 C, win,
area, region, &menu_stack, menu_to_kmi, menu_tagged);
819 if (include_all_areas) {
822 (item->wm_context !=
nullptr) ?
823 space_type_ui_items[item->wm_context->space_type_ui_index].
name :
827 if (item->menu_parent !=
nullptr) {
830 while (menu_parent && menu_parent->
parent) {
832 menu_parent = menu_parent->
parent;
834 while (menu_parent) {
841 const char *drawstr = (
const char *)
BLI_ghash_lookup(menu_display_name_map, item->mt);
842 if (drawstr ==
nullptr) {
843 drawstr =
CTX_IFACE_(item->mt->translation_context, item->mt->label);
848 if (kmi !=
nullptr) {
858 if (item->drawstr_submenu !=
nullptr) {
882 data->memarena = memarena;
884 if (include_all_areas) {
888 if (space_type_ui_items_free) {
915 switch (item->type) {
916 case MenuSearch_Item::Type::Operator: {
917 if (item->op.opptr !=
nullptr) {
922 case MenuSearch_Item::Type::RNA: {
936 if (item ==
nullptr) {
951 switch (item->
type) {
952 case MenuSearch_Item::Type::Operator: {
955 C, item->
op.type, item->
op.opcontext, item->
op.opptr,
nullptr, item->
drawstr);
959 case MenuSearch_Item::Type::RNA: {
962 const int index = item->
rna.index;
964 bool changed =
false;
1000 const bool UNUSED(is_first))
1013 for (
int i = 0; i < filtered_amount; i++) {
1041 bool has_menu =
false;
1043 memset(&
data->context_menu_data, 0x0,
sizeof(
data->context_menu_data));
1044 uiBut *but = &
data->context_menu_data.but;
1086 memset(&
data->context_menu_data, 0x0,
sizeof(
data->context_menu_data));
1087 uiBut *but = &
data->context_menu_data.but;
1097 tip_init[0] =
event->
xy[0];
1098 tip_init[1] =
event->xy[1] - (
UI_UNIT_Y / 2);
1161 static char search[256] =
"";
1167 block, search, 0, ICON_VIEWZOOM,
sizeof(search), 0, 0,
UI_UNIT_X * 6,
UI_UNIT_Y, 0, 0,
"");
struct ScrArea * CTX_wm_area(const bContext *C)
void CTX_store_set(bContext *C, bContextStore *store)
void CTX_wm_region_set(bContext *C, struct ARegion *region)
struct wmWindowManager * CTX_wm_manager(const bContext *C)
struct ARegion * CTX_wm_region(const bContext *C)
void CTX_wm_area_set(bContext *C, struct ScrArea *area)
struct wmWindow * CTX_wm_window(const bContext *C)
struct ARegion * BKE_area_find_region_type(const struct ScrArea *area, int type)
A dynamically sized string ADT.
void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) ATTR_NONNULL()
int BLI_dynstr_get_len(const DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_dynstr_clear(DynStr *ds) ATTR_NONNULL()
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
DynStr * BLI_dynstr_new_memarena(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
void BLI_dynstr_get_cstring_ex(const DynStr *__restrict ds, char *__restrict rets) ATTR_NONNULL()
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
bool BLI_ghash_haskey(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void BLI_ghashIterator_step(GHashIterator *ghi)
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
#define GHASH_ITER(gh_iter_, ghash_)
GSet * BLI_gset_ptr_new(const char *info)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
GHash * BLI_ghash_ptr_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_ensure_p(GHash *gh, void *key, void ***r_val) ATTR_WARN_UNUSED_RESULT
bool BLI_gset_add(GSet *gs, void *key)
BLI_INLINE bool BLI_ghashIterator_done(const GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
bool BLI_gset_remove(GSet *gs, const void *key, GSetKeyFreeFP keyfreefp)
void void void * BLI_linklist_pop(LinkNode **listp) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void void BLI_linklist_prepend(LinkNode **listp, void *ptr) ATTR_NONNULL(1)
#define LISTBASE_FOREACH(type, var, list)
void void void BLI_movelisttolist(struct ListBase *dst, struct ListBase *src) ATTR_NONNULL(1
void void BLI_listbase_sort(struct ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void unit_m4(float m[4][4])
void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
struct MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
#define BLI_MEMARENA_STD_BUFSIZE
void * BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
void * BLI_memarena_calloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
#define STRNCPY(dst, src)
#define SNPRINTF(dst, format,...)
bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL()
void BLI_string_search_add(StringSearch *search, const char *str, void *user_data, int weight)
void BLI_string_search_free(StringSearch *search)
StringSearch * BLI_string_search_new(void)
int BLI_string_search_query(StringSearch *search, const char *query, void ***r_data)
#define CTX_IFACE_(context, msgid)
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
uiBlock * uiLayoutGetBlock(uiLayout *layout)
const struct uiStyle * UI_style_get_dpi(void)
struct ARegion * UI_tooltip_create_from_button(struct bContext *C, struct ARegion *butregion, uiBut *but, bool is_label)
void UI_menutype_draw(struct bContext *C, struct MenuType *mt, struct uiLayout *layout)
void UI_but_func_search_set(uiBut *but, uiButSearchCreateFn search_create_fn, uiButSearchUpdateFn search_update_fn, void *arg, bool free_arg, uiFreeArgFunc search_arg_free_fn, uiButHandleFunc search_exec_fn, void *active)
bool UI_search_item_add(uiSearchItems *items, const char *name, void *poin, int iconid, int but_flag, uint8_t name_prefix_offset)
void UI_but_func_search_set_tooltip(uiBut *but, uiButSearchTooltipFn tooltip_fn)
void UI_block_end(const struct bContext *C, uiBlock *block)
void UI_but_func_search_set_context_menu(uiBut *but, uiButSearchContextMenuFn context_menu_fn)
uiLayout * UI_block_layout(uiBlock *block, int dir, int type, int x, int y, int size, int em, int padding, const struct uiStyle *style)
struct MenuType * UI_but_menutype_get(uiBut *but)
void UI_block_free(const struct bContext *C, uiBlock *block)
void UI_but_func_search_set_sep_string(uiBut *but, const char *search_sep_string)
uiBlock * UI_block_begin(const struct bContext *C, struct ARegion *region, const char *name, eUIEmbossType emboss)
uiBut * uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxlen, int x, int y, short width, short height, float a1, float a2, const char *tip)
void UI_block_layout_set_current(uiBlock *block, uiLayout *layout)
void UI_block_flag_enable(uiBlock *block, int flag)
void uiLayoutSetOperatorContext(uiLayout *layout, wmOperatorCallContext opcontext)
@ UI_BLOCK_SHOW_SHORTCUT_ALWAYS
@ WM_OP_INVOKE_REGION_WIN
void ui_window_to_block_fl(const ARegion *region, uiBlock *block, float *r_x, float *r_y)
struct ARegion * ui_searchbox_create_menu(struct bContext *C, struct ARegion *butregion, uiButSearch *search_but)
int ui_but_icon(const uiBut *but)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
static void area(int d1, int d2, int e1, int e2, float weights[2])
bool active
all scheduled work for the GPU.
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
bool RNA_property_array_check(PropertyRNA *prop)
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
PropertyType RNA_property_type(PropertyRNA *prop)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
const char * RNA_property_translation_context(const PropertyRNA *prop)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
bool RNA_property_enum_item_from_value_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
const char * RNA_property_ui_name(const PropertyRNA *prop)
#define UI_MENU_ARROW_SEP
struct GHash * block_name_map
char name[UI_MAX_NAME_STR]
wmOperatorCallContext opcontext
struct bContextStore * context
struct PointerRNA * opptr
struct wmOperatorType * optype
char drawstr[UI_MAX_DRAW_STR]
char strdata[UI_MAX_NAME_STR]
struct PropertyRNA * rnaprop
struct PointerRNA rnapoin
const char * translation_context
struct wmEvent * eventstate
bool WM_operator_poll(bContext *C, wmOperatorType *ot)
void WM_event_get_keymaps_from_handler(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
void WM_operator_name_call_ptr_with_depends_on_cursor(bContext *C, wmOperatorType *ot, wmOperatorCallContext opcontext, PointerRNA *properties, const wmEvent *event, const char *drawstr)
int WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact, char *result, const int result_len)
bool WM_keymap_poll(bContext *C, wmKeyMap *keymap)
void WM_operatortype_iter(GHashIterator *ghi)
const char * WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *properties)
size_t WM_operator_py_idname(char *dst, const char *src)
void WM_operator_properties_free(PointerRNA *ptr)
bScreen * WM_window_get_active_screen(const wmWindow *win)