Cleanup: use iterator macros for event handlers
authorCampbell Barton <ideasman42@gmail.com>
Tue, 19 Feb 2019 22:19:07 +0000 (09:19 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 19 Feb 2019 22:38:33 +0000 (09:38 +1100)
source/blender/windowmanager/intern/wm.c
source/blender/windowmanager/intern/wm_dragdrop.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_keymap.c

index 72b906ce853d03e7265bd8a37eb84ba3acd10e53..ac65bf6a888dff1142c2b229212c972a3bf14d07 100644 (file)
@@ -198,7 +198,7 @@ void WM_operator_handlers_clear(wmWindowManager *wm, wmOperatorType *ot)
        for (win = wm->windows.first; win; win = win->next) {
                ListBase *lb[2] = {&win->handlers, &win->modalhandlers};
                for (int i = 0; i < ARRAY_SIZE(lb); i++) {
-                       for (wmEventHandler *handler_base = lb[i]->first; handler_base; handler_base = handler_base->next) {
+                       LISTBASE_FOREACH (wmEventHandler *, handler_base, lb[i]) {
                                if (handler_base->type == WM_HANDLER_TYPE_OP) {
                                        wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
                                        if (handler->op && handler->op->type == ot) {
index 7a066ef4282f8f6f17d1976090ec04aea304b35a..fcfc9c8b0ae42ba9cef1f74529600204004c8fa2 100644 (file)
@@ -194,7 +194,7 @@ void WM_drag_free_list(struct ListBase *lb)
 
 static const char *dropbox_active(bContext *C, ListBase *handlers, wmDrag *drag, const wmEvent *event)
 {
-       for (wmEventHandler *handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) {
                        wmEventHandler_Dropbox *handler = (wmEventHandler_Dropbox *)handler_base;
                        if (handler->dropboxes) {
index 53c4d4fa5e6312efe237c1ac3d2aa8d7752af279..b439d41d0638e97dab57d565797bb7914354ccaf 100644 (file)
@@ -614,11 +614,7 @@ static void wm_handler_ui_cancel(bContext *C)
        if (!ar)
                return;
 
-       for (wmEventHandler *handler_base = ar->handlers.first, *handler_base_next;
-            handler_base;
-            handler_base = handler_base_next)
-       {
-               handler_base_next = handler_base->next;
+       LISTBASE_FOREACH_MUTABLE (wmEventHandler *, handler_base, &ar->handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_UI) {
                        wmEventHandler_UI *handler = (wmEventHandler_UI *)handler_base;
                        BLI_assert(handler->handle_fn != NULL);
@@ -3246,11 +3242,7 @@ void WM_event_add_fileselect(bContext *C, wmOperator *op)
        UI_popup_handlers_remove_all(C, &win->modalhandlers);
 
        /* only allow 1 file selector open per window */
-       for (wmEventHandler *handler_base = win->modalhandlers.first, *handler_base_next;
-            handler_base;
-            handler_base = handler_base_next)
-       {
-               handler_base_next = handler_base->next;
+       LISTBASE_FOREACH_MUTABLE (wmEventHandler *, handler_base, &win->modalhandlers) {
                if (handler_base->type == WM_HANDLER_TYPE_OP) {
                        wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
                        if (handler->is_fileselect == false) {
@@ -3343,7 +3335,7 @@ wmEventHandler_Op *WM_event_add_modal_handler(bContext *C, wmOperator *op)
  */
 void WM_event_modal_handler_area_replace(wmWindow *win, const ScrArea *old_area, ScrArea *new_area)
 {
-       for (wmEventHandler *handler_base = win->modalhandlers.first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, &win->modalhandlers) {
                if (handler_base->type == WM_HANDLER_TYPE_OP) {
                        wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
                        /* fileselect handler is quite special... it needs to keep old area stored in handler, so don't change it */
@@ -3360,7 +3352,7 @@ void WM_event_modal_handler_area_replace(wmWindow *win, const ScrArea *old_area,
  */
 void WM_event_modal_handler_region_replace(wmWindow *win, const ARegion *old_region, ARegion *new_region)
 {
-       for (wmEventHandler *handler_base = win->modalhandlers.first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, &win->modalhandlers) {
                if (handler_base->type == WM_HANDLER_TYPE_OP) {
                        wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
                        if (handler->context.region == old_region) {
@@ -3379,7 +3371,7 @@ wmEventHandler_Keymap *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap
        }
 
        /* only allow same keymap once */
-       for (wmEventHandler *handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_KEYMAP) {
                        wmEventHandler_Keymap *handler = (wmEventHandler_Keymap *)handler_base;
                        if (handler->keymap == keymap) {
@@ -3423,7 +3415,7 @@ wmEventHandler_Keymap *WM_event_add_keymap_handler_bb(ListBase *handlers, wmKeyM
 
 void WM_event_remove_keymap_handler(ListBase *handlers, wmKeyMap *keymap)
 {
-       for (wmEventHandler *handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_KEYMAP) {
                        wmEventHandler_Keymap *handler = (wmEventHandler_Keymap *)handler_base;
                        if (handler->keymap == keymap) {
@@ -3479,9 +3471,7 @@ void WM_event_remove_ui_handler(
         wmUIHandlerFunc handle_fn, wmUIHandlerRemoveFunc remove_fn,
         void *user_data, const bool postpone)
 {
-       wmEventHandler *handler_base;
-
-       for (handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_UI) {
                        wmEventHandler_UI *handler = (wmEventHandler_UI *)handler_base;
                        if ((handler->handle_fn == handle_fn) &&
@@ -3506,11 +3496,7 @@ void WM_event_free_ui_handler_all(
         bContext *C, ListBase *handlers,
         wmUIHandlerFunc handle_fn, wmUIHandlerRemoveFunc remove_fn)
 {
-       for (wmEventHandler *handler_base = handlers->first, *handler_base_next;
-            handler_base;
-            handler_base = handler_base_next)
-       {
-               handler_base_next = handler_base->next;
+       LISTBASE_FOREACH_MUTABLE (wmEventHandler *, handler_base, handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_UI) {
                        wmEventHandler_UI *handler = (wmEventHandler_UI *)handler_base;
                        if ((handler->handle_fn == handle_fn) &&
@@ -3527,7 +3513,7 @@ void WM_event_free_ui_handler_all(
 wmEventHandler_Dropbox *WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropboxes)
 {
        /* only allow same dropbox once */
-       for (wmEventHandler *handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) {
                        wmEventHandler_Dropbox *handler = (wmEventHandler_Dropbox *)handler_base;
                        if (handler->dropboxes == dropboxes) {
@@ -3549,12 +3535,7 @@ wmEventHandler_Dropbox *WM_event_add_dropbox_handler(ListBase *handlers, ListBas
 /* XXX solution works, still better check the real cause (ton) */
 void WM_event_remove_area_handler(ListBase *handlers, void *area)
 {
-
-       for (wmEventHandler *handler_base = handlers->first, *handler_base_next;
-            handler_base;
-            handler_base = handler_base_next)
-       {
-               handler_base_next = handler_base->next;
+       LISTBASE_FOREACH_MUTABLE (wmEventHandler *, handler_base, handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_UI) {
                        wmEventHandler_UI *handler = (wmEventHandler_UI *)handler_base;
                        if (handler->context.area == area) {
@@ -4489,7 +4470,7 @@ static wmKeyMapItem *wm_kmi_from_event(
         bContext *C, wmWindowManager *wm,
         ListBase *handlers, const wmEvent *event)
 {
-       for (wmEventHandler *handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
                /* during this loop, ui handlers for nested menus can tag multiple handlers free */
                if (handler_base->flag & WM_HANDLER_DO_FREE) {
                        /* pass */
@@ -4760,7 +4741,7 @@ bool WM_window_modal_keymap_status_draw(
 {
        wmKeyMap *keymap = NULL;
        wmOperator *op = NULL;
-       for (wmEventHandler *handler_base = win->modalhandlers.first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, &win->modalhandlers) {
                if (handler_base->type == WM_HANDLER_TYPE_OP) {
                        wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
                        if (handler->op != NULL) {
index 670c6604dd0843d180e30475092d2740770fb61c..927a0411c3b38edc588a2bea97b10555f003f352 100644 (file)
@@ -1399,7 +1399,7 @@ void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *UNUSED(w
 
        /* if a modal operator is running, don't autosave, but try again in 10 seconds */
        for (wmWindow *win = wm->windows.first; win; win = win->next) {
-               for (wmEventHandler *handler_base = win->modalhandlers.first; handler_base; handler_base = handler_base->next) {
+               LISTBASE_FOREACH (wmEventHandler *, handler_base, &win->modalhandlers) {
                        if (handler_base->type == WM_HANDLER_TYPE_OP) {
                                wmEventHandler_Op *handler = (wmEventHandler_Op *)handler_base;
                                if (handler->op) {
index c170f0589c0c53ad9a747355ad975780cd74c19d..c522378ae32e048b7102ef39685041965f46716e 100644 (file)
@@ -1229,7 +1229,7 @@ static wmKeyMapItem *wm_keymap_item_find_handlers(
        wmKeyMap *keymap;
 
        /* find keymap item in handlers */
-       for (wmEventHandler *handler_base = handlers->first; handler_base; handler_base = handler_base->next) {
+       LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
                if (handler_base->type == WM_HANDLER_TYPE_KEYMAP) {
                        wmEventHandler_Keymap *handler = (wmEventHandler_Keymap *)handler_base;
                        keymap = WM_keymap_active(wm, handler->keymap);