diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 30 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 31 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_jobs.c | 57 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 181 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operator_type.c | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_surface.c | 3 |
7 files changed, 107 insertions, 203 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 1bd8c675807..9d118b70e43 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -376,10 +376,9 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C) /* Cached: editor refresh callbacks now, they get context. */ LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { const bScreen *screen = WM_window_get_active_screen(win); - ScrArea *area; CTX_wm_window_set(C, win); - for (area = screen->areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { if (area->do_refresh) { CTX_wm_area_set(C, area); ED_area_do_refresh(C, area); @@ -516,7 +515,7 @@ void wm_event_do_notifiers(bContext *C) bScreen *screen = WM_window_get_active_screen(win); WorkSpace *workspace = WM_window_get_active_workspace(win); - /* Dilter out notifiers. */ + /* Filter out notifiers. */ if (note->category == NC_SCREEN && note->reference && note->reference != screen && note->reference != workspace && note->reference != WM_window_get_active_layout(win)) { /* Pass. */ @@ -525,8 +524,6 @@ void wm_event_do_notifiers(bContext *C) /* Pass. */ } else { - ARegion *region; - /* XXX context in notifiers? */ CTX_wm_window_set(C, win); @@ -538,13 +535,13 @@ void wm_event_do_notifiers(bContext *C) # endif ED_screen_do_listen(C, note); - for (region = screen->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) { ED_region_do_listen(win, NULL, region, note, scene); } ED_screen_areas_iter (win, screen, area) { ED_area_do_listen(win, area, note, scene); - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { ED_region_do_listen(win, area, region, note, scene); } } @@ -1708,7 +1705,8 @@ static void wm_handler_op_context(bContext *C, wmEventHandler_Op *handler, const } if (region == NULL) { - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region_iter, &area->regionbase) { + region = region_iter; if (region == handler->context.region) { break; } @@ -2247,23 +2245,23 @@ static int wm_handler_fileselect_do(bContext *C, } } else { - wmWindow *temp_win; ScrArea *ctx_area = CTX_wm_area(C); - for (temp_win = wm->windows.first; temp_win; temp_win = temp_win->next) { + wmWindow *temp_win = NULL; + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { bScreen *screen = WM_window_get_active_screen(temp_win); ScrArea *file_area = screen->areabase.first; if (screen->temp && (file_area->spacetype == SPACE_FILE)) { int win_size[2]; bool is_maximized; - ED_fileselect_window_params_get(temp_win, win_size, &is_maximized); + ED_fileselect_window_params_get(win, win_size, &is_maximized); ED_fileselect_params_to_userdef(file_area->spacedata.first, win_size, is_maximized); if (BLI_listbase_is_single(&file_area->spacedata)) { - BLI_assert(ctx_win != temp_win); + BLI_assert(ctx_win != win); - wm_window_close(C, wm, temp_win); + wm_window_close(C, wm, win); CTX_wm_window_set(C, ctx_win); /* #wm_window_close() NULLs. */ /* Some operators expect a drawable context (for EVT_FILESELECT_EXEC). */ @@ -2272,7 +2270,7 @@ static int wm_handler_fileselect_do(bContext *C, * opening (UI_BLOCK_MOVEMOUSE_QUIT). */ wm_get_cursor_position(ctx_win, &ctx_win->eventstate->x, &ctx_win->eventstate->y); wm->winactive = ctx_win; /* Reports use this... */ - if (handler->context.win == temp_win) { + if (handler->context.win == win) { handler->context.win = NULL; } } @@ -2283,6 +2281,7 @@ static int wm_handler_fileselect_do(bContext *C, ED_area_prevspace(C, file_area); } + temp_win = win; break; } } @@ -2485,14 +2484,13 @@ static int wm_handlers_do_keymap_with_gizmo_handler( { int action = WM_HANDLER_CONTINUE; bool keymap_poll = false; - wmKeyMapItem *kmi; PRINT("%s: checking '%s' ...", __func__, keymap->idname); if (WM_keymap_poll(C, keymap)) { keymap_poll = true; PRINT("pass\n"); - for (kmi = keymap->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) { if (wm_eventmatch(event, kmi)) { PRINT("%s: item matched '%s'\n", __func__, kmi->idname); diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 3ddac8babd4..6ec6f3d9a6f 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -178,22 +178,17 @@ bool wm_file_or_image_is_modified(const Main *bmain, const wmWindowManager *wm) */ static void wm_window_match_init(bContext *C, ListBase *wmlist) { - wmWindowManager *wm; - wmWindow *win, *active_win; - *wmlist = G_MAIN->wm; BLI_listbase_clear(&G_MAIN->wm); - active_win = CTX_wm_window(C); + wmWindow *active_win = CTX_wm_window(C); /* first wrap up running stuff */ /* code copied from wm_init_exit.c */ - for (wm = wmlist->first; wm; wm = wm->id.next) { - + LISTBASE_FOREACH (wmWindowManager *, wm, wmlist) { WM_jobs_kill_all(wm); - for (win = wm->windows.first; win; win = win->next) { - + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { CTX_wm_window_set(C, win); /* needed by operator close callbacks */ WM_event_remove_handlers(C, &win->handlers); WM_event_remove_handlers(C, &win->modalhandlers); @@ -519,11 +514,9 @@ void WM_file_autoexec_init(const char *filepath) void wm_file_read_report(bContext *C, Main *bmain) { ReportList *reports = NULL; - Scene *sce; - - for (sce = bmain->scenes.first; sce; sce = sce->id.next) { - if (sce->r.engine[0] && - BLI_findstring(&R_engines, sce->r.engine, offsetof(RenderEngineType, idname)) == NULL) { + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { + if (scene->r.engine[0] && + BLI_findstring(&R_engines, scene->r.engine, offsetof(RenderEngineType, idname)) == NULL) { if (reports == NULL) { reports = CTX_wm_reports(C); } @@ -532,8 +525,8 @@ void wm_file_read_report(bContext *C, Main *bmain) RPT_ERROR, "Engine '%s' not available for scene '%s' (an add-on may need to be installed " "or enabled)", - sce->r.engine, - sce->id.name + 2); + scene->r.engine, + scene->id.name + 2); } } @@ -1136,7 +1129,7 @@ void wm_homefile_read(bContext *C, if (use_userdef) { /* Clear keymaps because the current default keymap may have been initialized * from user preferences, which have been reset. */ - for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { + LISTBASE_FOREACH (wmWindowManager *, wm, &bmain->wm) { if (wm->defaultconf) { wm->defaultconf->flag &= ~KEYCONF_INIT_DEFAULT; } @@ -1236,8 +1229,7 @@ static void wm_history_file_write(void) fp = BLI_fopen(name, "w"); if (fp) { - struct RecentFile *recent; - for (recent = G.recent_files.first; recent; recent = recent->next) { + LISTBASE_FOREACH (RecentFile *, recent, &G.recent_files) { fprintf(fp, "%s\n", recent->filepath); } fclose(fp); @@ -1430,7 +1422,6 @@ static bool wm_file_write(bContext *C, ReportList *reports) { Main *bmain = CTX_data_main(C); - Library *li; int len; int ok = false; BlendThumbnail *thumb, *main_thumb; @@ -1459,7 +1450,7 @@ static bool wm_file_write(bContext *C, * its handy for scripts to save to a predefined name without blender editing it */ /* send the OnSave event */ - for (li = bmain->libraries.first; li; li = li->id.next) { + LISTBASE_FOREACH (Library *, li, &bmain->libraries) { if (BLI_path_cmp(li->filepath_abs, filepath) == 0) { BKE_reportf(reports, RPT_ERROR, "Cannot overwrite used library '%.240s'", filepath); return ok; diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 74f352c0b62..7984c2fd879 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -412,9 +412,7 @@ void WM_init_splash(bContext *C) /* free strings of open recent files */ static void free_openrecent(void) { - struct RecentFile *recent; - - for (recent = G.recent_files.first; recent; recent = recent->next) { + LISTBASE_FOREACH (RecentFile *, recent, &G.recent_files) { MEM_freeN(recent->filepath); } diff --git a/source/blender/windowmanager/intern/wm_jobs.c b/source/blender/windowmanager/intern/wm_jobs.c index a1140c01d44..443a6fd1979 100644 --- a/source/blender/windowmanager/intern/wm_jobs.c +++ b/source/blender/windowmanager/intern/wm_jobs.c @@ -222,10 +222,8 @@ wmJob *WM_jobs_get( /* returns true if job runs, for UI (progress) indicators */ bool WM_jobs_test(wmWindowManager *wm, void *owner, int job_type) { - wmJob *wm_job; - /* job can be running or about to run (suspended) */ - for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) { + LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) { if (wm_job->owner == owner) { if (ELEM(job_type, WM_JOB_TYPE_ANY, wm_job->job_type)) { if (wm_job->running || wm_job->suspended) { @@ -266,17 +264,14 @@ static void wm_jobs_update_progress_bars(wmWindowManager *wm) /* if there are running jobs, set the global progress indicator */ if (jobs_progress > 0) { - wmWindow *win; float progress = total_progress / (float)jobs_progress; - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { WM_progress_set(win, progress); } } else { - wmWindow *win; - - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { WM_progress_clear(win); } } @@ -400,7 +395,6 @@ static void *do_job_thread(void *job_v) /* don't allow same startjob to be executed twice */ static void wm_jobs_test_suspend_stop(wmWindowManager *wm, wmJob *test) { - wmJob *wm_job; bool suspend = false; /* job added with suspend flag, we wait 1 timer step before activating it */ @@ -410,7 +404,7 @@ static void wm_jobs_test_suspend_stop(wmWindowManager *wm, wmJob *test) } else { /* check other jobs */ - for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) { + LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) { /* obvious case, no test needed */ if (wm_job == test || !wm_job->running) { continue; @@ -568,11 +562,7 @@ void WM_jobs_kill_all(wmWindowManager *wm) /* wait until every job ended, except for one owner (used in undo to keep screen job alive) */ void WM_jobs_kill_all_except(wmWindowManager *wm, void *owner) { - wmJob *wm_job, *next_job; - - for (wm_job = wm->jobs.first; wm_job; wm_job = next_job) { - next_job = wm_job->next; - + LISTBASE_FOREACH_MUTABLE (wmJob *, wm_job, &wm->jobs) { if (wm_job->owner != owner) { wm_jobs_kill_job(wm, wm_job); } @@ -581,11 +571,7 @@ void WM_jobs_kill_all_except(wmWindowManager *wm, void *owner) void WM_jobs_kill_type(struct wmWindowManager *wm, void *owner, int job_type) { - wmJob *wm_job, *next_job; - - for (wm_job = wm->jobs.first; wm_job; wm_job = next_job) { - next_job = wm_job->next; - + LISTBASE_FOREACH_MUTABLE (wmJob *, wm_job, &wm->jobs) { if (!owner || wm_job->owner == owner) { if (ELEM(job_type, WM_JOB_TYPE_ANY, wm_job->job_type)) { wm_jobs_kill_job(wm, wm_job); @@ -597,9 +583,7 @@ void WM_jobs_kill_type(struct wmWindowManager *wm, void *owner, int job_type) /* signal job(s) from this owner or callback to stop, timer is required to get handled */ void WM_jobs_stop(wmWindowManager *wm, void *owner, void *startjob) { - wmJob *wm_job; - - for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) { + LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) { if (wm_job->owner == owner || wm_job->startjob == startjob) { if (wm_job->running) { wm_job->stop = true; @@ -613,17 +597,9 @@ void WM_jobs_kill(wmWindowManager *wm, void *owner, void (*startjob)(void *, short int *, short int *, float *)) { - wmJob *wm_job; - - wm_job = wm->jobs.first; - while (wm_job) { + LISTBASE_FOREACH_MUTABLE (wmJob *, wm_job, &wm->jobs) { if (wm_job->owner == owner || wm_job->startjob == startjob) { - wmJob *wm_job_kill = wm_job; - wm_job = wm_job->next; - wm_jobs_kill_job(wm, wm_job_kill); - } - else { - wm_job = wm_job->next; + wm_jobs_kill_job(wm, wm_job); } } } @@ -631,9 +607,7 @@ void WM_jobs_kill(wmWindowManager *wm, /* kill job entirely, also removes timer itself */ void wm_jobs_timer_ended(wmWindowManager *wm, wmTimer *wt) { - wmJob *wm_job; - - for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) { + LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) { if (wm_job->wt == wt) { wm_jobs_kill_job(wm, wm_job); return; @@ -644,13 +618,8 @@ void wm_jobs_timer_ended(wmWindowManager *wm, wmTimer *wt) /* hardcoded to event TIMERJOBS */ void wm_jobs_timer(wmWindowManager *wm, wmTimer *wt) { - wmJob *wm_job, *wm_jobnext; - - for (wm_job = wm->jobs.first; wm_job; wm_job = wm_jobnext) { - wm_jobnext = wm_job->next; - + LISTBASE_FOREACH_MUTABLE (wmJob *, wm_job, &wm->jobs) { if (wm_job->wt == wt) { - /* running threads */ if (wm_job->threads.first) { @@ -735,9 +704,7 @@ void wm_jobs_timer(wmWindowManager *wm, wmTimer *wt) bool WM_jobs_has_running(wmWindowManager *wm) { - wmJob *wm_job; - - for (wm_job = wm->jobs.first; wm_job; wm_job = wm_job->next) { + LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) { if (wm_job->running) { return true; } diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 1daab07812d..1f730be8c82 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -392,8 +392,6 @@ static wmKeyMap *wm_keymap_new(const char *idname, int spaceid, int regionid) static wmKeyMap *wm_keymap_copy(wmKeyMap *keymap) { wmKeyMap *keymapn = MEM_dupallocN(keymap); - wmKeyMapItem *kmi, *kmin; - wmKeyMapDiffItem *kmdi, *kmdin; keymapn->modal_items = keymap->modal_items; keymapn->poll = keymap->poll; @@ -401,14 +399,14 @@ static wmKeyMap *wm_keymap_copy(wmKeyMap *keymap) BLI_listbase_clear(&keymapn->items); keymapn->flag &= ~(KEYMAP_UPDATE | KEYMAP_EXPANDED); - for (kmdi = keymap->diff_items.first; kmdi; kmdi = kmdi->next) { - kmdin = wm_keymap_diff_item_copy(kmdi); - BLI_addtail(&keymapn->items, kmdin); + LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &keymap->diff_items) { + wmKeyMapDiffItem *kmdi_new = wm_keymap_diff_item_copy(kmdi); + BLI_addtail(&keymapn->items, kmdi_new); } - for (kmi = keymap->items.first; kmi; kmi = kmi->next) { - kmin = wm_keymap_item_copy(kmi); - BLI_addtail(&keymapn->items, kmin); + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) { + wmKeyMapItem *kmi_new = wm_keymap_item_copy(kmi); + BLI_addtail(&keymapn->items, kmi_new); } return keymapn; @@ -416,14 +414,11 @@ static wmKeyMap *wm_keymap_copy(wmKeyMap *keymap) void WM_keymap_clear(wmKeyMap *keymap) { - wmKeyMapItem *kmi; - wmKeyMapDiffItem *kmdi; - - for (kmdi = keymap->diff_items.first; kmdi; kmdi = kmdi->next) { + LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &keymap->diff_items) { wm_keymap_diff_item_free(kmdi); } - for (kmi = keymap->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) { wm_keymap_item_free(kmi); } @@ -558,20 +553,16 @@ bool WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi) static void wm_keymap_addon_add(wmKeyMap *keymap, wmKeyMap *addonmap) { - wmKeyMapItem *kmi, *kmin; - - for (kmi = addonmap->items.first; kmi; kmi = kmi->next) { - kmin = wm_keymap_item_copy(kmi); - keymap_item_set_id(keymap, kmin); - BLI_addhead(&keymap->items, kmin); + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &addonmap->items) { + wmKeyMapItem *kmi_new = wm_keymap_item_copy(kmi); + keymap_item_set_id(keymap, kmi_new); + BLI_addhead(&keymap->items, kmi_new); } } static wmKeyMapItem *wm_keymap_find_item_equals(wmKeyMap *km, wmKeyMapItem *needle) { - wmKeyMapItem *kmi; - - for (kmi = km->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) { if (wm_keymap_item_equals(kmi, needle)) { return kmi; } @@ -582,9 +573,7 @@ static wmKeyMapItem *wm_keymap_find_item_equals(wmKeyMap *km, wmKeyMapItem *need static wmKeyMapItem *wm_keymap_find_item_equals_result(wmKeyMap *km, wmKeyMapItem *needle) { - wmKeyMapItem *kmi; - - for (kmi = km->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) { if (wm_keymap_item_equals_result(kmi, needle)) { return kmi; } @@ -596,21 +585,18 @@ static wmKeyMapItem *wm_keymap_find_item_equals_result(wmKeyMap *km, wmKeyMapIte static void wm_keymap_diff( wmKeyMap *diff_km, wmKeyMap *from_km, wmKeyMap *to_km, wmKeyMap *orig_km, wmKeyMap *addon_km) { - wmKeyMapItem *kmi, *to_kmi, *orig_kmi; - wmKeyMapDiffItem *kmdi; - - for (kmi = from_km->items.first; kmi; kmi = kmi->next) { - to_kmi = WM_keymap_item_find_id(to_km, kmi->id); + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &from_km->items) { + wmKeyMapItem *to_kmi = WM_keymap_item_find_id(to_km, kmi->id); if (!to_kmi) { /* remove item */ - kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); + wmKeyMapDiffItem *kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); kmdi->remove_item = wm_keymap_item_copy(kmi); BLI_addtail(&diff_km->diff_items, kmdi); } else if (to_kmi && !wm_keymap_item_equals(kmi, to_kmi)) { /* replace item */ - kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); + wmKeyMapDiffItem *kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); kmdi->remove_item = wm_keymap_item_copy(kmi); kmdi->add_item = wm_keymap_item_copy(to_kmi); BLI_addtail(&diff_km->diff_items, kmdi); @@ -618,7 +604,7 @@ static void wm_keymap_diff( /* sync expanded flag back to original so we don't lose it on repatch */ if (to_kmi) { - orig_kmi = WM_keymap_item_find_id(orig_km, kmi->id); + wmKeyMapItem *orig_kmi = WM_keymap_item_find_id(orig_km, kmi->id); if (!orig_kmi && addon_km) { orig_kmi = wm_keymap_find_item_equals(addon_km, kmi); @@ -631,10 +617,10 @@ static void wm_keymap_diff( } } - for (kmi = to_km->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &to_km->items) { if (kmi->id < 0) { /* add item */ - kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); + wmKeyMapDiffItem *kmdi = MEM_callocN(sizeof(wmKeyMapDiffItem), "wmKeyMapDiffItem"); kmdi->add_item = wm_keymap_item_copy(kmi); BLI_addtail(&diff_km->diff_items, kmdi); } @@ -643,12 +629,9 @@ static void wm_keymap_diff( static void wm_keymap_patch(wmKeyMap *km, wmKeyMap *diff_km) { - wmKeyMapDiffItem *kmdi; - wmKeyMapItem *kmi_remove, *kmi_add; - - for (kmdi = diff_km->diff_items.first; kmdi; kmdi = kmdi->next) { + LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &diff_km->diff_items) { /* find item to remove */ - kmi_remove = NULL; + wmKeyMapItem *kmi_remove = NULL; if (kmdi->remove_item) { kmi_remove = wm_keymap_find_item_equals(km, kmdi->remove_item); if (!kmi_remove) { @@ -660,7 +643,7 @@ static void wm_keymap_patch(wmKeyMap *km, wmKeyMap *diff_km) if (kmdi->add_item) { /* Do not re-add an already existing keymap item! See T42088. */ /* We seek only for exact copy here! See T42137. */ - kmi_add = wm_keymap_find_item_equals(km, kmdi->add_item); + wmKeyMapItem *kmi_add = wm_keymap_find_item_equals(km, kmdi->add_item); /** If kmi_add is same as kmi_remove (can happen in some cases, * typically when we got kmi_remove from #wm_keymap_find_item_equals_result()), @@ -712,11 +695,11 @@ static wmKeyMap *wm_keymap_patch_update(ListBase *lb, wmKeyMap *addonmap, wmKeyMap *usermap) { - wmKeyMap *km; int expanded = 0; /* remove previous keymap in list, we will replace it */ - km = WM_keymap_list_find(lb, defaultmap->idname, defaultmap->spaceid, defaultmap->regionid); + wmKeyMap *km = WM_keymap_list_find( + lb, defaultmap->idname, defaultmap->spaceid, defaultmap->regionid); if (km) { expanded = (km->flag & (KEYMAP_EXPANDED | KEYMAP_CHILDREN_EXPANDED)); WM_keymap_clear(km); @@ -727,13 +710,12 @@ static wmKeyMap *wm_keymap_patch_update(ListBase *lb, if (usermap && !(usermap->flag & KEYMAP_DIFF)) { /* for compatibility with old user preferences with non-diff * keymaps we override the original entirely */ - wmKeyMapItem *kmi, *orig_kmi; km = wm_keymap_copy(usermap); /* try to find corresponding id's for items */ - for (kmi = km->items.first; kmi; kmi = kmi->next) { - orig_kmi = wm_keymap_find_item_equals(defaultmap, kmi); + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) { + wmKeyMapItem *orig_kmi = wm_keymap_find_item_equals(defaultmap, kmi); if (!orig_kmi) { orig_kmi = wm_keymap_find_item_equals_result(defaultmap, kmi); } @@ -779,10 +761,8 @@ static void wm_keymap_diff_update(ListBase *lb, wmKeyMap *addonmap, wmKeyMap *km) { - wmKeyMap *diffmap, *prevmap, *origmap; - /* create temporary default + addon keymap for diff */ - origmap = defaultmap; + wmKeyMap *origmap = defaultmap; if (addonmap) { defaultmap = wm_keymap_copy(defaultmap); @@ -790,14 +770,14 @@ static void wm_keymap_diff_update(ListBase *lb, } /* remove previous diff keymap in list, we will replace it */ - prevmap = WM_keymap_list_find(lb, km->idname, km->spaceid, km->regionid); + wmKeyMap *prevmap = WM_keymap_list_find(lb, km->idname, km->spaceid, km->regionid); if (prevmap) { WM_keymap_clear(prevmap); BLI_freelinkN(lb, prevmap); } /* create diff keymap */ - diffmap = wm_keymap_new(km->idname, km->spaceid, km->regionid); + wmKeyMap *diffmap = wm_keymap_new(km->idname, km->spaceid, km->regionid); diffmap->flag |= KEYMAP_DIFF; if (defaultmap->flag & KEYMAP_MODAL) { diffmap->flag |= KEYMAP_MODAL; @@ -833,9 +813,7 @@ static void wm_keymap_diff_update(ListBase *lb, wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid) { - wmKeyMap *km; - - for (km = lb->first; km; km = km->next) { + LISTBASE_FOREACH (wmKeyMap *, km, lb) { if (km->spaceid == spaceid && km->regionid == regionid) { if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) { return km; @@ -851,9 +829,7 @@ wmKeyMap *WM_keymap_list_find_spaceid_or_empty(ListBase *lb, int spaceid, int regionid) { - wmKeyMap *km; - - for (km = lb->first; km; km = km->next) { + LISTBASE_FOREACH (wmKeyMap *, km, lb) { if (ELEM(km->spaceid, spaceid, SPACE_EMPTY) && km->regionid == regionid) { if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) { return km; @@ -928,17 +904,16 @@ wmKeyMap *WM_modalkeymap_ensure(wmKeyConfig *keyconf, wmKeyMap *WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname) { - wmKeyMap *km; - - for (km = keyconf->keymaps.first; km; km = km->next) { + LISTBASE_FOREACH (wmKeyMap *, km, &keyconf->keymaps) { if (km->flag & KEYMAP_MODAL) { if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) { + return km; break; } } } - return km; + return NULL; } wmKeyMapItem *WM_modalkeymap_add_item( @@ -1015,17 +990,13 @@ static void wm_user_modal_keymap_set_items(wmWindowManager *wm, wmKeyMap *km) { /* here we convert propvalue string values delayed, due to python keymaps * being created before the actual modal keymaps, so no modal_items */ - wmKeyMap *defaultkm; - wmKeyMapItem *kmi; - int propvalue; if (km && (km->flag & KEYMAP_MODAL) && !km->modal_items) { if (wm->defaultconf == NULL) { return; } - defaultkm = WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, 0, 0); - + wmKeyMap *defaultkm = WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, 0, 0); if (!defaultkm) { return; } @@ -1035,8 +1006,9 @@ static void wm_user_modal_keymap_set_items(wmWindowManager *wm, wmKeyMap *km) km->poll_modal_item = defaultkm->poll_modal_item; if (km->modal_items) { - for (kmi = km->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) { if (kmi->propvalue_str[0]) { + int propvalue; if (RNA_enum_value_from_id(km->modal_items, kmi->propvalue_str, &propvalue)) { kmi->propvalue = propvalue; } @@ -1510,8 +1482,6 @@ static wmKeyMapItem *wm_keymap_item_find(const bContext *C, const struct wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap) { - wmKeyMapItem *found; - /* XXX Hack! Macro operators in menu entry have their whole props defined, * which is not the case for relevant keymap entries. * Could be good to check and harmonize this, @@ -1521,7 +1491,8 @@ static wmKeyMapItem *wm_keymap_item_find(const bContext *C, is_strict = is_strict && ((ot->flag & OPTYPE_MACRO) == 0); } - found = wm_keymap_item_find_props(C, opname, opcontext, properties, is_strict, params, r_keymap); + wmKeyMapItem *found = wm_keymap_item_find_props( + C, opname, opcontext, properties, is_strict, params, r_keymap); /* This block is *only* useful in one case: when op uses an enum menu in its prop member * (then, we want to rerun a comparison with that 'prop' unset). Note this remains brittle, @@ -1556,8 +1527,6 @@ static wmKeyMapItem *wm_keymap_item_find(const bContext *C, /* Debug only, helps spotting mismatches between menu entries and shortcuts! */ if (G.debug & G_DEBUG_WM) { if (!found && is_strict && properties) { - wmKeyMap *km; - wmKeyMapItem *kmi; if (ot) { /* make a copy of the properties and set unset ones to their default values. */ PointerRNA opptr; @@ -1566,7 +1535,8 @@ static wmKeyMapItem *wm_keymap_item_find(const bContext *C, RNA_pointer_create(NULL, ot->srna, properties_default, &opptr); WM_operator_properties_default(&opptr, true); - kmi = wm_keymap_item_find_props( + wmKeyMap *km; + wmKeyMapItem *kmi = wm_keymap_item_find_props( C, opname, opcontext, properties_default, is_strict, params, &km); if (kmi) { char kmi_str[128]; @@ -1687,15 +1657,13 @@ wmKeyMapItem *WM_key_event_operator_from_keymap(wmKeyMap *keymap, bool WM_keymap_item_compare(wmKeyMapItem *k1, wmKeyMapItem *k2) { - int k1type, k2type; - if (k1->flag & KMI_INACTIVE || k2->flag & KMI_INACTIVE) { return 0; } /* take event mapping into account */ - k1type = WM_userdef_event_map(k1->type); - k2type = WM_userdef_event_map(k2->type); + int k1type = WM_userdef_event_map(k1->type); + int k2type = WM_userdef_event_map(k2->type); if (k1type != KM_ANY && k2type != KM_ANY && k1type != k2type) { return 0; @@ -1777,13 +1745,10 @@ void WM_keyconfig_update_operatortype(void) static bool wm_keymap_test_and_clear_update(wmKeyMap *km) { - wmKeyMapItem *kmi; - int update; - - update = (km->flag & KEYMAP_UPDATE); + int update = (km->flag & KEYMAP_UPDATE); km->flag &= ~KEYMAP_UPDATE; - for (kmi = km->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) { update = update || (kmi->flag & KMI_UPDATE); kmi->flag &= ~KMI_UPDATE; } @@ -1794,9 +1759,7 @@ static bool wm_keymap_test_and_clear_update(wmKeyMap *km) static wmKeyMap *wm_keymap_preset(wmWindowManager *wm, wmKeyMap *km) { wmKeyConfig *keyconf = WM_keyconfig_active(wm); - wmKeyMap *keymap; - - keymap = WM_keymap_list_find(&keyconf->keymaps, km->idname, km->spaceid, km->regionid); + wmKeyMap *keymap = WM_keymap_list_find(&keyconf->keymaps, km->idname, km->spaceid, km->regionid); if (!keymap && wm->defaultconf) { keymap = WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, km->spaceid, km->regionid); } @@ -1806,9 +1769,6 @@ static wmKeyMap *wm_keymap_preset(wmWindowManager *wm, wmKeyMap *km) void WM_keyconfig_update(wmWindowManager *wm) { - wmKeyMap *km, *defaultmap, *addonmap, *usermap, *kmn; - wmKeyMapItem *kmi; - wmKeyMapDiffItem *kmdi; bool compat_update = false; if (G.background) { @@ -1822,8 +1782,6 @@ void WM_keyconfig_update(wmWindowManager *wm) if (wm_keymap_update_flag & WM_KEYMAP_UPDATE_OPERATORTYPE) { /* an operatortype has been removed, this wont happen often * but when it does we have to check _every_ keymap item */ - wmKeyConfig *kc; - ListBase *keymaps_lb[] = { &U.user_keymaps, &wm->userconf->keymaps, @@ -1838,7 +1796,7 @@ void WM_keyconfig_update(wmWindowManager *wm) wm_keymap_item_properties_update_ot_from_list(keymaps_lb[i]); } - for (kc = wm->keyconfigs.first; kc; kc = kc->next) { + LISTBASE_FOREACH (wmKeyConfig *, kc, &wm->keyconfigs) { wm_keymap_item_properties_update_ot_from_list(&kc->keymaps); } @@ -1850,9 +1808,9 @@ void WM_keyconfig_update(wmWindowManager *wm) } /* update operator properties for non-modal user keymaps */ - for (km = U.user_keymaps.first; km; km = km->next) { + LISTBASE_FOREACH (wmKeyMap *, km, &U.user_keymaps) { if ((km->flag & KEYMAP_MODAL) == 0) { - for (kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) { + LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &km->diff_items) { if (kmdi->add_item) { wm_keymap_item_properties_set(kmdi->add_item); } @@ -1861,19 +1819,19 @@ void WM_keyconfig_update(wmWindowManager *wm) } } - for (kmi = km->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) { wm_keymap_item_properties_set(kmi); } } } /* update U.user_keymaps with user key configuration changes */ - for (km = wm->userconf->keymaps.first; km; km = km->next) { + LISTBASE_FOREACH (wmKeyMap *, km, &wm->userconf->keymaps) { /* only diff if the user keymap was modified */ if (wm_keymap_test_and_clear_update(km)) { /* find keymaps */ - defaultmap = wm_keymap_preset(wm, km); - addonmap = WM_keymap_list_find( + wmKeyMap *defaultmap = wm_keymap_preset(wm, km); + wmKeyMap *addonmap = WM_keymap_list_find( &wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid); /* diff */ @@ -1884,18 +1842,20 @@ void WM_keyconfig_update(wmWindowManager *wm) } /* create user key configuration from preset + addon + user preferences */ - for (km = wm->defaultconf->keymaps.first; km; km = km->next) { + LISTBASE_FOREACH (wmKeyMap *, km, &wm->defaultconf->keymaps) { /* find keymaps */ - defaultmap = wm_keymap_preset(wm, km); - addonmap = WM_keymap_list_find(&wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid); - usermap = WM_keymap_list_find(&U.user_keymaps, km->idname, km->spaceid, km->regionid); + wmKeyMap *defaultmap = wm_keymap_preset(wm, km); + wmKeyMap *addonmap = WM_keymap_list_find( + &wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid); + wmKeyMap *usermap = WM_keymap_list_find( + &U.user_keymaps, km->idname, km->spaceid, km->regionid); /* For now only the default map defines modal key-maps, * if we support modal keymaps for 'addonmap', these will need to be enabled too. */ wm_user_modal_keymap_set_items(wm, defaultmap); /* add */ - kmn = wm_keymap_patch_update(&wm->userconf->keymaps, defaultmap, addonmap, usermap); + wmKeyMap *kmn = wm_keymap_patch_update(&wm->userconf->keymaps, defaultmap, addonmap, usermap); if (kmn) { kmn->modal_items = km->modal_items; @@ -1928,14 +1888,12 @@ void WM_keyconfig_update(wmWindowManager *wm) wmKeyMap *WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap) { - wmKeyMap *km; - if (!keymap) { return NULL; } /* first user defined keymaps */ - km = WM_keymap_list_find( + wmKeyMap *km = WM_keymap_list_find( &wm->userconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); if (km) { @@ -1955,16 +1913,13 @@ wmKeyMap *WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap) void WM_keymap_item_restore_to_default(wmWindowManager *wm, wmKeyMap *keymap, wmKeyMapItem *kmi) { - wmKeyMap *defaultmap, *addonmap; - wmKeyMapItem *orig; - if (!keymap) { return; } /* construct default keymap from preset + addons */ - defaultmap = wm_keymap_preset(wm, keymap); - addonmap = WM_keymap_list_find( + wmKeyMap *defaultmap = wm_keymap_preset(wm, keymap); + wmKeyMap *addonmap = WM_keymap_list_find( &wm->addonconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); if (addonmap) { @@ -1973,7 +1928,7 @@ void WM_keymap_item_restore_to_default(wmWindowManager *wm, wmKeyMap *keymap, wm } /* find original item */ - orig = WM_keymap_item_find_id(defaultmap, kmi->id); + wmKeyMapItem *orig = WM_keymap_item_find_id(defaultmap, kmi->id); if (orig) { /* restore to original */ @@ -2030,9 +1985,7 @@ void WM_keymap_restore_to_default(wmKeyMap *keymap, wmWindowManager *wm) wmKeyMapItem *WM_keymap_item_find_id(wmKeyMap *keymap, int id) { - wmKeyMapItem *kmi; - - for (kmi = keymap->items.first; kmi; kmi = kmi->next) { + LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) { if (kmi->id == id) { return kmi; } diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c index 7621862708e..4c4fd2b1a8e 100644 --- a/source/blender/windowmanager/intern/wm_operator_type.c +++ b/source/blender/windowmanager/intern/wm_operator_type.c @@ -572,9 +572,7 @@ wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char static void wm_operatortype_free_macro(wmOperatorType *ot) { - wmOperatorTypeMacro *otmacro; - - for (otmacro = ot->macro.first; otmacro; otmacro = otmacro->next) { + LISTBASE_FOREACH (wmOperatorTypeMacro *, otmacro, &ot->macro) { if (otmacro->ptr) { WM_operator_properties_free(otmacro->ptr); MEM_freeN(otmacro->ptr); diff --git a/source/blender/windowmanager/intern/wm_surface.c b/source/blender/windowmanager/intern/wm_surface.c index 4139574460b..715f72d70cf 100644 --- a/source/blender/windowmanager/intern/wm_surface.c +++ b/source/blender/windowmanager/intern/wm_surface.c @@ -116,8 +116,7 @@ void wm_surfaces_free(void) { wm_surface_clear_drawable(); - for (wmSurface *surf = global_surface_list.first, *surf_next; surf; surf = surf_next) { - surf_next = surf->next; + LISTBASE_FOREACH_MUTABLE (wmSurface *, surf, &global_surface_list) { wm_surface_remove(surf); } |