Code cleanup: use typedefs for ui handler functions

This commit is contained in:
2014-06-03 08:58:16 +10:00
parent 9016d6d7a0
commit bf640a6a7f
4 changed files with 36 additions and 26 deletions

View File

@@ -2506,7 +2506,7 @@ void uiPupBlockO(bContext *C, uiBlockCreateFunc func, void *arg, const char *opn
void uiPupBlock(bContext *C, uiBlockCreateFunc func, void *arg)
{
uiPupBlockO(C, func, arg, NULL, 0);
uiPupBlockO(C, func, arg, NULL, WM_OP_INVOKE_DEFAULT);
}
void uiPupBlockEx(bContext *C, uiBlockCreateFunc func, uiBlockHandleFunc popup_func, uiBlockCancelFunc cancel_func, void *arg)

View File

@@ -145,19 +145,22 @@ struct wmEventHandler *WM_event_add_keymap_handler_priority(ListBase *handlers,
void WM_event_remove_keymap_handler(ListBase *handlers, wmKeyMap *keymap);
typedef int (*wmUIHandlerFunc)(struct bContext *C, const struct wmEvent *event, void *userdata);
typedef void (*wmUIHandlerRemoveFunc)(struct bContext *C, void *userdata);
struct wmEventHandler *WM_event_add_ui_handler(
const struct bContext *C, ListBase *handlers,
int (*func)(struct bContext *C, const struct wmEvent *event, void *userdata),
void (*remove)(struct bContext *C, void *userdata), void *userdata);
void WM_event_remove_ui_handler(ListBase *handlers,
int (*func)(struct bContext *C, const struct wmEvent *event, void *userdata),
void (*remove)(struct bContext *C, void *userdata),
void *userdata, const bool postpone);
void WM_event_remove_area_handler(struct ListBase *handlers, void *area);
void WM_event_free_ui_handler_all(struct bContext *C, ListBase *handlers,
int (*func)(struct bContext *C, const struct wmEvent *event, void *userdata),
void (*remove)(struct bContext *C, void *userdata));
wmUIHandlerFunc ui_handle, wmUIHandlerRemoveFunc ui_remove,
void *userdata);
void WM_event_remove_ui_handler(
ListBase *handlers,
wmUIHandlerFunc ui_handle, wmUIHandlerRemoveFunc ui_remove,
void *userdata, const bool postpone);
void WM_event_remove_area_handler(
struct ListBase *handlers, void *area);
void WM_event_free_ui_handler_all(
struct bContext *C, ListBase *handlers,
wmUIHandlerFunc ui_handle, wmUIHandlerRemoveFunc ui_remove);
struct wmEventHandler *WM_event_add_modal_handler(struct bContext *C, struct wmOperator *op);
void WM_event_remove_handlers(struct bContext *C, ListBase *handlers);

View File

@@ -190,9 +190,6 @@ enum {
#define WM_UI_HANDLER_CONTINUE 0
#define WM_UI_HANDLER_BREAK 1
typedef int (*wmUIHandlerFunc)(struct bContext *C, const struct wmEvent *event, void *userdata);
typedef void (*wmUIHandlerRemoveFunc)(struct bContext *C, void *userdata);
/* ************** Notifiers ****************** */
typedef struct wmNotifier {

View File

@@ -2547,12 +2547,14 @@ void WM_event_remove_keymap_handler(ListBase *handlers, wmKeyMap *keymap)
}
}
wmEventHandler *WM_event_add_ui_handler(const bContext *C, ListBase *handlers,
wmUIHandlerFunc func, wmUIHandlerRemoveFunc remove, void *userdata)
wmEventHandler *WM_event_add_ui_handler(
const bContext *C, ListBase *handlers,
wmUIHandlerFunc ui_handle, wmUIHandlerRemoveFunc ui_remove,
void *userdata)
{
wmEventHandler *handler = MEM_callocN(sizeof(wmEventHandler), "event ui handler");
handler->ui_handle = func;
handler->ui_remove = remove;
handler->ui_handle = ui_handle;
handler->ui_remove = ui_remove;
handler->ui_userdata = userdata;
if (C) {
handler->ui_area = CTX_wm_area(C);
@@ -2572,13 +2574,18 @@ wmEventHandler *WM_event_add_ui_handler(const bContext *C, ListBase *handlers,
}
/* set "postpone" for win->modalhandlers, this is in a running for () loop in wm_handlers_do() */
void WM_event_remove_ui_handler(ListBase *handlers,
wmUIHandlerFunc func, wmUIHandlerRemoveFunc remove, void *userdata, const bool postpone)
void WM_event_remove_ui_handler(
ListBase *handlers,
wmUIHandlerFunc ui_handle, wmUIHandlerRemoveFunc ui_remove,
void *userdata, const bool postpone)
{
wmEventHandler *handler;
for (handler = handlers->first; handler; handler = handler->next) {
if (handler->ui_handle == func && handler->ui_remove == remove && handler->ui_userdata == userdata) {
if ((handler->ui_handle == ui_handle) &&
(handler->ui_remove == ui_remove) &&
(handler->ui_userdata == userdata))
{
/* handlers will be freed in wm_handlers_do() */
if (postpone) {
handler->flag |= WM_HANDLER_DO_FREE;
@@ -2592,15 +2599,18 @@ void WM_event_remove_ui_handler(ListBase *handlers,
}
}
void WM_event_free_ui_handler_all(bContext *C, ListBase *handlers,
wmUIHandlerFunc func, wmUIHandlerRemoveFunc remove)
void WM_event_free_ui_handler_all(
bContext *C, ListBase *handlers,
wmUIHandlerFunc ui_handle, wmUIHandlerRemoveFunc ui_remove)
{
wmEventHandler *handler, *handler_next;
for (handler = handlers->first; handler; handler = handler_next) {
handler_next = handler->next;
if (handler->ui_handle == func && handler->ui_remove == remove) {
remove(C, handler->ui_userdata);
if ((handler->ui_handle == ui_handle) &&
(handler->ui_remove == ui_remove))
{
ui_remove(C, handler->ui_userdata);
BLI_remlink(handlers, handler);
wm_event_free_handler(handler);
}