Interface: Free argument callback for popups
Reviewers: brecht Differential Revision: https://developer.blender.org/D4858
This commit is contained in:
@@ -594,9 +594,16 @@ struct uiLayout *UI_pie_menu_layout(struct uiPieMenu *pie);
|
||||
typedef uiBlock *(*uiBlockCreateFunc)(struct bContext *C, struct ARegion *ar, void *arg1);
|
||||
typedef void (*uiBlockCancelFunc)(struct bContext *C, void *arg1);
|
||||
|
||||
void UI_popup_block_invoke(struct bContext *C, uiBlockCreateFunc func, void *arg);
|
||||
void UI_popup_block_invoke_ex(
|
||||
struct bContext *C, uiBlockCreateFunc func, void *arg, const char *opname, int opcontext);
|
||||
void UI_popup_block_invoke(struct bContext *C,
|
||||
uiBlockCreateFunc func,
|
||||
void *arg,
|
||||
void (*arg_free)(void *arg));
|
||||
void UI_popup_block_invoke_ex(struct bContext *C,
|
||||
uiBlockCreateFunc func,
|
||||
void *arg,
|
||||
void (*arg_free)(void *arg),
|
||||
const char *opname,
|
||||
int opcontext);
|
||||
void UI_popup_block_ex(struct bContext *C,
|
||||
uiBlockCreateFunc func,
|
||||
uiBlockHandleFunc popup_func,
|
||||
|
||||
@@ -266,7 +266,7 @@ static void menu_add_shortcut_cancel(struct bContext *C, void *arg1)
|
||||
static void popup_change_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2))
|
||||
{
|
||||
uiBut *but = (uiBut *)arg1;
|
||||
UI_popup_block_invoke(C, menu_change_shortcut, but);
|
||||
UI_popup_block_invoke(C, menu_change_shortcut, but, NULL);
|
||||
}
|
||||
|
||||
static void remove_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2))
|
||||
|
||||
@@ -3785,7 +3785,7 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat
|
||||
}
|
||||
|
||||
if (func || handlefunc) {
|
||||
data->menu = ui_popup_block_create(C, data->region, but, func, handlefunc, arg);
|
||||
data->menu = ui_popup_block_create(C, data->region, but, func, handlefunc, arg, NULL);
|
||||
if (but->block->handle) {
|
||||
data->menu->popup = but->block->handle->popup;
|
||||
}
|
||||
|
||||
@@ -539,13 +539,12 @@ struct uiKeyNavLock {
|
||||
typedef uiBlock *(*uiBlockHandleCreateFunc)(struct bContext *C,
|
||||
struct uiPopupBlockHandle *handle,
|
||||
void *arg1);
|
||||
typedef void (*uiBlockHandleFreeFunc)(struct uiPopupBlockHandle *handle, void *arg1);
|
||||
|
||||
struct uiPopupBlockCreate {
|
||||
uiBlockCreateFunc create_func;
|
||||
uiBlockHandleCreateFunc handle_create_func;
|
||||
uiBlockHandleFreeFunc free_func;
|
||||
void *arg;
|
||||
void (*arg_free)(void *arg);
|
||||
|
||||
int event_xy[2];
|
||||
|
||||
@@ -662,7 +661,8 @@ uiPopupBlockHandle *ui_popup_block_create(struct bContext *C,
|
||||
uiBut *but,
|
||||
uiBlockCreateFunc create_func,
|
||||
uiBlockHandleCreateFunc handle_create_func,
|
||||
void *arg);
|
||||
void *arg,
|
||||
void (*arg_free)(void *arg));
|
||||
uiPopupBlockHandle *ui_popup_menu_create(struct bContext *C,
|
||||
struct ARegion *butregion,
|
||||
uiBut *but,
|
||||
|
||||
@@ -208,7 +208,7 @@ void UI_pie_menu_end(bContext *C, uiPieMenu *pie)
|
||||
wmWindow *window = CTX_wm_window(C);
|
||||
uiPopupBlockHandle *menu;
|
||||
|
||||
menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PIE, pie);
|
||||
menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PIE, pie, NULL);
|
||||
menu->popup = true;
|
||||
menu->towardstime = PIL_check_seconds_timer();
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ uiPopupBlockHandle *ui_popup_menu_create(
|
||||
pup->menu_func = menu_func;
|
||||
pup->menu_arg = arg;
|
||||
|
||||
handle = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup);
|
||||
handle = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup, NULL);
|
||||
|
||||
if (!but) {
|
||||
handle->popup = true;
|
||||
@@ -463,7 +463,7 @@ void UI_popup_menu_end(bContext *C, uiPopupMenu *pup)
|
||||
butregion = pup->butregion;
|
||||
}
|
||||
|
||||
menu = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup);
|
||||
menu = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup, NULL);
|
||||
menu->popup = true;
|
||||
|
||||
UI_popup_handlers_add(C, &window->modalhandlers, menu, 0);
|
||||
@@ -581,13 +581,17 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports)
|
||||
/** \name Popup Block API
|
||||
* \{ */
|
||||
|
||||
void UI_popup_block_invoke_ex(
|
||||
bContext *C, uiBlockCreateFunc func, void *arg, const char *opname, int opcontext)
|
||||
void UI_popup_block_invoke_ex(bContext *C,
|
||||
uiBlockCreateFunc func,
|
||||
void *arg,
|
||||
void (*arg_free)(void *arg),
|
||||
const char *opname,
|
||||
int opcontext)
|
||||
{
|
||||
wmWindow *window = CTX_wm_window(C);
|
||||
uiPopupBlockHandle *handle;
|
||||
|
||||
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg);
|
||||
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg, arg_free);
|
||||
handle->popup = true;
|
||||
handle->can_refresh = true;
|
||||
handle->optype = (opname) ? WM_operatortype_find(opname, 0) : NULL;
|
||||
@@ -598,9 +602,12 @@ void UI_popup_block_invoke_ex(
|
||||
WM_event_add_mousemove(C);
|
||||
}
|
||||
|
||||
void UI_popup_block_invoke(bContext *C, uiBlockCreateFunc func, void *arg)
|
||||
void UI_popup_block_invoke(bContext *C,
|
||||
uiBlockCreateFunc func,
|
||||
void *arg,
|
||||
void (*arg_free)(void *arg))
|
||||
{
|
||||
UI_popup_block_invoke_ex(C, func, arg, NULL, WM_OP_INVOKE_DEFAULT);
|
||||
UI_popup_block_invoke_ex(C, func, arg, arg_free, NULL, WM_OP_INVOKE_DEFAULT);
|
||||
}
|
||||
|
||||
void UI_popup_block_ex(bContext *C,
|
||||
@@ -613,7 +620,7 @@ void UI_popup_block_ex(bContext *C,
|
||||
wmWindow *window = CTX_wm_window(C);
|
||||
uiPopupBlockHandle *handle;
|
||||
|
||||
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg);
|
||||
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg, NULL);
|
||||
handle->popup = true;
|
||||
handle->retvalue = 1;
|
||||
handle->can_refresh = true;
|
||||
@@ -635,7 +642,7 @@ void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int
|
||||
wmWindow *window = CTX_wm_window(C);
|
||||
uiPopupBlockHandle *handle;
|
||||
|
||||
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, op);
|
||||
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, op, NULL);
|
||||
handle->popup = 1;
|
||||
handle->retvalue = 1;
|
||||
handle->can_refresh = true;
|
||||
|
||||
@@ -244,7 +244,7 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v
|
||||
return block;
|
||||
}
|
||||
|
||||
static void ui_block_free_func_POPOVER(uiPopupBlockHandle *UNUSED(handle), void *arg_pup)
|
||||
static void ui_block_free_func_POPOVER(void *arg_pup)
|
||||
{
|
||||
uiPopover *pup = arg_pup;
|
||||
if (pup->keymap != NULL) {
|
||||
@@ -282,8 +282,8 @@ uiPopupBlockHandle *ui_popover_panel_create(
|
||||
|
||||
/* Create popup block. */
|
||||
uiPopupBlockHandle *handle;
|
||||
handle = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPOVER, pup);
|
||||
handle->popup_create_vars.free_func = ui_block_free_func_POPOVER;
|
||||
handle = ui_popup_block_create(
|
||||
C, butregion, but, NULL, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER);
|
||||
handle->can_refresh = true;
|
||||
|
||||
/* Add handlers. If attached to a button, the button will already
|
||||
@@ -386,8 +386,8 @@ void UI_popover_end(bContext *C, uiPopover *pup, wmKeyMap *keymap)
|
||||
WM_event_set_keymap_handler_post_callback(pup->keymap_handler, popover_keymap_fn, pup);
|
||||
}
|
||||
|
||||
handle = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_POPOVER, pup);
|
||||
handle->popup_create_vars.free_func = ui_block_free_func_POPOVER;
|
||||
handle = ui_popup_block_create(
|
||||
C, NULL, NULL, NULL, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER);
|
||||
|
||||
/* Add handlers. */
|
||||
UI_popup_handlers_add(C, &window->modalhandlers, handle, 0);
|
||||
|
||||
@@ -748,7 +748,8 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C,
|
||||
uiBut *but,
|
||||
uiBlockCreateFunc create_func,
|
||||
uiBlockHandleCreateFunc handle_create_func,
|
||||
void *arg)
|
||||
void *arg,
|
||||
void (*arg_free)(void *arg))
|
||||
{
|
||||
wmWindow *window = CTX_wm_window(C);
|
||||
uiBut *activebut = UI_context_active_but_get(C);
|
||||
@@ -775,6 +776,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C,
|
||||
handle->popup_create_vars.create_func = create_func;
|
||||
handle->popup_create_vars.handle_create_func = handle_create_func;
|
||||
handle->popup_create_vars.arg = arg;
|
||||
handle->popup_create_vars.arg_free = arg_free;
|
||||
handle->popup_create_vars.but = but;
|
||||
handle->popup_create_vars.butregion = but ? butregion : NULL;
|
||||
copy_v2_v2_int(handle->popup_create_vars.event_xy, &window->eventstate->x);
|
||||
@@ -820,8 +822,8 @@ void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle)
|
||||
}
|
||||
}
|
||||
|
||||
if (handle->popup_create_vars.free_func) {
|
||||
handle->popup_create_vars.free_func(handle, handle->popup_create_vars.arg);
|
||||
if (handle->popup_create_vars.arg_free) {
|
||||
handle->popup_create_vars.arg_free(handle->popup_create_vars.arg);
|
||||
}
|
||||
|
||||
ui_popup_block_remove(C, handle);
|
||||
|
||||
@@ -1188,7 +1188,7 @@ static uiBlock *node_find_menu(bContext *C, ARegion *ar, void *arg_op)
|
||||
|
||||
static int node_find_node_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
{
|
||||
UI_popup_block_invoke(C, node_find_menu, op);
|
||||
UI_popup_block_invoke(C, node_find_menu, op, NULL);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
|
||||
@@ -2810,7 +2810,7 @@ void wm_test_autorun_warning(bContext *C)
|
||||
if (win) {
|
||||
wmWindow *prevwin = CTX_wm_window(C);
|
||||
CTX_wm_window_set(C, win);
|
||||
UI_popup_block_invoke(C, block_create_autorun_warning, NULL);
|
||||
UI_popup_block_invoke(C, block_create_autorun_warning, NULL, NULL);
|
||||
CTX_wm_window_set(C, prevwin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -870,7 +870,7 @@ int WM_enum_search_invoke_previews(bContext *C, wmOperator *op, short prv_cols,
|
||||
search_menu.prv_cols = prv_cols;
|
||||
search_menu.prv_rows = prv_rows;
|
||||
|
||||
UI_popup_block_invoke(C, wm_enum_search_menu, &search_menu);
|
||||
UI_popup_block_invoke(C, wm_enum_search_menu, &search_menu, NULL);
|
||||
|
||||
return OPERATOR_INTERFACE;
|
||||
}
|
||||
@@ -879,7 +879,7 @@ int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(eve
|
||||
{
|
||||
static struct EnumSearchMenu search_menu;
|
||||
search_menu.op = op;
|
||||
UI_popup_block_invoke(C, wm_enum_search_menu, &search_menu);
|
||||
UI_popup_block_invoke(C, wm_enum_search_menu, &search_menu, NULL);
|
||||
return OPERATOR_INTERFACE;
|
||||
}
|
||||
|
||||
@@ -1402,7 +1402,7 @@ int WM_operator_redo_popup(bContext *C, wmOperator *op)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
UI_popup_block_invoke(C, wm_block_create_redo, op);
|
||||
UI_popup_block_invoke(C, wm_block_create_redo, op, NULL);
|
||||
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
@@ -1714,7 +1714,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
|
||||
|
||||
static int wm_splash_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
|
||||
{
|
||||
UI_popup_block_invoke(C, wm_block_create_splash, NULL);
|
||||
UI_popup_block_invoke(C, wm_block_create_splash, NULL, NULL);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
@@ -1820,7 +1820,7 @@ static int wm_search_menu_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv
|
||||
data.size[0] = UI_searchbox_size_x() * 2;
|
||||
data.size[1] = UI_searchbox_size_y();
|
||||
|
||||
UI_popup_block_invoke(C, wm_block_search_menu, &data);
|
||||
UI_popup_block_invoke(C, wm_block_search_menu, &data, NULL);
|
||||
|
||||
return OPERATOR_INTERFACE;
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ static void wm_confirm_quit(bContext *C)
|
||||
|
||||
if (GHOST_SupportsNativeDialogs() == 0) {
|
||||
if (!UI_popup_block_name_exists(C, "confirm_quit_popup")) {
|
||||
UI_popup_block_invoke(C, block_create_confirm_quit, NULL);
|
||||
UI_popup_block_invoke(C, block_create_confirm_quit, NULL, NULL);
|
||||
}
|
||||
}
|
||||
else if (GHOST_confirmQuit(win->ghostwin)) {
|
||||
|
||||
Reference in New Issue
Block a user